]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
ShellPkg: acpiview: Update SRAT parser to ACPI 6.3
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Srat / SratParser.c
index a8aa420487bb6bf29fc38221d0b221573c64b8b3..6fe7bf681132df08133e3e03e3ee3f020d905dd2 100644 (file)
@@ -5,7 +5,7 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
   @par Reference(s):\r
-    - ACPI 6.2 Specification - Errata A, September 2017\r
+    - ACPI 6.3 Specification - January 2019\r
 **/\r
 \r
 #include <IndustryStandard/Acpi.h>\r
@@ -17,6 +17,7 @@
 // Local Variables\r
 STATIC CONST UINT8* SratRAType;\r
 STATIC CONST UINT8* SratRALength;\r
+STATIC CONST UINT8* SratDeviceHandleType;\r
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;\r
 \r
 /**\r
@@ -40,6 +41,167 @@ ValidateSratReserved (
   }\r
 }\r
 \r
+/**\r
+  This function validates the Device Handle Type field in the Generic Initiator\r
+  Affinity Structure.\r
+\r
+  @param [in] Ptr     Pointer to the start of the field data.\r
+  @param [in] Context Pointer to context specific information e.g. this\r
+                      could be a pointer to the ACPI table header.\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+ValidateSratDeviceHandleType (\r
+  IN UINT8* Ptr,\r
+  IN VOID*  Context\r
+  )\r
+{\r
+  UINT8   DeviceHandleType;\r
+\r
+  DeviceHandleType = *Ptr;\r
+\r
+  if (DeviceHandleType > EFI_ACPI_6_3_PCI_DEVICE_HANDLE) {\r
+    IncrementErrorCount ();\r
+    Print (\r
+      L"\nERROR: Invalid Device Handle Type: %d. Must be between 0 and %d.",\r
+      DeviceHandleType,\r
+      EFI_ACPI_6_3_PCI_DEVICE_HANDLE\r
+      );\r
+  }\r
+}\r
+\r
+/**\r
+  This function traces the PCI BDF Number field inside Device Handle - PCI\r
+\r
+  @param [in] Format  Format string for tracing the data.\r
+  @param [in] Ptr     Pointer to the start of the buffer.\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+DumpSratPciBdfNumber (\r
+  IN CONST CHAR16* Format,\r
+  IN UINT8*        Ptr\r
+  )\r
+{\r
+  CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];\r
+\r
+  Print (L"\n");\r
+\r
+  /*\r
+    The PCI BDF Number subfields are printed in the order specified in the ACPI\r
+    specification. The format of the 16-bit PCI BDF Number field is as follows:\r
+\r
+    +-----+------+------+\r
+    |DEV  | FUNC | BUS  |\r
+    +-----+------+------+\r
+    |15:11| 10:8 |  7:0 |\r
+    +-----+------+------+\r
+  */\r
+\r
+  // Print PCI Bus Number (Bits 7:0 of Byte 2)\r
+  UnicodeSPrint (\r
+    Buffer,\r
+    sizeof (Buffer),\r
+    L"PCI Bus Number"\r
+    );\r
+  PrintFieldName (4, Buffer);\r
+  Print (\r
+    L"0x%x\n",\r
+    *Ptr\r
+    );\r
+\r
+  Ptr++;\r
+\r
+  // Print PCI Device Number (Bits 7:3 of Byte 3)\r
+  UnicodeSPrint (\r
+    Buffer,\r
+    sizeof (Buffer),\r
+    L"PCI Device Number"\r
+    );\r
+  PrintFieldName (4, Buffer);\r
+  Print (\r
+    L"0x%x\n",\r
+    (*Ptr & (BIT7 | BIT6 | BIT5 | BIT4 | BIT3)) >> 3\r
+    );\r
+\r
+  // PCI Function Number (Bits 2:0 of Byte 3)\r
+  UnicodeSPrint (\r
+    Buffer,\r
+    sizeof (Buffer),\r
+    L"PCI Function Number"\r
+    );\r
+  PrintFieldName (4, Buffer);\r
+  Print (\r
+    L"0x%x\n",\r
+    *Ptr & (BIT2 | BIT1 | BIT0)\r
+    );\r
+}\r
+\r
+/**\r
+  An ACPI_PARSER array describing the Device Handle - ACPI\r
+**/\r
+STATIC CONST ACPI_PARSER SratDeviceHandleAcpiParser[] = {\r
+  {L"ACPI_HID", 8, 0, L"0x%lx", NULL, NULL, NULL, NULL},\r
+  {L"ACPI_UID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},\r
+  {L"Reserved", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}\r
+};\r
+\r
+/**\r
+  An ACPI_PARSER array describing the Device Handle - PCI\r
+**/\r
+STATIC CONST ACPI_PARSER SratDeviceHandlePciParser[] = {\r
+  {L"PCI Segment", 2, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
+  {L"PCI BDF Number", 2, 2, NULL, DumpSratPciBdfNumber, NULL, NULL, NULL},\r
+  {L"Reserved", 12, 4, L"%x %x %x %x - %x %x %x %x - %x %x %x %x", Dump12Chars,\r
+   NULL, NULL, NULL}\r
+};\r
+\r
+/**\r
+  This function traces the Device Handle field inside Generic Initiator\r
+  Affinity Structure.\r
+\r
+  @param [in] Format  Format string for tracing the data.\r
+  @param [in] Ptr     Pointer to the start of the buffer.\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+DumpSratDeviceHandle (\r
+  IN CONST CHAR16* Format,\r
+  IN UINT8*        Ptr\r
+ )\r
+{\r
+  if (SratDeviceHandleType == NULL) {\r
+    IncrementErrorCount ();\r
+    Print (L"\nERROR: Device Handle Type read incorrectly.\n");\r
+    return;\r
+  }\r
+\r
+  Print (L"\n");\r
+\r
+  if (*SratDeviceHandleType == EFI_ACPI_6_3_ACPI_DEVICE_HANDLE) {\r
+    ParseAcpi (\r
+      TRUE,\r
+      2,\r
+      NULL,\r
+      Ptr,\r
+      sizeof (EFI_ACPI_6_3_DEVICE_HANDLE_ACPI),\r
+      PARSER_PARAMS (SratDeviceHandleAcpiParser)\r
+      );\r
+  } else if (*SratDeviceHandleType == EFI_ACPI_6_3_PCI_DEVICE_HANDLE) {\r
+    ParseAcpi (\r
+      TRUE,\r
+      2,\r
+      NULL,\r
+      Ptr,\r
+      sizeof (EFI_ACPI_6_3_DEVICE_HANDLE_PCI),\r
+      PARSER_PARAMS (SratDeviceHandlePciParser)\r
+      );\r
+  }\r
+}\r
+\r
 /**\r
   This function traces the APIC Proximity Domain field.\r
 \r
@@ -103,6 +265,22 @@ STATIC CONST ACPI_PARSER SratGicITSAffinityParser[] = {
   {L"ITS Id", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},\r
 };\r
 \r
+/**\r
+  An ACPI_PARSER array describing the Generic Initiator Affinity Structure\r
+**/\r
+STATIC CONST ACPI_PARSER SratGenericInitiatorAffinityParser[] = {\r
+  {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
+  {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},\r
+\r
+  {L"Reserved", 1, 2, L"0x%x", NULL, NULL, NULL, NULL},\r
+  {L"Device Handle Type", 1, 3, L"%d", NULL, (VOID**)&SratDeviceHandleType,\r
+   ValidateSratDeviceHandleType, NULL},\r
+  {L"Proximity Domain", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},\r
+  {L"Device Handle", 16, 8, L"%s", DumpSratDeviceHandle, NULL, NULL, NULL},\r
+  {L"Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},\r
+  {L"Reserved", 4, 28, L"0x%x", NULL, NULL, NULL, NULL}\r
+};\r
+\r
 /**\r
   An ACPI_PARSER array describing the Memory Affinity structure.\r
 **/\r
@@ -183,6 +361,7 @@ ParseAcpiSrat (
   UINT8* ResourcePtr;\r
   UINT32 GicCAffinityIndex;\r
   UINT32 GicITSAffinityIndex;\r
+  UINT32 GenericInitiatorAffinityIndex;\r
   UINT32 MemoryAffinityIndex;\r
   UINT32 ApicSapicAffinityIndex;\r
   UINT32 X2ApicAffinityIndex;\r
@@ -190,6 +369,7 @@ ParseAcpiSrat (
 \r
   GicCAffinityIndex = 0;\r
   GicITSAffinityIndex = 0;\r
+  GenericInitiatorAffinityIndex = 0;\r
   MemoryAffinityIndex = 0;\r
   ApicSapicAffinityIndex = 0;\r
   X2ApicAffinityIndex = 0;\r
@@ -232,7 +412,7 @@ ParseAcpiSrat (
     }\r
 \r
     switch (*SratRAType) {\r
-      case EFI_ACPI_6_2_GICC_AFFINITY:\r
+      case EFI_ACPI_6_3_GICC_AFFINITY:\r
         AsciiSPrint (\r
           Buffer,\r
           sizeof (Buffer),\r
@@ -249,7 +429,7 @@ ParseAcpiSrat (
           );\r
         break;\r
 \r
-      case EFI_ACPI_6_2_GIC_ITS_AFFINITY:\r
+      case EFI_ACPI_6_3_GIC_ITS_AFFINITY:\r
         AsciiSPrint (\r
           Buffer,\r
           sizeof (Buffer),\r
@@ -266,7 +446,24 @@ ParseAcpiSrat (
           );\r
         break;\r
 \r
-      case EFI_ACPI_6_2_MEMORY_AFFINITY:\r
+      case EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY:\r
+        AsciiSPrint (\r
+          Buffer,\r
+          sizeof (Buffer),\r
+          "Generic Initiator Affinity Structure [%d]",\r
+          GenericInitiatorAffinityIndex++\r
+        );\r
+        ParseAcpi (\r
+          TRUE,\r
+          2,\r
+          Buffer,\r
+          ResourcePtr,\r
+          *SratRALength,\r
+          PARSER_PARAMS (SratGenericInitiatorAffinityParser)\r
+        );\r
+        break;\r
+\r
+      case EFI_ACPI_6_3_MEMORY_AFFINITY:\r
         AsciiSPrint (\r
           Buffer,\r
           sizeof (Buffer),\r
@@ -283,7 +480,7 @@ ParseAcpiSrat (
           );\r
         break;\r
 \r
-      case EFI_ACPI_6_2_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY:\r
+      case EFI_ACPI_6_3_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY:\r
         AsciiSPrint (\r
           Buffer,\r
           sizeof (Buffer),\r
@@ -300,7 +497,7 @@ ParseAcpiSrat (
           );\r
         break;\r
 \r
-      case EFI_ACPI_6_2_PROCESSOR_LOCAL_X2APIC_AFFINITY:\r
+      case EFI_ACPI_6_3_PROCESSOR_LOCAL_X2APIC_AFFINITY:\r
         AsciiSPrint (\r
           Buffer,\r
           sizeof (Buffer),\r