Home | History | Annotate | Line # | Download | only in isapnp
wdc_isapnp.c revision 1.19.2.4
      1  1.19.2.4     skrll /*	$NetBSD: wdc_isapnp.c,v 1.19.2.4 2004/09/21 13:30:16 skrll Exp $	*/
      2       1.1   mycroft 
      3       1.6   mycroft /*-
      4  1.19.2.1     skrll  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
      5       1.6   mycroft  * All rights reserved.
      6       1.1   mycroft  *
      7       1.6   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8       1.6   mycroft  * by Charles M. Hannum and by Onno van der Linden.
      9       1.1   mycroft  *
     10       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     11       1.1   mycroft  * modification, are permitted provided that the following conditions
     12       1.1   mycroft  * are met:
     13       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     14       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     15       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     18       1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     19       1.1   mycroft  *    must display the following acknowledgement:
     20       1.6   mycroft  *        This product includes software developed by the NetBSD
     21       1.6   mycroft  *        Foundation, Inc. and its contributors.
     22       1.6   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.6   mycroft  *    contributors may be used to endorse or promote products derived
     24       1.6   mycroft  *    from this software without specific prior written permission.
     25       1.1   mycroft  *
     26       1.6   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.6   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.6   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.6   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.6   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.6   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.6   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.6   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.6   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.6   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.6   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   mycroft  */
     38      1.14     lukem 
     39      1.14     lukem #include <sys/cdefs.h>
     40  1.19.2.4     skrll __KERNEL_RCSID(0, "$NetBSD: wdc_isapnp.c,v 1.19.2.4 2004/09/21 13:30:16 skrll Exp $");
     41       1.1   mycroft 
     42       1.1   mycroft #include <sys/param.h>
     43       1.1   mycroft #include <sys/systm.h>
     44       1.1   mycroft #include <sys/device.h>
     45       1.8    bouyer #include <sys/malloc.h>
     46       1.1   mycroft 
     47       1.1   mycroft #include <machine/bus.h>
     48       1.1   mycroft #include <machine/intr.h>
     49       1.1   mycroft 
     50       1.1   mycroft #include <dev/isa/isavar.h>
     51       1.1   mycroft #include <dev/isa/isadmavar.h>
     52       1.1   mycroft 
     53       1.1   mycroft #include <dev/isapnp/isapnpreg.h>
     54       1.1   mycroft #include <dev/isapnp/isapnpvar.h>
     55       1.5  christos #include <dev/isapnp/isapnpdevs.h>
     56       1.1   mycroft 
     57       1.8    bouyer #include <dev/ata/atavar.h>
     58       1.1   mycroft #include <dev/ic/wdcreg.h>
     59       1.1   mycroft #include <dev/ic/wdcvar.h>
     60       1.1   mycroft 
     61       1.1   mycroft struct wdc_isapnp_softc {
     62       1.1   mycroft 	struct	wdc_softc sc_wdcdev;
     63  1.19.2.2     skrll 	struct	ata_channel *wdc_chanlist[1];
     64  1.19.2.2     skrll 	struct	ata_channel ata_channel;
     65  1.19.2.1     skrll 	struct	ata_queue wdc_chqueue;
     66  1.19.2.2     skrll 	struct	wdc_regs wdc_regs;
     67       1.3   thorpej 	isa_chipset_tag_t sc_ic;
     68       1.1   mycroft 	void	*sc_ih;
     69       1.1   mycroft 	int	sc_drq;
     70       1.1   mycroft };
     71       1.1   mycroft 
     72  1.19.2.2     skrll static int	wdc_isapnp_probe(struct device *, struct cfdata *, void *);
     73  1.19.2.2     skrll static void	wdc_isapnp_attach(struct device *, struct device *, void *);
     74       1.1   mycroft 
     75      1.17   thorpej CFATTACH_DECL(wdc_isapnp, sizeof(struct wdc_isapnp_softc),
     76      1.18   thorpej     wdc_isapnp_probe, wdc_isapnp_attach, NULL, NULL);
     77       1.1   mycroft 
     78       1.1   mycroft #ifdef notyet
     79  1.19.2.2     skrll static void	wdc_isapnp_dma_setup(struct wdc_isapnp_softc *);
     80  1.19.2.2     skrll static void	wdc_isapnp_dma_start(void *, void *, size_t, int);
     81  1.19.2.2     skrll static void	wdc_isapnp_dma_finish(void *);
     82       1.1   mycroft #endif
     83       1.1   mycroft 
     84  1.19.2.2     skrll static int
     85  1.19.2.2     skrll wdc_isapnp_probe(struct device *parent, struct cfdata *match, void *aux)
     86       1.1   mycroft {
     87      1.13   mycroft 	int pri, variant;
     88      1.12   mycroft 
     89      1.13   mycroft 	pri = isapnp_devmatch(aux, &isapnp_wdc_devinfo, &variant);
     90      1.13   mycroft 	if (pri && variant > 0)
     91      1.13   mycroft 		pri = 0;
     92      1.13   mycroft 	return (pri);
     93       1.1   mycroft }
     94       1.1   mycroft 
     95  1.19.2.2     skrll static void
     96  1.19.2.2     skrll wdc_isapnp_attach(struct device *parent, struct device *self, void *aux)
     97       1.1   mycroft {
     98       1.1   mycroft 	struct wdc_isapnp_softc *sc = (void *)self;
     99  1.19.2.2     skrll 	struct wdc_regs *wdr;
    100       1.1   mycroft 	struct isapnp_attach_args *ipa = aux;
    101  1.19.2.1     skrll 	int i;
    102       1.1   mycroft 
    103       1.1   mycroft 	if (ipa->ipa_nio != 2 ||
    104       1.1   mycroft 	    ipa->ipa_nmem != 0 ||
    105       1.1   mycroft 	    ipa->ipa_nmem32 != 0 ||
    106       1.1   mycroft 	    ipa->ipa_nirq != 1 ||
    107       1.1   mycroft 	    ipa->ipa_ndrq > 1) {
    108      1.19      matt 		printf(": unexpected configuration\n");
    109       1.1   mycroft 		return;
    110       1.1   mycroft 	}
    111       1.1   mycroft 
    112       1.1   mycroft 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    113      1.19      matt 		printf(": couldn't map registers\n");
    114       1.1   mycroft 		return;
    115       1.1   mycroft 	}
    116       1.1   mycroft 
    117      1.19      matt 	printf(": %s %s\n", ipa->ipa_devident, ipa->ipa_devclass);
    118       1.1   mycroft 
    119  1.19.2.2     skrll 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    120  1.19.2.2     skrll 	wdr->cmd_iot = ipa->ipa_iot;
    121  1.19.2.2     skrll 	wdr->ctl_iot = ipa->ipa_iot;
    122       1.7  wrstuden 	/*
    123       1.7  wrstuden 	 * An IDE controller can feed us the regions in any order. Pass
    124       1.7  wrstuden 	 * them along with the 8-byte region in sc_ad.ioh, and the other
    125       1.7  wrstuden 	 * (2 byte) region in auxioh.
    126       1.7  wrstuden 	 */
    127       1.7  wrstuden 	if (ipa->ipa_io[0].length == 8) {
    128  1.19.2.2     skrll 		wdr->cmd_baseioh = ipa->ipa_io[0].h;
    129  1.19.2.2     skrll 		wdr->ctl_ioh = ipa->ipa_io[1].h;
    130       1.7  wrstuden 	} else {
    131  1.19.2.2     skrll 		wdr->cmd_baseioh = ipa->ipa_io[1].h;
    132  1.19.2.2     skrll 		wdr->ctl_ioh = ipa->ipa_io[0].h;
    133       1.7  wrstuden 	}
    134  1.19.2.1     skrll 
    135  1.19.2.1     skrll 	for (i = 0; i < WDC_NREG; i++) {
    136  1.19.2.2     skrll 		if (bus_space_subregion(wdr->cmd_iot,
    137  1.19.2.2     skrll 		    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
    138  1.19.2.2     skrll 		    &wdr->cmd_iohs[i]) != 0) {
    139  1.19.2.1     skrll 			printf(": couldn't subregion registers\n");
    140  1.19.2.1     skrll 			return;
    141  1.19.2.1     skrll 		}
    142  1.19.2.1     skrll 	}
    143  1.19.2.2     skrll 	wdc_init_shadow_regs(&sc->ata_channel);
    144  1.19.2.2     skrll 	wdr->data32iot = wdr->cmd_iot;
    145  1.19.2.2     skrll 	wdr->data32ioh = wdr->cmd_iohs[0];
    146       1.8    bouyer 
    147       1.3   thorpej 	sc->sc_ic = ipa->ipa_ic;
    148       1.1   mycroft 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    149  1.19.2.2     skrll 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->ata_channel);
    150       1.1   mycroft 
    151       1.1   mycroft #ifdef notyet
    152       1.1   mycroft 	if (ipa->ipa_ndrq > 0) {
    153       1.1   mycroft 		sc->sc_drq = ipa->ipa_drq[0].num;
    154       1.1   mycroft 
    155  1.19.2.2     skrll 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    156  1.19.2.2     skrll 		sc->sc_wdcdev.dma_start = &wdc_isapnp_dma_start;
    157  1.19.2.2     skrll 		sc->sc_wdcdev.dma_finish = &wdc_isapnp_dma_finish;
    158       1.8    bouyer 		wdc_isapnp_dma_setup(sc);
    159       1.1   mycroft 	}
    160       1.1   mycroft #endif
    161  1.19.2.2     skrll 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    162  1.19.2.2     skrll 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    163  1.19.2.2     skrll 	sc->wdc_chanlist[0] = &sc->ata_channel;
    164  1.19.2.2     skrll 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    165  1.19.2.2     skrll 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    166  1.19.2.2     skrll 	sc->ata_channel.ch_channel = 0;
    167  1.19.2.2     skrll 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    168  1.19.2.2     skrll 	sc->ata_channel.ch_queue = &sc->wdc_chqueue;
    169  1.19.2.1     skrll 
    170  1.19.2.2     skrll 	wdcattach(&sc->ata_channel);
    171       1.1   mycroft }
    172       1.1   mycroft 
    173       1.1   mycroft #ifdef notyet
    174       1.1   mycroft static void
    175  1.19.2.2     skrll wdc_isapnp_dma_setup(struct wdc_isapnp_softc *sc)
    176       1.1   mycroft {
    177       1.1   mycroft 
    178       1.3   thorpej 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    179       1.1   mycroft 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    180       1.1   mycroft 		printf("%s: can't create map for drq %d\n",
    181       1.1   mycroft 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    182  1.19.2.2     skrll 		sc->sc_wdcdev.sc_atac.atac_cap &= ~ATAC_CAP_DMA;
    183       1.1   mycroft 	}
    184       1.1   mycroft }
    185       1.1   mycroft 
    186       1.1   mycroft static void
    187  1.19.2.2     skrll wdc_isapnp_dma_start(void *scv, void *buf, size_t size, int read)
    188       1.1   mycroft {
    189       1.1   mycroft 	struct wdc_isapnp_softc *sc = scv;
    190       1.1   mycroft 
    191      1.11   mycroft 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf, size, NULL,
    192      1.11   mycroft 	    (read ? DMAMODE_READ : DMAMODE_WRITE) | DMAMODE_DEMAND,
    193       1.1   mycroft 	    BUS_DMA_NOWAIT);
    194       1.1   mycroft }
    195       1.1   mycroft 
    196       1.1   mycroft static void
    197  1.19.2.2     skrll wdc_isapnp_dma_finish(void *scv)
    198       1.1   mycroft {
    199       1.1   mycroft 	struct wdc_isapnp_softc *sc = scv;
    200       1.1   mycroft 
    201       1.3   thorpej 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    202       1.1   mycroft }
    203       1.1   mycroft #endif
    204