Home | History | Annotate | Line # | Download | only in pci
artsata.c revision 1.21.4.1
      1  1.21.4.1      yamt /*	$NetBSD: artsata.c,v 1.21.4.1 2012/10/30 17:21:22 yamt 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  *
     19       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1   thorpej  */
     31       1.1   thorpej 
     32      1.16       dsl #include <sys/cdefs.h>
     33  1.21.4.1      yamt __KERNEL_RCSID(0, "$NetBSD: artsata.c,v 1.21.4.1 2012/10/30 17:21:22 yamt Exp $");
     34      1.16       dsl 
     35       1.6  rearnsha #include "opt_pciide.h"
     36       1.6  rearnsha 
     37       1.1   thorpej #include <sys/param.h>
     38       1.1   thorpej #include <sys/systm.h>
     39       1.5  rearnsha #include <sys/malloc.h>
     40       1.1   thorpej 
     41       1.1   thorpej #include <dev/pci/pcivar.h>
     42       1.1   thorpej #include <dev/pci/pcidevs.h>
     43       1.1   thorpej #include <dev/pci/pciidereg.h>
     44       1.1   thorpej #include <dev/pci/pciidevar.h>
     45       1.5  rearnsha #include <dev/pci/pciide_i31244_reg.h>
     46       1.5  rearnsha 
     47       1.5  rearnsha #include <dev/ata/satareg.h>
     48       1.5  rearnsha #include <dev/ata/satavar.h>
     49       1.5  rearnsha #include <dev/ata/atareg.h>
     50       1.5  rearnsha #include <dev/ata/atavar.h>
     51       1.1   thorpej 
     52      1.21    dyoung static void artisea_chip_map(struct pciide_softc*,
     53      1.21    dyoung     const struct pci_attach_args *);
     54       1.1   thorpej 
     55      1.17      cube static int  artsata_match(device_t, cfdata_t, void *);
     56      1.17      cube static void artsata_attach(device_t, device_t, void *);
     57       1.1   thorpej 
     58       1.1   thorpej static const struct pciide_product_desc pciide_artsata_products[] =  {
     59       1.1   thorpej 	{ PCI_PRODUCT_INTEL_31244,
     60       1.1   thorpej 	  0,
     61       1.1   thorpej 	  "Intel 31244 Serial ATA Controller",
     62       1.1   thorpej 	  artisea_chip_map,
     63       1.1   thorpej 	},
     64       1.1   thorpej 	{ 0,
     65       1.1   thorpej 	  0,
     66       1.1   thorpej 	  NULL,
     67       1.1   thorpej 	  NULL
     68       1.1   thorpej 	}
     69       1.1   thorpej };
     70       1.1   thorpej 
     71       1.5  rearnsha struct artisea_cmd_map
     72       1.5  rearnsha {
     73       1.5  rearnsha 	u_int8_t offset;
     74       1.5  rearnsha 	u_int8_t size;
     75       1.5  rearnsha };
     76       1.5  rearnsha 
     77       1.5  rearnsha static const struct artisea_cmd_map artisea_dpa_cmd_map[] =
     78       1.7     perry {
     79       1.5  rearnsha 	{ARTISEA_SUPDDR, 4},	/* 0 Data */
     80       1.7     perry 	{ARTISEA_SUPDER, 1},	/* 1 Error */
     81       1.5  rearnsha 	{ARTISEA_SUPDCSR, 2},	/* 2 Sector Count */
     82       1.5  rearnsha 	{ARTISEA_SUPDSNR, 2},	/* 3 Sector Number */
     83       1.5  rearnsha 	{ARTISEA_SUPDCLR, 2},	/* 4 Cylinder Low */
     84       1.5  rearnsha 	{ARTISEA_SUPDCHR, 2},	/* 5 Cylinder High */
     85       1.5  rearnsha 	{ARTISEA_SUPDDHR, 1},	/* 6 Device/Head */
     86       1.5  rearnsha 	{ARTISEA_SUPDCR, 1},	/* 7 Command */
     87       1.5  rearnsha 	{ARTISEA_SUPDSR, 1},	/* 8 Status */
     88       1.5  rearnsha 	{ARTISEA_SUPDFR, 2}	/* 9 Feature */
     89       1.5  rearnsha };
     90       1.5  rearnsha 
     91       1.5  rearnsha #define ARTISEA_NUM_CHAN 4
     92       1.5  rearnsha 
     93      1.17      cube CFATTACH_DECL_NEW(artsata, sizeof(struct pciide_softc),
     94       1.1   thorpej     artsata_match, artsata_attach, NULL, NULL);
     95       1.1   thorpej 
     96       1.1   thorpej static int
     97      1.17      cube artsata_match(device_t parent, cfdata_t match, void *aux)
     98       1.1   thorpej {
     99       1.1   thorpej 	struct pci_attach_args *pa = aux;
    100       1.1   thorpej 
    101       1.1   thorpej 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
    102       1.1   thorpej 		if (pciide_lookup_product(pa->pa_id, pciide_artsata_products))
    103       1.1   thorpej 			return (2);
    104       1.1   thorpej 	}
    105       1.1   thorpej 	return (0);
    106       1.1   thorpej }
    107       1.1   thorpej 
    108       1.1   thorpej static void
    109      1.17      cube artsata_attach(device_t parent, device_t self, void *aux)
    110       1.1   thorpej {
    111       1.1   thorpej 	struct pci_attach_args *pa = aux;
    112      1.17      cube 	struct pciide_softc *sc = device_private(self);
    113      1.17      cube 
    114      1.17      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    115       1.1   thorpej 
    116       1.1   thorpej 	pciide_common_attach(sc, pa,
    117       1.1   thorpej 	    pciide_lookup_product(pa->pa_id, pciide_artsata_products));
    118       1.1   thorpej 
    119       1.1   thorpej }
    120       1.1   thorpej 
    121       1.1   thorpej static void
    122      1.21    dyoung artisea_mapregs(const struct pci_attach_args *pa, struct pciide_channel *cp,
    123      1.12  christos     int (*pci_intr)(void *))
    124       1.5  rearnsha {
    125       1.5  rearnsha 	struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
    126       1.5  rearnsha 	struct ata_channel *wdc_cp = &cp->ata_channel;
    127       1.5  rearnsha 	struct wdc_regs *wdr = CHAN_TO_WDC_REGS(wdc_cp);
    128       1.5  rearnsha 	const char *intrstr;
    129       1.5  rearnsha 	pci_intr_handle_t intrhandle;
    130       1.5  rearnsha 	int i;
    131       1.5  rearnsha 
    132       1.5  rearnsha 	cp->compat = 0;
    133       1.5  rearnsha 
    134       1.5  rearnsha 	if (sc->sc_pci_ih == NULL) {
    135       1.5  rearnsha 		if (pci_intr_map(pa, &intrhandle) != 0) {
    136      1.17      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    137      1.17      cube 			    "couldn't map native-PCI interrupt\n");
    138       1.5  rearnsha 			goto bad;
    139       1.7     perry 		}
    140       1.5  rearnsha 		intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    141       1.5  rearnsha 		sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
    142       1.5  rearnsha 		    intrhandle, IPL_BIO, pci_intr, sc);
    143       1.5  rearnsha 		if (sc->sc_pci_ih != NULL) {
    144      1.17      cube 			aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    145      1.17      cube 			    "using %s for native-PCI interrupt\n",
    146       1.5  rearnsha 			    intrstr ? intrstr : "unknown interrupt");
    147       1.5  rearnsha 		} else {
    148      1.17      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    149      1.17      cube 			    "couldn't establish native-PCI interrupt");
    150       1.5  rearnsha 			if (intrstr != NULL)
    151      1.19     njoly 				aprint_error(" at %s", intrstr);
    152      1.19     njoly 			aprint_error("\n");
    153       1.5  rearnsha 			goto bad;
    154       1.5  rearnsha 		}
    155       1.5  rearnsha 	}
    156       1.5  rearnsha 	cp->ih = sc->sc_pci_ih;
    157       1.5  rearnsha 	wdr->cmd_iot = sc->sc_ba5_st;
    158       1.5  rearnsha 	if (bus_space_subregion (sc->sc_ba5_st, sc->sc_ba5_sh,
    159       1.5  rearnsha 	    ARTISEA_DPA_PORT_BASE(wdc_cp->ch_channel), 0x200,
    160       1.5  rearnsha 	    &wdr->cmd_baseioh) != 0) {
    161      1.17      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    162      1.17      cube 		    "couldn't map %s channel cmd regs\n", cp->name);
    163       1.5  rearnsha 		goto bad;
    164       1.5  rearnsha 	}
    165       1.5  rearnsha 
    166       1.5  rearnsha 	wdr->ctl_iot = sc->sc_ba5_st;
    167       1.5  rearnsha 	if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    168       1.5  rearnsha 	    ARTISEA_SUPDDCTLR, 1, &cp->ctl_baseioh) != 0) {
    169      1.17      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    170      1.17      cube 		    "couldn't map %s channel ctl regs\n", cp->name);
    171       1.5  rearnsha 		goto bad;
    172       1.5  rearnsha 	}
    173       1.5  rearnsha 	wdr->ctl_ioh = cp->ctl_baseioh;
    174       1.5  rearnsha 
    175       1.5  rearnsha 	for (i = 0; i < WDC_NREG + 2; i++) {
    176       1.5  rearnsha 
    177       1.7     perry 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    178       1.5  rearnsha 		    artisea_dpa_cmd_map[i].offset, artisea_dpa_cmd_map[i].size,
    179       1.5  rearnsha 		    &wdr->cmd_iohs[i]) != 0) {
    180      1.17      cube 			aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    181      1.17      cube 			    "couldn't subregion %s channel cmd regs\n",
    182      1.17      cube 			    cp->name);
    183       1.5  rearnsha 			goto bad;
    184       1.5  rearnsha 		}
    185       1.5  rearnsha 	}
    186       1.5  rearnsha 	wdr->data32iot = wdr->cmd_iot;
    187       1.5  rearnsha 	wdr->data32ioh = wdr->cmd_iohs[0];
    188       1.5  rearnsha 
    189      1.13    bouyer 	wdr->sata_iot = wdr->cmd_iot;
    190      1.13    bouyer 	wdr->sata_baseioh = wdr->cmd_baseioh;
    191      1.13    bouyer 
    192      1.13    bouyer 	if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    193      1.13    bouyer 	    ARTISEA_SUPERSET_DPA_OFF + ARTISEA_SUPDSSSR, 1,
    194      1.13    bouyer 	    &wdr->sata_status) != 0) {
    195      1.17      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    196      1.17      cube 		    "couldn't map channel %d sata_status regs\n",
    197      1.13    bouyer 		    wdc_cp->ch_channel);
    198      1.13    bouyer 		goto bad;
    199      1.13    bouyer 	}
    200      1.13    bouyer 	if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    201      1.13    bouyer 	    ARTISEA_SUPERSET_DPA_OFF + ARTISEA_SUPDSSER, 1,
    202      1.13    bouyer 	    &wdr->sata_error) != 0) {
    203      1.17      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    204      1.17      cube 		    "couldn't map channel %d sata_error regs\n",
    205      1.13    bouyer 		    wdc_cp->ch_channel);
    206      1.13    bouyer 		goto bad;
    207      1.13    bouyer 	}
    208      1.13    bouyer 	if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
    209      1.13    bouyer 	    ARTISEA_SUPERSET_DPA_OFF + ARTISEA_SUPDSSCR, 1,
    210      1.13    bouyer 	    &wdr->sata_control) != 0) {
    211      1.17      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    212      1.17      cube 		    "couldn't map channel %d sata_control regs\n",
    213      1.13    bouyer 		    wdc_cp->ch_channel);
    214      1.13    bouyer 		goto bad;
    215      1.13    bouyer 	}
    216      1.13    bouyer 
    217       1.5  rearnsha 	wdcattach(wdc_cp);
    218       1.5  rearnsha 	return;
    219       1.5  rearnsha 
    220       1.5  rearnsha bad:
    221      1.13    bouyer 	wdc_cp->ch_flags |= ATACH_DISABLED;
    222       1.5  rearnsha 	return;
    223       1.5  rearnsha }
    224       1.5  rearnsha 
    225       1.5  rearnsha static int
    226      1.12  christos artisea_chansetup(struct pciide_softc *sc, int channel,
    227      1.14  christos     pcireg_t interface)
    228       1.5  rearnsha {
    229       1.5  rearnsha 	struct pciide_channel *cp = &sc->pciide_channels[channel];
    230       1.5  rearnsha 	sc->wdc_chanarray[channel] = &cp->ata_channel;
    231       1.5  rearnsha 	cp->name = PCIIDE_CHANNEL_NAME(channel);
    232       1.5  rearnsha 	cp->ata_channel.ch_channel = channel;
    233       1.5  rearnsha 	cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    234       1.5  rearnsha 	cp->ata_channel.ch_queue =
    235       1.5  rearnsha 	    malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
    236       1.5  rearnsha 	if (cp->ata_channel.ch_queue == NULL) {
    237       1.5  rearnsha 		aprint_error("%s %s channel: "
    238       1.5  rearnsha 		    "can't allocate memory for command queue",
    239      1.17      cube 		device_xname(sc->sc_wdcdev.sc_atac.atac_dev), cp->name);
    240       1.5  rearnsha 		return 0;
    241       1.5  rearnsha 	}
    242       1.5  rearnsha 	return 1;
    243       1.5  rearnsha }
    244       1.5  rearnsha 
    245       1.5  rearnsha static void
    246      1.21    dyoung artisea_mapreg_dma(struct pciide_softc *sc, const struct pci_attach_args *pa)
    247       1.5  rearnsha {
    248       1.5  rearnsha 	struct pciide_channel *pc;
    249       1.5  rearnsha 	int chan;
    250       1.5  rearnsha 	u_int32_t dma_ctl;
    251       1.5  rearnsha 	u_int32_t cacheline_len;
    252       1.5  rearnsha 
    253      1.17      cube 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    254      1.17      cube 	    "bus-master DMA support present");
    255       1.5  rearnsha 
    256       1.5  rearnsha 	sc->sc_dma_ok = 1;
    257       1.5  rearnsha 
    258       1.5  rearnsha 	/*
    259       1.7     perry 	 * Errata #4 says that if the cacheline length is not set correctly,
    260       1.5  rearnsha 	 * we can get corrupt MWI and Memory-Block-Write transactions.
    261       1.5  rearnsha 	 */
    262       1.5  rearnsha 	cacheline_len = PCI_CACHELINE(pci_conf_read (pa->pa_pc, pa->pa_tag,
    263       1.5  rearnsha 	    PCI_BHLC_REG));
    264       1.5  rearnsha 	if (cacheline_len == 0) {
    265      1.15        ad 		aprint_verbose(", but unused (cacheline size not set in PCI conf)\n");
    266       1.5  rearnsha 		sc->sc_dma_ok = 0;
    267       1.5  rearnsha 		return;
    268       1.5  rearnsha 	}
    269       1.5  rearnsha 
    270       1.5  rearnsha 	/*
    271       1.5  rearnsha 	 * Final step of the work-around is to force the DMA engine to use
    272       1.5  rearnsha 	 * the cache-line length information.
    273       1.5  rearnsha 	 */
    274       1.5  rearnsha 	dma_ctl = pci_conf_read(pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUDCSCR);
    275       1.5  rearnsha 	dma_ctl |= SUDCSCR_DMA_WCAE | SUDCSCR_DMA_RCAE;
    276       1.5  rearnsha 	pci_conf_write(pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUDCSCR, dma_ctl);
    277       1.5  rearnsha 
    278       1.5  rearnsha 	sc->sc_wdcdev.dma_arg = sc;
    279       1.5  rearnsha 	sc->sc_wdcdev.dma_init = pciide_dma_init;
    280       1.5  rearnsha 	sc->sc_wdcdev.dma_start = pciide_dma_start;
    281       1.5  rearnsha 	sc->sc_wdcdev.dma_finish = pciide_dma_finish;
    282       1.5  rearnsha 	sc->sc_dma_iot = sc->sc_ba5_st;
    283       1.5  rearnsha 	sc->sc_dmat = pa->pa_dmat;
    284       1.5  rearnsha 
    285      1.17      cube 	if (device_cfdata(sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
    286       1.5  rearnsha 	    PCIIDE_OPTIONS_NODMA) {
    287      1.15        ad 		aprint_verbose(
    288       1.5  rearnsha 		    ", but unused (forced off by config file)\n");
    289       1.5  rearnsha 		sc->sc_dma_ok = 0;
    290       1.5  rearnsha 		return;
    291       1.5  rearnsha 	}
    292       1.5  rearnsha 
    293       1.5  rearnsha 	/*
    294       1.5  rearnsha 	 * Set up the default handles for the DMA registers.
    295       1.5  rearnsha 	 * Just reserve 32 bits for each handle, unless space
    296       1.5  rearnsha 	 * doesn't permit it.
    297       1.5  rearnsha 	 */
    298       1.5  rearnsha 	for (chan = 0; chan < ARTISEA_NUM_CHAN; chan++) {
    299       1.5  rearnsha 		pc = &sc->pciide_channels[chan];
    300       1.5  rearnsha 		if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    301       1.5  rearnsha 		    ARTISEA_DPA_PORT_BASE(chan) + ARTISEA_SUPDDCMDR, 2,
    302       1.5  rearnsha 		    &pc->dma_iohs[IDEDMA_CMD]) != 0 ||
    303       1.5  rearnsha 		    bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    304       1.5  rearnsha 		    ARTISEA_DPA_PORT_BASE(chan) + ARTISEA_SUPDDSR, 1,
    305       1.5  rearnsha 		    &pc->dma_iohs[IDEDMA_CTL]) != 0 ||
    306       1.5  rearnsha 		    bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
    307       1.5  rearnsha 		    ARTISEA_DPA_PORT_BASE(chan) + ARTISEA_SUPDDDTPR, 4,
    308       1.5  rearnsha 		    &pc->dma_iohs[IDEDMA_TBL]) != 0) {
    309       1.5  rearnsha 			sc->sc_dma_ok = 0;
    310      1.15        ad 			aprint_verbose(", but can't subregion registers\n");
    311       1.5  rearnsha 			return;
    312       1.5  rearnsha 		}
    313       1.5  rearnsha 	}
    314       1.5  rearnsha 
    315      1.15        ad 	aprint_verbose("\n");
    316       1.5  rearnsha }
    317       1.5  rearnsha 
    318       1.5  rearnsha static void
    319      1.21    dyoung artisea_chip_map_dpa(struct pciide_softc *sc, const struct pci_attach_args *pa)
    320       1.5  rearnsha {
    321       1.5  rearnsha 	struct pciide_channel *cp;
    322       1.5  rearnsha 	pcireg_t interface;
    323       1.5  rearnsha 	int channel;
    324       1.5  rearnsha 
    325       1.5  rearnsha 	interface = PCI_INTERFACE(pa->pa_class);
    326       1.5  rearnsha 
    327      1.17      cube 	aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    328      1.17      cube 	    "interface wired in DPA mode\n");
    329       1.5  rearnsha 
    330       1.5  rearnsha 	if (pci_mapreg_map(pa, ARTISEA_PCI_DPA_BASE, PCI_MAPREG_MEM_TYPE_64BIT,
    331      1.20  jakllsch 	    0, &sc->sc_ba5_st, &sc->sc_ba5_sh, NULL, &sc->sc_ba5_ss) != 0)
    332       1.5  rearnsha 		return;
    333       1.5  rearnsha 
    334       1.5  rearnsha 	artisea_mapreg_dma(sc, pa);
    335       1.7     perry 
    336       1.5  rearnsha 	sc->sc_wdcdev.cap = WDC_CAPABILITY_WIDEREGS;
    337       1.5  rearnsha 
    338       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    339       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    340       1.5  rearnsha 	if (sc->sc_dma_ok) {
    341       1.5  rearnsha 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    342       1.5  rearnsha 		sc->sc_wdcdev.irqack = pciide_irqack;
    343       1.5  rearnsha 		sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    344       1.5  rearnsha 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    345       1.5  rearnsha 	}
    346       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    347       1.5  rearnsha 
    348       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    349       1.5  rearnsha 	sc->sc_wdcdev.sc_atac.atac_nchannels = ARTISEA_NUM_CHAN;
    350      1.13    bouyer 	sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
    351  1.21.4.1      yamt 	sc->sc_wdcdev.wdc_maxdrives = 1;
    352       1.5  rearnsha 
    353       1.5  rearnsha 	wdc_allocate_regs(&sc->sc_wdcdev);
    354       1.5  rearnsha 
    355       1.7     perry 	/*
    356       1.5  rearnsha 	 * Perform a quick check to ensure that the device isn't configured
    357       1.5  rearnsha 	 * in Spread-spectrum clocking mode.  This feature is buggy and has
    358       1.5  rearnsha 	 * been removed from the latest documentation.
    359       1.5  rearnsha 	 *
    360       1.5  rearnsha 	 * Note that although this bit is in the Channel regs, it's the same
    361       1.5  rearnsha 	 * for all channels, so we check it just once here.
    362       1.5  rearnsha 	 */
    363       1.5  rearnsha 	if ((bus_space_read_4 (sc->sc_ba5_st, sc->sc_ba5_sh,
    364       1.5  rearnsha 	    ARTISEA_DPA_PORT_BASE(0) + ARTISEA_SUPERSET_DPA_OFF +
    365       1.5  rearnsha 	    ARTISEA_SUPDPFR) & SUPDPFR_SSCEN) != 0) {
    366      1.17      cube 		aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    367      1.17      cube 		    "Spread-specturm clocking not supported by device\n");
    368       1.5  rearnsha 		return;
    369       1.5  rearnsha 	}
    370       1.5  rearnsha 
    371       1.5  rearnsha 	/* Clear the LED0-only bit.  */
    372       1.5  rearnsha 	pci_conf_write (pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUECSR0,
    373       1.5  rearnsha 	    pci_conf_read (pa->pa_pc, pa->pa_tag, ARTISEA_PCI_SUECSR0) &
    374       1.5  rearnsha 	    ~SUECSR0_LED0_ONLY);
    375       1.5  rearnsha 
    376       1.5  rearnsha 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    377       1.5  rearnsha 	     channel++) {
    378       1.5  rearnsha 		cp = &sc->pciide_channels[channel];
    379       1.5  rearnsha 		if (artisea_chansetup(sc, channel, interface) == 0)
    380       1.5  rearnsha 			continue;
    381       1.5  rearnsha 		/* XXX We can probably do interrupts more efficiently.  */
    382      1.20  jakllsch 		artisea_mapregs(pa, cp, pciide_pci_intr);
    383       1.5  rearnsha 	}
    384       1.5  rearnsha }
    385       1.5  rearnsha 
    386       1.5  rearnsha static void
    387      1.21    dyoung artisea_chip_map(struct pciide_softc *sc, const struct pci_attach_args *pa)
    388       1.1   thorpej {
    389       1.1   thorpej 	struct pciide_channel *cp;
    390       1.1   thorpej 	pcireg_t interface;
    391       1.1   thorpej 	int channel;
    392       1.1   thorpej 
    393       1.1   thorpej 	if (pciide_chipen(sc, pa) == 0)
    394       1.1   thorpej 		return;
    395       1.1   thorpej 
    396       1.5  rearnsha 	interface = PCI_INTERFACE(pa->pa_class);
    397       1.5  rearnsha 
    398       1.5  rearnsha 	if (interface == 0) {
    399       1.5  rearnsha 		artisea_chip_map_dpa (sc, pa);
    400       1.5  rearnsha 		return;
    401       1.5  rearnsha 	}
    402       1.5  rearnsha 
    403      1.17      cube 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    404      1.17      cube 	    "bus-master DMA support present");
    405       1.6  rearnsha #ifdef PCIIDE_I31244_DISABLEDMA
    406       1.1   thorpej 	if (sc->sc_pp->ide_product == PCI_PRODUCT_INTEL_31244 &&
    407       1.1   thorpej 	    PCI_REVISION(pa->pa_class) == 0) {
    408      1.15        ad 		aprint_verbose(" but disabled due to rev. 0");
    409       1.1   thorpej 		sc->sc_dma_ok = 0;
    410       1.1   thorpej 	} else
    411       1.1   thorpej #endif
    412       1.1   thorpej 		pciide_mapreg_dma(sc, pa);
    413      1.15        ad 	aprint_verbose("\n");
    414       1.1   thorpej 
    415       1.1   thorpej 	/*
    416       1.1   thorpej 	 * XXX Configure LEDs to show activity.
    417       1.1   thorpej 	 */
    418       1.1   thorpej 
    419       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    420       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    421       1.1   thorpej 	if (sc->sc_dma_ok) {
    422       1.4   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
    423       1.1   thorpej 		sc->sc_wdcdev.irqack = pciide_irqack;
    424       1.4   thorpej 		sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    425       1.4   thorpej 		sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
    426       1.1   thorpej 	}
    427       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
    428       1.1   thorpej 
    429       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    430       1.4   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    431       1.1   thorpej 
    432       1.3   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    433       1.3   thorpej 
    434       1.4   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    435       1.4   thorpej 	     channel++) {
    436       1.1   thorpej 		cp = &sc->pciide_channels[channel];
    437       1.1   thorpej 		if (pciide_chansetup(sc, channel, interface) == 0)
    438       1.1   thorpej 			continue;
    439      1.20  jakllsch 		pciide_mapchan(pa, cp, interface, pciide_pci_intr);
    440       1.1   thorpej 	}
    441       1.1   thorpej }
    442