839. The kernel-side drivers take what they need as parameters
(The title and slug are provisional.)
Parked until milestone 1062 (the device control planes leave the kernel) lands (ruled 2026-11-10 UTC). Most of the kernel files below leave the kernel there, so this milestone is then cut to the drivers that remain in the kernel, or retired if none needs it.
Codebase rule 2 says a driver never reaches into a kernel global: it gets a base address, "later a
DMA allocator, later an interrupt registration". The driver crates underneath already obey it.
crates/e1000e takes its hardware through the DirectMemoryAccessRegion, Tails and pch::Hardware traits.
crates/designware_ethernet has Hw, Region, Tails and Mdio, and
crates/designware_mobile_storage has RegisterWindowAndClock. None of them names a kernel path or keeps a
static. The kernel files that wire those crates to a device do not obey it. This milestone moves the
three things they reach for into parameters: the device's base address, a DMA allocator, and an
IOMMU handle.
Reuse: nothing taken; the shape is the tree's own. crates/page_tables's Mapper already takes its frame
allocator as a closure, which milestone 774 (a page-table allocator that fails on its Nth call) cites
as rule 2 paying off. kernel/src/drivers/pl011.rs is constructed from a base address and knows
nothing else. A search of kernel/ and crates/ for an existing DMA-allocator or IOMMU trait
(grep -rn -E 'trait [A-Za-z]*(Dma|Alloc|Iommu)') found none.
Today
Measured on ea7a58d with grep -n -E 'crate::(pci|memory|iommu)::|^static '. Line numbers are
the tree's at that commit.
kernel/src/e1000e.rs (379 lines):
:97finds its own device withcrate::pci::find_e1000e_device().:91keepsstatic REGION: AtomicU64, so the DMA region outlives every caller and is found again by the next bring-up.:215allocates that region withcrate::memory::alloc_contiguous_zeroed.:218and:219callcrate::iommu::is_activeandcrate::iommu::confinedirectly.
kernel/src/virtual_io.rs (1,756 lines):
:16importsVIRTUAL_IO_MMIO_BASEfromarch::mmu;:52,:78and:192add slot offsets to it, and:62,:100and:186read the slot count frommmu::virtual_io_slots().:175callscrate::pci::find_block_device_n.:735allocates the shadow ring withcrate::memory::alloc_zeroed.:743to:750callcrate::iommu::is_active,virtual_io_regionsandconfineinsideregister, which has nine callers underkernel/src/user/and inuser.rs.:707keepsstatic DEVICES. See the correction below on why this one stays.
Two more files have the same three reaches, and the brief that raised this did not name them:
kernel/src/non_volatile_memory_express.rs::507(find_nvme_device),:510(alloc_contiguous_zeroed),:513,:538and:539(iommu).kernel/src/extensible_host_controller_interface.rs::82(find_xhci_device),:110and:111(iommu::scope_of,is_active),:116(alloc_contiguous_zeroed),:119(confine).
Leaving those two out would apply the rule to half the identical code, so they are in scope.
Two corrections to the premise
virtual_io.rs is not a driver, by its own header: it is bus enumeration plus the transport that
mediates a userspace driver's Object::Virtio capability. Its static DEVICES is the table those
capabilities index. That is kernel object state of the same kind as the scheduler's IPC tables, not
a driver's private global. This milestone leaves it where it is. The enumeration half and
register still take the base, the allocator and the IOMMU handle as parameters.
kernel/src/designware_ethernet.rs has the same shape too: :179 (static REGION), :194
(crate::memory::jh7110_ethernet) and :366 (alloc_contiguous_zeroed). It is left out because
nothing proves it under QEMU. Its only machine is the JH7110 on radon, so changing it means
somebody boots radon. It should become a proposal when this lands, with needs_person: yes.
The shape
The composition root is the service under kernel/src/user/ that calls each bring-up
(bring_up in e1000e_service.rs calls e1000e::bring_up). It finds the device, owns the region, and hands
both to the driver. So:
- Bring-up takes the device record the service found (
PciE1000eDeviceand its siblings already carry the base and the requester id), instead of callingcrate::pciitself. - Bring-up takes a DMA allocator. Its shape is the lane's call; a closure returning
Option<PageFrame>, asMappertakes, is the precedent and probably enough. - Bring-up takes an IOMMU handle that answers
is_active,scope_ofandconfine. Todaycrate::iommuis free functions over a global, so the handle is a new type. - The once-per-boot region moves from
e1000e.rs'sstatic REGIONto the service, which already refuses a second wiring while the first process lives. virtio's probe takes the window (base, stride, slot count and first interrupt) from its caller rather than fromarch::mmu.
Every new type is a name calef has not ruled on, so each ships provisional with a /// Name:
marker and the report says so.
Not in scope: mmu::phys_to_virt and arch::timer. They are arch services every driver reads, and
rule 2's own list puts interrupt registration and the like "later". Threading them through is a
separate argument.
Done when
- Outside
#[cfg(test)]code, this prints nothing:grep -n -E 'crate::(pci|memory|iommu)::' kernel/src/e1000e.rs kernel/src/virtual_io.rs kernel/src/non_volatile_memory_express.rs kernel/src/extensible_host_controller_interface.rs. kernel/src/e1000e.rshas nostatic, andvirtual_io.rsimports nothing fromarch::mmubutphys_to_virt.- The existing gates pass on aarch64, riscv64 and x86_64 with no test changed. That means the
e1000e gates in
notes/e1000e.md, the NVMe and xHCI gates, andvirtio's two IOMMU tests (the_iommu_faults_a_dma_that_escapes_the_domain,a_device_write_to_the_read_only_shadow_is_refused). - Both
virtiofalsification patches underkernel/falsifications/still apply and still fail the test they name. They patchkernel/src/iommu.rsandcrates/page_tables, so an IOMMU handle that moves code iniommu.rshas to carry them along. script/fastpath-footprintandscript/stack-frame-checkare unchanged; none of these paths is hot, so a change there is a finding.
What the seam buys
Today region_for in e1000e.rs and register in virtual_io.rs panic on an exhausted allocator with .expect. With the
allocator a parameter, a kernel test can hand in one that fails, the way milestone 774 does for page
tables. Turning those panics into refusals is the obvious next step. It changes behavior, so it is
not part of this refactor.
Index row
The driver crates already take their hardware through traits. The kernel files that wire them
(e1000e.rs, virtual_io.rs, the NVMe and xHCI bring-ups) do not: they find their own device on the
PCI bus, allocate DMA from crate::memory and confine it through crate::iommu, against codebase
rule 2. This passes the device record, a DMA allocator and an IOMMU handle in from the service that
wires each one. It leaves virtio's capability table in place, because that is kernel object state,
and defers the DesignWare Ethernet bring-up to a proposal, because only radon can prove it.