cper-section-pcie.c (3b7f45b562adaa70cbc645526581fa5f303c3c35) | cper-section-pcie.c (3ab351fe5f23568c5a2284d769937916d60e4c3d) |
---|---|
1/** 2 * Describes functions for converting PCIe CPER sections from binary and JSON format 3 * into an intermediate format. 4 * 5 * Author: Lawrence.Tang@arm.com 6 **/ 7#include <stdio.h> 8#include <string.h> --- 66 unchanged lines hidden (view full) --- 75 char* encoded = b64_encode((unsigned char*)pcie_error->Capability.PcieCap, 60); 76 json_object* capability = json_object_new_object(); 77 json_object_object_add(capability, "data", json_object_new_string(encoded)); 78 free(encoded); 79 json_object_object_add(section_ir, "capabilityStructure", capability); 80 81 //AER information. 82 json_object* aer_capability_ir = json_object_new_object(); | 1/** 2 * Describes functions for converting PCIe CPER sections from binary and JSON format 3 * into an intermediate format. 4 * 5 * Author: Lawrence.Tang@arm.com 6 **/ 7#include <stdio.h> 8#include <string.h> --- 66 unchanged lines hidden (view full) --- 75 char* encoded = b64_encode((unsigned char*)pcie_error->Capability.PcieCap, 60); 76 json_object* capability = json_object_new_object(); 77 json_object_object_add(capability, "data", json_object_new_string(encoded)); 78 free(encoded); 79 json_object_object_add(section_ir, "capabilityStructure", capability); 80 81 //AER information. 82 json_object* aer_capability_ir = json_object_new_object(); |
83 EFI_PCIE_ADV_ERROR_EXT_CAPABILITY* aer_capability = (EFI_PCIE_ADV_ERROR_EXT_CAPABILITY*)pcie_error->AerInfo.PcieAer; 84 json_object_object_add(aer_capability_ir, "capabilityID", 85 json_object_new_uint64(aer_capability->Header.PcieExtendedCapabilityId)); 86 json_object_object_add(aer_capability_ir, "capabilityVersion", 87 json_object_new_uint64(aer_capability->Header.CapabilityVersion)); 88 json_object_object_add(aer_capability_ir, "uncorrectableErrorStatusRegister", 89 json_object_new_uint64(aer_capability->UncorrectableErrorStatusReg)); 90 json_object_object_add(aer_capability_ir, "uncorrectableErrorMaskRegister", 91 json_object_new_uint64(aer_capability->UncorrectableErrorMaskReg)); 92 json_object_object_add(aer_capability_ir, "uncorrectableErrorSeverityRegister", 93 json_object_new_uint64(aer_capability->UncorrectableErrorSeverityReg)); 94 json_object_object_add(aer_capability_ir, "correctableErrorStatusRegister", 95 json_object_new_uint64(aer_capability->CorrectableErrorStatusReg)); 96 json_object_object_add(aer_capability_ir, "correctableErrorMaskRegister", 97 json_object_new_uint64(aer_capability->CorrectableErrorMaskReg)); 98 json_object_object_add(aer_capability_ir, "aeccReg", json_object_new_uint64(aer_capability->AeccReg)); 99 100 //Header log register (b64). 101 encoded = b64_encode((unsigned char*)aer_capability->HeaderLogReg, 16); 102 json_object_object_add(aer_capability_ir, "headerLogRegister", json_object_new_string(encoded)); | 83 encoded = b64_encode((unsigned char*)pcie_error->AerInfo.PcieAer, 96); 84 json_object_object_add(aer_capability_ir, "data", json_object_new_string(encoded)); |
103 free(encoded); | 85 free(encoded); |
104 105 //Remaining AER fields. 106 json_object_object_add(aer_capability_ir, "rootErrorCommand", 107 json_object_new_uint64(aer_capability->RootErrorCommand)); 108 json_object_object_add(aer_capability_ir, "rootErrorStatus", 109 json_object_new_uint64(aer_capability->RootErrorStatus)); 110 json_object_object_add(aer_capability_ir, "errorSourceIDRegister", 111 json_object_new_uint64(aer_capability->ErrorSourceIdReg)); 112 json_object_object_add(aer_capability_ir, "correctableErrorSourceIDRegister", 113 json_object_new_uint64(aer_capability->CorrectableSourceIdReg)); 114 | |
115 json_object_object_add(section_ir, "aerInfo", aer_capability_ir); 116 return section_ir; 117} 118 119//Converts a single CPER-JSON PCIe section into CPER binary, outputting to the given stream. 120void ir_section_pcie_to_cper(json_object* section, FILE* out) 121{ 122 EFI_PCIE_ERROR_DATA* section_cper = (EFI_PCIE_ERROR_DATA*)calloc(1, sizeof(EFI_PCIE_ERROR_DATA)); 123 124 //Validation bits. 125 section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"), 126 8, PCIE_ERROR_VALID_BITFIELD_NAMES); 127 128 //Version. 129 json_object* version = json_object_object_get(section, "version"); | 86 json_object_object_add(section_ir, "aerInfo", aer_capability_ir); 87 return section_ir; 88} 89 90//Converts a single CPER-JSON PCIe section into CPER binary, outputting to the given stream. 91void ir_section_pcie_to_cper(json_object* section, FILE* out) 92{ 93 EFI_PCIE_ERROR_DATA* section_cper = (EFI_PCIE_ERROR_DATA*)calloc(1, sizeof(EFI_PCIE_ERROR_DATA)); 94 95 //Validation bits. 96 section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"), 97 8, PCIE_ERROR_VALID_BITFIELD_NAMES); 98 99 //Version. 100 json_object* version = json_object_object_get(section, "version"); |
130 int minor = json_object_get_int(json_object_object_get(version, "minor")); 131 int major = json_object_get_int(json_object_object_get(version, "major")); 132 section_cper->Version = int_to_bcd(minor) + ((UINT16)(int_to_bcd(major)) << 8); | 101 UINT32 minor = int_to_bcd(json_object_get_int(json_object_object_get(version, "minor"))); 102 UINT32 major = int_to_bcd(json_object_get_int(json_object_object_get(version, "major"))); 103 section_cper->Version = minor + (major << 8); |
133 134 //Command/status registers. 135 json_object* command_status = json_object_object_get(section, "commandStatus"); 136 UINT32 command = (UINT16)json_object_get_uint64(json_object_object_get(command_status, "commandRegister")); 137 UINT32 status = (UINT16)json_object_get_uint64(json_object_object_get(command_status, "statusRegister")); 138 section_cper->CommandStatus = command + (status << 16); 139 140 //Device ID. 141 json_object* device_id = json_object_object_get(section, "deviceID"); 142 UINT64 class_id = json_object_get_uint64(json_object_object_get(device_id, "classCode")); 143 section_cper->DevBridge.VendorId = 144 (UINT16)json_object_get_uint64(json_object_object_get(device_id, "vendorID")); 145 section_cper->DevBridge.DeviceId = 146 (UINT16)json_object_get_uint64(json_object_object_get(device_id, "deviceID")); 147 section_cper->DevBridge.ClassCode[0] = class_id >> 16; 148 section_cper->DevBridge.ClassCode[1] = (class_id >> 8) & 0xFF; | 104 105 //Command/status registers. 106 json_object* command_status = json_object_object_get(section, "commandStatus"); 107 UINT32 command = (UINT16)json_object_get_uint64(json_object_object_get(command_status, "commandRegister")); 108 UINT32 status = (UINT16)json_object_get_uint64(json_object_object_get(command_status, "statusRegister")); 109 section_cper->CommandStatus = command + (status << 16); 110 111 //Device ID. 112 json_object* device_id = json_object_object_get(section, "deviceID"); 113 UINT64 class_id = json_object_get_uint64(json_object_object_get(device_id, "classCode")); 114 section_cper->DevBridge.VendorId = 115 (UINT16)json_object_get_uint64(json_object_object_get(device_id, "vendorID")); 116 section_cper->DevBridge.DeviceId = 117 (UINT16)json_object_get_uint64(json_object_object_get(device_id, "deviceID")); 118 section_cper->DevBridge.ClassCode[0] = class_id >> 16; 119 section_cper->DevBridge.ClassCode[1] = (class_id >> 8) & 0xFF; |
149 section_cper->DevBridge.ClassCode[1] = class_id & 0xFF; | 120 section_cper->DevBridge.ClassCode[2] = class_id & 0xFF; |
150 section_cper->DevBridge.Function = 151 (UINT8)json_object_get_uint64(json_object_object_get(device_id, "functionNumber")); 152 section_cper->DevBridge.Device = 153 (UINT8)json_object_get_uint64(json_object_object_get(device_id, "deviceNumber")); 154 section_cper->DevBridge.Segment = 155 (UINT16)json_object_get_uint64(json_object_object_get(device_id, "segmentNumber")); 156 section_cper->DevBridge.PrimaryOrDeviceBus = 157 (UINT8)json_object_get_uint64(json_object_object_get(device_id, "primaryOrDeviceBusNumber")); --- 12 unchanged lines hidden (view full) --- 170 json_object* capability = json_object_object_get(section, "capabilityStructure"); 171 json_object* encoded = json_object_object_get(capability, "data"); 172 UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded)); 173 memcpy(section_cper->Capability.PcieCap, decoded, 60); 174 free(decoded); 175 176 //AER capability structure. 177 json_object* aer_info = json_object_object_get(section, "aerInfo"); | 121 section_cper->DevBridge.Function = 122 (UINT8)json_object_get_uint64(json_object_object_get(device_id, "functionNumber")); 123 section_cper->DevBridge.Device = 124 (UINT8)json_object_get_uint64(json_object_object_get(device_id, "deviceNumber")); 125 section_cper->DevBridge.Segment = 126 (UINT16)json_object_get_uint64(json_object_object_get(device_id, "segmentNumber")); 127 section_cper->DevBridge.PrimaryOrDeviceBus = 128 (UINT8)json_object_get_uint64(json_object_object_get(device_id, "primaryOrDeviceBusNumber")); --- 12 unchanged lines hidden (view full) --- 141 json_object* capability = json_object_object_get(section, "capabilityStructure"); 142 json_object* encoded = json_object_object_get(capability, "data"); 143 UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded)); 144 memcpy(section_cper->Capability.PcieCap, decoded, 60); 145 free(decoded); 146 147 //AER capability structure. 148 json_object* aer_info = json_object_object_get(section, "aerInfo"); |
178 EFI_PCIE_ADV_ERROR_EXT_CAPABILITY* aer_capability = 179 (EFI_PCIE_ADV_ERROR_EXT_CAPABILITY*)section_cper->AerInfo.PcieAer; 180 aer_capability->Header.PcieExtendedCapabilityId = 181 json_object_get_uint64(json_object_object_get(aer_info, "capabilityID")); 182 aer_capability->Header.CapabilityVersion = 183 json_object_get_uint64(json_object_object_get(aer_info, "capabilityVersion")); 184 aer_capability->UncorrectableErrorStatusReg = 185 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "uncorrectableErrorStatusRegister")); 186 aer_capability->UncorrectableErrorMaskReg = 187 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "uncorrectableErrorMaskRegister")); 188 aer_capability->UncorrectableErrorSeverityReg = 189 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "uncorrectableErrorSeverityRegister")); 190 aer_capability->CorrectableErrorStatusReg = 191 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "correctableErrorStatusRegister")); 192 aer_capability->CorrectableErrorMaskReg = 193 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "correctableErrorMaskRegister")); 194 aer_capability->AeccReg = 195 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "aeccReg")); 196 197 //AER header log register. 198 encoded = json_object_object_get(aer_info, "headerLogRegister"); | 149 encoded = json_object_object_get(aer_info, "data"); |
199 decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded)); | 150 decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded)); |
200 memcpy(aer_capability->HeaderLogReg, decoded, 16); | 151 memcpy(section_cper->AerInfo.PcieAer, decoded, 96); |
201 free(decoded); 202 | 152 free(decoded); 153 |
203 //Remaining AER fields. 204 aer_capability->RootErrorCommand = 205 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "rootErrorCommand")); 206 aer_capability->RootErrorStatus = 207 (UINT32)json_object_get_uint64(json_object_object_get(aer_info, "rootErrorStatus")); 208 aer_capability->ErrorSourceIdReg = 209 (UINT16)json_object_get_uint64(json_object_object_get(aer_info, "errorSourceIDRegister")); 210 aer_capability->CorrectableSourceIdReg = 211 (UINT16)json_object_get_uint64(json_object_object_get(aer_info, "correctableErrorSourceIDRegister")); 212 213 | |
214 //Miscellaneous value fields. 215 section_cper->PortType = (UINT32)readable_pair_to_integer(json_object_object_get(section, "portType")); 216 section_cper->SerialNo = json_object_get_uint64(json_object_object_get(section, "deviceSerialNumber")); 217 218 //Write out to stream, free resources. | 154 //Miscellaneous value fields. 155 section_cper->PortType = (UINT32)readable_pair_to_integer(json_object_object_get(section, "portType")); 156 section_cper->SerialNo = json_object_get_uint64(json_object_object_get(section, "deviceSerialNumber")); 157 158 //Write out to stream, free resources. |
219 fwrite(§ion_cper, sizeof(section_cper), 1, out); | 159 fwrite(section_cper, sizeof(EFI_PCIE_ERROR_DATA), 1, out); |
220 fflush(out); 221 free(section_cper); 222} | 160 fflush(out); 161 free(section_cper); 162} |