interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / disk / README.md

128 lines · 8784 bytes Raw Blame History Rendered
1# native/disk: AIENOS disk layer in C
2
3- `disk.h` / `disk.c`: the `disk_dev` contract (512 or 4096 byte blocks),
4 bounds checks, splitting by `max_blocks_per_io`, and an ordered 32-entry
5 queue with flush barriers and fail-stop.
6- `disk_file.c`: hosted file backend (pread/pwrite) with a power-cut
7 injector, used by the tests. It is not part of the freestanding library.
8- `disk_nvme.h` / `disk_nvme.c`: freestanding polled NVMe driver ported from
9 `crates/aienos-kernel/src/nvme*.rs` and `docs/P3_NVME_*.md`. It does not use
10 libc or a heap. Platform access goes through `nvme_ops`, and DMA goes
11 through one caller region carved into fixed pages plus a bounce buffer.
12- `disk_sdhci.h` / `disk_sdhci.c`: freestanding polled SD Host Controller
13 driver for the Raspberry Pi 5 microSD slot (BCM2712 `brcm,bcm2712-sdhci`,
14 a standard SDHCI). PIO only: no DMA, no heap, no libc, aligned 32-bit
15 register access only. SD 2.0+ cards (SDSC and SDHC/SDXC), 3.3 V, 25 MHz
16 default speed, 1- or 4-bit bus.
17- `qemu/`: bare-metal AArch64 payloads that run the NVMe driver against
18 QEMU's emulated NVMe (`scripts/qemu_native_nvme_test.sh`) and the SD
19 driver against QEMU's `sdhci-pci` + `sd-card`
20 (`scripts/qemu_native_sdhci_test.sh`: spec 2.00 with a 64 MiB SDSC card,
21 spec 3.00 with a 4 GiB SDHC card). `STORE_OBJS=` links
22 extra objects (for example native/store) later.
23
24```
25make # out/libaienos_disk.a (disk.c, disk_nvme.c, disk_sdhci.c) + out/disk_file.o
26make test # last line: AIENOS_DISK_NATIVE: PASS
27make freestanding # nm -u of the linked library objects must be empty
28make sanitize # ASan + UBSan
29make mutants # each GUARD line deleted in turn; AIENOS_DISK_MUTANTS: PASS
30```
31
32Host tests run against software NVMe and SDHCI + SD card models written in
33`tests/nvme_test.c` and `tests/sdhci_test.c`. QEMU runs against QEMU's
34models. None of them qualifies any physical controller; the Pi 5 run is
35separate evidence.
36
37## Unsafe assumptions: what is now checked
38
39Items [UA] come from `docs/P3_NVME_UNSAFE_ASSUMPTIONS.md`. "Mutant" is the
40GUARD tag that `make mutants` deletes. All tests named are in `tests/nvme_test.c`
41unless they say otherwise.
42
43| Item | Check or limit (mutant) | Error | Covering test |
44|---|---|---|---|
45| [UA P0] CAP.MPSMIN/MPSMAX ignored | MPSMIN (bits 51:48) must be 0; 4 KiB pages only (nvme-mpsmin). MPSMAX >= 0 always holds once MPSMIN is 0 | NVME_EMPS | test_cap_checks (MPSMIN 1, 15) |
46| [UA P0] CAP.MQES not enforced | admin depth 8 <= MQES+1 (nvme-mqes-admin); I/O depth <= MQES+1 (nvme-mqes-io) | NVME_EMQES | test_cap_checks (MQES 3 with I/O depth 2, MQES 7 with depth 16) |
47| [UA P1] CAP.CSS not validated | bit 37 (NVM) required (nvme-css) | NVME_ECSS | test_cap_checks |
48| [UA P1] hard-coded NSID 1 | NSID comes from Identify CNS 02h, or the caller NSID must be 1..NN (nvme-nsid); NSZE != 0 (nvme-nsze) | NVME_ENSID / ENSZE | test_namespace (empty list, CNS 02h unsupported, active NSID 3, NSID > NN, inactive NSID) |
49| [UA P1] LBADS lower bound | only 9 or 12 accepted (nvme-lbads); metadata must be 0 (nvme-meta); FLBAS <= NLBAF and bits 6:5 clear (nvme-flbas) | NVME_ELBADS / EMETA / EFLBAS | test_lbads (all 0..31), test_namespace |
50| [UA P2] CAP.AMS | documented limit: round robin is mandatory, so CC.AMS = 0 always | none | test_init_ok asserts CC.AMS = 0 |
51| [UA P2] readiness off-by-one vs CAP.TO | wait gives up after exactly TO x 500 ms (nvme-ready-bound); CSTS.CFS stops the wait (nvme-cfs-ready) | NVME_ETIMEOUT / ECFS | test_readiness_timeouts (exact 500000 us, TO=0, TO=4, ready after 200 ms, CFS) |
52| [UA P2] completion SQID unverified | SQID must match the queue (nvme-sqid), CID must match (nvme-cid), then fail-stop | NVME_ESQID / ECID | test_completion_faults |
53| [UA P3] VS never read | major version must be 1 or 2 (nvme-vs) | NVME_EVS | test_cap_checks (0.1, 3.0, 1.0, 2.0) |
54| command poll unbounded | max(1000 ms, TO x 500 ms) budget (nvme-cmd-bound); CFS during a command (nvme-cfs-cmd); fail-stop until re-init (nvme-failstop) | NVME_ETIMEOUT / ECFS / ESTATE | test_completion_faults, test_flush_and_reopen |
55| queue entry sizes | Identify SQES/CQES must allow 64 B / 16 B (nvme-sqes, nvme-cqes) | NVME_EQES | test_cap_checks |
56| transfer size / MDTS | min(128 KiB, 4 KiB << MDTS, bounce) (nvme-xfer); LBA range (nvme-range); a refused request rings no doorbell | NVME_ERANGE | test_mdts_and_range |
57| PRP construction | length/offset overflow (prp-len-wrap), address wrap (prp-addr-wrap), list capacity (prp-list-cap); lists chain through the last entry | NVME_EARG / ERANGE | test_prps |
58| power-fail atomicity | NAWUPF/AWUPF unit (atomic-unit), NABSPF/NABO boundary (atomic-boundary) | n/a | test_atomicity |
59| disk_dev bounds | zero count (disk-zero), LBA (disk-lba), end overflow (disk-end), queue depth (queue-bound), queue fail-stop (queue-failstop) | DISK_E* | tests/disk_test.c |
60
61Other limits: one command in flight at a time; every request goes through
62the bounce buffer; doorbells use the CAP.DSTRD stride (tested with DSTRD=2);
63a command that completes with a non-zero status returns DISK_EIO and the
64queue stays usable.
65
66## Errors found in the reference material
67
68- `docs/P3_NVME_CONTROLLER_AUDIT.md` gives some CAP bit positions wrong. CSS
69 is bits 44:37, not `(cap>>45)&0xff`. MPSMIN is the 4-bit field 51:48, not
70 `&0xff`. CAP.AMS bit 0 is not "round robin": AMS (bits 18:17) only
71 advertises WRR and vendor-specific arbitration.
72- The Rust `atomicity.rs` boundary uses `(nabspf + 1) as u16`, which wraps to
73 0 when NABSPF is 0xffff. The C port computes in 64 bits, and
74 test_atomicity covers that case.
75- The Rust readiness loop sleeps one more step than CAP.TO allows. The C port
76 stops at exactly TO x 500 ms.
77
78## SD host driver: what is checked
79
80Each check below is a GUARD line that `make mutants` deletes; a test in
81`tests/sdhci_test.c` fails for every one. The software model also flags any
82command issued while CMD/DATA inhibit is set, any data command while the card
83is still programming, a wrong response type, a wrong address mode (byte for
84SDSC, block for SDHC), and any unaligned or out-of-window register access.
85
86| Check (mutant) | Error |
87|---|---|
88| any error bit in INT_STATUS ends the wait (sdhci-err-int) | SDHCI_ECMD / SDHCI_EDATA |
89| command line (and data line for data/busy commands) idle before issue (sdhci-inhibit) | SDHCI_ETIMEOUT |
90| R1 card-status error bits 0xfdf98008 (sdhci-r1) | SDHCI_ESTATUS |
91| HOST_VERSION spec 2.00 or later (sdhci-ver) | SDHCI_EVER |
92| software reset clears within 100 ms (sdhci-reset) | SDHCI_ERESET |
93| controller supports 3.3 V (sdhci-volt) | SDHCI_EVOLT |
94| a base clock, from CAPABILITIES or the caller (sdhci-clock0) | SDHCI_ECLOCK |
95| card present (sdhci-nocard) | SDHCI_ENOCARD |
96| CMD8 echo 0x1aa: SD 2.0+ cards only (sdhci-cmd8) | SDHCI_ECARD |
97| ACMD41 power-up bounded to 100 polls (sdhci-acmd41-bound) | SDHCI_ETIMEOUT |
98| CSD capacity non-zero (sdhci-csd-zero) | SDHCI_ECSD |
99| no I/O after a failure until init runs again (sdhci-ready, sdhci-failstop) | DISK_ESTATE |
100| lba/count inside the card, refused before any command (sdhci-range) | DISK_ERANGE |
101| after a write, CMD13 until the card is back in transfer state (sdhci-tran) | SDHCI_ETIMEOUT |
102
103Not done yet: high-speed (50 MHz) and UHS modes, 1.8 V signalling, ADMA, and card
104removal while running.
105
106Where these drivers run on real hardware: the Pi 5 kernel binds the SD driver at
107a fixed base address with a 200 MHz base clock (`native/kernel/core/pi5.c`; the
108ACPI method that gives the range is not run by the kernel) and has used it to
109write its log and the Store on the card (`evidence/pi5_hardware_runs_2026-10-13/`).
110The 2017 iMac kernel uses `disk_nvme.c` read-only; its build refuses any write or
111flush call from `native/kernel/x86/` (`evidence/imac_kernel1_2026-10-17/`).
112
113## Forward seeded Omega NVMe read path
114
115`omega_nvme.om` is the bounded, read-only protocol engine for aienux #31.
116The existing C driver/model are unchanged verification oracles, not a runtime
117implementation behind the Omega interface. The hosted transport exercises real
118QEMU NVMe admin/IO queues, exact identity/extent approval, phase/head/tail wrap,
119completion correlation, two-page PRPs and fail-stop DMA retention. Host fixtures,
120disposable-QEMU refusals and guard-removal mutants are filed in
121`tests/omega_nvme_receipt.txt`.
122
123See [OMEGA_NVME_READ.md](OMEGA_NVME_READ.md) for the pinned compiler, the explicit
124manifest byte layout, repeatable gate and exact measurement-first physical
125procedure. Physical and native transport qualification remain **NOT_RUN**
126(hardware-unverified).
127The QTest transport must not be mistaken for a kernel/VFIO adapter or permission
128to open/reset the live root NVMe. The existing recovery USB remains read-only.