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