Home | History | Annotate | Line # | Download | only in isapnp
wdc_isapnp.c revision 1.39.34.1
      1  1.39.34.1      yamt /*	$NetBSD: wdc_isapnp.c,v 1.39.34.1 2012/10/30 17:21:17 yamt Exp $	*/
      2        1.1   mycroft 
      3        1.6   mycroft /*-
      4       1.20   mycroft  * 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  *
     19        1.6   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.6   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.6   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.6   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.6   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.6   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.6   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.6   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.6   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.6   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.6   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1   mycroft  */
     31       1.14     lukem 
     32       1.14     lukem #include <sys/cdefs.h>
     33  1.39.34.1      yamt __KERNEL_RCSID(0, "$NetBSD: wdc_isapnp.c,v 1.39.34.1 2012/10/30 17:21:17 yamt Exp $");
     34        1.1   mycroft 
     35        1.1   mycroft #include <sys/param.h>
     36        1.1   mycroft #include <sys/systm.h>
     37        1.1   mycroft #include <sys/device.h>
     38        1.8    bouyer #include <sys/malloc.h>
     39        1.1   mycroft 
     40       1.37        ad #include <sys/bus.h>
     41       1.37        ad #include <sys/intr.h>
     42        1.1   mycroft 
     43        1.1   mycroft #include <dev/isa/isavar.h>
     44        1.1   mycroft #include <dev/isa/isadmavar.h>
     45        1.1   mycroft 
     46        1.1   mycroft #include <dev/isapnp/isapnpreg.h>
     47        1.1   mycroft #include <dev/isapnp/isapnpvar.h>
     48        1.5  christos #include <dev/isapnp/isapnpdevs.h>
     49        1.1   mycroft 
     50        1.8    bouyer #include <dev/ata/atavar.h>
     51        1.1   mycroft #include <dev/ic/wdcreg.h>
     52        1.1   mycroft #include <dev/ic/wdcvar.h>
     53        1.1   mycroft 
     54        1.1   mycroft struct wdc_isapnp_softc {
     55        1.1   mycroft 	struct	wdc_softc sc_wdcdev;
     56       1.28   thorpej 	struct	ata_channel *wdc_chanlist[1];
     57       1.28   thorpej 	struct	ata_channel ata_channel;
     58       1.24   thorpej 	struct	ata_queue wdc_chqueue;
     59       1.28   thorpej 	struct	wdc_regs wdc_regs;
     60        1.3   thorpej 	isa_chipset_tag_t sc_ic;
     61        1.1   mycroft 	void	*sc_ih;
     62        1.1   mycroft 	int	sc_drq;
     63        1.1   mycroft };
     64        1.1   mycroft 
     65       1.38      cube static int	wdc_isapnp_probe(device_t, cfdata_t, void *);
     66       1.38      cube static void	wdc_isapnp_attach(device_t, device_t, void *);
     67        1.1   mycroft 
     68       1.38      cube CFATTACH_DECL_NEW(wdc_isapnp, sizeof(struct wdc_isapnp_softc),
     69       1.18   thorpej     wdc_isapnp_probe, wdc_isapnp_attach, NULL, NULL);
     70        1.1   mycroft 
     71        1.1   mycroft #ifdef notyet
     72       1.29   thorpej static void	wdc_isapnp_dma_setup(struct wdc_isapnp_softc *);
     73       1.29   thorpej static void	wdc_isapnp_dma_start(void *, void *, size_t, int);
     74       1.29   thorpej static void	wdc_isapnp_dma_finish(void *);
     75        1.1   mycroft #endif
     76        1.1   mycroft 
     77       1.29   thorpej static int
     78       1.38      cube wdc_isapnp_probe(device_t parent, cfdata_t match, void *aux)
     79        1.1   mycroft {
     80       1.13   mycroft 	int pri, variant;
     81       1.12   mycroft 
     82       1.13   mycroft 	pri = isapnp_devmatch(aux, &isapnp_wdc_devinfo, &variant);
     83       1.13   mycroft 	if (pri && variant > 0)
     84       1.13   mycroft 		pri = 0;
     85       1.13   mycroft 	return (pri);
     86        1.1   mycroft }
     87        1.1   mycroft 
     88       1.29   thorpej static void
     89       1.38      cube wdc_isapnp_attach(device_t parent, device_t self, void *aux)
     90        1.1   mycroft {
     91       1.34   thorpej 	struct wdc_isapnp_softc *sc = device_private(self);
     92       1.28   thorpej 	struct wdc_regs *wdr;
     93        1.1   mycroft 	struct isapnp_attach_args *ipa = aux;
     94       1.23      fvdl 	int i;
     95        1.1   mycroft 
     96        1.1   mycroft 	if (ipa->ipa_nio != 2 ||
     97        1.1   mycroft 	    ipa->ipa_nmem != 0 ||
     98        1.1   mycroft 	    ipa->ipa_nmem32 != 0 ||
     99        1.1   mycroft 	    ipa->ipa_nirq != 1 ||
    100        1.1   mycroft 	    ipa->ipa_ndrq > 1) {
    101       1.38      cube 		aprint_error(": unexpected configuration\n");
    102        1.1   mycroft 		return;
    103        1.1   mycroft 	}
    104        1.1   mycroft 
    105        1.1   mycroft 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    106       1.38      cube 		aprint_error(": couldn't map registers\n");
    107        1.1   mycroft 		return;
    108        1.1   mycroft 	}
    109        1.1   mycroft 
    110       1.38      cube 	aprint_normal(": %s %s\n", ipa->ipa_devident, ipa->ipa_devclass);
    111        1.1   mycroft 
    112       1.38      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    113       1.28   thorpej 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    114       1.28   thorpej 	wdr->cmd_iot = ipa->ipa_iot;
    115       1.28   thorpej 	wdr->ctl_iot = ipa->ipa_iot;
    116        1.7  wrstuden 	/*
    117        1.7  wrstuden 	 * An IDE controller can feed us the regions in any order. Pass
    118        1.7  wrstuden 	 * them along with the 8-byte region in sc_ad.ioh, and the other
    119        1.7  wrstuden 	 * (2 byte) region in auxioh.
    120        1.7  wrstuden 	 */
    121        1.7  wrstuden 	if (ipa->ipa_io[0].length == 8) {
    122       1.28   thorpej 		wdr->cmd_baseioh = ipa->ipa_io[0].h;
    123       1.28   thorpej 		wdr->ctl_ioh = ipa->ipa_io[1].h;
    124        1.7  wrstuden 	} else {
    125       1.28   thorpej 		wdr->cmd_baseioh = ipa->ipa_io[1].h;
    126       1.28   thorpej 		wdr->ctl_ioh = ipa->ipa_io[0].h;
    127        1.7  wrstuden 	}
    128       1.23      fvdl 
    129       1.23      fvdl 	for (i = 0; i < WDC_NREG; i++) {
    130       1.28   thorpej 		if (bus_space_subregion(wdr->cmd_iot,
    131       1.28   thorpej 		    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
    132       1.28   thorpej 		    &wdr->cmd_iohs[i]) != 0) {
    133       1.38      cube 			aprint_error(": couldn't subregion registers\n");
    134       1.23      fvdl 			return;
    135       1.23      fvdl 		}
    136       1.23      fvdl 	}
    137       1.28   thorpej 	wdr->data32iot = wdr->cmd_iot;
    138       1.28   thorpej 	wdr->data32ioh = wdr->cmd_iohs[0];
    139        1.8    bouyer 
    140        1.3   thorpej 	sc->sc_ic = ipa->ipa_ic;
    141        1.1   mycroft 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    142       1.28   thorpej 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->ata_channel);
    143        1.1   mycroft 
    144        1.1   mycroft #ifdef notyet
    145        1.1   mycroft 	if (ipa->ipa_ndrq > 0) {
    146        1.1   mycroft 		sc->sc_drq = ipa->ipa_drq[0].num;
    147        1.1   mycroft 
    148       1.30   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    149       1.30   thorpej 		sc->sc_wdcdev.dma_start = &wdc_isapnp_dma_start;
    150       1.30   thorpej 		sc->sc_wdcdev.dma_finish = &wdc_isapnp_dma_finish;
    151        1.8    bouyer 		wdc_isapnp_dma_setup(sc);
    152        1.1   mycroft 	}
    153        1.1   mycroft #endif
    154       1.30   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    155       1.30   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    156       1.28   thorpej 	sc->wdc_chanlist[0] = &sc->ata_channel;
    157       1.30   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    158       1.30   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    159  1.39.34.1      yamt 	sc->sc_wdcdev.wdc_maxdrives = 2;
    160       1.28   thorpej 	sc->ata_channel.ch_channel = 0;
    161       1.30   thorpej 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    162       1.28   thorpej 	sc->ata_channel.ch_queue = &sc->wdc_chqueue;
    163       1.20   mycroft 
    164       1.31   thorpej 	wdc_init_shadow_regs(&sc->ata_channel);
    165       1.31   thorpej 
    166       1.28   thorpej 	wdcattach(&sc->ata_channel);
    167        1.1   mycroft }
    168        1.1   mycroft 
    169        1.1   mycroft #ifdef notyet
    170        1.1   mycroft static void
    171       1.29   thorpej wdc_isapnp_dma_setup(struct wdc_isapnp_softc *sc)
    172        1.1   mycroft {
    173        1.1   mycroft 
    174        1.3   thorpej 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    175        1.1   mycroft 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    176       1.38      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    177       1.38      cube 		    "can't create map for drq %d\n", sc->sc_drq);
    178       1.30   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap &= ~ATAC_CAP_DMA;
    179        1.1   mycroft 	}
    180        1.1   mycroft }
    181        1.1   mycroft 
    182        1.1   mycroft static void
    183       1.29   thorpej wdc_isapnp_dma_start(void *scv, void *buf, size_t size, int read)
    184        1.1   mycroft {
    185        1.1   mycroft 	struct wdc_isapnp_softc *sc = scv;
    186        1.1   mycroft 
    187       1.11   mycroft 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf, size, NULL,
    188       1.11   mycroft 	    (read ? DMAMODE_READ : DMAMODE_WRITE) | DMAMODE_DEMAND,
    189        1.1   mycroft 	    BUS_DMA_NOWAIT);
    190        1.1   mycroft }
    191        1.1   mycroft 
    192        1.1   mycroft static void
    193       1.29   thorpej wdc_isapnp_dma_finish(void *scv)
    194        1.1   mycroft {
    195        1.1   mycroft 	struct wdc_isapnp_softc *sc = scv;
    196        1.1   mycroft 
    197        1.3   thorpej 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    198        1.1   mycroft }
    199        1.1   mycroft #endif
    200