mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
Merge pull request #404 from ThingsCouldGetDicey/fix/control-table-generator-parity
fix(rmapi): preserve existing memory controls in table generator
This commit is contained in:
@ -65,6 +65,26 @@ class TableGeneratorsAndLpwrCheckTest(unittest.TestCase):
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
mod.main(["--check"])
|
||||
|
||||
def test_rmapi_supplement_preserves_existing_memory_controls(self):
|
||||
mod = _load("generate_rmapi_tables", "tools/generate_rmapi_tables.py")
|
||||
data = json.loads(mod.DOSSIER.read_text(encoding="utf-8"))
|
||||
text, count, _ = mod.render_table(data, mod.SUPPLEMENTAL_METHODS)
|
||||
self.assertEqual(text, mod.TARGET.read_text(encoding="utf-8"))
|
||||
self.assertGreaterEqual(count, len(data["methods"]))
|
||||
self.assertIn("m(0x4789f2, 0x410110, 0x10208, 0, 16, 43653)", text)
|
||||
self.assertIn("m(0x4789f2, 0x410118, 0x8, 0, 8, 43651)", text)
|
||||
|
||||
def test_rmapi_supplement_deduplicates_identical_and_rejects_conflicting_rows(self):
|
||||
mod = _load("generate_rmapi_tables", "tools/generate_rmapi_tables.py")
|
||||
row = (1, 0x101, 8, 0, 4, 1)
|
||||
data = {
|
||||
"class_defs": [{"name": "Obj", "classId": 1, "ancestors": []}],
|
||||
"methods": [[0x101, "_nv000001rm", 8, 0, 4, "Obj", "m"]],
|
||||
}
|
||||
self.assertEqual(mod.render_table(data, (row,)), mod.render_table(data))
|
||||
with self.assertRaisesRegex(ValueError, "conflicting supplemental"):
|
||||
mod.render_table(data, ((1, 0x101, 8, 0, 8, 1),))
|
||||
|
||||
def test_find_rm_object_and_sha256_mismatch_under_O(self):
|
||||
for rel in (
|
||||
"tools/generate_pf_board_ids.py",
|
||||
|
||||
@ -14,7 +14,19 @@ DOSSIER = ROOT / "analysis/closed-driver-580/rmapi-userspace.json"
|
||||
TARGET = ROOT / "src/nvidia/src/rmapi/control_table.rs"
|
||||
|
||||
|
||||
def render_table(data: dict) -> tuple[str, int, int]:
|
||||
# Existing Memory-class exports present in the checked-in control table but
|
||||
# absent from the userspace dossier. Preserve the exact current descriptors
|
||||
# (including flags) rather than treating this as new binary extraction.
|
||||
# See rmapi/memory.rs CMD_MEM_SURFACE_INFO / CMD_MEM_PAGE_SIZE and
|
||||
# analysis/closed-driver-580/rmapi-memory-constructor-spec.md section 7.
|
||||
# Format: (class, command, flags, access right, parameter size, handler).
|
||||
SUPPLEMENTAL_METHODS = (
|
||||
(0x4789f2, 0x410110, 0x10208, 0, 16, 43653),
|
||||
(0x4789f2, 0x410118, 0x8, 0, 8, 43651),
|
||||
)
|
||||
|
||||
|
||||
def render_table(data: dict, supplemental=()) -> tuple[str, int, int]:
|
||||
class_ids = {entry["name"]: entry["classId"] for entry in data["class_defs"]}
|
||||
|
||||
def class_of(owner):
|
||||
@ -24,6 +36,15 @@ def render_table(data: dict) -> tuple[str, int, int]:
|
||||
(class_of(owner), method, flags, access, size, int(handler[3:-2]))
|
||||
for method, handler, flags, access, size, owner, _name in data["methods"]
|
||||
)
|
||||
for method in supplemental:
|
||||
matches = [row for row in methods if row[:2] == method[:2]]
|
||||
if not matches:
|
||||
methods.append(method)
|
||||
elif any(row != method for row in matches):
|
||||
raise ValueError(
|
||||
f"conflicting supplemental control descriptor {method[0]:#x}/{method[1]:#x}"
|
||||
)
|
||||
methods.sort()
|
||||
lines = [
|
||||
"//! Exported control methods and NVOC class ancestry of the original (580.178.04).",
|
||||
"//! Generated by tools/generate_rmapi_tables.py from the RM API dossier; do not edit.",
|
||||
@ -80,7 +101,7 @@ def main(argv=None) -> None:
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
data = json.loads(DOSSIER.read_text(encoding="utf-8"))
|
||||
text, method_count, class_count = render_table(data)
|
||||
text, method_count, class_count = render_table(data, SUPPLEMENTAL_METHODS)
|
||||
if args.check:
|
||||
if not TARGET.is_file() or TARGET.read_text(encoding="utf-8") != text:
|
||||
raise SystemExit("control_table.rs is stale")
|
||||
|
||||
Reference in New Issue
Block a user