Home | History | Annotate | Line # | Download | only in gsc
osiop_gsc.c revision 1.1.4.2
      1  1.1.4.2  rmind /*	$NetBSD: osiop_gsc.c,v 1.1.4.2 2014/05/18 17:45:11 rmind Exp $	*/
      2  1.1.4.2  rmind 
      3  1.1.4.2  rmind /*
      4  1.1.4.2  rmind  * Copyright (c) 2001 Matt Fredette.  All rights reserved.
      5  1.1.4.2  rmind  *
      6  1.1.4.2  rmind  * Redistribution and use in source and binary forms, with or without
      7  1.1.4.2  rmind  * modification, are permitted provided that the following conditions
      8  1.1.4.2  rmind  * are met:
      9  1.1.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     10  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer.
     11  1.1.4.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     13  1.1.4.2  rmind  *    documentation and/or other materials provided with the distribution.
     14  1.1.4.2  rmind  * 3. The name of the author may not be used to endorse or promote products
     15  1.1.4.2  rmind  *    derived from this software without specific prior written permission.
     16  1.1.4.2  rmind  *
     17  1.1.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     18  1.1.4.2  rmind  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  1.1.4.2  rmind  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  1.1.4.2  rmind  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  1.1.4.2  rmind  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  1.1.4.2  rmind  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  1.1.4.2  rmind  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  1.1.4.2  rmind  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  1.1.4.2  rmind  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  1.1.4.2  rmind  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  1.1.4.2  rmind  */
     28  1.1.4.2  rmind 
     29  1.1.4.2  rmind /*-
     30  1.1.4.2  rmind  * Copyright (c) 2001, 2002 Izumi Tsutsui.  All rights reserved.
     31  1.1.4.2  rmind  *
     32  1.1.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     33  1.1.4.2  rmind  * modification, are permitted provided that the following conditions
     34  1.1.4.2  rmind  * are met:
     35  1.1.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     36  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer.
     37  1.1.4.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     38  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     39  1.1.4.2  rmind  *    documentation and/or other materials provided with the distribution.
     40  1.1.4.2  rmind  *
     41  1.1.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     42  1.1.4.2  rmind  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     43  1.1.4.2  rmind  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     44  1.1.4.2  rmind  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     45  1.1.4.2  rmind  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     46  1.1.4.2  rmind  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     47  1.1.4.2  rmind  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     48  1.1.4.2  rmind  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     49  1.1.4.2  rmind  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     50  1.1.4.2  rmind  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     51  1.1.4.2  rmind  */
     52  1.1.4.2  rmind 
     53  1.1.4.2  rmind /*	$OpenBSD: siop_gsc.c,v 1.1 1998/11/04 17:01:35 mickey Exp $	*/
     54  1.1.4.2  rmind 
     55  1.1.4.2  rmind /*
     56  1.1.4.2  rmind  * Copyright (c) 1998 Michael Shalayeff
     57  1.1.4.2  rmind  * All rights reserved.
     58  1.1.4.2  rmind  *
     59  1.1.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     60  1.1.4.2  rmind  * modification, are permitted provided that the following conditions
     61  1.1.4.2  rmind  * are met:
     62  1.1.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     63  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer.
     64  1.1.4.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     65  1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     66  1.1.4.2  rmind  *    documentation and/or other materials provided with the distribution.
     67  1.1.4.2  rmind  * 3. The name of the author may not be used to endorse or promote products
     68  1.1.4.2  rmind  *    derived from this software without specific prior written permission.
     69  1.1.4.2  rmind  *
     70  1.1.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     71  1.1.4.2  rmind  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     72  1.1.4.2  rmind  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     73  1.1.4.2  rmind  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     74  1.1.4.2  rmind  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     75  1.1.4.2  rmind  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     76  1.1.4.2  rmind  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     77  1.1.4.2  rmind  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     78  1.1.4.2  rmind  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     79  1.1.4.2  rmind  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     80  1.1.4.2  rmind  */
     81  1.1.4.2  rmind 
     82  1.1.4.2  rmind #include <sys/cdefs.h>
     83  1.1.4.2  rmind __KERNEL_RCSID(0, "$NetBSD: osiop_gsc.c,v 1.1.4.2 2014/05/18 17:45:11 rmind Exp $");
     84  1.1.4.2  rmind 
     85  1.1.4.2  rmind #include <sys/param.h>
     86  1.1.4.2  rmind #include <sys/systm.h>
     87  1.1.4.2  rmind #include <sys/device.h>
     88  1.1.4.2  rmind #include <sys/buf.h>
     89  1.1.4.2  rmind #include <sys/malloc.h>
     90  1.1.4.2  rmind 
     91  1.1.4.2  rmind #include <dev/scsipi/scsi_all.h>
     92  1.1.4.2  rmind #include <dev/scsipi/scsipi_all.h>
     93  1.1.4.2  rmind #include <dev/scsipi/scsiconf.h>
     94  1.1.4.2  rmind 
     95  1.1.4.2  rmind #include <machine/cpu.h>
     96  1.1.4.2  rmind #include <machine/intr.h>
     97  1.1.4.2  rmind #include <machine/iomod.h>
     98  1.1.4.2  rmind #include <machine/autoconf.h>
     99  1.1.4.2  rmind #include <sys/bus.h>
    100  1.1.4.2  rmind 
    101  1.1.4.2  rmind #include <dev/ic/osiopreg.h>
    102  1.1.4.2  rmind #include <dev/ic/osiopvar.h>
    103  1.1.4.2  rmind 
    104  1.1.4.2  rmind #include <hppa/dev/cpudevs.h>
    105  1.1.4.2  rmind #include <hppa/gsc/gscbusvar.h>
    106  1.1.4.2  rmind #include <hppa/hppa/machdep.h>
    107  1.1.4.2  rmind 
    108  1.1.4.2  rmind #define OSIOP_GSC_RESET         0x0000
    109  1.1.4.2  rmind #define	OSIOP_GSC_OFFSET	0x0100
    110  1.1.4.2  rmind 
    111  1.1.4.2  rmind int osiop_gsc_match(device_t, cfdata_t, void *);
    112  1.1.4.2  rmind void osiop_gsc_attach(device_t, device_t, void *);
    113  1.1.4.2  rmind int osiop_gsc_intr(void *);
    114  1.1.4.2  rmind 
    115  1.1.4.2  rmind CFATTACH_DECL_NEW(osiop_gsc, sizeof(struct osiop_softc),
    116  1.1.4.2  rmind     osiop_gsc_match, osiop_gsc_attach, NULL, NULL);
    117  1.1.4.2  rmind 
    118  1.1.4.2  rmind int
    119  1.1.4.2  rmind osiop_gsc_match(device_t parent, cfdata_t cf, void *aux)
    120  1.1.4.2  rmind {
    121  1.1.4.2  rmind 	struct gsc_attach_args *ga = aux;
    122  1.1.4.2  rmind 	bus_space_handle_t ioh;
    123  1.1.4.2  rmind 	int rv = 1;
    124  1.1.4.2  rmind 
    125  1.1.4.2  rmind 	if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
    126  1.1.4.2  rmind 	    (ga->ga_type.iodc_sv_model != HPPA_FIO_GSCSI))
    127  1.1.4.2  rmind 		return 0;
    128  1.1.4.2  rmind 
    129  1.1.4.2  rmind 	if (bus_space_map(ga->ga_iot, ga->ga_hpa,
    130  1.1.4.2  rmind 	    OSIOP_GSC_OFFSET + OSIOP_NREGS, 0, &ioh))
    131  1.1.4.2  rmind 		return 0;
    132  1.1.4.2  rmind 
    133  1.1.4.2  rmind 
    134  1.1.4.2  rmind 	bus_space_unmap(ga->ga_iot, ioh, OSIOP_GSC_OFFSET + OSIOP_NREGS);
    135  1.1.4.2  rmind 	return rv;
    136  1.1.4.2  rmind }
    137  1.1.4.2  rmind 
    138  1.1.4.2  rmind void
    139  1.1.4.2  rmind osiop_gsc_attach(device_t parent, device_t self, void *aux)
    140  1.1.4.2  rmind {
    141  1.1.4.2  rmind 	struct osiop_softc *sc = device_private(self);
    142  1.1.4.2  rmind 	struct gsc_attach_args *ga = aux;
    143  1.1.4.2  rmind 	bus_space_handle_t ioh;
    144  1.1.4.2  rmind 
    145  1.1.4.2  rmind 	sc->sc_dev = self;
    146  1.1.4.2  rmind 	sc->sc_bst = ga->ga_iot;
    147  1.1.4.2  rmind 	sc->sc_dmat = ga->ga_dmatag;
    148  1.1.4.2  rmind 	if (bus_space_map(sc->sc_bst, ga->ga_hpa,
    149  1.1.4.2  rmind 	    OSIOP_GSC_OFFSET + OSIOP_NREGS, 0, &ioh)) {
    150  1.1.4.2  rmind 		aprint_error(": couldn't map I/O ports\n");
    151  1.1.4.2  rmind 		return;
    152  1.1.4.2  rmind 	}
    153  1.1.4.2  rmind 	if (bus_space_subregion(sc->sc_bst, ioh,
    154  1.1.4.2  rmind 	    OSIOP_GSC_OFFSET, OSIOP_NREGS, &sc->sc_reg)) {
    155  1.1.4.2  rmind 		aprint_error(": couldn't get chip ports\n");
    156  1.1.4.2  rmind 		return;
    157  1.1.4.2  rmind 	}
    158  1.1.4.2  rmind 
    159  1.1.4.2  rmind 	sc->sc_clock_freq = ga->ga_ca.ca_pir.filler2[14] / 1000000;
    160  1.1.4.2  rmind 	if (!sc->sc_clock_freq)
    161  1.1.4.2  rmind 		sc->sc_clock_freq = 50;
    162  1.1.4.2  rmind 
    163  1.1.4.2  rmind 	sc->sc_ctest7 = 0; /* | OSIOP_CTEST7_TT1 */
    164  1.1.4.2  rmind 	sc->sc_dcntl = OSIOP_DCNTL_EA;
    165  1.1.4.2  rmind 
    166  1.1.4.2  rmind 	sc->sc_flags = 0;
    167  1.1.4.2  rmind 	sc->sc_id = ga->ga_scsi_target;
    168  1.1.4.2  rmind 
    169  1.1.4.2  rmind 	/*
    170  1.1.4.2  rmind 	 * Reset the SCSI subsystem.
    171  1.1.4.2  rmind 	 */
    172  1.1.4.2  rmind 	bus_space_write_1(sc->sc_bst, ioh, OSIOP_GSC_RESET, 0);
    173  1.1.4.2  rmind 	DELAY(1000);
    174  1.1.4.2  rmind 
    175  1.1.4.2  rmind 	/*
    176  1.1.4.2  rmind 	 * Call common attachment
    177  1.1.4.2  rmind 	 */
    178  1.1.4.2  rmind #ifdef OSIOP_DEBUG
    179  1.1.4.2  rmind 	{
    180  1.1.4.2  rmind 		extern int osiop_debug;
    181  1.1.4.2  rmind 		osiop_debug = -1;
    182  1.1.4.2  rmind 	}
    183  1.1.4.2  rmind #endif /* OSIOP_DEBUG */
    184  1.1.4.2  rmind 	osiop_attach(sc);
    185  1.1.4.2  rmind 
    186  1.1.4.2  rmind 	(void)hppa_intr_establish(IPL_BIO, osiop_gsc_intr, sc, ga->ga_ir,
    187  1.1.4.2  rmind 	    ga->ga_irq);
    188  1.1.4.2  rmind }
    189  1.1.4.2  rmind 
    190  1.1.4.2  rmind /*
    191  1.1.4.2  rmind  * interrupt handler
    192  1.1.4.2  rmind  */
    193  1.1.4.2  rmind int
    194  1.1.4.2  rmind osiop_gsc_intr(void *arg)
    195  1.1.4.2  rmind {
    196  1.1.4.2  rmind 	struct osiop_softc *sc = arg;
    197  1.1.4.2  rmind 	uint8_t istat;
    198  1.1.4.2  rmind 
    199  1.1.4.2  rmind 	/* This is potentially nasty, since the IRQ is level triggered... */
    200  1.1.4.2  rmind 	if (sc->sc_flags & OSIOP_INTSOFF)
    201  1.1.4.2  rmind 		return (0);
    202  1.1.4.2  rmind 
    203  1.1.4.2  rmind 	istat = osiop_read_1(sc, OSIOP_ISTAT);
    204  1.1.4.2  rmind 
    205  1.1.4.2  rmind 	if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0)
    206  1.1.4.2  rmind 		return (0);
    207  1.1.4.2  rmind 
    208  1.1.4.2  rmind 	/* Save interrupt details for the back-end interrupt handler */
    209  1.1.4.2  rmind 	sc->sc_sstat0 = osiop_read_1(sc, OSIOP_SSTAT0);
    210  1.1.4.2  rmind 	sc->sc_istat = istat;
    211  1.1.4.2  rmind 	/*
    212  1.1.4.2  rmind 	 * Per page 4-18 of the LSI 53C710 Technical Manual,
    213  1.1.4.2  rmind 	 * "insert a delay equivalent to 12 BCLK periods between
    214  1.1.4.2  rmind 	 * the reads [of DSTAT and SSTAT0] to ensure that the
    215  1.1.4.2  rmind 	 * interrupts clear properly."
    216  1.1.4.2  rmind 	 */
    217  1.1.4.2  rmind 	DELAY(100);
    218  1.1.4.2  rmind 	sc->sc_dstat = osiop_read_1(sc, OSIOP_DSTAT);
    219  1.1.4.2  rmind 
    220  1.1.4.2  rmind 	/* Deal with the interrupt */
    221  1.1.4.2  rmind 	osiop_intr(sc);
    222  1.1.4.2  rmind 
    223  1.1.4.2  rmind 	/* Blink the LED. */
    224  1.1.4.2  rmind 	hppa_led_blink(HPPA_LED_DISK);
    225  1.1.4.2  rmind 
    226  1.1.4.2  rmind 	return (1);
    227  1.1.4.2  rmind }
    228