Home | History | Annotate | Line # | Download | only in pci
satalink.c revision 1.1
      1  1.1  thorpej /*	$NetBSD: satalink.c,v 1.1 2003/12/13 23:13:41 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*
      4  1.1  thorpej  * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
      5  1.1  thorpej  *
      6  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      7  1.1  thorpej  * modification, are permitted provided that the following conditions
      8  1.1  thorpej  * are met:
      9  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     10  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     11  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     14  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     15  1.1  thorpej  *    must display the following acknowledgement:
     16  1.1  thorpej  *	This product includes software developed by Manuel Bouyer.
     17  1.1  thorpej  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  thorpej  *    derived from this software without specific prior written permission.
     19  1.1  thorpej  *
     20  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  thorpej  */
     31  1.1  thorpej 
     32  1.1  thorpej #include <sys/param.h>
     33  1.1  thorpej #include <sys/systm.h>
     34  1.1  thorpej #include <sys/malloc.h>
     35  1.1  thorpej 
     36  1.1  thorpej #include <dev/pci/pcivar.h>
     37  1.1  thorpej #include <dev/pci/pcidevs.h>
     38  1.1  thorpej #include <dev/pci/pciidereg.h>
     39  1.1  thorpej #include <dev/pci/pciidevar.h>
     40  1.1  thorpej #include <dev/pci/pciide_sii3112_reg.h>
     41  1.1  thorpej 
     42  1.1  thorpej 
     43  1.1  thorpej static int  satalink_match(struct device *, struct cfdata *, void *);
     44  1.1  thorpej static void satalink_attach(struct device *, struct device *, void *);
     45  1.1  thorpej 
     46  1.1  thorpej CFATTACH_DECL(satalink, sizeof(struct pciide_softc),
     47  1.1  thorpej     satalink_match, satalink_attach, NULL, NULL);
     48  1.1  thorpej 
     49  1.1  thorpej static void sii3112_chip_map(struct pciide_softc*, struct pci_attach_args*);
     50  1.1  thorpej static void sii3112_setup_channel(struct channel_softc*);
     51  1.1  thorpej 
     52  1.1  thorpej static const struct pciide_product_desc pciide_satalink_products[] =  {
     53  1.1  thorpej 	{ PCI_PRODUCT_CMDTECH_3112,
     54  1.1  thorpej 	  0,
     55  1.1  thorpej 	  "Silicon Image SATALink 3112",
     56  1.1  thorpej 	  sii3112_chip_map,
     57  1.1  thorpej 	},
     58  1.1  thorpej 	{ 0,
     59  1.1  thorpej 	  0,
     60  1.1  thorpej 	  NULL,
     61  1.1  thorpej 	  NULL
     62  1.1  thorpej 	}
     63  1.1  thorpej };
     64  1.1  thorpej 
     65  1.1  thorpej static int
     66  1.1  thorpej satalink_match(struct device *parent, struct cfdata *match, void *aux)
     67  1.1  thorpej {
     68  1.1  thorpej 	struct pci_attach_args *pa = aux;
     69  1.1  thorpej 
     70  1.1  thorpej 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CMDTECH) {
     71  1.1  thorpej 		if (pciide_lookup_product(pa->pa_id, pciide_satalink_products))
     72  1.1  thorpej 			return (2);
     73  1.1  thorpej 	}
     74  1.1  thorpej 	return (0);
     75  1.1  thorpej }
     76  1.1  thorpej 
     77  1.1  thorpej static void
     78  1.1  thorpej satalink_attach(struct device *parent, struct device *self, void *aux)
     79  1.1  thorpej {
     80  1.1  thorpej 	struct pci_attach_args *pa = aux;
     81  1.1  thorpej 	struct pciide_softc *sc = (struct pciide_softc *)self;
     82  1.1  thorpej 
     83  1.1  thorpej 	pciide_common_attach(sc, pa,
     84  1.1  thorpej 	    pciide_lookup_product(pa->pa_id, pciide_satalink_products));
     85  1.1  thorpej 
     86  1.1  thorpej }
     87  1.1  thorpej 
     88  1.1  thorpej static void
     89  1.1  thorpej sii3112_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
     90  1.1  thorpej {
     91  1.1  thorpej 	struct pciide_channel *cp;
     92  1.1  thorpej 	bus_size_t cmdsize, ctlsize;
     93  1.1  thorpej 	pcireg_t interface;
     94  1.1  thorpej 	int channel;
     95  1.1  thorpej 
     96  1.1  thorpej 	if (pciide_chipen(sc, pa) == 0)
     97  1.1  thorpej 		return;
     98  1.1  thorpej 
     99  1.1  thorpej 	aprint_normal("%s: bus-master DMA support present",
    100  1.1  thorpej 	    sc->sc_wdcdev.sc_dev.dv_xname);
    101  1.1  thorpej 	pciide_mapreg_dma(sc, pa);
    102  1.1  thorpej 	aprint_normal("\n");
    103  1.1  thorpej 
    104  1.1  thorpej 	/*
    105  1.1  thorpej 	 * Rev. <= 0x01 of the 3112 have a bug that can cause data
    106  1.1  thorpej 	 * corruption if DMA transfers cross an 8K boundary.  This is
    107  1.1  thorpej 	 * apparently hard to tickle, but we'll go ahead and play it
    108  1.1  thorpej 	 * safe.
    109  1.1  thorpej 	 */
    110  1.1  thorpej 	if (PCI_REVISION(pa->pa_class) <= 0x01) {
    111  1.1  thorpej 		sc->sc_dma_maxsegsz = 8192;
    112  1.1  thorpej 		sc->sc_dma_boundary = 8192;
    113  1.1  thorpej 	}
    114  1.1  thorpej 
    115  1.1  thorpej 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32 |
    116  1.1  thorpej 	    WDC_CAPABILITY_MODE;
    117  1.1  thorpej 	sc->sc_wdcdev.PIO_cap = 4;
    118  1.1  thorpej 	if (sc->sc_dma_ok) {
    119  1.1  thorpej 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_UDMA;
    120  1.1  thorpej 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_IRQACK;
    121  1.1  thorpej 		sc->sc_wdcdev.irqack = pciide_irqack;
    122  1.1  thorpej 		sc->sc_wdcdev.DMA_cap = 2;
    123  1.1  thorpej 		sc->sc_wdcdev.UDMA_cap = 6;
    124  1.1  thorpej 	}
    125  1.1  thorpej 	sc->sc_wdcdev.set_modes = sii3112_setup_channel;
    126  1.1  thorpej 
    127  1.1  thorpej 	sc->sc_wdcdev.channels = sc->wdc_chanarray;
    128  1.1  thorpej 	sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
    129  1.1  thorpej 
    130  1.1  thorpej 	/*
    131  1.1  thorpej 	 * The 3112 can be told to identify as a RAID controller.
    132  1.1  thorpej 	 * In this case, we have to fake interface
    133  1.1  thorpej 	 */
    134  1.1  thorpej 	if (PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {
    135  1.1  thorpej 		interface = PCI_INTERFACE(pa->pa_class);
    136  1.1  thorpej 	} else {
    137  1.1  thorpej 		interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
    138  1.1  thorpej 		    PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
    139  1.1  thorpej 	}
    140  1.1  thorpej 
    141  1.1  thorpej 	for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
    142  1.1  thorpej 		cp = &sc->pciide_channels[channel];
    143  1.1  thorpej 		if (pciide_chansetup(sc, channel, interface) == 0)
    144  1.1  thorpej 			continue;
    145  1.1  thorpej 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    146  1.1  thorpej 		    pciide_pci_intr);
    147  1.1  thorpej 	}
    148  1.1  thorpej }
    149  1.1  thorpej 
    150  1.1  thorpej static void
    151  1.1  thorpej sii3112_setup_channel(struct channel_softc *chp)
    152  1.1  thorpej {
    153  1.1  thorpej 	struct ata_drive_datas *drvp;
    154  1.1  thorpej 	int drive;
    155  1.1  thorpej 	u_int32_t idedma_ctl, dtm;
    156  1.1  thorpej 	struct pciide_channel *cp = (struct pciide_channel*)chp;
    157  1.1  thorpej 	struct pciide_softc *sc = (struct pciide_softc*)cp->wdc_channel.wdc;
    158  1.1  thorpej 
    159  1.1  thorpej 	/* setup DMA if needed */
    160  1.1  thorpej 	pciide_channel_dma_setup(cp);
    161  1.1  thorpej 
    162  1.1  thorpej 	idedma_ctl = 0;
    163  1.1  thorpej 	dtm = 0;
    164  1.1  thorpej 
    165  1.1  thorpej 	for (drive = 0; drive < 2; drive++) {
    166  1.1  thorpej 		drvp = &chp->ch_drive[drive];
    167  1.1  thorpej 		/* If no drive, skip */
    168  1.1  thorpej 		if ((drvp->drive_flags & DRIVE) == 0)
    169  1.1  thorpej 			continue;
    170  1.1  thorpej 		if (drvp->drive_flags & DRIVE_UDMA) {
    171  1.1  thorpej 			/* use Ultra/DMA */
    172  1.1  thorpej 			drvp->drive_flags &= ~DRIVE_DMA;
    173  1.1  thorpej 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    174  1.1  thorpej 			dtm |= DTM_IDEx_DMA;
    175  1.1  thorpej 		} else if (drvp->drive_flags & DRIVE_DMA) {
    176  1.1  thorpej 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    177  1.1  thorpej 			dtm |= DTM_IDEx_DMA;
    178  1.1  thorpej 		} else {
    179  1.1  thorpej 			dtm |= DTM_IDEx_PIO;
    180  1.1  thorpej 		}
    181  1.1  thorpej 	}
    182  1.1  thorpej 
    183  1.1  thorpej 	/*
    184  1.1  thorpej 	 * Nothing to do to setup modes; it is meaningless in S-ATA
    185  1.1  thorpej 	 * (but many S-ATA drives still want to get the SET_FEATURE
    186  1.1  thorpej 	 * command).
    187  1.1  thorpej 	 */
    188  1.1  thorpej 	if (idedma_ctl != 0) {
    189  1.1  thorpej 		/* Add software bits in status register */
    190  1.1  thorpej 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    191  1.1  thorpej 		    idedma_ctl);
    192  1.1  thorpej 	}
    193  1.1  thorpej 	pci_conf_write(sc->sc_pc, sc->sc_tag,
    194  1.1  thorpej 	    chp->channel == 0 ? SII3112_DTM_IDE0 : SII3112_DTM_IDE1, dtm);
    195  1.1  thorpej }
    196