Home | History | Annotate | Line # | Download | only in pci
piixide.c revision 1.16
      1  1.16     cube /*	$NetBSD: piixide.c,v 1.16 2004/10/22 15:09:22 cube 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.1   bouyer  * 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.1   bouyer #include <sys/param.h>
     33   1.1   bouyer #include <sys/systm.h>
     34   1.1   bouyer 
     35   1.1   bouyer #include <dev/pci/pcivar.h>
     36   1.1   bouyer #include <dev/pci/pcidevs.h>
     37   1.1   bouyer #include <dev/pci/pciidereg.h>
     38   1.1   bouyer #include <dev/pci/pciidevar.h>
     39   1.1   bouyer #include <dev/pci/pciide_piix_reg.h>
     40   1.1   bouyer 
     41   1.2  thorpej static void piix_chip_map(struct pciide_softc*, struct pci_attach_args *);
     42  1.12  thorpej static void piix_setup_channel(struct ata_channel *);
     43  1.12  thorpej static void piix3_4_setup_channel(struct ata_channel *);
     44   1.2  thorpej static u_int32_t piix_setup_idetim_timings(u_int8_t, u_int8_t, u_int8_t);
     45   1.2  thorpej static u_int32_t piix_setup_idetim_drvs(struct ata_drive_datas *);
     46   1.2  thorpej static u_int32_t piix_setup_sidetim_timings(u_int8_t, u_int8_t, u_int8_t);
     47   1.5   bouyer static void piixsata_chip_map(struct pciide_softc*, struct pci_attach_args *);
     48   1.2  thorpej 
     49   1.2  thorpej static int  piixide_match(struct device *, struct cfdata *, void *);
     50   1.2  thorpej static void piixide_attach(struct device *, struct device *, void *);
     51   1.1   bouyer 
     52   1.2  thorpej static const struct pciide_product_desc pciide_intel_products[] =  {
     53   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82092AA,
     54   1.1   bouyer 	  0,
     55   1.1   bouyer 	  "Intel 82092AA IDE controller",
     56   1.1   bouyer 	  default_chip_map,
     57   1.1   bouyer 	},
     58   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82371FB_IDE,
     59   1.1   bouyer 	  0,
     60   1.1   bouyer 	  "Intel 82371FB IDE controller (PIIX)",
     61   1.1   bouyer 	  piix_chip_map,
     62   1.1   bouyer 	},
     63   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82371SB_IDE,
     64   1.1   bouyer 	  0,
     65   1.1   bouyer 	  "Intel 82371SB IDE Interface (PIIX3)",
     66   1.1   bouyer 	  piix_chip_map,
     67   1.1   bouyer 	},
     68   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82371AB_IDE,
     69   1.1   bouyer 	  0,
     70   1.1   bouyer 	  "Intel 82371AB IDE controller (PIIX4)",
     71   1.1   bouyer 	  piix_chip_map,
     72   1.1   bouyer 	},
     73   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82440MX_IDE,
     74   1.1   bouyer 	  0,
     75   1.1   bouyer 	  "Intel 82440MX IDE controller",
     76   1.1   bouyer 	  piix_chip_map
     77   1.1   bouyer 	},
     78   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801AA_IDE,
     79   1.1   bouyer 	  0,
     80   1.1   bouyer 	  "Intel 82801AA IDE Controller (ICH)",
     81   1.1   bouyer 	  piix_chip_map,
     82   1.1   bouyer 	},
     83   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801AB_IDE,
     84   1.1   bouyer 	  0,
     85   1.1   bouyer 	  "Intel 82801AB IDE Controller (ICH0)",
     86   1.1   bouyer 	  piix_chip_map,
     87   1.1   bouyer 	},
     88   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801BA_IDE,
     89   1.1   bouyer 	  0,
     90   1.1   bouyer 	  "Intel 82801BA IDE Controller (ICH2)",
     91   1.1   bouyer 	  piix_chip_map,
     92   1.1   bouyer 	},
     93   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801BAM_IDE,
     94   1.1   bouyer 	  0,
     95   1.1   bouyer 	  "Intel 82801BAM IDE Controller (ICH2-M)",
     96   1.1   bouyer 	  piix_chip_map,
     97   1.1   bouyer 	},
     98   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801CA_IDE_1,
     99   1.1   bouyer 	  0,
    100   1.1   bouyer 	  "Intel 82801CA IDE Controller (ICH3)",
    101   1.1   bouyer 	  piix_chip_map,
    102   1.1   bouyer 	},
    103   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801CA_IDE_2,
    104   1.1   bouyer 	  0,
    105   1.1   bouyer 	  "Intel 82801CA IDE Controller (ICH3)",
    106   1.1   bouyer 	  piix_chip_map,
    107   1.1   bouyer 	},
    108   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801DB_IDE,
    109   1.1   bouyer 	  0,
    110   1.1   bouyer 	  "Intel 82801DB IDE Controller (ICH4)",
    111   1.1   bouyer 	  piix_chip_map,
    112   1.1   bouyer 	},
    113   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801DBM_IDE,
    114   1.1   bouyer 	  0,
    115   1.1   bouyer 	  "Intel 82801DBM IDE Controller (ICH4-M)",
    116   1.1   bouyer 	  piix_chip_map,
    117   1.1   bouyer 	},
    118   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801EB_IDE,
    119   1.1   bouyer 	  0,
    120   1.1   bouyer 	  "Intel 82801EB IDE Controller (ICH5)",
    121   1.1   bouyer 	  piix_chip_map,
    122   1.1   bouyer 	},
    123   1.1   bouyer 	{ PCI_PRODUCT_INTEL_82801EB_SATA,
    124   1.1   bouyer 	  0,
    125   1.1   bouyer 	  "Intel 82801EB Serial ATA Controller",
    126   1.5   bouyer 	  piixsata_chip_map,
    127   1.4   bouyer 	},
    128   1.4   bouyer 	{ PCI_PRODUCT_INTEL_82801ER_SATA,
    129   1.4   bouyer 	  0,
    130   1.4   bouyer 	  "Intel 82801ER Serial ATA/Raid Controller",
    131   1.5   bouyer 	  piixsata_chip_map,
    132   1.1   bouyer 	},
    133   1.9  thorpej 	{ PCI_PRODUCT_INTEL_6300ESB_IDE,
    134   1.9  thorpej 	  0,
    135   1.9  thorpej 	  "Intel 6300ESB IDE Controller (ICH5)",
    136   1.9  thorpej 	  piix_chip_map,
    137   1.9  thorpej 	},
    138   1.9  thorpej 	{ PCI_PRODUCT_INTEL_6300ESB_SATA,
    139   1.9  thorpej 	  0,
    140   1.9  thorpej 	  "Intel 6300ESB Serial ATA Controller",
    141   1.9  thorpej 	  piixsata_chip_map,
    142   1.9  thorpej 	},
    143  1.16     cube 	{ PCI_PRODUCT_INTEL_82801FB_SATA,
    144  1.16     cube 	  0,
    145  1.16     cube 	  "Intel 82801FB Serial ATA/Raid Controller",
    146  1.16     cube 	  piixsata_chip_map,
    147  1.16     cube 	},
    148  1.16     cube 	{ PCI_PRODUCT_INTEL_82801FR_SATA,
    149  1.16     cube 	  0,
    150  1.16     cube 	  "Intel 82801FR Serial ATA/Raid Controller",
    151  1.16     cube 	  piixsata_chip_map,
    152  1.16     cube 	},
    153   1.1   bouyer 	{ 0,
    154   1.1   bouyer 	  0,
    155   1.1   bouyer 	  NULL,
    156   1.1   bouyer 	  NULL
    157   1.1   bouyer 	}
    158   1.1   bouyer };
    159   1.1   bouyer 
    160   1.1   bouyer CFATTACH_DECL(piixide, sizeof(struct pciide_softc),
    161   1.1   bouyer     piixide_match, piixide_attach, NULL, NULL);
    162   1.1   bouyer 
    163   1.2  thorpej static int
    164   1.2  thorpej piixide_match(struct device *parent, struct cfdata *match, void *aux)
    165   1.1   bouyer {
    166   1.1   bouyer 	struct pci_attach_args *pa = aux;
    167   1.1   bouyer 
    168   1.1   bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
    169   1.1   bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_intel_products))
    170   1.1   bouyer 			return (2);
    171   1.1   bouyer 	}
    172   1.1   bouyer 	return (0);
    173   1.1   bouyer }
    174   1.1   bouyer 
    175   1.2  thorpej static void
    176   1.2  thorpej piixide_attach(struct device *parent, struct device *self, void *aux)
    177   1.1   bouyer {
    178   1.1   bouyer 	struct pci_attach_args *pa = aux;
    179   1.1   bouyer 	struct pciide_softc *sc = (struct pciide_softc *)self;
    180   1.1   bouyer 
    181   1.1   bouyer 	pciide_common_attach(sc, pa,
    182   1.1   bouyer 	    pciide_lookup_product(pa->pa_id, pciide_intel_products));
    183   1.1   bouyer 
    184   1.1   bouyer }
    185   1.1   bouyer 
    186   1.2  thorpej static void
    187   1.2  thorpej piix_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    188   1.1   bouyer {
    189   1.1   bouyer 	struct pciide_channel *cp;
    190   1.1   bouyer 	int channel;
    191   1.1   bouyer 	u_int32_t idetim;
    192   1.1   bouyer 	bus_size_t cmdsize, ctlsize;
    193   1.1   bouyer 
    194   1.1   bouyer 	if (pciide_chipen(sc, pa) == 0)
    195   1.1   bouyer 		return;
    196   1.1   bouyer 
    197   1.1   bouyer 	aprint_normal("%s: bus-master DMA support present",
    198  1.14  thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    199   1.1   bouyer 	pciide_mapreg_dma(sc, pa);
    200   1.1   bouyer 	aprint_normal("\n");
    201  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    202   1.1   bouyer 	if (sc->sc_dma_ok) {
    203  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    204   1.1   bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    205   1.1   bouyer 		switch(sc->sc_pp->ide_product) {
    206   1.1   bouyer 		case PCI_PRODUCT_INTEL_82371AB_IDE:
    207   1.1   bouyer 		case PCI_PRODUCT_INTEL_82440MX_IDE:
    208   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801AA_IDE:
    209   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801AB_IDE:
    210   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801BA_IDE:
    211   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801BAM_IDE:
    212   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801CA_IDE_1:
    213   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801CA_IDE_2:
    214   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801DB_IDE:
    215   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801DBM_IDE:
    216   1.1   bouyer 		case PCI_PRODUCT_INTEL_82801EB_IDE:
    217   1.9  thorpej 		case PCI_PRODUCT_INTEL_6300ESB_IDE:
    218  1.14  thorpej 			sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
    219   1.1   bouyer 		}
    220   1.1   bouyer 	}
    221  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    222  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    223   1.1   bouyer 	switch(sc->sc_pp->ide_product) {
    224   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801AA_IDE:
    225  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    226   1.1   bouyer 		break;
    227   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801BA_IDE:
    228   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801BAM_IDE:
    229   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801CA_IDE_1:
    230   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801CA_IDE_2:
    231   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801DB_IDE:
    232   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801DBM_IDE:
    233   1.1   bouyer 	case PCI_PRODUCT_INTEL_82801EB_IDE:
    234   1.9  thorpej 	case PCI_PRODUCT_INTEL_6300ESB_IDE:
    235  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    236   1.1   bouyer 		break;
    237   1.1   bouyer 	default:
    238  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    239   1.1   bouyer 	}
    240   1.1   bouyer 	if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82371FB_IDE)
    241  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_set_modes = piix_setup_channel;
    242   1.1   bouyer 	else
    243  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_set_modes = piix3_4_setup_channel;
    244  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    245  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    246   1.1   bouyer 
    247  1.11  thorpej 	ATADEBUG_PRINT(("piix_setup_chip: old idetim=0x%x",
    248   1.1   bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM)),
    249   1.1   bouyer 	    DEBUG_PROBE);
    250   1.1   bouyer 	if (sc->sc_pp->ide_product != PCI_PRODUCT_INTEL_82371FB_IDE) {
    251  1.11  thorpej 		ATADEBUG_PRINT((", sidetim=0x%x",
    252   1.1   bouyer 		    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM)),
    253   1.1   bouyer 		    DEBUG_PROBE);
    254  1.14  thorpej 		if (sc->sc_wdcdev.sc_atac.atac_cap & ATAC_CAP_UDMA) {
    255  1.11  thorpej 			ATADEBUG_PRINT((", udamreg 0x%x",
    256   1.1   bouyer 			    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG)),
    257   1.1   bouyer 			    DEBUG_PROBE);
    258   1.1   bouyer 		}
    259   1.1   bouyer 		if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE ||
    260   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AB_IDE ||
    261   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
    262   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
    263   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
    264   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
    265   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
    266   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
    267   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
    268   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE) {
    269  1.11  thorpej 			ATADEBUG_PRINT((", IDE_CONTROL 0x%x",
    270   1.1   bouyer 			    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_CONFIG)),
    271   1.1   bouyer 			    DEBUG_PROBE);
    272   1.1   bouyer 		}
    273   1.1   bouyer 
    274   1.1   bouyer 	}
    275  1.11  thorpej 	ATADEBUG_PRINT(("\n"), DEBUG_PROBE);
    276   1.1   bouyer 
    277  1.12  thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    278  1.12  thorpej 
    279  1.14  thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    280  1.14  thorpej 	     channel++) {
    281   1.1   bouyer 		cp = &sc->pciide_channels[channel];
    282   1.1   bouyer 		/* PIIX is compat-only */
    283   1.1   bouyer 		if (pciide_chansetup(sc, channel, 0) == 0)
    284   1.1   bouyer 			continue;
    285   1.1   bouyer 		idetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM);
    286   1.1   bouyer 		if ((PIIX_IDETIM_READ(idetim, channel) &
    287   1.1   bouyer 		    PIIX_IDETIM_IDE) == 0) {
    288   1.1   bouyer #if 1
    289   1.1   bouyer 			aprint_normal("%s: %s channel ignored (disabled)\n",
    290  1.14  thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    291  1.12  thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    292   1.1   bouyer 			continue;
    293   1.1   bouyer #else
    294   1.1   bouyer 			pcireg_t interface;
    295   1.1   bouyer 
    296   1.1   bouyer 			idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE,
    297   1.1   bouyer 			    channel);
    298   1.1   bouyer 			pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_IDETIM,
    299   1.1   bouyer 			    idetim);
    300   1.1   bouyer 			interface = PCI_INTERFACE(pci_conf_read(sc->sc_pc,
    301   1.1   bouyer 			    sc->sc_tag, PCI_CLASS_REG));
    302   1.1   bouyer 			aprint_normal("channel %d idetim=%08x interface=%02x\n",
    303   1.1   bouyer 			    channel, idetim, interface);
    304   1.1   bouyer #endif
    305   1.1   bouyer 		}
    306   1.1   bouyer 		/* PIIX are compat-only pciide devices */
    307   1.1   bouyer 		pciide_mapchan(pa, cp, 0, &cmdsize, &ctlsize, pciide_pci_intr);
    308   1.1   bouyer 	}
    309   1.1   bouyer 
    310  1.11  thorpej 	ATADEBUG_PRINT(("piix_setup_chip: idetim=0x%x",
    311   1.1   bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM)),
    312   1.1   bouyer 	    DEBUG_PROBE);
    313   1.1   bouyer 	if (sc->sc_pp->ide_product != PCI_PRODUCT_INTEL_82371FB_IDE) {
    314  1.11  thorpej 		ATADEBUG_PRINT((", sidetim=0x%x",
    315   1.1   bouyer 		    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM)),
    316   1.1   bouyer 		    DEBUG_PROBE);
    317  1.14  thorpej 		if (sc->sc_wdcdev.sc_atac.atac_cap & ATAC_CAP_UDMA) {
    318  1.11  thorpej 			ATADEBUG_PRINT((", udamreg 0x%x",
    319   1.1   bouyer 			    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG)),
    320   1.1   bouyer 			    DEBUG_PROBE);
    321   1.1   bouyer 		}
    322   1.1   bouyer 		if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE ||
    323   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AB_IDE ||
    324   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
    325   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
    326   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
    327   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
    328   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
    329   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
    330   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
    331   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE) {
    332  1.11  thorpej 			ATADEBUG_PRINT((", IDE_CONTROL 0x%x",
    333   1.1   bouyer 			    pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_CONFIG)),
    334   1.1   bouyer 			    DEBUG_PROBE);
    335   1.1   bouyer 		}
    336   1.1   bouyer 	}
    337  1.11  thorpej 	ATADEBUG_PRINT(("\n"), DEBUG_PROBE);
    338   1.1   bouyer }
    339   1.1   bouyer 
    340   1.2  thorpej static void
    341  1.12  thorpej piix_setup_channel(struct ata_channel *chp)
    342   1.1   bouyer {
    343   1.1   bouyer 	u_int8_t mode[2], drive;
    344   1.1   bouyer 	u_int32_t oidetim, idetim, idedma_ctl;
    345  1.13  thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    346  1.13  thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    347  1.12  thorpej 	struct ata_drive_datas *drvp = cp->ata_channel.ch_drive;
    348   1.1   bouyer 
    349   1.1   bouyer 	oidetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM);
    350   1.8  thorpej 	idetim = PIIX_IDETIM_CLEAR(oidetim, 0xffff, chp->ch_channel);
    351   1.1   bouyer 	idedma_ctl = 0;
    352   1.1   bouyer 
    353   1.1   bouyer 	/* set up new idetim: Enable IDE registers decode */
    354   1.1   bouyer 	idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE,
    355   1.8  thorpej 	    chp->ch_channel);
    356   1.1   bouyer 
    357   1.1   bouyer 	/* setup DMA */
    358   1.1   bouyer 	pciide_channel_dma_setup(cp);
    359   1.1   bouyer 
    360   1.1   bouyer 	/*
    361   1.1   bouyer 	 * Here we have to mess up with drives mode: PIIX can't have
    362   1.1   bouyer 	 * different timings for master and slave drives.
    363   1.1   bouyer 	 * We need to find the best combination.
    364   1.1   bouyer 	 */
    365   1.1   bouyer 
    366   1.1   bouyer 	/* If both drives supports DMA, take the lower mode */
    367   1.1   bouyer 	if ((drvp[0].drive_flags & DRIVE_DMA) &&
    368   1.1   bouyer 	    (drvp[1].drive_flags & DRIVE_DMA)) {
    369   1.1   bouyer 		mode[0] = mode[1] =
    370   1.1   bouyer 		    min(drvp[0].DMA_mode, drvp[1].DMA_mode);
    371   1.1   bouyer 		    drvp[0].DMA_mode = mode[0];
    372   1.1   bouyer 		    drvp[1].DMA_mode = mode[1];
    373   1.1   bouyer 		goto ok;
    374   1.1   bouyer 	}
    375   1.1   bouyer 	/*
    376   1.1   bouyer 	 * If only one drive supports DMA, use its mode, and
    377   1.1   bouyer 	 * put the other one in PIO mode 0 if mode not compatible
    378   1.1   bouyer 	 */
    379   1.1   bouyer 	if (drvp[0].drive_flags & DRIVE_DMA) {
    380   1.1   bouyer 		mode[0] = drvp[0].DMA_mode;
    381   1.1   bouyer 		mode[1] = drvp[1].PIO_mode;
    382   1.1   bouyer 		if (piix_isp_pio[mode[1]] != piix_isp_dma[mode[0]] ||
    383   1.1   bouyer 		    piix_rtc_pio[mode[1]] != piix_rtc_dma[mode[0]])
    384   1.1   bouyer 			mode[1] = drvp[1].PIO_mode = 0;
    385   1.1   bouyer 		goto ok;
    386   1.1   bouyer 	}
    387   1.1   bouyer 	if (drvp[1].drive_flags & DRIVE_DMA) {
    388   1.1   bouyer 		mode[1] = drvp[1].DMA_mode;
    389   1.1   bouyer 		mode[0] = drvp[0].PIO_mode;
    390   1.1   bouyer 		if (piix_isp_pio[mode[0]] != piix_isp_dma[mode[1]] ||
    391   1.1   bouyer 		    piix_rtc_pio[mode[0]] != piix_rtc_dma[mode[1]])
    392   1.1   bouyer 			mode[0] = drvp[0].PIO_mode = 0;
    393   1.1   bouyer 		goto ok;
    394   1.1   bouyer 	}
    395   1.1   bouyer 	/*
    396   1.1   bouyer 	 * If both drives are not DMA, takes the lower mode, unless
    397   1.1   bouyer 	 * one of them is PIO mode < 2
    398   1.1   bouyer 	 */
    399   1.1   bouyer 	if (drvp[0].PIO_mode < 2) {
    400   1.1   bouyer 		mode[0] = drvp[0].PIO_mode = 0;
    401   1.1   bouyer 		mode[1] = drvp[1].PIO_mode;
    402   1.1   bouyer 	} else if (drvp[1].PIO_mode < 2) {
    403   1.1   bouyer 		mode[1] = drvp[1].PIO_mode = 0;
    404   1.1   bouyer 		mode[0] = drvp[0].PIO_mode;
    405   1.1   bouyer 	} else {
    406   1.1   bouyer 		mode[0] = mode[1] =
    407   1.1   bouyer 		    min(drvp[1].PIO_mode, drvp[0].PIO_mode);
    408   1.1   bouyer 		drvp[0].PIO_mode = mode[0];
    409   1.1   bouyer 		drvp[1].PIO_mode = mode[1];
    410   1.1   bouyer 	}
    411   1.1   bouyer ok:	/* The modes are setup */
    412   1.1   bouyer 	for (drive = 0; drive < 2; drive++) {
    413   1.1   bouyer 		if (drvp[drive].drive_flags & DRIVE_DMA) {
    414   1.1   bouyer 			idetim |= piix_setup_idetim_timings(
    415   1.8  thorpej 			    mode[drive], 1, chp->ch_channel);
    416   1.1   bouyer 			goto end;
    417   1.1   bouyer 		}
    418   1.1   bouyer 	}
    419   1.1   bouyer 	/* If we are there, none of the drives are DMA */
    420   1.1   bouyer 	if (mode[0] >= 2)
    421   1.1   bouyer 		idetim |= piix_setup_idetim_timings(
    422   1.8  thorpej 		    mode[0], 0, chp->ch_channel);
    423   1.1   bouyer 	else
    424   1.1   bouyer 		idetim |= piix_setup_idetim_timings(
    425   1.8  thorpej 		    mode[1], 0, chp->ch_channel);
    426   1.1   bouyer end:	/*
    427   1.1   bouyer 	 * timing mode is now set up in the controller. Enable
    428   1.1   bouyer 	 * it per-drive
    429   1.1   bouyer 	 */
    430   1.1   bouyer 	for (drive = 0; drive < 2; drive++) {
    431   1.1   bouyer 		/* If no drive, skip */
    432   1.1   bouyer 		if ((drvp[drive].drive_flags & DRIVE) == 0)
    433   1.1   bouyer 			continue;
    434   1.1   bouyer 		idetim |= piix_setup_idetim_drvs(&drvp[drive]);
    435   1.1   bouyer 		if (drvp[drive].drive_flags & DRIVE_DMA)
    436   1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    437   1.1   bouyer 	}
    438   1.1   bouyer 	if (idedma_ctl != 0) {
    439   1.1   bouyer 		/* Add software bits in status register */
    440   1.3     fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    441   1.1   bouyer 		    idedma_ctl);
    442   1.1   bouyer 	}
    443   1.1   bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_IDETIM, idetim);
    444   1.1   bouyer }
    445   1.1   bouyer 
    446   1.2  thorpej static void
    447  1.12  thorpej piix3_4_setup_channel(struct ata_channel *chp)
    448   1.1   bouyer {
    449   1.1   bouyer 	struct ata_drive_datas *drvp;
    450   1.1   bouyer 	u_int32_t oidetim, idetim, sidetim, udmareg, ideconf, idedma_ctl;
    451  1.13  thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    452  1.13  thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    453   1.8  thorpej 	struct wdc_softc *wdc = &sc->sc_wdcdev;
    454  1.15  thorpej 	int drive, s;
    455   1.8  thorpej 	int channel = chp->ch_channel;
    456   1.1   bouyer 
    457   1.1   bouyer 	oidetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_IDETIM);
    458   1.1   bouyer 	sidetim = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM);
    459   1.1   bouyer 	udmareg = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG);
    460   1.1   bouyer 	ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, PIIX_CONFIG);
    461   1.1   bouyer 	idetim = PIIX_IDETIM_CLEAR(oidetim, 0xffff, channel);
    462   1.1   bouyer 	sidetim &= ~(PIIX_SIDETIM_ISP_MASK(channel) |
    463   1.1   bouyer 	    PIIX_SIDETIM_RTC_MASK(channel));
    464   1.1   bouyer 	idedma_ctl = 0;
    465   1.1   bouyer 
    466   1.1   bouyer 	/* set up new idetim: Enable IDE registers decode */
    467   1.1   bouyer 	idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, channel);
    468   1.1   bouyer 
    469   1.1   bouyer 	/* setup DMA if needed */
    470   1.1   bouyer 	pciide_channel_dma_setup(cp);
    471   1.1   bouyer 
    472   1.1   bouyer 	for (drive = 0; drive < 2; drive++) {
    473   1.1   bouyer 		udmareg &= ~(PIIX_UDMACTL_DRV_EN(channel, drive) |
    474   1.1   bouyer 		    PIIX_UDMATIM_SET(0x3, channel, drive));
    475   1.1   bouyer 		drvp = &chp->ch_drive[drive];
    476   1.1   bouyer 		/* If no drive, skip */
    477   1.1   bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    478   1.1   bouyer 			continue;
    479   1.1   bouyer 		if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
    480   1.1   bouyer 		    (drvp->drive_flags & DRIVE_UDMA) == 0))
    481   1.1   bouyer 			goto pio;
    482   1.1   bouyer 
    483   1.1   bouyer 		if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE ||
    484   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AB_IDE ||
    485   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
    486   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
    487   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
    488   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
    489   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
    490   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
    491   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
    492   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE) {
    493   1.1   bouyer 			ideconf |= PIIX_CONFIG_PINGPONG;
    494   1.1   bouyer 		}
    495   1.1   bouyer 		if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BA_IDE ||
    496   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801BAM_IDE ||
    497   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_1 ||
    498   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801CA_IDE_2 ||
    499   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DB_IDE ||
    500   1.1   bouyer 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801DBM_IDE ||
    501   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801EB_IDE ||
    502   1.9  thorpej 		    sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_6300ESB_IDE) {
    503   1.1   bouyer 			/* setup Ultra/100 */
    504   1.1   bouyer 			if (drvp->UDMA_mode > 2 &&
    505   1.1   bouyer 			    (ideconf & PIIX_CONFIG_CR(channel, drive)) == 0)
    506   1.1   bouyer 				drvp->UDMA_mode = 2;
    507   1.1   bouyer 			if (drvp->UDMA_mode > 4) {
    508   1.1   bouyer 				ideconf |= PIIX_CONFIG_UDMA100(channel, drive);
    509   1.1   bouyer 			} else {
    510   1.1   bouyer 				ideconf &= ~PIIX_CONFIG_UDMA100(channel, drive);
    511   1.1   bouyer 				if (drvp->UDMA_mode > 2) {
    512   1.1   bouyer 					ideconf |= PIIX_CONFIG_UDMA66(channel,
    513   1.1   bouyer 					    drive);
    514   1.1   bouyer 				} else {
    515   1.1   bouyer 					ideconf &= ~PIIX_CONFIG_UDMA66(channel,
    516   1.1   bouyer 					    drive);
    517   1.1   bouyer 				}
    518   1.1   bouyer 			}
    519   1.1   bouyer 		}
    520   1.1   bouyer 		if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_82801AA_IDE) {
    521   1.1   bouyer 			/* setup Ultra/66 */
    522   1.1   bouyer 			if (drvp->UDMA_mode > 2 &&
    523   1.1   bouyer 			    (ideconf & PIIX_CONFIG_CR(channel, drive)) == 0)
    524   1.1   bouyer 				drvp->UDMA_mode = 2;
    525   1.1   bouyer 			if (drvp->UDMA_mode > 2)
    526   1.1   bouyer 				ideconf |= PIIX_CONFIG_UDMA66(channel, drive);
    527   1.1   bouyer 			else
    528   1.1   bouyer 				ideconf &= ~PIIX_CONFIG_UDMA66(channel, drive);
    529   1.1   bouyer 		}
    530  1.14  thorpej 		if ((wdc->sc_atac.atac_cap & ATAC_CAP_UDMA) &&
    531   1.1   bouyer 		    (drvp->drive_flags & DRIVE_UDMA)) {
    532   1.1   bouyer 			/* use Ultra/DMA */
    533  1.15  thorpej 			s = splbio();
    534   1.1   bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    535  1.15  thorpej 			splx(s);
    536   1.1   bouyer 			udmareg |= PIIX_UDMACTL_DRV_EN( channel, drive);
    537   1.1   bouyer 			udmareg |= PIIX_UDMATIM_SET(
    538   1.1   bouyer 			    piix4_sct_udma[drvp->UDMA_mode], channel, drive);
    539   1.1   bouyer 		} else {
    540   1.1   bouyer 			/* use Multiword DMA */
    541  1.15  thorpej 			s = splbio();
    542   1.1   bouyer 			drvp->drive_flags &= ~DRIVE_UDMA;
    543  1.15  thorpej 			splx(s);
    544   1.1   bouyer 			if (drive == 0) {
    545   1.1   bouyer 				idetim |= piix_setup_idetim_timings(
    546   1.1   bouyer 				    drvp->DMA_mode, 1, channel);
    547   1.1   bouyer 			} else {
    548   1.1   bouyer 				sidetim |= piix_setup_sidetim_timings(
    549   1.1   bouyer 					drvp->DMA_mode, 1, channel);
    550   1.1   bouyer 				idetim =PIIX_IDETIM_SET(idetim,
    551   1.1   bouyer 				    PIIX_IDETIM_SITRE, channel);
    552   1.1   bouyer 			}
    553   1.1   bouyer 		}
    554   1.1   bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    555   1.1   bouyer 
    556   1.1   bouyer pio:		/* use PIO mode */
    557   1.1   bouyer 		idetim |= piix_setup_idetim_drvs(drvp);
    558   1.1   bouyer 		if (drive == 0) {
    559   1.1   bouyer 			idetim |= piix_setup_idetim_timings(
    560   1.1   bouyer 			    drvp->PIO_mode, 0, channel);
    561   1.1   bouyer 		} else {
    562   1.1   bouyer 			sidetim |= piix_setup_sidetim_timings(
    563   1.1   bouyer 				drvp->PIO_mode, 0, channel);
    564   1.1   bouyer 			idetim =PIIX_IDETIM_SET(idetim,
    565   1.1   bouyer 			    PIIX_IDETIM_SITRE, channel);
    566   1.1   bouyer 		}
    567   1.1   bouyer 	}
    568   1.1   bouyer 	if (idedma_ctl != 0) {
    569   1.1   bouyer 		/* Add software bits in status register */
    570   1.3     fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    571   1.1   bouyer 		    idedma_ctl);
    572   1.1   bouyer 	}
    573   1.1   bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_IDETIM, idetim);
    574   1.1   bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_SIDETIM, sidetim);
    575   1.1   bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_UDMAREG, udmareg);
    576   1.1   bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, PIIX_CONFIG, ideconf);
    577   1.1   bouyer }
    578   1.1   bouyer 
    579   1.1   bouyer 
    580   1.1   bouyer /* setup ISP and RTC fields, based on mode */
    581   1.1   bouyer static u_int32_t
    582   1.1   bouyer piix_setup_idetim_timings(mode, dma, channel)
    583   1.1   bouyer 	u_int8_t mode;
    584   1.1   bouyer 	u_int8_t dma;
    585   1.1   bouyer 	u_int8_t channel;
    586   1.1   bouyer {
    587   1.1   bouyer 
    588   1.1   bouyer 	if (dma)
    589   1.1   bouyer 		return PIIX_IDETIM_SET(0,
    590   1.1   bouyer 		    PIIX_IDETIM_ISP_SET(piix_isp_dma[mode]) |
    591   1.1   bouyer 		    PIIX_IDETIM_RTC_SET(piix_rtc_dma[mode]),
    592   1.1   bouyer 		    channel);
    593   1.1   bouyer 	else
    594   1.1   bouyer 		return PIIX_IDETIM_SET(0,
    595   1.1   bouyer 		    PIIX_IDETIM_ISP_SET(piix_isp_pio[mode]) |
    596   1.1   bouyer 		    PIIX_IDETIM_RTC_SET(piix_rtc_pio[mode]),
    597   1.1   bouyer 		    channel);
    598   1.1   bouyer }
    599   1.1   bouyer 
    600   1.1   bouyer /* setup DTE, PPE, IE and TIME field based on PIO mode */
    601   1.1   bouyer static u_int32_t
    602   1.1   bouyer piix_setup_idetim_drvs(drvp)
    603   1.1   bouyer 	struct ata_drive_datas *drvp;
    604   1.1   bouyer {
    605   1.1   bouyer 	u_int32_t ret = 0;
    606  1.12  thorpej 	struct ata_channel *chp = drvp->chnl_softc;
    607   1.8  thorpej 	u_int8_t channel = chp->ch_channel;
    608   1.1   bouyer 	u_int8_t drive = drvp->drive;
    609   1.1   bouyer 
    610   1.1   bouyer 	/*
    611   1.1   bouyer 	 * If drive is using UDMA, timings setups are independant
    612   1.1   bouyer 	 * So just check DMA and PIO here.
    613   1.1   bouyer 	 */
    614   1.1   bouyer 	if (drvp->drive_flags & DRIVE_DMA) {
    615   1.1   bouyer 		/* if mode = DMA mode 0, use compatible timings */
    616   1.1   bouyer 		if ((drvp->drive_flags & DRIVE_DMA) &&
    617   1.1   bouyer 		    drvp->DMA_mode == 0) {
    618   1.1   bouyer 			drvp->PIO_mode = 0;
    619   1.1   bouyer 			return ret;
    620   1.1   bouyer 		}
    621   1.1   bouyer 		ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_TIME(drive), channel);
    622   1.1   bouyer 		/*
    623   1.1   bouyer 		 * PIO and DMA timings are the same, use fast timings for PIO
    624   1.1   bouyer 		 * too, else use compat timings.
    625   1.1   bouyer 		 */
    626   1.1   bouyer 		if ((piix_isp_pio[drvp->PIO_mode] !=
    627   1.1   bouyer 		    piix_isp_dma[drvp->DMA_mode]) ||
    628   1.1   bouyer 		    (piix_rtc_pio[drvp->PIO_mode] !=
    629   1.1   bouyer 		    piix_rtc_dma[drvp->DMA_mode]))
    630   1.1   bouyer 			drvp->PIO_mode = 0;
    631   1.1   bouyer 		/* if PIO mode <= 2, use compat timings for PIO */
    632   1.1   bouyer 		if (drvp->PIO_mode <= 2) {
    633   1.1   bouyer 			ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_DTE(drive),
    634   1.1   bouyer 			    channel);
    635   1.1   bouyer 			return ret;
    636   1.1   bouyer 		}
    637   1.1   bouyer 	}
    638   1.1   bouyer 
    639   1.1   bouyer 	/*
    640   1.1   bouyer 	 * Now setup PIO modes. If mode < 2, use compat timings.
    641   1.1   bouyer 	 * Else enable fast timings. Enable IORDY and prefetch/post
    642   1.1   bouyer 	 * if PIO mode >= 3.
    643   1.1   bouyer 	 */
    644   1.1   bouyer 
    645   1.1   bouyer 	if (drvp->PIO_mode < 2)
    646   1.1   bouyer 		return ret;
    647   1.1   bouyer 
    648   1.1   bouyer 	ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_TIME(drive), channel);
    649   1.1   bouyer 	if (drvp->PIO_mode >= 3) {
    650   1.1   bouyer 		ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_IE(drive), channel);
    651   1.1   bouyer 		ret = PIIX_IDETIM_SET(ret, PIIX_IDETIM_PPE(drive), channel);
    652   1.1   bouyer 	}
    653   1.1   bouyer 	return ret;
    654   1.1   bouyer }
    655   1.1   bouyer 
    656   1.1   bouyer /* setup values in SIDETIM registers, based on mode */
    657   1.1   bouyer static u_int32_t
    658   1.1   bouyer piix_setup_sidetim_timings(mode, dma, channel)
    659   1.1   bouyer 	u_int8_t mode;
    660   1.1   bouyer 	u_int8_t dma;
    661   1.1   bouyer 	u_int8_t channel;
    662   1.1   bouyer {
    663   1.1   bouyer 	if (dma)
    664   1.1   bouyer 		return PIIX_SIDETIM_ISP_SET(piix_isp_dma[mode], channel) |
    665   1.1   bouyer 		    PIIX_SIDETIM_RTC_SET(piix_rtc_dma[mode], channel);
    666   1.1   bouyer 	else
    667   1.1   bouyer 		return PIIX_SIDETIM_ISP_SET(piix_isp_pio[mode], channel) |
    668   1.1   bouyer 		    PIIX_SIDETIM_RTC_SET(piix_rtc_pio[mode], channel);
    669   1.5   bouyer }
    670   1.5   bouyer 
    671   1.5   bouyer static void
    672   1.5   bouyer piixsata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    673   1.5   bouyer {
    674   1.5   bouyer 	struct pciide_channel *cp;
    675   1.5   bouyer 	bus_size_t cmdsize, ctlsize;
    676   1.5   bouyer 	pcireg_t interface;
    677   1.5   bouyer 	int channel;
    678   1.5   bouyer 
    679   1.5   bouyer 	if (pciide_chipen(sc, pa) == 0)
    680   1.5   bouyer 		return;
    681   1.5   bouyer 
    682   1.5   bouyer 	aprint_normal("%s: bus-master DMA support present",
    683  1.14  thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    684   1.5   bouyer 	pciide_mapreg_dma(sc, pa);
    685   1.5   bouyer 	aprint_normal("\n");
    686   1.1   bouyer 
    687  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    688  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    689   1.1   bouyer 	if (sc->sc_dma_ok) {
    690  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    691   1.1   bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    692  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    693  1.14  thorpej 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    694   1.1   bouyer 	}
    695  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    696   1.1   bouyer 
    697  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    698  1.14  thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    699   1.1   bouyer 
    700   1.1   bouyer 	interface = PCI_INTERFACE(pa->pa_class);
    701   1.1   bouyer 
    702  1.12  thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    703  1.12  thorpej 
    704  1.14  thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    705  1.14  thorpej 	     channel++) {
    706   1.1   bouyer 		cp = &sc->pciide_channels[channel];
    707   1.1   bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    708   1.1   bouyer 			continue;
    709   1.1   bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    710   1.1   bouyer 		    pciide_pci_intr);
    711   1.1   bouyer 	}
    712   1.1   bouyer }
    713