1 /**
2  * Functions for generating psuedo-random CXL component 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 //Generates a single psuedo-random CXL component error section, saving the resulting address to the given
13 //location. Returns the size of the newly created section.
14 size_t generate_section_cxl_component(void** location)
15 {
16     //Create a random length for the CXL component event log.
17     //The logs attached here do not necessarily conform to the specification, and are simply random.
18     int log_len = rand() % 64;
19 
20     //Create random bytes.
21     int size = 32 + log_len;
22     UINT8* bytes = generate_random_bytes(size);
23 
24     //Set reserved areas to zero.
25     UINT64* validation = (UINT64*)(bytes + 4);
26     *validation &= 0b111;
27     UINT16* slot_number = (UINT16*)(bytes + 21);
28     *slot_number &= ~0b111; //Device ID slot number bits 0-2.
29     *(bytes + 23) = 0; //Device ID byte 11.
30 
31     //Set expected values.
32     UINT32* length = (UINT32*)bytes;
33     *length = size;
34 
35     //Set return values, exit.
36     *location = bytes;
37     return size;
38 }