Home | History | Annotate | Line # | Download | only in isapnp
      1  1.20   msaitoh /*	$NetBSD: aha_isapnp.c,v 1.20 2016/07/14 10:19:06 msaitoh 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  *
     19   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1  christos  */
     31   1.4     lukem 
     32   1.4     lukem #include <sys/cdefs.h>
     33  1.20   msaitoh __KERNEL_RCSID(0, "$NetBSD: aha_isapnp.c,v 1.20 2016/07/14 10:19:06 msaitoh Exp $");
     34   1.1  christos 
     35   1.1  christos #include <sys/param.h>
     36   1.1  christos #include <sys/systm.h>
     37   1.1  christos #include <sys/conf.h>
     38   1.1  christos #include <sys/device.h>
     39   1.1  christos 
     40  1.13        ad #include <sys/bus.h>
     41   1.1  christos 
     42   1.1  christos #include <dev/scsipi/scsi_all.h>
     43   1.1  christos #include <dev/scsipi/scsipi_all.h>
     44   1.1  christos #include <dev/scsipi/scsiconf.h>
     45   1.1  christos 
     46   1.1  christos #include <dev/isa/isavar.h>
     47   1.1  christos 
     48   1.1  christos #include <dev/isapnp/isapnpreg.h>
     49   1.1  christos #include <dev/isapnp/isapnpvar.h>
     50   1.1  christos #include <dev/isapnp/isapnpdevs.h>
     51   1.1  christos 
     52   1.1  christos 
     53   1.1  christos #include <dev/ic/ahareg.h>
     54   1.1  christos #include <dev/ic/ahavar.h>
     55   1.1  christos 
     56  1.19   tsutsui static int	aha_isapnp_probe(device_t, cfdata_t, void *);
     57  1.19   tsutsui static void	aha_isapnp_attach(device_t, device_t, void *);
     58   1.1  christos 
     59  1.18   tsutsui CFATTACH_DECL_NEW(aha_isapnp, sizeof(struct aha_softc),
     60   1.7   thorpej     aha_isapnp_probe, aha_isapnp_attach, NULL, NULL);
     61   1.1  christos 
     62   1.1  christos int
     63  1.17    cegger aha_isapnp_probe(device_t parent, cfdata_t match, void *aux)
     64   1.1  christos {
     65   1.3   mycroft 	int pri, variant;
     66   1.2   mycroft 
     67   1.3   mycroft 	pri = isapnp_devmatch(aux, &isapnp_aha_devinfo, &variant);
     68   1.3   mycroft 	if (pri && variant > 0)
     69   1.3   mycroft 		pri = 0;
     70   1.3   mycroft 	return (pri);
     71   1.1  christos }
     72   1.1  christos 
     73   1.1  christos void
     74  1.17    cegger aha_isapnp_attach(device_t parent, device_t self, void *aux)
     75   1.1  christos {
     76  1.10   thorpej 	struct aha_softc *sc = device_private(self);
     77   1.1  christos 	struct aha_probe_data apd;
     78   1.1  christos 	struct isapnp_attach_args *ipa = aux;
     79   1.1  christos 
     80  1.18   tsutsui 	sc->sc_dev = self;
     81  1.18   tsutsui 
     82   1.1  christos 	printf("\n");
     83   1.1  christos 
     84   1.1  christos 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
     85  1.18   tsutsui 		aprint_error_dev(self, "error in region allocation\n");
     86   1.1  christos 		return;
     87   1.1  christos 	}
     88   1.1  christos 
     89   1.1  christos 	sc->sc_iot = ipa->ipa_iot;
     90   1.1  christos 	sc->sc_ioh = ipa->ipa_io[0].h;
     91   1.1  christos 	sc->sc_dmat = ipa->ipa_dmat;
     92   1.1  christos 
     93   1.1  christos 	if (!aha_find(sc->sc_iot, sc->sc_ioh, &apd)) {
     94  1.18   tsutsui 		aprint_error_dev(self, "aha_find failed\n");
     95   1.1  christos 		return;
     96   1.1  christos 	}
     97   1.1  christos 
     98   1.1  christos 	if (ipa->ipa_ndrq == 0) {
     99   1.1  christos 		if (apd.sc_drq != -1) {
    100  1.20   msaitoh 			aprint_error_dev(self,
    101  1.20   msaitoh 			    "no PnP drq, but card has one\n");
    102   1.1  christos 			return;
    103   1.1  christos 		}
    104   1.1  christos 	} else if (apd.sc_drq != ipa->ipa_drq[0].num) {
    105  1.20   msaitoh 		aprint_error_dev(self, "card drq # (%d) != PnP # (%d)\n",
    106  1.20   msaitoh 		    apd.sc_drq, ipa->ipa_drq[0].num);
    107   1.1  christos 		return;
    108   1.1  christos 	} else {
    109   1.1  christos 		int error = isa_dmacascade(ipa->ipa_ic, ipa->ipa_drq[0].num);
    110   1.1  christos 		if (error) {
    111  1.18   tsutsui 			aprint_error_dev(self,
    112  1.18   tsutsui 			    "unable to cascade DRQ, error = %d\n", error);
    113   1.1  christos 			return;
    114   1.1  christos 		}
    115   1.1  christos 	}
    116   1.1  christos 
    117   1.1  christos 	if (apd.sc_irq != ipa->ipa_irq[0].num) {
    118  1.20   msaitoh 		aprint_error_dev(self, "card irq # (%d) != PnP # (%d)\n",
    119  1.20   msaitoh 		    apd.sc_irq, ipa->ipa_irq[0].num);
    120   1.1  christos 		return;
    121   1.1  christos 	}
    122   1.1  christos 
    123   1.1  christos 
    124   1.1  christos 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    125   1.1  christos 	    ipa->ipa_irq[0].type, IPL_BIO, aha_intr, sc);
    126   1.1  christos 
    127   1.1  christos 	if (sc->sc_ih == NULL) {
    128  1.18   tsutsui 		aprint_error_dev(self, "couldn't establish interrupt\n");
    129   1.1  christos 		return;
    130   1.1  christos 	}
    131   1.1  christos 
    132   1.1  christos 	aha_attach(sc, &apd);
    133   1.1  christos }
    134