Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 1 | /** |
Lawrence Tang | efe17e2 | 2022-08-08 09:16:23 +0100 | [diff] [blame] | 2 | * Functions for generating pseudo-random CPER PCI/PCI-X bus error sections. |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 3 | * |
| 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include <stdlib.h> |
| 8 | #include "../../edk/BaseTypes.h" |
| 9 | #include "../gen-utils.h" |
Lawrence Tang | 8f97745 | 2022-08-24 14:55:07 +0100 | [diff] [blame^] | 10 | #include "gen-section.h" |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 11 | |
Lawrence Tang | efe17e2 | 2022-08-08 09:16:23 +0100 | [diff] [blame] | 12 | //Generates a single pseudo-random PCI/PCI-X bus error section, saving the resulting address to the given |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 13 | //location. Returns the size of the newly created section. |
| 14 | size_t generate_section_pci_bus(void** location) |
| 15 | { |
| 16 | //Create random bytes. |
Lawrence Tang | 0a4b3f2 | 2022-07-21 10:40:10 +0100 | [diff] [blame] | 17 | int size = 72; |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 18 | UINT8* bytes = generate_random_bytes(size); |
| 19 | |
| 20 | //Set reserved areas to zero. |
| 21 | UINT64* validation = (UINT64*)bytes; |
| 22 | *validation &= 0x1FF; //Validation 9-63 |
| 23 | UINT32* reserved = (UINT32*)(bytes + 20); |
| 24 | *reserved = 0; |
| 25 | UINT64* bus_command = (UINT64*)(bytes + 40); |
Lawrence Tang | 5f388a3 | 2022-08-08 10:49:02 +0100 | [diff] [blame] | 26 | *bus_command &= ((UINT64)0b1 << 56); //Bus command bytes bar bit 56. |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 27 | |
| 28 | //Fix values that could be above range. |
| 29 | UINT16* error_type = (UINT16*)(bytes + 16); |
| 30 | *error_type = rand() % 8; |
| 31 | |
| 32 | //Fix error status. |
| 33 | create_valid_error_section(bytes + 8); |
| 34 | |
| 35 | //Set return values, exit. |
| 36 | *location = bytes; |
| 37 | return size; |
| 38 | } |