public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 1/9] ShellPkg: Add AcpiView validators readme
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
@ 2021-12-15 17:19 ` Chris Jones
  2021-12-15 17:19 ` [PATCH v1 2/9] ShellPkg: Replace SBBR validation option with generic one Chris Jones
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Add readme to explain the function and use of the new AcpiView validator
framework.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Readme.md | 113 ++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Readme.md b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Readme.md
new file mode 100644
index 0000000000000000000000000000000000000000..ed8c29f00a3f99f272654e5dcae5d067eae574ed
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Readme.md
@@ -0,0 +1,113 @@
+# Validators Framework
+
+The validators framework allows for simple and easy post-parsing validation to
+take place. This framework gives AcpiView the ability to perform more complex
+validations by allowing validators access to ACPI data from all parsed tables
+at the same time.
+
+This framework is intended to be both generic and extensible to allow anyone to
+create their own validators with minimal changes needed to parsers and the
+AcpiView internal application code.
+
+## Running ACPI Validators
+
+The ACPI standard validator is always run after the parsing stage in AcpiView.
+Additional validators can also be run by using the command line flag
+`-r ValidatorId`, more information on this flag can be found in the AcpiView
+help string (`acpiview -?`).
+
+## Cross-table Validations
+
+The validators framework provides the ability to perform more complex
+validations, on ACPI data, than single field validation. By storing the data
+during the parsing stage it can later be used to perform validations using data
+from multiple tables. This is especially useful with ACPI fields of variable
+length as the storage and validation is handled dynamically at runtime.
+
+# ACPI Data Store
+
+The ACPI data store allows for any type of ACPI data to be stored and later
+accessed via the relevant methods in `AcpiDataStore.h`.
+
+`StoreAcpiMetaData(ListType, NodeType, Ptr, Length)`:
+   Called during the parsing stage to store relevant ACPI meta data as needed
+   for validation later. Each call stores one "packet" of meta data, of the
+   given length, in a linked list of the given ListType. NodeType can be used
+   to store nodes of different types within the same linked list.
+
+`GetMetaDataListHead(Type, Node)`:
+   Called during the validation stage to retrieve ACPI meta data stored in the
+   ACPI data store. The head of a linked list is returned that contains all
+   stored meta data of the given type.
+
+   Note: `GetMetaDataListHead()` returns the *head* of a linked list of meta
+   data. This head node is created upon initialisation and does not contain
+   any meta data itself, therefore
+   `(META_DATA_NODE*)GetFirstNode (&ListHead->Link);` should be used before
+   trying to dereference any meta data.
+
+## Example usage
+
+An example parser storing an ACPI table in the data store.
+```C
+// Parser.c
+
+// Our example table signature to store. This could be any data type as it will
+// be casted to VOID* in the data store.
+UINT32 Signature = SIGNATURE_32('A', 'B', 'C', 'D');
+
+// Store our table signature into our ACPI data store.
+Status = StoreAcpiMetaData (
+           MetaDataExampleSig,
+           MetaDataExampleNodeSig,
+           &Signature,
+           sizeof (Siganture)
+           );
+if (EFI_ERROR (Status)) {
+   return Status;
+}
+```
+
+An example validator retrieving and using meta data from the ACPI data store:
+```C
+// Validator.c
+
+META_DATA_NODE *ListHead;
+META_DATA_NODE *Node;
+
+// Retrieve a list of installed tables from the data store.
+Status = GetMetaDataListHead (MetaDataInstalledTables, &ListHead);
+if (EFI_ERROR (Status)) {
+   return Status;
+}
+
+// The first node is just a list head and contains no data, get the first
+// "real" node in the list.
+Node = (META_DATA_NODE*)GetFirstNode (&ListHead->Link);
+
+// Iterate through nodes and perform some validations with the data.
+while (!IsNull (&ListHead->Link, &Node->Link)) {
+   // ...
+}
+```
+
+## Structure
+
+The ACPI data store structure is an array containing linked lists of related
+META_DATA_NODE's. These nodes are grouped according to their META_DATA_TYPE
+with each META_DATA_TYPE pertaining to one linked list of META_DATA_NODEs.
+
+Each linked list of meta nodes is implemented via the standard doubly linked
+list implementation in MdePkg. This allows any of the standard traversal,
+query and accessing functions located in `MdePkg/Library/BaseLib/LinkedList.c`
+to be used on the linked list returned from calls to `GetMetaDataListHead()`.
+
+An example ACPI data store structure can be seen here:
+
+|---------------------------|
+|     MetaDataPpttProcs     | ---> Proc0 ---> Proc1
+|---------------------------|
+|     MetaDataMadtGicC      | ---> Proc0 ---> Proc1
+|---------------------------|
+|  MetaDataInstalledTables  | ---> "RSDP" ---> "XSDT" ---> "HMAT" ---> "PPTT"
+|---------------------------|
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 2/9] ShellPkg: Replace SBBR validation option with generic one
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
  2021-12-15 17:19 ` [PATCH v1 1/9] ShellPkg: Add AcpiView validators readme Chris Jones
@ 2021-12-15 17:19 ` Chris Jones
  2021-12-15 17:19 ` [PATCH v1 3/9] ShellPkg: Add post parsing validation framework Chris Jones
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

To facilitate the change to using generic validators, replace old SBBR
mandatory table validation config options with a more generic validator
config option.

As generic validators have not been implemented yet, simply assert
if trying to run a validator.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c             |  7 ---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c                    | 27 +++-------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c              | 52 ++++++++++----------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h              | 36 +++++++-------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c | 12 ++---
 5 files changed, 58 insertions(+), 76 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
index 75b949429ec9d22026147900be591cfdc94ead44..381651ca3af75ab777ccff596ea17fb39be629bc 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
@@ -227,13 +227,6 @@ ProcessAcpiTable (
     }
   }
 
- #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (GetMandatoryTableValidate ()) {
-    ArmSbbrIncrementTableCount (*AcpiTableSignature);
-  }
-
- #endif
-
   Status = GetParser (*AcpiTableSignature, &ParserProc);
   if (EFI_ERROR (Status)) {
     // No registered parser found, do default handling.
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index 9cdfcb3fae2aa85d3ed3835ae90f5230f685e0fa..8798410c05c03b98814b0c211d66287cbb6ef0e8 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
+  Copyright (c) 2016 - 2021, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Glossary:
@@ -23,10 +23,6 @@
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
 
-#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  #include "Arm/SbbrValidator.h"
-#endif
-
 STATIC UINT32  mTableCount;
 STATIC UINT32  mBinTableCount;
 
@@ -205,6 +201,7 @@ AcpiView (
   PARSE_ACPI_TABLE_PROC    RsdpParserProc;
   BOOLEAN                  Trace;
   SELECTED_ACPI_TABLE      *SelectedTable;
+  UINTN                    ValidatorId;
 
   //
   // set local variables to suppress incorrect compiler/analyzer warnings
@@ -250,13 +247,6 @@ AcpiView (
       return EFI_UNSUPPORTED;
     }
 
- #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-    if (GetMandatoryTableValidate ()) {
-      ArmSbbrResetTableCounts ();
-    }
-
- #endif
-
     // The RSDP length is 4 bytes starting at offset 20
     RsdpLength = *(UINT32 *)(RsdpPtr + RSDP_LENGTH_OFFSET);
 
@@ -284,13 +274,6 @@ AcpiView (
     return EFI_NOT_FOUND;
   }
 
- #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (GetMandatoryTableValidate ()) {
-    ArmSbbrReqsValidate ((ARM_SBBR_VERSION)GetMandatoryTableSpec ());
-  }
-
- #endif
-
   ReportOption = GetReportOption ();
   if (ReportTableList != ReportOption) {
     if (((ReportSelected == ReportOption)  ||
@@ -301,6 +284,12 @@ AcpiView (
     } else if (GetConsistencyChecking () &&
                (ReportDumpBinFile != ReportOption))
     {
+      // Run additional validators from command line args
+      ValidatorId = GetValidatorId ();
+      if (GetValidatorStatus () && (ValidatorId != 0)) {
+        ASSERT (0);   // Validators not implemented yet
+      }
+
       OriginalAttribute = gST->ConOut->Mode->Attribute;
 
       Print (L"\nTable Statistics:\n");
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c
index 8f6823f64b08f88a3cbe6ac01b2fc14e64423c75..e9a838812dbc5fc20fdf9ae7371e90f559f4ee2b 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c
@@ -1,7 +1,7 @@
 /** @file
   State and accessors for 'acpiview' configuration.
 
-  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.<BR>
+  Copyright (c) 2016 - 2021, ARM Limited. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -14,8 +14,8 @@
 STATIC BOOLEAN         mConsistencyCheck;
 STATIC BOOLEAN         mColourHighlighting;
 STATIC EREPORT_OPTION  mReportType;
-STATIC BOOLEAN         mMandatoryTableValidate;
-STATIC UINTN           mMandatoryTableSpec;
+STATIC BOOLEAN         mValidatorStatus;
+STATIC UINTN           mValidatorId;
 
 // User selection of which ACPI table should be checked
 SELECTED_ACPI_TABLE  mSelectedAcpiTable;
@@ -34,8 +34,8 @@ AcpiConfigSetDefaults (
   mSelectedAcpiTable.Name  = NULL;
   mSelectedAcpiTable.Found = FALSE;
   mConsistencyCheck        = TRUE;
-  mMandatoryTableValidate  = FALSE;
-  mMandatoryTableSpec      = 0;
+  mValidatorStatus         = FALSE;
+  mValidatorId             = 0;
 }
 
 /**
@@ -190,59 +190,59 @@ SetReportOption (
 }
 
 /**
-  This function returns the ACPI table requirements validation flag.
+  Return the ValidatorStatus flag.
 
-  @retval TRUE Check for mandatory table presence should be performed.
-**/
+  @retval TRUE   Validator should be run.
+  @retval FALSE  Validator should not be run.
+ **/
 BOOLEAN
 EFIAPI
-GetMandatoryTableValidate (
+GetValidatorStatus (
   VOID
   )
 {
-  return mMandatoryTableValidate;
+  return mValidatorStatus;
 }
 
 /**
-  This function sets the ACPI table requirements validation flag.
+  Set the ValidatorStatus flag.
 
-  @param [in] Validate Enable/Disable ACPI table requirements validation.
+  @param [in] Status  Enable (True)/Disable (False) running the optional
+                      Validator.
 **/
 VOID
 EFIAPI
-SetMandatoryTableValidate (
-  BOOLEAN  Validate
+SetValidatorStatus (
+  BOOLEAN  Status
   )
 {
-  mMandatoryTableValidate = Validate;
+  mValidatorStatus = Status;
 }
 
 /**
-  This function returns the identifier of specification to validate ACPI table
-  requirements against.
+  Return the ID of validator to run against the parsed ACPI tables.
 
-  @return ID of specification listing mandatory tables.
+  @return ID of validator to run.
 **/
 UINTN
 EFIAPI
-GetMandatoryTableSpec (
+GetValidatorId (
   VOID
   )
 {
-  return mMandatoryTableSpec;
+  return mValidatorId;
 }
 
 /**
-  This function sets the identifier of specification to validate ACPI table
-  requirements against.
+  Set the ID of the validator to run against the parsed ACPI tables.
 
-  @param [in] Spec ID of specification listing mandatory tables.
+  @param [in] ValidatorId  ID of validator.
 **/
 VOID
 EFIAPI
-SetMandatoryTableSpec (
-  UINTN  Spec
+SetValidatorId (
+  UINTN  ValidatorId
   )
 {
-  mMandatoryTableSpec = Spec;
+  mValidatorId = ValidatorId;
 }
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h
index c58755bf1def3fe778994ba30f598d831e0f1aa6..c6b1cf38cdd8f653b2ea04479aa625be1393762b 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h
@@ -1,7 +1,7 @@
 /** @file
   Header file for 'acpiview' configuration.
 
-  Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.<BR>
+  Copyright (c) 2016 - 2021, ARM Limited. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
@@ -53,49 +53,49 @@ SetConsistencyChecking (
   );
 
 /**
-  This function returns the ACPI table requirements validation flag.
+  Return the ValidatorStatus flag.
 
-  @retval TRUE Check for mandatory table presence should be performed.
-**/
+  @retval TRUE   Validator should be run.
+  @retval FALSE  Validator should not be run.
+ **/
 BOOLEAN
 EFIAPI
-GetMandatoryTableValidate (
+GetValidatorStatus (
   VOID
   );
 
 /**
-  This function sets the ACPI table requirements validation flag.
+  Set the ValidatorStatus flag.
 
-  @param [in] Validate Enable/Disable ACPI table requirements validation.
+  @param [in] Status  Enable (True)/Disable (False) running the optional
+                      Validator.
 **/
 VOID
 EFIAPI
-SetMandatoryTableValidate (
-  BOOLEAN  Validate
+SetValidatorStatus (
+  BOOLEAN  Status
   );
 
 /**
-  This function returns the identifier of specification to validate ACPI table
-  requirements against.
+  Return the ID of validator to run against the parsed ACPI tables.
 
-  @return ID of specification listing mandatory tables.
+  @return ID of validator to run.
 **/
 UINTN
 EFIAPI
-GetMandatoryTableSpec (
+GetValidatorId (
   VOID
   );
 
 /**
-  This function sets the identifier of specification to validate ACPI table
-  requirements against.
+  Set the ID of the validator to run against the parsed ACPI tables.
 
-  @param [in] Spec ID of specification listing mandatory tables.
+  @param [in] ValidatorId  ID of validator.
 **/
 VOID
 EFIAPI
-SetMandatoryTableSpec (
-  UINTN  Spec
+SetValidatorId (
+  UINTN  ValidatorId
   );
 
 /**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
index 09bdddb56e5bd70dec44bdbdcba88373f93daa66..15d2727ed13b66785b6c1078f214611b29aefd40 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
@@ -199,7 +199,7 @@ ShellCommandRunAcpiView (
   LIST_ENTRY         *Package;
   CHAR16             *ProblemParam;
   SHELL_FILE_HANDLE  TmpDumpFileHandle;
-  CONST CHAR16       *MandatoryTableSpecStr;
+  CONST CHAR16       *ValidatorIdStr;
   CONST CHAR16       *SelectedTableName;
 
   // Set configuration defaults
@@ -306,12 +306,12 @@ ShellCommandRunAcpiView (
       // Surpress consistency checking if requested
       SetConsistencyChecking (!ShellCommandLineGetFlag (Package, L"-q"));
 
-      // Evaluate the parameters for mandatory ACPI table presence checks
-      SetMandatoryTableValidate (ShellCommandLineGetFlag (Package, L"-r"));
-      MandatoryTableSpecStr = ShellCommandLineGetValue (Package, L"-r");
+      // Evaluate the parameters for running validators
+      SetValidatorStatus (ShellCommandLineGetFlag (Package, L"-r"));
+      ValidatorIdStr = ShellCommandLineGetValue (Package, L"-r");
 
-      if (MandatoryTableSpecStr != NULL) {
-        SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr));
+      if (ValidatorIdStr != NULL) {
+        SetValidatorId (ShellStrToUintn (ValidatorIdStr));
       }
 
       if (ShellCommandLineGetFlag (Package, L"-l")) {
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 3/9] ShellPkg: Add post parsing validation framework
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
  2021-12-15 17:19 ` [PATCH v1 1/9] ShellPkg: Add AcpiView validators readme Chris Jones
  2021-12-15 17:19 ` [PATCH v1 2/9] ShellPkg: Replace SBBR validation option with generic one Chris Jones
@ 2021-12-15 17:19 ` Chris Jones
  2021-12-15 17:19 ` [PATCH v1 4/9] ShellPkg: Add ACPI data store Chris Jones
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Add the framework for running generic post parsing validations. Included
is an example ACPI validator that will run validations on ACPI tables
that are applicable to all platforms. Currently no validations are
implemented in this validator however it will be called from the main
AcpiView.c application.

Also make AcpiViewConfig use the new VALIDATOR_ID enum when setting and
getting ValidatorId.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c                                      |  8 ++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c                                | 14 ++++--
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h                                |  6 ++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c                   | 10 +++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf                 |  3 ++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c | 19 +++++++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c                     | 52 +++++++++++++++++++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h                     | 53 ++++++++++++++++++++
 8 files changed, 156 insertions(+), 9 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index 8798410c05c03b98814b0c211d66287cbb6ef0e8..d4d5d907f613589c400544533e950460eed2ce3f 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -22,6 +22,7 @@
 #include "AcpiTableParser.h"
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
+#include "Validators/AcpiValidation.h"
 
 STATIC UINT32  mTableCount;
 STATIC UINT32  mBinTableCount;
@@ -284,10 +285,13 @@ AcpiView (
     } else if (GetConsistencyChecking () &&
                (ReportDumpBinFile != ReportOption))
     {
+      // Always run the ACPI validator
+      RunValidator (ValidatorIdAcpiStandard);
+
       // Run additional validators from command line args
       ValidatorId = GetValidatorId ();
-      if (GetValidatorStatus () && (ValidatorId != 0)) {
-        ASSERT (0);   // Validators not implemented yet
+      if (GetValidatorStatus () && (ValidatorId != ValidatorIdAcpiStandard)) {
+        RunValidator (ValidatorId);
       }
 
       OriginalAttribute = gST->ConOut->Mode->Attribute;
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c
index e9a838812dbc5fc20fdf9ae7371e90f559f4ee2b..98032b7c52eb9125ad2f2fd8c395b8e823edd428 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.c
@@ -15,7 +15,7 @@ STATIC BOOLEAN         mConsistencyCheck;
 STATIC BOOLEAN         mColourHighlighting;
 STATIC EREPORT_OPTION  mReportType;
 STATIC BOOLEAN         mValidatorStatus;
-STATIC UINTN           mValidatorId;
+STATIC VALIDATOR_ID    mValidatorId;
 
 // User selection of which ACPI table should be checked
 SELECTED_ACPI_TABLE  mSelectedAcpiTable;
@@ -35,7 +35,7 @@ AcpiConfigSetDefaults (
   mSelectedAcpiTable.Found = FALSE;
   mConsistencyCheck        = TRUE;
   mValidatorStatus         = FALSE;
-  mValidatorId             = 0;
+  mValidatorId             = ValidatorIdAcpiStandard;
 }
 
 /**
@@ -224,7 +224,7 @@ SetValidatorStatus (
 
   @return ID of validator to run.
 **/
-UINTN
+VALIDATOR_ID
 EFIAPI
 GetValidatorId (
   VOID
@@ -238,11 +238,17 @@ GetValidatorId (
 
   @param [in] ValidatorId  ID of validator.
 **/
-VOID
+EFI_STATUS
 EFIAPI
 SetValidatorId (
   UINTN  ValidatorId
   )
 {
+  if (ValidatorId >= ValidatorIdMax) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   mValidatorId = ValidatorId;
+
+  return EFI_SUCCESS;
 }
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h
index c6b1cf38cdd8f653b2ea04479aa625be1393762b..9103973db240b7425d9293bd5ab7cfe7851f7aff 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewConfig.h
@@ -8,6 +8,8 @@
 #ifndef ACPI_VIEW_CONFIG_H_
 #define ACPI_VIEW_CONFIG_H_
 
+#include "Validators/AcpiValidation.h"
+
 /**
   This function returns the colour highlighting status.
 
@@ -81,7 +83,7 @@ SetValidatorStatus (
 
   @return ID of validator to run.
 **/
-UINTN
+VALIDATOR_ID
 EFIAPI
 GetValidatorId (
   VOID
@@ -92,7 +94,7 @@ GetValidatorId (
 
   @param [in] ValidatorId  ID of validator.
 **/
-VOID
+EFI_STATUS
 EFIAPI
 SetValidatorId (
   UINTN  ValidatorId
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
index 15d2727ed13b66785b6c1078f214611b29aefd40..0032dda6aee13dad7ba9e1c22b204cf374eb8037 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
@@ -311,7 +311,15 @@ ShellCommandRunAcpiView (
       ValidatorIdStr = ShellCommandLineGetValue (Package, L"-r");
 
       if (ValidatorIdStr != NULL) {
-        SetValidatorId (ShellStrToUintn (ValidatorIdStr));
+        Status = SetValidatorId (ShellStrToUintn (ValidatorIdStr));
+        if (EFI_ERROR (Status)) {
+          ShellStatus = SHELL_INVALID_PARAMETER;
+          Print (
+            L"ERROR: ValidatorId %d not recognised.\n",
+            ShellStrToUintn (ValidatorIdStr)
+            );
+          goto Done;
+        }
       }
 
       if (ShellCommandLineGetFlag (Package, L"-l")) {
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
index 63fc5a1281a894841dac704484c3d4f9481edb46..245ccc811e199ebc511a42989a2024433cbb1a84 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
@@ -49,6 +49,9 @@ [Sources.common]
   Parsers/Srat/SratParser.c
   Parsers/Ssdt/SsdtParser.c
   Parsers/Xsdt/XsdtParser.c
+  Validators/AcpiValidation.c
+  Validators/AcpiValidation.h
+  Validators/AcpiStandard/AcpiStandardValidator.c
   UefiShellAcpiViewCommandLib.c
   UefiShellAcpiViewCommandLib.uni
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c
new file mode 100644
index 0000000000000000000000000000000000000000..d625c67321a53b8ad0569d98b9071556157394f4
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c
@@ -0,0 +1,19 @@
+/** @file
+  ACPI validations.
+
+  Copyright (c) 2021, Arm Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+/**
+  Entry point for validator, used to run platform agnostic ACPI validations.
+**/
+VOID
+EFIAPI
+AcpiStandardValidate (
+  VOID
+  )
+{
+  // Validations not implemented yet.
+  return;
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c
new file mode 100644
index 0000000000000000000000000000000000000000..8e12e19f2b67e1c4305585ed1384f82c401ec49e
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c
@@ -0,0 +1,52 @@
+/** @file
+  ACPI post-parsing validation framework.
+
+  Copyright (c) 2021, Arm Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/PrintLib.h>
+#include <Library/UefiLib.h>
+#include "AcpiValidation.h"
+
+/**
+  List of all validators that can be run.
+**/
+ACPI_VALIDATOR  mValidatorList[] = {
+  { ValidatorIdAcpiStandard, AcpiStandardValidate }
+};
+
+/**
+  Run the validator with the given ValidatorId.
+
+  @param [in] ValidatorId  The ID of the validator to run.
+**/
+VOID
+EFIAPI
+RunValidator (
+  IN UINTN  ValidatorId
+  )
+{
+  ACPI_VALIDATOR  *Validator;
+
+  if (ValidatorId >= ValidatorIdMax) {
+    Print (
+      L"\nValidatorId is not recognised." \
+      L" ValidatorId = %d.",
+      ValidatorId
+      );
+    return;
+  }
+
+  Validator = &mValidatorList[ValidatorId];
+  if ((Validator == NULL) || (Validator->Id != ValidatorId)) {
+    Print (
+      L"\nValidator cannot be retrieved." \
+      L" ValidatorId = %d.",
+      ValidatorId
+      );
+    return;
+  }
+
+  Validator->ValidatorProc ();
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h
new file mode 100644
index 0000000000000000000000000000000000000000..b7c5512ec673318ba2f15a8b986d33bdea6ec458
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h
@@ -0,0 +1,53 @@
+/** @file
+  Header file for post-parsing APCI validation.
+
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef ACPI_VALIDATION_H_
+#define ACPI_VALIDATION_H_
+
+/**
+  ID's for all known validators.
+**/
+typedef enum {
+  ValidatorIdAcpiStandard = 0,     ///< Platform agnostic ACPI spec checks.
+  ValidatorIdMax          = 1
+} VALIDATOR_ID;
+
+/**
+  A function pointer to the entry point of a validator.
+**/
+typedef VOID (EFIAPI *EDKII_ACPI_VALIDATOR_PROC)(VOID);
+
+/**
+  A validator is made up of an ID and function pointer to the validators entry
+  point.
+**/
+typedef struct AcpiValidator {
+  VALIDATOR_ID                 Id;
+  EDKII_ACPI_VALIDATOR_PROC    ValidatorProc;
+} ACPI_VALIDATOR;
+
+/**
+  Run the validator with the given ValidatorId.
+
+  @param [in] ValidatorId  The ID of the validator to run.
+**/
+VOID
+EFIAPI
+RunValidator (
+  IN UINTN  ValidatorId
+  );
+
+/**
+  Definition in Acpi/AcpiValidator.c
+**/
+VOID
+EFIAPI
+AcpiStandardValidate (
+  VOID
+  );
+
+#endif
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 4/9] ShellPkg: Add ACPI data store
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
                   ` (2 preceding siblings ...)
  2021-12-15 17:19 ` [PATCH v1 3/9] ShellPkg: Add post parsing validation framework Chris Jones
@ 2021-12-15 17:19 ` Chris Jones
  2021-12-15 17:19 ` [PATCH v1 5/9] ShellPkg: Store MADT and PPTT processor data Chris Jones
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Add a store for useful ACPI data that can be used in validation. This
data will be collected from the parsers, stored in the data store and
then can be accessed by validators once all parsing is complete.

The data is stored dynamically as nodes in a linked list that is
accessed by META_DATA_TYPE.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c                      |   6 +
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf |   2 +
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.c      | 179 ++++++++++++++++++++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h      | 101 +++++++++++
 4 files changed, 288 insertions(+)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index d4d5d907f613589c400544533e950460eed2ce3f..a8e0342591931ea3c91e18a6c5cdfa23073b1dcc 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -23,6 +23,7 @@
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
 #include "Validators/AcpiValidation.h"
+#include "Validators/AcpiDataStore.h"
 
 STATIC UINT32  mTableCount;
 STATIC UINT32  mBinTableCount;
@@ -218,6 +219,9 @@ AcpiView (
   ResetErrorCount ();
   ResetWarningCount ();
 
+  // Initialise the ACPI data store
+  InitAcpiDataStore ();
+
   // Retrieve the user selection of ACPI table to process
   GetSelectedAcpiTable (&SelectedTable);
 
@@ -294,6 +298,8 @@ AcpiView (
         RunValidator (ValidatorId);
       }
 
+      FreeAcpiDataStore ();
+
       OriginalAttribute = gST->ConOut->Mode->Attribute;
 
       Print (L"\nTable Statistics:\n");
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
index 245ccc811e199ebc511a42989a2024433cbb1a84..04913451289ebaf013e8290e46b462a554c9d825 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
@@ -51,6 +51,8 @@ [Sources.common]
   Parsers/Xsdt/XsdtParser.c
   Validators/AcpiValidation.c
   Validators/AcpiValidation.h
+  Validators/AcpiDataStore.c
+  Validators/AcpiDataStore.h
   Validators/AcpiStandard/AcpiStandardValidator.c
   UefiShellAcpiViewCommandLib.c
   UefiShellAcpiViewCommandLib.uni
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.c
new file mode 100644
index 0000000000000000000000000000000000000000..3a89e814d2b2e8761cb4ea6567aa941800dea96b
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.c
@@ -0,0 +1,179 @@
+/** @file
+  Storing and accessing ACPI data collected from parsers.
+
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <IndustryStandard/Acpi.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include "AcpiDataStore.h"
+
+STATIC META_DATA_NODE  mAcpiData[MetaDataMax];
+
+/**
+  Initialise the ACPI data store.
+**/
+VOID
+EFIAPI
+InitAcpiDataStore (
+  VOID
+  )
+{
+  UINTN  Index;
+
+  for (Index = 0; Index < MetaDataMax; Index++) {
+    InitializeListHead (&mAcpiData[Index].Link);
+  }
+}
+
+/**
+  Return the number of meta data nodes in a linked list of meta data.
+
+  @param [in]  Type      META_DATA_TYPE of data to get length of.
+  @param [out] Length    Length of the linked list.
+
+  @retval EFI_NOT_FOUND  ACPI data with the given type cannot be found.
+  @retval EFI_SUCCESS    Successfully returned the length of the linked list.
+**/
+EFI_STATUS
+EFIAPI
+GetMetaDataCount (
+  IN META_DATA_TYPE  Type,
+  OUT UINTN          *Length
+  )
+{
+  META_DATA_NODE  *Node;
+
+  *Length = 0;
+
+  if (Type >= MetaDataMax) {
+    Print (L"ERROR: Meta data type is not recognised.\n");
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Node = (META_DATA_NODE *)GetFirstNode (&mAcpiData[Type].Link);
+
+  while (!IsNull (&mAcpiData[Type].Link, &Node->Link)) {
+    (*Length)++;
+    Node = (META_DATA_NODE *)GetNextNode (&mAcpiData[Type].Link, &Node->Link);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get ACPI meta data of the given type.
+
+  @param [in]  Type        META_DATA_TYPE of data to return.
+  @param [out] ListHead    The head of a linked list of META_DATA_NODE's.
+
+  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
+  @retval EFI_NOT_FOUND          ACPI data with the given type cannot be found.
+  @retval EFI_SUCCESS            Successfully returned the desired list of Nodes.
+**/
+EFI_STATUS
+EFIAPI
+GetMetaDataListHead (
+  IN  META_DATA_TYPE  Type,
+  OUT META_DATA_NODE  **ListHead
+  )
+{
+  if (Type >= MetaDataMax) {
+    Print (L"ERROR: Meta data type is not recognised.\n");
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (ListHead == NULL) {
+    Print (L"ERROR: List head is NULL.\n");
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (IsListEmpty (&mAcpiData[Type].Link)) {
+    *ListHead = NULL;
+    return EFI_NOT_FOUND;
+  }
+
+  *ListHead = &mAcpiData[Type];
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Store ACPI meta data as a new node in the data store.
+
+  @param [in] ListType          Type of linked list to store the data in.
+  @param [in] NodeType          Type to give to the node that stores the data.
+  @param [in] Ptr               Pointer to the data to store.
+  @param [in] Length            Length of the data being stored (Ptr).
+
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources to allocate the data.
+  @retval EFI_SUCCESS           Successfully stored the data.
+**/
+EFI_STATUS
+EFIAPI
+StoreAcpiMetaData (
+  IN META_DATA_TYPE  ListType,
+  IN META_DATA_TYPE  NodeType,
+  IN VOID            *Ptr,
+  IN UINT8           Length
+  )
+{
+  META_DATA_NODE  *Node;
+  UINT8           *Data;
+
+  if ((ListType >= MetaDataMax) || (NodeType >= MetaDataMax)) {
+    Print (L"ERROR: Meta data type is not recognised.\n");
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Node = AllocateZeroPool (sizeof (META_DATA_NODE));
+  if (Node == NULL) {
+    Print (L"ERROR: Failed to allocate resources for new node.\n");
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  // Allocate and assign memory for the data to be stored.
+  Data = AllocateCopyPool (Length, Ptr);
+  if (Data == NULL) {
+    FreePool (Node);
+    Print (L"ERROR: Failed to allocate resources for node data.\n");
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  // Assign fields.
+  Node->Type   = NodeType;
+  Node->Data   = Data;
+  Node->Length = Length;
+
+  InsertTailList (&mAcpiData[ListType].Link, &Node->Link);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Free all ACPI data currently stored in the data store.
+**/
+VOID
+EFIAPI
+FreeAcpiDataStore (
+  VOID
+  )
+{
+  UINTN           Index;
+  META_DATA_NODE  *Node;
+  META_DATA_NODE  *TmpNode;
+
+  for (Index = 0; Index < MetaDataMax; Index++) {
+    Node = (META_DATA_NODE *)GetFirstNode (&mAcpiData[Index].Link);
+
+    while (!IsNull (&mAcpiData[Index].Link, &Node->Link)) {
+      TmpNode = Node;
+      Node    = (META_DATA_NODE *)RemoveEntryList (&TmpNode->Link);
+      FreePool (TmpNode->Data);
+      FreePool (TmpNode);
+    }
+  }
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h
new file mode 100644
index 0000000000000000000000000000000000000000..dfe45665372bae2516860d6c4e8d360ba88f906c
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h
@@ -0,0 +1,101 @@
+/** @file
+  Header file for storing and accessing ACPI data from parsers.
+
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef ACPI_DATA_STORE_H_
+#define ACPI_DATA_STORE_H_
+
+/**
+  Types of data that can be stored and accessed in the ACPI data store.
+**/
+typedef enum MetaDataType {
+  MetaDataPpttProcs = 0,   ///< List of all PPTT processor structures.
+  MetaDataMadtGicC  = 1,   ///< List of all MADT GICC structures.
+  MetaDataMax
+} META_DATA_TYPE;
+
+/**
+  A node containing data about an ACPI table.
+**/
+typedef struct MetaDataNode {
+  LIST_ENTRY        Link;   ///< Linked list entry.
+  META_DATA_TYPE    Type;   ///< Type of meta data.
+  UINT8             Length; ///< Length of meta data.
+  VOID              *Data;  ///< Pointer to the meta data.
+} META_DATA_NODE;
+
+/**
+  Initialise the ACPI data store.
+**/
+VOID
+EFIAPI
+InitAcpiDataStore (
+  VOID
+  );
+
+/**
+  Return the number of meta data nodes in a linked list of meta data.
+
+  @param [in]  Type      META_DATA_TYPE of data to get length of.
+  @param [out] Length    Length of the linked list.
+
+  @retval EFI_NOT_FOUND  ACPI data with the given type cannot be found.
+  @retval EFI_SUCCESS    Successfully returned the length of the linked list.
+**/
+EFI_STATUS
+EFIAPI
+GetMetaDataCount (
+  IN META_DATA_TYPE  Type,
+  OUT UINTN          *Length
+  );
+
+/**
+  Get ACPI meta data of the given type.
+
+  @param [in]  Type        META_DATA_TYPE of data to return.
+  @param [out] ListHead    The head of a linked list of META_DATA_NODE's.
+
+  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
+  @retval EFI_NOT_FOUND          ACPI data with the given type cannot be found.
+  @retval EFI_SUCCESS            Successfully returned the desired list of Nodes.
+**/
+EFI_STATUS
+EFIAPI
+GetMetaDataListHead (
+  IN  META_DATA_TYPE  Type,
+  OUT META_DATA_NODE  **ListHead
+  );
+
+/**
+  Store ACPI meta data as a new node in the data store.
+
+  @param [in] ListType          Type of linked list to store the data in.
+  @param [in] NodeType          Type to give to the node that stores the data.
+  @param [in] Ptr               Pointer to the data to store.
+  @param [in] Length            Length of the data being stored (Ptr).
+
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources to allocate the data.
+  @retval EFI_SUCCESS           Successfully stored the data.
+**/
+EFI_STATUS
+EFIAPI
+StoreAcpiMetaData (
+  IN META_DATA_TYPE  ListType,
+  IN META_DATA_TYPE  NodeType,
+  IN VOID            *Ptr,
+  IN UINT8           Length
+  );
+
+/**
+  Free all ACPI data currently stored in the data store.
+**/
+VOID
+EFIAPI
+FreeAcpiDataStore (
+  VOID
+  );
+
+#endif
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 5/9] ShellPkg: Store MADT and PPTT processor data
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
                   ` (3 preceding siblings ...)
  2021-12-15 17:19 ` [PATCH v1 4/9] ShellPkg: Add ACPI data store Chris Jones
@ 2021-12-15 17:19 ` Chris Jones
  2021-12-15 17:19 ` [PATCH v1 6/9] ShellPkg: Add processor ID cross table validation Chris Jones
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Store processor data from the MADT and PPTT ACPI tables so that it can
be used for processor ID validation.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c | 23 ++++++++++++++++---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 24 +++++++++++++++++---
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
index aaa68c99f51457050df0c6af39ab5e4912dc729f..837f22abf368449c22e526d0972aed57e4f96443 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
@@ -16,6 +16,7 @@
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
 #include "AcpiViewConfig.h"
+#include "Validators/AcpiDataStore.h"
 #include "MadtParser.h"
 
 // Local Variables
@@ -281,9 +282,10 @@ ParseAcpiMadt (
   IN UINT8    AcpiTableRevision
   )
 {
-  UINT32  Offset;
-  UINT8   *InterruptContollerPtr;
-  UINT32  GICDCount;
+  UINT32      Offset;
+  UINT8       *InterruptContollerPtr;
+  UINT32      GICDCount;
+  EFI_STATUS  Status;
 
   GICDCount = 0;
 
@@ -352,6 +354,21 @@ ParseAcpiMadt (
           *MadtInterruptControllerLength,
           PARSER_PARAMS (GicCParser)
           );
+
+        Status = StoreAcpiMetaData (
+                   MetaDataMadtGicC,
+                   MetaDataMadtGicC,
+                   InterruptContollerPtr,
+                   *MadtInterruptControllerLength
+                   );
+        if (EFI_ERROR (Status)) {
+          Print (
+            L"ERROR: Unable to store GICC type structure." \
+            L"Status = 0x%x.",
+            Status
+            );
+        }
+
         break;
       }
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
index 8d52bb5e4811298ddc45cdaef41150f6ee7819af..3f4158a68779ea164daee839fc2b145c828bb62c 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
@@ -14,6 +14,7 @@
 #include "AcpiParser.h"
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
+#include "Validators/AcpiDataStore.h"
 #include "PpttParser.h"
 
 // Local variables
@@ -370,9 +371,10 @@ DumpProcessorHierarchyNodeStructure (
   IN UINT8  Length
   )
 {
-  UINT32  Offset;
-  UINT32  Index;
-  CHAR16  Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
+  UINT32      Offset;
+  UINT32      Index;
+  CHAR16      Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
+  EFI_STATUS  Status;
 
   Offset = ParseAcpi (
              TRUE,
@@ -383,6 +385,22 @@ DumpProcessorHierarchyNodeStructure (
              PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)
              );
 
+  // Store the data for validation later.
+  Status = StoreAcpiMetaData (
+             MetaDataPpttProcs,
+             MetaDataPpttProcs,
+             Ptr,
+             Length
+             );
+  if (EFI_ERROR (Status)) {
+    Print (
+      L"\nERROR: Unable to store processor type structure." \
+      L" Status = 0x%x.",
+      Status
+      );
+    return;
+  }
+
   // Check if the values used to control the parsing logic have been
   // successfully read.
   if (NumberOfPrivateResources == NULL) {
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 6/9] ShellPkg: Add processor ID cross table validation
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
                   ` (4 preceding siblings ...)
  2021-12-15 17:19 ` [PATCH v1 5/9] ShellPkg: Store MADT and PPTT processor data Chris Jones
@ 2021-12-15 17:19 ` Chris Jones
  2021-12-15 17:19 ` [PATCH v1 7/9] ShellPkg: Add installed tables to parser collection Chris Jones
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Add processor ID cross table validation to the AcpiView global
validator. This validation retrieves MADT and PPTT processor data from
the ACPI data store and then compares the two to ensure that all PPTT
processor ID's are also found in the MADT as specified in ACPI 6.4 Table
5.138 - ACPI Processor ID.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c | 161 +++++++++++++++++++-
 1 file changed, 159 insertions(+), 2 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c
index d625c67321a53b8ad0569d98b9071556157394f4..5656628030867ed4e2b0c6116cd649ea6a949d91 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiStandard/AcpiStandardValidator.c
@@ -5,6 +5,157 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
+#include <Library/PrintLib.h>
+#include <Library/UefiLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include "AcpiParser.h"
+#include "AcpiViewConfig.h"
+#include "AcpiDataStore.h"
+
+/**
+  Test whether Id is unique among the IdList.
+
+  @param [in]  Id          ID to check.
+  @param [in]  IdList      List of already existing IDs.
+  @param [in]  IdListSize  Size of IdList.
+
+  @retval TRUE             Id does not exist in IdList.
+  @retval FALSE            Id already exists in IdList.
+**/
+STATIC
+BOOLEAN
+IsIdUnique (
+  IN CONST UINT32  Id,
+  IN CONST UINT32  *IdList,
+  IN CONST UINT32  IdListSize
+  )
+{
+  UINT32  Index;
+
+  for (Index = 0; Index < IdListSize; Index++) {
+    if (IdList[Index] == Id) {
+      return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+/**
+  Validate that processor ID's match across various ACPI tables.
+
+  @retval EFI_NOT_FOUND          Processor data cannot be found.
+  @retval EFI_INVALID_PARAMETER  Processor ID's are not valid.
+  @retval EFI_SUCCESS            All processor ID's are valid.
+**/
+EFI_STATUS
+EFIAPI
+ValidateProcId (
+  )
+{
+  EFI_STATUS                             Status;
+  META_DATA_NODE                         *PpttListHead;
+  META_DATA_NODE                         *PpttList;
+  META_DATA_NODE                         *MadtListHead;
+  META_DATA_NODE                         *MadtList;
+  UINTN                                  MadtListLength;
+  UINT32                                 *MadtIds;
+  UINTN                                  NodeIndex;
+  EFI_ACPI_6_4_GIC_STRUCTURE             MadtProc;
+  EFI_ACPI_6_4_PPTT_STRUCTURE_PROCESSOR  PpttProc;
+
+  NodeIndex = 0;
+
+  Status = GetMetaDataListHead (MetaDataMadtGicC, &MadtListHead);
+  if (EFI_ERROR (Status)) {
+    if (Status != EFI_NOT_FOUND) {
+      IncrementErrorCount ();
+      Print (
+        L"\nERROR: Cannot get MADT processor list." \
+        L" Status = 0x%x.",
+        Status
+        );
+    }
+
+    return Status;
+  }
+
+  Status = GetMetaDataCount (MetaDataMadtGicC, &MadtListLength);
+  if (EFI_ERROR (Status)) {
+    IncrementErrorCount ();
+    Print (
+      L"\nERROR: Cannot get MADT processor list length." \
+      L" Status = 0x%x.",
+      Status
+      );
+    return Status;
+  }
+
+  Status = GetMetaDataListHead (MetaDataPpttProcs, &PpttListHead);
+  if (EFI_ERROR (Status)) {
+    if (Status != EFI_NOT_FOUND) {
+      IncrementErrorCount ();
+      Print (
+        L"\nERROR: Cannot get PPTT processor list." \
+        L" Status = 0x%x.",
+        Status
+        );
+    }
+
+    return Status;
+  }
+
+  MadtIds = AllocateZeroPool (MadtListLength * sizeof (*MadtIds));
+  if (MadtIds == NULL) {
+    IncrementErrorCount ();
+    Print (L"\nERROR: Failed to allocate resources for MADT ID list.");
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  MadtList = (META_DATA_NODE *)GetFirstNode (&MadtListHead->Link);
+
+  // Extract MADT ID's from structures.
+  while (!IsNull (&MadtListHead->Link, &MadtList->Link)) {
+    MadtProc           = *(EFI_ACPI_6_4_GIC_STRUCTURE *)MadtList->Data;
+    MadtIds[NodeIndex] = MadtProc.AcpiProcessorUid;
+
+    MadtList = (META_DATA_NODE *)GetNextNode (
+                                   &MadtListHead->Link,
+                                   &MadtList->Link
+                                   );
+    NodeIndex++;
+  }
+
+  PpttList = (META_DATA_NODE *)GetFirstNode (&PpttListHead->Link);
+
+  // Compare PPTT ID's against the MADT.
+  while (!IsNull (&PpttListHead->Link, &PpttList->Link)) {
+    PpttProc = *(EFI_ACPI_6_4_PPTT_STRUCTURE_PROCESSOR *)PpttList->Data;
+
+    // Make sure this is a real processor and not a cluster.
+    if (PpttProc.Flags.NodeIsALeaf == EFI_ACPI_6_4_PPTT_NODE_IS_LEAF) {
+      // PpttProc.AcpiProcessorId must be found in our list of MADT ID's.
+      if (IsIdUnique (PpttProc.AcpiProcessorId, MadtIds, MadtListLength)) {
+        IncrementErrorCount ();
+        Print (
+          L"\nERROR: PPTT Processor ID %d is not found in the MADT.",
+          PpttProc.AcpiProcessorId
+          );
+        Status = EFI_INVALID_PARAMETER;
+      }
+    }
+
+    PpttList = (META_DATA_NODE *)GetNextNode (
+                                   &PpttListHead->Link,
+                                   &PpttList->Link
+                                   );
+  }
+
+  FreePool (MadtIds);
+
+  return Status;
+}
+
 /**
   Entry point for validator, used to run platform agnostic ACPI validations.
 **/
@@ -14,6 +165,12 @@ AcpiStandardValidate (
   VOID
   )
 {
-  // Validations not implemented yet.
-  return;
+  EFI_STATUS  Status;
+
+  if (GetReportOption () != ReportSelected) {
+    Status = ValidateProcId ();
+    if (EFI_ERROR (Status)) {
+      Print (L"\nERROR: Validate processor ID failed.\n");
+    }
+  }
 }
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 7/9] ShellPkg: Add installed tables to parser collection
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
                   ` (5 preceding siblings ...)
  2021-12-15 17:19 ` [PATCH v1 6/9] ShellPkg: Add processor ID cross table validation Chris Jones
@ 2021-12-15 17:19 ` Chris Jones
  2021-12-15 17:20 ` [PATCH v1 8/9] ShellPkg: Rewrite SBBR validation Chris Jones
  2021-12-15 17:20 ` [PATCH v1 9/9] ShellPkg: Add validator help string Chris Jones
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Add a new META_DATA_TYPE, "MetaDataInstalledTables" to store the
signatures from tables that have been successfully installed. This is
to allow validation of mandatory ACPI tables that are specified in the
Arm SBBR specification.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c          | 21 ++++++++++++++++++++
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h |  5 +++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
index 381651ca3af75ab777ccff596ea17fb39be629bc..d7717ae3a6c37513f082bf78c63337a1f517bca5 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
@@ -18,6 +18,7 @@
 #include "AcpiTableParser.h"
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
+#include "Validators/AcpiDataStore.h"
 
 #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
   #include "Arm/SbbrValidator.h"
@@ -243,4 +244,24 @@ ProcessAcpiTable (
     *AcpiTableLength,
     *AcpiTableRevision
     );
+
+  // Record that the table has been installed.
+  Status = StoreAcpiMetaData (
+             MetaDataInstalledTables,
+             MetaDataInstalledTables,
+             (UINT32 *)AcpiTableSignature,
+             sizeof (AcpiTableSignature)
+             );
+  if (EFI_ERROR (Status)) {
+    Print (
+      L"\nERROR: Unable to store %c%c%c%c signature." \
+      L" Status = 0x%x.",
+      SignaturePtr[0],
+      SignaturePtr[1],
+      SignaturePtr[2],
+      SignaturePtr[3],
+      Status
+      );
+    return;
+  }
 }
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h
index dfe45665372bae2516860d6c4e8d360ba88f906c..a2516acb0ca98dc473484f738d9bf2ae133c039f 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiDataStore.h
@@ -12,8 +12,9 @@
   Types of data that can be stored and accessed in the ACPI data store.
 **/
 typedef enum MetaDataType {
-  MetaDataPpttProcs = 0,   ///< List of all PPTT processor structures.
-  MetaDataMadtGicC  = 1,   ///< List of all MADT GICC structures.
+  MetaDataPpttProcs       = 0,  ///< List of all PPTT processor structures.
+  MetaDataMadtGicC        = 1,  ///< List of all MADT GICC structures.
+  MetaDataInstalledTables = 2,  ///< Signatures of all installed ACPI tables.
   MetaDataMax
 } META_DATA_TYPE;
 
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 8/9] ShellPkg: Rewrite SBBR validation
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
                   ` (6 preceding siblings ...)
  2021-12-15 17:19 ` [PATCH v1 7/9] ShellPkg: Add installed tables to parser collection Chris Jones
@ 2021-12-15 17:20 ` Chris Jones
  2021-12-15 17:20 ` [PATCH v1 9/9] ShellPkg: Add validator help string Chris Jones
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:20 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Rewrite SBBR validation into the validator framework. This decouples the
SBBR validations from the internal workings of the Acpiview application.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h                  | 91 ------------------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf      |  4 +-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c          |  3 +
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h          | 31 ++++++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/{ => Validators}/Arm/SbbrValidator.c | 97 +++++++++++++++++++-
 ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Arm/SbbrValidator.h       | 49 ++++++++++
 6 files changed, 178 insertions(+), 97 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h
deleted file mode 100644
index b6d46af776f081834cd3c396e6310d0f6b961659..0000000000000000000000000000000000000000
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/** @file
-  Header file for SbbrValidator.c
-
-  Copyright (c) 2020, ARM Limited. All rights reserved.
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-  @par Glossary:
-    - Sbbr or SBBR   - Server Base Boot Requirements
-    - Sbsa or SBSA   - Server Base System Architecture
-
-  @par Reference(s):
-    - Arm Server Base Boot Requirements 1.2, September 2019
-    - Arm Server Base Boot Requirements 1.1, May 2018
-    - Arm Server Base Boot Requirements 1.0, March 2016
-    - Arm Server Base System Architecture 6.0
-**/
-
-#ifndef SBBR_VALIDATOR_H_
-#define SBBR_VALIDATOR_H_
-
-#include <IndustryStandard/Acpi.h>
-
-/**
-  Arm SBBR specification versions.
-**/
-typedef enum {
-  ArmSbbrVersion_1_0 = 0,
-  ArmSbbrVersion_1_1 = 1,
-  ArmSbbrVersion_1_2 = 2,
-  ArmSbbrVersionMax  = 3
-} ARM_SBBR_VERSION;
-
-/**
-  The ACPI table instance counter.
-**/
-typedef struct AcpiTableCounter {
-  CONST UINT32    Signature;      /// ACPI table signature
-  UINT32          Count;          /// Instance count
-} ACPI_TABLE_COUNTER;
-
-/**
-  ACPI table SBBR requirements.
-**/
-typedef struct AcpiSbbrReq {
-  CONST UINT32    *Tables;       /// List of required tables
-  CONST UINT32    TableCount;    /// Number of elements in Tables
-} ACPI_SBBR_REQ;
-
-/**
-  Reset the platform ACPI table instance count for all SBBR-mandatory tables.
-**/
-VOID
-EFIAPI
-ArmSbbrResetTableCounts (
-  VOID
-  );
-
-/**
-  Increment instance count for SBBR-mandatory ACPI table with the given
-  signature.
-
-  @param [in]  Signature        ACPI table signature.
-
-  @retval TRUE      Count incremented successfully.
-  @retval FALSE     Table with the input signature not found.
-**/
-BOOLEAN
-EFIAPI
-ArmSbbrIncrementTableCount (
-  UINT32  Signature
-  );
-
-/**
-  Validate that all ACPI tables required by the given SBBR specification
-  version are installed on the platform.
-
-  @param [in]  Version      SBBR spec version to validate against.
-
-  @retval EFI_SUCCESS             All required tables are present.
-  @retval EFI_INVALID_PARAMETER   Invalid SBBR version.
-  @retval EFI_NOT_FOUND           One or more mandatory tables are missing.
-  @retval EFI_UNSUPPORTED         Mandatory ACPI table does not have its
-                                  instance count tracked.
-**/
-EFI_STATUS
-EFIAPI
-ArmSbbrReqsValidate (
-  ARM_SBBR_VERSION  Version
-  );
-
-#endif // SBBR_VALIDATOR_H_
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
index 04913451289ebaf013e8290e46b462a554c9d825..41c222e75cdc46ec110a8aeae22e8a70d7c8769d 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf
@@ -58,8 +58,8 @@ [Sources.common]
   UefiShellAcpiViewCommandLib.uni
 
 [Sources.ARM, Sources.AARCH64]
-  Arm/SbbrValidator.h
-  Arm/SbbrValidator.c
+  Validators/Arm/SbbrValidator.h
+  Validators/Arm/SbbrValidator.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c
index 8e12e19f2b67e1c4305585ed1384f82c401ec49e..48551ff66df12fb6a567cfb2c023c14131c03c25 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.c
@@ -13,6 +13,9 @@
   List of all validators that can be run.
 **/
 ACPI_VALIDATOR  mValidatorList[] = {
+  { ValidatorIdSbbr10,       Sbbr10Validate       },
+  { ValidatorIdSbbr11,       Sbbr11Validate       },
+  { ValidatorIdSbbr12,       Sbbr12Validate       },
   { ValidatorIdAcpiStandard, AcpiStandardValidate }
 };
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h
index b7c5512ec673318ba2f15a8b986d33bdea6ec458..d2db02a803eaaad2cf896677662b4ffb403decd5 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/AcpiValidation.h
@@ -12,8 +12,11 @@
   ID's for all known validators.
 **/
 typedef enum {
-  ValidatorIdAcpiStandard = 0,     ///< Platform agnostic ACPI spec checks.
-  ValidatorIdMax          = 1
+  ValidatorIdSbbr10       = 0,   ///< Arm SBBR 1.0 specification checks
+  ValidatorIdSbbr11       = 1,   ///< Arm SBBR 1.1 specification checks
+  ValidatorIdSbbr12       = 2,   ///< Arm SBBR 1.2 specification checks
+  ValidatorIdAcpiStandard = 3,   ///< Platform agnostic ACPI spec checks.
+  ValidatorIdMax          = 4
 } VALIDATOR_ID;
 
 /**
@@ -50,4 +53,28 @@ AcpiStandardValidate (
   VOID
   );
 
+/**
+  Definition in Arm/SbbrValidator.c
+**/
+VOID
+EFIAPI
+Sbbr10Validate (
+  );
+
+/**
+  Definition in Arm/SbbrValidator.c
+**/
+VOID
+EFIAPI
+Sbbr11Validate (
+  );
+
+/**
+  Definition in Arm/SbbrValidator.c
+**/
+VOID
+EFIAPI
+Sbbr12Validate (
+  );
+
 #endif
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Arm/SbbrValidator.c
similarity index 74%
rename from ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
rename to ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Arm/SbbrValidator.c
index 5b0e578af942adc8374f51fa4a53b52d1c0a7d61..d72b3ae861e9ca862819edd631c757b2368a7a79 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Arm/SbbrValidator.c
@@ -1,7 +1,7 @@
 /** @file
   Arm Server Base Boot Requirements ACPI table requirement validator.
 
-  Copyright (c) 2020, ARM Limited. All rights reserved.
+  Copyright (c) 2021, ARM Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Glossary:
@@ -18,7 +18,9 @@
 #include <Library/DebugLib.h>
 #include <Library/UefiLib.h>
 #include "AcpiParser.h"
-#include "Arm/SbbrValidator.h"
+#include "AcpiViewConfig.h"
+#include "Validators/AcpiDataStore.h"
+#include "SbbrValidator.h"
 
 /**
   SBBR specification version strings
@@ -221,3 +223,94 @@ ArmSbbrReqsValidate (
 
   return IsArmSbbrViolated ? EFI_NOT_FOUND : EFI_SUCCESS;
 }
+
+/**
+  Validate that the mandatory ACPI tables have been installed according to the
+  SBBR specification.
+
+  @param [in]  Version      SBBR spec version to validate against.
+**/
+VOID
+EFIAPI
+ValidateSbbrMandatoryTables (
+  ARM_SBBR_VERSION  Version
+  )
+{
+  EFI_STATUS      Status;
+  META_DATA_NODE  *TableListHead;
+  META_DATA_NODE  *TableList;
+  UINT32          Signature;
+
+  Status = GetMetaDataListHead (MetaDataInstalledTables, &TableListHead);
+  if (EFI_ERROR (Status)) {
+    IncrementErrorCount ();
+    Print (
+      L"\nERROR: Cannot get list of installed tables."
+      L" Status = 0x%x.",
+      Status
+      );
+    return;
+  }
+
+  TableList = (META_DATA_NODE *)GetFirstNode (&TableListHead->Link);
+
+  while (!IsNull (&TableListHead->Link, &TableList->Link)) {
+    Signature = *(UINT32 *)TableList->Data;
+    ArmSbbrIncrementTableCount (Signature);
+
+    TableList = (META_DATA_NODE *)GetNextNode (
+                                    &TableListHead->Link,
+                                    &TableList->Link
+                                    );
+  }
+
+  Status = ArmSbbrReqsValidate (Version);
+  if (EFI_ERROR (Status)) {
+    Print (L"\nERROR: Failed to validate SBBR mandatory tables.\n");
+    return;
+  }
+
+  ArmSbbrResetTableCounts ();
+}
+
+/**
+  Validate that the mandatory ACPI tables have been installed according to the
+  SBBR 1.0 specification.
+**/
+VOID
+EFIAPI
+Sbbr10Validate (
+  )
+{
+  if (GetReportOption () != ReportSelected) {
+    ValidateSbbrMandatoryTables (ArmSbbrVersion_1_0);
+  }
+}
+
+/**
+  Validate that the mandatory ACPI tables have been installed according to the
+  SBBR 1.1 specification.
+**/
+VOID
+EFIAPI
+Sbbr11Validate (
+  )
+{
+  if (GetReportOption () != ReportSelected) {
+    ValidateSbbrMandatoryTables (ArmSbbrVersion_1_1);
+  }
+}
+
+/**
+  Validate that the mandatory ACPI tables have been installed according to the
+  SBBR 1.2 specification.
+**/
+VOID
+EFIAPI
+Sbbr12Validate (
+  )
+{
+  if (GetReportOption () != ReportSelected) {
+    ValidateSbbrMandatoryTables (ArmSbbrVersion_1_2);
+  }
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Arm/SbbrValidator.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Arm/SbbrValidator.h
new file mode 100644
index 0000000000000000000000000000000000000000..4a7fc766c0e603c27924ecfa42a5603c018f3cdd
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Validators/Arm/SbbrValidator.h
@@ -0,0 +1,49 @@
+/** @file
+  Header file for SbbrValidator.c
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+    - Sbbr or SBBR   - Server Base Boot Requirements
+    - Sbsa or SBSA   - Server Base System Architecture
+
+  @par Reference(s):
+    - Arm Server Base Boot Requirements 1.2, September 2019
+    - Arm Server Base Boot Requirements 1.1, May 2018
+    - Arm Server Base Boot Requirements 1.0, March 2016
+    - Arm Server Base System Architecture 6.0
+**/
+
+#ifndef SBBR_VALIDATOR_H_
+#define SBBR_VALIDATOR_H_
+
+#include <IndustryStandard/Acpi.h>
+
+/**
+  Arm SBBR specification versions.
+**/
+typedef enum {
+  ArmSbbrVersion_1_0 = 0,
+  ArmSbbrVersion_1_1 = 1,
+  ArmSbbrVersion_1_2 = 2,
+  ArmSbbrVersionMax  = 3
+} ARM_SBBR_VERSION;
+
+/**
+  The ACPI table instance counter.
+**/
+typedef struct AcpiTableCounter {
+  CONST UINT32    Signature;      /// ACPI table signature
+  UINT32          Count;          /// Instance count
+} ACPI_TABLE_COUNTER;
+
+/**
+  ACPI table SBBR requirements.
+**/
+typedef struct AcpiSbbrReq {
+  CONST UINT32    *Tables;       /// List of required tables
+  CONST UINT32    TableCount;    /// Number of elements in Tables
+} ACPI_SBBR_REQ;
+
+#endif // SBBR_VALIDATOR_H_
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

* [PATCH v1 9/9] ShellPkg: Add validator help string
       [not found] <20211215154722.4860-1-christopher.jones@arm.com>
                   ` (7 preceding siblings ...)
  2021-12-15 17:20 ` [PATCH v1 8/9] ShellPkg: Rewrite SBBR validation Chris Jones
@ 2021-12-15 17:20 ` Chris Jones
  8 siblings, 0 replies; 9+ messages in thread
From: Chris Jones @ 2021-12-15 17:20 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: ray.ni@intel.com, zhichao.gao@intel.com, Sami Mujawar, nd

Bugzilla: 3773 (https://bugzilla.tianocore.org/show_bug.cgi?id=3773)

Amend the help string to explain the use of the validator option.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
---
 ShellPkg/Application/AcpiViewApp/AcpiViewApp.uni                             | 18 +++++++++---------
 ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni | 20 ++++++++++----------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/ShellPkg/Application/AcpiViewApp/AcpiViewApp.uni b/ShellPkg/Application/AcpiViewApp/AcpiViewApp.uni
index c56f21084356d193eededaec7662731a24b1de01..c296601ae7508f92f2520e9877c124325d045485 100644
--- a/ShellPkg/Application/AcpiViewApp/AcpiViewApp.uni
+++ b/ShellPkg/Application/AcpiViewApp/AcpiViewApp.uni
@@ -16,7 +16,7 @@
 "Display ACPI Table information.\r\n"
 ".SH SYNOPSIS\r\n"
 " \r\n"
-"ACPIVIEWAPP.EFI [[-?] | [[[[-l] | [-s AcpiTable [-d]]] [-q] [-h]] [-r Spec]]]\r\n"
+"ACPIVIEWAPP.EFI [[-?] | [[[[-l] | [-s AcpiTable [-d]]] [-q] [-h]] [-r ValidatorId]]]\r\n"
 " \r\n"
 ".SH OPTIONS\r\n"
 " \r\n"
@@ -27,12 +27,12 @@
 "  -d - Generate a binary file dump of the specified AcpiTable.\r\n"
 "  -q - Quiet. Suppress errors and warnings. Disables consistency checks.\r\n"
 "  -h - Enable colour highlighting.\r\n"
-"  -r - Validate that all required ACPI tables are installed\r\n"
-"         Spec  : Specification to validate against.\r\n"
-"                 For Arm, the possible values are:\r\n"
-"                   0 - Server Base Boot Requirements v1.0\r\n"
-"                   1 - Server Base Boot Requirements v1.1\r\n"
-"                   2 - Server Base Boot Requirements v1.2\r\n"
+"  -r - Run the specified validator\r\n"
+"         ValidatorId : Validator/Validations to run.\r\n"
+"                        For Arm validations, the possible values are:\r\n"
+"                           0 - Server Base Boot Requirements v1.0\r\n"
+"                           1 - Server Base Boot Requirements v1.1\r\n"
+"                           2 - Server Base Boot Requirements v1.2\r\n"
 "  -? - Show help.\r\n"
 " \r\n"
 ".SH DESCRIPTION\r\n"
@@ -110,8 +110,8 @@
 "  * To display contents of all ACPI tables:\r\n"
 "    fs0:\> acpiviewapp.efi\r\n"
 " \r\n"
-"  * To check if all Server Base Boot Requirements (SBBR) v1.2 mandatory\r\n"
-"    ACPI tables are installed (Arm only):\r\n"
+"  * To check if all Server Base Boot Requirements (SBBR) v1.2 are met\r\n"
+"    (Arm only):\r\n"
 "    fs0:\> acpiviewapp.efi -r 2\r\n"
 " \r\n"
 ".SH RETURNVALUES\r\n"
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni
index 393110e0ee98d54b3be0309c2d297a121c258570..c82caa83cf903376103a59b4e48895a84419dca3 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.uni
@@ -1,6 +1,6 @@
 // /**
 //
-// Copyright (c) 2016 - 2020, Arm Limited. All rights reserved.<BR>
+// Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.<BR>
 // SPDX-License-Identifier: BSD-2-Clause-Patent
 //
 // Module Name:
@@ -30,7 +30,7 @@
 "Display ACPI Table information.\r\n"
 ".SH SYNOPSIS\r\n"
 " \r\n"
-"ACPIVIEW [[-?] | [[[[-l] | [-s AcpiTable [-d]]] [-q] [-h]] [-r Spec]]]\r\n"
+"ACPIVIEW [[-?] | [[[[-l] | [-s AcpiTable [-d]]] [-q] [-h]] [-r ValidatorId]]]\r\n"
 " \r\n"
 ".SH OPTIONS\r\n"
 " \r\n"
@@ -41,12 +41,12 @@
 "  -d - Generate a binary file dump of the specified AcpiTable.\r\n"
 "  -q - Quiet. Suppress errors and warnings. Disables consistency checks.\r\n"
 "  -h - Enable colour highlighting.\r\n"
-"  -r - Validate that all required ACPI tables are installed\r\n"
-"         Spec  : Specification to validate against.\r\n"
-"                 For Arm, the possible values are:\r\n"
-"                   0 - Server Base Boot Requirements v1.0\r\n"
-"                   1 - Server Base Boot Requirements v1.1\r\n"
-"                   2 - Server Base Boot Requirements v1.2\r\n"
+"  -r - Run the specified validator\r\n"
+"         ValidatorId : Validator/Validations to run.\r\n"
+"                        For Arm validations, the possible values are:\r\n"
+"                           0 - Server Base Boot Requirements v1.0\r\n"
+"                           1 - Server Base Boot Requirements v1.1\r\n"
+"                           2 - Server Base Boot Requirements v1.2\r\n"
 "  -? - Show help.\r\n"
 " \r\n"
 ".SH DESCRIPTION\r\n"
@@ -126,8 +126,8 @@
 "  * To display contents of all ACPI tables:\r\n"
 "    fs0:\> acpiview\r\n"
 " \r\n"
-"  * To check if all Server Base Boot Requirements (SBBR) v1.2 mandatory\r\n"
-"    ACPI tables are installed (Arm only):\r\n"
+"  * To check if all Server Base Boot Requirements (SBBR) v1.2 are met\r\n"
+"    (Arm only):\r\n"
 "    fs0:\> acpiview -r 2\r\n"
 " \r\n"
 ".SH RETURNVALUES\r\n"
-- 
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")


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

end of thread, other threads:[~2021-12-15 17:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20211215154722.4860-1-christopher.jones@arm.com>
2021-12-15 17:19 ` [PATCH v1 1/9] ShellPkg: Add AcpiView validators readme Chris Jones
2021-12-15 17:19 ` [PATCH v1 2/9] ShellPkg: Replace SBBR validation option with generic one Chris Jones
2021-12-15 17:19 ` [PATCH v1 3/9] ShellPkg: Add post parsing validation framework Chris Jones
2021-12-15 17:19 ` [PATCH v1 4/9] ShellPkg: Add ACPI data store Chris Jones
2021-12-15 17:19 ` [PATCH v1 5/9] ShellPkg: Store MADT and PPTT processor data Chris Jones
2021-12-15 17:19 ` [PATCH v1 6/9] ShellPkg: Add processor ID cross table validation Chris Jones
2021-12-15 17:19 ` [PATCH v1 7/9] ShellPkg: Add installed tables to parser collection Chris Jones
2021-12-15 17:20 ` [PATCH v1 8/9] ShellPkg: Rewrite SBBR validation Chris Jones
2021-12-15 17:20 ` [PATCH v1 9/9] ShellPkg: Add validator help string Chris Jones

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