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