interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / tests / irq_ref.c

91 lines · 2863 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* Test-only state-transition oracle. Never linked into the Omega driver.
3 * Vendor contract: SWGEN0 (bit 6) is cleared before event handling, not after;
4 * lockdown ends register access. All other sources remain unsupported here.
5 * Queue arrivals/failures are explicit model inputs, not hardware observations.
6 */
7#include <stdint.h>
8#include <stdio.h>
9
10struct peer {
11 unsigned raw, mask, dest, queued, done, edge, fail, lock, tail, inactive;
12 unsigned mode, state, acks, reads, masks, progress, pending;
13};
14
15static unsigned pending(struct peer *p)
16{
17 ++p->reads;
18 if (p->tail && p->reads == 2) {
19 p->tail = 0;
20 p->raw |= 64;
21 ++p->queued;
22 }
23 return p->raw & p->mask & p->dest;
24}
25
26static int stop(struct peer *p, int code)
27{
28 p->mask = 0;
29 ++p->masks;
30 p->state = 2;
31 return code;
32}
33
34static int service(struct peer *p, unsigned generation, unsigned budget)
35{
36 if (!budget || budget > 64) return -1;
37 if (generation != 7) return -10;
38 if (p->state == 2) return -12;
39 if (p->state == 3) return -14;
40 if (p->mode || p->inactive) return -9;
41 p->progress = 0;
42 p->pending = pending(p);
43 if (!p->pending) return 0;
44 if (p->pending & ~64U) return stop(p, -13);
45 p->raw &= ~64U;
46 ++p->acks;
47 while (p->done != p->queued) {
48 if (p->progress == budget) return stop(p, -11);
49 if (p->done + 1 == p->fail) return stop(p, -15);
50 ++p->done;
51 ++p->progress;
52 if (p->edge && p->done == p->edge) {
53 p->edge = 0;
54 p->raw |= 64;
55 ++p->queued;
56 }
57 if (p->done == p->lock) {
58 p->state = 3;
59 return (int)p->progress;
60 }
61 }
62 p->pending = pending(p);
63 return (int)p->progress;
64}
65
66static void put(unsigned char *out, unsigned at, uint64_t v)
67{
68 for (unsigned i = 0; i < 8; ++i) out[at + i] = (unsigned char)(v >> (8*i));
69}
70
71int main(void)
72{
73 unsigned char in[16], out[128] = {0};
74 if (fread(in, 1, sizeof in, stdin) != sizeof in) return 2;
75 struct peer p = {
76 .raw=in[0], .mask=in[1], .dest=in[2], .queued=in[3],
77 .edge=in[5], .fail=in[6], .lock=in[7], .tail=in[8],
78 .inactive=in[9], .mode=in[10], .state=1,
79 };
80 int r = service(&p, in[11] ? 8 : 7, in[4]);
81 put(out, 0, (uint64_t)(r+32));
82 put(out, 8, p.state); put(out, 16, p.pending); put(out, 24, p.progress);
83 put(out, 32, p.done); put(out, 40, p.raw); put(out, 48, p.acks);
84 put(out, 56, p.reads); put(out, 64, p.masks);
85 r = in[12] ? service(&p, 7, in[4]) : -4;
86 put(out, 72, (uint64_t)(r+32));
87 put(out, 80, p.pending); put(out, 88, p.done); put(out, 96, p.acks);
88 put(out, 104, p.reads); put(out, 112, p.masks);
89 if (fwrite(out, 1, sizeof out, stdout) != sizeof out) return 4;
90 return 0;
91}