Home | History | Annotate | Line # | Download | only in pci
hptide.c revision 1.24.20.1
      1  1.24.20.1     matt /*	hptide.c,v 1.24 2007/02/09 21:55:27 ad Exp	*/
      2        1.1   bouyer 
      3        1.1   bouyer /*
      4        1.1   bouyer  * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
      5        1.1   bouyer  *
      6        1.1   bouyer  * Redistribution and use in source and binary forms, with or without
      7        1.1   bouyer  * modification, are permitted provided that the following conditions
      8        1.1   bouyer  * are met:
      9        1.1   bouyer  * 1. Redistributions of source code must retain the above copyright
     10        1.1   bouyer  *    notice, this list of conditions and the following disclaimer.
     11        1.1   bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1   bouyer  *    notice, this list of conditions and the following disclaimer in the
     13        1.1   bouyer  *    documentation and/or other materials provided with the distribution.
     14        1.1   bouyer  * 3. All advertising materials mentioning features or use of this software
     15        1.1   bouyer  *    must display the following acknowledgement:
     16        1.1   bouyer  *	This product includes software developed by Manuel Bouyer.
     17        1.1   bouyer  * 4. The name of the author may not be used to endorse or promote products
     18        1.1   bouyer  *    derived from this software without specific prior written permission.
     19        1.1   bouyer  *
     20        1.1   bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21        1.1   bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22        1.1   bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23       1.17    perry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24        1.1   bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25        1.1   bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26        1.1   bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27        1.1   bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28        1.1   bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29        1.1   bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30        1.1   bouyer  */
     31        1.1   bouyer 
     32       1.18    lukem #include <sys/cdefs.h>
     33  1.24.20.1     matt __KERNEL_RCSID(0, "hptide.c,v 1.24 2007/02/09 21:55:27 ad Exp");
     34       1.18    lukem 
     35        1.1   bouyer #include <sys/param.h>
     36        1.1   bouyer #include <sys/systm.h>
     37        1.1   bouyer 
     38        1.1   bouyer #include <dev/pci/pcivar.h>
     39        1.1   bouyer #include <dev/pci/pcidevs.h>
     40        1.1   bouyer #include <dev/pci/pciidereg.h>
     41        1.1   bouyer #include <dev/pci/pciidevar.h>
     42        1.1   bouyer #include <dev/pci/pciide_hpt_reg.h>
     43        1.1   bouyer 
     44        1.2  thorpej static void hpt_chip_map(struct pciide_softc*, struct pci_attach_args*);
     45       1.13  thorpej static void hpt_setup_channel(struct ata_channel*);
     46        1.2  thorpej static int  hpt_pci_intr(void *);
     47        1.1   bouyer 
     48  1.24.20.1     matt static int  hptide_match(device_t, cfdata_t, void *);
     49  1.24.20.1     matt static void hptide_attach(device_t, device_t, void *);
     50        1.1   bouyer 
     51  1.24.20.1     matt CFATTACH_DECL_NEW(hptide, sizeof(struct pciide_softc),
     52        1.1   bouyer     hptide_match, hptide_attach, NULL, NULL);
     53        1.1   bouyer 
     54        1.2  thorpej static const struct pciide_product_desc pciide_triones_products[] =  {
     55        1.7      chs 	{ PCI_PRODUCT_TRIONES_HPT302,
     56        1.7      chs 	  0,
     57        1.7      chs 	  NULL,
     58        1.7      chs 	  hpt_chip_map
     59        1.7      chs 	},
     60        1.1   bouyer 	{ PCI_PRODUCT_TRIONES_HPT366,
     61        1.3  mycroft 	  0,
     62        1.1   bouyer 	  NULL,
     63        1.1   bouyer 	  hpt_chip_map,
     64        1.1   bouyer 	},
     65        1.7      chs 	{ PCI_PRODUCT_TRIONES_HPT371,
     66        1.7      chs 	  0,
     67        1.7      chs 	  NULL,
     68        1.7      chs 	  hpt_chip_map,
     69        1.7      chs 	},
     70        1.7      chs 	{ PCI_PRODUCT_TRIONES_HPT372A,
     71        1.3  mycroft 	  0,
     72        1.1   bouyer 	  NULL,
     73        1.1   bouyer 	  hpt_chip_map
     74        1.1   bouyer 	},
     75        1.1   bouyer 	{ PCI_PRODUCT_TRIONES_HPT374,
     76        1.3  mycroft 	  0,
     77        1.1   bouyer 	  NULL,
     78        1.1   bouyer 	  hpt_chip_map
     79        1.1   bouyer 	},
     80        1.1   bouyer 	{ 0,
     81        1.1   bouyer 	  0,
     82        1.1   bouyer 	  NULL,
     83        1.1   bouyer 	  NULL
     84        1.1   bouyer 	}
     85        1.1   bouyer };
     86        1.1   bouyer 
     87        1.2  thorpej static int
     88  1.24.20.1     matt hptide_match(device_t parent, cfdata_t match, void *aux)
     89        1.1   bouyer {
     90        1.1   bouyer 	struct pci_attach_args *pa = aux;
     91        1.1   bouyer 
     92        1.1   bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TRIONES) {
     93        1.1   bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_triones_products))
     94        1.1   bouyer 			return (2);
     95        1.1   bouyer 	}
     96        1.1   bouyer 	return (0);
     97        1.1   bouyer }
     98        1.1   bouyer 
     99        1.2  thorpej static void
    100  1.24.20.1     matt hptide_attach(device_t parent, device_t self, void *aux)
    101        1.1   bouyer {
    102        1.1   bouyer 	struct pci_attach_args *pa = aux;
    103  1.24.20.1     matt 	struct pciide_softc *sc = device_private(self);
    104  1.24.20.1     matt 
    105  1.24.20.1     matt 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    106        1.1   bouyer 
    107        1.1   bouyer 	pciide_common_attach(sc, pa,
    108        1.1   bouyer 	    pciide_lookup_product(pa->pa_id, pciide_triones_products));
    109        1.1   bouyer 
    110        1.1   bouyer }
    111        1.1   bouyer 
    112        1.2  thorpej static void
    113        1.2  thorpej hpt_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    114        1.1   bouyer {
    115        1.1   bouyer 	struct pciide_channel *cp;
    116        1.5  mycroft 	int i, compatchan, revision;
    117        1.1   bouyer 	pcireg_t interface;
    118        1.1   bouyer 	bus_size_t cmdsize, ctlsize;
    119        1.1   bouyer 
    120        1.1   bouyer 	if (pciide_chipen(sc, pa) == 0)
    121        1.1   bouyer 		return;
    122        1.1   bouyer 
    123        1.1   bouyer 	revision = PCI_REVISION(pa->pa_class);
    124  1.24.20.1     matt 	aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    125  1.24.20.1     matt 	    "Triones/Highpoint ");
    126        1.7      chs 	switch (sc->sc_pp->ide_product) {
    127        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT302:
    128        1.7      chs 		aprint_normal("HPT302 IDE Controller\n");
    129        1.7      chs 		break;
    130        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT371:
    131        1.7      chs 		aprint_normal("HPT371 IDE Controller\n");
    132        1.7      chs 		break;
    133        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT374:
    134        1.1   bouyer 		aprint_normal("HPT374 IDE Controller\n");
    135        1.7      chs 		break;
    136        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT372A:
    137        1.7      chs 		aprint_normal("HPT372A IDE Controller\n");
    138        1.7      chs 		break;
    139        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT366:
    140        1.1   bouyer 		if (revision == HPT372_REV)
    141        1.1   bouyer 			aprint_normal("HPT372 IDE Controller\n");
    142        1.1   bouyer 		else if (revision == HPT370_REV)
    143        1.1   bouyer 			aprint_normal("HPT370 IDE Controller\n");
    144        1.1   bouyer 		else if (revision == HPT370A_REV)
    145        1.1   bouyer 			aprint_normal("HPT370A IDE Controller\n");
    146       1.21  xtraeme 		else if (revision == HPT368_REV)
    147       1.21  xtraeme 			aprint_normal("HPT368 IDE Controller\n");
    148        1.1   bouyer 		else if (revision == HPT366_REV)
    149        1.1   bouyer 			aprint_normal("HPT366 IDE Controller\n");
    150        1.1   bouyer 		else
    151        1.1   bouyer 			aprint_normal("unknown HPT IDE controller rev %d\n",
    152        1.1   bouyer 			    revision);
    153        1.7      chs 		break;
    154        1.7      chs 	default:
    155        1.1   bouyer 		aprint_normal("unknown HPT IDE controller 0x%x\n",
    156        1.1   bouyer 		    sc->sc_pp->ide_product);
    157        1.7      chs 	}
    158        1.1   bouyer 
    159       1.17    perry 	/*
    160        1.1   bouyer 	 * when the chip is in native mode it identifies itself as a
    161        1.1   bouyer 	 * 'misc mass storage'. Fake interface in this case.
    162        1.1   bouyer 	 */
    163        1.1   bouyer 	if (PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {
    164        1.1   bouyer 		interface = PCI_INTERFACE(pa->pa_class);
    165        1.1   bouyer 	} else {
    166        1.1   bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    167        1.1   bouyer 		    PCIIDE_INTERFACE_PCI(0);
    168        1.1   bouyer 		if ((sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT366 &&
    169       1.21  xtraeme 		    (revision == HPT368_REV || revision == HPT370_REV || revision == HPT370A_REV ||
    170        1.1   bouyer 		     revision == HPT372_REV)) ||
    171        1.7      chs 		    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT302 ||
    172        1.7      chs 		    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT371 ||
    173        1.7      chs 		    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT372A ||
    174        1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT374)
    175        1.1   bouyer 			interface |= PCIIDE_INTERFACE_PCI(1);
    176        1.1   bouyer 	}
    177        1.1   bouyer 
    178  1.24.20.1     matt 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    179  1.24.20.1     matt 	    "bus-master DMA support present");
    180        1.1   bouyer 	pciide_mapreg_dma(sc, pa);
    181       1.24       ad 	aprint_verbose("\n");
    182       1.15  thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    183        1.1   bouyer 	if (sc->sc_dma_ok) {
    184       1.15  thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    185        1.1   bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    186        1.1   bouyer 	}
    187       1.15  thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    188       1.15  thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    189        1.1   bouyer 
    190       1.15  thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = hpt_setup_channel;
    191       1.15  thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    192        1.1   bouyer 	if (sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT366 &&
    193       1.21  xtraeme 	    (revision == HPT366_REV || revision == HPT368_REV)) {
    194       1.15  thorpej 		sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    195       1.15  thorpej 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    196        1.1   bouyer 	} else {
    197       1.15  thorpej 		sc->sc_wdcdev.sc_atac.atac_nchannels = 2;
    198        1.1   bouyer 		if (sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT374 ||
    199        1.7      chs 		    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT372A ||
    200        1.7      chs 		    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT371 ||
    201        1.7      chs 		    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT302 ||
    202        1.1   bouyer 		    (sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT366 &&
    203        1.1   bouyer 		    revision == HPT372_REV))
    204       1.15  thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    205        1.1   bouyer 		else
    206       1.15  thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    207        1.1   bouyer 	}
    208       1.13  thorpej 
    209       1.13  thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    210       1.13  thorpej 
    211       1.15  thorpej 	for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
    212        1.1   bouyer 		cp = &sc->pciide_channels[i];
    213       1.15  thorpej 		if (sc->sc_wdcdev.sc_atac.atac_nchannels > 1) {
    214        1.1   bouyer 			compatchan = i;
    215        1.1   bouyer 			if((pciide_pci_read(sc->sc_pc, sc->sc_tag,
    216        1.1   bouyer 			   HPT370_CTRL1(i)) & HPT370_CTRL1_EN) == 0) {
    217        1.1   bouyer 				aprint_normal(
    218        1.1   bouyer 				    "%s: %s channel ignored (disabled)\n",
    219  1.24.20.1     matt 				    device_xname(
    220  1.24.20.1     matt 				      sc->sc_wdcdev.sc_atac.atac_dev),
    221  1.24.20.1     matt 				    cp->name);
    222       1.13  thorpej 				cp->ata_channel.ch_flags |= ATACH_DISABLED;
    223        1.1   bouyer 				continue;
    224        1.5  mycroft 			}
    225        1.5  mycroft 		} else {
    226        1.5  mycroft 			/*
    227        1.5  mycroft 			 * The 366 has 2 PCI IDE functions, one for primary and
    228        1.5  mycroft 			 * one for secondary. So we need to call
    229        1.5  mycroft 			 * pciide_mapregs_compat() with the real channel.
    230        1.5  mycroft 			 */
    231        1.5  mycroft 			if (pa->pa_function == 0)
    232        1.5  mycroft 				compatchan = 0;
    233        1.5  mycroft 			else if (pa->pa_function == 1)
    234        1.5  mycroft 				compatchan = 1;
    235        1.5  mycroft 			else {
    236  1.24.20.1     matt 				aprint_error_dev(
    237  1.24.20.1     matt 				    sc->sc_wdcdev.sc_atac.atac_dev,
    238  1.24.20.1     matt 				    "unexpected PCI function %d\n",
    239  1.24.20.1     matt 				    pa->pa_function);
    240        1.5  mycroft 				return;
    241        1.1   bouyer 			}
    242        1.1   bouyer 		}
    243        1.1   bouyer 		if (pciide_chansetup(sc, i, interface) == 0)
    244        1.1   bouyer 			continue;
    245        1.1   bouyer 		if (interface & PCIIDE_INTERFACE_PCI(i)) {
    246        1.1   bouyer 			pciide_mapregs_native(pa, cp, &cmdsize,
    247        1.1   bouyer 			    &ctlsize, hpt_pci_intr);
    248        1.1   bouyer 		} else {
    249        1.1   bouyer 			pciide_mapregs_compat(pa, cp, compatchan,
    250        1.1   bouyer 			    &cmdsize, &ctlsize);
    251       1.13  thorpej 			if ((cp->ata_channel.ch_flags & ATACH_DISABLED) == 0)
    252       1.10   bouyer 				pciide_map_compat_intr(pa, cp,
    253       1.10   bouyer 				    sc->sc_cy_compatchan);
    254        1.1   bouyer 		}
    255       1.13  thorpej 		wdcattach(&cp->ata_channel);
    256        1.1   bouyer 	}
    257        1.1   bouyer 	if ((sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT366 &&
    258       1.21  xtraeme 	    (revision == HPT368_REV || revision == HPT370_REV || revision == HPT370A_REV ||
    259       1.17    perry 	     revision == HPT372_REV)) ||
    260        1.7      chs 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT302 ||
    261        1.7      chs 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT371 ||
    262        1.7      chs 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT372A ||
    263        1.1   bouyer 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT374) {
    264        1.1   bouyer 		/*
    265        1.1   bouyer 		 * HPT370_REV and highter has a bit to disable interrupts,
    266        1.1   bouyer 		 * make sure to clear it
    267        1.1   bouyer 		 */
    268        1.1   bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, HPT_CSEL,
    269        1.1   bouyer 		    pciide_pci_read(sc->sc_pc, sc->sc_tag, HPT_CSEL) &
    270        1.1   bouyer 		    ~HPT_CSEL_IRQDIS);
    271        1.1   bouyer 	}
    272        1.1   bouyer 	/* set clocks, etc (mandatory on 372/4, optional otherwise) */
    273        1.1   bouyer 	if ((sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT366 &&
    274        1.1   bouyer 	     revision == HPT372_REV ) ||
    275        1.7      chs 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT302 ||
    276        1.7      chs 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT371 ||
    277        1.7      chs 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT372A ||
    278        1.1   bouyer 	    sc->sc_pp->ide_product == PCI_PRODUCT_TRIONES_HPT374)
    279        1.1   bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, HPT_SC2,
    280        1.1   bouyer 		    (pciide_pci_read(sc->sc_pc, sc->sc_tag, HPT_SC2) &
    281        1.1   bouyer 		     HPT_SC2_MAEN) | HPT_SC2_OSC_EN);
    282        1.1   bouyer 	return;
    283        1.1   bouyer }
    284        1.1   bouyer 
    285        1.2  thorpej static void
    286       1.13  thorpej hpt_setup_channel(struct ata_channel *chp)
    287        1.1   bouyer {
    288        1.1   bouyer 	struct ata_drive_datas *drvp;
    289       1.16  thorpej 	int drive, s;
    290        1.1   bouyer 	int cable;
    291        1.1   bouyer 	u_int32_t before, after;
    292        1.1   bouyer 	u_int32_t idedma_ctl;
    293       1.14  thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    294       1.14  thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    295        1.1   bouyer 	int revision =
    296        1.1   bouyer 	     PCI_REVISION(pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
    297        1.7      chs 	const u_int32_t *tim_pio, *tim_dma, *tim_udma;
    298        1.1   bouyer 
    299        1.1   bouyer 	cable = pciide_pci_read(sc->sc_pc, sc->sc_tag, HPT_CSEL);
    300        1.1   bouyer 
    301        1.1   bouyer 	/* setup DMA if needed */
    302        1.1   bouyer 	pciide_channel_dma_setup(cp);
    303        1.1   bouyer 
    304        1.1   bouyer 	idedma_ctl = 0;
    305        1.1   bouyer 
    306        1.7      chs 	/* select the timing arrays for the chip */
    307        1.7      chs 	switch (sc->sc_pp->ide_product) {
    308        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT374:
    309        1.7      chs 		tim_udma = hpt374_udma;
    310        1.7      chs 		tim_dma = hpt374_dma;
    311        1.7      chs 		tim_pio = hpt374_pio;
    312        1.7      chs 		break;
    313        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT302:
    314        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT371:
    315        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT372A:
    316        1.7      chs 		tim_udma = hpt372_udma;
    317        1.7      chs 		tim_dma = hpt372_dma;
    318        1.7      chs 		tim_pio = hpt372_pio;
    319        1.7      chs 		break;
    320        1.7      chs 	case PCI_PRODUCT_TRIONES_HPT366:
    321        1.7      chs 	default:
    322        1.7      chs 		switch (revision) {
    323        1.7      chs 		case HPT372_REV:
    324        1.7      chs 			tim_udma = hpt372_udma;
    325        1.7      chs 			tim_dma = hpt372_dma;
    326        1.7      chs 			tim_pio = hpt372_pio;
    327        1.7      chs 			break;
    328        1.7      chs 		case HPT370_REV:
    329        1.7      chs 		case HPT370A_REV:
    330        1.7      chs 			tim_udma = hpt370_udma;
    331        1.7      chs 			tim_dma = hpt370_dma;
    332        1.7      chs 			tim_pio = hpt370_pio;
    333        1.7      chs 			break;
    334       1.21  xtraeme 		case HPT368_REV:
    335        1.7      chs 		case HPT366_REV:
    336        1.7      chs 		default:
    337        1.7      chs 			tim_udma = hpt366_udma;
    338        1.7      chs 			tim_dma = hpt366_dma;
    339        1.7      chs 			tim_pio = hpt366_pio;
    340        1.7      chs 			break;
    341        1.7      chs 		}
    342        1.7      chs 	}
    343        1.7      chs 
    344        1.1   bouyer 	/* Per drive settings */
    345       1.20   bouyer 	for (drive = 0; drive < chp->ch_ndrive; drive++) {
    346        1.1   bouyer 		drvp = &chp->ch_drive[drive];
    347        1.1   bouyer 		/* If no drive, skip */
    348        1.1   bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    349        1.1   bouyer 			continue;
    350        1.1   bouyer 		before = pci_conf_read(sc->sc_pc, sc->sc_tag,
    351        1.9  thorpej 					HPT_IDETIM(chp->ch_channel, drive));
    352        1.1   bouyer 
    353        1.1   bouyer 		/* add timing values, setup DMA if needed */
    354        1.1   bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    355        1.1   bouyer 			/* use Ultra/DMA */
    356       1.16  thorpej 			s = splbio();
    357        1.1   bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    358       1.16  thorpej 			splx(s);
    359        1.9  thorpej 			if ((cable & HPT_CSEL_CBLID(chp->ch_channel)) != 0 &&
    360        1.1   bouyer 			    drvp->UDMA_mode > 2)
    361        1.1   bouyer 				drvp->UDMA_mode = 2;
    362        1.7      chs 			after = tim_udma[drvp->UDMA_mode];
    363        1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    364        1.1   bouyer 		} else if (drvp->drive_flags & DRIVE_DMA) {
    365        1.1   bouyer 			/*
    366        1.1   bouyer 			 * use Multiword DMA.
    367        1.1   bouyer 			 * Timings will be used for both PIO and DMA, so adjust
    368        1.1   bouyer 			 * DMA mode if needed
    369        1.1   bouyer 			 */
    370        1.1   bouyer 			if (drvp->PIO_mode >= 3 &&
    371        1.1   bouyer 			    (drvp->DMA_mode + 2) > drvp->PIO_mode) {
    372        1.1   bouyer 				drvp->DMA_mode = drvp->PIO_mode - 2;
    373        1.1   bouyer 			}
    374        1.7      chs 			after = tim_dma[drvp->DMA_mode];
    375        1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    376        1.1   bouyer 		} else {
    377        1.1   bouyer 			/* PIO only */
    378        1.7      chs 			after = tim_pio[drvp->PIO_mode];
    379        1.1   bouyer 		}
    380        1.1   bouyer 		pci_conf_write(sc->sc_pc, sc->sc_tag,
    381        1.9  thorpej 		    HPT_IDETIM(chp->ch_channel, drive), after);
    382       1.12  thorpej 		ATADEBUG_PRINT(("%s: bus speed register set to 0x%08x "
    383  1.24.20.1     matt 		    "(BIOS 0x%08x)\n", device_xname(drvp->drv_softc),
    384        1.1   bouyer 		    after, before), DEBUG_PROBE);
    385        1.1   bouyer 	}
    386        1.1   bouyer 	if (idedma_ctl != 0) {
    387        1.1   bouyer 		/* Add software bits in status register */
    388        1.6     fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    389        1.1   bouyer 		    idedma_ctl);
    390        1.1   bouyer 	}
    391        1.1   bouyer }
    392        1.1   bouyer 
    393        1.2  thorpej static int
    394        1.2  thorpej hpt_pci_intr(void *arg)
    395        1.1   bouyer {
    396        1.1   bouyer 	struct pciide_softc *sc = arg;
    397        1.1   bouyer 	struct pciide_channel *cp;
    398       1.13  thorpej 	struct ata_channel *wdc_cp;
    399        1.1   bouyer 	int rv = 0;
    400        1.1   bouyer 	int dmastat, i, crv;
    401        1.1   bouyer 
    402       1.15  thorpej 	for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
    403        1.6     fvdl 		cp = &sc->pciide_channels[i];
    404        1.6     fvdl 		dmastat = bus_space_read_1(sc->sc_dma_iot,
    405        1.6     fvdl 		    cp->dma_iohs[IDEDMA_CTL], 0);
    406        1.1   bouyer 		if((dmastat & ( IDEDMA_CTL_ACT | IDEDMA_CTL_INTR)) !=
    407        1.1   bouyer 		    IDEDMA_CTL_INTR)
    408        1.1   bouyer 			continue;
    409       1.13  thorpej 		wdc_cp = &cp->ata_channel;
    410        1.1   bouyer 		crv = wdcintr(wdc_cp);
    411        1.1   bouyer 		if (crv == 0) {
    412  1.24.20.1     matt 			aprint_error("%s:%d: bogus intr\n",
    413  1.24.20.1     matt 			    device_xname(sc->sc_wdcdev.sc_atac.atac_dev), i);
    414        1.6     fvdl 			bus_space_write_1(sc->sc_dma_iot,
    415        1.6     fvdl 			    cp->dma_iohs[IDEDMA_CTL], 0, dmastat);
    416        1.1   bouyer 		} else
    417        1.1   bouyer 			rv = 1;
    418        1.1   bouyer 	}
    419        1.1   bouyer 	return rv;
    420        1.1   bouyer }
    421