Home | History | Annotate | Line # | Download | only in pci
siside.c revision 1.18.16.1
      1  1.18.16.1   gdamore /*	$NetBSD: siside.c,v 1.18.16.1 2006/07/13 17:49:29 gdamore 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.14     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.15     lukem #include <sys/cdefs.h>
     33  1.18.16.1   gdamore __KERNEL_RCSID(0, "$NetBSD: siside.c,v 1.18.16.1 2006/07/13 17:49:29 gdamore Exp $");
     34       1.15     lukem 
     35        1.1    bouyer #include <sys/param.h>
     36        1.1    bouyer #include <sys/systm.h>
     37        1.1    bouyer 
     38        1.1    bouyer #include <dev/pci/pcivar.h>
     39        1.1    bouyer #include <dev/pci/pcidevs.h>
     40        1.1    bouyer #include <dev/pci/pciidereg.h>
     41        1.1    bouyer #include <dev/pci/pciidevar.h>
     42        1.1    bouyer #include <dev/pci/pciide_sis_reg.h>
     43        1.1    bouyer 
     44        1.2   thorpej static void sis_chip_map(struct pciide_softc *, struct pci_attach_args *);
     45        1.6       skd static void sis_sata_chip_map(struct pciide_softc *, struct pci_attach_args *);
     46       1.10   thorpej static void sis_setup_channel(struct ata_channel *);
     47       1.10   thorpej static void sis96x_setup_channel(struct ata_channel *);
     48        1.2   thorpej 
     49        1.2   thorpej static int  sis_hostbr_match(struct pci_attach_args *);
     50        1.2   thorpej static int  sis_south_match(struct pci_attach_args *);
     51        1.1    bouyer 
     52        1.2   thorpej static int  siside_match(struct device *, struct cfdata *, void *);
     53        1.2   thorpej static void siside_attach(struct device *, struct device *, void *);
     54        1.1    bouyer 
     55        1.1    bouyer CFATTACH_DECL(siside, sizeof(struct pciide_softc),
     56        1.1    bouyer     siside_match, siside_attach, NULL, NULL);
     57        1.1    bouyer 
     58        1.2   thorpej static const struct pciide_product_desc pciide_sis_products[] =  {
     59        1.1    bouyer 	{ PCI_PRODUCT_SIS_5597_IDE,
     60        1.1    bouyer 	  0,
     61        1.1    bouyer 	  NULL,
     62        1.1    bouyer 	  sis_chip_map,
     63        1.1    bouyer 	},
     64        1.6       skd 	{ PCI_PRODUCT_SIS_180_SATA,
     65        1.6       skd 	  0,
     66        1.6       skd 	  NULL,
     67        1.6       skd 	  sis_sata_chip_map,
     68        1.6       skd 	},
     69  1.18.16.1   gdamore 	{ PCI_PRODUCT_SIS_181_SATA,
     70  1.18.16.1   gdamore 	  0,
     71  1.18.16.1   gdamore 	  NULL,
     72  1.18.16.1   gdamore 	  sis_sata_chip_map,
     73  1.18.16.1   gdamore 	},
     74  1.18.16.1   gdamore 	{ PCI_PRODUCT_SIS_182_SATA,
     75  1.18.16.1   gdamore 	  0,
     76  1.18.16.1   gdamore 	  NULL,
     77  1.18.16.1   gdamore 	  sis_sata_chip_map,
     78  1.18.16.1   gdamore 	},
     79        1.1    bouyer 	{ 0,
     80        1.1    bouyer 	  0,
     81        1.1    bouyer 	  NULL,
     82        1.1    bouyer 	  NULL
     83        1.1    bouyer 	}
     84        1.1    bouyer };
     85        1.1    bouyer 
     86        1.2   thorpej static int
     87        1.2   thorpej siside_match(struct device *parent, struct cfdata *match, void *aux)
     88        1.1    bouyer {
     89        1.1    bouyer 	struct pci_attach_args *pa = aux;
     90        1.1    bouyer 
     91        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SIS) {
     92        1.1    bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_sis_products))
     93        1.1    bouyer 			return (2);
     94        1.1    bouyer 	}
     95        1.1    bouyer 	return (0);
     96        1.1    bouyer }
     97        1.1    bouyer 
     98        1.2   thorpej static void
     99        1.2   thorpej siside_attach(struct device *parent, struct device *self, void *aux)
    100        1.1    bouyer {
    101        1.1    bouyer 	struct pci_attach_args *pa = aux;
    102        1.1    bouyer 	struct pciide_softc *sc = (struct pciide_softc *)self;
    103        1.1    bouyer 
    104        1.1    bouyer 	pciide_common_attach(sc, pa,
    105        1.1    bouyer 	    pciide_lookup_product(pa->pa_id, pciide_sis_products));
    106        1.1    bouyer 
    107        1.1    bouyer }
    108        1.1    bouyer 
    109        1.1    bouyer static struct sis_hostbr_type {
    110        1.1    bouyer 	u_int16_t id;
    111        1.1    bouyer 	u_int8_t rev;
    112        1.1    bouyer 	u_int8_t udma_mode;
    113       1.16  christos 	const char *name;
    114        1.1    bouyer 	u_int8_t type;
    115        1.1    bouyer #define SIS_TYPE_NOUDMA	0
    116        1.1    bouyer #define SIS_TYPE_66	1
    117        1.1    bouyer #define SIS_TYPE_100OLD	2
    118        1.1    bouyer #define SIS_TYPE_100NEW 3
    119        1.1    bouyer #define SIS_TYPE_133OLD 4
    120        1.1    bouyer #define SIS_TYPE_133NEW 5
    121        1.1    bouyer #define SIS_TYPE_SOUTH	6
    122        1.1    bouyer } sis_hostbr_type[] = {
    123        1.1    bouyer 	/* Most infos here are from sos (at) freebsd.org */
    124        1.1    bouyer 	{PCI_PRODUCT_SIS_530HB, 0x00, 4, "530", SIS_TYPE_66},
    125        1.1    bouyer #if 0
    126        1.1    bouyer 	/*
    127        1.1    bouyer 	 * controllers associated to a rev 0x2 530 Host to PCI Bridge
    128        1.1    bouyer 	 * have problems with UDMA (info provided by Christos)
    129        1.1    bouyer 	 */
    130        1.1    bouyer 	{PCI_PRODUCT_SIS_530HB, 0x02, 0, "530 (buggy)", SIS_TYPE_NOUDMA},
    131        1.1    bouyer #endif
    132        1.1    bouyer 	{PCI_PRODUCT_SIS_540HB, 0x00, 4, "540", SIS_TYPE_66},
    133        1.1    bouyer 	{PCI_PRODUCT_SIS_550HB, 0x00, 4, "550", SIS_TYPE_66},
    134        1.1    bouyer 	{PCI_PRODUCT_SIS_620,   0x00, 4, "620", SIS_TYPE_66},
    135        1.1    bouyer 	{PCI_PRODUCT_SIS_630,   0x00, 4, "630", SIS_TYPE_66},
    136        1.1    bouyer 	{PCI_PRODUCT_SIS_630,   0x30, 5, "630S", SIS_TYPE_100NEW},
    137        1.1    bouyer 	{PCI_PRODUCT_SIS_633,   0x00, 5, "633", SIS_TYPE_100NEW},
    138        1.1    bouyer 	{PCI_PRODUCT_SIS_635,   0x00, 5, "635", SIS_TYPE_100NEW},
    139        1.1    bouyer 	{PCI_PRODUCT_SIS_640,   0x00, 4, "640", SIS_TYPE_SOUTH},
    140        1.1    bouyer 	{PCI_PRODUCT_SIS_645,   0x00, 6, "645", SIS_TYPE_SOUTH},
    141        1.1    bouyer 	{PCI_PRODUCT_SIS_646,   0x00, 6, "645DX", SIS_TYPE_SOUTH},
    142        1.1    bouyer 	{PCI_PRODUCT_SIS_648,   0x00, 6, "648", SIS_TYPE_SOUTH},
    143        1.1    bouyer 	{PCI_PRODUCT_SIS_650,   0x00, 6, "650", SIS_TYPE_SOUTH},
    144        1.1    bouyer 	{PCI_PRODUCT_SIS_651,   0x00, 6, "651", SIS_TYPE_SOUTH},
    145        1.1    bouyer 	{PCI_PRODUCT_SIS_652,   0x00, 6, "652", SIS_TYPE_SOUTH},
    146        1.1    bouyer 	{PCI_PRODUCT_SIS_655,   0x00, 6, "655", SIS_TYPE_SOUTH},
    147        1.1    bouyer 	{PCI_PRODUCT_SIS_658,   0x00, 6, "658", SIS_TYPE_SOUTH},
    148  1.18.16.1   gdamore 	{PCI_PRODUCT_SIS_661,	0x00, 6, "661", SIS_TYPE_SOUTH},
    149        1.1    bouyer 	{PCI_PRODUCT_SIS_730,   0x00, 5, "730", SIS_TYPE_100OLD},
    150        1.1    bouyer 	{PCI_PRODUCT_SIS_733,   0x00, 5, "733", SIS_TYPE_100NEW},
    151        1.1    bouyer 	{PCI_PRODUCT_SIS_735,   0x00, 5, "735", SIS_TYPE_100NEW},
    152        1.1    bouyer 	{PCI_PRODUCT_SIS_740,   0x00, 5, "740", SIS_TYPE_SOUTH},
    153        1.7   mycroft 	{PCI_PRODUCT_SIS_741,   0x00, 5, "741", SIS_TYPE_SOUTH},
    154        1.1    bouyer 	{PCI_PRODUCT_SIS_745,   0x00, 5, "745", SIS_TYPE_100NEW},
    155        1.1    bouyer 	{PCI_PRODUCT_SIS_746,   0x00, 6, "746", SIS_TYPE_SOUTH},
    156        1.1    bouyer 	{PCI_PRODUCT_SIS_748,   0x00, 6, "748", SIS_TYPE_SOUTH},
    157        1.1    bouyer 	{PCI_PRODUCT_SIS_750,   0x00, 6, "750", SIS_TYPE_SOUTH},
    158        1.1    bouyer 	{PCI_PRODUCT_SIS_751,   0x00, 6, "751", SIS_TYPE_SOUTH},
    159        1.1    bouyer 	{PCI_PRODUCT_SIS_752,   0x00, 6, "752", SIS_TYPE_SOUTH},
    160        1.1    bouyer 	{PCI_PRODUCT_SIS_755,   0x00, 6, "755", SIS_TYPE_SOUTH},
    161  1.18.16.1   gdamore 	{PCI_PRODUCT_SIS_760,	0x00, 6, "760", SIS_TYPE_133NEW},
    162        1.1    bouyer 	/*
    163        1.1    bouyer 	 * From sos (at) freebsd.org: the 0x961 ID will never be found in real world
    164        1.1    bouyer 	 * {PCI_PRODUCT_SIS_961,   0x00, 6, "961", SIS_TYPE_133NEW},
    165        1.1    bouyer 	 */
    166        1.1    bouyer 	{PCI_PRODUCT_SIS_962,   0x00, 6, "962", SIS_TYPE_133NEW},
    167        1.1    bouyer 	{PCI_PRODUCT_SIS_963,   0x00, 6, "963", SIS_TYPE_133NEW},
    168        1.6       skd 	{PCI_PRODUCT_SIS_964,   0x00, 6, "964", SIS_TYPE_133NEW},
    169       1.17    bouyer 	{PCI_PRODUCT_SIS_965,   0x00, 6, "965", SIS_TYPE_133NEW},
    170        1.1    bouyer };
    171        1.1    bouyer 
    172        1.1    bouyer static struct sis_hostbr_type *sis_hostbr_type_match;
    173        1.1    bouyer 
    174        1.1    bouyer static int
    175        1.2   thorpej sis_hostbr_match(struct pci_attach_args *pa)
    176        1.1    bouyer {
    177        1.1    bouyer 	int i;
    178       1.17    bouyer 	pcireg_t id, reg;
    179        1.2   thorpej 
    180        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_SIS)
    181        1.1    bouyer 		return 0;
    182       1.17    bouyer 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SIS_85C503) {
    183       1.17    bouyer 		reg = pci_conf_read(pa->pa_pc, pa->pa_tag, SIS96x_DETECT);
    184       1.17    bouyer 		pci_conf_write(pa->pa_pc, pa->pa_tag, SIS96x_DETECT,
    185       1.17    bouyer 		    reg | SIS96x_DETECT_MASQ);
    186       1.17    bouyer 		id = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_ID_REG);
    187       1.17    bouyer 		if (((PCI_PRODUCT(id) & 0xfff0) != 0x0960)
    188       1.17    bouyer 		    && (PCI_PRODUCT(id) != 0x0018)) {
    189       1.17    bouyer 			pci_conf_write(pa->pa_pc, pa->pa_tag, SIS96x_DETECT,
    190       1.17    bouyer 			    reg);
    191       1.17    bouyer 		} else {
    192       1.17    bouyer 			pa->pa_id = id;
    193       1.17    bouyer 		}
    194       1.17    bouyer 	}
    195       1.17    bouyer 
    196        1.1    bouyer 	sis_hostbr_type_match = NULL;
    197        1.1    bouyer 	for (i = 0;
    198        1.1    bouyer 	    i < sizeof(sis_hostbr_type) / sizeof(sis_hostbr_type[0]);
    199        1.1    bouyer 	    i++) {
    200        1.1    bouyer 		if (PCI_PRODUCT(pa->pa_id) == sis_hostbr_type[i].id &&
    201        1.1    bouyer 		    PCI_REVISION(pa->pa_class) >= sis_hostbr_type[i].rev)
    202        1.1    bouyer 			sis_hostbr_type_match = &sis_hostbr_type[i];
    203        1.1    bouyer 	}
    204        1.1    bouyer 	return (sis_hostbr_type_match != NULL);
    205        1.1    bouyer }
    206        1.1    bouyer 
    207        1.2   thorpej static int
    208        1.2   thorpej sis_south_match(struct pci_attach_args *pa)
    209        1.1    bouyer {
    210        1.2   thorpej 
    211        1.2   thorpej 	return (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SIS &&
    212        1.1    bouyer 		PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SIS_85C503 &&
    213        1.1    bouyer 		PCI_REVISION(pa->pa_class) >= 0x10);
    214        1.1    bouyer }
    215        1.1    bouyer 
    216        1.2   thorpej static void
    217        1.2   thorpej sis_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    218        1.1    bouyer {
    219        1.1    bouyer 	struct pciide_channel *cp;
    220        1.1    bouyer 	int channel;
    221        1.1    bouyer 	u_int8_t sis_ctr0 = pciide_pci_read(sc->sc_pc, sc->sc_tag, SIS_CTRL0);
    222        1.1    bouyer 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    223        1.1    bouyer 	pcireg_t rev = PCI_REVISION(pa->pa_class);
    224        1.1    bouyer 	bus_size_t cmdsize, ctlsize;
    225        1.1    bouyer 
    226        1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    227        1.1    bouyer 		return;
    228        1.1    bouyer 
    229        1.6       skd 	aprint_normal("%s: Silicon Integrated Systems ",
    230       1.12   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    231        1.1    bouyer 	pci_find_device(NULL, sis_hostbr_match);
    232        1.1    bouyer 	if (sis_hostbr_type_match) {
    233        1.1    bouyer 		if (sis_hostbr_type_match->type == SIS_TYPE_SOUTH) {
    234        1.1    bouyer 			pciide_pci_write(sc->sc_pc, sc->sc_tag, SIS_REG_57,
    235        1.1    bouyer 			    pciide_pci_read(sc->sc_pc, sc->sc_tag,
    236        1.1    bouyer 			    SIS_REG_57) & 0x7f);
    237        1.1    bouyer 			if (PCI_PRODUCT(pci_conf_read(sc->sc_pc, sc->sc_tag,
    238        1.1    bouyer 			    PCI_ID_REG)) == SIS_PRODUCT_5518) {
    239        1.1    bouyer 				aprint_normal("96X UDMA%d",
    240        1.1    bouyer 				    sis_hostbr_type_match->udma_mode);
    241        1.1    bouyer 				sc->sis_type = SIS_TYPE_133NEW;
    242       1.12   thorpej 				sc->sc_wdcdev.sc_atac.atac_udma_cap =
    243        1.1    bouyer 			    	    sis_hostbr_type_match->udma_mode;
    244        1.1    bouyer 			} else {
    245        1.1    bouyer 				if (pci_find_device(NULL, sis_south_match)) {
    246        1.1    bouyer 					sc->sis_type = SIS_TYPE_133OLD;
    247       1.12   thorpej 					sc->sc_wdcdev.sc_atac.atac_udma_cap =
    248        1.1    bouyer 				    	    sis_hostbr_type_match->udma_mode;
    249        1.1    bouyer 				} else {
    250        1.1    bouyer 					sc->sis_type = SIS_TYPE_100NEW;
    251       1.12   thorpej 					sc->sc_wdcdev.sc_atac.atac_udma_cap =
    252        1.1    bouyer 					    sis_hostbr_type_match->udma_mode;
    253        1.1    bouyer 				}
    254        1.1    bouyer 			}
    255        1.1    bouyer 		} else {
    256        1.1    bouyer 			sc->sis_type = sis_hostbr_type_match->type;
    257       1.12   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap =
    258        1.1    bouyer 		    	    sis_hostbr_type_match->udma_mode;
    259        1.1    bouyer 		}
    260        1.1    bouyer 		aprint_normal(sis_hostbr_type_match->name);
    261        1.1    bouyer 	} else {
    262        1.1    bouyer 		aprint_normal("5597/5598");
    263        1.1    bouyer 		if (rev >= 0xd0) {
    264       1.12   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    265        1.1    bouyer 			sc->sis_type = SIS_TYPE_66;
    266        1.1    bouyer 		} else {
    267       1.12   thorpej 			sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
    268        1.1    bouyer 			sc->sis_type = SIS_TYPE_NOUDMA;
    269        1.1    bouyer 		}
    270        1.1    bouyer 	}
    271        1.1    bouyer 	aprint_normal(" IDE controller (rev. 0x%02x)\n",
    272        1.1    bouyer 	    PCI_REVISION(pa->pa_class));
    273        1.1    bouyer 	aprint_normal("%s: bus-master DMA support present",
    274       1.12   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    275        1.1    bouyer 	pciide_mapreg_dma(sc, pa);
    276        1.1    bouyer 	aprint_normal("\n");
    277        1.1    bouyer 
    278       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    279        1.1    bouyer 	if (sc->sc_dma_ok) {
    280       1.12   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    281        1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    282        1.1    bouyer 		if (sc->sis_type >= SIS_TYPE_66)
    283       1.12   thorpej 			sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
    284        1.1    bouyer 	}
    285        1.1    bouyer 
    286       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    287       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    288        1.1    bouyer 
    289       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    290       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    291        1.1    bouyer 	switch(sc->sis_type) {
    292        1.1    bouyer 	case SIS_TYPE_NOUDMA:
    293        1.1    bouyer 	case SIS_TYPE_66:
    294        1.1    bouyer 	case SIS_TYPE_100OLD:
    295       1.12   thorpej 		sc->sc_wdcdev.sc_atac.atac_set_modes = sis_setup_channel;
    296        1.1    bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, SIS_MISC,
    297        1.1    bouyer 		    pciide_pci_read(sc->sc_pc, sc->sc_tag, SIS_MISC) |
    298        1.1    bouyer 		    SIS_MISC_TIM_SEL | SIS_MISC_FIFO_SIZE | SIS_MISC_GTC);
    299        1.1    bouyer 		break;
    300        1.1    bouyer 	case SIS_TYPE_100NEW:
    301        1.1    bouyer 	case SIS_TYPE_133OLD:
    302       1.12   thorpej 		sc->sc_wdcdev.sc_atac.atac_set_modes = sis_setup_channel;
    303        1.1    bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, SIS_REG_49,
    304        1.1    bouyer 		    pciide_pci_read(sc->sc_pc, sc->sc_tag, SIS_REG_49) | 0x01);
    305        1.1    bouyer 		break;
    306        1.1    bouyer 	case SIS_TYPE_133NEW:
    307       1.12   thorpej 		sc->sc_wdcdev.sc_atac.atac_set_modes = sis96x_setup_channel;
    308        1.1    bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, SIS_REG_50,
    309        1.1    bouyer 		    pciide_pci_read(sc->sc_pc, sc->sc_tag, SIS_REG_50) & 0xf7);
    310        1.1    bouyer 		pciide_pci_write(sc->sc_pc, sc->sc_tag, SIS_REG_52,
    311        1.1    bouyer 		    pciide_pci_read(sc->sc_pc, sc->sc_tag, SIS_REG_52) & 0xf7);
    312        1.1    bouyer 		break;
    313        1.1    bouyer 	}
    314       1.10   thorpej 
    315       1.10   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    316        1.1    bouyer 
    317       1.12   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    318       1.12   thorpej 	     channel++) {
    319        1.1    bouyer 		cp = &sc->pciide_channels[channel];
    320        1.1    bouyer 		if (pciide_chansetup(sc, channel, interface) == 0)
    321        1.1    bouyer 			continue;
    322        1.1    bouyer 		if ((channel == 0 && (sis_ctr0 & SIS_CTRL0_CHAN0_EN) == 0) ||
    323        1.1    bouyer 		    (channel == 1 && (sis_ctr0 & SIS_CTRL0_CHAN1_EN) == 0)) {
    324        1.1    bouyer 			aprint_normal("%s: %s channel ignored (disabled)\n",
    325       1.12   thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    326       1.10   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    327        1.1    bouyer 			continue;
    328        1.1    bouyer 		}
    329        1.1    bouyer 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    330        1.1    bouyer 		    pciide_pci_intr);
    331        1.1    bouyer 	}
    332        1.1    bouyer }
    333        1.1    bouyer 
    334        1.2   thorpej static void
    335       1.10   thorpej sis96x_setup_channel(struct ata_channel *chp)
    336        1.1    bouyer {
    337        1.1    bouyer 	struct ata_drive_datas *drvp;
    338       1.13   thorpej 	int drive, s;
    339        1.1    bouyer 	u_int32_t sis_tim;
    340        1.1    bouyer 	u_int32_t idedma_ctl;
    341        1.1    bouyer 	int regtim;
    342       1.11   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    343       1.11   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    344        1.1    bouyer 
    345        1.1    bouyer 	sis_tim = 0;
    346        1.1    bouyer 	idedma_ctl = 0;
    347        1.1    bouyer 	/* setup DMA if needed */
    348        1.1    bouyer 	pciide_channel_dma_setup(cp);
    349        1.1    bouyer 
    350        1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    351        1.1    bouyer 		regtim = SIS_TIM133(
    352        1.1    bouyer 		    pciide_pci_read(sc->sc_pc, sc->sc_tag, SIS_REG_57),
    353        1.5   thorpej 		    chp->ch_channel, drive);
    354        1.1    bouyer 		drvp = &chp->ch_drive[drive];
    355        1.1    bouyer 		/* If no drive, skip */
    356        1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    357        1.1    bouyer 			continue;
    358        1.1    bouyer 		/* add timing values, setup DMA if needed */
    359        1.1    bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    360        1.1    bouyer 			/* use Ultra/DMA */
    361       1.13   thorpej 			s = splbio();
    362        1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    363       1.13   thorpej 			splx(s);
    364        1.1    bouyer 			if (pciide_pci_read(sc->sc_pc, sc->sc_tag,
    365        1.5   thorpej 			    SIS96x_REG_CBL(chp->ch_channel)) & SIS96x_REG_CBL_33) {
    366        1.1    bouyer 				if (drvp->UDMA_mode > 2)
    367        1.1    bouyer 					drvp->UDMA_mode = 2;
    368        1.1    bouyer 			}
    369        1.1    bouyer 			sis_tim |= sis_udma133new_tim[drvp->UDMA_mode];
    370        1.1    bouyer 			sis_tim |= sis_pio133new_tim[drvp->PIO_mode];
    371        1.1    bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    372        1.1    bouyer 		} else if (drvp->drive_flags & DRIVE_DMA) {
    373        1.1    bouyer 			/*
    374        1.1    bouyer 			 * use Multiword DMA
    375        1.1    bouyer 			 * Timings will be used for both PIO and DMA,
    376        1.1    bouyer 			 * so adjust DMA mode if needed
    377        1.1    bouyer 			 */
    378        1.1    bouyer 			if (drvp->PIO_mode > (drvp->DMA_mode + 2))
    379        1.1    bouyer 				drvp->PIO_mode = drvp->DMA_mode + 2;
    380        1.1    bouyer 			if (drvp->DMA_mode + 2 > (drvp->PIO_mode))
    381        1.1    bouyer 				drvp->DMA_mode = (drvp->PIO_mode > 2) ?
    382        1.1    bouyer 				    drvp->PIO_mode - 2 : 0;
    383        1.1    bouyer 			sis_tim |= sis_dma133new_tim[drvp->DMA_mode];
    384        1.1    bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    385        1.1    bouyer 		} else {
    386        1.1    bouyer 			sis_tim |= sis_pio133new_tim[drvp->PIO_mode];
    387        1.1    bouyer 		}
    388        1.9   thorpej 		ATADEBUG_PRINT(("sis96x_setup_channel: new timings reg for "
    389        1.1    bouyer 		    "channel %d drive %d: 0x%x (reg 0x%x)\n",
    390        1.5   thorpej 		    chp->ch_channel, drive, sis_tim, regtim), DEBUG_PROBE);
    391        1.1    bouyer 		pci_conf_write(sc->sc_pc, sc->sc_tag, regtim, sis_tim);
    392        1.1    bouyer 	}
    393        1.1    bouyer 	if (idedma_ctl != 0) {
    394        1.1    bouyer 		/* Add software bits in status register */
    395        1.3      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    396        1.1    bouyer 		    idedma_ctl);
    397        1.1    bouyer 	}
    398        1.1    bouyer }
    399        1.1    bouyer 
    400        1.2   thorpej static void
    401       1.10   thorpej sis_setup_channel(struct ata_channel *chp)
    402        1.1    bouyer {
    403        1.1    bouyer 	struct ata_drive_datas *drvp;
    404       1.13   thorpej 	int drive, s;
    405        1.1    bouyer 	u_int32_t sis_tim;
    406        1.1    bouyer 	u_int32_t idedma_ctl;
    407       1.11   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    408       1.11   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    409        1.1    bouyer 
    410        1.9   thorpej 	ATADEBUG_PRINT(("sis_setup_channel: old timings reg for "
    411       1.14     perry 	    "channel %d 0x%x\n", chp->ch_channel,
    412        1.5   thorpej 	    pci_conf_read(sc->sc_pc, sc->sc_tag, SIS_TIM(chp->ch_channel))),
    413        1.1    bouyer 	    DEBUG_PROBE);
    414        1.1    bouyer 	sis_tim = 0;
    415        1.1    bouyer 	idedma_ctl = 0;
    416        1.1    bouyer 	/* setup DMA if needed */
    417        1.1    bouyer 	pciide_channel_dma_setup(cp);
    418        1.1    bouyer 
    419        1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    420        1.1    bouyer 		drvp = &chp->ch_drive[drive];
    421        1.1    bouyer 		/* If no drive, skip */
    422        1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    423        1.1    bouyer 			continue;
    424        1.1    bouyer 		/* add timing values, setup DMA if needed */
    425        1.1    bouyer 		if ((drvp->drive_flags & DRIVE_DMA) == 0 &&
    426        1.1    bouyer 		    (drvp->drive_flags & DRIVE_UDMA) == 0)
    427        1.1    bouyer 			goto pio;
    428        1.1    bouyer 
    429        1.1    bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    430        1.1    bouyer 			/* use Ultra/DMA */
    431       1.13   thorpej 			s = splbio();
    432        1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    433       1.13   thorpej 			splx(s);
    434        1.1    bouyer 			if (pciide_pci_read(sc->sc_pc, sc->sc_tag,
    435        1.5   thorpej 			    SIS_REG_CBL) & SIS_REG_CBL_33(chp->ch_channel)) {
    436        1.1    bouyer 				if (drvp->UDMA_mode > 2)
    437        1.1    bouyer 					drvp->UDMA_mode = 2;
    438        1.1    bouyer 			}
    439        1.1    bouyer 			switch (sc->sis_type) {
    440        1.1    bouyer 			case SIS_TYPE_66:
    441        1.1    bouyer 			case SIS_TYPE_100OLD:
    442       1.14     perry 				sis_tim |= sis_udma66_tim[drvp->UDMA_mode] <<
    443        1.1    bouyer 				    SIS_TIM66_UDMA_TIME_OFF(drive);
    444        1.1    bouyer 				break;
    445        1.1    bouyer 			case SIS_TYPE_100NEW:
    446        1.1    bouyer 				sis_tim |=
    447       1.14     perry 				    sis_udma100new_tim[drvp->UDMA_mode] <<
    448        1.1    bouyer 				    SIS_TIM100_UDMA_TIME_OFF(drive);
    449        1.1    bouyer 			case SIS_TYPE_133OLD:
    450        1.1    bouyer 				sis_tim |=
    451       1.14     perry 				    sis_udma133old_tim[drvp->UDMA_mode] <<
    452        1.1    bouyer 				    SIS_TIM100_UDMA_TIME_OFF(drive);
    453        1.1    bouyer 				break;
    454        1.1    bouyer 			default:
    455        1.1    bouyer 				aprint_error("unknown SiS IDE type %d\n",
    456        1.1    bouyer 				    sc->sis_type);
    457        1.1    bouyer 			}
    458        1.1    bouyer 		} else {
    459        1.1    bouyer 			/*
    460        1.1    bouyer 			 * use Multiword DMA
    461        1.1    bouyer 			 * Timings will be used for both PIO and DMA,
    462        1.1    bouyer 			 * so adjust DMA mode if needed
    463        1.1    bouyer 			 */
    464        1.1    bouyer 			if (drvp->PIO_mode > (drvp->DMA_mode + 2))
    465        1.1    bouyer 				drvp->PIO_mode = drvp->DMA_mode + 2;
    466        1.1    bouyer 			if (drvp->DMA_mode + 2 > (drvp->PIO_mode))
    467        1.1    bouyer 				drvp->DMA_mode = (drvp->PIO_mode > 2) ?
    468        1.1    bouyer 				    drvp->PIO_mode - 2 : 0;
    469        1.1    bouyer 			if (drvp->DMA_mode == 0)
    470        1.1    bouyer 				drvp->PIO_mode = 0;
    471        1.1    bouyer 		}
    472        1.1    bouyer 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    473        1.1    bouyer pio:		switch (sc->sis_type) {
    474        1.1    bouyer 		case SIS_TYPE_NOUDMA:
    475        1.1    bouyer 		case SIS_TYPE_66:
    476        1.1    bouyer 		case SIS_TYPE_100OLD:
    477        1.1    bouyer 			sis_tim |= sis_pio_act[drvp->PIO_mode] <<
    478        1.1    bouyer 			    SIS_TIM66_ACT_OFF(drive);
    479        1.1    bouyer 			sis_tim |= sis_pio_rec[drvp->PIO_mode] <<
    480        1.1    bouyer 			    SIS_TIM66_REC_OFF(drive);
    481        1.1    bouyer 			break;
    482        1.1    bouyer 		case SIS_TYPE_100NEW:
    483        1.1    bouyer 		case SIS_TYPE_133OLD:
    484        1.1    bouyer 			sis_tim |= sis_pio_act[drvp->PIO_mode] <<
    485        1.1    bouyer 			    SIS_TIM100_ACT_OFF(drive);
    486        1.1    bouyer 			sis_tim |= sis_pio_rec[drvp->PIO_mode] <<
    487        1.1    bouyer 			    SIS_TIM100_REC_OFF(drive);
    488        1.1    bouyer 			break;
    489        1.1    bouyer 		default:
    490        1.1    bouyer 			aprint_error("unknown SiS IDE type %d\n",
    491        1.1    bouyer 			    sc->sis_type);
    492        1.1    bouyer 		}
    493        1.1    bouyer 	}
    494        1.9   thorpej 	ATADEBUG_PRINT(("sis_setup_channel: new timings reg for "
    495        1.5   thorpej 	    "channel %d 0x%x\n", chp->ch_channel, sis_tim), DEBUG_PROBE);
    496        1.5   thorpej 	pci_conf_write(sc->sc_pc, sc->sc_tag, SIS_TIM(chp->ch_channel),
    497        1.5   thorpej 		       sis_tim);
    498        1.1    bouyer 	if (idedma_ctl != 0) {
    499        1.1    bouyer 		/* Add software bits in status register */
    500        1.3      fvdl 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    501        1.1    bouyer 		    idedma_ctl);
    502        1.1    bouyer 	}
    503        1.1    bouyer }
    504        1.6       skd 
    505        1.6       skd static void
    506        1.6       skd sis_sata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    507        1.6       skd {
    508        1.6       skd 	struct pciide_channel *cp;
    509        1.6       skd 	pcireg_t interface = PCI_INTERFACE(pa->pa_class);
    510        1.6       skd 	int channel;
    511        1.6       skd 	bus_size_t cmdsize, ctlsize;
    512        1.6       skd 
    513        1.6       skd 	if (pciide_chipen(sc, pa) == 0)
    514        1.6       skd 		return;
    515        1.6       skd 
    516        1.6       skd 	if (interface == 0) {
    517        1.9   thorpej 		ATADEBUG_PRINT(("sis_sata_chip_map interface == 0\n"),
    518        1.6       skd 		    DEBUG_PROBE);
    519        1.6       skd 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    520        1.6       skd 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    521        1.6       skd 	}
    522        1.6       skd 
    523        1.6       skd 	aprint_normal("%s: Silicon Integrated Systems 180/96X SATA controller (rev. 0x%02x)\n",
    524       1.12   thorpej 		      sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    525        1.6       skd 		      PCI_REVISION(pa->pa_class));
    526        1.6       skd 
    527        1.6       skd 	aprint_normal("%s: bus-master DMA support present",
    528       1.12   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    529        1.6       skd 	pciide_mapreg_dma(sc, pa);
    530        1.6       skd 	aprint_normal("\n");
    531        1.6       skd 
    532        1.6       skd 	if (sc->sc_dma_ok) {
    533       1.12   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
    534        1.6       skd 		sc->sc_wdcdev.irqack = pciide_irqack;
    535        1.6       skd 	}
    536       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    537       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    538       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    539       1.12   thorpej 
    540       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    541       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    542       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    543       1.12   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    544        1.6       skd 
    545       1.10   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    546       1.10   thorpej 
    547       1.12   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    548       1.12   thorpej 	     channel++) {
    549        1.6       skd 		cp = &sc->pciide_channels[channel];
    550        1.6       skd 		if (pciide_chansetup(sc, channel, interface) == 0)
    551        1.6       skd 			continue;
    552        1.6       skd 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    553        1.6       skd 		    pciide_pci_intr);
    554        1.6       skd 	}
    555        1.6       skd }
    556