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/gsp/irqvfio.om # 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 / gsp / irqvfio.om` 269 lines ยท 4940 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Program-mode Linux VFIO effects, requires irq-omc.pin (omega-mv78122a72, draft1045). 3 note Never opens a path, binds a driver, resets a device or closes the caller-owned device fd. 4 note Caller must have acquired devicefd with vfioctl15210 IN THIS PROGRAM; vfioirq enforces provenance. 5 note This is not authorization to use a physical device. ogd admits only host model/memfd fixtures. 6 note Linux UAPI records: GET_IRQ_INFO16; SET_IRQS20+4count; count<=64. 7 note WolframLanguageEvaluator:{20+4*64,BitOr[4,32],BitOr[1,32],BitOr[1,8],BitOr[1,16]}->{276,36,33,9,17}. 8 global vigen ulong 1 9 global vifd int 1 10 global viefd int 1 11 global viidx ulong 1 12 global vistart ulong 1 13 global vincount ulong 1 14 global vicount ulong 1 15 global viflags ulong 1 16 global vistate ulong 1 17 global vialloc ulong 1 18 global vireg ulong 1 19 global viclose ulong 1 20 global viwakes ulong 1 21 global vibytes ulong 1 22 global vibuf uchar 276 23 global viinfo uchar 16 24 global vibar uchar 32 25 global viwake uchar 8 26 fn viput which ulong off ulong value ulong to void 27 for i ulong 4 28 b = uchar and shr value mul i 8 255 29 if eq which 0 30 put vibuf add off i b 31 end 32 if eq which 1 33 put viinfo add off i b 34 end 35 if eq which 2 36 put vibar add off i b 37 end 38 end 39 end 40 fn viget which ulong off ulong to ulong 41 v = ulong 0 42 for i ulong 4 43 b = uchar 0 44 if eq which 0 45 b = get vibuf add off i 46 end 47 if eq which 1 48 b = get viinfo add off i 49 end 50 if eq which 2 51 b = get vibar add off i 52 end 53 v = or v shl ulong b mul i 8 54 end 55 ret v 56 end 57 fn viwide off ulong to ulong 58 v = ulong 0 59 for i ulong 8 60 v = or v shl ulong get vibar add off i mul i 8 61 end 62 ret v 63 end 64 fn viadopt fd int gen ulong to long 65 if or lt fd 0 or eq gen 0 ne get vistate 0 0 66 ret -4 67 end 68 put vifd 0 fd 69 put vigen 0 gen 70 put vistate 0 1 71 ret 0 72 end 73 fn vimmio region uint to long 74 if ne get vistate 0 1 75 ret -4 76 end 77 for i ulong 32 78 put vibar i 0 79 end 80 viput 2 0 32 81 viput 2 8 ulong region 82 r = vfioctl get vifd 0 uint 15212 vibar 0 32 83 if ne r 0 84 ret r 85 end 86 if or ne viget 2 0 32 ne and viget 2 4 7 7 87 ret -95 88 end 89 if ne viget 2 8 ulong region 90 ret -95 91 end 92 size = viwide 16 93 if lt size 4096 94 ret -1 95 end 96 h = vfiomapw get vifd 0 vibar 0 32 97 if gt h 0 98 put vibytes 0 size 99 end 100 ret h 101 end 102 fn viquery idx ulong start ulong count ulong to long 103 if ne get vistate 0 1 104 ret -4 105 end 106 if or gt idx `4294967295` or eq count 0 gt count 64 107 ret -1 108 end 109 for i ulong 16 110 put viinfo i 0 111 end 112 viput 1 0 16 113 viput 1 8 idx 114 r = vfioirq get vifd 0 uint 15213 viinfo 0 16 115 if ne r 0 116 ret r 117 end 118 if or ne viget 1 0 16 ne viget 1 8 idx 119 ret -95 120 end 121 note No synthetic masking: both EVENTFD and MASKABLE capabilities must actually be reported. 122 flags = viget 1 4 123 if ne and flags 3 3 124 ret -95 125 end 126 n = viget 1 12 127 if gt start n 128 ret -1 129 end 130 if gt count sub n start 131 ret -1 132 end 133 put viidx 0 idx 134 put viflags 0 flags 135 put vicount 0 n 136 put vistart 0 start 137 put vincount 0 count 138 ret 0 139 end 140 fn viset flags ulong count ulong start ulong to long 141 n = ulong 20 142 if eq flags 36 143 n = add 20 mul count 4 144 end 145 viput 0 0 n 146 viput 0 4 flags 147 viput 0 8 get viidx 0 148 viput 0 12 start 149 viput 0 16 count 150 ret vfioirq get vifd 0 uint 15214 vibuf 0 n 151 end 152 fn vidisable to long 153 r = viset 33 0 0 154 if ne r 0 155 put vistate 0 7 156 ret r 157 end 158 put vireg 0 0 159 put vistate 0 6 160 ret 0 161 end 162 fn virelease to long 163 if or ne get vireg 0 0 or ne get vialloc 0 1 ne get viclose 0 0 164 ret -4 165 end 166 note close errors are ambiguous; never retry this numeric descriptor after the first close attempt. 167 put viclose 0 1 168 r = fclose get viefd 0 169 if ne r 0 170 put vistate 0 7 171 ret r 172 end 173 put vialloc 0 0 174 put vistate 0 8 175 ret 0 176 end 177 fn virollback error long to long 178 r = vidisable 179 if ne r 0 180 ret error 181 end 182 r = virelease 183 ret error 184 end 185 fn viregister to long 186 if or ne get vistate 0 1 eq get vincount 0 0 187 ret -4 188 end 189 e = eventfd uint 0 190 if lt e 0 191 ret e 192 end 193 put viefd 0 int e 194 put vialloc 0 1 195 put vistate 0 2 196 for i ulong get vincount 0 197 viput 0 add 20 mul i 4 ulong e 198 end 199 note Once attempted, bind ownership is uncertain until disable is acknowledged, even on ioctl error. 200 put vireg 0 1 201 r = viset 36 get vincount 0 get vistart 0 202 if ne r 0 203 ret virollback r 204 end 205 r = viset 9 get vincount 0 get vistart 0 206 if ne r 0 207 ret virollback r 208 end 209 put vistate 0 3 210 ret 0 211 end 212 fn viunmask to long 213 if ne get vistate 0 3 214 ret -4 215 end 216 r = viset 17 get vincount 0 get vistart 0 217 if eq r 0 218 put vistate 0 4 219 end 220 ret r 221 end 222 fn vican to long 223 if ne get vialloc 0 1 224 ret -4 225 end 226 for i ulong 8 227 put viwake i 0 228 end 229 put viwake 0 1 230 r = write get viefd 0 viwake 0 8 231 if eq r 8 232 ret 0 233 end 234 if eq r -11 235 if eq waitio get viefd 0 1 0 1 236 ret 0 237 end 238 end 239 if lt r 0 240 ret r 241 end 242 ret -5 243 end 244 note WolframLanguageEvaluator:UnitConvert[Quantity[1,\"Seconds\"],\"Nanoseconds\"]->`1000000000` nanoseconds. 245 fn viwait timeout long to long 246 if or ne get vialloc 0 1 or lt timeout 0 gt timeout `1000000000` 247 ret -4 248 end 249 r = waitio get viefd 0 1 timeout 250 if ne r 1 251 ret r 252 end 253 r = read get viefd 0 viwake 0 8 254 if eq r -11 255 ret 0 256 end 257 if ne r 8 258 if lt r 0 259 ret r 260 end 261 ret -5 262 end 263 v = ulong 0 264 for i ulong 8 265 v = or v shl ulong get viwake i mul i 8 266 end 267 put viwakes 0 v 268 ret 1 269 end