Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / x68k / dev / scsirom.c
blob5e8be829b44500bfdc76fcedacf0d2e263ab16a6
1 /* $NetBSD: scsirom.c,v 1.18 2008/06/25 08:14:59 isaki Exp $ */
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Minoura Makoto.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * SCSI BIOS ROM.
34 * Used to probe the board.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: scsirom.c,v 1.18 2008/06/25 08:14:59 isaki Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
44 #include <machine/bus.h>
45 #include <machine/cpu.h>
47 #include <arch/x68k/dev/intiovar.h>
48 #include <arch/x68k/dev/scsiromvar.h>
50 struct {
51 paddr_t addr, devaddr;
52 int intr;
53 const char id[7];
54 } scsirom_descr[] = {{
55 0x00fc0000, 0x00e96020, 108, "SCSIIN"
56 }, {
57 0x00ea0020, 0x00ea0000, 246, "SCSIEX"
58 }};
60 #define SCSIROM_ID 0x24
63 * autoconf stuff
65 static int scsirom_find(device_t, struct intio_attach_args *);
66 static int scsirom_match(device_t, cfdata_t, void *);
67 static void scsirom_attach(device_t, device_t, void *);
69 CFATTACH_DECL_NEW(scsirom, sizeof(struct scsirom_softc),
70 scsirom_match, scsirom_attach, NULL, NULL);
72 static int
73 scsirom_find(device_t parent, struct intio_attach_args *ia)
75 bus_space_handle_t ioh;
76 char buf[10];
77 int which;
78 int r = -1;
80 if (ia->ia_addr == scsirom_descr[INTERNAL].addr)
81 which = INTERNAL;
82 else if (ia->ia_addr == scsirom_descr[EXTERNAL].addr)
83 which = EXTERNAL;
84 else
85 return -1;
87 ia->ia_size = 0x1fe0;
88 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
89 return -1;
91 if (bus_space_map(ia->ia_bst, ia->ia_addr, ia->ia_size, 0, &ioh) < 0)
92 return -1;
93 if (badaddr((void *)IIOV(ia->ia_addr+SCSIROM_ID))) {
94 bus_space_unmap(ia->ia_bst, ioh, ia->ia_size);
95 return -1;
97 bus_space_read_region_1(ia->ia_bst, ioh, SCSIROM_ID, buf, 6);
98 if (memcmp(buf, scsirom_descr[which].id, 6) == 0)
99 r = which;
100 bus_space_unmap(ia->ia_bst, ioh, ia->ia_size);
102 return r;
105 static int
106 scsirom_match(device_t parent, cfdata_t cf, void *aux)
108 struct intio_attach_args *ia = aux;
109 int r;
111 if (strcmp(ia->ia_name, "scsirom") != 0)
112 return 0;
114 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT) {
115 ia->ia_addr = scsirom_descr[0].addr;
116 r = scsirom_find(parent, ia);
117 if (r == INTERNAL)
118 return 1;
119 ia->ia_addr = scsirom_descr[1].addr;
120 r = scsirom_find(parent, ia);
121 if (r == EXTERNAL)
122 return 1;
123 return 0;
124 } else if (scsirom_find(parent, ia) >= 0)
125 return 1;
126 else
127 return 0;
130 static void
131 scsirom_attach(device_t parent, device_t self, void *aux)
133 struct scsirom_softc *sc = device_private(self);
134 struct intio_attach_args *ia = aux;
135 int r;
136 cfdata_t cf;
138 sc->sc_addr = ia->ia_addr;
139 sc->sc_which = scsirom_find(parent, ia);
140 #ifdef DIAGNOSTIC
141 if (sc->sc_which < 0)
142 panic("SCSIROM curruption??");
143 #endif
144 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
145 #ifdef DIAGNOSTIC
146 if (r)
147 panic("IO map for SCSIROM corruption??");
148 #endif
150 ia->ia_addr = scsirom_descr[sc->sc_which].devaddr;
151 if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
152 ia->ia_intr = scsirom_descr[sc->sc_which].intr;
154 if (sc->sc_which == INTERNAL)
155 aprint_normal(": On-board at %p\n", (void *)ia->ia_addr);
156 else
157 aprint_normal(": External at %p\n", (void *)ia->ia_addr);
159 cf = config_search_ia(NULL, self, "scsirom", ia);
160 if (cf) {
161 config_attach(self, cf, ia, NULL);
162 } else {
163 aprint_normal_dev(self, "no matching device; ignored.\n");
166 return;