xref: /netbsd/sys/arch/x68k/dev/scsirom.c (revision bf9ec67e)
1 /*	$NetBSD: scsirom.c,v 1.6 2000/01/16 14:20:57 minoura Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999 NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Minoura Makoto.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. The name of the author may not be used to endorse or promote products
23  *    derived from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 /*
39  * SCSI BIOS ROM.
40  * Used to probe the board.
41  */
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 
47 #include <machine/bus.h>
48 #include <machine/cpu.h>
49 
50 #include <arch/x68k/dev/intiovar.h>
51 #include <arch/x68k/dev/scsiromvar.h>
52 
53 struct {
54 	paddr_t addr, devaddr;
55 	int intr;
56 	const char id[7];
57 } scsirom_descr[] = {{
58 	0x00fc0000, 0x00e96020, 108, "SCSIIN"
59 }, {
60 	0x00ea0020, 0x00ea0000, 246, "SCSIEX"
61 }};
62 
63 #define SCSIROM_ID	0x24
64 
65 /*
66  * autoconf stuff
67  */
68 static int scsirom_find __P((struct device *, struct intio_attach_args *));
69 static int scsirom_match __P((struct device *, struct cfdata *, void *));
70 static void scsirom_attach __P((struct device *, struct device *, void *));
71 
72 struct cfattach scsirom_ca = {
73 	sizeof(struct scsirom_softc), scsirom_match, scsirom_attach
74 };
75 
76 static int
77 scsirom_find (parent, ia)
78 	struct device *parent;
79 	struct intio_attach_args *ia;
80 {
81 	bus_space_handle_t ioh;
82 	char buf[10];
83 	int which;
84 	int r = -1;
85 
86 	if (ia->ia_addr == scsirom_descr[INTERNAL].addr)
87 		which = INTERNAL;
88 	else if (ia->ia_addr == scsirom_descr[EXTERNAL].addr)
89 		which = EXTERNAL;
90 	else
91 		return -1;
92 
93 	ia->ia_size = 0x1fe0;
94 	if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
95 		return -1;
96 
97 	if (bus_space_map (ia->ia_bst, ia->ia_addr, ia->ia_size, 0, &ioh) < 0)
98 		return -1;
99 	if (badaddr ((caddr_t)INTIO_ADDR(ia->ia_addr+SCSIROM_ID))) {
100 		bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
101 		return -1;
102 	}
103 	bus_space_read_region_1 (ia->ia_bst, ioh, SCSIROM_ID, buf, 6);
104 	if (memcmp(buf, scsirom_descr[which].id, 6) == 0)
105 		r = which;
106 	bus_space_unmap (ia->ia_bst, ioh, ia->ia_size);
107 
108 	return r;
109 }
110 
111 static int
112 scsirom_match(parent, cf, aux)
113 	struct device *parent;
114 	struct cfdata *cf;
115 	void *aux;
116 {
117 	struct intio_attach_args *ia = aux;
118 	int r;
119 
120 	if (strcmp (ia->ia_name, "scsirom") != 0)
121 		return 0;
122 
123 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT) {
124 		ia->ia_addr = scsirom_descr[0].addr;
125 		r = scsirom_find (parent, ia);
126 		if (r == INTERNAL)
127 			return 1;
128 		ia->ia_addr = scsirom_descr[1].addr;
129 		r = scsirom_find (parent, ia);
130 		if (r == EXTERNAL)
131 			return 1;
132 		return 0;
133 	} else if (scsirom_find(parent, ia) >= 0)
134 		return 1;
135 	else
136 		return 0;
137 }
138 
139 static void
140 scsirom_attach(parent, self, aux)
141 	struct device *parent, *self;
142 	void *aux;
143 {
144 	struct scsirom_softc *sc = (struct scsirom_softc *)self;
145 	struct intio_attach_args *ia = aux;
146 	int r;
147 	struct cfdata *cf;
148 
149 	sc->sc_addr = ia->ia_addr;
150 	sc->sc_which = scsirom_find (parent, ia);
151 #ifdef DIAGNOSTIC
152 	if (sc->sc_which < 0)
153 		panic ("SCSIROM curruption??");
154 #endif
155 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
156 #ifdef DIAGNOSTIC
157 	if (r)
158 		panic ("IO map for SCSIROM corruption??");
159 #endif
160 
161 	ia->ia_addr = scsirom_descr[sc->sc_which].devaddr;
162 	if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
163 		ia->ia_intr = scsirom_descr[sc->sc_which].intr;
164 
165 	if (sc->sc_which == INTERNAL)
166 		printf (": On-board at %p\n", (void*)ia->ia_addr);
167 	else
168 		printf (": External at %p\n", (void*)ia->ia_addr);
169 
170 	cf = config_search (NULL, self, ia);
171 	if (cf) {
172 		config_attach(self, cf, ia, NULL);
173 	} else {
174 		printf ("%s: no matching device; ignored.\n",
175 			self->dv_xname);
176 	}
177 
178 	return;
179 }
180