Home | History | Annotate | Line # | Download | only in isapnp
if_cs_isapnp.c revision 1.2
      1 /* $NetBSD: if_cs_isapnp.c,v 1.2 2002/05/21 02:47:05 augustss Exp $ */
      2 
      3 /*-
      4  * Copyright (c)2001 YAMAMOTO Takashi,
      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  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: if_cs_isapnp.c,v 1.2 2002/05/21 02:47:05 augustss Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/device.h>
     35 #include <sys/socket.h>
     36 
     37 #include "rnd.h"
     38 #if NRND > 0
     39 #include <sys/rnd.h>
     40 #endif
     41 
     42 #include <net/if.h>
     43 #include <net/if_ether.h>
     44 #include <net/if_media.h>
     45 
     46 #include <machine/bus.h>
     47 #include <machine/intr.h>
     48 
     49 #include <dev/isa/isavar.h>
     50 
     51 #include <dev/ic/cs89x0reg.h>
     52 #include <dev/ic/cs89x0var.h>
     53 
     54 #include <dev/isapnp/isapnpreg.h>
     55 #include <dev/isapnp/isapnpvar.h>
     56 #include <dev/isapnp/isapnpdevs.h>
     57 
     58 #define DEVNAME(sc) (sc)->sc_dev.dv_xname
     59 
     60 int cs_isapnp_match(struct device *, struct cfdata *, void *);
     61 void cs_isapnp_attach(struct device *, struct device *, void *);
     62 
     63 struct cfattach cs_isapnp_ca = {
     64 	sizeof(struct cs_softc),
     65 	cs_isapnp_match,
     66 	cs_isapnp_attach
     67 };
     68 
     69 int
     70 cs_isapnp_match(parent, match, aux)
     71 	struct device *parent;
     72 	struct cfdata *match;
     73 	void *aux;
     74 {
     75 	int pri, variant;
     76 
     77 	pri = isapnp_devmatch(aux, &isapnp_cs_devinfo, &variant);
     78 	if (pri && variant > 0)
     79 		pri = 0;
     80 	return pri;
     81 }
     82 
     83 void
     84 cs_isapnp_attach(parent, self, aux)
     85 	struct device *parent, *self;
     86 	void *aux;
     87 {
     88 	struct cs_softc *sc = (void *)self;
     89 	struct isapnp_attach_args *ipa = aux;
     90 #ifdef notyet
     91 	struct cs_softc_isa *isc = (void *)sc;
     92 	int i;
     93 #endif
     94 
     95 	printf("\n");
     96 
     97 	if (ipa->ipa_nio != 1 || ipa->ipa_nirq != 1 || ipa->ipa_ndrq) {
     98 		printf("%s: unexpected resource requirements\n",
     99 			DEVNAME(sc));
    100 		return;
    101 	}
    102 
    103 	if (ipa->ipa_io[0].length != CS8900_IOSIZE) {
    104 		printf("%s: unexpected io size\n", DEVNAME(sc));
    105 		return;
    106 	}
    107 
    108 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    109 		printf("%s: unable to allocate resources\n", DEVNAME(sc));
    110 		return;
    111 	}
    112 
    113 	printf("%s: %s %s\n", DEVNAME(sc), ipa->ipa_devident,
    114 		ipa->ipa_devclass);
    115 
    116 #ifdef notyet
    117 #ifdef DEBUG
    118 	printf("%s: nio=%u, nmem=%u, nmem32=%u, ndrq=%u, nirq=%u\n", DEVNAME(sc),
    119 		ipa->ipa_nio, ipa->ipa_nmem, ipa->ipa_nmem32, ipa->ipa_ndrq, ipa->ipa_nirq);
    120 #endif
    121 	isc->sc_ic = ipa->ipa_ic;
    122 	isc->sc_drq = ISACF_DRQ_DEFAULT;
    123 #endif
    124 	sc->sc_iot = ipa->ipa_iot;
    125 	sc->sc_ioh = ipa->ipa_io[0].h;
    126 	sc->sc_irq = ipa->ipa_irq[0].num;
    127 
    128 #ifdef notyet
    129 	for (i = 0; i < ipa->ipa_nmem; i++) {
    130 		if (ipa->ipa_mem[i].length == CS8900_MEMSIZE) {
    131 #if 0
    132 			u_int16_t id;
    133 
    134 			id = CS_READ_PACKET_PAGE_MEM(sc, PKTPG_EISA_NUM);
    135 			if (id != EISA_NUM_CRYSTAL) {
    136 				printf("%s: unexpected id(%u)\n",
    137 					 DEVNAME(sc), id);
    138 				continue;
    139 			}
    140 			printf("%s: correct id(%u) from mem=%u\n",
    141 				 DEVNAME(sc), id, (u_int)ipa->ipa_mem[i].h);
    142 #endif
    143 
    144 			sc->sc_memt = ipa->ipa_memt;
    145 			sc->sc_memh = ipa->ipa_mem[i].h;
    146 			sc->sc_pktpgaddr = ipa->ipa_mem[i].base;
    147 			sc->sc_cfgflags |= CFGFLG_MEM_MODE;
    148 			printf("%s: memory mode\n", DEVNAME(sc));
    149 			break;
    150 		}
    151 	}
    152 #endif
    153 
    154 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    155 		ipa->ipa_irq[0].type, IPL_NET, cs_intr, sc);
    156 	if (sc->sc_ih == 0) {
    157 		printf("%s: unable to establish interrupt\n",
    158 			DEVNAME(sc));
    159 		goto fail;
    160 	}
    161 
    162 	if (cs_attach(sc, 0, 0, 0, 0)) {
    163 		printf("%s: unable to attach\n", DEVNAME(sc));
    164 		goto fail;
    165 	}
    166 
    167 	return;
    168 
    169 fail:
    170 	if (sc->sc_ih)
    171 		isa_intr_disestablish(ipa->ipa_ic, sc->sc_ih);
    172 	isapnp_unconfig(ipa->ipa_iot, ipa->ipa_memt, ipa);
    173 }
    174