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