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