Files
nvdriver/tools/oracle_gsp_620.py
morebrackets 668bc20cee Merge remote-tracking branch 'origin/master' into pr-217
# Conflicts:
#	tools/oracle_gsp_620.py
2026-12-02 23:19:43 -08:00

401 lines
19 KiB
Python
Executable File

#!/usr/bin/env python3
"""Compare the selected NVIDIA open-module headers with nvdriver's 620 constants."""
import hashlib
import json
import os
from pathlib import Path
import re
import subprocess
import sys
import tempfile
# Prefer the in-repo reference tree when it is checked out, so the parity check actually runs on a
# machine that has it instead of silently skipping; OPEN_GPU_ROOT still overrides.
_REPO_REFERENCE_ROOT = Path(__file__).resolve().parent.parent / "target" / "ref" / "ogkm"
# Both 620 patch releases the driver is defined for: 620.70.06 (the original 620 workstation drop)
# and 620.73.04 (later installs, and the only one some cards have on disk). The R620 framing this
# oracle checks is the same in both, matching `gsp_image::releases_for_abi(GspAbiVersion::R620)`.
EXPECTED_SOURCE_VERSIONS = ("620.70.06", "620.73.04")
def _read_source_version(tree: str) -> str | None:
try:
m = re.search(
r"^[ \t]*NVIDIA_VERSION[ \t]*:?=[ \t]*([0-9]+(?:\.[0-9]+)+)[ \t]*(?:#.*)?$",
(Path(tree) / "version.mk").read_text(encoding="utf-8"),
re.MULTILINE,
)
except (OSError, UnicodeError):
return None
return m.group(1) if m else None
def _default_open_gpu_root() -> str:
if _REPO_REFERENCE_ROOT.is_dir():
return str(_REPO_REFERENCE_ROOT)
analysis_root = os.environ.get("NV_RS_ANALYSIS_ROOT")
if analysis_root:
candidates = [
*(os.path.join(analysis_root, "reference", f"open-gpu-kernel-modules-{v}") for v in EXPECTED_SOURCE_VERSIONS),
os.path.join(analysis_root, "reference", "open-gpu-kernel-modules"),
]
for candidate in candidates:
if os.path.isdir(candidate) and _read_source_version(candidate) in EXPECTED_SOURCE_VERSIONS:
return candidate
for candidate in candidates:
if os.path.isdir(candidate):
return candidate
return str(Path.home() / "open-gpu-kernel-modules")
OPEN_GPU_ROOT = os.environ.get("OPEN_GPU_ROOT") or _default_open_gpu_root()
C_PROBE = r"""
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
typedef uint8_t NvU8;
typedef uint16_t NvU16;
typedef uint32_t NvU32;
typedef uint64_t NvU64;
typedef uint32_t NV_STATUS;
typedef size_t NvLength;
typedef uint8_t NvBool;
#define NV_INLINE inline
#define NV_ABI_STABLE
#define NVBIT(n) (1U << (n))
#define NV_OFFSETOF(s, m) offsetof(s, m)
#define ct_assert(x) _Static_assert(x, #x)
#define DRF_SHIFT(drf) (0 ? drf)
#define DRF_MASK(drf) (0xFFFFFFFFU >> (31 - ((1 ? drf) - (0 ? drf))))
#define REF_NUM(drf, n) (((NvU32)(n) & DRF_MASK(drf)) << DRF_SHIFT(drf))
#define REF_DEF(drf, d) REF_NUM(drf, drf##d)
#define REF_VAL(drf, v) (((NvU32)(v) >> DRF_SHIFT(drf)) & DRF_MASK(drf))
#include "mctp_format.h"
#include "nvdm_format.h"
#include "gsp/gsp_fw_wpr_meta.h"
#include "vgpu/rpc_global_enums.h"
#include "gmcapi/gmcapi_base.h"
#include "gmcapi/gmcapi_system_info.h"
#include "gmcapi/gmcapi_gsp_config.h"
int main(void) {
printf("{\n");
printf(" \"mctp_transport_1_1_0_0_0\": %u,\n", mctpCreateTransportHeader(1, 1, 0, 0, 0));
printf(" \"mctp_nvdm_rm_rpc\": %u,\n", mctpCreateNvdmHeader(NVDM_TYPE_RM_RPC));
printf(" \"mctp_nvdm_gmcapi\": %u,\n", mctpCreateNvdmHeader(NVDM_TYPE_GMCAPI));
printf(" \"nvdm_type_rm_rpc\": %u,\n", (unsigned)NVDM_TYPE_RM_RPC);
printf(" \"nvdm_type_gmcapi\": %u,\n", (unsigned)NVDM_TYPE_GMCAPI);
printf(" \"sizeof_gmcapi_header\": %zu,\n", sizeof(GMCAPI_HEADER));
printf(" \"gmcapi_cmd_gsp_init\": %u,\n", (unsigned)GMCAPI_CMD_GSP_INIT);
printf(" \"gmcapi_cmd_exec_bl\": %u,\n", (unsigned)GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER);
printf(" \"gmcapi_cmd_exec_hs\": %u,\n", (unsigned)GMCAPI_CMD_EXEC_HS_BINARY);
printf(" \"gmcapi_cmd_suspend\": %u,\n", (unsigned)GMCAPI_CMD_GSP_SUSPEND);
printf(" \"gmcapi_cmd_resume_done\": %u,\n", (unsigned)GMCAPI_CMD_GSP_RESUME_DONE);
printf(" \"gmcapi_resp_flag\": %u,\n", (unsigned)GMCAPI_HEADER_COMMAND_FLAGS_RESPONSE);
printf(" \"gmcapi_id_mask\": %u,\n", (unsigned)GMCAPI_HEADER_COMMAND_ID_MASK);
printf(" \"gmcapi_off_command\": %zu,\n", offsetof(GMCAPI_HEADER, command));
printf(" \"gmcapi_off_size\": %zu,\n", offsetof(GMCAPI_HEADER, size));
printf(" \"gmcapi_off_sequence\": %zu,\n", offsetof(GMCAPI_HEADER, sequence));
printf(" \"gmcapi_off_reserved\": %zu,\n", offsetof(GMCAPI_HEADER, reserved));
printf(" \"gmcapi_off_data\": %zu,\n", offsetof(GMCAPI_HEADER, data));
printf(" \"si_pci_device_id\": %u,\n", (unsigned)NVGMC_SI_PCI_DEVICE_ID);
printf(" \"si_pci_sub_device_id\": %u,\n", (unsigned)NVGMC_SI_PCI_SUB_DEVICE_ID);
printf(" \"si_pci_revision_id\": %u,\n", (unsigned)NVGMC_SI_PCI_REVISION_ID);
printf(" \"si_pci_config_mirror_base\": %u,\n", (unsigned)NVGMC_SI_PCI_CONFIG_MIRROR_BASE);
printf(" \"si_pci_config_mirror_size\": %u,\n", (unsigned)NVGMC_SI_PCI_CONFIG_MIRROR_SIZE);
printf(" \"si_host_arch\": %u,\n", (unsigned)NVGMC_SI_HOST_ARCH);
printf(" \"si_host_os_type\": %u,\n", (unsigned)NVGMC_SI_HOST_OS_TYPE);
printf(" \"si_host_page_size\": %u,\n", (unsigned)NVGMC_SI_HOST_PAGE_SIZE);
printf(" \"si_timeout_us_vgpu\": %u,\n", (unsigned)NVGMC_SI_DEFAULT_TIMEOUT_US_VGPU);
printf(" \"si_timeout_us_graphics\": %u,\n", (unsigned)NVGMC_SI_DEFAULT_TIMEOUT_US_GRAPHICS_MODE);
printf(" \"si_timeout_us_compute\": %u,\n", (unsigned)NVGMC_SI_DEFAULT_TIMEOUT_US_COMPUTE_MODE);
printf(" \"si_pcie_flags\": %u,\n", (unsigned)NVGMC_SI_PCIE_FLAGS);
printf(" \"si_platform_flags\": %u,\n", (unsigned)NVGMC_SI_PLATFORM_FLAGS);
printf(" \"si_feature_flags\": %u,\n", (unsigned)NVGMC_SI_FEATURE_FLAGS);
printf(" \"si_vf_flags\": %u,\n", (unsigned)NVGMC_SI_VF_FLAGS);
printf(" \"si_gpu_phys_addr\": %u,\n", (unsigned)NVGMC_SI_GPU_PHYS_ADDR);
printf(" \"si_gpu_phys_fb_addr\": %u,\n", (unsigned)NVGMC_SI_GPU_PHYS_FB_ADDR);
printf(" \"si_gpu_phys_inst_addr\": %u,\n", (unsigned)NVGMC_SI_GPU_PHYS_INST_ADDR);
printf(" \"si_gpu_phys_io_addr\": %u,\n", (unsigned)NVGMC_SI_GPU_PHYS_IO_ADDR);
printf(" \"si_domain_bus_device_func\": %u,\n", (unsigned)NVGMC_SI_NV_DOMAIN_BUS_DEVICE_FUNC);
printf(" \"si_console_mem_size\": %u,\n", (unsigned)NVGMC_SI_CONSOLE_MEM_SIZE);
printf(" \"si_max_user_va\": %u,\n", (unsigned)NVGMC_SI_MAX_USER_VA);
printf(" \"si_kernel_driver_name\": %u,\n", (unsigned)NVGMC_SI_KERNEL_DRIVER_NAME);
printf(" \"si_kernel_driver_version\": %u,\n", (unsigned)NVGMC_SI_KERNEL_DRIVER_VERSION_STRING);
printf(" \"si_kernel_driver_changelist\": %u,\n", (unsigned)NVGMC_SI_KERNEL_DRIVER_CHANGELIST);
printf(" \"si_unstable_interface\": %u,\n", (unsigned)NVGMC_SI_UNSTABLE_INTERFACE_SUPPORT);
printf(" \"sc_vbios_revision\": %u,\n", (unsigned)NVGMC_SC_VBIOS_REVISION);
printf(" \"sc_internal_client\": %u,\n", (unsigned)NVGMC_SC_INTERNAL_CLIENT_HANDLE);
printf(" \"sc_internal_device\": %u,\n", (unsigned)NVGMC_SC_INTERNAL_DEVICE_HANDLE);
printf(" \"sc_internal_subdevice\": %u,\n", (unsigned)NVGMC_SC_INTERNAL_SUBDEVICE_HANDLE);
printf(" \"sc_fb_length\": %u,\n", (unsigned)NVGMC_SC_FB_LENGTH);
printf(" \"sc_bar1_pde_base\": %u,\n", (unsigned)NVGMC_SC_BAR1_PDE_BASE);
printf(" \"sc_bar2_pde_base\": %u,\n", (unsigned)NVGMC_SC_BAR2_PDE_BASE);
printf(" \"sc_vmmu_segment_size\": %u,\n", (unsigned)NVGMC_SC_VMMU_SEGMENT_SIZE);
printf(" \"sc_wpr_non_wpr_heap_offset\": %u,\n", (unsigned)NVGMC_SC_WPR_LAYOUT_NON_WPR_HEAP_OFFSET);
printf(" \"sc_wpr_frts_offset\": %u,\n", (unsigned)NVGMC_SC_WPR_LAYOUT_FRTS_OFFSET);
printf(" \"sc_gpu_name_string\": %u,\n", (unsigned)NVGMC_SC_GPU_NAME_STRING);
printf(" \"sc_gpu_short_name_string\": %u,\n", (unsigned)NVGMC_SC_GPU_SHORT_NAME_STRING);
printf(" \"sizeof_wpr_meta\": %zu,\n", sizeof(GspFwWprMeta));
printf(" \"wpr_magic\": %llu,\n", (unsigned long long)GSP_FW_WPR_META_MAGIC);
printf(" \"wpr_revision\": %llu,\n", (unsigned long long)GSP_FW_WPR_META_REVISION);
printf(" \"wpr_verified\": %llu,\n", (unsigned long long)GSP_FW_WPR_META_VERIFIED);
printf(" \"offsetof_paging_config\": %zu,\n", offsetof(GspFwWprMeta, pagingConfig));
printf(" \"wpr_off_magic\": %u,\n", (unsigned)offsetof(GspFwWprMeta, magic));
printf(" \"wpr_off_revision\": %u,\n", (unsigned)offsetof(GspFwWprMeta, revision));
printf(" \"wpr_off_radix3_addr\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sysmemAddrOfRadix3Elf));
printf(" \"wpr_off_radix3_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sizeOfRadix3Elf));
printf(" \"wpr_off_bootloader_addr\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sysmemAddrOfBootloader));
printf(" \"wpr_off_bootloader_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sizeOfBootloader));
printf(" \"wpr_off_bl_code\": %u,\n", (unsigned)offsetof(GspFwWprMeta, bootloaderCodeOffset));
printf(" \"wpr_off_bl_data\": %u,\n", (unsigned)offsetof(GspFwWprMeta, bootloaderDataOffset));
printf(" \"wpr_off_bl_manifest\": %u,\n", (unsigned)offsetof(GspFwWprMeta, bootloaderManifestOffset));
printf(" \"wpr_off_sig_addr\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sysmemAddrOfSignature));
printf(" \"wpr_off_sig_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sizeOfSignature));
printf(" \"wpr_off_rsvd_start\": %u,\n", (unsigned)offsetof(GspFwWprMeta, gspFwRsvdStart));
printf(" \"wpr_off_nonwpr_off\": %u,\n", (unsigned)offsetof(GspFwWprMeta, nonWprHeapOffset));
printf(" \"wpr_off_nonwpr_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, nonWprHeapSize));
printf(" \"wpr_off_wpr_start\": %u,\n", (unsigned)offsetof(GspFwWprMeta, gspFwWprStart));
printf(" \"wpr_off_heap_off\": %u,\n", (unsigned)offsetof(GspFwWprMeta, gspFwHeapOffset));
printf(" \"wpr_off_heap_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, gspFwHeapSize));
printf(" \"wpr_off_fw_off\": %u,\n", (unsigned)offsetof(GspFwWprMeta, gspFwOffset));
printf(" \"wpr_off_bootbin\": %u,\n", (unsigned)offsetof(GspFwWprMeta, bootBinOffset));
printf(" \"wpr_off_frts_off\": %u,\n", (unsigned)offsetof(GspFwWprMeta, frtsOffset));
printf(" \"wpr_off_frts_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, frtsSize));
printf(" \"wpr_off_wpr_end\": %u,\n", (unsigned)offsetof(GspFwWprMeta, gspFwWprEnd));
printf(" \"wpr_off_fb_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, fbSize));
printf(" \"wpr_off_vga_off\": %u,\n", (unsigned)offsetof(GspFwWprMeta, vgaWorkspaceOffset));
printf(" \"wpr_off_vga_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, vgaWorkspaceSize));
printf(" \"wpr_off_boot_count\": %u,\n", (unsigned)offsetof(GspFwWprMeta, bootCount));
printf(" \"wpr_off_crash_addr\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sysmemAddrOfCrashReportQueue));
printf(" \"wpr_off_crash_size\": %u,\n", (unsigned)offsetof(GspFwWprMeta, sizeOfCrashReportQueue));
printf(" \"wpr_off_vf_partitions\": %u,\n", (unsigned)offsetof(GspFwWprMeta, gspFwHeapVfPartitionCount));
printf(" \"wpr_off_flags\": %u,\n", (unsigned)offsetof(GspFwWprMeta, flags));
printf(" \"wpr_off_pmu_reserved\": %u,\n", (unsigned)offsetof(GspFwWprMeta, pmuReservedSize));
printf(" \"wpr_off_verified\": %u,\n", (unsigned)offsetof(GspFwWprMeta, verified));
printf(" \"wpr_flag_nvle\": %u,\n", (unsigned)GSP_FW_FLAGS_MULTI_GPU_NVLE_ENABLED);
printf(" \"rpc_num_functions\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_NUM_FUNCTIONS);
printf(" \"rpc_num_events\": %u,\n", (unsigned)NV_VGPU_MSG_EVENT_NUM_EVENTS);
printf(" \"rpc_bind_bar2\": %u,\n", (unsigned)NV_VGPU_MSG_EVENT_BIND_BAR2);
printf(" \"rpc_gsp_static_info\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO);
printf(" \"rpc_gsp_set_system_info\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO);
printf(" \"rpc_set_registry\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_SET_REGISTRY);
printf(" \"rpc_gsp_init_post_objgpu\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_GSP_INIT_POST_OBJGPU);
printf(" \"rpc_init_gsp_trace_crash_buffer\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_INIT_GSP_TRACE_CRASH_BUFFER);
printf(" \"rpc_ctrl_gpu_set_migration_block\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_CTRL_GPU_SET_MIGRATION_BLOCK);
printf(" \"rpc_ctrl_fifo_vgpu_swrunlist_submit\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_CTRL_FIFO_VGPU_SWRUNLIST_SUBMIT);
printf(" \"rpc_ctrl_fifo_vgpu_swrunlist_channel_update\": %u,\n", (unsigned)NV_VGPU_MSG_FUNCTION_CTRL_FIFO_VGPU_SWRUNLIST_CHANNEL_UPDATE);
printf(" \"rpc_send_guest_stun\": %u\n", (unsigned)NV_VGPU_MSG_FUNCTION_SEND_GUEST_STUN_COMPLETION);
printf("}\n");
return 0;
}
"""
EXPECTED_RUST = {
"mctp_transport_1_1_0_0_0": 0xC0000001,
"mctp_nvdm_rm_rpc": 0x2510DE7E,
"mctp_nvdm_gmcapi": 0x2610DE7E,
"nvdm_type_rm_rpc": 0x25,
"nvdm_type_gmcapi": 0x26,
"sizeof_gmcapi_header": 40,
"gmcapi_cmd_gsp_init": 0x00010001,
"gmcapi_cmd_exec_bl": 0x00010002,
"gmcapi_cmd_exec_hs": 0x00010003,
"gmcapi_cmd_suspend": 0x00010004,
"gmcapi_cmd_resume_done": 0x00010005,
"gmcapi_resp_flag": 0x01000000,
"gmcapi_id_mask": 0x00FFFFFF,
"gmcapi_off_command": 0x00,
"gmcapi_off_size": 0x04,
"gmcapi_off_sequence": 0x08,
"gmcapi_off_reserved": 0x14,
"gmcapi_off_data": 0x28,
"si_pci_device_id": 0x0001,
"si_pci_sub_device_id": 0x0002,
"si_pci_revision_id": 0x0003,
"si_pci_config_mirror_base": 0x0010,
"si_pci_config_mirror_size": 0x0011,
"si_host_arch": 0x0070,
"si_host_os_type": 0x0071,
"si_host_page_size": 0x0078,
"si_timeout_us_vgpu": 0x00A0,
"si_timeout_us_graphics": 0x00A1,
"si_timeout_us_compute": 0x00A2,
"si_pcie_flags": 0x1000,
"si_platform_flags": 0x1001,
"si_feature_flags": 0x1002,
"si_vf_flags": 0x1003,
"si_gpu_phys_addr": 0x1010,
"si_gpu_phys_fb_addr": 0x1011,
"si_gpu_phys_inst_addr": 0x1012,
"si_gpu_phys_io_addr": 0x1013,
"si_domain_bus_device_func": 0x1020,
"si_console_mem_size": 0x1031,
"si_max_user_va": 0x1032,
"si_kernel_driver_name": 0x1100,
"si_kernel_driver_version": 0x1101,
"si_kernel_driver_changelist": 0x1102,
"si_unstable_interface": 0x1110,
"sc_vbios_revision": 0x0052,
"sc_internal_client": 0x0FF0,
"sc_internal_device": 0x0FF1,
"sc_internal_subdevice": 0x0FF2,
"sc_fb_length": 0x1010,
"sc_bar1_pde_base": 0x1020,
"sc_bar2_pde_base": 0x1021,
"sc_vmmu_segment_size": 0x1050,
"sc_wpr_non_wpr_heap_offset": 0x1080,
"sc_wpr_frts_offset": 0x1081,
"sc_gpu_name_string": 0x2000,
"sc_gpu_short_name_string": 0x2001,
"sizeof_wpr_meta": 256,
"wpr_magic": 0xDC3AAE21371A60B3,
"wpr_revision": 1,
"wpr_verified": 0xA0A0A0A0A0A0A0A0,
"offsetof_paging_config": 0xF2,
"wpr_off_magic": 0x00,
"wpr_off_revision": 0x08,
"wpr_off_radix3_addr": 0x10,
"wpr_off_radix3_size": 0x18,
"wpr_off_bootloader_addr": 0x20,
"wpr_off_bootloader_size": 0x28,
"wpr_off_bl_code": 0x30,
"wpr_off_bl_data": 0x38,
"wpr_off_bl_manifest": 0x40,
"wpr_off_sig_addr": 0x48,
"wpr_off_sig_size": 0x50,
"wpr_off_rsvd_start": 0x58,
"wpr_off_nonwpr_off": 0x60,
"wpr_off_nonwpr_size": 0x68,
"wpr_off_wpr_start": 0x70,
"wpr_off_heap_off": 0x78,
"wpr_off_heap_size": 0x80,
"wpr_off_fw_off": 0x88,
"wpr_off_bootbin": 0x90,
"wpr_off_frts_off": 0x98,
"wpr_off_frts_size": 0xA0,
"wpr_off_wpr_end": 0xA8,
"wpr_off_fb_size": 0xB0,
"wpr_off_vga_off": 0xB8,
"wpr_off_vga_size": 0xC0,
"wpr_off_boot_count": 0xC8,
"wpr_off_crash_addr": 0xE0,
"wpr_off_crash_size": 0xE8,
"wpr_off_vf_partitions": 0xF0,
"wpr_off_flags": 0xF1,
"wpr_off_pmu_reserved": 0xF4,
"wpr_off_verified": 0xF8,
"wpr_flag_nvle": 8,
"rpc_num_functions": 233,
"rpc_num_events": 0x102E,
"rpc_bind_bar2": 0x1024,
"rpc_send_guest_stun": 232,
"rpc_gsp_static_info": 0x41,
"rpc_gsp_set_system_info": 0x48,
"rpc_set_registry": 0x49,
"rpc_gsp_init_post_objgpu": 0x4A,
"rpc_init_gsp_trace_crash_buffer": 228,
"rpc_ctrl_gpu_set_migration_block": 229,
"rpc_ctrl_fifo_vgpu_swrunlist_submit": 230,
"rpc_ctrl_fifo_vgpu_swrunlist_channel_update": 231,
}
def main() -> int:
root = Path(OPEN_GPU_ROOT).resolve()
includes = (
root / "src/nvidia/arch/nvalloc/common/inc",
root / "src/nvidia/inc/kernel",
root / "src/nvidia/interface",
)
report = {
"name": "gsp_620_70_06_c_header_parity",
"source_tree": str(root),
"source_version": None,
"header_sha256": {},
}
def unavailable(reason):
print(json.dumps({**report, "status": "skipped", "passed": False, "error": reason}))
return 2
def failed(reason, **details):
print(json.dumps({**report, "status": "failed", "passed": False, "error": reason, **details}))
return 1
try:
version = re.search(
r"^[ \t]*NVIDIA_VERSION[ \t]*:?=[ \t]*([0-9]+(?:\.[0-9]+)+)[ \t]*(?:#.*)?$",
(root / "version.mk").read_text(encoding="utf-8"),
re.MULTILINE,
)
if version is None:
return unavailable("version.mk has no NVIDIA_VERSION")
report["source_version"] = version.group(1)
if report["source_version"] not in EXPECTED_SOURCE_VERSIONS:
return unavailable(
f"expected NVIDIA_VERSION {' or '.join(EXPECTED_SOURCE_VERSIONS)}, "
f"found {report['source_version']}"
)
# Resolve the probe's quoted includes in the same order as gcc.
for name in re.findall(r'^#include "([^"]+)"', C_PROBE, re.MULTILINE):
header = next((directory / name for directory in includes
if (directory / name).is_file()), None)
if header is None:
return unavailable(f"missing probe header {name}")
report["header_sha256"][str(header.relative_to(root))] = hashlib.sha256(
header.read_bytes()
).hexdigest()
except (OSError, UnicodeError) as exc:
return unavailable(f"cannot read source tree: {exc}")
with tempfile.TemporaryDirectory() as td:
src = os.path.join(td, "probe.c")
exe = os.path.join(td, "probe")
with open(src, "w", encoding="utf-8") as f:
f.write(C_PROBE)
cmd = [
"gcc",
"-O2",
*(f"-I{directory}" for directory in includes),
src,
"-o",
exe,
]
try:
res = subprocess.run(cmd, capture_output=True, text=True)
except (OSError, UnicodeError) as exc:
return failed(f"cannot run C compiler: {exc}")
if res.returncode != 0:
return failed("C probe failed to compile", gcc_stderr=res.stderr)
try:
c_vals = json.loads(subprocess.check_output([exe], text=True))
except (OSError, ValueError, subprocess.CalledProcessError) as exc:
return failed(f"cannot read C probe result: {exc}")
if not isinstance(c_vals, dict):
return failed("C probe result is not a JSON object")
diffs = []
for k, want in EXPECTED_RUST.items():
got = c_vals.get(k)
if got != want:
diffs.append({"field": k, "rust": want, "c_620": got})
result = {
**report,
"status": "failed" if diffs else "passed",
"passed": len(diffs) == 0,
"checked_fields": len(EXPECTED_RUST),
"diffs": diffs,
}
print(json.dumps(result, indent=2))
return 0 if not diffs else 1
if __name__ == "__main__":
sys.exit(main())