Home | History | Annotate | Line # | Download | only in pci
viaide.c revision 1.23
      1  1.23       abs /*	$NetBSD: viaide.c,v 1.23 2005/02/02 11:19:49 abs 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 
     33   1.1    bouyer #include <sys/param.h>
     34   1.1    bouyer #include <sys/systm.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_apollo_reg.h>
     41   1.1    bouyer 
     42   1.5      fvdl static int	via_pcib_match(struct pci_attach_args *);
     43   1.4     enami static void	via_chip_map(struct pciide_softc *, struct pci_attach_args *);
     44   1.4     enami static void	via_sata_chip_map(struct pciide_softc *,
     45   1.4     enami 		    struct pci_attach_args *);
     46  1.15   thorpej static void	via_setup_channel(struct ata_channel *);
     47   1.4     enami 
     48   1.4     enami static int	viaide_match(struct device *, struct cfdata *, void *);
     49   1.4     enami static void	viaide_attach(struct device *, struct device *, void *);
     50   1.4     enami static const struct pciide_product_desc *
     51   1.4     enami 		viaide_lookup(pcireg_t);
     52   1.1    bouyer 
     53   1.1    bouyer CFATTACH_DECL(viaide, sizeof(struct pciide_softc),
     54   1.1    bouyer     viaide_match, viaide_attach, NULL, NULL);
     55   1.1    bouyer 
     56   1.2   thorpej static const struct pciide_product_desc pciide_amd_products[] =  {
     57   1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC756_IDE,
     58   1.1    bouyer 	  0,
     59   1.1    bouyer 	  "Advanced Micro Devices AMD756 IDE Controller",
     60   1.1    bouyer 	  via_chip_map
     61   1.1    bouyer 	},
     62   1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC766_IDE,
     63   1.1    bouyer 	  0,
     64   1.1    bouyer 	  "Advanced Micro Devices AMD766 IDE Controller",
     65   1.1    bouyer 	  via_chip_map
     66   1.1    bouyer 	},
     67   1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC768_IDE,
     68   1.1    bouyer 	  0,
     69   1.1    bouyer 	  "Advanced Micro Devices AMD768 IDE Controller",
     70   1.1    bouyer 	  via_chip_map
     71   1.1    bouyer 	},
     72   1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC8111_IDE,
     73   1.1    bouyer 	  0,
     74   1.1    bouyer 	  "Advanced Micro Devices AMD8111 IDE Controller",
     75   1.1    bouyer 	  via_chip_map
     76   1.1    bouyer 	},
     77   1.1    bouyer 	{ 0,
     78   1.1    bouyer 	  0,
     79   1.1    bouyer 	  NULL,
     80   1.1    bouyer 	  NULL
     81   1.1    bouyer 	}
     82   1.1    bouyer };
     83   1.1    bouyer 
     84   1.2   thorpej static const struct pciide_product_desc pciide_nvidia_products[] = {
     85   1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE_ATA100,
     86   1.1    bouyer 	  0,
     87   1.1    bouyer 	  "NVIDIA nForce IDE Controller",
     88   1.1    bouyer 	  via_chip_map
     89   1.1    bouyer 	},
     90   1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE2_ATA133,
     91   1.1    bouyer 	  0,
     92   1.1    bouyer 	  "NVIDIA nForce2 IDE Controller",
     93   1.1    bouyer 	  via_chip_map
     94   1.1    bouyer 	},
     95  1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133,
     96  1.20  jdolecek 	  0,
     97  1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 IDE Controller",
     98  1.20  jdolecek 	  via_chip_map
     99  1.20  jdolecek 	},
    100  1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_SATA,
    101  1.20  jdolecek 	  0,
    102  1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 Serial ATA Controller",
    103  1.20  jdolecek 	  via_sata_chip_map
    104  1.20  jdolecek 	},
    105  1.10      fvdl 	{ PCI_PRODUCT_NVIDIA_NFORCE3_ATA133,
    106  1.10      fvdl 	  0,
    107  1.10      fvdl 	  "NVIDIA nForce3 IDE Controller",
    108  1.10      fvdl 	  via_chip_map
    109  1.10      fvdl 	},
    110  1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133,
    111  1.19   xtraeme 	  0,
    112  1.19   xtraeme 	  "NVIDIA nForce3 250 IDE Controller",
    113  1.19   xtraeme 	  via_chip_map
    114  1.19   xtraeme 	},
    115  1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA,
    116  1.19   xtraeme 	  0,
    117  1.19   xtraeme 	  "NVIDIA nForce3 250 Serial ATA Controller",
    118  1.19   xtraeme 	  via_sata_chip_map
    119  1.19   xtraeme 	},
    120  1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_ATA133,
    121  1.21      kent 	  0,
    122  1.21      kent 	  "NVIDIA nForce4 IDE Controller",
    123  1.21      kent 	  via_chip_map
    124  1.21      kent 	},
    125  1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA1,
    126  1.21      kent 	  0,
    127  1.21      kent 	  "NVIDIA nForce4 Serial ATA Controller",
    128  1.21      kent 	  via_sata_chip_map
    129  1.21      kent 	},
    130  1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA2,
    131  1.21      kent 	  0,
    132  1.21      kent 	  "NVIDIA nForce4 Serial ATA Controller",
    133  1.21      kent 	  via_sata_chip_map
    134  1.21      kent 	},
    135   1.1    bouyer 	{ 0,
    136   1.1    bouyer 	  0,
    137   1.1    bouyer 	  NULL,
    138   1.1    bouyer 	  NULL
    139   1.1    bouyer 	}
    140   1.1    bouyer };
    141   1.1    bouyer 
    142   1.2   thorpej static const struct pciide_product_desc pciide_via_products[] =  {
    143   1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586_IDE,
    144   1.1    bouyer 	  0,
    145   1.1    bouyer 	  NULL,
    146   1.1    bouyer 	  via_chip_map,
    147   1.1    bouyer 	 },
    148   1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586A_IDE,
    149   1.1    bouyer 	  0,
    150   1.1    bouyer 	  NULL,
    151   1.1    bouyer 	  via_chip_map,
    152   1.1    bouyer 	},
    153  1.23       abs 	{ PCI_PRODUCT_VIATECH_VT6421_RAID,
    154  1.22       abs 	  0,
    155  1.23       abs 	  "VIA Technologies VT6421 Serial RAID Controller",
    156  1.22       abs 	  via_sata_chip_map,
    157  1.22       abs 	},
    158   1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT8237_SATA,
    159   1.6   mycroft 	  0,
    160   1.1    bouyer 	  "VIA Technologies VT8237 SATA Controller",
    161   1.1    bouyer 	  via_sata_chip_map,
    162   1.1    bouyer 	},
    163   1.1    bouyer 	{ 0,
    164   1.1    bouyer 	  0,
    165   1.1    bouyer 	  NULL,
    166   1.1    bouyer 	  NULL
    167   1.1    bouyer 	}
    168   1.1    bouyer };
    169   1.1    bouyer 
    170   1.4     enami static const struct pciide_product_desc *
    171   1.4     enami viaide_lookup(pcireg_t id)
    172   1.4     enami {
    173   1.4     enami 
    174   1.4     enami 	switch (PCI_VENDOR(id)) {
    175   1.4     enami 	case PCI_VENDOR_VIATECH:
    176   1.4     enami 		return (pciide_lookup_product(id, pciide_via_products));
    177   1.4     enami 
    178   1.4     enami 	case PCI_VENDOR_AMD:
    179   1.4     enami 		return (pciide_lookup_product(id, pciide_amd_products));
    180   1.4     enami 
    181   1.4     enami 	case PCI_VENDOR_NVIDIA:
    182   1.4     enami 		return (pciide_lookup_product(id, pciide_nvidia_products));
    183   1.4     enami 	}
    184   1.4     enami 	return (NULL);
    185   1.4     enami }
    186   1.4     enami 
    187   1.2   thorpej static int
    188   1.2   thorpej viaide_match(struct device *parent, struct cfdata *match, void *aux)
    189   1.1    bouyer {
    190   1.1    bouyer 	struct pci_attach_args *pa = aux;
    191   1.1    bouyer 
    192   1.4     enami 	if (viaide_lookup(pa->pa_id) != NULL)
    193   1.4     enami 		return (2);
    194   1.1    bouyer 	return (0);
    195   1.1    bouyer }
    196   1.1    bouyer 
    197   1.2   thorpej static void
    198   1.2   thorpej viaide_attach(struct device *parent, struct device *self, void *aux)
    199   1.1    bouyer {
    200   1.1    bouyer 	struct pci_attach_args *pa = aux;
    201   1.1    bouyer 	struct pciide_softc *sc = (struct pciide_softc *)self;
    202   1.4     enami 	const struct pciide_product_desc *pp;
    203   1.1    bouyer 
    204   1.4     enami 	pp = viaide_lookup(pa->pa_id);
    205   1.1    bouyer 	if (pp == NULL)
    206   1.1    bouyer 		panic("viaide_attach");
    207   1.1    bouyer 	pciide_common_attach(sc, pa, pp);
    208   1.1    bouyer }
    209   1.1    bouyer 
    210   1.5      fvdl static int
    211   1.5      fvdl via_pcib_match(struct pci_attach_args *pa)
    212   1.5      fvdl {
    213   1.5      fvdl 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    214   1.5      fvdl 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA &&
    215   1.5      fvdl 	    PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH)
    216   1.5      fvdl 		return (1);
    217   1.5      fvdl 	return 0;
    218   1.5      fvdl }
    219   1.5      fvdl 
    220   1.2   thorpej static void
    221   1.2   thorpej via_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    222   1.1    bouyer {
    223   1.1    bouyer 	struct pciide_channel *cp;
    224   1.1    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    225   1.1    bouyer 	pcireg_t vendor = PCI_VENDOR(pa->pa_id);
    226   1.1    bouyer 	int channel;
    227   1.1    bouyer 	u_int32_t ideconf;
    228   1.1    bouyer 	bus_size_t cmdsize, ctlsize;
    229   1.1    bouyer 	pcireg_t pcib_id, pcib_class;
    230   1.5      fvdl 	struct pci_attach_args pcib_pa;
    231   1.1    bouyer 
    232   1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    233   1.1    bouyer 		return;
    234   1.1    bouyer 
    235   1.3     enami 	switch (vendor) {
    236   1.1    bouyer 	case PCI_VENDOR_VIATECH:
    237   1.1    bouyer 		/*
    238   1.5      fvdl 		 * get a PCI tag for the ISA bridge.
    239   1.1    bouyer 		 */
    240  1.12  drochner 		if (pci_find_device(&pcib_pa, via_pcib_match) == 0)
    241   1.5      fvdl 			goto unknown;
    242   1.5      fvdl 		pcib_id = pcib_pa.pa_id;
    243   1.5      fvdl 		pcib_class = pcib_pa.pa_class;
    244   1.1    bouyer 		aprint_normal("%s: VIA Technologies ",
    245  1.17   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    246   1.1    bouyer 		switch (PCI_PRODUCT(pcib_id)) {
    247   1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    248   1.1    bouyer 			aprint_normal("VT82C586 (Apollo VP) ");
    249   1.1    bouyer 			if(PCI_REVISION(pcib_class) >= 0x02) {
    250   1.1    bouyer 				aprint_normal("ATA33 controller\n");
    251  1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    252   1.1    bouyer 			} else {
    253   1.1    bouyer 				aprint_normal("controller\n");
    254  1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    255   1.1    bouyer 			}
    256   1.1    bouyer 			break;
    257   1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C596A:
    258   1.1    bouyer 			aprint_normal("VT82C596A (Apollo Pro) ");
    259   1.1    bouyer 			if (PCI_REVISION(pcib_class) >= 0x12) {
    260   1.1    bouyer 				aprint_normal("ATA66 controller\n");
    261  1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    262   1.1    bouyer 			} else {
    263   1.1    bouyer 				aprint_normal("ATA33 controller\n");
    264  1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    265   1.1    bouyer 			}
    266   1.1    bouyer 			break;
    267   1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C686A_ISA:
    268   1.1    bouyer 			aprint_normal("VT82C686A (Apollo KX133) ");
    269   1.1    bouyer 			if (PCI_REVISION(pcib_class) >= 0x40) {
    270   1.1    bouyer 				aprint_normal("ATA100 controller\n");
    271  1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    272   1.1    bouyer 			} else {
    273   1.1    bouyer 				aprint_normal("ATA66 controller\n");
    274  1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    275   1.1    bouyer 			}
    276   1.1    bouyer 			break;
    277   1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8231:
    278   1.1    bouyer 			aprint_normal("VT8231 ATA100 controller\n");
    279  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    280   1.1    bouyer 			break;
    281   1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8233:
    282   1.1    bouyer 			aprint_normal("VT8233 ATA100 controller\n");
    283  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    284   1.1    bouyer 			break;
    285   1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8233A:
    286   1.1    bouyer 			aprint_normal("VT8233A ATA133 controller\n");
    287  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    288   1.1    bouyer 			break;
    289   1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8235:
    290   1.1    bouyer 			aprint_normal("VT8235 ATA133 controller\n");
    291  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    292   1.1    bouyer 			break;
    293   1.5      fvdl 		case PCI_PRODUCT_VIATECH_VT8237:
    294   1.1    bouyer 			aprint_normal("VT8237 ATA133 controller\n");
    295  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    296   1.1    bouyer 			break;
    297   1.1    bouyer 		default:
    298   1.5      fvdl unknown:
    299   1.1    bouyer 			aprint_normal("unknown VIA ATA controller\n");
    300  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    301   1.1    bouyer 		}
    302   1.1    bouyer 		sc->sc_apo_regbase = APO_VIA_REGBASE;
    303   1.1    bouyer 		break;
    304   1.1    bouyer 	case PCI_VENDOR_AMD:
    305   1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    306  1.11    bouyer 		case PCI_PRODUCT_AMD_PBC8111_IDE:
    307  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    308  1.11    bouyer 			break;
    309   1.1    bouyer 		case PCI_PRODUCT_AMD_PBC766_IDE:
    310   1.1    bouyer 		case PCI_PRODUCT_AMD_PBC768_IDE:
    311  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    312   1.1    bouyer 			break;
    313   1.1    bouyer 		default:
    314  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    315   1.1    bouyer 		}
    316   1.1    bouyer 		sc->sc_apo_regbase = APO_AMD_REGBASE;
    317   1.1    bouyer 		break;
    318   1.1    bouyer 	case PCI_VENDOR_NVIDIA:
    319   1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    320   1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE_ATA100:
    321  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    322   1.1    bouyer 			break;
    323   1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133:
    324  1.20  jdolecek 		case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133:
    325   1.5      fvdl 		case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133:
    326  1.19   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133:
    327  1.21      kent 		case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133:
    328  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    329   1.1    bouyer 			break;
    330   1.1    bouyer 		}
    331   1.1    bouyer 		sc->sc_apo_regbase = APO_NVIDIA_REGBASE;
    332   1.1    bouyer 		break;
    333   1.1    bouyer 	default:
    334   1.1    bouyer 		panic("via_chip_map: unknown vendor");
    335   1.1    bouyer 	}
    336   1.3     enami 
    337   1.1    bouyer 	aprint_normal("%s: bus-master DMA support present",
    338  1.17   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    339   1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    340   1.1    bouyer 	aprint_normal("\n");
    341  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    342   1.1    bouyer 	if (sc->sc_dma_ok) {
    343  1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    344   1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    345  1.17   thorpej 		if (sc->sc_wdcdev.sc_atac.atac_udma_cap > 0)
    346  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
    347   1.1    bouyer 	}
    348  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    349  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    350  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = via_setup_channel;
    351  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    352  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    353   1.1    bouyer 
    354  1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    355  1.15   thorpej 
    356  1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
    357   1.1    bouyer 	    "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    358   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc)),
    359   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc)),
    360   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    361   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))),
    362   1.1    bouyer 	    DEBUG_PROBE);
    363   1.1    bouyer 
    364   1.1    bouyer 	ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
    365  1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    366  1.17   thorpej 	     channel++) {
    367   1.1    bouyer 		cp = &sc->pciide_channels[channel];
    368   1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    369   1.1    bouyer 			continue;
    370   1.1    bouyer 
    371   1.1    bouyer 		if ((ideconf & APO_IDECONF_EN(channel)) == 0) {
    372   1.1    bouyer 			aprint_normal("%s: %s channel ignored (disabled)\n",
    373  1.17   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    374  1.15   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    375   1.1    bouyer 			continue;
    376   1.1    bouyer 		}
    377   1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    378   1.1    bouyer 		    pciide_pci_intr);
    379   1.1    bouyer 	}
    380   1.1    bouyer }
    381   1.1    bouyer 
    382   1.2   thorpej static void
    383  1.15   thorpej via_setup_channel(struct ata_channel *chp)
    384   1.1    bouyer {
    385   1.1    bouyer 	u_int32_t udmatim_reg, datatim_reg;
    386   1.1    bouyer 	u_int8_t idedma_ctl;
    387  1.18   thorpej 	int mode, drive, s;
    388   1.1    bouyer 	struct ata_drive_datas *drvp;
    389  1.17   thorpej 	struct atac_softc *atac = chp->ch_atac;
    390  1.16   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    391  1.16   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    392   1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    393   1.1    bouyer 	int rev = PCI_REVISION(
    394   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
    395   1.1    bouyer #endif
    396   1.1    bouyer 
    397   1.1    bouyer 	idedma_ctl = 0;
    398   1.1    bouyer 	datatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
    399   1.1    bouyer 	udmatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc));
    400   1.9   thorpej 	datatim_reg &= ~APO_DATATIM_MASK(chp->ch_channel);
    401   1.9   thorpej 	udmatim_reg &= ~APO_UDMA_MASK(chp->ch_channel);
    402   1.1    bouyer 
    403   1.1    bouyer 	/* setup DMA if needed */
    404   1.1    bouyer 	pciide_channel_dma_setup(cp);
    405   1.1    bouyer 
    406   1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    407   1.1    bouyer 		drvp = &chp->ch_drive[drive];
    408   1.1    bouyer 		/* If no drive, skip */
    409   1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    410   1.1    bouyer 			continue;
    411   1.1    bouyer 		/* add timing values, setup DMA if needed */
    412   1.1    bouyer 		if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
    413   1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA) == 0)) {
    414   1.1    bouyer 			mode = drvp->PIO_mode;
    415   1.1    bouyer 			goto pio;
    416   1.1    bouyer 		}
    417  1.17   thorpej 		if ((atac->atac_cap & ATAC_CAP_UDMA) &&
    418   1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA)) {
    419   1.1    bouyer 			/* use Ultra/DMA */
    420  1.18   thorpej 			s = splbio();
    421   1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    422  1.18   thorpej 			splx(s);
    423   1.9   thorpej 			udmatim_reg |= APO_UDMA_EN(chp->ch_channel, drive) |
    424   1.9   thorpej 			    APO_UDMA_EN_MTH(chp->ch_channel, drive);
    425   1.3     enami 			switch (PCI_VENDOR(sc->sc_pci_id)) {
    426   1.1    bouyer 			case PCI_VENDOR_VIATECH:
    427  1.17   thorpej 				if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 6) {
    428   1.1    bouyer 					/* 8233a */
    429   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    430   1.9   thorpej 					    chp->ch_channel,
    431   1.1    bouyer 					    drive,
    432   1.1    bouyer 					    via_udma133_tim[drvp->UDMA_mode]);
    433  1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 5) {
    434   1.1    bouyer 					/* 686b */
    435   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    436   1.9   thorpej 					    chp->ch_channel,
    437   1.1    bouyer 					    drive,
    438   1.1    bouyer 					    via_udma100_tim[drvp->UDMA_mode]);
    439  1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 4) {
    440   1.1    bouyer 					/* 596b or 686a */
    441   1.1    bouyer 					udmatim_reg |= APO_UDMA_CLK66(
    442   1.9   thorpej 					    chp->ch_channel);
    443   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    444   1.9   thorpej 					    chp->ch_channel,
    445   1.1    bouyer 					    drive,
    446   1.1    bouyer 					    via_udma66_tim[drvp->UDMA_mode]);
    447   1.1    bouyer 				} else {
    448   1.1    bouyer 					/* 596a or 586b */
    449   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    450   1.9   thorpej 					    chp->ch_channel,
    451   1.1    bouyer 					    drive,
    452   1.1    bouyer 					    via_udma33_tim[drvp->UDMA_mode]);
    453   1.1    bouyer 				}
    454   1.1    bouyer 				break;
    455   1.1    bouyer 			case PCI_VENDOR_AMD:
    456   1.1    bouyer 			case PCI_VENDOR_NVIDIA:
    457   1.9   thorpej 				udmatim_reg |= APO_UDMA_TIME(chp->ch_channel,
    458   1.1    bouyer 				    drive, amd7x6_udma_tim[drvp->UDMA_mode]);
    459   1.1    bouyer 				 break;
    460   1.1    bouyer 			}
    461   1.1    bouyer 			/* can use PIO timings, MW DMA unused */
    462   1.1    bouyer 			mode = drvp->PIO_mode;
    463   1.1    bouyer 		} else {
    464   1.1    bouyer 			/* use Multiword DMA, but only if revision is OK */
    465  1.18   thorpej 			s = splbio();
    466   1.1    bouyer 			drvp->drive_flags &= ~DRIVE_UDMA;
    467  1.18   thorpej 			splx(s);
    468   1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    469   1.1    bouyer 			/*
    470   1.1    bouyer 			 * The workaround doesn't seem to be necessary
    471   1.1    bouyer 			 * with all drives, so it can be disabled by
    472   1.1    bouyer 			 * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
    473   1.1    bouyer 			 * triggered.
    474   1.1    bouyer 			 */
    475   1.1    bouyer 			if (PCI_VENDOR(sc->sc_pci_id) == PCI_VENDOR_AMD &&
    476   1.1    bouyer 			    sc->sc_pp->ide_product ==
    477   1.3     enami 			    PCI_PRODUCT_AMD_PBC756_IDE &&
    478   1.1    bouyer 			    AMD756_CHIPREV_DISABLEDMA(rev)) {
    479   1.1    bouyer 				aprint_normal(
    480   1.1    bouyer 				    "%s:%d:%d: multi-word DMA disabled due "
    481   1.1    bouyer 				    "to chip revision\n",
    482  1.17   thorpej 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    483   1.9   thorpej 				    chp->ch_channel, drive);
    484   1.1    bouyer 				mode = drvp->PIO_mode;
    485  1.18   thorpej 				s = splbio();
    486   1.1    bouyer 				drvp->drive_flags &= ~DRIVE_DMA;
    487  1.18   thorpej 				splx(s);
    488   1.1    bouyer 				goto pio;
    489   1.1    bouyer 			}
    490   1.1    bouyer #endif
    491   1.1    bouyer 			/* mode = min(pio, dma+2) */
    492   1.3     enami 			if (drvp->PIO_mode <= (drvp->DMA_mode + 2))
    493   1.1    bouyer 				mode = drvp->PIO_mode;
    494   1.1    bouyer 			else
    495   1.1    bouyer 				mode = drvp->DMA_mode + 2;
    496   1.1    bouyer 		}
    497   1.1    bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    498   1.1    bouyer 
    499   1.1    bouyer pio:		/* setup PIO mode */
    500   1.1    bouyer 		if (mode <= 2) {
    501   1.1    bouyer 			drvp->DMA_mode = 0;
    502   1.1    bouyer 			drvp->PIO_mode = 0;
    503   1.1    bouyer 			mode = 0;
    504   1.1    bouyer 		} else {
    505   1.1    bouyer 			drvp->PIO_mode = mode;
    506   1.1    bouyer 			drvp->DMA_mode = mode - 2;
    507   1.1    bouyer 		}
    508   1.1    bouyer 		datatim_reg |=
    509   1.9   thorpej 		    APO_DATATIM_PULSE(chp->ch_channel, drive,
    510   1.1    bouyer 			apollo_pio_set[mode]) |
    511   1.9   thorpej 		    APO_DATATIM_RECOV(chp->ch_channel, drive,
    512   1.1    bouyer 			apollo_pio_rec[mode]);
    513   1.1    bouyer 	}
    514   1.1    bouyer 	if (idedma_ctl != 0) {
    515   1.1    bouyer 		/* Add software bits in status register */
    516   1.7      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    517   1.1    bouyer 		    idedma_ctl);
    518   1.1    bouyer 	}
    519   1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc), datatim_reg);
    520   1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_UDMA(sc), udmatim_reg);
    521  1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    522   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    523   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))), DEBUG_PROBE);
    524   1.1    bouyer }
    525   1.1    bouyer 
    526   1.2   thorpej static void
    527   1.2   thorpej via_sata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    528   1.1    bouyer {
    529   1.1    bouyer 	struct pciide_channel *cp;
    530   1.1    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    531   1.1    bouyer 	int channel;
    532   1.1    bouyer 	bus_size_t cmdsize, ctlsize;
    533   1.1    bouyer 
    534   1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    535   1.1    bouyer 		return;
    536   1.1    bouyer 
    537   1.3     enami 	if (interface == 0) {
    538  1.14   thorpej 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    539   1.3     enami 		    DEBUG_PROBE);
    540   1.1    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    541   1.3     enami 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    542   1.1    bouyer 	}
    543   1.1    bouyer 
    544   1.1    bouyer 	aprint_normal("%s: bus-master DMA support present",
    545  1.17   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    546   1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    547   1.1    bouyer 	aprint_normal("\n");
    548   1.1    bouyer 
    549   1.1    bouyer 	if (sc->sc_dma_ok) {
    550  1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
    551   1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    552   1.1    bouyer 	}
    553  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    554  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    555  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    556  1.17   thorpej 
    557  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    558  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    559  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    560  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    561   1.1    bouyer 
    562  1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    563  1.15   thorpej 
    564  1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    565  1.17   thorpej 	     channel++) {
    566   1.1    bouyer 		cp = &sc->pciide_channels[channel];
    567   1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    568   1.1    bouyer 			continue;
    569   1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    570   1.3     enami 		    pciide_pci_intr);
    571   1.1    bouyer 	}
    572   1.1    bouyer }
    573