Home | History | Annotate | Line # | Download | only in pci
viaide.c revision 1.40
      1  1.40   mlelstv /*	$NetBSD: viaide.c,v 1.40 2007/02/10 10:23:18 mlelstv 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.40   mlelstv __KERNEL_RCSID(0, "$NetBSD: viaide.c,v 1.40 2007/02/10 10:23:18 mlelstv 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.38     isaki 	{ PCI_PRODUCT_AMD_CS5536_IDE,
     91  1.38     isaki 	  0,
     92  1.38     isaki 	  "Advanced Micro Devices CS5536 IDE Controller",
     93  1.38     isaki 	  via_chip_map
     94  1.38     isaki 	},
     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.35    bouyer 	  via_sata_chip_map_0,
    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.40   mlelstv 		case PCI_PRODUCT_VIATECH_VT8237A_ISA:
    422  1.40   mlelstv 			aprint_normal("VT8237A ATA133 controller\n");
    423  1.40   mlelstv 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    424  1.40   mlelstv 			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.1    bouyer 		case PCI_PRODUCT_AMD_PBC766_IDE:
    438   1.1    bouyer 		case PCI_PRODUCT_AMD_PBC768_IDE:
    439  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    440   1.1    bouyer 			break;
    441   1.1    bouyer 		default:
    442  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    443   1.1    bouyer 		}
    444   1.1    bouyer 		sc->sc_apo_regbase = APO_AMD_REGBASE;
    445   1.1    bouyer 		break;
    446   1.1    bouyer 	case PCI_VENDOR_NVIDIA:
    447   1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    448   1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE_ATA100:
    449  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    450   1.1    bouyer 			break;
    451   1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133:
    452  1.20  jdolecek 		case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133:
    453   1.5      fvdl 		case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133:
    454  1.19   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133:
    455  1.21      kent 		case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133:
    456  1.28   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE430_ATA133:
    457  1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP04_IDE:
    458  1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP55_IDE:
    459  1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP61_IDE:
    460  1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP65_IDE:
    461  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    462   1.1    bouyer 			break;
    463   1.1    bouyer 		}
    464   1.1    bouyer 		sc->sc_apo_regbase = APO_NVIDIA_REGBASE;
    465   1.1    bouyer 		break;
    466   1.1    bouyer 	default:
    467   1.1    bouyer 		panic("via_chip_map: unknown vendor");
    468   1.1    bouyer 	}
    469   1.3     enami 
    470  1.39        ad 	aprint_verbose("%s: bus-master DMA support present",
    471  1.17   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    472   1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    473  1.39        ad 	aprint_verbose("\n");
    474  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    475   1.1    bouyer 	if (sc->sc_dma_ok) {
    476  1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    477   1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    478  1.17   thorpej 		if (sc->sc_wdcdev.sc_atac.atac_udma_cap > 0)
    479  1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
    480   1.1    bouyer 	}
    481  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    482  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    483  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = via_setup_channel;
    484  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    485  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    486   1.1    bouyer 
    487  1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    488  1.15   thorpej 
    489  1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
    490   1.1    bouyer 	    "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    491   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc)),
    492   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc)),
    493   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    494   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))),
    495   1.1    bouyer 	    DEBUG_PROBE);
    496   1.1    bouyer 
    497   1.1    bouyer 	ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
    498  1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    499  1.17   thorpej 	     channel++) {
    500   1.1    bouyer 		cp = &sc->pciide_channels[channel];
    501   1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    502   1.1    bouyer 			continue;
    503   1.1    bouyer 
    504   1.1    bouyer 		if ((ideconf & APO_IDECONF_EN(channel)) == 0) {
    505   1.1    bouyer 			aprint_normal("%s: %s channel ignored (disabled)\n",
    506  1.17   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    507  1.15   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    508   1.1    bouyer 			continue;
    509   1.1    bouyer 		}
    510   1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    511   1.1    bouyer 		    pciide_pci_intr);
    512   1.1    bouyer 	}
    513   1.1    bouyer }
    514   1.1    bouyer 
    515   1.2   thorpej static void
    516  1.15   thorpej via_setup_channel(struct ata_channel *chp)
    517   1.1    bouyer {
    518   1.1    bouyer 	u_int32_t udmatim_reg, datatim_reg;
    519   1.1    bouyer 	u_int8_t idedma_ctl;
    520  1.18   thorpej 	int mode, drive, s;
    521   1.1    bouyer 	struct ata_drive_datas *drvp;
    522  1.17   thorpej 	struct atac_softc *atac = chp->ch_atac;
    523  1.16   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    524  1.16   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    525   1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    526   1.1    bouyer 	int rev = PCI_REVISION(
    527   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
    528   1.1    bouyer #endif
    529   1.1    bouyer 
    530   1.1    bouyer 	idedma_ctl = 0;
    531   1.1    bouyer 	datatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
    532   1.1    bouyer 	udmatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc));
    533   1.9   thorpej 	datatim_reg &= ~APO_DATATIM_MASK(chp->ch_channel);
    534   1.9   thorpej 	udmatim_reg &= ~APO_UDMA_MASK(chp->ch_channel);
    535   1.1    bouyer 
    536   1.1    bouyer 	/* setup DMA if needed */
    537   1.1    bouyer 	pciide_channel_dma_setup(cp);
    538   1.1    bouyer 
    539   1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    540   1.1    bouyer 		drvp = &chp->ch_drive[drive];
    541   1.1    bouyer 		/* If no drive, skip */
    542   1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    543   1.1    bouyer 			continue;
    544   1.1    bouyer 		/* add timing values, setup DMA if needed */
    545   1.1    bouyer 		if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
    546   1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA) == 0)) {
    547   1.1    bouyer 			mode = drvp->PIO_mode;
    548   1.1    bouyer 			goto pio;
    549   1.1    bouyer 		}
    550  1.17   thorpej 		if ((atac->atac_cap & ATAC_CAP_UDMA) &&
    551   1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA)) {
    552   1.1    bouyer 			/* use Ultra/DMA */
    553  1.18   thorpej 			s = splbio();
    554   1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    555  1.18   thorpej 			splx(s);
    556   1.9   thorpej 			udmatim_reg |= APO_UDMA_EN(chp->ch_channel, drive) |
    557   1.9   thorpej 			    APO_UDMA_EN_MTH(chp->ch_channel, drive);
    558   1.3     enami 			switch (PCI_VENDOR(sc->sc_pci_id)) {
    559   1.1    bouyer 			case PCI_VENDOR_VIATECH:
    560  1.17   thorpej 				if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 6) {
    561   1.1    bouyer 					/* 8233a */
    562   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    563   1.9   thorpej 					    chp->ch_channel,
    564   1.1    bouyer 					    drive,
    565   1.1    bouyer 					    via_udma133_tim[drvp->UDMA_mode]);
    566  1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 5) {
    567   1.1    bouyer 					/* 686b */
    568   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    569   1.9   thorpej 					    chp->ch_channel,
    570   1.1    bouyer 					    drive,
    571   1.1    bouyer 					    via_udma100_tim[drvp->UDMA_mode]);
    572  1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 4) {
    573   1.1    bouyer 					/* 596b or 686a */
    574   1.1    bouyer 					udmatim_reg |= APO_UDMA_CLK66(
    575   1.9   thorpej 					    chp->ch_channel);
    576   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    577   1.9   thorpej 					    chp->ch_channel,
    578   1.1    bouyer 					    drive,
    579   1.1    bouyer 					    via_udma66_tim[drvp->UDMA_mode]);
    580   1.1    bouyer 				} else {
    581   1.1    bouyer 					/* 596a or 586b */
    582   1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    583   1.9   thorpej 					    chp->ch_channel,
    584   1.1    bouyer 					    drive,
    585   1.1    bouyer 					    via_udma33_tim[drvp->UDMA_mode]);
    586   1.1    bouyer 				}
    587   1.1    bouyer 				break;
    588   1.1    bouyer 			case PCI_VENDOR_AMD:
    589   1.1    bouyer 			case PCI_VENDOR_NVIDIA:
    590   1.9   thorpej 				udmatim_reg |= APO_UDMA_TIME(chp->ch_channel,
    591   1.1    bouyer 				    drive, amd7x6_udma_tim[drvp->UDMA_mode]);
    592   1.1    bouyer 				 break;
    593   1.1    bouyer 			}
    594   1.1    bouyer 			/* can use PIO timings, MW DMA unused */
    595   1.1    bouyer 			mode = drvp->PIO_mode;
    596   1.1    bouyer 		} else {
    597   1.1    bouyer 			/* use Multiword DMA, but only if revision is OK */
    598  1.18   thorpej 			s = splbio();
    599   1.1    bouyer 			drvp->drive_flags &= ~DRIVE_UDMA;
    600  1.18   thorpej 			splx(s);
    601   1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    602   1.1    bouyer 			/*
    603   1.1    bouyer 			 * The workaround doesn't seem to be necessary
    604   1.1    bouyer 			 * with all drives, so it can be disabled by
    605   1.1    bouyer 			 * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
    606   1.1    bouyer 			 * triggered.
    607   1.1    bouyer 			 */
    608   1.1    bouyer 			if (PCI_VENDOR(sc->sc_pci_id) == PCI_VENDOR_AMD &&
    609   1.1    bouyer 			    sc->sc_pp->ide_product ==
    610   1.3     enami 			    PCI_PRODUCT_AMD_PBC756_IDE &&
    611   1.1    bouyer 			    AMD756_CHIPREV_DISABLEDMA(rev)) {
    612   1.1    bouyer 				aprint_normal(
    613   1.1    bouyer 				    "%s:%d:%d: multi-word DMA disabled due "
    614   1.1    bouyer 				    "to chip revision\n",
    615  1.17   thorpej 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    616   1.9   thorpej 				    chp->ch_channel, drive);
    617   1.1    bouyer 				mode = drvp->PIO_mode;
    618  1.18   thorpej 				s = splbio();
    619   1.1    bouyer 				drvp->drive_flags &= ~DRIVE_DMA;
    620  1.18   thorpej 				splx(s);
    621   1.1    bouyer 				goto pio;
    622   1.1    bouyer 			}
    623   1.1    bouyer #endif
    624   1.1    bouyer 			/* mode = min(pio, dma+2) */
    625   1.3     enami 			if (drvp->PIO_mode <= (drvp->DMA_mode + 2))
    626   1.1    bouyer 				mode = drvp->PIO_mode;
    627   1.1    bouyer 			else
    628   1.1    bouyer 				mode = drvp->DMA_mode + 2;
    629   1.1    bouyer 		}
    630   1.1    bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    631   1.1    bouyer 
    632   1.1    bouyer pio:		/* setup PIO mode */
    633   1.1    bouyer 		if (mode <= 2) {
    634   1.1    bouyer 			drvp->DMA_mode = 0;
    635   1.1    bouyer 			drvp->PIO_mode = 0;
    636   1.1    bouyer 			mode = 0;
    637   1.1    bouyer 		} else {
    638   1.1    bouyer 			drvp->PIO_mode = mode;
    639   1.1    bouyer 			drvp->DMA_mode = mode - 2;
    640   1.1    bouyer 		}
    641   1.1    bouyer 		datatim_reg |=
    642   1.9   thorpej 		    APO_DATATIM_PULSE(chp->ch_channel, drive,
    643   1.1    bouyer 			apollo_pio_set[mode]) |
    644   1.9   thorpej 		    APO_DATATIM_RECOV(chp->ch_channel, drive,
    645   1.1    bouyer 			apollo_pio_rec[mode]);
    646   1.1    bouyer 	}
    647   1.1    bouyer 	if (idedma_ctl != 0) {
    648   1.1    bouyer 		/* Add software bits in status register */
    649   1.7      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    650   1.1    bouyer 		    idedma_ctl);
    651   1.1    bouyer 	}
    652   1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc), datatim_reg);
    653   1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_UDMA(sc), udmatim_reg);
    654  1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    655   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    656   1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))), DEBUG_PROBE);
    657   1.1    bouyer }
    658   1.1    bouyer 
    659  1.35    bouyer static int
    660  1.35    bouyer via_sata_chip_map_common(struct pciide_softc *sc, struct pci_attach_args *pa)
    661   1.1    bouyer {
    662  1.35    bouyer 	bus_size_t satasize;
    663  1.36    bouyer 	int maptype, ret;
    664   1.1    bouyer 
    665   1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    666  1.35    bouyer 		return 0;
    667   1.1    bouyer 
    668  1.39        ad 	aprint_verbose("%s: bus-master DMA support present",
    669  1.17   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    670   1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    671  1.39        ad 	aprint_verbose("\n");
    672   1.1    bouyer 
    673   1.1    bouyer 	if (sc->sc_dma_ok) {
    674  1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
    675   1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    676   1.1    bouyer 	}
    677  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    678  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    679  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    680  1.17   thorpej 
    681  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    682  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    683  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    684  1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    685   1.1    bouyer 
    686  1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    687  1.36    bouyer 	maptype = pci_mapreg_type(pa->pa_pc, pa->pa_tag,
    688  1.36    bouyer 	    PCI_MAPREG_START + 0x14);
    689  1.36    bouyer 	switch(maptype) {
    690  1.36    bouyer 	case PCI_MAPREG_TYPE_IO:
    691  1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    692  1.36    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    693  1.36    bouyer 		    NULL, &satasize);
    694  1.36    bouyer 		break;
    695  1.36    bouyer 	case PCI_MAPREG_MEM_TYPE_32BIT:
    696  1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    697  1.35    bouyer 		    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    698  1.35    bouyer 		    0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    699  1.36    bouyer 		    NULL, &satasize);
    700  1.36    bouyer 		break;
    701  1.36    bouyer 	default:
    702  1.36    bouyer 		aprint_error("%s: couldn't map sata regs, unsupported"
    703  1.36    bouyer 		    "maptype (0x%x)\n", sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    704  1.36    bouyer 		    maptype);
    705  1.36    bouyer 		return 0;
    706  1.36    bouyer 	}
    707  1.36    bouyer 	if (ret != 0) {
    708  1.36    bouyer 		aprint_error("%s: couldn't map sata regs\n",
    709  1.36    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    710  1.36    bouyer 		return 0;
    711  1.35    bouyer 	}
    712  1.35    bouyer 	return 1;
    713  1.35    bouyer }
    714  1.35    bouyer 
    715  1.35    bouyer static void
    716  1.35    bouyer via_sata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa,
    717  1.35    bouyer     int satareg_shift)
    718  1.35    bouyer {
    719  1.35    bouyer 	struct pciide_channel *cp;
    720  1.35    bouyer 	struct ata_channel *wdc_cp;
    721  1.35    bouyer 	struct wdc_regs *wdr;
    722  1.35    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    723  1.35    bouyer 	int channel;
    724  1.35    bouyer 	bus_size_t cmdsize, ctlsize;
    725  1.35    bouyer 
    726  1.35    bouyer 	if (via_sata_chip_map_common(sc, pa) == 0)
    727  1.35    bouyer 		return;
    728  1.35    bouyer 
    729  1.35    bouyer 	if (interface == 0) {
    730  1.35    bouyer 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    731  1.35    bouyer 		    DEBUG_PROBE);
    732  1.35    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    733  1.35    bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    734  1.35    bouyer 	}
    735  1.15   thorpej 
    736  1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    737  1.17   thorpej 	     channel++) {
    738   1.1    bouyer 		cp = &sc->pciide_channels[channel];
    739   1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    740   1.1    bouyer 			continue;
    741  1.35    bouyer 		wdc_cp = &cp->ata_channel;
    742  1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    743  1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
    744  1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
    745  1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    746  1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x0, 1,
    747  1.35    bouyer 		    &wdr->sata_status) != 0) {
    748  1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    749  1.35    bouyer 			    "sata_status regs\n",
    750  1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    751  1.35    bouyer 			    wdc_cp->ch_channel);
    752  1.35    bouyer 			continue;
    753  1.35    bouyer 		}
    754  1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    755  1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x4, 1,
    756  1.35    bouyer 		    &wdr->sata_error) != 0) {
    757  1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    758  1.35    bouyer 			    "sata_error 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) + 0x8, 1,
    765  1.35    bouyer 		    &wdr->sata_control) != 0) {
    766  1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    767  1.35    bouyer 			    "sata_control 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 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    773   1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    774   1.3     enami 		    pciide_pci_intr);
    775   1.1    bouyer 	}
    776   1.1    bouyer }
    777  1.35    bouyer 
    778  1.35    bouyer static void
    779  1.35    bouyer via_sata_chip_map_0(struct pciide_softc *sc, struct pci_attach_args *pa)
    780  1.35    bouyer {
    781  1.35    bouyer 	via_sata_chip_map(sc, pa, 0);
    782  1.35    bouyer }
    783  1.35    bouyer 
    784  1.35    bouyer static void
    785  1.35    bouyer via_sata_chip_map_6(struct pciide_softc *sc, struct pci_attach_args *pa)
    786  1.35    bouyer {
    787  1.35    bouyer 	via_sata_chip_map(sc, pa, 6);
    788  1.35    bouyer }
    789  1.35    bouyer 
    790  1.35    bouyer static void
    791  1.35    bouyer via_sata_chip_map_7(struct pciide_softc *sc, struct pci_attach_args *pa)
    792  1.35    bouyer {
    793  1.35    bouyer 	via_sata_chip_map(sc, pa, 7);
    794  1.35    bouyer }
    795  1.35    bouyer 
    796  1.35    bouyer static void
    797  1.35    bouyer via_sata_chip_map_new(struct pciide_softc *sc, struct pci_attach_args *pa)
    798  1.35    bouyer {
    799  1.35    bouyer 	struct pciide_channel *cp;
    800  1.35    bouyer 	struct ata_channel *wdc_cp;
    801  1.35    bouyer 	struct wdc_regs *wdr;
    802  1.35    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    803  1.35    bouyer 	int channel;
    804  1.35    bouyer 	bus_size_t cmdsize;
    805  1.35    bouyer 	pci_intr_handle_t intrhandle;
    806  1.35    bouyer 	const char *intrstr;
    807  1.35    bouyer 	int i;
    808  1.35    bouyer 
    809  1.35    bouyer 	if (via_sata_chip_map_common(sc, pa) == 0)
    810  1.35    bouyer 		return;
    811  1.35    bouyer 
    812  1.35    bouyer 	if (interface == 0) {
    813  1.35    bouyer 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    814  1.35    bouyer 		    DEBUG_PROBE);
    815  1.35    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    816  1.35    bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    817  1.35    bouyer 	}
    818  1.35    bouyer 
    819  1.35    bouyer 	if (pci_intr_map(pa, &intrhandle) != 0) {
    820  1.35    bouyer 		aprint_error("%s: couldn't map native-PCI interrupt\n",
    821  1.35    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    822  1.35    bouyer 		return;
    823  1.35    bouyer 	}
    824  1.35    bouyer 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    825  1.35    bouyer 	sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    826  1.35    bouyer 	    intrhandle, IPL_BIO, pciide_pci_intr, sc);
    827  1.35    bouyer 	if (sc->sc_pci_ih == NULL) {
    828  1.35    bouyer 		aprint_error(
    829  1.35    bouyer 		    "%s: couldn't establish native-PCI interrupt",
    830  1.35    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    831  1.35    bouyer 		if (intrstr != NULL)
    832  1.35    bouyer 		    aprint_error(" at %s", intrstr);
    833  1.35    bouyer 		aprint_error("\n");
    834  1.35    bouyer 		return;
    835  1.35    bouyer 	}
    836  1.35    bouyer 	aprint_normal("%s: using %s for native-PCI interrupt\n",
    837  1.35    bouyer 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    838  1.35    bouyer 	    intrstr ? intrstr : "unknown interrupt");
    839  1.35    bouyer 
    840  1.35    bouyer 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    841  1.35    bouyer 	     channel++) {
    842  1.35    bouyer 		cp = &sc->pciide_channels[channel];
    843  1.35    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    844  1.35    bouyer 			continue;
    845  1.35    bouyer 		cp->ata_channel.ch_ndrive = 1;
    846  1.35    bouyer 		wdc_cp = &cp->ata_channel;
    847  1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    848  1.35    bouyer 
    849  1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
    850  1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
    851  1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    852  1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x0, 1,
    853  1.35    bouyer 		    &wdr->sata_status) != 0) {
    854  1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    855  1.35    bouyer 			    "sata_status regs\n",
    856  1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    857  1.35    bouyer 			    wdc_cp->ch_channel);
    858  1.35    bouyer 			continue;
    859  1.35    bouyer 		}
    860  1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    861  1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x4, 1,
    862  1.35    bouyer 		    &wdr->sata_error) != 0) {
    863  1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    864  1.35    bouyer 			    "sata_error 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) + 0x8, 1,
    871  1.35    bouyer 		    &wdr->sata_control) != 0) {
    872  1.35    bouyer 			aprint_error("%s: couldn't map channel %d "
    873  1.35    bouyer 			    "sata_control 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 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    879  1.35    bouyer 
    880  1.35    bouyer 		if (pci_mapreg_map(pa, (0x10 + (4 * (channel))),
    881  1.35    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &wdr->cmd_iot, &wdr->cmd_baseioh,
    882  1.35    bouyer 		    NULL, &cmdsize) != 0) {
    883  1.35    bouyer 			aprint_error("%s: couldn't map %s channel regs\n",
    884  1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    885  1.35    bouyer 			    cp->name);
    886  1.35    bouyer 		}
    887  1.35    bouyer 		wdr->ctl_iot = wdr->cmd_iot;
    888  1.35    bouyer 		for (i = 0; i < WDC_NREG; i++) {
    889  1.35    bouyer 			if (bus_space_subregion(wdr->cmd_iot,
    890  1.35    bouyer 			    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
    891  1.35    bouyer 			    &wdr->cmd_iohs[i]) != 0) {
    892  1.35    bouyer 				aprint_error("%s: couldn't subregion %s "
    893  1.35    bouyer 				    "channel cmd regs\n",
    894  1.35    bouyer 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    895  1.35    bouyer 				    cp->name);
    896  1.35    bouyer 				return;
    897  1.35    bouyer 			}
    898  1.35    bouyer 		}
    899  1.35    bouyer 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    900  1.35    bouyer 		    WDC_NREG + 2, 1,  &wdr->ctl_ioh) != 0) {
    901  1.35    bouyer 			aprint_error("%s: couldn't map channel %d ctl regs\n",
    902  1.35    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
    903  1.35    bouyer 			return;
    904  1.35    bouyer 		}
    905  1.35    bouyer 		wdc_init_shadow_regs(wdc_cp);
    906  1.35    bouyer 		wdcattach(wdc_cp);
    907  1.35    bouyer 	}
    908  1.35    bouyer }
    909