public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring
@ 2019-07-22  7:50 Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct() Krzysztof Koch
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Krzysztof Koch @ 2019-07-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: jaben.carsey, ray.ni, zhichao.gao, Sami.Mujawar, Matteo.Carlini,
	nd

This set of patches consists of a number of changes which make the code
structure consistent across the existing ACPI table parsers. These are
all refactoring changes which do not modify the existing functionality
of the acpiview UEFI shell tool.

Changes can be seen at: https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_code_style_enhance_v2

Krzysztof Koch (6):
  ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
  ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
  ShellPkg: acpiview: RSDP: Make code consistent with other parsers
  ShellPkg: acpiview: SRAT: Minor code style enhancements
  ShellPkg: acpiview: MADT: Split structure length validation
  ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c              | 26 +++++++++-------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h              |  8 +++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 ++++++++++++++------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 +++++++++++++-----
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 +++++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c |  3 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 18 +++--------
 8 files changed, 82 insertions(+), 48 deletions(-)

--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
  2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
@ 2019-07-22  7:50 ` Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 2/6] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call Krzysztof Koch
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Koch @ 2019-07-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: jaben.carsey, ray.ni, zhichao.gao, Sami.Mujawar, Matteo.Carlini,
	nd

Modify the signature of the DumpGasStruct() function to include the
buffer length parameter and to return the number of bytes parsed by
the function.

This way it becomes possible to prevent buffer overruns when dumping
Generic Address Structure's (GAS) fields in the acpiview table
parsers.

Update all existing DumpGasStruct() calls in acpiview to add the
length argument.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---

Notes:
    v2:
    - Pass GAS_LENGTH to DumpGasStruct() in DBG2 parser [Zhichao]

    v1:
    - Modify DumpGasStruct() signature [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c              | 26 +++++++++++---------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h              |  8 ++++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |  2 +-
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db89332197c0dc0e 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = {
 
   @param [in] Ptr     Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*        Ptr,
-  IN UINT32        Indent
+  IN UINT32        Indent,
+  IN UINT32        Length
   )
 {
   Print (L"\n");
-  ParseAcpi (
-    TRUE,
-    Indent,
-    NULL,
-    Ptr,
-    GAS_LENGTH,
-    PARSER_PARAMS (GasParser)
-    );
+  return ParseAcpi (
+           TRUE,
+           Indent,
+           NULL,
+           Ptr,
+           Length,
+           PARSER_PARAMS (GasParser)
+           );
 }
 
 /**
@@ -621,7 +625,7 @@ DumpGas (
   IN UINT8*        Ptr
   )
 {
-  DumpGasStruct (Ptr, 2);
+  DumpGasStruct (Ptr, 2, GAS_LENGTH);
 }
 
 /**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebaebbf3079eaba01 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -405,12 +405,16 @@ ParseAcpi (
 
   @param [in] Ptr     Pointer to the start of the buffer.
   @param [in] Indent  Number of spaces to indent the output.
+  @param [in] Length  Length of the GAS structure buffer.
+
+  @retval Number of bytes parsed.
 **/
-VOID
+UINT32
 EFIAPI
 DumpGasStruct (
   IN UINT8*        Ptr,
-  IN UINT32        Indent
+  IN UINT32        Indent,
+  IN UINT32        Length
   );
 
 /**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 1efcbd40f86efdabed2152540a415db8a950fb71..c6929695a1032c57761ef85002d6c51b7800ce23 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -134,7 +134,7 @@ DumpDbgDeviceInfo (
   AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
   while (Index < (*GasCount)) {
     PrintFieldName (4, L"BaseAddressRegister");
-    DumpGasStruct (DataPtr, 4);
+    DumpGasStruct (DataPtr, 4, GAS_LENGTH);
     PrintFieldName (4, L"Address Size");
     Print (L"0x%x\n", AddrSize[Index]);
     DataPtr += GAS_LENGTH;
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/6] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
  2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct() Krzysztof Koch
@ 2019-07-22  7:50 ` Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 3/6] ShellPkg: acpiview: RSDP: Make code consistent with other parsers Krzysztof Koch
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Koch @ 2019-07-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: jaben.carsey, ray.ni, zhichao.gao, Sami.Mujawar, Matteo.Carlini,
	nd

Remove a call to ParseAcpi() responsible for getting the XSDT table
length. This call is not needed because the ACPI table buffer length is
provided as an input argument to the ParseAcpiXsdt() function.

Modify remaining code to use the AcpiTableLength argument of the
ParseAcpiXsdt() function instead of a global static variable.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---

Notes:
    v1:
    - remove redundant ParseAcpi() call [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
index 4196168bff47d70c67f79f3fc1f4cdee302d460e..e39061f8e2612f2cce4aebf51a511b63b703662b 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
@@ -1,7 +1,7 @@
 /** @file
   XSDT table parser
 
-  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Reference(s):
@@ -60,22 +60,12 @@ ParseAcpiXsdt (
   UINTN         EntryIndex;
   CHAR16        Buffer[32];
 
-  // Parse the ACPI header to get the length
-  ParseAcpi (
-    FALSE,
-    0,
-    "XSDT",
-    Ptr,
-    ACPI_DESCRIPTION_HEADER_LENGTH,
-    PARSER_PARAMS (XsdtParser)
-    );
-
   Offset = ParseAcpi (
              Trace,
              0,
              "XSDT",
              Ptr,
-             *AcpiHdrInfo.Length,
+             AcpiTableLength,
              PARSER_PARAMS (XsdtParser)
              );
 
@@ -84,7 +74,7 @@ ParseAcpiXsdt (
   if (Trace) {
     EntryIndex = 0;
     TablePointer = (UINT64*)(Ptr + TableOffset);
-    while (Offset < (*AcpiHdrInfo.Length)) {
+    while (Offset < AcpiTableLength) {
       CONST UINT32* Signature;
       CONST UINT32* Length;
       CONST UINT8*  Revision;
@@ -140,7 +130,7 @@ ParseAcpiXsdt (
   // Process the tables
   Offset = TableOffset;
   TablePointer = (UINT64*)(Ptr + TableOffset);
-  while (Offset < (*AcpiHdrInfo.Length)) {
+  while (Offset < AcpiTableLength) {
     if ((UINT64*)(UINTN)(*TablePointer) != NULL) {
       ProcessAcpiTable ((UINT8*)(UINTN)(*TablePointer));
     }
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/6] ShellPkg: acpiview: RSDP: Make code consistent with other parsers
  2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct() Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 2/6] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call Krzysztof Koch
@ 2019-07-22  7:50 ` Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 4/6] ShellPkg: acpiview: SRAT: Minor code style enhancements Krzysztof Koch
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Koch @ 2019-07-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: jaben.carsey, ray.ni, zhichao.gao, Sami.Mujawar, Matteo.Carlini,
	nd

List ParseAcpi() function arguments one per line in order to make this
function call consistent with ParseAcpi() calls in other ACPI table
parsers.

Also, notify the user that XsdtAddress value of 0 results in RSDP
parsing being terminated and that the XSDT table will not be processed.

This effectively means that no more ACPI tables will be parsed because
of this RSDP table content error.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---

Notes:
    v1:
    - minor code style enhancements [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
index 4bf928139a507d0b8f203ed0cbf0863cc2ec5de5..5a5c4b50c12e6eb0aa0efb1765df7e123f614da3 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c
@@ -129,7 +129,14 @@ ParseAcpiRsdp (
     VerifyChecksum (TRUE, Ptr, AcpiTableLength);
   }
 
-  ParseAcpi (Trace, 0, "RSDP", Ptr, AcpiTableLength, PARSER_PARAMS (RsdpParser));
+  ParseAcpi (
+    Trace,
+    0,
+    "RSDP",
+    Ptr,
+    AcpiTableLength,
+    PARSER_PARAMS (RsdpParser)
+    );
 
   // This code currently supports parsing of XSDT table only
   // and does not parse the RSDT table. Platforms provide the
@@ -137,7 +144,7 @@ ParseAcpiRsdp (
   // Therefore the RSDT should not be used on ARM platforms.
   if ((*XsdtAddress) == 0) {
     IncrementErrorCount ();
-    Print (L"ERROR: XSDT Pointer is not set.\n");
+    Print (L"ERROR: XSDT Pointer is not set. RSDP parsing aborted.\n");
     return;
   }
 
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/6] ShellPkg: acpiview: SRAT: Minor code style enhancements
  2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
                   ` (2 preceding siblings ...)
  2019-07-22  7:50 ` [PATCH v2 3/6] ShellPkg: acpiview: RSDP: Make code consistent with other parsers Krzysztof Koch
@ 2019-07-22  7:50 ` Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 5/6] ShellPkg: acpiview: MADT: Split structure length validation Krzysztof Koch
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Koch @ 2019-07-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: jaben.carsey, ray.ni, zhichao.gao, Sami.Mujawar, Matteo.Carlini,
	nd

Minor changes to the SRAT parser code to conform with the EDKII coding
style and to make it consistent with other ACPI table parsers.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---

Notes:
    v1:
    - minor code style enhancements [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 03d28d52842040e4872e204fc10ae3dba7861936..59c77401eaab32b73a9f83fd4d63785221b3c222 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -206,6 +206,7 @@ ParseAcpiSrat (
              AcpiTableLength,
              PARSER_PARAMS (SratParser)
              );
+
   ResourcePtr = Ptr + Offset;
 
   while (Offset < AcpiTableLength) {
@@ -250,7 +251,7 @@ ParseAcpiSrat (
           ResourcePtr,
           *SratRALength,
           PARSER_PARAMS (SratGicITSAffinityParser)
-        );
+          );
         break;
 
       case EFI_ACPI_6_2_MEMORY_AFFINITY:
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/6] ShellPkg: acpiview: MADT: Split structure length validation
  2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
                   ` (3 preceding siblings ...)
  2019-07-22  7:50 ` [PATCH v2 4/6] ShellPkg: acpiview: SRAT: Minor code style enhancements Krzysztof Koch
@ 2019-07-22  7:50 ` Krzysztof Koch
  2019-07-22  7:50 ` [PATCH v2 6/6] ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation Krzysztof Koch
  2019-07-22  9:11 ` [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Gao, Zhichao
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Koch @ 2019-07-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: jaben.carsey, ray.ni, zhichao.gao, Sami.Mujawar, Matteo.Carlini,
	nd

Split the Interrupt Controller Structure length validation in the
acpiview UEFI shell tool into two logical parts:
1. Ensuring MADT table parser forward progress.
2. Preventing MADT table buffer overruns.

Also, make the condition for infinite loop detection applicable to
all types of Interrupt Controller Structures (for all interrupt models
which can be represented in MADT). Check if the controller length
specified is shorter than the byte size of the first two fields
('Type' and 'Length') present in every valid Interrupt Controller
Structure.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---

Notes:
    v1:
    - split MADT structure length validation [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 30 ++++++++++++++------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index 338295d30e35c366a60505225cf57145a8e73d93..d80ebd1a2bae7a4acffe687ca5ee7b4090f0e223 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -260,16 +260,30 @@ ParseAcpiMadt (
       PARSER_PARAMS (MadtInterruptControllerHeaderParser)
       );
 
-    if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
-        (*MadtInterruptControllerLength < 4)) {
+    // Make sure forward progress is made.
+    if (*MadtInterruptControllerLength < 2) {
       IncrementErrorCount ();
       Print (
-         L"ERROR: Invalid Interrupt Controller Length,"
-          L" Type = %d, Length = %d\n",
-         *MadtInterruptControllerType,
-         *MadtInterruptControllerLength
-         );
-      break;
+        L"ERROR: Structure length is too small: " \
+          L"MadtInterruptControllerLength = %d. " \
+          L"MadtInterruptControllerType = %d. MADT parsing aborted.\n",
+        *MadtInterruptControllerLength,
+        *MadtInterruptControllerType
+        );
+      return;
+    }
+
+    // Make sure the MADT structure lies inside the table
+    if ((Offset + *MadtInterruptControllerLength) > AcpiTableLength) {
+      IncrementErrorCount ();
+      Print (
+        L"ERROR: Invalid MADT structure length. " \
+          L"MadtInterruptControllerLength = %d. " \
+          L"RemainingTableBufferLength = %d. MADT parsing aborted.\n",
+        *MadtInterruptControllerLength,
+        AcpiTableLength - Offset
+        );
+      return;
     }
 
     switch (*MadtInterruptControllerType) {
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 6/6] ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation
  2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
                   ` (4 preceding siblings ...)
  2019-07-22  7:50 ` [PATCH v2 5/6] ShellPkg: acpiview: MADT: Split structure length validation Krzysztof Koch
@ 2019-07-22  7:50 ` Krzysztof Koch
  2019-07-22  9:11 ` [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Gao, Zhichao
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Koch @ 2019-07-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: jaben.carsey, ray.ni, zhichao.gao, Sami.Mujawar, Matteo.Carlini,
	nd

Move Performance Monitoring Counter Group (PMCG) node ID mapping count
validation from the core IORT acpiview parser logic to a dedicated
function. Now, the pointer to the validation function is passed to the
IortNodePmcgParser[] ACPI_PARSER array.

This check does not affect the flow of IORT parsing and is limited to
a single table field in scope, therefore, it is better to keep it away
from the code responsible for traversing the table.

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---

Notes:
    v1:
    - refactor PMCG node mapping count validation [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c | 32 ++++++++++++++------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index 0461205b4f8bc02aa11ab1db1d0deb73bce053b7..7c850b3813d5204775e2cc247cabf42358b25769 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -53,6 +53,28 @@ ValidateItsIdMappingCount (
   }
 }
 
+/**
+  This function validates the ID Mapping array count for the Performance
+  Monitoring Counter Group (PMCG) node.
+
+  @param [in] Ptr     Pointer to the start of the field data.
+  @param [in] Context Pointer to context specific information e.g. this
+                      could be a pointer to the ACPI table header.
+**/
+STATIC
+VOID
+EFIAPI
+ValidatePmcgIdMappingCount (
+  IN UINT8* Ptr,
+  IN VOID*  Context
+  )
+{
+  if (*(UINT32*)Ptr > 1) {
+    IncrementErrorCount ();
+    Print (L"\nERROR: IORT ID Mapping count must not be greater than 1.");
+  }
+}
+
 /**
   This function validates the ID Mapping array offset for the ITS node.
 
@@ -216,7 +238,7 @@ STATIC CONST ACPI_PARSER IortNodeRootComplexParser[] = {
   An ACPI_PARSER array describing the IORT PMCG node.
 **/
 STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
-  PARSE_IORT_NODE_HEADER (NULL, NULL),
+  PARSE_IORT_NODE_HEADER (ValidatePmcgIdMappingCount, NULL),
   {L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
   {L"Overflow interrupt GSIV", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
   {L"Node reference", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
@@ -537,14 +559,6 @@ DumpIortNodePmcg (
   if (*IortIdMappingCount != 0) {
     DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
   }
-
-  if (*IortIdMappingCount > 1) {
-    IncrementErrorCount ();
-    Print (
-      L"ERROR: ID mapping must not be greater than 1. Id Mapping Count =%d\n",
-      *IortIdMappingCount
-      );
-  }
 }
 
 /**
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring
  2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
                   ` (5 preceding siblings ...)
  2019-07-22  7:50 ` [PATCH v2 6/6] ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation Krzysztof Koch
@ 2019-07-22  9:11 ` Gao, Zhichao
  6 siblings, 0 replies; 8+ messages in thread
From: Gao, Zhichao @ 2019-07-22  9:11 UTC (permalink / raw)
  To: Krzysztof Koch, devel@edk2.groups.io
  Cc: Carsey, Jaben, Ni, Ray, Sami.Mujawar@arm.com,
	Matteo.Carlini@arm.com, nd@arm.com

Series: Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>

> -----Original Message-----
> From: Krzysztof Koch [mailto:krzysztof.koch@arm.com]
> Sent: Monday, July 22, 2019 3:50 PM
> To: devel@edk2.groups.io
> Cc: Carsey, Jaben <jaben.carsey@intel.com>; Ni, Ray <ray.ni@intel.com>; Gao,
> Zhichao <zhichao.gao@intel.com>; Sami.Mujawar@arm.com;
> Matteo.Carlini@arm.com; nd@arm.com
> Subject: [PATCH v2 0/6] Acpiview table parsers code style enhancements and
> refactoring
> 
> This set of patches consists of a number of changes which make the code
> structure consistent across the existing ACPI table parsers. These are all
> refactoring changes which do not modify the existing functionality of the
> acpiview UEFI shell tool.
> 
> Changes can be seen at:
> https://github.com/KrzysztofKoch1/edk2/tree/612_acpiview_code_style_enhan
> ce_v2
> 
> Krzysztof Koch (6):
>   ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct()
>   ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call
>   ShellPkg: acpiview: RSDP: Make code consistent with other parsers
>   ShellPkg: acpiview: SRAT: Minor code style enhancements
>   ShellPkg: acpiview: MADT: Split structure length validation
>   ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation
> 
>  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c              | 26
> +++++++++-------
>  ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h              |  8
> +++--
>  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c |
> 2 +-  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
> | 32 ++++++++++++++------
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c |
> 30 +++++++++++++-----
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c |
> 11 +++++--
> ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c |  3
> +-  ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
> | 18 +++--------
>  8 files changed, 82 insertions(+), 48 deletions(-)
> 
> --
> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-22  9:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-22  7:50 [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Krzysztof Koch
2019-07-22  7:50 ` [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct() Krzysztof Koch
2019-07-22  7:50 ` [PATCH v2 2/6] ShellPkg: acpiview: XSDT: Remove redundant ParseAcpi() call Krzysztof Koch
2019-07-22  7:50 ` [PATCH v2 3/6] ShellPkg: acpiview: RSDP: Make code consistent with other parsers Krzysztof Koch
2019-07-22  7:50 ` [PATCH v2 4/6] ShellPkg: acpiview: SRAT: Minor code style enhancements Krzysztof Koch
2019-07-22  7:50 ` [PATCH v2 5/6] ShellPkg: acpiview: MADT: Split structure length validation Krzysztof Koch
2019-07-22  7:50 ` [PATCH v2 6/6] ShellPkg: acpiview: IORT: Refactor PMCG node mapping count validation Krzysztof Koch
2019-07-22  9:11 ` [PATCH v2 0/6] Acpiview table parsers code style enhancements and refactoring Gao, Zhichao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox