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#291 (code only)
Apply it
git checkout -b patch-3aae2d793821fc9b 2bc7146ee21806d0537c16fe70acabf5f0f6126f curl -fsSL https://interplane.io/drakestapleton/aienux/patches/3aae2d793821fc9b.patch | git am
Provenance
github-import 1
aien-dev/aienux
291
b0c241e1dc6be9a14b63d67c4bde9f8140d6cf4b
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":291,"url":"https://github.com/aien-dev/aienux/pull/291","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:08Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index dbafc4d6..d8c3c07a 100644 --- a/.crumb +++ b/.crumb @@ -33,8 +33,8 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "2508c6a924a31abe677b3d564e8172057fdbb8e4b8c3441ce2ec207f771f6f6e", - "last_commit": "6c9c279", + "digest": "8d74f1310d995e22561d226cd8d1b9e682ff4d2087744288b9ffd2e1a5971598", + "last_commit": "2bc7146", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, @@ -45,15 +45,15 @@ "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:c93b50212afee19aa7c152c53fd9329a04047f066f9ef3d18bdcc7eb3919e57e", - "compiled_at": "2026-10-08T19:22:53Z", + "children_root": "sha256:602c7412daa910a2a9330a9330815e04b41293dfb1e8b24f656ba9641cb073d2", + "compiled_at": "2026-10-08T20:55:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:a90c942c363dd04a1141de44d62ecc2b13027ec64e0e58d992cb142e5e12491f", + "digest": "sha256:19c411defb0c80092a8f280e7c34f5c4592a69042f4fea32674d913602fc2261", "evidence_files": 153, "evidence_root": "sha256:29aa8775feb12d9e0e64b41fc1fc48b97e32dc16bf9176562cbe9fe1ea934f00", "files": 3026, - "generated_at_commit": "6c9c2799bd7e4a2a3f9b4185ae55c15942ed5fdb", - "source_tree": "sha256:50041d54f493aa0ef288579f559dd27646b26b0665e2ba670ee9bee7ccf63aca" + "generated_at_commit": "2bc7146ee21806d0537c16fe70acabf5f0f6126f", + "source_tree": "sha256:e60f824a0c8a8e331fa6b7194a121808952b854d5a3432c456d572f76406d197" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index 19b92524..fd99d776 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "0bff4de2cdaf9905ed7745907b1791dbcd8b74346471421b140808c4021a3b86", - "last_commit": "6c9c279", + "digest": "b47571fa3b5eb47059f00780535c46cf82c21af7956bc4eb3eb7d75e7450acab", + "last_commit": "2bc7146", "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:483e925cab7fe680f03080ef5bae1c6b1fd0b2128f60521f89b214d019ade1a5", - "compiled_at": "2026-10-08T19:22:53Z", + "children_root": "sha256:e18fc3db4c0756270c97037df877ec94f8bd21f7d67256c49c01aa636935d844", + "compiled_at": "2026-10-08T20:55:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:2508c6a924a31abe677b3d564e8172057fdbb8e4b8c3441ce2ec207f771f6f6e", + "digest": "sha256:8d74f1310d995e22561d226cd8d1b9e682ff4d2087744288b9ffd2e1a5971598", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 453, - "generated_at_commit": "6c9c2799bd7e4a2a3f9b4185ae55c15942ed5fdb", - "source_tree": "sha256:f380bef47a92a11422c47452aa0f75a7916cedf8983812a217aea714e109417e" + "generated_at_commit": "2bc7146ee21806d0537c16fe70acabf5f0f6126f", + "source_tree": "sha256:70628cdac734ea7fca82204eaad18bc8d46cdae3facf7d304e17db58423a02fa" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index c126b142..42e717c1 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -63,32 +63,32 @@ "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { - "digest": "eb486dd2df49bdb2cfb324751f5d3ef3bfee1d103448c4868d0e66f354f19f57", - "last_commit": "6c9c279", + "digest": "8bec4ed4dbf4745c8f311bebfbd58eab460696ec9651b1d3ac7b2f712e72a4cf", + "last_commit": "2bc7146", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, { "digest": "e650493f5b00f0c22a9415f6b6bac3682d0ae95da8d22f4f96768ce420f180c4", - "last_commit": "9696c7d", + "last_commit": "2bc7146", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, { "digest": "8252fab960e4a3bb686f2e864b0d9a0571f43381d5006de2ff6c134c132ef092", - "last_commit": "6c9c279", + "last_commit": "2bc7146", "name": "mm", "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { - "digest": "0a7eb3875f4a67e425459d8026dfd62df410f4b4b40d052d1f9e9a740ac8688d", - "last_commit": "6c9c279", + "digest": "92746c0561f8e54e2164b2616421fe55acb34bd38aff2461110a437d483b4053", + "last_commit": "2bc7146", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { "digest": "914e88d9cb6247068ad34e800b17579e9f4d3717c4a9e94cd66ee44ecf0b9bc0", - "last_commit": "9696c7d", + "last_commit": "2bc7146", "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:ecd7fa69cf22a075779debb40e75fe3a7c0dae4f9b6a7e27f5302aacbc14cc05", - "compiled_at": "2026-10-08T19:22:53Z", + "children_root": "sha256:0a2830745e83800fe517e2f9e374b269aeeb689bbda5368d02735bf3566190cf", + "compiled_at": "2026-10-08T20:55:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:0bff4de2cdaf9905ed7745907b1791dbcd8b74346471421b140808c4021a3b86", + "digest": "sha256:b47571fa3b5eb47059f00780535c46cf82c21af7956bc4eb3eb7d75e7450acab", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 289, - "generated_at_commit": "6c9c2799bd7e4a2a3f9b4185ae55c15942ed5fdb", - "source_tree": "sha256:948d2b5a45ea4f1ebf616f3b6a9a401105e7955ef9d7739653df46ab7b24f001" + "generated_at_commit": "2bc7146ee21806d0537c16fe70acabf5f0f6126f", + "source_tree": "sha256:086e9508300b8e643c6ecb3c8f1a18af237068cdafbdc979682d82700eded2d1" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/dev/.crumb b/native/kernel/dev/.crumb index 74bb5dc0..6f904bf9 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-08T19:22:53Z", + "compiled_at": "2026-10-08T20:55:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:eb486dd2df49bdb2cfb324751f5d3ef3bfee1d103448c4868d0e66f354f19f57", + "digest": "sha256:8bec4ed4dbf4745c8f311bebfbd58eab460696ec9651b1d3ac7b2f712e72a4cf", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 27, - "generated_at_commit": "6c9c2799bd7e4a2a3f9b4185ae55c15942ed5fdb", - "source_tree": "sha256:143b14d79855296492d77e5431b5f5631ffa4ddc64e8e93001b602efd1fde3c2" + "generated_at_commit": "2bc7146ee21806d0537c16fe70acabf5f0f6126f", + "source_tree": "sha256:14784b04b7698f9d607bb95d9a7ac04aa1d615bf75025fa570314e8bdfadf5df" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/dev/devices.c b/native/kernel/dev/devices.c index de054b40..16d44b9e 100644 --- a/native/kernel/dev/devices.c +++ b/native/kernel/dev/devices.c @@ -62,6 +62,13 @@ int ck_stage_devices(void) ck_xhci_after_sweep(&g_pci); /* TEST-ONLY bm-left-on mutation hook; no-op otherwise */ int nrc = ck_nvme_bind(&g_nvme, &g_pci); if (nrc) ck_dev_nvme_release(); /* a failed bind never keeps DMA */ + /* Report-only (aienos#31, cut S1): the NVMe the multi-segment discovery sees, and whether it is the + * function the segment-0 probe bound above. Binding is unchanged. */ + { + uint32_t dn = 0; + const pci_found *df = pci_stage_disc_found(&dn); + (void)pci_nvme_disc_report(df, dn, g_nvme.pf); + } virtio_pci_caps caps; const pci_func *vf = 0; int vrc = ck_virtio_net_probe(&g_pci, &caps, &vf); diff --git a/native/kernel/dev/pci.c b/native/kernel/dev/pci.c index 42d7de5d..ade648f8 100644 --- a/native/kernel/dev/pci.c +++ b/native/kernel/dev/pci.c @@ -564,3 +564,53 @@ const pci_found *pci_stage_disc_found(uint32_t *n) *n = g_disc_all_n; return g_disc_all; } + +static int found_before(const pci_found *a, const pci_found *b) +{ + if (a->segment != b->segment) return a->segment < b->segment; + if (a->bus != b->bus) return a->bus < b->bus; + if (a->dev != b->dev) return a->dev < b->dev; + return a->fn < b->fn; +} + +const pci_found *pci_disc_find_class(const pci_found *f, uint32_t n, uint32_t class_code, uint32_t mask, + uint32_t *count) +{ + const pci_found *best = 0; + uint32_t c = 0; + for (uint32_t i = 0; f && i < n; i++) { + if ((f[i].class_code & mask) != (class_code & mask)) continue; + c++; + if (!best || found_before(&f[i], best)) best = &f[i]; + } + if (count) *count = c; + return best; +} + +/* BAR0 as firmware left it (type bits stripped), 64-bit when the type says so. */ +static uint64_t found_bar0(const pci_found *f) +{ + uint32_t raw = f->bar_raw[0]; + if (raw & 1u) return 0; /* I/O BAR: not a memory address */ + uint64_t a = raw & ~0xfu; + if (((raw >> 1) & 3u) == 2u) a |= (uint64_t)f->bar_raw[1] << 32; + return a; +} + +int pci_nvme_disc_report(const pci_found *f, uint32_t n, const pci_func *bound) +{ + uint32_t cnt = 0; + const pci_found *c = pci_disc_find_class(f, n, 0x010802u, 0xffffffu, &cnt); + if (!c) { + ck_printf("nvme_disc: no class 0x010802 function found by discovery (report-only; bound via segment-0 probe: %s)\n", + bound ? "different" : "none"); + return 0; + } + const char *rel = !bound ? "none" + : (bound->segment == c->segment && bound->bus == c->bus && bound->dev == c->dev && bound->fn == c->fn) + ? "same" : "different"; + ck_printf("nvme_disc: candidate seg %04x %02x:%02x.%u bar0=0x%llx decode=%u (report-only; bound via segment-0 probe: %s)\n", + c->segment, c->bus, c->dev, c->fn, (unsigned long long)found_bar0(c), (c->command >> 1) & 1u, rel); + ck_printf("nvme_disc: candidates=%u\n", cnt); + return (int)cnt; +} diff --git a/native/kernel/dev/pci.h b/native/kernel/dev/pci.h index dfef1436..7951a58e 100644 --- a/native/kernel/dev/pci.h +++ b/native/kernel/dev/pci.h @@ -189,4 +189,15 @@ int pci_stage_discover_report(void); * read-only MMIO window report (mmio_window.h). */ const pci_found *pci_stage_disc_found(uint32_t *n); +/* NVMe through multi-segment discovery (aienos#31, cut S1). Pure selector over + * a discovery result: the first function (lowest segment, then bus, device, + * function) whose class_code & mask == class_code & mask of the argument, or + * NULL. *count (may be NULL) receives how many functions match. Reads only. */ +const pci_found *pci_disc_find_class(const pci_found *f, uint32_t n, uint32_t class_code, uint32_t mask, + uint32_t *count); +/* Report-only: print the discovery's NVMe (class 0x010802) candidate and + * whether the function the segment-0 probe bound (`bound`, NULL when none) + * is the same. Changes no state; returns the number of candidates. */ +int pci_nvme_disc_report(const pci_found *f, uint32_t n, const pci_func *bound); + #endif diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb index 3484e323..999aeaa8 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": "888b438572314172f18df52857b6944d99eee4da30879a9529dd4fb60b810f34", - "last_commit": "6c9c279", + "digest": "fad382cd7d13229d5c405da8dda0a1e0c654b5964b50e9c606ede401712fa8b6", + "last_commit": "2bc7146", "name": "tests", "purpose": "Directory native/kernel/svc/tests. Purpose not yet described by a human." } ], - "children_root": "sha256:94f60cd1c34c5ae4cff0e68696855fcda17faa2e3b8f457890eba212cab8429d", - "compiled_at": "2026-10-08T19:22:53Z", + "children_root": "sha256:ef6515417279758e8cad782e4d8d6c2c2208ee9b907764f4a19acf625442611c", + "compiled_at": "2026-10-08T20:55:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:0a7eb3875f4a67e425459d8026dfd62df410f4b4b40d052d1f9e9a740ac8688d", + "digest": "sha256:92746c0561f8e54e2164b2616421fe55acb34bd38aff2461110a437d483b4053", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 35, - "generated_at_commit": "6c9c2799bd7e4a2a3f9b4185ae55c15942ed5fdb", - "source_tree": "sha256:d732de545873e9c9bc878b9e59cafdab9de87402771ec705d17d9a0dfa644fb1" + "generated_at_commit": "2bc7146ee21806d0537c16fe70acabf5f0f6126f", + "source_tree": "sha256:8b83480b0e21d0730d1bdd2352efc6a9f2e3800beb193413248201fc1e65ede8" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/tests/.crumb b/native/kernel/svc/tests/.crumb index f93aa900..2404c353 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-08T19:22:53Z", + "compiled_at": "2026-10-08T20:55:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:888b438572314172f18df52857b6944d99eee4da30879a9529dd4fb60b810f34", + "digest": "sha256:fad382cd7d13229d5c405da8dda0a1e0c654b5964b50e9c606ede401712fa8b6", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 3, - "generated_at_commit": "6c9c2799bd7e4a2a3f9b4185ae55c15942ed5fdb", - "source_tree": "sha256:9ee97eada964e633dc634752452cd0575794f5643eef5c9f52e4810f58335696" + "generated_at_commit": "2bc7146ee21806d0537c16fe70acabf5f0f6126f", + "source_tree": "sha256:e28312bae8bd73464239c186a6bbf6cadbf10220f442af074589059cb612fb9d" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/tests/stage_test.c b/native/kernel/svc/tests/stage_test.c index eb7a27a4..468e75bc 100644 --- a/native/kernel/svc/tests/stage_test.c +++ b/native/kernel/svc/tests/stage_test.c @@ -557,6 +557,144 @@ static void test_discover_in_stage(void) munmap(e15, FAKE_BYTES); } +/* ---------------- NVMe found through multi-segment discovery (aienos#31, cut S1) ---------------- */ + +/* Fake segment with a type-1 bridge at 00:00.0 (secondary bus 1) and an NVMe + * (class 010802, SYNTHETIC ids, 64-bit BAR0 at `bar0`, memory decode per + * `decode`) at 01:00.0. The Spark NVMe segment/BDF is not recorded in + * docs/GB10_PLATFORM_TOPOLOGY.md, so every segment number used for it here is + * synthetic. */ +static uint8_t *mk_nvme_seg(uint64_t bar0, int decode) +{ + uint8_t *ecam = map_aligned(FAKE_BYTES); + if (!ecam) return NULL; + memset(ecam, 0xff, FAKE_BYTES); + uint8_t *c; + memset(c = cfgp(ecam, 0, 0, 0), 0, 4096); + mkfn(c, 0x1b36, 0x000c /* 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, 0x144d, 0xa80a /* SYNTHETIC nvme id */, 0x010802, 0); + put32(c + 0x10, (uint32_t)bar0 | 4u); + put32(c + 0x14, (uint32_t)(bar0 >> 32)); + put32(c + 0x04, decode ? 0x2u : 0u); + return ecam; +} + +static size_t mk_n_mcfg(uint8_t *t, int n, uint8_t *const *e, const uint16_t *seg) +{ + uint64_t b[4]; + uint8_t sb[4] = {0, 0, 0, 0}, eb[4] = {1, 1, 1, 1}; + for (int i = 0; i < n; i++) b[i] = (uint64_t)(uintptr_t)e[i]; + return mk_mcfg(t, n, b, seg, sb, eb); +} + +static void test_pci_disc_find_class(void) +{ + pci_found f[4]; + memset(f, 0, sizeof f); + f[0].segment = 9; f[0].bus = 1; f[0].class_code = 0x010802; + f[1].segment = 2; f[1].bus = 5; f[1].dev = 1; f[1].class_code = 0x010802; + f[2].segment = 2; f[2].bus = 5; f[2].dev = 0; f[2].fn = 1; f[2].class_code = 0x010802; + f[3].segment = 0; f[3].class_code = 0x060000; + uint32_t cnt = 99; + const pci_found *p = pci_disc_find_class(f, 4, 0x010802, 0xffffff, &cnt); + CHECK(p == &f[2] && cnt == 3); /* lowest segment, bus, dev, fn; all three counted */ + CHECK(pci_disc_find_class(f, 4, 0x010802, 0xffffff, NULL) == &f[2]); + CHECK(pci_disc_find_class(f, 4, 0x0c0330, 0xffffff, &cnt) == NULL && cnt == 0); + CHECK(pci_disc_find_class(NULL, 0, 0x010802, 0xffffff, &cnt) == NULL && cnt == 0); + CHECK(pci_disc_find_class(f, 4, 0x010800, 0xffff00, &cnt) == &f[2] && cnt == 3); /* mask */ + CHECK(pci_disc_find_class(f, 4, 0x060000, 0xff0000, &cnt) == &f[3] && cnt == 1); /* base class only */ +} + +static void test_nvme_disc_report(void) +{ + uint8_t *e0 = mk_fake_seg0(), *e15 = mk_fake_seg15_aligned(); + uint8_t *e3 = mk_nvme_seg(0x4000000000ull, 1), *e7 = mk_nvme_seg(0x5000000000ull, 0); + CHECK(e0 && e15 && e3 && e7); + if (!e0 || !e15 || !e3 || !e7) return; + /* Segment 0 here is a host bridge only (no NVMe): GB10 style. */ + static uint8_t c0[FAKE_BYTES], c3[FAKE_BYTES], c7[FAKE_BYTES], c15[FAKE_BYTES]; + memset(cfgp(e0, 0, 1, 0), 0xff, 4096); /* drop the NIC */ + memcpy(c0, e0, FAKE_BYTES); memcpy(c3, e3, FAKE_BYTES); memcpy(c7, e7, FAKE_BYTES); memcpy(c15, e15, FAKE_BYTES); + CHECK(mprotect(e0, FAKE_BYTES, PROT_READ) == 0 && mprotect(e3, FAKE_BYTES, PROT_READ) == 0); + CHECK(mprotect(e7, FAKE_BYTES, PROT_READ) == 0 && mprotect(e15, FAKE_BYTES, PROT_READ) == 0); + /* Table order is NOT segment order: 15, 7, 3, 0. */ + uint8_t *es[4] = {e15, e7, e3, e0}; + uint16_t ss[4] = {FAKE_SEG, 7, 3, 0}; + uint8_t t[44 + 16 * 4 + 16]; + mk_n_mcfg(t, 4, es, ss); + ck_host_mcfg = t; + ck_host_try_map_ok = 1; + ck_host_try_map_fail = 0; + + pci_func bound; + memset(&bound, 0, sizeof bound); + ck_host_capture_start(); + CHECK(pci_stage_discover_report() == PCI_OK); + uint32_t nf = 0; + const pci_found *found = pci_stage_disc_found(&nf); + + /* No segment-0 bind at all: report "none". */ + CHECK(pci_nvme_disc_report(found, nf, NULL) == 2); + /* Bound function is the discovered one (same segment 3, 01:00.0). */ + bound.segment = 3; bound.bus = 1; bound.dev = 0; bound.fn = 0; + CHECK(pci_nvme_disc_report(found, nf, &bound) == 2); + /* Bound function differs (segment-0 style 00:02.0). */ + bound.segment = 0; bound.bus = 0; bound.dev = 2; + CHECK(pci_nvme_disc_report(found, nf, &bound) == 2); + /* No candidates at all. */ + CHECK(pci_nvme_disc_report(found, 0, NULL) == 0); + CHECK(pci_nvme_disc_report(found, 0, &bound) == 0); + ck_host_capture_stop(); + const char *x = ck_host_capture_text(); + CHECK(has(x, "pci_disc: segments=4 functions=7")); + CHECK(has(x, "nvme_disc: candidate seg 0003 01:00.0 bar0=0x4000000000 decode=1 (report-only; bound via segment-0 probe: none)\n")); + CHECK(has(x, "nvme_disc: candidate seg 0003 01:00.0 bar0=0x4000000000 decode=1 (report-only; bound via segment-0 probe: same)\n")); + CHECK(has(x, "nvme_disc: candidate seg 0003 01:00.0 bar0=0x4000000000 decode=1 (report-only; bound via segment-0 probe: different)\n")); + CHECK(!has(x, "seg 0007 01:00.0 bar0=0x5000000000 decode=0 (report-only; bound")); /* second one is counted, not chosen */ + CHECK(has(x, "nvme_disc: candidates=2\n")); + CHECK(has(x, "nvme_disc: no class 0x010802 function found by discovery (report-only; bound via segment-0 probe: none)\n")); + CHECK(has(x, "nvme_disc: no class 0x010802 function found by discovery (report-only; bound via segment-0 probe: different)\n")); + /* Read-only: fake ECAMs are PROT_READ (a config write would have killed the test) and unchanged. */ + CHECK(memcmp(e0, c0, FAKE_BYTES) == 0 && memcmp(e3, c3, FAKE_BYTES) == 0); + CHECK(memcmp(e7, c7, FAKE_BYTES) == 0 && memcmp(e15, c15, FAKE_BYTES) == 0); + + ck_host_mcfg = NULL; + ck_host_try_map_ok = 0; + munmap(e0, FAKE_BYTES); munmap(e3, FAKE_BYTES); munmap(e7, FAKE_BYTES); munmap(e15, FAKE_BYTES); +} + +/* The devices stage prints the nvme_disc report after the bind, with the + * binding unchanged (the NVMe behind segment 3 is reported; the stage's + * segment-0 probe finds no NVMe, so nothing binds and the report says "none"). */ +static void test_nvme_disc_in_stage(void) +{ + uint8_t *e0 = mk_fake_seg0(), *e3 = mk_nvme_seg(0x4000000000ull, 0); /* decode off: the B3 window report must not read the fake BAR */ + CHECK(e0 && e3); + if (!e0 || !e3) return; + uint8_t *es[2] = {e0, e3}; + uint16_t ss[2] = {0, 3}; + uint8_t t[44 + 16 * 2 + 16]; + mk_n_mcfg(t, 2, es, ss); + ck_host_mcfg = t; + ck_host_try_map_ok = 1; + ck_host_quiet = 1; + ck_host_capture_start(); + CHECK(ck_stage_devices() == 0); + ck_host_capture_stop(); + const char *x = ck_host_capture_text(); + const char *d = strstr(x, "nvme_disc: candidate seg 0003 01:00.0"), *v = strstr(x, "devices: pci=ok"); + CHECK(d && v && d < v); + CHECK(has(x, "decode=0 (report-only; bound via segment-0 probe: none)\n")); + CHECK(has(x, "bound via segment-0 probe: none)\n")); + CHECK(has(x, "devices: pci=ok nvme=unbound")); + ck_host_mcfg = NULL; + ck_host_try_map_ok = 0; + ck_host_quiet = 0; + munmap(e0, FAKE_BYTES); munmap(e3, FAKE_BYTES); +} + /* ---------------- Store boot ---------------- */ @@ -1801,6 +1939,9 @@ int main(void) test_discover_edges(); test_discover_report(); test_discover_in_stage(); + test_pci_disc_find_class(); + test_nvme_disc_report(); + test_nvme_disc_in_stage(); test_mmio_window(); test_mmio_unmap(); test_mmio_stage_report();