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. |
Ed Tanous | fedd457 | 2024-07-12 13:56:00 -0700 | [diff] [blame] | 3 | * |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include <stdlib.h> |
Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 8 | #include <libcper/BaseTypes.h> |
| 9 | #include <libcper/generator/gen-utils.h> |
| 10 | #include <libcper/generator/sections/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. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 14 | size_t generate_section_pci_bus(void **location, |
| 15 | GEN_VALID_BITS_TEST_TYPE validBitsType) |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 16 | { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 17 | //Create random bytes. |
| 18 | int size = 72; |
| 19 | UINT8 *bytes = generate_random_bytes(size); |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 20 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 21 | //Set reserved areas to zero. |
| 22 | UINT64 *validation = (UINT64 *)bytes; |
| 23 | *validation &= 0x1FF; //Validation 9-63 |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 24 | if (validBitsType == ALL_VALID) { |
| 25 | *validation = 0x1FF; |
| 26 | } else if (validBitsType == SOME_VALID) { |
| 27 | *validation = 0x155; |
| 28 | } |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 29 | UINT32 *reserved = (UINT32 *)(bytes + 20); |
| 30 | *reserved = 0; |
| 31 | UINT64 *bus_command = (UINT64 *)(bytes + 40); |
| 32 | *bus_command &= ((UINT64)0x1 << 56); //Bus command bytes bar bit 56. |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 33 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 34 | //Fix values that could be above range. |
| 35 | UINT16 *error_type = (UINT16 *)(bytes + 16); |
Ed Tanous | 2d4d3b6 | 2025-03-11 10:34:29 -0700 | [diff] [blame^] | 36 | *error_type = cper_rand() % 8; |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 37 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 38 | //Fix error status. |
| 39 | create_valid_error_section(bytes + 8); |
| 40 | |
| 41 | //Set return values, exit. |
| 42 | *location = bytes; |
| 43 | return size; |
| 44 | } |