Re: [edk2] [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib

2019-03-27 Thread Gao, Zhichao
Thanks for your comments. I will update base on 1, 2, 3.
I have tested on Nt32Pkg and OvmfPkg to replace the PEIM debug lib with the new 
one and add MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf with the 
original PEIM DebugLib to dsc and fdf file.
The PEIMs which use the DebugLib can output debug message fine.

Thanks,
Zhichao

> -Original Message-
> From: Gao, Liming
> Sent: Thursday, March 28, 2019 10:04 AM
> To: Gao, Zhichao ; edk2-devel@lists.01.org
> Cc: Wang, Jian J ; Wu, Hao A ;
> Ni, Ray ; Zeng, Star ; Sean Brogan
> ; Michael Turner
> ; Bret Barkelew
> 
> Subject: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add
> PEI debug lib
> 
> Zhichao:
>For new library instance, I have some comments.
> 
> 1) DebugPrint(). If DebugPpi is not found, directly return instead of
> CpuDeadLoop().
> 2) DebugAssert(). If DebugPpi is not found, bases on
> PcdDebugPropertyMask value to trig CpuDeadLoop() or CpuBreakPoint().
> 3) Please rename mDebugPpi as the specific prefix name to avoid the name
> confliction.
> 4) What test is done for this library instance?
> 
> Thanks
> Liming
> >-Original Message-
> >From: Gao, Zhichao
> >Sent: Thursday, March 21, 2019 10:05 PM
> >To: edk2-devel@lists.01.org
> >Cc: Gao, Liming ; Wang, Jian J
> >; Wu, Hao A ; Ni, Ray
> >; Zeng, Star ; Sean Brogan
> >; Michael Turner
> >; Bret Barkelew
> >
> >Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> >debug lib
> >
> >From: Liming Gao 
> >
> >REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> >
> >Add a PEI debug library instance PeiDebugLibDebugPpi base on DebugPpi.
> >Using the combination of the DebugServicePei and this lib instance can
> >reduce the image size of PEI drivers.
> >
> >Contributed-under: TianoCore Contribution Agreement 1.1
> >Signed-off-by: Zhichao Gao 
> >Cc: Jian J Wang 
> >Cc: Hao Wu 
> >Cc: Ray Ni 
> >Cc: Star Zeng 
> >Cc: Liming Gao 
> >Cc: Sean Brogan 
> >Cc: Michael Turner 
> >Cc: Bret Barkelew 
> >---
> > .../Library/PeiDebugLibDebugPpi/DebugLib.c | 456
> >+
> > .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf|  55 +++
> > 2 files changed, 511 insertions(+)
> > create mode 100644
> >MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > create mode 100644
> >MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> >
> >diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> >b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> >new file mode 100644
> >index 00..75859163ae
> >--- /dev/null
> >+++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> >@@ -0,0 +1,456 @@
> >+/** @file
> >+  PEI debug lib instance base on DebugPpi to save size
> >+
> >+  Copyright (c) 2019, Intel Corporation. All rights reserved.
> >+
> >+  This program and the accompanying materials  are licensed and made
> >+ available under the terms and conditions of the BSD
> >License
> >+  which accompanies this distribution.  The full text of the license
> >+ may be
> >found at
> >+  http://opensource.org/licenses/bsd-license.php
> >+
> >+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> >BASIS,
> >+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> >EXPRESS OR IMPLIED.
> >+
> >+**/
> >+
> >+#include 
> >+#include 
> >+#include 
> >+#include 
> >+#include 
> >+#include 
> >+#include 
> >+
> >+EDKII_DEBUG_PPI *mDebugPpi = NULL;
> >+
> >+/**
> >+  Prints a debug message to the debug output device if the specified
> >+  error level is enabled.
> >+
> >+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> >+ function  GetDebugPrintErrorLevel (), then print the message
> >+ specified by Format
> >and
> >+  the associated variable argument list to the debug output device.
> >+
> >+  If Format is NULL, then ASSERT().
> >+
> >+  @param  ErrorLevelThe error level of the debug message.
> >+  @param  FormatFormat string for the debug message to print.
> >+  @param  ...   Variable argument list whose contents are accessed
> >+based on the format string specified by Format.
> >+
> >+**/
> >+VOID
> >+EFIAPI
> >+DebugPrint (
> >+  IN  UINTNErrorLevel,
> >+  IN  CONST CHAR8  *Format,
> >+  ...
> >+  )
> >+{
> >+  VA_LIST Marker;
> >+
> >+  VA_START (Marker, Format);
> >+  DebugVPrint (ErrorLevel, Format, Marker);
> >+  VA_END (Marker);
> >+}
> >+
> >+
> >+/**
> >+  Prints a debug message to the debug output device if the specified
> >+  error level is enabled.
> >+  This function use BASE_LIST which would provide a more compatible
> >+  service than VA_LIST.
> >+
> >+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> >+ function  GetDebugPrintErrorLevel (), then print the message
> >+ specified by Format
> >and
> >+  the associated variable argument list to the debug output device.
> >+
> >+  If Format is NULL, then ASSERT().
> >+
> >+  @param  ErrorLevel  The error level of the debug 

Re: [edk2] [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib

2019-03-27 Thread Gao, Liming
Zhichao:
   For new library instance, I have some comments. 

1) DebugPrint(). If DebugPpi is not found, directly return instead of 
CpuDeadLoop().
2) DebugAssert(). If DebugPpi is not found, bases on PcdDebugPropertyMask value 
to trig CpuDeadLoop() or CpuBreakPoint(). 
3) Please rename mDebugPpi as the specific prefix name to avoid the name 
confliction. 
4) What test is done for this library instance? 

Thanks
Liming
>-Original Message-
>From: Gao, Zhichao
>Sent: Thursday, March 21, 2019 10:05 PM
>To: edk2-devel@lists.01.org
>Cc: Gao, Liming ; Wang, Jian J
>; Wu, Hao A ; Ni, Ray
>; Zeng, Star ; Sean Brogan
>; Michael Turner
>; Bret Barkelew
>
>Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
>debug lib
>
>From: Liming Gao 
>
>REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
>
>Add a PEI debug library instance PeiDebugLibDebugPpi base on
>DebugPpi. Using the combination of the DebugServicePei and
>this lib instance can reduce the image size of PEI drivers.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Zhichao Gao 
>Cc: Jian J Wang 
>Cc: Hao Wu 
>Cc: Ray Ni 
>Cc: Star Zeng 
>Cc: Liming Gao 
>Cc: Sean Brogan 
>Cc: Michael Turner 
>Cc: Bret Barkelew 
>---
> .../Library/PeiDebugLibDebugPpi/DebugLib.c | 456
>+
> .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf|  55 +++
> 2 files changed, 511 insertions(+)
> create mode 100644
>MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> create mode 100644
>MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
>
>diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
>b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
>new file mode 100644
>index 00..75859163ae
>--- /dev/null
>+++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
>@@ -0,0 +1,456 @@
>+/** @file
>+  PEI debug lib instance base on DebugPpi to save size
>+
>+  Copyright (c) 2019, Intel Corporation. All rights reserved.
>+
>+  This program and the accompanying materials
>+  are licensed and made available under the terms and conditions of the BSD
>License
>+  which accompanies this distribution.  The full text of the license may be
>found at
>+  http://opensource.org/licenses/bsd-license.php
>+
>+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+
>+**/
>+
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+
>+EDKII_DEBUG_PPI *mDebugPpi = NULL;
>+
>+/**
>+  Prints a debug message to the debug output device if the specified
>+  error level is enabled.
>+
>+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
>+  GetDebugPrintErrorLevel (), then print the message specified by Format
>and
>+  the associated variable argument list to the debug output device.
>+
>+  If Format is NULL, then ASSERT().
>+
>+  @param  ErrorLevelThe error level of the debug message.
>+  @param  FormatFormat string for the debug message to print.
>+  @param  ...   Variable argument list whose contents are accessed
>+based on the format string specified by Format.
>+
>+**/
>+VOID
>+EFIAPI
>+DebugPrint (
>+  IN  UINTNErrorLevel,
>+  IN  CONST CHAR8  *Format,
>+  ...
>+  )
>+{
>+  VA_LIST Marker;
>+
>+  VA_START (Marker, Format);
>+  DebugVPrint (ErrorLevel, Format, Marker);
>+  VA_END (Marker);
>+}
>+
>+
>+/**
>+  Prints a debug message to the debug output device if the specified
>+  error level is enabled.
>+  This function use BASE_LIST which would provide a more compatible
>+  service than VA_LIST.
>+
>+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
>+  GetDebugPrintErrorLevel (), then print the message specified by Format
>and
>+  the associated variable argument list to the debug output device.
>+
>+  If Format is NULL, then ASSERT().
>+
>+  @param  ErrorLevel  The error level of the debug message.
>+  @param  Format  Format string for the debug message to print.
>+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
>+
>+**/
>+VOID
>+EFIAPI
>+DebugBPrint (
>+  IN  UINTN ErrorLevel,
>+  IN  CONST CHAR8   *Format,
>+  IN  BASE_LIST BaseListMarker
>+  )
>+{
>+  EFI_STATUS  Status;
>+
>+  //
>+  // If Format is NULL, then ASSERT().
>+  //
>+  ASSERT (Format != NULL);
>+
>+  //
>+  // Check driver Debug Level value and global debug level
>+  //
>+  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
>+return;
>+  }
>+
>+  if (mDebugPpi == NULL) {
>+Status = PeiServicesLocatePpi (
>+,
>+0,
>+NULL,
>+(VOID **)
>+);
>+if (EFI_ERROR (Status)) {
>+  CpuDeadLoop();
>+}
>+  }
>+
>+  mDebugPpi->DebugBPrint (
>+  ErrorLevel,
>+  Format,
>+  BaseListMarker
>+  

Re: [edk2] [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib

2019-03-21 Thread Wu, Hao A
If it follows the EDK II C Coding Standards Specification, then ignore
my relating comments then,

Best Regards,
Hao Wu

> -Original Message-
> From: Gao, Zhichao
> Sent: Friday, March 22, 2019 10:19 AM
> To: Wu, Hao A; edk2-devel@lists.01.org
> Cc: Gao, Liming; Wang, Jian J; Ni, Ray; Zeng, Star; Sean Brogan; Michael 
> Turner;
> Bret Barkelew
> Subject: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> debug lib
> 
> For the sections you point. It seems good to watch the patch downloaded.
> The indention is one or two space behind the function name depend on tab
> expand(2 space).
> Is it need to adjust them?
> 
> Thanks,
> Zhichao
> 
> > -Original Message-
> > From: Wu, Hao A
> > Sent: Friday, March 22, 2019 10:09 AM
> > To: Gao, Zhichao ; edk2-devel@lists.01.org
> > Cc: Gao, Liming ; Wang, Jian J
> > ; Ni, Ray ; Zeng, Star
> > ; Sean Brogan ;
> > Michael Turner ; Bret Barkelew
> > 
> > Subject: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add
> > PEI debug lib
> >
> > > -Original Message-
> > > From: Gao, Zhichao
> > > Sent: Thursday, March 21, 2019 10:05 PM
> > > To: edk2-devel@lists.01.org
> > > Cc: Gao, Liming; Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Sean
> > > Brogan; Michael Turner; Bret Barkelew
> > > Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> > > debug lib
> > >
> > > From: Liming Gao 
> > >
> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> > >
> > > Add a PEI debug library instance PeiDebugLibDebugPpi base on DebugPpi.
> > > Using the combination of the DebugServicePei and this lib instance can
> > > reduce the image size of PEI drivers.
> > >
> > > Contributed-under: TianoCore Contribution Agreement 1.1
> > > Signed-off-by: Zhichao Gao 
> > > Cc: Jian J Wang 
> > > Cc: Hao Wu 
> > > Cc: Ray Ni 
> > > Cc: Star Zeng 
> > > Cc: Liming Gao 
> > > Cc: Sean Brogan 
> > > Cc: Michael Turner 
> > > Cc: Bret Barkelew 
> > > ---
> > >  .../Library/PeiDebugLibDebugPpi/DebugLib.c | 456
> > > +
> > >  .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf|  55 +++
> > >  2 files changed, 511 insertions(+)
> > >  create mode 100644
> > > MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > >  create mode 100644
> > > MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> > >
> > > diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > > b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > > new file mode 100644
> > > index 00..75859163ae
> > > --- /dev/null
> > > +++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > > @@ -0,0 +1,456 @@
> > > +/** @file
> > > +  PEI debug lib instance base on DebugPpi to save size
> > > +
> > > +  Copyright (c) 2019, Intel Corporation. All rights reserved.
> > > +
> > > +  This program and the accompanying materials  are licensed and made
> > > + available under the terms and conditions of the BSD
> > > License
> > > +  which accompanies this distribution.  The full text of the license
> > > + may be
> > > found at
> > > +  http://opensource.org/licenses/bsd-license.php
> > > +
> > > +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > > BASIS,
> > > +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> > > EXPRESS OR IMPLIED.
> > > +
> > > +**/
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +EDKII_DEBUG_PPI *mDebugPpi = NULL;
> > > +
> > > +/**
> > > +  Prints a debug message to the debug output device if the specified
> > > +  error level is enabled.
> > > +
> > > +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> > > + function  GetDebugPrintErrorLevel (), then print the message
> > > + specified by Format and  the associated variable argument list to the
> > debug output device.
> > > +
> > > +  If Format is NULL, then ASSERT().
> > > +
> > > +  @param  ErrorLevelThe error level of the debug message.
> > > +  @param  FormatFormat string for the debug message to print.
> > > +  @param  ...   Variable argument list whose contents are 
> > > accessed
> > > +based on the format string specified by Format.
> > > +
> > > +**/
> > > +VOID
> > > +EFIAPI
> > > +DebugPrint (
> > > +  IN  UINTNErrorLevel,
> > > +  IN  CONST CHAR8  *Format,
> > > +  ...
> > > +  )
> > > +{
> > > +  VA_LIST Marker;
> > > +
> > > +  VA_START (Marker, Format);
> > > +  DebugVPrint (ErrorLevel, Format, Marker);
> > > +  VA_END (Marker);
> > > +}
> > > +
> > > +
> > > +/**
> > > +  Prints a debug message to the debug output device if the specified
> > > +  error level is enabled.
> > > +  This function use BASE_LIST which would provide a more compatible
> > > +  service than VA_LIST.
> > > +
> > > +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> > > + function  GetDebugPrintErrorLevel (), then print the 

Re: [edk2] [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib

2019-03-21 Thread Gao, Zhichao
For the sections you point. It seems good to watch the patch downloaded.
The indention is one or two space behind the function name depend on tab 
expand(2 space).
Is it need to adjust them?

Thanks,
Zhichao

> -Original Message-
> From: Wu, Hao A
> Sent: Friday, March 22, 2019 10:09 AM
> To: Gao, Zhichao ; edk2-devel@lists.01.org
> Cc: Gao, Liming ; Wang, Jian J
> ; Ni, Ray ; Zeng, Star
> ; Sean Brogan ;
> Michael Turner ; Bret Barkelew
> 
> Subject: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add
> PEI debug lib
> 
> > -Original Message-
> > From: Gao, Zhichao
> > Sent: Thursday, March 21, 2019 10:05 PM
> > To: edk2-devel@lists.01.org
> > Cc: Gao, Liming; Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Sean
> > Brogan; Michael Turner; Bret Barkelew
> > Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> > debug lib
> >
> > From: Liming Gao 
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> >
> > Add a PEI debug library instance PeiDebugLibDebugPpi base on DebugPpi.
> > Using the combination of the DebugServicePei and this lib instance can
> > reduce the image size of PEI drivers.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Zhichao Gao 
> > Cc: Jian J Wang 
> > Cc: Hao Wu 
> > Cc: Ray Ni 
> > Cc: Star Zeng 
> > Cc: Liming Gao 
> > Cc: Sean Brogan 
> > Cc: Michael Turner 
> > Cc: Bret Barkelew 
> > ---
> >  .../Library/PeiDebugLibDebugPpi/DebugLib.c | 456
> > +
> >  .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf|  55 +++
> >  2 files changed, 511 insertions(+)
> >  create mode 100644
> > MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> >  create mode 100644
> > MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> >
> > diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > new file mode 100644
> > index 00..75859163ae
> > --- /dev/null
> > +++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > @@ -0,0 +1,456 @@
> > +/** @file
> > +  PEI debug lib instance base on DebugPpi to save size
> > +
> > +  Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +
> > +  This program and the accompanying materials  are licensed and made
> > + available under the terms and conditions of the BSD
> > License
> > +  which accompanies this distribution.  The full text of the license
> > + may be
> > found at
> > +  http://opensource.org/licenses/bsd-license.php
> > +
> > +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > BASIS,
> > +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> > EXPRESS OR IMPLIED.
> > +
> > +**/
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +EDKII_DEBUG_PPI *mDebugPpi = NULL;
> > +
> > +/**
> > +  Prints a debug message to the debug output device if the specified
> > +  error level is enabled.
> > +
> > +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> > + function  GetDebugPrintErrorLevel (), then print the message
> > + specified by Format and  the associated variable argument list to the
> debug output device.
> > +
> > +  If Format is NULL, then ASSERT().
> > +
> > +  @param  ErrorLevelThe error level of the debug message.
> > +  @param  FormatFormat string for the debug message to print.
> > +  @param  ...   Variable argument list whose contents are accessed
> > +based on the format string specified by Format.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +DebugPrint (
> > +  IN  UINTNErrorLevel,
> > +  IN  CONST CHAR8  *Format,
> > +  ...
> > +  )
> > +{
> > +  VA_LIST Marker;
> > +
> > +  VA_START (Marker, Format);
> > +  DebugVPrint (ErrorLevel, Format, Marker);
> > +  VA_END (Marker);
> > +}
> > +
> > +
> > +/**
> > +  Prints a debug message to the debug output device if the specified
> > +  error level is enabled.
> > +  This function use BASE_LIST which would provide a more compatible
> > +  service than VA_LIST.
> > +
> > +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> > + function  GetDebugPrintErrorLevel (), then print the message
> > + specified by Format and  the associated variable argument list to the
> debug output device.
> > +
> > +  If Format is NULL, then ASSERT().
> > +
> > +  @param  ErrorLevel  The error level of the debug message.
> > +  @param  Format  Format string for the debug message to print.
> > +  @param  BaseListMarker  BASE_LIST marker for the variable argument
> list.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +DebugBPrint (
> > +  IN  UINTN ErrorLevel,
> > +  IN  CONST CHAR8   *Format,
> > +  IN  BASE_LIST BaseListMarker
> > +  )
> > +{
> > +  EFI_STATUS  Status;
> > +
> > +  //
> > +  // If Format is NULL, then ASSERT().
> > +  //
> > +  ASSERT (Format != NULL);
> > +
> > +  //
> > 

Re: [edk2] [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib

2019-03-21 Thread Wu, Hao A
> -Original Message-
> From: Gao, Zhichao
> Sent: Thursday, March 21, 2019 10:05 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming; Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Sean Brogan;
> Michael Turner; Bret Barkelew
> Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> debug lib
> 
> From: Liming Gao 
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> 
> Add a PEI debug library instance PeiDebugLibDebugPpi base on
> DebugPpi. Using the combination of the DebugServicePei and
> this lib instance can reduce the image size of PEI drivers.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Zhichao Gao 
> Cc: Jian J Wang 
> Cc: Hao Wu 
> Cc: Ray Ni 
> Cc: Star Zeng 
> Cc: Liming Gao 
> Cc: Sean Brogan 
> Cc: Michael Turner 
> Cc: Bret Barkelew 
> ---
>  .../Library/PeiDebugLibDebugPpi/DebugLib.c | 456
> +
>  .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf|  55 +++
>  2 files changed, 511 insertions(+)
>  create mode 100644
> MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
>  create mode 100644
> MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> 
> diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> new file mode 100644
> index 00..75859163ae
> --- /dev/null
> +++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> @@ -0,0 +1,456 @@
> +/** @file
> +  PEI debug lib instance base on DebugPpi to save size
> +
> +  Copyright (c) 2019, Intel Corporation. All rights reserved.
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD
> License
> +  which accompanies this distribution.  The full text of the license may be
> found at
> +  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> EXPRESS OR IMPLIED.
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +EDKII_DEBUG_PPI *mDebugPpi = NULL;
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
> +  GetDebugPrintErrorLevel (), then print the message specified by Format and
> +  the associated variable argument list to the debug output device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevelThe error level of the debug message.
> +  @param  FormatFormat string for the debug message to print.
> +  @param  ...   Variable argument list whose contents are accessed
> +based on the format string specified by Format.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugPrint (
> +  IN  UINTNErrorLevel,
> +  IN  CONST CHAR8  *Format,
> +  ...
> +  )
> +{
> +  VA_LIST Marker;
> +
> +  VA_START (Marker, Format);
> +  DebugVPrint (ErrorLevel, Format, Marker);
> +  VA_END (Marker);
> +}
> +
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +  This function use BASE_LIST which would provide a more compatible
> +  service than VA_LIST.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
> +  GetDebugPrintErrorLevel (), then print the message specified by Format and
> +  the associated variable argument list to the debug output device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel  The error level of the debug message.
> +  @param  Format  Format string for the debug message to print.
> +  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugBPrint (
> +  IN  UINTN ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  BASE_LIST BaseListMarker
> +  )
> +{
> +  EFI_STATUS  Status;
> +
> +  //
> +  // If Format is NULL, then ASSERT().
> +  //
> +  ASSERT (Format != NULL);
> +
> +  //
> +  // Check driver Debug Level value and global debug level
> +  //
> +  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
> +return;
> +  }
> +
> +  if (mDebugPpi == NULL) {
> +Status = PeiServicesLocatePpi (

*

> +,
> +0,
> +NULL,
> +(VOID **)
> +);

*

The indention seems not consistent for the above several lines.


> +if (EFI_ERROR (Status)) {
> +  CpuDeadLoop();
> +}
> +  }
> +
> +  mDebugPpi->DebugBPrint (

*

> +  ErrorLevel,
> +  Format,
> +  BaseListMarker
> +  );

*

The indention seems not consistent for the above several lines.


> +}
> +
> +
> +/**
> +  Worker function that convert a VA_LIST to a BASE_LIST based on a
> +  

[edk2] [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib

2019-03-21 Thread Zhichao Gao
From: Liming Gao 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add a PEI debug library instance PeiDebugLibDebugPpi base on
DebugPpi. Using the combination of the DebugServicePei and
this lib instance can reduce the image size of PEI drivers.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao 
Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Ray Ni 
Cc: Star Zeng 
Cc: Liming Gao 
Cc: Sean Brogan 
Cc: Michael Turner 
Cc: Bret Barkelew 
---
 .../Library/PeiDebugLibDebugPpi/DebugLib.c | 456 +
 .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf|  55 +++
 2 files changed, 511 insertions(+)
 create mode 100644 MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
 create mode 100644 
MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf

diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c 
b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
new file mode 100644
index 00..75859163ae
--- /dev/null
+++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
@@ -0,0 +1,456 @@
+/** @file
+  PEI debug lib instance base on DebugPpi to save size
+
+  Copyright (c) 2019, Intel Corporation. All rights reserved.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+EDKII_DEBUG_PPI *mDebugPpi = NULL;
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevelThe error level of the debug message.
+  @param  FormatFormat string for the debug message to print.
+  @param  ...   Variable argument list whose contents are accessed
+based on the format string specified by Format.
+
+**/
+VOID
+EFIAPI
+DebugPrint (
+  IN  UINTNErrorLevel,
+  IN  CONST CHAR8  *Format,
+  ...
+  )
+{
+  VA_LIST Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel  The error level of the debug message.
+  @param  Format  Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST BaseListMarker
+  )
+{
+  EFI_STATUS  Status;
+
+  //
+  // If Format is NULL, then ASSERT().
+  //
+  ASSERT (Format != NULL);
+
+  //
+  // Check driver Debug Level value and global debug level
+  //
+  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
+return;
+  }
+
+  if (mDebugPpi == NULL) {
+Status = PeiServicesLocatePpi (
+,
+0,
+NULL,
+(VOID **)
+);
+if (EFI_ERROR (Status)) {
+  CpuDeadLoop();
+}
+  }
+
+  mDebugPpi->DebugBPrint (
+  ErrorLevel,
+  Format,
+  BaseListMarker
+  );
+}
+
+
+/**
+  Worker function that convert a VA_LIST to a BASE_LIST based on a
+  Null-terminated format string.
+
+  @param  Format  Null-terminated format string.
+  @param  VaListMarkerVA_LIST style variable argument list consumed
+  by processing Format.
+  @param  BaseListMarker  BASE_LIST style variable argument list consumed
+  by processing Format.
+  @param  SizeThe size, in bytes, of the BaseListMarker buffer.
+
+  @return TRUE   The VA_LIST has been converted to BASE_LIST.
+  @return FALSE  The VA_LIST has not been converted to BASE_LIST.
+
+**/
+BOOLEAN
+VaListToBaseList (
+  IN  CONST CHAR8  *Format,
+  IN  VA_LIST  VaListMarker,
+  OUT BASE_LISTBaseListMarker,
+  IN  UINTNSize
+  )
+{
+  BASE_LIST   BaseListStart;
+  BOOLEAN Long;
+
+  ASSERT (Format != NULL);
+
+