|
10 | 10 |
|
11 | 11 | import struct |
12 | 12 | from ..fw.agx.handoff import GFXHandoff |
| 13 | +from m1n1.constructutils import Ver |
13 | 14 | from ..utils import * |
14 | 15 | from ..malloc import Heap |
15 | 16 | from enum import IntEnum |
@@ -239,16 +240,22 @@ def closed(self): |
239 | 240 | return False |
240 | 241 |
|
241 | 242 |
|
| 243 | +if Ver.check("G >= G15"): |
| 244 | + UAT_L0_OFF = 42 |
| 245 | +else: |
| 246 | + UAT_L0_OFF = 39 |
| 247 | + |
242 | 248 | class UAT(Reloadable): |
243 | 249 | NUM_CONTEXTS = 64 |
244 | 250 |
|
245 | 251 | PAGE_BITS = 14 |
246 | 252 | PAGE_SIZE = 1 << PAGE_BITS |
247 | 253 |
|
| 254 | + # "size" is the number of entries at that level |
248 | 255 | L0_SIZE = 2 |
249 | | - L0_OFF = 39 |
250 | | - L1_SIZE = 8 |
| 256 | + L0_OFF = UAT_L0_OFF |
251 | 257 | L1_OFF = 36 |
| 258 | + L1_SIZE = 1 << (L0_OFF - L1_OFF) |
252 | 259 | L2_OFF = 25 |
253 | 260 | L3_OFF = 14 |
254 | 261 |
|
@@ -277,6 +284,8 @@ def __init__(self, iface, util=None, hv=None): |
277 | 284 | self.shared_region = self.sgx_dev.gfx_shared_region_base |
278 | 285 | self.gpu_region = self.sgx_dev.gpu_region_base |
279 | 286 | self.ttbr0_base = self.u.memalign(self.PAGE_SIZE, self.PAGE_SIZE) |
| 287 | + # We reuse the TTBR1 which the firmware is using, because it also has the FW-side mappings. |
| 288 | + # The alternative would be to map self.sgx_dev.gfx_shared_l2_region_base into a new TTBR1. |
280 | 289 | self.ttbr1_base = self.sgx_dev.gfx_shared_region_base |
281 | 290 | self.handoff = GFXHandoff(self.u) |
282 | 291 |
|
@@ -499,8 +508,8 @@ def invalidate_cache(self): |
499 | 508 |
|
500 | 509 | def recurse_level(self, level, base, table, page_fn=None, table_fn=None): |
501 | 510 | def extend(addr): |
502 | | - if addr >= 0x80_00000000: |
503 | | - addr |= 0xf00_00000000 |
| 511 | + if addr >= (1 << UAT_L0_OFF): |
| 512 | + addr |= 0xffffffff_ffffffff ^ self.VA_MASK |
504 | 513 | return addr |
505 | 514 |
|
506 | 515 | offset, size, ptecls = self.LEVELS[level] |
@@ -539,7 +548,11 @@ def init(self): |
539 | 548 |
|
540 | 549 | print("[UAT] Initializing...") |
541 | 550 |
|
| 551 | + #print(f"[UAT] TTBAT @ 0x{self.gpu_region:016x}") |
| 552 | + #print(f"[UAT] ASC carveout region @ 0x{self.shared_region:016x}") |
| 553 | + |
542 | 554 | # Clear out any stale kernel page tables |
| 555 | + # (The third entry is the TTBR1 shared L2 table, which is fine to keep.) |
543 | 556 | self.p.memset64(self.ttbr1_base + 0x10, 0, 0x3ff0) |
544 | 557 | self.u.inst("tlbi vmalle1os") |
545 | 558 |
|
|
0 commit comments