Home | History | Annotate | Line # | Download | only in dev
sebuf.c revision 1.17
      1 /*	$NetBSD: sebuf.c,v 1.17 2008/06/28 12:13:38 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gordon W. Ross.
      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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Sun3/E SCSI/Ethernet board.  This is a VME board with some memory,
     34  * an Intel Ether, and an NCR5380 SCSI with a cheap DMA engine.
     35  * Note that the SCSI DMA engine can ONLY access the memory on
     36  * the SE board, NOT the main memory, because it can not master
     37  * VME transfers.
     38  *
     39  * This driver ("sebuf") is the parent of two child drivers:
     40  *   se: yet another variant of NCR 5380 SCSI H/W
     41  *   ie: yet anotehr variant of Intel 82586 Ethernet
     42  *
     43  * The job of this parent is to map the memory and partition it for
     44  * the two children.  This driver has no device nodes.
     45  */
     46 
     47 #include <sys/cdefs.h>
     48 __KERNEL_RCSID(0, "$NetBSD: sebuf.c,v 1.17 2008/06/28 12:13:38 tsutsui Exp $");
     49 
     50 #include <sys/param.h>
     51 #include <sys/systm.h>
     52 #include <sys/conf.h>
     53 #include <sys/device.h>
     54 #include <sys/ioctl.h>
     55 #include <sys/malloc.h>
     56 #include <sys/mman.h>
     57 #include <sys/proc.h>
     58 #include <sys/tty.h>
     59 
     60 #include <uvm/uvm_extern.h>
     61 
     62 #include <machine/autoconf.h>
     63 #include <machine/cpu.h>
     64 
     65 #include "sereg.h"
     66 #include "sevar.h"
     67 
     68 struct sebuf_softc {
     69 	device_t sc_dev;		/* base device (required) */
     70 	struct sebuf_regs *sc_regs;
     71 };
     72 
     73 /*
     74  * Autoconfig attachment
     75  */
     76 
     77 static int  sebuf_match(device_t, cfdata_t, void *);
     78 static void sebuf_attach(device_t, device_t, void *);
     79 static int  sebuf_print(void *, const char *);
     80 
     81 CFATTACH_DECL_NEW(sebuf, sizeof(struct sebuf_softc),
     82     sebuf_match, sebuf_attach, NULL, NULL);
     83 
     84 static int
     85 sebuf_match(device_t parent, cfdata_t cf, void *args)
     86 {
     87 	struct confargs *ca = args;
     88 	struct se_regs *sreg;
     89 	struct ie_regs *ereg;
     90 	int pa, x;
     91 
     92 	if (ca->ca_paddr == -1)
     93 		return 0;
     94 
     95 	/* Is it there at all? */
     96 	pa = ca->ca_paddr;
     97 	x = bus_peek(ca->ca_bustype, pa, 2);
     98 	if (x == -1)
     99 		return 0;
    100 
    101 	/* Look at the CSR for the SCSI part. */
    102 	pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_scsi_regs);
    103 	sreg = bus_tmapin(ca->ca_bustype, pa);
    104 	/* Write some bits that are wired to zero. */
    105 	sreg->se_csr = 0xFFF3;
    106 	x = peek_word((void *)(&sreg->se_csr));
    107 	bus_tmapout(sreg);
    108 	if ((x == -1) || (x & 0xFCF0)) {
    109 #ifdef	DEBUG
    110 		aprint_debug("%s: SCSI csr=0x%x\n", __func__, x);
    111 #endif
    112 		return 0;
    113 	}
    114 
    115 	/* Look at the CSR for the Ethernet part. */
    116 	pa = ca->ca_paddr + offsetof(struct sebuf_regs, se_eth_regs);
    117 	ereg = bus_tmapin(ca->ca_bustype, pa);
    118 	/* Write some bits that are wired to zero. */
    119 	ereg->ie_csr = 0x0FFF;
    120 	x = peek_word((void *)(&ereg->ie_csr));
    121 	bus_tmapout(ereg);
    122 	if ((x == -1) || (x & 0xFFF)) {
    123 #ifdef	DEBUG
    124 		printf("%s: Ether csr=0x%x\n", __func__, x);
    125 #endif
    126 		return 0;
    127 	}
    128 
    129 	/* Default interrupt priority always splbio==2 */
    130 	if (ca->ca_intpri == -1)
    131 		ca->ca_intpri = 2;
    132 
    133 	return 1;
    134 }
    135 
    136 static void
    137 sebuf_attach(device_t parent, device_t self, void *args)
    138 {
    139 	struct sebuf_softc *sc = device_private(self);
    140 	struct confargs *ca = args;
    141 	struct sebuf_attach_args aa;
    142 	struct sebuf_regs *regs;
    143 
    144 	sc->sc_dev = self;
    145 	aprint_normal("\n");
    146 
    147 	if (ca->ca_intpri != 2)
    148 		panic("sebuf: bad level");
    149 
    150 	/* Map in the whole board. */
    151 	regs = (struct sebuf_regs *)bus_mapin(ca->ca_bustype, ca->ca_paddr,
    152 	    sizeof(struct sebuf_regs));
    153 	if (regs == NULL)
    154 		panic("%s", __func__);
    155 	sc->sc_regs = regs;
    156 
    157 	/* Attach the SCSI child. */
    158 	aa.ca = *ca;	/* structure copy */
    159 	aa.ca.ca_paddr = 0; /* prevent misuse */
    160 	aa.name = "se";
    161 	aa.buf  = &regs->se_scsi_buf[0];
    162 	aa.blen = SE_NCRBUFSIZE;
    163 	aa.regs = &regs->se_scsi_regs;
    164 	(void)config_found(self, (void *)&aa, sebuf_print);
    165 
    166 	/* Attach the Ethernet child. */
    167 	aa.ca.ca_intpri++;
    168 	aa.ca.ca_intvec++;
    169 	aa.name = "ie";
    170 	aa.buf  = &regs->se_eth_buf[0];
    171 	aa.blen = SE_IEBUFSIZE;
    172 	aa.regs = &regs->se_eth_regs;
    173 	(void)config_found(self, (void *)&aa, sebuf_print);
    174 }
    175 
    176 static int
    177 sebuf_print(void *aux, const char *name)
    178 {
    179 
    180 	if (name != NULL)
    181 		aprint_normal("%s: ", name);
    182 
    183 	return UNCONF;
    184 }
    185