Home | History | Annotate | Line # | Download | only in isapnp
wdc_isapnp.c revision 1.2.2.6
      1  1.2.2.6   bouyer /*	$NetBSD: wdc_isapnp.c,v 1.2.2.6 1998/09/20 16:37:23 bouyer Exp $	*/
      2      1.1  mycroft 
      3  1.2.2.5   bouyer /*-
      4  1.2.2.5   bouyer  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.2.2.5   bouyer  * All rights reserved.
      6      1.1  mycroft  *
      7  1.2.2.5   bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.2.5   bouyer  * 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.2.2.5   bouyer  *        This product includes software developed by the NetBSD
     21  1.2.2.5   bouyer  *        Foundation, Inc. and its contributors.
     22  1.2.2.5   bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.2.5   bouyer  *    contributors may be used to endorse or promote products derived
     24  1.2.2.5   bouyer  *    from this software without specific prior written permission.
     25      1.1  mycroft  *
     26  1.2.2.5   bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.2.5   bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.2.5   bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.2.5   bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.2.5   bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.2.5   bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.2.5   bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.2.5   bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.2.5   bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.2.5   bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.2.5   bouyer  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  mycroft  */
     38      1.1  mycroft 
     39      1.1  mycroft #include <sys/types.h>
     40      1.1  mycroft #include <sys/param.h>
     41      1.1  mycroft #include <sys/systm.h>
     42      1.1  mycroft #include <sys/device.h>
     43  1.2.2.1   bouyer #include <sys/malloc.h>
     44      1.1  mycroft 
     45      1.1  mycroft #include <machine/bus.h>
     46      1.1  mycroft #include <machine/intr.h>
     47      1.1  mycroft 
     48      1.1  mycroft #include <dev/isa/isavar.h>
     49      1.1  mycroft #include <dev/isa/isadmavar.h>
     50      1.1  mycroft 
     51      1.1  mycroft #include <dev/isapnp/isapnpreg.h>
     52      1.1  mycroft #include <dev/isapnp/isapnpvar.h>
     53  1.2.2.4   bouyer #include <dev/isapnp/isapnpdevs.h>
     54      1.1  mycroft 
     55  1.2.2.1   bouyer #include <dev/ata/atavar.h>
     56      1.1  mycroft #include <dev/ic/wdcreg.h>
     57      1.1  mycroft #include <dev/ic/wdcvar.h>
     58      1.1  mycroft 
     59      1.1  mycroft struct wdc_isapnp_softc {
     60      1.1  mycroft 	struct	wdc_softc sc_wdcdev;
     61  1.2.2.1   bouyer 	struct	channel_softc wdc_channel;
     62  1.2.2.2   bouyer 	isa_chipset_tag_t sc_ic;
     63      1.1  mycroft 	void	*sc_ih;
     64      1.1  mycroft 	int	sc_drq;
     65      1.1  mycroft };
     66      1.1  mycroft 
     67      1.1  mycroft int	wdc_isapnp_probe 	__P((struct device *, struct cfdata *, void *));
     68      1.1  mycroft void	wdc_isapnp_attach 	__P((struct device *, struct device *, void *));
     69      1.1  mycroft 
     70      1.1  mycroft struct cfattach wdc_isapnp_ca = {
     71      1.1  mycroft 	sizeof(struct wdc_isapnp_softc), wdc_isapnp_probe, wdc_isapnp_attach
     72      1.1  mycroft };
     73      1.1  mycroft 
     74      1.1  mycroft #ifdef notyet
     75  1.2.2.1   bouyer static void	wdc_isapnp_dma_setup __P((struct wdc_isapnp_softc *));
     76      1.1  mycroft static void	wdc_isapnp_dma_start __P((void *, void *, size_t, int));
     77      1.1  mycroft static void	wdc_isapnp_dma_finish __P((void *));
     78      1.1  mycroft #endif
     79      1.1  mycroft 
     80      1.1  mycroft int
     81      1.1  mycroft wdc_isapnp_probe(parent, match, aux)
     82      1.1  mycroft 	struct device *parent;
     83      1.1  mycroft 	struct cfdata *match;
     84      1.1  mycroft 	void *aux;
     85      1.1  mycroft {
     86  1.2.2.4   bouyer 	return isapnp_devmatch(aux, &isapnp_wdc_devinfo);
     87      1.1  mycroft }
     88      1.1  mycroft 
     89      1.1  mycroft void
     90      1.1  mycroft wdc_isapnp_attach(parent, self, aux)
     91      1.1  mycroft 	struct device *parent, *self;
     92      1.1  mycroft 	void *aux;
     93      1.1  mycroft {
     94      1.1  mycroft 	struct wdc_isapnp_softc *sc = (void *)self;
     95      1.1  mycroft 	struct isapnp_attach_args *ipa = aux;
     96      1.1  mycroft 
     97      1.1  mycroft 	printf("\n");
     98      1.1  mycroft 
     99      1.1  mycroft 	if (ipa->ipa_nio != 2 ||
    100      1.1  mycroft 	    ipa->ipa_nmem != 0 ||
    101      1.1  mycroft 	    ipa->ipa_nmem32 != 0 ||
    102      1.1  mycroft 	    ipa->ipa_nirq != 1 ||
    103      1.1  mycroft 	    ipa->ipa_ndrq > 1) {
    104      1.1  mycroft 		printf("%s: unexpected configuration\n",
    105      1.1  mycroft 		    sc->sc_wdcdev.sc_dev.dv_xname);
    106      1.1  mycroft 		return;
    107      1.1  mycroft 	}
    108      1.1  mycroft 
    109      1.1  mycroft 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    110      1.1  mycroft 		printf("%s: couldn't map registers\n",
    111      1.1  mycroft 		    sc->sc_wdcdev.sc_dev.dv_xname);
    112      1.1  mycroft 		return;
    113      1.1  mycroft 	}
    114      1.1  mycroft 
    115      1.1  mycroft 	printf("%s: %s %s\n", sc->sc_wdcdev.sc_dev.dv_xname, ipa->ipa_devident,
    116      1.1  mycroft 	    ipa->ipa_devclass);
    117      1.1  mycroft 
    118  1.2.2.1   bouyer 	sc->wdc_channel.cmd_iot = ipa->ipa_iot;
    119  1.2.2.1   bouyer 	sc->wdc_channel.ctl_iot = ipa->ipa_iot;
    120  1.2.2.6   bouyer 	/*
    121  1.2.2.6   bouyer 	 * An IDE controller can feed us the regions in any order. Pass
    122  1.2.2.6   bouyer 	 * them along with the 8-byte region in sc_ad.ioh, and the other
    123  1.2.2.6   bouyer 	 * (2 byte) region in auxioh.
    124  1.2.2.6   bouyer 	 */
    125  1.2.2.6   bouyer 	if (ipa->ipa_io[0].length == 8) {
    126  1.2.2.6   bouyer 		sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
    127  1.2.2.6   bouyer 		sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
    128  1.2.2.6   bouyer 	} else {
    129  1.2.2.6   bouyer 		sc->wdc_channel.cmd_ioh = ipa->ipa_io[1].h;
    130  1.2.2.6   bouyer 		sc->wdc_channel.ctl_ioh = ipa->ipa_io[0].h;
    131  1.2.2.6   bouyer 	}
    132  1.2.2.2   bouyer 	sc->sc_ic = ipa->ipa_ic;
    133      1.1  mycroft 
    134      1.1  mycroft 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    135  1.2.2.1   bouyer 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel);
    136      1.1  mycroft 
    137      1.1  mycroft #ifdef notyet
    138      1.1  mycroft 	if (ipa->ipa_ndrq > 0) {
    139      1.1  mycroft 		sc->sc_drq = ipa->ipa_drq[0].num;
    140      1.1  mycroft 
    141      1.1  mycroft 		sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
    142      1.1  mycroft 		sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
    143      1.1  mycroft 		sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
    144  1.2.2.1   bouyer 		wdc_isapnp_dma_setup(sc);
    145      1.1  mycroft 	}
    146      1.1  mycroft #endif
    147  1.2.2.1   bouyer 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
    148  1.2.2.1   bouyer 	sc->sc_wdcdev.pio_mode = 0;
    149  1.2.2.1   bouyer 	sc->sc_wdcdev.channels = &sc->wdc_channel;
    150  1.2.2.1   bouyer 	sc->sc_wdcdev.nchannels = 1;
    151  1.2.2.1   bouyer 	sc->wdc_channel.channel = 0;
    152  1.2.2.1   bouyer 	sc->wdc_channel.wdc = &sc->sc_wdcdev;
    153  1.2.2.1   bouyer 	sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
    154  1.2.2.1   bouyer 	    M_DEVBUF, M_NOWAIT);
    155  1.2.2.1   bouyer 	if (sc->wdc_channel.ch_queue == NULL) {
    156  1.2.2.1   bouyer 	    printf("%s: can't allocate memory for command queue",
    157  1.2.2.1   bouyer 		sc->sc_wdcdev.sc_dev.dv_xname);
    158  1.2.2.1   bouyer 	    return;
    159  1.2.2.1   bouyer 	}
    160  1.2.2.1   bouyer 	wdcattach(&sc->wdc_channel);
    161      1.1  mycroft }
    162      1.1  mycroft 
    163      1.1  mycroft #ifdef notyet
    164      1.1  mycroft static void
    165  1.2.2.1   bouyer wdc_isapnp_dma_setup(sc)
    166  1.2.2.1   bouyer 	struct wdc_isapnp_softc *sc;
    167      1.1  mycroft {
    168      1.1  mycroft 
    169  1.2.2.2   bouyer 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    170      1.1  mycroft 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    171      1.1  mycroft 		printf("%s: can't create map for drq %d\n",
    172      1.1  mycroft 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
    173  1.2.2.1   bouyer 		sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
    174      1.1  mycroft 	}
    175      1.1  mycroft }
    176      1.1  mycroft 
    177      1.1  mycroft static void
    178      1.1  mycroft wdc_isapnp_dma_start(scv, buf, size, read)
    179      1.1  mycroft 	void *scv, *buf;
    180      1.1  mycroft 	size_t size;
    181      1.1  mycroft 	int read;
    182      1.1  mycroft {
    183      1.1  mycroft 	struct wdc_isapnp_softc *sc = scv;
    184      1.1  mycroft 
    185  1.2.2.2   bouyer 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf,
    186      1.1  mycroft 	    size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
    187      1.1  mycroft 	    BUS_DMA_NOWAIT);
    188      1.1  mycroft }
    189      1.1  mycroft 
    190      1.1  mycroft static void
    191      1.1  mycroft wdc_isapnp_dma_finish(scv)
    192      1.1  mycroft 	void *scv;
    193      1.1  mycroft {
    194      1.1  mycroft 	struct wdc_isapnp_softc *sc = scv;
    195      1.1  mycroft 
    196  1.2.2.2   bouyer 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    197      1.1  mycroft }
    198      1.1  mycroft #endif
    199