xref: /openbmc/libcper/generator/sections/gen-section-cxl-component.c (revision 2d4d3b65396596d8939bacaea54ed529530362f9)
1 /**
2  * Functions for generating pseudo-random CXL component 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 CXL component error section, saving the resulting address to the given
13 //location. Returns the size of the newly created section.
generate_section_cxl_component(void ** location,GEN_VALID_BITS_TEST_TYPE validBitsType)14 size_t generate_section_cxl_component(void **location,
15 				      GEN_VALID_BITS_TEST_TYPE validBitsType)
16 {
17 	//Create a random length for the CXL component event log.
18 	//The logs attached here do not necessarily conform to the specification, and are simply random.
19 	int log_len = cper_rand() % 64;
20 
21 	//Create random bytes.
22 	int size = 32 + log_len;
23 	UINT8 *bytes = generate_random_bytes(size);
24 
25 	//Set reserved areas to zero.
26 	UINT32 *validation = (UINT32 *)(bytes + 4);
27 	*validation &= 0x7;
28 	if (validBitsType == ALL_VALID) {
29 		*validation = 0x7;
30 	} else if (validBitsType == SOME_VALID) {
31 		*validation = 0x5;
32 	}
33 	*(validation + 1) = 0;
34 	UINT8 *slot_number = (UINT8 *)(bytes + 21);
35 	*slot_number &= ~0x7; //Device ID slot number bits 0-2.
36 	*(bytes + 23) = 0;    //Device ID byte 11.
37 
38 	//Set expected values.
39 	UINT32 *length = (UINT32 *)bytes;
40 	*length = size;
41 
42 	//Set return values, exit.
43 	*location = bytes;
44 	return size;
45 }
46