Home | History | Annotate | Line # | Download | only in isapnp
aha_isapnp.c revision 1.2
      1  1.2   mycroft /*	$NetBSD: aha_isapnp.c,v 1.2 1999/03/22 09:44:13 mycroft Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*-
      4  1.1  christos  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.1  christos  * All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  christos  * by Christos Zoulas.
      9  1.1  christos  *
     10  1.1  christos  * Redistribution and use in source and binary forms, with or without
     11  1.1  christos  * modification, are permitted provided that the following conditions
     12  1.1  christos  * are met:
     13  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  christos  *    documentation and/or other materials provided with the distribution.
     18  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     19  1.1  christos  *    must display the following acknowledgement:
     20  1.1  christos  *        This product includes software developed by the NetBSD
     21  1.1  christos  *        Foundation, Inc. and its contributors.
     22  1.1  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  christos  *    contributors may be used to endorse or promote products derived
     24  1.1  christos  *    from this software without specific prior written permission.
     25  1.1  christos  *
     26  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  christos  */
     38  1.1  christos 
     39  1.1  christos #include <sys/param.h>
     40  1.1  christos #include <sys/systm.h>
     41  1.1  christos #include <sys/conf.h>
     42  1.1  christos #include <sys/device.h>
     43  1.1  christos 
     44  1.1  christos #include <machine/bus.h>
     45  1.1  christos 
     46  1.1  christos #include <dev/scsipi/scsi_all.h>
     47  1.1  christos #include <dev/scsipi/scsipi_all.h>
     48  1.1  christos #include <dev/scsipi/scsiconf.h>
     49  1.1  christos 
     50  1.1  christos #include <dev/isa/isavar.h>
     51  1.1  christos 
     52  1.1  christos #include <dev/isapnp/isapnpreg.h>
     53  1.1  christos #include <dev/isapnp/isapnpvar.h>
     54  1.1  christos #include <dev/isapnp/isapnpdevs.h>
     55  1.1  christos 
     56  1.1  christos 
     57  1.1  christos #include <dev/ic/ahareg.h>
     58  1.1  christos #include <dev/ic/ahavar.h>
     59  1.1  christos 
     60  1.1  christos int	aha_isapnp_probe __P((struct device *, struct cfdata *, void *));
     61  1.1  christos void	aha_isapnp_attach __P((struct device *, struct device *, void *));
     62  1.1  christos 
     63  1.1  christos struct cfattach aha_isapnp_ca = {
     64  1.1  christos 	sizeof(struct aha_softc), aha_isapnp_probe, aha_isapnp_attach
     65  1.1  christos };
     66  1.1  christos 
     67  1.1  christos int
     68  1.1  christos aha_isapnp_probe(parent, match, aux)
     69  1.1  christos 	struct device *parent;
     70  1.1  christos 	struct cfdata *match;
     71  1.1  christos 	void *aux;
     72  1.1  christos {
     73  1.2   mycroft 	int variant;
     74  1.2   mycroft 
     75  1.2   mycroft 	return (isapnp_devmatch(aux, &isapnp_aha_devinfo, &variant));
     76  1.1  christos }
     77  1.1  christos 
     78  1.1  christos void
     79  1.1  christos aha_isapnp_attach(parent, self, aux)
     80  1.1  christos 	struct device *parent, *self;
     81  1.1  christos 	void *aux;
     82  1.1  christos {
     83  1.1  christos 	struct aha_softc *sc = (void *)self;
     84  1.1  christos 	struct aha_probe_data apd;
     85  1.1  christos 	struct isapnp_attach_args *ipa = aux;
     86  1.1  christos 
     87  1.1  christos 	printf("\n");
     88  1.1  christos 
     89  1.1  christos 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
     90  1.1  christos 		printf("%s: error in region allocation\n",
     91  1.1  christos 		    sc->sc_dev.dv_xname);
     92  1.1  christos 		return;
     93  1.1  christos 	}
     94  1.1  christos 
     95  1.1  christos 	sc->sc_iot = ipa->ipa_iot;
     96  1.1  christos 	sc->sc_ioh = ipa->ipa_io[0].h;
     97  1.1  christos 	sc->sc_dmat = ipa->ipa_dmat;
     98  1.1  christos 
     99  1.1  christos 	if (!aha_find(sc->sc_iot, sc->sc_ioh, &apd)) {
    100  1.1  christos 		printf("%s: aha_find failed\n", sc->sc_dev.dv_xname);
    101  1.1  christos 		return;
    102  1.1  christos 	}
    103  1.1  christos 
    104  1.1  christos 	if (ipa->ipa_ndrq == 0) {
    105  1.1  christos 		if (apd.sc_drq != -1) {
    106  1.1  christos 			printf("%s: no PnP drq, but card has one\n",
    107  1.1  christos 			    sc->sc_dev.dv_xname);
    108  1.1  christos 			return;
    109  1.1  christos 		}
    110  1.1  christos 	} else if (apd.sc_drq != ipa->ipa_drq[0].num) {
    111  1.1  christos 		printf("%s: card drq # (%d) != PnP # (%d)\n",
    112  1.1  christos 		    sc->sc_dev.dv_xname, apd.sc_drq, ipa->ipa_drq[0].num);
    113  1.1  christos 		return;
    114  1.1  christos 	} else {
    115  1.1  christos 		int error = isa_dmacascade(ipa->ipa_ic, ipa->ipa_drq[0].num);
    116  1.1  christos 		if (error) {
    117  1.1  christos 			printf("%s: unable to cascade DRQ, error = %d\n",
    118  1.1  christos 			    sc->sc_dev.dv_xname, error);
    119  1.1  christos 			return;
    120  1.1  christos 		}
    121  1.1  christos 	}
    122  1.1  christos 
    123  1.1  christos 	if (apd.sc_irq != ipa->ipa_irq[0].num) {
    124  1.1  christos 		printf("%s: card irq # (%d) != PnP # (%d)\n",
    125  1.1  christos 		    sc->sc_dev.dv_xname, apd.sc_irq, ipa->ipa_irq[0].num);
    126  1.1  christos 		return;
    127  1.1  christos 	}
    128  1.1  christos 
    129  1.1  christos 
    130  1.1  christos 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    131  1.1  christos 	    ipa->ipa_irq[0].type, IPL_BIO, aha_intr, sc);
    132  1.1  christos 
    133  1.1  christos 	if (sc->sc_ih == NULL) {
    134  1.1  christos 		printf("%s: couldn't establish interrupt\n",
    135  1.1  christos 		    sc->sc_dev.dv_xname);
    136  1.1  christos 		return;
    137  1.1  christos 	}
    138  1.1  christos 
    139  1.1  christos 	aha_attach(sc, &apd);
    140  1.1  christos }
    141