omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / uvm / ioctl.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Server-side host MODEL only; no Linux device endpoint or RM object resolver. |
| 3 | note NVIDIA580.173.02 kernel-open/nvidia-uvm/uvm_ioctl.h:381-409,491-562; |
| 4 | note uvm_linux_ioctl.h:28-38; uvm_types.h:69-71,84-94. Layout measured by tests/uvms_offsets.c. |
| 5 | note Explicit imported object capability (handle,PA,size), not a reinterpretation of RM handle as PA. |
| 6 | global siab uchar 9264 |
| 7 | global siob uchar 9264 |
| 8 | global siolen ulong 1 |
| 9 | global siinit ulong 1 |
| 10 | global sigpu ulong 1 |
| 11 | global sivs ulong 1 |
| 12 | global siuuid uchar 16 |
| 13 | global sicli ulong 1 |
| 14 | global sifd ulong 1 |
| 15 | global sigrp ulong 1 |
| 16 | global siobj ulong 24 |
| 17 | fn siload off ulong n ulong to ulong |
| 18 | v = ulong 0 |
| 19 | for j ulong n |
| 20 | v = or v shl ulong get siab add off j mul j 8 |
| 21 | end |
| 22 | ret v |
| 23 | end |
| 24 | fn sistore off ulong n ulong v ulong to void |
| 25 | for j ulong n |
| 26 | put siob add off j uchar and shr v mul j 8 255 |
| 27 | end |
| 28 | end |
| 29 | fn siobject handle ulong pa ulong size ulong to ulong |
| 30 | if or eq handle 0 eq pa 0 |
| 31 | ret UVEINVAL |
| 32 | end |
| 33 | if or ne rem pa UV4K 0 ne rem size UV4K 0 |
| 34 | ret UVEALIGN |
| 35 | end |
| 36 | if or eq size 0 or ge pa UVPA52 gt size sub UVPA52 pa |
| 37 | ret UVERANGE |
| 38 | end |
| 39 | if uvpoolhit pa size |
| 40 | ret UVERANGE |
| 41 | end |
| 42 | for j ulong 8 |
| 43 | if eq get siobj mul j 3 handle |
| 44 | ret UVEBUSY |
| 45 | end |
| 46 | end |
| 47 | for j ulong 8 |
| 48 | if eq get siobj mul j 3 0 |
| 49 | put siobj mul j 3 handle |
| 50 | put siobj add mul j 3 1 pa |
| 51 | put siobj add mul j 3 2 size |
| 52 | ret UVOK |
| 53 | end |
| 54 | end |
| 55 | ret UVENOM |
| 56 | end |
| 57 | fn sisize cmd ulong to ulong |
| 58 | if eq cmd 805306369 |
| 59 | ret 16 |
| 60 | end |
| 61 | if eq cmd 37 |
| 62 | ret 40 |
| 63 | end |
| 64 | if eq cmd 38 |
| 65 | ret 20 |
| 66 | end |
| 67 | if eq cmd 23 |
| 68 | ret 16 |
| 69 | end |
| 70 | if eq cmd 33 |
| 71 | ret 9264 |
| 72 | end |
| 73 | if eq cmd 34 |
| 74 | ret 24 |
| 75 | end |
| 76 | if eq cmd 25 |
| 77 | ret 32 |
| 78 | end |
| 79 | if eq cmd 39 |
| 80 | ret 8 |
| 81 | end |
| 82 | ret 0 |
| 83 | end |
| 84 | fn sistoff cmd ulong to ulong |
| 85 | if or eq cmd 805306369 eq cmd 23 |
| 86 | ret 8 |
| 87 | end |
| 88 | if eq cmd 37 |
| 89 | ret 36 |
| 90 | end |
| 91 | if or eq cmd 38 eq cmd 34 |
| 92 | ret 16 |
| 93 | end |
| 94 | if eq cmd 33 |
| 95 | ret 9260 |
| 96 | end |
| 97 | if eq cmd 25 |
| 98 | ret 28 |
| 99 | end |
| 100 | ret 4 |
| 101 | end |
| 102 | fn siuidmatch to bool |
| 103 | for j ulong 16 |
| 104 | if ne get siab j get siuuid j |
| 105 | ret false |
| 106 | end |
| 107 | end |
| 108 | ret true |
| 109 | end |
| 110 | fn sireg to ulong |
| 111 | if ne get sigpu 0 0 |
| 112 | ret UVEBUSY |
| 113 | end |
| 114 | nz = ulong 0 |
| 115 | for j ulong 16 |
| 116 | nz = or nz ulong get siab j |
| 117 | end |
| 118 | if or eq nz 0 or eq siload 28 4 0 ge siload 24 4 2147483648 |
| 119 | ret UVEINVAL |
| 120 | end |
| 121 | for j ulong 16 |
| 122 | put siuuid j get siab j |
| 123 | end |
| 124 | put sicli 0 siload 28 4 |
| 125 | put sifd 0 siload 24 4 |
| 126 | put sigpu 0 1 |
| 127 | sistore 16 4 0 |
| 128 | sistore 20 4 4294967295 |
| 129 | ret UVOK |
| 130 | end |
| 131 | fn simap to ulong |
| 132 | if or eq get sigpu 0 0 eq get sivs 0 0 |
| 133 | ret UVEPERM |
| 134 | end |
| 135 | if ne siload 9240 8 1 |
| 136 | ret UVEINVAL |
| 137 | end |
| 138 | for j ulong 16 |
| 139 | if ne get siab add j 24 get siuuid j |
| 140 | ret UVEINVAL |
| 141 | end |
| 142 | end |
| 143 | note Model supports default mapping/cache/format only, refuses all unimplemented attributes. |
| 144 | for j ulong 20 |
| 145 | if ne get siab add j 40 0 |
| 146 | ret UVEINVAL |
| 147 | end |
| 148 | end |
| 149 | if or ne siload 9248 4 get sifd 0 ne siload 9252 4 get sicli 0 |
| 150 | ret UVEPERM |
| 151 | end |
| 152 | handle = siload 9256 4 |
| 153 | for j ulong 8 |
| 154 | if and ne handle 0 eq get siobj mul j 3 handle |
| 155 | off = siload 16 8 |
| 156 | size = siload 8 8 |
| 157 | cap = get siobj add mul j 3 2 |
| 158 | if gt off cap |
| 159 | ret UVERANGE |
| 160 | end |
| 161 | if gt size sub cap off |
| 162 | ret UVERANGE |
| 163 | end |
| 164 | ret sadd siload 0 8 size add get siobj add mul j 3 1 off 5 |
| 165 | end |
| 166 | end |
| 167 | ret UVENOENT |
| 168 | end |
| 169 | fn siaction cmd ulong to ulong |
| 170 | if eq cmd 805306369 |
| 171 | if ne get siinit 0 0 |
| 172 | ret UVEBUSY |
| 173 | end |
| 174 | if gt siload 0 8 1 |
| 175 | ret UVEINVAL |
| 176 | end |
| 177 | r = screate |
| 178 | if ne r UVOK |
| 179 | ret r |
| 180 | end |
| 181 | put siinit 0 1 |
| 182 | ret UVOK |
| 183 | end |
| 184 | if eq get siinit 0 0 |
| 185 | ret UVEPERM |
| 186 | end |
| 187 | if eq cmd 37 |
| 188 | ret sireg |
| 189 | end |
| 190 | if eq cmd 38 |
| 191 | if or eq get sigpu 0 0 not siuidmatch |
| 192 | ret UVENOENT |
| 193 | end |
| 194 | if ne get sn 0 0 |
| 195 | ret UVEBUSY |
| 196 | end |
| 197 | put sigpu 0 0 |
| 198 | put sivs 0 0 |
| 199 | ret UVOK |
| 200 | end |
| 201 | if eq cmd 23 |
| 202 | if eq get sigrp 0 18446744073709551615 |
| 203 | ret UVENOM |
| 204 | end |
| 205 | put sigrp 0 add get sigrp 0 1 |
| 206 | sistore 0 8 get sigrp 0 |
| 207 | ret UVOK |
| 208 | end |
| 209 | if eq cmd 25 |
| 210 | if or eq get sigpu 0 0 not siuidmatch |
| 211 | ret UVENOENT |
| 212 | end |
| 213 | if ne get sivs 0 0 |
| 214 | ret UVEBUSY |
| 215 | end |
| 216 | if or ne siload 16 4 get sifd 0 or ne siload 20 4 get sicli 0 eq siload 24 4 0 |
| 217 | ret UVEINVAL |
| 218 | end |
| 219 | put sivs 0 1 |
| 220 | ret UVOK |
| 221 | end |
| 222 | if eq cmd 33 |
| 223 | ret simap |
| 224 | end |
| 225 | if eq cmd 34 |
| 226 | ret sremove siload 0 8 siload 8 8 |
| 227 | end |
| 228 | sistore 0 4 1 |
| 229 | ret UVOK |
| 230 | end |
| 231 | fn sidispatch cmd ulong size ulong to ulong |
| 232 | put siolen 0 0 |
| 233 | need = sisize cmd |
| 234 | if eq need 0 |
| 235 | ret UVEINVAL |
| 236 | end |
| 237 | if ne need size |
| 238 | ret UVEINVAL |
| 239 | end |
| 240 | for j ulong size |
| 241 | put siob j get siab j |
| 242 | end |
| 243 | r = siaction cmd |
| 244 | nv = ulong 0 |
| 245 | if ne r UVOK |
| 246 | nv = 31 |
| 247 | if eq r UVEPERM |
| 248 | nv = 64 |
| 249 | end |
| 250 | if eq r UVEBUSY |
| 251 | nv = 23 |
| 252 | end |
| 253 | end |
| 254 | sistore sistoff cmd 4 nv |
| 255 | put siolen 0 size |
| 256 | ret r |
| 257 | end |