Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-gpu-driver/blob/main/tests/complete_ref.c # omega-gpu-driver aien-dev/omega-gpu-driver Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-gpu-driver / tests / complete_ref.c` 182 lines ยท 5283 bytes Raw Blame History 1 /* tests/complete_ref.c: TEST-ONLY C referee for chan/complete.om. Never linked into driver. 2 * Builds against NVIDIA open-gpu-kernel-modules 580.173.02 headers (MIT). 3 * Compares exact command encodings, wrap-safe progress math, capability refusals, 4 * and timeout quarantine latch with tests/complete_trace.om. */ 5 #include 6 #include 7 #include 8 #include 9 #include 10 11 #include "nvtypes.h" 12 #include "nvmisc.h" 13 #include "class/clc96f.h" 14 15 #define CMOK 0 16 #define CMEINVAL (-1) 17 #define CMEALIGN (-2) 18 #define CMERANGE (-3) 19 #define CMESTATE (-4) 20 #define CMESTALE (-5) 21 #define CMEFULL (-6) 22 #define CMEGEN (-10) 23 #define CMETIME (-11) 24 #define CMEQUAR (-12) 25 26 #define CHNINC 0x20000000u 27 #define CMSEMM (NVC96F_SEM_ADDR_LO >> 2) /* 23 */ 28 #define MMVALIM (1ULL << 57) 29 30 static uint32_t cmhdr(uint32_t subc, uint32_t count) 31 { 32 return CHNINC | ((count & 0x3ff) << 16) | ((subc & 7) << 13) | CMSEMM; 33 } 34 35 static int cmrel(uint32_t subc, uint64_t va, uint32_t seq, uint32_t *wds) 36 { 37 if (subc > 7) return CMEINVAL; 38 if ((va & 3) != 0) return CMEALIGN; 39 if (va == 0 || va >= MMVALIM) return CMERANGE; 40 wds[0] = cmhdr(subc, 5); 41 wds[1] = (uint32_t)(va & 0xFFFFFFFCULL); 42 wds[2] = (uint32_t)((va >> 32) & 0x1FFFFFFULL); 43 wds[3] = seq; 44 wds[4] = 0; 45 wds[5] = DRF_DEF(C96F, _SEM_EXECUTE, _OPERATION, _RELEASE) | 46 DRF_DEF(C96F, _SEM_EXECUTE, _PAYLOAD_SIZE, _32BIT) | 47 DRF_DEF(C96F, _SEM_EXECUTE, _RELEASE_WFI, _DIS); 48 return 6; 49 } 50 51 static int cmacq(uint32_t subc, uint64_t va, uint32_t seq, uint32_t *wds) 52 { 53 if (subc > 7) return CMEINVAL; 54 if ((va & 3) != 0) return CMEALIGN; 55 if (va == 0 || va >= MMVALIM) return CMERANGE; 56 wds[0] = cmhdr(subc, 5); 57 wds[1] = (uint32_t)(va & 0xFFFFFFFCULL); 58 wds[2] = (uint32_t)((va >> 32) & 0x1FFFFFFULL); 59 wds[3] = seq; 60 wds[4] = 0; 61 wds[5] = DRF_DEF(C96F, _SEM_EXECUTE, _OPERATION, _ACQUIRE); 62 return 6; 63 } 64 65 static long cmprog(uint32_t ret, uint32_t put, uint32_t obs) 66 { 67 uint32_t inflight = put - ret; 68 if (inflight == 0) { 69 if (obs == ret) return 0; 70 return CMESTALE; 71 } 72 uint32_t prog = obs - ret; 73 if (prog == 0) return 0; 74 if (prog > inflight) return CMESTALE; 75 return (long)prog; 76 } 77 78 static void show_cmd(int id, int rc, const uint32_t *wds) 79 { 80 if (rc > 0) { 81 printf("cmd %d rc=%d %08x %08x %08x %08x %08x %08x\n", 82 id, rc, wds[0], wds[1], wds[2], wds[3], wds[4], wds[5]); 83 } else { 84 printf("cmd %d rc=%d\n", id, rc); 85 } 86 } 87 88 static void show_prog(int id, long rc) 89 { 90 printf("prog %d rc=%ld\n", id, rc); 91 } 92 93 static void show_cap(int id, int rc) 94 { 95 printf("cap %d rc=%d\n", id, rc); 96 } 97 98 static void show_drain(int id, int rc, int st, int bst, int wst) 99 { 100 printf("drain %d rc=%d st=%d bst=%d wst=%d\n", id, rc, st, bst, wst); 101 } 102 103 int main(void) 104 { 105 uint32_t wds[6]; 106 int rc; 107 108 /* 1. Command encoding */ 109 memset(wds, 0, sizeof wds); 110 rc = cmrel(0, 0x20000000ULL, 1, wds); 111 show_cmd(1, rc, wds); 112 113 memset(wds, 0, sizeof wds); 114 rc = cmrel(3, 0x100000004ULL, 42, wds); 115 show_cmd(2, rc, wds); 116 117 memset(wds, 0, sizeof wds); 118 rc = cmrel(7, 0x800000000ULL, 0xFFFFFFFFU, wds); 119 show_cmd(3, rc, wds); 120 121 rc = cmrel(8, 0x20000000ULL, 1, wds); 122 show_cmd(4, rc, wds); 123 124 rc = cmrel(0, 0x1001ULL, 1, wds); 125 show_cmd(5, rc, wds); 126 127 rc = cmrel(0, 0ULL, 1, wds); 128 show_cmd(6, rc, wds); 129 130 rc = cmrel(0, MMVALIM + 4, 1, wds); 131 show_cmd(7, rc, wds); 132 133 memset(wds, 0, sizeof wds); 134 rc = cmacq(1, 0x40000000ULL, 10, wds); 135 show_cmd(8, rc, wds); 136 137 /* 2. Sequence progress (wrap-safe) */ 138 show_prog(10, cmprog(0, 10, 0)); 139 show_prog(11, cmprog(0, 10, 5)); 140 show_prog(12, cmprog(0, 10, 10)); 141 show_prog(13, cmprog(0, 10, 11)); 142 show_prog(14, cmprog(5, 10, 4)); 143 show_prog(15, cmprog(0xFFFFFFFEU, 3, 1)); 144 show_prog(16, cmprog(0xFFFFFFFEU, 3, 0xFFFFFFFEU)); 145 show_prog(17, cmprog(0xFFFFFFFEU, 3, 4)); 146 show_prog(18, cmprog(0xFFFFFFFEU, 3, 0xFFFFFFFDU)); 147 show_prog(19, cmprog(100, 100, 100)); 148 show_prog(20, cmprog(100, 100, 101)); 149 150 /* 3. Capability refusals */ 151 /* id 30: simulator window mmwkind=0 */ 152 show_cap(30, CMESTATE); 153 /* id 31: unmapped window mmwst=MMWOWN */ 154 show_cap(31, CMESTATE); 155 /* id 32: epoch mismatch */ 156 show_cap(32, CMEGEN); 157 /* id 33: cached buffer */ 158 show_cap(33, CMESTATE); 159 /* id 34: non-polled buffer */ 160 show_cap(34, CMESTATE); 161 /* id 35: misaligned offset */ 162 show_cap(35, CMEALIGN); 163 /* id 36: valid bind */ 164 show_cap(36, CMOK); 165 /* id 38: unbound slot rejects cmdrain */ 166 show_cap(38, CMESTATE); 167 /* id 42: cmsub over ring capacity rejects */ 168 show_cap(42, CMEFULL); 169 /* id 43: cmsub exceeding channel submitted entries rejects */ 170 show_cap(43, CMERANGE); 171 172 /* 4. Drain & timeout quarantine */ 173 /* id 40: successful drain: rc=CMOK st=CMSIDLE(4) bst=GMLIVE(1) wst=MMWPUB(3) */ 174 show_drain(40, CMOK, 4, 1, 3); 175 /* id 41: timeout drain: rc=CMETIME st=CMSQST(6) bst=GMQUAR(2) wst=MMWQUAR(4) */ 176 show_drain(41, CMETIME, 6, 2, 4); 177 /* Terminal quarantines are never resurrected by the fixture. */ 178 show_cap(37, CMESTATE); 179 show_cap(39, CMESTATE); 180 181 return 0; 182 }