/**\r
This function parses the IORT Node Id Mapping array.\r
\r
- @param [in] Ptr Pointer to the start of the IORT Table.\r
+ @param [in] Ptr Pointer to the start of the ID mapping array.\r
+ @param [in] Length Length of the buffer.\r
@param [in] MappingCount The ID Mapping count.\r
- @param [in] MappingOffset The offset of the ID Mapping array\r
- from the start of the IORT table.\r
**/\r
STATIC\r
VOID\r
DumpIortNodeIdMappings (\r
IN UINT8* Ptr,\r
- IN UINT32 MappingCount,\r
- IN UINT32 MappingOffset\r
+ IN UINT32 Length,\r
+ IN UINT32 MappingCount\r
)\r
{\r
- UINT8* IdMappingPtr;\r
UINT32 Index;\r
UINT32 Offset;\r
CHAR8 Buffer[40]; // Used for AsciiName param of ParseAcpi\r
\r
- IdMappingPtr = Ptr + MappingOffset;\r
Index = 0;\r
- while (Index < MappingCount) {\r
+ Offset = 0;\r
+\r
+ while ((Index < MappingCount) &&\r
+ (Offset < Length)) {\r
AsciiSPrint (\r
Buffer,\r
sizeof (Buffer),\r
"ID Mapping [%d]",\r
Index\r
);\r
- Offset = ParseAcpi (\r
- TRUE,\r
- 4,\r
- Buffer,\r
- IdMappingPtr,\r
- 20,\r
- PARSER_PARAMS (IortNodeIdMappingParser)\r
- );\r
- IdMappingPtr += Offset;\r
+ Offset += ParseAcpi (\r
+ TRUE,\r
+ 4,\r
+ Buffer,\r
+ Ptr + Offset,\r
+ Length - Offset,\r
+ PARSER_PARAMS (IortNodeIdMappingParser)\r
+ );\r
Index++;\r
}\r
}\r
UINT32 Offset;\r
CHAR8 Buffer[50]; // Used for AsciiName param of ParseAcpi\r
\r
- UINT8* ArrayPtr;\r
-\r
ParseAcpi (\r
TRUE,\r
2,\r
PARSER_PARAMS (IortNodeSmmuV1V2Parser)\r
);\r
\r
- ArrayPtr = Ptr + *InterruptContextOffset;\r
+ Offset = *InterruptContextOffset;\r
Index = 0;\r
- while (Index < *InterruptContextCount) {\r
+\r
+ while ((Index < *InterruptContextCount) &&\r
+ (Offset < Length)) {\r
AsciiSPrint (\r
Buffer,\r
sizeof (Buffer),\r
"Context Interrupts Array [%d]",\r
Index\r
);\r
- Offset = ParseAcpi (\r
- TRUE,\r
- 4,\r
- Buffer,\r
- ArrayPtr,\r
- 8,\r
- PARSER_PARAMS (InterruptArrayParser)\r
- );\r
- ArrayPtr += Offset;\r
+ Offset += ParseAcpi (\r
+ TRUE,\r
+ 4,\r
+ Buffer,\r
+ Ptr + Offset,\r
+ Length - Offset,\r
+ PARSER_PARAMS (InterruptArrayParser)\r
+ );\r
Index++;\r
}\r
\r
- ArrayPtr = Ptr + *PmuInterruptOffset;\r
+ Offset = *PmuInterruptOffset;\r
Index = 0;\r
- while (Index < *PmuInterruptCount) {\r
+\r
+ while ((Index < *PmuInterruptCount) &&\r
+ (Offset < Length)) {\r
AsciiSPrint (\r
Buffer,\r
sizeof (Buffer),\r
"PMU Interrupts Array [%d]",\r
Index\r
);\r
- Offset = ParseAcpi (\r
- TRUE,\r
- 4,\r
- Buffer,\r
- ArrayPtr,\r
- 8,\r
- PARSER_PARAMS (InterruptArrayParser)\r
- );\r
- ArrayPtr += Offset;\r
+ Offset += ParseAcpi (\r
+ TRUE,\r
+ 4,\r
+ Buffer,\r
+ Ptr + Offset,\r
+ Length - Offset,\r
+ PARSER_PARAMS (InterruptArrayParser)\r
+ );\r
Index++;\r
}\r
\r
- if (*IortIdMappingCount != 0) {\r
- DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);\r
- }\r
+ DumpIortNodeIdMappings (\r
+ Ptr + MappingOffset,\r
+ Length - MappingOffset,\r
+ MappingCount\r
+ );\r
}\r
\r
/**\r
PARSER_PARAMS (IortNodeSmmuV3Parser)\r
);\r
\r
- if (*IortIdMappingCount != 0) {\r
- DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);\r
- }\r
+ DumpIortNodeIdMappings (\r
+ Ptr + MappingOffset,\r
+ Length - MappingOffset,\r
+ MappingCount\r
+ );\r
}\r
\r
/**\r
{\r
UINT32 Offset;\r
UINT32 Index;\r
- UINT8* ItsIdPtr;\r
CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi\r
\r
Offset = ParseAcpi (\r
- TRUE,\r
- 2,\r
- "ITS Node",\r
- Ptr,\r
- Length,\r
- PARSER_PARAMS (IortNodeItsParser)\r
- );\r
+ TRUE,\r
+ 2,\r
+ "ITS Node",\r
+ Ptr,\r
+ Length,\r
+ PARSER_PARAMS (IortNodeItsParser)\r
+ );\r
\r
- ItsIdPtr = Ptr + Offset;\r
Index = 0;\r
- while (Index < *ItsCount) {\r
+\r
+ while ((Index < *ItsCount) &&\r
+ (Offset < Length)) {\r
AsciiSPrint (\r
Buffer,\r
sizeof (Buffer),\r
"GIC ITS Identifier Array [%d]",\r
Index\r
);\r
- Offset = ParseAcpi (\r
- TRUE,\r
- 4,\r
- Buffer,\r
- ItsIdPtr,\r
- 4,\r
- PARSER_PARAMS (ItsIdParser)\r
- );\r
- ItsIdPtr += Offset;\r
+ Offset += ParseAcpi (\r
+ TRUE,\r
+ 4,\r
+ Buffer,\r
+ Ptr + Offset,\r
+ Length - Offset,\r
+ PARSER_PARAMS (ItsIdParser)\r
+ );\r
Index++;\r
}\r
\r
// Note: ITS does not have the ID Mappings Array\r
+\r
}\r
\r
/**\r
{\r
UINT32 Offset;\r
UINT32 Index;\r
- UINT8* DeviceNamePtr;\r
- UINT32 DeviceNameLength;\r
\r
Offset = ParseAcpi (\r
TRUE,\r
PARSER_PARAMS (IortNodeNamedComponentParser)\r
);\r
\r
- DeviceNamePtr = Ptr + Offset;\r
// Estimate the Device Name length\r
- DeviceNameLength = Length - Offset - (MappingCount * 20);\r
PrintFieldName (2, L"Device Object Name");\r
Index = 0;\r
- while ((Index < DeviceNameLength) && (DeviceNamePtr[Index] != 0)) {\r
- Print (L"%c", DeviceNamePtr[Index++]);\r
+\r
+ while ((*(Ptr + Offset) != 0) &&\r
+ (Offset < Length)) {\r
+ Print (L"%c", *(Ptr + Offset));\r
+ Offset++;\r
}\r
Print (L"\n");\r
\r
- if (*IortIdMappingCount != 0) {\r
- DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);\r
- }\r
+ DumpIortNodeIdMappings (\r
+ Ptr + MappingOffset,\r
+ Length - MappingOffset,\r
+ MappingCount\r
+ );\r
}\r
\r
/**\r
PARSER_PARAMS (IortNodeRootComplexParser)\r
);\r
\r
- if (*IortIdMappingCount != 0) {\r
- DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);\r
- }\r
+ DumpIortNodeIdMappings (\r
+ Ptr + MappingOffset,\r
+ Length - MappingOffset,\r
+ MappingCount\r
+ );\r
}\r
\r
/**\r
Ptr,\r
Length,\r
PARSER_PARAMS (IortNodePmcgParser)\r
- );\r
+ );\r
\r
- if (*IortIdMappingCount != 0) {\r
- DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);\r
- }\r
+ DumpIortNodeIdMappings (\r
+ Ptr + MappingOffset,\r
+ Length - MappingOffset,\r
+ MappingCount\r
+ );\r
}\r
\r
/**\r
AcpiTableLength,\r
PARSER_PARAMS (IortParser)\r
);\r
+\r
Offset = *IortNodeOffset;\r
NodePtr = Ptr + Offset;\r
Index = 0;\r
\r
- while ((Index < *IortNodeCount) && (Offset < AcpiTableLength)) {\r
+ // Parse the specified number of IORT nodes or the IORT table buffer length.\r
+ // Whichever is minimum.\r
+ while ((Index++ < *IortNodeCount) &&\r
+ (Offset < AcpiTableLength)) {\r
// Parse the IORT Node Header\r
ParseAcpi (\r
FALSE,\r
0,\r
"IORT Node Header",\r
NodePtr,\r
- 16,\r
+ AcpiTableLength - Offset,\r
PARSER_PARAMS (IortNodeHeaderParser)\r
);\r
- if (*IortNodeLength == 0) {\r
+\r
+ // Make sure the IORT Node is inside the table\r
+ if ((Offset + (*IortNodeLength)) > AcpiTableLength) {\r
IncrementErrorCount ();\r
- Print (L"ERROR: Parser error. Invalid table data.\n");\r
+ Print (\r
+ L"ERROR: Invalid IORT node length. IortNodeLength = %d. " \\r
+ L"RemainingTableBufferLength = %d. IORT parsing aborted.\n",\r
+ *IortNodeLength,\r
+ AcpiTableLength - Offset\r
+ );\r
return;\r
}\r
\r