Home | History | Annotate | Line # | Download | only in pci
schide.c revision 1.7.2.2
      1  1.7.2.2       tls /*	$NetBSD: schide.c,v 1.7.2.2 2014/08/20 00:03:48 tls Exp $	*/
      2      1.1  jakllsch /*	$OpenBSD: pciide.c,v 1.305 2009/11/01 01:50:15 dlg Exp $	*/
      3      1.1  jakllsch 
      4      1.1  jakllsch /*
      5      1.1  jakllsch  * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
      6      1.1  jakllsch  *
      7      1.1  jakllsch  * Redistribution and use in source and binary forms, with or without
      8      1.1  jakllsch  * modification, are permitted provided that the following conditions
      9      1.1  jakllsch  * are met:
     10      1.1  jakllsch  * 1. Redistributions of source code must retain the above copyright
     11      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer.
     12      1.1  jakllsch  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  jakllsch  *    documentation and/or other materials provided with the distribution.
     15      1.1  jakllsch  *
     16      1.1  jakllsch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.1  jakllsch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.1  jakllsch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1  jakllsch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.1  jakllsch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21      1.1  jakllsch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22      1.1  jakllsch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23      1.1  jakllsch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24      1.1  jakllsch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25      1.1  jakllsch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26      1.1  jakllsch  *
     27      1.1  jakllsch  */
     28      1.1  jakllsch 
     29      1.1  jakllsch /*
     30      1.1  jakllsch  * Copyright (c) 1996, 1998 Christopher G. Demetriou.  All rights reserved.
     31      1.1  jakllsch  *
     32      1.1  jakllsch  * Redistribution and use in source and binary forms, with or without
     33      1.1  jakllsch  * modification, are permitted provided that the following conditions
     34      1.1  jakllsch  * are met:
     35      1.1  jakllsch  * 1. Redistributions of source code must retain the above copyright
     36      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer.
     37      1.1  jakllsch  * 2. Redistributions in binary form must reproduce the above copyright
     38      1.1  jakllsch  *    notice, this list of conditions and the following disclaimer in the
     39      1.1  jakllsch  *    documentation and/or other materials provided with the distribution.
     40      1.1  jakllsch  * 3. All advertising materials mentioning features or use of this software
     41      1.1  jakllsch  *    must display the following acknowledgement:
     42      1.1  jakllsch  *      This product includes software developed by Christopher G. Demetriou
     43      1.1  jakllsch  *	for the NetBSD Project.
     44      1.1  jakllsch  * 4. The name of the author may not be used to endorse or promote products
     45      1.1  jakllsch  *    derived from this software without specific prior written permission
     46      1.1  jakllsch  *
     47      1.1  jakllsch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48      1.1  jakllsch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49      1.1  jakllsch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50      1.1  jakllsch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     51      1.1  jakllsch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     52      1.1  jakllsch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     53      1.1  jakllsch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     54      1.1  jakllsch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     55      1.1  jakllsch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     56      1.1  jakllsch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     57      1.1  jakllsch  */
     58      1.1  jakllsch 
     59      1.1  jakllsch #include <sys/cdefs.h>
     60  1.7.2.2       tls __KERNEL_RCSID(0, "$NetBSD: schide.c,v 1.7.2.2 2014/08/20 00:03:48 tls Exp $");
     61      1.1  jakllsch 
     62      1.1  jakllsch #include <sys/param.h>
     63      1.1  jakllsch #include <sys/systm.h>
     64      1.1  jakllsch 
     65      1.1  jakllsch #include <dev/pci/pcivar.h>
     66      1.1  jakllsch #include <dev/pci/pcidevs.h>
     67      1.1  jakllsch #include <dev/pci/pciidereg.h>
     68      1.1  jakllsch #include <dev/pci/pciidevar.h>
     69      1.1  jakllsch #include <dev/pci/pciide_sch_reg.h>
     70      1.1  jakllsch 
     71      1.2    dyoung static void sch_chip_map(struct pciide_softc*, const struct pci_attach_args*);
     72      1.1  jakllsch static void sch_setup_channel(struct ata_channel*);
     73      1.1  jakllsch static int  schide_match(device_t, cfdata_t, void *);
     74      1.1  jakllsch static void schide_attach(device_t, device_t, void *);
     75      1.1  jakllsch 
     76      1.1  jakllsch CFATTACH_DECL_NEW(schide, sizeof(struct pciide_softc),
     77  1.7.2.2       tls     schide_match, schide_attach, pciide_detach, NULL);
     78      1.1  jakllsch 
     79      1.1  jakllsch static const struct pciide_product_desc pciide_sch_products[] =  {
     80      1.1  jakllsch 	{ PCI_PRODUCT_INTEL_SCH_IDE,
     81      1.1  jakllsch 	  0,
     82      1.1  jakllsch 	  "Intel SCH IDE Controller",
     83      1.1  jakllsch 	  sch_chip_map,
     84      1.1  jakllsch 	},
     85      1.1  jakllsch 	{ 0,
     86      1.1  jakllsch 	  0,
     87      1.1  jakllsch 	  NULL,
     88      1.1  jakllsch 	  NULL
     89      1.1  jakllsch 	}
     90      1.1  jakllsch };
     91      1.1  jakllsch 
     92      1.1  jakllsch static int
     93      1.1  jakllsch schide_match(device_t parent, cfdata_t match, void *aux)
     94      1.1  jakllsch {
     95      1.1  jakllsch 	struct pci_attach_args *pa = aux;
     96      1.1  jakllsch 
     97      1.1  jakllsch 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
     98      1.1  jakllsch 		if (pciide_lookup_product(pa->pa_id, pciide_sch_products))
     99      1.1  jakllsch 			return (2);
    100      1.1  jakllsch 	}
    101      1.1  jakllsch 	return (0);
    102      1.1  jakllsch }
    103      1.1  jakllsch 
    104      1.1  jakllsch static void
    105      1.1  jakllsch schide_attach(device_t parent, device_t self, void *aux)
    106      1.1  jakllsch {
    107      1.1  jakllsch 	struct pci_attach_args *pa = aux;
    108      1.1  jakllsch 	struct pciide_softc *sc = device_private(self);
    109      1.1  jakllsch 
    110  1.7.2.1    bouyer 	self->dv_maxphys = MIN(parent->dv_maxphys, MACHINE_MAXPHYS);
    111  1.7.2.1    bouyer 
    112      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    113      1.1  jakllsch 
    114      1.1  jakllsch 	pciide_common_attach(sc, pa,
    115      1.1  jakllsch 	    pciide_lookup_product(pa->pa_id, pciide_sch_products));
    116      1.1  jakllsch 
    117      1.1  jakllsch }
    118      1.1  jakllsch 
    119      1.1  jakllsch static void
    120      1.2    dyoung sch_chip_map(struct pciide_softc *sc, const struct pci_attach_args *pa)
    121      1.1  jakllsch {
    122      1.1  jakllsch 	struct pciide_channel *cp;
    123      1.1  jakllsch 	pcireg_t interface;
    124      1.1  jakllsch 	int channel;
    125      1.1  jakllsch 
    126      1.1  jakllsch 	if (pciide_chipen(sc, pa) == 0)
    127      1.1  jakllsch 		return;
    128      1.1  jakllsch 
    129      1.1  jakllsch 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    130      1.1  jakllsch 	    "bus-master DMA support present");
    131      1.1  jakllsch 	pciide_mapreg_dma(sc, pa);
    132      1.1  jakllsch 	aprint_verbose("\n");
    133      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    134      1.1  jakllsch 
    135      1.1  jakllsch 	if (sc->sc_dma_ok) {
    136      1.1  jakllsch 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    137      1.1  jakllsch 		sc->sc_wdcdev.irqack = pciide_irqack;
    138      1.1  jakllsch 	}
    139      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    140      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    141      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
    142      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_set_modes = sch_setup_channel;
    143      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    144      1.1  jakllsch 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    145      1.7    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    146      1.1  jakllsch 
    147      1.1  jakllsch 
    148      1.1  jakllsch 	ATADEBUG_PRINT(("sch_setup_chip: old d0tim=0x%x, d1tim=0x%x\n",
    149      1.1  jakllsch 	    pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D0TIM),
    150      1.1  jakllsch 	    pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D1TIM)),
    151      1.1  jakllsch 	    DEBUG_PROBE);
    152      1.1  jakllsch 
    153      1.1  jakllsch 	interface = PCI_INTERFACE(pa->pa_class);
    154      1.1  jakllsch 
    155      1.1  jakllsch 	wdc_allocate_regs(&sc->sc_wdcdev);
    156      1.1  jakllsch 
    157      1.1  jakllsch 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    158      1.1  jakllsch 	     channel++) {
    159      1.1  jakllsch 		cp = &sc->pciide_channels[channel];
    160      1.1  jakllsch 		if (pciide_chansetup(sc, channel, interface) == 0)
    161      1.1  jakllsch 			continue;
    162      1.1  jakllsch 		pciide_mapchan(pa, cp, interface, pciide_pci_intr);
    163      1.1  jakllsch 	}
    164      1.1  jakllsch 
    165      1.1  jakllsch 	ATADEBUG_PRINT(("sch_setup_chip: d0tim=0x%x, d1tim=0x%x\n",
    166      1.1  jakllsch 	    pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D0TIM),
    167      1.1  jakllsch 	    pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D1TIM)),
    168      1.1  jakllsch 	    DEBUG_PROBE);
    169      1.1  jakllsch }
    170      1.1  jakllsch 
    171      1.1  jakllsch static void
    172      1.1  jakllsch sch_setup_channel(struct ata_channel *chp)
    173      1.1  jakllsch {
    174      1.1  jakllsch 	struct ata_drive_datas *drvp;
    175      1.1  jakllsch 	u_int32_t tim, timaddr, idedma_ctl;
    176      1.1  jakllsch 	struct atac_softc *atac = chp->ch_atac;
    177      1.1  jakllsch 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    178      1.1  jakllsch 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    179      1.1  jakllsch 	int drive, s;
    180      1.1  jakllsch 
    181      1.1  jakllsch 	idedma_ctl = 0;
    182      1.1  jakllsch 
    183      1.1  jakllsch 	/* setup DMA if needed */
    184      1.1  jakllsch 	pciide_channel_dma_setup(cp);
    185      1.1  jakllsch 
    186      1.1  jakllsch 	/* Per drive settings */
    187      1.1  jakllsch 	for (drive = 0; drive < 2; drive++) {
    188      1.1  jakllsch 		drvp = &chp->ch_drive[drive];
    189      1.1  jakllsch 		/* If no drive, skip */
    190      1.7    bouyer 		if (drvp->drive_type == ATA_DRIVET_NONE)
    191      1.1  jakllsch 			continue;
    192      1.1  jakllsch 
    193      1.1  jakllsch 		timaddr = (drive == 0) ? SCH_D0TIM : SCH_D1TIM;
    194      1.1  jakllsch 		tim = pci_conf_read(sc->sc_pc, sc->sc_tag, timaddr);
    195      1.1  jakllsch 		tim &= ~SCH_TIM_MASK;
    196      1.1  jakllsch 
    197      1.7    bouyer 		if (((drvp->drive_flags & ATA_DRIVE_DMA) == 0 &&
    198      1.7    bouyer 		    (drvp->drive_flags & ATA_DRIVE_UDMA) == 0))
    199      1.1  jakllsch 			goto pio;
    200      1.1  jakllsch 
    201      1.1  jakllsch 		/* add timing values, setup DMA if needed */
    202      1.1  jakllsch 		if ((atac->atac_cap & ATAC_CAP_UDMA) &&
    203      1.7    bouyer 		    (drvp->drive_flags & ATA_DRIVE_UDMA)) {
    204      1.1  jakllsch 			/* use Ultra/DMA */
    205      1.1  jakllsch 			tim |= (drvp->UDMA_mode << 16) | SCH_TIM_SYNCDMA;
    206      1.1  jakllsch 		} else {
    207      1.1  jakllsch 			/* use Multiword DMA */
    208      1.1  jakllsch 			s = splbio();
    209      1.7    bouyer 			drvp->drive_flags &= ~ATA_DRIVE_UDMA;
    210      1.1  jakllsch 			splx(s);
    211      1.1  jakllsch 			tim &= ~SCH_TIM_SYNCDMA;
    212      1.1  jakllsch 		}
    213      1.1  jakllsch 		idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    214      1.1  jakllsch 
    215      1.1  jakllsch pio:		/* use PIO mode */
    216      1.1  jakllsch 
    217      1.1  jakllsch 		tim |= (drvp->DMA_mode << 8) | (drvp->PIO_mode);
    218      1.1  jakllsch 		pci_conf_write(sc->sc_pc, sc->sc_tag, timaddr, tim);
    219      1.1  jakllsch 	}
    220      1.1  jakllsch 	if (idedma_ctl != 0) {
    221      1.1  jakllsch 		/* Add software bits in status register */
    222      1.1  jakllsch 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    223      1.1  jakllsch 		    idedma_ctl);
    224      1.1  jakllsch 	}
    225      1.1  jakllsch }
    226