Home | History | Annotate | Line # | Download | only in dev
if_ie_obio.c revision 1.1
      1 /*	$NetBSD: if_ie_obio.c,v 1.1 1996/03/26 14:38:31 gwr Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Gordon W. Ross
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Gordon Ross
     18  * 4. The name of the Author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Machine-dependent glue for the Intel Ethernet (ie) driver.
     35  */
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 #include <sys/protosw.h>
     41 #include <sys/socket.h>
     42 #include <net/if.h>
     43 
     44 #ifdef INET
     45 #include <netinet/in.h>
     46 #include <netinet/in_systm.h>
     47 #include <netinet/in_var.h>
     48 #include <netinet/ip.h>
     49 #include <netinet/if_ether.h>
     50 #endif
     51 
     52 #include <machine/autoconf.h>
     53 #include <machine/cpu.h>
     54 #include <machine/dvma.h>
     55 #include <machine/isr.h>
     56 #include <machine/obio.h>
     57 #include <machine/idprom.h>
     58 #include <machine/vmparam.h>
     59 
     60 #include "i82586.h"
     61 #include "if_ie.h"
     62 #include "if_ie_subr.h"
     63 
     64 static void ie_obreset __P((struct ie_softc *));
     65 static void ie_obattend __P((struct ie_softc *));
     66 static void ie_obrun __P((struct ie_softc *));
     67 
     68 /*
     69  * New-style autoconfig attachment
     70  */
     71 
     72 static int  ie_obio_match __P((struct device *, void *, void *));
     73 static void ie_obio_attach __P((struct device *, struct device *, void *));
     74 
     75 struct cfattach ie_obio_ca = {
     76 	sizeof(struct ie_softc), ie_obio_match, ie_obio_attach
     77 };
     78 
     79 
     80 static int
     81 ie_obio_match(parent, vcf, args)
     82 	struct device *parent;
     83 	void *vcf, *args;
     84 {
     85 	struct cfdata *cf = vcf;
     86 	struct confargs *ca = args;
     87 	int pa, x;
     88 
     89 #ifdef	DIAGNOSTIC
     90 	if (ca->ca_bustype != BUS_OBIO) {
     91 		printf("ie_obio_match: bustype %d?\n", ca->ca_bustype);
     92 		return (0);
     93 	}
     94 #endif
     95 
     96 	/*
     97 	 * OBIO match functions may be called for every possible
     98 	 * physical address, so match only our physical address.
     99 	 */
    100 	if ((pa = cf->cf_paddr) == -1) {
    101 		/* Use our default PA. */
    102 		pa = OBIO_INTEL_ETHER;
    103 	}
    104 	if (pa != ca->ca_paddr)
    105 		return (0);
    106 
    107 	x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
    108 	return (x != -1);
    109 }
    110 
    111 void
    112 ie_obio_attach(parent, self, args)
    113 	struct device *parent;
    114 	struct device *self;
    115 	void *args;
    116 {
    117 	struct ie_softc *sc = (void *) self;
    118 	struct cfdata *cf = self->dv_cfdata;
    119 	struct confargs *ca = args;
    120 	int intpri;
    121 
    122 	/* Default interrupt level. */
    123 	if ((intpri = cf->cf_intpri) == -1)
    124 		intpri = 3;
    125 	printf(" level %d", intpri);
    126 
    127 	sc->hard_type = IE_OBIO;
    128 	sc->reset_586 = ie_obreset;
    129 	sc->chan_attn = ie_obattend;
    130 	sc->run_586 = ie_obrun;
    131 	sc->sc_bcopy = bcopy;
    132 	sc->sc_bzero = bzero;
    133 
    134 	/*
    135 	 * The on-board "ie" just uses main memory, so
    136 	 * we can choose how much memory to give it.
    137 	 * XXX: Would like to use less than 64K...
    138 	 */
    139 	sc->sc_msize = 0x8000; /* MEMSIZE 32K */
    140 
    141 	/* Map in the control registers. */
    142 	sc->sc_reg = obio_alloc(ca->ca_paddr, OBIO_INTEL_ETHER_SIZE);
    143 
    144 	/* Allocate "shared" memory (in DVMA space). */
    145 	sc->sc_maddr = dvma_malloc(sc->sc_msize);
    146 	if (sc->sc_maddr == NULL)
    147 		panic(": not enough dvma space");
    148 
    149 	/*
    150 	 * The on-board "ie" is wired-up such that its
    151 	 * memory access goes to the high 16 megabytes
    152 	 * of the on-board memory space (on-board DVMA).
    153 	 */
    154 	sc->sc_iobase = (caddr_t)DVMA_OBIO_SLAVE_BASE;
    155 
    156 	/*
    157 	 * Set the System Configuration Pointer (SCP).
    158 	 * Its location is system-dependent because the
    159 	 * i82586 reads it from a fixed physical address.
    160 	 * On this hardware, the i82586 address maps to
    161 	 * a 24-bit offset in on-board DVMA space. The
    162 	 * SCP happens to fall in a page used by the
    163 	 * PROM monitor, which the PROM knows about.
    164 	 */
    165 	sc->scp = (volatile void *) (sc->sc_iobase + IE_SCP_ADDR);
    166 
    167 	/*
    168 	 * The rest of ram is used for buffers.
    169 	 */
    170 	sc->buf_area    = sc->sc_maddr;
    171 	sc->buf_area_sz = sc->sc_msize;
    172 
    173 	/* Set the ethernet address. */
    174 	idprom_etheraddr(sc->sc_addr);
    175 
    176 	/* Do machine-independent parts of attach. */
    177 	ie_attach(sc);
    178 
    179 	/* Install interrupt handler. */
    180 	isr_add_autovect(ie_intr, (void *)sc, intpri);
    181 }
    182 
    183 
    184 /*
    185  * onboard ie support
    186  */
    187 void
    188 ie_obreset(sc)
    189 	struct ie_softc *sc;
    190 {
    191 	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
    192 	ieo->obctrl = 0;
    193 	delay(100);			/* XXX could be shorter? */
    194 	ieo->obctrl = IEOB_NORSET;
    195 }
    196 void
    197 ie_obattend(sc)
    198 	struct ie_softc *sc;
    199 {
    200 	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
    201 
    202 	ieo->obctrl |= IEOB_ATTEN;	/* flag! */
    203 	ieo->obctrl &= ~IEOB_ATTEN;	/* down. */
    204 }
    205 
    206 void
    207 ie_obrun(sc)
    208 	struct ie_softc *sc;
    209 {
    210 	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
    211 
    212 	ieo->obctrl |= (IEOB_ONAIR|IEOB_IENAB|IEOB_NORSET);
    213 }
    214 
    215