2010-11-17 22:36:54 +03:00
|
|
|
/* $NetBSD: pciide_common.c,v 1.48 2010/11/17 19:36:54 dholland Exp $ */
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1999, 2000, 2001, 2003 Manuel Bouyer.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
2005-02-27 03:26:58 +03:00
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
2003-10-08 15:51:59 +04:00
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 1998 Christopher G. Demetriou. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Christopher G. Demetriou
|
|
|
|
* for the NetBSD Project.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI IDE controller driver.
|
|
|
|
*
|
|
|
|
* Author: Christopher G. Demetriou, March 2, 1998 (derived from NetBSD
|
|
|
|
* sys/dev/pci/ppb.c, revision 1.16).
|
|
|
|
*
|
|
|
|
* See "PCI IDE Controller Specification, Revision 1.0 3/4/94" and
|
|
|
|
* "Programming Interface for Bus Master IDE Controller, Revision 1.0
|
|
|
|
* 5/16/94" from the PCI SIG.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2010-11-17 22:36:54 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: pciide_common.c,v 1.48 2010/11/17 19:36:54 dholland Exp $");
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
#include <dev/pci/pciidereg.h>
|
|
|
|
#include <dev/pci/pciidevar.h>
|
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
#include <dev/ic/wdcreg.h>
|
|
|
|
|
2004-08-13 08:10:49 +04:00
|
|
|
#ifdef ATADEBUG
|
|
|
|
int atadebug_pciide_mask = 0;
|
2003-10-08 15:51:59 +04:00
|
|
|
#endif
|
|
|
|
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2005-02-27 03:26:58 +03:00
|
|
|
static const char dmaerrfmt[] =
|
2003-10-08 15:51:59 +04:00
|
|
|
"%s:%d: unable to %s table DMA map for drive %d, error=%d\n";
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
/* Default product description for devices not known from this controller */
|
|
|
|
const struct pciide_product_desc default_product_desc = {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"Generic PCI IDE controller",
|
|
|
|
default_chip_map,
|
2005-02-27 03:26:58 +03:00
|
|
|
};
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
const struct pciide_product_desc *
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_lookup_product(pcireg_t id, const struct pciide_product_desc *pp)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
for (; pp->chip_map != NULL; pp++)
|
|
|
|
if (PCI_PRODUCT(id) == pp->ide_product)
|
|
|
|
break;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2003-10-08 15:51:59 +04:00
|
|
|
if (pp->chip_map == NULL)
|
|
|
|
return NULL;
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_common_attach(struct pciide_softc *sc, struct pci_attach_args *pa, const struct pciide_product_desc *pp)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
|
|
pcitag_t tag = pa->pa_tag;
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
pcireg_t csr;
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2003-10-08 15:51:59 +04:00
|
|
|
char devinfo[256];
|
|
|
|
const char *displaydev;
|
|
|
|
|
|
|
|
aprint_naive(": disk controller\n");
|
|
|
|
|
|
|
|
sc->sc_pci_id = pa->pa_id;
|
|
|
|
if (pp == NULL) {
|
|
|
|
/* should only happen for generic pciide devices */
|
|
|
|
sc->sc_pp = &default_product_desc;
|
2004-04-24 01:13:05 +04:00
|
|
|
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
|
2003-10-08 15:51:59 +04:00
|
|
|
displaydev = devinfo;
|
|
|
|
} else {
|
|
|
|
sc->sc_pp = pp;
|
|
|
|
displaydev = sc->sc_pp->ide_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if displaydev == NULL, printf is done in chip-specific map */
|
|
|
|
if (displaydev)
|
2009-08-23 20:21:36 +04:00
|
|
|
aprint_normal(": %s (rev. 0x%02x)\n", displaydev,
|
2003-10-08 15:51:59 +04:00
|
|
|
PCI_REVISION(pa->pa_class));
|
2009-08-23 20:21:36 +04:00
|
|
|
else
|
|
|
|
aprint_normal("\n");
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
sc->sc_pc = pa->pa_pc;
|
|
|
|
sc->sc_tag = pa->pa_tag;
|
|
|
|
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
/* Set up DMA defaults; these might be adjusted by chip_map. */
|
|
|
|
sc->sc_dma_maxsegsz = IDEDMA_BYTE_COUNT_MAX;
|
|
|
|
sc->sc_dma_boundary = IDEDMA_BYTE_COUNT_ALIGN;
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2003-10-08 15:51:59 +04:00
|
|
|
|
2004-08-13 08:10:49 +04:00
|
|
|
#ifdef ATADEBUG
|
|
|
|
if (atadebug_pciide_mask & DEBUG_PROBE)
|
2003-10-08 15:51:59 +04:00
|
|
|
pci_conf_print(sc->sc_pc, sc->sc_tag, NULL);
|
|
|
|
#endif
|
|
|
|
sc->sc_pp->chip_map(sc, pa);
|
|
|
|
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
if (sc->sc_dma_ok) {
|
|
|
|
csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
|
|
|
|
csr |= PCI_COMMAND_MASTER_ENABLE;
|
|
|
|
pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
|
|
|
|
}
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2004-08-13 08:10:49 +04:00
|
|
|
ATADEBUG_PRINT(("pciide: command/status register=%x\n",
|
2003-10-08 15:51:59 +04:00
|
|
|
pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG)), DEBUG_PROBE);
|
|
|
|
}
|
|
|
|
|
2010-11-05 21:07:23 +03:00
|
|
|
int
|
|
|
|
pciide_common_detach(struct pciide_softc *sc, int flags)
|
|
|
|
{
|
|
|
|
struct pciide_channel *cp;
|
|
|
|
struct ata_channel *wdc_cp;
|
|
|
|
struct wdc_regs *wdr;
|
|
|
|
int channel, drive;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = wdcdetach(sc->sc_wdcdev.sc_atac.atac_dev, flags);
|
|
|
|
if (rv)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
|
|
|
|
channel++) {
|
|
|
|
cp = &sc->pciide_channels[channel];
|
|
|
|
wdc_cp = &cp->ata_channel;
|
|
|
|
wdr = CHAN_TO_WDC_REGS(wdc_cp);
|
|
|
|
|
|
|
|
if (wdc_cp->ch_flags & ATACH_DISABLED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wdr->cmd_ios != 0)
|
|
|
|
bus_space_unmap(wdr->cmd_iot,
|
|
|
|
wdr->cmd_baseioh, wdr->cmd_ios);
|
|
|
|
if (cp->compat != 0) {
|
|
|
|
if (wdr->ctl_ios != 0)
|
|
|
|
bus_space_unmap(wdr->ctl_iot,
|
|
|
|
wdr->ctl_ioh, wdr->ctl_ios);
|
|
|
|
} else {
|
|
|
|
if (cp->ctl_ios != 0)
|
|
|
|
bus_space_unmap(wdr->ctl_iot,
|
|
|
|
cp->ctl_baseioh, cp->ctl_ios);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (drive = 0; drive < cp->ata_channel.ch_ndrive; drive++) {
|
2010-11-17 22:36:54 +03:00
|
|
|
#if NATA_DMA
|
2010-11-05 21:07:23 +03:00
|
|
|
pciide_dma_table_teardown(sc, channel, drive);
|
2010-11-17 22:36:54 +03:00
|
|
|
#endif
|
2010-11-05 21:07:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
free(cp->ata_channel.ch_queue, M_DEVBUF);
|
|
|
|
cp->ata_channel.atabus = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-17 22:36:54 +03:00
|
|
|
#if NATA_DMA
|
2010-11-05 21:07:23 +03:00
|
|
|
if (sc->sc_dma_ios != 0)
|
|
|
|
bus_space_unmap(sc->sc_dma_iot, sc->sc_dma_ioh, sc->sc_dma_ios);
|
|
|
|
if (sc->sc_ba5_ss != 0)
|
2010-11-05 22:48:43 +03:00
|
|
|
bus_space_unmap(sc->sc_ba5_st, sc->sc_ba5_sh, sc->sc_ba5_ss);
|
2010-11-17 22:36:54 +03:00
|
|
|
#endif
|
2010-11-05 21:07:23 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-06 03:29:09 +03:00
|
|
|
int
|
|
|
|
pciide_detach(device_t self, int flags)
|
|
|
|
{
|
|
|
|
struct pciide_softc *sc = device_private(self);
|
|
|
|
struct pciide_channel *cp;
|
|
|
|
int channel;
|
|
|
|
#ifndef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH
|
|
|
|
bool has_compat_chan;
|
|
|
|
|
|
|
|
has_compat_chan = false;
|
|
|
|
for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
|
|
|
|
channel++) {
|
|
|
|
cp = &sc->pciide_channels[channel];
|
|
|
|
if (cp->compat != 0) {
|
|
|
|
has_compat_chan = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_compat_chan != false)
|
|
|
|
return EBUSY;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
|
|
|
|
channel++) {
|
|
|
|
cp = &sc->pciide_channels[channel];
|
|
|
|
if (cp->compat != 0)
|
|
|
|
if (cp->ih != NULL)
|
|
|
|
pciide_unmap_compat_intr(sc->sc_pc, cp, channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_pci_ih != NULL)
|
|
|
|
pci_intr_disestablish(sc->sc_pc, sc->sc_pci_ih);
|
|
|
|
|
|
|
|
return pciide_common_detach(sc, flags);
|
|
|
|
}
|
|
|
|
|
2003-10-08 15:51:59 +04:00
|
|
|
/* tell whether the chip is enabled or not */
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_chipen(struct pciide_softc *sc, struct pci_attach_args *pa)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
pcireg_t csr;
|
|
|
|
|
|
|
|
if ((pa->pa_flags & PCI_FLAGS_IO_ENABLED) == 0) {
|
|
|
|
csr = pci_conf_read(sc->sc_pc, sc->sc_tag,
|
|
|
|
PCI_COMMAND_STATUS_REG);
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"device disabled (at %s)\n",
|
2003-10-08 15:51:59 +04:00
|
|
|
(csr & PCI_COMMAND_IO_ENABLE) == 0 ?
|
|
|
|
"device" : "bridge");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-05 21:07:23 +03:00
|
|
|
pciide_mapregs_compat(struct pci_attach_args *pa, struct pciide_channel *cp, int compatchan)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2004-08-20 03:25:35 +04:00
|
|
|
struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
|
2004-08-14 19:08:04 +04:00
|
|
|
struct ata_channel *wdc_cp = &cp->ata_channel;
|
2004-08-20 03:25:35 +04:00
|
|
|
struct wdc_regs *wdr = CHAN_TO_WDC_REGS(wdc_cp);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
int i;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
cp->compat = 1;
|
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->cmd_iot = pa->pa_iot;
|
|
|
|
if (bus_space_map(wdr->cmd_iot, PCIIDE_COMPAT_CMD_BASE(compatchan),
|
|
|
|
PCIIDE_COMPAT_CMD_SIZE, 0, &wdr->cmd_baseioh) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't map %s channel cmd regs\n", cp->name);
|
2003-10-08 15:51:59 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
2010-11-05 21:07:23 +03:00
|
|
|
wdr->cmd_ios = PCIIDE_COMPAT_CMD_SIZE;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->ctl_iot = pa->pa_iot;
|
|
|
|
if (bus_space_map(wdr->ctl_iot, PCIIDE_COMPAT_CTL_BASE(compatchan),
|
|
|
|
PCIIDE_COMPAT_CTL_SIZE, 0, &wdr->ctl_ioh) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't map %s channel ctl regs\n", cp->name);
|
2010-11-05 21:07:23 +03:00
|
|
|
bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh, wdr->cmd_ios);
|
2003-10-08 15:51:59 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
2010-11-05 21:07:23 +03:00
|
|
|
wdr->ctl_ios = PCIIDE_COMPAT_CTL_SIZE;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
for (i = 0; i < WDC_NREG; i++) {
|
2004-08-14 19:08:04 +04:00
|
|
|
if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, i,
|
|
|
|
i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't subregion %s channel cmd regs\n",
|
|
|
|
cp->name);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
2004-05-26 00:42:40 +04:00
|
|
|
wdc_init_shadow_regs(wdc_cp);
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->data32iot = wdr->cmd_iot;
|
|
|
|
wdr->data32ioh = wdr->cmd_iohs[0];
|
2003-10-08 15:51:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
2004-08-14 19:08:04 +04:00
|
|
|
cp->ata_channel.ch_flags |= ATACH_DISABLED;
|
2003-10-08 15:51:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-16 00:23:31 +03:00
|
|
|
pciide_mapregs_native(struct pci_attach_args *pa,
|
2010-11-05 21:07:23 +03:00
|
|
|
struct pciide_channel *cp, int (*pci_intr)(void *))
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2004-08-20 03:25:35 +04:00
|
|
|
struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
|
2004-08-14 19:08:04 +04:00
|
|
|
struct ata_channel *wdc_cp = &cp->ata_channel;
|
2004-08-20 03:25:35 +04:00
|
|
|
struct wdc_regs *wdr = CHAN_TO_WDC_REGS(wdc_cp);
|
2003-10-08 15:51:59 +04:00
|
|
|
const char *intrstr;
|
|
|
|
pci_intr_handle_t intrhandle;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
int i;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
cp->compat = 0;
|
|
|
|
|
|
|
|
if (sc->sc_pci_ih == NULL) {
|
|
|
|
if (pci_intr_map(pa, &intrhandle) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't map native-PCI interrupt\n");
|
2003-10-08 15:51:59 +04:00
|
|
|
goto bad;
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
2003-10-08 15:51:59 +04:00
|
|
|
intrstr = pci_intr_string(pa->pa_pc, intrhandle);
|
|
|
|
sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
|
|
|
|
intrhandle, IPL_BIO, pci_intr, sc);
|
|
|
|
if (sc->sc_pci_ih != NULL) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"using %s for native-PCI interrupt\n",
|
2003-10-08 15:51:59 +04:00
|
|
|
intrstr ? intrstr : "unknown interrupt");
|
|
|
|
} else {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't establish native-PCI interrupt");
|
2003-10-08 15:51:59 +04:00
|
|
|
if (intrstr != NULL)
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(" at %s", intrstr);
|
|
|
|
aprint_error("\n");
|
2003-10-08 15:51:59 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cp->ih = sc->sc_pci_ih;
|
2004-01-04 01:56:52 +03:00
|
|
|
if (pci_mapreg_map(pa, PCIIDE_REG_CMD_BASE(wdc_cp->ch_channel),
|
2003-10-08 15:51:59 +04:00
|
|
|
PCI_MAPREG_TYPE_IO, 0,
|
2010-11-05 21:07:23 +03:00
|
|
|
&wdr->cmd_iot, &wdr->cmd_baseioh, NULL, &wdr->cmd_ios) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't map %s channel cmd regs\n", cp->name);
|
2003-10-08 15:51:59 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (pci_mapreg_map(pa, PCIIDE_REG_CTL_BASE(wdc_cp->ch_channel),
|
2003-10-08 15:51:59 +04:00
|
|
|
PCI_MAPREG_TYPE_IO, 0,
|
2010-11-05 21:07:23 +03:00
|
|
|
&wdr->ctl_iot, &cp->ctl_baseioh, NULL, &cp->ctl_ios) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't map %s channel ctl regs\n", cp->name);
|
2010-11-05 21:07:23 +03:00
|
|
|
bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh, wdr->cmd_ios);
|
2003-10-08 15:51:59 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* In native mode, 4 bytes of I/O space are mapped for the control
|
|
|
|
* register, the control register is at offset 2. Pass the generic
|
|
|
|
* code a handle for only one byte at the right offset.
|
|
|
|
*/
|
2004-08-14 19:08:04 +04:00
|
|
|
if (bus_space_subregion(wdr->ctl_iot, cp->ctl_baseioh, 2, 1,
|
|
|
|
&wdr->ctl_ioh) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"unable to subregion %s channel ctl regs\n", cp->name);
|
2010-11-05 21:07:23 +03:00
|
|
|
bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh, wdr->cmd_ios);
|
|
|
|
bus_space_unmap(wdr->cmd_iot, cp->ctl_baseioh, cp->ctl_ios);
|
2003-10-08 15:51:59 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
for (i = 0; i < WDC_NREG; i++) {
|
2004-08-14 19:08:04 +04:00
|
|
|
if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, i,
|
|
|
|
i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"couldn't subregion %s channel cmd regs\n",
|
|
|
|
cp->name);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
2004-05-26 00:42:40 +04:00
|
|
|
wdc_init_shadow_regs(wdc_cp);
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->data32iot = wdr->cmd_iot;
|
|
|
|
wdr->data32ioh = wdr->cmd_iohs[0];
|
2003-10-08 15:51:59 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
2004-08-14 19:08:04 +04:00
|
|
|
cp->ata_channel.ch_flags |= ATACH_DISABLED;
|
2003-10-08 15:51:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_mapreg_dma(struct pciide_softc *sc, struct pci_attach_args *pa)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
pcireg_t maptype;
|
|
|
|
bus_addr_t addr;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
struct pciide_channel *pc;
|
|
|
|
int reg, chan;
|
|
|
|
bus_size_t size;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Map DMA registers
|
|
|
|
*
|
|
|
|
* Note that sc_dma_ok is the right variable to test to see if
|
|
|
|
* DMA can be done. If the interface doesn't support DMA,
|
|
|
|
* sc_dma_ok will never be non-zero. If the DMA regs couldn't
|
|
|
|
* be mapped, it'll be zero. I.e., sc_dma_ok will only be
|
|
|
|
* non-zero if the interface supports DMA and the registers
|
|
|
|
* could be mapped.
|
|
|
|
*
|
|
|
|
* XXX Note that despite the fact that the Bus Master IDE specs
|
|
|
|
* XXX say that "The bus master IDE function uses 16 bytes of IO
|
|
|
|
* XXX space," some controllers (at least the United
|
|
|
|
* XXX Microelectronics UM8886BF) place it in memory space.
|
|
|
|
*/
|
|
|
|
maptype = pci_mapreg_type(pa->pa_pc, pa->pa_tag,
|
|
|
|
PCIIDE_REG_BUS_MASTER_DMA);
|
|
|
|
|
|
|
|
switch (maptype) {
|
|
|
|
case PCI_MAPREG_TYPE_IO:
|
|
|
|
sc->sc_dma_ok = (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
|
|
|
|
PCIIDE_REG_BUS_MASTER_DMA, PCI_MAPREG_TYPE_IO,
|
|
|
|
&addr, NULL, NULL) == 0);
|
|
|
|
if (sc->sc_dma_ok == 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(
|
2003-10-08 15:51:59 +04:00
|
|
|
", but unused (couldn't query registers)");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((sc->sc_pp->ide_flags & IDE_16BIT_IOSPACE)
|
|
|
|
&& addr >= 0x10000) {
|
|
|
|
sc->sc_dma_ok = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(
|
2003-10-08 15:51:59 +04:00
|
|
|
", but unused (registers at unsafe address "
|
|
|
|
"%#lx)", (unsigned long)addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2003-10-08 15:51:59 +04:00
|
|
|
case PCI_MAPREG_MEM_TYPE_32BIT:
|
|
|
|
sc->sc_dma_ok = (pci_mapreg_map(pa,
|
|
|
|
PCIIDE_REG_BUS_MASTER_DMA, maptype, 0,
|
2010-11-05 21:07:23 +03:00
|
|
|
&sc->sc_dma_iot, &sc->sc_dma_ioh, NULL, &sc->sc_dma_ios)
|
|
|
|
== 0);
|
2003-10-08 15:51:59 +04:00
|
|
|
sc->sc_dmat = pa->pa_dmat;
|
|
|
|
if (sc->sc_dma_ok == 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(", but unused (couldn't map registers)");
|
2003-10-08 15:51:59 +04:00
|
|
|
} else {
|
|
|
|
sc->sc_wdcdev.dma_arg = sc;
|
|
|
|
sc->sc_wdcdev.dma_init = pciide_dma_init;
|
|
|
|
sc->sc_wdcdev.dma_start = pciide_dma_start;
|
|
|
|
sc->sc_wdcdev.dma_finish = pciide_dma_finish;
|
|
|
|
}
|
|
|
|
|
2008-03-18 23:46:35 +03:00
|
|
|
if (device_cfdata(sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
|
2003-10-08 15:51:59 +04:00
|
|
|
PCIIDE_OPTIONS_NODMA) {
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(
|
2003-10-08 15:51:59 +04:00
|
|
|
", but unused (forced off by config file)");
|
|
|
|
sc->sc_dma_ok = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sc->sc_dma_ok = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(
|
2003-10-08 15:51:59 +04:00
|
|
|
", but unsupported register maptype (0x%x)", maptype);
|
|
|
|
}
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
|
2004-06-05 01:15:00 +04:00
|
|
|
if (sc->sc_dma_ok == 0)
|
|
|
|
return;
|
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
/*
|
|
|
|
* Set up the default handles for the DMA registers.
|
|
|
|
* Just reserve 32 bits for each handle, unless space
|
|
|
|
* doesn't permit it.
|
|
|
|
*/
|
|
|
|
for (chan = 0; chan < PCIIDE_NUM_CHANNELS; chan++) {
|
|
|
|
pc = &sc->pciide_channels[chan];
|
|
|
|
for (reg = 0; reg < IDEDMA_NREGS; reg++) {
|
|
|
|
size = 4;
|
|
|
|
if (size > (IDEDMA_SCH_OFFSET - reg))
|
|
|
|
size = IDEDMA_SCH_OFFSET - reg;
|
|
|
|
if (bus_space_subregion(sc->sc_dma_iot, sc->sc_dma_ioh,
|
|
|
|
IDEDMA_SCH_OFFSET * chan + reg, size,
|
|
|
|
&pc->dma_iohs[reg]) != 0) {
|
|
|
|
sc->sc_dma_ok = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(", but can't subregion offset %d "
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
"size %lu", reg, (u_long)size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif /* NATA_DMA */
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_compat_intr(void *arg)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
struct pciide_channel *cp = arg;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* should only be called for a compat channel */
|
|
|
|
if (cp->compat == 0)
|
|
|
|
panic("pciide compat intr called for non-compat chan %p", cp);
|
|
|
|
#endif
|
2004-08-14 19:08:04 +04:00
|
|
|
return (wdcintr(&cp->ata_channel));
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_pci_intr(void *arg)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
struct pciide_softc *sc = arg;
|
|
|
|
struct pciide_channel *cp;
|
2004-08-14 19:08:04 +04:00
|
|
|
struct ata_channel *wdc_cp;
|
2003-10-08 15:51:59 +04:00
|
|
|
int i, rv, crv;
|
|
|
|
|
|
|
|
rv = 0;
|
2004-08-20 10:39:37 +04:00
|
|
|
for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
|
2003-10-08 15:51:59 +04:00
|
|
|
cp = &sc->pciide_channels[i];
|
2004-08-14 19:08:04 +04:00
|
|
|
wdc_cp = &cp->ata_channel;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
/* If a compat channel skip. */
|
|
|
|
if (cp->compat)
|
|
|
|
continue;
|
|
|
|
/* if this channel not waiting for intr, skip */
|
2004-08-14 19:08:04 +04:00
|
|
|
if ((wdc_cp->ch_flags & ATACH_IRQ_WAIT) == 0)
|
2003-10-08 15:51:59 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
crv = wdcintr(wdc_cp);
|
|
|
|
if (crv == 0)
|
|
|
|
; /* leave rv alone */
|
|
|
|
else if (crv == 1)
|
|
|
|
rv = 1; /* claim the intr */
|
|
|
|
else if (rv == 0) /* crv should be -1 in this case */
|
|
|
|
rv = crv; /* if we've done no better, take it */
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_channel_dma_setup(struct pciide_channel *cp)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2004-08-21 04:28:34 +04:00
|
|
|
int drive, s;
|
2004-08-20 03:25:35 +04:00
|
|
|
struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
|
2003-10-08 15:51:59 +04:00
|
|
|
struct ata_drive_datas *drvp;
|
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
KASSERT(cp->ata_channel.ch_ndrive != 0);
|
|
|
|
|
|
|
|
for (drive = 0; drive < cp->ata_channel.ch_ndrive; drive++) {
|
|
|
|
drvp = &cp->ata_channel.ch_drive[drive];
|
2003-10-08 15:51:59 +04:00
|
|
|
/* If no drive, skip */
|
|
|
|
if ((drvp->drive_flags & DRIVE) == 0)
|
|
|
|
continue;
|
|
|
|
/* setup DMA if needed */
|
|
|
|
if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
|
|
|
|
(drvp->drive_flags & DRIVE_UDMA) == 0) ||
|
|
|
|
sc->sc_dma_ok == 0) {
|
2004-08-21 04:28:34 +04:00
|
|
|
s = splbio();
|
2003-10-08 15:51:59 +04:00
|
|
|
drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);
|
2004-08-21 04:28:34 +04:00
|
|
|
splx(s);
|
2003-10-08 15:51:59 +04:00
|
|
|
continue;
|
|
|
|
}
|
2004-08-14 19:08:04 +04:00
|
|
|
if (pciide_dma_table_setup(sc, cp->ata_channel.ch_channel,
|
2004-01-04 01:56:52 +03:00
|
|
|
drive) != 0) {
|
2003-10-08 15:51:59 +04:00
|
|
|
/* Abort DMA setup */
|
2004-08-21 04:28:34 +04:00
|
|
|
s = splbio();
|
2003-10-08 15:51:59 +04:00
|
|
|
drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);
|
2004-08-21 04:28:34 +04:00
|
|
|
splx(s);
|
2003-10-08 15:51:59 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-15 06:18:22 +03:00
|
|
|
#define NIDEDMA_TABLES(sc) \
|
2005-02-15 15:20:37 +03:00
|
|
|
(MAXPHYS/(min((sc)->sc_dma_maxsegsz, PAGE_SIZE)) + 1)
|
2005-02-15 06:18:22 +03:00
|
|
|
|
2003-10-08 15:51:59 +04:00
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
pciide_dma_table_setup(struct pciide_softc *sc, int channel, int drive)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2010-11-05 21:07:23 +03:00
|
|
|
int error;
|
2003-10-08 15:51:59 +04:00
|
|
|
const bus_size_t dma_table_size =
|
2005-02-15 06:18:22 +03:00
|
|
|
sizeof(struct idedma_table) * NIDEDMA_TABLES(sc);
|
2003-10-08 15:51:59 +04:00
|
|
|
struct pciide_dma_maps *dma_maps =
|
|
|
|
&sc->pciide_channels[channel].dma_maps[drive];
|
|
|
|
|
|
|
|
/* If table was already allocated, just return */
|
|
|
|
if (dma_maps->dma_table)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Allocate memory for the DMA tables and map it */
|
|
|
|
if ((error = bus_dmamem_alloc(sc->sc_dmat, dma_table_size,
|
2010-11-05 21:07:23 +03:00
|
|
|
IDEDMA_TBL_ALIGN, IDEDMA_TBL_ALIGN, &dma_maps->dmamap_table_seg,
|
|
|
|
1, &dma_maps->dmamap_table_nseg, BUS_DMA_NOWAIT)) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(dmaerrfmt,
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
|
|
|
|
"allocate", drive, error);
|
2003-10-08 15:51:59 +04:00
|
|
|
return error;
|
|
|
|
}
|
2010-11-05 21:07:23 +03:00
|
|
|
if ((error = bus_dmamem_map(sc->sc_dmat, &dma_maps->dmamap_table_seg,
|
|
|
|
dma_maps->dmamap_table_nseg, dma_table_size,
|
2007-03-04 08:59:00 +03:00
|
|
|
(void **)&dma_maps->dma_table,
|
2003-10-08 15:51:59 +04:00
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(dmaerrfmt,
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
|
|
|
|
"map", drive, error);
|
2003-10-08 15:51:59 +04:00
|
|
|
return error;
|
|
|
|
}
|
2004-08-13 08:10:49 +04:00
|
|
|
ATADEBUG_PRINT(("pciide_dma_table_setup: table at %p len %lu, "
|
2003-10-08 15:51:59 +04:00
|
|
|
"phy 0x%lx\n", dma_maps->dma_table, (u_long)dma_table_size,
|
2010-11-05 21:07:23 +03:00
|
|
|
(unsigned long)dma_maps->dmamap_table_seg.ds_addr), DEBUG_PROBE);
|
2003-10-08 15:51:59 +04:00
|
|
|
/* Create and load table DMA map for this disk */
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, dma_table_size,
|
|
|
|
1, dma_table_size, IDEDMA_TBL_ALIGN, BUS_DMA_NOWAIT,
|
|
|
|
&dma_maps->dmamap_table)) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(dmaerrfmt,
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
|
|
|
|
"create", drive, error);
|
2003-10-08 15:51:59 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat,
|
|
|
|
dma_maps->dmamap_table,
|
|
|
|
dma_maps->dma_table,
|
|
|
|
dma_table_size, NULL, BUS_DMA_NOWAIT)) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(dmaerrfmt,
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
|
|
|
|
"load", drive, error);
|
2003-10-08 15:51:59 +04:00
|
|
|
return error;
|
|
|
|
}
|
2004-08-13 08:10:49 +04:00
|
|
|
ATADEBUG_PRINT(("pciide_dma_table_setup: phy addr of table 0x%lx\n",
|
2003-10-08 15:51:59 +04:00
|
|
|
(unsigned long)dma_maps->dmamap_table->dm_segs[0].ds_addr),
|
|
|
|
DEBUG_PROBE);
|
|
|
|
/* Create a xfer DMA map for this drive */
|
2005-02-15 15:20:37 +03:00
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, MAXPHYS,
|
2005-02-15 06:18:22 +03:00
|
|
|
NIDEDMA_TABLES(sc), sc->sc_dma_maxsegsz, sc->sc_dma_boundary,
|
2003-10-08 15:51:59 +04:00
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
|
|
|
|
&dma_maps->dmamap_xfer)) != 0) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(dmaerrfmt,
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
|
|
|
|
"create xfer", drive, error);
|
2003-10-08 15:51:59 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-05 21:07:23 +03:00
|
|
|
void
|
|
|
|
pciide_dma_table_teardown(struct pciide_softc *sc, int channel, int drive)
|
|
|
|
{
|
|
|
|
struct pciide_channel *cp;
|
|
|
|
struct pciide_dma_maps *dma_maps;
|
|
|
|
|
|
|
|
cp = &sc->pciide_channels[channel];
|
|
|
|
dma_maps = &cp->dma_maps[drive];
|
|
|
|
|
|
|
|
if (dma_maps->dma_table == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, dma_maps->dmamap_xfer);
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_table);
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, dma_maps->dmamap_table);
|
|
|
|
bus_dmamem_unmap(sc->sc_dmat, dma_maps->dma_table,
|
|
|
|
sizeof(struct idedma_table) * NIDEDMA_TABLES(sc));
|
|
|
|
bus_dmamem_free(sc->sc_dmat, &dma_maps->dmamap_table_seg,
|
|
|
|
dma_maps->dmamap_table_nseg);
|
|
|
|
|
|
|
|
dma_maps->dma_table = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-08 15:51:59 +04:00
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
pciide_dma_dmamap_setup(struct pciide_softc *sc, int channel, int drive, void *databuf, size_t datalen, int flags)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
int error, seg;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
struct pciide_channel *cp = &sc->pciide_channels[channel];
|
|
|
|
struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
error = bus_dmamap_load(sc->sc_dmat,
|
|
|
|
dma_maps->dmamap_xfer,
|
|
|
|
databuf, datalen, NULL, BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
|
|
|
|
((flags & WDC_DMA_READ) ? BUS_DMA_READ : BUS_DMA_WRITE));
|
|
|
|
if (error) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error(dmaerrfmt,
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
|
|
|
|
"load xfer", drive, error);
|
2003-10-08 15:51:59 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
|
|
|
|
dma_maps->dmamap_xfer->dm_mapsize,
|
|
|
|
(flags & WDC_DMA_READ) ?
|
|
|
|
BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
for (seg = 0; seg < dma_maps->dmamap_xfer->dm_nsegs; seg++) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* A segment must not cross a 64k boundary */
|
|
|
|
{
|
|
|
|
u_long phys = dma_maps->dmamap_xfer->dm_segs[seg].ds_addr;
|
|
|
|
u_long len = dma_maps->dmamap_xfer->dm_segs[seg].ds_len;
|
|
|
|
if ((phys & ~IDEDMA_BYTE_COUNT_MASK) !=
|
|
|
|
((phys + len - 1) & ~IDEDMA_BYTE_COUNT_MASK)) {
|
|
|
|
printf("pciide_dma: segment %d physical addr 0x%lx"
|
|
|
|
" len 0x%lx not properly aligned\n",
|
|
|
|
seg, phys, len);
|
|
|
|
panic("pciide_dma: buf align");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
dma_maps->dma_table[seg].base_addr =
|
|
|
|
htole32(dma_maps->dmamap_xfer->dm_segs[seg].ds_addr);
|
|
|
|
dma_maps->dma_table[seg].byte_count =
|
|
|
|
htole32(dma_maps->dmamap_xfer->dm_segs[seg].ds_len &
|
|
|
|
IDEDMA_BYTE_COUNT_MASK);
|
2004-08-13 08:10:49 +04:00
|
|
|
ATADEBUG_PRINT(("\t seg %d len %d addr 0x%x\n",
|
2003-10-08 15:51:59 +04:00
|
|
|
seg, le32toh(dma_maps->dma_table[seg].byte_count),
|
|
|
|
le32toh(dma_maps->dma_table[seg].base_addr)), DEBUG_DMA);
|
|
|
|
|
|
|
|
}
|
|
|
|
dma_maps->dma_table[dma_maps->dmamap_xfer->dm_nsegs -1].byte_count |=
|
|
|
|
htole32(IDEDMA_BYTE_COUNT_EOT);
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_table, 0,
|
|
|
|
dma_maps->dmamap_table->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (dma_maps->dmamap_table->dm_segs[0].ds_addr & ~IDEDMA_TBL_MASK) {
|
2004-11-24 22:52:50 +03:00
|
|
|
printf("pciide_dma_dmamap_setup: addr 0x%lx "
|
|
|
|
"not properly aligned\n",
|
2003-10-08 15:51:59 +04:00
|
|
|
(u_long)dma_maps->dmamap_table->dm_segs[0].ds_addr);
|
|
|
|
panic("pciide_dma_init: table align");
|
|
|
|
}
|
|
|
|
#endif
|
2004-11-24 22:52:50 +03:00
|
|
|
/* remember flags */
|
|
|
|
dma_maps->dma_flags = flags;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
pciide_dma_init(void *v, int channel, int drive, void *databuf, size_t datalen, int flags)
|
2004-11-24 22:52:50 +03:00
|
|
|
{
|
|
|
|
struct pciide_softc *sc = v;
|
|
|
|
int error;
|
|
|
|
struct pciide_channel *cp = &sc->pciide_channels[channel];
|
|
|
|
struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
|
2003-10-08 15:51:59 +04:00
|
|
|
|
2004-11-24 22:52:50 +03:00
|
|
|
if ((error = pciide_dma_dmamap_setup(sc, channel, drive,
|
|
|
|
databuf, datalen, flags)) != 0)
|
|
|
|
return error;
|
|
|
|
/* Maps are ready. Start DMA function */
|
2003-10-08 15:51:59 +04:00
|
|
|
/* Clear status bits */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
|
|
|
|
bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0));
|
2003-10-08 15:51:59 +04:00
|
|
|
/* Write table addr */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_TBL], 0,
|
2003-10-08 15:51:59 +04:00
|
|
|
dma_maps->dmamap_table->dm_segs[0].ds_addr);
|
|
|
|
/* set read/write */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
|
2003-12-19 22:09:20 +03:00
|
|
|
((flags & WDC_DMA_READ) ? IDEDMA_CMD_WRITE : 0) | cp->idedma_cmd);
|
2003-10-08 15:51:59 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-11-16 04:32:37 +03:00
|
|
|
pciide_dma_start(void *v, int channel, int drive)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
struct pciide_softc *sc = v;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
struct pciide_channel *cp = &sc->pciide_channels[channel];
|
2003-10-08 15:51:59 +04:00
|
|
|
|
2004-08-13 08:10:49 +04:00
|
|
|
ATADEBUG_PRINT(("pciide_dma_start\n"),DEBUG_XFERS);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
|
|
|
|
bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0)
|
|
|
|
| IDEDMA_CMD_START);
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
pciide_dma_finish(void *v, int channel, int drive, int force)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
struct pciide_softc *sc = v;
|
|
|
|
u_int8_t status;
|
|
|
|
int error = 0;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
struct pciide_channel *cp = &sc->pciide_channels[channel];
|
|
|
|
struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
|
2003-10-08 15:51:59 +04:00
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
status = bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0);
|
2004-08-13 08:10:49 +04:00
|
|
|
ATADEBUG_PRINT(("pciide_dma_finish: status 0x%x\n", status),
|
2003-10-08 15:51:59 +04:00
|
|
|
DEBUG_XFERS);
|
|
|
|
|
2004-08-03 02:20:54 +04:00
|
|
|
if (force == WDC_DMAEND_END && (status & IDEDMA_CTL_INTR) == 0)
|
2003-10-08 15:51:59 +04:00
|
|
|
return WDC_DMAST_NOIRQ;
|
|
|
|
|
|
|
|
/* stop DMA channel */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
|
|
|
|
bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0)
|
|
|
|
& ~IDEDMA_CMD_START);
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
/* Unload the map of the data buffer */
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
|
|
|
|
dma_maps->dmamap_xfer->dm_mapsize,
|
|
|
|
(dma_maps->dma_flags & WDC_DMA_READ) ?
|
|
|
|
BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_xfer);
|
|
|
|
|
2004-08-03 02:20:54 +04:00
|
|
|
if ((status & IDEDMA_CTL_ERR) != 0 && force != WDC_DMAEND_ABRT_QUIET) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error("%s:%d:%d: bus-master DMA error: status=0x%x\n",
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
|
|
|
|
drive, status);
|
2003-10-08 15:51:59 +04:00
|
|
|
error |= WDC_DMAST_ERR;
|
|
|
|
}
|
|
|
|
|
2004-08-03 02:20:54 +04:00
|
|
|
if ((status & IDEDMA_CTL_INTR) == 0 && force != WDC_DMAEND_ABRT_QUIET) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error("%s:%d:%d: bus-master DMA error: missing "
|
|
|
|
"interrupt, status=0x%x\n",
|
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
|
2004-08-20 10:39:37 +04:00
|
|
|
channel, drive, status);
|
2003-10-08 15:51:59 +04:00
|
|
|
error |= WDC_DMAST_NOIRQ;
|
|
|
|
}
|
|
|
|
|
2004-08-03 02:20:54 +04:00
|
|
|
if ((status & IDEDMA_CTL_ACT) != 0 && force != WDC_DMAEND_ABRT_QUIET) {
|
2003-10-08 15:51:59 +04:00
|
|
|
/* data underrun, may be a valid condition for ATAPI */
|
|
|
|
error |= WDC_DMAST_UNDER;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_irqack(struct ata_channel *chp)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2004-08-20 03:25:35 +04:00
|
|
|
struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
|
|
|
|
struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
/* clear status bits in IDE DMA registers */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
|
|
|
|
bus_space_read_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0));
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif /* NATA_DMA */
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
/* some common code used by several chip_map */
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_chansetup(struct pciide_softc *sc, int channel, pcireg_t interface)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
struct pciide_channel *cp = &sc->pciide_channels[channel];
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->wdc_chanarray[channel] = &cp->ata_channel;
|
2003-10-08 15:51:59 +04:00
|
|
|
cp->name = PCIIDE_CHANNEL_NAME(channel);
|
2004-08-14 19:08:04 +04:00
|
|
|
cp->ata_channel.ch_channel = channel;
|
2004-08-20 10:39:37 +04:00
|
|
|
cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
|
2004-08-14 19:08:04 +04:00
|
|
|
cp->ata_channel.ch_queue =
|
2004-01-01 20:18:53 +03:00
|
|
|
malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
|
2004-08-14 19:08:04 +04:00
|
|
|
if (cp->ata_channel.ch_queue == NULL) {
|
2003-10-08 15:51:59 +04:00
|
|
|
aprint_error("%s %s channel: "
|
|
|
|
"can't allocate memory for command queue",
|
2008-03-18 23:46:35 +03:00
|
|
|
device_xname(sc->sc_wdcdev.sc_atac.atac_dev), cp->name);
|
2003-10-08 15:51:59 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2006-01-17 03:40:49 +03:00
|
|
|
cp->ata_channel.ch_ndrive = 2;
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"%s channel %s to %s mode\n", cp->name,
|
2003-10-08 15:51:59 +04:00
|
|
|
(interface & PCIIDE_INTERFACE_SETTABLE(channel)) ?
|
|
|
|
"configured" : "wired",
|
|
|
|
(interface & PCIIDE_INTERFACE_PCI(channel)) ?
|
|
|
|
"native-PCI" : "compatibility");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* some common code used by several chip channel_map */
|
|
|
|
void
|
2009-03-16 00:23:31 +03:00
|
|
|
pciide_mapchan(struct pci_attach_args *pa,
|
|
|
|
struct pciide_channel *cp,
|
2010-11-05 21:07:23 +03:00
|
|
|
pcireg_t interface, int (*pci_intr)(void *))
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2004-08-14 19:08:04 +04:00
|
|
|
struct ata_channel *wdc_cp = &cp->ata_channel;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (interface & PCIIDE_INTERFACE_PCI(wdc_cp->ch_channel))
|
2010-11-05 21:07:23 +03:00
|
|
|
pciide_mapregs_native(pa, cp, pci_intr);
|
2004-08-02 23:37:33 +04:00
|
|
|
else {
|
2010-11-05 21:07:23 +03:00
|
|
|
pciide_mapregs_compat(pa, cp, wdc_cp->ch_channel);
|
2004-08-14 19:08:04 +04:00
|
|
|
if ((cp->ata_channel.ch_flags & ATACH_DISABLED) == 0)
|
2004-08-02 23:37:33 +04:00
|
|
|
pciide_map_compat_intr(pa, cp, wdc_cp->ch_channel);
|
|
|
|
}
|
2003-10-08 15:51:59 +04:00
|
|
|
wdcattach(wdc_cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* generic code to map the compat intr.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
pciide_map_compat_intr(struct pci_attach_args *pa, struct pciide_channel *cp, int compatchan)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2004-08-20 03:25:35 +04:00
|
|
|
struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
|
2004-08-20 10:39:37 +04:00
|
|
|
cp->ih =
|
2008-03-18 23:46:35 +03:00
|
|
|
pciide_machdep_compat_intr_establish(sc->sc_wdcdev.sc_atac.atac_dev,
|
2004-08-20 10:39:37 +04:00
|
|
|
pa, compatchan, pciide_compat_intr, cp);
|
2003-10-08 15:51:59 +04:00
|
|
|
if (cp->ih == NULL) {
|
|
|
|
#endif
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"no compatibility interrupt for use by %s "
|
|
|
|
"channel\n", cp->name);
|
2004-08-14 19:08:04 +04:00
|
|
|
cp->ata_channel.ch_flags |= ATACH_DISABLED;
|
2003-10-08 15:51:59 +04:00
|
|
|
#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-11-06 03:29:09 +03:00
|
|
|
void
|
|
|
|
pciide_unmap_compat_intr(pci_chipset_tag_t pc, struct pciide_channel *cp, int compatchan)
|
|
|
|
{
|
|
|
|
#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH
|
|
|
|
struct pciide_softc *sc = CHAN_TO_PCIIDE(&cp->ata_channel);
|
|
|
|
|
|
|
|
pciide_machdep_compat_intr_disestablish(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
sc->sc_pc, compatchan, cp->ih);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-10-08 15:51:59 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
default_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
|
|
|
struct pciide_channel *cp;
|
|
|
|
pcireg_t interface = PCI_INTERFACE(pa->pa_class);
|
|
|
|
pcireg_t csr;
|
2006-10-17 17:45:05 +04:00
|
|
|
int channel;
|
|
|
|
#if NATA_DMA
|
|
|
|
int drive;
|
2003-10-08 15:51:59 +04:00
|
|
|
u_int8_t idedma_ctl;
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2005-05-30 02:16:00 +04:00
|
|
|
const char *failreason;
|
2004-08-14 19:08:04 +04:00
|
|
|
struct wdc_regs *wdr;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
if (pciide_chipen(sc, pa) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (interface & PCIIDE_INTERFACE_BUS_MASTER_DMA) {
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"bus-master DMA support present");
|
2003-10-08 15:51:59 +04:00
|
|
|
if (sc->sc_pp == &default_product_desc &&
|
2008-03-18 23:46:35 +03:00
|
|
|
(device_cfdata(sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
|
2003-10-08 15:51:59 +04:00
|
|
|
PCIIDE_OPTIONS_DMA) == 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(", but unused (no driver support)");
|
2003-10-08 15:51:59 +04:00
|
|
|
sc->sc_dma_ok = 0;
|
|
|
|
} else {
|
|
|
|
pciide_mapreg_dma(sc, pa);
|
|
|
|
if (sc->sc_dma_ok != 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose(", used without full driver "
|
2003-10-08 15:51:59 +04:00
|
|
|
"support");
|
|
|
|
}
|
2006-10-17 17:45:05 +04:00
|
|
|
#else
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"bus-master DMA support present, but unused (no driver "
|
|
|
|
"support)");
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif /* NATA_DMA */
|
2003-10-08 15:51:59 +04:00
|
|
|
} else {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"hardware does not support DMA");
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
sc->sc_dma_ok = 0;
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose("\n");
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
if (sc->sc_dma_ok) {
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
|
2003-10-08 15:51:59 +04:00
|
|
|
sc->sc_wdcdev.irqack = pciide_irqack;
|
|
|
|
}
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_dma_cap = 0;
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif
|
2003-10-08 15:51:59 +04:00
|
|
|
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
|
|
|
|
sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
|
|
|
|
sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
|
2003-10-08 15:51:59 +04:00
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
wdc_allocate_regs(&sc->sc_wdcdev);
|
|
|
|
|
2004-08-20 10:39:37 +04:00
|
|
|
for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
|
|
|
|
channel++) {
|
2003-10-08 15:51:59 +04:00
|
|
|
cp = &sc->pciide_channels[channel];
|
|
|
|
if (pciide_chansetup(sc, channel, interface) == 0)
|
|
|
|
continue;
|
2004-08-20 03:25:35 +04:00
|
|
|
wdr = CHAN_TO_WDC_REGS(&cp->ata_channel);
|
2004-05-05 21:56:14 +04:00
|
|
|
if (interface & PCIIDE_INTERFACE_PCI(channel))
|
2010-11-05 21:07:23 +03:00
|
|
|
pciide_mapregs_native(pa, cp, pciide_pci_intr);
|
2004-05-05 21:56:14 +04:00
|
|
|
else
|
|
|
|
pciide_mapregs_compat(pa, cp,
|
2010-11-05 21:07:23 +03:00
|
|
|
cp->ata_channel.ch_channel);
|
2004-08-14 19:08:04 +04:00
|
|
|
if (cp->ata_channel.ch_flags & ATACH_DISABLED)
|
2003-10-08 15:51:59 +04:00
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Check to see if something appears to be there.
|
|
|
|
*/
|
|
|
|
failreason = NULL;
|
|
|
|
/*
|
|
|
|
* In native mode, always enable the controller. It's
|
|
|
|
* not possible to have an ISA board using the same address
|
|
|
|
* anyway.
|
|
|
|
*/
|
2004-08-02 23:37:33 +04:00
|
|
|
if (interface & PCIIDE_INTERFACE_PCI(channel)) {
|
2004-08-14 19:08:04 +04:00
|
|
|
wdcattach(&cp->ata_channel);
|
2004-08-02 23:37:33 +04:00
|
|
|
continue;
|
|
|
|
}
|
2004-08-14 19:08:04 +04:00
|
|
|
if (!wdcprobe(&cp->ata_channel)) {
|
2003-10-08 15:51:59 +04:00
|
|
|
failreason = "not responding; disabled or no drives?";
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now, make sure it's actually attributable to this PCI IDE
|
|
|
|
* channel by trying to access the channel again while the
|
|
|
|
* PCI IDE controller's I/O space is disabled. (If the
|
|
|
|
* channel no longer appears to be there, it belongs to
|
|
|
|
* this controller.) YUCK!
|
|
|
|
*/
|
|
|
|
csr = pci_conf_read(sc->sc_pc, sc->sc_tag,
|
|
|
|
PCI_COMMAND_STATUS_REG);
|
|
|
|
pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_COMMAND_STATUS_REG,
|
|
|
|
csr & ~PCI_COMMAND_IO_ENABLE);
|
2004-08-14 19:08:04 +04:00
|
|
|
if (wdcprobe(&cp->ata_channel))
|
2003-10-08 15:51:59 +04:00
|
|
|
failreason = "other hardware responding at addresses";
|
|
|
|
pci_conf_write(sc->sc_pc, sc->sc_tag,
|
|
|
|
PCI_COMMAND_STATUS_REG, csr);
|
|
|
|
next:
|
|
|
|
if (failreason) {
|
2008-03-18 23:46:35 +03:00
|
|
|
aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
|
|
|
|
"%s channel ignored (%s)\n", cp->name, failreason);
|
2004-08-14 19:08:04 +04:00
|
|
|
cp->ata_channel.ch_flags |= ATACH_DISABLED;
|
|
|
|
bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh,
|
2010-11-05 21:07:23 +03:00
|
|
|
wdr->cmd_ios);
|
|
|
|
bus_space_unmap(wdr->ctl_iot, wdr->ctl_ioh,
|
|
|
|
wdr->ctl_ios);
|
2004-05-05 21:56:14 +04:00
|
|
|
} else {
|
2004-08-02 23:37:33 +04:00
|
|
|
pciide_map_compat_intr(pa, cp,
|
2004-08-14 19:08:04 +04:00
|
|
|
cp->ata_channel.ch_channel);
|
|
|
|
wdcattach(&cp->ata_channel);
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
if (sc->sc_dma_ok == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Allocate DMA maps */
|
2004-08-20 10:39:37 +04:00
|
|
|
for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
|
|
|
|
channel++) {
|
2003-10-08 15:51:59 +04:00
|
|
|
idedma_ctl = 0;
|
|
|
|
cp = &sc->pciide_channels[channel];
|
2004-08-14 19:08:04 +04:00
|
|
|
for (drive = 0; drive < cp->ata_channel.ch_ndrive; drive++) {
|
2006-01-05 01:10:10 +03:00
|
|
|
/*
|
|
|
|
* we have not probed the drives yet, allocate
|
|
|
|
* ressources for all of them.
|
|
|
|
*/
|
2003-10-08 15:51:59 +04:00
|
|
|
if (pciide_dma_table_setup(sc, channel, drive) != 0) {
|
|
|
|
/* Abort DMA setup */
|
|
|
|
aprint_error(
|
|
|
|
"%s:%d:%d: can't allocate DMA maps, "
|
|
|
|
"using PIO transfers\n",
|
2008-03-18 23:46:35 +03:00
|
|
|
device_xname(
|
|
|
|
sc->sc_wdcdev.sc_atac.atac_dev),
|
2003-10-08 15:51:59 +04:00
|
|
|
channel, drive);
|
2006-01-05 01:10:10 +03:00
|
|
|
sc->sc_dma_ok = 0;
|
|
|
|
sc->sc_wdcdev.sc_atac.atac_cap &= ~ATAC_CAP_DMA;
|
|
|
|
sc->sc_wdcdev.irqack = NULL;
|
|
|
|
break;
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
|
|
|
idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
|
|
|
|
}
|
|
|
|
if (idedma_ctl != 0) {
|
|
|
|
/* Add software bits in status register */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(sc->sc_dma_iot,
|
|
|
|
cp->dma_iohs[IDEDMA_CTL], 0, idedma_ctl);
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
|
|
|
}
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif /* NATA_DMA */
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
sata_setup_channel(struct ata_channel *chp)
|
2003-10-08 15:51:59 +04:00
|
|
|
{
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_DMA
|
2003-10-08 15:51:59 +04:00
|
|
|
struct ata_drive_datas *drvp;
|
2006-10-17 19:16:30 +04:00
|
|
|
int drive;
|
|
|
|
#if NATA_UDMA
|
|
|
|
int s;
|
|
|
|
#endif
|
2003-10-08 15:51:59 +04:00
|
|
|
u_int32_t idedma_ctl;
|
2004-08-20 03:25:35 +04:00
|
|
|
struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
|
|
|
|
struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
|
2003-10-08 15:51:59 +04:00
|
|
|
|
|
|
|
/* setup DMA if needed */
|
|
|
|
pciide_channel_dma_setup(cp);
|
|
|
|
|
|
|
|
idedma_ctl = 0;
|
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
for (drive = 0; drive < cp->ata_channel.ch_ndrive; drive++) {
|
2003-10-08 15:51:59 +04:00
|
|
|
drvp = &chp->ch_drive[drive];
|
|
|
|
/* If no drive, skip */
|
|
|
|
if ((drvp->drive_flags & DRIVE) == 0)
|
|
|
|
continue;
|
2006-10-17 17:45:05 +04:00
|
|
|
#if NATA_UDMA
|
2003-10-08 15:51:59 +04:00
|
|
|
if (drvp->drive_flags & DRIVE_UDMA) {
|
|
|
|
/* use Ultra/DMA */
|
2004-08-21 04:28:34 +04:00
|
|
|
s = splbio();
|
2003-10-08 15:51:59 +04:00
|
|
|
drvp->drive_flags &= ~DRIVE_DMA;
|
2004-08-21 04:28:34 +04:00
|
|
|
splx(s);
|
2003-10-08 15:51:59 +04:00
|
|
|
idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
|
2006-10-17 17:45:05 +04:00
|
|
|
} else
|
|
|
|
#endif /* NATA_UDMA */
|
|
|
|
if (drvp->drive_flags & DRIVE_DMA) {
|
2003-10-08 15:51:59 +04:00
|
|
|
idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing to do to setup modes; it is meaningless in S-ATA
|
|
|
|
* (but many S-ATA drives still want to get the SET_FEATURE
|
|
|
|
* command).
|
|
|
|
*/
|
|
|
|
if (idedma_ctl != 0) {
|
|
|
|
/* Add software bits in status register */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
|
2003-10-08 15:51:59 +04:00
|
|
|
idedma_ctl);
|
|
|
|
}
|
2006-10-17 17:45:05 +04:00
|
|
|
#endif /* NATA_DMA */
|
2003-10-08 15:51:59 +04:00
|
|
|
}
|