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