oosiop_gsc.c revision 1.1.10.2 1 1.1.10.2 tls /* $NetBSD: oosiop_gsc.c,v 1.1.10.2 2014/08/20 00:03:04 tls Exp $ */
2 1.1.10.2 tls
3 1.1.10.2 tls /*
4 1.1.10.2 tls * Copyright (c) 2001 Matt Fredette. All rights reserved.
5 1.1.10.2 tls *
6 1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
7 1.1.10.2 tls * modification, are permitted provided that the following conditions
8 1.1.10.2 tls * are met:
9 1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
10 1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
11 1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
13 1.1.10.2 tls * documentation and/or other materials provided with the distribution.
14 1.1.10.2 tls * 3. The name of the author may not be used to endorse or promote products
15 1.1.10.2 tls * derived from this software without specific prior written permission.
16 1.1.10.2 tls *
17 1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 1.1.10.2 tls * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1.10.2 tls * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1.10.2 tls * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1.10.2 tls * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1.10.2 tls * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1.10.2 tls * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1.10.2 tls * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1.10.2 tls * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1.10.2 tls * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1.10.2 tls */
28 1.1.10.2 tls
29 1.1.10.2 tls /*-
30 1.1.10.2 tls * Copyright (c) 2001,2002 Izumi Tsutsui. All rights reserved.
31 1.1.10.2 tls *
32 1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
33 1.1.10.2 tls * modification, are permitted provided that the following conditions
34 1.1.10.2 tls * are met:
35 1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
36 1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
37 1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
38 1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
39 1.1.10.2 tls * documentation and/or other materials provided with the distribution.
40 1.1.10.2 tls *
41 1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
42 1.1.10.2 tls * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 1.1.10.2 tls * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 1.1.10.2 tls * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
45 1.1.10.2 tls * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 1.1.10.2 tls * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 1.1.10.2 tls * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 1.1.10.2 tls * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 1.1.10.2 tls * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
50 1.1.10.2 tls * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 1.1.10.2 tls */
52 1.1.10.2 tls
53 1.1.10.2 tls /* $OpenBSD: siop_gsc.c,v 1.1 1998/11/04 17:01:35 mickey Exp $ */
54 1.1.10.2 tls
55 1.1.10.2 tls /*
56 1.1.10.2 tls * Copyright (c) 1998 Michael Shalayeff
57 1.1.10.2 tls * All rights reserved.
58 1.1.10.2 tls *
59 1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
60 1.1.10.2 tls * modification, are permitted provided that the following conditions
61 1.1.10.2 tls * are met:
62 1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
63 1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
64 1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
65 1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
66 1.1.10.2 tls * documentation and/or other materials provided with the distribution.
67 1.1.10.2 tls * 3. The name of the author may not be used to endorse or promote products
68 1.1.10.2 tls * derived from this software without specific prior written permission.
69 1.1.10.2 tls *
70 1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
71 1.1.10.2 tls * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
72 1.1.10.2 tls * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
73 1.1.10.2 tls * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
74 1.1.10.2 tls * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
75 1.1.10.2 tls * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
76 1.1.10.2 tls * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
77 1.1.10.2 tls * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
78 1.1.10.2 tls * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
79 1.1.10.2 tls * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80 1.1.10.2 tls */
81 1.1.10.2 tls
82 1.1.10.2 tls #include <sys/cdefs.h>
83 1.1.10.2 tls __KERNEL_RCSID(0, "$NetBSD: oosiop_gsc.c,v 1.1.10.2 2014/08/20 00:03:04 tls Exp $");
84 1.1.10.2 tls
85 1.1.10.2 tls #include <sys/param.h>
86 1.1.10.2 tls #include <sys/systm.h>
87 1.1.10.2 tls #include <sys/device.h>
88 1.1.10.2 tls #include <sys/buf.h>
89 1.1.10.2 tls #include <sys/malloc.h>
90 1.1.10.2 tls
91 1.1.10.2 tls #include <dev/scsipi/scsi_all.h>
92 1.1.10.2 tls #include <dev/scsipi/scsipi_all.h>
93 1.1.10.2 tls #include <dev/scsipi/scsiconf.h>
94 1.1.10.2 tls
95 1.1.10.2 tls #include <machine/cpu.h>
96 1.1.10.2 tls #include <machine/intr.h>
97 1.1.10.2 tls #include <machine/iomod.h>
98 1.1.10.2 tls #include <machine/autoconf.h>
99 1.1.10.2 tls #include <sys/bus.h>
100 1.1.10.2 tls
101 1.1.10.2 tls #include <dev/ic/oosiopreg.h>
102 1.1.10.2 tls #include <dev/ic/oosiopvar.h>
103 1.1.10.2 tls
104 1.1.10.2 tls #include <hppa/dev/cpudevs.h>
105 1.1.10.2 tls #include <hppa/gsc/gscbusvar.h>
106 1.1.10.2 tls #include <hppa/hppa/machdep.h>
107 1.1.10.2 tls
108 1.1.10.2 tls #define OOSIOP_GSC_RESET 0x0000
109 1.1.10.2 tls #define OOSIOP_GSC_OFFSET 0x0100
110 1.1.10.2 tls
111 1.1.10.2 tls int oosiop_gsc_match(device_t, cfdata_t, void *);
112 1.1.10.2 tls void oosiop_gsc_attach(device_t, device_t, void *);
113 1.1.10.2 tls int oosiop_gsc_intr(void *);
114 1.1.10.2 tls
115 1.1.10.2 tls CFATTACH_DECL_NEW(oosiop_gsc, sizeof(struct oosiop_softc),
116 1.1.10.2 tls oosiop_gsc_match, oosiop_gsc_attach, NULL, NULL);
117 1.1.10.2 tls
118 1.1.10.2 tls int
119 1.1.10.2 tls oosiop_gsc_match(device_t parent, cfdata_t cf, void *aux)
120 1.1.10.2 tls {
121 1.1.10.2 tls struct gsc_attach_args *ga = aux;
122 1.1.10.2 tls bus_space_handle_t ioh;
123 1.1.10.2 tls int rv = 1;
124 1.1.10.2 tls
125 1.1.10.2 tls if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
126 1.1.10.2 tls ga->ga_type.iodc_sv_model != HPPA_FIO_SCSI)
127 1.1.10.2 tls return 0;
128 1.1.10.2 tls
129 1.1.10.2 tls if (bus_space_map(ga->ga_iot, ga->ga_hpa,
130 1.1.10.2 tls OOSIOP_GSC_OFFSET + OOSIOP_NREGS, 0, &ioh))
131 1.1.10.2 tls return 0;
132 1.1.10.2 tls
133 1.1.10.2 tls
134 1.1.10.2 tls bus_space_unmap(ga->ga_iot, ioh, OOSIOP_GSC_OFFSET + OOSIOP_NREGS);
135 1.1.10.2 tls return rv;
136 1.1.10.2 tls }
137 1.1.10.2 tls
138 1.1.10.2 tls void
139 1.1.10.2 tls oosiop_gsc_attach(device_t parent, device_t self, void *aux)
140 1.1.10.2 tls {
141 1.1.10.2 tls struct oosiop_softc *sc = device_private(self);
142 1.1.10.2 tls struct gsc_attach_args *ga = aux;
143 1.1.10.2 tls bus_space_handle_t ioh;
144 1.1.10.2 tls
145 1.1.10.2 tls sc->sc_dev = self;
146 1.1.10.2 tls sc->sc_bst = ga->ga_iot;
147 1.1.10.2 tls sc->sc_dmat = ga->ga_dmatag;
148 1.1.10.2 tls if (bus_space_map(sc->sc_bst, ga->ga_hpa,
149 1.1.10.2 tls OOSIOP_GSC_OFFSET + OOSIOP_NREGS, 0, &ioh)) {
150 1.1.10.2 tls aprint_error(": couldn't map I/O ports\n");
151 1.1.10.2 tls return;
152 1.1.10.2 tls }
153 1.1.10.2 tls if (bus_space_subregion(sc->sc_bst, ioh,
154 1.1.10.2 tls OOSIOP_GSC_OFFSET, OOSIOP_NREGS, &sc->sc_bsh)) {
155 1.1.10.2 tls aprint_error(": couldn't get chip ports\n");
156 1.1.10.2 tls return;
157 1.1.10.2 tls }
158 1.1.10.2 tls
159 1.1.10.2 tls sc->sc_freq = ga->ga_ca.ca_pir.filler2[14];
160 1.1.10.2 tls if (sc->sc_freq == 0)
161 1.1.10.2 tls sc->sc_freq = 50000000;
162 1.1.10.2 tls
163 1.1.10.2 tls sc->sc_chip = OOSIOP_700;
164 1.1.10.2 tls sc->sc_id = ga->ga_scsi_target;
165 1.1.10.2 tls
166 1.1.10.2 tls /*
167 1.1.10.2 tls * Reset SCSI subsystem.
168 1.1.10.2 tls */
169 1.1.10.2 tls bus_space_write_1(sc->sc_bst, ioh, OOSIOP_GSC_RESET, 0);
170 1.1.10.2 tls DELAY(1000);
171 1.1.10.2 tls
172 1.1.10.2 tls /*
173 1.1.10.2 tls * Call common attachment
174 1.1.10.2 tls */
175 1.1.10.2 tls oosiop_attach(sc);
176 1.1.10.2 tls
177 1.1.10.2 tls (void)hppa_intr_establish(IPL_BIO, oosiop_gsc_intr, sc,
178 1.1.10.2 tls ga->ga_ir, ga->ga_irq);
179 1.1.10.2 tls }
180 1.1.10.2 tls
181 1.1.10.2 tls /*
182 1.1.10.2 tls * interrupt handler
183 1.1.10.2 tls */
184 1.1.10.2 tls int
185 1.1.10.2 tls oosiop_gsc_intr(void *arg)
186 1.1.10.2 tls {
187 1.1.10.2 tls struct oosiop_softc *sc = arg;
188 1.1.10.2 tls int rv;
189 1.1.10.2 tls
190 1.1.10.2 tls rv = oosiop_intr(sc);
191 1.1.10.2 tls
192 1.1.10.2 tls /* Blink the LED. */
193 1.1.10.2 tls hppa_led_blink(HPPA_LED_DISK);
194 1.1.10.2 tls
195 1.1.10.2 tls return rv;
196 1.1.10.2 tls }
197