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