Home | History | Annotate | Line # | Download | only in isapnp
wdc_isapnp.c revision 1.2.2.4
      1 /*	$NetBSD: wdc_isapnp.c,v 1.2.2.4 1998/07/27 19:02:47 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Charles M. Hannum.  All rights reserved.
      5  *
      6  * DMA and multi-sector PIO handling are derived from code contributed by
      7  * Onno van der Linden.
      8  *
      9  * ISA attachment created by Christopher G. Demetriou.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by Charles M. Hannum.
     22  * 4. The name of the author may not be used to endorse or promote products
     23  *    derived from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35  */
     36 
     37 #include <sys/types.h>
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/device.h>
     41 #include <sys/malloc.h>
     42 
     43 #include <machine/bus.h>
     44 #include <machine/intr.h>
     45 
     46 #include <dev/isa/isavar.h>
     47 #include <dev/isa/isadmavar.h>
     48 
     49 #include <dev/isapnp/isapnpreg.h>
     50 #include <dev/isapnp/isapnpvar.h>
     51 #include <dev/isapnp/isapnpdevs.h>
     52 
     53 #include <dev/ata/atavar.h>
     54 #include <dev/ic/wdcreg.h>
     55 #include <dev/ic/wdcvar.h>
     56 
     57 struct wdc_isapnp_softc {
     58 	struct	wdc_softc sc_wdcdev;
     59 	struct	channel_softc wdc_channel;
     60 	isa_chipset_tag_t sc_ic;
     61 	void	*sc_ih;
     62 	int	sc_drq;
     63 };
     64 
     65 int	wdc_isapnp_probe 	__P((struct device *, struct cfdata *, void *));
     66 void	wdc_isapnp_attach 	__P((struct device *, struct device *, void *));
     67 
     68 struct cfattach wdc_isapnp_ca = {
     69 	sizeof(struct wdc_isapnp_softc), wdc_isapnp_probe, wdc_isapnp_attach
     70 };
     71 
     72 #ifdef notyet
     73 static void	wdc_isapnp_dma_setup __P((struct wdc_isapnp_softc *));
     74 static void	wdc_isapnp_dma_start __P((void *, void *, size_t, int));
     75 static void	wdc_isapnp_dma_finish __P((void *));
     76 #endif
     77 
     78 int
     79 wdc_isapnp_probe(parent, match, aux)
     80 	struct device *parent;
     81 	struct cfdata *match;
     82 	void *aux;
     83 {
     84 	return isapnp_devmatch(aux, &isapnp_wdc_devinfo);
     85 }
     86 
     87 void
     88 wdc_isapnp_attach(parent, self, aux)
     89 	struct device *parent, *self;
     90 	void *aux;
     91 {
     92 	struct wdc_isapnp_softc *sc = (void *)self;
     93 	struct isapnp_attach_args *ipa = aux;
     94 
     95 	printf("\n");
     96 
     97 	if (ipa->ipa_nio != 2 ||
     98 	    ipa->ipa_nmem != 0 ||
     99 	    ipa->ipa_nmem32 != 0 ||
    100 	    ipa->ipa_nirq != 1 ||
    101 	    ipa->ipa_ndrq > 1) {
    102 		printf("%s: unexpected configuration\n",
    103 		    sc->sc_wdcdev.sc_dev.dv_xname);
    104 		return;
    105 	}
    106 
    107 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    108 		printf("%s: couldn't map registers\n",
    109 		    sc->sc_wdcdev.sc_dev.dv_xname);
    110 		return;
    111 	}
    112 
    113 	printf("%s: %s %s\n", sc->sc_wdcdev.sc_dev.dv_xname, ipa->ipa_devident,
    114 	    ipa->ipa_devclass);
    115 
    116 	sc->wdc_channel.cmd_iot = ipa->ipa_iot;
    117 	sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
    118 	sc->wdc_channel.ctl_iot = ipa->ipa_iot;
    119 	sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
    120 	sc->sc_ic = ipa->ipa_ic;
    121 
    122 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    123 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel);
    124 
    125 #ifdef notyet
    126 	if (ipa->ipa_ndrq > 0) {
    127 		sc->sc_drq = ipa->ipa_drq[0].num;
    128 
    129 		sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
    130 		sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
    131 		sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
    132 		wdc_isapnp_dma_setup(sc);
    133 	}
    134 #endif
    135 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
    136 	sc->sc_wdcdev.pio_mode = 0;
    137 	sc->sc_wdcdev.channels = &sc->wdc_channel;
    138 	sc->sc_wdcdev.nchannels = 1;
    139 	sc->wdc_channel.channel = 0;
    140 	sc->wdc_channel.wdc = &sc->sc_wdcdev;
    141 	sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
    142 	    M_DEVBUF, M_NOWAIT);
    143 	if (sc->wdc_channel.ch_queue == NULL) {
    144 	    printf("%s: can't allocate memory for command queue",
    145 		sc->sc_wdcdev.sc_dev.dv_xname);
    146 	    return;
    147 	}
    148 	wdcattach(&sc->wdc_channel);
    149 }
    150 
    151 #ifdef notyet
    152 static void
    153 wdc_isapnp_dma_setup(sc)
    154 	struct wdc_isapnp_softc *sc;
    155 {
    156 
    157 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    158 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    159 		printf("%s: can't create map for drq %d\n",
    160 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    161 		sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
    162 	}
    163 }
    164 
    165 static void
    166 wdc_isapnp_dma_start(scv, buf, size, read)
    167 	void *scv, *buf;
    168 	size_t size;
    169 	int read;
    170 {
    171 	struct wdc_isapnp_softc *sc = scv;
    172 
    173 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf,
    174 	    size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
    175 	    BUS_DMA_NOWAIT);
    176 }
    177 
    178 static void
    179 wdc_isapnp_dma_finish(scv)
    180 	void *scv;
    181 {
    182 	struct wdc_isapnp_softc *sc = scv;
    183 
    184 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    185 }
    186 #endif
    187