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