Home | History | Annotate | Line # | Download | only in isapnp
      1 /*	$NetBSD: aic_isapnp.c,v 1.21 2009/09/22 13:20:36 tsutsui 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 Enami Tsugutomo <enami (at) but-b.or.jp>
      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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: aic_isapnp.c,v 1.21 2009/09/22 13:20:36 tsutsui Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 
     39 #include <sys/bus.h>
     40 
     41 #include <dev/isa/isavar.h>
     42 
     43 #include <dev/isapnp/isapnpreg.h>
     44 #include <dev/isapnp/isapnpvar.h>
     45 #include <dev/isapnp/isapnpdevs.h>
     46 
     47 #include <dev/scsipi/scsipi_all.h>
     48 #include <dev/scsipi/scsipiconf.h>
     49 #include <dev/scsipi/scsi_all.h>
     50 
     51 #include <dev/ic/aic6360var.h>
     52 
     53 struct aic_isapnp_softc {
     54 	struct	aic_softc sc_aic;	/* real "com" softc */
     55 
     56 	/* ISAPnP-specific goo. */
     57 	void	*sc_ih;			/* interrupt handler */
     58 };
     59 
     60 static int	aic_isapnp_match(device_t, cfdata_t, void *);
     61 static void	aic_isapnp_attach(device_t, device_t, void *);
     62 
     63 CFATTACH_DECL_NEW(aic_isapnp, sizeof(struct aic_isapnp_softc),
     64     aic_isapnp_match, aic_isapnp_attach, NULL, NULL);
     65 
     66 int
     67 aic_isapnp_match(device_t parent, cfdata_t match, void *aux)
     68 {
     69 	int pri, variant;
     70 
     71 	pri = isapnp_devmatch(aux, &isapnp_aic_devinfo, &variant);
     72 	if (pri && variant > 0)
     73 		pri = 0;
     74 	return (pri);
     75 }
     76 
     77 void
     78 aic_isapnp_attach(device_t parent, device_t self, void *aux)
     79 {
     80 	struct aic_isapnp_softc *isc = device_private(self);
     81 	struct aic_softc *sc = &isc->sc_aic;
     82 	struct isapnp_attach_args *ipa = aux;
     83 
     84 	sc->sc_dev = self;
     85 
     86 	printf("\n");
     87 
     88 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
     89 		aprint_error_dev(self, "error in region allocation\n");
     90 		return;
     91 	}
     92 
     93 	sc->sc_iot = ipa->ipa_iot;
     94 	sc->sc_ioh = ipa->ipa_io[0].h;
     95 
     96 	if (!aic_find(sc->sc_iot, sc->sc_ioh)) {
     97 		aprint_error_dev(self, "couldn't find device\n");
     98 		return;
     99 	}
    100 
    101 	aicattach(sc);
    102 
    103 	/* Establish the interrupt handler. */
    104 	isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    105 	    ipa->ipa_irq[0].type, IPL_BIO, aicintr, sc);
    106 	if (isc->sc_ih == NULL)
    107 		aprint_error_dev(self, "couldn't establish interrupt\n");
    108 }
    109