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