blob: 395defb30f4f10e801e3105a8a1c49f1da895dd1 [file] [log] [blame]
Lawrence Tangde9707f2022-07-19 10:54:31 +01001/**
Lawrence Tangefe17e22022-08-08 09:16:23 +01002 * Functions for generating pseudo-random CXL component error sections.
Ed Tanousfedd4572024-07-12 13:56:00 -07003 *
Lawrence Tangde9707f2022-07-19 10:54:31 +01004 * Author: Lawrence.Tang@arm.com
5 **/
6
7#include <stdlib.h>
Thu Nguyene42fb482024-10-15 14:43:11 +00008#include <libcper/BaseTypes.h>
9#include <libcper/generator/gen-utils.h>
10#include <libcper/generator/sections/gen-section.h>
Lawrence Tangde9707f2022-07-19 10:54:31 +010011
Lawrence Tangefe17e22022-08-08 09:16:23 +010012//Generates a single pseudo-random CXL 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.
John Chungf8fc7052024-05-03 20:05:29 +080014size_t generate_section_cxl_component(void **location)
Lawrence Tangde9707f2022-07-19 10:54:31 +010015{
John Chungf8fc7052024-05-03 20:05:29 +080016 //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;
Lawrence Tangde9707f2022-07-19 10:54:31 +010019
John Chungf8fc7052024-05-03 20:05:29 +080020 //Create random bytes.
21 int size = 32 + log_len;
22 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010023
John Chungf8fc7052024-05-03 20:05:29 +080024 //Set reserved areas to zero.
25 UINT32 *validation = (UINT32 *)(bytes + 4);
26 *validation &= 0x7;
27 *(validation + 1) = 0;
28 UINT8 *slot_number = (UINT8 *)(bytes + 21);
29 *slot_number &= ~0x7; //Device ID slot number bits 0-2.
30 *(bytes + 23) = 0; //Device ID byte 11.
Lawrence Tangde9707f2022-07-19 10:54:31 +010031
John Chungf8fc7052024-05-03 20:05:29 +080032 //Set expected values.
33 UINT32 *length = (UINT32 *)bytes;
34 *length = size;
35
36 //Set return values, exit.
37 *location = bytes;
38 return size;
39}