[edk2-devel] [PATCH v2 5/8] ShellPkg/AcpiView: Refactor PrintFieldName

Tomas Pilar (tpilar) Tomas.Pilar at arm.com
Sun Jul 12 10:32:12 UTC 2020


The AcpiView core method is refactored to take format
and parameters rather than a fully formatted string. This
allows for far more flexible parser writing.

Change-Id: I02c30939f2c5ad98da7174303ae241839d2c8eba
Cc: Ray Ni <ray.ni at intel.com>
Cc: Zhichao Gao <zhichao.gao at intel.com>
Signed-off-by: Tomas Pilar <tomas.pilar at arm.com>
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  | 30 ---------------
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  | 19 ----------
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.c | 38 +++++++++++++++++++
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.h | 21 ++++++++++
 .../Parsers/Dbg2/Dbg2Parser.c                 |  1 +
 .../Parsers/Fadt/FadtParser.c                 |  1 +
 .../Parsers/Iort/IortParser.c                 |  1 +
 .../Parsers/Pptt/PpttParser.c                 |  1 +
 .../Parsers/Slit/SlitParser.c                 |  1 +
 .../Parsers/Srat/SratParser.c                 |  1 +
 .../Parsers/Xsdt/XsdtParser.c                 |  1 +
 11 files changed, 66 insertions(+), 49 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index b88594cf3865..54d87e2768e1 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -13,8 +13,6 @@
 #include "AcpiViewConfig.h"
 #include "AcpiViewLog.h"
 
-STATIC UINT32   gIndent;
-
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
@@ -390,34 +388,6 @@ Dump12Chars (
     );
 }
 
-/**
-  This function indents and prints the ACPI table Field Name.
-
-  @param [in] Indent      Number of spaces to add to the global table indent.
-                          The global table indent is 0 by default; however
-                          this value is updated on entry to the ParseAcpi()
-                          by adding the indent value provided to ParseAcpi()
-                          and restored back on exit.
-                          Therefore the total indent in the output is
-                          dependent on from where this function is called.
-  @param [in] FieldName   Pointer to the Field Name.
-**/
-VOID
-EFIAPI
-PrintFieldName (
-  IN UINT32         Indent,
-  IN CONST CHAR16*  FieldName
-)
-{
-  Print (
-    L"%*a%-*s : ",
-    gIndent + Indent,
-    "",
-    (OUTPUT_FIELD_COLUMN_WIDTH - gIndent - Indent),
-    FieldName
-    );
-}
-
 /**
   This function is used to parse an ACPI table buffer.
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 84eae61c8889..eb0c74eef144 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -204,25 +204,6 @@ Dump12Chars (
   IN       UINT8*  Ptr
   );
 
-/**
-  This function indents and prints the ACPI table Field Name.
-
-  @param [in] Indent      Number of spaces to add to the global table
-                          indent. The global table indent is 0 by default;
-                          however this value is updated on entry to the
-                          ParseAcpi() by adding the indent value provided to
-                          ParseAcpi() and restored back on exit. Therefore
-                          the total indent in the output is dependent on from
-                          where this function is called.
-  @param [in] FieldName   Pointer to the Field Name.
-**/
-VOID
-EFIAPI
-PrintFieldName (
-  IN UINT32         Indent,
-  IN CONST CHAR16*  FieldName
-  );
-
 /**
   This function pointer is the template for customizing the trace output
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
index 7ec276ac7528..18bbf67eef0a 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
@@ -27,6 +27,7 @@ static const CHAR16* mErrorTypeDesc [ACPI_ERROR_MAX] = {
 // Publicly accessible error and warning counters.
 UINT32   mTableErrorCount;
 UINT32   mTableWarningCount;
+UINT32   gIndent;
 
 /**
   Change the attributes of the standard output console
@@ -336,3 +337,40 @@ CheckConstraintInternal (
   // Return TRUE if constraint was violated
   return !Constraint;
 }
+
+/**
+  This function indents and prints the ACPI table Field Name.
+
+  @param [in] Indent      Number of spaces to add to the global table indent.
+                          The global table indent is 0 by default; however
+                          this value is updated on entry to the ParseAcpi()
+                          by adding the indent value provided to ParseAcpi()
+                          and restored back on exit.
+                          Therefore the total indent in the output is
+                          dependent on from where this function is called.
+  @param [in] FieldName   Pointer to the format string for field name.
+  @param [in] ...         Variable List parameters to format.
+**/
+VOID
+EFIAPI
+PrintFieldName (
+  IN UINT32         Indent,
+  IN CONST CHAR16*  FieldNameFormat,
+  ...
+  )
+{
+  VA_LIST Marker;
+  CHAR16 Buffer[64];
+
+  VA_START(Marker, FieldNameFormat);
+  UnicodeVSPrint(Buffer, sizeof(Buffer), FieldNameFormat, Marker);
+  VA_END(Marker);
+
+  AcpiViewOutput (
+    L"%*a%-*s : ",
+    gIndent + Indent,
+    "",
+    (OUTPUT_FIELD_COLUMN_WIDTH - gIndent - Indent),
+    Buffer
+    );
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h
index ce276ef7add2..0077646ca253 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h
@@ -40,6 +40,7 @@ typedef enum {
 // Publicly accessible error and warning counters.
 extern UINT32   mTableErrorCount;
 extern UINT32   mTableWarningCount;
+extern UINT32   gIndent;
 
 /**
   AcpiView output and logging function. Will log the event to
@@ -171,6 +172,26 @@ CheckConstraintInternal (
     !!(Constraint),                               \
     ACPI_WARN)
 
+/**
+  This function indents and prints the ACPI table Field Name.
+
+  @param [in] Indent      Number of spaces to add to the global table indent.
+                          The global table indent is 0 by default; however
+                          this value is updated on entry to the ParseAcpi()
+                          by adding the indent value provided to ParseAcpi()
+                          and restored back on exit.
+                          Therefore the total indent in the output is
+                          dependent on from where this function is called.
+  @param [in] FieldName   Pointer to the format string for field name.
+  @param [in] ...         Variable List parameters to format.
+**/
+VOID
+EFIAPI
+PrintFieldName (
+  IN UINT32         Indent,
+  IN CONST CHAR16*  FieldNameFormat,
+  ...
+  );
 
 // Maximum string size that can be printed
 #define MAX_OUTPUT_SIZE 256
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
index 9df111ecaa7d..dd69ed6992ba 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
@@ -12,6 +12,7 @@
 #include <Library/UefiLib.h>
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiViewLog.h"
 
 // Local variables pointing to the table fields
 STATIC CONST UINT32* OffsetDbgDeviceInfo;
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
index d86718bab67d..4734864dfdcf 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c
@@ -13,6 +13,7 @@
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
 #include "AcpiView.h"
+#include "AcpiViewLog.h"
 
 // Local variables
 STATIC CONST UINT32* DsdtAddress;
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
index f7447947b230..356f355939aa 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c
@@ -14,6 +14,7 @@
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
 #include "AcpiViewConfig.h"
+#include "AcpiViewLog.h"
 
 // Local variables
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
index acd2b81bb325..97a5203efb5f 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
@@ -15,6 +15,7 @@
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
 #include "PpttParser.h"
+#include "AcpiViewLog.h"
 
 // Local variables
 STATIC CONST UINT8*  ProcessorTopologyStructureType;
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
index e4625ee8b139..cedfc8a71849 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c
@@ -13,6 +13,7 @@
 #include <Library/UefiLib.h>
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiViewLog.h"
 
 // Local Variables
 STATIC CONST UINT64* SlitSystemLocalityCount;
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index b9b67820b89f..568a0400bf07 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -14,6 +14,7 @@
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
 #include "AcpiViewConfig.h"
+#include "AcpiViewLog.h"
 
 // Local Variables
 STATIC CONST UINT8* SratRAType;
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
index e39061f8e261..771c4f322b8e 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
@@ -13,6 +13,7 @@
 #include <Library/PrintLib.h>
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiViewLog.h"
 
 // Local variables
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
-- 
2.24.1.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62378): https://edk2.groups.io/g/devel/message/62378
Mute This Topic: https://groups.io/mt/75454451/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list