blob: 5f67c09b51da8efa318174f78a6faea02b47a534 [file] [log] [blame]
Lawrence Tangde9707f2022-07-19 10:54:31 +01001/**
2 * Functions for generating psuedo-random CPER PCIe error sections.
3 *
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
12#define PCIE_PORT_TYPES (int []){0, 1, 4, 5, 6, 7, 8, 9, 10}
13
14//Generates a single psuedo-random PCIe error section, saving the resulting address to the given
15//location. Returns the size of the newly created section.
16size_t generate_section_pcie(void** location)
17{
18 //Create random bytes.
19 int size = 208;
20 UINT8* bytes = generate_random_bytes(size);
21
22 //Set reserved areas to zero.
23 UINT64* validation = (UINT64*)bytes;
24 *validation &= 0xFF; //Validation 8-63
25 UINT32* version = (UINT32*)(bytes + 12);
26 *version &= 0xFFFF; //Version bytes 2-3
27 UINT32* reserved = (UINT32*)(bytes + 20);
28 *reserved = 0; //Reserved bytes 20-24
29 *(bytes + 39) = 0; //Device ID byte 15
30
31 //Fix values that could be above range.
32 UINT32* port_type = (UINT32*)(bytes + 8);
33 *port_type = PCIE_PORT_TYPES[rand() % (sizeof(PCIE_PORT_TYPES) / sizeof(int))];
34
35 //Set return values, exit.
36 *location = bytes;
37 return size;
38}