-/**\r
+/** @file\r
MADT table parser\r
\r
- Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.\r
+ 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
+ - Arm Generic Interrupt Controller Architecture Specification,\r
+ GIC architecture version 3 and version 4, issue E\r
+ - Arm Server Base System Architecture 5.0\r
**/\r
\r
#include <IndustryStandard/Acpi.h>\r
#include <Library/UefiLib.h>\r
#include "AcpiParser.h"\r
#include "AcpiTableParser.h"\r
+#include "MadtParser.h"\r
\r
// Local Variables\r
STATIC CONST UINT8* MadtInterruptControllerType;\r
STATIC CONST UINT8* MadtInterruptControllerLength;\r
STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;\r
\r
-// Forward declarations\r
+/**\r
+ This function validates the System Vector Base in the GICD.\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
ValidateGICDSystemVectorBase (\r
IN UINT8* Ptr,\r
IN VOID* Context\r
-);\r
+)\r
+{\r
+ if (*(UINT32*)Ptr != 0) {\r
+ IncrementErrorCount ();\r
+ Print (\r
+ L"\nERROR: System Vector Base must be zero."\r
+ );\r
+ }\r
+}\r
+\r
+/**\r
+ This function validates the SPE Overflow Interrupt in the GICC.\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
+ValidateSpeOverflowInterrupt (\r
+ IN UINT8* Ptr,\r
+ IN VOID* Context\r
+ )\r
+{\r
+ UINT16 SpeOverflowInterrupt;\r
+\r
+ SpeOverflowInterrupt = *(UINT16*)Ptr;\r
+\r
+ // SPE not supported by this processor\r
+ if (SpeOverflowInterrupt == 0) {\r
+ return;\r
+ }\r
\r
-/** An ACPI_PARSER array describing the GICC Interrupt\r
- Controller Structure.\r
-*/\r
+ if ((SpeOverflowInterrupt < ARM_PPI_ID_MIN) ||\r
+ ((SpeOverflowInterrupt > ARM_PPI_ID_MAX) &&\r
+ (SpeOverflowInterrupt < ARM_PPI_ID_EXTENDED_MIN)) ||\r
+ (SpeOverflowInterrupt > ARM_PPI_ID_EXTENDED_MAX)) {\r
+ IncrementErrorCount ();\r
+ Print (\r
+ L"\nERROR: SPE Overflow Interrupt ID of %d is not in the allowed PPI ID "\r
+ L"ranges of %d-%d or %d-%d (for GICv3.1 or later).",\r
+ SpeOverflowInterrupt,\r
+ ARM_PPI_ID_MIN,\r
+ ARM_PPI_ID_MAX,\r
+ ARM_PPI_ID_EXTENDED_MIN,\r
+ ARM_PPI_ID_EXTENDED_MAX\r
+ );\r
+ } else if (SpeOverflowInterrupt != ARM_PPI_ID_PMBIRQ) {\r
+ IncrementWarningCount();\r
+ Print (\r
+ L"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with SBSA "\r
+ L"Level 3 PPI ID assignment: %d.",\r
+ SpeOverflowInterrupt,\r
+ ARM_PPI_ID_PMBIRQ\r
+ );\r
+ }\r
+}\r
+\r
+/**\r
+ An ACPI_PARSER array describing the GICC Interrupt Controller Structure.\r
+**/\r
STATIC CONST ACPI_PARSER GicCParser[] = {\r
{L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
{L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},\r
{L"MPIDR", 8, 68, L"0x%lx", NULL, NULL, NULL, NULL},\r
{L"Processor Power Efficiency Class", 1, 76, L"0x%x", NULL, NULL, NULL,\r
NULL},\r
- {L"Reserved", 3, 77, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}\r
+ {L"Reserved", 1, 77, L"0x%x", NULL, NULL, NULL, NULL},\r
+ {L"SPE overflow Interrupt", 2, 78, L"0x%x", NULL, NULL,\r
+ ValidateSpeOverflowInterrupt, NULL}\r
};\r
\r
-/** An ACPI_PARSER array describing the GICD Interrupt\r
- Controller Structure.\r
-*/\r
+/**\r
+ An ACPI_PARSER array describing the GICD Interrupt Controller Structure.\r
+**/\r
STATIC CONST ACPI_PARSER GicDParser[] = {\r
{L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
{L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},\r
{L"Reserved", 3, 21, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}\r
};\r
\r
-/** An ACPI_PARSER array describing the MSI Frame Interrupt\r
- Controller Structure.\r
-*/\r
+/**\r
+ An ACPI_PARSER array describing the MSI Frame Interrupt Controller Structure.\r
+**/\r
STATIC CONST ACPI_PARSER GicMSIFrameParser[] = {\r
{L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
{L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},\r
{L"SPI Base", 2, 22, L"0x%x", NULL, NULL, NULL, NULL}\r
};\r
\r
-/** An ACPI_PARSER array describing the GICR Interrupt\r
- Controller Structure.\r
-*/\r
+/**\r
+ An ACPI_PARSER array describing the GICR Interrupt Controller Structure.\r
+**/\r
STATIC CONST ACPI_PARSER GicRParser[] = {\r
{L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
{L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},\r
{L"Discovery Range Length", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}\r
};\r
\r
-/** An ACPI_PARSER array describing the GIC ITS Interrupt\r
- Controller Structure.\r
-*/\r
+/**\r
+ An ACPI_PARSER array describing the GIC ITS Interrupt Controller Structure.\r
+**/\r
STATIC CONST ACPI_PARSER GicITSParser[] = {\r
{L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r
{L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},\r
{L"Reserved", 4, 16, L"0x%x", NULL, NULL, NULL, NULL}\r
};\r
\r
-/** An ACPI_PARSER array describing the ACPI MADT Table.\r
-*/\r
+/**\r
+ An ACPI_PARSER array describing the ACPI MADT Table.\r
+**/\r
STATIC CONST ACPI_PARSER MadtParser[] = {\r
PARSE_ACPI_HEADER (&AcpiHdrInfo),\r
{L"Local Interrupt Controller Address", 4, 36, L"0x%x", NULL, NULL, NULL,\r
{L"Flags", 4, 40, L"0x%x", NULL, NULL, NULL, NULL}\r
};\r
\r
-/** An ACPI_PARSER array describing the MADT Interrupt\r
- Controller Structure Header Structure.\r
-*/\r
+/**\r
+ An ACPI_PARSER array describing the MADT Interrupt Controller Structure Header Structure.\r
+**/\r
STATIC CONST ACPI_PARSER MadtInterruptControllerHeaderParser[] = {\r
{NULL, 1, 0, NULL, NULL, (VOID**)&MadtInterruptControllerType, NULL, NULL},\r
{L"Length", 1, 1, NULL, NULL, (VOID**)&MadtInterruptControllerLength, NULL,\r
{L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}\r
};\r
\r
-/** This function validates the System Vector Base in the GICD.\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
-ValidateGICDSystemVectorBase (\r
- IN UINT8* Ptr,\r
- IN VOID* Context\r
-)\r
-{\r
- if (*(UINT32*)Ptr != 0) {\r
- IncrementErrorCount ();\r
- Print (\r
- L"\nERROR: System Vector Base must be zero."\r
- );\r
- }\r
-}\r
-\r
-/** This function parses the ACPI MADT table.\r
+/**\r
+ This function parses the ACPI MADT table.\r
When trace is enabled this function parses the MADT table and\r
traces the ACPI table fields.\r
\r
@param [in] Ptr Pointer to the start of the buffer.\r
@param [in] AcpiTableLength Length of the ACPI table.\r
@param [in] AcpiTableRevision Revision of the ACPI table.\r
-*/\r
+**/\r
VOID\r
EFIAPI\r
ParseAcpiMadt (\r
{\r
UINT32 Offset;\r
UINT8* InterruptContollerPtr;\r
- UINT32 GICDCount = 0;\r
+ UINT32 GICDCount;\r
+\r
+ GICDCount = 0;\r
\r
if (!Trace) {\r
return;\r
0,\r
NULL,\r
InterruptContollerPtr,\r
- 2, // Length is 1 byte at offset 1\r
+ AcpiTableLength - Offset,\r
PARSER_PARAMS (MadtInterruptControllerHeaderParser)\r
);\r
\r
- if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||\r
- (*MadtInterruptControllerLength < 4)) {\r
+ // Check if the values used to control the parsing logic have been\r
+ // successfully read.\r
+ if ((MadtInterruptControllerType == NULL) ||\r
+ (MadtInterruptControllerLength == NULL)) {\r
+ IncrementErrorCount ();\r
+ Print (\r
+ L"ERROR: Insufficient remaining table buffer length to read the " \\r
+ L"Interrupt Controller Structure header. Length = %d.\n",\r
+ AcpiTableLength - Offset\r
+ );\r
+ return;\r
+ }\r
+\r
+ // Make sure forward progress is made.\r
+ if (*MadtInterruptControllerLength < 2) {\r
+ IncrementErrorCount ();\r
+ Print (\r
+ L"ERROR: Structure length is too small: " \\r
+ L"MadtInterruptControllerLength = %d. " \\r
+ L"MadtInterruptControllerType = %d. MADT parsing aborted.\n",\r
+ *MadtInterruptControllerLength,\r
+ *MadtInterruptControllerType\r
+ );\r
+ return;\r
+ }\r
+\r
+ // Make sure the MADT structure lies inside the table\r
+ if ((Offset + *MadtInterruptControllerLength) > AcpiTableLength) {\r
IncrementErrorCount ();\r
Print (\r
- L"ERROR: Invalid Interrupt Controller Length,"\r
- " Type = %d, Length = %d\n",\r
- *MadtInterruptControllerType,\r
- *MadtInterruptControllerLength\r
- );\r
- break;\r
+ L"ERROR: Invalid MADT structure length. " \\r
+ L"MadtInterruptControllerLength = %d. " \\r
+ L"RemainingTableBufferLength = %d. MADT parsing aborted.\n",\r
+ *MadtInterruptControllerLength,\r
+ AcpiTableLength - Offset\r
+ );\r
+ return;\r
}\r
\r
switch (*MadtInterruptControllerType) {\r
- case EFI_ACPI_6_2_GIC: {\r
+ case EFI_ACPI_6_3_GIC: {\r
ParseAcpi (\r
TRUE,\r
2,\r
break;\r
}\r
\r
- case EFI_ACPI_6_2_GICD: {\r
+ case EFI_ACPI_6_3_GICD: {\r
if (++GICDCount > 1) {\r
IncrementErrorCount ();\r
Print (\r
L"ERROR: Only one GICD must be present,"\r
- " GICDCount = %d\n",\r
+ L" GICDCount = %d\n",\r
GICDCount\r
);\r
}\r
break;\r
}\r
\r
- case EFI_ACPI_6_2_GIC_MSI_FRAME: {\r
+ case EFI_ACPI_6_3_GIC_MSI_FRAME: {\r
ParseAcpi (\r
TRUE,\r
2,\r
break;\r
}\r
\r
- case EFI_ACPI_6_2_GICR: {\r
+ case EFI_ACPI_6_3_GICR: {\r
ParseAcpi (\r
TRUE,\r
2,\r
break;\r
}\r
\r
- case EFI_ACPI_6_2_GIC_ITS: {\r
+ case EFI_ACPI_6_3_GIC_ITS: {\r
ParseAcpi (\r
TRUE,\r
2,\r
IncrementErrorCount ();\r
Print (\r
L"ERROR: Unknown Interrupt Controller Structure,"\r
- " Type = %d, Length = %d\n",\r
+ L" Type = %d, Length = %d\n",\r
*MadtInterruptControllerType,\r
*MadtInterruptControllerLength\r
);\r