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/uvm/pt.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 / uvm / pt.om` 483 lines ยท 7356 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note uvm/pt.om: page-table walk, map/unmap, and the 32-slot VA allocator. 3 note Walk codes UVCONT UVFREE UVMAPPED UVCONF UVMISS stay inside this unit. 4 note The public returns are UVOK through UVFATAL. 5 fn uvwklv va ulong to ulong 6 tbl = ulong 0 7 for lv ulong 4 8 idx = uvlvidx lv va 9 ent = add tbl mul idx 8 10 v = uvld64 ent 11 if ne and v 1 0 12 ret UVCONF 13 end 14 if eq and shr v 1 3 0 15 put uvmiss 0 add lv 1 16 ret UVMISS 17 end 18 pa = and v UVPDMSK 19 if uvbadpa pa 20 ret UVCONF 21 end 22 tbl = sub pa UVPOOL 23 end 24 put uvtbl 0 tbl 25 ret UVCONT 26 end 27 fn uvslot va ulong lv ulong to ulong 28 tbl = ulong 0 29 for j ulong lv 30 v = uvld64 add tbl mul uvlvidx j va 8 31 tbl = sub and v UVPDMSK UVPOOL 32 end 33 ret add tbl mul uvlvidx lv va 8 34 end 35 fn uvfill va ulong to ulong 36 for n ulong 5 37 r = uvwklv va 38 if eq r UVCONT 39 ret UVOK 40 end 41 if ne r UVMISS 42 ret r 43 end 44 lv = sub get uvmiss 0 1 45 r2 = uvptnew 46 if ne r2 UVOK 47 ret r2 48 end 49 uvst64 uvslot va lv uvpde add UVPOOL get uvout 0 UVAPSYS 50 end 51 ret UVENOM 52 end 53 fn uvpdent va ulong to ulong 54 idx = uvlvidx 4 va 55 ent = add get uvtbl 0 mul idx 16 56 put uvw0 0 uvld64 ent 57 put uvw1 0 uvld64 add ent 8 58 ret ent 59 end 60 fn uvwk2m va ulong to ulong 61 ent = uvpdent va 62 w0 = get uvw0 0 63 if ne and w0 1 0 64 put uvleaf 0 ent 65 ret UVMAPPED 66 end 67 if or ne and shr w0 1 3 0 ne and shr get uvw1 0 1 3 0 68 ret UVCONF 69 end 70 put uvleaf 0 ent 71 ret UVFREE 72 end 73 fn uvwk64 va ulong to ulong 74 ent = uvpdent va 75 w0 = get uvw0 0 76 if ne and w0 1 0 77 ret UVCONF 78 end 79 if ne and shr get uvw1 0 1 3 0 80 ret UVCONF 81 end 82 ap = and shr w0 1 3 83 if eq ap 0 84 put uvmiss 0 5 85 ret UVMISS 86 end 87 pa = and w0 UVBIGMSK 88 if uvbadpa pa 89 ret UVCONF 90 end 91 idx = uvlvidx 5 va 92 put uvleaf 0 add sub pa UVPOOL mul idx 8 93 v = uvld64 get uvleaf 0 94 if ne and v 1 0 95 ret UVMAPPED 96 end 97 ret UVFREE 98 end 99 fn uvwk4 va ulong to ulong 100 ent = uvpdent va 101 w1 = get uvw1 0 102 if ne and w1 1 0 103 ret UVCONF 104 end 105 if ne and shr get uvw0 0 1 3 0 106 ret UVCONF 107 end 108 ap = and shr w1 1 3 109 if eq ap 0 110 put uvmiss 0 6 111 ret UVMISS 112 end 113 pa = and w1 UVPDMSK 114 if uvbadpa pa 115 ret UVCONF 116 end 117 idx = uvlvidx 6 va 118 put uvleaf 0 add sub pa UVPOOL mul idx 8 119 v = uvld64 get uvleaf 0 120 if ne and v 1 0 121 ret UVMAPPED 122 end 123 ret UVFREE 124 end 125 fn uvwalk va ulong page ulong to ulong 126 r = uvwklv va 127 if ne r UVCONT 128 ret r 129 end 130 if eq page UV2M 131 ret uvwk2m va 132 end 133 if eq page UV64K 134 ret uvwk64 va 135 end 136 ret uvwk4 va 137 end 138 fn uvens64 va ulong to ulong 139 r = uvwk64 va 140 if ne r UVMISS 141 ret r 142 end 143 r2 = uvptnew 144 if ne r2 UVOK 145 ret r2 146 end 147 ent = uvpdent va 148 uvst64 ent uvpde add UVPOOL get uvout 0 UVAPSYS 149 ret uvwk64 va 150 end 151 fn uvens4 va ulong to ulong 152 r = uvwk4 va 153 if ne r UVMISS 154 ret r 155 end 156 r2 = uvptnew 157 if ne r2 UVOK 158 ret r2 159 end 160 ent = uvpdent va 161 uvst64 add ent 8 uvpde add UVPOOL get uvout 0 UVAPSYS 162 uvst64 ent 0 163 ret uvwk4 va 164 end 165 fn uvensure va ulong page ulong to ulong 166 r = uvfill va 167 if ne r UVOK 168 ret r 169 end 170 if eq page UV2M 171 ret uvwk2m va 172 end 173 if eq page UV64K 174 ret uvens64 va 175 end 176 ret uvens4 va 177 end 178 fn uvchk va ulong size ulong page ulong to ulong 179 if and ne page UV4K and ne page UV64K ne page UV2M 180 ret UVEINVAL 181 end 182 if eq size 0 183 ret UVEINVAL 184 end 185 if gt size mul page 8 186 ret UVEINVAL 187 end 188 if ne rem size page 0 189 ret UVEINVAL 190 end 191 if ne and va sub page 1 0 192 ret UVEALIGN 193 end 194 if ge va UVVA57 195 ret UVERANGE 196 end 197 if gt size sub UVVA57 va 198 ret UVERANGE 199 end 200 ret UVOK 201 end 202 fn uvaddneed va ulong page ulong to ulong 203 r = uvwalk va page 204 if or eq r UVMAPPED eq r UVCONF 205 ret UVEBUSY 206 end 207 if ne r UVMISS 208 ret UVOK 209 end 210 last = ulong 6 211 if eq page UV2M 212 last = 4 213 end 214 if eq page UV64K 215 last = 5 216 end 217 j = get uvmiss 0 218 while le j last bound 8 219 skip = and eq page UV4K eq j 5 220 if not skip 221 key = shr va add uvlvhi j 1 222 if ne key get uvkey j 223 put uvkey j key 224 put uvout 0 add get uvout 0 1 225 end 226 end 227 j = add j 1 228 end 229 ret UVOK 230 end 231 fn uvinstall va ulong pa ulong page ulong ap ulong pcf ulong to ulong 232 r = uvensure va page 233 if ne r UVFREE 234 ret r 235 end 236 uvst64 get uvleaf 0 uvpte pa ap pcf 237 ret UVOK 238 end 239 fn uvpoolhit pa ulong sz ulong to bool 240 if ge pa add UVPOOL UVBYTES 241 ret false 242 end 243 if le add pa sz UVPOOL 244 ret false 245 end 246 ret true 247 end 248 fn uvchkmap va ulong pa ulong size ulong page ulong ap ulong pcf ulong to ulong 249 r = uvchk va size page 250 if ne r UVOK 251 ret r 252 end 253 if ne and pa sub page 1 0 254 ret UVEALIGN 255 end 256 if ge pa UVPA52 257 ret UVERANGE 258 end 259 if gt size sub UVPA52 pa 260 ret UVERANGE 261 end 262 if uvpoolhit pa size 263 ret UVERANGE 264 end 265 if gt ap 3 266 ret UVEINVAL 267 end 268 if gt pcf 31 269 ret UVEINVAL 270 end 271 ret UVOK 272 end 273 fn uvmap va ulong pa ulong size ulong page ulong ap ulong pcf ulong to ulong 274 r = uvchkmap va pa size page ap pcf 275 if ne r UVOK 276 ret r 277 end 278 for k ulong 8 279 put uvkey k `18446744073709551615` 280 end 281 put uvout 0 0 282 off = ulong 0 283 for n ulong 8 284 if ge off size 285 break 286 end 287 r = uvaddneed add va off page 288 if ne r UVOK 289 ret r 290 end 291 off = add off page 292 end 293 if gt get uvout 0 uvnfree 294 ret UVENOM 295 end 296 off = 0 297 for n ulong 8 298 if ge off size 299 break 300 end 301 r = uvinstall add va off add pa off page ap pcf 302 if ne r UVOK 303 ret r 304 end 305 off = add off page 306 end 307 ret UVOK 308 end 309 fn uvunmap va ulong size ulong page ulong to ulong 310 r = uvchk va size page 311 if ne r UVOK 312 ret r 313 end 314 off = ulong 0 315 for n ulong 8 316 if ge off size 317 break 318 end 319 r = uvwalk add va off page 320 if ne r UVMAPPED 321 ret UVENOENT 322 end 323 off = add off page 324 end 325 off = 0 326 for n ulong 8 327 if ge off size 328 break 329 end 330 r = uvwalk add va off page 331 if ne r UVMAPPED 332 ret UVENOENT 333 end 334 uvst64 get uvleaf 0 0 335 off = add off page 336 end 337 ret UVOK 338 end 339 fn uvread va ulong page ulong to ulong 340 r = uvwalk va page 341 if ne r UVMAPPED 342 put uvdpa 0 0 343 put uvdap 0 0 344 put uvdpcf 0 0 345 put uvdv 0 0 346 ret r 347 end 348 v = uvld64 get uvleaf 0 349 put uvdv 0 and v 1 350 put uvdap 0 and shr v 1 3 351 put uvdpcf 0 and shr v 3 31 352 put uvdpa 0 and v UVPDMSK 353 ret UVMAPPED 354 end 355 fn uvoverlap va ulong sz ulong to bool 356 for i ulong 32 357 if ne get uvrsz i 0 358 b = get uvrva i 359 if and lt va add b get uvrsz i lt b add va sz 360 ret true 361 end 362 end 363 end 364 ret false 365 end 366 fn uvclaim va ulong sz ulong page ulong to ulong 367 for i ulong 32 368 if eq get uvrsz i 0 369 put uvrva i va 370 put uvrsz i sz 371 put uvrpg i page 372 put uvrpa i 0 373 put uvrro i 0 374 put uvrn 0 add get uvrn 0 1 375 put uvout 0 va 376 ret UVOK 377 end 378 end 379 ret UVENOM 380 end 381 fn uvallocat va ulong sz ulong page ulong to ulong 382 if and ne page UV4K and ne page UV64K ne page UV2M 383 ret UVEINVAL 384 end 385 if eq sz 0 386 ret UVEINVAL 387 end 388 if ne rem sz page 0 389 ret UVEINVAL 390 end 391 if ne rem va page 0 392 ret UVEALIGN 393 end 394 if lt va UVBASE 395 ret UVERANGE 396 end 397 if gt sz sub add UVBASE UVWIN va 398 ret UVERANGE 399 end 400 if uvoverlap va sz 401 ret UVEBUSY 402 end 403 ret uvclaim va sz page 404 end 405 fn uvalloc sz ulong page ulong to ulong 406 if and ne page UV4K and ne page UV64K ne page UV2M 407 ret UVEINVAL 408 end 409 if eq sz 0 410 ret UVEINVAL 411 end 412 if ne rem sz page 0 413 ret UVEINVAL 414 end 415 if gt sz UVWIN 416 ret UVERANGE 417 end 418 off = UVBASE 419 while lt off add UVBASE UVWIN bound 65536 420 if eq rem off page 0 421 if not uvoverlap off sz 422 if le sz sub add UVBASE UVWIN off 423 ret uvclaim off sz page 424 end 425 end 426 end 427 off = add off page 428 end 429 ret UVENOM 430 end 431 fn uvfind va ulong to ulong 432 for i ulong 32 433 if ne get uvrsz i 0 434 if and ge va get uvrva i lt va add get uvrva i get uvrsz i 435 ret i 436 end 437 end 438 end 439 ret 32 440 end 441 fn uvbind va ulong pa ulong to ulong 442 i = uvfind va 443 if ge i 32 444 ret UVENOENT 445 end 446 page = get uvrpg i 447 if ne rem pa page 0 448 ret UVEALIGN 449 end 450 if ge pa UVPA52 451 ret UVERANGE 452 end 453 if uvpoolhit pa page 454 ret UVERANGE 455 end 456 put uvrpa i pa 457 ret UVOK 458 end 459 fn uvprot va ulong ro ulong to ulong 460 i = uvfind va 461 if ge i 32 462 ret UVENOENT 463 end 464 put uvrro i ro 465 ret UVOK 466 end 467 fn uvinit to ulong 468 for i ulong 65536 469 put uvmem i 0 470 end 471 for i ulong 16 472 put uvused i 0 473 end 474 for i ulong 32 475 put uvrsz i 0 476 put uvrva i 0 477 put uvrpa i 0 478 put uvrro i 0 479 put uvrpg i 0 480 end 481 put uvrn 0 0 482 ret uvptnew 483 end