interplane.Get Omega
Read in your language

physics-mv

FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.

Brought by drakestapleton

branch main Branches Tags History

physics-mv / m15 / tools / m15tool.c

701 lines · 29585 bytes Raw Blame History
1#include "../physics_accel.h"
2#include "../physics_accel_native.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <stdbool.h>
7#include <unistd.h>
8#include <sys/stat.h>
9#include <time.h>
10#include <assert.h>
11
12#define PHYSICS_KERNEL_MEM_BASE 0x0000000080000000ULL
13#define PHYSICS_KERNEL_MEM_SIZE 0x0000000001000000ULL /* 16 MiB */
14
15static void print_gate(const char *name, bool pass, const char *desc) {
16 printf(" [%s] %-42s : %s\n", pass ? "PASS" : "FAIL", name, desc);
17}
18
19/* ============================================================================
20 * GATE 1: PHYSICS_ACCEL_MEM_BOUNDS_PASS
21 * Coherent DRAM envelope boundaries and Physics kernel memory isolation.
22 * ============================================================================ */
23static bool test_gate_1_mem_bounds(void) {
24 PhysicsAcceleratorLink link;
25 physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
26 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE);
27
28 Smmuv3StreamConfig cfg = {
29 .stream_id = GB10_STREAM_ID,
30 .ste_index = 0,
31 .cd_table_base = 0x82000000ULL,
32 .ttbr0_base = 0x83000000ULL,
33 .mair_value = 0xFF,
34 .t0sz = 16,
35 .granule_size = 4096,
36 .stage1_enabled = true,
37 .fault_trap_enabled = true
38 };
39 physics_accel_configure_smmu(&link, &cfg);
40
41 AcceleratorCapability cap = {
42 .slot = 1,
43 .generation = 1,
44 .principal_id = 42,
45 .resource_type = RES_ACCELERATOR,
46 .allowed_ops = ACCEL_OP_MAP_DMA | ACCEL_OP_UNMAP_DMA,
47 .iova_bound_base = 0x10000000ULL,
48 .iova_bound_size = 0x10000000ULL,
49 .queue_id_mask = 0x1,
50 .revocation_state = 1
51 };
52
53 /* 1. Valid window in DRAM */
54 DmaWindowDescriptor valid_win = {
55 .iova_base = 0x10000000ULL,
56 .phys_base = 0x90000000ULL,
57 .size_bytes = 0x100000ULL,
58 .permissions = DMA_PERM_READ | DMA_PERM_WRITE | DMA_PERM_COHERENT
59 };
60 EffectReceipt r1;
61 int rc1 = physics_accel_grant_dma_window(&link, &cap, &valid_win, &r1);
62 if (rc1 != 0 || r1.decision != DEC_ADMITTED) return false;
63
64 /* 2. Invalid window: overlapping protected Physics kernel memory */
65 DmaWindowDescriptor kernel_overlap_win = {
66 .iova_base = 0x11000000ULL,
67 .phys_base = 0x80500000ULL, /* Inside [0x80000000, 0x81000000) */
68 .size_bytes = 0x100000ULL,
69 .permissions = DMA_PERM_READ | DMA_PERM_WRITE
70 };
71 EffectReceipt r2;
72 int rc2 = physics_accel_grant_dma_window(&link, &cap, &kernel_overlap_win, &r2);
73 if (rc2 == 0 || r2.decision != DEC_REJECTED) return false;
74
75 /* 3. Invalid window: completely outside DRAM envelope */
76 DmaWindowDescriptor outside_win = {
77 .iova_base = 0x12000000ULL,
78 .phys_base = 0x3000000000ULL, /* Outside 128 GiB DRAM */
79 .size_bytes = 0x100000ULL,
80 .permissions = DMA_PERM_READ | DMA_PERM_WRITE
81 };
82 EffectReceipt r3;
83 int rc3 = physics_accel_grant_dma_window(&link, &cap, &outside_win, &r3);
84 if (rc3 == 0 || r3.decision != DEC_REJECTED) return false;
85
86 return true;
87}
88
89/* ============================================================================
90 * GATE 2: PHYSICS_ACCEL_DMA_POLICY_PASS
91 * SMMUv3 Stage 1 IOVA-to-PA translation mapping policy and DMA sandboxing.
92 * ============================================================================ */
93static bool test_gate_2_dma_policy(void) {
94 PhysicsAcceleratorLink link;
95 physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
96 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE);
97
98 Smmuv3StreamConfig cfg = {
99 .stream_id = GB10_STREAM_ID,
100 .ste_index = 0,
101 .cd_table_base = 0x82000000ULL,
102 .ttbr0_base = 0x83000000ULL,
103 .mair_value = 0xFF,
104 .t0sz = 16,
105 .granule_size = 4096,
106 .stage1_enabled = true,
107 .fault_trap_enabled = true
108 };
109 if (physics_accel_configure_smmu(&link, &cfg) != 0) return false;
110
111 AcceleratorCapability cap = {
112 .slot = 1,
113 .generation = 1,
114 .principal_id = 42,
115 .resource_type = RES_ACCELERATOR,
116 .allowed_ops = ACCEL_OP_MAP_DMA | ACCEL_OP_UNMAP_DMA,
117 .iova_bound_base = 0x10000000ULL,
118 .iova_bound_size = 0x10000000ULL,
119 .revocation_state = 1
120 };
121
122 DmaWindowDescriptor win = {
123 .iova_base = 0x10000000ULL,
124 .phys_base = 0x90000000ULL,
125 .size_bytes = 0x20000ULL,
126 .permissions = DMA_PERM_READ | DMA_PERM_WRITE | DMA_PERM_COHERENT
127 };
128 EffectReceipt r;
129 if (physics_accel_grant_dma_window(&link, &cap, &win, &r) != 0) return false;
130
131 /* Verify SMMU translation at base, interior, and edge */
132 uint64_t pa = 0;
133 if (physics_accel_smmu_translate(&link, 0x10000000ULL, 4096, DMA_PERM_READ, &pa) != SMMU_FAULT_NONE) return false;
134 if (pa != 0x90000000ULL) return false;
135
136 if (physics_accel_smmu_translate(&link, 0x10004000ULL, 4096, DMA_PERM_WRITE, &pa) != SMMU_FAULT_NONE) return false;
137 if (pa != 0x90004000ULL) return false;
138
139 if (physics_accel_smmu_translate(&link, 0x1001F000ULL, 4096, DMA_PERM_READ, &pa) != SMMU_FAULT_NONE) return false;
140 if (pa != 0x9001F000ULL) return false;
141
142 /* DMA Sandbox Verification: unmapped IOVA access fails closed */
143 if (physics_accel_smmu_translate(&link, 0x20000000ULL, 4096, DMA_PERM_READ, &pa) != SMMU_FAULT_TRANSLATION) return false;
144
145 /* DMA Sandbox Verification: permission violation fails closed */
146 DmaWindowDescriptor ro_win = {
147 .iova_base = 0x10050000ULL,
148 .phys_base = 0x90050000ULL,
149 .size_bytes = 0x10000ULL,
150 .permissions = DMA_PERM_READ /* Read-only */
151 };
152 if (physics_accel_grant_dma_window(&link, &cap, &ro_win, &r) != 0) return false;
153 if (physics_accel_smmu_translate(&link, 0x10050000ULL, 4096, DMA_PERM_WRITE, &pa) != SMMU_FAULT_PERMISSION) return false;
154
155 /* DMA Sandbox Verification: overlapping IOVA windows rejected */
156 DmaWindowDescriptor overlap_win = {
157 .iova_base = 0x10008000ULL, /* Overlaps win */
158 .phys_base = 0x90100000ULL,
159 .size_bytes = 0x10000ULL,
160 .permissions = DMA_PERM_READ | DMA_PERM_WRITE
161 };
162 int rc_overlap = physics_accel_grant_dma_window(&link, &cap, &overlap_win, &r);
163 if (rc_overlap == 0 || r.decision != DEC_REJECTED) return false;
164
165 return true;
166}
167
168/* ============================================================================
169 * GATE 3: PHYSICS_ACCEL_QUEUE_AUTHORITY_PASS
170 * Bounded queue authority, ring pointer governance, and doorbell mediation.
171 * ============================================================================ */
172static bool test_gate_3_queue_authority(void) {
173 PhysicsAcceleratorLink link;
174 physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
175 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE);
176
177 Smmuv3StreamConfig cfg = {
178 .stream_id = GB10_STREAM_ID,
179 .ste_index = 0,
180 .cd_table_base = 0x82000000ULL,
181 .ttbr0_base = 0x83000000ULL,
182 .mair_value = 0xFF,
183 .t0sz = 16,
184 .granule_size = 4096,
185 .stage1_enabled = true,
186 .fault_trap_enabled = true
187 };
188 physics_accel_configure_smmu(&link, &cfg);
189
190 AcceleratorCapability cap = {
191 .slot = 1,
192 .generation = 1,
193 .principal_id = 42,
194 .resource_type = RES_ACCELERATOR,
195 .allowed_ops = ACCEL_OP_ALLOC_QUEUE | ACCEL_OP_SUBMIT | ACCEL_OP_MAP_DMA,
196 .iova_bound_base = 0x10000000ULL,
197 .iova_bound_size = 0x10000000ULL,
198 .queue_id_mask = 0x1,
199 .revocation_state = 1
200 };
201
202 EffectReceipt r;
203 if (physics_accel_alloc_queue(&link, &cap, 0, &r) != 0) return false;
204 if (r.decision != DEC_ADMITTED) return false;
205 if (!link.queues[0].active) return false;
206
207 /* Map command buffer DMA window */
208 DmaWindowDescriptor cmd_win = {
209 .iova_base = 0x10000000ULL,
210 .phys_base = 0x90000000ULL,
211 .size_bytes = 0x10000ULL,
212 .permissions = DMA_PERM_READ | DMA_PERM_WRITE | DMA_PERM_COHERENT
213 };
214 if (physics_accel_grant_dma_window(&link, &cap, &cmd_win, &r) != 0) return false;
215
216 /* Submit command descriptor within granted window */
217 EffectIntent valid_intent = {
218 .version = 1,
219 .length = sizeof(EffectIntent),
220 .request_id = 501,
221 .principal_id = 42,
222 .capability_slot = 1,
223 .capability_generation = 1,
224 .resource_type = RES_ACCELERATOR,
225 .operation = ACCEL_OP_SUBMIT,
226 .target_base = 0, /* queue_id = 0 */
227 .target_size = 64,
228 .param0 = 0x10001000ULL /* IOVA of command descriptor */
229 };
230 if (physics_accel_submit_command(&link, &cap, &valid_intent, &r) != 0) return false;
231 if (r.decision != DEC_ADMITTED) return false;
232 if (link.queues[0].tail_index != 1) return false;
233
234 /* Refusal on unmapped command descriptor IOVA */
235 EffectIntent rogue_intent = valid_intent;
236 rogue_intent.request_id = 502;
237 rogue_intent.param0 = 0x40000000ULL; /* Unmapped IOVA */
238 int rc = physics_accel_submit_command(&link, &cap, &rogue_intent, &r);
239 if (rc == 0 || r.decision != DEC_REJECTED) return false;
240
241 return true;
242}
243
244/* ============================================================================
245 * GATE 4: PHYSICS_ACCEL_DEVICE_LIFECYCLE_PASS
246 * Monotonic device lifecycle progression and fault recovery.
247 * ============================================================================ */
248static bool test_gate_4_device_lifecycle(void) {
249 PhysicsAcceleratorLink link;
250 if (physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
251 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE) != 0) return false;
252 if (link.device_state != ACCEL_STATE_PROBED) return false;
253
254 Smmuv3StreamConfig cfg = {
255 .stream_id = GB10_STREAM_ID,
256 .ste_index = 0,
257 .cd_table_base = 0x82000000ULL,
258 .ttbr0_base = 0x83000000ULL,
259 .mair_value = 0xFF,
260 .t0sz = 16,
261 .granule_size = 4096,
262 .stage1_enabled = true,
263 .fault_trap_enabled = true
264 };
265 if (physics_accel_configure_smmu(&link, &cfg) != 0) return false;
266 if (link.device_state != ACCEL_STATE_CONFIGURED) return false;
267
268 AcceleratorCapability cap = {
269 .slot = 1,
270 .generation = 1,
271 .principal_id = 42,
272 .resource_type = RES_ACCELERATOR,
273 .allowed_ops = ACCEL_OP_ALLOC_QUEUE | ACCEL_OP_RESET,
274 .revocation_state = 1
275 };
276 EffectReceipt r;
277 if (physics_accel_alloc_queue(&link, &cap, 0, &r) != 0) return false;
278 if (link.device_state != ACCEL_STATE_ACTIVE) return false;
279
280 /* Simulate SMMU fault and verify containment */
281 physics_accel_handle_fault(&link, SMMU_FAULT_TRANSLATION, 0xDEADBEEFULL);
282 if (link.device_state != ACCEL_STATE_FAULTED) return false;
283 if (link.active_queues != 0) return false;
284
285 /* Execute non-disruptive reset recovery */
286 if (physics_accel_reset_device(&link, &cap, &r) != 0) return false;
287 if (r.decision != DEC_ADMITTED) return false;
288 if (link.device_state != ACCEL_STATE_CONFIGURED) return false;
289
290 return true;
291}
292
293/* ============================================================================
294 * GATE 5: PHYSICS_ACCEL_RECEIPT_CHAIN_PASS
295 * Immutable 192B receipt with rolling SHA-256 seal chain.
296 * ============================================================================ */
297static bool test_gate_5_receipt_chain(void) {
298 PhysicsAcceleratorLink link;
299 physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
300 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE);
301
302 EffectReceipt r1, r2, r3;
303 EffectIntent i1 = { .version = 1, .length = 64, .request_id = 1 };
304 EffectIntent i2 = { .version = 1, .length = 64, .request_id = 2 };
305 EffectIntent i3 = { .version = 1, .length = 64, .request_id = 3 };
306
307 physics_accel_commit_receipt(&link, &i1, DEC_ADMITTED, 0, 100, 1, &r1);
308 physics_accel_commit_receipt(&link, &i2, DEC_ADMITTED, 0, 200, 2, &r2);
309 physics_accel_commit_receipt(&link, &i3, DEC_ADMITTED, 0, 300, 3, &r3);
310
311 /* Check rolling seal chain binding */
312 if (memcmp(r2.previous_receipt_digest, r1.receipt_digest, 32) != 0) return false;
313 if (memcmp(r3.previous_receipt_digest, r2.receipt_digest, 32) != 0) return false;
314 if (memcmp(link.last_receipt_digest, r3.receipt_digest, 32) != 0) return false;
315
316 /* Check machine generation strictly monotonic */
317 if (r2.machine_generation != r1.machine_generation + 1) return false;
318 if (r3.machine_generation != r2.machine_generation + 1) return false;
319
320 return true;
321}
322
323/* ============================================================================
324 * GATE 6: PHYSICS_ACCEL_OMEGA_INGRESS_PASS
325 * Omega mediated intent ingress and capability gating.
326 * ============================================================================ */
327static bool test_gate_6_omega_ingress(void) {
328 PhysicsAcceleratorLink link;
329 physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
330 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE);
331
332 /* Revoked capability presentation must be rejected fail-closed */
333 AcceleratorCapability revoked_cap = {
334 .slot = 1,
335 .generation = 1,
336 .principal_id = 99,
337 .resource_type = RES_ACCELERATOR,
338 .allowed_ops = ACCEL_OP_MAP_DMA,
339 .revocation_state = 2 /* REVOKED */
340 };
341 DmaWindowDescriptor win = {
342 .iova_base = 0x10000000ULL,
343 .phys_base = 0x90000000ULL,
344 .size_bytes = 0x10000ULL,
345 .permissions = DMA_PERM_READ
346 };
347 EffectReceipt r;
348 int rc = physics_accel_grant_dma_window(&link, &revoked_cap, &win, &r);
349 if (rc == 0 || r.decision != DEC_REJECTED) return false;
350 if (r.rejection_reason != DEC_REJECTED_REVOKED) return false;
351
352 return true;
353}
354
355/* ============================================================================
356 * GATE 7: PHYSICS_ACCEL_HARDWARE_BOUNDARY_PASS
357 * Truthful observation of DGX Spark hardware topology (BDF, vendor/device ID,
358 * SMMUv3 platform device, IOMMU group, Stream ID provenance, BAR0 aperture,
359 * explicit subsystem ownership recording, and 0 guessed MMIO writes).
360 * ============================================================================ */
361static bool test_gate_7_hardware_boundary(void) {
362 Smmuv3NativeProbe probe;
363 int rc = physics_accel_native_verify_hardware_boundary(&probe);
364 if (rc != 0) {
365 printf(" [FAIL] Hardware boundary verification failed (rc=%d)\n", rc);
366 return false;
367 }
368
369 /* Verify ownership boundary table is recorded */
370 size_t boundary_count = 0;
371 const HardwareOwnershipBoundary *boundaries = physics_accel_get_hardware_ownership_boundaries(&boundary_count);
372 if (!boundaries || boundary_count < 6) {
373 printf(" [FAIL] Incomplete hardware ownership boundary recording\n");
374 return false;
375 }
376
377 printf(" [Boundary] PCI BDF: %s\n", probe.pci_bdf);
378 printf(" [Boundary] Device: %s (0x%04x:0x%04x)\n", probe.device_name, probe.vendor_id, probe.device_id);
379 printf(" [Boundary] IOMMU Group: %u\n", probe.iommu_group);
380 printf(" [Boundary] SMMUv3 Base: %s @ 0x%08llx\n", probe.smmu_name, (unsigned long long)probe.smmu_base);
381 printf(" [Boundary] Stream ID: 0x%04x (256 dec, ACPI IORT Node 29)\n", probe.stream_id);
382 printf(" [Boundary] BAR0 Aperture: 0x%08llx - 0x%08llx (%llu MiB)\n",
383 (unsigned long long)probe.bar0_base,
384 (unsigned long long)(probe.bar0_base + probe.bar0_size - 1),
385 (unsigned long long)probe.bar0_size / (1024 * 1024));
386 printf(" [Boundary] Subsystems: %zu ownership boundaries documented\n", boundary_count);
387 printf(" [Boundary] Sovereign Rule: 0 guessed MMIO writes performed\n");
388
389 return true;
390}
391
392/* ============================================================================
393 * GATE 8: PHYSICS_ACCEL_ZERO_RUNTIME_DEP_PASS
394 * Strictly scans sovereign substrate files for forbidden runtime dependencies,
395 * CUDA APIs, LLVM JIT, Python headers, or GCC inline assembly.
396 * ============================================================================ */
397static bool line_has_word(const char *line, const char *word) {
398 const char *p = line;
399 size_t wlen = strlen(word);
400 while ((p = strstr(p, word)) != NULL) {
401 bool left_ok = (p == line) || (!((p[-1] >= 'a' && p[-1] <= 'z') ||
402 (p[-1] >= 'A' && p[-1] <= 'Z') ||
403 (p[-1] >= '0' && p[-1] <= '9') ||
404 p[-1] == '_'));
405 const char *after = p + wlen;
406 bool right_ok = (*after == '\0') || (!((*after >= 'a' && *after <= 'z') ||
407 (*after >= 'A' && *after <= 'Z') ||
408 (*after >= '0' && *after <= '9') ||
409 *after == '_'));
410 if (left_ok && right_ok) return true;
411 p += wlen;
412 }
413 return false;
414}
415
416static bool test_gate_8_zero_runtime_dep(void) {
417 const char *canonical_files[] = {
418 "m15/physics_accel.c",
419 "m15/physics_accel.h",
420 "m15/physics_accel_native.c",
421 "m15/physics_accel_native.h",
422 "sha256_clean.c"
423 };
424 const char *forbidden[] = {
425 "__asm__",
426 "asm(",
427 "Python.h",
428 "system(",
429 "popen(",
430 "libcuda",
431 "cudaMalloc",
432 "cudaMemcpy",
433 "cudaLaunch",
434 "cuMemAlloc",
435 "cuLaunch",
436 "LLVM",
437 "nvcc",
438 "PTX"
439 };
440
441 for (size_t i = 0; i < sizeof(canonical_files) / sizeof(canonical_files[0]); i++) {
442 const char *p = canonical_files[i];
443 FILE *f = fopen(p, "r");
444 char alt_path[256];
445 if (!f) {
446 snprintf(alt_path, sizeof(alt_path), "../%s", canonical_files[i]);
447 f = fopen(alt_path, "r");
448 if (!f) {
449 printf(" [FAIL] Could not open canonical file: %s\n", p);
450 return false;
451 }
452 p = alt_path;
453 }
454
455 char line[1024];
456 uint32_t line_num = 0;
457 while (fgets(line, sizeof(line), f)) {
458 line_num++;
459 char *trim = line;
460 while (*trim == ' ' || *trim == '\t') trim++;
461 if (trim[0] == '/' && (trim[1] == '*' || trim[1] == '/')) continue;
462
463 for (size_t k = 0; k < sizeof(forbidden) / sizeof(forbidden[0]); k++) {
464 if (line_has_word(line, forbidden[k])) {
465 printf(" [FAIL] Forbidden token '%s' in %s:%u\n", forbidden[k], p, line_num);
466 fclose(f);
467 return false;
468 }
469 }
470 }
471 fclose(f);
472 }
473
474 printf(" [Toolchain] Host qualification compiler: GCC (temporary non-lineage scaffold)\n");
475 printf(" [Toolchain] Canonical accelerator runtime dependencies: 0 CUDA, 0 LLVM, 0 Python, 0 inline asm\n");
476 return true;
477}
478
479/* ============================================================================
480 * GATE 9: PHYSICS_ACCEL_PROVENANCE_PASS
481 * Verifies capability provenance, monotonic attenuation, and slot checking.
482 * ============================================================================ */
483static bool test_gate_9_provenance(void) {
484 PhysicsAcceleratorLink link;
485 physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
486 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE);
487
488 AcceleratorCapability base_cap = {
489 .slot = 1,
490 .generation = 1,
491 .principal_id = 42,
492 .resource_type = RES_ACCELERATOR,
493 .allowed_ops = ACCEL_OP_MAP_DMA | ACCEL_OP_UNMAP_DMA,
494 .iova_bound_base = 0x10000000ULL,
495 .iova_bound_size = 0x10000000ULL,
496 .queue_id_mask = 0x1,
497 .revocation_state = 1
498 };
499
500 /* Attenuation check: requesting unpermitted operation fails closed */
501 int val = physics_accel_validate_capability(&link, &base_cap, ACCEL_OP_RESET, 0, 0);
502 if (val != DEC_REJECTED_OPERATION) return false;
503
504 /* Resource type check: wrong resource type fails closed */
505 AcceleratorCapability wrong_res_cap = base_cap;
506 wrong_res_cap.resource_type = 0x9999;
507 val = physics_accel_validate_capability(&link, &wrong_res_cap, ACCEL_OP_MAP_DMA, 0, 0);
508 if (val != DEC_REJECTED_RESOURCE) return false;
509
510 /* Out of bounds IOVA request fails closed */
511 val = physics_accel_validate_capability(&link, &base_cap, ACCEL_OP_MAP_DMA,
512 0x05000000ULL, 0x1000ULL);
513 if (val != DEC_REJECTED_BOUNDS) return false;
514
515 return true;
516}
517
518/* ============================================================================
519 * GATE 10: PHYSICS_ACCEL_RECEIPT_PASS
520 * Verifies formal 192-byte EffectReceipt committing observed hardware boundary.
521 * ============================================================================ */
522static bool test_gate_10_receipt(void) {
523 PhysicsAcceleratorLink link;
524 physics_accel_init(&link, DGX_SPARK_DRAM_BASE, DGX_SPARK_DRAM_SIZE,
525 PHYSICS_KERNEL_MEM_BASE, PHYSICS_KERNEL_MEM_SIZE);
526
527 Smmuv3NativeProbe probe;
528 if (physics_accel_native_probe(&probe) != 0) return false;
529
530 EffectReceipt receipt;
531 int rc = physics_accel_native_commit_boundary_receipt(&link, &probe, &receipt);
532 if (rc != 0) return false;
533
534 if (receipt.version != 1 || receipt.length != 192) return false;
535 if (receipt.decision != DEC_ADMITTED) return false;
536 if (receipt.actual_effect != probe.bar0_base) return false;
537 if (receipt.output != probe.stream_id) return false;
538 if (receipt.measurement != probe.smmu_base) return false;
539 if (receipt.machine_generation != 2) return false;
540
541 /* Verify seal matches rolling chain */
542 if (memcmp(link.last_receipt_digest, receipt.receipt_digest, 32) != 0) return false;
543
544 return true;
545}
546
547/* ============================================================================
548 * DEMONSTRATION & ARTIFACT EXPORT
549 * ============================================================================ */
550
551static void run_demonstration(void) {
552 printf("================================================================================\n");
553 printf(" AIEN PHYSICS SUBSTRATE — MILESTONE 15: HARDWARE BOUNDARY DEMONSTRATION\n");
554 printf("================================================================================\n");
555
556 Smmuv3NativeProbe probe;
557 if (physics_accel_native_probe(&probe) != 0) {
558 printf(" [ERROR] Hardware probe failed!\n");
559 return;
560 }
561
562 printf(" OBSERVED HARDWARE TOPOLOGY:\n");
563 printf(" PCI BDF: %s\n", probe.pci_bdf);
564 printf(" Device: %s (0x%04x:0x%04x)\n", probe.device_name, probe.vendor_id, probe.device_id);
565 printf(" IOMMU Group: %u\n", probe.iommu_group);
566 printf(" SMMUv3 Device: %s @ 0x%08llx\n", probe.smmu_name, (unsigned long long)probe.smmu_base);
567 printf(" Stream ID: 0x%04x (256 decimal, ACPI IORT Node 29)\n", probe.stream_id);
568 printf(" Coherent DRAM: [0x80000000, 0x2080000000) (128 GiB unified LPDDR5x)\n");
569 printf(" BAR0 Aperture: 0x%08llx - 0x%08llx (%llu MiB)\n",
570 (unsigned long long)probe.bar0_base,
571 (unsigned long long)(probe.bar0_base + probe.bar0_size - 1),
572 (unsigned long long)probe.bar0_size / (1024 * 1024));
573 printf("\n");
574
575 printf(" SUBSYSTEM OWNERSHIP BOUNDARIES:\n");
576 size_t count = 0;
577 const HardwareOwnershipBoundary *b = physics_accel_get_hardware_ownership_boundaries(&count);
578 for (size_t i = 0; i < count; i++) {
579 printf(" [%zu] %-28s : %s\n", i + 1, b[i].subsystem, b[i].current_owner);
580 printf(" Physics Status : %s\n", b[i].physics_status);
581 printf(" Transfer Plan : %s\n", b[i].transfer_plan);
582 }
583 printf("\n");
584
585 printf(" CANONICAL BOUNDARY PRINCIPLE:\n");
586 printf(" M15 ESTABLISHES WHO MAY TOUCH THE ACCELERATOR (Authority & Topology Grounding)\n");
587 printf(" M16 DISCOVERS HOW THE ACCELERATOR IS ACTUALLY COMMANDED (Empirical Path Discovery)\n");
588 printf("================================================================================\n");
589}
590
591static void dump_evidence(void) {
592 const char *dir = "evidence/m15-boundary";
593 mkdir("evidence", 0755);
594 mkdir(dir, 0755);
595
596 Smmuv3NativeProbe probe;
597 physics_accel_native_probe(&probe);
598
599 char path[256];
600 snprintf(path, sizeof(path), "%s/hardware-boundary.txt", dir);
601 FILE *f = fopen(path, "w");
602 if (f) {
603 fprintf(f, "Machine: NVIDIA DGX Spark\n");
604 fprintf(f, "PCI BDF: %s\n", probe.pci_bdf);
605 fprintf(f, "Vendor ID: 0x%04x\n", probe.vendor_id);
606 fprintf(f, "Device ID: 0x%04x\n", probe.device_id);
607 fprintf(f, "IOMMU Group: %u\n", probe.iommu_group);
608 fprintf(f, "SMMUv3 Base: 0x%08llx\n", (unsigned long long)probe.smmu_base);
609 fprintf(f, "Stream ID: 0x%04x\n", probe.stream_id);
610 fprintf(f, "BAR0 Base: 0x%08llx\n", (unsigned long long)probe.bar0_base);
611 fprintf(f, "BAR0 Size: %llu\n", (unsigned long long)probe.bar0_size);
612 fprintf(f, "Coherent DRAM: [0x80000000, 0x2080000000) 128 GiB\n");
613 fclose(f);
614 }
615
616 snprintf(path, sizeof(path), "%s/ownership-boundaries.txt", dir);
617 f = fopen(path, "w");
618 if (f) {
619 size_t count = 0;
620 const HardwareOwnershipBoundary *b = physics_accel_get_hardware_ownership_boundaries(&count);
621 for (size_t i = 0; i < count; i++) {
622 fprintf(f, "Subsystem: %s\n", b[i].subsystem);
623 fprintf(f, "Current Owner: %s\n", b[i].current_owner);
624 fprintf(f, "Physics Status: %s\n", b[i].physics_status);
625 fprintf(f, "Transfer Plan: %s\n\n", b[i].transfer_plan);
626 }
627 fclose(f);
628 }
629
630 printf(" [Evidence] Boundary evidence artifacts dumped to %s/\n", dir);
631}
632
633/* ============================================================================
634 * MAIN RUNNER
635 * ============================================================================ */
636
637int main(int argc, char **argv) {
638 if (argc >= 2 && strcmp(argv[1], "--demonstrate-accelerator") == 0) {
639 run_demonstration();
640 return 0;
641 }
642 if (argc >= 2 && strcmp(argv[1], "--dump-evidence-artifacts") == 0) {
643 dump_evidence();
644 return 0;
645 }
646
647 bool run_all = (argc >= 2 && strcmp(argv[1], "--run-m15-gates") == 0);
648
649 if (!run_all) {
650 printf("m15tool -- AIEN Physics Milestone 15 Qualification Tool\n");
651 printf("Usage: %s [--run-m15-gates | --demonstrate-accelerator | --dump-evidence-artifacts]\n", argv[0]);
652 return 0;
653 }
654
655 printf("================================================================================\n");
656 printf(" AIEN PHYSICS SUBSTRATE — MILESTONE 15: QUALIFICATION RUNNER\n");
657 printf("================================================================================\n");
658 printf("Timestamp: %lu\n", (unsigned long)time(NULL));
659 printf("Host: NVIDIA DGX Spark (Grace Neoverse V2 + Blackwell GB10)\n");
660 printf("Boundary: Authority Model & Empirically Grounded Hardware Topology\n\n");
661
662 bool g1 = test_gate_1_mem_bounds();
663 print_gate("PHYSICS_ACCEL_MEM_BOUNDS_PASS", g1, "Coherent DRAM boundaries and kernel memory isolation");
664
665 bool g2 = test_gate_2_dma_policy();
666 print_gate("PHYSICS_ACCEL_DMA_POLICY_PASS", g2, "SMMUv3 Stage 1 IOVA-to-PA translation policy and DMA sandboxing");
667
668 bool g3 = test_gate_3_queue_authority();
669 print_gate("PHYSICS_ACCEL_QUEUE_AUTHORITY_PASS", g3, "Bounded queue authority and doorbell mediation policy");
670
671 bool g4 = test_gate_4_device_lifecycle();
672 print_gate("PHYSICS_ACCEL_DEVICE_LIFECYCLE_PASS", g4, "Deterministic monotonic device lifecycle transitions and fault isolation");
673
674 bool g5 = test_gate_5_receipt_chain();
675 print_gate("PHYSICS_ACCEL_RECEIPT_CHAIN_PASS", g5, "Immutable 192B receipt with rolling SHA-256 seal chain");
676
677 bool g6 = test_gate_6_omega_ingress();
678 print_gate("PHYSICS_ACCEL_OMEGA_INGRESS_PASS", g6, "Omega mediated intent ingress and capability gating");
679
680 bool g7 = test_gate_7_hardware_boundary();
681 print_gate("PHYSICS_ACCEL_HARDWARE_BOUNDARY_PASS", g7, "Truthful DGX Spark hardware topology observation & ownership recording");
682
683 bool g8 = test_gate_8_zero_runtime_dep();
684 print_gate("PHYSICS_ACCEL_ZERO_RUNTIME_DEP_PASS", g8, "Zero foreign runtime dependencies (0 CUDA, 0 LLVM, 0 Python, 0 inline asm)");
685
686 bool g9 = test_gate_9_provenance();
687 print_gate("PHYSICS_ACCEL_PROVENANCE_PASS", g9, "Capability provenance verification and monotonic attenuation");
688
689 bool g10 = test_gate_10_receipt();
690 print_gate("PHYSICS_ACCEL_RECEIPT_PASS", g10, "192B EffectReceipt certifying observed hardware boundary parameters");
691
692 int total_gates = 10;
693 int passed = (g1?1:0) + (g2?1:0) + (g3?1:0) + (g4?1:0) + (g5?1:0) +
694 (g6?1:0) + (g7?1:0) + (g8?1:0) + (g9?1:0) + (g10?1:0);
695
696 printf("================================================================================\n");
697 printf(" QUALIFICATION GATES: %d | PASSED: %d | FAILED: %d\n", total_gates, passed, total_gates - passed);
698 printf("================================================================================\n");
699
700 return (passed == total_gates) ? 0 : 1;
701}