Add CXL protocol, fix missing addresses on ARM.
diff --git a/cper-parse.c b/cper-parse.c
index a9c7bdc..5551fb7 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -22,6 +22,7 @@
 #include "sections/cper-section-dmar-vtd.h"
 #include "sections/cper-section-dmar-iommu.h"
 #include "sections/cper-section-ccix-per.h"
+#include "sections/cper-section-cxl-protocol.h"
 
 //Private pre-definitions.
 json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header);
@@ -265,8 +266,11 @@
         section_type_readable = "IOMMU specific DMAr section";
     else if (guid_equal(&section_descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
         section_type_readable = "CCIX PER Log Error";
+    else if (guid_equal(&section_descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
+        section_type_readable = "CXL Protocol Error";
 
     //todo: How do you determine if this is a CXL component event?
+    //perhaps refer to CXL Specification, Rev 2.0
     // if (guid_equal(&section_descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
     //     section_type_readable = "CXL Component Event";
 
@@ -338,6 +342,8 @@
         result = cper_section_dmar_iommu_to_ir(section, descriptor);
     else if (guid_equal(&descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
         result = cper_section_ccix_per_to_ir(section, descriptor);
+    else if (guid_equal(&descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
+        result = cper_section_cxl_protocol_to_ir(section, descriptor);
     else
     {
         //Failed read, unknown GUID.
diff --git a/edk/Cper.c b/edk/Cper.c
index dfed1ae..69a68f8 100644
--- a/edk/Cper.c
+++ b/edk/Cper.c
@@ -36,6 +36,7 @@
 EFI_GUID gEfiDirectedIoDMArErrorSectionGuid = { 0x71761d37, 0x32b2, 0x45cd, { 0xa7, 0xd0, 0xb0, 0xfe, 0xdd, 0x93, 0xe8, 0xcf }};
 EFI_GUID gEfiIommuDMArErrorSectionGuid      = { 0x036f84e1, 0x7f37, 0x428c, { 0xa7, 0x9e, 0x57, 0x5f, 0xdf, 0xaa, 0x84, 0xec }};
 EFI_GUID gEfiCcixPerLogErrorSectionGuid     = { 0x91335EF6, 0xEBFB, 0x4478, {0xA6, 0xA6, 0x88, 0xB7, 0x28, 0xCF, 0x75, 0xD7 }};
+EFI_GUID gEfiCxlProtocolErrorSectionGuid    = { 0x80B9EFB4, 0x52B5, 0x4DE3, { 0xA7, 0x77, 0x68, 0x78, 0x4B, 0x77, 0x10, 0x48 }};
 
 //IA32/x64 error segment GUIDs.
 EFI_GUID gEfiIa32x64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, {0xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C } };
diff --git a/edk/Cper.h b/edk/Cper.h
index a2e2fb6..536858f 100644
--- a/edk/Cper.h
+++ b/edk/Cper.h
@@ -1266,6 +1266,7 @@
 extern EFI_GUID   gEfiDirectedIoDMArErrorSectionGuid;

 extern EFI_GUID   gEfiIommuDMArErrorSectionGuid;

 extern EFI_GUID   gEfiCcixPerLogErrorSectionGuid;

+extern EFI_GUID   gEfiCxlProtocolErrorSectionGuid;

 #pragma pack()

 

 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)

diff --git a/sections/cper-section-arm.c b/sections/cper-section-arm.c
index 3e95dc5..b8def2b 100644
--- a/sections/cper-section-arm.c
+++ b/sections/cper-section-arm.c
@@ -124,6 +124,10 @@
     }
     json_object_object_add(error_info_ir, "errorInformation", error_subinfo);
 
+    //Virtual fault address, physical fault address.
+    json_object_object_add(error_info_ir, "virtualFaultAddress", json_object_new_uint64(error_info->VirtualFaultAddress));
+    json_object_object_add(error_info_ir, "physicalFaultAddress", json_object_new_uint64(error_info->PhysicalFaultAddress));
+    
     return error_info_ir;
 }
 
diff --git a/sections/cper-section-cxl-protocol.c b/sections/cper-section-cxl-protocol.c
new file mode 100644
index 0000000..41b6ee5
--- /dev/null
+++ b/sections/cper-section-cxl-protocol.c
@@ -0,0 +1,88 @@
+/**
+ * Describes functions for converting CXL protocol error CPER sections from binary and JSON format
+ * into an intermediate format.
+ * 
+ * Author: Lawrence.Tang@arm.com
+ **/
+#include <stdio.h>
+#include "json.h"
+#include "../edk/Cper.h"
+#include "../cper-utils.h"
+#include "cper-section-cxl-protocol.h"
+
+//Converts a single CXL protocol error CPER section into JSON IR.
+json_object* cper_section_cxl_protocol_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+{
+    EFI_CXL_PROTOCOL_ERROR_DATA* cxl_protocol_error = (EFI_CXL_PROTOCOL_ERROR_DATA*)section;
+    json_object* section_ir = json_object_new_object();
+
+    //Validation bits.
+    json_object* validation = bitfield_to_ir(cxl_protocol_error->ValidBits, 7, CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES);
+    json_object_object_add(section_ir, "validationBits", validation);
+
+    //Type of detecting agent.
+    json_object* agent_type = integer_to_readable_pair(cxl_protocol_error->CxlAgentType, 2,
+        CXL_PROTOCOL_ERROR_AGENT_TYPES_KEYS,
+        CXL_PROTOCOL_ERROR_AGENT_TYPES_VALUES,
+        "Unknown (Reserved)");
+    json_object_object_add(section_ir, "agentType", agent_type);
+
+    //CXL agent address, depending on the agent type.
+    if (cxl_protocol_error->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT)
+    {
+        //Address is a CXL1.1 device agent.
+        json_object* agent_address = json_object_new_object();
+        json_object_object_add(agent_address, "functionNumber", 
+            json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.FunctionNumber));
+        json_object_object_add(agent_address, "deviceNumber", 
+            json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.DeviceNumber));
+        json_object_object_add(agent_address, "busNumber", 
+            json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.BusNumber));
+        json_object_object_add(agent_address, "segmentNumber", 
+            json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.SegmentNumber));
+
+        json_object_object_add(section_ir, "cxlAgentAddress", agent_address);
+    }
+    else if (cxl_protocol_error->CxlAgentType == CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT)
+    {
+        //Address is a CXL port RCRB base address.
+        json_object_object_add(section_ir, "cxlAgentAddress", 
+            json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.PortRcrbBaseAddress));
+    }
+
+    //Device ID.
+    json_object* device_id = json_object_new_object();
+    json_object_object_add(device_id, "vendorID", 
+        json_object_new_uint64(cxl_protocol_error->DeviceId.VendorId));
+    json_object_object_add(device_id, "deviceID", 
+        json_object_new_uint64(cxl_protocol_error->DeviceId.DeviceId));
+    json_object_object_add(device_id, "subsystemVendorID", 
+        json_object_new_uint64(cxl_protocol_error->DeviceId.SubsystemVendorId));
+    json_object_object_add(device_id, "subsystemDeviceID", 
+        json_object_new_uint64(cxl_protocol_error->DeviceId.SubsystemDeviceId));
+    json_object_object_add(device_id, "classCode", 
+        json_object_new_uint64(cxl_protocol_error->DeviceId.ClassCode));
+    json_object_object_add(device_id, "slotNumber", 
+        json_object_new_uint64(cxl_protocol_error->DeviceId.SlotNumber));
+    json_object_object_add(section_ir, "deviceID", device_id);
+
+    //Device serial & capability structure (if CXL 1.1 device).
+    if (cxl_protocol_error->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT)
+    {
+        json_object_object_add(section_ir, "deviceSerial", json_object_new_uint64(cxl_protocol_error->DeviceSerial));
+        //todo: add generic parser for PCI capability structure (see Cper.h)
+    }
+
+    //CXL DVSEC & error log length.
+    json_object_object_add(section_ir, "dvsecLength", json_object_new_int(cxl_protocol_error->CxlDvsecLength));
+    json_object_object_add(section_ir, "errorLogLength", json_object_new_int(cxl_protocol_error->CxlErrorLogLength));
+
+    //CXL DVSEC
+    //todo: for CXL 1.1 devices, implement this as the "CXL DVSEC For Flex Bus Device" structure as in CXL 1.1 spec.
+    //todo: for CXL 1.1 host downstream port, implement this as "CXL DVSEC For Flex Bus Port" structure as in CXL 1.1 spec.
+
+    //CXL Error Log
+    //todo: implement this as the "CXL RAS Capability Structure" as in CXL 1.1 spec.
+    
+    return section_ir;
+}
\ No newline at end of file
diff --git a/sections/cper-section-cxl-protocol.h b/sections/cper-section-cxl-protocol.h
new file mode 100644
index 0000000..9dd5de4
--- /dev/null
+++ b/sections/cper-section-cxl-protocol.h
@@ -0,0 +1,55 @@
+#ifndef CPER_SECTION_CXL_PROTOCOL_H
+#define CPER_SECTION_CXL_PROTOCOL_H
+
+#include "json.h"
+#include "../edk/Cper.h"
+
+#define CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES (const char*[]) {"cxlAgentTypeValid", "cxlAgentAddressValid", \
+    "deviceIDValid", "deviceSerialNumberValid", "capabilityStructureValid", "cxlDvsecValid", "cslErrorLogValid"}
+#define CXL_PROTOCOL_ERROR_AGENT_TYPES_KEYS (int []){0, 1}
+#define CXL_PROTOCOL_ERROR_AGENT_TYPES_VALUES (const char*[]){"CXL 1.1 Device", "CXL 1.1 Host Downstream Port"}
+#define CXL_PROTOCOL_ERROR_DEVICE_AGENT 0
+#define CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT 1
+
+///
+/// CXL Protocol Error Section
+///
+typedef struct {
+    UINT64 VendorId : 16;
+    UINT64 DeviceId : 16;
+    UINT64 SubsystemVendorId : 16;
+    UINT64 SubsystemDeviceId : 16;
+    UINT64 ClassCode : 16;
+    UINT64 Reserved1 : 3;
+    UINT64 SlotNumber : 13;
+    UINT64 Reserved2 : 32;
+} EFI_CXL_DEVICE_ID;
+
+typedef struct {
+    UINT64 FunctionNumber : 8;
+    UINT64 DeviceNumber : 8;
+    UINT64 BusNumber : 8;
+    UINT64 SegmentNumber : 16;
+    UINT64 Reserved : 24;
+} EFI_CXL_DEVICE_AGENT_ADDRESS;
+
+typedef union {
+    EFI_CXL_DEVICE_AGENT_ADDRESS DeviceAddress; //Active when the agent is a CXL1.1 device in CxlAgentType.
+    UINT64 PortRcrbBaseAddress; //Active when the agent is a CXL1.1 host downstream port in CxlAgentType.
+} EFI_CXL_AGENT_ADDRESS;
+
+typedef struct {
+    UINT64 ValidBits;
+    UINT64 CxlAgentType;
+    EFI_CXL_AGENT_ADDRESS CxlAgentAddress;
+    EFI_CXL_DEVICE_ID DeviceId;
+    UINT64 DeviceSerial;
+    EFI_PCIE_ERROR_DATA_CAPABILITY CapabilityStructure;
+    UINT16 CxlDvsecLength;
+    UINT16 CxlErrorLogLength;
+    UINT32 Reserved;
+} EFI_CXL_PROTOCOL_ERROR_DATA;
+
+json_object* cper_section_cxl_protocol_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
+
+#endif
\ No newline at end of file