spc.c revision 1.26 1 1.26 lukem /* $NetBSD: spc.c,v 1.26 2003/07/15 01:44:52 lukem Exp $ */
2 1.1 oki
3 1.20 minoura /*-
4 1.20 minoura * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.20 minoura * All rights reserved.
6 1.20 minoura *
7 1.20 minoura * This code is derived from software contributed to The NetBSD Foundation
8 1.20 minoura * by Jarle Greipsland, Charles M. Hannum and Masaru Oki.
9 1.1 oki *
10 1.1 oki * Redistribution and use in source and binary forms, with or without
11 1.1 oki * modification, are permitted provided that the following conditions
12 1.1 oki * are met:
13 1.1 oki * 1. Redistributions of source code must retain the above copyright
14 1.1 oki * notice, this list of conditions and the following disclaimer.
15 1.1 oki * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 oki * notice, this list of conditions and the following disclaimer in the
17 1.1 oki * documentation and/or other materials provided with the distribution.
18 1.1 oki * 3. All advertising materials mentioning features or use of this software
19 1.1 oki * must display the following acknowledgement:
20 1.20 minoura * This product includes software developed by the NetBSD
21 1.20 minoura * Foundation, Inc. and its contributors.
22 1.20 minoura * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.20 minoura * contributors may be used to endorse or promote products derived
24 1.20 minoura * from this software without specific prior written permission.
25 1.1 oki *
26 1.20 minoura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.20 minoura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.20 minoura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.20 minoura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.20 minoura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.20 minoura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.20 minoura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.20 minoura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.20 minoura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.20 minoura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 oki * POSSIBILITY OF SUCH DAMAGE.
37 1.1 oki */
38 1.26 lukem
39 1.26 lukem #include <sys/cdefs.h>
40 1.26 lukem __KERNEL_RCSID(0, "$NetBSD: spc.c,v 1.26 2003/07/15 01:44:52 lukem Exp $");
41 1.1 oki
42 1.15 jonathan #include "opt_ddb.h"
43 1.1 oki
44 1.1 oki #include <sys/param.h>
45 1.1 oki #include <sys/systm.h>
46 1.1 oki #include <sys/kernel.h>
47 1.1 oki #include <sys/device.h>
48 1.20 minoura
49 1.20 minoura #include <machine/bus.h>
50 1.20 minoura #include <machine/cpu.h>
51 1.1 oki
52 1.10 bouyer #include <dev/scsipi/scsi_all.h>
53 1.10 bouyer #include <dev/scsipi/scsipi_all.h>
54 1.10 bouyer #include <dev/scsipi/scsiconf.h>
55 1.1 oki
56 1.20 minoura #include <arch/x68k/dev/intiovar.h>
57 1.20 minoura #include <arch/x68k/dev/scsiromvar.h>
58 1.20 minoura #include <arch/x68k/x68k/iodevice.h>
59 1.1 oki
60 1.20 minoura #include <dev/ic/mb89352var.h>
61 1.20 minoura #include <dev/ic/mb89352reg.h>
62 1.1 oki
63 1.20 minoura static int spc_intio_match __P((struct device *, struct cfdata *, void *));
64 1.20 minoura static void spc_intio_attach __P((struct device *, struct device *, void *));
65 1.1 oki
66 1.23 thorpej CFATTACH_DECL(spc_intio, sizeof (struct spc_softc),
67 1.24 thorpej spc_intio_match, spc_intio_attach, NULL, NULL);
68 1.1 oki
69 1.20 minoura static int
70 1.20 minoura spc_intio_match(parent, cf, aux)
71 1.1 oki struct device *parent;
72 1.16 minoura struct cfdata *cf;
73 1.16 minoura void *aux;
74 1.1 oki {
75 1.20 minoura struct intio_attach_args *ia = aux;
76 1.20 minoura bus_space_tag_t iot = ia->ia_bst;
77 1.20 minoura bus_space_handle_t ioh;
78 1.1 oki
79 1.20 minoura ia->ia_size=0x20;
80 1.1 oki
81 1.20 minoura if (intio_map_allocate_region(parent->dv_parent, ia,
82 1.20 minoura INTIO_MAP_TESTONLY) < 0)
83 1.1 oki return 0;
84 1.1 oki
85 1.20 minoura if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED,
86 1.20 minoura &ioh) < 0)
87 1.20 minoura return 0;
88 1.21 minoura if (badaddr ((caddr_t)INTIO_ADDR(ia->ia_addr + BDID)))
89 1.1 oki return 0;
90 1.20 minoura bus_space_unmap(iot, ioh, 0x20);
91 1.1 oki
92 1.20 minoura return 1;
93 1.1 oki }
94 1.1 oki
95 1.20 minoura static void
96 1.20 minoura spc_intio_attach(parent, self, aux)
97 1.1 oki struct device *parent, *self;
98 1.1 oki void *aux;
99 1.1 oki {
100 1.20 minoura struct spc_softc *sc = (struct spc_softc *)self;
101 1.20 minoura struct intio_attach_args *ia = aux;
102 1.20 minoura bus_space_tag_t iot = ia->ia_bst;
103 1.20 minoura bus_space_handle_t ioh;
104 1.20 minoura
105 1.20 minoura printf ("\n");
106 1.20 minoura
107 1.20 minoura intio_map_allocate_region(parent->dv_parent, ia,
108 1.20 minoura INTIO_MAP_ALLOCATE);
109 1.20 minoura if (bus_space_map(iot, ia->ia_addr, 0x20, BUS_SPACE_MAP_SHIFTED,
110 1.20 minoura &ioh)) {
111 1.20 minoura printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
112 1.12 oki return;
113 1.1 oki }
114 1.1 oki
115 1.20 minoura sc->sc_iot = iot;
116 1.20 minoura sc->sc_ioh = ioh;
117 1.20 minoura sc->sc_initiator = IODEVbase->io_sram[0x70] & 0x7; /* XXX */
118 1.1 oki
119 1.25 tsutsui if (intio_intr_establish(ia->ia_intr, "spc", spc_intr, sc))
120 1.20 minoura panic ("spcattach: interrupt vector busy");
121 1.1 oki
122 1.25 tsutsui spc_attach(sc);
123 1.1 oki }
124