Home | History | Annotate | Line # | Download | only in pci
pdcide.c revision 1.12.2.5
      1  1.12.2.5  skrll /*	$NetBSD: pdcide.c,v 1.12.2.5 2004/09/21 13:31:07 skrll Exp $	*/
      2  1.12.2.2  skrll 
      3  1.12.2.2  skrll /*
      4  1.12.2.2  skrll  * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
      5  1.12.2.2  skrll  *
      6  1.12.2.2  skrll  * Redistribution and use in source and binary forms, with or without
      7  1.12.2.2  skrll  * modification, are permitted provided that the following conditions
      8  1.12.2.2  skrll  * are met:
      9  1.12.2.2  skrll  * 1. Redistributions of source code must retain the above copyright
     10  1.12.2.2  skrll  *    notice, this list of conditions and the following disclaimer.
     11  1.12.2.2  skrll  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.12.2.2  skrll  *    notice, this list of conditions and the following disclaimer in the
     13  1.12.2.2  skrll  *    documentation and/or other materials provided with the distribution.
     14  1.12.2.2  skrll  * 3. All advertising materials mentioning features or use of this software
     15  1.12.2.2  skrll  *    must display the following acknowledgement:
     16  1.12.2.2  skrll  *	This product includes software developed by Manuel Bouyer.
     17  1.12.2.2  skrll  * 4. The name of the author may not be used to endorse or promote products
     18  1.12.2.2  skrll  *    derived from this software without specific prior written permission.
     19  1.12.2.2  skrll  *
     20  1.12.2.2  skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.12.2.2  skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.12.2.2  skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.12.2.2  skrll  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.12.2.2  skrll  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.12.2.2  skrll  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.12.2.2  skrll  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.12.2.2  skrll  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.12.2.2  skrll  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.12.2.2  skrll  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.12.2.2  skrll  */
     31  1.12.2.2  skrll 
     32  1.12.2.2  skrll #include <sys/param.h>
     33  1.12.2.2  skrll #include <sys/systm.h>
     34  1.12.2.2  skrll 
     35  1.12.2.2  skrll #include <dev/pci/pcivar.h>
     36  1.12.2.2  skrll #include <dev/pci/pcidevs.h>
     37  1.12.2.2  skrll #include <dev/pci/pciidereg.h>
     38  1.12.2.2  skrll #include <dev/pci/pciidevar.h>
     39  1.12.2.2  skrll #include <dev/pci/pciide_pdc202xx_reg.h>
     40  1.12.2.2  skrll 
     41  1.12.2.2  skrll static void pdc202xx_chip_map(struct pciide_softc *, struct pci_attach_args *);
     42  1.12.2.3  skrll static void pdc202xx_setup_channel(struct ata_channel *);
     43  1.12.2.3  skrll static void pdc20268_setup_channel(struct ata_channel *);
     44  1.12.2.2  skrll static int  pdc202xx_pci_intr(void *);
     45  1.12.2.2  skrll static int  pdc20265_pci_intr(void *);
     46  1.12.2.2  skrll static void pdc20262_dma_start(void *, int, int);
     47  1.12.2.2  skrll static int  pdc20262_dma_finish(void *, int, int, int);
     48  1.12.2.2  skrll 
     49  1.12.2.2  skrll static int  pdcide_match(struct device *, struct cfdata *, void *);
     50  1.12.2.2  skrll static void pdcide_attach(struct device *, struct device *, void *);
     51  1.12.2.2  skrll 
     52  1.12.2.2  skrll CFATTACH_DECL(pdcide, sizeof(struct pciide_softc),
     53  1.12.2.2  skrll     pdcide_match, pdcide_attach, NULL, NULL);
     54  1.12.2.2  skrll 
     55  1.12.2.2  skrll static const struct pciide_product_desc pciide_promise_products[] =  {
     56  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20246,
     57  1.12.2.2  skrll 	  0,
     58  1.12.2.2  skrll 	  "Promise Ultra33/ATA Bus Master IDE Accelerator",
     59  1.12.2.2  skrll 	  pdc202xx_chip_map,
     60  1.12.2.2  skrll 	},
     61  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20262,
     62  1.12.2.2  skrll 	  0,
     63  1.12.2.2  skrll 	  "Promise Ultra66/ATA Bus Master IDE Accelerator",
     64  1.12.2.2  skrll 	  pdc202xx_chip_map,
     65  1.12.2.2  skrll 	},
     66  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20267,
     67  1.12.2.2  skrll 	  0,
     68  1.12.2.2  skrll 	  "Promise Ultra100/ATA Bus Master IDE Accelerator",
     69  1.12.2.2  skrll 	  pdc202xx_chip_map,
     70  1.12.2.2  skrll 	},
     71  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20265,
     72  1.12.2.2  skrll 	  0,
     73  1.12.2.2  skrll 	  "Promise Ultra100/ATA Bus Master IDE Accelerator",
     74  1.12.2.2  skrll 	  pdc202xx_chip_map,
     75  1.12.2.2  skrll 	},
     76  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20268,
     77  1.12.2.2  skrll 	  0,
     78  1.12.2.2  skrll 	  "Promise Ultra100TX2/ATA Bus Master IDE Accelerator",
     79  1.12.2.2  skrll 	  pdc202xx_chip_map,
     80  1.12.2.2  skrll 	},
     81  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20270,
     82  1.12.2.2  skrll 	  0,
     83  1.12.2.2  skrll 	  "Promise Ultra100TX2v2/ATA Bus Master IDE Accelerator",
     84  1.12.2.2  skrll 	  pdc202xx_chip_map,
     85  1.12.2.2  skrll 	},
     86  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20269,
     87  1.12.2.2  skrll 	  0,
     88  1.12.2.2  skrll 	  "Promise Ultra133/ATA Bus Master IDE Accelerator",
     89  1.12.2.2  skrll 	  pdc202xx_chip_map,
     90  1.12.2.2  skrll 	},
     91  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20276,
     92  1.12.2.2  skrll 	  0,
     93  1.12.2.2  skrll 	  "Promise Ultra133TX2/ATA Bus Master IDE Accelerator",
     94  1.12.2.2  skrll 	  pdc202xx_chip_map,
     95  1.12.2.2  skrll 	},
     96  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20275,
     97  1.12.2.2  skrll 	  0,
     98  1.12.2.2  skrll 	  "Promise Ultra133/ATA Bus Master IDE Accelerator (MB)",
     99  1.12.2.2  skrll 	  pdc202xx_chip_map,
    100  1.12.2.2  skrll 	},
    101  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20271,
    102  1.12.2.2  skrll 	  0,
    103  1.12.2.2  skrll 	  "Promise Ultra133TX2v2/ATA Bus Master IDE Accelerator",
    104  1.12.2.2  skrll 	  pdc202xx_chip_map,
    105  1.12.2.2  skrll 	},
    106  1.12.2.2  skrll 	{ PCI_PRODUCT_PROMISE_PDC20277,
    107  1.12.2.2  skrll 	  0,
    108  1.12.2.2  skrll 	  "Promise Fasttrak133 Lite Bus Master IDE Accelerator",
    109  1.12.2.2  skrll 	  pdc202xx_chip_map,
    110  1.12.2.2  skrll 	},
    111  1.12.2.2  skrll 	{ 0,
    112  1.12.2.2  skrll 	  0,
    113  1.12.2.2  skrll 	  NULL,
    114  1.12.2.2  skrll 	  NULL
    115  1.12.2.2  skrll 	}
    116  1.12.2.2  skrll };
    117  1.12.2.2  skrll 
    118  1.12.2.2  skrll static int
    119  1.12.2.2  skrll pdcide_match(struct device *parent, struct cfdata *match, void *aux)
    120  1.12.2.2  skrll {
    121  1.12.2.2  skrll 	struct pci_attach_args *pa = aux;
    122  1.12.2.2  skrll 
    123  1.12.2.2  skrll 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_PROMISE) {
    124  1.12.2.2  skrll 		if (pciide_lookup_product(pa->pa_id, pciide_promise_products))
    125  1.12.2.2  skrll 			return (2);
    126  1.12.2.2  skrll 	}
    127  1.12.2.2  skrll 	return (0);
    128  1.12.2.2  skrll }
    129  1.12.2.2  skrll 
    130  1.12.2.2  skrll static void
    131  1.12.2.2  skrll pdcide_attach(struct device *parent, struct device *self, void *aux)
    132  1.12.2.2  skrll {
    133  1.12.2.2  skrll 	struct pci_attach_args *pa = aux;
    134  1.12.2.2  skrll 	struct pciide_softc *sc = (struct pciide_softc *)self;
    135  1.12.2.2  skrll 
    136  1.12.2.2  skrll 	pciide_common_attach(sc, pa,
    137  1.12.2.2  skrll 	    pciide_lookup_product(pa->pa_id, pciide_promise_products));
    138  1.12.2.2  skrll 
    139  1.12.2.2  skrll }
    140  1.12.2.2  skrll 
    141  1.12.2.2  skrll /* Macros to test product */
    142  1.12.2.2  skrll #define PDC_IS_262(sc)							\
    143  1.12.2.2  skrll 	((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20262 ||	\
    144  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20267 ||	\
    145  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20265 ||	\
    146  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20268 ||	\
    147  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20270 || \
    148  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 ||	\
    149  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 ||	\
    150  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
    151  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
    152  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
    153  1.12.2.2  skrll #define PDC_IS_265(sc)							\
    154  1.12.2.2  skrll 	((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20267 ||	\
    155  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20265 ||	\
    156  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20268 ||	\
    157  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20270 || \
    158  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 ||	\
    159  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 ||	\
    160  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
    161  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
    162  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
    163  1.12.2.2  skrll #define PDC_IS_268(sc)							\
    164  1.12.2.2  skrll 	((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20268 ||	\
    165  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20270 || \
    166  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 ||	\
    167  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 ||	\
    168  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
    169  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
    170  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
    171  1.12.2.2  skrll #define PDC_IS_276(sc)							\
    172  1.12.2.2  skrll 	((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 ||	\
    173  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 ||	\
    174  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
    175  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
    176  1.12.2.2  skrll 	(sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
    177  1.12.2.2  skrll 
    178  1.12.2.2  skrll static void
    179  1.12.2.2  skrll pdc202xx_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    180  1.12.2.2  skrll {
    181  1.12.2.2  skrll 	struct pciide_channel *cp;
    182  1.12.2.2  skrll 	int channel;
    183  1.12.2.2  skrll 	pcireg_t interface, st, mode;
    184  1.12.2.2  skrll 	bus_size_t cmdsize, ctlsize;
    185  1.12.2.2  skrll 
    186  1.12.2.2  skrll 	if (!PDC_IS_268(sc)) {
    187  1.12.2.2  skrll 		st = pci_conf_read(sc->sc_pc, sc->sc_tag, PDC2xx_STATE);
    188  1.12.2.3  skrll 		ATADEBUG_PRINT(("pdc202xx_setup_chip: controller state 0x%x\n",
    189  1.12.2.2  skrll 		    st), DEBUG_PROBE);
    190  1.12.2.2  skrll 		/* turn off  RAID mode */
    191  1.12.2.2  skrll 		if (st & PDC2xx_STATE_IDERAID) {
    192  1.12.2.3  skrll 			ATADEBUG_PRINT(("pdc202xx_setup_chip: turning off RAID mode\n"), DEBUG_PROBE);
    193  1.12.2.2  skrll 			st &= ~PDC2xx_STATE_IDERAID;
    194  1.12.2.2  skrll 			pci_conf_write(sc->sc_pc, sc->sc_tag, PDC2xx_STATE, st);
    195  1.12.2.2  skrll 		}
    196  1.12.2.2  skrll 	} else
    197  1.12.2.2  skrll 		st = PDC2xx_STATE_NATIVE | PDC262_STATE_EN(0) | PDC262_STATE_EN(1);
    198  1.12.2.2  skrll 
    199  1.12.2.2  skrll 	if (pciide_chipen(sc, pa) == 0)
    200  1.12.2.2  skrll 		return;
    201  1.12.2.2  skrll 
    202  1.12.2.2  skrll 	/*
    203  1.12.2.2  skrll 	 * can't rely on the PCI_CLASS_REG content if the chip was in raid
    204  1.12.2.2  skrll 	 * mode. We have to fake interface
    205  1.12.2.2  skrll 	 */
    206  1.12.2.2  skrll 	interface = PCIIDE_INTERFACE_SETTABLE(0) | PCIIDE_INTERFACE_SETTABLE(1);
    207  1.12.2.2  skrll 	if (st & PDC2xx_STATE_NATIVE)
    208  1.12.2.2  skrll 		interface |= PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    209  1.12.2.2  skrll 
    210  1.12.2.2  skrll 	aprint_normal("%s: bus-master DMA support present",
    211  1.12.2.3  skrll 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    212  1.12.2.2  skrll 	pciide_mapreg_dma(sc, pa);
    213  1.12.2.2  skrll 	aprint_normal("\n");
    214  1.12.2.3  skrll 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    215  1.12.2.2  skrll 	if (sc->sc_dma_ok) {
    216  1.12.2.3  skrll 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    217  1.12.2.2  skrll 		sc->sc_wdcdev.irqack = pciide_irqack;
    218  1.12.2.2  skrll 	}
    219  1.12.2.2  skrll 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    220  1.12.2.2  skrll 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    221  1.12.2.3  skrll 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    222  1.12.2.3  skrll 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    223  1.12.2.3  skrll 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    224  1.12.2.2  skrll 	if (PDC_IS_276(sc))
    225  1.12.2.3  skrll 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    226  1.12.2.2  skrll 	else if (PDC_IS_265(sc))
    227  1.12.2.3  skrll 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    228  1.12.2.2  skrll 	else if (PDC_IS_262(sc))
    229  1.12.2.3  skrll 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    230  1.12.2.2  skrll 	else
    231  1.12.2.3  skrll 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    232  1.12.2.3  skrll 	sc->sc_wdcdev.sc_atac.atac_set_modes = PDC_IS_268(sc) ?
    233  1.12.2.2  skrll 			pdc20268_setup_channel : pdc202xx_setup_channel;
    234  1.12.2.3  skrll 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    235  1.12.2.3  skrll 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    236  1.12.2.3  skrll 
    237  1.12.2.3  skrll 	wdc_allocate_regs(&sc->sc_wdcdev);
    238  1.12.2.2  skrll 
    239  1.12.2.2  skrll 	if (sc->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20262 ||
    240  1.12.2.2  skrll 	    sc->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20267 ||
    241  1.12.2.2  skrll 	    sc->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20265) {
    242  1.12.2.2  skrll 		sc->sc_wdcdev.dma_start = pdc20262_dma_start;
    243  1.12.2.2  skrll 		sc->sc_wdcdev.dma_finish = pdc20262_dma_finish;
    244  1.12.2.2  skrll 	}
    245  1.12.2.2  skrll 
    246  1.12.2.2  skrll 	if (!PDC_IS_268(sc)) {
    247  1.12.2.2  skrll 		/* setup failsafe defaults */
    248  1.12.2.2  skrll 		mode = 0;
    249  1.12.2.2  skrll 		mode = PDC2xx_TIM_SET_PA(mode, pdc2xx_pa[0]);
    250  1.12.2.2  skrll 		mode = PDC2xx_TIM_SET_PB(mode, pdc2xx_pb[0]);
    251  1.12.2.2  skrll 		mode = PDC2xx_TIM_SET_MB(mode, pdc2xx_dma_mb[0]);
    252  1.12.2.2  skrll 		mode = PDC2xx_TIM_SET_MC(mode, pdc2xx_dma_mc[0]);
    253  1.12.2.2  skrll 		for (channel = 0;
    254  1.12.2.3  skrll 		     channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    255  1.12.2.2  skrll 		     channel++) {
    256  1.12.2.3  skrll 			ATADEBUG_PRINT(("pdc202xx_setup_chip: channel %d "
    257  1.12.2.2  skrll 			    "drive 0 initial timings  0x%x, now 0x%x\n",
    258  1.12.2.2  skrll 			    channel, pci_conf_read(sc->sc_pc, sc->sc_tag,
    259  1.12.2.2  skrll 			    PDC2xx_TIM(channel, 0)), mode | PDC2xx_TIM_IORDYp),
    260  1.12.2.2  skrll 			    DEBUG_PROBE);
    261  1.12.2.2  skrll 			pci_conf_write(sc->sc_pc, sc->sc_tag,
    262  1.12.2.2  skrll 			    PDC2xx_TIM(channel, 0), mode | PDC2xx_TIM_IORDYp);
    263  1.12.2.3  skrll 			ATADEBUG_PRINT(("pdc202xx_setup_chip: channel %d "
    264  1.12.2.2  skrll 			    "drive 1 initial timings  0x%x, now 0x%x\n",
    265  1.12.2.2  skrll 			    channel, pci_conf_read(sc->sc_pc, sc->sc_tag,
    266  1.12.2.2  skrll 			    PDC2xx_TIM(channel, 1)), mode), DEBUG_PROBE);
    267  1.12.2.2  skrll 			pci_conf_write(sc->sc_pc, sc->sc_tag,
    268  1.12.2.2  skrll 			    PDC2xx_TIM(channel, 1), mode);
    269  1.12.2.2  skrll 		}
    270  1.12.2.2  skrll 
    271  1.12.2.2  skrll 		mode = PDC2xx_SCR_DMA;
    272  1.12.2.2  skrll 		if (PDC_IS_265(sc)) {
    273  1.12.2.2  skrll 			mode = PDC2xx_SCR_SET_GEN(mode, PDC265_SCR_GEN_LAT);
    274  1.12.2.2  skrll 		} else if (PDC_IS_262(sc)) {
    275  1.12.2.2  skrll 			mode = PDC2xx_SCR_SET_GEN(mode, PDC262_SCR_GEN_LAT);
    276  1.12.2.2  skrll 		} else {
    277  1.12.2.2  skrll 			/* the BIOS set it up this way */
    278  1.12.2.2  skrll 			mode = PDC2xx_SCR_SET_GEN(mode, 0x1);
    279  1.12.2.2  skrll 		}
    280  1.12.2.2  skrll 		mode = PDC2xx_SCR_SET_I2C(mode, 0x3); /* ditto */
    281  1.12.2.2  skrll 		mode = PDC2xx_SCR_SET_POLL(mode, 0x1); /* ditto */
    282  1.12.2.3  skrll 		ATADEBUG_PRINT(("pdc202xx_setup_chip: initial SCR  0x%x, "
    283  1.12.2.2  skrll 		    "now 0x%x\n",
    284  1.12.2.2  skrll 		    bus_space_read_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    285  1.12.2.2  skrll 			PDC2xx_SCR),
    286  1.12.2.2  skrll 		    mode), DEBUG_PROBE);
    287  1.12.2.2  skrll 		bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    288  1.12.2.2  skrll 		    PDC2xx_SCR, mode);
    289  1.12.2.2  skrll 
    290  1.12.2.2  skrll 		/* controller initial state register is OK even without BIOS */
    291  1.12.2.2  skrll 		/* Set DMA mode to IDE DMA compatibility */
    292  1.12.2.2  skrll 		mode =
    293  1.12.2.2  skrll 		    bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_PM);
    294  1.12.2.3  skrll 		ATADEBUG_PRINT(("pdc202xx_setup_chip: primary mode 0x%x", mode),
    295  1.12.2.2  skrll 		    DEBUG_PROBE);
    296  1.12.2.2  skrll 		bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_PM,
    297  1.12.2.2  skrll 		    mode | 0x1);
    298  1.12.2.2  skrll 		mode =
    299  1.12.2.2  skrll 		    bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_SM);
    300  1.12.2.3  skrll 		ATADEBUG_PRINT((", secondary mode 0x%x\n", mode ), DEBUG_PROBE);
    301  1.12.2.2  skrll 		bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_SM,
    302  1.12.2.2  skrll 		    mode | 0x1);
    303  1.12.2.2  skrll 	}
    304  1.12.2.3  skrll 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    305  1.12.2.3  skrll 	     channel++) {
    306  1.12.2.2  skrll 		cp = &sc->pciide_channels[channel];
    307  1.12.2.2  skrll 		if (pciide_chansetup(sc, channel, interface) == 0)
    308  1.12.2.2  skrll 			continue;
    309  1.12.2.2  skrll 		if ((st & (PDC_IS_262(sc) ?
    310  1.12.2.2  skrll 		    PDC262_STATE_EN(channel):PDC246_STATE_EN(channel))) == 0) {
    311  1.12.2.2  skrll 			aprint_normal("%s: %s channel ignored (disabled)\n",
    312  1.12.2.3  skrll 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    313  1.12.2.3  skrll 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    314  1.12.2.2  skrll 			continue;
    315  1.12.2.2  skrll 		}
    316  1.12.2.2  skrll 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    317  1.12.2.2  skrll 		    PDC_IS_265(sc) ? pdc20265_pci_intr : pdc202xx_pci_intr);
    318  1.12.2.2  skrll 		/* clear interrupt, in case there is one pending */
    319  1.12.2.2  skrll 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    320  1.12.2.2  skrll 		    IDEDMA_CTL_INTR);
    321  1.12.2.2  skrll 	}
    322  1.12.2.2  skrll 	return;
    323  1.12.2.2  skrll }
    324  1.12.2.2  skrll 
    325  1.12.2.2  skrll static void
    326  1.12.2.3  skrll pdc202xx_setup_channel(struct ata_channel *chp)
    327  1.12.2.2  skrll {
    328  1.12.2.2  skrll 	struct ata_drive_datas *drvp;
    329  1.12.2.3  skrll 	int drive, s;
    330  1.12.2.2  skrll 	pcireg_t mode, st;
    331  1.12.2.2  skrll 	u_int32_t idedma_ctl, scr, atapi;
    332  1.12.2.3  skrll 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    333  1.12.2.3  skrll 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    334  1.12.2.2  skrll 	int channel = chp->ch_channel;
    335  1.12.2.2  skrll 
    336  1.12.2.2  skrll 	/* setup DMA if needed */
    337  1.12.2.2  skrll 	pciide_channel_dma_setup(cp);
    338  1.12.2.2  skrll 
    339  1.12.2.2  skrll 	idedma_ctl = 0;
    340  1.12.2.3  skrll 	ATADEBUG_PRINT(("pdc202xx_setup_channel %s: scr 0x%x\n",
    341  1.12.2.3  skrll 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    342  1.12.2.2  skrll 	    bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC262_U66)),
    343  1.12.2.2  skrll 	    DEBUG_PROBE);
    344  1.12.2.2  skrll 
    345  1.12.2.2  skrll 	/* Per channel settings */
    346  1.12.2.2  skrll 	if (PDC_IS_262(sc)) {
    347  1.12.2.2  skrll 		scr = bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh,
    348  1.12.2.2  skrll 		    PDC262_U66);
    349  1.12.2.2  skrll 		st = pci_conf_read(sc->sc_pc, sc->sc_tag, PDC2xx_STATE);
    350  1.12.2.2  skrll 		/* Trim UDMA mode */
    351  1.12.2.2  skrll 		if ((st & PDC262_STATE_80P(channel)) != 0 ||
    352  1.12.2.2  skrll 		    (chp->ch_drive[0].drive_flags & DRIVE_UDMA &&
    353  1.12.2.2  skrll 		    chp->ch_drive[0].UDMA_mode <= 2) ||
    354  1.12.2.2  skrll 		    (chp->ch_drive[1].drive_flags & DRIVE_UDMA &&
    355  1.12.2.2  skrll 		    chp->ch_drive[1].UDMA_mode <= 2)) {
    356  1.12.2.2  skrll 			if (chp->ch_drive[0].UDMA_mode > 2)
    357  1.12.2.2  skrll 				chp->ch_drive[0].UDMA_mode = 2;
    358  1.12.2.2  skrll 			if (chp->ch_drive[1].UDMA_mode > 2)
    359  1.12.2.2  skrll 				chp->ch_drive[1].UDMA_mode = 2;
    360  1.12.2.2  skrll 		}
    361  1.12.2.2  skrll 		/* Set U66 if needed */
    362  1.12.2.2  skrll 		if ((chp->ch_drive[0].drive_flags & DRIVE_UDMA &&
    363  1.12.2.2  skrll 		    chp->ch_drive[0].UDMA_mode > 2) ||
    364  1.12.2.2  skrll 		    (chp->ch_drive[1].drive_flags & DRIVE_UDMA &&
    365  1.12.2.2  skrll 		    chp->ch_drive[1].UDMA_mode > 2))
    366  1.12.2.2  skrll 			scr |= PDC262_U66_EN(channel);
    367  1.12.2.2  skrll 		else
    368  1.12.2.2  skrll 			scr &= ~PDC262_U66_EN(channel);
    369  1.12.2.2  skrll 		bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh,
    370  1.12.2.2  skrll 		    PDC262_U66, scr);
    371  1.12.2.3  skrll 		ATADEBUG_PRINT(("pdc202xx_setup_channel %s:%d: ATAPI 0x%x\n",
    372  1.12.2.3  skrll 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel,
    373  1.12.2.2  skrll 		    bus_space_read_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    374  1.12.2.2  skrll 		    PDC262_ATAPI(channel))), DEBUG_PROBE);
    375  1.12.2.2  skrll 		if (chp->ch_drive[0].drive_flags & DRIVE_ATAPI ||
    376  1.12.2.2  skrll 			chp->ch_drive[1].drive_flags & DRIVE_ATAPI) {
    377  1.12.2.2  skrll 			if (((chp->ch_drive[0].drive_flags & DRIVE_UDMA) &&
    378  1.12.2.2  skrll 			    !(chp->ch_drive[1].drive_flags & DRIVE_UDMA) &&
    379  1.12.2.2  skrll 			    (chp->ch_drive[1].drive_flags & DRIVE_DMA)) ||
    380  1.12.2.2  skrll 			    ((chp->ch_drive[1].drive_flags & DRIVE_UDMA) &&
    381  1.12.2.2  skrll 			    !(chp->ch_drive[0].drive_flags & DRIVE_UDMA) &&
    382  1.12.2.2  skrll 			    (chp->ch_drive[0].drive_flags & DRIVE_DMA)))
    383  1.12.2.2  skrll 				atapi = 0;
    384  1.12.2.2  skrll 			else
    385  1.12.2.2  skrll 				atapi = PDC262_ATAPI_UDMA;
    386  1.12.2.2  skrll 			bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    387  1.12.2.2  skrll 			    PDC262_ATAPI(channel), atapi);
    388  1.12.2.2  skrll 		}
    389  1.12.2.2  skrll 	}
    390  1.12.2.2  skrll 	for (drive = 0; drive < 2; drive++) {
    391  1.12.2.2  skrll 		drvp = &chp->ch_drive[drive];
    392  1.12.2.2  skrll 		/* If no drive, skip */
    393  1.12.2.2  skrll 		if ((drvp->drive_flags & DRIVE) == 0)
    394  1.12.2.2  skrll 			continue;
    395  1.12.2.2  skrll 		mode = 0;
    396  1.12.2.2  skrll 		if (drvp->drive_flags & DRIVE_UDMA) {
    397  1.12.2.2  skrll 			/* use Ultra/DMA */
    398  1.12.2.3  skrll 			s = splbio();
    399  1.12.2.2  skrll 			drvp->drive_flags &= ~DRIVE_DMA;
    400  1.12.2.3  skrll 			splx(s);
    401  1.12.2.2  skrll 			mode = PDC2xx_TIM_SET_MB(mode,
    402  1.12.2.2  skrll 			    pdc2xx_udma_mb[drvp->UDMA_mode]);
    403  1.12.2.2  skrll 			mode = PDC2xx_TIM_SET_MC(mode,
    404  1.12.2.2  skrll 			    pdc2xx_udma_mc[drvp->UDMA_mode]);
    405  1.12.2.2  skrll 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    406  1.12.2.2  skrll 		} else if (drvp->drive_flags & DRIVE_DMA) {
    407  1.12.2.2  skrll 			mode = PDC2xx_TIM_SET_MB(mode,
    408  1.12.2.2  skrll 			    pdc2xx_dma_mb[drvp->DMA_mode]);
    409  1.12.2.2  skrll 			mode = PDC2xx_TIM_SET_MC(mode,
    410  1.12.2.2  skrll 			    pdc2xx_dma_mc[drvp->DMA_mode]);
    411  1.12.2.2  skrll 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    412  1.12.2.2  skrll 		} else {
    413  1.12.2.2  skrll 			mode = PDC2xx_TIM_SET_MB(mode,
    414  1.12.2.2  skrll 			    pdc2xx_dma_mb[0]);
    415  1.12.2.2  skrll 			mode = PDC2xx_TIM_SET_MC(mode,
    416  1.12.2.2  skrll 			    pdc2xx_dma_mc[0]);
    417  1.12.2.2  skrll 		}
    418  1.12.2.2  skrll 		mode = PDC2xx_TIM_SET_PA(mode, pdc2xx_pa[drvp->PIO_mode]);
    419  1.12.2.2  skrll 		mode = PDC2xx_TIM_SET_PB(mode, pdc2xx_pb[drvp->PIO_mode]);
    420  1.12.2.2  skrll 		if (drvp->drive_flags & DRIVE_ATA)
    421  1.12.2.2  skrll 			mode |= PDC2xx_TIM_PRE;
    422  1.12.2.2  skrll 		mode |= PDC2xx_TIM_SYNC | PDC2xx_TIM_ERRDY;
    423  1.12.2.2  skrll 		if (drvp->PIO_mode >= 3) {
    424  1.12.2.2  skrll 			mode |= PDC2xx_TIM_IORDY;
    425  1.12.2.2  skrll 			if (drive == 0)
    426  1.12.2.2  skrll 				mode |= PDC2xx_TIM_IORDYp;
    427  1.12.2.2  skrll 		}
    428  1.12.2.3  skrll 		ATADEBUG_PRINT(("pdc202xx_setup_channel: %s:%d:%d "
    429  1.12.2.2  skrll 		    "timings 0x%x\n",
    430  1.12.2.3  skrll 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    431  1.12.2.2  skrll 		    chp->ch_channel, drive, mode), DEBUG_PROBE);
    432  1.12.2.2  skrll 		pci_conf_write(sc->sc_pc, sc->sc_tag,
    433  1.12.2.2  skrll 		    PDC2xx_TIM(chp->ch_channel, drive), mode);
    434  1.12.2.2  skrll 	}
    435  1.12.2.2  skrll 	if (idedma_ctl != 0) {
    436  1.12.2.2  skrll 		/* Add software bits in status register */
    437  1.12.2.2  skrll 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL],
    438  1.12.2.2  skrll 		    0, idedma_ctl);
    439  1.12.2.2  skrll 	}
    440  1.12.2.2  skrll }
    441  1.12.2.2  skrll 
    442  1.12.2.2  skrll static void
    443  1.12.2.3  skrll pdc20268_setup_channel(struct ata_channel *chp)
    444  1.12.2.2  skrll {
    445  1.12.2.2  skrll 	struct ata_drive_datas *drvp;
    446  1.12.2.3  skrll 	int drive, s;
    447  1.12.2.2  skrll 	u_int32_t idedma_ctl;
    448  1.12.2.3  skrll 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    449  1.12.2.3  skrll 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    450  1.12.2.2  skrll 	int u100;
    451  1.12.2.2  skrll 
    452  1.12.2.2  skrll 	/* setup DMA if needed */
    453  1.12.2.2  skrll 	pciide_channel_dma_setup(cp);
    454  1.12.2.2  skrll 
    455  1.12.2.2  skrll 	idedma_ctl = 0;
    456  1.12.2.2  skrll 
    457  1.12.2.2  skrll 	/* I don't know what this is for, FreeBSD does it ... */
    458  1.12.2.2  skrll 	bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh,
    459  1.12.2.2  skrll 	    IDEDMA_CMD + 0x1 + IDEDMA_SCH_OFFSET * chp->ch_channel, 0x0b);
    460  1.12.2.2  skrll 
    461  1.12.2.2  skrll 	/*
    462  1.12.2.2  skrll 	 * cable type detect, from FreeBSD
    463  1.12.2.2  skrll 	 */
    464  1.12.2.2  skrll 	u100 = (bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh,
    465  1.12.2.2  skrll 	    IDEDMA_CMD + 0x3 + IDEDMA_SCH_OFFSET * chp->ch_channel) & 0x04) ?
    466  1.12.2.2  skrll 	    0 : 1;
    467  1.12.2.2  skrll 
    468  1.12.2.2  skrll 	for (drive = 0; drive < 2; drive++) {
    469  1.12.2.2  skrll 		drvp = &chp->ch_drive[drive];
    470  1.12.2.2  skrll 		/* If no drive, skip */
    471  1.12.2.2  skrll 		if ((drvp->drive_flags & DRIVE) == 0)
    472  1.12.2.2  skrll 			continue;
    473  1.12.2.2  skrll 		if (drvp->drive_flags & DRIVE_UDMA) {
    474  1.12.2.2  skrll 			/* use Ultra/DMA */
    475  1.12.2.3  skrll 			s = splbio();
    476  1.12.2.2  skrll 			drvp->drive_flags &= ~DRIVE_DMA;
    477  1.12.2.3  skrll 			splx(s);
    478  1.12.2.2  skrll 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    479  1.12.2.2  skrll 			if (drvp->UDMA_mode > 2 && u100 == 0)
    480  1.12.2.2  skrll 				drvp->UDMA_mode = 2;
    481  1.12.2.2  skrll 		} else if (drvp->drive_flags & DRIVE_DMA) {
    482  1.12.2.2  skrll 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    483  1.12.2.2  skrll 		}
    484  1.12.2.2  skrll 	}
    485  1.12.2.2  skrll 	/* nothing to do to setup modes, the controller snoop SET_FEATURE cmd */
    486  1.12.2.2  skrll 	if (idedma_ctl != 0) {
    487  1.12.2.2  skrll 		/* Add software bits in status register */
    488  1.12.2.2  skrll 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL],
    489  1.12.2.2  skrll 		    0, idedma_ctl);
    490  1.12.2.2  skrll 	}
    491  1.12.2.2  skrll }
    492  1.12.2.2  skrll 
    493  1.12.2.2  skrll static int
    494  1.12.2.2  skrll pdc202xx_pci_intr(void *arg)
    495  1.12.2.2  skrll {
    496  1.12.2.2  skrll 	struct pciide_softc *sc = arg;
    497  1.12.2.2  skrll 	struct pciide_channel *cp;
    498  1.12.2.3  skrll 	struct ata_channel *wdc_cp;
    499  1.12.2.2  skrll 	int i, rv, crv;
    500  1.12.2.2  skrll 	u_int32_t scr;
    501  1.12.2.2  skrll 
    502  1.12.2.2  skrll 	rv = 0;
    503  1.12.2.2  skrll 	scr = bus_space_read_4(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_SCR);
    504  1.12.2.3  skrll 	for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
    505  1.12.2.2  skrll 		cp = &sc->pciide_channels[i];
    506  1.12.2.3  skrll 		wdc_cp = &cp->ata_channel;
    507  1.12.2.2  skrll 		/* If a compat channel skip. */
    508  1.12.2.2  skrll 		if (cp->compat)
    509  1.12.2.2  skrll 			continue;
    510  1.12.2.2  skrll 		if (scr & PDC2xx_SCR_INT(i)) {
    511  1.12.2.2  skrll 			crv = wdcintr(wdc_cp);
    512  1.12.2.3  skrll 			if (crv == 0)
    513  1.12.2.2  skrll 				printf("%s:%d: bogus intr (reg 0x%x)\n",
    514  1.12.2.3  skrll 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    515  1.12.2.3  skrll 				    i, scr);
    516  1.12.2.3  skrll 			else
    517  1.12.2.2  skrll 				rv = 1;
    518  1.12.2.2  skrll 		}
    519  1.12.2.2  skrll 	}
    520  1.12.2.2  skrll 	return rv;
    521  1.12.2.2  skrll }
    522  1.12.2.2  skrll 
    523  1.12.2.2  skrll static int
    524  1.12.2.2  skrll pdc20265_pci_intr(void *arg)
    525  1.12.2.2  skrll {
    526  1.12.2.2  skrll 	struct pciide_softc *sc = arg;
    527  1.12.2.2  skrll 	struct pciide_channel *cp;
    528  1.12.2.3  skrll 	struct ata_channel *wdc_cp;
    529  1.12.2.2  skrll 	int i, rv, crv;
    530  1.12.2.2  skrll 	u_int32_t dmastat;
    531  1.12.2.2  skrll 
    532  1.12.2.2  skrll 	rv = 0;
    533  1.12.2.3  skrll 	for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
    534  1.12.2.2  skrll 		cp = &sc->pciide_channels[i];
    535  1.12.2.3  skrll 		wdc_cp = &cp->ata_channel;
    536  1.12.2.2  skrll 		/* If a compat channel skip. */
    537  1.12.2.2  skrll 		if (cp->compat)
    538  1.12.2.2  skrll 			continue;
    539  1.12.2.2  skrll #if 0
    540  1.12.2.2  skrll 		bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh, IDEDMA_CMD + 0x1 + IDEDMA_SCH_OFFSET * i, 0x0b);
    541  1.12.2.2  skrll 		if ((bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, IDEDMA_CMD + 0x3 + IDEDMA_SCH_OFFSET * i) & 0x20) == 0)
    542  1.12.2.2  skrll 			continue;
    543  1.12.2.2  skrll #endif
    544  1.12.2.2  skrll 		/*
    545  1.12.2.2  skrll 		 * The Ultra/100 seems to assert PDC2xx_SCR_INT * spuriously,
    546  1.12.2.2  skrll 		 * however it asserts INT in IDEDMA_CTL even for non-DMA ops.
    547  1.12.2.2  skrll 		 * So use it instead (requires 2 reg reads instead of 1,
    548  1.12.2.2  skrll 		 * but we can't do it another way).
    549  1.12.2.2  skrll 		 */
    550  1.12.2.2  skrll 		dmastat = bus_space_read_1(sc->sc_dma_iot,
    551  1.12.2.2  skrll 		    cp->dma_iohs[IDEDMA_CTL], 0);
    552  1.12.2.2  skrll 		if((dmastat & IDEDMA_CTL_INTR) == 0)
    553  1.12.2.2  skrll 			continue;
    554  1.12.2.2  skrll 		crv = wdcintr(wdc_cp);
    555  1.12.2.2  skrll 		if (crv == 0)
    556  1.12.2.2  skrll 			printf("%s:%d: bogus intr\n",
    557  1.12.2.3  skrll 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, i);
    558  1.12.2.2  skrll 		else
    559  1.12.2.2  skrll 			rv = 1;
    560  1.12.2.2  skrll 	}
    561  1.12.2.2  skrll 	return rv;
    562  1.12.2.2  skrll }
    563  1.12.2.2  skrll 
    564  1.12.2.2  skrll static void
    565  1.12.2.2  skrll pdc20262_dma_start(void *v, int channel, int drive)
    566  1.12.2.2  skrll {
    567  1.12.2.2  skrll 	struct pciide_softc *sc = v;
    568  1.12.2.2  skrll 	struct pciide_dma_maps *dma_maps =
    569  1.12.2.2  skrll 	    &sc->pciide_channels[channel].dma_maps[drive];
    570  1.12.2.2  skrll 	int atapi;
    571  1.12.2.2  skrll 
    572  1.12.2.2  skrll 	if (dma_maps->dma_flags & WDC_DMA_LBA48) {
    573  1.12.2.2  skrll 		atapi = (dma_maps->dma_flags & WDC_DMA_READ) ?
    574  1.12.2.2  skrll 		    PDC262_ATAPI_LBA48_READ : PDC262_ATAPI_LBA48_WRITE;
    575  1.12.2.2  skrll 		atapi |= dma_maps->dmamap_xfer->dm_mapsize >> 1;
    576  1.12.2.2  skrll 		bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    577  1.12.2.2  skrll 		    PDC262_ATAPI(channel), atapi);
    578  1.12.2.2  skrll 	}
    579  1.12.2.2  skrll 
    580  1.12.2.2  skrll 	pciide_dma_start(v, channel, drive);
    581  1.12.2.2  skrll }
    582  1.12.2.2  skrll 
    583  1.12.2.2  skrll static int
    584  1.12.2.2  skrll pdc20262_dma_finish(void *v, int channel, int drive, int force)
    585  1.12.2.2  skrll {
    586  1.12.2.2  skrll 	struct pciide_softc *sc = v;
    587  1.12.2.2  skrll 	struct pciide_dma_maps *dma_maps =
    588  1.12.2.2  skrll 	    &sc->pciide_channels[channel].dma_maps[drive];
    589  1.12.2.3  skrll 	struct ata_channel *chp;
    590  1.12.2.2  skrll 	int atapi, error;
    591  1.12.2.2  skrll 
    592  1.12.2.2  skrll 	error = pciide_dma_finish(v, channel, drive, force);
    593  1.12.2.2  skrll 
    594  1.12.2.2  skrll 	if (dma_maps->dma_flags & WDC_DMA_LBA48) {
    595  1.12.2.2  skrll 		chp = sc->wdc_chanarray[channel];
    596  1.12.2.2  skrll 		atapi = 0;
    597  1.12.2.2  skrll 		if (chp->ch_drive[0].drive_flags & DRIVE_ATAPI ||
    598  1.12.2.2  skrll 		    chp->ch_drive[1].drive_flags & DRIVE_ATAPI) {
    599  1.12.2.2  skrll 			if ((!(chp->ch_drive[0].drive_flags & DRIVE_UDMA) ||
    600  1.12.2.2  skrll 			    (chp->ch_drive[1].drive_flags & DRIVE_UDMA) ||
    601  1.12.2.2  skrll 			    !(chp->ch_drive[1].drive_flags & DRIVE_DMA)) &&
    602  1.12.2.2  skrll 			    (!(chp->ch_drive[1].drive_flags & DRIVE_UDMA) ||
    603  1.12.2.2  skrll 			    (chp->ch_drive[0].drive_flags & DRIVE_UDMA) ||
    604  1.12.2.2  skrll 			    !(chp->ch_drive[0].drive_flags & DRIVE_DMA)))
    605  1.12.2.2  skrll 				atapi = PDC262_ATAPI_UDMA;
    606  1.12.2.2  skrll 		}
    607  1.12.2.2  skrll 		bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    608  1.12.2.2  skrll 		    PDC262_ATAPI(channel), atapi);
    609  1.12.2.2  skrll 	}
    610  1.12.2.2  skrll 
    611  1.12.2.2  skrll 	return error;
    612  1.12.2.2  skrll }
    613