Home | History | Annotate | Line # | Download | only in dev
sc_mbmem.c revision 1.11.66.2
      1  1.11.66.2      yamt /*	$NetBSD: sc_mbmem.c,v 1.11.66.2 2009/05/04 08:11:59 yamt Exp $	*/
      2        1.1  fredette 
      3        1.1  fredette /*-
      4        1.1  fredette  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5        1.1  fredette  * All rights reserved.
      6        1.1  fredette  *
      7        1.1  fredette  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1  fredette  * by Adam Glass, David Jones, Gordon W. Ross, and Matthew Fredette.
      9        1.1  fredette  *
     10        1.1  fredette  * Redistribution and use in source and binary forms, with or without
     11        1.1  fredette  * modification, are permitted provided that the following conditions
     12        1.1  fredette  * are met:
     13        1.1  fredette  * 1. Redistributions of source code must retain the above copyright
     14        1.1  fredette  *    notice, this list of conditions and the following disclaimer.
     15        1.1  fredette  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1  fredette  *    notice, this list of conditions and the following disclaimer in the
     17        1.1  fredette  *    documentation and/or other materials provided with the distribution.
     18        1.1  fredette  *
     19        1.1  fredette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1  fredette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1  fredette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1  fredette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1  fredette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1  fredette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1  fredette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1  fredette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1  fredette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1  fredette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1  fredette  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1  fredette  */
     31        1.1  fredette 
     32        1.1  fredette /*
     33        1.1  fredette  * This file contains only the machine-dependent parts of the
     34        1.1  fredette  * Sun-2 SCSI driver.  (Autoconfig stuff and DMA functions.)
     35        1.1  fredette  * The machine-independent parts are in sunscpal.c
     36        1.1  fredette  *
     37        1.1  fredette  * Supported hardware includes:
     38        1.1  fredette  * Sun SCSI-2 on Multibus (Sun2/120,Sun2/170)
     39        1.1  fredette  * Sun SCSI-2 on VME (Sun2/50,Sun3/160,Sun3/260,others?)
     40        1.1  fredette  *
     41        1.1  fredette  * Credits, history:
     42        1.1  fredette  *
     43        1.1  fredette  * Matthew Fredette took revision 1.15 of si_vme.c, and then heavily
     44        1.1  fredette  * modified it to support the Sun sc.  The remaining credits
     45        1.1  fredette  * are from si_vme.c:
     46        1.1  fredette  *
     47        1.1  fredette  * David Jones wrote the initial version of this module, which
     48        1.1  fredette  * included support for the VME adapter only. (no reselection).
     49        1.1  fredette  *
     50        1.1  fredette  * Gordon Ross added support for the OBIO adapter, and re-worked
     51        1.1  fredette  * both the VME and OBIO code to support disconnect/reselect.
     52        1.1  fredette  * (Required figuring out the hardware "features" noted above.)
     53        1.1  fredette  *
     54        1.1  fredette  * The autoconfiguration boilerplate came from Adam Glass.
     55        1.1  fredette  */
     56        1.1  fredette 
     57        1.1  fredette /*****************************************************************
     58        1.1  fredette  * Multibus functions for sc
     59        1.1  fredette  ****************************************************************/
     60        1.8     lukem 
     61        1.8     lukem #include <sys/cdefs.h>
     62  1.11.66.2      yamt __KERNEL_RCSID(0, "$NetBSD: sc_mbmem.c,v 1.11.66.2 2009/05/04 08:11:59 yamt Exp $");
     63        1.1  fredette 
     64        1.1  fredette #include <sys/param.h>
     65        1.1  fredette #include <sys/systm.h>
     66        1.1  fredette #include <sys/errno.h>
     67        1.1  fredette #include <sys/kernel.h>
     68        1.1  fredette #include <sys/malloc.h>
     69        1.1  fredette #include <sys/device.h>
     70        1.1  fredette #include <sys/buf.h>
     71        1.1  fredette #include <sys/proc.h>
     72        1.1  fredette #include <sys/user.h>
     73        1.1  fredette 
     74        1.1  fredette #include <dev/scsipi/scsi_all.h>
     75        1.1  fredette #include <dev/scsipi/scsipi_all.h>
     76        1.1  fredette #include <dev/scsipi/scsipi_debug.h>
     77        1.1  fredette #include <dev/scsipi/scsiconf.h>
     78        1.1  fredette 
     79        1.1  fredette #include <machine/autoconf.h>
     80        1.1  fredette #include <machine/bus.h>
     81        1.1  fredette 
     82        1.1  fredette /* #define DEBUG XXX */
     83        1.1  fredette 
     84        1.1  fredette #include <dev/ic/sunscpalreg.h>
     85        1.1  fredette #include <dev/ic/sunscpalvar.h>
     86        1.1  fredette 
     87        1.2  fredette /* Yes, we use a VME header file. */
     88        1.2  fredette #include <dev/vme/screg.h>
     89        1.1  fredette 
     90        1.1  fredette /*
     91        1.1  fredette  * Transfers smaller than this are done using PIO
     92        1.1  fredette  * (on assumption they're not worth DMA overhead)
     93        1.1  fredette  */
     94        1.1  fredette #define	MIN_DMA_LEN 128
     95        1.1  fredette 
     96        1.1  fredette /*
     97        1.1  fredette  * New-style autoconfig attachment
     98        1.1  fredette  */
     99        1.1  fredette 
    100  1.11.66.2      yamt static int	sunsc_mbmem_match(device_t, cfdata_t, void *);
    101  1.11.66.2      yamt static void	sunsc_mbmem_attach(device_t, device_t, void *);
    102        1.9       chs static int	sunsc_mbmem_intr(void *);
    103        1.1  fredette 
    104  1.11.66.2      yamt CFATTACH_DECL_NEW(sc_mbmem, sizeof(struct sunscpal_softc),
    105        1.6   thorpej     sunsc_mbmem_match, sunsc_mbmem_attach, NULL, NULL);
    106        1.1  fredette 
    107        1.1  fredette /*
    108        1.1  fredette  * Options for parity, DMA, and interrupts.
    109        1.1  fredette  */
    110        1.1  fredette int sunsc_mbmem_options = 0x00;
    111        1.1  fredette 
    112        1.9       chs static int
    113  1.11.66.2      yamt sunsc_mbmem_match(device_t parent, cfdata_t cf, void *aux)
    114        1.1  fredette {
    115        1.2  fredette 	struct mbmem_attach_args *mbma = aux;
    116        1.2  fredette 	bus_space_handle_t bh;
    117  1.11.66.2      yamt 	bool matched;
    118        1.1  fredette 
    119        1.1  fredette 	/* No default Multibus address. */
    120        1.2  fredette 	if (mbma->mbma_paddr == -1)
    121  1.11.66.2      yamt 		return 0;
    122        1.1  fredette 
    123        1.2  fredette 	/* Make sure there is something there... */
    124        1.2  fredette 	if (bus_space_map(mbma->mbma_bustag, mbma->mbma_paddr, SCREG_BANK_SZ,
    125  1.11.66.2      yamt 	    0, &bh))
    126  1.11.66.2      yamt 		return 0;
    127  1.11.66.2      yamt 	matched =
    128  1.11.66.2      yamt 	    (bus_space_peek_2(mbma->mbma_bustag, bh, SCREG_ICR, NULL) == 0);
    129        1.2  fredette 	bus_space_unmap(mbma->mbma_bustag, bh, SCREG_BANK_SZ);
    130        1.2  fredette 	if (!matched)
    131  1.11.66.2      yamt 		return 0;
    132        1.1  fredette 
    133        1.1  fredette 	/* Default interrupt priority. */
    134        1.2  fredette 	if (mbma->mbma_pri == -1)
    135        1.2  fredette 		mbma->mbma_pri = 2;
    136        1.1  fredette 
    137  1.11.66.2      yamt 	return 1;
    138        1.1  fredette }
    139        1.1  fredette 
    140        1.9       chs static void
    141  1.11.66.2      yamt sunsc_mbmem_attach(device_t parent, device_t self, void *args)
    142        1.1  fredette {
    143  1.11.66.2      yamt 	struct sunscpal_softc *sc = device_private(self);
    144       1.11   thorpej 	struct cfdata *cf = device_cfdata(self);
    145        1.2  fredette 	struct mbmem_attach_args *mbma = args;
    146        1.2  fredette 	int i;
    147        1.1  fredette 
    148  1.11.66.2      yamt 	sc->sc_dev = self;
    149  1.11.66.2      yamt 
    150        1.1  fredette 	/* Map in the device. */
    151        1.2  fredette 	sc->sunscpal_regt = mbma->mbma_bustag;
    152        1.2  fredette 	sc->sunscpal_dmat = mbma->mbma_dmatag;
    153        1.2  fredette 	if (bus_space_map(mbma->mbma_bustag, mbma->mbma_paddr, SCREG_BANK_SZ,
    154  1.11.66.2      yamt 	    0, &sc->sunscpal_regh))
    155  1.11.66.2      yamt 		panic("%s: can't map", __func__);
    156        1.1  fredette 
    157        1.1  fredette 	/* Device register offsets. */
    158        1.2  fredette 	sc->sunscpal_data = SCREG_DATA;
    159        1.2  fredette 	sc->sunscpal_cmd_stat = SCREG_CMD_STAT;
    160        1.2  fredette 	sc->sunscpal_icr = SCREG_ICR;
    161        1.2  fredette 	sc->sunscpal_dma_addr_h = SCREG_DMA_ADDR_H;
    162        1.2  fredette 	sc->sunscpal_dma_addr_l = SCREG_DMA_ADDR_L;
    163        1.2  fredette 	sc->sunscpal_dma_count = SCREG_DMA_COUNT;
    164        1.2  fredette 	sc->sunscpal_intvec = SCREG_INTVEC;
    165        1.1  fredette 
    166        1.2  fredette 	/* Allocate DMA handles. */
    167        1.2  fredette 	i = SUNSCPAL_OPENINGS * sizeof(struct sunscpal_dma_handle);
    168  1.11.66.2      yamt 	sc->sc_dma_handles = malloc(i, M_DEVBUF, M_WAITOK);
    169        1.2  fredette 	if (sc->sc_dma_handles == NULL)
    170        1.7       wiz 		panic("sc: DMA handles malloc failed");
    171        1.2  fredette 	for (i = 0; i < SUNSCPAL_OPENINGS; i++)
    172        1.2  fredette 		if (bus_dmamap_create(sc->sunscpal_dmat, SUNSCPAL_MAX_DMA_LEN,
    173  1.11.66.2      yamt 		    1, SUNSCPAL_MAX_DMA_LEN,
    174  1.11.66.2      yamt 		    0, BUS_DMA_WAITOK, &sc->sc_dma_handles[i].dh_dmamap) != 0)
    175        1.7       wiz 			panic("sc: DMA map create failed");
    176        1.2  fredette 
    177        1.1  fredette 	/* Miscellaneous. */
    178        1.1  fredette 	sc->sc_min_dma_len = MIN_DMA_LEN;
    179        1.1  fredette 	sc->sc_rev = SUNSCPAL_VARIANT_501_1006;
    180        1.1  fredette 
    181        1.1  fredette 	/* Attach interrupt handler. */
    182        1.2  fredette 	bus_intr_establish(mbma->mbma_bustag, mbma->mbma_pri, IPL_BIO, 0,
    183  1.11.66.2      yamt 	    sunsc_mbmem_intr, sc);
    184        1.1  fredette 
    185        1.1  fredette 	/* Do the common attach stuff. */
    186  1.11.66.2      yamt 	sunscpal_attach(sc, cf->cf_flags ? cf->cf_flags : sunsc_mbmem_options);
    187        1.1  fredette }
    188        1.1  fredette 
    189        1.1  fredette static int
    190        1.1  fredette sunsc_mbmem_intr(void *arg)
    191        1.1  fredette {
    192        1.1  fredette 	struct sunscpal_softc *sc = arg;
    193        1.1  fredette 	int claimed;
    194        1.1  fredette 
    195        1.1  fredette 	claimed = sunscpal_intr(sc);
    196        1.1  fredette #ifdef	DEBUG
    197  1.11.66.2      yamt 	if (claimed == 0) {
    198  1.11.66.2      yamt 		printf("%s: spurious from SBC\n", __func__);
    199        1.1  fredette 	}
    200        1.1  fredette #endif
    201        1.1  fredette 	/* Yes, we DID cause this interrupt. */
    202        1.1  fredette 	claimed = 1;
    203        1.1  fredette 
    204  1.11.66.2      yamt 	return claimed;
    205        1.1  fredette }
    206