roadmap BUILT

165. x86_64 PCI enumeration: wire kernel/src/pci.rs to ACPI's MCFG

BUILT. Of the three things it owed, two are built elsewhere (PCI interrupt routing by milestone 215 (a PCI function's interrupt reaches nothing on x86_64), VT-d by milestone 161's item 6). The third, a real BAR placement, is closed below, measured under real firmware.

It checks whether x86_64 can reach a real-hardware data point for DECISIONS §86 (whether an NVMe driver can leave the kernel) faster and cheaper than a from-scratch JH7110 driver would. The reason to expect so: x86's PCIe discovery is ACPI-described and architecturally identical between QEMU's q35 and real x86 hardware (unlike RISC-V's QEMU-only fake ECAM device).

It needed no system call surface, new dependency or decision section of its own. What it unblocks (real NVMe-behind-IOMMU on x86) is gated on VT-d, item 6 of milestone 161, which is built.

The gap, as notes/x86-port.md already named it

Milestone 161 (the x86_64 kernel port) landed real ACPI table parsing (the RSDP scan, the root table walk, the MADT, and the MCFG) against real hardware evidence (the Dell OptiPlex 7050 Micro, milestone 87 (the x86_64 bare-metal machine)). notes/x86-port/acpi-and-pci.md's "discovery seam" section recorded the gap this milestone closes: "The PCIe ECAM window the MCFG describes is exactly the constant arch::mmu::PCI_ECAM_PHYS hardcodes... The constant should come from here rather than being checked against here, and doing that is a line of code once something consumes it." kernel/src/pci.rs itself said the same thing at its own probe: "A machine whose tree has no such node... answers every probe here with nobody home", true of x86_64 unconditionally, since it has no device tree at all.

What was built

  1. The seam. memory::record_pci_regions fills memory::pci_regions() directly (the same static every probe in pci.rs already reads), the x86_64 counterpart of how memory::init fills it from a pci-host-ecam-generic device-tree node on the other two architectures. Called once from main.rs's boot tour, right after read_acpi, with the ECAM window from ACPI's MCFG and a hardcoded BAR window (see the BAR paragraph below).

  2. The real complication, found by measurement rather than assumed away. Reading ACPI's MCFG is not sufficient by itself. QEMU's monitor was used to check directly (xp on the physical address the MCFG names, before any kernel code ran): the address faults ("Cannot access memory"), not the all-ones an absent PCI device would read. The chipset's ECAM decode is off until something programs the host bridge's PCIEXBAR register (offset 0x60 in bus 0, device 0, function 0's configuration space). A real BIOS or UEFI does this before ever handing control to an OS, and PVH (the protocol this port boots through) is a hypervisor entry point, not firmware, so nothing has. arch::x86_64::machine::enable_pcie_ecam programs it through the legacy CONFIG_ADDRESS/CONFIG_DATA ports (0xcf8/0xcfc, already-existing primitives in arch::x86_64::port, written for exactly this and unused until now). The same address was then confirmed, still via the monitor, to read the host bridge's own vendor/device id (8086:29c0) once the register was enabled. This is very likely a PVH-only step: real firmware (what milestone 87's OptiPlex will boot through) does this already, and rewriting the same base to the same value there should be a no-op. It is written unconditionally rather than assumed so this port does not depend on that being true.

  3. The BAR window is hardcoded, not discovered, and this is a real, permanent limitation rather than a temporary gap. ACPI's MCFG names only the ECAM window. The 32-bit MMIO window BARs live in the PCI host bridge's _CRS object on a real ACPI machine, which is AML, and this kernel has no AML interpreter (notes/x86-port/acpi-and-pci.md's own "What is deliberately not decoded"). arch::x86_64::mmu::PCI_BAR_PHYS is a hardcoded constant (0xc000_0000, q35's conventional PCI hole), confirmed disjoint from RAM, ECAM, the HPET and both APICs by reading QEMU's info mtree. It is not exercised by an actual BAR placement: no PCI function that needs one is on the bus under the current runner (see below).

  4. Proof, under QEMU's q35. kernel::pci::tests::acpi_mcfg_wires_a_real_ecam_window_that_finds_the_host_bridge (new, x86_64-only) enumerates the bus through the ACPI-sourced, now-enabled ECAM window. It asserts it finds q35's own host bridge (bus 0, device 0, function 0, vendor 8086, device 29c0), a chipset function present regardless of what -device flags the runner does or does not pass. script/test on all three architectures: aarch64 295/1, riscv64 298/1, x86_64 99/6 (one skip converted to one pass versus the pre-existing baseline; no regressions). script/lint green.

What was not built, and what this means for §86, in appendices

What 2026-09-02 found, and what it corrects

Three things, and the first of them is why this block did not stay closed as a wiring exercise.

The first, the ACPI walk refusing every table on a machine with real RAM, is told in acpi-walk-bound.md with the gate that now watches for it.

The PCIEXBAR write was unconditional, and the fault that justified it does not reproduce

enable_pcie_ecam wrote the register unconditionally with a 256 MiB length field, reasoning (in this block, above) that rewriting the same base under real firmware "should be a no-op". It is a no-op only if the length agrees too. Firmware may size the window at 128 or 64 MiB, and the write then widens the chipset's decode over whatever physical addresses sit above it, which on xenon is discovered at a null modem. Chipsets that lock the register after firmware writes it are the other half: there the write is dropped and only a read back would ever say so.

It now reads first, treats "enabled at the base the MCFG itself reports" as firmware's own work, and writes only otherwise, with the length derived from the MCFG's bus count. A bus count the register cannot encode leaves the window as found and says so.

And the measurement above is corrected. Re-measured on QEMU 11.1.1 from inside the guest, which is the side being served, the register reads 0xb0000001 on the PVH path before anything writes it. The whole suite's PCI half (the MCFG witness, NVMe, both userspace PCIe driver tests) passes with this function writing nothing. The monitor still answers "Cannot access memory" at that address on the same boot, so the monitor and the guest disagree, and this block's original reading of the monitor as evidence about the guest's decode does not hold. Nothing needs to decide whether QEMU changed or the inference was always wrong, because the register is asked rather than assumed. The consequence to record is that the writing arm is now unexercised on both paths this kernel boots, and stays for the machine that genuinely arrives with the decode off.

The BAR window: measured under real firmware, and it is not a corner case

Item 3 above called the hardcoded BAR window "a real, permanent limitation" and noted it was not exercised by an actual placement. It is exercised now (milestone 215 drives a virtio-blk-pci disk whose BARs this kernel places), so the open question changed shape. Not whether the placement works, but how much of the machine it moves, and whether the place it moves things to is free there.

pci::bar_census (provisional name) answers both in one read-only pass of config space, printed on the x86 boot line: functions on the bus, and functions carrying a BAR outside the window mmu::map_everything maps. Measured 2026-09-02: 5 of 8 under PVH, 3 of 6 under OVMF, 4 of 7 with a virtio-blk-pci disk attached. Real firmware placing the addresses does not change the shape of the problem, only which addresses, and place_bars relocates them all into PCI_BAR_PHYS (0xc000_0000, 2 MiB mapped), a constant checked once against QEMU's info mtree.

That is the number to read first on xenon's first boot: a machine whose RAM reaches above 0xc000_0000 would have this kernel move most of its bus on top of memory, and the line says so before anything is driven.

Two decisions this block had left open, now made

What is proven where

On patagonia, under QEMU: enumeration through an ACPI-sourced ECAM window on both boot paths, including one where the MCFG's base (0xe0000000) differs from the constant, and including tables read at a physical address a real machine would use. Real firmware leaving the ECAM decode already enabled, so this kernel writes nothing. A count of how much of the bus this kernel relocates, under both firmware and no firmware.

Only xenon can confirm: that PCI_BAR_PHYS is free on that machine, which is the census's whole point. That its firmware presents an MCFG with first bus 0 and a bus count PCIEXBAR can encode. And that its ACPI tables are below 4 GiB, which every machine's are and none promises.

One of milestone 215's three xenon-only questions is now half answered. That block owed "that a real function's MSI-X table is reachable once firmware rather than this kernel has placed its BARs". Under OVMF firmware does place them, and the census says where: outside this kernel's window, so place_bars moves them and the MSI-X table is reached through the kernel's own address rather than firmware's. What is still unproven is the same thing on silicon, and the reason it cannot be proven here is the handoff below. When this was written the suite did not run under real firmware, only the tour did. Milestone 195 (finish the UEFI boot path) now runs it under OVMF.

What is owed

Follow-on

Index row

Scoped as a parallel check on whether x86_64 reaches a real-hardware data point for DECISIONS §86 faster than a from-scratch JH7110 PCIe driver would. Wires memory::pci_regions() from ACPI's MCFG instead of a device-tree node, and finds a real complication along the way. PVH boots run no firmware, so nothing has enabled the chipset's ECAM decode, which this milestone does itself (measured on QEMU's monitor: the address faults until the host bridge's PCIEXBAR register is programmed). Proven under q35: real PCI enumeration finds the machine's own host bridge over the ACPI-sourced window. Does not reach §86's confinement half: x86 had no IOMMU driver when this was raised, so a real NVMe-behind-IOMMU data point was gated on VT-d, not on anything here. VT-d landed 2026-08-25 as milestone 161's item 6 (the x86_64 kernel port). Closed 2026-09-02, and the thing that kept it open was not the wiring: the ACPI walk bounded itself at 1 GiB while boot.s's direct map covers 4, and both runners passed -m 256M, so firmware's tables fit and every gate passed. At 2 GiB under OVMF the same kernel found no ACPI at all, so no APIC, no timer, no PCI and no VT-d, which was unconditional on any real machine. The UEFI gate now boots where firmware's tables are high, and the PCIEXBAR write reads before it writes so it cannot widen a window firmware sized. pci::bar_census prints how much of the bus this kernel relocates into its hardcoded BAR window (5 of 8 under PVH, 3 of 6 under OVMF).