aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / tests / test_gb10_gsp_nvhdr.c
| 1 | /* test_gb10_gsp_nvhdr -- compares the builder's mirror structs (dev/gb10_gsp_boot.h) with the |
| 2 | * NVIDIA headers themselves, field by field, and decodes a built plan through the NVIDIA types. |
| 3 | * Needs open-gpu-kernel-modules at tag 580.173.02 (MIT) on the include path: the Makefile target |
| 4 | * gb10-gsp-nvhdr-test passes OGKM_DIR (default ~/workspace/_ext/open-gpu-kernel-modules-580.173.02) |
| 5 | * and fails, never skips, when the tree is missing. Host only; nothing NVIDIA is linked or shipped. |
| 6 | * |
| 7 | * Covered from the real headers: GspFwWprMeta, LibosMemoryRegionInitArgument, |
| 8 | * GSP_ARGUMENTS_CACHED (+ MESSAGE_QUEUE_INIT_ARGUMENTS, GSP_SR_INIT_ARGUMENTS), msgqTxHeader, |
| 9 | * msgqRxHeader, rpc_message_header_v03_00, rpc_gsp_rm_alloc_v03_00, rpc_gsp_rm_control_v03_00, |
| 10 | * rpc_free_v03_00, GSP_FMC_BOOT_PARAMS, NVDM_PAYLOAD_COT, the function and event numbers. |
| 11 | * GSP_MSG_QUEUE_ELEMENT (message_queue_priv.h) pulls RM-internal headers (nvassert.h needs an |
| 12 | * NV_PORT_HEADER); its five fields are re-declared here verbatim around NVIDIA's own |
| 13 | * rpc_message_header_v. PACKED_REGISTRY_TABLE (g_os_nvoc.h) and GspSystemInfo / |
| 14 | * GspStaticConfigInfo (gsp_static_config.h) are in the same position and stay checked by the |
| 15 | * hosted tool ck_gsp_rpc_encode (inventory section 13). */ |
| 16 | #include <stddef.h> |
| 17 | #include <stdint.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include "nvtypes.h" |
| 21 | #include "nvstatus.h" |
| 22 | #include "gsp/gsp_fw_wpr_meta.h" |
| 23 | #include "libos_init_args.h" |
| 24 | #include "gpu/gsp/gsp_init_args.h" |
| 25 | #include "msgq/msgq_priv.h" |
| 26 | #include "gsp/gspifpub.h" |
| 27 | #include "fsp/fsp_nvdm_format.h" |
| 28 | #include "gpu/fsp/kern_fsp_cot_payload.h" |
| 29 | #include "vgpu/rpc_headers.h" |
| 30 | #define RPC_STRUCTURES |
| 31 | #define RPC_GENERIC_UNION |
| 32 | #include "g_rpc-structures.h" |
| 33 | #define RPC_MESSAGE_STRUCTURES |
| 34 | #include "g_rpc-message-header.h" |
| 35 | #include "ck_test.h" |
| 36 | #include "gb10_gsp_boot.h" |
| 37 | |
| 38 | typedef struct { /* message_queue_priv.h:43-51, verbatim fields */ |
| 39 | NvU8 authTagBuffer[16]; |
| 40 | NvU8 aadBuffer[16]; |
| 41 | NvU32 checkSum; |
| 42 | NvU32 seqNum; |
| 43 | NvU32 elemCount; |
| 44 | NV_DECLARE_ALIGNED(rpc_message_header_v rpc, 8); |
| 45 | } NV_GSP_MSG_QUEUE_ELEMENT; |
| 46 | |
| 47 | #define SAME(M, N, fm, fn) CHECK(offsetof(M, fm) == offsetof(N, fn) && sizeof(((M *)0)->fm) == sizeof(((N *)0)->fn)) |
| 48 | |
| 49 | static void test_layouts(void) |
| 50 | { |
| 51 | CHECK(sizeof(gsp_mirror_wpr_meta) == sizeof(GspFwWprMeta)); |
| 52 | #define W(f) SAME(gsp_mirror_wpr_meta, GspFwWprMeta, f, f) |
| 53 | W(magic); W(revision); W(sysmemAddrOfRadix3Elf); W(sizeOfRadix3Elf); W(sysmemAddrOfBootloader); W(sizeOfBootloader); |
| 54 | W(bootloaderCodeOffset); W(bootloaderDataOffset); W(bootloaderManifestOffset); W(sysmemAddrOfSignature); W(sizeOfSignature); |
| 55 | W(gspFwRsvdStart); W(nonWprHeapOffset); W(nonWprHeapSize); W(gspFwWprStart); W(gspFwHeapOffset); W(gspFwHeapSize); |
| 56 | W(gspFwOffset); W(bootBinOffset); W(frtsOffset); W(frtsSize); W(gspFwWprEnd); W(fbSize); W(vgaWorkspaceOffset); |
| 57 | W(vgaWorkspaceSize); W(bootCount); W(partitionRpcAddr); W(partitionRpcRequestOffset); W(partitionRpcReplyOffset); |
| 58 | W(elfCodeOffset); W(elfDataOffset); W(elfCodeSize); W(elfDataSize); W(lsUcodeVersion); W(gspFwHeapVfPartitionCount); |
| 59 | W(flags); W(padding); W(pmuReservedSize); W(verified); |
| 60 | CHECK(GSP_WPR_META_MAGIC == GSP_FW_WPR_META_MAGIC && GSP_WPR_META_REVISION == GSP_FW_WPR_META_REVISION); |
| 61 | |
| 62 | CHECK(sizeof(gsp_mirror_libos_arg) == sizeof(LibosMemoryRegionInitArgument)); |
| 63 | #define L(f) SAME(gsp_mirror_libos_arg, LibosMemoryRegionInitArgument, f, f) |
| 64 | L(id8); L(pa); L(size); L(kind); L(loc); |
| 65 | CHECK(GSP_LIBOS_KIND_CONTIGUOUS == LIBOS_MEMORY_REGION_CONTIGUOUS && GSP_LIBOS_LOC_SYSMEM == LIBOS_MEMORY_REGION_LOC_SYSMEM); |
| 66 | |
| 67 | CHECK(sizeof(gsp_mirror_args_cached) == sizeof(GSP_ARGUMENTS_CACHED)); |
| 68 | #define A(fm, fn) SAME(gsp_mirror_args_cached, GSP_ARGUMENTS_CACHED, fm, fn) |
| 69 | A(mq.sharedMemPhysAddr, messageQueueInitArguments.sharedMemPhysAddr); |
| 70 | A(mq.pageTableEntryCount, messageQueueInitArguments.pageTableEntryCount); |
| 71 | A(mq.cmdQueueOffset, messageQueueInitArguments.cmdQueueOffset); |
| 72 | A(mq.statQueueOffset, messageQueueInitArguments.statQueueOffset); |
| 73 | A(sr.oldLevel, srInitArguments.oldLevel); A(sr.flags, srInitArguments.flags); |
| 74 | A(sr.bInPMTransition, srInitArguments.bInPMTransition); |
| 75 | A(gpuInstance, gpuInstance); A(bDmemStack, bDmemStack); |
| 76 | A(profilerArgs.pa, profilerArgs.pa); A(profilerArgs.size, profilerArgs.size); |
| 77 | A(sysmemHeapArgs.pa, sysmemHeapArgs.pa); A(sysmemHeapArgs.size, sysmemHeapArgs.size); |
| 78 | |
| 79 | CHECK(sizeof(gsp_mirror_msgq_tx) == sizeof(msgqTxHeader) && sizeof(msgqRxHeader) == 4); |
| 80 | #define T(f) SAME(gsp_mirror_msgq_tx, msgqTxHeader, f, f) |
| 81 | T(version); T(size); T(msgSize); T(msgCount); T(writePtr); T(flags); T(rxHdrOff); T(entryOff); |
| 82 | CHECK(GSP_MQ_FLAGS_SWAP_RX == MSGQ_FLAGS_SWAP_RX && MSGQ_VERSION == 0); |
| 83 | |
| 84 | CHECK(sizeof(gsp_mirror_rpc_hdr) == sizeof(rpc_message_header_v03_00)); |
| 85 | #define R(f) SAME(gsp_mirror_rpc_hdr, rpc_message_header_v03_00, f, f) |
| 86 | R(header_version); R(signature); R(length); R(function); R(rpc_result); R(rpc_result_private); R(sequence); |
| 87 | SAME(gsp_mirror_rpc_hdr, rpc_message_header_v03_00, cpuRmGfid, u.cpuRmGfid); |
| 88 | CHECK(GSP_RPC_SIGNATURE == NV_VGPU_MSG_SIGNATURE_VALID && GSP_RPC_PENDING == NV_VGPU_MSG_RESULT_RPC_PENDING); |
| 89 | CHECK(GSP_RPC_HEADER_VERSION == ((NV_VGPU_MSG_HEADER_VERSION_MAJOR_TOT << 24) | (NV_VGPU_MSG_HEADER_VERSION_MINOR_TOT << 16))); |
| 90 | |
| 91 | CHECK(sizeof(gsp_mirror_elem) == sizeof(NV_GSP_MSG_QUEUE_ELEMENT)); |
| 92 | SAME(gsp_mirror_elem, NV_GSP_MSG_QUEUE_ELEMENT, checkSum, checkSum); |
| 93 | SAME(gsp_mirror_elem, NV_GSP_MSG_QUEUE_ELEMENT, seqNum, seqNum); |
| 94 | SAME(gsp_mirror_elem, NV_GSP_MSG_QUEUE_ELEMENT, elemCount, elemCount); |
| 95 | SAME(gsp_mirror_elem, NV_GSP_MSG_QUEUE_ELEMENT, rpc, rpc); |
| 96 | |
| 97 | #define RA(f) SAME(gsp_mirror_rm_alloc, rpc_gsp_rm_alloc_v03_00, f, f) |
| 98 | RA(hClient); RA(hParent); RA(hObject); RA(hClass); RA(status); RA(paramsSize); RA(flags); RA(reserved); |
| 99 | CHECK(offsetof(rpc_gsp_rm_alloc_v03_00, params) == GSP_RM_ALLOC_FIXED); |
| 100 | #define RC(f) SAME(gsp_mirror_rm_control, rpc_gsp_rm_control_v03_00, f, f) |
| 101 | RC(hClient); RC(hObject); RC(cmd); RC(status); RC(paramsSize); RC(rmapiRpcFlags); RC(rmctrlFlags); |
| 102 | RC(rmctrlAccessRight); RC(reserved0); |
| 103 | CHECK(offsetof(rpc_gsp_rm_control_v03_00, params) == GSP_RM_CONTROL_FIXED); |
| 104 | CHECK(sizeof(rpc_free_v03_00) == GSP_RM_FREE_SIZE); |
| 105 | #define RF(f) SAME(gsp_mirror_rm_free, NVOS00_PARAMETERS_v03_00, f, f) |
| 106 | RF(hRoot); RF(hObjectParent); RF(hObjectOld); RF(status); |
| 107 | |
| 108 | CHECK(GSP_FN_FREE == NV_VGPU_MSG_FUNCTION_FREE && GSP_FN_GET_GSP_STATIC_INFO == NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO && |
| 109 | GSP_FN_CONTINUATION == NV_VGPU_MSG_FUNCTION_CONTINUATION_RECORD && GSP_FN_SET_SYSTEM_INFO == NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO && |
| 110 | GSP_FN_SET_REGISTRY == NV_VGPU_MSG_FUNCTION_SET_REGISTRY && GSP_FN_GSP_RM_CONTROL == NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL && |
| 111 | GSP_FN_GSP_RM_ALLOC == NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC); |
| 112 | CHECK(GSP_EV_INIT_DONE == NV_VGPU_MSG_EVENT_GSP_INIT_DONE && GSP_EV_RUN_CPU_SEQUENCER == NV_VGPU_MSG_EVENT_GSP_RUN_CPU_SEQUENCER); |
| 113 | |
| 114 | CHECK(sizeof(gsp_mirror_fmc_params) == sizeof(GSP_FMC_BOOT_PARAMS)); |
| 115 | #define F(fm, fn) SAME(gsp_mirror_fmc_params, GSP_FMC_BOOT_PARAMS, fm, fn) |
| 116 | F(regkeys, initParams.regkeys); |
| 117 | F(boot.target, bootGspRmParams.target); F(boot.gspRmDescSize, bootGspRmParams.gspRmDescSize); |
| 118 | F(boot.gspRmDescOffset, bootGspRmParams.gspRmDescOffset); F(boot.wprCarveoutOffset, bootGspRmParams.wprCarveoutOffset); |
| 119 | F(boot.wprCarveoutSize, bootGspRmParams.wprCarveoutSize); F(boot.bIsGspRmBoot, bootGspRmParams.bIsGspRmBoot); |
| 120 | F(rm.target, gspRmParams.target); F(rm.bootArgsOffset, gspRmParams.bootArgsOffset); |
| 121 | F(spdm.target, gspSpdmParams.target); F(spdm.payloadBufferOffset, gspSpdmParams.payloadBufferOffset); |
| 122 | F(spdm.payloadBufferSize, gspSpdmParams.payloadBufferSize); |
| 123 | F(mem.flushSysmemAddrValLo, gspRmMemParams.flushSysmemAddrValLo); |
| 124 | F(mem.flushSysmemAddrValHi, gspRmMemParams.flushSysmemAddrValHi); |
| 125 | CHECK(GSP_DMA_TARGET_COHERENT == GSP_DMA_TARGET_COHERENT_SYSTEM && GSP_DMA_TARGET_NONCOHERENT == GSP_DMA_TARGET_NONCOHERENT_SYSTEM); |
| 126 | |
| 127 | CHECK(sizeof(gsp_mirror_cot) == sizeof(NVDM_PAYLOAD_COT)); |
| 128 | #define C(f) SAME(gsp_mirror_cot, NVDM_PAYLOAD_COT, f, f) |
| 129 | C(version); C(size); C(gspFmcSysmemOffset); C(frtsSysmemOffset); C(frtsSysmemSize); C(frtsVidmemOffset); |
| 130 | C(frtsVidmemSize); C(hash384); C(publicKey); C(signature); C(gspBootArgsSysmemOffset); |
| 131 | CHECK(NVDM_TYPE_COT == 0x14); |
| 132 | } |
| 133 | |
| 134 | /* Build a plan with synthetic bytes and read it back through the NVIDIA types. */ |
| 135 | static void test_decode(void) |
| 136 | { |
| 137 | enum { CAP = 4u << 20, ELF = 300000 }; |
| 138 | uint8_t *mem = aligned_alloc(4096, CAP), *elf = calloc(1, ELF), *bl = calloc(1, GSP_GB10B_BOOTLOADER_SIZE); |
| 139 | static uint8_t sig[512], fmc[9000], h[48], k[384], s[384], si[GSP_SYSTEM_INFO_SIZE]; |
| 140 | gsp_boot_in in = { .rm_elf = elf, .rm_elf_size = ELF, .rm_sig = sig, .rm_sig_size = 300, |
| 141 | .bootloader = bl, .bootloader_size = GSP_GB10B_BOOTLOADER_SIZE, .bl_code_off = 0xb000, .bl_data_off = 0xa00, |
| 142 | .fmc = fmc, .fmc_size = sizeof fmc, .fmc_hash = h, .fmc_pubkey = k, .fmc_sig = s, |
| 143 | .sysmem_heap_pa = 0x40000000ULL, .sysmem_heap_size = 512u << 20, .system_info = si, .dma_bits = 41 }; |
| 144 | gsp_arena a; gsp_boot_plan p; const char *why = 0; |
| 145 | CHECK(gsp_arena_init(&a, mem, 0x10000000ULL, CAP) == 0 && gsp_boot_build(&a, &in, &p, &why) == 0); |
| 146 | #define AT(pa) (mem + ((pa) - 0x10000000ULL)) |
| 147 | GspFwWprMeta w; memcpy(&w, AT(p.wpr_meta.pa), sizeof w); |
| 148 | CHECK(w.magic == GSP_FW_WPR_META_MAGIC && w.revision == GSP_FW_WPR_META_REVISION); |
| 149 | CHECK(w.sysmemAddrOfRadix3Elf == p.radix3_root_pa && w.sizeOfRadix3Elf == ELF); |
| 150 | CHECK(w.sysmemAddrOfBootloader == p.bootloader.pa && w.sizeOfBootloader == GSP_GB10B_BOOTLOADER_SIZE); |
| 151 | CHECK(w.sysmemAddrOfSignature == p.signature.pa && w.sizeOfSignature == 512 && w.gspFwHeapSize == (133ULL << 20)); |
| 152 | CHECK(w.frtsSize == 0 && w.nonWprHeapSize == 0 && w.vgaWorkspaceSize == 0 && w.pmuReservedSize == 0 && w.verified == 0); |
| 153 | LibosMemoryRegionInitArgument la[8]; memcpy(la, AT(p.libos_args.pa), sizeof la); |
| 154 | CHECK(la[7].pa == p.args_cached.pa && la[7].size == 4096 && la[7].kind == LIBOS_MEMORY_REGION_CONTIGUOUS); |
| 155 | CHECK(la[5].size == 0x1000 && la[0].loc == LIBOS_MEMORY_REGION_LOC_SYSMEM); |
| 156 | GSP_ARGUMENTS_CACHED g; memcpy(&g, AT(p.args_cached.pa), sizeof g); |
| 157 | CHECK(g.messageQueueInitArguments.sharedMemPhysAddr == p.rpc_shared.pa && g.messageQueueInitArguments.pageTableEntryCount == 129); |
| 158 | CHECK(g.messageQueueInitArguments.cmdQueueOffset == 4096 && g.messageQueueInitArguments.statQueueOffset == 4096 + 0x40000); |
| 159 | CHECK(g.bDmemStack == NV_TRUE && g.sysmemHeapArgs.pa == 0x40000000ULL && g.sysmemHeapArgs.size == (512ULL << 20)); |
| 160 | msgqTxHeader tx; memcpy(&tx, AT(p.cmdq_pa), sizeof tx); |
| 161 | CHECK(tx.version == 0 && tx.size == 0x40000 && tx.msgSize == 4096 && tx.msgCount == 63 && tx.writePtr == 1); |
| 162 | CHECK(tx.flags == MSGQ_FLAGS_SWAP_RX && tx.rxHdrOff == 32 && tx.entryOff == 4096); |
| 163 | NV_GSP_MSG_QUEUE_ELEMENT el; memcpy(&el, AT(p.cmdq_pa) + 4096, sizeof el); |
| 164 | CHECK(el.seqNum == 0 && el.elemCount == 1 && el.rpc.function == NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO); |
| 165 | CHECK(el.rpc.length == sizeof(rpc_message_header_v) + GSP_SYSTEM_INFO_SIZE && el.rpc.signature == NV_VGPU_MSG_SIGNATURE_VALID); |
| 166 | GSP_FMC_BOOT_PARAMS f; memcpy(&f, AT(p.fmc_params.pa), sizeof f); |
| 167 | CHECK(f.bootGspRmParams.target == GSP_DMA_TARGET_COHERENT_SYSTEM && f.bootGspRmParams.gspRmDescSize == sizeof(GspFwWprMeta)); |
| 168 | CHECK(f.bootGspRmParams.gspRmDescOffset == p.wpr_meta.pa && f.bootGspRmParams.bIsGspRmBoot == NV_TRUE); |
| 169 | CHECK(f.gspRmParams.target == GSP_DMA_TARGET_NONCOHERENT_SYSTEM && f.gspRmParams.bootArgsOffset == p.libos_args.pa); |
| 170 | NVDM_PAYLOAD_COT c; memcpy(&c, p.cot_packet + 8, sizeof c); |
| 171 | CHECK(c.version == 1 && c.size == sizeof(NVDM_PAYLOAD_COT) && c.gspFmcSysmemOffset == p.fmc.pa); |
| 172 | CHECK(c.frtsSysmemSize == sizeof fmc && c.gspBootArgsSysmemOffset == p.fmc_params.pa); |
| 173 | |
| 174 | gsp_mq q; |
| 175 | CHECK(gsp_mq_attach(&q, &a, &p) == 0); |
| 176 | uint32_t prm[4] = {1, 2, 3, 4}, seq; |
| 177 | CHECK(gsp_rpc_rm_alloc(&q, 0xc1d00001, 0xc1d00001, 0xcaf00010, 0x0080, prm, sizeof prm, &seq, &why) == 0); |
| 178 | uint8_t raw[4096]; memcpy(raw, AT(p.cmdq_pa) + 4096 + 4096, sizeof raw); |
| 179 | NV_GSP_MSG_QUEUE_ELEMENT *e = (NV_GSP_MSG_QUEUE_ELEMENT *)raw; |
| 180 | rpc_gsp_rm_alloc_v03_00 *ra = (rpc_gsp_rm_alloc_v03_00 *)(raw + sizeof *e); |
| 181 | CHECK(e->rpc.function == NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC && e->rpc.length == sizeof(rpc_message_header_v) + sizeof(rpc_gsp_rm_alloc_v03_00)); |
| 182 | CHECK(ra->hObject == 0xcaf00010 && ra->hClass == 0x0080 && ra->paramsSize == sizeof prm && ra->flags == 0 && |
| 183 | memcmp(ra->params, prm, sizeof prm) == 0); |
| 184 | free(mem); free(elf); free(bl); |
| 185 | } |
| 186 | |
| 187 | int main(void) |
| 188 | { |
| 189 | test_layouts(); |
| 190 | test_decode(); |
| 191 | return ck_t_verdict("test_gb10_gsp_nvhdr"); |
| 192 | } |