Home | History | Annotate | Line # | Download | only in pci
viaide.c revision 1.83.2.2
      1  1.83.2.2       tls /*	$NetBSD: viaide.c,v 1.83.2.2 2014/08/20 00:03:48 tls 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  *
     15       1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16       1.1    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17       1.1    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18      1.24     perry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19       1.1    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20       1.1    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21       1.1    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22       1.1    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23       1.1    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24       1.1    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25       1.1    bouyer  *
     26       1.1    bouyer  */
     27       1.1    bouyer 
     28      1.25     lukem #include <sys/cdefs.h>
     29  1.83.2.2       tls __KERNEL_RCSID(0, "$NetBSD: viaide.c,v 1.83.2.2 2014/08/20 00:03:48 tls Exp $");
     30      1.25     lukem 
     31       1.1    bouyer #include <sys/param.h>
     32       1.1    bouyer #include <sys/systm.h>
     33      1.76  jakllsch #include <sys/malloc.h>
     34       1.1    bouyer 
     35       1.1    bouyer #include <dev/pci/pcivar.h>
     36       1.1    bouyer #include <dev/pci/pcidevs.h>
     37       1.1    bouyer #include <dev/pci/pciidereg.h>
     38       1.1    bouyer #include <dev/pci/pciidevar.h>
     39       1.1    bouyer #include <dev/pci/pciide_apollo_reg.h>
     40       1.1    bouyer 
     41      1.72    dyoung static int	via_pcib_match(const struct pci_attach_args *);
     42      1.72    dyoung static void	via_chip_map(struct pciide_softc *,
     43      1.72    dyoung 		    const struct pci_attach_args *);
     44      1.72    dyoung static void	via_mapchan(const struct pci_attach_args *,
     45      1.72    dyoung 		    struct pciide_channel *,
     46      1.70  jakllsch 		    pcireg_t, int (*)(void *));
     47      1.72    dyoung static void	via_mapregs_compat_native(const struct pci_attach_args *,
     48      1.70  jakllsch 		    struct pciide_channel *);
     49      1.35    bouyer static int	via_sata_chip_map_common(struct pciide_softc *,
     50      1.76  jakllsch 		    const struct pci_attach_args *);
     51       1.4     enami static void	via_sata_chip_map(struct pciide_softc *,
     52      1.72    dyoung 		    const struct pci_attach_args *, int);
     53      1.35    bouyer static void	via_sata_chip_map_6(struct pciide_softc *,
     54      1.72    dyoung 		    const struct pci_attach_args *);
     55      1.35    bouyer static void	via_sata_chip_map_7(struct pciide_softc *,
     56      1.72    dyoung 		    const struct pci_attach_args *);
     57      1.35    bouyer static void	via_sata_chip_map_new(struct pciide_softc *,
     58      1.72    dyoung 		    const struct pci_attach_args *);
     59      1.15   thorpej static void	via_setup_channel(struct ata_channel *);
     60       1.4     enami 
     61      1.53      cube static int	viaide_match(device_t, cfdata_t, void *);
     62      1.53      cube static void	viaide_attach(device_t, device_t, void *);
     63       1.4     enami static const struct pciide_product_desc *
     64       1.4     enami 		viaide_lookup(pcireg_t);
     65      1.68    dyoung static bool	viaide_suspend(device_t, const pmf_qual_t *);
     66      1.68    dyoung static bool	viaide_resume(device_t, const pmf_qual_t *);
     67       1.1    bouyer 
     68      1.53      cube CFATTACH_DECL_NEW(viaide, sizeof(struct pciide_softc),
     69      1.71  jakllsch     viaide_match, viaide_attach, pciide_detach, NULL);
     70       1.1    bouyer 
     71       1.2   thorpej static const struct pciide_product_desc pciide_amd_products[] =  {
     72       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC756_IDE,
     73       1.1    bouyer 	  0,
     74      1.59  jmcneill 	  "AMD AMD756 IDE Controller",
     75       1.1    bouyer 	  via_chip_map
     76       1.1    bouyer 	},
     77       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC766_IDE,
     78       1.1    bouyer 	  0,
     79      1.59  jmcneill 	  "AMD AMD766 IDE Controller",
     80       1.1    bouyer 	  via_chip_map
     81       1.1    bouyer 	},
     82       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC768_IDE,
     83       1.1    bouyer 	  0,
     84      1.59  jmcneill 	  "AMD AMD768 IDE Controller",
     85       1.1    bouyer 	  via_chip_map
     86       1.1    bouyer 	},
     87       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC8111_IDE,
     88       1.1    bouyer 	  0,
     89      1.59  jmcneill 	  "AMD AMD8111 IDE Controller",
     90       1.1    bouyer 	  via_chip_map
     91       1.1    bouyer 	},
     92      1.38     isaki 	{ PCI_PRODUCT_AMD_CS5536_IDE,
     93      1.38     isaki 	  0,
     94      1.59  jmcneill 	  "AMD CS5536 IDE Controller",
     95      1.38     isaki 	  via_chip_map
     96      1.38     isaki 	},
     97       1.1    bouyer 	{ 0,
     98       1.1    bouyer 	  0,
     99       1.1    bouyer 	  NULL,
    100       1.1    bouyer 	  NULL
    101       1.1    bouyer 	}
    102       1.1    bouyer };
    103       1.1    bouyer 
    104       1.2   thorpej static const struct pciide_product_desc pciide_nvidia_products[] = {
    105       1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE_ATA100,
    106       1.1    bouyer 	  0,
    107       1.1    bouyer 	  "NVIDIA nForce IDE Controller",
    108       1.1    bouyer 	  via_chip_map
    109       1.1    bouyer 	},
    110       1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE2_ATA133,
    111       1.1    bouyer 	  0,
    112       1.1    bouyer 	  "NVIDIA nForce2 IDE Controller",
    113       1.1    bouyer 	  via_chip_map
    114       1.1    bouyer 	},
    115      1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133,
    116      1.20  jdolecek 	  0,
    117      1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 IDE Controller",
    118      1.20  jdolecek 	  via_chip_map
    119      1.20  jdolecek 	},
    120      1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_SATA,
    121      1.20  jdolecek 	  0,
    122      1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 Serial ATA Controller",
    123      1.35    bouyer 	  via_sata_chip_map_6
    124      1.20  jdolecek 	},
    125      1.10      fvdl 	{ PCI_PRODUCT_NVIDIA_NFORCE3_ATA133,
    126      1.10      fvdl 	  0,
    127      1.10      fvdl 	  "NVIDIA nForce3 IDE Controller",
    128      1.10      fvdl 	  via_chip_map
    129      1.10      fvdl 	},
    130      1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133,
    131      1.19   xtraeme 	  0,
    132      1.19   xtraeme 	  "NVIDIA nForce3 250 IDE Controller",
    133      1.19   xtraeme 	  via_chip_map
    134      1.19   xtraeme 	},
    135      1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA,
    136      1.19   xtraeme 	  0,
    137      1.19   xtraeme 	  "NVIDIA nForce3 250 Serial ATA Controller",
    138      1.35    bouyer 	  via_sata_chip_map_6
    139      1.19   xtraeme 	},
    140      1.32   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA2,
    141      1.32   xtraeme 	  0,
    142      1.32   xtraeme 	  "NVIDIA nForce3 250 Serial ATA Controller",
    143      1.35    bouyer 	  via_sata_chip_map_6
    144      1.32   xtraeme 	},
    145      1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_ATA133,
    146      1.21      kent 	  0,
    147      1.21      kent 	  "NVIDIA nForce4 IDE Controller",
    148      1.21      kent 	  via_chip_map
    149      1.21      kent 	},
    150      1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA1,
    151      1.21      kent 	  0,
    152      1.21      kent 	  "NVIDIA nForce4 Serial ATA Controller",
    153      1.35    bouyer 	  via_sata_chip_map_6
    154      1.21      kent 	},
    155      1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA2,
    156      1.21      kent 	  0,
    157      1.21      kent 	  "NVIDIA nForce4 Serial ATA Controller",
    158      1.35    bouyer 	  via_sata_chip_map_6
    159      1.21      kent 	},
    160      1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_ATA133,
    161      1.27      manu 	  0,
    162      1.27      manu 	  "NVIDIA nForce430 IDE Controller",
    163      1.27      manu 	  via_chip_map
    164      1.27      manu 	},
    165      1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_SATA1,
    166      1.27      manu 	  0,
    167      1.27      manu 	  "NVIDIA nForce430 Serial ATA Controller",
    168      1.35    bouyer 	  via_sata_chip_map_6
    169      1.27      manu 	},
    170      1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_SATA2,
    171      1.27      manu 	  0,
    172      1.27      manu 	  "NVIDIA nForce430 Serial ATA Controller",
    173      1.35    bouyer 	  via_sata_chip_map_6
    174      1.27      manu 	},
    175      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_IDE,
    176      1.30   xtraeme 	  0,
    177      1.30   xtraeme 	  "NVIDIA MCP04 IDE Controller",
    178      1.30   xtraeme 	  via_chip_map
    179      1.30   xtraeme 	},
    180      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_SATA,
    181      1.30   xtraeme 	  0,
    182      1.31   xtraeme 	  "NVIDIA MCP04 Serial ATA Controller",
    183      1.35    bouyer 	  via_sata_chip_map_6
    184      1.30   xtraeme 	},
    185      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_SATA2,
    186      1.30   xtraeme 	  0,
    187      1.31   xtraeme 	  "NVIDIA MCP04 Serial ATA Controller",
    188      1.35    bouyer 	  via_sata_chip_map_6
    189      1.30   xtraeme 	},
    190      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_IDE,
    191      1.30   xtraeme 	  0,
    192      1.30   xtraeme 	  "NVIDIA MCP55 IDE Controller",
    193      1.30   xtraeme 	  via_chip_map
    194      1.30   xtraeme 	},
    195      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_SATA,
    196      1.30   xtraeme 	  0,
    197      1.31   xtraeme 	  "NVIDIA MCP55 Serial ATA Controller",
    198      1.35    bouyer 	  via_sata_chip_map_6
    199      1.30   xtraeme 	},
    200      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_SATA2,
    201      1.30   xtraeme 	  0,
    202      1.31   xtraeme 	  "NVIDIA MCP55 Serial ATA Controller",
    203      1.35    bouyer 	  via_sata_chip_map_6
    204      1.30   xtraeme 	},
    205      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_IDE,
    206      1.33   xtraeme 	  0,
    207      1.33   xtraeme 	  "NVIDIA MCP61 IDE Controller",
    208      1.33   xtraeme 	  via_chip_map
    209      1.33   xtraeme 	},
    210      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_IDE,
    211      1.33   xtraeme 	  0,
    212      1.33   xtraeme 	  "NVIDIA MCP65 IDE Controller",
    213      1.33   xtraeme 	  via_chip_map
    214      1.33   xtraeme 	},
    215      1.46   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP73_IDE,
    216      1.46   xtraeme 	  0,
    217      1.46   xtraeme 	  "NVIDIA MCP73 IDE Controller",
    218      1.46   xtraeme 	  via_chip_map
    219      1.46   xtraeme 	},
    220      1.46   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP77_IDE,
    221      1.46   xtraeme 	  0,
    222      1.46   xtraeme 	  "NVIDIA MCP77 IDE Controller",
    223      1.46   xtraeme 	  via_chip_map
    224      1.46   xtraeme 	},
    225      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_SATA,
    226      1.33   xtraeme 	  0,
    227      1.33   xtraeme 	  "NVIDIA MCP61 Serial ATA Controller",
    228      1.35    bouyer 	  via_sata_chip_map_6
    229      1.33   xtraeme 	},
    230      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_SATA2,
    231      1.33   xtraeme 	  0,
    232      1.33   xtraeme 	  "NVIDIA MCP61 Serial ATA Controller",
    233      1.35    bouyer 	  via_sata_chip_map_6
    234      1.33   xtraeme 	},
    235      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_SATA3,
    236      1.33   xtraeme 	  0,
    237      1.33   xtraeme 	  "NVIDIA MCP61 Serial ATA Controller",
    238      1.35    bouyer 	  via_sata_chip_map_6
    239      1.33   xtraeme 	},
    240      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA,
    241      1.33   xtraeme 	  0,
    242      1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    243      1.35    bouyer 	  via_sata_chip_map_6
    244      1.33   xtraeme 	},
    245      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA2,
    246      1.33   xtraeme 	  0,
    247      1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    248      1.35    bouyer 	  via_sata_chip_map_6
    249      1.33   xtraeme 	},
    250      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA3,
    251      1.33   xtraeme 	  0,
    252      1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    253      1.35    bouyer 	  via_sata_chip_map_6
    254      1.33   xtraeme 	},
    255      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA4,
    256      1.33   xtraeme 	  0,
    257      1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    258      1.35    bouyer 	  via_sata_chip_map_6
    259      1.33   xtraeme 	},
    260      1.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_IDE,
    261      1.43   xtraeme 	  0,
    262      1.43   xtraeme 	  "NVIDIA MCP67 IDE Controller",
    263      1.43   xtraeme 	  via_chip_map,
    264      1.43   xtraeme 	},
    265      1.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_SATA,
    266      1.43   xtraeme 	  0,
    267      1.43   xtraeme 	  "NVIDIA MCP67 Serial ATA Controller",
    268      1.43   xtraeme 	  via_sata_chip_map_6,
    269      1.43   xtraeme 	},
    270      1.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_SATA2,
    271      1.43   xtraeme 	  0,
    272      1.43   xtraeme 	  "NVIDIA MCP67 Serial ATA Controller",
    273      1.43   xtraeme 	  via_sata_chip_map_6,
    274      1.43   xtraeme 	},
    275      1.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_SATA3,
    276      1.43   xtraeme 	  0,
    277      1.43   xtraeme 	  "NVIDIA MCP67 Serial ATA Controller",
    278      1.43   xtraeme 	  via_sata_chip_map_6,
    279      1.43   xtraeme 	},
    280      1.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_SATA4,
    281      1.43   xtraeme 	  0,
    282      1.43   xtraeme 	  "NVIDIA MCP67 Serial ATA Controller",
    283      1.43   xtraeme 	  via_sata_chip_map_6,
    284      1.43   xtraeme 	},
    285       1.1    bouyer 	{ 0,
    286       1.1    bouyer 	  0,
    287       1.1    bouyer 	  NULL,
    288       1.1    bouyer 	  NULL
    289       1.1    bouyer 	}
    290       1.1    bouyer };
    291       1.1    bouyer 
    292       1.2   thorpej static const struct pciide_product_desc pciide_via_products[] =  {
    293       1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586_IDE,
    294       1.1    bouyer 	  0,
    295       1.1    bouyer 	  NULL,
    296       1.1    bouyer 	  via_chip_map,
    297       1.1    bouyer 	 },
    298       1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586A_IDE,
    299       1.1    bouyer 	  0,
    300       1.1    bouyer 	  NULL,
    301       1.1    bouyer 	  via_chip_map,
    302       1.1    bouyer 	},
    303      1.42   xtraeme 	{ PCI_PRODUCT_VIATECH_CX700_IDE,
    304      1.42   xtraeme 	  0,
    305      1.44   xtraeme 	  NULL,
    306      1.42   xtraeme 	  via_chip_map,
    307      1.42   xtraeme 	},
    308      1.57     rmind 	{ PCI_PRODUCT_VIATECH_CX700M2_IDE,
    309      1.57     rmind 	  0,
    310      1.57     rmind 	  NULL,
    311      1.57     rmind 	  via_chip_map,
    312      1.57     rmind 	},
    313      1.78   tsutsui 	{ PCI_PRODUCT_VIATECH_VX900_IDE,
    314      1.78   tsutsui 	  0,
    315      1.78   tsutsui 	  NULL,
    316      1.78   tsutsui 	  via_chip_map,
    317      1.78   tsutsui 	},
    318      1.77       phx 	{ PCI_PRODUCT_VIATECH_VT6410_RAID,
    319      1.77       phx 	  0,
    320      1.77       phx 	  NULL,
    321      1.77       phx 	  via_chip_map,
    322      1.77       phx 	},
    323      1.23       abs 	{ PCI_PRODUCT_VIATECH_VT6421_RAID,
    324      1.22       abs 	  0,
    325      1.76  jakllsch 	  "VIA Technologies VT6421 Serial ATA RAID Controller",
    326      1.35    bouyer 	  via_sata_chip_map_new,
    327      1.22       abs 	},
    328       1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT8237_SATA,
    329       1.6   mycroft 	  0,
    330       1.1    bouyer 	  "VIA Technologies VT8237 SATA Controller",
    331      1.35    bouyer 	  via_sata_chip_map_7,
    332      1.35    bouyer 	},
    333      1.35    bouyer 	{ PCI_PRODUCT_VIATECH_VT8237A_SATA,
    334      1.35    bouyer 	  0,
    335      1.35    bouyer 	  "VIA Technologies VT8237A SATA Controller",
    336      1.41   garbled 	  via_sata_chip_map_7,
    337       1.1    bouyer 	},
    338      1.60  jmcneill 	{ PCI_PRODUCT_VIATECH_VT8237A_SATA_2,
    339      1.60  jmcneill 	  0,
    340      1.60  jmcneill 	  "VIA Technologies VT8237A (5337) SATA Controller",
    341      1.60  jmcneill 	  via_sata_chip_map_7,
    342      1.60  jmcneill 	},
    343      1.29   xtraeme 	{ PCI_PRODUCT_VIATECH_VT8237R_SATA,
    344      1.29   xtraeme 	  0,
    345      1.29   xtraeme 	  "VIA Technologies VT8237R SATA Controller",
    346      1.63  jakllsch 	  via_sata_chip_map_7,
    347      1.29   xtraeme 	},
    348      1.58    nonaka 	{ PCI_PRODUCT_VIATECH_VT8237S_SATA,
    349      1.58    nonaka 	  0,
    350      1.58    nonaka 	  "VIA Technologies VT8237S SATA Controller",
    351      1.58    nonaka 	  via_sata_chip_map_7,
    352      1.58    nonaka 	},
    353       1.1    bouyer 	{ 0,
    354       1.1    bouyer 	  0,
    355       1.1    bouyer 	  NULL,
    356       1.1    bouyer 	  NULL
    357       1.1    bouyer 	}
    358       1.1    bouyer };
    359       1.1    bouyer 
    360       1.4     enami static const struct pciide_product_desc *
    361       1.4     enami viaide_lookup(pcireg_t id)
    362       1.4     enami {
    363       1.4     enami 
    364       1.4     enami 	switch (PCI_VENDOR(id)) {
    365       1.4     enami 	case PCI_VENDOR_VIATECH:
    366       1.4     enami 		return (pciide_lookup_product(id, pciide_via_products));
    367       1.4     enami 
    368       1.4     enami 	case PCI_VENDOR_AMD:
    369       1.4     enami 		return (pciide_lookup_product(id, pciide_amd_products));
    370       1.4     enami 
    371       1.4     enami 	case PCI_VENDOR_NVIDIA:
    372       1.4     enami 		return (pciide_lookup_product(id, pciide_nvidia_products));
    373       1.4     enami 	}
    374       1.4     enami 	return (NULL);
    375       1.4     enami }
    376       1.4     enami 
    377       1.2   thorpej static int
    378      1.53      cube viaide_match(device_t parent, cfdata_t match, void *aux)
    379       1.1    bouyer {
    380      1.76  jakllsch 	const struct pci_attach_args *pa = aux;
    381       1.1    bouyer 
    382       1.4     enami 	if (viaide_lookup(pa->pa_id) != NULL)
    383       1.4     enami 		return (2);
    384       1.1    bouyer 	return (0);
    385       1.1    bouyer }
    386       1.1    bouyer 
    387       1.2   thorpej static void
    388      1.53      cube viaide_attach(device_t parent, device_t self, void *aux)
    389       1.1    bouyer {
    390      1.76  jakllsch 	const struct pci_attach_args *pa = aux;
    391      1.53      cube 	struct pciide_softc *sc = device_private(self);
    392       1.4     enami 	const struct pciide_product_desc *pp;
    393       1.1    bouyer 
    394  1.83.2.1    bouyer 	self->dv_maxphys = MIN(parent->dv_maxphys, MACHINE_MAXPHYS);
    395  1.83.2.1    bouyer 
    396      1.53      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    397      1.53      cube 
    398       1.4     enami 	pp = viaide_lookup(pa->pa_id);
    399       1.1    bouyer 	if (pp == NULL)
    400       1.1    bouyer 		panic("viaide_attach");
    401       1.1    bouyer 	pciide_common_attach(sc, pa, pp);
    402      1.51     joerg 
    403      1.51     joerg 	if (!pmf_device_register(self, viaide_suspend, viaide_resume))
    404      1.51     joerg 		aprint_error_dev(self, "couldn't establish power handler\n");
    405       1.1    bouyer }
    406       1.1    bouyer 
    407       1.5      fvdl static int
    408      1.72    dyoung via_pcib_match(const struct pci_attach_args *pa)
    409       1.5      fvdl {
    410       1.5      fvdl 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    411       1.5      fvdl 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA &&
    412       1.5      fvdl 	    PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH)
    413       1.5      fvdl 		return (1);
    414       1.5      fvdl 	return 0;
    415       1.5      fvdl }
    416       1.5      fvdl 
    417      1.51     joerg static bool
    418      1.68    dyoung viaide_suspend(device_t dv, const pmf_qual_t *qual)
    419      1.51     joerg {
    420      1.51     joerg 	struct pciide_softc *sc = device_private(dv);
    421      1.51     joerg 
    422      1.51     joerg 	sc->sc_pm_reg[0] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
    423      1.51     joerg 	/* APO_DATATIM(sc) includes APO_UDMA(sc) */
    424      1.51     joerg 	sc->sc_pm_reg[1] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
    425      1.51     joerg 	/* This two are VIA-only, but should be ignored by other devices. */
    426      1.51     joerg 	sc->sc_pm_reg[2] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc));
    427      1.51     joerg 	sc->sc_pm_reg[3] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_MISCTIM(sc));
    428      1.51     joerg 
    429      1.51     joerg 	return true;
    430      1.51     joerg }
    431      1.51     joerg 
    432      1.51     joerg static bool
    433      1.68    dyoung viaide_resume(device_t dv, const pmf_qual_t *qual)
    434      1.51     joerg {
    435      1.51     joerg 	struct pciide_softc *sc = device_private(dv);
    436      1.51     joerg 
    437      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc),
    438      1.51     joerg 	    sc->sc_pm_reg[0]);
    439      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc),
    440      1.51     joerg 	    sc->sc_pm_reg[1]);
    441      1.51     joerg 	/* This two are VIA-only, but should be ignored by other devices. */
    442      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc),
    443      1.51     joerg 	    sc->sc_pm_reg[2]);
    444      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_MISCTIM(sc),
    445      1.51     joerg 	    sc->sc_pm_reg[3]);
    446      1.51     joerg 
    447      1.51     joerg 	return true;
    448      1.51     joerg }
    449      1.51     joerg 
    450       1.2   thorpej static void
    451      1.72    dyoung via_chip_map(struct pciide_softc *sc, const struct pci_attach_args *pa)
    452       1.1    bouyer {
    453       1.1    bouyer 	struct pciide_channel *cp;
    454       1.1    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    455       1.1    bouyer 	pcireg_t vendor = PCI_VENDOR(pa->pa_id);
    456       1.1    bouyer 	int channel;
    457       1.1    bouyer 	u_int32_t ideconf;
    458       1.1    bouyer 	pcireg_t pcib_id, pcib_class;
    459       1.5      fvdl 	struct pci_attach_args pcib_pa;
    460       1.1    bouyer 
    461       1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    462       1.1    bouyer 		return;
    463       1.1    bouyer 
    464       1.3     enami 	switch (vendor) {
    465       1.1    bouyer 	case PCI_VENDOR_VIATECH:
    466      1.77       phx 		switch (PCI_PRODUCT(pa->pa_id)) {
    467      1.77       phx 		case PCI_PRODUCT_VIATECH_VT6410_RAID:
    468      1.77       phx 			aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    469      1.77       phx 			    "VIA Technologies VT6410 IDE controller\n");
    470      1.77       phx 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    471      1.77       phx 			interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    472      1.77       phx 			    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    473       1.1    bouyer 			break;
    474      1.78   tsutsui 		case PCI_PRODUCT_VIATECH_VX900_IDE:
    475      1.78   tsutsui 			aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    476      1.78   tsutsui 			    "VIA Technologies VX900 ATA133 controller\n");
    477      1.78   tsutsui 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    478      1.78   tsutsui 			break;
    479      1.77       phx 		default:
    480      1.77       phx 			/*
    481      1.77       phx 			 * get a PCI tag for the ISA bridge.
    482      1.77       phx 			 */
    483      1.77       phx 			if (pci_find_device(&pcib_pa, via_pcib_match) == 0)
    484      1.77       phx 				goto unknown;
    485      1.77       phx 			pcib_id = pcib_pa.pa_id;
    486      1.77       phx 			pcib_class = pcib_pa.pa_class;
    487      1.77       phx 			aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    488      1.77       phx 			    "VIA Technologies ");
    489      1.77       phx 			switch (PCI_PRODUCT(pcib_id)) {
    490      1.77       phx 			case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    491      1.77       phx 				aprint_normal("VT82C586 (Apollo VP) ");
    492      1.77       phx 				if(PCI_REVISION(pcib_class) >= 0x02) {
    493      1.77       phx 					aprint_normal("ATA33 controller\n");
    494      1.77       phx 					sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    495      1.77       phx 				} else {
    496      1.77       phx 					aprint_normal("controller\n");
    497      1.77       phx 					sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    498      1.77       phx 				}
    499      1.77       phx 				break;
    500      1.77       phx 			case PCI_PRODUCT_VIATECH_VT82C596A:
    501      1.77       phx 				aprint_normal("VT82C596A (Apollo Pro) ");
    502      1.77       phx 				if (PCI_REVISION(pcib_class) >= 0x12) {
    503      1.77       phx 					aprint_normal("ATA66 controller\n");
    504      1.77       phx 					sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    505      1.77       phx 				} else {
    506      1.77       phx 					aprint_normal("ATA33 controller\n");
    507      1.77       phx 					sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    508      1.77       phx 				}
    509      1.77       phx 				break;
    510      1.77       phx 			case PCI_PRODUCT_VIATECH_VT82C686A_ISA:
    511      1.77       phx 				aprint_normal("VT82C686A (Apollo KX133) ");
    512      1.77       phx 				if (PCI_REVISION(pcib_class) >= 0x40) {
    513      1.77       phx 					aprint_normal("ATA100 controller\n");
    514      1.77       phx 					sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    515      1.77       phx 				} else {
    516      1.77       phx 					aprint_normal("ATA66 controller\n");
    517      1.77       phx 					sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    518      1.77       phx 				}
    519      1.77       phx 				break;
    520      1.77       phx 			case PCI_PRODUCT_VIATECH_VT8231:
    521      1.77       phx 				aprint_normal("VT8231 ATA100 controller\n");
    522      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    523      1.77       phx 				break;
    524      1.77       phx 			case PCI_PRODUCT_VIATECH_VT8233:
    525      1.77       phx 				aprint_normal("VT8233 ATA100 controller\n");
    526      1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    527      1.77       phx 				break;
    528      1.77       phx 			case PCI_PRODUCT_VIATECH_VT8233A:
    529      1.77       phx 				aprint_normal("VT8233A ATA133 controller\n");
    530      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    531      1.77       phx 				break;
    532      1.77       phx 			case PCI_PRODUCT_VIATECH_VT8235:
    533      1.77       phx 				aprint_normal("VT8235 ATA133 controller\n");
    534      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    535      1.77       phx 				break;
    536      1.77       phx 			case PCI_PRODUCT_VIATECH_VT8237:
    537      1.77       phx 				aprint_normal("VT8237 ATA133 controller\n");
    538      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    539      1.77       phx 				break;
    540      1.77       phx 			case PCI_PRODUCT_VIATECH_VT8237A_ISA:
    541      1.77       phx 				aprint_normal("VT8237A ATA133 controller\n");
    542      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    543      1.77       phx 				break;
    544      1.77       phx 			case PCI_PRODUCT_VIATECH_CX700:
    545      1.77       phx 				aprint_normal("CX700 ATA133 controller\n");
    546      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    547      1.77       phx 				break;
    548      1.77       phx 			case PCI_PRODUCT_VIATECH_VT8251:
    549      1.77       phx 				aprint_normal("VT8251 ATA133 controller\n");
    550      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    551      1.77       phx 				break;
    552      1.77       phx 			default:
    553      1.77       phx 		unknown:
    554      1.77       phx 				aprint_normal("unknown VIA ATA controller\n");
    555      1.77       phx 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    556       1.1    bouyer 			}
    557       1.1    bouyer 			break;
    558       1.1    bouyer 		}
    559       1.1    bouyer 		sc->sc_apo_regbase = APO_VIA_REGBASE;
    560       1.1    bouyer 		break;
    561       1.1    bouyer 	case PCI_VENDOR_AMD:
    562       1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    563      1.11    bouyer 		case PCI_PRODUCT_AMD_PBC8111_IDE:
    564      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    565      1.11    bouyer 			break;
    566      1.45   xtraeme 		case PCI_PRODUCT_AMD_CS5536_IDE:
    567       1.1    bouyer 		case PCI_PRODUCT_AMD_PBC766_IDE:
    568       1.1    bouyer 		case PCI_PRODUCT_AMD_PBC768_IDE:
    569      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    570       1.1    bouyer 			break;
    571       1.1    bouyer 		default:
    572      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    573       1.1    bouyer 		}
    574       1.1    bouyer 		sc->sc_apo_regbase = APO_AMD_REGBASE;
    575       1.1    bouyer 		break;
    576       1.1    bouyer 	case PCI_VENDOR_NVIDIA:
    577       1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    578       1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE_ATA100:
    579      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    580       1.1    bouyer 			break;
    581       1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133:
    582      1.20  jdolecek 		case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133:
    583       1.5      fvdl 		case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133:
    584      1.19   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133:
    585      1.21      kent 		case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133:
    586      1.28   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE430_ATA133:
    587      1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP04_IDE:
    588      1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP55_IDE:
    589      1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP61_IDE:
    590      1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP65_IDE:
    591      1.43   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP67_IDE:
    592      1.47   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP73_IDE:
    593      1.47   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP77_IDE:
    594      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    595       1.1    bouyer 			break;
    596       1.1    bouyer 		}
    597       1.1    bouyer 		sc->sc_apo_regbase = APO_NVIDIA_REGBASE;
    598       1.1    bouyer 		break;
    599       1.1    bouyer 	default:
    600       1.1    bouyer 		panic("via_chip_map: unknown vendor");
    601       1.1    bouyer 	}
    602       1.3     enami 
    603      1.53      cube 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    604      1.53      cube 	    "bus-master DMA support present");
    605       1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    606      1.39        ad 	aprint_verbose("\n");
    607      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    608       1.1    bouyer 	if (sc->sc_dma_ok) {
    609      1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    610       1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    611      1.17   thorpej 		if (sc->sc_wdcdev.sc_atac.atac_udma_cap > 0)
    612      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
    613       1.1    bouyer 	}
    614      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    615      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    616      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = via_setup_channel;
    617      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    618      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    619      1.83    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    620       1.1    bouyer 
    621      1.41   garbled 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    622      1.41   garbled 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    623      1.41   garbled 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    624      1.41   garbled 
    625      1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    626      1.15   thorpej 
    627      1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
    628       1.1    bouyer 	    "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    629       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc)),
    630       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc)),
    631       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    632       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))),
    633       1.1    bouyer 	    DEBUG_PROBE);
    634       1.1    bouyer 
    635       1.1    bouyer 	ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
    636      1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    637      1.17   thorpej 	     channel++) {
    638       1.1    bouyer 		cp = &sc->pciide_channels[channel];
    639       1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    640       1.1    bouyer 			continue;
    641       1.1    bouyer 
    642       1.1    bouyer 		if ((ideconf & APO_IDECONF_EN(channel)) == 0) {
    643      1.53      cube 			aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    644      1.53      cube 			    "%s channel ignored (disabled)\n", cp->name);
    645      1.15   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    646       1.1    bouyer 			continue;
    647       1.1    bouyer 		}
    648      1.70  jakllsch 		via_mapchan(pa, cp, interface, pciide_pci_intr);
    649       1.1    bouyer 	}
    650       1.1    bouyer }
    651       1.1    bouyer 
    652       1.2   thorpej static void
    653      1.72    dyoung via_mapchan(const struct pci_attach_args *pa,	struct pciide_channel *cp,
    654      1.70  jakllsch     pcireg_t interface, int (*pci_intr)(void *))
    655      1.50       phx {
    656      1.50       phx 	struct ata_channel *wdc_cp;
    657      1.50       phx 	struct pciide_softc *sc;
    658      1.50       phx 	prop_bool_t compat_nat_enable;
    659      1.50       phx 
    660      1.50       phx 	wdc_cp = &cp->ata_channel;
    661      1.50       phx 	sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    662      1.50       phx 	compat_nat_enable = prop_dictionary_get(
    663      1.53      cube 	    device_properties(sc->sc_wdcdev.sc_atac.atac_dev),
    664      1.53      cube 	      "use-compat-native-irq");
    665      1.50       phx 
    666      1.50       phx 	if (interface & PCIIDE_INTERFACE_PCI(wdc_cp->ch_channel)) {
    667      1.50       phx 		/* native mode with irq 14/15 requested? */
    668      1.50       phx 		if (compat_nat_enable != NULL &&
    669      1.50       phx 		    prop_bool_true(compat_nat_enable))
    670      1.70  jakllsch 			via_mapregs_compat_native(pa, cp);
    671      1.50       phx 		else
    672      1.70  jakllsch 			pciide_mapregs_native(pa, cp, pci_intr);
    673      1.50       phx 	} else {
    674      1.70  jakllsch 		pciide_mapregs_compat(pa, cp, wdc_cp->ch_channel);
    675      1.50       phx 		if ((cp->ata_channel.ch_flags & ATACH_DISABLED) == 0)
    676      1.50       phx 			pciide_map_compat_intr(pa, cp, wdc_cp->ch_channel);
    677      1.50       phx 	}
    678      1.50       phx 	wdcattach(wdc_cp);
    679      1.50       phx }
    680      1.50       phx 
    681      1.50       phx /*
    682      1.50       phx  * At least under certain (mis)configurations (e.g. on the "Pegasos" board)
    683      1.50       phx  * the VT8231-IDE's native mode only works with irq 14/15, and cannot be
    684      1.50       phx  * programmed to use a single native PCI irq alone. So we install an interrupt
    685      1.50       phx  * handler for each channel, as in compatibility mode.
    686      1.50       phx  */
    687      1.50       phx static void
    688      1.72    dyoung via_mapregs_compat_native(const struct pci_attach_args *pa,
    689      1.70  jakllsch     struct pciide_channel *cp)
    690      1.50       phx {
    691      1.50       phx 	struct ata_channel *wdc_cp;
    692      1.50       phx 	struct pciide_softc *sc;
    693      1.50       phx 
    694      1.50       phx 	wdc_cp = &cp->ata_channel;
    695      1.50       phx 	sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    696      1.50       phx 
    697      1.50       phx 	/* XXX prevent pciide_mapregs_native from installing a handler */
    698      1.50       phx 	if (sc->sc_pci_ih == NULL)
    699      1.50       phx 		sc->sc_pci_ih = (void *)~0;
    700      1.70  jakllsch 	pciide_mapregs_native(pa, cp, NULL);
    701      1.50       phx 
    702      1.50       phx 	/* interrupts are fixed to 14/15, as in compatibility mode */
    703      1.55       phx 	cp->compat = 1;
    704      1.50       phx 	if ((wdc_cp->ch_flags & ATACH_DISABLED) == 0) {
    705      1.50       phx #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    706      1.50       phx 		cp->ih = pciide_machdep_compat_intr_establish(
    707      1.53      cube 		    sc->sc_wdcdev.sc_atac.atac_dev, pa, wdc_cp->ch_channel,
    708      1.55       phx 		    pciide_compat_intr, cp);
    709      1.50       phx 		if (cp->ih == NULL) {
    710      1.50       phx #endif
    711      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    712      1.53      cube 			    "no compatibility interrupt for "
    713      1.53      cube 			    "use by %s channel\n", cp->name);
    714      1.50       phx 			wdc_cp->ch_flags |= ATACH_DISABLED;
    715      1.50       phx #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    716      1.50       phx 		}
    717      1.50       phx 		sc->sc_pci_ih = cp->ih;  /* XXX */
    718      1.50       phx #endif
    719      1.50       phx 	}
    720      1.50       phx }
    721      1.50       phx 
    722      1.50       phx static void
    723      1.15   thorpej via_setup_channel(struct ata_channel *chp)
    724       1.1    bouyer {
    725       1.1    bouyer 	u_int32_t udmatim_reg, datatim_reg;
    726       1.1    bouyer 	u_int8_t idedma_ctl;
    727      1.18   thorpej 	int mode, drive, s;
    728       1.1    bouyer 	struct ata_drive_datas *drvp;
    729      1.17   thorpej 	struct atac_softc *atac = chp->ch_atac;
    730      1.16   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    731      1.16   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    732       1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    733       1.1    bouyer 	int rev = PCI_REVISION(
    734       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
    735       1.1    bouyer #endif
    736       1.1    bouyer 
    737       1.1    bouyer 	idedma_ctl = 0;
    738       1.1    bouyer 	datatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
    739       1.1    bouyer 	udmatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc));
    740       1.9   thorpej 	datatim_reg &= ~APO_DATATIM_MASK(chp->ch_channel);
    741       1.9   thorpej 	udmatim_reg &= ~APO_UDMA_MASK(chp->ch_channel);
    742       1.1    bouyer 
    743       1.1    bouyer 	/* setup DMA if needed */
    744       1.1    bouyer 	pciide_channel_dma_setup(cp);
    745       1.1    bouyer 
    746       1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    747       1.1    bouyer 		drvp = &chp->ch_drive[drive];
    748       1.1    bouyer 		/* If no drive, skip */
    749      1.83    bouyer 		if (drvp->drive_type == ATA_DRIVET_NONE)
    750       1.1    bouyer 			continue;
    751       1.1    bouyer 		/* add timing values, setup DMA if needed */
    752      1.83    bouyer 		if (((drvp->drive_flags & ATA_DRIVE_DMA) == 0 &&
    753      1.83    bouyer 		    (drvp->drive_flags & ATA_DRIVE_UDMA) == 0)) {
    754       1.1    bouyer 			mode = drvp->PIO_mode;
    755       1.1    bouyer 			goto pio;
    756       1.1    bouyer 		}
    757      1.17   thorpej 		if ((atac->atac_cap & ATAC_CAP_UDMA) &&
    758      1.83    bouyer 		    (drvp->drive_flags & ATA_DRIVE_UDMA)) {
    759       1.1    bouyer 			/* use Ultra/DMA */
    760      1.18   thorpej 			s = splbio();
    761      1.83    bouyer 			drvp->drive_flags &= ~ATA_DRIVE_DMA;
    762      1.18   thorpej 			splx(s);
    763       1.9   thorpej 			udmatim_reg |= APO_UDMA_EN(chp->ch_channel, drive) |
    764       1.9   thorpej 			    APO_UDMA_EN_MTH(chp->ch_channel, drive);
    765       1.3     enami 			switch (PCI_VENDOR(sc->sc_pci_id)) {
    766       1.1    bouyer 			case PCI_VENDOR_VIATECH:
    767      1.17   thorpej 				if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 6) {
    768       1.1    bouyer 					/* 8233a */
    769       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    770       1.9   thorpej 					    chp->ch_channel,
    771       1.1    bouyer 					    drive,
    772       1.1    bouyer 					    via_udma133_tim[drvp->UDMA_mode]);
    773      1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 5) {
    774       1.1    bouyer 					/* 686b */
    775       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    776       1.9   thorpej 					    chp->ch_channel,
    777       1.1    bouyer 					    drive,
    778       1.1    bouyer 					    via_udma100_tim[drvp->UDMA_mode]);
    779      1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 4) {
    780       1.1    bouyer 					/* 596b or 686a */
    781       1.1    bouyer 					udmatim_reg |= APO_UDMA_CLK66(
    782       1.9   thorpej 					    chp->ch_channel);
    783       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    784       1.9   thorpej 					    chp->ch_channel,
    785       1.1    bouyer 					    drive,
    786       1.1    bouyer 					    via_udma66_tim[drvp->UDMA_mode]);
    787       1.1    bouyer 				} else {
    788       1.1    bouyer 					/* 596a or 586b */
    789       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    790       1.9   thorpej 					    chp->ch_channel,
    791       1.1    bouyer 					    drive,
    792       1.1    bouyer 					    via_udma33_tim[drvp->UDMA_mode]);
    793       1.1    bouyer 				}
    794       1.1    bouyer 				break;
    795       1.1    bouyer 			case PCI_VENDOR_AMD:
    796       1.1    bouyer 			case PCI_VENDOR_NVIDIA:
    797       1.9   thorpej 				udmatim_reg |= APO_UDMA_TIME(chp->ch_channel,
    798       1.1    bouyer 				    drive, amd7x6_udma_tim[drvp->UDMA_mode]);
    799       1.1    bouyer 				 break;
    800       1.1    bouyer 			}
    801       1.1    bouyer 			/* can use PIO timings, MW DMA unused */
    802       1.1    bouyer 			mode = drvp->PIO_mode;
    803       1.1    bouyer 		} else {
    804       1.1    bouyer 			/* use Multiword DMA, but only if revision is OK */
    805      1.18   thorpej 			s = splbio();
    806      1.83    bouyer 			drvp->drive_flags &= ~ATA_DRIVE_UDMA;
    807      1.18   thorpej 			splx(s);
    808       1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    809       1.1    bouyer 			/*
    810       1.1    bouyer 			 * The workaround doesn't seem to be necessary
    811       1.1    bouyer 			 * with all drives, so it can be disabled by
    812       1.1    bouyer 			 * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
    813       1.1    bouyer 			 * triggered.
    814       1.1    bouyer 			 */
    815       1.1    bouyer 			if (PCI_VENDOR(sc->sc_pci_id) == PCI_VENDOR_AMD &&
    816       1.1    bouyer 			    sc->sc_pp->ide_product ==
    817       1.3     enami 			    PCI_PRODUCT_AMD_PBC756_IDE &&
    818       1.1    bouyer 			    AMD756_CHIPREV_DISABLEDMA(rev)) {
    819       1.1    bouyer 				aprint_normal(
    820       1.1    bouyer 				    "%s:%d:%d: multi-word DMA disabled due "
    821       1.1    bouyer 				    "to chip revision\n",
    822      1.53      cube 				    device_xname(
    823      1.53      cube 				      sc->sc_wdcdev.sc_atac.atac_dev),
    824       1.9   thorpej 				    chp->ch_channel, drive);
    825       1.1    bouyer 				mode = drvp->PIO_mode;
    826      1.18   thorpej 				s = splbio();
    827      1.83    bouyer 				drvp->drive_flags &= ~ATA_DRIVE_DMA;
    828      1.18   thorpej 				splx(s);
    829       1.1    bouyer 				goto pio;
    830       1.1    bouyer 			}
    831       1.1    bouyer #endif
    832       1.1    bouyer 			/* mode = min(pio, dma+2) */
    833       1.3     enami 			if (drvp->PIO_mode <= (drvp->DMA_mode + 2))
    834       1.1    bouyer 				mode = drvp->PIO_mode;
    835       1.1    bouyer 			else
    836       1.1    bouyer 				mode = drvp->DMA_mode + 2;
    837       1.1    bouyer 		}
    838       1.1    bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    839       1.1    bouyer 
    840       1.1    bouyer pio:		/* setup PIO mode */
    841       1.1    bouyer 		if (mode <= 2) {
    842       1.1    bouyer 			drvp->DMA_mode = 0;
    843       1.1    bouyer 			drvp->PIO_mode = 0;
    844       1.1    bouyer 			mode = 0;
    845       1.1    bouyer 		} else {
    846       1.1    bouyer 			drvp->PIO_mode = mode;
    847       1.1    bouyer 			drvp->DMA_mode = mode - 2;
    848       1.1    bouyer 		}
    849       1.1    bouyer 		datatim_reg |=
    850       1.9   thorpej 		    APO_DATATIM_PULSE(chp->ch_channel, drive,
    851       1.1    bouyer 			apollo_pio_set[mode]) |
    852       1.9   thorpej 		    APO_DATATIM_RECOV(chp->ch_channel, drive,
    853       1.1    bouyer 			apollo_pio_rec[mode]);
    854       1.1    bouyer 	}
    855       1.1    bouyer 	if (idedma_ctl != 0) {
    856       1.1    bouyer 		/* Add software bits in status register */
    857       1.7      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    858       1.1    bouyer 		    idedma_ctl);
    859       1.1    bouyer 	}
    860       1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc), datatim_reg);
    861       1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_UDMA(sc), udmatim_reg);
    862      1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    863       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    864       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))), DEBUG_PROBE);
    865       1.1    bouyer }
    866       1.1    bouyer 
    867      1.35    bouyer static int
    868      1.76  jakllsch via_sata_chip_map_common(struct pciide_softc *sc,
    869      1.76  jakllsch     const struct pci_attach_args *cpa)
    870       1.1    bouyer {
    871      1.74    dyoung 	pcireg_t csr;
    872      1.36    bouyer 	int maptype, ret;
    873      1.76  jakllsch 	struct pci_attach_args pac, *pa = &pac;
    874      1.76  jakllsch 
    875      1.76  jakllsch 	pac = *cpa;
    876       1.1    bouyer 
    877       1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    878      1.35    bouyer 		return 0;
    879       1.1    bouyer 
    880      1.53      cube 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    881      1.53      cube 	    "bus-master DMA support present");
    882       1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    883      1.39        ad 	aprint_verbose("\n");
    884       1.1    bouyer 
    885       1.1    bouyer 	if (sc->sc_dma_ok) {
    886      1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
    887       1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    888       1.1    bouyer 	}
    889      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    890      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    891      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    892      1.17   thorpej 
    893      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    894      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    895      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    896      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    897      1.83    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    898       1.1    bouyer 
    899      1.41   garbled 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    900      1.41   garbled 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    901      1.41   garbled 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    902      1.41   garbled 
    903      1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    904      1.36    bouyer 	maptype = pci_mapreg_type(pa->pa_pc, pa->pa_tag,
    905      1.36    bouyer 	    PCI_MAPREG_START + 0x14);
    906      1.36    bouyer 	switch(maptype) {
    907      1.36    bouyer 	case PCI_MAPREG_TYPE_IO:
    908      1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    909      1.36    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    910      1.70  jakllsch 		    NULL, &sc->sc_ba5_ss);
    911      1.36    bouyer 		break;
    912      1.36    bouyer 	case PCI_MAPREG_MEM_TYPE_32BIT:
    913      1.69    dyoung 		/*
    914      1.69    dyoung 		 * Enable memory-space access if it isn't already there.
    915      1.69    dyoung 		 */
    916      1.74    dyoung 		csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
    917      1.74    dyoung 		    PCI_COMMAND_STATUS_REG);
    918      1.74    dyoung 		if ((csr & PCI_COMMAND_MEM_ENABLE) == 0 &&
    919      1.75    dyoung 		    (pa->pa_flags & PCI_FLAGS_MEM_OKAY) != 0) {
    920      1.69    dyoung 
    921      1.69    dyoung 			pci_conf_write(pa->pa_pc, pa->pa_tag,
    922      1.69    dyoung 			    PCI_COMMAND_STATUS_REG,
    923      1.69    dyoung 			    csr | PCI_COMMAND_MEM_ENABLE);
    924      1.69    dyoung 		}
    925      1.69    dyoung 
    926      1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    927      1.35    bouyer 		    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    928      1.35    bouyer 		    0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    929      1.70  jakllsch 		    NULL, &sc->sc_ba5_ss);
    930      1.36    bouyer 		break;
    931      1.36    bouyer 	default:
    932      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    933      1.54  dholland 		    "couldn't map sata regs, unsupported maptype (0x%x)\n",
    934      1.36    bouyer 		    maptype);
    935      1.36    bouyer 		return 0;
    936      1.36    bouyer 	}
    937      1.36    bouyer 	if (ret != 0) {
    938      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    939      1.53      cube 		    "couldn't map sata regs\n");
    940      1.36    bouyer 		return 0;
    941      1.35    bouyer 	}
    942      1.35    bouyer 	return 1;
    943      1.35    bouyer }
    944      1.35    bouyer 
    945      1.35    bouyer static void
    946      1.76  jakllsch via_sata_chip_map(struct pciide_softc *sc, const struct pci_attach_args *pa,
    947      1.35    bouyer     int satareg_shift)
    948      1.35    bouyer {
    949      1.35    bouyer 	struct pciide_channel *cp;
    950      1.35    bouyer 	struct ata_channel *wdc_cp;
    951      1.35    bouyer 	struct wdc_regs *wdr;
    952      1.73  jakllsch 	pcireg_t interface;
    953      1.35    bouyer 	int channel;
    954      1.35    bouyer 
    955      1.73  jakllsch 	interface = PCI_INTERFACE(pa->pa_class);
    956      1.73  jakllsch 
    957      1.35    bouyer 	if (via_sata_chip_map_common(sc, pa) == 0)
    958      1.35    bouyer 		return;
    959      1.35    bouyer 
    960      1.35    bouyer 	if (interface == 0) {
    961      1.35    bouyer 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    962      1.35    bouyer 		    DEBUG_PROBE);
    963      1.35    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    964      1.35    bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    965      1.35    bouyer 	}
    966      1.15   thorpej 
    967      1.83    bouyer 	sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    968      1.83    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 1;
    969      1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    970      1.17   thorpej 	     channel++) {
    971       1.1    bouyer 		cp = &sc->pciide_channels[channel];
    972       1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    973       1.1    bouyer 			continue;
    974      1.35    bouyer 		wdc_cp = &cp->ata_channel;
    975      1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    976      1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
    977      1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
    978      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    979      1.64  jakllsch 		    (wdc_cp->ch_channel << satareg_shift) + 0x0, 4,
    980      1.35    bouyer 		    &wdr->sata_status) != 0) {
    981      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    982      1.53      cube 			    "couldn't map channel %d sata_status regs\n",
    983      1.35    bouyer 			    wdc_cp->ch_channel);
    984      1.35    bouyer 			continue;
    985      1.35    bouyer 		}
    986      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    987      1.64  jakllsch 		    (wdc_cp->ch_channel << satareg_shift) + 0x4, 4,
    988      1.35    bouyer 		    &wdr->sata_error) != 0) {
    989      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    990      1.53      cube 			    "couldn't map channel %d sata_error regs\n",
    991      1.35    bouyer 			    wdc_cp->ch_channel);
    992      1.35    bouyer 			continue;
    993      1.35    bouyer 		}
    994      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    995      1.64  jakllsch 		    (wdc_cp->ch_channel << satareg_shift) + 0x8, 4,
    996      1.35    bouyer 		    &wdr->sata_control) != 0) {
    997      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    998      1.53      cube 			    "couldn't map channel %d sata_control regs\n",
    999      1.35    bouyer 			    wdc_cp->ch_channel);
   1000      1.35    bouyer 			continue;
   1001      1.35    bouyer 		}
   1002      1.70  jakllsch 		pciide_mapchan(pa, cp, interface, pciide_pci_intr);
   1003       1.1    bouyer 	}
   1004       1.1    bouyer }
   1005      1.35    bouyer 
   1006      1.35    bouyer static void
   1007      1.72    dyoung via_sata_chip_map_6(struct pciide_softc *sc, const struct pci_attach_args *pa)
   1008      1.35    bouyer {
   1009      1.35    bouyer 	via_sata_chip_map(sc, pa, 6);
   1010      1.35    bouyer }
   1011      1.35    bouyer 
   1012      1.35    bouyer static void
   1013      1.72    dyoung via_sata_chip_map_7(struct pciide_softc *sc, const struct pci_attach_args *pa)
   1014      1.35    bouyer {
   1015      1.35    bouyer 	via_sata_chip_map(sc, pa, 7);
   1016      1.35    bouyer }
   1017      1.35    bouyer 
   1018      1.35    bouyer static void
   1019      1.76  jakllsch via_vt6421_mapreg_dma(struct pciide_softc *sc, const struct pci_attach_args *pa)
   1020      1.76  jakllsch {
   1021      1.76  jakllsch 	struct pciide_channel *pc;
   1022      1.76  jakllsch 	int chan, reg;
   1023      1.76  jakllsch 	bus_size_t size;
   1024      1.76  jakllsch 
   1025      1.76  jakllsch 	sc->sc_dma_ok = (pci_mapreg_map(pa, PCIIDE_REG_BUS_MASTER_DMA,
   1026      1.76  jakllsch 	    PCI_MAPREG_TYPE_IO, 0, &sc->sc_dma_iot, &sc->sc_dma_ioh,
   1027      1.76  jakllsch 	    NULL, &sc->sc_dma_ios) == 0);
   1028      1.76  jakllsch 	sc->sc_dmat = pa->pa_dmat;
   1029      1.76  jakllsch 	if (sc->sc_dma_ok == 0) {
   1030      1.76  jakllsch 		aprint_verbose(", but unused (couldn't map registers)");
   1031      1.76  jakllsch 	} else {
   1032      1.76  jakllsch 		sc->sc_wdcdev.dma_arg = sc;
   1033      1.76  jakllsch 		sc->sc_wdcdev.dma_init = pciide_dma_init;
   1034      1.76  jakllsch 		sc->sc_wdcdev.dma_start = pciide_dma_start;
   1035      1.76  jakllsch 		sc->sc_wdcdev.dma_finish = pciide_dma_finish;
   1036      1.76  jakllsch 	}
   1037      1.76  jakllsch 
   1038      1.76  jakllsch 	if (device_cfdata(sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
   1039      1.76  jakllsch 	    PCIIDE_OPTIONS_NODMA) {
   1040      1.76  jakllsch 		aprint_verbose(
   1041      1.76  jakllsch 		    ", but unused (forced off by config file)");
   1042      1.76  jakllsch 		sc->sc_dma_ok = 0;
   1043      1.76  jakllsch 	}
   1044      1.76  jakllsch 
   1045      1.76  jakllsch 	if (sc->sc_dma_ok == 0)
   1046      1.76  jakllsch 		return;
   1047      1.76  jakllsch 
   1048      1.76  jakllsch 	for (chan = 0; chan < 4; chan++) {
   1049      1.76  jakllsch 		pc = &sc->pciide_channels[chan];
   1050      1.76  jakllsch 		for (reg = 0; reg < IDEDMA_NREGS; reg++) {
   1051      1.76  jakllsch 			size = 4;
   1052      1.76  jakllsch 			if (size > (IDEDMA_SCH_OFFSET - reg))
   1053      1.76  jakllsch 				size = IDEDMA_SCH_OFFSET - reg;
   1054      1.76  jakllsch 			if (bus_space_subregion(sc->sc_dma_iot, sc->sc_dma_ioh,
   1055      1.76  jakllsch 			    IDEDMA_SCH_OFFSET * chan + reg, size,
   1056      1.76  jakllsch 			    &pc->dma_iohs[reg]) != 0) {
   1057      1.76  jakllsch 				sc->sc_dma_ok = 0;
   1058      1.76  jakllsch 				aprint_verbose(", but can't subregion offset "
   1059      1.76  jakllsch 				               "%d size %lu",
   1060      1.76  jakllsch 					       reg, (u_long)size);
   1061      1.76  jakllsch 				return;
   1062      1.76  jakllsch 			}
   1063      1.76  jakllsch 		}
   1064      1.76  jakllsch 	}
   1065      1.76  jakllsch }
   1066      1.76  jakllsch 
   1067      1.76  jakllsch static int
   1068      1.76  jakllsch via_vt6421_chansetup(struct pciide_softc *sc, int channel)
   1069      1.76  jakllsch {
   1070      1.76  jakllsch 	struct pciide_channel *cp = &sc->pciide_channels[channel];
   1071      1.76  jakllsch 
   1072      1.76  jakllsch 	sc->wdc_chanarray[channel] = &cp->ata_channel;
   1073      1.76  jakllsch 
   1074      1.76  jakllsch 	cp->ata_channel.ch_channel = channel;
   1075      1.76  jakllsch 	cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
   1076      1.76  jakllsch 	cp->ata_channel.ch_queue =
   1077      1.76  jakllsch 	    malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
   1078      1.76  jakllsch 	if (cp->ata_channel.ch_queue == NULL) {
   1079      1.76  jakllsch 		aprint_error("%s channel %d: "
   1080      1.76  jakllsch 		    "can't allocate memory for command queue",
   1081      1.76  jakllsch 		    device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel);
   1082      1.76  jakllsch 		return 0;
   1083      1.76  jakllsch 	}
   1084      1.76  jakllsch 	return 1;
   1085      1.76  jakllsch }
   1086      1.76  jakllsch 
   1087      1.76  jakllsch static void
   1088      1.72    dyoung via_sata_chip_map_new(struct pciide_softc *sc,
   1089      1.76  jakllsch     const struct pci_attach_args *pa)
   1090      1.35    bouyer {
   1091      1.35    bouyer 	struct pciide_channel *cp;
   1092      1.35    bouyer 	struct ata_channel *wdc_cp;
   1093      1.35    bouyer 	struct wdc_regs *wdr;
   1094      1.35    bouyer 	int channel;
   1095      1.35    bouyer 	pci_intr_handle_t intrhandle;
   1096      1.35    bouyer 	const char *intrstr;
   1097      1.35    bouyer 	int i;
   1098  1.83.2.2       tls 	char intrbuf[PCI_INTRSTR_LEN];
   1099      1.35    bouyer 
   1100      1.76  jakllsch 	if (pciide_chipen(sc, pa) == 0)
   1101      1.76  jakllsch 		return;
   1102      1.76  jakllsch 
   1103      1.76  jakllsch 	sc->sc_apo_regbase = APO_VIA_VT6421_REGBASE;
   1104      1.76  jakllsch 
   1105      1.76  jakllsch 	if (pci_mapreg_map(pa, PCI_BAR(5), PCI_MAPREG_TYPE_IO, 0,
   1106      1.76  jakllsch 	    &sc->sc_ba5_st, &sc->sc_ba5_sh, NULL, &sc->sc_ba5_ss) != 0) {
   1107      1.76  jakllsch 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1108      1.76  jakllsch 		    "couldn't map SATA regs\n");
   1109      1.76  jakllsch 	}
   1110      1.73  jakllsch 
   1111      1.76  jakllsch 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1112      1.76  jakllsch 	    "bus-master DMA support present");
   1113      1.76  jakllsch 	via_vt6421_mapreg_dma(sc, pa);
   1114      1.76  jakllsch 	aprint_verbose("\n");
   1115      1.35    bouyer 
   1116      1.76  jakllsch 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
   1117      1.76  jakllsch 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
   1118      1.76  jakllsch 	if (sc->sc_dma_ok) {
   1119      1.76  jakllsch 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
   1120      1.76  jakllsch 		sc->sc_wdcdev.irqack = pciide_irqack;
   1121      1.76  jakllsch 		sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
   1122      1.76  jakllsch 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
   1123      1.35    bouyer 	}
   1124      1.76  jakllsch 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
   1125      1.76  jakllsch 
   1126      1.76  jakllsch 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
   1127      1.76  jakllsch 	sc->sc_wdcdev.sc_atac.atac_nchannels = 3;
   1128      1.83    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
   1129      1.76  jakllsch 
   1130      1.76  jakllsch 	wdc_allocate_regs(&sc->sc_wdcdev);
   1131      1.35    bouyer 
   1132      1.35    bouyer 	if (pci_intr_map(pa, &intrhandle) != 0) {
   1133      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1134      1.53      cube 		    "couldn't map native-PCI interrupt\n");
   1135      1.35    bouyer 		return;
   1136      1.35    bouyer 	}
   1137  1.83.2.2       tls 	intrstr = pci_intr_string(pa->pa_pc, intrhandle, intrbuf, sizeof(intrbuf));
   1138      1.35    bouyer 	sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
   1139      1.35    bouyer 	    intrhandle, IPL_BIO, pciide_pci_intr, sc);
   1140      1.35    bouyer 	if (sc->sc_pci_ih == NULL) {
   1141      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1142      1.53      cube 		    "couldn't establish native-PCI interrupt");
   1143      1.35    bouyer 		if (intrstr != NULL)
   1144      1.35    bouyer 		    aprint_error(" at %s", intrstr);
   1145      1.35    bouyer 		aprint_error("\n");
   1146      1.35    bouyer 		return;
   1147      1.35    bouyer 	}
   1148      1.53      cube 	aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1149      1.53      cube 	    "using %s for native-PCI interrupt\n",
   1150      1.35    bouyer 	    intrstr ? intrstr : "unknown interrupt");
   1151      1.35    bouyer 
   1152      1.35    bouyer 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
   1153      1.35    bouyer 	     channel++) {
   1154      1.35    bouyer 		cp = &sc->pciide_channels[channel];
   1155      1.76  jakllsch 		if (via_vt6421_chansetup(sc, channel) == 0)
   1156      1.35    bouyer 			continue;
   1157      1.35    bouyer 		wdc_cp = &cp->ata_channel;
   1158      1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
   1159      1.35    bouyer 
   1160      1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
   1161      1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
   1162      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
   1163      1.64  jakllsch 		    (wdc_cp->ch_channel << 6) + 0x0, 4,
   1164      1.35    bouyer 		    &wdr->sata_status) != 0) {
   1165      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1166      1.53      cube 			    "couldn't map channel %d sata_status regs\n",
   1167      1.35    bouyer 			    wdc_cp->ch_channel);
   1168      1.35    bouyer 			continue;
   1169      1.35    bouyer 		}
   1170      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
   1171      1.64  jakllsch 		    (wdc_cp->ch_channel << 6) + 0x4, 4,
   1172      1.35    bouyer 		    &wdr->sata_error) != 0) {
   1173      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1174      1.53      cube 			    "couldn't map channel %d sata_error regs\n",
   1175      1.35    bouyer 			    wdc_cp->ch_channel);
   1176      1.35    bouyer 			continue;
   1177      1.35    bouyer 		}
   1178      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
   1179      1.64  jakllsch 		    (wdc_cp->ch_channel << 6) + 0x8, 4,
   1180      1.35    bouyer 		    &wdr->sata_control) != 0) {
   1181      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1182      1.53      cube 			    "couldn't map channel %d sata_control regs\n",
   1183      1.35    bouyer 			    wdc_cp->ch_channel);
   1184      1.35    bouyer 			continue;
   1185      1.35    bouyer 		}
   1186      1.35    bouyer 
   1187      1.76  jakllsch 		if (pci_mapreg_map(pa, PCI_BAR(wdc_cp->ch_channel),
   1188      1.35    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &wdr->cmd_iot, &wdr->cmd_baseioh,
   1189      1.70  jakllsch 		    NULL, &wdr->cmd_ios) != 0) {
   1190      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1191      1.53      cube 			    "couldn't map %s channel regs\n", cp->name);
   1192      1.35    bouyer 		}
   1193      1.35    bouyer 		wdr->ctl_iot = wdr->cmd_iot;
   1194      1.35    bouyer 		for (i = 0; i < WDC_NREG; i++) {
   1195      1.35    bouyer 			if (bus_space_subregion(wdr->cmd_iot,
   1196      1.35    bouyer 			    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
   1197      1.35    bouyer 			    &wdr->cmd_iohs[i]) != 0) {
   1198      1.53      cube 				aprint_error_dev(
   1199      1.53      cube 				    sc->sc_wdcdev.sc_atac.atac_dev,
   1200      1.53      cube 				    "couldn't subregion %s "
   1201      1.53      cube 				    "channel cmd regs\n", cp->name);
   1202      1.35    bouyer 				return;
   1203      1.35    bouyer 			}
   1204      1.35    bouyer 		}
   1205      1.35    bouyer 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
   1206      1.35    bouyer 		    WDC_NREG + 2, 1,  &wdr->ctl_ioh) != 0) {
   1207      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1208      1.53      cube 			    "couldn't map channel %d ctl regs\n", channel);
   1209      1.35    bouyer 			return;
   1210      1.35    bouyer 		}
   1211      1.35    bouyer 		wdc_init_shadow_regs(wdc_cp);
   1212      1.65   tsutsui 		wdr->data32iot = wdr->cmd_iot;
   1213      1.65   tsutsui 		wdr->data32ioh = wdr->cmd_iohs[wd_data];
   1214      1.35    bouyer 		wdcattach(wdc_cp);
   1215      1.35    bouyer 	}
   1216      1.35    bouyer }
   1217