Home | History | Annotate | Line # | Download | only in pci
artsata.c revision 1.10.4.1
      1  1.10.4.1   gdamore /*	$NetBSD: artsata.c,v 1.10.4.1 2006/07/13 17:49:26 gdamore Exp $	*/
      2       1.1   thorpej 
      3       1.1   thorpej /*-
      4       1.1   thorpej  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5       1.1   thorpej  * All rights reserved.
      6       1.1   thorpej  *
      7       1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   thorpej  * by Jason R. Thorpe of Wasabi Systems, Inc.
      9       1.1   thorpej  *
     10       1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11       1.1   thorpej  * modification, are permitted provided that the following conditions
     12       1.1   thorpej  * are met:
     13       1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14       1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15       1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18       1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     19       1.1   thorpej  *    must display the following acknowledgement:
     20       1.1   thorpej  *	This product includes software developed by the NetBSD
     21       1.1   thorpej  *	Foundation, Inc. and its contributors.
     22       1.1   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1   thorpej  *    contributors may be used to endorse or promote products derived
     24       1.1   thorpej  *    from this software without specific prior written permission.
     25       1.1   thorpej  *
     26       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   thorpej  */
     38       1.1   thorpej 
     39       1.6  rearnsha #include "opt_pciide.h"
     40       1.6  rearnsha 
     41  1.10.4.1   gdamore #include <sys/cdefs.h>
     42  1.10.4.1   gdamore __KERNEL_RCSID(0, "$NetBSD: artsata.c,v 1.10.4.1 2006/07/13 17:49:26 gdamore Exp $");
     43  1.10.4.1   gdamore 
     44       1.1   thorpej #include <sys/param.h>
     45       1.1   thorpej #include <sys/systm.h>
     46       1.5  rearnsha #include <sys/malloc.h>
     47       1.1   thorpej 
     48       1.1   thorpej #include <dev/pci/pcivar.h>
     49       1.1   thorpej #include <dev/pci/pcidevs.h>
     50       1.1   thorpej #include <dev/pci/pciidereg.h>
     51       1.1   thorpej #include <dev/pci/pciidevar.h>
     52       1.5  rearnsha #include <dev/pci/pciide_i31244_reg.h>
     53       1.5  rearnsha 
     54       1.5  rearnsha #include <dev/ata/satareg.h>
     55       1.5  rearnsha #include <dev/ata/satavar.h>
     56       1.5  rearnsha #include <dev/ata/atareg.h>
     57       1.5  rearnsha #include <dev/ata/atavar.h>
     58       1.1   thorpej 
     59       1.1   thorpej static void artisea_chip_map(struct pciide_softc*, struct pci_attach_args *);
     60       1.1   thorpej 
     61       1.1   thorpej static int  artsata_match(struct device *, struct cfdata *, void *);
     62       1.1   thorpej static void artsata_attach(struct device *, struct device *, void *);
     63       1.1   thorpej 
     64       1.1   thorpej static const struct pciide_product_desc pciide_artsata_products[] =  {
     65       1.1   thorpej 	{ PCI_PRODUCT_INTEL_31244,
     66       1.1   thorpej 	  0,
     67       1.1   thorpej 	  "Intel 31244 Serial ATA Controller",
     68       1.1   thorpej 	  artisea_chip_map,
     69       1.1   thorpej 	},
     70       1.1   thorpej 	{ 0,
     71       1.1   thorpej 	  0,
     72       1.1   thorpej 	  NULL,
     73       1.1   thorpej 	  NULL
     74       1.1   thorpej 	}
     75       1.1   thorpej };
     76       1.1   thorpej 
     77       1.5  rearnsha struct artisea_cmd_map
     78       1.5  rearnsha {
     79       1.5  rearnsha 	u_int8_t offset;
     80       1.5  rearnsha 	u_int8_t size;
     81       1.5  rearnsha };
     82       1.5  rearnsha 
     83       1.5  rearnsha static const struct artisea_cmd_map artisea_dpa_cmd_map[] =
     84       1.7     perry {
     85       1.5  rearnsha 	{ARTISEA_SUPDDR, 4},	/* 0 Data */
     86       1.7     perry 	{ARTISEA_SUPDER, 1},	/* 1 Error */
     87       1.5  rearnsha 	{ARTISEA_SUPDCSR, 2},	/* 2 Sector Count */
     88       1.5  rearnsha 	{ARTISEA_SUPDSNR, 2},	/* 3 Sector Number */
     89       1.5  rearnsha 	{ARTISEA_SUPDCLR, 2},	/* 4 Cylinder Low */
     90       1.5  rearnsha 	{ARTISEA_SUPDCHR, 2},	/* 5 Cylinder High */
     91       1.5  rearnsha 	{ARTISEA_SUPDDHR, 1},	/* 6 Device/Head */
     92       1.5  rearnsha 	{ARTISEA_SUPDCR, 1},	/* 7 Command */
     93       1.5  rearnsha 	{ARTISEA_SUPDSR, 1},	/* 8 Status */
     94       1.5  rearnsha 	{ARTISEA_SUPDFR, 2}	/* 9 Feature */
     95       1.5  rearnsha };
     96       1.5  rearnsha 
     97       1.5  rearnsha #define ARTISEA_NUM_CHAN 4
     98       1.5  rearnsha 
     99       1.1   thorpej CFATTACH_DECL(artsata, sizeof(struct pciide_softc),
    100       1.1   thorpej     artsata_match, artsata_attach, NULL, NULL);
    101       1.1   thorpej 
    102       1.1   thorpej static int
    103       1.1   thorpej artsata_match(struct device *parent, struct cfdata *match, void *aux)
    104       1.1   thorpej {
    105       1.1   thorpej 	struct pci_attach_args *pa = aux;
    106       1.1   thorpej 
    107       1.1   thorpej 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
    108       1.1   thorpej 		if (pciide_lookup_product(pa->pa_id, pciide_artsata_products))
    109       1.1   thorpej 			return (2);
    110       1.1   thorpej 	}
    111       1.1   thorpej 	return (0);
    112       1.1   thorpej }
    113       1.1   thorpej 
    114       1.1   thorpej static void
    115       1.1   thorpej artsata_attach(struct device *parent, struct device *self, void *aux)
    116       1.1   thorpej {
    117       1.1   thorpej 	struct pci_attach_args *pa = aux;
    118       1.1   thorpej 	struct pciide_softc *sc = (struct pciide_softc *)self;
    119       1.1   thorpej 
    120       1.1   thorpej 	pciide_common_attach(sc, pa,
    121       1.1   thorpej 	    pciide_lookup_product(pa->pa_id, pciide_artsata_products));
    122       1.1   thorpej 
    123       1.1   thorpej }
    124       1.1   thorpej 
    125       1.1   thorpej static void
    126       1.5  rearnsha artisea_drv_probe(struct ata_channel *chp)
    127       1.5  rearnsha {
    128       1.5  rearnsha 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    129       1.5  rearnsha 	struct wdc_regs *wdr = CHAN_TO_WDC_REGS(chp);
    130       1.5  rearnsha 	uint32_t scontrol, sstatus;
    131       1.5  rearnsha 	uint16_t scnt, sn, cl, ch;
    132       1.5  rearnsha 	int i, s;
    133       1.5  rearnsha 
    134       1.5  rearnsha 	/* XXX This should be done by other code. */
    135       1.5  rearnsha 	for (i = 0; i < 2; i++) {
    136       1.5  rearnsha 		chp->ch_drive[i].chnl_softc = chp;
    137       1.5  rearnsha 		chp->ch_drive[i].drive = i;
    138       1.5  rearnsha 	}
    139       1.5  rearnsha 
    140       1.5  rearnsha 	/*
    141       1.5  rearnsha 	 * First we have to bring the PHYs online, in case the firmware
    142       1.5  rearnsha 	 * has not already done so.  The 31244 leaves the disks off-line
    143       1.5  rearnsha 	 * on reset to avoid excessive power surges due to multiple spindle
    144       1.5  rearnsha 	 * spin up.
    145       1.5  rearnsha 	 *
    146       1.5  rearnsha 	 * The work-around for errata #1 says that we must write 0 to the
    147       1.5  rearnsha 	 * port first to be sure of correctly initializing the device.
    148       1.5  rearnsha 	 *
    149       1.5  rearnsha 	 * XXX will this try to bring multiple disks on-line too quickly?
    150       1.5  rearnsha 	 */
    151       1.5  rearnsha 	bus_space_write_4 (wdr->cmd_iot, wdr->cmd_baseioh,
    152       1.5  rearnsha 	    ARTISEA_SUPERSET_DPA_OFF + ARTISEA_SUPDSSCR, 0);
    153       1.5  rearnsha 	scontrol = SControl_IPM_NONE | SControl_SPD_ANY | SControl_DET_INIT;
    154       1.5  rearnsha 	bus_space_write_4 (wdr->cmd_iot, wdr->cmd_baseioh,
    155       1.5  rearnsha 	    ARTISEA_SUPERSET_DPA_OFF + ARTISEA_SUPDSSCR, scontrol);
    156       1.5  rearnsha 
    157       1.5  rearnsha 	scontrol &= ~SControl_DET_INIT;
    158       1.5  rearnsha 	bus_space_write_4 (wdr->cmd_iot, wdr->cmd_baseioh,
    159       1.5  rearnsha 	    ARTISEA_SUPERSET_DPA_OFF + ARTISEA_SUPDSSCR, scontrol);
    160       1.5  rearnsha 
    161       1.5  rearnsha 	delay(50 * 1000);
    162       1.5  rearnsha 	sstatus = bus_space_read_4(wdr->cmd_iot, wdr->cmd_baseioh,
    163       1.5  rearnsha 	    ARTISEA_SUPERSET_DPA_OFF + ARTISEA_SUPDSSSR);
    164       1.5  rearnsha 
    165       1.5  rearnsha 	switch (sstatus & SStatus_DET_mask) {
    166       1.5  rearnsha 	case SStatus_DET_NODEV:
    167       1.5  rearnsha 		/* No Device; be silent.  */
    168       1.5  rearnsha 		break;
    169       1.5  rearnsha 
    170       1.5  rearnsha 	case SStatus_DET_DEV_NE:
    171       1.5  rearnsha 		aprint_error("%s: port %d: device connected, but "
    172       1.5  rearnsha 		    "communication not established\n",
    173       1.5  rearnsha 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel);
    174       1.5  rearnsha 		break;
    175       1.5  rearnsha 
    176       1.5  rearnsha 	case SStatus_DET_OFFLINE:
    177       1.5  rearnsha 		aprint_error("%s: port %d: PHY offline\n",
    178       1.5  rearnsha 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel);
    179       1.5  rearnsha 		break;
    180       1.5  rearnsha 
    181       1.5  rearnsha 	case SStatus_DET_DEV:
    182       1.5  rearnsha 		bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], 0,
    183       1.5  rearnsha 		    WDSD_IBM);
    184       1.5  rearnsha 		delay(10);	/* 400ns delay */
    185       1.5  rearnsha 		scnt = bus_space_read_2(wdr->cmd_iot,
    186       1.5  rearnsha 		    wdr->cmd_iohs[wd_seccnt], 0);
    187       1.5  rearnsha 		sn = bus_space_read_2(wdr->cmd_iot,
    188       1.5  rearnsha 		    wdr->cmd_iohs[wd_sector], 0);
    189       1.5  rearnsha 		cl = bus_space_read_2(wdr->cmd_iot,
    190       1.5  rearnsha 		    wdr->cmd_iohs[wd_cyl_lo], 0);
    191       1.5  rearnsha 		ch = bus_space_read_2(wdr->cmd_iot,
    192       1.5  rearnsha 		    wdr->cmd_iohs[wd_cyl_hi], 0);
    193       1.5  rearnsha 		printf("%s: port %d: scnt=0x%x sn=0x%x cl=0x%x ch=0x%x\n",
    194       1.5  rearnsha 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel,
    195       1.5  rearnsha 		    scnt, sn, cl, ch);
    196       1.5  rearnsha 		/*
    197       1.5  rearnsha 		 * scnt and sn are supposed to be 0x1 for ATAPI, but in some
    198       1.5  rearnsha 		 * cases we get wrong values here, so ignore it.
    199       1.5  rearnsha 		 */
    200       1.5  rearnsha 		s = splbio();
    201       1.5  rearnsha 		if (cl == 0x14 && ch == 0xeb)
    202       1.5  rearnsha 			chp->ch_drive[0].drive_flags |= DRIVE_ATAPI;
    203       1.5  rearnsha 		else
    204       1.5  rearnsha 			chp->ch_drive[0].drive_flags |= DRIVE_ATA;
    205       1.5  rearnsha 		splx(s);
    206       1.5  rearnsha 
    207       1.5  rearnsha 		aprint_normal("%s: port %d: device present, speed: %s\n",
    208       1.5  rearnsha 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel,
    209       1.5  rearnsha 		    sata_speed(sstatus));
    210       1.5  rearnsha 		break;
    211       1.5  rearnsha 
    212       1.5  rearnsha 	default:
    213       1.5  rearnsha 		aprint_error("%s: port %d: unknown SStatus: 0x%08x\n",
    214       1.5  rearnsha 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel,
    215       1.5  rearnsha 		    sstatus);
    216       1.5  rearnsha 	}
    217       1.5  rearnsha 
    218       1.5  rearnsha }
    219       1.5  rearnsha 
    220       1.5  rearnsha static void
    221       1.5  rearnsha artisea_mapregs(struct pci_attach_args *pa, struct pciide_channel *cp,
    222       1.5  rearnsha 	bus_size_t *cmdsizep, bus_size_t *ctlsizep, int (*pci_intr)(void *))
    223       1.5  rearnsha {
    224       1.5  rearnsha 	struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    225       1.5  rearnsha 	struct ata_channel *wdc_cp = &cp->ata_channel;
    226       1.5  rearnsha 	struct wdc_regs *wdr = CHAN_TO_WDC_REGS(wdc_cp);
    227       1.5  rearnsha 	const char *intrstr;
    228       1.5  rearnsha 	pci_intr_handle_t intrhandle;
    229       1.5  rearnsha 	int i;
    230       1.5  rearnsha 
    231       1.5  rearnsha 	cp->compat = 0;
    232       1.5  rearnsha 
    233       1.5  rearnsha 	if (sc->sc_pci_ih == NULL) {
    234       1.5  rearnsha 		if (pci_intr_map(pa, &intrhandle) != 0) {
    235       1.5  rearnsha 			aprint_error("%s: couldn't map native-PCI interrupt\n",
    236       1.5  rearnsha 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    237       1.5  rearnsha 			goto bad;
    238       1.7     perry 		}
    239       1.5  rearnsha 		intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    240       1.5  rearnsha 		sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    241       1.5  rearnsha 		    intrhandle, IPL_BIO, pci_intr, sc);
    242       1.5  rearnsha 		if (sc->sc_pci_ih != NULL) {
    243       1.5  rearnsha 			aprint_normal("%s: using %s for native-PCI interrupt\n",
    244       1.5  rearnsha 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
    245       1.5  rearnsha 			    intrstr ? intrstr : "unknown interrupt");
    246       1.5  rearnsha 		} else {
    247       1.5  rearnsha 			aprint_error(
    248       1.5  rearnsha 			    "%s: couldn't establish native-PCI interrupt",
    249       1.5  rearnsha 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    250       1.5  rearnsha 			if (intrstr != NULL)
    251       1.5  rearnsha 				aprint_normal(" at %s", intrstr);
    252       1.5  rearnsha 			aprint_normal("\n");
    253       1.5  rearnsha 			goto bad;
    254       1.5  rearnsha 		}
    255       1.5  rearnsha 	}
    256       1.5  rearnsha 	cp->ih = sc->sc_pci_ih;
    257       1.5  rearnsha 	wdr->cmd_iot = sc->sc_ba5_st;
    258       1.5  rearnsha 	if (bus_space_subregion (sc->sc_ba5_st, sc->sc_ba5_sh,
    259       1.5  rearnsha 	    ARTISEA_DPA_PORT_BASE(wdc_cp->ch_channel), 0x200,
    260       1.5  rearnsha 	    &wdr->cmd_baseioh) != 0) {
    261       1.5  rearnsha 		aprint_error("%s: couldn't map %s channel cmd regs\n",
    262       1.5  rearnsha 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    263       1.5  rearnsha 		goto bad;
    264       1.5  rearnsha 	}
    265       1.5  rearnsha 
    266       1.5  rearnsha 	wdr->ctl_iot = sc->sc_ba5_st;
    267       1.5  rearnsha 	if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    268       1.5  rearnsha 	    ARTISEA_SUPDDCTLR, 1, &cp->ctl_baseioh) != 0) {
    269       1.5  rearnsha 		aprint_error("%s: couldn't map %s channel ctl regs\n",
    270       1.5  rearnsha 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    271       1.5  rearnsha 		goto bad;
    272       1.5  rearnsha 	}
    273       1.5  rearnsha 	wdr->ctl_ioh = cp->ctl_baseioh;
    274       1.5  rearnsha 
    275       1.5  rearnsha 	for (i = 0; i < WDC_NREG + 2; i++) {
    276       1.5  rearnsha 
    277       1.7     perry 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    278       1.5  rearnsha 		    artisea_dpa_cmd_map[i].offset, artisea_dpa_cmd_map[i].size,
    279       1.5  rearnsha 		    &wdr->cmd_iohs[i]) != 0) {
    280       1.5  rearnsha 			aprint_error("%s: couldn't subregion %s channel "
    281       1.5  rearnsha 				     "cmd regs\n",
    282       1.5  rearnsha 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    283       1.5  rearnsha 			goto bad;
    284       1.5  rearnsha 		}
    285       1.5  rearnsha 	}
    286       1.5  rearnsha 	wdr->data32iot = wdr->cmd_iot;
    287       1.5  rearnsha 	wdr->data32ioh = wdr->cmd_iohs[0];
    288       1.5  rearnsha 
    289       1.5  rearnsha 	wdcattach(wdc_cp);
    290       1.5  rearnsha 	return;
    291       1.5  rearnsha 
    292       1.5  rearnsha bad:
    293       1.5  rearnsha 	cp->ata_channel.ch_flags |= ATACH_DISABLED;
    294       1.5  rearnsha 	return;
    295       1.5  rearnsha }
    296       1.5  rearnsha 
    297       1.5  rearnsha static int
    298       1.5  rearnsha artisea_chansetup(struct pciide_softc *sc, int channel, pcireg_t interface)
    299       1.5  rearnsha {
    300       1.5  rearnsha 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    301       1.5  rearnsha 	sc->wdc_chanarray[channel] = &cp->ata_channel;
    302       1.5  rearnsha 	cp->name = PCIIDE_CHANNEL_NAME(channel);
    303       1.5  rearnsha 	cp->ata_channel.ch_channel = channel;
    304       1.5  rearnsha 	cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    305       1.5  rearnsha 	cp->ata_channel.ch_queue =
    306       1.5  rearnsha 	    malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
    307       1.9    bouyer 	cp->ata_channel.ch_ndrive = 2;
    308       1.5  rearnsha 	if (cp->ata_channel.ch_queue == NULL) {
    309       1.5  rearnsha 		aprint_error("%s %s channel: "
    310       1.5  rearnsha 		    "can't allocate memory for command queue",
    311       1.5  rearnsha 		sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, cp->name);
    312       1.5  rearnsha 		return 0;
    313       1.5  rearnsha 	}
    314       1.5  rearnsha 	return 1;
    315       1.5  rearnsha }
    316       1.5  rearnsha 
    317       1.5  rearnsha static void
    318       1.5  rearnsha artisea_mapreg_dma(struct pciide_softc *sc, struct pci_attach_args *pa)
    319       1.5  rearnsha {
    320       1.5  rearnsha 	struct pciide_channel *pc;
    321       1.5  rearnsha 	int chan;
    322       1.5  rearnsha 	u_int32_t dma_ctl;
    323       1.5  rearnsha 	u_int32_t cacheline_len;
    324       1.5  rearnsha 
    325       1.5  rearnsha 	aprint_normal("%s: bus-master DMA support present",
    326       1.5  rearnsha 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    327       1.5  rearnsha 
    328       1.5  rearnsha 	sc->sc_dma_ok = 1;
    329       1.5  rearnsha 
    330       1.5  rearnsha 	/*
    331       1.7     perry 	 * Errata #4 says that if the cacheline length is not set correctly,
    332       1.5  rearnsha 	 * we can get corrupt MWI and Memory-Block-Write transactions.
    333       1.5  rearnsha 	 */
    334       1.5  rearnsha 	cacheline_len = PCI_CACHELINE(pci_conf_read (pa->pa_pc, pa->pa_tag,
    335       1.5  rearnsha 	    PCI_BHLC_REG));
    336       1.5  rearnsha 	if (cacheline_len == 0) {
    337       1.5  rearnsha 		aprint_normal(", but unused (cacheline size not set in PCI conf)\n");
    338       1.5  rearnsha 		sc->sc_dma_ok = 0;
    339       1.5  rearnsha 		return;
    340       1.5  rearnsha 	}
    341       1.5  rearnsha 
    342       1.5  rearnsha 	/*
    343       1.5  rearnsha 	 * Final step of the work-around is to force the DMA engine to use
    344       1.5  rearnsha 	 * the cache-line length information.
    345       1.5  rearnsha 	 */
    346       1.5  rearnsha 	dma_ctl = pci_conf_read(pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUDCSCR);
    347       1.5  rearnsha 	dma_ctl |= SUDCSCR_DMA_WCAE | SUDCSCR_DMA_RCAE;
    348       1.5  rearnsha 	pci_conf_write(pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUDCSCR, dma_ctl);
    349       1.5  rearnsha 
    350       1.5  rearnsha 	sc->sc_wdcdev.dma_arg = sc;
    351       1.5  rearnsha 	sc->sc_wdcdev.dma_init = pciide_dma_init;
    352       1.5  rearnsha 	sc->sc_wdcdev.dma_start = pciide_dma_start;
    353       1.5  rearnsha 	sc->sc_wdcdev.dma_finish = pciide_dma_finish;
    354       1.5  rearnsha 	sc->sc_dma_iot = sc->sc_ba5_st;
    355       1.5  rearnsha 	sc->sc_dmat = pa->pa_dmat;
    356       1.5  rearnsha 
    357      1.10   thorpej 	if (device_cfdata(&sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
    358       1.5  rearnsha 	    PCIIDE_OPTIONS_NODMA) {
    359       1.5  rearnsha 		aprint_normal(
    360       1.5  rearnsha 		    ", but unused (forced off by config file)\n");
    361       1.5  rearnsha 		sc->sc_dma_ok = 0;
    362       1.5  rearnsha 		return;
    363       1.5  rearnsha 	}
    364       1.5  rearnsha 
    365       1.5  rearnsha 	/*
    366       1.5  rearnsha 	 * Set up the default handles for the DMA registers.
    367       1.5  rearnsha 	 * Just reserve 32 bits for each handle, unless space
    368       1.5  rearnsha 	 * doesn't permit it.
    369       1.5  rearnsha 	 */
    370       1.5  rearnsha 	for (chan = 0; chan < ARTISEA_NUM_CHAN; chan++) {
    371       1.5  rearnsha 		pc = &sc->pciide_channels[chan];
    372       1.5  rearnsha 		if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    373       1.5  rearnsha 		    ARTISEA_DPA_PORT_BASE(chan) + ARTISEA_SUPDDCMDR, 2,
    374       1.5  rearnsha 		    &pc->dma_iohs[IDEDMA_CMD]) != 0 ||
    375       1.5  rearnsha 		    bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    376       1.5  rearnsha 		    ARTISEA_DPA_PORT_BASE(chan) + ARTISEA_SUPDDSR, 1,
    377       1.5  rearnsha 		    &pc->dma_iohs[IDEDMA_CTL]) != 0 ||
    378       1.5  rearnsha 		    bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    379       1.5  rearnsha 		    ARTISEA_DPA_PORT_BASE(chan) + ARTISEA_SUPDDDTPR, 4,
    380       1.5  rearnsha 		    &pc->dma_iohs[IDEDMA_TBL]) != 0) {
    381       1.5  rearnsha 			sc->sc_dma_ok = 0;
    382       1.5  rearnsha 			aprint_normal(", but can't subregion registers\n");
    383       1.5  rearnsha 			return;
    384       1.5  rearnsha 		}
    385       1.5  rearnsha 	}
    386       1.5  rearnsha 
    387       1.5  rearnsha 	aprint_normal("\n");
    388       1.5  rearnsha }
    389       1.5  rearnsha 
    390       1.5  rearnsha static void
    391       1.5  rearnsha artisea_chip_map_dpa(struct pciide_softc *sc, struct pci_attach_args *pa)
    392       1.5  rearnsha {
    393       1.5  rearnsha 	struct pciide_channel *cp;
    394       1.5  rearnsha 	bus_size_t cmdsize, ctlsize;
    395       1.5  rearnsha 	pcireg_t interface;
    396       1.5  rearnsha 	int channel;
    397       1.5  rearnsha 
    398       1.5  rearnsha 	interface = PCI_INTERFACE(pa->pa_class);
    399       1.5  rearnsha 
    400       1.5  rearnsha 	aprint_normal("%s: interface wired in DPA mode\n",
    401       1.5  rearnsha 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    402       1.5  rearnsha 
    403       1.5  rearnsha 	if (pci_mapreg_map(pa, ARTISEA_PCI_DPA_BASE, PCI_MAPREG_MEM_TYPE_64BIT,
    404       1.5  rearnsha 	    0, &sc->sc_ba5_st, &sc->sc_ba5_sh, NULL, NULL) != 0)
    405       1.5  rearnsha 		return;
    406       1.5  rearnsha 
    407       1.5  rearnsha 	artisea_mapreg_dma(sc, pa);
    408       1.7     perry 
    409       1.5  rearnsha 	sc->sc_wdcdev.cap = WDC_CAPABILITY_WIDEREGS;
    410       1.5  rearnsha 
    411       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    412       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    413       1.5  rearnsha 	if (sc->sc_dma_ok) {
    414       1.5  rearnsha 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    415       1.5  rearnsha 		sc->sc_wdcdev.irqack = pciide_irqack;
    416       1.5  rearnsha 		sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    417       1.5  rearnsha 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    418       1.5  rearnsha 	}
    419       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    420       1.5  rearnsha 
    421       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    422       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_nchannels = ARTISEA_NUM_CHAN;
    423       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_probe = artisea_drv_probe;
    424       1.5  rearnsha 
    425       1.5  rearnsha 	wdc_allocate_regs(&sc->sc_wdcdev);
    426       1.5  rearnsha 
    427       1.7     perry 	/*
    428       1.5  rearnsha 	 * Perform a quick check to ensure that the device isn't configured
    429       1.5  rearnsha 	 * in Spread-spectrum clocking mode.  This feature is buggy and has
    430       1.5  rearnsha 	 * been removed from the latest documentation.
    431       1.5  rearnsha 	 *
    432       1.5  rearnsha 	 * Note that although this bit is in the Channel regs, it's the same
    433       1.5  rearnsha 	 * for all channels, so we check it just once here.
    434       1.5  rearnsha 	 */
    435       1.5  rearnsha 	if ((bus_space_read_4 (sc->sc_ba5_st, sc->sc_ba5_sh,
    436       1.5  rearnsha 	    ARTISEA_DPA_PORT_BASE(0) + ARTISEA_SUPERSET_DPA_OFF +
    437       1.5  rearnsha 	    ARTISEA_SUPDPFR) & SUPDPFR_SSCEN) != 0) {
    438       1.5  rearnsha 		aprint_error("%s: Spread-specturm clocking not supported by device\n",
    439       1.5  rearnsha 		     sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    440       1.5  rearnsha 		return;
    441       1.5  rearnsha 	}
    442       1.5  rearnsha 
    443       1.5  rearnsha 	/* Clear the LED0-only bit.  */
    444       1.5  rearnsha 	pci_conf_write (pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUECSR0,
    445       1.5  rearnsha 	    pci_conf_read (pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUECSR0) &
    446       1.5  rearnsha 	    ~SUECSR0_LED0_ONLY);
    447       1.5  rearnsha 
    448       1.5  rearnsha 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    449       1.5  rearnsha 	     channel++) {
    450       1.5  rearnsha 		cp = &sc->pciide_channels[channel];
    451       1.5  rearnsha 		if (artisea_chansetup(sc, channel, interface) == 0)
    452       1.5  rearnsha 			continue;
    453       1.5  rearnsha 		/* XXX We can probably do interrupts more efficiently.  */
    454       1.5  rearnsha 		artisea_mapregs(pa, cp, &cmdsize, &ctlsize, pciide_pci_intr);
    455       1.5  rearnsha 	}
    456       1.5  rearnsha }
    457       1.5  rearnsha 
    458       1.5  rearnsha static void
    459       1.1   thorpej artisea_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    460       1.1   thorpej {
    461       1.1   thorpej 	struct pciide_channel *cp;
    462       1.1   thorpej 	bus_size_t cmdsize, ctlsize;
    463       1.1   thorpej 	pcireg_t interface;
    464       1.1   thorpej 	int channel;
    465       1.1   thorpej 
    466       1.1   thorpej 	if (pciide_chipen(sc, pa) == 0)
    467       1.1   thorpej 		return;
    468       1.1   thorpej 
    469       1.5  rearnsha 	interface = PCI_INTERFACE(pa->pa_class);
    470       1.5  rearnsha 
    471       1.5  rearnsha 	if (interface == 0) {
    472       1.5  rearnsha 		artisea_chip_map_dpa (sc, pa);
    473       1.5  rearnsha 		return;
    474       1.5  rearnsha 	}
    475       1.5  rearnsha 
    476       1.1   thorpej 	aprint_normal("%s: bus-master DMA support present",
    477       1.4   thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    478       1.6  rearnsha #ifdef PCIIDE_I31244_DISABLEDMA
    479       1.1   thorpej 	if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_31244 &&
    480       1.1   thorpej 	    PCI_REVISION(pa->pa_class) == 0) {
    481       1.1   thorpej 		aprint_normal(" but disabled due to rev. 0");
    482       1.1   thorpej 		sc->sc_dma_ok = 0;
    483       1.1   thorpej 	} else
    484       1.1   thorpej #endif
    485       1.1   thorpej 		pciide_mapreg_dma(sc, pa);
    486       1.1   thorpej 	aprint_normal("\n");
    487       1.1   thorpej 
    488       1.1   thorpej 	/*
    489       1.1   thorpej 	 * XXX Configure LEDs to show activity.
    490       1.1   thorpej 	 */
    491       1.1   thorpej 
    492       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    493       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    494       1.1   thorpej 	if (sc->sc_dma_ok) {
    495       1.4   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    496       1.1   thorpej 		sc->sc_wdcdev.irqack = pciide_irqack;
    497       1.4   thorpej 		sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    498       1.4   thorpej 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    499       1.1   thorpej 	}
    500       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    501       1.1   thorpej 
    502       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    503       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    504       1.1   thorpej 
    505       1.3   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    506       1.3   thorpej 
    507       1.4   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    508       1.4   thorpej 	     channel++) {
    509       1.1   thorpej 		cp = &sc->pciide_channels[channel];
    510       1.1   thorpej 		if (pciide_chansetup(sc, channel, interface) == 0)
    511       1.1   thorpej 			continue;
    512       1.1   thorpej 		pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
    513       1.1   thorpej 		    pciide_pci_intr);
    514       1.1   thorpej 	}
    515       1.1   thorpej }
    516