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