1 /* $NetBSD: scsirom.c,v 1.18 2008/06/25 08:14:59 isaki Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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>
51 paddr_t addr
, devaddr
;
54 } scsirom_descr
[] = {{
55 0x00fc0000, 0x00e96020, 108, "SCSIIN"
57 0x00ea0020, 0x00ea0000, 246, "SCSIEX"
60 #define SCSIROM_ID 0x24
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
);
73 scsirom_find(device_t parent
, struct intio_attach_args
*ia
)
75 bus_space_handle_t ioh
;
80 if (ia
->ia_addr
== scsirom_descr
[INTERNAL
].addr
)
82 else if (ia
->ia_addr
== scsirom_descr
[EXTERNAL
].addr
)
88 if (intio_map_allocate_region(parent
, ia
, INTIO_MAP_TESTONLY
))
91 if (bus_space_map(ia
->ia_bst
, ia
->ia_addr
, ia
->ia_size
, 0, &ioh
) < 0)
93 if (badaddr((void *)IIOV(ia
->ia_addr
+SCSIROM_ID
))) {
94 bus_space_unmap(ia
->ia_bst
, ioh
, ia
->ia_size
);
97 bus_space_read_region_1(ia
->ia_bst
, ioh
, SCSIROM_ID
, buf
, 6);
98 if (memcmp(buf
, scsirom_descr
[which
].id
, 6) == 0)
100 bus_space_unmap(ia
->ia_bst
, ioh
, ia
->ia_size
);
106 scsirom_match(device_t parent
, cfdata_t cf
, void *aux
)
108 struct intio_attach_args
*ia
= aux
;
111 if (strcmp(ia
->ia_name
, "scsirom") != 0)
114 if (ia
->ia_addr
== INTIOCF_ADDR_DEFAULT
) {
115 ia
->ia_addr
= scsirom_descr
[0].addr
;
116 r
= scsirom_find(parent
, ia
);
119 ia
->ia_addr
= scsirom_descr
[1].addr
;
120 r
= scsirom_find(parent
, ia
);
124 } else if (scsirom_find(parent
, ia
) >= 0)
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
;
138 sc
->sc_addr
= ia
->ia_addr
;
139 sc
->sc_which
= scsirom_find(parent
, ia
);
141 if (sc
->sc_which
< 0)
142 panic("SCSIROM curruption??");
144 r
= intio_map_allocate_region(parent
, ia
, INTIO_MAP_ALLOCATE
);
147 panic("IO map for SCSIROM corruption??");
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
);
157 aprint_normal(": External at %p\n", (void *)ia
->ia_addr
);
159 cf
= config_search_ia(NULL
, self
, "scsirom", ia
);
161 config_attach(self
, cf
, ia
, NULL
);
163 aprint_normal_dev(self
, "no matching device; ignored.\n");