]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
feat: Fase 9 — ATA Bus Master IDE DMA for read/write
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 10:37:38 +0000 (07:37 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:20:50 +0000 (23:20 -0300)
commit237463d3063093fdd07fbaa61ed76ac041a40f6a
treefabb8e72f4bfd3633c5b301dce326cbb1490c27a
parent629bb6d6b3717f0fa0a4abbc044f8fd330551754
feat: Fase 9 — ATA Bus Master IDE DMA for read/write

Implement Bus Master IDE DMA as a transparent upgrade over PIO:

- New ata_dma.c: Bus Master IDE DMA driver for PIIX3 IDE controller
  - Finds IDE controller via PCI class 0x01:0x01
  - Reads BAR4 for Bus Master I/O base, enables PCI bus mastering
  - Allocates PRDT and bounce buffer pages at dedicated VAs
    (0xC0220000/0xC0221000) to avoid heap VA collisions
  - Polling-based DMA completion (BSY clear + BM Active clear)
  - IRQ 14 handler with dma_active flag to prevent race between
    IRQ handler and polling loop on ATA status register
  - spin_lock (not irqsave) for serialization — PIIX3 requires
    interrupt delivery for DMA completion signaling

- Modified ata_pio.c: transparent DMA upgrade
  - ata_pio_init_primary_master registers IRQ 14 handler early
    (before IDENTIFY) to prevent INTRQ storm
  - Calls ata_dma_init after IDENTIFY to probe for DMA capability
  - ata_pio_read28/write28 delegate to DMA when available,
    fall back to PIO if DMA init failed

- New include/ata_dma.h: public API header

Key bugs fixed during development:
- hal_mm_phys_to_virt can map PMM pages into heap VA range
  (phys 0x10000000 -> virt 0xD0000000 = heap base) — use
  dedicated VAs instead
- ATA INTRQ must be deasserted by reading status register;
  without IRQ handler, unacknowledged INTRQ causes interrupt storm
- nIEN must be cleared before DMA so device asserts INTRQ
- DMA direction bit must be set before Start bit per ATA spec

Tested: 4-CPU (25s) and 1-CPU (45s) pass all init.elf tests
including diskfs getdents and /persist/counter.
include/ata_dma.h [new file with mode: 0644]
src/hal/x86/ata_dma.c [new file with mode: 0644]
src/hal/x86/ata_pio.c