blob: c0e59c024f2d28251879c5eaab2e85138e019868 [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/PCI-X bus 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 PCI/PCI-X bus 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.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080014size_t generate_section_pci_bus(void **location,
15 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangde9707f2022-07-19 10:54:31 +010016{
John Chungf8fc7052024-05-03 20:05:29 +080017 //Create random bytes.
18 int size = 72;
19 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010020
John Chungf8fc7052024-05-03 20:05:29 +080021 //Set reserved areas to zero.
22 UINT64 *validation = (UINT64 *)bytes;
23 *validation &= 0x1FF; //Validation 9-63
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080024 if (validBitsType == ALL_VALID) {
25 *validation = 0x1FF;
26 } else if (validBitsType == SOME_VALID) {
27 *validation = 0x155;
28 }
John Chungf8fc7052024-05-03 20:05:29 +080029 UINT32 *reserved = (UINT32 *)(bytes + 20);
30 *reserved = 0;
31 UINT64 *bus_command = (UINT64 *)(bytes + 40);
32 *bus_command &= ((UINT64)0x1 << 56); //Bus command bytes bar bit 56.
Lawrence Tangde9707f2022-07-19 10:54:31 +010033
John Chungf8fc7052024-05-03 20:05:29 +080034 //Fix values that could be above range.
35 UINT16 *error_type = (UINT16 *)(bytes + 16);
Ed Tanous2d4d3b62025-03-11 10:34:29 -070036 *error_type = cper_rand() % 8;
Lawrence Tangde9707f2022-07-19 10:54:31 +010037
John Chungf8fc7052024-05-03 20:05:29 +080038 //Fix error status.
39 create_valid_error_section(bytes + 8);
40
41 //Set return values, exit.
42 *location = bytes;
43 return size;
44}