Home | History | Annotate | Line # | Download | only in isapnp
aha_isapnp.c revision 1.2
      1 /*	$NetBSD: aha_isapnp.c,v 1.2 1999/03/22 09:44:13 mycroft Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Christos Zoulas.
      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 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/conf.h>
     42 #include <sys/device.h>
     43 
     44 #include <machine/bus.h>
     45 
     46 #include <dev/scsipi/scsi_all.h>
     47 #include <dev/scsipi/scsipi_all.h>
     48 #include <dev/scsipi/scsiconf.h>
     49 
     50 #include <dev/isa/isavar.h>
     51 
     52 #include <dev/isapnp/isapnpreg.h>
     53 #include <dev/isapnp/isapnpvar.h>
     54 #include <dev/isapnp/isapnpdevs.h>
     55 
     56 
     57 #include <dev/ic/ahareg.h>
     58 #include <dev/ic/ahavar.h>
     59 
     60 int	aha_isapnp_probe __P((struct device *, struct cfdata *, void *));
     61 void	aha_isapnp_attach __P((struct device *, struct device *, void *));
     62 
     63 struct cfattach aha_isapnp_ca = {
     64 	sizeof(struct aha_softc), aha_isapnp_probe, aha_isapnp_attach
     65 };
     66 
     67 int
     68 aha_isapnp_probe(parent, match, aux)
     69 	struct device *parent;
     70 	struct cfdata *match;
     71 	void *aux;
     72 {
     73 	int variant;
     74 
     75 	return (isapnp_devmatch(aux, &isapnp_aha_devinfo, &variant));
     76 }
     77 
     78 void
     79 aha_isapnp_attach(parent, self, aux)
     80 	struct device *parent, *self;
     81 	void *aux;
     82 {
     83 	struct aha_softc *sc = (void *)self;
     84 	struct aha_probe_data apd;
     85 	struct isapnp_attach_args *ipa = aux;
     86 
     87 	printf("\n");
     88 
     89 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
     90 		printf("%s: error in region allocation\n",
     91 		    sc->sc_dev.dv_xname);
     92 		return;
     93 	}
     94 
     95 	sc->sc_iot = ipa->ipa_iot;
     96 	sc->sc_ioh = ipa->ipa_io[0].h;
     97 	sc->sc_dmat = ipa->ipa_dmat;
     98 
     99 	if (!aha_find(sc->sc_iot, sc->sc_ioh, &apd)) {
    100 		printf("%s: aha_find failed\n", sc->sc_dev.dv_xname);
    101 		return;
    102 	}
    103 
    104 	if (ipa->ipa_ndrq == 0) {
    105 		if (apd.sc_drq != -1) {
    106 			printf("%s: no PnP drq, but card has one\n",
    107 			    sc->sc_dev.dv_xname);
    108 			return;
    109 		}
    110 	} else if (apd.sc_drq != ipa->ipa_drq[0].num) {
    111 		printf("%s: card drq # (%d) != PnP # (%d)\n",
    112 		    sc->sc_dev.dv_xname, apd.sc_drq, ipa->ipa_drq[0].num);
    113 		return;
    114 	} else {
    115 		int error = isa_dmacascade(ipa->ipa_ic, ipa->ipa_drq[0].num);
    116 		if (error) {
    117 			printf("%s: unable to cascade DRQ, error = %d\n",
    118 			    sc->sc_dev.dv_xname, error);
    119 			return;
    120 		}
    121 	}
    122 
    123 	if (apd.sc_irq != ipa->ipa_irq[0].num) {
    124 		printf("%s: card irq # (%d) != PnP # (%d)\n",
    125 		    sc->sc_dev.dv_xname, apd.sc_irq, ipa->ipa_irq[0].num);
    126 		return;
    127 	}
    128 
    129 
    130 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    131 	    ipa->ipa_irq[0].type, IPL_BIO, aha_intr, sc);
    132 
    133 	if (sc->sc_ih == NULL) {
    134 		printf("%s: couldn't establish interrupt\n",
    135 		    sc->sc_dev.dv_xname);
    136 		return;
    137 	}
    138 
    139 	aha_attach(sc, &apd);
    140 }
    141