Skip to content

ata: reuse firmware-configured DMA with PIO fallback - #128

Merged
FengHeting merged 1 commit into
ViudiraTech:developfrom
FengHeting:pata-dma
Nov 4, 2026
Merged

FengHeting merged 1 commit into
ViudiraTech:developfrom
FengHeting:pata-dma

Conversation

@FengHeting

Copy link
Copy Markdown
Contributor

Summary

The PATA driver sent SET FEATURES to put the drive into UDMA/MWDMA but never programmed the chipset timing registers, so DMA did not work on real hardware. This reuses the mode the firmware already paired between the drive and the host, without vendor-specific timing code.

  • ATA/ATAPI drives with DMA in IDENTIFY and a bus-master BAR4 are DMA candidates.
  • Each candidate is validated once at boot by reading the same sectors with PIO and DMA and comparing the buffers.
  • A failed validation, missing BAR4, or runtime bus-master error permanently drops the drive to PIO. ATA retries the same request in PIO; ATAPI resumes READ(12) from the completed offset; a stuck BSY resets the channel and drops both drives on it.
  • ATAPI capacity probing follows REQUEST SENSE retries and maps a missing medium to -ENOMEDIUM.

Scope

Only the PATA (IDE-interface) driver changes. There is no SET FEATURES, no UDMA/MWDMA negotiation, and no vendor timing programming; full-speed DMA still needs chipset-specific support.

Testing

  • make -j$(nproc) passes.
  • QEMU PIIX3 + OVMF: ATA disk and ATAPI CD are detected, partitions/files read correctly, and the [DMA]/[PIO] mode is logged.
  • The DMA validation failure path was exercised; the same request completes through PIO.

The firmware pairs its host timing with the drive's DMA mode.  Probe each
drive without sending SET FEATURES or programming vendor timing registers,
then compare a PIO and a DMA read of the same sectors once at boot.  A
failed check, a missing BAR4, or a runtime bus-master error drops the drive
to PIO; ATA retries the same request in PIO, ATAPI resumes from the
completed offset, and a stuck BSY resets the channel.

ATAPI capacity probing follows REQUEST SENSE retries and maps a missing
medium to -ENOMEDIUM.

Signed-off-by: MicroFish <2609948707@qq.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@FengHeting
FengHeting merged commit b1c5843 into ViudiraTech:develop Nov 4, 2026
2 checks passed
@FengHeting
FengHeting deleted the pata-dma branch November 5, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant