1 /* $NetBSD: osiop_gsc.c,v 1.1 2014/02/24 07:23:43 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: osiop_gsc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $"); 84 85 #include <sys/param.h> 86 #include <sys/systm.h> 87 #include <sys/device.h> 88 #include <sys/buf.h> 89 #include <sys/malloc.h> 90 91 #include <dev/scsipi/scsi_all.h> 92 #include <dev/scsipi/scsipi_all.h> 93 #include <dev/scsipi/scsiconf.h> 94 95 #include <machine/cpu.h> 96 #include <machine/intr.h> 97 #include <machine/iomod.h> 98 #include <machine/autoconf.h> 99 #include <sys/bus.h> 100 101 #include <dev/ic/osiopreg.h> 102 #include <dev/ic/osiopvar.h> 103 104 #include <hppa/dev/cpudevs.h> 105 #include <hppa/gsc/gscbusvar.h> 106 #include <hppa/hppa/machdep.h> 107 108 #define OSIOP_GSC_RESET 0x0000 109 #define OSIOP_GSC_OFFSET 0x0100 110 111 int osiop_gsc_match(device_t, cfdata_t, void *); 112 void osiop_gsc_attach(device_t, device_t, void *); 113 int osiop_gsc_intr(void *); 114 115 CFATTACH_DECL_NEW(osiop_gsc, sizeof(struct osiop_softc), 116 osiop_gsc_match, osiop_gsc_attach, NULL, NULL); 117 118 int 119 osiop_gsc_match(device_t parent, cfdata_t cf, void *aux) 120 { 121 struct gsc_attach_args *ga = aux; 122 bus_space_handle_t ioh; 123 int rv = 1; 124 125 if (ga->ga_type.iodc_type != HPPA_TYPE_FIO || 126 (ga->ga_type.iodc_sv_model != HPPA_FIO_GSCSI)) 127 return 0; 128 129 if (bus_space_map(ga->ga_iot, ga->ga_hpa, 130 OSIOP_GSC_OFFSET + OSIOP_NREGS, 0, &ioh)) 131 return 0; 132 133 134 bus_space_unmap(ga->ga_iot, ioh, OSIOP_GSC_OFFSET + OSIOP_NREGS); 135 return rv; 136 } 137 138 void 139 osiop_gsc_attach(device_t parent, device_t self, void *aux) 140 { 141 struct osiop_softc *sc = device_private(self); 142 struct gsc_attach_args *ga = aux; 143 bus_space_handle_t ioh; 144 145 sc->sc_dev = self; 146 sc->sc_bst = ga->ga_iot; 147 sc->sc_dmat = ga->ga_dmatag; 148 if (bus_space_map(sc->sc_bst, ga->ga_hpa, 149 OSIOP_GSC_OFFSET + OSIOP_NREGS, 0, &ioh)) { 150 aprint_error(": couldn't map I/O ports\n"); 151 return; 152 } 153 if (bus_space_subregion(sc->sc_bst, ioh, 154 OSIOP_GSC_OFFSET, OSIOP_NREGS, &sc->sc_reg)) { 155 aprint_error(": couldn't get chip ports\n"); 156 return; 157 } 158 159 sc->sc_clock_freq = ga->ga_ca.ca_pir.filler2[14] / 1000000; 160 if (!sc->sc_clock_freq) 161 sc->sc_clock_freq = 50; 162 163 sc->sc_ctest7 = 0; /* | OSIOP_CTEST7_TT1 */ 164 sc->sc_dcntl = OSIOP_DCNTL_EA; 165 166 sc->sc_flags = 0; 167 sc->sc_id = ga->ga_scsi_target; 168 169 /* 170 * Reset the SCSI subsystem. 171 */ 172 bus_space_write_1(sc->sc_bst, ioh, OSIOP_GSC_RESET, 0); 173 DELAY(1000); 174 175 /* 176 * Call common attachment 177 */ 178 #ifdef OSIOP_DEBUG 179 { 180 extern int osiop_debug; 181 osiop_debug = -1; 182 } 183 #endif /* OSIOP_DEBUG */ 184 osiop_attach(sc); 185 186 (void)hppa_intr_establish(IPL_BIO, osiop_gsc_intr, sc, ga->ga_ir, 187 ga->ga_irq); 188 } 189 190 /* 191 * interrupt handler 192 */ 193 int 194 osiop_gsc_intr(void *arg) 195 { 196 struct osiop_softc *sc = arg; 197 uint8_t istat; 198 199 /* This is potentially nasty, since the IRQ is level triggered... */ 200 if (sc->sc_flags & OSIOP_INTSOFF) 201 return (0); 202 203 istat = osiop_read_1(sc, OSIOP_ISTAT); 204 205 if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0) 206 return (0); 207 208 /* Save interrupt details for the back-end interrupt handler */ 209 sc->sc_sstat0 = osiop_read_1(sc, OSIOP_SSTAT0); 210 sc->sc_istat = istat; 211 /* 212 * Per page 4-18 of the LSI 53C710 Technical Manual, 213 * "insert a delay equivalent to 12 BCLK periods between 214 * the reads [of DSTAT and SSTAT0] to ensure that the 215 * interrupts clear properly." 216 */ 217 DELAY(100); 218 sc->sc_dstat = osiop_read_1(sc, OSIOP_DSTAT); 219 220 /* Deal with the interrupt */ 221 osiop_intr(sc); 222 223 /* Blink the LED. */ 224 hppa_led_blink(HPPA_LED_DISK); 225 226 return (1); 227 } 228