Home | History | Annotate | Download | only in pci
History log of /src/sys/dev/pci/pciide_common.c
RevisionDateAuthorComments
 1.72  16-Apr-2025  andvar Introduce the ATADEBUG_PCIIDE_MASK option to allow setting the
atadebug_pciide_mask variable, similar to the existing ATADEBUG_MASK
and ATADEBUG_WD_MASK options used in ata/ata.c and ata/wdc.c

No functional changes intended by default.

approved by bouyer.
 1.71  31-Mar-2024  thorpej As the final step in configuraing bus-master DMA, consult the boolean device
property "pciide-disable-dma" and disable bus-master DMA if that property is
present and true.
 1.70  20-Nov-2023  thorpej pciide_dma_dmamap_setup(): If we end up with a DMA segment with an odd
length or odd starting address, unload the map and return EINVAL. Some
controllers get really upset if a DMA segment has an odd address or length.
This can happen if a physio user performs a virtually-contiguous I/O that
starts at an odd address and spans a page boundary where the resulting
physical pages are discontiguous. The EINVAL return will cause the upper
layers in the ATA code to re-try the I/O using PIO, which should (will
in all of my tests) succeed.

PR port-alpha/56434
 1.69  20-Nov-2023  thorpej Revert previous. I'm going to make a slight change to the patch, and
want it collapsed into a single commit to make it easier to pull into
netbsd-10.
 1.68  20-Nov-2023  thorpej pciide_dma_dmamap_setup(): If we end up with a DMA segment with an odd
length, unload the map and return EIO. Some controllers get really upset
if a DMA segment has an odd length. This can happen if a physio user
performs a virtually-contiguous I/O that starts at an odd address and spans
a page boundary where the resulting physical pages are discontiguous.

Ultimately, it's up to the physio user to paint inside the lines, but this
will prevent the disk controller from wandering off into the weeds, at least.

PR port-alpha/56434
 1.67  24-Aug-2020  msaitoh branches: 1.67.20;
s/ressource/resource/. No functional change.
 1.66  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.65  20-Oct-2017  jdolecek branches: 1.65.2; 1.65.4;
move ata_queue_alloc(1) and ata_queue_free() calls to ata_channel_init()
and ata_channel_destroy() respectively, to make attachment code simpler,
and to make it easier to spot special queue manipulation like cmdide(4)

on topic of PR kern/52606
 1.64  17-Oct-2017  jdolecek reintroduce ATACH_IRQ_WAIT flag for attachments using wdcintr(), only
process the interrupt when the flag is set - this fixes spurious interrupt
during post-reset drive setup in wdc_ata_bio_start(), and wdc_atapi_start()

while those functions set WDCTL_IDS, this seems to be ignored by certain
(maybe all) PCI-IDE controllers; usually the implicit KERNEL_LOCK() would
prevent the interrupt anyway, but not when the start routine is started
from the atabus thread, which doesn't take it

fixes 'panic: wdc_ata_bio_intr: bad state' reported on current-users
by Chavdar Ivanov
 1.63  07-Oct-2017  jdolecek Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.62  13-Oct-2016  jdolecek branches: 1.62.4;
provide intr xname
 1.61  07-Jul-2016  msaitoh branches: 1.61.2;
KNF. Remove extra spaces. No functional change.
 1.60  29-Mar-2014  christos branches: 1.60.6;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.
 1.59  22-Jun-2013  matt branches: 1.59.2;
When allocating the channel queue, make sure the return memory is zeroed.
 1.58  14-Nov-2012  jakllsch don't attempt to re-unmap the interrupt on detach
 1.57  31-Jul-2012  bouyer branches: 1.57.2;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.56  26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.55  24-Jul-2012  jakllsch Revert dsl@'s changes of Sun, 15 Jul 2012 10:55:35 +0000 and
Sun, 15 Jul 2012 10:56:50 +0000, excepting the kernel version bump.
First step in reverting regressions to ata(4) subsystem during the addition of
port multiplier support.
 1.54  15-Jul-2012  dsl Some namespace protection (and add greppablity).
Prefix the DRIVE_ and DRIVET_ constants from atavar.h with ATA_.
Don't use an enum for drive_type - you don't know how big it will be.
Move driver_type to avoid implicit structure padding (esp on arm).
This change is purely lexical and mechanical.

Update to 6.99.9 - this wasn't done when the SATA PMP changes
were made - I'm sure they warranted a bump.
 1.53  02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.52  30-Jan-2012  drochner Use pci_aprint_devinfo(9) instead of pci_devinfo+aprint_{normal,naive}
where it looks straightforward, and pci_aprint_devinfo_fancy in a few
others where drivers want to supply their own device names instead
of the pcidevs generated one. More complicated cases, where names
are composed at runtime, are left alone for now. It certainly makes
sense to simplify the drivers here rather than inventing a catch-all API.
This should serve as as example for new drivers, and also ensure
consistent output in the AB_QUIET ("boot -q") case. Also, it avoids
excessive stack usage where drivers attach child devices because the
buffer for the device name is not kept on the local stack anymore.
 1.51  17-May-2011  dyoung branches: 1.51.4; 1.51.8;
PCI_FLAGS_IO_ENABLED and PCI_FLAGS_MEM_ENABLED changed their functional
role in NetBSD (drivers are no longer supposed to write these to
pa_flags) without changing name. Correct that.

Rename PCI_FLAGS_IO_ENABLED to PCI_FLAGS_IO_OKAY and
PCI_FLAGS_MEM_ENABLED to PCI_FLAGS_MEM_OKAY, thus making their names
consistent with the other PCI flags and poisoning 3rd-party driver
sources that use the flags in the old bad way.

This patch produces no binary changes in this set of PCI kernels when
they are compiled w/o 'options DIAGNOSTIC' and w/ -V MKREPRO=yes:

algor P4032 P5064 P6032
alpha GENERIC
amd64 GENERIC XEN3_DOM0
arc GENERIC
atari HADES MILAN-PCIIDE
bebox GENERIC
cats GENERIC
cobalt GENERIC
evbarm-el ADI_BRH ARMADILLO9 CP3100 GEMINI GEMINI_MASTER GEMINI_SLAVE
evbarm-el GUMSTIX HDL_G IMX31LITE INTEGRATOR IQ31244 IQ80310 IQ80321
evbarm-el IXDP425 IXM1200 KUROBOX_PRO
evbarm-el LUBBOCK MARVELL_NAS NAPPI NSLU2 SHEEVAPLUG SMDK2800 TEAMASA_NPWR
evbarm-el TEAMASA_NPWR_FC TS7200 TWINTAIL ZAO425
evbmips-el AP30 DBAU1500 DBAU1550 MALTA MERAKI MTX-1 OMSAL400 RB153 WGT624V3
evbmips64-el XLSATX
evbppc EV64260 MPC8536DS MPC8548CDS OPENBLOCKS200 OPENBLOCKS266
evbppc OPENBLOCKS266_OPT P2020RDB PMPPC RB800 WALNUT
hp700 GENERIC
i386 ALL XEN3_DOM0 XEN3_DOMU
ibmnws GENERIC
iyonix GENERIC
landisk GENERIC
macppc GENERIC
mvmeppc GENERIC
netwinder GENERIC
ofppc GENERIC
prep GENERIC
sandpoint GENERIC
sbmips-el GENERIC
sgimips GENERIC32_IP2x GENERIC32_IP3x
sparc GENERIC_SUN4U KRUPS
sparc64 GENERIC
 1.50  10-May-2011  dyoung Stop abuse of PCI_FLAGS_IO_ENABLED and PCI_FLAGS_MEM_ENABLED. The flags
specifically tell a driver that bridges upstream forward PCI I/O (or
memory) transactions to the device." Only bus drivers have any business
modifying these.
 1.49  04-Apr-2011  dyoung Neither pci_dma64_available(), pci_probe_device(), pci_mapreg_map(9),
pci_find_rom(), pci_intr_map(9), pci_enumerate_bus(), nor the match
predicate passed to pciide_compat_intr_establish() should ever modify
their pci_attach_args argument, so make their pci_attach_args arguments
const and deal with the fallout throughout the kernel.

For the most part, these changes add a 'const' where there was no
'const' before, however, some drivers and MD code used to modify
pci_attach_args. Now those drivers either copy their pci_attach_args
and modify the copy, or refrain from modifying pci_attach_args:

Xen: according to Manuel Bouyer, writing to pci_attach_args in
pci_intr_map() was a leftover from Xen 2. Probably a bug. I
stopped writing it. I have not tested this change.

siside(4): sis_hostbr_match() needlessly wrote to pci_attach_args.
Probably a bug. I use a temporary variable. I have not tested this
change.

slide(4): sl82c105_chip_map() overwrote the caller's pci_attach_args.
Probably a bug. Use a local pci_attach_args. I have not tested
this change.

viaide(4): via_sata_chip_map() and via_sata_chip_map_new() overwrote the
caller's pci_attach_args. Probably a bug. Make a local copy of the
caller's pci_attach_args and modify the copy. I have not tested
this change.

While I'm here, make pci_mapreg_submap() static.

With these changes in place, I have tested the compilation of these
kernels:

alpha GENERIC
amd64 GENERIC XEN3_DOM0
arc GENERIC
atari HADES MILAN-PCIIDE
bebox GENERIC
cats GENERIC
cobalt GENERIC
evbarm-eb NSLU2
evbarm-el ADI_BRH ARMADILLO9 CP3100 GEMINI GEMINI_MASTER GEMINI_SLAVE GUMSTIX
HDL_G IMX31LITE INTEGRATOR IQ31244 IQ80310 IQ80321 IXDP425 IXM1200
KUROBOX_PRO LUBBOCK MARVELL_NAS NAPPI SHEEVAPLUG SMDK2800 TEAMASA_NPWR
TEAMASA_NPWR_FC TS7200 TWINTAIL ZAO425
evbmips-el AP30 DBAU1500 DBAU1550 MALTA MERAKI MTX-1 OMSAL400 RB153 WGT624V3
evbmips64-el XLSATX
evbppc EV64260 MPC8536DS MPC8548CDS OPENBLOCKS200 OPENBLOCKS266
OPENBLOCKS266_OPT P2020RDB PMPPC RB800 WALNUT
hp700 GENERIC
i386 ALL XEN3_DOM0 XEN3_DOMU
ibmnws GENERIC
macppc GENERIC
mvmeppc GENERIC
netwinder GENERIC
ofppc GENERIC
prep GENERIC
sandpoint GENERIC
sgimips GENERIC32_IP2x
sparc GENERIC_SUN4U KRUPS
sparc64 GENERIC

As of Sun Apr 3 15:26:26 CDT 2011, I could not compile these kernels
with or without my patches in place:

### evbmips-el GDIUM

nbmake: nbmake: don't know how to make /home/dyoung/pristine-nbsd/src/sys/arch/mips/mips/softintr.c. Stop

### evbarm-el MPCSA_GENERIC
src/sys/arch/evbarm/conf/MPCSA_GENERIC:318: ds1672rtc*: unknown device `ds1672rtc'

### ia64 GENERIC

/tmp/genassym.28085/assym.c: In function 'f111':
/tmp/genassym.28085/assym.c:67: error: invalid application of 'sizeof' to incomplete type 'struct pcb'
/tmp/genassym.28085/assym.c:76: error: dereferencing pointer to incomplete type

### sgimips GENERIC32_IP3x

crmfb.o: In function `crmfb_attach':
crmfb.c:(.text+0x2304): undefined reference to `ddc_read_edid'
crmfb.c:(.text+0x2304): relocation truncated to fit: R_MIPS_26 against `ddc_read_edid'
crmfb.c:(.text+0x234c): undefined reference to `edid_parse'
crmfb.c:(.text+0x234c): relocation truncated to fit: R_MIPS_26 against `edid_parse'
crmfb.c:(.text+0x2354): undefined reference to `edid_print'
crmfb.c:(.text+0x2354): relocation truncated to fit: R_MIPS_26 against `edid_print'
 1.48  17-Nov-2010  dholland branches: 1.48.2;
Fix build when NATA_DMA is 0.
 1.47  13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.46  06-Nov-2010  jakllsch Rework pciide(4) detachment to take the legacy interrupt mapping into
consideration and avoid future code duplication.

Ports wanting to enable detachment of controllers with compatibility-mapped
channels will need to supply a pciide_machdep_compat_intr_disestablish()
function.
 1.45  05-Nov-2010  jakllsch Correct copy/paste error in as-of-yet-unused pciide_common_detach().
 1.44  05-Nov-2010  jakllsch Pave the way for detachment of pciide(4)-family ATA controllers.
 1.43  19-Oct-2009  bouyer branches: 1.43.2; 1.43.4;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.42  23-Aug-2009  jmcneill Print device description on the same line as locators.
 1.41  15-Mar-2009  cegger ansify function definitions
 1.40  14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.39  14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.38  18-Mar-2008  cube branches: 1.38.4; 1.38.12; 1.38.18;
Split device_t and softc for ATA devices, as well as wd(4). Other
cosmetic changes where appropriate.
 1.37  04-Mar-2007  christos branches: 1.37.16; 1.37.32; 1.37.36;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.36  09-Feb-2007  ad branches: 1.36.2;
Merge newlock2 to head.
 1.35  16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.34  17-Oct-2006  itohy Silence unused variable warning.
 1.33  17-Oct-2006  itohy Make pciide(4)-only configurations (without other DMA-capable driver) compile.
 1.32  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.31  29-Mar-2006  thorpej branches: 1.31.8; 1.31.10;
Use device_cfdata().
 1.30  17-Jan-2006  bouyer branches: 1.30.2; 1.30.4; 1.30.6; 1.30.8; 1.30.10;
Add missing ch_ndrive initialisations. Pointed out by Juan RP.
 1.29  04-Jan-2006  bouyer Fix forcing use of DMA mode for the generic pciide driver: default_chip_map()
is called from pciide_attach() and at this point we don't know which drives
are here. Just assume all drives are there and allocate DMA ressources for
all of them.
 1.28  11-Dec-2005  christos branches: 1.28.2;
merge ktrace-lwp.
 1.27  29-May-2005  christos branches: 1.27.2;
Add a const.
 1.26  27-Feb-2005  perry branches: 1.26.2;
nuke trailing whitespace
 1.25  15-Feb-2005  briggs Allow MAXPHYS-sized instead of IDEDMA_BYTE_COUNT_MAX-sized transfers
to be described by a transfer table.
 1.24  15-Feb-2005  briggs Move the definition of NIDEDMA_TABLES from pciidereg.h to be closer to
its only user in pciide_common.c. Also redefine NIDEDMA_TABLES to match
the max DMA transfer size specified in the call to bus_dmamap_create()
(IDEDMA_BYTE_COUNT_MAX instead of MAXPHYS).
The macro is also redefined to handle devices that have a PAGE_SIZE greater
than sc_dma_maxsegsz (buggy revision of satalink 3112 on ibm4xx).
 1.23  04-Feb-2005  perry de-__P
 1.22  24-Nov-2004  bouyer branches: 1.22.4; 1.22.6;
Move bus_dma setup out of pciide_dma_init() in a new function,
pciide_dma_dmamap_setup(), for the benefit of drivers that needs special
registers setup in dmainit().
 1.21  21-Aug-2004  thorpej atastart() (called only at splbio(), and from interrupts) can change
drive_flags, to make sure all drive_flags manipulations are done at
splbio().
 1.20  20-Aug-2004  thorpej Move most of wdc_softc into a new atac_softc structure that contains
info common to all types of ATA controllers.
 1.19  19-Aug-2004  thorpej - Add and use a CHAN_TO_WDC() macro to get the wdc_softc from an
ata_channel.
- Add and use a CHAN_TO_WDC_REGS() macro to get the wdc_regs from an
ata_channel.
- Add and use a CHAN_TO_PCIIDE() macro to get the pciide_softc from an
ata_channel.
- Add and use a CHAN_TO_PCHAN() macro to get the pciide_channel from an
ata_channel. (This one just hides a cast, and is really just for
consistency with the others.)
 1.18  16-Aug-2004  enami Dereference ch_wdc after filled.
 1.17  14-Aug-2004  thorpej - Split the register handles out of struct wdc_channel into a separate
wdc_regs structure, and array of which (indexed per channel) is pointed
to by struct wdc_softc.
- Move the resulting wdc_channel structure to atavar.h and rename it to
ata_channel. Rename the corresponding flags.
- Add a "ch_ndrive" member to struct ata_channel, which indicates the
maximum number of drives that can be present on the channel. For now,
this is always 2. Add an ATA_MAXDRIVES constant that places an upper
limit on this value, also currently 2.
 1.16  13-Aug-2004  thorpej WDCDEBUG -> ATADEBUG.
 1.15  13-Aug-2004  thorpej Don't bother with bits that tell of the presence of optional callbacks;
just check the function pointers for NULL.
 1.14  02-Aug-2004  bouyer branches: 1.14.2;
Make it possible for (*dma_finish)() to abort quietly a DMA op. Use this
in wdc_reset_channel().
 1.13  02-Aug-2004  bouyer Don't map the interrupt in pciide_mapregs_compat().
In default_chip_map() we'll do further checks to see if the channel should
really be enabled, and in case it's not we would keep the interrupt mapped.
Fix kern/26502 from Christian Biere.
 1.12  04-Jun-2004  bouyer Don't try to bus_space_subregion() registers that didn't get mapped.
Problem reported and fix tested by Kurt Schreiner on port-alpha.
 1.11  25-May-2004  thorpej Add the notion of "shadow registers" to the wdc driver. These shadow
registers are registers that overlap with others on many controllers, but
which may actually be distinct on some controllers. Right now, the two
shadows are:

- wd_status (usually overlaps wd_command)
- wd_features (usually overlaps wd_error)

Add a new helper function, wdc_init_shadow_regs(), used to initialize
the shadow register handles on controllers where they do actually overlap.

Partially from Jordan Rhody @ Wasabi Systems, Inc.
 1.10  05-May-2004  bouyer default_chip_map(): We can't use pciide_mapchan() here, because
pciide_mapchan() will attach an atabus, and we don't know yet if this
channel is enabled or not.
Fix kern/25455 by Dave Huang.
 1.9  23-Apr-2004  itojun pass string length (= boundary info) to pci_devinfo so that we do not run over
the end of memory region
 1.8  03-Jan-2004  thorpej branches: 1.8.2;
More wdc_channel structure member namespace cleanup:
- channel -> ch_channel
- wdc -> ch_wdc
 1.7  03-Jan-2004  thorpej Rename "struct channel_softc" to "struct wdc_channel".
 1.6  01-Jan-2004  thorpej Rename:
- wdc_xfer to ata_xfer
- channel_queue to ata_queue
and move them to <dev/ata/atavar.h> so they can be used by non-wdc ATA
controllers. Clean up the member names of these structures while at it.
 1.5  19-Dec-2003  thorpej Some controllers must have certain bits always be set in the IDEDMA_CMD
register for proper operation. Add a prototype field in the pciide_channel
for this register and use it as necessary when writing the IDEDMA_CMD
register.
 1.4  19-Dec-2003  thorpej Move the PCIIDE_OPTIONS_* constants into pciidevar.h
 1.3  27-Nov-2003  fvdl 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).
 1.2  23-Oct-2003  bouyer If we found a compat channel disabled, unmap the registers. There may be
an ISA IDE adapter at the same address.
 1.1  08-Oct-2003  bouyer Split pciide in per-chip family driver, as proposed in
http://mail-index.netbsd.org/tech-kern/2003/09/25/0007.html
We now have:
acardide* at pci? dev ? function ? # Acard IDE controllers
aceride* at pci? dev ? function ? # Acer Lab IDE controllers
cmdide* at pci? dev ? function ? # CMD tech IDE controllers
cypide* at pci? dev ? function ? # Cypress IDE controllers
hptide* at pci? dev ? function ? # Triones/HighPoint IDE controllers
optiide* at pci? dev ? function ? # Opti IDE controllers
piixide* at pci? dev ? function ? # Intel IDE controllers
pdcide* at pci? dev ? function ? # Promise IDE controllers
siside* at pci? dev ? function ? # SiS IDE controllers
slide* at pci? dev ? function ? # Symphony Labs IDE controllers
viaide* at pci? dev ? function ? # VIA/AMD/Nvidia IDE controllers
pciide* at pci? dev ? function ? flags 0x0000 # GENERIC pciide driver

serverworks driver not commited yet; there are still copyright issues about
it.
 1.8.2.3  11-Aug-2004  jmc branches: 1.8.2.3.2;
Pullup rev 1.13 (requested by bouyer in ticket #734)

Don't map the interrupt in pciide_mapregs_compat().
In default_chip_map() we'll do further checks to see if the channel should
really be enabled, and in case it's not we would keep the interrupt mapped.
PR#26502
 1.8.2.2  05-Jun-2004  jmc Pullup rev 1.12 (requested by bouyer in ticket #443)

Don't try to bus_space_subregion() registers that didn't get mapped.
 1.8.2.1  09-May-2004  jdc Pull up revision 1.10 (requested by bouyer in ticket #267)

default_chip_map(): We can't use pciide_mapchan() here, because
pciide_mapchan() will attach an atabus, and we don't know yet if this
channel is enabled or not.
Fix kern/25455 by Dave Huang.
 1.8.2.3.2.2  05-Jan-2006  riz Pull up following revision(s) (requested by bouyer in ticket #10212):
sys/dev/pci/pciide_common.c: revision 1.29 via patch
Fix forcing use of DMA mode for the generic pciide driver: default_chip_map()
is called from pciide_attach() and at this point we don't know which drives
are here. Just assume all drives are there and allocate DMA ressources for
all of them.
 1.8.2.3.2.1  16-Mar-2005  tron Pull up revision 1.22 (requested by bouyer in ticket #1016):
Move bus_dma setup out of pciide_dma_init() in a new function,
pciide_dma_dmamap_setup(), for the benefit of drivers that needs special
registers setup in dmainit().
 1.14.2.10  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.14.2.9  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.14.2.8  15-Feb-2005  skrll Sync with HEAD.
 1.14.2.7  04-Feb-2005  skrll Sync with HEAD.
 1.14.2.6  29-Nov-2004  skrll Sync with HEAD.
 1.14.2.5  21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.4  18-Sep-2004  skrll Sync with HEAD.
 1.14.2.3  25-Aug-2004  skrll Sync with HEAD.
 1.14.2.2  03-Aug-2004  skrll Sync with HEAD
 1.14.2.1  02-Aug-2004  skrll file pciide_common.c was added on branch ktrace-lwp on 2004-08-03 10:49:11 +0000
 1.22.6.2  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.22.6.1  12-Feb-2005  yamt sync with head.
 1.22.4.1  29-Apr-2005  kent sync with -current
 1.26.2.1  05-Jan-2006  riz Pull up following revision(s) (requested by bouyer in ticket #1087):
sys/dev/pci/pciide_common.c: revision 1.29
Fix forcing use of DMA mode for the generic pciide driver: default_chip_map()
is called from pciide_attach() and at this point we don't know which drives
are here. Just assume all drives are there and allocate DMA ressources for
all of them.
 1.27.2.5  24-Mar-2008  yamt sync with head.
 1.27.2.4  03-Sep-2007  yamt sync with head.
 1.27.2.3  26-Feb-2007  yamt sync with head.
 1.27.2.2  30-Dec-2006  yamt sync with head.
 1.27.2.1  21-Jun-2006  yamt sync with head.
 1.28.2.2  01-Feb-2006  yamt sync with head.
 1.28.2.1  15-Jan-2006  yamt sync with head.
 1.30.10.1  31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.30.8.1  19-Apr-2006  elad sync with head.
 1.30.6.1  01-Apr-2006  yamt sync with head.
 1.30.4.1  22-Apr-2006  simonb Sync with head.
 1.30.2.1  09-Sep-2006  rpaulo sync with head
 1.31.10.2  10-Dec-2006  yamt sync with head.
 1.31.10.1  22-Oct-2006  yamt sync with head
 1.31.8.3  06-Feb-2007  ad Quiten noisy boot messages.
 1.31.8.2  06-Feb-2007  ad Quieten noisy boot messages.
 1.31.8.1  18-Nov-2006  ad Sync with head.
 1.36.2.1  12-Mar-2007  rmind Sync with HEAD.
 1.37.36.1  03-Apr-2008  mjf Sync with HEAD.
 1.37.32.1  24-Mar-2008  keiichi sync with head.
 1.37.16.1  23-Mar-2008  matt sync with HEAD
 1.38.18.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.38.12.1  28-Apr-2009  skrll Sync with HEAD.
 1.38.4.3  11-Mar-2010  yamt sync with head
 1.38.4.2  16-Sep-2009  yamt sync with head
 1.38.4.1  04-May-2009  yamt sync with head.
 1.43.4.3  31-May-2011  rmind sync with head
 1.43.4.2  21-Apr-2011  rmind sync with head
 1.43.4.1  05-Mar-2011  rmind sync with head
 1.43.2.1  06-Nov-2010  uebayasi Sync with HEAD.
 1.48.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.51.8.1  18-Feb-2012  mrg merge to -current.
 1.51.4.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.51.4.3  16-Jan-2013  yamt sync with (a bit old) head
 1.51.4.2  30-Oct-2012  yamt sync with head
 1.51.4.1  17-Apr-2012  yamt sync with head
 1.57.2.4  03-Dec-2017  jdolecek update from HEAD
 1.57.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.57.2.2  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.57.2.1  09-Oct-2012  bouyer Support transfers of up to MACHINE_MAXPHYS in all pciide variants, and ahci.
wd(4) limits its maxphys depending on the drives's capability (64k sectors
for LBA48, 256 sectors for LBA and 128 sectors for older devices).

I assumed all pciide controllers could do MACHINE_MAXPHYS transfers, but
this may not be true. The capabilities of each controller variants should be
looked at more closely.
 1.59.2.1  18-May-2014  rmind sync with head
 1.60.6.2  05-Dec-2016  skrll Sync with HEAD
 1.60.6.1  09-Jul-2016  skrll Sync with HEAD
 1.61.2.1  04-Nov-2016  pgoyette Sync with HEAD
 1.62.4.3  27-Sep-2017  jdolecek change wdc_init_shadow_regs() to accept only struct wdc_regs, it doesn't
touch anything else

factor out the probe-only struct ata_channel initialization to wdcprobe(), to
reduce duplication of logic in individual drivers, and to actually work now
that more init is needed beyond the memset()
 1.62.4.2  12-Aug-2017  jdolecek remove all logic around ATACH_IRQ_WAIT and channel-global ch_error/ch_status,
so that there is less hidden state shared by commands; primary intent is
to make the NCQ and non-NCQ paths more similar, and remove possibility
of incorrect handling for the NCQ commands

tested both disk and ATAPI - piixide(4) on QEMU, and siisata(4),
ahcisata(4), mvsata(4) on real hw
 1.62.4.1  10-Apr-2017  jdolecek ATA infrastructure improvements to eventually support more outstanding
commands

patch by Matt Thomas
 1.65.4.1  10-Jun-2019  christos Sync with HEAD
 1.65.2.1  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.67.20.1  26-Nov-2023  bouyer Pull up following revision(s) (requested by thorpej in ticket #470):
sys/dev/pci/pciide_common.c: revision 1.70
pciide_dma_dmamap_setup(): If we end up with a DMA segment with an odd
length or odd starting address, unload the map and return EINVAL. Some
controllers get really upset if a DMA segment has an odd address or length.
This can happen if a physio user performs a virtually-contiguous I/O that
starts at an odd address and spans a page boundary where the resulting
physical pages are discontiguous. The EINVAL return will cause the upper
layers in the ATA code to re-try the I/O using PIO, which should (will
in all of my tests) succeed.
PR port-alpha/56434

RSS XML Feed