Home | History | Annotate | Line # | Download | only in isapnp
wdc_isapnp.c revision 1.44
      1 /*	$NetBSD: wdc_isapnp.c,v 1.44 2017/10/20 07:06:07 jdolecek Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum and by Onno van der Linden.
      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: wdc_isapnp.c,v 1.44 2017/10/20 07:06:07 jdolecek Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 #include <sys/malloc.h>
     39 
     40 #include <sys/bus.h>
     41 #include <sys/intr.h>
     42 
     43 #include <dev/isa/isavar.h>
     44 #include <dev/isa/isadmavar.h>
     45 
     46 #include <dev/isapnp/isapnpreg.h>
     47 #include <dev/isapnp/isapnpvar.h>
     48 #include <dev/isapnp/isapnpdevs.h>
     49 
     50 #include <dev/ata/atavar.h>
     51 #include <dev/ic/wdcreg.h>
     52 #include <dev/ic/wdcvar.h>
     53 
     54 struct wdc_isapnp_softc {
     55 	struct	wdc_softc sc_wdcdev;
     56 	struct	ata_channel *wdc_chanlist[1];
     57 	struct	ata_channel ata_channel;
     58 	struct	wdc_regs wdc_regs;
     59 	isa_chipset_tag_t sc_ic;
     60 	void	*sc_ih;
     61 	int	sc_drq;
     62 };
     63 
     64 static int	wdc_isapnp_probe(device_t, cfdata_t, void *);
     65 static void	wdc_isapnp_attach(device_t, device_t, void *);
     66 
     67 CFATTACH_DECL_NEW(wdc_isapnp, sizeof(struct wdc_isapnp_softc),
     68     wdc_isapnp_probe, wdc_isapnp_attach, NULL, NULL);
     69 
     70 #ifdef notyet
     71 static void	wdc_isapnp_dma_setup(struct wdc_isapnp_softc *);
     72 static void	wdc_isapnp_dma_start(void *, void *, size_t, int);
     73 static void	wdc_isapnp_dma_finish(void *);
     74 #endif
     75 
     76 static int
     77 wdc_isapnp_probe(device_t parent, cfdata_t match, void *aux)
     78 {
     79 	int pri, variant;
     80 
     81 	pri = isapnp_devmatch(aux, &isapnp_wdc_devinfo, &variant);
     82 	if (pri && variant > 0)
     83 		pri = 0;
     84 	return (pri);
     85 }
     86 
     87 static void
     88 wdc_isapnp_attach(device_t parent, device_t self, void *aux)
     89 {
     90 	struct wdc_isapnp_softc *sc = device_private(self);
     91 	struct wdc_regs *wdr;
     92 	struct isapnp_attach_args *ipa = aux;
     93 	int i;
     94 
     95 	if (ipa->ipa_nio != 2 ||
     96 	    ipa->ipa_nmem != 0 ||
     97 	    ipa->ipa_nmem32 != 0 ||
     98 	    ipa->ipa_nirq != 1 ||
     99 	    ipa->ipa_ndrq > 1) {
    100 		aprint_error(": unexpected configuration\n");
    101 		return;
    102 	}
    103 
    104 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    105 		aprint_error(": couldn't map registers\n");
    106 		return;
    107 	}
    108 
    109 	aprint_normal(": %s %s\n", ipa->ipa_devident, ipa->ipa_devclass);
    110 
    111 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    112 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    113 	wdr->cmd_iot = ipa->ipa_iot;
    114 	wdr->ctl_iot = ipa->ipa_iot;
    115 	/*
    116 	 * An IDE controller can feed us the regions in any order. Pass
    117 	 * them along with the 8-byte region in sc_ad.ioh, and the other
    118 	 * (2 byte) region in auxioh.
    119 	 */
    120 	if (ipa->ipa_io[0].length == 8) {
    121 		wdr->cmd_baseioh = ipa->ipa_io[0].h;
    122 		wdr->ctl_ioh = ipa->ipa_io[1].h;
    123 	} else {
    124 		wdr->cmd_baseioh = ipa->ipa_io[1].h;
    125 		wdr->ctl_ioh = ipa->ipa_io[0].h;
    126 	}
    127 
    128 	for (i = 0; i < WDC_NREG; i++) {
    129 		if (bus_space_subregion(wdr->cmd_iot,
    130 		    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
    131 		    &wdr->cmd_iohs[i]) != 0) {
    132 			aprint_error(": couldn't subregion registers\n");
    133 			return;
    134 		}
    135 	}
    136 	wdr->data32iot = wdr->cmd_iot;
    137 	wdr->data32ioh = wdr->cmd_iohs[0];
    138 
    139 	sc->sc_ic = ipa->ipa_ic;
    140 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    141 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->ata_channel);
    142 
    143 #ifdef notyet
    144 	if (ipa->ipa_ndrq > 0) {
    145 		sc->sc_drq = ipa->ipa_drq[0].num;
    146 
    147 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    148 		sc->sc_wdcdev.dma_start = &wdc_isapnp_dma_start;
    149 		sc->sc_wdcdev.dma_finish = &wdc_isapnp_dma_finish;
    150 		wdc_isapnp_dma_setup(sc);
    151 	}
    152 #endif
    153 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    154 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    155 	sc->wdc_chanlist[0] = &sc->ata_channel;
    156 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    157 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    158 	sc->sc_wdcdev.wdc_maxdrives = 2;
    159 	sc->ata_channel.ch_channel = 0;
    160 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    161 
    162 	wdc_init_shadow_regs(wdr);
    163 
    164 	wdcattach(&sc->ata_channel);
    165 }
    166 
    167 #ifdef notyet
    168 static void
    169 wdc_isapnp_dma_setup(struct wdc_isapnp_softc *sc)
    170 {
    171 
    172 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
    173 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    174 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    175 		    "can't create map for drq %d\n", sc->sc_drq);
    176 		sc->sc_wdcdev.sc_atac.atac_cap &= ~ATAC_CAP_DMA;
    177 	}
    178 }
    179 
    180 static void
    181 wdc_isapnp_dma_start(void *scv, void *buf, size_t size, int read)
    182 {
    183 	struct wdc_isapnp_softc *sc = scv;
    184 
    185 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf, size, NULL,
    186 	    (read ? DMAMODE_READ : DMAMODE_WRITE) | DMAMODE_DEMAND,
    187 	    BUS_DMA_NOWAIT);
    188 }
    189 
    190 static void
    191 wdc_isapnp_dma_finish(void *scv)
    192 {
    193 	struct wdc_isapnp_softc *sc = scv;
    194 
    195 	isa_dmadone(sc->sc_ic, sc->sc_drq);
    196 }
    197 #endif
    198