Home | History | Annotate | Line # | Download | only in pci
pdcsata.c revision 1.15.36.1
      1  1.15.36.1   keiichi /*	$NetBSD: pdcsata.c,v 1.15.36.1 2008/03/24 07:15:49 keiichi Exp $	*/
      2        1.1    bouyer 
      3        1.1    bouyer /*
      4        1.1    bouyer  * Copyright (c) 2004, 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.3     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.9   xtraeme #include <sys/cdefs.h>
     33  1.15.36.1   keiichi __KERNEL_RCSID(0, "$NetBSD: pdcsata.c,v 1.15.36.1 2008/03/24 07:15:49 keiichi Exp $");
     34        1.9   xtraeme 
     35        1.1    bouyer #include <sys/types.h>
     36        1.1    bouyer #include <sys/malloc.h>
     37        1.1    bouyer #include <sys/param.h>
     38        1.1    bouyer #include <sys/systm.h>
     39        1.1    bouyer 
     40        1.1    bouyer #include <dev/pci/pcivar.h>
     41        1.1    bouyer #include <dev/pci/pcidevs.h>
     42        1.1    bouyer #include <dev/pci/pciidereg.h>
     43        1.1    bouyer #include <dev/pci/pciidevar.h>
     44        1.4  christos #include <dev/ata/atareg.h>
     45        1.4  christos #include <dev/ata/satavar.h>
     46        1.4  christos #include <dev/ata/satareg.h>
     47        1.1    bouyer 
     48       1.13    bouyer #define PDC203xx_SATA_NCHANNELS 4
     49       1.13    bouyer #define PDC203xx_COMBO_NCHANNELS 3
     50       1.13    bouyer #define PDC40718_SATA_NCHANNELS 4
     51       1.13    bouyer #define PDC20575_COMBO_NCHANNELS 3
     52        1.1    bouyer 
     53        1.1    bouyer #define PDC203xx_BAR_IDEREGS 0x1c /* BAR where the IDE registers are mapped */
     54        1.1    bouyer 
     55        1.7  christos #define PDC_CHANNELBASE(ch) 0x200 + ((ch) * 0x80)
     56        1.7  christos #define PDC_ERRMASK 0x00780700
     57        1.7  christos 
     58       1.13    bouyer #define	PDC205_REGADDR(base,ch)	((base)+((ch)<<8))
     59       1.13    bouyer #define	PDC205_SSTATUS(ch)	PDC205_REGADDR(0x400,ch)
     60       1.13    bouyer #define	PDC205_SERROR(ch)	PDC205_REGADDR(0x404,ch)
     61       1.13    bouyer #define	PDC205_SCONTROL(ch)	PDC205_REGADDR(0x408,ch)
     62       1.13    bouyer #define	PDC205_MULTIPLIER(ch)	PDC205_REGADDR(0x4e8,ch)
     63       1.13    bouyer 
     64        1.1    bouyer static void pdcsata_chip_map(struct pciide_softc *, struct pci_attach_args *);
     65        1.1    bouyer static void pdc203xx_setup_channel(struct ata_channel *);
     66        1.1    bouyer static void pdc203xx_irqack(struct ata_channel *);
     67        1.1    bouyer static int  pdc203xx_dma_init(void *, int, int, void *, size_t, int);
     68        1.1    bouyer static void pdc203xx_dma_start(void *,int ,int);
     69        1.1    bouyer static int  pdc203xx_dma_finish(void *, int, int, int);
     70       1.13    bouyer static void pdc203xx_combo_probe(struct ata_channel *);
     71        1.7  christos static int  pdcsata_pci_intr(void *);
     72        1.7  christos static void pdcsata_do_reset(struct ata_channel *, int);
     73        1.1    bouyer 
     74  1.15.36.1   keiichi static int  pdcsata_match(device_t, cfdata_t, void *);
     75  1.15.36.1   keiichi static void pdcsata_attach(device_t, device_t, void *);
     76        1.1    bouyer 
     77  1.15.36.1   keiichi CFATTACH_DECL_NEW(pdcsata, sizeof(struct pciide_softc),
     78        1.1    bouyer     pdcsata_match, pdcsata_attach, NULL, NULL);
     79        1.1    bouyer 
     80        1.1    bouyer static const struct pciide_product_desc pciide_pdcsata_products[] =  {
     81        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20318,
     82        1.1    bouyer 	  0,
     83        1.1    bouyer 	  "Promise PDC20318 SATA150 controller",
     84        1.1    bouyer 	  pdcsata_chip_map,
     85        1.1    bouyer 	},
     86        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20319,
     87        1.1    bouyer 	  0,
     88        1.1    bouyer 	  "Promise PDC20319 SATA150 controller",
     89        1.1    bouyer 	  pdcsata_chip_map,
     90        1.1    bouyer 	},
     91        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20371,
     92        1.1    bouyer 	  0,
     93        1.1    bouyer 	  "Promise PDC20371 SATA150 controller",
     94        1.1    bouyer 	  pdcsata_chip_map,
     95        1.1    bouyer 	},
     96        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20375,
     97        1.1    bouyer 	  0,
     98        1.1    bouyer 	  "Promise PDC20375 SATA150 controller",
     99        1.1    bouyer 	  pdcsata_chip_map,
    100        1.1    bouyer 	},
    101        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20376,
    102        1.1    bouyer 	  0,
    103        1.1    bouyer 	  "Promise PDC20376 SATA150 controller",
    104        1.1    bouyer 	  pdcsata_chip_map,
    105        1.1    bouyer 	},
    106        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20377,
    107        1.1    bouyer 	  0,
    108        1.1    bouyer 	  "Promise PDC20377 SATA150 controller",
    109        1.1    bouyer 	  pdcsata_chip_map,
    110        1.1    bouyer 	},
    111        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20378,
    112        1.1    bouyer 	  0,
    113        1.1    bouyer 	  "Promise PDC20378 SATA150 controller",
    114        1.1    bouyer 	  pdcsata_chip_map,
    115        1.1    bouyer 	},
    116        1.1    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20379,
    117        1.1    bouyer 	  0,
    118        1.1    bouyer 	  "Promise PDC20379 SATA150 controller",
    119        1.1    bouyer 	  pdcsata_chip_map,
    120        1.1    bouyer 	},
    121        1.8   xtraeme 	{ PCI_PRODUCT_PROMISE_PDC40518,
    122        1.8   xtraeme 	  0,
    123       1.11   xtraeme 	  "Promise PDC40518 SATA150 controller",
    124       1.11   xtraeme 	  pdcsata_chip_map,
    125       1.11   xtraeme 	},
    126       1.11   xtraeme 	{ PCI_PRODUCT_PROMISE_PDC40519,
    127       1.11   xtraeme 	  0,
    128       1.11   xtraeme 	  "Promise PDC40519 SATA 150 controller",
    129        1.8   xtraeme 	  pdcsata_chip_map,
    130        1.8   xtraeme 	},
    131        1.4  christos 	{ PCI_PRODUCT_PROMISE_PDC40718,
    132        1.4  christos 	  0,
    133        1.4  christos 	  "Promise PDC40718 SATA300 controller",
    134        1.4  christos 	  pdcsata_chip_map,
    135        1.4  christos 	},
    136        1.4  christos 	{ PCI_PRODUCT_PROMISE_PDC40719,
    137        1.4  christos 	  0,
    138        1.4  christos 	  "Promise PDC40719 SATA300 controller",
    139        1.4  christos 	  pdcsata_chip_map,
    140        1.4  christos 	},
    141       1.11   xtraeme 	{ PCI_PRODUCT_PROMISE_PDC40779,
    142       1.11   xtraeme 	  0,
    143       1.11   xtraeme 	  "Promise PDC40779 SATA300 controller",
    144       1.11   xtraeme 	  pdcsata_chip_map,
    145       1.11   xtraeme 	},
    146        1.6    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20571,
    147        1.6    bouyer 	  0,
    148        1.6    bouyer 	  "Promise PDC20571 SATA150 controller",
    149        1.6    bouyer 	  pdcsata_chip_map,
    150        1.6    bouyer 	},
    151        1.6    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20575,
    152        1.6    bouyer 	  0,
    153        1.6    bouyer 	  "Promise PDC20575 SATA150 controller",
    154        1.6    bouyer 	  pdcsata_chip_map,
    155        1.6    bouyer 	},
    156        1.6    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20579,
    157        1.6    bouyer 	  0,
    158        1.6    bouyer 	  "Promise PDC20579 SATA150 controller",
    159        1.6    bouyer 	  pdcsata_chip_map,
    160        1.6    bouyer 	},
    161       1.10   dsainty 	{ PCI_PRODUCT_PROMISE_PDC20771,
    162       1.10   dsainty 	  0,
    163       1.10   dsainty 	  "Promise PDC20771 SATA300 controller",
    164       1.10   dsainty 	  pdcsata_chip_map,
    165       1.10   dsainty 	},
    166        1.8   xtraeme 	{ PCI_PRODUCT_PROMISE_PDC20775,
    167        1.8   xtraeme 	  0,
    168        1.8   xtraeme 	  "Promise PDC20775 SATA300 controller",
    169        1.8   xtraeme 	  pdcsata_chip_map,
    170        1.8   xtraeme 	},
    171       1.13    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20617,
    172       1.13    bouyer 	  0,
    173       1.13    bouyer 	  "Promise PDC2020617 Ultra/133 controller",
    174       1.13    bouyer 	  pdcsata_chip_map,
    175       1.13    bouyer 	},
    176       1.13    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20618,
    177       1.13    bouyer 	  0,
    178       1.13    bouyer 	  "Promise PDC20618 Ultra/133 controller",
    179       1.13    bouyer 	  pdcsata_chip_map,
    180       1.13    bouyer 	},
    181       1.13    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20619,
    182       1.13    bouyer 	  0,
    183       1.13    bouyer 	  "Promise PDC20619 Ultra/133 controller",
    184       1.13    bouyer 	  pdcsata_chip_map,
    185       1.13    bouyer 	},
    186       1.13    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20620,
    187       1.13    bouyer 	  0,
    188       1.13    bouyer 	  "Promise PDC20620 Ultra/133 controller",
    189       1.13    bouyer 	  pdcsata_chip_map,
    190       1.13    bouyer 	},
    191       1.13    bouyer 	{ PCI_PRODUCT_PROMISE_PDC20621,
    192       1.13    bouyer 	  0,
    193       1.13    bouyer 	  "Promise PDC20621 Ultra/133 controller",
    194       1.13    bouyer 	  pdcsata_chip_map,
    195       1.13    bouyer 	},
    196        1.1    bouyer 	{ 0,
    197        1.1    bouyer 	  0,
    198        1.1    bouyer 	  NULL,
    199        1.1    bouyer 	  NULL
    200        1.1    bouyer 	}
    201        1.1    bouyer };
    202        1.1    bouyer 
    203        1.1    bouyer static int
    204  1.15.36.1   keiichi pdcsata_match(device_t parent, cfdata_t match, void *aux)
    205        1.1    bouyer {
    206        1.1    bouyer 	struct pci_attach_args *pa = aux;
    207        1.1    bouyer 
    208        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_PROMISE) {
    209        1.1    bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_pdcsata_products))
    210        1.1    bouyer 			return (2);
    211        1.1    bouyer 	}
    212        1.1    bouyer 	return (0);
    213        1.1    bouyer }
    214        1.1    bouyer 
    215        1.1    bouyer static void
    216  1.15.36.1   keiichi pdcsata_attach(device_t parent, device_t self, void *aux)
    217        1.1    bouyer {
    218        1.1    bouyer 	struct pci_attach_args *pa = aux;
    219  1.15.36.1   keiichi 	struct pciide_softc *sc = device_private(self);
    220  1.15.36.1   keiichi 
    221  1.15.36.1   keiichi 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    222        1.1    bouyer 
    223        1.1    bouyer 	pciide_common_attach(sc, pa,
    224        1.1    bouyer 	    pciide_lookup_product(pa->pa_id, pciide_pdcsata_products));
    225        1.1    bouyer }
    226        1.1    bouyer 
    227        1.1    bouyer static void
    228        1.1    bouyer pdcsata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    229        1.1    bouyer {
    230        1.1    bouyer 	struct pciide_channel *cp;
    231        1.1    bouyer 	struct ata_channel *wdc_cp;
    232        1.1    bouyer 	struct wdc_regs *wdr;
    233        1.1    bouyer 	int channel, i;
    234        1.1    bouyer 	bus_size_t dmasize;
    235        1.1    bouyer 	pci_intr_handle_t intrhandle;
    236        1.1    bouyer 	const char *intrstr;
    237        1.1    bouyer 
    238        1.1    bouyer 	/*
    239        1.1    bouyer 	 * Promise SATA controllers have 3 or 4 channels,
    240        1.1    bouyer 	 * the usual IDE registers are mapped in I/O space, with offsets.
    241        1.1    bouyer 	 */
    242        1.1    bouyer 	if (pci_intr_map(pa, &intrhandle) != 0) {
    243  1.15.36.1   keiichi 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    244  1.15.36.1   keiichi 		    "couldn't map interrupt\n");
    245        1.1    bouyer 		return;
    246        1.1    bouyer 	}
    247        1.1    bouyer 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    248        1.7  christos 	sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    249        1.7  christos 	    intrhandle, IPL_BIO, pdcsata_pci_intr, sc);
    250        1.4  christos 
    251        1.1    bouyer 	if (sc->sc_pci_ih == NULL) {
    252  1.15.36.1   keiichi 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    253  1.15.36.1   keiichi 		    "couldn't establish native-PCI interrupt");
    254        1.1    bouyer 		if (intrstr != NULL)
    255        1.1    bouyer 		    aprint_normal(" at %s", intrstr);
    256        1.1    bouyer 		aprint_normal("\n");
    257        1.1    bouyer 		return;
    258        1.1    bouyer 	}
    259  1.15.36.1   keiichi 	aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    260  1.15.36.1   keiichi 	    "interrupting at %s\n",
    261  1.15.36.1   keiichi 	    intrstr ? intrstr : "unknown interrupt");
    262        1.3     perry 
    263        1.1    bouyer 	sc->sc_dma_ok = (pci_mapreg_map(pa, PCIIDE_REG_BUS_MASTER_DMA,
    264        1.1    bouyer 	    PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_dma_iot,
    265        1.1    bouyer 	    &sc->sc_dma_ioh, NULL, &dmasize) == 0);
    266        1.1    bouyer 	if (!sc->sc_dma_ok) {
    267  1.15.36.1   keiichi 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    268  1.15.36.1   keiichi 		    "couldn't map bus-master DMA registers\n");
    269        1.1    bouyer 		pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
    270        1.1    bouyer 		return;
    271        1.1    bouyer 	}
    272        1.1    bouyer 
    273        1.1    bouyer 	sc->sc_dmat = pa->pa_dmat;
    274        1.1    bouyer 
    275        1.1    bouyer 	if (pci_mapreg_map(pa, PDC203xx_BAR_IDEREGS,
    276        1.1    bouyer 	    PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_ba5_st,
    277        1.1    bouyer 	    &sc->sc_ba5_sh, NULL, NULL) != 0) {
    278  1.15.36.1   keiichi 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    279  1.15.36.1   keiichi 		    "couldn't map IDE registers\n");
    280        1.1    bouyer 		bus_space_unmap(sc->sc_dma_iot, sc->sc_dma_ioh, dmasize);
    281        1.1    bouyer 		pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
    282        1.1    bouyer 		return;
    283        1.1    bouyer 	}
    284        1.1    bouyer 
    285  1.15.36.1   keiichi 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    286  1.15.36.1   keiichi 	    "bus-master DMA support present\n");
    287        1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
    288        1.1    bouyer 	if (sc->sc_dma_ok) {
    289        1.1    bouyer 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    290        1.1    bouyer 	}
    291        1.2    bouyer 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    292        1.2    bouyer 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    293        1.2    bouyer 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    294        1.1    bouyer 	sc->sc_wdcdev.irqack = pdc203xx_irqack;
    295        1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    296        1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    297        1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    298        1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_set_modes = pdc203xx_setup_channel;
    299        1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    300        1.4  christos 
    301        1.7  christos 	sc->sc_wdcdev.reset = pdcsata_do_reset;
    302        1.7  christos 
    303        1.4  christos 	switch (sc->sc_pp->ide_product) {
    304        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20318:
    305        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20319:
    306       1.13    bouyer 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x6c,
    307       1.13    bouyer 		    0x00ff0033);
    308       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    309       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC203xx_SATA_NCHANNELS;
    310       1.13    bouyer 		break;
    311        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20371:
    312        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20375:
    313        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20376:
    314        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20377:
    315        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20378:
    316        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20379:
    317       1.13    bouyer 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x6c,
    318       1.13    bouyer 		    0x00ff0033);
    319       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = pdc203xx_combo_probe;
    320       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC203xx_COMBO_NCHANNELS;
    321        1.4  christos 		break;
    322        1.4  christos 
    323        1.8   xtraeme 	case PCI_PRODUCT_PROMISE_PDC40518:
    324       1.11   xtraeme 	case PCI_PRODUCT_PROMISE_PDC40519:
    325        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC40718:
    326        1.4  christos 	case PCI_PRODUCT_PROMISE_PDC40719:
    327       1.11   xtraeme 	case PCI_PRODUCT_PROMISE_PDC40779:
    328       1.13    bouyer 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60,
    329       1.13    bouyer 		    0x00ff00ff);
    330       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC40718_SATA_NCHANNELS;
    331       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    332       1.13    bouyer 		break;
    333       1.13    bouyer 
    334        1.6    bouyer 	case PCI_PRODUCT_PROMISE_PDC20571:
    335        1.6    bouyer 	case PCI_PRODUCT_PROMISE_PDC20575:
    336        1.6    bouyer 	case PCI_PRODUCT_PROMISE_PDC20579:
    337       1.10   dsainty 	case PCI_PRODUCT_PROMISE_PDC20771:
    338        1.8   xtraeme 	case PCI_PRODUCT_PROMISE_PDC20775:
    339       1.13    bouyer 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60,
    340       1.13    bouyer 		    0x00ff00ff);
    341       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC20575_COMBO_NCHANNELS;
    342       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = pdc203xx_combo_probe;
    343       1.13    bouyer 		break;
    344        1.6    bouyer 
    345       1.13    bouyer 	case PCI_PRODUCT_PROMISE_PDC20617:
    346       1.13    bouyer 	case PCI_PRODUCT_PROMISE_PDC20618:
    347       1.13    bouyer 	case PCI_PRODUCT_PROMISE_PDC20619:
    348       1.13    bouyer 	case PCI_PRODUCT_PROMISE_PDC20620:
    349       1.13    bouyer 	case PCI_PRODUCT_PROMISE_PDC20621:
    350       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_nchannels =
    351       1.13    bouyer 		    ((bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    352       1.13    bouyer 			0x48) & 0x01) ? 1 : 0) +
    353       1.13    bouyer 		    ((bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    354       1.13    bouyer 			0x48) & 0x02) ? 1 : 0) +
    355       1.13    bouyer 		    2;
    356       1.13    bouyer 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_drvprobe;
    357        1.6    bouyer 
    358       1.13    bouyer 	default:
    359       1.13    bouyer 		aprint_error("unknown promise product 0x%x\n",
    360       1.13    bouyer 		    sc->sc_pp->ide_product);
    361        1.4  christos 	}
    362        1.4  christos 
    363        1.1    bouyer 	wdc_allocate_regs(&sc->sc_wdcdev);
    364        1.1    bouyer 
    365        1.1    bouyer 	sc->sc_wdcdev.dma_arg = sc;
    366        1.1    bouyer 	sc->sc_wdcdev.dma_init = pdc203xx_dma_init;
    367        1.1    bouyer 	sc->sc_wdcdev.dma_start = pdc203xx_dma_start;
    368        1.1    bouyer 	sc->sc_wdcdev.dma_finish = pdc203xx_dma_finish;
    369        1.1    bouyer 
    370        1.1    bouyer 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    371        1.1    bouyer 	     channel++) {
    372        1.1    bouyer 		cp = &sc->pciide_channels[channel];
    373        1.1    bouyer 		sc->wdc_chanarray[channel] = &cp->ata_channel;
    374        1.1    bouyer 
    375        1.1    bouyer 		cp->ih = sc->sc_pci_ih;
    376        1.1    bouyer 		cp->name = NULL;
    377        1.1    bouyer 		cp->ata_channel.ch_channel = channel;
    378        1.1    bouyer 		cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    379        1.1    bouyer 		cp->ata_channel.ch_queue =
    380        1.1    bouyer 		    malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
    381        1.5    bouyer 		cp->ata_channel.ch_ndrive = 2;
    382        1.1    bouyer 		if (cp->ata_channel.ch_queue == NULL) {
    383        1.1    bouyer 			aprint_error("%s channel %d: "
    384        1.1    bouyer 			    "can't allocate memory for command queue\n",
    385  1.15.36.1   keiichi 			    device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
    386  1.15.36.1   keiichi 			    channel);
    387        1.1    bouyer 			goto next_channel;
    388        1.1    bouyer 		}
    389        1.1    bouyer 		wdc_cp = &cp->ata_channel;
    390        1.1    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    391        1.1    bouyer 
    392        1.1    bouyer 		wdr->ctl_iot = sc->sc_ba5_st;
    393        1.1    bouyer 		wdr->cmd_iot = sc->sc_ba5_st;
    394        1.1    bouyer 
    395        1.1    bouyer 		if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    396        1.1    bouyer 		    0x0238 + (channel << 7), 1, &wdr->ctl_ioh) != 0) {
    397  1.15.36.1   keiichi 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    398  1.15.36.1   keiichi 			    "couldn't map channel %d ctl regs\n", channel);
    399        1.1    bouyer 			goto next_channel;
    400        1.1    bouyer 		}
    401        1.1    bouyer 		for (i = 0; i < WDC_NREG; i++) {
    402        1.1    bouyer 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    403        1.1    bouyer 			    0x0200 + (i << 2) + (channel << 7), i == 0 ? 4 : 1,
    404        1.1    bouyer 			    &wdr->cmd_iohs[i]) != 0) {
    405  1.15.36.1   keiichi 				aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    406  1.15.36.1   keiichi 				    "couldn't map channel %d cmd regs\n",
    407        1.1    bouyer 				    channel);
    408        1.1    bouyer 				goto next_channel;
    409        1.1    bouyer 			}
    410        1.1    bouyer 		}
    411        1.1    bouyer 		wdc_init_shadow_regs(wdc_cp);
    412        1.1    bouyer 
    413        1.1    bouyer 		/*
    414        1.1    bouyer 		 * subregion de busmaster registers. They're spread all over
    415        1.1    bouyer 		 * the controller's register space :(. They are also 4 bytes
    416        1.1    bouyer 		 * sized, with some specific extentions in the extra bits.
    417        1.1    bouyer 		 * It also seems that the IDEDMA_CTL register isn't available.
    418        1.1    bouyer 		 */
    419        1.1    bouyer 		if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    420        1.1    bouyer 		    0x260 + (channel << 7), 1,
    421        1.1    bouyer 		    &cp->dma_iohs[IDEDMA_CMD]) != 0) {
    422        1.1    bouyer 			aprint_normal("%s channel %d: can't subregion DMA "
    423        1.1    bouyer 			    "registers\n",
    424  1.15.36.1   keiichi 			    device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
    425  1.15.36.1   keiichi 			    channel);
    426        1.1    bouyer 			goto next_channel;
    427        1.1    bouyer 		}
    428        1.1    bouyer 		if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    429        1.1    bouyer 		    0x244 + (channel << 7), 4,
    430        1.1    bouyer 		    &cp->dma_iohs[IDEDMA_TBL]) != 0) {
    431        1.1    bouyer 			aprint_normal("%s channel %d: can't subregion DMA "
    432        1.1    bouyer 			    "registers\n",
    433  1.15.36.1   keiichi 			    device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
    434  1.15.36.1   keiichi 			    channel);
    435        1.1    bouyer 			goto next_channel;
    436        1.1    bouyer 		}
    437        1.1    bouyer 
    438       1.13    bouyer 		/* subregion the SATA registers */
    439       1.13    bouyer 		if (sc->sc_wdcdev.sc_atac.atac_probe == wdc_sataprobe ||
    440       1.13    bouyer 		    (sc->sc_wdcdev.sc_atac.atac_probe == pdc203xx_combo_probe
    441       1.13    bouyer 		    && channel < 2)) {
    442       1.13    bouyer 			wdr->sata_iot = sc->sc_ba5_st;
    443       1.13    bouyer 			wdr->sata_baseioh = sc->sc_ba5_sh;
    444       1.13    bouyer 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    445       1.13    bouyer 			    PDC205_SSTATUS(channel), 1,
    446       1.13    bouyer 			    &wdr->sata_status) != 0) {
    447  1.15.36.1   keiichi 				aprint_error_dev(
    448  1.15.36.1   keiichi 				    sc->sc_wdcdev.sc_atac.atac_dev,
    449  1.15.36.1   keiichi 				    "couldn't map channel %d "
    450  1.15.36.1   keiichi 				    "sata_status regs\n", channel);
    451       1.13    bouyer 				goto next_channel;
    452       1.13    bouyer 			}
    453       1.13    bouyer 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    454       1.13    bouyer 			    PDC205_SERROR(channel), 1, &wdr->sata_error) != 0) {
    455  1.15.36.1   keiichi 				aprint_error_dev(
    456  1.15.36.1   keiichi 				    sc->sc_wdcdev.sc_atac.atac_dev,
    457  1.15.36.1   keiichi 				    "couldn't map channel %d "
    458  1.15.36.1   keiichi 				    "sata_error regs\n", channel);
    459       1.13    bouyer 				goto next_channel;
    460       1.13    bouyer 			}
    461       1.13    bouyer 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    462       1.13    bouyer 			    PDC205_SCONTROL(channel), 1,
    463       1.13    bouyer 			    &wdr->sata_control) != 0) {
    464  1.15.36.1   keiichi 				aprint_error_dev(
    465  1.15.36.1   keiichi 				    sc->sc_wdcdev.sc_atac.atac_dev,
    466  1.15.36.1   keiichi 				    "couldn't map channel %d "
    467  1.15.36.1   keiichi 				    "sata_control regs\n", channel);
    468       1.13    bouyer 				goto next_channel;
    469       1.13    bouyer 			}
    470       1.13    bouyer 		}
    471       1.13    bouyer 
    472        1.1    bouyer 		wdcattach(wdc_cp);
    473        1.1    bouyer 		bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    474        1.1    bouyer 		    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    475        1.1    bouyer 			0) & ~0x00003f9f) | (channel + 1));
    476        1.1    bouyer 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    477        1.1    bouyer 		    (channel + 1) << 2, 0x00000001);
    478        1.1    bouyer next_channel:
    479        1.1    bouyer 	continue;
    480        1.1    bouyer 	}
    481        1.1    bouyer 	return;
    482        1.1    bouyer }
    483        1.1    bouyer 
    484        1.1    bouyer static void
    485       1.13    bouyer pdc203xx_combo_probe(struct ata_channel *chp)
    486       1.13    bouyer {
    487       1.13    bouyer 	if (chp->ch_channel < 2)
    488       1.13    bouyer 		wdc_sataprobe(chp);
    489       1.13    bouyer 	else
    490       1.13    bouyer 		wdc_drvprobe(chp);
    491       1.13    bouyer }
    492       1.13    bouyer 
    493       1.13    bouyer static void
    494        1.1    bouyer pdc203xx_setup_channel(struct ata_channel *chp)
    495        1.1    bouyer {
    496        1.1    bouyer 	struct ata_drive_datas *drvp;
    497        1.1    bouyer 	int drive, s;
    498        1.1    bouyer 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    499        1.1    bouyer 
    500        1.1    bouyer 	pciide_channel_dma_setup(cp);
    501        1.1    bouyer 
    502        1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    503        1.1    bouyer 		drvp = &chp->ch_drive[drive];
    504        1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    505        1.1    bouyer 			continue;
    506        1.1    bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    507        1.1    bouyer 			s = splbio();
    508        1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    509        1.1    bouyer 			splx(s);
    510        1.1    bouyer 		}
    511        1.1    bouyer 	}
    512        1.1    bouyer }
    513        1.1    bouyer 
    514        1.1    bouyer static int
    515        1.7  christos pdcsata_pci_intr(void *arg)
    516        1.1    bouyer {
    517        1.1    bouyer 	struct pciide_softc *sc = arg;
    518        1.1    bouyer 	struct pciide_channel *cp;
    519        1.1    bouyer 	struct ata_channel *wdc_cp;
    520        1.3     perry 	int i, rv, crv;
    521        1.7  christos 	u_int32_t scr, status, chanbase;
    522        1.4  christos 
    523        1.4  christos 	rv = 0;
    524        1.4  christos 	scr = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40);
    525        1.7  christos 	if (scr == 0xffffffff) return(rv);
    526        1.4  christos 	bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40, scr & 0x0000ffff);
    527        1.7  christos 	scr = scr & 0x0000ffff;
    528        1.7  christos 	if (!scr) return(rv);
    529        1.4  christos 
    530        1.4  christos 	for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
    531        1.4  christos 		cp = &sc->pciide_channels[i];
    532        1.4  christos 		wdc_cp = &cp->ata_channel;
    533        1.4  christos 		if (scr & (1 << (i + 1))) {
    534        1.7  christos 			chanbase = PDC_CHANNELBASE(i) + 0x48;
    535        1.7  christos 			status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    536        1.7  christos 			if (status & PDC_ERRMASK) {
    537        1.7  christos 				chanbase = PDC_CHANNELBASE(i) + 0x60;
    538        1.7  christos 				status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    539        1.7  christos 				status |= 0x800;
    540        1.7  christos 				bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
    541        1.7  christos 				status &= ~0x800;
    542        1.7  christos 				bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
    543        1.7  christos 				status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    544        1.7  christos 				continue;
    545        1.7  christos 			}
    546        1.4  christos 			crv = wdcintr(wdc_cp);
    547        1.4  christos 			if (crv == 0) {
    548  1.15.36.1   keiichi 				aprint_error("%s:%d: bogus intr (reg 0x%x)\n",
    549  1.15.36.1   keiichi 				    device_xname(
    550  1.15.36.1   keiichi 				      sc->sc_wdcdev.sc_atac.atac_dev), i, scr);
    551        1.4  christos 			} else
    552        1.4  christos 				rv = 1;
    553        1.4  christos 		}
    554        1.4  christos 	}
    555        1.4  christos 	return rv;
    556        1.4  christos }
    557        1.4  christos 
    558        1.1    bouyer static void
    559        1.1    bouyer pdc203xx_irqack(struct ata_channel *chp)
    560        1.1    bouyer {
    561        1.1    bouyer 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    562        1.1    bouyer 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    563        1.1    bouyer 
    564        1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    565        1.1    bouyer 	    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    566        1.1    bouyer 		0) & ~0x00003f9f) | (cp->ata_channel.ch_channel + 1));
    567        1.1    bouyer 	bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    568        1.1    bouyer 	    (cp->ata_channel.ch_channel + 1) << 2, 0x00000001);
    569        1.1    bouyer }
    570        1.1    bouyer 
    571        1.1    bouyer static int
    572        1.1    bouyer pdc203xx_dma_init(void *v, int channel, int drive, void *databuf,
    573        1.1    bouyer     size_t datalen, int flags)
    574        1.1    bouyer {
    575        1.1    bouyer 	struct pciide_softc *sc = v;
    576        1.1    bouyer 
    577        1.1    bouyer 	return pciide_dma_dmamap_setup(sc, channel, drive,
    578        1.1    bouyer 	    databuf, datalen, flags);
    579        1.1    bouyer }
    580        1.1    bouyer 
    581        1.1    bouyer static void
    582        1.1    bouyer pdc203xx_dma_start(void *v, int channel, int drive)
    583        1.1    bouyer {
    584        1.1    bouyer 	struct pciide_softc *sc = v;
    585        1.1    bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    586        1.1    bouyer 	struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
    587        1.1    bouyer 
    588        1.1    bouyer 	/* Write table addr */
    589        1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_TBL], 0,
    590        1.1    bouyer 	    dma_maps->dmamap_table->dm_segs[0].ds_addr);
    591        1.1    bouyer 	/* start DMA engine */
    592        1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    593        1.1    bouyer 	    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    594        1.1    bouyer 	    0) & ~0xc0) | ((dma_maps->dma_flags & WDC_DMA_READ) ? 0x80 : 0xc0));
    595        1.1    bouyer }
    596        1.1    bouyer 
    597        1.1    bouyer static int
    598       1.14  christos pdc203xx_dma_finish(void *v, int channel, int drive, int force)
    599        1.1    bouyer {
    600        1.1    bouyer 	struct pciide_softc *sc = v;
    601        1.1    bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    602        1.1    bouyer 	struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
    603        1.1    bouyer 
    604        1.1    bouyer 	/* stop DMA channel */
    605        1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    606        1.1    bouyer 	    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    607        1.1    bouyer 	    0) & ~0x80));
    608        1.1    bouyer 
    609        1.1    bouyer 	/* Unload the map of the data buffer */
    610        1.1    bouyer 	bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
    611        1.1    bouyer 	    dma_maps->dmamap_xfer->dm_mapsize,
    612        1.1    bouyer 	    (dma_maps->dma_flags & WDC_DMA_READ) ?
    613        1.1    bouyer 	    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    614        1.1    bouyer 	bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_xfer);
    615        1.1    bouyer 
    616        1.1    bouyer 	return 0;
    617        1.1    bouyer }
    618        1.4  christos 
    619        1.4  christos 
    620        1.4  christos static void
    621        1.7  christos pdcsata_do_reset(struct ata_channel *chp, int poll)
    622        1.4  christos {
    623        1.4  christos 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    624        1.7  christos 	int reset, status, i, chanbase;
    625        1.7  christos 
    626        1.7  christos 	/* reset SATA */
    627        1.7  christos 	reset = (1 << 11);
    628        1.7  christos 	chanbase = PDC_CHANNELBASE(chp->ch_channel) + 0x60;
    629        1.7  christos 	for (i = 0; i < 11;i ++) {
    630        1.7  christos 		status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    631        1.7  christos 		if (status & reset) break;
    632        1.7  christos 		delay(100);
    633        1.7  christos 		status |= reset;
    634        1.7  christos 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
    635        1.7  christos 	}
    636        1.7  christos 	status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    637        1.7  christos 	status &= ~reset;
    638        1.7  christos 	bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
    639        1.7  christos 	status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    640        1.4  christos 
    641        1.4  christos 	wdc_do_reset(chp, poll);
    642        1.4  christos }
    643