blob: a06f545d6127d1d6d28464589ac771494b7ec8c3 [file] [log] [blame]
Karthik Rajagopalan683e0552024-03-07 12:30:43 -08001/**
2 * Functions for generating pseudo-random CPER NVIDIA error sections.
3 *
4 **/
5
6#include <stdlib.h>
Ed Tanous2d17ace2024-08-27 14:45:38 -07007#include <stddef.h>
Karthik Rajagopalan683e0552024-03-07 12:30:43 -08008#include <string.h>
9#include <stdio.h>
Thu Nguyene42fb482024-10-15 14:43:11 +000010#include <libcper/BaseTypes.h>
11#include <libcper/generator/gen-utils.h>
12#include <libcper/generator/sections/gen-section.h>
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080013
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.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080016size_t generate_section_nvidia(void **location,
17 GEN_VALID_BITS_TEST_TYPE validBitsType)
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080018{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080019 (void)validBitsType;
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080020 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 };
28
29 init_random();
30
31 //Create random bytes.
Ed Tanous2d17ace2024-08-27 14:45:38 -070032 int numRegs = 6;
33 size_t size = offsetof(EFI_NVIDIA_ERROR_DATA, Register) +
34 numRegs * sizeof(EFI_NVIDIA_REGISTER_DATA);
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080035 UINT8 *section = generate_random_bytes(size);
36
37 //Reserved byte.
38 EFI_NVIDIA_ERROR_DATA *nvidia_error = (EFI_NVIDIA_ERROR_DATA *)section;
39 nvidia_error->Reserved = 0;
40
Ed Tanous2d17ace2024-08-27 14:45:38 -070041 //Number of Registers.
42 nvidia_error->NumberRegs = numRegs;
43
44 //Severity (0 to 3 as defined in UEFI spec).
45 nvidia_error->Severity %= 4;
46
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080047 //Signature.
48 int idx_random = rand() % (sizeof(signatures) / sizeof(signatures[0]));
49 strncpy(nvidia_error->Signature, signatures[idx_random],
Patrick Williams379e4922024-08-28 11:14:34 -040050 sizeof(nvidia_error->Signature) - 1);
51 nvidia_error->Signature[sizeof(nvidia_error->Signature) - 1] = '\0';
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080052
53 //Set return values, exit.
54 *location = section;
55 return size;
56}