Home | History | Annotate | Line # | Download | only in vsa
ncr.c revision 1.16
      1 /*	$NetBSD: ncr.c,v 1.16 1998/12/06 13:55:09 ragge Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Adam Glass, David Jones, Gordon W. Ross, and Jens A. Nilsson.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * This file contains the machine-dependent parts of the NCR-5380
     41  * controller. The machine-independent parts are in ncr5380sbc.c.
     42  *
     43  * Note: Only PIO transfers for now which implicates very bad
     44  * performance. DMA support will come soon.
     45  *
     46  * Jens A. Nilsson.
     47  *
     48  * Credits:
     49  *
     50  * This code is based on arch/sun3/dev/si*
     51  * Written by David Jones, Gordon Ross, and Adam Glass.
     52  */
     53 
     54 #include <sys/param.h>
     55 #include <sys/systm.h>
     56 #include <sys/errno.h>
     57 #include <sys/kernel.h>
     58 #include <sys/malloc.h>
     59 #include <sys/device.h>
     60 #include <sys/buf.h>
     61 #include <sys/proc.h>
     62 #include <sys/user.h>
     63 
     64 #include <dev/scsipi/scsi_all.h>
     65 #include <dev/scsipi/scsipi_all.h>
     66 #include <dev/scsipi/scsipi_debug.h>
     67 #include <dev/scsipi/scsiconf.h>
     68 
     69 #include <dev/ic/ncr5380reg.h>
     70 #include <dev/ic/ncr5380var.h>
     71 
     72 #include <machine/vsbus.h>
     73 #include <machine/bus.h>
     74 
     75 #include "ioconf.h"
     76 
     77 #define MIN_DMA_LEN 128
     78 
     79 #ifdef notyet
     80 struct si_dma_handle {
     81 	int	dh_flags;
     82 #define SIDH_BUSY	1
     83 #define SIDH_OUT	2
     84 	u_char	*dh_addr;
     85 };
     86 #endif
     87 
     88 struct si_softc {
     89 	struct ncr5380_softc	ncr_sc;
     90 };
     91 
     92 /* This is copied from julian's bt driver */
     93 /* "so we have a default dev struct for our link struct." */
     94 static struct scsipi_device si_dev = {
     95 	NULL,	/* Use default error handler. */
     96 	NULL,	/* Use default start handler. */
     97 	NULL,	/* Use default async handler. */
     98 	NULL,	/* Use default "done" routine. */
     99 };
    100 
    101 static int si_match(struct device *, struct cfdata *, void *);
    102 static void si_attach(struct device *, struct device *, void *);
    103 static void si_minphys(struct buf *);
    104 static void si_intr(int);
    105 void dk_establish(void);
    106 
    107 struct cfattach ncr_ca = {
    108 	sizeof(struct si_softc), si_match, si_attach
    109 };
    110 
    111 void
    112 dk_establish(void)
    113 {
    114 #if 0
    115 	printf("faking dk_establish()...\n");
    116 #endif
    117 }
    118 
    119 static int
    120 si_match(parent, cf, aux)
    121 	struct device *parent;
    122 	struct cfdata *cf;
    123 	void *aux;
    124 {
    125 	struct vsbus_attach_args *va = aux;
    126 
    127 	if (va->va_type == 0x200C0080)
    128 		return 1;
    129 	return 0;
    130 }
    131 
    132 static void
    133 si_attach(parent, self, args)
    134 	struct device	*parent, *self;
    135 	void		*args;
    136 {
    137 	struct si_softc *sc = (struct si_softc *) self;
    138 	struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
    139 #ifdef notyet
    140 	struct confargs *ca = args;
    141 #endif
    142 
    143 	printf("\n");
    144 	/*
    145 	 * MD function pointers used by the MI code.
    146 	 */
    147 	ncr_sc->sc_pio_out = ncr5380_pio_out;
    148 	ncr_sc->sc_pio_in =  ncr5380_pio_in;
    149 
    150 #ifdef notyet
    151 	ncr_sc->sc_dma_alloc = si_dma_alloc;
    152 	ncr_sc->sc_dma_free  = si_dma_free;
    153 	ncr_sc->sc_dma_setup = si_dma_setup;
    154 	ncr_sc->sc_dma_start = si_dma_start;
    155 	ncr_sc->sc_dma_poll  = si_dma_poll;
    156 	ncr_sc->sc_dma_eop   = si_dma_eop;
    157 	ncr_sc->sc_dma_stop  = si_dma_stop;
    158 #endif
    159 	ncr_sc->sc_intr_on   = NULL /*si_intr_on*/;
    160 	ncr_sc->sc_intr_off  = NULL /*si_intr_off*/;
    161 
    162 	ncr_sc->sc_dma_alloc = NULL;
    163 	ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
    164 
    165 	/*
    166 	 * Fill in the adapter.
    167 	 */
    168 	ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
    169 	ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
    170 
    171 	/*
    172 	 * Fill in the prototype scsi_link.
    173 	 */
    174 	ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
    175 	ncr_sc->sc_link.adapter_softc = sc;
    176 	ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
    177 	ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
    178 	ncr_sc->sc_link.device = &si_dev;
    179 	ncr_sc->sc_link.type = BUS_SCSI;
    180 
    181 	/*
    182 	 * Initialize fields used by the MI code.
    183 	 */
    184 	ncr_sc->sci_r0 = sca_regs + 0x80; /* CUR_DATA/OUT_DATA (rw) */
    185 	ncr_sc->sci_r1 = sca_regs + 0x84; /* INI_CMD           (rw) */
    186 	ncr_sc->sci_r2 = sca_regs + 0x88; /* MODE              (rw) */
    187 	ncr_sc->sci_r3 = sca_regs + 0x8c; /* TAR_CMD           (rw) */
    188 	ncr_sc->sci_r4 = sca_regs + 0x90; /* CUR_STAT/SEL_ENA  (rw) */
    189 	ncr_sc->sci_r5 = sca_regs + 0x94; /* STATUS/DMA_SEND   (rw) */
    190 	ncr_sc->sci_r6 = sca_regs + 0x98; /* IN_DATA/DMA_TRCV  (rw) */
    191 	ncr_sc->sci_r7 = sca_regs + 0x9c; /* RESET/DMA_IRCV    (rw) */
    192 
    193 	/*
    194 	 * Initialize si board itself.
    195 	 */
    196 	ncr5380_init(ncr_sc);
    197 	ncr5380_reset_scsibus(ncr_sc);
    198 
    199 	vsbus_intr_attach(1, si_intr, 0); /* 0 is arg for si_intr */
    200 	vsbus_intr_enable(1);
    201 
    202 	config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
    203 }
    204 
    205 static void
    206 si_minphys(struct buf *bp)
    207 {
    208 #if 0
    209 	printf("minphys: blkno=%d, bcount=%d, data=0x%x, flags=%x\n",
    210 			bp->b_blkno, (int) bp->b_bcount,
    211 			(unsigned) bp->b_data, (unsigned) bp->b_flags);
    212 #endif
    213 }
    214 
    215 static void
    216 si_intr(int arg)
    217 {
    218 #if 0
    219 	printf("si_intr: arg=%d\n", arg);
    220 #endif
    221 	ncr5380_intr(ncr_cd.cd_devs[arg]);
    222 }
    223 
    224