Home | History | Annotate | Line # | Download | only in isa
if_le_isa.c revision 1.7.4.2
      1  1.7.4.2        is /*	$NetBSD: if_le_isa.c,v 1.7.4.2 1997/03/10 13:46:16 is Exp $	*/
      2      1.1   thorpej 
      3      1.1   thorpej /*-
      4      1.1   thorpej  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      5      1.1   thorpej  * Copyright (c) 1992, 1993
      6      1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
      7      1.1   thorpej  *
      8      1.1   thorpej  * This code is derived from software contributed to Berkeley by
      9      1.1   thorpej  * Ralph Campbell and Rick Macklem.
     10      1.1   thorpej  *
     11      1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     12      1.1   thorpej  * modification, are permitted provided that the following conditions
     13      1.1   thorpej  * are met:
     14      1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     15      1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     16      1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18      1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     19      1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     20      1.1   thorpej  *    must display the following acknowledgement:
     21      1.1   thorpej  *	This product includes software developed by the University of
     22      1.1   thorpej  *	California, Berkeley and its contributors.
     23      1.1   thorpej  * 4. Neither the name of the University nor the names of its contributors
     24      1.1   thorpej  *    may be used to endorse or promote products derived from this software
     25      1.1   thorpej  *    without specific prior written permission.
     26      1.1   thorpej  *
     27      1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28      1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29      1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30      1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31      1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32      1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33      1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34      1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35      1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36      1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37      1.1   thorpej  * SUCH DAMAGE.
     38      1.1   thorpej  *
     39      1.1   thorpej  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     40      1.1   thorpej  */
     41      1.1   thorpej 
     42      1.1   thorpej #include "bpfilter.h"
     43      1.1   thorpej 
     44      1.1   thorpej #include <sys/param.h>
     45      1.1   thorpej #include <sys/systm.h>
     46      1.1   thorpej #include <sys/mbuf.h>
     47      1.1   thorpej #include <sys/syslog.h>
     48      1.1   thorpej #include <sys/socket.h>
     49      1.1   thorpej #include <sys/device.h>
     50      1.1   thorpej 
     51      1.1   thorpej #include <net/if.h>
     52  1.7.4.1        is #include <net/if_ether.h>
     53      1.1   thorpej 
     54      1.1   thorpej #ifdef INET
     55      1.1   thorpej #include <netinet/in.h>
     56  1.7.4.2        is #include <netinet/if_inarp.h>
     57      1.1   thorpej #endif
     58      1.1   thorpej 
     59      1.1   thorpej #include <vm/vm.h>
     60      1.1   thorpej 
     61      1.1   thorpej #include <machine/cpu.h>
     62      1.2   mycroft #include <machine/intr.h>
     63      1.6   thorpej #include <machine/bus.h>
     64      1.1   thorpej 
     65      1.1   thorpej #include <dev/isa/isareg.h>
     66      1.1   thorpej #include <dev/isa/isavar.h>
     67      1.1   thorpej #include <dev/isa/isadmavar.h>
     68      1.1   thorpej 
     69      1.1   thorpej #include <dev/ic/am7990reg.h>
     70      1.1   thorpej #include <dev/ic/am7990var.h>
     71      1.1   thorpej 
     72      1.1   thorpej #include <dev/isa/if_levar.h>
     73      1.1   thorpej 
     74      1.1   thorpej static char *card_type[] =
     75      1.1   thorpej     { "unknown", "BICC Isolan", "NE2100", "DEPCA", "PCnet-ISA" };
     76      1.1   thorpej 
     77      1.1   thorpej int le_isa_probe __P((struct device *, void *, void *));
     78      1.1   thorpej void le_isa_attach __P((struct device *, struct device *, void *));
     79      1.1   thorpej 
     80      1.1   thorpej struct cfattach le_isa_ca = {
     81      1.1   thorpej 	sizeof(struct le_softc), le_isa_probe, le_isa_attach
     82      1.1   thorpej };
     83      1.1   thorpej 
     84      1.1   thorpej int depca_isa_probe __P((struct le_softc *, struct isa_attach_args *));
     85      1.1   thorpej int ne2100_isa_probe __P((struct le_softc *, struct isa_attach_args *));
     86      1.1   thorpej int bicc_isa_probe __P((struct le_softc *, struct isa_attach_args *));
     87      1.1   thorpej int lance_isa_probe __P((struct am7990_softc *));
     88      1.1   thorpej 
     89      1.1   thorpej int le_isa_intredge __P((void *));
     90      1.1   thorpej 
     91      1.1   thorpej hide void le_isa_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     92      1.1   thorpej hide u_int16_t le_isa_rdcsr __P((struct am7990_softc *, u_int16_t));
     93      1.1   thorpej 
     94      1.6   thorpej void	depca_copytobuf __P((struct am7990_softc *, void *, int, int));
     95      1.6   thorpej void	depca_copyfrombuf __P((struct am7990_softc *, void *, int, int));
     96      1.6   thorpej void	depca_zerobuf __P((struct am7990_softc *, int, int));
     97      1.6   thorpej 
     98      1.1   thorpej hide void
     99      1.1   thorpej le_isa_wrcsr(sc, port, val)
    100      1.1   thorpej 	struct am7990_softc *sc;
    101      1.1   thorpej 	u_int16_t port, val;
    102      1.1   thorpej {
    103      1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    104      1.6   thorpej 	bus_space_tag_t iot = lesc->sc_iot;
    105      1.6   thorpej 	bus_space_handle_t ioh = lesc->sc_ioh;
    106      1.1   thorpej 
    107      1.6   thorpej 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    108      1.6   thorpej 	bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
    109      1.1   thorpej }
    110      1.1   thorpej 
    111      1.1   thorpej hide u_int16_t
    112      1.1   thorpej le_isa_rdcsr(sc, port)
    113      1.1   thorpej 	struct am7990_softc *sc;
    114      1.1   thorpej 	u_int16_t port;
    115      1.1   thorpej {
    116      1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    117      1.6   thorpej 	bus_space_tag_t iot = lesc->sc_iot;
    118      1.6   thorpej 	bus_space_handle_t ioh = lesc->sc_ioh;
    119      1.1   thorpej 	u_int16_t val;
    120      1.1   thorpej 
    121      1.6   thorpej 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    122      1.6   thorpej 	val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
    123      1.1   thorpej 	return (val);
    124      1.1   thorpej }
    125      1.1   thorpej 
    126      1.1   thorpej int
    127      1.1   thorpej le_isa_probe(parent, match, aux)
    128      1.1   thorpej 	struct device *parent;
    129      1.1   thorpej 	void *match, *aux;
    130      1.1   thorpej {
    131      1.1   thorpej 	struct le_softc *lesc = match;
    132      1.1   thorpej 	struct isa_attach_args *ia = aux;
    133      1.1   thorpej 
    134      1.1   thorpej 	if (bicc_isa_probe(lesc, ia))
    135      1.1   thorpej 		return (1);
    136      1.1   thorpej 	if (ne2100_isa_probe(lesc, ia))
    137      1.1   thorpej 		return (1);
    138      1.1   thorpej 	if (depca_isa_probe(lesc, ia))
    139      1.1   thorpej 		return (1);
    140      1.1   thorpej 
    141      1.1   thorpej 	return (0);
    142      1.1   thorpej }
    143      1.1   thorpej 
    144      1.1   thorpej int
    145      1.1   thorpej depca_isa_probe(lesc, ia)
    146      1.1   thorpej 	struct le_softc *lesc;
    147      1.1   thorpej 	struct isa_attach_args *ia;
    148      1.1   thorpej {
    149      1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    150      1.1   thorpej 	int iobase = ia->ia_iobase, port;
    151      1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    152      1.6   thorpej 	bus_space_handle_t ioh;
    153      1.6   thorpej 	bus_space_handle_t memh;
    154      1.4  christos #if 0
    155      1.6   thorpej 	u_int32_t sum, rom_sum;
    156      1.6   thorpej 	u_int8_t x;
    157      1.4  christos #endif
    158      1.1   thorpej 	int i;
    159      1.1   thorpej 
    160      1.6   thorpej 	/* Map i/o space. */
    161      1.6   thorpej 	if (bus_space_map(iot, iobase, 16, 0, &ioh))
    162      1.6   thorpej 		return 0;
    163      1.6   thorpej 
    164      1.6   thorpej 	if (ia->ia_maddr == MADDRUNK || ia->ia_msize == -1)
    165      1.6   thorpej 		goto bad;
    166      1.6   thorpej 
    167      1.6   thorpej 	/* Map card RAM. */
    168      1.6   thorpej 	if (bus_space_map(ia->ia_memt, ia->ia_maddr, ia->ia_msize,
    169      1.6   thorpej 	    0, &memh))
    170      1.6   thorpej 		goto bad;
    171      1.6   thorpej 
    172      1.6   thorpej 	/* Just needed to check mapability; don't need it anymore. */
    173      1.6   thorpej 	bus_space_unmap(ia->ia_memt, ia->ia_maddr, ia->ia_msize);
    174      1.6   thorpej 
    175      1.7   thorpej 	lesc->sc_iot = iot;
    176      1.7   thorpej 	lesc->sc_ioh = ioh;
    177      1.6   thorpej 	lesc->sc_rap = DEPCA_RAP;
    178      1.6   thorpej 	lesc->sc_rdp = DEPCA_RDP;
    179      1.1   thorpej 	lesc->sc_card = DEPCA;
    180      1.1   thorpej 
    181      1.1   thorpej 	if (lance_isa_probe(sc) == 0)
    182      1.6   thorpej 		goto bad;
    183      1.1   thorpej 
    184      1.6   thorpej 	bus_space_write_1(iot, ioh, DEPCA_CSR, DEPCA_CSR_DUM);
    185      1.1   thorpej 
    186      1.1   thorpej 	/*
    187      1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    188      1.1   thorpej 	 *
    189      1.1   thorpej 	 * The address PROM is 32 bytes wide, and we access it through
    190      1.1   thorpej 	 * a single I/O port.  On each read, it rotates to the next
    191      1.1   thorpej 	 * position.  We find the ethernet address by looking for a
    192      1.1   thorpej 	 * particular sequence of bytes (0xff, 0x00, 0x55, 0xaa, 0xff,
    193      1.1   thorpej 	 * 0x00, 0x55, 0xaa), and then reading the next 8 bytes (the
    194      1.1   thorpej 	 * ethernet address and a checksum).
    195      1.1   thorpej 	 *
    196      1.1   thorpej 	 * It appears that the PROM can be at one of two locations, so
    197      1.1   thorpej 	 * we just try both.
    198      1.1   thorpej 	 */
    199      1.6   thorpej 	port = DEPCA_ADP;
    200      1.1   thorpej 	for (i = 0; i < 32; i++)
    201      1.6   thorpej 		if (bus_space_read_1(iot, ioh, port) == 0xff &&
    202      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    203      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    204      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa &&
    205      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xff &&
    206      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    207      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    208      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa)
    209      1.1   thorpej 			goto found;
    210      1.6   thorpej 	port = DEPCA_ADP + 1;
    211      1.1   thorpej 	for (i = 0; i < 32; i++)
    212      1.6   thorpej 		if (bus_space_read_1(iot, ioh, port) == 0xff &&
    213      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    214      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    215      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa &&
    216      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xff &&
    217      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    218      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    219      1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa)
    220      1.1   thorpej 			goto found;
    221      1.5  christos 	printf("%s: address not found\n", sc->sc_dev.dv_xname);
    222      1.6   thorpej 	goto bad;
    223      1.1   thorpej 
    224      1.1   thorpej found:
    225  1.7.4.1        is 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    226  1.7.4.1        is 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, port);
    227      1.1   thorpej 
    228      1.1   thorpej #if 0
    229      1.1   thorpej 	sum =
    230  1.7.4.1        is 	    (sc->sc_enaddr[0] <<  2) +
    231  1.7.4.1        is 	    (sc->sc_enaddr[1] << 10) +
    232  1.7.4.1        is 	    (sc->sc_enaddr[2] <<  1) +
    233  1.7.4.1        is 	    (sc->sc_enaddr[3] <<  9) +
    234  1.7.4.1        is 	    (sc->sc_enaddr[4] <<  0) +
    235  1.7.4.1        is 	    (sc->sc_enaddr[5] <<  8);
    236      1.1   thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    237      1.1   thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    238      1.1   thorpej 
    239      1.6   thorpej 	rom_sum = bus_space_read_1(iot, ioh, port);
    240      1.6   thorpej 	rom_sum |= bus_space_read_1(iot, ioh, port) << 8;
    241      1.1   thorpej 
    242      1.1   thorpej 	if (sum != rom_sum) {
    243      1.5  christos 		printf("%s: checksum mismatch; calculated %04x != read %04x",
    244      1.1   thorpej 		    sc->sc_dev.dv_xname, sum, rom_sum);
    245      1.6   thorpej 		goto bad;
    246      1.1   thorpej 	}
    247      1.1   thorpej #endif
    248      1.1   thorpej 
    249      1.6   thorpej 	bus_space_write_1(iot, ioh, DEPCA_CSR, DEPCA_CSR_NORMAL);
    250      1.6   thorpej 
    251      1.6   thorpej 	/*
    252      1.6   thorpej 	 * XXX INDIRECT BROKENNESS!
    253      1.6   thorpej 	 * XXX Should always unmap, and re-map in if_le_isa_attach().
    254      1.6   thorpej 	 */
    255      1.1   thorpej 
    256      1.1   thorpej 	ia->ia_iosize = 16;
    257      1.1   thorpej 	ia->ia_drq = DRQUNK;
    258      1.1   thorpej 	return 1;
    259      1.6   thorpej 
    260      1.6   thorpej  bad:
    261      1.6   thorpej 	bus_space_unmap(iot, ioh, 16);
    262      1.6   thorpej 	return 0;
    263      1.1   thorpej }
    264      1.1   thorpej 
    265      1.1   thorpej int
    266      1.1   thorpej ne2100_isa_probe(lesc, ia)
    267      1.1   thorpej 	struct le_softc *lesc;
    268      1.1   thorpej 	struct isa_attach_args *ia;
    269      1.1   thorpej {
    270      1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    271      1.1   thorpej 	int iobase = ia->ia_iobase;
    272      1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    273      1.6   thorpej 	bus_space_handle_t ioh;
    274      1.1   thorpej 	int i;
    275      1.1   thorpej 
    276      1.6   thorpej 	/* Map i/o space. */
    277      1.6   thorpej 	if (bus_space_map(iot, iobase, 24, 0, &ioh))
    278      1.6   thorpej 		return 0;
    279      1.6   thorpej 
    280      1.7   thorpej 	lesc->sc_iot = iot;
    281      1.7   thorpej 	lesc->sc_ioh = ioh;
    282      1.6   thorpej 	lesc->sc_rap = NE2100_RAP;
    283      1.6   thorpej 	lesc->sc_rdp = NE2100_RDP;
    284      1.1   thorpej 	lesc->sc_card = NE2100;
    285      1.1   thorpej 
    286      1.6   thorpej 	if (lance_isa_probe(sc) == 0) {
    287      1.6   thorpej 		bus_space_unmap(iot, ioh, 24);
    288      1.1   thorpej 		return 0;
    289      1.6   thorpej 	}
    290      1.1   thorpej 
    291      1.1   thorpej 	/*
    292      1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    293      1.1   thorpej 	 */
    294  1.7.4.1        is 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    295  1.7.4.1        is 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, i);
    296      1.6   thorpej 
    297      1.6   thorpej 	/*
    298      1.6   thorpej 	 * XXX INDIRECT BROKENNESS!
    299      1.6   thorpej 	 * XXX Should always unmap, and re-map in if_le_isa_attach().
    300      1.6   thorpej 	 */
    301      1.1   thorpej 
    302      1.1   thorpej 	ia->ia_iosize = 24;
    303      1.1   thorpej 	return 1;
    304      1.1   thorpej }
    305      1.1   thorpej 
    306      1.1   thorpej int
    307      1.1   thorpej bicc_isa_probe(lesc, ia)
    308      1.1   thorpej 	struct le_softc *lesc;
    309      1.1   thorpej 	struct isa_attach_args *ia;
    310      1.1   thorpej {
    311      1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    312      1.1   thorpej 	int iobase = ia->ia_iobase;
    313      1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    314      1.6   thorpej 	bus_space_handle_t ioh;
    315      1.1   thorpej 	int i;
    316      1.1   thorpej 
    317      1.6   thorpej 	/* Map i/o space. */
    318      1.6   thorpej 	if (bus_space_map(iot, iobase, 16, 0, &ioh))
    319      1.6   thorpej 		return 0;
    320      1.6   thorpej 
    321      1.7   thorpej 	lesc->sc_iot = iot;
    322      1.7   thorpej 	lesc->sc_ioh = ioh;
    323      1.6   thorpej 	lesc->sc_rap = BICC_RAP;
    324      1.6   thorpej 	lesc->sc_rdp = BICC_RDP;
    325      1.1   thorpej 	lesc->sc_card = BICC;
    326      1.1   thorpej 
    327      1.6   thorpej 	if (lance_isa_probe(sc) == 0) {
    328      1.6   thorpej 		bus_space_unmap(iot, ioh, 16);
    329      1.1   thorpej 		return 0;
    330      1.6   thorpej 	}
    331      1.1   thorpej 
    332      1.1   thorpej 	/*
    333      1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    334      1.1   thorpej 	 */
    335  1.7.4.1        is 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    336  1.7.4.1        is 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, i * 2);
    337      1.6   thorpej 
    338      1.6   thorpej 	/*
    339      1.6   thorpej 	 * XXX INDIRECT BROKENNESS!
    340      1.6   thorpej 	 * XXX Should always unmap, and re-map in if_le_isa_attach().
    341      1.6   thorpej 	 */
    342      1.1   thorpej 
    343      1.1   thorpej 	ia->ia_iosize = 16;
    344      1.1   thorpej 	return 1;
    345      1.1   thorpej }
    346      1.1   thorpej 
    347      1.1   thorpej /*
    348      1.1   thorpej  * Determine which chip is present on the card.
    349      1.1   thorpej  */
    350      1.1   thorpej int
    351      1.1   thorpej lance_isa_probe(sc)
    352      1.1   thorpej 	struct am7990_softc *sc;
    353      1.1   thorpej {
    354      1.1   thorpej 
    355      1.1   thorpej 	/* Stop the LANCE chip and put it in a known state. */
    356      1.1   thorpej 	le_isa_wrcsr(sc, LE_CSR0, LE_C0_STOP);
    357      1.1   thorpej 	delay(100);
    358      1.1   thorpej 
    359      1.1   thorpej 	if (le_isa_rdcsr(sc, LE_CSR0) != LE_C0_STOP)
    360      1.1   thorpej 		return 0;
    361      1.1   thorpej 
    362      1.1   thorpej 	le_isa_wrcsr(sc, LE_CSR3, sc->sc_conf3);
    363      1.1   thorpej 	return 1;
    364      1.1   thorpej }
    365      1.1   thorpej 
    366      1.1   thorpej void
    367      1.1   thorpej le_isa_attach(parent, self, aux)
    368      1.1   thorpej 	struct device *parent, *self;
    369      1.1   thorpej 	void *aux;
    370      1.1   thorpej {
    371      1.1   thorpej 	struct le_softc *lesc = (void *)self;
    372      1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    373      1.1   thorpej 	struct isa_attach_args *ia = aux;
    374      1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    375      1.6   thorpej 	bus_space_tag_t memt = ia->ia_memt;
    376      1.6   thorpej 	bus_space_handle_t memh;
    377      1.1   thorpej 
    378      1.5  christos 	printf(": %s Ethernet\n", card_type[lesc->sc_card]);
    379      1.1   thorpej 
    380      1.6   thorpej 	lesc->sc_iot = iot;
    381      1.6   thorpej 	lesc->sc_memt = memt;
    382      1.6   thorpej 
    383      1.6   thorpej 	/* XXX SHOULD RE-MAP I/O SPACE HERE. */
    384      1.6   thorpej 
    385      1.1   thorpej 	if (lesc->sc_card == DEPCA) {
    386      1.6   thorpej 		u_char val;
    387      1.1   thorpej 		int i;
    388      1.1   thorpej 
    389      1.6   thorpej 		/* Map shared memory. */
    390      1.6   thorpej 		if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize,
    391      1.6   thorpej 		    0, &memh))
    392      1.6   thorpej 			panic("le_isa_attach: can't map shared memory");
    393      1.6   thorpej 
    394      1.6   thorpej 		lesc->sc_memh = memh;
    395      1.1   thorpej 
    396      1.1   thorpej 		val = 0xff;
    397      1.1   thorpej 		for (;;) {
    398      1.6   thorpej #if 0	/* XXX !! */
    399      1.6   thorpej 			bus_space_set_region_1(memt, memh, 0, val);
    400      1.6   thorpej #else
    401      1.1   thorpej 			for (i = 0; i < ia->ia_msize; i++)
    402      1.6   thorpej 				bus_space_write_1(memt, memh, i, val);
    403      1.6   thorpej #endif
    404      1.1   thorpej 			for (i = 0; i < ia->ia_msize; i++)
    405      1.6   thorpej 				if (bus_space_read_1(memt, memh, 1) != val) {
    406      1.5  christos 					printf("%s: failed to clear memory\n",
    407      1.1   thorpej 					    sc->sc_dev.dv_xname);
    408      1.1   thorpej 					return;
    409      1.1   thorpej 				}
    410      1.1   thorpej 			if (val == 0x00)
    411      1.1   thorpej 				break;
    412      1.1   thorpej 			val -= 0x55;
    413      1.1   thorpej 		}
    414      1.1   thorpej 
    415      1.1   thorpej 		sc->sc_conf3 = LE_C3_ACON;
    416      1.6   thorpej 		sc->sc_mem = 0;			/* Not used. */
    417      1.1   thorpej 		sc->sc_addr = 0;
    418      1.1   thorpej 		sc->sc_memsize = ia->ia_msize;
    419      1.1   thorpej 	} else {
    420      1.1   thorpej 		sc->sc_mem = malloc(16384, M_DEVBUF, M_NOWAIT);
    421      1.1   thorpej 		if (sc->sc_mem == 0) {
    422      1.5  christos 			printf("%s: couldn't allocate memory for card\n",
    423      1.1   thorpej 			    sc->sc_dev.dv_xname);
    424      1.1   thorpej 			return;
    425      1.1   thorpej 		}
    426      1.1   thorpej 
    427      1.1   thorpej 		sc->sc_conf3 = 0;
    428      1.6   thorpej 		sc->sc_addr = kvtop(sc->sc_mem);	/* XXX !! */
    429      1.1   thorpej 		sc->sc_memsize = 16384;
    430      1.1   thorpej 	}
    431      1.1   thorpej 
    432      1.6   thorpej 	if (lesc->sc_card == DEPCA) {
    433      1.6   thorpej 		sc->sc_copytodesc = depca_copytobuf;
    434      1.6   thorpej 		sc->sc_copyfromdesc = depca_copyfrombuf;
    435      1.6   thorpej 		sc->sc_copytobuf = depca_copytobuf;
    436      1.6   thorpej 		sc->sc_copyfrombuf = depca_copyfrombuf;
    437      1.6   thorpej 		sc->sc_zerobuf = depca_zerobuf;
    438      1.6   thorpej 	} else {
    439      1.6   thorpej 		sc->sc_copytodesc = am7990_copytobuf_contig;
    440      1.6   thorpej 		sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    441      1.6   thorpej 		sc->sc_copytobuf = am7990_copytobuf_contig;
    442      1.6   thorpej 		sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    443      1.6   thorpej 		sc->sc_zerobuf = am7990_zerobuf_contig;
    444      1.6   thorpej 	}
    445      1.1   thorpej 
    446      1.1   thorpej 	sc->sc_rdcsr = le_isa_rdcsr;
    447      1.1   thorpej 	sc->sc_wrcsr = le_isa_wrcsr;
    448      1.1   thorpej 	sc->sc_hwinit = NULL;
    449      1.1   thorpej 
    450      1.5  christos 	printf("%s", sc->sc_dev.dv_xname);
    451      1.1   thorpej 	am7990_config(sc);
    452      1.1   thorpej 
    453      1.1   thorpej 	if (ia->ia_drq != DRQUNK)
    454      1.1   thorpej 		isa_dmacascade(ia->ia_drq);
    455      1.1   thorpej 
    456      1.1   thorpej 	lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    457      1.1   thorpej 	    IPL_NET, le_isa_intredge, sc);
    458      1.1   thorpej }
    459      1.1   thorpej 
    460      1.1   thorpej /*
    461      1.1   thorpej  * Controller interrupt.
    462      1.1   thorpej  */
    463      1.3   thorpej int
    464      1.1   thorpej le_isa_intredge(arg)
    465      1.1   thorpej 	void *arg;
    466      1.1   thorpej {
    467      1.1   thorpej 
    468      1.1   thorpej 	if (am7990_intr(arg) == 0)
    469      1.1   thorpej 		return (0);
    470      1.1   thorpej 	for (;;)
    471      1.1   thorpej 		if (am7990_intr(arg) == 0)
    472      1.1   thorpej 			return (1);
    473      1.6   thorpej }
    474      1.6   thorpej 
    475      1.6   thorpej /*
    476      1.6   thorpej  * DEPCA shared memory access functions.
    477      1.6   thorpej  */
    478      1.6   thorpej 
    479      1.6   thorpej void
    480      1.6   thorpej depca_copytobuf(sc, from, boff, len)
    481      1.6   thorpej 	struct am7990_softc *sc;
    482      1.6   thorpej 	void *from;
    483      1.6   thorpej 	int boff, len;
    484      1.6   thorpej {
    485      1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    486      1.6   thorpej 
    487      1.6   thorpej 	bus_space_write_region_1(lesc->sc_memt, lesc->sc_memh, boff,
    488      1.6   thorpej 	    from, len);
    489      1.6   thorpej }
    490      1.6   thorpej 
    491      1.6   thorpej void
    492      1.6   thorpej depca_copyfrombuf(sc, to, boff, len)
    493      1.6   thorpej 	struct am7990_softc *sc;
    494      1.6   thorpej 	void *to;
    495      1.6   thorpej 	int boff, len;
    496      1.6   thorpej {
    497      1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    498      1.6   thorpej 
    499      1.6   thorpej 	bus_space_read_region_1(lesc->sc_memt, lesc->sc_memh, boff,
    500      1.6   thorpej 	    to, len);
    501      1.6   thorpej }
    502      1.6   thorpej 
    503      1.6   thorpej void
    504      1.6   thorpej depca_zerobuf(sc, boff, len)
    505      1.6   thorpej 	struct am7990_softc *sc;
    506      1.6   thorpej 	int boff, len;
    507      1.6   thorpej {
    508      1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    509      1.6   thorpej 
    510      1.6   thorpej #if 0	/* XXX !! */
    511      1.6   thorpej 	bus_space_set_region_1(lesc->sc_memt, lesc->sc_memh, boff,
    512      1.6   thorpej 	    0x00, len);
    513      1.6   thorpej #else
    514      1.6   thorpej 	for (; len != 0; boff++, len--)
    515      1.6   thorpej 		bus_space_write_1(lesc->sc_memt, lesc->sc_memh, boff, 0x00);
    516      1.6   thorpej #endif
    517      1.1   thorpej }
    518