Home | History | Annotate | Line # | Download | only in pci
viaide.c revision 1.53.2.1
      1  1.53.2.1      yamt /*	$NetBSD: viaide.c,v 1.53.2.1 2008/05/18 12:34:23 yamt 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.53.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: viaide.c,v 1.53.2.1 2008/05/18 12:34:23 yamt 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.50       phx static void	via_mapchan(struct pci_attach_args *, struct pciide_channel *,
     48      1.50       phx 		    pcireg_t, bus_size_t *, bus_size_t *, int (*)(void *));
     49      1.50       phx static void	vt8231_mapregs_native(struct pci_attach_args *,
     50      1.50       phx 		    struct pciide_channel *, bus_size_t *, bus_size_t *,
     51      1.50       phx 		    int (*)(void *));
     52      1.35    bouyer static int	via_sata_chip_map_common(struct pciide_softc *,
     53      1.35    bouyer 		    struct pci_attach_args *);
     54       1.4     enami static void	via_sata_chip_map(struct pciide_softc *,
     55      1.35    bouyer 		    struct pci_attach_args *, int);
     56      1.35    bouyer static void	via_sata_chip_map_0(struct pciide_softc *,
     57      1.35    bouyer 		    struct pci_attach_args *);
     58      1.35    bouyer static void	via_sata_chip_map_6(struct pciide_softc *,
     59      1.35    bouyer 		    struct pci_attach_args *);
     60      1.35    bouyer static void	via_sata_chip_map_7(struct pciide_softc *,
     61      1.35    bouyer 		    struct pci_attach_args *);
     62      1.35    bouyer static void	via_sata_chip_map_new(struct pciide_softc *,
     63       1.4     enami 		    struct pci_attach_args *);
     64      1.15   thorpej static void	via_setup_channel(struct ata_channel *);
     65       1.4     enami 
     66      1.53      cube static int	viaide_match(device_t, cfdata_t, void *);
     67      1.53      cube static void	viaide_attach(device_t, device_t, void *);
     68       1.4     enami static const struct pciide_product_desc *
     69       1.4     enami 		viaide_lookup(pcireg_t);
     70      1.52    dyoung static bool	viaide_suspend(device_t PMF_FN_PROTO);
     71      1.52    dyoung static bool	viaide_resume(device_t PMF_FN_PROTO);
     72       1.1    bouyer 
     73      1.53      cube CFATTACH_DECL_NEW(viaide, sizeof(struct pciide_softc),
     74       1.1    bouyer     viaide_match, viaide_attach, NULL, NULL);
     75       1.1    bouyer 
     76       1.2   thorpej static const struct pciide_product_desc pciide_amd_products[] =  {
     77       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC756_IDE,
     78       1.1    bouyer 	  0,
     79       1.1    bouyer 	  "Advanced Micro Devices AMD756 IDE Controller",
     80       1.1    bouyer 	  via_chip_map
     81       1.1    bouyer 	},
     82       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC766_IDE,
     83       1.1    bouyer 	  0,
     84       1.1    bouyer 	  "Advanced Micro Devices AMD766 IDE Controller",
     85       1.1    bouyer 	  via_chip_map
     86       1.1    bouyer 	},
     87       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC768_IDE,
     88       1.1    bouyer 	  0,
     89       1.1    bouyer 	  "Advanced Micro Devices AMD768 IDE Controller",
     90       1.1    bouyer 	  via_chip_map
     91       1.1    bouyer 	},
     92       1.1    bouyer 	{ PCI_PRODUCT_AMD_PBC8111_IDE,
     93       1.1    bouyer 	  0,
     94       1.1    bouyer 	  "Advanced Micro Devices AMD8111 IDE Controller",
     95       1.1    bouyer 	  via_chip_map
     96       1.1    bouyer 	},
     97      1.38     isaki 	{ PCI_PRODUCT_AMD_CS5536_IDE,
     98      1.38     isaki 	  0,
     99      1.38     isaki 	  "Advanced Micro Devices CS5536 IDE Controller",
    100      1.38     isaki 	  via_chip_map
    101      1.38     isaki 	},
    102       1.1    bouyer 	{ 0,
    103       1.1    bouyer 	  0,
    104       1.1    bouyer 	  NULL,
    105       1.1    bouyer 	  NULL
    106       1.1    bouyer 	}
    107       1.1    bouyer };
    108       1.1    bouyer 
    109       1.2   thorpej static const struct pciide_product_desc pciide_nvidia_products[] = {
    110       1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE_ATA100,
    111       1.1    bouyer 	  0,
    112       1.1    bouyer 	  "NVIDIA nForce IDE Controller",
    113       1.1    bouyer 	  via_chip_map
    114       1.1    bouyer 	},
    115       1.1    bouyer 	{ PCI_PRODUCT_NVIDIA_NFORCE2_ATA133,
    116       1.1    bouyer 	  0,
    117       1.1    bouyer 	  "NVIDIA nForce2 IDE Controller",
    118       1.1    bouyer 	  via_chip_map
    119       1.1    bouyer 	},
    120      1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133,
    121      1.20  jdolecek 	  0,
    122      1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 IDE Controller",
    123      1.20  jdolecek 	  via_chip_map
    124      1.20  jdolecek 	},
    125      1.20  jdolecek 	{ PCI_PRODUCT_NVIDIA_NFORCE2_400_SATA,
    126      1.20  jdolecek 	  0,
    127      1.20  jdolecek 	  "NVIDIA nForce2 Ultra 400 Serial ATA Controller",
    128      1.35    bouyer 	  via_sata_chip_map_6
    129      1.20  jdolecek 	},
    130      1.10      fvdl 	{ PCI_PRODUCT_NVIDIA_NFORCE3_ATA133,
    131      1.10      fvdl 	  0,
    132      1.10      fvdl 	  "NVIDIA nForce3 IDE Controller",
    133      1.10      fvdl 	  via_chip_map
    134      1.10      fvdl 	},
    135      1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133,
    136      1.19   xtraeme 	  0,
    137      1.19   xtraeme 	  "NVIDIA nForce3 250 IDE Controller",
    138      1.19   xtraeme 	  via_chip_map
    139      1.19   xtraeme 	},
    140      1.19   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA,
    141      1.19   xtraeme 	  0,
    142      1.19   xtraeme 	  "NVIDIA nForce3 250 Serial ATA Controller",
    143      1.35    bouyer 	  via_sata_chip_map_6
    144      1.19   xtraeme 	},
    145      1.32   xtraeme 	{ PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA2,
    146      1.32   xtraeme 	  0,
    147      1.32   xtraeme 	  "NVIDIA nForce3 250 Serial ATA Controller",
    148      1.35    bouyer 	  via_sata_chip_map_6
    149      1.32   xtraeme 	},
    150      1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_ATA133,
    151      1.21      kent 	  0,
    152      1.21      kent 	  "NVIDIA nForce4 IDE Controller",
    153      1.21      kent 	  via_chip_map
    154      1.21      kent 	},
    155      1.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA1,
    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.21      kent 	{ PCI_PRODUCT_NVIDIA_NFORCE4_SATA2,
    161      1.21      kent 	  0,
    162      1.21      kent 	  "NVIDIA nForce4 Serial ATA Controller",
    163      1.35    bouyer 	  via_sata_chip_map_6
    164      1.21      kent 	},
    165      1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_ATA133,
    166      1.27      manu 	  0,
    167      1.27      manu 	  "NVIDIA nForce430 IDE Controller",
    168      1.27      manu 	  via_chip_map
    169      1.27      manu 	},
    170      1.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_SATA1,
    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.27      manu 	{ PCI_PRODUCT_NVIDIA_NFORCE430_SATA2,
    176      1.27      manu 	  0,
    177      1.27      manu 	  "NVIDIA nForce430 Serial ATA Controller",
    178      1.35    bouyer 	  via_sata_chip_map_6
    179      1.27      manu 	},
    180      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_IDE,
    181      1.30   xtraeme 	  0,
    182      1.30   xtraeme 	  "NVIDIA MCP04 IDE Controller",
    183      1.30   xtraeme 	  via_chip_map
    184      1.30   xtraeme 	},
    185      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP04_SATA,
    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_MCP04_SATA2,
    191      1.30   xtraeme 	  0,
    192      1.31   xtraeme 	  "NVIDIA MCP04 Serial ATA Controller",
    193      1.35    bouyer 	  via_sata_chip_map_6
    194      1.30   xtraeme 	},
    195      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_IDE,
    196      1.30   xtraeme 	  0,
    197      1.30   xtraeme 	  "NVIDIA MCP55 IDE Controller",
    198      1.30   xtraeme 	  via_chip_map
    199      1.30   xtraeme 	},
    200      1.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_SATA,
    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.30   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP55_SATA2,
    206      1.30   xtraeme 	  0,
    207      1.31   xtraeme 	  "NVIDIA MCP55 Serial ATA Controller",
    208      1.35    bouyer 	  via_sata_chip_map_6
    209      1.30   xtraeme 	},
    210      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_IDE,
    211      1.33   xtraeme 	  0,
    212      1.33   xtraeme 	  "NVIDIA MCP61 IDE Controller",
    213      1.33   xtraeme 	  via_chip_map
    214      1.33   xtraeme 	},
    215      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_IDE,
    216      1.33   xtraeme 	  0,
    217      1.33   xtraeme 	  "NVIDIA MCP65 IDE Controller",
    218      1.33   xtraeme 	  via_chip_map
    219      1.33   xtraeme 	},
    220      1.46   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP73_IDE,
    221      1.46   xtraeme 	  0,
    222      1.46   xtraeme 	  "NVIDIA MCP73 IDE Controller",
    223      1.46   xtraeme 	  via_chip_map
    224      1.46   xtraeme 	},
    225      1.46   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP77_IDE,
    226      1.46   xtraeme 	  0,
    227      1.46   xtraeme 	  "NVIDIA MCP77 IDE Controller",
    228      1.46   xtraeme 	  via_chip_map
    229      1.46   xtraeme 	},
    230      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP61_SATA,
    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_SATA2,
    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_MCP61_SATA3,
    241      1.33   xtraeme 	  0,
    242      1.33   xtraeme 	  "NVIDIA MCP61 Serial ATA Controller",
    243      1.35    bouyer 	  via_sata_chip_map_6
    244      1.33   xtraeme 	},
    245      1.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA,
    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_SATA2,
    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_SATA3,
    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.33   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP65_SATA4,
    261      1.33   xtraeme 	  0,
    262      1.33   xtraeme 	  "NVIDIA MCP65 Serial ATA Controller",
    263      1.35    bouyer 	  via_sata_chip_map_6
    264      1.33   xtraeme 	},
    265      1.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_IDE,
    266      1.43   xtraeme 	  0,
    267      1.43   xtraeme 	  "NVIDIA MCP67 IDE Controller",
    268      1.43   xtraeme 	  via_chip_map,
    269      1.43   xtraeme 	},
    270      1.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_SATA,
    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_SATA2,
    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_SATA3,
    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.43   xtraeme 	{ PCI_PRODUCT_NVIDIA_MCP67_SATA4,
    286      1.43   xtraeme 	  0,
    287      1.43   xtraeme 	  "NVIDIA MCP67 Serial ATA Controller",
    288      1.43   xtraeme 	  via_sata_chip_map_6,
    289      1.43   xtraeme 	},
    290       1.1    bouyer 	{ 0,
    291       1.1    bouyer 	  0,
    292       1.1    bouyer 	  NULL,
    293       1.1    bouyer 	  NULL
    294       1.1    bouyer 	}
    295       1.1    bouyer };
    296       1.1    bouyer 
    297       1.2   thorpej static const struct pciide_product_desc pciide_via_products[] =  {
    298       1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586_IDE,
    299       1.1    bouyer 	  0,
    300       1.1    bouyer 	  NULL,
    301       1.1    bouyer 	  via_chip_map,
    302       1.1    bouyer 	 },
    303       1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT82C586A_IDE,
    304       1.1    bouyer 	  0,
    305       1.1    bouyer 	  NULL,
    306       1.1    bouyer 	  via_chip_map,
    307       1.1    bouyer 	},
    308      1.42   xtraeme 	{ PCI_PRODUCT_VIATECH_CX700_IDE,
    309      1.42   xtraeme 	  0,
    310      1.44   xtraeme 	  NULL,
    311      1.42   xtraeme 	  via_chip_map,
    312      1.42   xtraeme 	},
    313      1.23       abs 	{ PCI_PRODUCT_VIATECH_VT6421_RAID,
    314      1.22       abs 	  0,
    315      1.23       abs 	  "VIA Technologies VT6421 Serial RAID Controller",
    316      1.35    bouyer 	  via_sata_chip_map_new,
    317      1.22       abs 	},
    318       1.1    bouyer 	{ PCI_PRODUCT_VIATECH_VT8237_SATA,
    319       1.6   mycroft 	  0,
    320       1.1    bouyer 	  "VIA Technologies VT8237 SATA Controller",
    321      1.35    bouyer 	  via_sata_chip_map_7,
    322      1.35    bouyer 	},
    323      1.35    bouyer 	{ PCI_PRODUCT_VIATECH_VT8237A_SATA,
    324      1.35    bouyer 	  0,
    325      1.35    bouyer 	  "VIA Technologies VT8237A SATA Controller",
    326      1.41   garbled 	  via_sata_chip_map_7,
    327       1.1    bouyer 	},
    328      1.29   xtraeme 	{ PCI_PRODUCT_VIATECH_VT8237R_SATA,
    329      1.29   xtraeme 	  0,
    330      1.29   xtraeme 	  "VIA Technologies VT8237R SATA Controller",
    331      1.35    bouyer 	  via_sata_chip_map_0,
    332      1.29   xtraeme 	},
    333       1.1    bouyer 	{ 0,
    334       1.1    bouyer 	  0,
    335       1.1    bouyer 	  NULL,
    336       1.1    bouyer 	  NULL
    337       1.1    bouyer 	}
    338       1.1    bouyer };
    339       1.1    bouyer 
    340       1.4     enami static const struct pciide_product_desc *
    341       1.4     enami viaide_lookup(pcireg_t id)
    342       1.4     enami {
    343       1.4     enami 
    344       1.4     enami 	switch (PCI_VENDOR(id)) {
    345       1.4     enami 	case PCI_VENDOR_VIATECH:
    346       1.4     enami 		return (pciide_lookup_product(id, pciide_via_products));
    347       1.4     enami 
    348       1.4     enami 	case PCI_VENDOR_AMD:
    349       1.4     enami 		return (pciide_lookup_product(id, pciide_amd_products));
    350       1.4     enami 
    351       1.4     enami 	case PCI_VENDOR_NVIDIA:
    352       1.4     enami 		return (pciide_lookup_product(id, pciide_nvidia_products));
    353       1.4     enami 	}
    354       1.4     enami 	return (NULL);
    355       1.4     enami }
    356       1.4     enami 
    357       1.2   thorpej static int
    358      1.53      cube viaide_match(device_t parent, cfdata_t match, void *aux)
    359       1.1    bouyer {
    360       1.1    bouyer 	struct pci_attach_args *pa = aux;
    361       1.1    bouyer 
    362       1.4     enami 	if (viaide_lookup(pa->pa_id) != NULL)
    363       1.4     enami 		return (2);
    364       1.1    bouyer 	return (0);
    365       1.1    bouyer }
    366       1.1    bouyer 
    367       1.2   thorpej static void
    368      1.53      cube viaide_attach(device_t parent, device_t self, void *aux)
    369       1.1    bouyer {
    370       1.1    bouyer 	struct pci_attach_args *pa = aux;
    371      1.53      cube 	struct pciide_softc *sc = device_private(self);
    372       1.4     enami 	const struct pciide_product_desc *pp;
    373       1.1    bouyer 
    374      1.53      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    375      1.53      cube 
    376       1.4     enami 	pp = viaide_lookup(pa->pa_id);
    377       1.1    bouyer 	if (pp == NULL)
    378       1.1    bouyer 		panic("viaide_attach");
    379       1.1    bouyer 	pciide_common_attach(sc, pa, pp);
    380      1.51     joerg 
    381      1.51     joerg 	if (!pmf_device_register(self, viaide_suspend, viaide_resume))
    382      1.51     joerg 		aprint_error_dev(self, "couldn't establish power handler\n");
    383       1.1    bouyer }
    384       1.1    bouyer 
    385       1.5      fvdl static int
    386       1.5      fvdl via_pcib_match(struct pci_attach_args *pa)
    387       1.5      fvdl {
    388       1.5      fvdl 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    389       1.5      fvdl 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA &&
    390       1.5      fvdl 	    PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH)
    391       1.5      fvdl 		return (1);
    392       1.5      fvdl 	return 0;
    393       1.5      fvdl }
    394       1.5      fvdl 
    395      1.51     joerg static bool
    396      1.52    dyoung viaide_suspend(device_t dv PMF_FN_ARGS)
    397      1.51     joerg {
    398      1.51     joerg 	struct pciide_softc *sc = device_private(dv);
    399      1.51     joerg 
    400      1.51     joerg 	sc->sc_pm_reg[0] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
    401      1.51     joerg 	/* APO_DATATIM(sc) includes APO_UDMA(sc) */
    402      1.51     joerg 	sc->sc_pm_reg[1] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
    403      1.51     joerg 	/* This two are VIA-only, but should be ignored by other devices. */
    404      1.51     joerg 	sc->sc_pm_reg[2] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc));
    405      1.51     joerg 	sc->sc_pm_reg[3] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_MISCTIM(sc));
    406      1.51     joerg 
    407      1.51     joerg 	return true;
    408      1.51     joerg }
    409      1.51     joerg 
    410      1.51     joerg static bool
    411      1.52    dyoung viaide_resume(device_t dv PMF_FN_ARGS)
    412      1.51     joerg {
    413      1.51     joerg 	struct pciide_softc *sc = device_private(dv);
    414      1.51     joerg 
    415      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc),
    416      1.51     joerg 	    sc->sc_pm_reg[0]);
    417      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc),
    418      1.51     joerg 	    sc->sc_pm_reg[1]);
    419      1.51     joerg 	/* This two are VIA-only, but should be ignored by other devices. */
    420      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc),
    421      1.51     joerg 	    sc->sc_pm_reg[2]);
    422      1.51     joerg 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_MISCTIM(sc),
    423      1.51     joerg 	    sc->sc_pm_reg[3]);
    424      1.51     joerg 
    425      1.51     joerg 	return true;
    426      1.51     joerg }
    427      1.51     joerg 
    428       1.2   thorpej static void
    429       1.2   thorpej via_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    430       1.1    bouyer {
    431       1.1    bouyer 	struct pciide_channel *cp;
    432       1.1    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    433       1.1    bouyer 	pcireg_t vendor = PCI_VENDOR(pa->pa_id);
    434       1.1    bouyer 	int channel;
    435       1.1    bouyer 	u_int32_t ideconf;
    436       1.1    bouyer 	bus_size_t cmdsize, ctlsize;
    437       1.1    bouyer 	pcireg_t pcib_id, pcib_class;
    438       1.5      fvdl 	struct pci_attach_args pcib_pa;
    439       1.1    bouyer 
    440       1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    441       1.1    bouyer 		return;
    442       1.1    bouyer 
    443       1.3     enami 	switch (vendor) {
    444       1.1    bouyer 	case PCI_VENDOR_VIATECH:
    445       1.1    bouyer 		/*
    446       1.5      fvdl 		 * get a PCI tag for the ISA bridge.
    447       1.1    bouyer 		 */
    448      1.12  drochner 		if (pci_find_device(&pcib_pa, via_pcib_match) == 0)
    449       1.5      fvdl 			goto unknown;
    450       1.5      fvdl 		pcib_id = pcib_pa.pa_id;
    451       1.5      fvdl 		pcib_class = pcib_pa.pa_class;
    452      1.53      cube 		aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    453      1.53      cube 		    "VIA Technologies ");
    454       1.1    bouyer 		switch (PCI_PRODUCT(pcib_id)) {
    455       1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    456       1.1    bouyer 			aprint_normal("VT82C586 (Apollo VP) ");
    457       1.1    bouyer 			if(PCI_REVISION(pcib_class) >= 0x02) {
    458       1.1    bouyer 				aprint_normal("ATA33 controller\n");
    459      1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    460       1.1    bouyer 			} else {
    461       1.1    bouyer 				aprint_normal("controller\n");
    462      1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    463       1.1    bouyer 			}
    464       1.1    bouyer 			break;
    465       1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C596A:
    466       1.1    bouyer 			aprint_normal("VT82C596A (Apollo Pro) ");
    467       1.1    bouyer 			if (PCI_REVISION(pcib_class) >= 0x12) {
    468       1.1    bouyer 				aprint_normal("ATA66 controller\n");
    469      1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    470       1.1    bouyer 			} else {
    471       1.1    bouyer 				aprint_normal("ATA33 controller\n");
    472      1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    473       1.1    bouyer 			}
    474       1.1    bouyer 			break;
    475       1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT82C686A_ISA:
    476       1.1    bouyer 			aprint_normal("VT82C686A (Apollo KX133) ");
    477       1.1    bouyer 			if (PCI_REVISION(pcib_class) >= 0x40) {
    478       1.1    bouyer 				aprint_normal("ATA100 controller\n");
    479      1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    480       1.1    bouyer 			} else {
    481       1.1    bouyer 				aprint_normal("ATA66 controller\n");
    482      1.17   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    483       1.1    bouyer 			}
    484       1.1    bouyer 			break;
    485       1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8231:
    486       1.1    bouyer 			aprint_normal("VT8231 ATA100 controller\n");
    487      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    488       1.1    bouyer 			break;
    489       1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8233:
    490       1.1    bouyer 			aprint_normal("VT8233 ATA100 controller\n");
    491      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    492       1.1    bouyer 			break;
    493       1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8233A:
    494       1.1    bouyer 			aprint_normal("VT8233A ATA133 controller\n");
    495      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    496       1.1    bouyer 			break;
    497       1.1    bouyer 		case PCI_PRODUCT_VIATECH_VT8235:
    498       1.1    bouyer 			aprint_normal("VT8235 ATA133 controller\n");
    499      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    500       1.1    bouyer 			break;
    501       1.5      fvdl 		case PCI_PRODUCT_VIATECH_VT8237:
    502       1.1    bouyer 			aprint_normal("VT8237 ATA133 controller\n");
    503      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    504       1.1    bouyer 			break;
    505      1.40   mlelstv 		case PCI_PRODUCT_VIATECH_VT8237A_ISA:
    506      1.40   mlelstv 			aprint_normal("VT8237A ATA133 controller\n");
    507      1.40   mlelstv 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    508      1.40   mlelstv 			break;
    509      1.44   xtraeme 		case PCI_PRODUCT_VIATECH_CX700_IDE:
    510      1.44   xtraeme 			aprint_normal("CX700 ATA133 controller\n");
    511      1.44   xtraeme 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    512      1.44   xtraeme 			break;
    513       1.1    bouyer 		default:
    514       1.5      fvdl unknown:
    515       1.1    bouyer 			aprint_normal("unknown VIA ATA controller\n");
    516      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    517       1.1    bouyer 		}
    518       1.1    bouyer 		sc->sc_apo_regbase = APO_VIA_REGBASE;
    519       1.1    bouyer 		break;
    520       1.1    bouyer 	case PCI_VENDOR_AMD:
    521       1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    522      1.11    bouyer 		case PCI_PRODUCT_AMD_PBC8111_IDE:
    523      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    524      1.11    bouyer 			break;
    525      1.45   xtraeme 		case PCI_PRODUCT_AMD_CS5536_IDE:
    526       1.1    bouyer 		case PCI_PRODUCT_AMD_PBC766_IDE:
    527       1.1    bouyer 		case PCI_PRODUCT_AMD_PBC768_IDE:
    528      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    529       1.1    bouyer 			break;
    530       1.1    bouyer 		default:
    531      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
    532       1.1    bouyer 		}
    533       1.1    bouyer 		sc->sc_apo_regbase = APO_AMD_REGBASE;
    534       1.1    bouyer 		break;
    535       1.1    bouyer 	case PCI_VENDOR_NVIDIA:
    536       1.1    bouyer 		switch (sc->sc_pp->ide_product) {
    537       1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE_ATA100:
    538      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    539       1.1    bouyer 			break;
    540       1.1    bouyer 		case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133:
    541      1.20  jdolecek 		case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133:
    542       1.5      fvdl 		case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133:
    543      1.19   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133:
    544      1.21      kent 		case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133:
    545      1.28   xtraeme 		case PCI_PRODUCT_NVIDIA_NFORCE430_ATA133:
    546      1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP04_IDE:
    547      1.30   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP55_IDE:
    548      1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP61_IDE:
    549      1.33   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP65_IDE:
    550      1.43   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP67_IDE:
    551      1.47   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP73_IDE:
    552      1.47   xtraeme 		case PCI_PRODUCT_NVIDIA_MCP77_IDE:
    553      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    554       1.1    bouyer 			break;
    555       1.1    bouyer 		}
    556       1.1    bouyer 		sc->sc_apo_regbase = APO_NVIDIA_REGBASE;
    557       1.1    bouyer 		break;
    558       1.1    bouyer 	default:
    559       1.1    bouyer 		panic("via_chip_map: unknown vendor");
    560       1.1    bouyer 	}
    561       1.3     enami 
    562      1.53      cube 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    563      1.53      cube 	    "bus-master DMA support present");
    564       1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    565      1.39        ad 	aprint_verbose("\n");
    566      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    567       1.1    bouyer 	if (sc->sc_dma_ok) {
    568      1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    569       1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    570      1.17   thorpej 		if (sc->sc_wdcdev.sc_atac.atac_udma_cap > 0)
    571      1.17   thorpej 			sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
    572       1.1    bouyer 	}
    573      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    574      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    575      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = via_setup_channel;
    576      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    577      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    578       1.1    bouyer 
    579      1.41   garbled 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    580      1.41   garbled 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    581      1.41   garbled 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    582      1.41   garbled 
    583      1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    584      1.15   thorpej 
    585      1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
    586       1.1    bouyer 	    "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    587       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc)),
    588       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc)),
    589       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    590       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))),
    591       1.1    bouyer 	    DEBUG_PROBE);
    592       1.1    bouyer 
    593       1.1    bouyer 	ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
    594      1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    595      1.17   thorpej 	     channel++) {
    596       1.1    bouyer 		cp = &sc->pciide_channels[channel];
    597       1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    598       1.1    bouyer 			continue;
    599       1.1    bouyer 
    600       1.1    bouyer 		if ((ideconf & APO_IDECONF_EN(channel)) == 0) {
    601      1.53      cube 			aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    602      1.53      cube 			    "%s channel ignored (disabled)\n", cp->name);
    603      1.15   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    604       1.1    bouyer 			continue;
    605       1.1    bouyer 		}
    606      1.50       phx 		via_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    607       1.1    bouyer 		    pciide_pci_intr);
    608       1.1    bouyer 	}
    609       1.1    bouyer }
    610       1.1    bouyer 
    611       1.2   thorpej static void
    612      1.50       phx via_mapchan(struct pci_attach_args *pa,	struct pciide_channel *cp,
    613      1.50       phx     pcireg_t interface, bus_size_t *cmdsizep, bus_size_t *ctlsizep,
    614      1.50       phx     int (*pci_intr)(void *))
    615      1.50       phx {
    616      1.50       phx 	struct ata_channel *wdc_cp;
    617      1.50       phx 	struct pciide_softc *sc;
    618      1.50       phx 	prop_bool_t compat_nat_enable;
    619      1.50       phx 
    620      1.50       phx 	wdc_cp = &cp->ata_channel;
    621      1.50       phx 	sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    622      1.50       phx 	compat_nat_enable = prop_dictionary_get(
    623      1.53      cube 	    device_properties(sc->sc_wdcdev.sc_atac.atac_dev),
    624      1.53      cube 	      "use-compat-native-irq");
    625      1.50       phx 
    626      1.50       phx 	if (interface & PCIIDE_INTERFACE_PCI(wdc_cp->ch_channel)) {
    627      1.50       phx 		/* native mode with irq 14/15 requested? */
    628      1.50       phx 		if (compat_nat_enable != NULL &&
    629      1.50       phx 		    prop_bool_true(compat_nat_enable))
    630      1.50       phx 			vt8231_mapregs_native(pa, cp, cmdsizep, ctlsizep,
    631      1.50       phx 			    pci_intr);
    632      1.50       phx 		else
    633      1.50       phx 			pciide_mapregs_native(pa, cp, cmdsizep, ctlsizep,
    634      1.50       phx 			    pci_intr);
    635      1.50       phx 	} else {
    636      1.50       phx 		pciide_mapregs_compat(pa, cp, wdc_cp->ch_channel, cmdsizep,
    637      1.50       phx 		    ctlsizep);
    638      1.50       phx 		if ((cp->ata_channel.ch_flags & ATACH_DISABLED) == 0)
    639      1.50       phx 			pciide_map_compat_intr(pa, cp, wdc_cp->ch_channel);
    640      1.50       phx 	}
    641      1.50       phx 	wdcattach(wdc_cp);
    642      1.50       phx }
    643      1.50       phx 
    644      1.50       phx /*
    645      1.50       phx  * At least under certain (mis)configurations (e.g. on the "Pegasos" board)
    646      1.50       phx  * the VT8231-IDE's native mode only works with irq 14/15, and cannot be
    647      1.50       phx  * programmed to use a single native PCI irq alone. So we install an interrupt
    648      1.50       phx  * handler for each channel, as in compatibility mode.
    649      1.50       phx  */
    650      1.50       phx static void
    651      1.50       phx vt8231_mapregs_native(struct pci_attach_args *pa, struct pciide_channel *cp,
    652      1.50       phx     bus_size_t *cmdsizep, bus_size_t *ctlsizep, int (*pci_intr)(void *))
    653      1.50       phx {
    654      1.50       phx 	struct ata_channel *wdc_cp;
    655      1.50       phx 	struct pciide_softc *sc;
    656      1.50       phx 
    657      1.50       phx 	wdc_cp = &cp->ata_channel;
    658      1.50       phx 	sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    659      1.50       phx 
    660      1.50       phx 	/* XXX prevent pciide_mapregs_native from installing a handler */
    661      1.50       phx 	if (sc->sc_pci_ih == NULL)
    662      1.50       phx 		sc->sc_pci_ih = (void *)~0;
    663      1.50       phx 	pciide_mapregs_native(pa, cp, cmdsizep, ctlsizep, NULL);
    664      1.50       phx 
    665      1.50       phx 	/* interrupts are fixed to 14/15, as in compatibility mode */
    666      1.50       phx 	if ((wdc_cp->ch_flags & ATACH_DISABLED) == 0) {
    667      1.50       phx #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    668      1.50       phx 		cp->ih = pciide_machdep_compat_intr_establish(
    669      1.53      cube 		    sc->sc_wdcdev.sc_atac.atac_dev, pa, wdc_cp->ch_channel,
    670      1.50       phx 		    pci_intr, sc);
    671      1.50       phx 		if (cp->ih == NULL) {
    672      1.50       phx #endif
    673      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    674      1.53      cube 			    "no compatibility interrupt for "
    675      1.53      cube 			    "use by %s channel\n", cp->name);
    676      1.50       phx 			wdc_cp->ch_flags |= ATACH_DISABLED;
    677      1.50       phx #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    678      1.50       phx 		}
    679      1.50       phx 		sc->sc_pci_ih = cp->ih;  /* XXX */
    680      1.50       phx #endif
    681      1.50       phx 	}
    682      1.50       phx }
    683      1.50       phx 
    684      1.50       phx static void
    685      1.15   thorpej via_setup_channel(struct ata_channel *chp)
    686       1.1    bouyer {
    687       1.1    bouyer 	u_int32_t udmatim_reg, datatim_reg;
    688       1.1    bouyer 	u_int8_t idedma_ctl;
    689      1.18   thorpej 	int mode, drive, s;
    690       1.1    bouyer 	struct ata_drive_datas *drvp;
    691      1.17   thorpej 	struct atac_softc *atac = chp->ch_atac;
    692      1.16   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    693      1.16   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    694       1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    695       1.1    bouyer 	int rev = PCI_REVISION(
    696       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
    697       1.1    bouyer #endif
    698       1.1    bouyer 
    699       1.1    bouyer 	idedma_ctl = 0;
    700       1.1    bouyer 	datatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
    701       1.1    bouyer 	udmatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc));
    702       1.9   thorpej 	datatim_reg &= ~APO_DATATIM_MASK(chp->ch_channel);
    703       1.9   thorpej 	udmatim_reg &= ~APO_UDMA_MASK(chp->ch_channel);
    704       1.1    bouyer 
    705       1.1    bouyer 	/* setup DMA if needed */
    706       1.1    bouyer 	pciide_channel_dma_setup(cp);
    707       1.1    bouyer 
    708       1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    709       1.1    bouyer 		drvp = &chp->ch_drive[drive];
    710       1.1    bouyer 		/* If no drive, skip */
    711       1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    712       1.1    bouyer 			continue;
    713       1.1    bouyer 		/* add timing values, setup DMA if needed */
    714       1.1    bouyer 		if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
    715       1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA) == 0)) {
    716       1.1    bouyer 			mode = drvp->PIO_mode;
    717       1.1    bouyer 			goto pio;
    718       1.1    bouyer 		}
    719      1.17   thorpej 		if ((atac->atac_cap & ATAC_CAP_UDMA) &&
    720       1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA)) {
    721       1.1    bouyer 			/* use Ultra/DMA */
    722      1.18   thorpej 			s = splbio();
    723       1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    724      1.18   thorpej 			splx(s);
    725       1.9   thorpej 			udmatim_reg |= APO_UDMA_EN(chp->ch_channel, drive) |
    726       1.9   thorpej 			    APO_UDMA_EN_MTH(chp->ch_channel, drive);
    727       1.3     enami 			switch (PCI_VENDOR(sc->sc_pci_id)) {
    728       1.1    bouyer 			case PCI_VENDOR_VIATECH:
    729      1.17   thorpej 				if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 6) {
    730       1.1    bouyer 					/* 8233a */
    731       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    732       1.9   thorpej 					    chp->ch_channel,
    733       1.1    bouyer 					    drive,
    734       1.1    bouyer 					    via_udma133_tim[drvp->UDMA_mode]);
    735      1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 5) {
    736       1.1    bouyer 					/* 686b */
    737       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    738       1.9   thorpej 					    chp->ch_channel,
    739       1.1    bouyer 					    drive,
    740       1.1    bouyer 					    via_udma100_tim[drvp->UDMA_mode]);
    741      1.17   thorpej 				} else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 4) {
    742       1.1    bouyer 					/* 596b or 686a */
    743       1.1    bouyer 					udmatim_reg |= APO_UDMA_CLK66(
    744       1.9   thorpej 					    chp->ch_channel);
    745       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    746       1.9   thorpej 					    chp->ch_channel,
    747       1.1    bouyer 					    drive,
    748       1.1    bouyer 					    via_udma66_tim[drvp->UDMA_mode]);
    749       1.1    bouyer 				} else {
    750       1.1    bouyer 					/* 596a or 586b */
    751       1.1    bouyer 					udmatim_reg |= APO_UDMA_TIME(
    752       1.9   thorpej 					    chp->ch_channel,
    753       1.1    bouyer 					    drive,
    754       1.1    bouyer 					    via_udma33_tim[drvp->UDMA_mode]);
    755       1.1    bouyer 				}
    756       1.1    bouyer 				break;
    757       1.1    bouyer 			case PCI_VENDOR_AMD:
    758       1.1    bouyer 			case PCI_VENDOR_NVIDIA:
    759       1.9   thorpej 				udmatim_reg |= APO_UDMA_TIME(chp->ch_channel,
    760       1.1    bouyer 				    drive, amd7x6_udma_tim[drvp->UDMA_mode]);
    761       1.1    bouyer 				 break;
    762       1.1    bouyer 			}
    763       1.1    bouyer 			/* can use PIO timings, MW DMA unused */
    764       1.1    bouyer 			mode = drvp->PIO_mode;
    765       1.1    bouyer 		} else {
    766       1.1    bouyer 			/* use Multiword DMA, but only if revision is OK */
    767      1.18   thorpej 			s = splbio();
    768       1.1    bouyer 			drvp->drive_flags &= ~DRIVE_UDMA;
    769      1.18   thorpej 			splx(s);
    770       1.1    bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
    771       1.1    bouyer 			/*
    772       1.1    bouyer 			 * The workaround doesn't seem to be necessary
    773       1.1    bouyer 			 * with all drives, so it can be disabled by
    774       1.1    bouyer 			 * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
    775       1.1    bouyer 			 * triggered.
    776       1.1    bouyer 			 */
    777       1.1    bouyer 			if (PCI_VENDOR(sc->sc_pci_id) == PCI_VENDOR_AMD &&
    778       1.1    bouyer 			    sc->sc_pp->ide_product ==
    779       1.3     enami 			    PCI_PRODUCT_AMD_PBC756_IDE &&
    780       1.1    bouyer 			    AMD756_CHIPREV_DISABLEDMA(rev)) {
    781       1.1    bouyer 				aprint_normal(
    782       1.1    bouyer 				    "%s:%d:%d: multi-word DMA disabled due "
    783       1.1    bouyer 				    "to chip revision\n",
    784      1.53      cube 				    device_xname(
    785      1.53      cube 				      sc->sc_wdcdev.sc_atac.atac_dev),
    786       1.9   thorpej 				    chp->ch_channel, drive);
    787       1.1    bouyer 				mode = drvp->PIO_mode;
    788      1.18   thorpej 				s = splbio();
    789       1.1    bouyer 				drvp->drive_flags &= ~DRIVE_DMA;
    790      1.18   thorpej 				splx(s);
    791       1.1    bouyer 				goto pio;
    792       1.1    bouyer 			}
    793       1.1    bouyer #endif
    794       1.1    bouyer 			/* mode = min(pio, dma+2) */
    795       1.3     enami 			if (drvp->PIO_mode <= (drvp->DMA_mode + 2))
    796       1.1    bouyer 				mode = drvp->PIO_mode;
    797       1.1    bouyer 			else
    798       1.1    bouyer 				mode = drvp->DMA_mode + 2;
    799       1.1    bouyer 		}
    800       1.1    bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    801       1.1    bouyer 
    802       1.1    bouyer pio:		/* setup PIO mode */
    803       1.1    bouyer 		if (mode <= 2) {
    804       1.1    bouyer 			drvp->DMA_mode = 0;
    805       1.1    bouyer 			drvp->PIO_mode = 0;
    806       1.1    bouyer 			mode = 0;
    807       1.1    bouyer 		} else {
    808       1.1    bouyer 			drvp->PIO_mode = mode;
    809       1.1    bouyer 			drvp->DMA_mode = mode - 2;
    810       1.1    bouyer 		}
    811       1.1    bouyer 		datatim_reg |=
    812       1.9   thorpej 		    APO_DATATIM_PULSE(chp->ch_channel, drive,
    813       1.1    bouyer 			apollo_pio_set[mode]) |
    814       1.9   thorpej 		    APO_DATATIM_RECOV(chp->ch_channel, drive,
    815       1.1    bouyer 			apollo_pio_rec[mode]);
    816       1.1    bouyer 	}
    817       1.1    bouyer 	if (idedma_ctl != 0) {
    818       1.1    bouyer 		/* Add software bits in status register */
    819       1.7      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    820       1.1    bouyer 		    idedma_ctl);
    821       1.1    bouyer 	}
    822       1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc), datatim_reg);
    823       1.1    bouyer 	pci_conf_write(sc->sc_pc, sc->sc_tag, APO_UDMA(sc), udmatim_reg);
    824      1.14   thorpej 	ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
    825       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
    826       1.1    bouyer 	    pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))), DEBUG_PROBE);
    827       1.1    bouyer }
    828       1.1    bouyer 
    829      1.35    bouyer static int
    830      1.35    bouyer via_sata_chip_map_common(struct pciide_softc *sc, struct pci_attach_args *pa)
    831       1.1    bouyer {
    832      1.35    bouyer 	bus_size_t satasize;
    833      1.36    bouyer 	int maptype, ret;
    834       1.1    bouyer 
    835       1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    836      1.35    bouyer 		return 0;
    837       1.1    bouyer 
    838      1.53      cube 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    839      1.53      cube 	    "bus-master DMA support present");
    840       1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    841      1.39        ad 	aprint_verbose("\n");
    842       1.1    bouyer 
    843       1.1    bouyer 	if (sc->sc_dma_ok) {
    844      1.17   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
    845       1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    846       1.1    bouyer 	}
    847      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    848      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    849      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    850      1.17   thorpej 
    851      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    852      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    853      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    854      1.17   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    855       1.1    bouyer 
    856      1.41   garbled 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    857      1.41   garbled 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    858      1.41   garbled 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    859      1.41   garbled 
    860      1.15   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    861      1.36    bouyer 	maptype = pci_mapreg_type(pa->pa_pc, pa->pa_tag,
    862      1.36    bouyer 	    PCI_MAPREG_START + 0x14);
    863      1.36    bouyer 	switch(maptype) {
    864      1.36    bouyer 	case PCI_MAPREG_TYPE_IO:
    865      1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    866      1.36    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    867      1.36    bouyer 		    NULL, &satasize);
    868      1.36    bouyer 		break;
    869      1.36    bouyer 	case PCI_MAPREG_MEM_TYPE_32BIT:
    870      1.36    bouyer 		ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
    871      1.35    bouyer 		    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    872      1.35    bouyer 		    0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
    873      1.36    bouyer 		    NULL, &satasize);
    874      1.36    bouyer 		break;
    875      1.36    bouyer 	default:
    876      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    877  1.53.2.1      yamt 		    "couldn't map sata regs, unsupported maptype (0x%x)\n",
    878      1.36    bouyer 		    maptype);
    879      1.36    bouyer 		return 0;
    880      1.36    bouyer 	}
    881      1.36    bouyer 	if (ret != 0) {
    882      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    883      1.53      cube 		    "couldn't map sata regs\n");
    884      1.36    bouyer 		return 0;
    885      1.35    bouyer 	}
    886      1.35    bouyer 	return 1;
    887      1.35    bouyer }
    888      1.35    bouyer 
    889      1.35    bouyer static void
    890      1.35    bouyer via_sata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa,
    891      1.35    bouyer     int satareg_shift)
    892      1.35    bouyer {
    893      1.35    bouyer 	struct pciide_channel *cp;
    894      1.35    bouyer 	struct ata_channel *wdc_cp;
    895      1.35    bouyer 	struct wdc_regs *wdr;
    896      1.35    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    897      1.35    bouyer 	int channel;
    898      1.35    bouyer 	bus_size_t cmdsize, ctlsize;
    899      1.35    bouyer 
    900      1.35    bouyer 	if (via_sata_chip_map_common(sc, pa) == 0)
    901      1.35    bouyer 		return;
    902      1.35    bouyer 
    903      1.35    bouyer 	if (interface == 0) {
    904      1.35    bouyer 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    905      1.35    bouyer 		    DEBUG_PROBE);
    906      1.35    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    907      1.35    bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    908      1.35    bouyer 	}
    909      1.15   thorpej 
    910      1.17   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    911      1.17   thorpej 	     channel++) {
    912       1.1    bouyer 		cp = &sc->pciide_channels[channel];
    913       1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    914       1.1    bouyer 			continue;
    915      1.35    bouyer 		wdc_cp = &cp->ata_channel;
    916      1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    917      1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
    918      1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
    919      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    920      1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x0, 1,
    921      1.35    bouyer 		    &wdr->sata_status) != 0) {
    922      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    923      1.53      cube 			    "couldn't map channel %d sata_status regs\n",
    924      1.35    bouyer 			    wdc_cp->ch_channel);
    925      1.35    bouyer 			continue;
    926      1.35    bouyer 		}
    927      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    928      1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x4, 1,
    929      1.35    bouyer 		    &wdr->sata_error) != 0) {
    930      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    931      1.53      cube 			    "couldn't map channel %d sata_error regs\n",
    932      1.35    bouyer 			    wdc_cp->ch_channel);
    933      1.35    bouyer 			continue;
    934      1.35    bouyer 		}
    935      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    936      1.35    bouyer 		    (wdc_cp->ch_channel << satareg_shift) + 0x8, 1,
    937      1.35    bouyer 		    &wdr->sata_control) != 0) {
    938      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    939      1.53      cube 			    "couldn't map channel %d sata_control regs\n",
    940      1.35    bouyer 			    wdc_cp->ch_channel);
    941      1.35    bouyer 			continue;
    942      1.35    bouyer 		}
    943      1.35    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    944       1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    945       1.3     enami 		    pciide_pci_intr);
    946       1.1    bouyer 	}
    947       1.1    bouyer }
    948      1.35    bouyer 
    949      1.35    bouyer static void
    950      1.35    bouyer via_sata_chip_map_0(struct pciide_softc *sc, struct pci_attach_args *pa)
    951      1.35    bouyer {
    952      1.35    bouyer 	via_sata_chip_map(sc, pa, 0);
    953      1.35    bouyer }
    954      1.35    bouyer 
    955      1.35    bouyer static void
    956      1.35    bouyer via_sata_chip_map_6(struct pciide_softc *sc, struct pci_attach_args *pa)
    957      1.35    bouyer {
    958      1.35    bouyer 	via_sata_chip_map(sc, pa, 6);
    959      1.35    bouyer }
    960      1.35    bouyer 
    961      1.35    bouyer static void
    962      1.35    bouyer via_sata_chip_map_7(struct pciide_softc *sc, struct pci_attach_args *pa)
    963      1.35    bouyer {
    964      1.35    bouyer 	via_sata_chip_map(sc, pa, 7);
    965      1.35    bouyer }
    966      1.35    bouyer 
    967      1.35    bouyer static void
    968      1.35    bouyer via_sata_chip_map_new(struct pciide_softc *sc, struct pci_attach_args *pa)
    969      1.35    bouyer {
    970      1.35    bouyer 	struct pciide_channel *cp;
    971      1.35    bouyer 	struct ata_channel *wdc_cp;
    972      1.35    bouyer 	struct wdc_regs *wdr;
    973      1.35    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    974      1.35    bouyer 	int channel;
    975      1.35    bouyer 	bus_size_t cmdsize;
    976      1.35    bouyer 	pci_intr_handle_t intrhandle;
    977      1.35    bouyer 	const char *intrstr;
    978      1.35    bouyer 	int i;
    979      1.35    bouyer 
    980      1.35    bouyer 	if (via_sata_chip_map_common(sc, pa) == 0)
    981      1.35    bouyer 		return;
    982      1.35    bouyer 
    983      1.35    bouyer 	if (interface == 0) {
    984      1.35    bouyer 		ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
    985      1.35    bouyer 		    DEBUG_PROBE);
    986      1.35    bouyer 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    987      1.35    bouyer 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    988      1.35    bouyer 	}
    989      1.35    bouyer 
    990      1.35    bouyer 	if (pci_intr_map(pa, &intrhandle) != 0) {
    991      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    992      1.53      cube 		    "couldn't map native-PCI interrupt\n");
    993      1.35    bouyer 		return;
    994      1.35    bouyer 	}
    995      1.35    bouyer 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    996      1.35    bouyer 	sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    997      1.35    bouyer 	    intrhandle, IPL_BIO, pciide_pci_intr, sc);
    998      1.35    bouyer 	if (sc->sc_pci_ih == NULL) {
    999      1.53      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1000      1.53      cube 		    "couldn't establish native-PCI interrupt");
   1001      1.35    bouyer 		if (intrstr != NULL)
   1002      1.35    bouyer 		    aprint_error(" at %s", intrstr);
   1003      1.35    bouyer 		aprint_error("\n");
   1004      1.35    bouyer 		return;
   1005      1.35    bouyer 	}
   1006      1.53      cube 	aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1007      1.53      cube 	    "using %s for native-PCI interrupt\n",
   1008      1.35    bouyer 	    intrstr ? intrstr : "unknown interrupt");
   1009      1.35    bouyer 
   1010      1.35    bouyer 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
   1011      1.35    bouyer 	     channel++) {
   1012      1.35    bouyer 		cp = &sc->pciide_channels[channel];
   1013      1.35    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
   1014      1.35    bouyer 			continue;
   1015      1.35    bouyer 		cp->ata_channel.ch_ndrive = 1;
   1016      1.35    bouyer 		wdc_cp = &cp->ata_channel;
   1017      1.35    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
   1018      1.35    bouyer 
   1019      1.35    bouyer 		wdr->sata_iot = sc->sc_ba5_st;
   1020      1.35    bouyer 		wdr->sata_baseioh = sc->sc_ba5_sh;
   1021      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
   1022      1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x0, 1,
   1023      1.35    bouyer 		    &wdr->sata_status) != 0) {
   1024      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1025      1.53      cube 			    "couldn't map channel %d sata_status regs\n",
   1026      1.35    bouyer 			    wdc_cp->ch_channel);
   1027      1.35    bouyer 			continue;
   1028      1.35    bouyer 		}
   1029      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
   1030      1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x4, 1,
   1031      1.35    bouyer 		    &wdr->sata_error) != 0) {
   1032      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1033      1.53      cube 			    "couldn't map channel %d sata_error regs\n",
   1034      1.35    bouyer 			    wdc_cp->ch_channel);
   1035      1.35    bouyer 			continue;
   1036      1.35    bouyer 		}
   1037      1.35    bouyer 		if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
   1038      1.35    bouyer 		    (wdc_cp->ch_channel << 6) + 0x8, 1,
   1039      1.35    bouyer 		    &wdr->sata_control) != 0) {
   1040      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1041      1.53      cube 			    "couldn't map channel %d sata_control regs\n",
   1042      1.35    bouyer 			    wdc_cp->ch_channel);
   1043      1.35    bouyer 			continue;
   1044      1.35    bouyer 		}
   1045      1.35    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
   1046      1.35    bouyer 
   1047      1.35    bouyer 		if (pci_mapreg_map(pa, (0x10 + (4 * (channel))),
   1048      1.35    bouyer 		    PCI_MAPREG_TYPE_IO, 0, &wdr->cmd_iot, &wdr->cmd_baseioh,
   1049      1.35    bouyer 		    NULL, &cmdsize) != 0) {
   1050      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1051      1.53      cube 			    "couldn't map %s channel regs\n", cp->name);
   1052      1.35    bouyer 		}
   1053      1.35    bouyer 		wdr->ctl_iot = wdr->cmd_iot;
   1054      1.35    bouyer 		for (i = 0; i < WDC_NREG; i++) {
   1055      1.35    bouyer 			if (bus_space_subregion(wdr->cmd_iot,
   1056      1.35    bouyer 			    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
   1057      1.35    bouyer 			    &wdr->cmd_iohs[i]) != 0) {
   1058      1.53      cube 				aprint_error_dev(
   1059      1.53      cube 				    sc->sc_wdcdev.sc_atac.atac_dev,
   1060      1.53      cube 				    "couldn't subregion %s "
   1061      1.53      cube 				    "channel cmd regs\n", cp->name);
   1062      1.35    bouyer 				return;
   1063      1.35    bouyer 			}
   1064      1.35    bouyer 		}
   1065      1.35    bouyer 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
   1066      1.35    bouyer 		    WDC_NREG + 2, 1,  &wdr->ctl_ioh) != 0) {
   1067      1.53      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
   1068      1.53      cube 			    "couldn't map channel %d ctl regs\n", channel);
   1069      1.35    bouyer 			return;
   1070      1.35    bouyer 		}
   1071      1.35    bouyer 		wdc_init_shadow_regs(wdc_cp);
   1072      1.35    bouyer 		wdcattach(wdc_cp);
   1073      1.35    bouyer 	}
   1074      1.35    bouyer }
   1075