Home | History | Annotate | Line # | Download | only in pci
pdcsata.c revision 1.11.2.2
      1  1.11.2.2        ad /*	$NetBSD: pdcsata.c,v 1.11.2.2 2007/02/06 13:32:31 ad 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.11.2.2        ad __KERNEL_RCSID(0, "$NetBSD: pdcsata.c,v 1.11.2.2 2007/02/06 13:32:31 ad 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.11.2.1        ad #define PDC203xx_SATA_NCHANNELS 4
     49  1.11.2.1        ad #define PDC203xx_COMBO_NCHANNELS 3
     50  1.11.2.1        ad #define PDC40718_SATA_NCHANNELS 4
     51  1.11.2.1        ad #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.11.2.1        ad #define	PDC205_REGADDR(base,ch)	((base)+((ch)<<8))
     59  1.11.2.1        ad #define	PDC205_SSTATUS(ch)	PDC205_REGADDR(0x400,ch)
     60  1.11.2.1        ad #define	PDC205_SERROR(ch)	PDC205_REGADDR(0x404,ch)
     61  1.11.2.1        ad #define	PDC205_SCONTROL(ch)	PDC205_REGADDR(0x408,ch)
     62  1.11.2.1        ad #define	PDC205_MULTIPLIER(ch)	PDC205_REGADDR(0x4e8,ch)
     63  1.11.2.1        ad 
     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.11.2.1        ad 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.1    bouyer static int  pdcsata_match(struct device *, struct cfdata *, void *);
     75       1.1    bouyer static void pdcsata_attach(struct device *, struct device *, void *);
     76       1.1    bouyer 
     77       1.1    bouyer CFATTACH_DECL(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.11.2.1        ad 	{ PCI_PRODUCT_PROMISE_PDC20617,
    172  1.11.2.1        ad 	  0,
    173  1.11.2.1        ad 	  "Promise PDC2020617 Ultra/133 controller",
    174  1.11.2.1        ad 	  pdcsata_chip_map,
    175  1.11.2.1        ad 	},
    176  1.11.2.1        ad 	{ PCI_PRODUCT_PROMISE_PDC20618,
    177  1.11.2.1        ad 	  0,
    178  1.11.2.1        ad 	  "Promise PDC20618 Ultra/133 controller",
    179  1.11.2.1        ad 	  pdcsata_chip_map,
    180  1.11.2.1        ad 	},
    181  1.11.2.1        ad 	{ PCI_PRODUCT_PROMISE_PDC20619,
    182  1.11.2.1        ad 	  0,
    183  1.11.2.1        ad 	  "Promise PDC20619 Ultra/133 controller",
    184  1.11.2.1        ad 	  pdcsata_chip_map,
    185  1.11.2.1        ad 	},
    186  1.11.2.1        ad 	{ PCI_PRODUCT_PROMISE_PDC20620,
    187  1.11.2.1        ad 	  0,
    188  1.11.2.1        ad 	  "Promise PDC20620 Ultra/133 controller",
    189  1.11.2.1        ad 	  pdcsata_chip_map,
    190  1.11.2.1        ad 	},
    191  1.11.2.1        ad 	{ PCI_PRODUCT_PROMISE_PDC20621,
    192  1.11.2.1        ad 	  0,
    193  1.11.2.1        ad 	  "Promise PDC20621 Ultra/133 controller",
    194  1.11.2.1        ad 	  pdcsata_chip_map,
    195  1.11.2.1        ad 	},
    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.11.2.1        ad pdcsata_match(struct device *parent, struct cfdata *match,
    205  1.11.2.1        ad     void *aux)
    206       1.1    bouyer {
    207       1.1    bouyer 	struct pci_attach_args *pa = aux;
    208       1.1    bouyer 
    209       1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_PROMISE) {
    210       1.1    bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_pdcsata_products))
    211       1.1    bouyer 			return (2);
    212       1.1    bouyer 	}
    213       1.1    bouyer 	return (0);
    214       1.1    bouyer }
    215       1.1    bouyer 
    216       1.1    bouyer static void
    217       1.1    bouyer pdcsata_attach(struct device *parent, struct device *self, void *aux)
    218       1.1    bouyer {
    219       1.1    bouyer 	struct pci_attach_args *pa = aux;
    220       1.1    bouyer 	struct pciide_softc *sc = (struct pciide_softc *)self;
    221       1.1    bouyer 
    222       1.1    bouyer 	pciide_common_attach(sc, pa,
    223       1.1    bouyer 	    pciide_lookup_product(pa->pa_id, pciide_pdcsata_products));
    224       1.1    bouyer }
    225       1.1    bouyer 
    226       1.1    bouyer static void
    227       1.1    bouyer pdcsata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    228       1.1    bouyer {
    229       1.1    bouyer 	struct pciide_channel *cp;
    230       1.1    bouyer 	struct ata_channel *wdc_cp;
    231       1.1    bouyer 	struct wdc_regs *wdr;
    232       1.1    bouyer 	int channel, i;
    233       1.1    bouyer 	bus_size_t dmasize;
    234       1.1    bouyer 	pci_intr_handle_t intrhandle;
    235       1.1    bouyer 	const char *intrstr;
    236       1.1    bouyer 
    237       1.1    bouyer 	/*
    238       1.1    bouyer 	 * Promise SATA controllers have 3 or 4 channels,
    239       1.1    bouyer 	 * the usual IDE registers are mapped in I/O space, with offsets.
    240       1.1    bouyer 	 */
    241       1.1    bouyer 	if (pci_intr_map(pa, &intrhandle) != 0) {
    242       1.1    bouyer 		aprint_error("%s: couldn't map interrupt\n",
    243       1.1    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    244       1.1    bouyer 		return;
    245       1.1    bouyer 	}
    246       1.1    bouyer 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    247       1.7  christos 	sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    248       1.7  christos 	    intrhandle, IPL_BIO, pdcsata_pci_intr, sc);
    249       1.4  christos 
    250       1.1    bouyer 	if (sc->sc_pci_ih == NULL) {
    251       1.1    bouyer 		aprint_error("%s: couldn't establish native-PCI interrupt",
    252       1.1    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    253       1.1    bouyer 		if (intrstr != NULL)
    254       1.1    bouyer 		    aprint_normal(" at %s", intrstr);
    255       1.1    bouyer 		aprint_normal("\n");
    256       1.1    bouyer 		return;
    257       1.1    bouyer 	}
    258       1.1    bouyer 	aprint_normal("%s: interrupting at %s\n",
    259       1.1    bouyer 		sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    260       1.1    bouyer 		intrstr ? intrstr : "unknown interrupt");
    261       1.3     perry 
    262       1.1    bouyer 	sc->sc_dma_ok = (pci_mapreg_map(pa, PCIIDE_REG_BUS_MASTER_DMA,
    263       1.1    bouyer 	    PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_dma_iot,
    264       1.1    bouyer 	    &sc->sc_dma_ioh, NULL, &dmasize) == 0);
    265       1.1    bouyer 	if (!sc->sc_dma_ok) {
    266       1.1    bouyer 		aprint_error("%s: couldn't map bus-master DMA registers\n",
    267       1.1    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    268       1.1    bouyer 		pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
    269       1.1    bouyer 		return;
    270       1.1    bouyer 	}
    271       1.1    bouyer 
    272       1.1    bouyer 	sc->sc_dmat = pa->pa_dmat;
    273       1.1    bouyer 
    274       1.1    bouyer 	if (pci_mapreg_map(pa, PDC203xx_BAR_IDEREGS,
    275       1.1    bouyer 	    PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_ba5_st,
    276       1.1    bouyer 	    &sc->sc_ba5_sh, NULL, NULL) != 0) {
    277       1.1    bouyer 		aprint_error("%s: couldn't map IDE registers\n",
    278       1.1    bouyer 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    279       1.1    bouyer 		bus_space_unmap(sc->sc_dma_iot, sc->sc_dma_ioh, dmasize);
    280       1.1    bouyer 		pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
    281       1.1    bouyer 		return;
    282       1.1    bouyer 	}
    283       1.1    bouyer 
    284  1.11.2.2        ad 	aprint_verbose("%s: bus-master DMA support present\n",
    285       1.1    bouyer 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    286       1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
    287       1.1    bouyer 	if (sc->sc_dma_ok) {
    288       1.1    bouyer 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    289       1.1    bouyer 	}
    290       1.2    bouyer 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    291       1.2    bouyer 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
    292       1.2    bouyer 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
    293       1.1    bouyer 	sc->sc_wdcdev.irqack = pdc203xx_irqack;
    294       1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    295       1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    296       1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    297       1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_set_modes = pdc203xx_setup_channel;
    298       1.1    bouyer 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    299       1.4  christos 
    300       1.7  christos 	sc->sc_wdcdev.reset = pdcsata_do_reset;
    301       1.7  christos 
    302       1.4  christos 	switch (sc->sc_pp->ide_product) {
    303       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20318:
    304       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20319:
    305  1.11.2.1        ad 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x6c,
    306  1.11.2.1        ad 		    0x00ff0033);
    307  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    308  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC203xx_SATA_NCHANNELS;
    309  1.11.2.1        ad 		break;
    310       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20371:
    311       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20375:
    312       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20376:
    313       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20377:
    314       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20378:
    315       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC20379:
    316  1.11.2.1        ad 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x6c,
    317  1.11.2.1        ad 		    0x00ff0033);
    318  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_probe = pdc203xx_combo_probe;
    319  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC203xx_COMBO_NCHANNELS;
    320       1.4  christos 		break;
    321       1.4  christos 
    322       1.8   xtraeme 	case PCI_PRODUCT_PROMISE_PDC40518:
    323      1.11   xtraeme 	case PCI_PRODUCT_PROMISE_PDC40519:
    324       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC40718:
    325       1.4  christos 	case PCI_PRODUCT_PROMISE_PDC40719:
    326      1.11   xtraeme 	case PCI_PRODUCT_PROMISE_PDC40779:
    327  1.11.2.1        ad 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60,
    328  1.11.2.1        ad 		    0x00ff00ff);
    329  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC40718_SATA_NCHANNELS;
    330  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    331       1.4  christos 		break;
    332  1.11.2.1        ad 
    333  1.11.2.1        ad 	case PCI_PRODUCT_PROMISE_PDC20571:
    334       1.6    bouyer 	case PCI_PRODUCT_PROMISE_PDC20575:
    335       1.6    bouyer 	case PCI_PRODUCT_PROMISE_PDC20579:
    336      1.10   dsainty 	case PCI_PRODUCT_PROMISE_PDC20771:
    337       1.8   xtraeme 	case PCI_PRODUCT_PROMISE_PDC20775:
    338  1.11.2.1        ad 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60,
    339  1.11.2.1        ad 		    0x00ff00ff);
    340  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_nchannels = PDC20575_COMBO_NCHANNELS;
    341  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_probe = pdc203xx_combo_probe;
    342  1.11.2.1        ad 		break;
    343       1.6    bouyer 
    344  1.11.2.1        ad 	case PCI_PRODUCT_PROMISE_PDC20617:
    345  1.11.2.1        ad 	case PCI_PRODUCT_PROMISE_PDC20618:
    346  1.11.2.1        ad 	case PCI_PRODUCT_PROMISE_PDC20619:
    347  1.11.2.1        ad 	case PCI_PRODUCT_PROMISE_PDC20620:
    348  1.11.2.1        ad 	case PCI_PRODUCT_PROMISE_PDC20621:
    349  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_nchannels =
    350  1.11.2.1        ad 		    ((bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    351  1.11.2.1        ad 			0x48) & 0x01) ? 1 : 0) +
    352  1.11.2.1        ad 		    ((bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    353  1.11.2.1        ad 			0x48) & 0x02) ? 1 : 0) +
    354  1.11.2.1        ad 		    2;
    355  1.11.2.1        ad 		sc->sc_wdcdev.sc_atac.atac_probe = wdc_drvprobe;
    356       1.6    bouyer 
    357  1.11.2.1        ad 	default:
    358  1.11.2.1        ad 		aprint_error("unknown promise product 0x%x\n",
    359  1.11.2.1        ad 		    sc->sc_pp->ide_product);
    360       1.4  christos 	}
    361       1.4  christos 
    362       1.1    bouyer 	wdc_allocate_regs(&sc->sc_wdcdev);
    363       1.1    bouyer 
    364       1.1    bouyer 	sc->sc_wdcdev.dma_arg = sc;
    365       1.1    bouyer 	sc->sc_wdcdev.dma_init = pdc203xx_dma_init;
    366       1.1    bouyer 	sc->sc_wdcdev.dma_start = pdc203xx_dma_start;
    367       1.1    bouyer 	sc->sc_wdcdev.dma_finish = pdc203xx_dma_finish;
    368       1.1    bouyer 
    369       1.1    bouyer 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    370       1.1    bouyer 	     channel++) {
    371       1.1    bouyer 		cp = &sc->pciide_channels[channel];
    372       1.1    bouyer 		sc->wdc_chanarray[channel] = &cp->ata_channel;
    373       1.1    bouyer 
    374       1.1    bouyer 		cp->ih = sc->sc_pci_ih;
    375       1.1    bouyer 		cp->name = NULL;
    376       1.1    bouyer 		cp->ata_channel.ch_channel = channel;
    377       1.1    bouyer 		cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    378       1.1    bouyer 		cp->ata_channel.ch_queue =
    379       1.1    bouyer 		    malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
    380       1.5    bouyer 		cp->ata_channel.ch_ndrive = 2;
    381       1.1    bouyer 		if (cp->ata_channel.ch_queue == NULL) {
    382       1.1    bouyer 			aprint_error("%s channel %d: "
    383       1.1    bouyer 			    "can't allocate memory for command queue\n",
    384       1.1    bouyer 			sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
    385       1.1    bouyer 			goto next_channel;
    386       1.1    bouyer 		}
    387       1.1    bouyer 		wdc_cp = &cp->ata_channel;
    388       1.1    bouyer 		wdr = CHAN_TO_WDC_REGS(wdc_cp);
    389       1.1    bouyer 
    390       1.1    bouyer 		wdr->ctl_iot = sc->sc_ba5_st;
    391       1.1    bouyer 		wdr->cmd_iot = sc->sc_ba5_st;
    392       1.1    bouyer 
    393       1.1    bouyer 		if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    394       1.1    bouyer 		    0x0238 + (channel << 7), 1, &wdr->ctl_ioh) != 0) {
    395       1.1    bouyer 			aprint_error("%s: couldn't map channel %d ctl regs\n",
    396       1.1    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    397       1.1    bouyer 			    channel);
    398       1.1    bouyer 			goto next_channel;
    399       1.1    bouyer 		}
    400       1.1    bouyer 		for (i = 0; i < WDC_NREG; i++) {
    401       1.1    bouyer 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    402       1.1    bouyer 			    0x0200 + (i << 2) + (channel << 7), i == 0 ? 4 : 1,
    403       1.1    bouyer 			    &wdr->cmd_iohs[i]) != 0) {
    404       1.1    bouyer 				aprint_error("%s: couldn't map channel %d cmd "
    405       1.1    bouyer 				    "regs\n",
    406       1.1    bouyer 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    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.1    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
    425       1.1    bouyer 			goto next_channel;
    426       1.1    bouyer 		}
    427       1.1    bouyer 		if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    428       1.1    bouyer 		    0x244 + (channel << 7), 4,
    429       1.1    bouyer 		    &cp->dma_iohs[IDEDMA_TBL]) != 0) {
    430       1.1    bouyer 			aprint_normal("%s channel %d: can't subregion DMA "
    431       1.1    bouyer 			    "registers\n",
    432       1.1    bouyer 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
    433       1.1    bouyer 			goto next_channel;
    434       1.1    bouyer 		}
    435       1.1    bouyer 
    436  1.11.2.1        ad 		/* subregion the SATA registers */
    437  1.11.2.1        ad 		if (sc->sc_wdcdev.sc_atac.atac_probe == wdc_sataprobe ||
    438  1.11.2.1        ad 		    (sc->sc_wdcdev.sc_atac.atac_probe == pdc203xx_combo_probe
    439  1.11.2.1        ad 		    && channel < 2)) {
    440  1.11.2.1        ad 			wdr->sata_iot = sc->sc_ba5_st;
    441  1.11.2.1        ad 			wdr->sata_baseioh = sc->sc_ba5_sh;
    442  1.11.2.1        ad 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    443  1.11.2.1        ad 			    PDC205_SSTATUS(channel), 1,
    444  1.11.2.1        ad 			    &wdr->sata_status) != 0) {
    445  1.11.2.1        ad 				aprint_error("%s: couldn't map channel %d "
    446  1.11.2.1        ad 				    "sata_status regs\n",
    447  1.11.2.1        ad 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    448  1.11.2.1        ad 				    channel);
    449  1.11.2.1        ad 				goto next_channel;
    450  1.11.2.1        ad 			}
    451  1.11.2.1        ad 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    452  1.11.2.1        ad 			    PDC205_SERROR(channel), 1, &wdr->sata_error) != 0) {
    453  1.11.2.1        ad 				aprint_error("%s: couldn't map channel %d "
    454  1.11.2.1        ad 				    "sata_error regs\n",
    455  1.11.2.1        ad 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    456  1.11.2.1        ad 				    channel);
    457  1.11.2.1        ad 				goto next_channel;
    458  1.11.2.1        ad 			}
    459  1.11.2.1        ad 			if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    460  1.11.2.1        ad 			    PDC205_SCONTROL(channel), 1,
    461  1.11.2.1        ad 			    &wdr->sata_control) != 0) {
    462  1.11.2.1        ad 				aprint_error("%s: couldn't map channel %d "
    463  1.11.2.1        ad 				    "sata_control regs\n",
    464  1.11.2.1        ad 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    465  1.11.2.1        ad 				    channel);
    466  1.11.2.1        ad 				goto next_channel;
    467  1.11.2.1        ad 			}
    468  1.11.2.1        ad 		}
    469  1.11.2.1        ad 
    470       1.1    bouyer 		wdcattach(wdc_cp);
    471       1.1    bouyer 		bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    472       1.1    bouyer 		    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    473       1.1    bouyer 			0) & ~0x00003f9f) | (channel + 1));
    474       1.1    bouyer 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    475       1.1    bouyer 		    (channel + 1) << 2, 0x00000001);
    476       1.1    bouyer next_channel:
    477       1.1    bouyer 	continue;
    478       1.1    bouyer 	}
    479       1.1    bouyer 	return;
    480       1.1    bouyer }
    481       1.1    bouyer 
    482       1.1    bouyer static void
    483  1.11.2.1        ad pdc203xx_combo_probe(struct ata_channel *chp)
    484  1.11.2.1        ad {
    485  1.11.2.1        ad 	if (chp->ch_channel < 2)
    486  1.11.2.1        ad 		wdc_sataprobe(chp);
    487  1.11.2.1        ad 	else
    488  1.11.2.1        ad 		wdc_drvprobe(chp);
    489  1.11.2.1        ad }
    490  1.11.2.1        ad 
    491  1.11.2.1        ad static void
    492       1.1    bouyer pdc203xx_setup_channel(struct ata_channel *chp)
    493       1.1    bouyer {
    494       1.1    bouyer 	struct ata_drive_datas *drvp;
    495       1.1    bouyer 	int drive, s;
    496       1.1    bouyer 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    497       1.1    bouyer 
    498       1.1    bouyer 	pciide_channel_dma_setup(cp);
    499       1.1    bouyer 
    500       1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    501       1.1    bouyer 		drvp = &chp->ch_drive[drive];
    502       1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    503       1.1    bouyer 			continue;
    504       1.1    bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    505       1.1    bouyer 			s = splbio();
    506       1.1    bouyer 			drvp->drive_flags &= ~DRIVE_DMA;
    507       1.1    bouyer 			splx(s);
    508       1.1    bouyer 		}
    509       1.1    bouyer 	}
    510       1.1    bouyer }
    511       1.1    bouyer 
    512       1.1    bouyer static int
    513       1.7  christos pdcsata_pci_intr(void *arg)
    514       1.1    bouyer {
    515       1.1    bouyer 	struct pciide_softc *sc = arg;
    516       1.1    bouyer 	struct pciide_channel *cp;
    517       1.1    bouyer 	struct ata_channel *wdc_cp;
    518       1.3     perry 	int i, rv, crv;
    519       1.7  christos 	u_int32_t scr, status, chanbase;
    520       1.4  christos 
    521       1.4  christos 	rv = 0;
    522       1.4  christos 	scr = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40);
    523       1.7  christos 	if (scr == 0xffffffff) return(rv);
    524       1.4  christos 	bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40, scr & 0x0000ffff);
    525       1.7  christos 	scr = scr & 0x0000ffff;
    526       1.7  christos 	if (!scr) return(rv);
    527       1.4  christos 
    528       1.4  christos 	for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
    529       1.4  christos 		cp = &sc->pciide_channels[i];
    530       1.4  christos 		wdc_cp = &cp->ata_channel;
    531       1.4  christos 		if (scr & (1 << (i + 1))) {
    532       1.7  christos 			chanbase = PDC_CHANNELBASE(i) + 0x48;
    533       1.7  christos 			status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    534       1.7  christos 			if (status & PDC_ERRMASK) {
    535       1.7  christos 				chanbase = PDC_CHANNELBASE(i) + 0x60;
    536       1.7  christos 				status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    537       1.7  christos 				status |= 0x800;
    538       1.7  christos 				bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
    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 = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    542       1.7  christos 				continue;
    543       1.7  christos 			}
    544       1.4  christos 			crv = wdcintr(wdc_cp);
    545       1.4  christos 			if (crv == 0) {
    546       1.4  christos 				printf("%s:%d: bogus intr (reg 0x%x)\n",
    547       1.4  christos 				    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    548       1.4  christos 				    i, scr);
    549       1.4  christos 			} else
    550       1.4  christos 				rv = 1;
    551       1.4  christos 		}
    552       1.4  christos 	}
    553       1.4  christos 	return rv;
    554       1.4  christos }
    555       1.4  christos 
    556       1.1    bouyer static void
    557       1.1    bouyer pdc203xx_irqack(struct ata_channel *chp)
    558       1.1    bouyer {
    559       1.1    bouyer 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    560       1.1    bouyer 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    561       1.1    bouyer 
    562       1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    563       1.1    bouyer 	    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    564       1.1    bouyer 		0) & ~0x00003f9f) | (cp->ata_channel.ch_channel + 1));
    565       1.1    bouyer 	bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
    566       1.1    bouyer 	    (cp->ata_channel.ch_channel + 1) << 2, 0x00000001);
    567       1.1    bouyer }
    568       1.1    bouyer 
    569       1.1    bouyer static int
    570       1.1    bouyer pdc203xx_dma_init(void *v, int channel, int drive, void *databuf,
    571       1.1    bouyer     size_t datalen, int flags)
    572       1.1    bouyer {
    573       1.1    bouyer 	struct pciide_softc *sc = v;
    574       1.1    bouyer 
    575       1.1    bouyer 	return pciide_dma_dmamap_setup(sc, channel, drive,
    576       1.1    bouyer 	    databuf, datalen, flags);
    577       1.1    bouyer }
    578       1.1    bouyer 
    579       1.1    bouyer static void
    580       1.1    bouyer pdc203xx_dma_start(void *v, int channel, int drive)
    581       1.1    bouyer {
    582       1.1    bouyer 	struct pciide_softc *sc = v;
    583       1.1    bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    584       1.1    bouyer 	struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
    585       1.1    bouyer 
    586       1.1    bouyer 	/* Write table addr */
    587       1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_TBL], 0,
    588       1.1    bouyer 	    dma_maps->dmamap_table->dm_segs[0].ds_addr);
    589       1.1    bouyer 	/* start DMA engine */
    590       1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    591       1.1    bouyer 	    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    592       1.1    bouyer 	    0) & ~0xc0) | ((dma_maps->dma_flags & WDC_DMA_READ) ? 0x80 : 0xc0));
    593       1.1    bouyer }
    594       1.1    bouyer 
    595       1.1    bouyer static int
    596       1.1    bouyer pdc203xx_dma_finish(void *v, int channel, int drive, int force)
    597       1.1    bouyer {
    598       1.1    bouyer 	struct pciide_softc *sc = v;
    599       1.1    bouyer 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    600       1.1    bouyer 	struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
    601       1.1    bouyer 
    602       1.1    bouyer 	/* stop DMA channel */
    603       1.1    bouyer 	bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
    604       1.1    bouyer 	    (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
    605       1.1    bouyer 	    0) & ~0x80));
    606       1.1    bouyer 
    607       1.1    bouyer 	/* Unload the map of the data buffer */
    608       1.1    bouyer 	bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
    609       1.1    bouyer 	    dma_maps->dmamap_xfer->dm_mapsize,
    610       1.1    bouyer 	    (dma_maps->dma_flags & WDC_DMA_READ) ?
    611       1.1    bouyer 	    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    612       1.1    bouyer 	bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_xfer);
    613       1.1    bouyer 
    614       1.1    bouyer 	return 0;
    615       1.1    bouyer }
    616       1.4  christos 
    617       1.4  christos 
    618       1.4  christos static void
    619       1.7  christos pdcsata_do_reset(struct ata_channel *chp, int poll)
    620       1.4  christos {
    621       1.4  christos 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    622       1.7  christos 	int reset, status, i, chanbase;
    623       1.7  christos 
    624       1.7  christos 	/* reset SATA */
    625       1.7  christos 	reset = (1 << 11);
    626       1.7  christos 	chanbase = PDC_CHANNELBASE(chp->ch_channel) + 0x60;
    627       1.7  christos 	for (i = 0; i < 11;i ++) {
    628       1.7  christos 		status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    629       1.7  christos 		if (status & reset) break;
    630       1.7  christos 		delay(100);
    631       1.7  christos 		status |= reset;
    632       1.7  christos 		bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
    633       1.7  christos 	}
    634       1.7  christos 	status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    635       1.7  christos 	status &= ~reset;
    636       1.7  christos 	bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase, status);
    637       1.7  christos 	status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, chanbase);
    638       1.4  christos 
    639       1.4  christos 	wdc_do_reset(chp, poll);
    640       1.4  christos 
    641       1.4  christos }
    642