1 /** 2 * Functions for generating pseudo-random CPER PCI/PCI-X bus error sections. 3 * 4 * Author: Lawrence.Tang@arm.com 5 **/ 6 7 #include <stdlib.h> 8 #include <libcper/BaseTypes.h> 9 #include <libcper/generator/gen-utils.h> 10 #include <libcper/generator/sections/gen-section.h> 11 12 //Generates a single pseudo-random PCI/PCI-X bus error section, saving the resulting address to the given 13 //location. Returns the size of the newly created section. generate_section_pci_bus(void ** location,GEN_VALID_BITS_TEST_TYPE validBitsType)14size_t generate_section_pci_bus(void **location, 15 GEN_VALID_BITS_TEST_TYPE validBitsType) 16 { 17 //Create random bytes. 18 int size = 72; 19 UINT8 *bytes = generate_random_bytes(size); 20 21 //Set reserved areas to zero. 22 UINT64 *validation = (UINT64 *)bytes; 23 *validation &= 0x1FF; //Validation 9-63 24 if (validBitsType == ALL_VALID) { 25 *validation = 0x1FF; 26 } else if (validBitsType == SOME_VALID) { 27 *validation = 0x155; 28 } 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. 33 34 //Fix values that could be above range. 35 UINT16 *error_type = (UINT16 *)(bytes + 16); 36 *error_type = rand() % 8; 37 38 //Fix error status. 39 create_valid_error_section(bytes + 8); 40 41 //Set return values, exit. 42 *location = bytes; 43 return size; 44 } 45