Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Describes functions for converting CXL protocol error CPER sections from binary and JSON format |
| 3 | * into an intermediate format. |
Ed Tanous | fedd457 | 2024-07-12 13:56:00 -0700 | [diff] [blame] | 4 | * |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 5 | * Author: Lawrence.Tang@arm.com |
| 6 | **/ |
| 7 | #include <stdio.h> |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 8 | #include <string.h> |
Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 9 | #include <libcper/base64.h> |
| 10 | #include <libcper/Cper.h> |
| 11 | #include <libcper/cper-utils.h> |
| 12 | #include <libcper/sections/cper-section-cxl-protocol.h> |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 13 | |
| 14 | //Converts a single CXL protocol error CPER section into JSON IR. |
Ed Tanous | 5aedbb2 | 2025-03-05 18:02:34 -0800 | [diff] [blame^] | 15 | json_object *cper_section_cxl_protocol_to_ir(const void *section) |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 16 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 17 | EFI_CXL_PROTOCOL_ERROR_DATA *cxl_protocol_error = |
| 18 | (EFI_CXL_PROTOCOL_ERROR_DATA *)section; |
| 19 | json_object *section_ir = json_object_new_object(); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 20 | ValidationTypes ui64Type = { |
| 21 | UINT_64T, .value.ui64 = cxl_protocol_error->ValidBits |
| 22 | }; |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 23 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 24 | //Type of detecting agent. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 25 | if (isvalid_prop_to_ir(&ui64Type, 0)) { |
| 26 | json_object *agent_type = integer_to_readable_pair( |
| 27 | cxl_protocol_error->CxlAgentType, 2, |
| 28 | CXL_PROTOCOL_ERROR_AGENT_TYPES_KEYS, |
| 29 | CXL_PROTOCOL_ERROR_AGENT_TYPES_VALUES, |
| 30 | "Unknown (Reserved)"); |
| 31 | json_object_object_add(section_ir, "agentType", agent_type); |
| 32 | } |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 33 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 34 | //CXL agent address, depending on the agent type. |
| 35 | json_object *agent_address = json_object_new_object(); |
| 36 | if (cxl_protocol_error->CxlAgentType == |
| 37 | CXL_PROTOCOL_ERROR_DEVICE_AGENT) { |
| 38 | //Address is a CXL1.1 device agent. |
| 39 | json_object_object_add( |
| 40 | agent_address, "functionNumber", |
| 41 | json_object_new_uint64( |
| 42 | cxl_protocol_error->CxlAgentAddress |
| 43 | .DeviceAddress.FunctionNumber)); |
| 44 | json_object_object_add( |
| 45 | agent_address, "deviceNumber", |
| 46 | json_object_new_uint64( |
| 47 | cxl_protocol_error->CxlAgentAddress |
| 48 | .DeviceAddress.DeviceNumber)); |
| 49 | json_object_object_add( |
| 50 | agent_address, "busNumber", |
| 51 | json_object_new_uint64( |
| 52 | cxl_protocol_error->CxlAgentAddress |
| 53 | .DeviceAddress.BusNumber)); |
| 54 | json_object_object_add( |
| 55 | agent_address, "segmentNumber", |
| 56 | json_object_new_uint64( |
| 57 | cxl_protocol_error->CxlAgentAddress |
| 58 | .DeviceAddress.SegmentNumber)); |
| 59 | } else if (cxl_protocol_error->CxlAgentType == |
| 60 | CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT) { |
| 61 | //Address is a CXL port RCRB base address. |
| 62 | json_object_object_add( |
| 63 | agent_address, "value", |
| 64 | json_object_new_uint64( |
| 65 | cxl_protocol_error->CxlAgentAddress |
| 66 | .PortRcrbBaseAddress)); |
| 67 | } |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 68 | if (isvalid_prop_to_ir(&ui64Type, 1)) { |
| 69 | json_object_object_add(section_ir, "cxlAgentAddress", |
| 70 | agent_address); |
| 71 | } else { |
| 72 | json_object_put(agent_address); |
| 73 | } |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 74 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 75 | json_object *device_id = json_object_new_object(); |
| 76 | json_object_object_add( |
| 77 | device_id, "vendorID", |
| 78 | json_object_new_uint64(cxl_protocol_error->DeviceId.VendorId)); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 79 | |
| 80 | //Device ID. |
| 81 | if (isvalid_prop_to_ir(&ui64Type, 2)) { |
| 82 | json_object_object_add( |
| 83 | device_id, "deviceID", |
| 84 | json_object_new_uint64( |
| 85 | cxl_protocol_error->DeviceId.DeviceId)); |
| 86 | json_object_object_add( |
| 87 | device_id, "subsystemVendorID", |
| 88 | json_object_new_uint64( |
| 89 | cxl_protocol_error->DeviceId.SubsystemVendorId)); |
| 90 | json_object_object_add( |
| 91 | device_id, "subsystemDeviceID", |
| 92 | json_object_new_uint64( |
| 93 | cxl_protocol_error->DeviceId.SubsystemDeviceId)); |
| 94 | json_object_object_add( |
| 95 | device_id, "classCode", |
| 96 | json_object_new_uint64( |
| 97 | cxl_protocol_error->DeviceId.ClassCode)); |
| 98 | json_object_object_add( |
| 99 | device_id, "slotNumber", |
| 100 | json_object_new_uint64( |
| 101 | cxl_protocol_error->DeviceId.SlotNumber)); |
| 102 | json_object_object_add(section_ir, "deviceID", device_id); |
| 103 | } |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 104 | |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 105 | char *encoded; |
Lawrence Tang | 368e0b4 | 2022-07-07 14:31:06 +0100 | [diff] [blame] | 106 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 107 | if (isvalid_prop_to_ir(&ui64Type, 3)) { |
| 108 | //Device serial & capability structure (if CXL 1.1 device). |
| 109 | if (cxl_protocol_error->CxlAgentType == |
| 110 | CXL_PROTOCOL_ERROR_DEVICE_AGENT) { |
| 111 | json_object_object_add( |
| 112 | section_ir, "deviceSerial", |
| 113 | json_object_new_uint64( |
| 114 | cxl_protocol_error->DeviceSerial)); |
| 115 | } |
| 116 | } |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 117 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 118 | int32_t encoded_len = 0; |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 119 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 120 | //The PCIe capability structure provided here could either be PCIe 1.1 Capability Structure |
| 121 | //(36-byte, padded to 60 bytes) or PCIe 2.0 Capability Structure (60-byte). There does not seem |
| 122 | //to be a way to differentiate these, so this is left as a b64 dump. |
| 123 | if (isvalid_prop_to_ir(&ui64Type, 4)) { |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 124 | encoded = base64_encode( |
| 125 | (UINT8 *)cxl_protocol_error->CapabilityStructure.PcieCap, |
| 126 | 60, &encoded_len); |
| 127 | if (encoded == NULL) { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 128 | printf("Failed to allocate encode output buffer. \n"); |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 129 | return NULL; |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 130 | } |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 131 | json_object_object_add(section_ir, "capabilityStructure", |
| 132 | json_object_new_string_len(encoded, |
| 133 | encoded_len)); |
| 134 | free(encoded); |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 135 | } |
Lawrence Tang | b98ec66 | 2022-07-06 16:50:21 +0100 | [diff] [blame] | 136 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 137 | const char *cur_pos = (const char *)(cxl_protocol_error + 1); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 138 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 139 | if (isvalid_prop_to_ir(&ui64Type, 5)) { |
| 140 | //CXL DVSEC & error log length. |
| 141 | json_object_object_add( |
| 142 | section_ir, "dvsecLength", |
| 143 | json_object_new_int( |
| 144 | cxl_protocol_error->CxlDvsecLength)); |
| 145 | //CXL DVSEC |
| 146 | //For CXL 1.1 devices, this is the "CXL DVSEC For Flex Bus Device" structure as in CXL 1.1 spec. |
| 147 | //For CXL 1.1 host downstream ports, this is the "CXL DVSEC For Flex Bus Port" structure as in CXL 1.1 spec. |
| 148 | int32_t encoded_len = 0; |
| 149 | |
| 150 | encoded = base64_encode((UINT8 *)cur_pos, |
| 151 | cxl_protocol_error->CxlDvsecLength, |
| 152 | &encoded_len); |
| 153 | if (encoded == NULL) { |
| 154 | return NULL; |
| 155 | } |
| 156 | json_object_object_add(section_ir, "cxlDVSEC", |
| 157 | json_object_new_string_len(encoded, |
| 158 | encoded_len)); |
| 159 | |
| 160 | free(encoded); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 161 | } |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 162 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 163 | cur_pos += cxl_protocol_error->CxlDvsecLength; |
Lawrence Tang | 368e0b4 | 2022-07-07 14:31:06 +0100 | [diff] [blame] | 164 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 165 | if (isvalid_prop_to_ir(&ui64Type, 6)) { |
| 166 | json_object_object_add( |
| 167 | section_ir, "errorLogLength", |
| 168 | json_object_new_int( |
| 169 | cxl_protocol_error->CxlErrorLogLength)); |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 170 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 171 | //CXL Error Log |
| 172 | //This is the "CXL RAS Capability Structure" as in CXL 1.1 spec. |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 173 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 174 | encoded_len = 0; |
| 175 | encoded = base64_encode((UINT8 *)cur_pos, |
| 176 | cxl_protocol_error->CxlErrorLogLength, |
| 177 | &encoded_len); |
| 178 | |
| 179 | if (encoded == NULL) { |
| 180 | printf("Failed to allocate encode output buffer. \n"); |
| 181 | return NULL; |
| 182 | } |
| 183 | json_object_object_add(section_ir, "cxlErrorLog", |
| 184 | json_object_new_string_len(encoded, |
| 185 | encoded_len)); |
| 186 | free(encoded); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 187 | } |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 188 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 189 | return section_ir; |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | //Converts a single CXL protocol CPER-JSON section into CPER binary, outputting to the given stream. |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 193 | void ir_section_cxl_protocol_to_cper(json_object *section, FILE *out) |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 194 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 195 | EFI_CXL_PROTOCOL_ERROR_DATA *section_cper = |
| 196 | (EFI_CXL_PROTOCOL_ERROR_DATA *)calloc( |
| 197 | 1, sizeof(EFI_CXL_PROTOCOL_ERROR_DATA)); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 198 | struct json_object *obj = NULL; |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 199 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 200 | //Validation bits. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 201 | ValidationTypes ui64Type = { UINT_64T, .value.ui64 = 0 }; |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 202 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 203 | //Detecting agent type. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 204 | if (json_object_object_get_ex(section, "agentType", &obj)) { |
| 205 | section_cper->CxlAgentType = readable_pair_to_integer(obj); |
| 206 | add_to_valid_bitfield(&ui64Type, 0); |
| 207 | } |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 208 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 209 | //Based on the agent type, set the address. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 210 | if (json_object_object_get_ex(section, "cxlAgentAddress", &obj)) { |
| 211 | json_object *address = obj; |
| 212 | if (section_cper->CxlAgentType == |
| 213 | CXL_PROTOCOL_ERROR_DEVICE_AGENT) { |
| 214 | //Address is split by function, device, bus & segment. |
| 215 | UINT64 function = json_object_get_uint64( |
| 216 | json_object_object_get(address, |
| 217 | "functionNumber")); |
| 218 | UINT64 device = json_object_get_uint64( |
| 219 | json_object_object_get(address, |
| 220 | "deviceNumber")); |
| 221 | UINT64 bus = json_object_get_uint64( |
| 222 | json_object_object_get(address, "busNumber")); |
| 223 | UINT64 segment = json_object_get_uint64( |
| 224 | json_object_object_get(address, |
| 225 | "segmentNumber")); |
| 226 | section_cper->CxlAgentAddress.DeviceAddress |
| 227 | .FunctionNumber = function; |
| 228 | section_cper->CxlAgentAddress.DeviceAddress |
| 229 | .DeviceNumber = device; |
| 230 | section_cper->CxlAgentAddress.DeviceAddress.BusNumber = |
| 231 | bus; |
| 232 | section_cper->CxlAgentAddress.DeviceAddress |
| 233 | .SegmentNumber = segment; |
| 234 | } else if (section_cper->CxlAgentType == |
| 235 | CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT) { |
| 236 | //Plain RCRB base address. |
| 237 | section_cper->CxlAgentAddress.PortRcrbBaseAddress = |
| 238 | json_object_get_uint64(json_object_object_get( |
| 239 | address, "value")); |
| 240 | } |
| 241 | add_to_valid_bitfield(&ui64Type, 1); |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 242 | } |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 243 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 244 | //Device ID information. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 245 | if (json_object_object_get_ex(section, "deviceID", &obj)) { |
| 246 | json_object *device_id = obj; |
| 247 | section_cper->DeviceId.VendorId = json_object_get_uint64( |
| 248 | json_object_object_get(device_id, "vendorID")); |
| 249 | section_cper->DeviceId.DeviceId = json_object_get_uint64( |
| 250 | json_object_object_get(device_id, "deviceID")); |
| 251 | section_cper->DeviceId.SubsystemVendorId = |
| 252 | json_object_get_uint64(json_object_object_get( |
| 253 | device_id, "subsystemVendorID")); |
| 254 | section_cper->DeviceId.SubsystemDeviceId = |
| 255 | json_object_get_uint64(json_object_object_get( |
| 256 | device_id, "subsystemDeviceID")); |
| 257 | section_cper->DeviceId.ClassCode = json_object_get_uint64( |
| 258 | json_object_object_get(device_id, "classCode")); |
| 259 | section_cper->DeviceId.SlotNumber = json_object_get_uint64( |
| 260 | json_object_object_get(device_id, "slotNumber")); |
| 261 | add_to_valid_bitfield(&ui64Type, 2); |
| 262 | } |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 263 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 264 | //If CXL 1.1 device, the serial number & PCI capability structure. |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 265 | UINT8 *decoded; |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 266 | if (section_cper->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT) { |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 267 | if (json_object_object_get_ex(section, "deviceSerial", &obj)) { |
| 268 | section_cper->DeviceSerial = |
| 269 | json_object_get_uint64(obj); |
| 270 | add_to_valid_bitfield(&ui64Type, 3); |
| 271 | } |
| 272 | if (json_object_object_get_ex(section, "capabilityStructure", |
| 273 | &obj)) { |
| 274 | json_object *encoded = obj; |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 275 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 276 | int32_t decoded_len = 0; |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 277 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 278 | decoded = base64_decode( |
| 279 | json_object_get_string(encoded), |
| 280 | json_object_get_string_len(encoded), |
| 281 | &decoded_len); |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 282 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 283 | if (decoded == NULL) { |
| 284 | printf("Failed to allocate decode output buffer. \n"); |
| 285 | } else { |
| 286 | memcpy(section_cper->CapabilityStructure.PcieCap, |
| 287 | decoded, decoded_len); |
| 288 | free(decoded); |
| 289 | add_to_valid_bitfield(&ui64Type, 4); |
| 290 | } |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 291 | } |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 292 | } |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 293 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 294 | //DVSEC length & error log length. |
| 295 | section_cper->CxlDvsecLength = (UINT16)json_object_get_int( |
| 296 | json_object_object_get(section, "dvsecLength")); |
| 297 | section_cper->CxlErrorLogLength = (UINT16)json_object_get_int( |
| 298 | json_object_object_get(section, "errorLogLength")); |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 299 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 300 | json_object *encodedsrc = NULL; |
| 301 | json_object *encodederr = NULL; |
| 302 | |
| 303 | //DVSEC out: write valid bits |
| 304 | if (json_object_object_get_ex(section, "cxlDVSEC", &obj)) { |
| 305 | add_to_valid_bitfield(&ui64Type, 5); |
| 306 | encodedsrc = obj; |
| 307 | } |
| 308 | |
| 309 | //Error log: write valid bits |
| 310 | if (json_object_object_get_ex(section, "cxlErrorLog", &obj)) { |
| 311 | add_to_valid_bitfield(&ui64Type, 6); |
| 312 | encodederr = obj; |
| 313 | } |
| 314 | section_cper->ValidBits = ui64Type.value.ui64; |
| 315 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 316 | //Write header to stream. |
| 317 | fwrite(section_cper, sizeof(EFI_CXL_PROTOCOL_ERROR_DATA), 1, out); |
| 318 | fflush(out); |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 319 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 320 | //DVSEC out to stream. |
Ed Tanous | a7d2cdd | 2024-07-15 11:07:27 -0700 | [diff] [blame] | 321 | int32_t decoded_len = 0; |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 322 | if (encodedsrc != NULL) { |
| 323 | decoded = base64_decode(json_object_get_string(encodedsrc), |
| 324 | json_object_get_string_len(encodedsrc), |
| 325 | &decoded_len); |
| 326 | if (decoded == NULL) { |
| 327 | printf("Failed to allocate decode output buffer. \n"); |
| 328 | } else { |
| 329 | fwrite(decoded, decoded_len, 1, out); |
| 330 | fflush(out); |
| 331 | free(decoded); |
| 332 | } |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 333 | } |
Lawrence Tang | aec8390 | 2022-07-18 09:41:08 +0100 | [diff] [blame] | 334 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 335 | //Error log out to stream. |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 336 | decoded_len = 0; |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 337 | if (encodederr != NULL) { |
| 338 | decoded = base64_decode(json_object_get_string(encodederr), |
| 339 | json_object_get_string_len(encodederr), |
| 340 | &decoded_len); |
| 341 | if (decoded == NULL) { |
| 342 | printf("Failed to allocate decode output buffer. \n"); |
| 343 | } else { |
| 344 | fwrite(decoded, decoded_len, 1, out); |
| 345 | fflush(out); |
| 346 | free(decoded); |
| 347 | } |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 348 | } |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 349 | |
| 350 | free(section_cper); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 351 | } |