blob: 7913b9a9e067e67adfd004b35ffa20e4e9c5b9c8 [file] [log] [blame]
Lawrence Tangde9707f2022-07-19 10:54:31 +01001/**
Lawrence Tangefe17e22022-08-08 09:16:23 +01002 * Functions for generating pseudo-random CPER PCI component error sections.
Lawrence Tangde9707f2022-07-19 10:54:31 +01003 *
4 * Author: Lawrence.Tang@arm.com
5 **/
6
7#include <stdlib.h>
8#include "../../edk/BaseTypes.h"
9#include "../gen-utils.h"
10#include "gen-sections.h"
11
Lawrence Tangefe17e22022-08-08 09:16:23 +010012//Generates a single pseudo-random PCI component error section, saving the resulting address to the given
Lawrence Tangde9707f2022-07-19 10:54:31 +010013//location. Returns the size of the newly created section.
14size_t generate_section_pci_dev(void** location)
15{
16 //Generate how many register pairs will be attached to this section.
17 UINT32 num_memory_pairs = rand() % 4;
18 UINT32 num_io_pairs = rand() % 4;
19 UINT32 num_registers = num_memory_pairs + num_io_pairs;
20
21 //Create random bytes.
22 int size = 40 + (num_registers * 16);
23 UINT8* bytes = generate_random_bytes(size);
24
25 //Set reserved areas to zero.
26 UINT64* validation = (UINT64*)bytes;
27 *validation &= 0b11111; //Validation 5-63
28 for (int i=0; i<5; i++)
29 *(bytes + 27 + i) = 0; //Bytes 11-15 of ID info.
Lawrence Tangd34f2b12022-07-19 15:36:31 +010030
31 //Set expected values.
32 UINT32* memory_number_field = (UINT32*)(bytes + 32);
33 UINT32* io_number_field = (UINT32*)(bytes + 36);
34 *memory_number_field = num_memory_pairs;
35 *io_number_field = num_io_pairs;
Lawrence Tangde9707f2022-07-19 10:54:31 +010036
37 //Fix error status.
38 create_valid_error_section(bytes + 8);
39
40 //Set return values, exit.
41 *location = bytes;
42 return size;
43}