aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
GitHub aien-dev/aienux#287 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/c6de7dfc4d68b5ae.bundle -o c6de7dfc4d68b5ae.bundle git fetch c6de7dfc4d68b5ae.bundle refs/pull/287/head
Provenance
github-import 1
aien-dev/aienux
287
409524f4227671c1c9d702c1a5d8c421f7e15170
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":287,"url":"https://github.com/aien-dev/aienux/pull/287","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:08Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index b336844b..626f2370 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "a252348440fc99cd39be36019cb30bf8a01b6e2a0b6dcce89828ebde5e18d367", - "last_commit": "827e20f", + "digest": "11efd71d613be5ca1fb6405abb1688d6d3f72fd1ac1e5dc8e091734d0f2688a0", + "last_commit": "0f70efd", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "4fb3cbe4fe847679a956f9a7da3183125e71a7383f362cca04fa9b8d20439cd8", - "last_commit": "3b26ea9", + "digest": "fcfb41da00d8ff2d8162483a8bc323cdf31e6e30dddc05b90f481535e53ef61f", + "last_commit": "c250fd2", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { "digest": "c53533f3712e26103f053602b917b580a6ac839b71f7ecab13fae29e49c0aa50", - "last_commit": "9d98903", + "last_commit": "fa209e4", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:d0e63ce498033cef5cdf20626984da8f8d904347a66bedc60bc51fb167d09edc", - "compiled_at": "2026-10-08T15:06:47Z", + "children_root": "sha256:b18f53d6f3866ed04e705e68e737b98e0bf8b95297ac63bec2c64873c3d144e2", + "compiled_at": "2026-10-08T15:58:17Z", "compiler": "crumb-compile/1", - "digest": "sha256:16d7f335d3e4170f7fb8bad4aa8a3485b4d43ee13f4e1cef35dabdee83474b3f", + "digest": "sha256:a45ee1b6377453711868dd83c5dab79daea2bc2e8edf9d57dc50e851c2b0490f", "evidence_files": 153, "evidence_root": "sha256:29aa8775feb12d9e0e64b41fc1fc48b97e32dc16bf9176562cbe9fe1ea934f00", - "files": 3023, - "generated_at_commit": "9d9890388426bbfec1080dbbc395d852e1c57eea", - "source_tree": "sha256:6fbac6573f0d2a3e9395b63a6e4c3766c88205abb2ab4fd1b4e0b8bb74667158" + "files": 3024, + "generated_at_commit": "2835db1cbb0117521468f3ab12e5396a2ad4f3f3", + "source_tree": "sha256:0cfe70787e4c9405fd19d9785ca373ae07bd4cafe715e4e53ee431bf30c1cad6" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 0a1fd987..39a39942 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -18,26 +18,26 @@ "children": [ { "digest": "3de6d16c0e46eb82e0eeb6de63973cc3ab3d995f18d9ad30eceac263d0209fa6", - "last_commit": "c410191", + "last_commit": "bf475a0", "name": "adr", "purpose": "Directory docs/adr. Purpose not yet described by a human." }, { "digest": "e9e804e088a0b2316d035b957c09289bf9f6176eece959d43c40c6e66005fe5e", - "last_commit": "5849a7a", + "last_commit": "7e15a57", "name": "crumbs", "purpose": "Directory docs/crumbs. Purpose not yet described by a human." } ], "children_root": "sha256:55bcc89f5282eb2e3f4e86d882abdfb5f4ea39e427ef97ef620b2267e5701eb1", - "compiled_at": "2026-10-08T14:56:09Z", + "compiled_at": "2026-10-08T15:18:36Z", "compiler": "crumb-compile/1", - "digest": "sha256:a252348440fc99cd39be36019cb30bf8a01b6e2a0b6dcce89828ebde5e18d367", + "digest": "sha256:11efd71d613be5ca1fb6405abb1688d6d3f72fd1ac1e5dc8e091734d0f2688a0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 63, - "generated_at_commit": "c4101915eb9f0babc01b25f62a86c5a2f00708e5", - "source_tree": "sha256:10655481a16e29bbb4777f76efa19998f19063876fcd6e7561a5ef5252193d36" + "files": 64, + "generated_at_commit": "0f70efd93df7cfb2fa9444cd310518ec17fb24d9", + "source_tree": "sha256:f49c87e18a4fd3bb65aad1d6e550068930af578493cc12322d7d6fecc1b4ea2d" }, "owner_lane": "", "provenance": { diff --git a/docs/GB10_NATIVE_DEPENDENCY_MAP.md b/docs/GB10_NATIVE_DEPENDENCY_MAP.md new file mode 100644 index 00000000..3a62cf2a --- /dev/null +++ b/docs/GB10_NATIVE_DEPENDENCY_MAP.md @@ -0,0 +1,262 @@ +# GB10 native dependency map (issue #286, cut A) + +Status: source inventory. No builds, no tests, no hardware runs, no GPU access were done to write this. Every row was read from source at the pinned commits below. Claims are tagged OBSERVED (read in source), INFERRED (with confidence) or UNKNOWN. + +## Plain-English summary + +Today the GPU works on this machine because a Linux program talks to NVIDIA's Linux driver through special device files. Omega's code never touches the chip directly. Everything it does goes through two small layers in the PHYSICS repo, which in turn ask the NVIDIA driver to do the hard work (wake the chip, load firmware, build memory maps, create a work queue, report faults). + +For AIENOS to run the GPU without Linux, three things have to be true: + +1. The part of Omega that makes GPU programs (instruction encoding, work descriptors, constant banks) must keep working. It is mostly plain C with no Linux dependency, so it can be reused. OBSERVED. +2. Everything the Linux driver does for us today must be done by AIENOS code instead. That is the long list in section 3. Nothing in the current code does any of it by itself. OBSERVED. +3. The pieces of Omega that are tangled up with Linux (a global lock, clocks, memory allocation, sleeping, threads) need a small "platform services" layer so the same code can run on both. OBSERVED that the tangle exists, INFERRED (medium) that a services layer is the right fix. + +The vector engine (`OmegaGpuBackend`) is already a clean seam. The persistent session, the numerical launchers, the resident runtime and the accelerator world are not: they call the driver layer directly. Section 5 says which cut moves each one. Section 6 says what waits on the open execution-order decision and which steps only Drake can do (boots, firmware, chip use under AIENOS). + +## Pins and how they were checked + +| Item | Value | Status | +| --- | --- | --- | +| Omega | `2ae8677c604fb1b9566d27412cff7b0339e5df55` | checked out, `git rev-parse HEAD` matches | +| PHYSICS | `6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf` | checked out, matches | +| Omega `physics.lock` | contains exactly the PHYSICS sha above | OBSERVED, pin confirmed | +| AIENOS code | `fa209e454dda90d933076e5fd1f333731fd9a3c1` (docs-only ADR 0019 merge `bf475a08`) | from the issue, not re-read here | + +Line numbers below are at those pins. Omega links look like `omega:src/file.c#Lnn`, PHYSICS links look like `physics:path#Lnn`. Full URL form: `https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/<path>#Lnn` and `https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/<path>#Lnn`. Files under Omega `evidence/` are frozen snapshots of older copies of these sources and are excluded from the inventory (OBSERVED: they hold copies of `omega_gpu_session.c`, `*_api.c` and so on). + +Governance note. The issue calls `aien-dev/aien-architecture#163` "an OPEN Drake decision". OBSERVED: #163 itself is a merged pull request (merged 2026-10-08T02:28Z) that recorded the conflict. The decision is still open per `CURRENT_EXECUTION_PLAN.md` line 720 ("Drake resolves which governs; until then neither is revised"). This document treats the decision as open and does not resolve it. + +## 1. The Linux driver layer, as it exists + +Two PHYSICS headers define the whole surface. + +| Layer | What it is | Source | +| --- | --- | --- | +| `Nvrm` / `NvrmMem` and `nvrm_*` | Userspace client of the NVIDIA open kernel module (RM and UVM). `NvrmMem` assumes one address is both the CPU and GPU virtual address. | [nvrm.h:23-28](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L23), [nvrm.h:50-86](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L50), [nvrm.h:88-109](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L88), [nvrm.h:119](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L119) | +| `M16NativeContext` and `m16_native_*` | Thin wrapper: embeds one `Nvrm`, one pushbuffer slot, one marker slot, 64 legacy allocation slots. Adds channel creation, method enqueue, doorbell, marker polling. | [m16_native.h:14-19](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/m16/m16_native.h#L14), [m16_native.h:22-52](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/m16/m16_native.h#L22) | + +Both are OBSERVED to need `/dev/nvidiactl`, `/dev/nvidia0` and `/dev/nvidia-uvm` ([nvrm.h:2-7](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L2), [nvrm.c:218-220](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L218)). + +## 2. Callers, grouped by subsystem + +Counting rule: one row is one source file (or one tight set of files) that names `nvrm_*`, `m16_native_*`, `Nvrm`, `NvrmMem` or `M16NativeContext`. Line lists are the call sites found by grep, not every mention. "Tangled" means the file calls the driver layer directly. + +### S1. Vector engine (the existing backend seam) + +| # | File | Driver-layer use | Notes | +| --- | --- | --- | --- | +| 1 | [omega:src/omega_gpu_engine.h#L200](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.h#L200) and [omega_gpu_engine.c#L299](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.c#L299) | none. 15-function `OmegaGpuBackend` table (open_device, create_channel, alloc, copy_in, fill_poison, build, submit, wait_marker, wait_marker2, wait_release_semaphore, barrier, copy_out, diagnostics, free_buf, close). | OBSERVED: contract is driver-free. It uses `stdatomic` and `clock_gettime` only ([engine.c#L84-86](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.c#L84), [#L140](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.c#L140)). The latch `g_blocked` ([#L85](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.c#L85)) implements "uncertain completion refuses all work". | +| 2 | [omega:src/omega_blackwell_engine.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L39) | `m16_native_open` [L215](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L215), `m16_native_create_channel` [L229](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L229), `nvrm_alloc_gpu_uncached` [L124](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L124), `nvrm_free` [L132](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L132) [L172](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L172) [L617](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L617), `m16_native_submit_methods` [L496](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L496), `m16_native_wait_marker` [L515](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L515), `m16_native_close` [L630](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L630), `nvrm_mthd` (pure header builder) at 12 sites from [L402](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L402) | The Linux implementation of the table. Backend export at [L655](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L655). Clock: `clock_gettime` [L84](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L84). | +| 3 | [omega:src/omega_blackwell_submit.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L7) | `m16_native_open` [L184](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L184) [L435](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L435), `m16_native_create_channel` [L185](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L185) [L436](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L436), `nvrm_alloc_gpu_uncached` at 16 sites [L191-211](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L191) [L440-463](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L440), `m16_native_submit_methods` [L366](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L366) [L608](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L608), `m16_native_wait_marker` [L91](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L91), `m16_native_close` | Older one-shot launch path (per-call open, run, close). Also holds the second copy of the 18-word setup prefix ([L19](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L19)). Tangled. | + +### S2. Persistent inference session + +| # | File | Driver-layer use | Notes | +| --- | --- | --- | --- | +| 4 | [omega:src/omega_gpu_session.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L13) and [omega_gpu_session.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.h#L43) | `nvrm_open` [L159](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L159), `m16_native_create_channel` [L160](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L160), `nvrm_close` [L159](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L159), `nvrm_alloc_gpu_uncached` [L91](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L91), `nvrm_free` [L110](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L110), `m16_native_submit_methods` [L277](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L277), `m16_native_wait_marker` [L54](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L54), `nvrm_retire` [L286](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L286), `m16_native_close` [L160](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L160) [L167](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L167) [L191](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L191) | Process-wide singleton `g_s` ([L29](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L29)), global mutex ([L28](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L28)), latch `g_blocked` ([L30](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L30)). Public API takes `NvrmMem*` ([L89](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L89), [L108](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L108)), so the Linux type leaks to every caller. Not behind `OmegaGpuBackend`. | +| 5 | [omega:src/omega_gpu_elementwise_api.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_elementwise_api.c#L871), [omega_gpu_matmul_api.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_matmul_api.c#L22), [omega_gpu_attention_api.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_attention_api.c#L495) | No direct `nvrm_*` or `m16_*` calls. Store `NvrmMem` ([elementwise L871](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_elementwise_api.c#L871), [matmul L38,L48](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_matmul_api.c#L38), [attention L495](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_attention_api.c#L495)) and call `omega_gpu_session_*`. | Indirect callers. They also take the session lock macro and use `clock_gettime` ([elementwise L961](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_elementwise_api.c#L961), [matmul L68](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_matmul_api.c#L68), [attention L582](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_attention_api.c#L582)) and `malloc`/`calloc`. Migrate with the session, not alone. | + +### S3. Numerical launchers (E1 chip paths) + +| # | File | Driver-layer use | Notes | +| --- | --- | --- | --- | +| 6 | [omega:src/omega_numeric_gb10.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_gb10.c#L109) | `m16_native_create_channel` [L109](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_gb10.c#L109), `nvrm_alloc` x8 [L112-126](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_gb10.c#L112), `nvrm_alloc_gpu_uncached` [L125](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_gb10.c#L125), `m16_native_submit_methods` [L291](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_gb10.c#L291) | One-shot launcher. Uses cached `nvrm_alloc` for non-polled buffers. | +| 7 | [omega:src/omega_numeric_reduce_gb10.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_reduce_gb10.c#L331) | create_channel [L331](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_reduce_gb10.c#L331), `nvrm_alloc` [L333-341](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_reduce_gb10.c#L333), uncached [L342](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_reduce_gb10.c#L342), submit [L473](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_reduce_gb10.c#L473) | same shape | +| 8 | [omega:src/omega_numeric_divsqrt_gb10.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_divsqrt_gb10.c#L1523) | create_channel [L1523](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_divsqrt_gb10.c#L1523), `nvrm_alloc` [L1525-1535](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_divsqrt_gb10.c#L1525), uncached [L1534](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_divsqrt_gb10.c#L1534), submit [L1617](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_divsqrt_gb10.c#L1617) | same shape | +| 9 | [omega:src/omega_numeric_ldst_gb10.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_ldst_gb10.c#L270) | create_channel [L270](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_ldst_gb10.c#L270), `nvrm_alloc` [L272-279](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_ldst_gb10.c#L272), uncached [L280](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_ldst_gb10.c#L280), submit [L361](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_ldst_gb10.c#L361) | same shape | +| 10 | [omega:src/omega_numeric_native.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_native.h#L5) | `m16_native_open` [L19](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_native.h#L19), `m16_native_close` [L26](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_native.h#L26), `m16_native_wait_marker` [L34](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_native.h#L34) | Shared wrappers used by rows 6-9. | + +The `open` for rows 6-9 happens in the tests that call them (see row 21), not in the launcher files. INFERRED (medium): launcher files receive a ready `M16NativeContext*`. + +### S4. Resident runtime and accelerator world + +| # | File | Driver-layer use | Notes | +| --- | --- | --- | --- | +| 11 | [omega:src/runtime/rx_resident_gpu.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L12) | `m16_native_open` + `create_channel` [L1041](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L1041), `nvrm_alloc` [L729-733](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L729), `nvrm_alloc_gpu_uncached` [L732](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L732) [L1055](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L1055), `m16_native_submit_methods` [L854](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L854), `nvrm_channel_destroy` [L971](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L971), `nvrm_channel` [L984](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L984), `m16_native_close` | Resident "seat". Heaviest Linux coupling in Omega: pthreads (`pthread_create` [L941](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L941) [L999](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L999) [L1092](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L1092)), CPU affinity and thread names ([L901-907](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L901)), `getenv("RX_SEAT_LEASE_CPU")` [L902](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L902), `usleep` (5 sites, e.g. [L719](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L719)). Recreates the channel at run time ([L971-984](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L971)). | +| 12 | [omega:src/omega_accelerator_world.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L110) and [.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.h#L65) | open/create_channel [L154-157](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L154), `nvrm_alloc_gpu_uncached` [L167](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L167) [L175](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L175) [L184](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L184) [L270](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L270) [L376](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L376), `nvrm_free` [L110](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L110) [L122](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L122), `nvrm_channel` / `nvrm_channel_destroy` [L533](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L533) [L527](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L527), `nvrm_enqueue` [L724](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L724), `nvrm_ring` [L753](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L753), `nvrm_retire` [L883](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L883) [L1067](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L1067) [L1303](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L1303), `m16_native_submit_methods` [L1056](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L1056) [L1292](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L1292) | The only Omega code that drives enqueue, ring and retire by hand (split submit). Public structs hold `NvrmMem` ([.h L65,79,84,92](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.h#L65)) and `M16NativeContext` ([.h L146](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.h#L146)). | +| 13 | [omega:src/omega_world_gates.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_world_gates.c#L740) | `nvrm_enqueue` [L740](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_world_gates.c#L740), `nvrm_retire` [L797](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_world_gates.c#L797), `nvrm_alloc_gpu_uncached` [L934](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_world_gates.c#L934), `m16_native_wait_marker_ge` [L2183](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_world_gates.c#L2183) [L2266](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_world_gates.c#L2266) | Gate code for the world; same split-submit style as row 12. | + +### S5. FORGE realization and evidence identity + +| # | File | Driver-layer use | Notes | +| --- | --- | --- | --- | +| 14 | [omega:src/forge_realization.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/forge_realization.c#L37) / [.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/forge_realization.h#L6) | takes `Nvrm *rm` as a parameter ([L37](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/forge_realization.c#L37)); no direct calls found | Type dependency only. | +| 15 | [omega:src/omega_evidence.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_evidence.c#L153) / [.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_evidence.h#L26) | reads `Nvrm` fields `compute_class`, `sm_version`, `gpu_uuid` ([L158-161](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_evidence.c#L158)) | Receipts bind hardware identity from a live `Nvrm`. A native backend must supply the same facts from its own source. | +| 16 | [omega:src/omega_blackwell_gates.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_gates.c#L1114) | observed-hardware identity from live `Nvrm` ([L1114-1127](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_gates.c#L1114)) | Same dependency as row 15. | +| 17 | [physics:forge/forge_realize.c](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_realize.c#L231) | `nvrm_channel` [L231](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_realize.c#L231), `nvrm_alloc` [L235-240](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_realize.c#L235), `m16_native_build_release` [L255](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_realize.c#L255), `nvrm_enqueue` [L269](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_realize.c#L269), `nvrm_ring` [L275](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_realize.c#L275), `m16_native_wait_marker` [L278](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_realize.c#L278), `nvrm_free` | PHYSICS-side FORGE. | +| 18 | [physics:forge/forge_descriptor.c](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_descriptor.c#L199) | `nvrm_open` [L199](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_descriptor.c#L199), `nvrm_close` [L207](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_descriptor.c#L207) [L219](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_descriptor.c#L219) [L272](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/forge/forge_descriptor.c#L272) | Opens the device to read identity. | + +### S6. PHYSICS qualification programs, gates and tests + +| # | File | Driver-layer use | Notes | +| --- | --- | --- | --- | +| 19 | [physics:m16/m16_concurrent.c](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/m16/m16_concurrent.c#L29), [m16_requalify.c](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/m16/m16_requalify.c#L44) | open, alloc_memory, create_channel, build_release, enqueue, ring_doorbell, wait_marker, `nvrm_retire`, close | Qualification programs. Linux-only by design. | +| 20 | [physics:nvrm/lifecycle_gates.c](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/lifecycle_gates.c#L193), [submission_visibility_gates.c](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/submission_visibility_gates.c#L13), [tests/test_forge_seam.c](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/tests/test_forge_seam.c#L105) | exercise `nvrm_open/alloc/free/channel/submit/close`, fault injection fields ([nvrm.h:80-81](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L80)) | Their value is as the Linux reference behavior to preserve (alloc/free accounting, quarantine, GPFIFO full). | + +### S7. Omega tests, fakes, benches, build scripts + +| # | File | Driver-layer use | Notes | +| --- | --- | --- | --- | +| 21 | [omega:tests/test_numeric_lifecycle.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/test_numeric_lifecycle.c#L10), [gpu_serving_alloc_count_test.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/gpu_serving_alloc_count_test.c#L43), [numeric_native/other_launcher.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/numeric_native/other_launcher.c), [numeric_native/m16_native.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/numeric_native/m16_native.h) | `m16_native_open/close/wait_marker`, `nvrm_open/close/retire` | Host or chip tests. The `numeric_native` pair is a local stub of the header. | +| 22 | [omega:tests/fake_m16_native.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/fake_m16_native.c#L293) / [.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/fake_m16_native.h), [test_omega_blackwell_engine.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/test_omega_blackwell_engine.c#L38) | a simulated implementation of the whole `m16_native_*` and needed `nvrm_*` surface ([open L293](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/fake_m16_native.c#L293), [alloc L322,L350](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/fake_m16_native.c#L322), [submit L374](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/fake_m16_native.c#L374), [wait L410](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tests/fake_m16_native.c#L410)) | The existing host-only seam test. Built without any physics `.c` ([omega-gpu-engine.mk:48](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/mk/omega-gpu-engine.mk#L48)). Reusable for cut A contract tests. | +| 23 | [omega:bench/prime_race/gb10_native.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/bench/prime_race/gb10_native.c#L108), [tests/gb10_launch_cost.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/bench/prime_race/tests/gb10_launch_cost.c#L82) | declare `NvrmMem` (no named call matched in grep) | Bench code. INFERRED (medium): uses the session API. Not read line by line. | +| 24 | [omega:mk/omega-gpu-engine.mk](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/mk/omega-gpu-engine.mk#L30), [src/omega_physics_dir.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_physics_dir.h#L14), [tools/chip_run.sh](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tools/chip_run.sh#L195), [tools/e1_manifest.sh](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tools/e1_manifest.sh#L63), [tools/r16_authpath.sh](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/tools/r16_authpath.sh#L65) | build wiring: include paths `-I$PHYSICS/nvrm -I$PHYSICS/m16`, physics checkout probe for `m16/m16_native.h`, a rule that physical-seat sources (`m16_native.c`, `nvrm.c`) must not appear in a host build | A freestanding target needs its own build rule; the guard in `r16_authpath.sh` is a useful pattern. | + +Totals: 24 rows, 7 subsystem groups (S1 to S7). Direct callers with live driver calls: rows 2, 3, 4, 6 to 13, 17 to 21. Type-only or identity-only dependants: rows 5, 14, 15, 16, 23. + +## 3. Other Linux-only dependencies in the GPU paths + +| Dependency | Where (OBSERVED) | Why it matters natively | +| --- | --- | --- | +| open/ioctl/mmap on `/dev/nvidia*` | `open` [nvrm.c:153,162,218-220](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L153); `ioctl` [nvrm.c:58-59](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L58), [#L145](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L145); `mmap` of RM memory [#L177](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L177); reserve of fixed VA with `MAP_FIXED_NOREPLACE` [#L485](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L485); `munmap` [#L507](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L507), [#L596](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L596) | The whole backend. Replaced, not wrapped. | +| `ioctl` header types | `nv-ioctl.h`, `uvm_ioctl.h` ([nvrm.c:21-25](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L21)) | Linux driver ABI headers from the pinned open-gpu-kernel-modules tree. Cannot be in the freestanding build. | +| pthread mutex | `g_mu` [session.c:28](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L28), lock/unlock [L67-68](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L67) [L187-194](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L187); the three `*_api.c` files take it through `omega_gpu_session_lock()` | Needs a platform lock service. | +| pthread threads, affinity, names | [rx_resident_gpu.c:53,67,901-907,941,952,974,999,1092,1116](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L941) | Needs a platform thread or task service, or a redesign. | +| `clock_gettime(CLOCK_MONOTONIC)` | [session.c:38](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L38), [m16_native.c:90](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/m16/m16_native.c#L90), [engine.c:140](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.c#L140), [blackwell_engine.c:84](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L84), [blackwell_submit.c:27](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L27), `*_api.c` (see row 5) | Timeouts and latency. Needs a monotonic clock service. The engine already has a test clock hook ([engine.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.h#L242)); the issue forbids that hook in production. | +| `usleep(50)` polling | [m16_native.c:105](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/m16/m16_native.c#L105), five sites in [rx_resident_gpu.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L719) | Needs a wait service (sleep, yield or interrupt). | +| `malloc`/`calloc`/`free` | [blackwell_submit.c:69,381,619](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L69); matmul and attention APIs (e.g. [matmul L304-504](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_matmul_api.c#L304), [attention L453-918](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_attention_api.c#L453)); numeric launchers ([gb10 L87-89](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_numeric_gb10.c#L87)); [rx_resident_gpu.c:80,1021,1039,1072](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L1021) | Needs a host heap service. CPU memory only. | +| `getenv` | `RX_SEAT_LEASE_CPU` [rx_resident_gpu.c:902](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/runtime/rx_resident_gpu.c#L902); `PHYSICS_DIR` [omega_physics_dir.h:28](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_physics_dir.h#L28) | Configuration source. Native needs an explicit config input. | +| `fopen`, `realpath` | [blackwell_submit.c:711](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L711), [omega_physics_dir.h:14,33,63](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_physics_dir.h#L14) | File access in launch and build helpers. | +| signals | none found in these files | OBSERVED absent (grep for `signal(`, `sigaction`). | +| ARM barriers and `yield` | `dsb sy` [session.c:231,284](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L231), [nvrm.c:735,737](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L735); `yield` [session.c:51](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L51) | Inline assembly, portable to bare-metal AArch64. Not Linux-only. | +| `stdatomic` | [engine.c:84-85](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.c#L84), session stats | Portable if the freestanding toolchain provides it. UNKNOWN for the AIENOS C toolchain. | +| libc string/stdio | `snprintf`, `vsnprintf` for error text ([nvrm.c:50-56](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L50), [session.c:59-65](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L59)) | Needs a freestanding formatter or a diagnostics service. | + +## 4. Driver responsibility map + +For each duty listed in issue #286 cut A: where today's code gets it, and what the AIENOS-native replacement must provide. "RM" is NVIDIA's resource manager inside the Linux driver. Everything RM does internally is not visible in our source (OBSERVED: we only see the ioctl call and its parameters). + +| Responsibility | Today (RM/UVM call site) | Native replacement must provide | +| --- | --- | --- | +| Device and firmware init | `NV01_ROOT_CLIENT` alloc [nvrm.c:223](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L223); card enumeration `NV_ESC_CARD_INFO` [#L235](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L235); `NV01_DEVICE_0` [#L255](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L255); `NV20_SUBDEVICE_0` [#L258](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L258); identity and SM version via `GPU_GET_ID_INFO`, `GR_GET_INFO`, `GPU_GET_GID_INFO` ([#L267-306](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L267)). The driver already initialized the chip and loaded GSP firmware before our process starts. | OBSERVED: our code does no firmware work at all. Native needs the full bring-up: reset and power state, GSP firmware load and handoff, protocol with GSP, readiness waits, identity and capability queries. This is cut C and is the largest UNKNOWN (see section 8). | +| Context creation | Class list query [nvrm.c:267-271](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L267), picks compute, GPFIFO and usermode classes ([#L274-279](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L274)); `KEPLER_CHANNEL_GROUP_A` [#L620](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L620); `FERMI_CONTEXT_SHARE_A` [#L625](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L625); compute object alloc [#L646](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L646) | A context object that owns engine state (graphics/compute context, saved registers) with explicit lifetime. INFERRED (medium): RM sets up compute-engine per-context state (local memory windows, shader memory) inside the compute object alloc, which our code never sees. | +| Address spaces | `NV01_MEMORY_VIRTUAL` [#L262](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L262), `FERMI_VASPACE_A` [#L300](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L300); UVM registration `UVM_INITIALIZE` [#L227](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L227), `UVM_REGISTER_GPU` [#L313](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L313), `UVM_REGISTER_GPU_VASPACE` [#L321](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L321); identical CPU and GPU virtual addresses via a reserved VA slot ([acquire_va_slot #L188](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L188), [va_take #L367](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L367)) | A GPU address space object, separate from the CPU MMU and SMMU services (issue cut D). The same-address design is a Linux/UVM choice ([nvrm.h:25](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L25)); native contracts must carry CPU address and GPU address as distinct values. | +| Allocation | `NV01_MEMORY_SYSTEM` alloc [nvrm.c:506](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L506) with explicit cache attribute ([alloc_with_cacheability #L477](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L477), uncached entry [#L473](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L473)); CPU map [#L161-177](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L161); free and live-table checks [#L543](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L543); fixed table sizes 4096 free and 4096 live ([nvrm.h:15-16](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L15)) | A bounded, reclaiming GPU-visible allocator with explicit cache policy per buffer and CPU mapping. The `ck_dma_alloc` bump pool does not qualify (issue). Must keep the uncached rule for host-polled words (hardware manual, `nvos.h` GPU_CACHEABLE comment; OBSERVED in code at [session.c:91](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L91)). | +| GPU page tables | Created and edited by UVM/RM inside the kernel: `UVM_CREATE_EXTERNAL_RANGE` [nvrm.c:423](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L423), `NV_ESC_RM_MAP_MEMORY_DMA` [#L435](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L435), `UVM_MAP_EXTERNAL_ALLOCATION` [#L450](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L450); teardown `UVM_FREE` [#L112](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L112), `NV_ESC_RM_UNMAP_MEMORY_DMA` [#L124](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L124) | OBSERVED: our code never writes a page-table entry; it only asks UVM to map. Native must own the GPU MMU format, page-table memory, TLB invalidation and fault handling. UNKNOWN: exact GB10 format and invalidation protocol from our sources. Evidence of sensitivity: omega#323 recorded a GPU page fault on a page boundary when code was not padded by 2 KB ([omega_gpu_code_alloc.h:1-12](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_code_alloc.h#L1)). | +| Channel and queue creation | GPFIFO ring plus USERD in one allocation ([nvrm.c:632-645](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L632)); error notifier allocation [#L632](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L632); `BLACKWELL_CHANNEL_GPFIFO_A` object [#L645](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L645); schedule `NVA06C_CTRL_CMD_GPFIFO_SCHEDULE` [#L670](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L670); destroy [#L677](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L677) | Channel creation including runlist insertion, scheduling enable and disable, and destruction. Own the GPFIFO and USERD layout (OBSERVED: Blackwell USERD documents no GPGet, so consumption is tracked by the caller, [nvrm.c:729-731](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L729)). | +| Submit token and doorbell | `GET_WORK_SUBMIT_TOKEN` [nvrm.c:648-649](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L648); usermode object plus 64 KB MMIO map [#L281-285](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L281); GP entry write and GPPut [#L723-737](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L723); doorbell store `*rm->doorbell = rm->token` [#L746](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L746) | A capability-bound doorbell page mapping and the token value for the channel. Native needs to learn the token from the channel it created, not from RM. UNKNOWN how token derivation works without RM. | +| Completion | None from the driver. Our code writes a marker with a method stream and polls it: release methods ([session.c:271-282](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L271)), `m16_native_wait_marker_ge` poll loop with `usleep(50)` ([m16_native.c:98-109](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/m16/m16_native.c#L98)), plus a second marker after an L2 flush. Entries retired by hand with `nvrm_retire` ([nvrm.c:741](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L741)). | OBSERVED: completion is host polling of GPU-uncached memory, no interrupt used. Native keeps the same marker protocol and needs a wait service (timer plus yield). A timeout latches the session (`g_blocked`, [session.c:280](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L280)); that behavior must carry over. | +| Interrupts | None used by our code. | OBSERVED absent. Native may poll only (issue says polling does not count as interrupt support). Needs the GIC/MSI-X/ITS route for any fault or completion interrupt: [gic.c refuses INTIDs >= 1020](https://github.com/aien-dev/aienos/blob/fa209e454dda90d933076e5fd1f333731fd9a3c1/native/kernel/arch/gic.c) per the issue. Not re-read here. | +| Error reporting | RM error notifier allocated and passed to the channel ([nvrm.c:632,638](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L632)); text errors in `rm->err` ([#L50-56](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L50)); sticky `faulted` flag set at many failure sites (e.g. [#L330](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L330), [#L488](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L488), [#L566](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L566)). Faults on the chip surface through the Linux kernel log (Xid), not through our code. | OBSERVED: nothing in Omega reads the error notifier (no use of `notifier` outside nvrm.c allocation and free). Native needs fault capture, channel-error read-back, and a fail-closed quiescence state. Per issue: after a timeout, do not free memory the GPU can still reach. | +| Teardown | Ordered frees in `nvrm_close` ([nvrm.c:755-801](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L755)), channel destroy ([#L677-713](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L677)), `munmap` ([#L596](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L596)); session on-close hooks ([session.c:177-196](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L177)). Process exit closes the file descriptors, so RM reclaims leaks. | Native has no process-exit safety net. It needs explicit revoke and reclaim of channels, mappings, memory and the address space, with known-completion cleanup and uncertain-completion quarantine. | + +## 5. Reusable pieces versus Linux-only pieces + +### Reusable (driver-independent) + +| Piece | Source | Why reusable (OBSERVED unless tagged) | +| --- | --- | --- | +| Blackwell instruction IR, register allocator, encoder | [omega_blackwell_codegen.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_codegen.h#L170) (`omega_bw_ir_*`, `omega_bw_regalloc_solve`, `omega_bw_encode_program`), [.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_codegen.c#L8) | Includes only `stdio`, `stdlib`, `string`, `sha256.h` and a submit header ([codegen.c:1-6](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_codegen.c#L1)). No device calls. Heap (`stdlib`) use is CPU-side. INFERRED (medium) that it builds freestanding once a heap and `snprintf` exist. Note it includes `omega_blackwell_submit.h` (the Linux path header), which must be checked for pulling in `m16_native.h`. UNKNOWN. | +| Matmul and attention codegen entry points | [codegen.h:197-232](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_codegen.h#L197) | Pure functions from spec to code bytes. | +| QMD builders and invariant check | [omega_blackwell_qmd.h:44-66](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_qmd.h#L44), [.c:39-237](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_qmd.c#L39) | Only `string.h`. Pure word builders. | +| Constant-bank builders | [qmd.c:153-209](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_qmd.c#L153) | Pure. But see the caveat below. | +| Code buffer sizing (2 KB prefetch tail) | [omega_gpu_code_alloc.h](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_code_alloc.h#L19) | Header only, "no device, no physics headers". | +| Engine state machine, latch, job and result types | [omega_gpu_engine.h/.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_engine.c#L299) | Driver-free. Needs only a clock and atomics. | +| Method header builder `nvrm_mthd` | [nvrm.h:112-114](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L112) | Static inline arithmetic. Lives in a Linux header today. It should move to a shared encoding header (cut A "factor shared hardware encoding"). | +| GP entry encoder `nvrm_gp_entry` | [nvrm.c:715](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L715) | Pure arithmetic; declared in `nvrm.h`. Same move. | +| Pushbuffer assembly (launch method stream) | [session.c:232-270](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L232) | Builds words in a local array. Only the submit and wait calls are driver-tied. Today this logic is duplicated across [session.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L22), [blackwell_submit.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L19), [blackwell_engine.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_engine.c#L301), [accelerator_world.c](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_accelerator_world.c#L980) and the numeric launchers. INFERRED (medium): a single shared builder is a precondition for a clean port. | +| AIENOS pure BAR/identity decoding | [crates/aienos-accel/src/lib.rs](https://github.com/aien-dev/aienos/blob/fa209e454dda90d933076e5fd1f333731fd9a3c1/crates/aienos-accel/src/lib.rs) | Per issue; not re-read here. | + +### Caveats on "reusable" + +- The constant bank 0 template is "empirically captured from physical Blackwell GB10 compute channel bring-up" ([qmd.c:4-7](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_qmd.c#L4), 224 words, [L8](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_qmd.c#L8)). It is patched at four word positions with the bank address ([L155-165](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_qmd.c#L155)); other words may encode values RM chose for this context. The header marks this class of data `EPISTEMIC_REVERSE_ENGINEERED` ([qmd.h:18](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_qmd.h#L18)). Whether the other words are constant across contexts is UNKNOWN. +- The 18-word setup prefix `SETUP_WORDS` ([session.c:22](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L22), [submit.c:19](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_submit.c#L19)) programs compute-class state words. Which of these RM would otherwise have set, and whether a native context needs them, is UNKNOWN. +- The QMD takes a `scratch_va` and a semaphore address placed in session scratch ([session.c:214](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_session.c#L214)). Per-context local-memory setup that normally precedes such launches is not visible in our source. UNKNOWN. + +### Linux-only + +Everything in `nvrm.c` and `m16_native.c`; the `Nvrm`/`NvrmMem`/`M16NativeContext` types (they embed fds and CPU pointers equal to GPU addresses); the session singleton and its mutex; the resident runtime's threads; `tests/fake_m16_native.c` (a test double of the Linux API, reusable only as a contract-test model). + +## 6. Caller group to cut table + +Cut letters as in issue #286: A map and freestanding boundary; B native discovery and bounded ownership; C firmware and device lifecycle; D native memory, queue and first compute; E follow-on (separately tracked). A row can be touched by more than one cut; the "migrates in" column names the cut that changes the caller itself. Entries are INFERRED (medium) from the issue text, since the issue does not assign callers. + +| Caller group (rows) | Migrates in | Why | +| --- | --- | --- | +| S1 vector engine contract (row 1) | A | Already driver-free; A extends it (platform services, versioning, refusal of unsupported operations). | +| S1 Blackwell engine backend (row 2) | A (Linux side kept private), D (native backend written beside it) | The first compute target is the integer vector add through this contract. | +| S1 legacy submit path (row 3) | A (dedupe encoding), no native port | Duplicate of the engine path. INFERRED (low): retire or keep as Linux reference. | +| S2 persistent session (row 4) | E (port); A (platform services, hide `NvrmMem`) | Issue says the session is not freestanding yet and is not part of first compute. | +| S2 elementwise, matmul, attention APIs (row 5) | E | Follow the session. | +| S3 numeric launchers (rows 6 to 10) | E | Issue excludes broad kernels from the first milestone. | +| S4 resident runtime (row 11) | E (late) | Threads, runtime channel recreation, polling; not needed for first compute. | +| S4 accelerator world and world gates (rows 12, 13) | E (late) | Hand-driven split submit. | +| S5 evidence and identity (rows 14 to 16) | A (define a hardware-identity record both backends fill), C (native source of identity) | Receipts must bind firmware identity (issue acceptance). | +| S5 FORGE realization (rows 17, 18) | E | PHYSICS-side, Linux-only. | +| S6 PHYSICS qualification and gate programs (rows 19, 20) | none migrate; they remain the Linux reference | Issue: preserve the Linux backend as reference. | +| S7 tests, fakes, benches, build scripts (rows 21 to 24) | A (contract tests over the fake; freestanding link target and its build rule), D (native receipts) | Issue: freestanding link target and contract tests before device init. | +| New code with no current caller: PCI multi-segment discovery, capability-bound MMIO/DMA/IRQ | B | No current Omega caller. | +| New code: GSP firmware transport and bring-up | C | No current caller. RM does it today. | +| New code: GPU page tables, allocator, channel, doorbell, completion | D | Replaces rows 4/12 usage of `nvrm_*` for the first-compute subset only. | + +No whole-project independence claim follows from migrating any one row (issue requirement). After cut D only the vector-add path would be native. + +## 7. Order dependencies + +Sources: `CURRENT_EXECUTION_PLAN.md` line 720 and NEXT-PHASE-3 (lines 791 to 800) in aien-architecture; issue #286 text; issue #285. + +Two orders exist for native AIENOS. Order 1 (older): M5 trust, M6 network, M7 inference, M8 persistent agent. Order 2 (NEXT-PHASE-3, newer): operator input, boot selection and rollback, PCI discovery, real-device storage, owner identity and trust, native inference, then GPU later. Both place GPU after native CPU inference (OBSERVED in the plan; the plan states Campaign 3 lists "later GPU"). The plan recommends Order 2 but records that Drake decides. + +### Can proceed now (host-only, no physical device, no kernel-order commitment) + +- Cut A in full: this map, the platform-services contract, hiding `NvrmMem` behind typed handles, moving `nvrm_mthd` and `nvrm_gp_entry` into a shared encoding header, a freestanding link target for the codegen, QMD and engine files, backend contract tests over the existing fake. INFERRED (high): no kernel or hardware change. +- B host fixtures: multi-segment MCFG parsing tests, fake config-space access that fails on any write, GPU identity fixture on a nonzero segment, malformed and overlapping entry tests. These are pure parsing and fixtures. The issue already authorizes "Host-only interface, parser, fixture, and refusal work". +- C host work: inventory of firmware and protocol sources, parsers and refusal tests for firmware metadata. No loading. +- D host work: simulated-device tests for allocator, address-space bookkeeping and refusal paths, using no real GPU. + +### Cannot start until #163's decision is made, or needs coordination first + +These items change shared kernel code or occupy a place in the native sequence, so scheduling them depends on which order governs. INFERRED (medium); the plan does not list per-step dependencies, so this is my reading. + +| Cut and step | Why it waits | +| --- | --- | +| B: wiring multi-segment discovery into the boot path, or changing `pci_enumerate` / `pci_stage_probe` | Order 2 puts PCI discovery right after boot selection; Order 1 does not schedule PCI before M7. The first PR (aienos#287) only adds new read-only functions and host tests and leaves the boot path unchanged; the coordinator confirmed on 2026-10-08 that no other lane owns `pci.c`. | +| B: capability-bound MMIO, DMA and interrupt resources in the kernel | Touches IPC/capability code and `ck_mmio_map`, which trust and physical-memory-authority work also rely on. Order matters for what exists first. | +| B: IORT/SMMU audit and extension for a second SMMU, GIC/ITS work for an interrupt route | Same shared kernel areas; storage and input lanes use them. | +| B: QEMU gates for the above | Gate numbering and CI are shared. | +| C: all implementation beyond host parsers | Requires physical bring-up prerequisites (see below). | +| D: any kernel-side allocator or queue code merged to main | Depends on the B resources and on #285 when it reuses domain-1 numbers. | +| E: all | Follows first compute. | + +### Operator steps (Drake only, not planned work) + +Each of these needs Drake and the existing attended-hardware, quiet-window and recovery procedures. None are authorized by this document or by the issue. + +- OPERATOR STEP: boot AIENOS on the physical Spark (any native boot with the GB10 visible). +- OPERATOR STEP: any firmware load or GSP handoff on real hardware. +- OPERATOR STEP: any GPU use under native AIENOS, including the first vector-add run and repeated runs. +- OPERATOR STEP: a cold or warm start from a documented power/reset state without prior Linux GPU driver initialization (cut C proof). +- OPERATOR STEP: device reset or power cycle to test recovery. +- OPERATOR STEP: Secure Boot, boot menu or recovery-stick actions if a native image must be booted. + +Per the issue, these also wait on: native input and recovery, boot rollback, physical memory authority, and the relevant storage and trust dependencies. INFERRED (high) that the physical GB10 DMA/translation question (is the GPU behind the SMMU window?) must be answered before C or D can run with confinement. + +### Issue #285 trigger + +OBSERVED in #285: the first change that lets a domain-1 kernel resource number (kind 2 or 3: kernel channel or object) be destroyed and reissued at run time, or persists one across reboot or rollback, must implement the per-resource incarnation counter in the same change. Until then `gen_lookup` has no real counter and nonzero `required_generation` is refused. + +Where it may bite here. A GPU channel is the likely domain-1 kernel channel (INFERRED, medium) and cut D must "destroy and reopen" it (issue acceptance: normal teardown/reopen, repeated runs). If the native channel is released and its number reissued, the counter must ship in that cut. If cut D keeps one channel number per boot and never reuses it, the trigger does not fire. UNKNOWN: which GPU-private allocations map to domain 1 (the issue says to define this mapping explicitly; no such mapping exists in the files read here). The counter must not be equated with handle-slot generations or Omega world epochs (#285 text). + +## 8. Known unknowns + +1. UNKNOWN: GB10 GSP firmware transport and initialization protocol, exact firmware blobs and versions, and what is public. Our source contains none of it (RM does it, [nvrm.c:223](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.c#L223)). Blocks cut C. +2. UNKNOWN: GPU MMU page-table format, TLB invalidation and fault-reporting registers on GB10, as implemented by the pinned driver. Our code only requests mappings. +3. UNKNOWN: how the work-submit token is derived and the channel is made runnable without RM (`GET_WORK_SUBMIT_TOKEN`, `GPFIFO_SCHEDULE`). +4. UNKNOWN: which words of the captured constant bank 0 template and the 18-word setup prefix are context-independent versus values RM chose. Needed before a native context can reuse the Omega QMD and cbank builders. +5. UNKNOWN: the per-context compute engine state RM initializes during compute-object allocation (local memory, shader memory windows). +6. UNKNOWN: whether GPU memory traffic on GB10 passes through the AIENOS-confinable SMMU window or uses another path (the issue flags this; [GB10_PLATFORM_TOPOLOGY.md](https://github.com/aien-dev/aienos/blob/fa209e454dda90d933076e5fd1f333731fd9a3c1/docs/GB10_PLATFORM_TOPOLOGY.md) not re-read here). +7. UNKNOWN: whether the GPU interrupt route (MSI-X/ITS/LPI) is required for correctness or only for efficiency, given the current code is polling only. +8. UNKNOWN: whether the codegen files link freestanding. `omega_blackwell_codegen.c` includes `omega_blackwell_submit.h` ([L2](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_blackwell_codegen.c#L2)); whether that header pulls in Linux types was not checked. +9. UNKNOWN: the AIENOS C toolchain's support for `stdatomic.h`, 64-bit atomics and inline AArch64 assembly in the freestanding target. +10. UNKNOWN: contents and Linux dependence of the bench files (row 23) and of every tool script beyond the lines cited. Not read in full. +11. UNKNOWN: the AIENOS-side current state. The AIENOS rows in this document repeat the issue's findings at `fa209e45`; they were not re-read here. +12. UNKNOWN: relationship of Xid 31 fault in omega#323 (padded code fix) to a native page-fault handler. The padding cause is INFERRED in the source comment itself ([omega_gpu_code_alloc.h:8-10](https://github.com/aien-dev/omega/blob/2ae8677c604fb1b9566d27412cff7b0339e5df55/src/omega_gpu_code_alloc.h#L8)). +13. UNKNOWN: whether the 4096-entry fixed tables in `Nvrm` ([nvrm.h:15-16](https://github.com/aien-dev/physics/blob/6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf/nvrm/nvrm.h#L15)) are the right bound for a native allocator. + +## 9. Scope and limits of this document + +- Source inventory only. No build, test, hardware access or qualification run was performed, and none is claimed. +- Counts come from `grep` over the pinned trees at the listed paths. A caller that reaches the driver layer through a path not matched by these patterns could be missing. Evidence snapshot directories were excluded on purpose. +- The caller-to-cut table and the order dependency table are INFERRED. They are a proposal for review, not a decision. +- This document does not resolve aien-architecture#163 and does not authorize any boot, firmware change, reset or chip use. diff --git a/native/.crumb b/native/.crumb index 4369623b..9e6f89d5 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "2818fb66a9ca2dfce7f9c51733f7b175ad61f917e6a84436a42841ffd434c8f4", - "last_commit": "3b26ea9", + "digest": "c28edd6ebdf3c8e7285402d71efea9c5576429e7fb024dd79152f01f054866b0", + "last_commit": "c250fd2", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -109,15 +109,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:495bf4e4e0be4d5a633d16fc816e1141dcd75da29d4ee75a885b7658c69b8429", - "compiled_at": "2026-10-08T15:06:47Z", + "children_root": "sha256:08488a453b23e5b8836cffd54ceae1beb91d8307612299ff5c19354ebff14934", + "compiled_at": "2026-10-08T15:58:17Z", "compiler": "crumb-compile/1", - "digest": "sha256:4fb3cbe4fe847679a956f9a7da3183125e71a7383f362cca04fa9b8d20439cd8", + "digest": "sha256:fcfb41da00d8ff2d8162483a8bc323cdf31e6e30dddc05b90f481535e53ef61f", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 451, - "generated_at_commit": "9d9890388426bbfec1080dbbc395d852e1c57eea", - "source_tree": "sha256:84755fb8dc4b1801abdc15557191c75a354069eba706513f2643f16c8c76fcff" + "generated_at_commit": "2835db1cbb0117521468f3ab12e5396a2ad4f3f3", + "source_tree": "sha256:c3e7e36669876b9d4f2699ded3a2593f547ef6ca44b75e86411245ca5668791d" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index cb680e89..50c2bac8 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -58,13 +58,13 @@ }, { "digest": "ef1dd930dc3a359952e25dfc3c6d4c7a3a9ef3113bc2bd61c82efb8018f4dec3", - "last_commit": "3b26ea9", + "last_commit": "827e20f", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { - "digest": "fb8880e2cf5544851b097a3f9977d543ec58a4644a8e43ea615c7242a55de245", - "last_commit": "8641977", + "digest": "21bbcdddd7bb19bdc26b94e33495527555ce09589e355dbe233a39edc2bb3448", + "last_commit": "c250fd2", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, @@ -81,14 +81,14 @@ "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { - "digest": "25f9bc7ba37e97d49ebc01a48acf93cddb55bda543bed09eb60d25c43caaaaa5", - "last_commit": "8641977", + "digest": "f2a5c970c1c337189c6c1251edb501cbb77da5139043d3b4f3187d03bf37e725", + "last_commit": "c250fd2", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { "digest": "a2824603eee1429e7fe251a0051d43ec3d3822ba7f3796d2d554c359f0588ed0", - "last_commit": "3b26ea9", + "last_commit": "827e20f", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, @@ -99,15 +99,15 @@ "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:35dec528fcfd0bc269b879c51cc0d15d0bf448b9ad8a95e16371053a6097670c", - "compiled_at": "2026-10-08T15:06:47Z", + "children_root": "sha256:c8f64fe5280d1c55049b5260e4bb9306d96d558847eea11c42c2db653164453b", + "compiled_at": "2026-10-08T15:58:17Z", "compiler": "crumb-compile/1", - "digest": "sha256:2818fb66a9ca2dfce7f9c51733f7b175ad61f917e6a84436a42841ffd434c8f4", + "digest": "sha256:c28edd6ebdf3c8e7285402d71efea9c5576429e7fb024dd79152f01f054866b0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 287, - "generated_at_commit": "9d9890388426bbfec1080dbbc395d852e1c57eea", - "source_tree": "sha256:6e067439437bc2058d47dbb4d32b14bfde722b7974a7f9b131ab23d4f51ee9fa" + "generated_at_commit": "2835db1cbb0117521468f3ab12e5396a2ad4f3f3", + "source_tree": "sha256:038bf075bdc8ca7e4783a786a3db03c4f20eb3430fd3802f69e7bb4214eda8b3" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/dev/.crumb b/native/kernel/dev/.crumb index 8ff88708..ce558072 100644 --- a/native/kernel/dev/.crumb +++ b/native/kernel/dev/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-08T04:37:23Z", + "compiled_at": "2026-10-08T15:14:34Z", "compiler": "crumb-compile/1", - "digest": "sha256:fb8880e2cf5544851b097a3f9977d543ec58a4644a8e43ea615c7242a55de245", + "digest": "sha256:21bbcdddd7bb19bdc26b94e33495527555ce09589e355dbe233a39edc2bb3448", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 25, - "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244", - "source_tree": "sha256:d3a4a94ebc39bc7829d2ab686b737ab803fd53087202b4c002dee51b900673f0" + "generated_at_commit": "bf475a089d2824e0c923c42e73f948cc65c87c32", + "source_tree": "sha256:19bbff893ccd5342120c5ff800f7141dd8e126733e66be51c1c8958ef24fef8b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/dev/pci.c b/native/kernel/dev/pci.c index e5860d6f..07f61ad3 100644 --- a/native/kernel/dev/pci.c +++ b/native/kernel/dev/pci.c @@ -376,3 +376,118 @@ int pci_stage_probe(pci_system *s) wp ? " (window: QEMU virt mmio32, QEMU-only assumption)" : " (no window: firmware assignment only)"); return PCI_OK; } + +/* ---- Read-only discovery (see pci.h). ---- */ + +int pci_mcfg_parse_all(const uint8_t *t, size_t len, pci_ecam *out, uint32_t cap, uint32_t *n_out) +{ + if (!t || !out || !n_out) return PCI_E_ARG; + if (len < 44u + 16u) return PCI_E_MCFG; + if (t[0] != 'M' || t[1] != 'C' || t[2] != 'F' || t[3] != 'G') return PCI_E_MCFG; + if (le32(t + 4) != len) return PCI_E_MCFG; + if ((len - 44u) % 16u != 0) return PCI_E_MCFG; + uint32_t n = 0; + for (size_t off = 44; off + 16 <= len; off += 16) { + const uint8_t *e = t + off; + pci_ecam c; + c.base = le64(e); + c.segment = (uint16_t)(e[8] | e[9] << 8); + c.start_bus = e[10]; + c.end_bus = e[11]; + if (c.base == 0 || (c.base & 0xfffffu) != 0 || c.start_bus > c.end_bus) return PCI_E_MCFG; + uint64_t span = (uint64_t)((uint32_t)c.end_bus + 1u) << 20; + if (c.base + span < c.base) return PCI_E_MCFG; + for (uint32_t i = 0; i < n; i++) { + if (out[i].segment == c.segment && out[i].start_bus <= c.end_bus && c.start_bus <= out[i].end_bus) + return PCI_E_MCFG; + } + if (n >= cap) return PCI_E_FULL; + out[n++] = c; + } + *n_out = n; + return PCI_OK; +} + +/* The only config access discovery uses: const volatile, so a store through + * it does not compile. */ +static uint32_t rd32(const volatile uint8_t *c, uint32_t off) { return *(const volatile uint32_t *)(c + (off & ~3u)); } + +#define DISC_MAX_DEPTH 8u + +typedef struct { + const pci_bus_access *a; + uint16_t segment; + pci_found *out; + uint32_t cap, n, bridges; + uint32_t seen[8]; /* 256-bit visited set of scanned buses */ +} disc_ctx; + +static int disc_bus(disc_ctx *d, uint8_t bus, uint32_t depth) +{ + d->seen[bus >> 5] |= 1u << (bus & 31u); + for (uint32_t dev = 0; dev < 32; dev++) { + for (uint32_t fn = 0; fn < 8; fn++) { + const volatile uint8_t *c = pci_cfg(d->a, bus, (uint8_t)dev, (uint8_t)fn); + if (!c) return PCI_OK; + uint32_t id = rd32(c, CFG_VENDOR); + uint16_t vendor = (uint16_t)id; + if (vendor == 0xffffu || vendor == 0) { + if (fn == 0) break; /* no function 0: no device */ + continue; + } + uint8_t ht = (uint8_t)(rd32(c, 0x0c) >> 16); + if (d->n >= d->cap) return PCI_E_FULL; + pci_found *f = &d->out[d->n++]; + *f = (pci_found){0}; + f->segment = d->segment; + f->bus = bus; + f->dev = (uint8_t)dev; + f->fn = (uint8_t)fn; + f->vendor = vendor; + f->device = (uint16_t)(id >> 16); + uint32_t cr = rd32(c, CFG_CLASSREV); + f->class_code = cr >> 8; + f->revision = (uint8_t)cr; + f->header_type = ht; + uint32_t kind = ht & 0x7fu; + uint32_t nbars = kind == 0 ? 6u : (kind == 1 ? 2u : 0u); + for (uint32_t i = 0; i < nbars; i++) f->bar_raw[i] = rd32(c, CFG_BAR0 + 4u * i); + if (kind == 0) { + uint32_t ss = rd32(c, CFG_SUBSYS); + f->subsys_vendor = (uint16_t)ss; + f->subsys_id = (uint16_t)(ss >> 16); + } else if (kind == 1) { + uint32_t bn = rd32(c, 0x18); + f->secondary = (uint8_t)(bn >> 8); + f->subordinate = (uint8_t)(bn >> 16); + uint8_t sec = f->secondary; + if (sec > bus && sec <= d->a->end_bus && f->subordinate >= sec && depth < DISC_MAX_DEPTH && + !(d->seen[sec >> 5] & (1u << (sec & 31u)))) { + d->bridges++; + int rc = disc_bus(d, sec, depth + 1u); + if (rc != PCI_OK) return rc; + } + } + if (fn == 0 && !(ht & 0x80u)) break; /* single-function device */ + } + } + return PCI_OK; +} + +int pci_discover(const pci_bus_access *a, uint16_t segment, pci_found *out, uint32_t cap, uint32_t *n_out, + uint32_t *bridges_followed) +{ + if (!a || !out || !n_out || !a->ecam || a->start_bus > a->end_bus) return PCI_E_ARG; + disc_ctx d; + d.a = a; + d.segment = segment; + d.out = out; + d.cap = cap; + d.n = 0; + d.bridges = 0; + for (int i = 0; i < 8; i++) d.seen[i] = 0; + int rc = disc_bus(&d, a->start_bus, 0); + *n_out = d.n; + if (bridges_followed) *bridges_followed = d.bridges; + return rc; +} diff --git a/native/kernel/dev/pci.h b/native/kernel/dev/pci.h index 29da2bed..6a5733d3 100644 --- a/native/kernel/dev/pci.h +++ b/native/kernel/dev/pci.h @@ -52,6 +52,49 @@ void pci_w32(volatile uint8_t *cfg, uint32_t off, uint32_t v); uint16_t pci_r16(volatile uint8_t *cfg, uint32_t off); void pci_w16(volatile uint8_t *cfg, uint32_t off, uint16_t v); +/* ---- Read-only discovery (multi-segment) ---- + * + * pci_enumerate sizes BARs, which writes config space (all-ones BAR writes, + * COMMAND changes). The functions below never do: pci_discover reads config + * space through a read-only helper (const volatile pointers) and nothing + * else, so it is safe to run against a device the kernel must not disturb. + * + * Discovery never sizes BARs and never writes. bar_raw holds exactly what + * firmware left in each BAR register, unsized: the size is unknown, and the + * low bits are type flags. The values are bus addresses, not assumed to be + * CPU addresses. Header type 0 has 6 BAR registers, type 1 has 2; the + * unused entries are 0. */ + +/* Every MCFG allocation, in table order, up to cap entries. Same header + * checks as pci_mcfg_parse. Each entry needs base != 0, 1 MiB aligned, + * start_bus <= end_bus and base + ((end_bus + 1) << 20) not overflowing + * u64. Two allocations for one segment with overlapping bus ranges (exact + * duplicates included) are PCI_E_MCFG. More entries than cap: PCI_E_FULL + * (never truncated). `base` is the ECAM address of bus 0 of the segment, so + * bus b sits at base + (b << 20). */ +int pci_mcfg_parse_all(const uint8_t *table, size_t len, pci_ecam *out, uint32_t cap, uint32_t *n_out); + +typedef struct { + uint16_t segment; + uint8_t bus, dev, fn; + uint16_t vendor, device; + uint32_t class_code; /* class << 16 | subclass << 8 | progif */ + uint8_t revision, header_type; + uint16_t subsys_vendor, subsys_id; /* header type 0 only, else 0 */ + uint32_t bar_raw[PCI_MAX_BARS]; /* as read, unsized */ + uint8_t secondary, subordinate; /* header type 1 only, else 0 */ +} pci_found; + +/* Scan segment `segment` through `a`: bus start_bus, then every type-1 bridge + * whose secondary > its own bus, secondary <= end_bus, subordinate >= + * secondary, depth < 8 and whose bus was not scanned already. Vendor 0xffff + * or 0 is absent; an absent function 0 skips the device; the multi-function + * bit is honored. Fills out[0..*n_out). *bridges_followed (may be NULL) + * counts bridges whose secondary bus was scanned. Capacity exhausted: + * PCI_E_FULL. */ +int pci_discover(const pci_bus_access *a, uint16_t segment, pci_found *out, uint32_t cap, uint32_t *n_out, + uint32_t *bridges_followed); + /* Window for BARs firmware did not assign. [base, limit) and next. */ typedef struct { uint64_t base, limit, next; diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb index 87570a71..2e63fa6c 100644 --- a/native/kernel/svc/.crumb +++ b/native/kernel/svc/.crumb @@ -23,21 +23,21 @@ "purpose": "Directory native/kernel/svc/compat. Purpose not yet described by a human." }, { - "digest": "39c9c2b8feff5aaf975298941e3e516abb7975052bea34d91eca7830c768ac3c", - "last_commit": "e387b50", + "digest": "e20962c560a6c4f4370da0e582830c691a81ef01cf376b8176bfa3bb2ee6e557", + "last_commit": "8641977", "name": "tests", "purpose": "Directory native/kernel/svc/tests. Purpose not yet described by a human." } ], - "children_root": "sha256:670b6e0b6cddb12a9c081e4f1a4144e7f60c33dabba0574172362f002960a90a", - "compiled_at": "2026-10-08T04:37:23Z", + "children_root": "sha256:433085fba7ead748420255532396e7ffa382b57cfe8fd4dd217772dc5829d778", + "compiled_at": "2026-10-08T15:14:34Z", "compiler": "crumb-compile/1", - "digest": "sha256:25f9bc7ba37e97d49ebc01a48acf93cddb55bda543bed09eb60d25c43caaaaa5", + "digest": "sha256:f2a5c970c1c337189c6c1251edb501cbb77da5139043d3b4f3187d03bf37e725", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 35, - "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244", - "source_tree": "sha256:1400b1372b600007257a87d133c05c05dbd8ea903b0b67ac1d685d0f49c9f636" + "generated_at_commit": "bf475a089d2824e0c923c42e73f948cc65c87c32", + "source_tree": "sha256:4ba0c2b6cbceb7b4be08a248a493bca2d22be438c5ff964204f729dfb181ca94" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/tests/.crumb b/native/kernel/svc/tests/.crumb index f2b876e8..7555255e 100644 --- a/native/kernel/svc/tests/.crumb +++ b/native/kernel/svc/tests/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-08T04:37:23Z", + "compiled_at": "2026-10-08T15:14:34Z", "compiler": "crumb-compile/1", - "digest": "sha256:39c9c2b8feff5aaf975298941e3e516abb7975052bea34d91eca7830c768ac3c", + "digest": "sha256:e20962c560a6c4f4370da0e582830c691a81ef01cf376b8176bfa3bb2ee6e557", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 3, - "generated_at_commit": "e387b502b58d9d15fd2751ec5ef4c60f93862244", - "source_tree": "sha256:62244da11a623586ce71985dea268cb6ddb89e998517fb5542d6e2b42f47222d" + "generated_at_commit": "bf475a089d2824e0c923c42e73f948cc65c87c32", + "source_tree": "sha256:3fe5e78fba4704feb11507270a818f7a70695056fecc32c73b2b3fe6e544aaed" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/tests/stage_test.c b/native/kernel/svc/tests/stage_test.c index 587730c6..67dbb13b 100644 --- a/native/kernel/svc/tests/stage_test.c +++ b/native/kernel/svc/tests/stage_test.c @@ -5,6 +5,9 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <signal.h> +#include <sys/mman.h> +#include <sys/wait.h> #include "ck.h" #include "ck_host.h" #include "devices.h" @@ -165,6 +168,239 @@ static void test_pci_enum(void) free(ecam); } +/* ---------------- Multi-segment MCFG + read-only discovery ---------------- */ + +/* The recorded GB10 Spark MCFG: 16 allocations, 300 bytes. + * Source: docs/GB10_PLATFORM_TOPOLOGY.md, "ACPI MCFG / ECAM". */ +static size_t mk_gb10_mcfg(uint8_t *t) +{ + uint64_t b[16]; + uint16_t sg[16]; + uint8_t sb[16], eb[16]; + for (int i = 0; i < 16; i++) { + sg[i] = (uint16_t)i; + sb[i] = 0; + if (i < 15) { + b[i] = 0xF300000000ull + (uint64_t)i * 0x10000000ull; + eb[i] = i <= 10 ? 15 : 255; + } else { + b[i] = 0x29000000ull; + eb[i] = 1; + } + } + return mk_mcfg(t, 16, b, sg, sb, eb); +} + +static void test_mcfg_all(void) +{ + uint8_t t[44 + 16 * 16]; + pci_ecam e[16]; + uint32_t n = 99; + size_t len = mk_gb10_mcfg(t); + CHECK(len == 300); + CHECK(pci_mcfg_parse_all(t, len, e, 16, &n) == PCI_OK && n == 16); + CHECK(e[0].segment == 0 && e[0].base == 0xF300000000ull && e[0].end_bus == 15); + CHECK(e[10].segment == 10 && e[10].base == 0xF300000000ull + 10 * 0x10000000ull && e[10].end_bus == 15); + CHECK(e[11].segment == 11 && e[11].end_bus == 255); + CHECK(e[14].segment == 14 && e[14].end_bus == 255); + CHECK(e[15].segment == 15 && e[15].base == 0x29000000ull && e[15].start_bus == 0 && e[15].end_bus == 1); + CHECK(pci_mcfg_parse_all(t, len, e, 15, &n) == PCI_E_FULL); /* never truncates */ + CHECK(pci_mcfg_parse_all(t, len, e, 16, NULL) == PCI_E_ARG); + CHECK(pci_mcfg_parse_all(NULL, len, e, 16, &n) == PCI_E_ARG); + CHECK(pci_mcfg_parse_all(t, len, NULL, 16, &n) == PCI_E_ARG); + CHECK(pci_mcfg_parse_all(t, len - 1, e, 16, &n) == PCI_E_MCFG); /* length field mismatch */ + CHECK(pci_mcfg_parse_all(t, 44, e, 16, &n) == PCI_E_MCFG); /* no allocation */ + + uint64_t b[2] = {0x4010000000ull, 0x4020000000ull}; + uint16_t s[2] = {3, 3}; + uint8_t sb[2] = {0, 0}, eb[2] = {7, 7}; + len = mk_mcfg(t, 2, b, s, sb, eb); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_E_MCFG); /* exact duplicate range */ + sb[1] = 7; eb[1] = 9; + len = mk_mcfg(t, 2, b, s, sb, eb); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_E_MCFG); /* overlap on bus 7 */ + sb[1] = 8; + len = mk_mcfg(t, 2, b, s, sb, eb); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_OK && n == 2); /* adjacent ranges are fine */ + s[1] = 4; sb[1] = 0; eb[1] = 7; + len = mk_mcfg(t, 2, b, s, sb, eb); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_OK && n == 2); /* same range, other segment */ + sb[0] = 2; sb[1] = 0; + len = mk_mcfg(t, 2, b, s, sb, eb); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_OK && e[0].start_bus == 2 && e[0].end_bus == 7); + uint64_t ov[1] = {0xfffffffffff00000ull}; + uint16_t s0[1] = {0}; + uint8_t sbo[1] = {0}, ebo[1] = {1}; + len = mk_mcfg(t, 1, ov, s0, sbo, ebo); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_E_MCFG); /* base + span wraps u64 */ + uint64_t z[1] = {0}; + len = mk_mcfg(t, 1, z, s0, sbo, ebo); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_E_MCFG); /* zero base */ + uint64_t mis[1] = {0x4010080000ull}; + len = mk_mcfg(t, 1, mis, s0, sbo, ebo); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_E_MCFG); /* not 1 MiB aligned */ + uint8_t sbb[1] = {5}, ebb[1] = {4}; + len = mk_mcfg(t, 1, b, s0, sbb, ebb); + CHECK(pci_mcfg_parse_all(t, len, e, 4, &n) == PCI_E_MCFG); /* start > end */ +} + +#define FAKE_SEG 15u +#define FAKE_BUSES 2u +#define FAKE_BYTES ((size_t)FAKE_BUSES << 20) + +/* Fake segment-15 ECAM: root bridge 00:00.0 (secondary 1) and the GB10 at + * 01:00.0. The bridge device id is SYNTHETIC (the topology doc does not + * record it); the BAR raw values are SYNTHETIC too. */ +static uint8_t *mk_fake_seg15(void) +{ + uint8_t *ecam = mmap(NULL, FAKE_BYTES, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (ecam == MAP_FAILED) return NULL; + memset(ecam, 0xff, FAKE_BYTES); + uint8_t *c; + memset(c = cfgp(ecam, 0, 0, 0), 0, 4096); + mkfn(c, 0x10de, 0x7777 /* SYNTHETIC bridge id */, 0x060400, 1); + c[0x18] = 0; c[0x19] = 1; c[0x1a] = 1; + memset(c = cfgp(ecam, 1, 0, 0), 0, 4096); + mkfn(c, 0x10de, 0x2e12, 0x030000, 0); + c[0x08] = 0xa1; /* revision */ + put32(c + 0x10, 0x0000000cu); /* SYNTHETIC raw BARs */ + put32(c + 0x14, 0x00000001u); + put32(c + 0x18, 0x00000004u); + put32(c + 0x2c, 0x000010deu); /* subsys 10de:0000 */ + return ecam; +} + +static void acc_for(pci_bus_access *a, uint8_t *ecam, uint8_t sb, uint8_t eb) +{ + a->ecam = ecam; + a->start_bus = sb; + a->end_bus = eb; +} + +static void test_discover_seg15(void) +{ + uint8_t *ecam = mk_fake_seg15(); + CHECK(ecam != NULL); + if (!ecam) return; + static uint8_t copy[FAKE_BYTES]; + memcpy(copy, ecam, FAKE_BYTES); + CHECK(mprotect(ecam, FAKE_BYTES, PROT_READ) == 0); + pci_bus_access a; + acc_for(&a, ecam, 0, 1); + pci_found f[8]; + uint32_t n = 0, br = 0; + CHECK(pci_discover(&a, FAKE_SEG, f, 8, &n, &br) == PCI_OK); + CHECK(n == 2 && br == 1); + const pci_found *g = NULL; + for (uint32_t i = 0; i < n; i++) + if (f[i].vendor == 0x10de && f[i].device == 0x2e12) g = &f[i]; + CHECK(g != NULL); + if (g) { + CHECK(g->segment == FAKE_SEG && g->bus == 1 && g->dev == 0 && g->fn == 0); + CHECK(g->class_code == 0x030000 && g->revision == 0xa1 && g->header_type == 0); + CHECK(g->subsys_vendor == 0x10de && g->subsys_id == 0); + CHECK(g->bar_raw[0] == 0xcu && g->bar_raw[1] == 1u && g->bar_raw[2] == 4u && g->bar_raw[3] == 0); + } + CHECK(f[0].bus == 0 && (f[0].header_type & 0x7f) == 1 && f[0].secondary == 1 && f[0].subordinate == 1); + CHECK(memcmp(ecam, copy, FAKE_BYTES) == 0); /* zero writes */ + munmap(ecam, FAKE_BYTES); +} + +/* Run fn in a child; return 1 when it died of SIGSEGV/SIGBUS. */ +static int child_died_on_write(void (*fn)(uint8_t *), uint8_t *ecam) +{ + fflush(stdout); + pid_t p = fork(); + if (p < 0) return 0; + if (p == 0) { + signal(SIGSEGV, SIG_DFL); /* sanitizer builds install their own handler */ + signal(SIGBUS, SIG_DFL); + fn(ecam); + _exit(0); /* survived the write: the trap did not fire */ + } + int st = 0; + if (waitpid(p, &st, 0) != p) return 0; + return WIFSIGNALED(st) && (WTERMSIG(st) == SIGSEGV || WTERMSIG(st) == SIGBUS); +} + +static void child_enumerate(uint8_t *ecam) +{ + static pci_system s; + memset(&s, 0, sizeof s); + s.ecam.segment = FAKE_SEG; + s.acc.ecam = ecam; + s.acc.start_bus = 0; + s.acc.end_bus = 1; + (void)pci_enumerate(&s, NULL); /* sizes BARs: must write */ +} +static void child_w32(uint8_t *ecam) { pci_w32(cfgp(ecam, 1, 0, 0), 0x10, 0xffffffffu); } + +/* Negative control: the read-only page trap must catch real writes. */ +static void test_discover_trap(void) +{ + uint8_t *ecam = mk_fake_seg15(); + CHECK(ecam != NULL); + if (!ecam) return; + CHECK(mprotect(ecam, FAKE_BYTES, PROT_READ) == 0); + CHECK(child_died_on_write(child_enumerate, ecam)); + CHECK(child_died_on_write(child_w32, ecam)); + munmap(ecam, FAKE_BYTES); +} + +static void test_discover_edges(void) +{ + pci_found f[8]; + uint32_t n = 9, br = 9; + pci_bus_access a; + uint8_t *ecam = mmap(NULL, 4u << 20, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + CHECK(ecam != MAP_FAILED); + if (ecam == MAP_FAILED) return; + uint8_t *c; + + memset(ecam, 0xff, 4u << 20); /* empty bus */ + acc_for(&a, ecam, 0, 3); + CHECK(pci_discover(&a, 0, f, 8, &n, &br) == PCI_OK && n == 0 && br == 0); + CHECK(pci_discover(NULL, 0, f, 8, &n, &br) == PCI_E_ARG); + CHECK(pci_discover(&a, 0, f, 8, NULL, &br) == PCI_E_ARG); + + /* Loop: bridge on bus 1 whose secondary points back to bus 0. */ + memset(c = cfgp(ecam, 0, 0, 0), 0, 4096); mkfn(c, 0x1b36, 1, 0x060400, 1); + c[0x19] = 1; c[0x1a] = 3; + memset(c = cfgp(ecam, 1, 0, 0), 0, 4096); mkfn(c, 0x1b36, 2, 0x060400, 1); + c[0x19] = 0; c[0x1a] = 3; + CHECK(pci_discover(&a, 0, f, 8, &n, &br) == PCI_OK); + CHECK(n == 2 && br == 1); /* back-edge not followed, counted once */ + + /* Secondary beyond end_bus: not followed. */ + memset(ecam, 0xff, 4u << 20); + memset(c = cfgp(ecam, 0, 0, 0), 0, 4096); mkfn(c, 0x1b36, 1, 0x060400, 1); + c[0x19] = 5; c[0x1a] = 5; + memset(c = cfgp(ecam, 1, 0, 0), 0, 4096); mkfn(c, 0x1b36, 3, 0x020000, 0); + CHECK(pci_discover(&a, 0, f, 8, &n, &br) == PCI_OK && n == 1 && br == 0); + c = cfgp(ecam, 0, 0, 0); c[0x19] = 2; c[0x1a] = 1; /* subordinate < secondary */ + CHECK(pci_discover(&a, 0, f, 8, &n, &br) == PCI_OK && n == 1 && br == 0); + + /* Multi-function and fn0-absent handling on bus 0. */ + memset(ecam, 0xff, 4u << 20); + memset(c = cfgp(ecam, 0, 1, 0), 0, 4096); mkfn(c, 0x8086, 1, 0x020000, 0x80); + memset(c = cfgp(ecam, 0, 1, 3), 0, 4096); mkfn(c, 0x8086, 2, 0x020000, 0); + memset(c = cfgp(ecam, 0, 2, 1), 0, 4096); mkfn(c, 0x8086, 3, 0x020000, 0); /* fn0 absent: skipped */ + memset(c = cfgp(ecam, 0, 3, 0), 0, 4096); mkfn(c, 0x8086, 4, 0x020000, 0); + memset(c = cfgp(ecam, 0, 3, 1), 0, 4096); mkfn(c, 0x8086, 5, 0x020000, 0); /* not multi-fn: skipped */ + CHECK(pci_discover(&a, 0, f, 8, &n, &br) == PCI_OK && n == 3); + + /* Capacity exhaustion. */ + CHECK(pci_discover(&a, 0, f, 2, &n, &br) == PCI_E_FULL); + + /* Nonzero start_bus accessor: ecam maps bus 2 at offset 0. */ + memset(ecam, 0xff, 4u << 20); + memset(c = cfgp(ecam, 0, 4, 0), 0, 4096); mkfn(c, 0x1af4, 9, 0x020000, 0); + acc_for(&a, ecam, 2, 3); + CHECK(pci_discover(&a, 7, f, 8, &n, &br) == PCI_OK && n == 1); + CHECK(f[0].segment == 7 && f[0].bus == 2 && f[0].dev == 4 && f[0].device == 9); + munmap(ecam, 4u << 20); +} + /* ---------------- Store boot ---------------- */ #define T_UNITS 128u @@ -1026,6 +1262,10 @@ int main(void) test_mcfg(); test_pci_bars(); test_pci_enum(); + test_mcfg_all(); + test_discover_seg15(); + test_discover_trap(); + test_discover_edges(); test_store(); test_artifact_store(); test_security();