Home | History | Annotate | Line # | Download | only in pci
cmdide.c revision 1.4
      1  1.4   simonb /*	$NetBSD: cmdide.c,v 1.4 2003/10/30 01:58:17 simonb 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 #include <sys/malloc.h>
     35  1.1   bouyer 
     36  1.1   bouyer #include <dev/pci/pcivar.h>
     37  1.1   bouyer #include <dev/pci/pcidevs.h>
     38  1.1   bouyer #include <dev/pci/pciidereg.h>
     39  1.1   bouyer #include <dev/pci/pciidevar.h>
     40  1.1   bouyer #include <dev/pci/pciide_cmd_reg.h>
     41  1.1   bouyer #include <dev/pci/pciide_sii3112_reg.h>
     42  1.1   bouyer 
     43  1.1   bouyer 
     44  1.2  thorpej static int  cmdide_match(struct device *, struct cfdata *, void *);
     45  1.2  thorpej static void cmdide_attach(struct device *, struct device *, void *);
     46  1.1   bouyer 
     47  1.1   bouyer CFATTACH_DECL(cmdide, sizeof(struct pciide_softc),
     48  1.1   bouyer     cmdide_match, cmdide_attach, NULL, NULL);
     49  1.1   bouyer 
     50  1.2  thorpej static void cmd_chip_map(struct pciide_softc*, struct pci_attach_args*);
     51  1.2  thorpej static void cmd0643_9_chip_map(struct pciide_softc*, struct pci_attach_args*);
     52  1.2  thorpej static void cmd0643_9_setup_channel(struct channel_softc*);
     53  1.2  thorpej static void cmd_channel_map(struct pci_attach_args *, struct pciide_softc *,
     54  1.2  thorpej 			    int);
     55  1.2  thorpej static int  cmd_pci_intr(void *);
     56  1.2  thorpej static void cmd646_9_irqack(struct channel_softc *);
     57  1.2  thorpej static void cmd680_chip_map(struct pciide_softc*, struct pci_attach_args*);
     58  1.2  thorpej static void cmd680_setup_channel(struct channel_softc*);
     59  1.2  thorpej static void cmd680_channel_map(struct pci_attach_args *, struct pciide_softc *,
     60  1.2  thorpej 			       int);
     61  1.1   bouyer 
     62  1.2  thorpej static void cmd3112_chip_map(struct pciide_softc*, struct pci_attach_args*);
     63  1.2  thorpej static void cmd3112_setup_channel(struct channel_softc*);
     64  1.1   bouyer 
     65  1.2  thorpej static const struct pciide_product_desc pciide_cmd_products[] =  {
     66  1.1   bouyer 	{ PCI_PRODUCT_CMDTECH_640,
     67  1.1   bouyer 	  0,
     68  1.1   bouyer 	  "CMD Technology PCI0640",
     69  1.1   bouyer 	  cmd_chip_map
     70  1.1   bouyer 	},
     71  1.1   bouyer 	{ PCI_PRODUCT_CMDTECH_643,
     72  1.1   bouyer 	  0,
     73  1.1   bouyer 	  "CMD Technology PCI0643",
     74  1.1   bouyer 	  cmd0643_9_chip_map,
     75  1.1   bouyer 	},
     76  1.1   bouyer 	{ PCI_PRODUCT_CMDTECH_646,
     77  1.1   bouyer 	  0,
     78  1.1   bouyer 	  "CMD Technology PCI0646",
     79  1.1   bouyer 	  cmd0643_9_chip_map,
     80  1.1   bouyer 	},
     81  1.1   bouyer 	{ PCI_PRODUCT_CMDTECH_648,
     82  1.3  mycroft 	  0,
     83  1.1   bouyer 	  "CMD Technology PCI0648",
     84  1.1   bouyer 	  cmd0643_9_chip_map,
     85  1.1   bouyer 	},
     86  1.1   bouyer 	{ PCI_PRODUCT_CMDTECH_649,
     87  1.3  mycroft 	  0,
     88  1.1   bouyer 	  "CMD Technology PCI0649",
     89  1.1   bouyer 	  cmd0643_9_chip_map,
     90  1.1   bouyer 	},
     91  1.1   bouyer 	{ PCI_PRODUCT_CMDTECH_680,
     92  1.3  mycroft 	  0,
     93  1.1   bouyer 	  "Silicon Image 0680",
     94  1.1   bouyer 	  cmd680_chip_map,
     95  1.1   bouyer 	},
     96  1.1   bouyer 	{ PCI_PRODUCT_CMDTECH_3112,
     97  1.3  mycroft 	  0,
     98  1.1   bouyer 	  "Silicon Image SATALink 3112",
     99  1.1   bouyer 	  cmd3112_chip_map,
    100  1.1   bouyer 	},
    101  1.1   bouyer 	{ 0,
    102  1.1   bouyer 	  0,
    103  1.1   bouyer 	  NULL,
    104  1.1   bouyer 	  NULL
    105  1.1   bouyer 	}
    106  1.1   bouyer };
    107  1.1   bouyer 
    108  1.2  thorpej static int
    109  1.2  thorpej cmdide_match(struct device *parent, struct cfdata *match, void *aux)
    110  1.1   bouyer {
    111  1.1   bouyer 	struct pci_attach_args *pa = aux;
    112  1.1   bouyer 
    113  1.1   bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CMDTECH) {
    114  1.1   bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_cmd_products))
    115  1.1   bouyer 			return (2);
    116  1.1   bouyer 	}
    117  1.1   bouyer 	return (0);
    118  1.1   bouyer }
    119  1.1   bouyer 
    120  1.2  thorpej static void
    121  1.2  thorpej cmdide_attach(struct device *parent, struct device *self, void *aux)
    122  1.1   bouyer {
    123  1.1   bouyer 	struct pci_attach_args *pa = aux;
    124  1.1   bouyer 	struct pciide_softc *sc = (struct pciide_softc *)self;
    125  1.1   bouyer 
    126  1.1   bouyer 	pciide_common_attach(sc, pa,
    127  1.1   bouyer 	    pciide_lookup_product(pa->pa_id, pciide_cmd_products));
    128  1.1   bouyer 
    129  1.1   bouyer }
    130  1.1   bouyer 
    131  1.2  thorpej static void
    132  1.2  thorpej cmd_channel_map(struct pci_attach_args *pa, struct pciide_softc *sc,
    133  1.2  thorpej     int channel)
    134  1.1   bouyer {
    135  1.1   bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    136  1.1   bouyer 	bus_size_t cmdsize, ctlsize;
    137  1.1   bouyer 	u_int8_t ctrl = pciide_pci_read(sc->sc_pc, sc->sc_tag, CMD_CTRL);
    138  1.1   bouyer 	int interface, one_channel;
    139  1.1   bouyer 
    140  1.1   bouyer 	/*
    141  1.1   bouyer 	 * The 0648/0649 can be told to identify as a RAID controller.
    142  1.1   bouyer 	 * In this case, we have to fake interface
    143  1.1   bouyer 	 */
    144  1.1   bouyer 	if (PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_MASS_STORAGE_IDE) {
    145  1.1   bouyer 		interface = PCIIDE_INTERFACE_SETTABLE(0) |
    146  1.1   bouyer 		    PCIIDE_INTERFACE_SETTABLE(1);
    147  1.1   bouyer 		if (pciide_pci_read(pa->pa_pc, pa->pa_tag, CMD_CONF) &
    148  1.1   bouyer 		    CMD_CONF_DSA1)
    149  1.1   bouyer 			interface |= PCIIDE_INTERFACE_PCI(0) |
    150  1.1   bouyer 			    PCIIDE_INTERFACE_PCI(1);
    151  1.1   bouyer 	} else {
    152  1.1   bouyer 		interface = PCI_INTERFACE(pa->pa_class);
    153  1.1   bouyer 	}
    154  1.1   bouyer 
    155  1.1   bouyer 	sc->wdc_chanarray[channel] = &cp->wdc_channel;
    156  1.1   bouyer 	cp->name = PCIIDE_CHANNEL_NAME(channel);
    157  1.1   bouyer 	cp->wdc_channel.channel = channel;
    158  1.1   bouyer 	cp->wdc_channel.wdc = &sc->sc_wdcdev;
    159  1.1   bouyer 
    160  1.1   bouyer 	/*
    161  1.1   bouyer 	 * Older CMD64X doesn't have independant channels
    162  1.1   bouyer 	 */
    163  1.1   bouyer 	switch (sc->sc_pp->ide_product) {
    164  1.1   bouyer 	case PCI_PRODUCT_CMDTECH_649:
    165  1.1   bouyer 		one_channel = 0;
    166  1.1   bouyer 		break;
    167  1.1   bouyer 	default:
    168  1.1   bouyer 		one_channel = 1;
    169  1.1   bouyer 		break;
    170  1.1   bouyer 	}
    171  1.1   bouyer 
    172  1.1   bouyer 	if (channel > 0 && one_channel) {
    173  1.1   bouyer 		cp->wdc_channel.ch_queue =
    174  1.1   bouyer 		    sc->pciide_channels[0].wdc_channel.ch_queue;
    175  1.1   bouyer 	} else {
    176  1.1   bouyer 		cp->wdc_channel.ch_queue =
    177  1.1   bouyer 		    malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
    178  1.1   bouyer 	}
    179  1.1   bouyer 	if (cp->wdc_channel.ch_queue == NULL) {
    180  1.1   bouyer 		aprint_error("%s %s channel: "
    181  1.1   bouyer 		    "can't allocate memory for command queue",
    182  1.1   bouyer 		    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
    183  1.1   bouyer 		    return;
    184  1.1   bouyer 	}
    185  1.1   bouyer 
    186  1.1   bouyer 	aprint_normal("%s: %s channel %s to %s mode\n",
    187  1.1   bouyer 	    sc->sc_wdcdev.sc_dev.dv_xname, cp->name,
    188  1.1   bouyer 	    (interface & PCIIDE_INTERFACE_SETTABLE(channel)) ?
    189  1.1   bouyer 	    "configured" : "wired",
    190  1.1   bouyer 	    (interface & PCIIDE_INTERFACE_PCI(channel)) ?
    191  1.1   bouyer 	    "native-PCI" : "compatibility");
    192  1.1   bouyer 
    193  1.1   bouyer 	/*
    194  1.1   bouyer 	 * with a CMD PCI64x, if we get here, the first channel is enabled:
    195  1.1   bouyer 	 * there's no way to disable the first channel without disabling
    196  1.1   bouyer 	 * the whole device
    197  1.1   bouyer 	 */
    198  1.1   bouyer 	if (channel != 0 && (ctrl & CMD_CTRL_2PORT) == 0) {
    199  1.1   bouyer 		aprint_normal("%s: %s channel ignored (disabled)\n",
    200  1.1   bouyer 		    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
    201  1.1   bouyer 		cp->wdc_channel.ch_flags |= WDCF_DISABLED;
    202  1.1   bouyer 		return;
    203  1.1   bouyer 	}
    204  1.1   bouyer 
    205  1.1   bouyer 	pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize, cmd_pci_intr);
    206  1.1   bouyer }
    207  1.1   bouyer 
    208  1.2  thorpej static int
    209  1.2  thorpej cmd_pci_intr(void *arg)
    210  1.1   bouyer {
    211  1.1   bouyer 	struct pciide_softc *sc = arg;
    212  1.1   bouyer 	struct pciide_channel *cp;
    213  1.1   bouyer 	struct channel_softc *wdc_cp;
    214  1.1   bouyer 	int i, rv, crv;
    215  1.1   bouyer 	u_int32_t priirq, secirq;
    216  1.1   bouyer 
    217  1.1   bouyer 	rv = 0;
    218  1.1   bouyer 	priirq = pciide_pci_read(sc->sc_pc, sc->sc_tag, CMD_CONF);
    219  1.1   bouyer 	secirq = pciide_pci_read(sc->sc_pc, sc->sc_tag, CMD_ARTTIM23);
    220  1.1   bouyer 	for (i = 0; i < sc->sc_wdcdev.nchannels; i++) {
    221  1.1   bouyer 		cp = &sc->pciide_channels[i];
    222  1.1   bouyer 		wdc_cp = &cp->wdc_channel;
    223  1.1   bouyer 		/* If a compat channel skip. */
    224  1.1   bouyer 		if (cp->compat)
    225  1.1   bouyer 			continue;
    226  1.1   bouyer 		if ((i == 0 && (priirq & CMD_CONF_DRV0_INTR)) ||
    227  1.1   bouyer 		    (i == 1 && (secirq & CMD_ARTTIM23_IRQ))) {
    228  1.1   bouyer 			crv = wdcintr(wdc_cp);
    229  1.1   bouyer 			if (crv == 0)
    230  1.1   bouyer 				printf("%s:%d: bogus intr\n",
    231  1.1   bouyer 				    sc->sc_wdcdev.sc_dev.dv_xname, i);
    232  1.1   bouyer 			else
    233  1.1   bouyer 				rv = 1;
    234  1.1   bouyer 		}
    235  1.1   bouyer 	}
    236  1.1   bouyer 	return rv;
    237  1.1   bouyer }
    238  1.1   bouyer 
    239  1.2  thorpej static void
    240  1.2  thorpej cmd_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    241  1.1   bouyer {
    242  1.1   bouyer 	int channel;
    243  1.1   bouyer 
    244  1.1   bouyer 	/*
    245  1.1   bouyer 	 * For a CMD PCI064x, the use of PCI_COMMAND_IO_ENABLE
    246  1.1   bouyer 	 * and base adresses registers can be disabled at
    247  1.1   bouyer 	 * hardware level. In this case, the device is wired
    248  1.1   bouyer 	 * in compat mode and its first channel is always enabled,
    249  1.1   bouyer 	 * but we can't rely on PCI_COMMAND_IO_ENABLE.
    250  1.1   bouyer 	 * In fact, it seems that the first channel of the CMD PCI0640
    251  1.1   bouyer 	 * can't be disabled.
    252  1.1   bouyer 	 */
    253  1.1   bouyer 
    254  1.1   bouyer #ifdef PCIIDE_CMD064x_DISABLE
    255  1.1   bouyer 	if (pciide_chipen(sc, pa) == 0)
    256  1.1   bouyer 		return;
    257  1.1   bouyer #endif
    258  1.1   bouyer 
    259  1.1   bouyer 	aprint_normal("%s: hardware does not support DMA\n",
    260  1.1   bouyer 	    sc->sc_wdcdev.sc_dev.dv_xname);
    261  1.1   bouyer 	sc->sc_dma_ok = 0;
    262  1.1   bouyer 
    263  1.1   bouyer 	sc->sc_wdcdev.channels = sc->wdc_chanarray;
    264  1.1   bouyer 	sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
    265  1.1   bouyer 	sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA16;
    266  1.1   bouyer 
    267  1.1   bouyer 	for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
    268  1.1   bouyer 		cmd_channel_map(pa, sc, channel);
    269  1.1   bouyer 	}
    270  1.1   bouyer }
    271  1.1   bouyer 
    272  1.2  thorpej static void
    273  1.2  thorpej cmd0643_9_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    274  1.1   bouyer {
    275  1.1   bouyer 	int channel;
    276  1.1   bouyer 	pcireg_t rev = PCI_REVISION(pa->pa_class);
    277  1.1   bouyer 
    278  1.1   bouyer 	/*
    279  1.1   bouyer 	 * For a CMD PCI064x, the use of PCI_COMMAND_IO_ENABLE
    280  1.1   bouyer 	 * and base adresses registers can be disabled at
    281  1.1   bouyer 	 * hardware level. In this case, the device is wired
    282  1.1   bouyer 	 * in compat mode and its first channel is always enabled,
    283  1.1   bouyer 	 * but we can't rely on PCI_COMMAND_IO_ENABLE.
    284  1.1   bouyer 	 * In fact, it seems that the first channel of the CMD PCI0640
    285  1.1   bouyer 	 * can't be disabled.
    286  1.1   bouyer 	 */
    287  1.1   bouyer 
    288  1.1   bouyer #ifdef PCIIDE_CMD064x_DISABLE
    289  1.1   bouyer 	if (pciide_chipen(sc, pa) == 0)
    290  1.1   bouyer 		return;
    291  1.1   bouyer #endif
    292  1.1   bouyer 
    293  1.1   bouyer 	aprint_normal("%s: bus-master DMA support present",
    294  1.1   bouyer 	    sc->sc_wdcdev.sc_dev.dv_xname);
    295  1.1   bouyer 	pciide_mapreg_dma(sc, pa);
    296  1.1   bouyer 	aprint_normal("\n");
    297  1.1   bouyer 	sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32 |
    298  1.1   bouyer 	    WDC_CAPABILITY_MODE;
    299  1.1   bouyer 	if (sc->sc_dma_ok) {
    300  1.1   bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_IRQACK;
    301  1.1   bouyer 		switch (sc->sc_pp->ide_product) {
    302  1.1   bouyer 		case PCI_PRODUCT_CMDTECH_649:
    303  1.1   bouyer 			sc->sc_wdcdev.cap |= WDC_CAPABILITY_UDMA;
    304  1.1   bouyer 			sc->sc_wdcdev.UDMA_cap = 5;
    305  1.1   bouyer 			sc->sc_wdcdev.irqack = cmd646_9_irqack;
    306  1.1   bouyer 			break;
    307  1.1   bouyer 		case PCI_PRODUCT_CMDTECH_648:
    308  1.1   bouyer 			sc->sc_wdcdev.cap |= WDC_CAPABILITY_UDMA;
    309  1.1   bouyer 			sc->sc_wdcdev.UDMA_cap = 4;
    310  1.1   bouyer 			sc->sc_wdcdev.irqack = cmd646_9_irqack;
    311  1.1   bouyer 			break;
    312  1.1   bouyer 		case PCI_PRODUCT_CMDTECH_646:
    313  1.1   bouyer 			if (rev >= CMD0646U2_REV) {
    314  1.1   bouyer 				sc->sc_wdcdev.cap |= WDC_CAPABILITY_UDMA;
    315  1.1   bouyer 				sc->sc_wdcdev.UDMA_cap = 2;
    316  1.1   bouyer 			} else if (rev >= CMD0646U_REV) {
    317  1.1   bouyer 			/*
    318  1.1   bouyer 			 * Linux's driver claims that the 646U is broken
    319  1.1   bouyer 			 * with UDMA. Only enable it if we know what we're
    320  1.1   bouyer 			 * doing
    321  1.1   bouyer 			 */
    322  1.1   bouyer #ifdef PCIIDE_CMD0646U_ENABLEUDMA
    323  1.1   bouyer 				sc->sc_wdcdev.cap |= WDC_CAPABILITY_UDMA;
    324  1.1   bouyer 				sc->sc_wdcdev.UDMA_cap = 2;
    325  1.1   bouyer #endif
    326  1.1   bouyer 				/* explicitly disable UDMA */
    327  1.1   bouyer 				pciide_pci_write(sc->sc_pc, sc->sc_tag,
    328  1.1   bouyer 				    CMD_UDMATIM(0), 0);
    329  1.1   bouyer 				pciide_pci_write(sc->sc_pc, sc->sc_tag,
    330  1.1   bouyer 				    CMD_UDMATIM(1), 0);
    331  1.1   bouyer 			}
    332  1.1   bouyer 			sc->sc_wdcdev.irqack = cmd646_9_irqack;
    333  1.1   bouyer 			break;
    334  1.1   bouyer 		default:
    335  1.1   bouyer 			sc->sc_wdcdev.irqack = pciide_irqack;
    336  1.1   bouyer 		}
    337  1.1   bouyer 	}
    338  1.1   bouyer 
    339  1.1   bouyer 	sc->sc_wdcdev.channels = sc->wdc_chanarray;
    340  1.1   bouyer 	sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
    341  1.1   bouyer 	sc->sc_wdcdev.PIO_cap = 4;
    342  1.1   bouyer 	sc->sc_wdcdev.DMA_cap = 2;
    343  1.1   bouyer 	sc->sc_wdcdev.set_modes = cmd0643_9_setup_channel;
    344  1.1   bouyer 
    345  1.1   bouyer 	WDCDEBUG_PRINT(("cmd0643_9_chip_map: old timings reg 0x%x 0x%x\n",
    346  1.1   bouyer 		pci_conf_read(sc->sc_pc, sc->sc_tag, 0x54),
    347  1.1   bouyer 		pci_conf_read(sc->sc_pc, sc->sc_tag, 0x58)),
    348  1.1   bouyer 		DEBUG_PROBE);
    349  1.1   bouyer 
    350  1.4   simonb 	for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++)
    351  1.1   bouyer 		cmd_channel_map(pa, sc, channel);
    352  1.4   simonb 
    353  1.1   bouyer 	/*
    354  1.1   bouyer 	 * note - this also makes sure we clear the irq disable and reset
    355  1.1   bouyer 	 * bits
    356  1.1   bouyer 	 */
    357  1.1   bouyer 	pciide_pci_write(sc->sc_pc, sc->sc_tag, CMD_DMA_MODE, CMD_DMA_MULTIPLE);
    358  1.1   bouyer 	WDCDEBUG_PRINT(("cmd0643_9_chip_map: timings reg now 0x%x 0x%x\n",
    359  1.1   bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, 0x54),
    360  1.1   bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, 0x58)),
    361  1.1   bouyer 	    DEBUG_PROBE);
    362  1.1   bouyer }
    363  1.1   bouyer 
    364  1.2  thorpej static void
    365  1.2  thorpej cmd0643_9_setup_channel(struct channel_softc *chp)
    366  1.1   bouyer {
    367  1.1   bouyer 	struct ata_drive_datas *drvp;
    368  1.1   bouyer 	u_int8_t tim;
    369  1.1   bouyer 	u_int32_t idedma_ctl, udma_reg;
    370  1.1   bouyer 	int drive;
    371  1.1   bouyer 	struct pciide_channel *cp = (struct pciide_channel*)chp;
    372  1.1   bouyer 	struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;
    373  1.1   bouyer 
    374  1.1   bouyer 	idedma_ctl = 0;
    375  1.1   bouyer 	/* setup DMA if needed */
    376  1.1   bouyer 	pciide_channel_dma_setup(cp);
    377  1.1   bouyer 
    378  1.1   bouyer 	for (drive = 0; drive < 2; drive++) {
    379  1.1   bouyer 		drvp = &chp->ch_drive[drive];
    380  1.1   bouyer 		/* If no drive, skip */
    381  1.1   bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    382  1.1   bouyer 			continue;
    383  1.1   bouyer 		/* add timing values, setup DMA if needed */
    384  1.1   bouyer 		tim = cmd0643_9_data_tim_pio[drvp->PIO_mode];
    385  1.1   bouyer 		if (drvp->drive_flags & (DRIVE_DMA | DRIVE_UDMA)) {
    386  1.1   bouyer 			if (drvp->drive_flags & DRIVE_UDMA) {
    387  1.1   bouyer 				/* UltraDMA on a 646U2, 0648 or 0649 */
    388  1.1   bouyer 				drvp->drive_flags &= ~DRIVE_DMA;
    389  1.1   bouyer 				udma_reg = pciide_pci_read(sc->sc_pc,
    390  1.1   bouyer 				    sc->sc_tag, CMD_UDMATIM(chp->channel));
    391  1.1   bouyer 				if (drvp->UDMA_mode > 2 &&
    392  1.1   bouyer 				    (pciide_pci_read(sc->sc_pc, sc->sc_tag,
    393  1.1   bouyer 				    CMD_BICSR) &
    394  1.1   bouyer 				    CMD_BICSR_80(chp->channel)) == 0)
    395  1.1   bouyer 					drvp->UDMA_mode = 2;
    396  1.1   bouyer 				if (drvp->UDMA_mode > 2)
    397  1.1   bouyer 					udma_reg &= ~CMD_UDMATIM_UDMA33(drive);
    398  1.1   bouyer 				else if (sc->sc_wdcdev.UDMA_cap > 2)
    399  1.1   bouyer 					udma_reg |= CMD_UDMATIM_UDMA33(drive);
    400  1.1   bouyer 				udma_reg |= CMD_UDMATIM_UDMA(drive);
    401  1.1   bouyer 				udma_reg &= ~(CMD_UDMATIM_TIM_MASK <<
    402  1.1   bouyer 				    CMD_UDMATIM_TIM_OFF(drive));
    403  1.1   bouyer 				udma_reg |=
    404  1.1   bouyer 				    (cmd0646_9_tim_udma[drvp->UDMA_mode] <<
    405  1.1   bouyer 				    CMD_UDMATIM_TIM_OFF(drive));
    406  1.1   bouyer 				pciide_pci_write(sc->sc_pc, sc->sc_tag,
    407  1.1   bouyer 				    CMD_UDMATIM(chp->channel), udma_reg);
    408  1.1   bouyer 			} else {
    409  1.1   bouyer 				/*
    410  1.1   bouyer 				 * use Multiword DMA.
    411  1.1   bouyer 				 * Timings will be used for both PIO and DMA,
    412  1.1   bouyer 				 * so adjust DMA mode if needed
    413  1.1   bouyer 				 * if we have a 0646U2/8/9, turn off UDMA
    414  1.1   bouyer 				 */
    415  1.1   bouyer 				if (sc->sc_wdcdev.cap & WDC_CAPABILITY_UDMA) {
    416  1.1   bouyer 					udma_reg = pciide_pci_read(sc->sc_pc,
    417  1.1   bouyer 					    sc->sc_tag,
    418  1.1   bouyer 					    CMD_UDMATIM(chp->channel));
    419  1.1   bouyer 					udma_reg &= ~CMD_UDMATIM_UDMA(drive);
    420  1.1   bouyer 					pciide_pci_write(sc->sc_pc, sc->sc_tag,
    421  1.1   bouyer 					    CMD_UDMATIM(chp->channel),
    422  1.1   bouyer 					    udma_reg);
    423  1.1   bouyer 				}
    424  1.1   bouyer 				if (drvp->PIO_mode >= 3 &&
    425  1.1   bouyer 				    (drvp->DMA_mode + 2) > drvp->PIO_mode) {
    426  1.1   bouyer 					drvp->DMA_mode = drvp->PIO_mode - 2;
    427  1.1   bouyer 				}
    428  1.1   bouyer 				tim = cmd0643_9_data_tim_dma[drvp->DMA_mode];
    429  1.1   bouyer 			}
    430  1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    431  1.1   bouyer 		}
    432  1.1   bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag,
    433  1.1   bouyer 		    CMD_DATA_TIM(chp->channel, drive), tim);
    434  1.1   bouyer 	}
    435  1.1   bouyer 	if (idedma_ctl != 0) {
    436  1.1   bouyer 		/* Add software bits in status register */
    437  1.1   bouyer 		bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh,
    438  1.1   bouyer 		    IDEDMA_CTL + (IDEDMA_SCH_OFFSET * chp->channel),
    439  1.1   bouyer 		    idedma_ctl);
    440  1.1   bouyer 	}
    441  1.1   bouyer }
    442  1.1   bouyer 
    443  1.2  thorpej static void
    444  1.2  thorpej cmd646_9_irqack(struct channel_softc *chp)
    445  1.1   bouyer {
    446  1.1   bouyer 	u_int32_t priirq, secirq;
    447  1.1   bouyer 	struct pciide_channel *cp = (struct pciide_channel*)chp;
    448  1.1   bouyer 	struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;
    449  1.1   bouyer 
    450  1.1   bouyer 	if (chp->channel == 0) {
    451  1.1   bouyer 		priirq = pciide_pci_read(sc->sc_pc, sc->sc_tag, CMD_CONF);
    452  1.1   bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, CMD_CONF, priirq);
    453  1.1   bouyer 	} else {
    454  1.1   bouyer 		secirq = pciide_pci_read(sc->sc_pc, sc->sc_tag, CMD_ARTTIM23);
    455  1.1   bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, CMD_ARTTIM23, secirq);
    456  1.1   bouyer 	}
    457  1.1   bouyer 	pciide_irqack(chp);
    458  1.1   bouyer }
    459  1.1   bouyer 
    460  1.2  thorpej static void
    461  1.2  thorpej cmd680_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    462  1.1   bouyer {
    463  1.1   bouyer 	int channel;
    464  1.1   bouyer 
    465  1.1   bouyer 	if (pciide_chipen(sc, pa) == 0)
    466  1.1   bouyer 		return;
    467  1.1   bouyer 
    468  1.1   bouyer 	aprint_normal("%s: bus-master DMA support present",
    469  1.1   bouyer 	    sc->sc_wdcdev.sc_dev.dv_xname);
    470  1.1   bouyer 	pciide_mapreg_dma(sc, pa);
    471  1.1   bouyer 	aprint_normal("\n");
    472  1.1   bouyer 	sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32 |
    473  1.1   bouyer 	    WDC_CAPABILITY_MODE;
    474  1.1   bouyer 	if (sc->sc_dma_ok) {
    475  1.1   bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_IRQACK;
    476  1.1   bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_UDMA;
    477  1.1   bouyer 		sc->sc_wdcdev.UDMA_cap = 6;
    478  1.1   bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    479  1.1   bouyer 	}
    480  1.1   bouyer 
    481  1.1   bouyer 	sc->sc_wdcdev.channels = sc->wdc_chanarray;
    482  1.1   bouyer 	sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
    483  1.1   bouyer 	sc->sc_wdcdev.PIO_cap = 4;
    484  1.1   bouyer 	sc->sc_wdcdev.DMA_cap = 2;
    485  1.1   bouyer 	sc->sc_wdcdev.set_modes = cmd680_setup_channel;
    486  1.1   bouyer 
    487  1.1   bouyer 	pciide_pci_write(sc->sc_pc, sc->sc_tag, 0x80, 0x00);
    488  1.1   bouyer 	pciide_pci_write(sc->sc_pc, sc->sc_tag, 0x84, 0x00);
    489  1.1   bouyer 	pciide_pci_write(sc->sc_pc, sc->sc_tag, 0x8a,
    490  1.1   bouyer 	    pciide_pci_read(sc->sc_pc, sc->sc_tag, 0x8a) | 0x01);
    491  1.4   simonb 	for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++)
    492  1.1   bouyer 		cmd680_channel_map(pa, sc, channel);
    493  1.1   bouyer }
    494  1.1   bouyer 
    495  1.2  thorpej static void
    496  1.2  thorpej cmd680_channel_map(struct pci_attach_args *pa, struct pciide_softc *sc,
    497  1.2  thorpej     int channel)
    498  1.1   bouyer {
    499  1.1   bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    500  1.1   bouyer 	bus_size_t cmdsize, ctlsize;
    501  1.1   bouyer 	int interface, i, reg;
    502  1.1   bouyer 	static const u_int8_t init_val[] =
    503  1.1   bouyer 	    {             0x8a, 0x32, 0x8a, 0x32, 0x8a, 0x32,
    504  1.1   bouyer 	      0x92, 0x43, 0x92, 0x43, 0x09, 0x40, 0x09, 0x40 };
    505  1.1   bouyer 
    506  1.1   bouyer 	if (PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_MASS_STORAGE_IDE) {
    507  1.1   bouyer 		interface = PCIIDE_INTERFACE_SETTABLE(0) |
    508  1.1   bouyer 		    PCIIDE_INTERFACE_SETTABLE(1);
    509  1.1   bouyer 		interface |= PCIIDE_INTERFACE_PCI(0) |
    510  1.1   bouyer 		    PCIIDE_INTERFACE_PCI(1);
    511  1.1   bouyer 	} else {
    512  1.1   bouyer 		interface = PCI_INTERFACE(pa->pa_class);
    513  1.1   bouyer 	}
    514  1.1   bouyer 
    515  1.1   bouyer 	sc->wdc_chanarray[channel] = &cp->wdc_channel;
    516  1.1   bouyer 	cp->name = PCIIDE_CHANNEL_NAME(channel);
    517  1.1   bouyer 	cp->wdc_channel.channel = channel;
    518  1.1   bouyer 	cp->wdc_channel.wdc = &sc->sc_wdcdev;
    519  1.1   bouyer 
    520  1.1   bouyer 	cp->wdc_channel.ch_queue =
    521  1.1   bouyer 	    malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
    522  1.1   bouyer 	if (cp->wdc_channel.ch_queue == NULL) {
    523  1.1   bouyer 		aprint_error("%s %s channel: "
    524  1.1   bouyer 		    "can't allocate memory for command queue",
    525  1.1   bouyer 		    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
    526  1.1   bouyer 		    return;
    527  1.1   bouyer 	}
    528  1.1   bouyer 
    529  1.1   bouyer 	/* XXX */
    530  1.1   bouyer 	reg = 0xa2 + channel * 16;
    531  1.1   bouyer 	for (i = 0; i < sizeof(init_val); i++)
    532  1.1   bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, reg + i, init_val[i]);
    533  1.1   bouyer 
    534  1.1   bouyer 	aprint_normal("%s: %s channel %s to %s mode\n",
    535  1.1   bouyer 	    sc->sc_wdcdev.sc_dev.dv_xname, cp->name,
    536  1.1   bouyer 	    (interface & PCIIDE_INTERFACE_SETTABLE(channel)) ?
    537  1.1   bouyer 	    "configured" : "wired",
    538  1.1   bouyer 	    (interface & PCIIDE_INTERFACE_PCI(channel)) ?
    539  1.1   bouyer 	    "native-PCI" : "compatibility");
    540  1.1   bouyer 
    541  1.1   bouyer 	pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize, pciide_pci_intr);
    542  1.1   bouyer }
    543  1.1   bouyer 
    544  1.2  thorpej static void
    545  1.2  thorpej cmd680_setup_channel(struct channel_softc *chp)
    546  1.1   bouyer {
    547  1.1   bouyer 	struct ata_drive_datas *drvp;
    548  1.1   bouyer 	u_int8_t mode, off, scsc;
    549  1.1   bouyer 	u_int16_t val;
    550  1.1   bouyer 	u_int32_t idedma_ctl;
    551  1.1   bouyer 	int drive;
    552  1.1   bouyer 	struct pciide_channel *cp = (struct pciide_channel*)chp;
    553  1.1   bouyer 	struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;
    554  1.1   bouyer 	pci_chipset_tag_t pc = sc->sc_pc;
    555  1.1   bouyer 	pcitag_t pa = sc->sc_tag;
    556  1.1   bouyer 	static const u_int8_t udma2_tbl[] =
    557  1.1   bouyer 	    { 0x0f, 0x0b, 0x07, 0x06, 0x03, 0x02, 0x01 };
    558  1.1   bouyer 	static const u_int8_t udma_tbl[] =
    559  1.1   bouyer 	    { 0x0c, 0x07, 0x05, 0x04, 0x02, 0x01, 0x00 };
    560  1.1   bouyer 	static const u_int16_t dma_tbl[] =
    561  1.1   bouyer 	    { 0x2208, 0x10c2, 0x10c1 };
    562  1.1   bouyer 	static const u_int16_t pio_tbl[] =
    563  1.1   bouyer 	    { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 };
    564  1.1   bouyer 
    565  1.1   bouyer 	idedma_ctl = 0;
    566  1.1   bouyer 	pciide_channel_dma_setup(cp);
    567  1.1   bouyer 	mode = pciide_pci_read(pc, pa, 0x80 + chp->channel * 4);
    568  1.1   bouyer 
    569  1.1   bouyer 	for (drive = 0; drive < 2; drive++) {
    570  1.1   bouyer 		drvp = &chp->ch_drive[drive];
    571  1.1   bouyer 		/* If no drive, skip */
    572  1.1   bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    573  1.1   bouyer 			continue;
    574  1.1   bouyer 		mode &= ~(0x03 << (drive * 4));
    575  1.1   bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    576  1.1   bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    577  1.1   bouyer 			off = 0xa0 + chp->channel * 16;
    578  1.1   bouyer 			if (drvp->UDMA_mode > 2 &&
    579  1.1   bouyer 			    (pciide_pci_read(pc, pa, off) & 0x01) == 0)
    580  1.1   bouyer 				drvp->UDMA_mode = 2;
    581  1.1   bouyer 			scsc = pciide_pci_read(pc, pa, 0x8a);
    582  1.1   bouyer 			if (drvp->UDMA_mode == 6 && (scsc & 0x30) == 0) {
    583  1.1   bouyer 				pciide_pci_write(pc, pa, 0x8a, scsc | 0x01);
    584  1.1   bouyer 				scsc = pciide_pci_read(pc, pa, 0x8a);
    585  1.1   bouyer 				if ((scsc & 0x30) == 0)
    586  1.1   bouyer 					drvp->UDMA_mode = 5;
    587  1.1   bouyer 			}
    588  1.1   bouyer 			mode |= 0x03 << (drive * 4);
    589  1.1   bouyer 			off = 0xac + chp->channel * 16 + drive * 2;
    590  1.1   bouyer 			val = pciide_pci_read(pc, pa, off) & ~0x3f;
    591  1.1   bouyer 			if (scsc & 0x30)
    592  1.1   bouyer 				val |= udma2_tbl[drvp->UDMA_mode];
    593  1.1   bouyer 			else
    594  1.1   bouyer 				val |= udma_tbl[drvp->UDMA_mode];
    595  1.1   bouyer 			pciide_pci_write(pc, pa, off, val);
    596  1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    597  1.1   bouyer 		} else if (drvp->drive_flags & DRIVE_DMA) {
    598  1.1   bouyer 			mode |= 0x02 << (drive * 4);
    599  1.1   bouyer 			off = 0xa8 + chp->channel * 16 + drive * 2;
    600  1.1   bouyer 			val = dma_tbl[drvp->DMA_mode];
    601  1.1   bouyer 			pciide_pci_write(pc, pa, off, val & 0xff);
    602  1.1   bouyer 			pciide_pci_write(pc, pa, off, val >> 8);
    603  1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    604  1.1   bouyer 		} else {
    605  1.1   bouyer 			mode |= 0x01 << (drive * 4);
    606  1.1   bouyer 			off = 0xa4 + chp->channel * 16 + drive * 2;
    607  1.1   bouyer 			val = pio_tbl[drvp->PIO_mode];
    608  1.1   bouyer 			pciide_pci_write(pc, pa, off, val & 0xff);
    609  1.1   bouyer 			pciide_pci_write(pc, pa, off, val >> 8);
    610  1.1   bouyer 		}
    611  1.1   bouyer 	}
    612  1.1   bouyer 
    613  1.1   bouyer 	pciide_pci_write(pc, pa, 0x80 + chp->channel * 4, mode);
    614  1.1   bouyer 	if (idedma_ctl != 0) {
    615  1.1   bouyer 		/* Add software bits in status register */
    616  1.1   bouyer 		bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh,
    617  1.1   bouyer 		    IDEDMA_CTL + (IDEDMA_SCH_OFFSET * chp->channel),
    618  1.1   bouyer 		    idedma_ctl);
    619  1.1   bouyer 	}
    620  1.1   bouyer }
    621  1.1   bouyer 
    622  1.2  thorpej static void
    623  1.2  thorpej cmd3112_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    624  1.1   bouyer {
    625  1.1   bouyer 	struct pciide_channel *cp;
    626  1.1   bouyer 	bus_size_t cmdsize, ctlsize;
    627  1.1   bouyer 	pcireg_t interface;
    628  1.1   bouyer 	int channel;
    629  1.1   bouyer 
    630  1.1   bouyer 	if (pciide_chipen(sc, pa) == 0)
    631  1.1   bouyer 		return;
    632  1.1   bouyer 
    633  1.1   bouyer 	aprint_normal("%s: bus-master DMA support present",
    634  1.1   bouyer 	    sc->sc_wdcdev.sc_dev.dv_xname);
    635  1.1   bouyer 	pciide_mapreg_dma(sc, pa);
    636  1.1   bouyer 	aprint_normal("\n");
    637  1.1   bouyer 
    638  1.1   bouyer 	/*
    639  1.1   bouyer 	 * Rev. <= 0x01 of the 3112 have a bug that can cause data
    640  1.1   bouyer 	 * corruption if DMA transfers cross an 8K boundary.  This is
    641  1.1   bouyer 	 * apparently hard to tickle, but we'll go ahead and play it
    642  1.1   bouyer 	 * safe.
    643  1.1   bouyer 	 */
    644  1.1   bouyer 	if (PCI_REVISION(pa->pa_class) <= 0x01) {
    645  1.1   bouyer 		sc->sc_dma_maxsegsz = 8192;
    646  1.1   bouyer 		sc->sc_dma_boundary = 8192;
    647  1.1   bouyer 	}
    648  1.1   bouyer 
    649  1.1   bouyer 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32 |
    650  1.1   bouyer 	    WDC_CAPABILITY_MODE;
    651  1.1   bouyer 	sc->sc_wdcdev.PIO_cap = 4;
    652  1.1   bouyer 	if (sc->sc_dma_ok) {
    653  1.1   bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_UDMA;
    654  1.1   bouyer 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_IRQACK;
    655  1.1   bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    656  1.1   bouyer 		sc->sc_wdcdev.DMA_cap = 2;
    657  1.1   bouyer 		sc->sc_wdcdev.UDMA_cap = 6;
    658  1.1   bouyer 	}
    659  1.1   bouyer 	sc->sc_wdcdev.set_modes = cmd3112_setup_channel;
    660  1.1   bouyer 
    661  1.1   bouyer 	sc->sc_wdcdev.channels = sc->wdc_chanarray;
    662  1.1   bouyer 	sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
    663  1.1   bouyer 
    664  1.1   bouyer 	/*
    665  1.1   bouyer 	 * The 3112 can be told to identify as a RAID controller.
    666  1.1   bouyer 	 * In this case, we have to fake interface
    667  1.1   bouyer 	 */
    668  1.1   bouyer 	if (PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {
    669  1.1   bouyer 		interface = PCI_INTERFACE(pa->pa_class);
    670  1.1   bouyer 	} else {
    671  1.1   bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    672  1.1   bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    673  1.1   bouyer 	}
    674  1.1   bouyer 
    675  1.1   bouyer 	for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
    676  1.1   bouyer 		cp = &sc->pciide_channels[channel];
    677  1.1   bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    678  1.1   bouyer 			continue;
    679  1.1   bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    680  1.1   bouyer 		    pciide_pci_intr);
    681  1.1   bouyer 	}
    682  1.1   bouyer }
    683  1.1   bouyer 
    684  1.2  thorpej static void
    685  1.2  thorpej cmd3112_setup_channel(struct channel_softc *chp)
    686  1.1   bouyer {
    687  1.1   bouyer 	struct ata_drive_datas *drvp;
    688  1.1   bouyer 	int drive;
    689  1.1   bouyer 	u_int32_t idedma_ctl, dtm;
    690  1.1   bouyer 	struct pciide_channel *cp = (struct pciide_channel*)chp;
    691  1.1   bouyer 	struct pciide_softc *sc = (struct pciide_softc*)cp->wdc_channel.wdc;
    692  1.1   bouyer 
    693  1.1   bouyer 	/* setup DMA if needed */
    694  1.1   bouyer 	pciide_channel_dma_setup(cp);
    695  1.1   bouyer 
    696  1.1   bouyer 	idedma_ctl = 0;
    697  1.1   bouyer 	dtm = 0;
    698  1.1   bouyer 
    699  1.1   bouyer 	for (drive = 0; drive < 2; drive++) {
    700  1.1   bouyer 		drvp = &chp->ch_drive[drive];
    701  1.1   bouyer 		/* If no drive, skip */
    702  1.1   bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    703  1.1   bouyer 			continue;
    704  1.1   bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    705  1.1   bouyer 			/* use Ultra/DMA */
    706  1.1   bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    707  1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    708  1.1   bouyer 			dtm |= DTM_IDEx_DMA;
    709  1.1   bouyer 		} else if (drvp->drive_flags & DRIVE_DMA) {
    710  1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    711  1.1   bouyer 			dtm |= DTM_IDEx_DMA;
    712  1.1   bouyer 		} else {
    713  1.1   bouyer 			dtm |= DTM_IDEx_PIO;
    714  1.1   bouyer 		}
    715  1.1   bouyer 	}
    716  1.1   bouyer 
    717  1.1   bouyer 	/*
    718  1.1   bouyer 	 * Nothing to do to setup modes; it is meaningless in S-ATA
    719  1.1   bouyer 	 * (but many S-ATA drives still want to get the SET_FEATURE
    720  1.1   bouyer 	 * command).
    721  1.1   bouyer 	 */
    722  1.1   bouyer 	if (idedma_ctl != 0) {
    723  1.1   bouyer 		/* Add software bits in status register */
    724  1.1   bouyer 		bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh,
    725  1.1   bouyer 		    IDEDMA_CTL + (IDEDMA_SCH_OFFSET * chp->channel),
    726  1.1   bouyer 		    idedma_ctl);
    727  1.1   bouyer 	}
    728  1.1   bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag,
    729  1.1   bouyer 	    chp->channel == 0 ? SII3112_DTM_IDE0 : SII3112_DTM_IDE1, dtm);
    730  1.1   bouyer }
    731