Karthik Rajagopalan | 683e055 | 2024-03-07 12:30:43 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Functions for generating pseudo-random CPER NVIDIA error sections. |
| 3 | * |
| 4 | **/ |
| 5 | |
| 6 | #include <stdlib.h> |
Ed Tanous | 2d17ace | 2024-08-27 14:45:38 -0700 | [diff] [blame] | 7 | #include <stddef.h> |
Karthik Rajagopalan | 683e055 | 2024-03-07 12:30:43 -0800 | [diff] [blame] | 8 | #include <string.h> |
| 9 | #include <stdio.h> |
Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 10 | #include <libcper/BaseTypes.h> |
| 11 | #include <libcper/generator/gen-utils.h> |
| 12 | #include <libcper/generator/sections/gen-section.h> |
Karthik Rajagopalan | 683e055 | 2024-03-07 12:30:43 -0800 | [diff] [blame] | 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. |
| 16 | size_t generate_section_nvidia(void **location) |
| 17 | { |
| 18 | const char *signatures[] = { |
| 19 | "DCC-ECC", "DCC-COH", "HSS-BUSY", "HSS-IDLE", |
| 20 | "CLink", "C2C", "C2C-IP-FAIL", "L0 RESET", |
| 21 | "L1 RESET", "L2 RESET", "PCIe", "PCIe-DPC", |
| 22 | "SOCHUB", "CCPLEXSCF", "CMET-NULL", "CMET-SHA256", |
| 23 | "CMET-FULL", "DRAM-CHANNELS", "PAGES-RETIRED", "CCPLEXGIC", |
| 24 | "MCF", "GPU-STATUS", "GPU-CONTNMT", "SMMU", |
| 25 | }; |
| 26 | |
| 27 | init_random(); |
| 28 | |
| 29 | //Create random bytes. |
Ed Tanous | 2d17ace | 2024-08-27 14:45:38 -0700 | [diff] [blame] | 30 | int numRegs = 6; |
| 31 | size_t size = offsetof(EFI_NVIDIA_ERROR_DATA, Register) + |
| 32 | numRegs * sizeof(EFI_NVIDIA_REGISTER_DATA); |
Karthik Rajagopalan | 683e055 | 2024-03-07 12:30:43 -0800 | [diff] [blame] | 33 | UINT8 *section = generate_random_bytes(size); |
| 34 | |
| 35 | //Reserved byte. |
| 36 | EFI_NVIDIA_ERROR_DATA *nvidia_error = (EFI_NVIDIA_ERROR_DATA *)section; |
| 37 | nvidia_error->Reserved = 0; |
| 38 | |
Ed Tanous | 2d17ace | 2024-08-27 14:45:38 -0700 | [diff] [blame] | 39 | //Number of Registers. |
| 40 | nvidia_error->NumberRegs = numRegs; |
| 41 | |
| 42 | //Severity (0 to 3 as defined in UEFI spec). |
| 43 | nvidia_error->Severity %= 4; |
| 44 | |
Karthik Rajagopalan | 683e055 | 2024-03-07 12:30:43 -0800 | [diff] [blame] | 45 | //Signature. |
| 46 | int idx_random = rand() % (sizeof(signatures) / sizeof(signatures[0])); |
| 47 | strncpy(nvidia_error->Signature, signatures[idx_random], |
Patrick Williams | 379e492 | 2024-08-28 11:14:34 -0400 | [diff] [blame] | 48 | sizeof(nvidia_error->Signature) - 1); |
| 49 | nvidia_error->Signature[sizeof(nvidia_error->Signature) - 1] = '\0'; |
Karthik Rajagopalan | 683e055 | 2024-03-07 12:30:43 -0800 | [diff] [blame] | 50 | |
| 51 | //Set return values, exit. |
| 52 | *location = section; |
| 53 | return size; |
| 54 | } |