Home | History | Annotate | Line # | Download | only in pci
viaide.c revision 1.37.2.2.2.2
      1  1.37.2.2.2.2  wrstuden /*	$NetBSD: viaide.c,v 1.37.2.2.2.2 2007/10/29 00:45:20 wrstuden 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.37.2.2.2.2  wrstuden __KERNEL_RCSID(0, "$NetBSD: viaide.c,v 1.37.2.2.2.2 2007/10/29 00:45:20 wrstuden 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.35    bouyer static int	via_sata_chip_map_common(struct pciide_softc *,
     48          1.35    bouyer 		    struct pci_attach_args *);
     49           1.4     enami static void	via_sata_chip_map(struct pciide_softc *,
     50          1.35    bouyer 		    struct pci_attach_args *, int);
     51          1.35    bouyer static void	via_sata_chip_map_0(struct pciide_softc *,
     52          1.35    bouyer 		    struct pci_attach_args *);
     53          1.35    bouyer static void	via_sata_chip_map_6(struct pciide_softc *,
     54          1.35    bouyer 		    struct pci_attach_args *);
     55          1.35    bouyer static void	via_sata_chip_map_7(struct pciide_softc *,
     56          1.35    bouyer 		    struct pci_attach_args *);
     57          1.35    bouyer static void	via_sata_chip_map_new(struct pciide_softc *,
     58           1.4     enami 		    struct pci_attach_args *);
     59          1.15   thorpej static void	via_setup_channel(struct ata_channel *);
     60           1.4     enami 
     61           1.4     enami static int	viaide_match(struct device *, struct cfdata *, void *);
     62           1.4     enami static void	viaide_attach(struct device *, struct device *, void *);
     63           1.4     enami static const struct pciide_product_desc *
     64           1.4     enami 		viaide_lookup(pcireg_t);
     65           1.1    bouyer 
     66           1.1    bouyer CFATTACH_DECL(viaide, sizeof(struct pciide_softc),
     67           1.1    bouyer     viaide_match, viaide_attach, NULL, NULL);
     68           1.1    bouyer 
     69           1.2   thorpej static const struct pciide_product_desc pciide_amd_products[] =  {
     70           1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC756_IDE,
     71           1.1    bouyer 	  0,
     72           1.1    bouyer 	  "Advanced Micro Devices AMD756 IDE Controller",
     73           1.1    bouyer 	  via_chip_map
     74           1.1    bouyer 	},
     75           1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC766_IDE,
     76           1.1    bouyer 	  0,
     77           1.1    bouyer 	  "Advanced Micro Devices AMD766 IDE Controller",
     78           1.1    bouyer 	  via_chip_map
     79           1.1    bouyer 	},
     80           1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC768_IDE,
     81           1.1    bouyer 	  0,
     82           1.1    bouyer 	  "Advanced Micro Devices AMD768 IDE Controller",
     83           1.1    bouyer 	  via_chip_map
     84           1.1    bouyer 	},
     85           1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC8111_IDE,
     86           1.1    bouyer 	  0,
     87           1.1    bouyer 	  "Advanced Micro Devices AMD8111 IDE Controller",
     88           1.1    bouyer 	  via_chip_map
     89           1.1    bouyer 	},
     90  1.37.2.2.2.1  wrstuden 	{ PCI_PRODUCT_AMD_CS5536_IDE,
     91  1.37.2.2.2.1  wrstuden 	  0,
     92  1.37.2.2.2.1  wrstuden 	  "Advanced Micro Devices CS5536 IDE Controller",
     93  1.37.2.2.2.1  wrstuden 	  via_chip_map
     94  1.37.2.2.2.1  wrstuden 	},
     95           1.1    bouyer 	{ 0,
     96           1.1    bouyer 	  0,
     97           1.1    bouyer 	  NULL,
     98           1.1    bouyer 	  NULL
     99           1.1    bouyer 	}
    100           1.1    bouyer };
    101           1.1    bouyer 
    102           1.2   thorpej static const struct pciide_product_desc pciide_nvidia_products[] = {
    103           1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE_ATA100,
    104           1.1    bouyer 	  0,
    105           1.1    bouyer 	  "NVIDIA nForce IDE Controller",
    106           1.1    bouyer 	  via_chip_map
    107           1.1    bouyer 	},
    108           1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE2_ATA133,
    109           1.1    bouyer 	  0,
    110           1.1    bouyer 	  "NVIDIA nForce2 IDE Controller",
    111           1.1    bouyer 	  via_chip_map
    112           1.1    bouyer 	},
    113          1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133,
    114          1.20  jdolecek 	  0,
    115          1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 IDE Controller",
    116          1.20  jdolecek 	  via_chip_map
    117          1.20  jdolecek 	},
    118          1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_SATA,
    119          1.20  jdolecek 	  0,
    120          1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 Serial ATA Controller",
    121          1.35    bouyer 	  via_sata_chip_map_6
    122          1.20  jdolecek 	},
    123          1.10      fvdl 	{ PCI_PRODUCT_NVIDIA_NFORCE3_ATA133,
    124          1.10      fvdl 	  0,
    125          1.10      fvdl 	  "NVIDIA nForce3 IDE Controller",
    126          1.10      fvdl 	  via_chip_map
    127          1.10      fvdl 	},
    128          1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133,
    129          1.19   xtraeme 	  0,
    130          1.19   xtraeme 	  "NVIDIA nForce3 250 IDE Controller",
    131          1.19   xtraeme 	  via_chip_map
    132          1.19   xtraeme 	},
    133          1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA,
    134          1.19   xtraeme 	  0,
    135          1.19   xtraeme 	  "NVIDIA nForce3 250 Serial ATA Controller",
    136          1.35    bouyer 	  via_sata_chip_map_6
    137          1.19   xtraeme 	},
    138          1.32   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA2,
    139          1.32   xtraeme 	  0,
    140          1.32   xtraeme 	  "NVIDIA nForce3 250 Serial ATA Controller",
    141          1.35    bouyer 	  via_sata_chip_map_6
    142          1.32   xtraeme 	},
    143          1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_ATA133,
    144          1.21      kent 	  0,
    145          1.21      kent 	  "NVIDIA nForce4 IDE Controller",
    146          1.21      kent 	  via_chip_map
    147          1.21      kent 	},
    148          1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA1,
    149          1.21      kent 	  0,
    150          1.21      kent 	  "NVIDIA nForce4 Serial ATA Controller",
    151          1.35    bouyer 	  via_sata_chip_map_6
    152          1.21      kent 	},
    153          1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA2,
    154          1.21      kent 	  0,
    155          1.21      kent 	  "NVIDIA nForce4 Serial ATA Controller",
    156          1.35    bouyer 	  via_sata_chip_map_6
    157          1.21      kent 	},
    158          1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_ATA133,
    159          1.27      manu 	  0,
    160          1.27      manu 	  "NVIDIA nForce430 IDE Controller",
    161          1.27      manu 	  via_chip_map
    162          1.27      manu 	},
    163          1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_SATA1,
    164          1.27      manu 	  0,
    165          1.27      manu 	  "NVIDIA nForce430 Serial ATA Controller",
    166          1.35    bouyer 	  via_sata_chip_map_6
    167          1.27      manu 	},
    168          1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_SATA2,
    169          1.27      manu 	  0,
    170          1.27      manu 	  "NVIDIA nForce430 Serial ATA Controller",
    171          1.35    bouyer 	  via_sata_chip_map_6
    172          1.27      manu 	},
    173          1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_IDE,
    174          1.30   xtraeme 	  0,
    175          1.30   xtraeme 	  "NVIDIA MCP04 IDE Controller",
    176          1.30   xtraeme 	  via_chip_map
    177          1.30   xtraeme 	},
    178          1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_SATA,
    179          1.30   xtraeme 	  0,
    180          1.31   xtraeme 	  "NVIDIA MCP04 Serial ATA Controller",
    181          1.35    bouyer 	  via_sata_chip_map_6
    182          1.30   xtraeme 	},
    183          1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_SATA2,
    184          1.30   xtraeme 	  0,
    185          1.31   xtraeme 	  "NVIDIA MCP04 Serial ATA Controller",
    186          1.35    bouyer 	  via_sata_chip_map_6
    187          1.30   xtraeme 	},
    188          1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_IDE,
    189          1.30   xtraeme 	  0,
    190          1.30   xtraeme 	  "NVIDIA MCP55 IDE Controller",
    191          1.30   xtraeme 	  via_chip_map
    192          1.30   xtraeme 	},
    193          1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_SATA,
    194          1.30   xtraeme 	  0,
    195          1.31   xtraeme 	  "NVIDIA MCP55 Serial ATA Controller",
    196          1.35    bouyer 	  via_sata_chip_map_6
    197          1.30   xtraeme 	},
    198          1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_SATA2,
    199          1.30   xtraeme 	  0,
    200          1.31   xtraeme 	  "NVIDIA MCP55 Serial ATA Controller",
    201          1.35    bouyer 	  via_sata_chip_map_6
    202          1.30   xtraeme 	},
    203          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_IDE,
    204          1.33   xtraeme 	  0,
    205          1.33   xtraeme 	  "NVIDIA MCP61 IDE Controller",
    206          1.33   xtraeme 	  via_chip_map
    207          1.33   xtraeme 	},
    208          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_IDE,
    209          1.33   xtraeme 	  0,
    210          1.33   xtraeme 	  "NVIDIA MCP65 IDE Controller",
    211          1.33   xtraeme 	  via_chip_map
    212          1.33   xtraeme 	},
    213          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_SATA,
    214          1.33   xtraeme 	  0,
    215          1.33   xtraeme 	  "NVIDIA MCP61 Serial ATA Controller",
    216          1.35    bouyer 	  via_sata_chip_map_6
    217          1.33   xtraeme 	},
    218          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_SATA2,
    219          1.33   xtraeme 	  0,
    220          1.33   xtraeme 	  "NVIDIA MCP61 Serial ATA Controller",
    221          1.35    bouyer 	  via_sata_chip_map_6
    222          1.33   xtraeme 	},
    223          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_SATA3,
    224          1.33   xtraeme 	  0,
    225          1.33   xtraeme 	  "NVIDIA MCP61 Serial ATA Controller",
    226          1.35    bouyer 	  via_sata_chip_map_6
    227          1.33   xtraeme 	},
    228          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA,
    229          1.33   xtraeme 	  0,
    230          1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    231          1.35    bouyer 	  via_sata_chip_map_6
    232          1.33   xtraeme 	},
    233          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA2,
    234          1.33   xtraeme 	  0,
    235          1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    236          1.35    bouyer 	  via_sata_chip_map_6
    237          1.33   xtraeme 	},
    238          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA3,
    239          1.33   xtraeme 	  0,
    240          1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    241          1.35    bouyer 	  via_sata_chip_map_6
    242          1.33   xtraeme 	},
    243          1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA4,
    244          1.33   xtraeme 	  0,
    245          1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    246          1.35    bouyer 	  via_sata_chip_map_6
    247          1.33   xtraeme 	},
    248           1.1    bouyer 	{ 0,
    249           1.1    bouyer 	  0,
    250           1.1    bouyer 	  NULL,
    251           1.1    bouyer 	  NULL
    252           1.1    bouyer 	}
    253           1.1    bouyer };
    254           1.1    bouyer 
    255           1.2   thorpej static const struct pciide_product_desc pciide_via_products[] =  {
    256           1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586_IDE,
    257           1.1    bouyer 	  0,
    258           1.1    bouyer 	  NULL,
    259           1.1    bouyer 	  via_chip_map,
    260           1.1    bouyer 	 },
    261           1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586A_IDE,
    262           1.1    bouyer 	  0,
    263           1.1    bouyer 	  NULL,
    264           1.1    bouyer 	  via_chip_map,
    265           1.1    bouyer 	},
    266          1.23       abs 	{ PCI_PRODUCT_VIATECH_VT6421_RAID,
    267          1.22       abs 	  0,
    268          1.23       abs 	  "VIA Technologies VT6421 Serial RAID Controller",
    269          1.35    bouyer 	  via_sata_chip_map_new,
    270          1.22       abs 	},
    271           1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT8237_SATA,
    272           1.6   mycroft 	  0,
    273           1.1    bouyer 	  "VIA Technologies VT8237 SATA Controller",
    274          1.35    bouyer 	  via_sata_chip_map_7,
    275          1.35    bouyer 	},
    276          1.35    bouyer 	{ PCI_PRODUCT_VIATECH_VT8237A_SATA,
    277          1.35    bouyer 	  0,
    278          1.35    bouyer 	  "VIA Technologies VT8237A SATA Controller",
    279      1.37.2.2    bouyer 	  via_sata_chip_map_7,
    280           1.1    bouyer 	},
    281          1.29   xtraeme 	{ PCI_PRODUCT_VIATECH_VT8237R_SATA,
    282          1.29   xtraeme 	  0,
    283          1.29   xtraeme 	  "VIA Technologies VT8237R SATA Controller",
    284          1.35    bouyer 	  via_sata_chip_map_0,
    285          1.29   xtraeme 	},
    286           1.1    bouyer 	{ 0,
    287           1.1    bouyer 	  0,
    288           1.1    bouyer 	  NULL,
    289           1.1    bouyer 	  NULL
    290           1.1    bouyer 	}
    291           1.1    bouyer };
    292           1.1    bouyer 
    293           1.4     enami static const struct pciide_product_desc *
    294           1.4     enami viaide_lookup(pcireg_t id)
    295           1.4     enami {
    296           1.4     enami 
    297           1.4     enami 	switch (PCI_VENDOR(id)) {
    298           1.4     enami 	case PCI_VENDOR_VIATECH:
    299           1.4     enami 		return (pciide_lookup_product(id, pciide_via_products));
    300           1.4     enami 
    301           1.4     enami 	case PCI_VENDOR_AMD:
    302           1.4     enami 		return (pciide_lookup_product(id, pciide_amd_products));
    303           1.4     enami 
    304           1.4     enami 	case PCI_VENDOR_NVIDIA:
    305           1.4     enami 		return (pciide_lookup_product(id, pciide_nvidia_products));
    306           1.4     enami 	}
    307           1.4     enami 	return (NULL);
    308           1.4     enami }
    309           1.4     enami 
    310           1.2   thorpej static int
    311          1.37  christos viaide_match(struct device *parent, struct cfdata *match,
    312          1.34  christos     void *aux)
    313           1.1    bouyer {
    314           1.1    bouyer 	struct pci_attach_args *pa = aux;
    315           1.1    bouyer 
    316           1.4     enami 	if (viaide_lookup(pa->pa_id) != NULL)
    317           1.4     enami 		return (2);
    318           1.1    bouyer 	return (0);
    319           1.1    bouyer }
    320           1.1    bouyer 
    321           1.2   thorpej static void
    322          1.37  christos viaide_attach(struct device *parent, struct device *self, void *aux)
    323           1.1    bouyer {
    324           1.1    bouyer 	struct pci_attach_args *pa = aux;
    325           1.1    bouyer 	struct pciide_softc *sc = (struct pciide_softc *)self;
    326           1.4     enami 	const struct pciide_product_desc *pp;
    327           1.1    bouyer 
    328           1.4     enami 	pp = viaide_lookup(pa->pa_id);
    329           1.1    bouyer 	if (pp == NULL)
    330           1.1    bouyer 		panic("viaide_attach");
    331           1.1    bouyer 	pciide_common_attach(sc, pa, pp);
    332           1.1    bouyer }
    333           1.1    bouyer 
    334           1.5      fvdl static int
    335           1.5      fvdl via_pcib_match(struct pci_attach_args *pa)
    336           1.5      fvdl {
    337           1.5      fvdl 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    338           1.5      fvdl 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA &&
    339           1.5      fvdl 	    PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH)
    340           1.5      fvdl 		return (1);
    341           1.5      fvdl 	return 0;
    342           1.5      fvdl }
    343           1.5      fvdl 
    344           1.2   thorpej static void
    345           1.2   thorpej via_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    346           1.1    bouyer {
    347           1.1    bouyer 	struct pciide_channel *cp;
    348           1.1    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    349           1.1    bouyer 	pcireg_t vendor = PCI_VENDOR(pa->pa_id);
    350           1.1    bouyer 	int channel;
    351           1.1    bouyer 	u_int32_t ideconf;
    352           1.1    bouyer 	bus_size_t cmdsize, ctlsize;
    353           1.1    bouyer 	pcireg_t pcib_id, pcib_class;
    354           1.5      fvdl 	struct pci_attach_args pcib_pa;
    355           1.1    bouyer 
    356           1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    357           1.1    bouyer 		return;
    358           1.1    bouyer 
    359           1.3     enami 	switch (vendor) {
    360           1.1    bouyer 	case PCI_VENDOR_VIATECH:
    361           1.1    bouyer 		/*
    362           1.5      fvdl 		 * get a PCI tag for the ISA bridge.
    363           1.1    bouyer 		 */
    364          1.12  drochner 		if (pci_find_device(&pcib_pa, via_pcib_match) == 0)
    365           1.5      fvdl 			goto unknown;
    366           1.5      fvdl 		pcib_id = pcib_pa.pa_id;
    367           1.5      fvdl 		pcib_class = pcib_pa.pa_class;
    368           1.1    bouyer 		aprint_normal("%s: VIA Technologies ",
    369          1.17   thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    370           1.1    bouyer 		switch (PCI_PRODUCT(pcib_id)) {
    371           1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    372           1.1    bouyer 			aprint_normal("VT82C586 (Apollo VP) ");
    373           1.1    bouyer 			if(PCI_REVISION(pcib_class) >= 0x02) {
    374           1.1    bouyer 				aprint_normal("ATA33 controller\n");
    375          1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    376           1.1    bouyer 			} else {
    377           1.1    bouyer 				aprint_normal("controller\n");
    378          1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    379           1.1    bouyer 			}
    380           1.1    bouyer 			break;
    381           1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C596A:
    382           1.1    bouyer 			aprint_normal("VT82C596A (Apollo Pro) ");
    383           1.1    bouyer 			if (PCI_REVISION(pcib_class) >= 0x12) {
    384           1.1    bouyer 				aprint_normal("ATA66 controller\n");
    385          1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    386           1.1    bouyer 			} else {
    387           1.1    bouyer 				aprint_normal("ATA33 controller\n");
    388          1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    389           1.1    bouyer 			}
    390           1.1    bouyer 			break;
    391           1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C686A_ISA:
    392           1.1    bouyer 			aprint_normal("VT82C686A (Apollo KX133) ");
    393           1.1    bouyer 			if (PCI_REVISION(pcib_class) >= 0x40) {
    394           1.1    bouyer 				aprint_normal("ATA100 controller\n");
    395          1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    396           1.1    bouyer 			} else {
    397           1.1    bouyer 				aprint_normal("ATA66 controller\n");
    398          1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    399           1.1    bouyer 			}
    400           1.1    bouyer 			break;
    401           1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8231:
    402           1.1    bouyer 			aprint_normal("VT8231 ATA100 controller\n");
    403          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    404           1.1    bouyer 			break;
    405           1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8233:
    406           1.1    bouyer 			aprint_normal("VT8233 ATA100 controller\n");
    407          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    408           1.1    bouyer 			break;
    409           1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8233A:
    410           1.1    bouyer 			aprint_normal("VT8233A ATA133 controller\n");
    411          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    412           1.1    bouyer 			break;
    413           1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8235:
    414           1.1    bouyer 			aprint_normal("VT8235 ATA133 controller\n");
    415          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    416           1.1    bouyer 			break;
    417           1.5      fvdl 		case PCI_PRODUCT_VIATECH_VT8237:
    418           1.1    bouyer 			aprint_normal("VT8237 ATA133 controller\n");
    419          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    420           1.1    bouyer 			break;
    421      1.37.2.1      tron 		case PCI_PRODUCT_VIATECH_VT8237A_ISA:
    422      1.37.2.1      tron 			aprint_normal("VT8237A ATA133 controller\n");
    423      1.37.2.1      tron 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    424      1.37.2.1      tron 			break;
    425           1.1    bouyer 		default:
    426           1.5      fvdl unknown:
    427           1.1    bouyer 			aprint_normal("unknown VIA ATA controller\n");
    428          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    429           1.1    bouyer 		}
    430           1.1    bouyer 		sc->sc_apo_regbase = APO_VIA_REGBASE;
    431           1.1    bouyer 		break;
    432           1.1    bouyer 	case PCI_VENDOR_AMD:
    433           1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    434          1.11    bouyer 		case PCI_PRODUCT_AMD_PBC8111_IDE:
    435          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    436          1.11    bouyer 			break;
    437  1.37.2.2.2.2  wrstuden 		case PCI_PRODUCT_AMD_CS5536_IDE:
    438           1.1    bouyer 		case PCI_PRODUCT_AMD_PBC766_IDE:
    439           1.1    bouyer 		case PCI_PRODUCT_AMD_PBC768_IDE:
    440          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    441           1.1    bouyer 			break;
    442           1.1    bouyer 		default:
    443          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    444           1.1    bouyer 		}
    445           1.1    bouyer 		sc->sc_apo_regbase = APO_AMD_REGBASE;
    446           1.1    bouyer 		break;
    447           1.1    bouyer 	case PCI_VENDOR_NVIDIA:
    448           1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    449           1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE_ATA100:
    450          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    451           1.1    bouyer 			break;
    452           1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133:
    453          1.20  jdolecek 		case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133:
    454           1.5      fvdl 		case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133:
    455          1.19   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133:
    456          1.21      kent 		case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133:
    457          1.28   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE430_ATA133:
    458          1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP04_IDE:
    459          1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP55_IDE:
    460          1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP61_IDE:
    461          1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP65_IDE:
    462          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    463           1.1    bouyer 			break;
    464           1.1    bouyer 		}
    465           1.1    bouyer 		sc->sc_apo_regbase = APO_NVIDIA_REGBASE;
    466           1.1    bouyer 		break;
    467           1.1    bouyer 	default:
    468           1.1    bouyer 		panic("via_chip_map: unknown vendor");
    469           1.1    bouyer 	}
    470           1.3     enami 
    471           1.1    bouyer 	aprint_normal("%s: bus-master DMA support present",
    472          1.17   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    473           1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    474           1.1    bouyer 	aprint_normal("\n");
    475          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    476           1.1    bouyer 	if (sc->sc_dma_ok) {
    477          1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    478           1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    479          1.17   thorpej 		if (sc->sc_wdcdev.sc_atac.atac_udma_cap > 0)
    480          1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
    481           1.1    bouyer 	}
    482          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    483          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    484          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = via_setup_channel;
    485          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    486          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    487           1.1    bouyer 
    488      1.37.2.2    bouyer 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    489      1.37.2.2    bouyer 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    490      1.37.2.2    bouyer 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    491      1.37.2.2    bouyer 
    492          1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    493          1.15   thorpej 
    494          1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
    495           1.1    bouyer 	    "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    496           1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc)),
    497           1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc)),
    498           1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    499           1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))),
    500           1.1    bouyer 	    DEBUG_PROBE);
    501           1.1    bouyer 
    502           1.1    bouyer 	ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
    503          1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    504          1.17   thorpej 	     channel++) {
    505           1.1    bouyer 		cp = &sc->pciide_channels[channel];
    506           1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    507           1.1    bouyer 			continue;
    508           1.1    bouyer 
    509           1.1    bouyer 		if ((ideconf & APO_IDECONF_EN(channel)) == 0) {
    510           1.1    bouyer 			aprint_normal("%s: %s channel ignored (disabled)\n",
    511          1.17   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    512          1.15   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    513           1.1    bouyer 			continue;
    514           1.1    bouyer 		}
    515           1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    516           1.1    bouyer 		    pciide_pci_intr);
    517           1.1    bouyer 	}
    518           1.1    bouyer }
    519           1.1    bouyer 
    520           1.2   thorpej static void
    521          1.15   thorpej via_setup_channel(struct ata_channel *chp)
    522           1.1    bouyer {
    523           1.1    bouyer 	u_int32_t udmatim_reg, datatim_reg;
    524           1.1    bouyer 	u_int8_t idedma_ctl;
    525          1.18   thorpej 	int mode, drive, s;
    526           1.1    bouyer 	struct ata_drive_datas *drvp;
    527          1.17   thorpej 	struct atac_softc *atac = chp->ch_atac;
    528          1.16   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    529          1.16   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    530           1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    531           1.1    bouyer 	int rev = PCI_REVISION(
    532           1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
    533           1.1    bouyer #endif
    534           1.1    bouyer 
    535           1.1    bouyer 	idedma_ctl = 0;
    536           1.1    bouyer 	datatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
    537           1.1    bouyer 	udmatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc));
    538           1.9   thorpej 	datatim_reg &= ~APO_DATATIM_MASK(chp->ch_channel);
    539           1.9   thorpej 	udmatim_reg &= ~APO_UDMA_MASK(chp->ch_channel);
    540           1.1    bouyer 
    541           1.1    bouyer 	/* setup DMA if needed */
    542           1.1    bouyer 	pciide_channel_dma_setup(cp);
    543           1.1    bouyer 
    544           1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    545           1.1    bouyer 		drvp = &chp->ch_drive[drive];
    546           1.1    bouyer 		/* If no drive, skip */
    547           1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    548           1.1    bouyer 			continue;
    549           1.1    bouyer 		/* add timing values, setup DMA if needed */
    550           1.1    bouyer 		if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
    551           1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA) == 0)) {
    552           1.1    bouyer 			mode = drvp->PIO_mode;
    553           1.1    bouyer 			goto pio;
    554           1.1    bouyer 		}
    555          1.17   thorpej 		if ((atac->atac_cap & ATAC_CAP_UDMA) &&
    556           1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA)) {
    557           1.1    bouyer 			/* use Ultra/DMA */
    558          1.18   thorpej 			s = splbio();
    559           1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    560          1.18   thorpej 			splx(s);
    561           1.9   thorpej 			udmatim_reg |= APO_UDMA_EN(chp->ch_channel, drive) |
    562           1.9   thorpej 			    APO_UDMA_EN_MTH(chp->ch_channel, drive);
    563           1.3     enami 			switch (PCI_VENDOR(sc->sc_pci_id)) {
    564           1.1    bouyer 			case PCI_VENDOR_VIATECH:
    565          1.17   thorpej 				if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 6) {
    566           1.1    bouyer 					/* 8233a */
    567           1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    568           1.9   thorpej 					    chp->ch_channel,
    569           1.1    bouyer 					    drive,
    570           1.1    bouyer 					    via_udma133_tim[drvp->UDMA_mode]);
    571          1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 5) {
    572           1.1    bouyer 					/* 686b */
    573           1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    574           1.9   thorpej 					    chp->ch_channel,
    575           1.1    bouyer 					    drive,
    576           1.1    bouyer 					    via_udma100_tim[drvp->UDMA_mode]);
    577          1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 4) {
    578           1.1    bouyer 					/* 596b or 686a */
    579           1.1    bouyer 					udmatim_reg |= APO_UDMA_CLK66(
    580           1.9   thorpej 					    chp->ch_channel);
    581           1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    582           1.9   thorpej 					    chp->ch_channel,
    583           1.1    bouyer 					    drive,
    584           1.1    bouyer 					    via_udma66_tim[drvp->UDMA_mode]);
    585           1.1    bouyer 				} else {
    586           1.1    bouyer 					/* 596a or 586b */
    587           1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    588           1.9   thorpej 					    chp->ch_channel,
    589           1.1    bouyer 					    drive,
    590           1.1    bouyer 					    via_udma33_tim[drvp->UDMA_mode]);
    591           1.1    bouyer 				}
    592           1.1    bouyer 				break;
    593           1.1    bouyer 			case PCI_VENDOR_AMD:
    594           1.1    bouyer 			case PCI_VENDOR_NVIDIA:
    595           1.9   thorpej 				udmatim_reg |= APO_UDMA_TIME(chp->ch_channel,
    596           1.1    bouyer 				    drive, amd7x6_udma_tim[drvp->UDMA_mode]);
    597           1.1    bouyer 				 break;
    598           1.1    bouyer 			}
    599           1.1    bouyer 			/* can use PIO timings, MW DMA unused */
    600           1.1    bouyer 			mode = drvp->PIO_mode;
    601           1.1    bouyer 		} else {
    602           1.1    bouyer 			/* use Multiword DMA, but only if revision is OK */
    603          1.18   thorpej 			s = splbio();
    604           1.1    bouyer 			drvp->drive_flags &= ~DRIVE_UDMA;
    605          1.18   thorpej 			splx(s);
    606           1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    607           1.1    bouyer 			/*
    608           1.1    bouyer 			 * The workaround doesn't seem to be necessary
    609           1.1    bouyer 			 * with all drives, so it can be disabled by
    610           1.1    bouyer 			 * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
    611           1.1    bouyer 			 * triggered.
    612           1.1    bouyer 			 */
    613           1.1    bouyer 			if (PCI_VENDOR(sc->sc_pci_id) == PCI_VENDOR_AMD &&
    614           1.1    bouyer 			    sc->sc_pp->ide_product ==
    615           1.3     enami 			    PCI_PRODUCT_AMD_PBC756_IDE &&
    616           1.1    bouyer 			    AMD756_CHIPREV_DISABLEDMA(rev)) {
    617           1.1    bouyer 				aprint_normal(
    618           1.1    bouyer 				    "%s:%d:%d: multi-word DMA disabled due "
    619           1.1    bouyer 				    "to chip revision\n",
    620          1.17   thorpej 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    621           1.9   thorpej 				    chp->ch_channel, drive);
    622           1.1    bouyer 				mode = drvp->PIO_mode;
    623          1.18   thorpej 				s = splbio();
    624           1.1    bouyer 				drvp->drive_flags &= ~DRIVE_DMA;
    625          1.18   thorpej 				splx(s);
    626           1.1    bouyer 				goto pio;
    627           1.1    bouyer 			}
    628           1.1    bouyer #endif
    629           1.1    bouyer 			/* mode = min(pio, dma+2) */
    630           1.3     enami 			if (drvp->PIO_mode <= (drvp->DMA_mode + 2))
    631           1.1    bouyer 				mode = drvp->PIO_mode;
    632           1.1    bouyer 			else
    633           1.1    bouyer 				mode = drvp->DMA_mode + 2;
    634           1.1    bouyer 		}
    635           1.1    bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    636           1.1    bouyer 
    637           1.1    bouyer pio:		/* setup PIO mode */
    638           1.1    bouyer 		if (mode <= 2) {
    639           1.1    bouyer 			drvp->DMA_mode = 0;
    640           1.1    bouyer 			drvp->PIO_mode = 0;
    641           1.1    bouyer 			mode = 0;
    642           1.1    bouyer 		} else {
    643           1.1    bouyer 			drvp->PIO_mode = mode;
    644           1.1    bouyer 			drvp->DMA_mode = mode - 2;
    645           1.1    bouyer 		}
    646           1.1    bouyer 		datatim_reg |=
    647           1.9   thorpej 		    APO_DATATIM_PULSE(chp->ch_channel, drive,
    648           1.1    bouyer 			apollo_pio_set[mode]) |
    649           1.9   thorpej 		    APO_DATATIM_RECOV(chp->ch_channel, drive,
    650           1.1    bouyer 			apollo_pio_rec[mode]);
    651           1.1    bouyer 	}
    652           1.1    bouyer 	if (idedma_ctl != 0) {
    653           1.1    bouyer 		/* Add software bits in status register */
    654           1.7      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    655           1.1    bouyer 		    idedma_ctl);
    656           1.1    bouyer 	}
    657           1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc), datatim_reg);
    658           1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_UDMA(sc), udmatim_reg);
    659          1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    660           1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    661           1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))), DEBUG_PROBE);
    662           1.1    bouyer }
    663           1.1    bouyer 
    664          1.35    bouyer static int
    665          1.35    bouyer via_sata_chip_map_common(struct pciide_softc *sc, struct pci_attach_args *pa)
    666           1.1    bouyer {
    667          1.35    bouyer 	bus_size_t satasize;
    668          1.36    bouyer 	int maptype, ret;
    669           1.1    bouyer 
    670           1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    671          1.35    bouyer 		return 0;
    672           1.1    bouyer 
    673           1.1    bouyer 	aprint_normal("%s: bus-master DMA support present",
    674          1.17   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    675           1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    676           1.1    bouyer 	aprint_normal("\n");
    677           1.1    bouyer 
    678           1.1    bouyer 	if (sc->sc_dma_ok) {
    679          1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
    680           1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    681           1.1    bouyer 	}
    682          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    683          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    684          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    685          1.17   thorpej 
    686          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    687          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    688          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    689          1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    690           1.1    bouyer 
    691      1.37.2.2    bouyer 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    692      1.37.2.2    bouyer 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    693      1.37.2.2    bouyer 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    694      1.37.2.2    bouyer 
    695          1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    696          1.36    bouyer 	maptype = pci_mapreg_type(pa->pa_pc, pa->pa_tag,
    697          1.36    bouyer 	    PCI_MAPREG_START + 0x14);
    698          1.36    bouyer 	switch(maptype) {
    699          1.36    bouyer 	case PCI_MAPREG_TYPE_IO:
    700          1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    701          1.36    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    702          1.36    bouyer 		    NULL, &satasize);
    703          1.36    bouyer 		break;
    704          1.36    bouyer 	case PCI_MAPREG_MEM_TYPE_32BIT:
    705          1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    706          1.35    bouyer 		    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    707          1.35    bouyer 		    0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    708          1.36    bouyer 		    NULL, &satasize);
    709          1.36    bouyer 		break;
    710          1.36    bouyer 	default:
    711          1.36    bouyer 		aprint_error("%s: couldn't map sata regs, unsupported"
    712          1.36    bouyer 		    "maptype (0x%x)\n", sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    713          1.36    bouyer 		    maptype);
    714          1.36    bouyer 		return 0;
    715          1.36    bouyer 	}
    716          1.36    bouyer 	if (ret != 0) {
    717          1.36    bouyer 		aprint_error("%s: couldn't map sata regs\n",
    718          1.36    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    719          1.36    bouyer 		return 0;
    720          1.35    bouyer 	}
    721          1.35    bouyer 	return 1;
    722          1.35    bouyer }
    723          1.35    bouyer 
    724          1.35    bouyer static void
    725          1.35    bouyer via_sata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa,
    726          1.35    bouyer     int satareg_shift)
    727          1.35    bouyer {
    728          1.35    bouyer 	struct pciide_channel *cp;
    729          1.35    bouyer 	struct ata_channel *wdc_cp;
    730          1.35    bouyer 	struct wdc_regs *wdr;
    731          1.35    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    732          1.35    bouyer 	int channel;
    733          1.35    bouyer 	bus_size_t cmdsize, ctlsize;
    734          1.35    bouyer 
    735          1.35    bouyer 	if (via_sata_chip_map_common(sc, pa) == 0)
    736          1.35    bouyer 		return;
    737          1.35    bouyer 
    738          1.35    bouyer 	if (interface == 0) {
    739          1.35    bouyer 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    740          1.35    bouyer 		    DEBUG_PROBE);
    741          1.35    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    742          1.35    bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    743          1.35    bouyer 	}
    744          1.15   thorpej 
    745          1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    746          1.17   thorpej 	     channel++) {
    747           1.1    bouyer 		cp = &sc->pciide_channels[channel];
    748           1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    749           1.1    bouyer 			continue;
    750          1.35    bouyer 		wdc_cp = &cp->ata_channel;
    751          1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    752          1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
    753          1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
    754          1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    755          1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x0, 1,
    756          1.35    bouyer 		    &wdr->sata_status) != 0) {
    757          1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    758          1.35    bouyer 			    "sata_status regs\n",
    759          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    760          1.35    bouyer 			    wdc_cp->ch_channel);
    761          1.35    bouyer 			continue;
    762          1.35    bouyer 		}
    763          1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    764          1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x4, 1,
    765          1.35    bouyer 		    &wdr->sata_error) != 0) {
    766          1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    767          1.35    bouyer 			    "sata_error regs\n",
    768          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    769          1.35    bouyer 			    wdc_cp->ch_channel);
    770          1.35    bouyer 			continue;
    771          1.35    bouyer 		}
    772          1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    773          1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x8, 1,
    774          1.35    bouyer 		    &wdr->sata_control) != 0) {
    775          1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    776          1.35    bouyer 			    "sata_control regs\n",
    777          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    778          1.35    bouyer 			    wdc_cp->ch_channel);
    779          1.35    bouyer 			continue;
    780          1.35    bouyer 		}
    781          1.35    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    782           1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    783           1.3     enami 		    pciide_pci_intr);
    784           1.1    bouyer 	}
    785           1.1    bouyer }
    786          1.35    bouyer 
    787          1.35    bouyer static void
    788          1.35    bouyer via_sata_chip_map_0(struct pciide_softc *sc, struct pci_attach_args *pa)
    789          1.35    bouyer {
    790          1.35    bouyer 	via_sata_chip_map(sc, pa, 0);
    791          1.35    bouyer }
    792          1.35    bouyer 
    793          1.35    bouyer static void
    794          1.35    bouyer via_sata_chip_map_6(struct pciide_softc *sc, struct pci_attach_args *pa)
    795          1.35    bouyer {
    796          1.35    bouyer 	via_sata_chip_map(sc, pa, 6);
    797          1.35    bouyer }
    798          1.35    bouyer 
    799          1.35    bouyer static void
    800          1.35    bouyer via_sata_chip_map_7(struct pciide_softc *sc, struct pci_attach_args *pa)
    801          1.35    bouyer {
    802          1.35    bouyer 	via_sata_chip_map(sc, pa, 7);
    803          1.35    bouyer }
    804          1.35    bouyer 
    805          1.35    bouyer static void
    806          1.35    bouyer via_sata_chip_map_new(struct pciide_softc *sc, struct pci_attach_args *pa)
    807          1.35    bouyer {
    808          1.35    bouyer 	struct pciide_channel *cp;
    809          1.35    bouyer 	struct ata_channel *wdc_cp;
    810          1.35    bouyer 	struct wdc_regs *wdr;
    811          1.35    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    812          1.35    bouyer 	int channel;
    813          1.35    bouyer 	bus_size_t cmdsize;
    814          1.35    bouyer 	pci_intr_handle_t intrhandle;
    815          1.35    bouyer 	const char *intrstr;
    816          1.35    bouyer 	int i;
    817          1.35    bouyer 
    818          1.35    bouyer 	if (via_sata_chip_map_common(sc, pa) == 0)
    819          1.35    bouyer 		return;
    820          1.35    bouyer 
    821          1.35    bouyer 	if (interface == 0) {
    822          1.35    bouyer 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    823          1.35    bouyer 		    DEBUG_PROBE);
    824          1.35    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    825          1.35    bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    826          1.35    bouyer 	}
    827          1.35    bouyer 
    828          1.35    bouyer 	if (pci_intr_map(pa, &intrhandle) != 0) {
    829          1.35    bouyer 		aprint_error("%s: couldn't map native-PCI interrupt\n",
    830          1.35    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    831          1.35    bouyer 		return;
    832          1.35    bouyer 	}
    833          1.35    bouyer 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    834          1.35    bouyer 	sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    835          1.35    bouyer 	    intrhandle, IPL_BIO, pciide_pci_intr, sc);
    836          1.35    bouyer 	if (sc->sc_pci_ih == NULL) {
    837          1.35    bouyer 		aprint_error(
    838          1.35    bouyer 		    "%s: couldn't establish native-PCI interrupt",
    839          1.35    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    840          1.35    bouyer 		if (intrstr != NULL)
    841          1.35    bouyer 		    aprint_error(" at %s", intrstr);
    842          1.35    bouyer 		aprint_error("\n");
    843          1.35    bouyer 		return;
    844          1.35    bouyer 	}
    845          1.35    bouyer 	aprint_normal("%s: using %s for native-PCI interrupt\n",
    846          1.35    bouyer 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    847          1.35    bouyer 	    intrstr ? intrstr : "unknown interrupt");
    848          1.35    bouyer 
    849          1.35    bouyer 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    850          1.35    bouyer 	     channel++) {
    851          1.35    bouyer 		cp = &sc->pciide_channels[channel];
    852          1.35    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    853          1.35    bouyer 			continue;
    854          1.35    bouyer 		cp->ata_channel.ch_ndrive = 1;
    855          1.35    bouyer 		wdc_cp = &cp->ata_channel;
    856          1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    857          1.35    bouyer 
    858          1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
    859          1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
    860          1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    861          1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x0, 1,
    862          1.35    bouyer 		    &wdr->sata_status) != 0) {
    863          1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    864          1.35    bouyer 			    "sata_status regs\n",
    865          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    866          1.35    bouyer 			    wdc_cp->ch_channel);
    867          1.35    bouyer 			continue;
    868          1.35    bouyer 		}
    869          1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    870          1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x4, 1,
    871          1.35    bouyer 		    &wdr->sata_error) != 0) {
    872          1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    873          1.35    bouyer 			    "sata_error regs\n",
    874          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    875          1.35    bouyer 			    wdc_cp->ch_channel);
    876          1.35    bouyer 			continue;
    877          1.35    bouyer 		}
    878          1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    879          1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x8, 1,
    880          1.35    bouyer 		    &wdr->sata_control) != 0) {
    881          1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    882          1.35    bouyer 			    "sata_control regs\n",
    883          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    884          1.35    bouyer 			    wdc_cp->ch_channel);
    885          1.35    bouyer 			continue;
    886          1.35    bouyer 		}
    887          1.35    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    888          1.35    bouyer 
    889          1.35    bouyer 		if (pci_mapreg_map(pa, (0x10 + (4 * (channel))),
    890          1.35    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &wdr->cmd_iot, &wdr->cmd_baseioh,
    891          1.35    bouyer 		    NULL, &cmdsize) != 0) {
    892          1.35    bouyer 			aprint_error("%s: couldn't map %s channel regs\n",
    893          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    894          1.35    bouyer 			    cp->name);
    895          1.35    bouyer 		}
    896          1.35    bouyer 		wdr->ctl_iot = wdr->cmd_iot;
    897          1.35    bouyer 		for (i = 0; i < WDC_NREG; i++) {
    898          1.35    bouyer 			if (bus_space_subregion(wdr->cmd_iot,
    899          1.35    bouyer 			    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
    900          1.35    bouyer 			    &wdr->cmd_iohs[i]) != 0) {
    901          1.35    bouyer 				aprint_error("%s: couldn't subregion %s "
    902          1.35    bouyer 				    "channel cmd regs\n",
    903          1.35    bouyer 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    904          1.35    bouyer 				    cp->name);
    905          1.35    bouyer 				return;
    906          1.35    bouyer 			}
    907          1.35    bouyer 		}
    908          1.35    bouyer 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    909          1.35    bouyer 		    WDC_NREG + 2, 1,  &wdr->ctl_ioh) != 0) {
    910          1.35    bouyer 			aprint_error("%s: couldn't map channel %d ctl regs\n",
    911          1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
    912          1.35    bouyer 			return;
    913          1.35    bouyer 		}
    914          1.35    bouyer 		wdc_init_shadow_regs(wdc_cp);
    915          1.35    bouyer 		wdcattach(wdc_cp);
    916          1.35    bouyer 	}
    917          1.35    bouyer }
    918