Home | History | Annotate | Line # | Download | only in pci
pciide_common.c revision 1.31.10.1
      1  1.31.10.1      yamt /*	$NetBSD: pciide_common.c,v 1.31.10.1 2006/10/22 06:06:19 yamt Exp $	*/
      2        1.1    bouyer 
      3        1.1    bouyer 
      4        1.1    bouyer /*
      5        1.1    bouyer  * Copyright (c) 1999, 2000, 2001, 2003 Manuel Bouyer.
      6        1.1    bouyer  *
      7        1.1    bouyer  * Redistribution and use in source and binary forms, with or without
      8        1.1    bouyer  * modification, are permitted provided that the following conditions
      9        1.1    bouyer  * are met:
     10        1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     11        1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     12        1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     14        1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     15        1.1    bouyer  * 3. All advertising materials mentioning features or use of this software
     16        1.1    bouyer  *    must display the following acknowledgement:
     17        1.1    bouyer  *	This product includes software developed by Manuel Bouyer.
     18        1.1    bouyer  * 4. Neither the name of the University nor the names of its contributors
     19        1.1    bouyer  *    may be used to endorse or promote products derived from this software
     20        1.1    bouyer  *    without specific prior written permission.
     21        1.1    bouyer  *
     22        1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23        1.1    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24        1.1    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25       1.26     perry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26        1.1    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27        1.1    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28        1.1    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29        1.1    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30        1.1    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31        1.1    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32        1.1    bouyer  *
     33        1.1    bouyer  */
     34        1.1    bouyer 
     35        1.1    bouyer 
     36        1.1    bouyer /*
     37        1.1    bouyer  * Copyright (c) 1996, 1998 Christopher G. Demetriou.  All rights reserved.
     38        1.1    bouyer  *
     39        1.1    bouyer  * Redistribution and use in source and binary forms, with or without
     40        1.1    bouyer  * modification, are permitted provided that the following conditions
     41        1.1    bouyer  * are met:
     42        1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     43        1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     44        1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     45        1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     46        1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     47        1.1    bouyer  * 3. All advertising materials mentioning features or use of this software
     48        1.1    bouyer  *    must display the following acknowledgement:
     49        1.1    bouyer  *      This product includes software developed by Christopher G. Demetriou
     50        1.1    bouyer  *	for the NetBSD Project.
     51        1.1    bouyer  * 4. The name of the author may not be used to endorse or promote products
     52        1.1    bouyer  *    derived from this software without specific prior written permission
     53        1.1    bouyer  *
     54        1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     55        1.1    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     56        1.1    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     57        1.1    bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     58        1.1    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     59        1.1    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     60        1.1    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     61        1.1    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     62        1.1    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     63        1.1    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     64        1.1    bouyer  */
     65        1.1    bouyer 
     66        1.1    bouyer /*
     67        1.1    bouyer  * PCI IDE controller driver.
     68        1.1    bouyer  *
     69        1.1    bouyer  * Author: Christopher G. Demetriou, March 2, 1998 (derived from NetBSD
     70        1.1    bouyer  * sys/dev/pci/ppb.c, revision 1.16).
     71        1.1    bouyer  *
     72        1.1    bouyer  * See "PCI IDE Controller Specification, Revision 1.0 3/4/94" and
     73        1.1    bouyer  * "Programming Interface for Bus Master IDE Controller, Revision 1.0
     74        1.1    bouyer  * 5/16/94" from the PCI SIG.
     75        1.1    bouyer  *
     76        1.1    bouyer  */
     77        1.1    bouyer 
     78        1.1    bouyer #include <sys/cdefs.h>
     79  1.31.10.1      yamt __KERNEL_RCSID(0, "$NetBSD: pciide_common.c,v 1.31.10.1 2006/10/22 06:06:19 yamt Exp $");
     80        1.1    bouyer 
     81        1.1    bouyer #include <sys/param.h>
     82        1.1    bouyer #include <sys/malloc.h>
     83        1.1    bouyer 
     84        1.1    bouyer #include <uvm/uvm_extern.h>
     85        1.1    bouyer 
     86        1.1    bouyer #include <dev/pci/pcireg.h>
     87        1.1    bouyer #include <dev/pci/pcivar.h>
     88        1.1    bouyer #include <dev/pci/pcidevs.h>
     89        1.1    bouyer #include <dev/pci/pciidereg.h>
     90        1.1    bouyer #include <dev/pci/pciidevar.h>
     91        1.1    bouyer 
     92        1.3      fvdl #include <dev/ic/wdcreg.h>
     93        1.3      fvdl 
     94       1.16   thorpej #ifdef ATADEBUG
     95       1.16   thorpej int atadebug_pciide_mask = 0;
     96        1.1    bouyer #endif
     97        1.1    bouyer 
     98  1.31.10.1      yamt #if NATA_DMA
     99       1.26     perry static const char dmaerrfmt[] =
    100        1.1    bouyer     "%s:%d: unable to %s table DMA map for drive %d, error=%d\n";
    101  1.31.10.1      yamt #endif
    102        1.1    bouyer 
    103        1.1    bouyer /* Default product description for devices not known from this controller */
    104        1.1    bouyer const struct pciide_product_desc default_product_desc = {
    105        1.1    bouyer 	0,
    106        1.1    bouyer 	0,
    107        1.1    bouyer 	"Generic PCI IDE controller",
    108        1.1    bouyer 	default_chip_map,
    109       1.26     perry };
    110        1.1    bouyer 
    111        1.1    bouyer const struct pciide_product_desc *
    112        1.1    bouyer pciide_lookup_product(id, pp)
    113        1.1    bouyer 	pcireg_t id;
    114        1.1    bouyer 	const struct pciide_product_desc *pp;
    115        1.1    bouyer {
    116        1.1    bouyer 	for (; pp->chip_map != NULL; pp++)
    117        1.1    bouyer 		if (PCI_PRODUCT(id) == pp->ide_product)
    118        1.1    bouyer 			break;
    119       1.26     perry 
    120        1.1    bouyer 	if (pp->chip_map == NULL)
    121        1.1    bouyer 		return NULL;
    122        1.1    bouyer 	return pp;
    123        1.1    bouyer }
    124        1.1    bouyer 
    125        1.1    bouyer void
    126        1.1    bouyer pciide_common_attach(sc, pa, pp)
    127        1.1    bouyer 	struct pciide_softc *sc;
    128        1.1    bouyer 	struct pci_attach_args *pa;
    129        1.1    bouyer 	const struct pciide_product_desc *pp;
    130        1.1    bouyer {
    131        1.1    bouyer 	pci_chipset_tag_t pc = pa->pa_pc;
    132        1.1    bouyer 	pcitag_t tag = pa->pa_tag;
    133  1.31.10.1      yamt #if NATA_DMA
    134        1.1    bouyer 	pcireg_t csr;
    135  1.31.10.1      yamt #endif
    136        1.1    bouyer 	char devinfo[256];
    137        1.1    bouyer 	const char *displaydev;
    138        1.1    bouyer 
    139        1.1    bouyer 	aprint_naive(": disk controller\n");
    140        1.1    bouyer 	aprint_normal("\n");
    141        1.1    bouyer 
    142        1.1    bouyer 	sc->sc_pci_id = pa->pa_id;
    143        1.1    bouyer 	if (pp == NULL) {
    144        1.1    bouyer 		/* should only happen for generic pciide devices */
    145        1.1    bouyer 		sc->sc_pp = &default_product_desc;
    146        1.9    itojun 		pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    147        1.1    bouyer 		displaydev = devinfo;
    148        1.1    bouyer 	} else {
    149        1.1    bouyer 		sc->sc_pp = pp;
    150        1.1    bouyer 		displaydev = sc->sc_pp->ide_name;
    151        1.1    bouyer 	}
    152        1.1    bouyer 
    153        1.1    bouyer 	/* if displaydev == NULL, printf is done in chip-specific map */
    154        1.1    bouyer 	if (displaydev)
    155        1.1    bouyer 		aprint_normal("%s: %s (rev. 0x%02x)\n",
    156       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, displaydev,
    157        1.1    bouyer 		    PCI_REVISION(pa->pa_class));
    158        1.1    bouyer 
    159        1.1    bouyer 	sc->sc_pc = pa->pa_pc;
    160        1.1    bouyer 	sc->sc_tag = pa->pa_tag;
    161        1.1    bouyer 
    162  1.31.10.1      yamt #if NATA_DMA
    163        1.1    bouyer 	/* Set up DMA defaults; these might be adjusted by chip_map. */
    164        1.1    bouyer 	sc->sc_dma_maxsegsz = IDEDMA_BYTE_COUNT_MAX;
    165        1.1    bouyer 	sc->sc_dma_boundary = IDEDMA_BYTE_COUNT_ALIGN;
    166  1.31.10.1      yamt #endif
    167        1.1    bouyer 
    168       1.16   thorpej #ifdef ATADEBUG
    169       1.16   thorpej 	if (atadebug_pciide_mask & DEBUG_PROBE)
    170        1.1    bouyer 		pci_conf_print(sc->sc_pc, sc->sc_tag, NULL);
    171        1.1    bouyer #endif
    172        1.1    bouyer 	sc->sc_pp->chip_map(sc, pa);
    173        1.1    bouyer 
    174  1.31.10.1      yamt #if NATA_DMA
    175        1.1    bouyer 	if (sc->sc_dma_ok) {
    176        1.1    bouyer 		csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    177        1.1    bouyer 		csr |= PCI_COMMAND_MASTER_ENABLE;
    178        1.1    bouyer 		pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    179        1.1    bouyer 	}
    180  1.31.10.1      yamt #endif
    181       1.16   thorpej 	ATADEBUG_PRINT(("pciide: command/status register=%x\n",
    182        1.1    bouyer 	    pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG)), DEBUG_PROBE);
    183        1.1    bouyer }
    184        1.1    bouyer 
    185        1.1    bouyer /* tell whether the chip is enabled or not */
    186        1.1    bouyer int
    187        1.1    bouyer pciide_chipen(sc, pa)
    188        1.1    bouyer 	struct pciide_softc *sc;
    189        1.1    bouyer 	struct pci_attach_args *pa;
    190        1.1    bouyer {
    191        1.1    bouyer 	pcireg_t csr;
    192        1.1    bouyer 
    193        1.1    bouyer 	if ((pa->pa_flags & PCI_FLAGS_IO_ENABLED) == 0) {
    194        1.1    bouyer 		csr = pci_conf_read(sc->sc_pc, sc->sc_tag,
    195        1.1    bouyer 		    PCI_COMMAND_STATUS_REG);
    196        1.1    bouyer 		aprint_normal("%s: device disabled (at %s)\n",
    197       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    198        1.1    bouyer 		   (csr & PCI_COMMAND_IO_ENABLE) == 0 ?
    199        1.1    bouyer 		   "device" : "bridge");
    200        1.1    bouyer 		return 0;
    201        1.1    bouyer 	}
    202        1.1    bouyer 	return 1;
    203        1.1    bouyer }
    204        1.1    bouyer 
    205        1.1    bouyer void
    206        1.1    bouyer pciide_mapregs_compat(pa, cp, compatchan, cmdsizep, ctlsizep)
    207        1.1    bouyer 	struct pci_attach_args *pa;
    208        1.1    bouyer 	struct pciide_channel *cp;
    209        1.1    bouyer 	int compatchan;
    210        1.1    bouyer 	bus_size_t *cmdsizep, *ctlsizep;
    211        1.1    bouyer {
    212       1.19   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    213       1.17   thorpej 	struct ata_channel *wdc_cp = &cp->ata_channel;
    214       1.19   thorpej 	struct wdc_regs *wdr = CHAN_TO_WDC_REGS(wdc_cp);
    215        1.3      fvdl 	int i;
    216        1.1    bouyer 
    217        1.1    bouyer 	cp->compat = 1;
    218        1.1    bouyer 	*cmdsizep = PCIIDE_COMPAT_CMD_SIZE;
    219        1.1    bouyer 	*ctlsizep = PCIIDE_COMPAT_CTL_SIZE;
    220        1.1    bouyer 
    221       1.17   thorpej 	wdr->cmd_iot = pa->pa_iot;
    222       1.17   thorpej 	if (bus_space_map(wdr->cmd_iot, PCIIDE_COMPAT_CMD_BASE(compatchan),
    223       1.17   thorpej 	    PCIIDE_COMPAT_CMD_SIZE, 0, &wdr->cmd_baseioh) != 0) {
    224        1.1    bouyer 		aprint_error("%s: couldn't map %s channel cmd regs\n",
    225       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    226        1.1    bouyer 		goto bad;
    227        1.1    bouyer 	}
    228        1.1    bouyer 
    229       1.17   thorpej 	wdr->ctl_iot = pa->pa_iot;
    230       1.17   thorpej 	if (bus_space_map(wdr->ctl_iot, PCIIDE_COMPAT_CTL_BASE(compatchan),
    231       1.17   thorpej 	    PCIIDE_COMPAT_CTL_SIZE, 0, &wdr->ctl_ioh) != 0) {
    232        1.1    bouyer 		aprint_error("%s: couldn't map %s channel ctl regs\n",
    233       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    234       1.17   thorpej 		bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh,
    235        1.1    bouyer 		    PCIIDE_COMPAT_CMD_SIZE);
    236        1.1    bouyer 		goto bad;
    237        1.1    bouyer 	}
    238        1.1    bouyer 
    239        1.3      fvdl 	for (i = 0; i < WDC_NREG; i++) {
    240       1.17   thorpej 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, i,
    241       1.17   thorpej 		    i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
    242        1.3      fvdl 			aprint_error("%s: couldn't subregion %s channel "
    243        1.3      fvdl 				     "cmd regs\n",
    244       1.20   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    245        1.3      fvdl 			goto bad;
    246        1.3      fvdl 		}
    247        1.3      fvdl 	}
    248       1.11   thorpej 	wdc_init_shadow_regs(wdc_cp);
    249       1.17   thorpej 	wdr->data32iot = wdr->cmd_iot;
    250       1.17   thorpej 	wdr->data32ioh = wdr->cmd_iohs[0];
    251        1.1    bouyer 	return;
    252        1.1    bouyer 
    253        1.1    bouyer bad:
    254       1.17   thorpej 	cp->ata_channel.ch_flags |= ATACH_DISABLED;
    255        1.1    bouyer 	return;
    256        1.1    bouyer }
    257        1.1    bouyer 
    258        1.1    bouyer void
    259        1.1    bouyer pciide_mapregs_native(pa, cp, cmdsizep, ctlsizep, pci_intr)
    260        1.1    bouyer 	struct pci_attach_args * pa;
    261        1.1    bouyer 	struct pciide_channel *cp;
    262        1.1    bouyer 	bus_size_t *cmdsizep, *ctlsizep;
    263       1.23     perry 	int (*pci_intr)(void *);
    264        1.1    bouyer {
    265       1.19   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    266       1.17   thorpej 	struct ata_channel *wdc_cp = &cp->ata_channel;
    267       1.19   thorpej 	struct wdc_regs *wdr = CHAN_TO_WDC_REGS(wdc_cp);
    268        1.1    bouyer 	const char *intrstr;
    269        1.1    bouyer 	pci_intr_handle_t intrhandle;
    270        1.3      fvdl 	int i;
    271        1.1    bouyer 
    272        1.1    bouyer 	cp->compat = 0;
    273        1.1    bouyer 
    274        1.1    bouyer 	if (sc->sc_pci_ih == NULL) {
    275        1.1    bouyer 		if (pci_intr_map(pa, &intrhandle) != 0) {
    276        1.1    bouyer 			aprint_error("%s: couldn't map native-PCI interrupt\n",
    277       1.20   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    278        1.1    bouyer 			goto bad;
    279       1.26     perry 		}
    280        1.1    bouyer 		intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    281        1.1    bouyer 		sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    282        1.1    bouyer 		    intrhandle, IPL_BIO, pci_intr, sc);
    283        1.1    bouyer 		if (sc->sc_pci_ih != NULL) {
    284        1.1    bouyer 			aprint_normal("%s: using %s for native-PCI interrupt\n",
    285       1.20   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    286        1.1    bouyer 			    intrstr ? intrstr : "unknown interrupt");
    287        1.1    bouyer 		} else {
    288        1.1    bouyer 			aprint_error(
    289        1.1    bouyer 			    "%s: couldn't establish native-PCI interrupt",
    290       1.20   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    291        1.1    bouyer 			if (intrstr != NULL)
    292        1.1    bouyer 				aprint_normal(" at %s", intrstr);
    293        1.1    bouyer 			aprint_normal("\n");
    294        1.1    bouyer 			goto bad;
    295        1.1    bouyer 		}
    296        1.1    bouyer 	}
    297        1.1    bouyer 	cp->ih = sc->sc_pci_ih;
    298        1.8   thorpej 	if (pci_mapreg_map(pa, PCIIDE_REG_CMD_BASE(wdc_cp->ch_channel),
    299        1.1    bouyer 	    PCI_MAPREG_TYPE_IO, 0,
    300       1.17   thorpej 	    &wdr->cmd_iot, &wdr->cmd_baseioh, NULL, cmdsizep) != 0) {
    301        1.1    bouyer 		aprint_error("%s: couldn't map %s channel cmd regs\n",
    302       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    303        1.1    bouyer 		goto bad;
    304        1.1    bouyer 	}
    305        1.1    bouyer 
    306        1.8   thorpej 	if (pci_mapreg_map(pa, PCIIDE_REG_CTL_BASE(wdc_cp->ch_channel),
    307        1.1    bouyer 	    PCI_MAPREG_TYPE_IO, 0,
    308       1.17   thorpej 	    &wdr->ctl_iot, &cp->ctl_baseioh, NULL, ctlsizep) != 0) {
    309        1.1    bouyer 		aprint_error("%s: couldn't map %s channel ctl regs\n",
    310       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    311       1.17   thorpej 		bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh,
    312        1.3      fvdl 		    *cmdsizep);
    313        1.1    bouyer 		goto bad;
    314        1.1    bouyer 	}
    315        1.1    bouyer 	/*
    316        1.1    bouyer 	 * In native mode, 4 bytes of I/O space are mapped for the control
    317        1.1    bouyer 	 * register, the control register is at offset 2. Pass the generic
    318        1.1    bouyer 	 * code a handle for only one byte at the right offset.
    319        1.1    bouyer 	 */
    320       1.17   thorpej 	if (bus_space_subregion(wdr->ctl_iot, cp->ctl_baseioh, 2, 1,
    321       1.17   thorpej 	    &wdr->ctl_ioh) != 0) {
    322        1.1    bouyer 		aprint_error("%s: unable to subregion %s channel ctl regs\n",
    323       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    324       1.17   thorpej 		bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh,
    325        1.3      fvdl 		     *cmdsizep);
    326       1.17   thorpej 		bus_space_unmap(wdr->cmd_iot, cp->ctl_baseioh, *ctlsizep);
    327        1.1    bouyer 		goto bad;
    328        1.1    bouyer 	}
    329        1.1    bouyer 
    330        1.3      fvdl 	for (i = 0; i < WDC_NREG; i++) {
    331       1.17   thorpej 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, i,
    332       1.17   thorpej 		    i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
    333        1.3      fvdl 			aprint_error("%s: couldn't subregion %s channel "
    334        1.3      fvdl 				     "cmd regs\n",
    335       1.20   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    336        1.3      fvdl 			goto bad;
    337        1.3      fvdl 		}
    338        1.3      fvdl 	}
    339       1.11   thorpej 	wdc_init_shadow_regs(wdc_cp);
    340       1.17   thorpej 	wdr->data32iot = wdr->cmd_iot;
    341       1.17   thorpej 	wdr->data32ioh = wdr->cmd_iohs[0];
    342        1.1    bouyer 	return;
    343        1.1    bouyer 
    344        1.1    bouyer bad:
    345       1.17   thorpej 	cp->ata_channel.ch_flags |= ATACH_DISABLED;
    346        1.1    bouyer 	return;
    347        1.1    bouyer }
    348        1.1    bouyer 
    349  1.31.10.1      yamt #if NATA_DMA
    350        1.1    bouyer void
    351        1.1    bouyer pciide_mapreg_dma(sc, pa)
    352        1.1    bouyer 	struct pciide_softc *sc;
    353        1.1    bouyer 	struct pci_attach_args *pa;
    354        1.1    bouyer {
    355        1.1    bouyer 	pcireg_t maptype;
    356        1.1    bouyer 	bus_addr_t addr;
    357        1.3      fvdl 	struct pciide_channel *pc;
    358        1.3      fvdl 	int reg, chan;
    359        1.3      fvdl 	bus_size_t size;
    360        1.1    bouyer 
    361        1.1    bouyer 	/*
    362        1.1    bouyer 	 * Map DMA registers
    363        1.1    bouyer 	 *
    364        1.1    bouyer 	 * Note that sc_dma_ok is the right variable to test to see if
    365        1.1    bouyer 	 * DMA can be done.  If the interface doesn't support DMA,
    366        1.1    bouyer 	 * sc_dma_ok will never be non-zero.  If the DMA regs couldn't
    367        1.1    bouyer 	 * be mapped, it'll be zero.  I.e., sc_dma_ok will only be
    368        1.1    bouyer 	 * non-zero if the interface supports DMA and the registers
    369        1.1    bouyer 	 * could be mapped.
    370        1.1    bouyer 	 *
    371        1.1    bouyer 	 * XXX Note that despite the fact that the Bus Master IDE specs
    372        1.1    bouyer 	 * XXX say that "The bus master IDE function uses 16 bytes of IO
    373        1.1    bouyer 	 * XXX space," some controllers (at least the United
    374        1.1    bouyer 	 * XXX Microelectronics UM8886BF) place it in memory space.
    375        1.1    bouyer 	 */
    376        1.1    bouyer 	maptype = pci_mapreg_type(pa->pa_pc, pa->pa_tag,
    377        1.1    bouyer 	    PCIIDE_REG_BUS_MASTER_DMA);
    378        1.1    bouyer 
    379        1.1    bouyer 	switch (maptype) {
    380        1.1    bouyer 	case PCI_MAPREG_TYPE_IO:
    381        1.1    bouyer 		sc->sc_dma_ok = (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
    382        1.1    bouyer 		    PCIIDE_REG_BUS_MASTER_DMA, PCI_MAPREG_TYPE_IO,
    383        1.1    bouyer 		    &addr, NULL, NULL) == 0);
    384        1.1    bouyer 		if (sc->sc_dma_ok == 0) {
    385        1.1    bouyer 			aprint_normal(
    386        1.1    bouyer 			    ", but unused (couldn't query registers)");
    387        1.1    bouyer 			break;
    388        1.1    bouyer 		}
    389        1.1    bouyer 		if ((sc->sc_pp->ide_flags & IDE_16BIT_IOSPACE)
    390        1.1    bouyer 		    && addr >= 0x10000) {
    391        1.1    bouyer 			sc->sc_dma_ok = 0;
    392        1.1    bouyer 			aprint_normal(
    393        1.1    bouyer 			    ", but unused (registers at unsafe address "
    394        1.1    bouyer 			    "%#lx)", (unsigned long)addr);
    395        1.1    bouyer 			break;
    396        1.1    bouyer 		}
    397        1.1    bouyer 		/* FALLTHROUGH */
    398       1.26     perry 
    399        1.1    bouyer 	case PCI_MAPREG_MEM_TYPE_32BIT:
    400        1.1    bouyer 		sc->sc_dma_ok = (pci_mapreg_map(pa,
    401        1.1    bouyer 		    PCIIDE_REG_BUS_MASTER_DMA, maptype, 0,
    402        1.1    bouyer 		    &sc->sc_dma_iot, &sc->sc_dma_ioh, NULL, NULL) == 0);
    403        1.1    bouyer 		sc->sc_dmat = pa->pa_dmat;
    404        1.1    bouyer 		if (sc->sc_dma_ok == 0) {
    405        1.1    bouyer 			aprint_normal(", but unused (couldn't map registers)");
    406        1.1    bouyer 		} else {
    407        1.1    bouyer 			sc->sc_wdcdev.dma_arg = sc;
    408        1.1    bouyer 			sc->sc_wdcdev.dma_init = pciide_dma_init;
    409        1.1    bouyer 			sc->sc_wdcdev.dma_start = pciide_dma_start;
    410        1.1    bouyer 			sc->sc_wdcdev.dma_finish = pciide_dma_finish;
    411        1.1    bouyer 		}
    412        1.1    bouyer 
    413       1.31   thorpej 		if (device_cfdata(&sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
    414        1.1    bouyer 		    PCIIDE_OPTIONS_NODMA) {
    415        1.1    bouyer 			aprint_normal(
    416        1.1    bouyer 			    ", but unused (forced off by config file)");
    417        1.1    bouyer 			sc->sc_dma_ok = 0;
    418        1.1    bouyer 		}
    419        1.1    bouyer 		break;
    420        1.1    bouyer 
    421        1.1    bouyer 	default:
    422        1.1    bouyer 		sc->sc_dma_ok = 0;
    423        1.1    bouyer 		aprint_normal(
    424        1.1    bouyer 		    ", but unsupported register maptype (0x%x)", maptype);
    425        1.1    bouyer 	}
    426        1.3      fvdl 
    427       1.12    bouyer 	if (sc->sc_dma_ok == 0)
    428       1.12    bouyer 		return;
    429       1.12    bouyer 
    430        1.3      fvdl 	/*
    431        1.3      fvdl 	 * Set up the default handles for the DMA registers.
    432        1.3      fvdl 	 * Just reserve 32 bits for each handle, unless space
    433        1.3      fvdl 	 * doesn't permit it.
    434        1.3      fvdl 	 */
    435        1.3      fvdl 	for (chan = 0; chan < PCIIDE_NUM_CHANNELS; chan++) {
    436        1.3      fvdl 		pc = &sc->pciide_channels[chan];
    437        1.3      fvdl 		for (reg = 0; reg < IDEDMA_NREGS; reg++) {
    438        1.3      fvdl 			size = 4;
    439        1.3      fvdl 			if (size > (IDEDMA_SCH_OFFSET - reg))
    440        1.3      fvdl 				size = IDEDMA_SCH_OFFSET - reg;
    441        1.3      fvdl 			if (bus_space_subregion(sc->sc_dma_iot, sc->sc_dma_ioh,
    442        1.3      fvdl 			    IDEDMA_SCH_OFFSET * chan + reg, size,
    443        1.3      fvdl 			    &pc->dma_iohs[reg]) != 0) {
    444        1.3      fvdl 				sc->sc_dma_ok = 0;
    445        1.3      fvdl 				aprint_normal(", but can't subregion offset %d "
    446        1.3      fvdl 					      "size %lu", reg, (u_long)size);
    447        1.3      fvdl 				return;
    448        1.3      fvdl 			}
    449        1.3      fvdl 		}
    450        1.3      fvdl 	}
    451        1.1    bouyer }
    452  1.31.10.1      yamt #endif	/* NATA_DMA */
    453        1.1    bouyer 
    454        1.1    bouyer int
    455        1.1    bouyer pciide_compat_intr(arg)
    456        1.1    bouyer 	void *arg;
    457        1.1    bouyer {
    458        1.1    bouyer 	struct pciide_channel *cp = arg;
    459        1.1    bouyer 
    460        1.1    bouyer #ifdef DIAGNOSTIC
    461        1.1    bouyer 	/* should only be called for a compat channel */
    462        1.1    bouyer 	if (cp->compat == 0)
    463        1.1    bouyer 		panic("pciide compat intr called for non-compat chan %p", cp);
    464        1.1    bouyer #endif
    465       1.17   thorpej 	return (wdcintr(&cp->ata_channel));
    466        1.1    bouyer }
    467        1.1    bouyer 
    468        1.1    bouyer int
    469        1.1    bouyer pciide_pci_intr(arg)
    470        1.1    bouyer 	void *arg;
    471        1.1    bouyer {
    472        1.1    bouyer 	struct pciide_softc *sc = arg;
    473        1.1    bouyer 	struct pciide_channel *cp;
    474       1.17   thorpej 	struct ata_channel *wdc_cp;
    475        1.1    bouyer 	int i, rv, crv;
    476        1.1    bouyer 
    477        1.1    bouyer 	rv = 0;
    478       1.20   thorpej 	for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
    479        1.1    bouyer 		cp = &sc->pciide_channels[i];
    480       1.17   thorpej 		wdc_cp = &cp->ata_channel;
    481        1.1    bouyer 
    482        1.1    bouyer 		/* If a compat channel skip. */
    483        1.1    bouyer 		if (cp->compat)
    484        1.1    bouyer 			continue;
    485        1.1    bouyer 		/* if this channel not waiting for intr, skip */
    486       1.17   thorpej 		if ((wdc_cp->ch_flags & ATACH_IRQ_WAIT) == 0)
    487        1.1    bouyer 			continue;
    488        1.1    bouyer 
    489        1.1    bouyer 		crv = wdcintr(wdc_cp);
    490        1.1    bouyer 		if (crv == 0)
    491        1.1    bouyer 			;		/* leave rv alone */
    492        1.1    bouyer 		else if (crv == 1)
    493        1.1    bouyer 			rv = 1;		/* claim the intr */
    494        1.1    bouyer 		else if (rv == 0)	/* crv should be -1 in this case */
    495        1.1    bouyer 			rv = crv;	/* if we've done no better, take it */
    496        1.1    bouyer 	}
    497        1.1    bouyer 	return (rv);
    498        1.1    bouyer }
    499        1.1    bouyer 
    500  1.31.10.1      yamt #if NATA_DMA
    501        1.1    bouyer void
    502        1.1    bouyer pciide_channel_dma_setup(cp)
    503        1.1    bouyer 	struct pciide_channel *cp;
    504        1.1    bouyer {
    505       1.21   thorpej 	int drive, s;
    506       1.19   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    507        1.1    bouyer 	struct ata_drive_datas *drvp;
    508        1.1    bouyer 
    509       1.17   thorpej 	KASSERT(cp->ata_channel.ch_ndrive != 0);
    510       1.17   thorpej 
    511       1.17   thorpej 	for (drive = 0; drive < cp->ata_channel.ch_ndrive; drive++) {
    512       1.17   thorpej 		drvp = &cp->ata_channel.ch_drive[drive];
    513        1.1    bouyer 		/* If no drive, skip */
    514        1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    515        1.1    bouyer 			continue;
    516        1.1    bouyer 		/* setup DMA if needed */
    517        1.1    bouyer 		if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
    518        1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA) == 0) ||
    519        1.1    bouyer 		    sc->sc_dma_ok == 0) {
    520       1.21   thorpej 			s = splbio();
    521        1.1    bouyer 			drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);
    522       1.21   thorpej 			splx(s);
    523        1.1    bouyer 			continue;
    524        1.1    bouyer 		}
    525       1.17   thorpej 		if (pciide_dma_table_setup(sc, cp->ata_channel.ch_channel,
    526        1.8   thorpej 					   drive) != 0) {
    527        1.1    bouyer 			/* Abort DMA setup */
    528       1.21   thorpej 			s = splbio();
    529        1.1    bouyer 			drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);
    530       1.21   thorpej 			splx(s);
    531        1.1    bouyer 			continue;
    532        1.1    bouyer 		}
    533        1.1    bouyer 	}
    534        1.1    bouyer }
    535        1.1    bouyer 
    536       1.24    briggs #define NIDEDMA_TABLES(sc)	\
    537       1.25    briggs 	(MAXPHYS/(min((sc)->sc_dma_maxsegsz, PAGE_SIZE)) + 1)
    538       1.24    briggs 
    539        1.1    bouyer int
    540        1.1    bouyer pciide_dma_table_setup(sc, channel, drive)
    541        1.1    bouyer 	struct pciide_softc *sc;
    542        1.1    bouyer 	int channel, drive;
    543        1.1    bouyer {
    544        1.1    bouyer 	bus_dma_segment_t seg;
    545        1.1    bouyer 	int error, rseg;
    546        1.1    bouyer 	const bus_size_t dma_table_size =
    547       1.24    briggs 	    sizeof(struct idedma_table) * NIDEDMA_TABLES(sc);
    548        1.1    bouyer 	struct pciide_dma_maps *dma_maps =
    549        1.1    bouyer 	    &sc->pciide_channels[channel].dma_maps[drive];
    550        1.1    bouyer 
    551        1.1    bouyer 	/* If table was already allocated, just return */
    552        1.1    bouyer 	if (dma_maps->dma_table)
    553        1.1    bouyer 		return 0;
    554        1.1    bouyer 
    555        1.1    bouyer 	/* Allocate memory for the DMA tables and map it */
    556        1.1    bouyer 	if ((error = bus_dmamem_alloc(sc->sc_dmat, dma_table_size,
    557        1.1    bouyer 	    IDEDMA_TBL_ALIGN, IDEDMA_TBL_ALIGN, &seg, 1, &rseg,
    558        1.1    bouyer 	    BUS_DMA_NOWAIT)) != 0) {
    559       1.20   thorpej 		aprint_error(dmaerrfmt, sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    560       1.20   thorpej 		    channel, "allocate", drive, error);
    561        1.1    bouyer 		return error;
    562        1.1    bouyer 	}
    563        1.1    bouyer 	if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
    564        1.1    bouyer 	    dma_table_size,
    565        1.1    bouyer 	    (caddr_t *)&dma_maps->dma_table,
    566        1.1    bouyer 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    567       1.20   thorpej 		aprint_error(dmaerrfmt, sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    568       1.20   thorpej 		    channel, "map", drive, error);
    569        1.1    bouyer 		return error;
    570        1.1    bouyer 	}
    571       1.16   thorpej 	ATADEBUG_PRINT(("pciide_dma_table_setup: table at %p len %lu, "
    572        1.1    bouyer 	    "phy 0x%lx\n", dma_maps->dma_table, (u_long)dma_table_size,
    573        1.1    bouyer 	    (unsigned long)seg.ds_addr), DEBUG_PROBE);
    574        1.1    bouyer 	/* Create and load table DMA map for this disk */
    575        1.1    bouyer 	if ((error = bus_dmamap_create(sc->sc_dmat, dma_table_size,
    576        1.1    bouyer 	    1, dma_table_size, IDEDMA_TBL_ALIGN, BUS_DMA_NOWAIT,
    577        1.1    bouyer 	    &dma_maps->dmamap_table)) != 0) {
    578       1.20   thorpej 		aprint_error(dmaerrfmt, sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    579       1.20   thorpej 		    channel, "create", drive, error);
    580        1.1    bouyer 		return error;
    581        1.1    bouyer 	}
    582        1.1    bouyer 	if ((error = bus_dmamap_load(sc->sc_dmat,
    583        1.1    bouyer 	    dma_maps->dmamap_table,
    584        1.1    bouyer 	    dma_maps->dma_table,
    585        1.1    bouyer 	    dma_table_size, NULL, BUS_DMA_NOWAIT)) != 0) {
    586       1.20   thorpej 		aprint_error(dmaerrfmt, sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    587       1.20   thorpej 		    channel, "load", drive, error);
    588        1.1    bouyer 		return error;
    589        1.1    bouyer 	}
    590       1.16   thorpej 	ATADEBUG_PRINT(("pciide_dma_table_setup: phy addr of table 0x%lx\n",
    591        1.1    bouyer 	    (unsigned long)dma_maps->dmamap_table->dm_segs[0].ds_addr),
    592        1.1    bouyer 	    DEBUG_PROBE);
    593        1.1    bouyer 	/* Create a xfer DMA map for this drive */
    594       1.25    briggs 	if ((error = bus_dmamap_create(sc->sc_dmat, MAXPHYS,
    595       1.24    briggs 	    NIDEDMA_TABLES(sc), sc->sc_dma_maxsegsz, sc->sc_dma_boundary,
    596        1.1    bouyer 	    BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
    597        1.1    bouyer 	    &dma_maps->dmamap_xfer)) != 0) {
    598       1.20   thorpej 		aprint_error(dmaerrfmt, sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    599       1.20   thorpej 		    channel, "create xfer", drive, error);
    600        1.1    bouyer 		return error;
    601        1.1    bouyer 	}
    602        1.1    bouyer 	return 0;
    603        1.1    bouyer }
    604        1.1    bouyer 
    605        1.1    bouyer int
    606       1.22    bouyer pciide_dma_dmamap_setup(sc, channel, drive, databuf, datalen, flags)
    607       1.22    bouyer 	struct pciide_softc *sc;
    608        1.1    bouyer 	int channel, drive;
    609        1.1    bouyer 	void *databuf;
    610        1.1    bouyer 	size_t datalen;
    611        1.1    bouyer 	int flags;
    612        1.1    bouyer {
    613        1.1    bouyer 	int error, seg;
    614        1.3      fvdl 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    615        1.3      fvdl 	struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
    616        1.1    bouyer 
    617        1.1    bouyer 	error = bus_dmamap_load(sc->sc_dmat,
    618        1.1    bouyer 	    dma_maps->dmamap_xfer,
    619        1.1    bouyer 	    databuf, datalen, NULL, BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
    620        1.1    bouyer 	    ((flags & WDC_DMA_READ) ? BUS_DMA_READ : BUS_DMA_WRITE));
    621        1.1    bouyer 	if (error) {
    622       1.20   thorpej 		printf(dmaerrfmt, sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    623       1.20   thorpej 		    channel, "load xfer", drive, error);
    624        1.1    bouyer 		return error;
    625        1.1    bouyer 	}
    626        1.1    bouyer 
    627        1.1    bouyer 	bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
    628        1.1    bouyer 	    dma_maps->dmamap_xfer->dm_mapsize,
    629        1.1    bouyer 	    (flags & WDC_DMA_READ) ?
    630        1.1    bouyer 	    BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
    631        1.1    bouyer 
    632        1.1    bouyer 	for (seg = 0; seg < dma_maps->dmamap_xfer->dm_nsegs; seg++) {
    633        1.1    bouyer #ifdef DIAGNOSTIC
    634        1.1    bouyer 		/* A segment must not cross a 64k boundary */
    635        1.1    bouyer 		{
    636        1.1    bouyer 		u_long phys = dma_maps->dmamap_xfer->dm_segs[seg].ds_addr;
    637        1.1    bouyer 		u_long len = dma_maps->dmamap_xfer->dm_segs[seg].ds_len;
    638        1.1    bouyer 		if ((phys & ~IDEDMA_BYTE_COUNT_MASK) !=
    639        1.1    bouyer 		    ((phys + len - 1) & ~IDEDMA_BYTE_COUNT_MASK)) {
    640        1.1    bouyer 			printf("pciide_dma: segment %d physical addr 0x%lx"
    641        1.1    bouyer 			    " len 0x%lx not properly aligned\n",
    642        1.1    bouyer 			    seg, phys, len);
    643        1.1    bouyer 			panic("pciide_dma: buf align");
    644        1.1    bouyer 		}
    645        1.1    bouyer 		}
    646        1.1    bouyer #endif
    647        1.1    bouyer 		dma_maps->dma_table[seg].base_addr =
    648        1.1    bouyer 		    htole32(dma_maps->dmamap_xfer->dm_segs[seg].ds_addr);
    649        1.1    bouyer 		dma_maps->dma_table[seg].byte_count =
    650        1.1    bouyer 		    htole32(dma_maps->dmamap_xfer->dm_segs[seg].ds_len &
    651        1.1    bouyer 		    IDEDMA_BYTE_COUNT_MASK);
    652       1.16   thorpej 		ATADEBUG_PRINT(("\t seg %d len %d addr 0x%x\n",
    653        1.1    bouyer 		   seg, le32toh(dma_maps->dma_table[seg].byte_count),
    654        1.1    bouyer 		   le32toh(dma_maps->dma_table[seg].base_addr)), DEBUG_DMA);
    655        1.1    bouyer 
    656        1.1    bouyer 	}
    657        1.1    bouyer 	dma_maps->dma_table[dma_maps->dmamap_xfer->dm_nsegs -1].byte_count |=
    658        1.1    bouyer 	    htole32(IDEDMA_BYTE_COUNT_EOT);
    659        1.1    bouyer 
    660        1.1    bouyer 	bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_table, 0,
    661        1.1    bouyer 	    dma_maps->dmamap_table->dm_mapsize,
    662        1.1    bouyer 	    BUS_DMASYNC_PREWRITE);
    663        1.1    bouyer 
    664        1.1    bouyer #ifdef DIAGNOSTIC
    665        1.1    bouyer 	if (dma_maps->dmamap_table->dm_segs[0].ds_addr & ~IDEDMA_TBL_MASK) {
    666       1.22    bouyer 		printf("pciide_dma_dmamap_setup: addr 0x%lx "
    667       1.22    bouyer 		    "not properly aligned\n",
    668        1.1    bouyer 		    (u_long)dma_maps->dmamap_table->dm_segs[0].ds_addr);
    669        1.1    bouyer 		panic("pciide_dma_init: table align");
    670        1.1    bouyer 	}
    671        1.1    bouyer #endif
    672       1.22    bouyer 	/* remember flags */
    673       1.22    bouyer 	dma_maps->dma_flags = flags;
    674       1.22    bouyer 
    675       1.22    bouyer 	return 0;
    676       1.22    bouyer }
    677       1.22    bouyer 
    678       1.22    bouyer int
    679       1.22    bouyer pciide_dma_init(v, channel, drive, databuf, datalen, flags)
    680       1.22    bouyer 	void *v;
    681       1.22    bouyer 	int channel, drive;
    682       1.22    bouyer 	void *databuf;
    683       1.22    bouyer 	size_t datalen;
    684       1.22    bouyer 	int flags;
    685       1.22    bouyer {
    686       1.22    bouyer 	struct pciide_softc *sc = v;
    687       1.22    bouyer 	int error;
    688       1.22    bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    689       1.22    bouyer 	struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
    690        1.1    bouyer 
    691       1.22    bouyer 	if ((error = pciide_dma_dmamap_setup(sc, channel, drive,
    692       1.22    bouyer 	    databuf, datalen, flags)) != 0)
    693       1.22    bouyer 		return error;
    694       1.22    bouyer 	/* Maps are ready. Start DMA function */
    695        1.1    bouyer 	/* Clear status bits */
    696        1.3      fvdl 	bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    697        1.3      fvdl 	    bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0));
    698        1.1    bouyer 	/* Write table addr */
    699        1.3      fvdl 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_TBL], 0,
    700        1.1    bouyer 	    dma_maps->dmamap_table->dm_segs[0].ds_addr);
    701        1.1    bouyer 	/* set read/write */
    702        1.3      fvdl 	bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    703        1.5   thorpej 	    ((flags & WDC_DMA_READ) ? IDEDMA_CMD_WRITE : 0) | cp->idedma_cmd);
    704        1.1    bouyer 	return 0;
    705        1.1    bouyer }
    706        1.1    bouyer 
    707        1.1    bouyer void
    708  1.31.10.1      yamt pciide_dma_start(void *v, int channel, int drive __unused)
    709        1.1    bouyer {
    710        1.1    bouyer 	struct pciide_softc *sc = v;
    711        1.3      fvdl 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    712        1.1    bouyer 
    713       1.16   thorpej 	ATADEBUG_PRINT(("pciide_dma_start\n"),DEBUG_XFERS);
    714        1.3      fvdl 	bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    715        1.3      fvdl 	    bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0)
    716        1.3      fvdl 		| IDEDMA_CMD_START);
    717        1.1    bouyer }
    718        1.1    bouyer 
    719        1.1    bouyer int
    720        1.1    bouyer pciide_dma_finish(v, channel, drive, force)
    721        1.1    bouyer 	void *v;
    722        1.1    bouyer 	int channel, drive;
    723        1.1    bouyer 	int force;
    724        1.1    bouyer {
    725        1.1    bouyer 	struct pciide_softc *sc = v;
    726        1.1    bouyer 	u_int8_t status;
    727        1.1    bouyer 	int error = 0;
    728        1.3      fvdl 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    729        1.3      fvdl 	struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
    730        1.1    bouyer 
    731        1.3      fvdl 	status = bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0);
    732       1.16   thorpej 	ATADEBUG_PRINT(("pciide_dma_finish: status 0x%x\n", status),
    733        1.1    bouyer 	    DEBUG_XFERS);
    734        1.1    bouyer 
    735       1.14    bouyer 	if (force == WDC_DMAEND_END && (status & IDEDMA_CTL_INTR) == 0)
    736        1.1    bouyer 		return WDC_DMAST_NOIRQ;
    737        1.1    bouyer 
    738        1.1    bouyer 	/* stop DMA channel */
    739        1.3      fvdl 	bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    740        1.3      fvdl 	    bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0)
    741        1.3      fvdl 		& ~IDEDMA_CMD_START);
    742        1.1    bouyer 
    743        1.1    bouyer 	/* Unload the map of the data buffer */
    744        1.1    bouyer 	bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
    745        1.1    bouyer 	    dma_maps->dmamap_xfer->dm_mapsize,
    746        1.1    bouyer 	    (dma_maps->dma_flags & WDC_DMA_READ) ?
    747        1.1    bouyer 	    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    748        1.1    bouyer 	bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_xfer);
    749        1.1    bouyer 
    750       1.14    bouyer 	if ((status & IDEDMA_CTL_ERR) != 0 && force != WDC_DMAEND_ABRT_QUIET) {
    751        1.1    bouyer 		printf("%s:%d:%d: bus-master DMA error: status=0x%x\n",
    752       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel, drive,
    753       1.20   thorpej 		    status);
    754        1.1    bouyer 		error |= WDC_DMAST_ERR;
    755        1.1    bouyer 	}
    756        1.1    bouyer 
    757       1.14    bouyer 	if ((status & IDEDMA_CTL_INTR) == 0 && force != WDC_DMAEND_ABRT_QUIET) {
    758        1.1    bouyer 		printf("%s:%d:%d: bus-master DMA error: missing interrupt, "
    759       1.20   thorpej 		    "status=0x%x\n", sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    760       1.20   thorpej 		    channel, drive, status);
    761        1.1    bouyer 		error |= WDC_DMAST_NOIRQ;
    762        1.1    bouyer 	}
    763        1.1    bouyer 
    764       1.14    bouyer 	if ((status & IDEDMA_CTL_ACT) != 0 && force != WDC_DMAEND_ABRT_QUIET) {
    765        1.1    bouyer 		/* data underrun, may be a valid condition for ATAPI */
    766        1.1    bouyer 		error |= WDC_DMAST_UNDER;
    767        1.1    bouyer 	}
    768        1.1    bouyer 	return error;
    769        1.1    bouyer }
    770        1.1    bouyer 
    771        1.1    bouyer void
    772        1.1    bouyer pciide_irqack(chp)
    773       1.17   thorpej 	struct ata_channel *chp;
    774        1.1    bouyer {
    775       1.19   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    776       1.19   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    777        1.1    bouyer 
    778        1.1    bouyer 	/* clear status bits in IDE DMA registers */
    779        1.3      fvdl 	bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    780        1.3      fvdl 	    bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0));
    781        1.1    bouyer }
    782  1.31.10.1      yamt #endif	/* NATA_DMA */
    783        1.1    bouyer 
    784        1.1    bouyer /* some common code used by several chip_map */
    785        1.1    bouyer int
    786        1.1    bouyer pciide_chansetup(sc, channel, interface)
    787        1.1    bouyer 	struct pciide_softc *sc;
    788        1.1    bouyer 	int channel;
    789        1.1    bouyer 	pcireg_t interface;
    790        1.1    bouyer {
    791        1.1    bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    792       1.17   thorpej 	sc->wdc_chanarray[channel] = &cp->ata_channel;
    793        1.1    bouyer 	cp->name = PCIIDE_CHANNEL_NAME(channel);
    794       1.17   thorpej 	cp->ata_channel.ch_channel = channel;
    795       1.20   thorpej 	cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    796       1.17   thorpej 	cp->ata_channel.ch_queue =
    797        1.6   thorpej 	    malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
    798       1.17   thorpej 	if (cp->ata_channel.ch_queue == NULL) {
    799        1.1    bouyer 		aprint_error("%s %s channel: "
    800        1.1    bouyer 		    "can't allocate memory for command queue",
    801       1.20   thorpej 		sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    802        1.1    bouyer 		return 0;
    803        1.1    bouyer 	}
    804       1.30    bouyer 	cp->ata_channel.ch_ndrive = 2;
    805        1.1    bouyer 	aprint_normal("%s: %s channel %s to %s mode\n",
    806       1.20   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name,
    807        1.1    bouyer 	    (interface & PCIIDE_INTERFACE_SETTABLE(channel)) ?
    808        1.1    bouyer 	    "configured" : "wired",
    809        1.1    bouyer 	    (interface & PCIIDE_INTERFACE_PCI(channel)) ?
    810        1.1    bouyer 	    "native-PCI" : "compatibility");
    811        1.1    bouyer 	return 1;
    812        1.1    bouyer }
    813        1.1    bouyer 
    814        1.1    bouyer /* some common code used by several chip channel_map */
    815        1.1    bouyer void
    816        1.1    bouyer pciide_mapchan(pa, cp, interface, cmdsizep, ctlsizep, pci_intr)
    817        1.1    bouyer 	struct pci_attach_args *pa;
    818        1.1    bouyer 	struct pciide_channel *cp;
    819        1.1    bouyer 	pcireg_t interface;
    820        1.1    bouyer 	bus_size_t *cmdsizep, *ctlsizep;
    821       1.23     perry 	int (*pci_intr)(void *);
    822        1.1    bouyer {
    823       1.17   thorpej 	struct ata_channel *wdc_cp = &cp->ata_channel;
    824        1.1    bouyer 
    825        1.8   thorpej 	if (interface & PCIIDE_INTERFACE_PCI(wdc_cp->ch_channel))
    826        1.1    bouyer 		pciide_mapregs_native(pa, cp, cmdsizep, ctlsizep, pci_intr);
    827       1.13    bouyer 	else {
    828        1.8   thorpej 		pciide_mapregs_compat(pa, cp, wdc_cp->ch_channel, cmdsizep,
    829        1.1    bouyer 		    ctlsizep);
    830       1.17   thorpej 		if ((cp->ata_channel.ch_flags & ATACH_DISABLED) == 0)
    831       1.13    bouyer 			pciide_map_compat_intr(pa, cp, wdc_cp->ch_channel);
    832       1.13    bouyer 	}
    833        1.1    bouyer 	wdcattach(wdc_cp);
    834        1.1    bouyer }
    835        1.1    bouyer 
    836        1.1    bouyer /*
    837        1.1    bouyer  * generic code to map the compat intr.
    838        1.1    bouyer  */
    839        1.1    bouyer void
    840        1.1    bouyer pciide_map_compat_intr(pa, cp, compatchan)
    841        1.1    bouyer 	struct pci_attach_args *pa;
    842        1.1    bouyer 	struct pciide_channel *cp;
    843        1.1    bouyer 	int compatchan;
    844        1.1    bouyer {
    845       1.19   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    846        1.1    bouyer 
    847        1.1    bouyer #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    848       1.20   thorpej 	cp->ih =
    849       1.20   thorpej 	   pciide_machdep_compat_intr_establish(&sc->sc_wdcdev.sc_atac.atac_dev,
    850       1.20   thorpej 	   pa, compatchan, pciide_compat_intr, cp);
    851        1.1    bouyer 	if (cp->ih == NULL) {
    852        1.1    bouyer #endif
    853        1.1    bouyer 		aprint_error("%s: no compatibility interrupt for use by %s "
    854       1.20   thorpej 		    "channel\n", sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    855       1.20   thorpej 		    cp->name);
    856       1.17   thorpej 		cp->ata_channel.ch_flags |= ATACH_DISABLED;
    857        1.1    bouyer #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    858        1.1    bouyer 	}
    859        1.1    bouyer #endif
    860        1.1    bouyer }
    861        1.1    bouyer 
    862        1.1    bouyer void
    863        1.1    bouyer default_chip_map(sc, pa)
    864        1.1    bouyer 	struct pciide_softc *sc;
    865        1.1    bouyer 	struct pci_attach_args *pa;
    866        1.1    bouyer {
    867        1.1    bouyer 	struct pciide_channel *cp;
    868        1.1    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    869        1.1    bouyer 	pcireg_t csr;
    870  1.31.10.1      yamt 	int channel;
    871  1.31.10.1      yamt #if NATA_DMA
    872  1.31.10.1      yamt 	int drive;
    873        1.1    bouyer 	u_int8_t idedma_ctl;
    874  1.31.10.1      yamt #endif
    875        1.1    bouyer 	bus_size_t cmdsize, ctlsize;
    876       1.27  christos 	const char *failreason;
    877       1.17   thorpej 	struct wdc_regs *wdr;
    878        1.1    bouyer 
    879        1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    880        1.1    bouyer 		return;
    881        1.1    bouyer 
    882        1.1    bouyer 	if (interface & PCIIDE_INTERFACE_BUS_MASTER_DMA) {
    883  1.31.10.1      yamt #if NATA_DMA
    884        1.1    bouyer 		aprint_normal("%s: bus-master DMA support present",
    885       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    886        1.1    bouyer 		if (sc->sc_pp == &default_product_desc &&
    887       1.31   thorpej 		    (device_cfdata(&sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
    888        1.1    bouyer 		    PCIIDE_OPTIONS_DMA) == 0) {
    889        1.1    bouyer 			aprint_normal(", but unused (no driver support)");
    890        1.1    bouyer 			sc->sc_dma_ok = 0;
    891        1.1    bouyer 		} else {
    892        1.1    bouyer 			pciide_mapreg_dma(sc, pa);
    893        1.1    bouyer 			if (sc->sc_dma_ok != 0)
    894        1.1    bouyer 				aprint_normal(", used without full driver "
    895        1.1    bouyer 				    "support");
    896        1.1    bouyer 		}
    897  1.31.10.1      yamt #else
    898  1.31.10.1      yamt 		aprint_normal("%s: bus-master DMA support present, but unused (no driver support)",
    899  1.31.10.1      yamt 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    900  1.31.10.1      yamt #endif	/* NATA_DMA */
    901        1.1    bouyer 	} else {
    902        1.1    bouyer 		aprint_normal("%s: hardware does not support DMA",
    903       1.20   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    904  1.31.10.1      yamt #if NATA_DMA
    905        1.1    bouyer 		sc->sc_dma_ok = 0;
    906  1.31.10.1      yamt #endif
    907        1.1    bouyer 	}
    908        1.1    bouyer 	aprint_normal("\n");
    909  1.31.10.1      yamt #if NATA_DMA
    910        1.1    bouyer 	if (sc->sc_dma_ok) {
    911       1.20   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    912        1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    913        1.1    bouyer 	}
    914  1.31.10.1      yamt #endif
    915       1.20   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    916  1.31.10.1      yamt #if NATA_DMA
    917       1.20   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 0;
    918  1.31.10.1      yamt #endif
    919        1.1    bouyer 
    920       1.20   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    921       1.20   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    922       1.20   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    923        1.1    bouyer 
    924       1.17   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    925       1.17   thorpej 
    926       1.20   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    927       1.20   thorpej 	     channel++) {
    928        1.1    bouyer 		cp = &sc->pciide_channels[channel];
    929        1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    930        1.1    bouyer 			continue;
    931       1.19   thorpej 		wdr = CHAN_TO_WDC_REGS(&cp->ata_channel);
    932       1.10    bouyer 		if (interface & PCIIDE_INTERFACE_PCI(channel))
    933       1.10    bouyer 			pciide_mapregs_native(pa, cp, &cmdsize, &ctlsize,
    934       1.10    bouyer 			    pciide_pci_intr);
    935       1.10    bouyer 		else
    936       1.10    bouyer 			pciide_mapregs_compat(pa, cp,
    937       1.17   thorpej 			    cp->ata_channel.ch_channel, &cmdsize, &ctlsize);
    938       1.17   thorpej 		if (cp->ata_channel.ch_flags & ATACH_DISABLED)
    939        1.1    bouyer 			continue;
    940        1.1    bouyer 		/*
    941        1.1    bouyer 		 * Check to see if something appears to be there.
    942        1.1    bouyer 		 */
    943        1.1    bouyer 		failreason = NULL;
    944        1.1    bouyer 		/*
    945        1.1    bouyer 		 * In native mode, always enable the controller. It's
    946        1.1    bouyer 		 * not possible to have an ISA board using the same address
    947        1.1    bouyer 		 * anyway.
    948        1.1    bouyer 		 */
    949       1.13    bouyer 		if (interface & PCIIDE_INTERFACE_PCI(channel)) {
    950       1.17   thorpej 			wdcattach(&cp->ata_channel);
    951       1.13    bouyer 			continue;
    952       1.13    bouyer 		}
    953       1.17   thorpej 		if (!wdcprobe(&cp->ata_channel)) {
    954        1.1    bouyer 			failreason = "not responding; disabled or no drives?";
    955        1.1    bouyer 			goto next;
    956        1.1    bouyer 		}
    957        1.1    bouyer 		/*
    958        1.1    bouyer 		 * Now, make sure it's actually attributable to this PCI IDE
    959        1.1    bouyer 		 * channel by trying to access the channel again while the
    960        1.1    bouyer 		 * PCI IDE controller's I/O space is disabled.  (If the
    961        1.1    bouyer 		 * channel no longer appears to be there, it belongs to
    962        1.1    bouyer 		 * this controller.)  YUCK!
    963        1.1    bouyer 		 */
    964        1.1    bouyer 		csr = pci_conf_read(sc->sc_pc, sc->sc_tag,
    965        1.1    bouyer 		    PCI_COMMAND_STATUS_REG);
    966        1.1    bouyer 		pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_COMMAND_STATUS_REG,
    967        1.1    bouyer 		    csr & ~PCI_COMMAND_IO_ENABLE);
    968       1.17   thorpej 		if (wdcprobe(&cp->ata_channel))
    969        1.1    bouyer 			failreason = "other hardware responding at addresses";
    970        1.1    bouyer 		pci_conf_write(sc->sc_pc, sc->sc_tag,
    971        1.1    bouyer 		    PCI_COMMAND_STATUS_REG, csr);
    972        1.1    bouyer next:
    973        1.1    bouyer 		if (failreason) {
    974        1.1    bouyer 			aprint_error("%s: %s channel ignored (%s)\n",
    975       1.20   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name,
    976        1.1    bouyer 			    failreason);
    977       1.17   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    978       1.17   thorpej 			bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh,
    979       1.17   thorpej 			    cmdsize);
    980       1.17   thorpej 			bus_space_unmap(wdr->ctl_iot, wdr->ctl_ioh, ctlsize);
    981       1.10    bouyer 		} else {
    982       1.13    bouyer 			pciide_map_compat_intr(pa, cp,
    983       1.17   thorpej 			    cp->ata_channel.ch_channel);
    984       1.17   thorpej 			wdcattach(&cp->ata_channel);
    985        1.1    bouyer 		}
    986        1.1    bouyer 	}
    987        1.1    bouyer 
    988  1.31.10.1      yamt #if NATA_DMA
    989        1.1    bouyer 	if (sc->sc_dma_ok == 0)
    990        1.1    bouyer 		return;
    991        1.1    bouyer 
    992        1.1    bouyer 	/* Allocate DMA maps */
    993       1.20   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    994       1.20   thorpej 	     channel++) {
    995        1.1    bouyer 		idedma_ctl = 0;
    996        1.1    bouyer 		cp = &sc->pciide_channels[channel];
    997       1.17   thorpej 		for (drive = 0; drive < cp->ata_channel.ch_ndrive; drive++) {
    998       1.29    bouyer 			/*
    999       1.29    bouyer 			 * we have not probed the drives yet, allocate
   1000       1.29    bouyer 			 * ressources for all of them.
   1001       1.29    bouyer 			 */
   1002        1.1    bouyer 			if (pciide_dma_table_setup(sc, channel, drive) != 0) {
   1003        1.1    bouyer 				/* Abort DMA setup */
   1004        1.1    bouyer 				aprint_error(
   1005        1.1    bouyer 				    "%s:%d:%d: can't allocate DMA maps, "
   1006        1.1    bouyer 				    "using PIO transfers\n",
   1007       1.20   thorpej 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
   1008        1.1    bouyer 				    channel, drive);
   1009       1.29    bouyer 				sc->sc_dma_ok = 0;
   1010       1.29    bouyer 				sc->sc_wdcdev.sc_atac.atac_cap &= ~ATAC_CAP_DMA;
   1011       1.29    bouyer 				sc->sc_wdcdev.irqack = NULL;
   1012       1.29    bouyer 				break;
   1013        1.1    bouyer 			}
   1014        1.1    bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
   1015        1.1    bouyer 		}
   1016        1.1    bouyer 		if (idedma_ctl != 0) {
   1017        1.1    bouyer 			/* Add software bits in status register */
   1018        1.3      fvdl 			bus_space_write_1(sc->sc_dma_iot,
   1019        1.3      fvdl 			    cp->dma_iohs[IDEDMA_CTL], 0, idedma_ctl);
   1020        1.1    bouyer 		}
   1021        1.1    bouyer 	}
   1022  1.31.10.1      yamt #endif	/* NATA_DMA */
   1023        1.1    bouyer }
   1024        1.1    bouyer 
   1025        1.1    bouyer void
   1026        1.1    bouyer sata_setup_channel(chp)
   1027       1.17   thorpej 	struct ata_channel *chp;
   1028        1.1    bouyer {
   1029  1.31.10.1      yamt #if NATA_DMA
   1030        1.1    bouyer 	struct ata_drive_datas *drvp;
   1031  1.31.10.1      yamt 	int drive;
   1032  1.31.10.1      yamt #if NATA_UDMA
   1033  1.31.10.1      yamt 	int s;
   1034  1.31.10.1      yamt #endif
   1035        1.1    bouyer 	u_int32_t idedma_ctl;
   1036       1.19   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
   1037       1.19   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
   1038        1.1    bouyer 
   1039        1.1    bouyer 	/* setup DMA if needed */
   1040        1.1    bouyer 	pciide_channel_dma_setup(cp);
   1041        1.1    bouyer 
   1042        1.1    bouyer 	idedma_ctl = 0;
   1043        1.1    bouyer 
   1044       1.17   thorpej 	for (drive = 0; drive < cp->ata_channel.ch_ndrive; drive++) {
   1045        1.1    bouyer 		drvp = &chp->ch_drive[drive];
   1046        1.1    bouyer 		/* If no drive, skip */
   1047        1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
   1048        1.1    bouyer 			continue;
   1049  1.31.10.1      yamt #if NATA_UDMA
   1050        1.1    bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
   1051        1.1    bouyer 			/* use Ultra/DMA */
   1052       1.21   thorpej 			s = splbio();
   1053        1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
   1054       1.21   thorpej 			splx(s);
   1055        1.1    bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
   1056  1.31.10.1      yamt 		} else
   1057  1.31.10.1      yamt #endif	/* NATA_UDMA */
   1058  1.31.10.1      yamt 		if (drvp->drive_flags & DRIVE_DMA) {
   1059        1.1    bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
   1060        1.1    bouyer 		}
   1061        1.1    bouyer 	}
   1062        1.1    bouyer 
   1063        1.1    bouyer 	/*
   1064        1.1    bouyer 	 * Nothing to do to setup modes; it is meaningless in S-ATA
   1065        1.1    bouyer 	 * (but many S-ATA drives still want to get the SET_FEATURE
   1066        1.1    bouyer 	 * command).
   1067        1.1    bouyer 	 */
   1068        1.1    bouyer 	if (idedma_ctl != 0) {
   1069        1.1    bouyer 		/* Add software bits in status register */
   1070        1.3      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
   1071        1.1    bouyer 		    idedma_ctl);
   1072        1.1    bouyer 	}
   1073  1.31.10.1      yamt #endif	/* NATA_DMA */
   1074        1.1    bouyer }
   1075