1 /**
2 * Functions for generating pseudo-random CPER NVIDIA error sections.
3 *
4 **/
5
6 #include <stdlib.h>
7 #include <stddef.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <libcper/BaseTypes.h>
11 #include <libcper/generator/gen-utils.h>
12 #include <libcper/generator/sections/gen-section.h>
13
14 //Generates a single pseudo-random NVIDIA error section, saving the resulting address to the given
15 //location. Returns the size of the newly created section.
generate_section_nvidia(void ** location,GEN_VALID_BITS_TEST_TYPE validBitsType)16 size_t generate_section_nvidia(void **location,
17 GEN_VALID_BITS_TEST_TYPE validBitsType)
18 {
19 (void)validBitsType;
20 const char *signatures[] = {
21 "DCC-ECC", "DCC-COH", "HSS-BUSY", "HSS-IDLE",
22 "CLink", "C2C", "C2C-IP-FAIL", "L0 RESET",
23 "L1 RESET", "L2 RESET", "PCIe", "PCIe-DPC",
24 "SOCHUB", "CCPLEXSCF", "CMET-NULL", "CMET-SHA256",
25 "CMET-FULL", "DRAM-CHANNELS", "PAGES-RETIRED", "CCPLEXGIC",
26 "MCF", "GPU-STATUS", "GPU-CONTNMT", "SMMU",
27 "CMET-INFO",
28 };
29
30 //Create random bytes.
31 int numRegs = 6;
32 size_t size = offsetof(EFI_NVIDIA_ERROR_DATA, Register) +
33 numRegs * sizeof(EFI_NVIDIA_REGISTER_DATA);
34 UINT8 *section = generate_random_bytes(size);
35
36 //Reserved byte.
37 EFI_NVIDIA_ERROR_DATA *nvidia_error = (EFI_NVIDIA_ERROR_DATA *)section;
38 nvidia_error->Reserved = 0;
39
40 //Number of Registers.
41 nvidia_error->NumberRegs = numRegs;
42
43 //Severity (0 to 3 as defined in UEFI spec).
44 nvidia_error->Severity %= 4;
45
46 //Signature.
47 int idx_random =
48 cper_rand() % (sizeof(signatures) / sizeof(signatures[0]));
49 strncpy(nvidia_error->Signature, signatures[idx_random],
50 sizeof(nvidia_error->Signature) - 1);
51 nvidia_error->Signature[sizeof(nvidia_error->Signature) - 1] = '\0';
52
53 //Set return values, exit.
54 *location = section;
55 return size;
56 }
57