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[][16 + 1] = {
21 "DCC-ECC\0\0\0\0\0\0\0\0\0",
22 "DCC-COH\0\0\0\0\0\0\0\0\0",
23 "HSS-BUSY\0\0\0\0\0\0\0\0",
24 "HSS-IDLE\0\0\0\0\0\0\0\0",
25 "CLink\0\0\0\0\0\0\0\0\0\0",
26 "C2C\0\0\0\0\0\0\0\0\0\0",
27 "C2C-IP-FAIL\0\0\0\0\0",
28 "L0 RESET\0\0\0\0\0\0\0\0",
29 "L1 RESET\0\0\0\0\0\0\0\0",
30 "L2 RESET\0\0\0\0\0\0\0\0",
31 "PCIe\0\0\0\0\0\0\0\0",
32 "PCIe-DPC\0\0\0\0\0\0\0\0",
33 "SOCHUB\0\0\0\0\0\0\0\0",
34 "CCPLEXSCF\0\0\0\0\0",
35 "CMET-NULL\0\0\0\0\0",
36 "CMET-SHA256\0\0\0\0\0",
37 "CMET-FULL\0\0\0\0\0",
38 "DRAM-CHANNELS\0\0\0",
39 "PAGES-RETIRED\0\0\0",
40 "CCPLEXGIC\0\0\0\0\0",
41 "MCF\0\0\0\0\0",
42 "GPU-STATUS\0\0\0\0\0\0",
43 "GPU-CONTNMT\0\0\0\0\0",
44 "SMMU\0\0\0\0\0\0\0\0",
45 "CMET-INFO\0\0\0\0\0\0\0",
46 };
47
48 //Create random bytes.
49 int numRegs = 6;
50 size_t size = offsetof(EFI_NVIDIA_ERROR_DATA, Register) +
51 numRegs * sizeof(EFI_NVIDIA_REGISTER_DATA);
52 UINT8 *section = generate_random_bytes(size);
53
54 //Reserved byte.
55 EFI_NVIDIA_ERROR_DATA *nvidia_error = (EFI_NVIDIA_ERROR_DATA *)section;
56 nvidia_error->Reserved = 0;
57
58 //Number of Registers.
59 nvidia_error->NumberRegs = numRegs;
60
61 //Severity (0 to 3 as defined in UEFI spec).
62 nvidia_error->Severity %= 4;
63
64 //Signature.
65 int idx_random =
66 cper_rand() % (sizeof(signatures) / sizeof(signatures[0]));
67 memcpy(nvidia_error->Signature, signatures[idx_random],
68 sizeof(nvidia_error->Signature));
69
70 //Set return values, exit.
71 *location = section;
72 return size;
73 }
74