Re: [edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Separate the timer ticking to calculate the packet live time.

2018-03-01 Thread Ye, Ting
Reviewed-by: Ye Ting  

-Original Message-
From: Wu, Jiaxin 
Sent: Friday, March 2, 2018 2:43 PM
To: edk2-devel@lists.01.org
Cc: Fu, Siyuan ; Wang, Fan ; Ye, Ting 

Subject: [Patch] MdeModulePkg/Mtftp4Dxe: Separate the timer ticking to 
calculate the packet live time.

From: Fu Siyuan 

TPL deadlock issue was enrolled by the commit of 39b0867d. To resolve the 
issue, this patch separated the timer ticking for all the MTFTP clients to 
calculate the packet live time in TPL_NOTIFY level.

Cc: Wang Fan 
Cc: Fu Siyuan 
Cc: Ye Ting 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan 
Signed-off-by: Jiaxin Wu 
---
 .../Universal/Network/Mtftp4Dxe/Mtftp4Driver.c | 34 ++---
 .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  5 +-
 .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.h   |  6 ++-
 .../Universal/Network/Mtftp4Dxe/Mtftp4Support.c| 57 +-
 .../Universal/Network/Mtftp4Dxe/Mtftp4Support.h| 16 +-
 5 files changed, 97 insertions(+), 21 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c 
b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
index a23d405baa..713cc66dd1 100644
--- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
+++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
@@ -1,9 +1,9 @@
 /** @file
   Implementation of Mtftp drivers.
 
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, 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
 
@@ -160,15 +160,16 @@ Mtftp4CreateService (
   MtftpSb->Signature  = MTFTP4_SERVICE_SIGNATURE;
   MtftpSb->ServiceBinding = gMtftp4ServiceBindingTemplete;
   MtftpSb->ChildrenNum= 0;
   InitializeListHead (>Children);
 
-  MtftpSb->Timer  = NULL;
-  MtftpSb->TimerToGetMap  = NULL;
-  MtftpSb->Controller = Controller;
-  MtftpSb->Image  = Image;
-  MtftpSb->ConnectUdp = NULL;
+  MtftpSb->Timer= NULL;
+  MtftpSb->TimerNotifyLevel = NULL;
+  MtftpSb->TimerToGetMap= NULL;
+  MtftpSb->Controller   = Controller;
+  MtftpSb->Image= Image;
+  MtftpSb->ConnectUdp   = NULL;
 
   //
   // Create the timer and a udp to be notified when UDP is uninstalled
   //
   Status = gBS->CreateEvent (
@@ -176,12 +177,24 @@ Mtftp4CreateService (
   TPL_CALLBACK,
   Mtftp4OnTimerTick,
   MtftpSb,
   >Timer
   );
+  if (EFI_ERROR (Status)) {
+FreePool (MtftpSb);
+return Status;
+  }
 
+  Status = gBS->CreateEvent (
+  EVT_NOTIFY_SIGNAL | EVT_TIMER,
+  TPL_NOTIFY,
+  Mtftp4OnTimerTickNotifyLevel,
+  MtftpSb,
+  >TimerNotifyLevel
+  );
   if (EFI_ERROR (Status)) {
+gBS->CloseEvent (MtftpSb->Timer);
 FreePool (MtftpSb);
 return Status;
   }
 
   //
@@ -194,10 +207,11 @@ Mtftp4CreateService (
   NULL,
   NULL,
   >TimerToGetMap
   );
   if (EFI_ERROR (Status)) {
+gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
 gBS->CloseEvent (MtftpSb->Timer);
 FreePool (MtftpSb);
 return Status;
   }
 
@@ -209,10 +223,11 @@ Mtftp4CreateService (
   NULL
   );
 
   if (MtftpSb->ConnectUdp == NULL) {
 gBS->CloseEvent (MtftpSb->TimerToGetMap);
+gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
 gBS->CloseEvent (MtftpSb->Timer);
 FreePool (MtftpSb);
 return EFI_DEVICE_ERROR;
   }
 
@@ -232,10 +247,11 @@ Mtftp4CleanService (
   IN MTFTP4_SERVICE *MtftpSb
   )
 {
   UdpIoFreeIo (MtftpSb->ConnectUdp);
   gBS->CloseEvent (MtftpSb->TimerToGetMap);
+  gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
   gBS->CloseEvent (MtftpSb->Timer);
 }
 
 
 /**
@@ -292,10 +308,16 @@ Mtftp4DriverBindingStart (
 
   if (EFI_ERROR (Status)) {
 goto ON_ERROR;
   }
 
+  Status = gBS->SetTimer (MtftpSb->TimerNotifyLevel, TimerPeriodic, 
+ TICKS_PER_SECOND);
+
+  if (EFI_ERROR (Status)) {
+goto ON_ERROR;
+  }
+  
   //
   // Install the Mtftp4ServiceBinding Protocol onto Controller
   //
   Status = gBS->InstallMultipleProtocolInterfaces (
   ,
diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c 
b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
index f5f9e6d8f7..d8c48ec8b2 100644
--- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
+++ 

Re: [edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Separate the timer ticking to calculate the packet live time.

2018-03-01 Thread Fu, Siyuan
Reviewed-by: Fu Siyuan 


> -Original Message-
> From: Wu, Jiaxin
> Sent: Friday, March 2, 2018 2:43 PM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Wang, Fan ; Ye,
> Ting 
> Subject: [Patch] MdeModulePkg/Mtftp4Dxe: Separate the timer ticking to
> calculate the packet live time.
> 
> From: Fu Siyuan 
> 
> TPL deadlock issue was enrolled by the commit of 39b0867d. To resolve the
> issue,
> this patch separated the timer ticking for all the MTFTP clients to
> calculate the
> packet live time in TPL_NOTIFY level.
> 
> Cc: Wang Fan 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan 
> Signed-off-by: Jiaxin Wu 
> ---
>  .../Universal/Network/Mtftp4Dxe/Mtftp4Driver.c | 34 ++---
>  .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  5 +-
>  .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.h   |  6 ++-
>  .../Universal/Network/Mtftp4Dxe/Mtftp4Support.c| 57
> +-
>  .../Universal/Network/Mtftp4Dxe/Mtftp4Support.h| 16 +-
>  5 files changed, 97 insertions(+), 21 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
> b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
> index a23d405baa..713cc66dd1 100644
> --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
> +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
> @@ -1,9 +1,9 @@
>  /** @file
>Implementation of Mtftp drivers.
> 
> -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2018, 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
> 
> @@ -160,15 +160,16 @@ Mtftp4CreateService (
>MtftpSb->Signature  = MTFTP4_SERVICE_SIGNATURE;
>MtftpSb->ServiceBinding = gMtftp4ServiceBindingTemplete;
>MtftpSb->ChildrenNum= 0;
>InitializeListHead (>Children);
> 
> -  MtftpSb->Timer  = NULL;
> -  MtftpSb->TimerToGetMap  = NULL;
> -  MtftpSb->Controller = Controller;
> -  MtftpSb->Image  = Image;
> -  MtftpSb->ConnectUdp = NULL;
> +  MtftpSb->Timer= NULL;
> +  MtftpSb->TimerNotifyLevel = NULL;
> +  MtftpSb->TimerToGetMap= NULL;
> +  MtftpSb->Controller   = Controller;
> +  MtftpSb->Image= Image;
> +  MtftpSb->ConnectUdp   = NULL;
> 
>//
>// Create the timer and a udp to be notified when UDP is uninstalled
>//
>Status = gBS->CreateEvent (
> @@ -176,12 +177,24 @@ Mtftp4CreateService (
>TPL_CALLBACK,
>Mtftp4OnTimerTick,
>MtftpSb,
>>Timer
>);
> +  if (EFI_ERROR (Status)) {
> +FreePool (MtftpSb);
> +return Status;
> +  }
> 
> +  Status = gBS->CreateEvent (
> +  EVT_NOTIFY_SIGNAL | EVT_TIMER,
> +  TPL_NOTIFY,
> +  Mtftp4OnTimerTickNotifyLevel,
> +  MtftpSb,
> +  >TimerNotifyLevel
> +  );
>if (EFI_ERROR (Status)) {
> +gBS->CloseEvent (MtftpSb->Timer);
>  FreePool (MtftpSb);
>  return Status;
>}
> 
>//
> @@ -194,10 +207,11 @@ Mtftp4CreateService (
>NULL,
>NULL,
>>TimerToGetMap
>);
>if (EFI_ERROR (Status)) {
> +gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
>  gBS->CloseEvent (MtftpSb->Timer);
>  FreePool (MtftpSb);
>  return Status;
>}
> 
> @@ -209,10 +223,11 @@ Mtftp4CreateService (
>NULL
>);
> 
>if (MtftpSb->ConnectUdp == NULL) {
>  gBS->CloseEvent (MtftpSb->TimerToGetMap);
> +gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
>  gBS->CloseEvent (MtftpSb->Timer);
>  FreePool (MtftpSb);
>  return EFI_DEVICE_ERROR;
>}
> 
> @@ -232,10 +247,11 @@ Mtftp4CleanService (
>IN MTFTP4_SERVICE *MtftpSb
>)
>  {
>UdpIoFreeIo (MtftpSb->ConnectUdp);
>gBS->CloseEvent (MtftpSb->TimerToGetMap);
> +  gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
>gBS->CloseEvent (MtftpSb->Timer);
>  }
> 
> 
>  /**
> @@ -292,10 +308,16 @@ Mtftp4DriverBindingStart (
> 
>if (EFI_ERROR (Status)) {
>  goto ON_ERROR;
>}
> 
> +  Status = gBS->SetTimer (MtftpSb->TimerNotifyLevel, TimerPeriodic,
> TICKS_PER_SECOND);
> +
> +  if (EFI_ERROR (Status)) {
> +goto ON_ERROR;
> +  }
> +
>//
>// Install the Mtftp4ServiceBinding Protocol onto Controller
>//
>Status = gBS->InstallMultipleProtocolInterfaces (
>

[edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Separate the timer ticking to calculate the packet live time.

2018-03-01 Thread Jiaxin Wu
From: Fu Siyuan 

TPL deadlock issue was enrolled by the commit of 39b0867d. To resolve the issue,
this patch separated the timer ticking for all the MTFTP clients to calculate 
the
packet live time in TPL_NOTIFY level.

Cc: Wang Fan 
Cc: Fu Siyuan 
Cc: Ye Ting 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan 
Signed-off-by: Jiaxin Wu 
---
 .../Universal/Network/Mtftp4Dxe/Mtftp4Driver.c | 34 ++---
 .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.c   |  5 +-
 .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.h   |  6 ++-
 .../Universal/Network/Mtftp4Dxe/Mtftp4Support.c| 57 +-
 .../Universal/Network/Mtftp4Dxe/Mtftp4Support.h| 16 +-
 5 files changed, 97 insertions(+), 21 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c 
b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
index a23d405baa..713cc66dd1 100644
--- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
+++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
@@ -1,9 +1,9 @@
 /** @file
   Implementation of Mtftp drivers.
 
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, 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
 
@@ -160,15 +160,16 @@ Mtftp4CreateService (
   MtftpSb->Signature  = MTFTP4_SERVICE_SIGNATURE;
   MtftpSb->ServiceBinding = gMtftp4ServiceBindingTemplete;
   MtftpSb->ChildrenNum= 0;
   InitializeListHead (>Children);
 
-  MtftpSb->Timer  = NULL;
-  MtftpSb->TimerToGetMap  = NULL;
-  MtftpSb->Controller = Controller;
-  MtftpSb->Image  = Image;
-  MtftpSb->ConnectUdp = NULL;
+  MtftpSb->Timer= NULL;
+  MtftpSb->TimerNotifyLevel = NULL;
+  MtftpSb->TimerToGetMap= NULL;
+  MtftpSb->Controller   = Controller;
+  MtftpSb->Image= Image;
+  MtftpSb->ConnectUdp   = NULL;
 
   //
   // Create the timer and a udp to be notified when UDP is uninstalled
   //
   Status = gBS->CreateEvent (
@@ -176,12 +177,24 @@ Mtftp4CreateService (
   TPL_CALLBACK,
   Mtftp4OnTimerTick,
   MtftpSb,
   >Timer
   );
+  if (EFI_ERROR (Status)) {
+FreePool (MtftpSb);
+return Status;
+  }
 
+  Status = gBS->CreateEvent (
+  EVT_NOTIFY_SIGNAL | EVT_TIMER,
+  TPL_NOTIFY,
+  Mtftp4OnTimerTickNotifyLevel,
+  MtftpSb,
+  >TimerNotifyLevel
+  );
   if (EFI_ERROR (Status)) {
+gBS->CloseEvent (MtftpSb->Timer);
 FreePool (MtftpSb);
 return Status;
   }
 
   //
@@ -194,10 +207,11 @@ Mtftp4CreateService (
   NULL,
   NULL,
   >TimerToGetMap
   );
   if (EFI_ERROR (Status)) {
+gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
 gBS->CloseEvent (MtftpSb->Timer);
 FreePool (MtftpSb);
 return Status;
   }
 
@@ -209,10 +223,11 @@ Mtftp4CreateService (
   NULL
   );
 
   if (MtftpSb->ConnectUdp == NULL) {
 gBS->CloseEvent (MtftpSb->TimerToGetMap);
+gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
 gBS->CloseEvent (MtftpSb->Timer);
 FreePool (MtftpSb);
 return EFI_DEVICE_ERROR;
   }
 
@@ -232,10 +247,11 @@ Mtftp4CleanService (
   IN MTFTP4_SERVICE *MtftpSb
   )
 {
   UdpIoFreeIo (MtftpSb->ConnectUdp);
   gBS->CloseEvent (MtftpSb->TimerToGetMap);
+  gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
   gBS->CloseEvent (MtftpSb->Timer);
 }
 
 
 /**
@@ -292,10 +308,16 @@ Mtftp4DriverBindingStart (
 
   if (EFI_ERROR (Status)) {
 goto ON_ERROR;
   }
 
+  Status = gBS->SetTimer (MtftpSb->TimerNotifyLevel, TimerPeriodic, 
TICKS_PER_SECOND);
+
+  if (EFI_ERROR (Status)) {
+goto ON_ERROR;
+  }
+  
   //
   // Install the Mtftp4ServiceBinding Protocol onto Controller
   //
   Status = gBS->InstallMultipleProtocolInterfaces (
   ,
diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c 
b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
index f5f9e6d8f7..d8c48ec8b2 100644
--- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
+++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
@@ -1080,10 +1080,11 @@ EfiMtftp4Poll (
   IN EFI_MTFTP4_PROTOCOL*This
   )
 {
   MTFTP4_PROTOCOL   *Instance;
   EFI_UDP4_PROTOCOL *Udp;
+  EFI_STATUSStatus;
 
   if (This == NULL) {
 return EFI_INVALID_PARAMETER;
   }
 
@@ -1094,11 +1095,13 @@ EfiMtftp4Poll (
   } else if (Instance->State == 

Re: [edk2] [RFC v1 1/1] MdeModulePkg/Usb: Use Pcd for UsbBootIoBlocks

2018-03-01 Thread Ming Huang


On 2018/2/27 18:01, Ni, Ruiyu wrote:
> On 2/27/2018 5:25 PM, Ming Huang wrote:
>>
>>
>> On 2018/2/27 13:25, Ni, Ruiyu wrote:
>>> I don't prefer to add PCD, unless we cannot find:
>>> 1. spec content  to describe the max/min blocks
>> There is no spec about the max/min blocks in my mind. I had checked this in
>> several pdf document like
>> Universal Serial Bus Mass Storage Class Specification Overview,
>> Universal Serial Bus Mass Storage Specification For Bootability,
>> Universal Serial Bus Mass Storage Class Bulk-Only Transport.
>>> 2. error handling when the blocks number is bigger than HW expects.
>> Where should error handling add to?  Error handing can't add to HW 
>> (end-point device),
>> because HW is not in our control scope.
> I mean maybe spec describes an error status could be returned from HW when 
> using 128. So that we can use 64, 32, and smaller value until HW is happy.
>
> I am curious how the other USB storage drivers handle this.
> PCD is a static way. Dynamic way is more preferred.
>

When using 128,  after waiting 5x5(USB_BOOT_COMMAND_RETRY=5, 
USB_BOOT_GENERAL_CMD_TIMEOUT=5) seconds,
the UsbBootReadBlocks ->UsbBootExecCmdWithRetry retrun TimeOut. I don't know 
why HW return Timeout.
Booting time is to long if using Dynamic way to fix the issue.
When using 64, It works and booting from HW succeed.
May be using PCD is a simple and effective mean.

Thanks
Ming
>
>>>
>>> Thanks/Ray
>>>
 -Original Message-
 From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
 Ming Huang
 Sent: Saturday, February 24, 2018 5:30 PM
 To: leif.lindh...@linaro.org; linaro-u...@lists.linaro.org; edk2-
 de...@lists.01.org; graeme.greg...@linaro.org; Zeng, Star
 ; Dong, Eric 
 Cc: huangmin...@huawei.com; ard.biesheu...@linaro.org; Ming Huang
 ; Gao, Liming ;
 mengfanr...@huawei.com; guoh...@huawei.com;
 zhangjinso...@huawei.com; Kinney, Michael D
 ; wai...@126.com;
 wanghuiqi...@huawei.com; huangda...@hisilicon.com
 Subject: [edk2] [RFC v1 1/1] MdeModulePkg/Usb: Use Pcd for
 UsbBootIoBlocks

 Booting from USB may fail while the macro USB_BOOT_IO_BLOCKS set to 128
 because 128 blocks is exceeded the maximun blocks of some USB
 devices,like some virtual CD-ROM from BMC. So, give a chance to set the
 value of USB_BOOT_IO_BLOCKS by adding a Pcd.

 Contributed-under: TianoCore Contribution Agreement 1.1
 Signed-off-by: Ming Huang 
 ---
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h | 7
 +--
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf | 4
 
   MdeModulePkg/MdeModulePkg.dec    | 4 
   MdeModulePkg/MdeModulePkg.uni    | 4 
   4 files changed, 17 insertions(+), 2 deletions(-)

 diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
 b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
 index 5ee50ac52a21..ca9240adbd5f 100644
 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
 +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
 @@ -16,6 +16,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
 KIND, EITHER EXPRESS OR IMPLIED.
   #ifndef _EFI_USB_MASS_BOOT_H_
   #define _EFI_USB_MASS_BOOT_H_

 +#include 
 +
   //
   // The opcodes of various USB boot commands:
   // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified @@
 -66,9 +68,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
 KIND, EITHER EXPRESS OR IMPLIED.
   #define USB_PDT_SIMPLE_DIRECT   0x0E   ///< Simplified 
 direct access
 device

   //
 -// Other parameters, Max carried size is 512B * 128 = 64KB
 +// Other parameters, Max carried size is depanded on Pcd.
 +// The default of PcdUsbBootIoBlocks is 128. 512B * 128 = 64KB
   //
 -#define USB_BOOT_IO_BLOCKS  128
 +#define USB_BOOT_IO_BLOCKS  (FixedPcdGet32
 (PcdUsbBootIoBlocks))

   //
   // Retry mass command times, set by experience diff --git
 a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 index 26d15c7679bf..40426512f884 100644
 ---
 a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 +++
 b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 @@ -60,6 +60,7 @@ [Sources]
     UsbMassDiskInfo.c

   [Packages]
 +  MdeModulePkg/MdeModulePkg.dec
     MdePkg/MdePkg.dec

   [LibraryClasses]
 @@ -83,5 +84,8 @@ [Protocols]
   # EVENT_TYPE_RELATIVE_TIMER    ## CONSUMES
   #

 +[FixedPcd]
 +  

Re: [edk2] [PATCH 3/3] UefiCpuPkg S3ResumePei: Signal S3SmmInitDone

2018-03-01 Thread Yao, Jiewen
Hi Star
Can we keep the human readable debug message?

-  DEBUG ((DEBUG_INFO, "SignalEndOfS3Resume - Enter\n"));
+  DEBUG ((DEBUG_INFO, "Signal %g to SMM - Enter\n", HandlerType));

Other update is good to me.
Reviewed-by: jiewen@intel.com


Thank you
Yao Jiewen


> -Original Message-
> From: Zeng, Star
> Sent: Friday, March 2, 2018 1:16 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star ; Yao, Jiewen ;
> Dong, Eric ; Laszlo Ersek 
> Subject: [PATCH 3/3] UefiCpuPkg S3ResumePei: Signal S3SmmInitDone
> 
> Cc: Jiewen Yao 
> Cc: Eric Dong 
> Cc: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng 
> ---
>  UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c  | 42
> +++---
>  .../Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf   |  3 ++
>  2 files changed, 33 insertions(+), 12 deletions(-)
> 
> diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
> b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
> index 4d776891a72d..2cb7b429e59c 100644
> --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
> +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -259,6 +260,12 @@ EFI_PEI_PPI_DESCRIPTOR mPpiListEndOfPeiTable = {
>0
>  };
> 
> +EFI_PEI_PPI_DESCRIPTOR mPpiListS3SmmInitDoneTable = {
> +  (EFI_PEI_PPI_DESCRIPTOR_PPI |
> EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
> +  ,
> +  0
> +};
> +
>  //
>  // Global Descriptor Table (GDT)
>  //
> @@ -322,13 +329,14 @@ IsLongModeWakingVector (
>  }
> 
>  /**
> -  Send EndOfS3Resume event to SmmCore through communication buffer
> way.
> +  Signal to SMM through communication buffer way.
> +
> +  @param[in]  HandlerType   SMI handler type to be signaled.
> 
> -  @retval  EFI_SUCCESS Return send the event success.
>  **/
> -EFI_STATUS
> -SignalEndOfS3Resume (
> -  VOID
> +VOID
> +SignalToSmmByCommunication (
> +  IN EFI_GUID   *HandlerType
>)
>  {
>EFI_STATUS Status;
> @@ -338,7 +346,7 @@ SignalEndOfS3Resume (
>SMM_COMMUNICATE_HEADER_64  Header64;
>VOID   *CommBuffer;
> 
> -  DEBUG ((DEBUG_INFO, "SignalEndOfS3Resume - Enter\n"));
> +  DEBUG ((DEBUG_INFO, "Signal %g to SMM - Enter\n", HandlerType));
> 
>//
>// This buffer consumed in DXE phase, so base on DXE mode to prepare
> communicate buffer.
> @@ -355,7 +363,7 @@ SignalEndOfS3Resume (
>  Header32.MessageLength = 0;
>  CommSize = OFFSET_OF (SMM_COMMUNICATE_HEADER_32, Data);
>}
> -  CopyGuid (CommBuffer, );
> +  CopyGuid (CommBuffer, HandlerType);
> 
>Status = PeiServicesLocatePpi (
>   ,
> @@ -365,7 +373,7 @@ SignalEndOfS3Resume (
>   );
>if (EFI_ERROR (Status)) {
>  DEBUG ((DEBUG_ERROR, "Locate Smm Communicate Ppi failed (%r)!\n",
> Status));
> -return Status;
> +return;
>}
> 
>Status = SmmCommunicationPpi->Communicate (
> @@ -377,8 +385,8 @@ SignalEndOfS3Resume (
>  DEBUG ((DEBUG_ERROR, "SmmCommunicationPpi->Communicate return
> failure (%r)!\n", Status));
>}
> 
> -  DEBUG ((DEBUG_INFO, "SignalEndOfS3Resume - Exit (%r)\n", Status));
> -  return Status;
> +  DEBUG ((DEBUG_INFO, "Signal %g to SMM - Exit (%r)\n", HandlerType,
> Status));
> +  return;
>  }
> 
>  /**
> @@ -464,11 +472,11 @@ S3ResumeBootOs (
>PERF_END_EX (NULL, "EndOfPeiPpi", NULL, 0, PERF_INMODULE_END_ID);
> 
>//
> -  // Signal EndOfS3Resume event.
> +  // Signal EndOfS3Resume to SMM.
>//
>PERF_START_EX (NULL, "EndOfS3Resume", NULL, 0,
> PERF_INMODULE_START_ID);
> 
> -  SignalEndOfS3Resume ();
> +  SignalToSmmByCommunication ();
> 
>PERF_END_EX (NULL, "EndOfS3Resume", NULL, 0,
> PERF_INMODULE_END_ID);
> 
> @@ -787,6 +795,16 @@ S3ResumeExecuteBootScript (
>  Status = SmmAccess->Lock ((EFI_PEI_SERVICES
> **)GetPeiServicesTablePointer (), SmmAccess, Index);
>}
>  }
> +
> +//
> +// Install S3SmmInitDone PPI.
> +//
> +Status = PeiServicesInstallPpi ();
> +ASSERT_EFI_ERROR (Status);
> +//
> +// Signal S3SmmInitDone to SMM.
> +//
> +SignalToSmmByCommunication ();
>}
> 
>if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
> diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
> b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
> index 9522ede726f4..47fecd7d6d80 100644
> --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
> +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
> @@ -78,6 +78,9 @@ [Guids]
>gEfiAcpiVariableGuid
>gEfiAcpiS3ContextGuid ##
> SOMETIMES_CONSUMES ## UNDEFINED # LockBox
>gEdkiiEndOfS3ResumeGuid   ##
> SOMETIMES_CONSUMES ## UNDEFINED # 

Re: [edk2] [PATCH 2/3] MdeModulePkg PiSmmCore: Register SMI handler to install S3SmmInitDone

2018-03-01 Thread Yao, Jiewen
Reviewed-by: jiewen@intel.com

> -Original Message-
> From: Zeng, Star
> Sent: Friday, March 2, 2018 1:16 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star ; Yao, Jiewen 
> Subject: [PATCH 2/3] MdeModulePkg PiSmmCore: Register SMI handler to install
> S3SmmInitDone
> 
> Cc: Jiewen Yao 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng 
> ---
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c   | 62
> ++-
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h   | 26 -
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf |  3 +-
>  3 files changed, 88 insertions(+), 3 deletions(-)
> 
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> index d2f0207b5c83..686b9b45a556 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
> @@ -1,7 +1,7 @@
>  /** @file
>SMM Core Main Entry Point
> 
> -  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
> +  Copyright (c) 2009 - 2018, 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
> @@ -87,6 +87,7 @@ SMM_CORE_SMI_HANDLERS  mSmmCoreSmiHandlers[]
> = {
>{ SmmExitBootServicesHandler, ,  NULL,
> FALSE },
>{ SmmReadyToBootHandler,  ,
> NULL, FALSE },
>{ SmmEndOfDxeHandler, ,
> NULL, TRUE },
> +  { SmmS3SmmInitDoneHandler,,
> NULL, FALSE },
>{ SmmEndOfS3ResumeHandler,,
> NULL, FALSE },
>{ NULL,   NULL,
> NULL, FALSE }
>  };
> @@ -472,6 +473,65 @@ SmmEndOfDxeHandler (
>  }
> 
>  /**
> +  Software SMI handler that is called when the S3SmmInitDone signal is
> triggered.
> +  This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are
> informed that
> +  S3 SMM initialization has been done.
> +
> +  @param  DispatchHandle  The unique handle assigned to this handler by
> SmiHandlerRegister().
> +  @param  Context Points to an optional handler context which
> was specified when the handler was registered.
> +  @param  CommBuffer  A pointer to a collection of data in memory
> that will
> +  be conveyed from a non-SMM environment into
> an SMM environment.
> +  @param  CommBufferSize  The size of the CommBuffer.
> +
> +  @return Status Code
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmS3SmmInitDoneHandler (
> +  IN EFI_HANDLE  DispatchHandle,
> +  IN CONST VOID  *Context,OPTIONAL
> +  IN OUT VOID*CommBuffer, OPTIONAL
> +  IN OUT UINTN   *CommBufferSize  OPTIONAL
> +  )
> +{
> +  EFI_STATUS  Status;
> +  EFI_HANDLE  SmmHandle;
> +
> +  DEBUG ((DEBUG_INFO, "SmmS3SmmInitDoneHandler\n"));
> +
> +  if (!mDuringS3Resume) {
> +DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
> +return EFI_SUCCESS;
> +  }
> +
> +  //
> +  // Install SMM S3SmmInitDone protocol
> +  //
> +  SmmHandle = NULL;
> +  Status = SmmInstallProtocolInterface (
> + ,
> + ,
> + EFI_NATIVE_INTERFACE,
> + NULL
> + );
> +  ASSERT_EFI_ERROR (Status);
> +
> +  //
> +  // Uninstall the protocol here because the comsumer just hook the
> +  // installation event.
> +  //
> +  Status = SmmUninstallProtocolInterface (
> +   SmmHandle,
> +   ,
> +   NULL
> +   );
> +  ASSERT_EFI_ERROR (Status);
> +
> +  return Status;
> +}
> +
> +/**
>Software SMI handler that is called when the EndOfS3Resume signal is
> triggered.
>This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are
> informed that
>S3 resume has finished.
> diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> index 8c10d833e2ae..2f6032646f46 100644
> --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
> @@ -2,7 +2,7 @@
>The internal header file includes the common header files, defines
>internal structure and functions used by SmmCore module.
> 
> -  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
> +  Copyright (c) 2009 - 2018, 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
> @@ -42,6 +42,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  #include 
>  #include 
> @@ -811,6 +812,29 @@ SmmReadyToBootHandler (
>);
> 
>  /**
> +  Software SMI handler that is called when the S3SmmInitDone signal is
> triggered.
> +  This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are
> informed 

Re: [edk2] [PATCH 1/3] MdeModulePkg: Add S3SmmInitDone definition

2018-03-01 Thread Yao, Jiewen
Reviewed-by: jiewen@intel.com

> -Original Message-
> From: Zeng, Star
> Sent: Friday, March 2, 2018 1:16 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star ; Yao, Jiewen 
> Subject: [PATCH 1/3] MdeModulePkg: Add S3SmmInitDone definition
> 
> Add gEdkiiS3SmmInitDoneGuid, after S3 SMM initialization is done and
> before S3 boot script is executed, this GUID is installed as PPI in
> PEI and protocol in SMM environment. It allows for PEIMs or SMM
> drivers to hook this point and do the required tasks.
> 
> Cc: Jiewen Yao 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng 
> ---
>  MdeModulePkg/Include/Guid/S3SmmInitDone.h | 27
> +++
>  MdeModulePkg/MdeModulePkg.dec |  3 +++
>  2 files changed, 30 insertions(+)
>  create mode 100644 MdeModulePkg/Include/Guid/S3SmmInitDone.h
> 
> diff --git a/MdeModulePkg/Include/Guid/S3SmmInitDone.h
> b/MdeModulePkg/Include/Guid/S3SmmInitDone.h
> new file mode 100644
> index ..53fef8ed19ef
> --- /dev/null
> +++ b/MdeModulePkg/Include/Guid/S3SmmInitDone.h
> @@ -0,0 +1,27 @@
> +/** @file
> +  After S3 SMM initialization is done and before S3 boot script is executed,
> +  this GUID is installed as PPI in PEI and protocol in SMM environment.
> +  It allows for PEIMs or SMM drivers to hook this point and do the required
> tasks.
> +
> +  Copyright (c) 2018, 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.
> +
> +**/
> +
> +#ifndef __S3_SMM_INIT_DONE_H__
> +#define __S3_SMM_INIT_DONE_H__
> +
> +#define EDKII_S3_SMM_INIT_DONE_GUID \
> +  { \
> +0x8f9d4825, 0x797d, 0x48fc, { 0x84, 0x71, 0x84, 0x50, 0x25, 0x79, 0x2e,
> 0xf6 } \
> +  }
> +
> +extern EFI_GUID gEdkiiS3SmmInitDoneGuid;
> +
> +#endif
> diff --git a/MdeModulePkg/MdeModulePkg.dec
> b/MdeModulePkg/MdeModulePkg.dec
> index 455979386e3f..2b24ba506832 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -406,6 +406,9 @@ [Guids]
>## Include/Guid/EndofS3Resume.h
>gEdkiiEndOfS3ResumeGuid = { 0x96f5296d, 0x05f7, 0x4f3c, {0x84, 0x67,
> 0xe4, 0x56, 0x89, 0x0e, 0x0c, 0xb5 } }
> 
> +  ## Include/Guid/S3SmmInitDone.h
> +  gEdkiiS3SmmInitDoneGuid = { 0x8f9d4825, 0x797d, 0x48fc, { 0x84, 0x71,
> 0x84, 0x50, 0x25, 0x79, 0x2e, 0xf6 } }
> +
>  [Ppis]
>## Include/Ppi/AtaController.h
>gPeiAtaControllerPpiGuid   = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0,
> 0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}
> --
> 2.7.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] UefiCpuPkg/MpInitLib: put mReservedApLoopFunc in executable memory

2018-03-01 Thread Jian J Wang
if PcdDxeNxMemoryProtectionPolicy is enabled for EfiReservedMemoryType
of memory, #PF will be triggered for each APs after ExitBootServices
in SCRT test. The root cause is that AP wakeup code executed at that
time is stored in memory of type EfiReservedMemoryType (referenced by
global mReservedApLoopFunc), which is marked as non-executable.

This patch fixes this issue by setting memory of mReservedApLoopFunc to
be executable immediately after allocation.

Cc: Ruiyu Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index fd2317924f..5fcb08677c 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -399,6 +399,21 @@ InitMpGlobalData (

);
   ASSERT_EFI_ERROR (Status);
+
+  //
+  // Make sure that the buffer memory is executable.
+  //
+  Status = gDS->GetMemorySpaceDescriptor (Address, );
+  if (!EFI_ERROR (Status)) {
+gDS->SetMemorySpaceAttributes (
+   Address,
+   EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (
+ CpuMpData->AddressMap.RelocateApLoopFuncSize
+ )),
+   MemDesc.Attributes & (~EFI_MEMORY_XP)
+   );
+  }
+
   mReservedApLoopFunc = (VOID *) (UINTN) Address;
   ASSERT (mReservedApLoopFunc != NULL);
   mReservedTopOfApStack = (UINTN) Address + EFI_PAGES_TO_SIZE 
(EFI_SIZE_TO_PAGES (ApSafeBufferSize));
-- 
2.15.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] Can you set a PCD value DSC default per ModuleType?

2018-03-01 Thread Andrew Fish


> On Mar 1, 2018, at 9:43 PM, Kinney, Michael D  
> wrote:
> 
> Andrew,
> 
> DSC does not support module type specific syntax.
> Just arch specific syntax.
> 
> https://edk2-docs.gitbooks.io/edk-ii-dsc-specification/content/2_dsc_overview/29_pcd_sections.html#29-pcd-sections
> 

Mike,

I understand. My question is why?

Actually I have a module with some shared code and a shared INF and I was 
looking at a way of conditionally including code. So I tried this. Which I 
notice is no longer in the tree. 

MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf:40:  X64/VirtualMemory.c  
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode

The reason for conditionally including the code is the library can run in a lot 
of different module types, but I need to call one line that is module specific 
and I was trying to figure out if I could do that conditionally?  Do I really 
need a new Library class to abstract  one line of code? Or do I need to clone 
the INF. The problem is my library gets include in the DXE CORE and SMM CORE 
and I'm have one line of DXE CORE only magic I was trying to abstract. 

Is there a way short of a new library class for one line of code to do this? 
The PCD worked, but I had to use the <> override to every place the DXE Core 
was referenced, which is not ideal. 

Thanks,

Andrew Fish

> Mike
> 
>> -Original Message-
>> From: edk2-devel [mailto:edk2-devel-
>> boun...@lists.01.org] On Behalf Of Andrew Fish
>> Sent: Thursday, March 1, 2018 8:07 PM
>> To: edk2-devel 
>> Subject: Re: [edk2] Can you set a PCD value DSC default
>> per ModuleType?
>> 
>> Sorry for a FeatureFlag, obviously anything dynamic
>> needs to be generic.
>> 
>> Thanks,
>> 
>> Andrew Fish
>> 
>>> On Mar 1, 2018, at 8:05 PM, Andrew Fish
>>  wrote:
>>> 
>>> Can you set a PCD value DSC default per ModuleType?
>> If not why not?
>>> 
>>> Thanks,
>>> 
>>> Andrew Fish
>>> ___
>>> edk2-devel mailing list
>>> edk2-devel@lists.01.org
>>> https://lists.01.org/mailman/listinfo/edk2-devel
>> 
>> ___
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [patch] MdeModulePkg/DxeCorePerfLib: Add status check instead of ASSERT

2018-03-01 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Dandan 
> Bi
> Sent: Thursday, March 1, 2018 3:14 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star ; Gao, Liming 
> Subject: [edk2] [patch] MdeModulePkg/DxeCorePerfLib: Add status check instead 
> of ASSERT
> 
> Currently DxeCorePerformanceLib will get SMM performance data based
> on SMM communication handler. If SMM communication handler returns error,
> the library will ASSERT. In fact, if SMM perf data is not found.
> DXE perf data can still be dumped. So using status check instead of
> ASSERT is better.
> 
> Cc: Liming Gao 
> Cc: Star Zeng 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Dandan Bi 
> ---
>  MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git 
> a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
> b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
> index 9b3224e..71d624f 100644
> --- a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
> +++ b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
> @@ -281,13 +281,12 @@ AllocateBootPerformanceTable (
>  // Get the size of boot records.
>  //
>  SmmCommData->Function   = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;
>  SmmCommData->BootRecordData = NULL;
>  Status = Communication->Communicate (Communication, 
> SmmBootRecordCommBuffer, );
> -ASSERT_EFI_ERROR (Status);
> 
> -if (!EFI_ERROR (SmmCommData->ReturnStatus) && 
> SmmCommData->BootRecordSize != 0) {
> +if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && 
> SmmCommData->BootRecordSize != 0) {
>//
>// Get all boot records
>//
>SmmCommData->Function   = 
> SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;
>SmmBootRecordDataSize   = SmmCommData->BootRecordSize;
> @@ -315,11 +314,11 @@ AllocateBootPerformanceTable (
>//
>// Prepare memory for Boot Performance table.
>// Boot Performance table includes BasicBoot record, and one or more 
> appended Boot Records.
>//
>BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + 
> mPerformanceLength + PcdGet32
> (PcdExtFpdtBootRecordPadSize);
> -  if (SmmCommData != NULL) {
> +  if (SmmCommData != NULL && SmmBootRecordData != NULL) {
>  BootPerformanceDataSize += SmmBootRecordDataSize;
>}
> 
>//
>// Try to allocate the same runtime buffer as last time boot.
> --
> 1.9.5.msysgit.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] Can you set a PCD value DSC default per ModuleType?

2018-03-01 Thread Kinney, Michael D
Andrew,

DSC does not support module type specific syntax.
Just arch specific syntax.

https://edk2-docs.gitbooks.io/edk-ii-dsc-specification/content/2_dsc_overview/29_pcd_sections.html#29-pcd-sections

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-
> boun...@lists.01.org] On Behalf Of Andrew Fish
> Sent: Thursday, March 1, 2018 8:07 PM
> To: edk2-devel 
> Subject: Re: [edk2] Can you set a PCD value DSC default
> per ModuleType?
> 
> Sorry for a FeatureFlag, obviously anything dynamic
> needs to be generic.
> 
> Thanks,
> 
> Andrew Fish
> 
> > On Mar 1, 2018, at 8:05 PM, Andrew Fish
>  wrote:
> >
> > Can you set a PCD value DSC default per ModuleType?
> If not why not?
> >
> > Thanks,
> >
> > Andrew Fish
> > ___
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [patch] MdeModulePkg: Fix incorrect commit introduced by commit SHA-1:052c98

2018-03-01 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: Bi, Dandan
> Sent: Thursday, March 1, 2018 3:14 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming ; Zeng, Star ; Ni, 
> Ruiyu 
> Subject: [patch] MdeModulePkg: Fix incorrect commit introduced by commit 
> SHA-1:052c98
> 
> The default value of PcdExtFpdtBootRecordPadSize is 0x2
> But the following commit in master update it to 0 by mistake.
> SHA-1: 052c98ce246a1ffb0b4c5185a644aa9f902650f7
> Subject: MdeModulePkg: Add ResetSystemPei PEIM
> 
> This patch is to restore the value.
> 
> Cc: Liming Gao 
> Cc: Star Zeng 
> Cc: Ruiyu Ni 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Dandan Bi 
> ---
>  MdeModulePkg/MdeModulePkg.dec | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
> index ba05859..d1b1af5 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -1743,11 +1743,11 @@
>
> gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosEntryPointProvideMethod|0x3|UINT32|0x00010069
> 
>## This PCD specifies the additional pad size in FPDT Basic Boot 
> Performance Table for
>#  the extension FPDT boot records received after ReadyToBoot and before 
> ExitBootService.
># @Prompt Pad size for extension FPDT boot records.
> -  
> gEfiMdeModulePkgTokenSpaceGuid.PcdExtFpdtBootRecordPadSize|0x0|UINT32|0x0001005F
> +  
> gEfiMdeModulePkgTokenSpaceGuid.PcdExtFpdtBootRecordPadSize|0x2|UINT32|0x0001005F
> 
>## Indicates if ConIn device are connected on demand.
>#   TRUE  - ConIn device are not connected during BDS and 
> ReadKeyStroke/ReadKeyStrokeEx produced
>#   by Consplitter should be called before any real key read 
> operation.
>#   FALSE - ConIn device may be connected normally during BDS.
> --
> 1.9.5.msysgit.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 1/3] MdeModulePkg: Add S3SmmInitDone definition

2018-03-01 Thread Star Zeng
Add gEdkiiS3SmmInitDoneGuid, after S3 SMM initialization is done and
before S3 boot script is executed, this GUID is installed as PPI in
PEI and protocol in SMM environment. It allows for PEIMs or SMM
drivers to hook this point and do the required tasks.

Cc: Jiewen Yao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng 
---
 MdeModulePkg/Include/Guid/S3SmmInitDone.h | 27 +++
 MdeModulePkg/MdeModulePkg.dec |  3 +++
 2 files changed, 30 insertions(+)
 create mode 100644 MdeModulePkg/Include/Guid/S3SmmInitDone.h

diff --git a/MdeModulePkg/Include/Guid/S3SmmInitDone.h 
b/MdeModulePkg/Include/Guid/S3SmmInitDone.h
new file mode 100644
index ..53fef8ed19ef
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/S3SmmInitDone.h
@@ -0,0 +1,27 @@
+/** @file
+  After S3 SMM initialization is done and before S3 boot script is executed,
+  this GUID is installed as PPI in PEI and protocol in SMM environment. 
+  It allows for PEIMs or SMM drivers to hook this point and do the required 
tasks.
+
+  Copyright (c) 2018, 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. 
+
+**/
+
+#ifndef __S3_SMM_INIT_DONE_H__
+#define __S3_SMM_INIT_DONE_H__
+
+#define EDKII_S3_SMM_INIT_DONE_GUID \
+  { \
+0x8f9d4825, 0x797d, 0x48fc, { 0x84, 0x71, 0x84, 0x50, 0x25, 0x79, 0x2e, 
0xf6 } \
+  }
+
+extern EFI_GUID gEdkiiS3SmmInitDoneGuid;
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 455979386e3f..2b24ba506832 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -406,6 +406,9 @@ [Guids]
   ## Include/Guid/EndofS3Resume.h
   gEdkiiEndOfS3ResumeGuid = { 0x96f5296d, 0x05f7, 0x4f3c, {0x84, 0x67, 0xe4, 
0x56, 0x89, 0x0e, 0x0c, 0xb5 } }
 
+  ## Include/Guid/S3SmmInitDone.h
+  gEdkiiS3SmmInitDoneGuid = { 0x8f9d4825, 0x797d, 0x48fc, { 0x84, 0x71, 0x84, 
0x50, 0x25, 0x79, 0x2e, 0xf6 } }
+
 [Ppis]
   ## Include/Ppi/AtaController.h
   gPeiAtaControllerPpiGuid   = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0, 0x7a, 
0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}
-- 
2.7.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 3/3] UefiCpuPkg S3ResumePei: Signal S3SmmInitDone

2018-03-01 Thread Star Zeng
Cc: Jiewen Yao 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng 
---
 UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c  | 42 +++---
 .../Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf   |  3 ++
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c 
b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
index 4d776891a72d..2cb7b429e59c 100644
--- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
+++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -259,6 +260,12 @@ EFI_PEI_PPI_DESCRIPTOR mPpiListEndOfPeiTable = {
   0
 };
 
+EFI_PEI_PPI_DESCRIPTOR mPpiListS3SmmInitDoneTable = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  0
+};
+
 //
 // Global Descriptor Table (GDT)
 //
@@ -322,13 +329,14 @@ IsLongModeWakingVector (
 }
 
 /**
-  Send EndOfS3Resume event to SmmCore through communication buffer way.
+  Signal to SMM through communication buffer way.
+
+  @param[in]  HandlerType   SMI handler type to be signaled.
 
-  @retval  EFI_SUCCESS Return send the event success.
 **/
-EFI_STATUS
-SignalEndOfS3Resume (
-  VOID
+VOID
+SignalToSmmByCommunication (
+  IN EFI_GUID   *HandlerType
   )
 {
   EFI_STATUS Status;
@@ -338,7 +346,7 @@ SignalEndOfS3Resume (
   SMM_COMMUNICATE_HEADER_64  Header64;
   VOID   *CommBuffer;
 
-  DEBUG ((DEBUG_INFO, "SignalEndOfS3Resume - Enter\n"));
+  DEBUG ((DEBUG_INFO, "Signal %g to SMM - Enter\n", HandlerType));
 
   //
   // This buffer consumed in DXE phase, so base on DXE mode to prepare 
communicate buffer.
@@ -355,7 +363,7 @@ SignalEndOfS3Resume (
 Header32.MessageLength = 0;
 CommSize = OFFSET_OF (SMM_COMMUNICATE_HEADER_32, Data);
   }
-  CopyGuid (CommBuffer, );
+  CopyGuid (CommBuffer, HandlerType);
 
   Status = PeiServicesLocatePpi (
  ,
@@ -365,7 +373,7 @@ SignalEndOfS3Resume (
  );
   if (EFI_ERROR (Status)) {
 DEBUG ((DEBUG_ERROR, "Locate Smm Communicate Ppi failed (%r)!\n", Status));
-return Status;
+return;
   }
 
   Status = SmmCommunicationPpi->Communicate (
@@ -377,8 +385,8 @@ SignalEndOfS3Resume (
 DEBUG ((DEBUG_ERROR, "SmmCommunicationPpi->Communicate return failure 
(%r)!\n", Status));
   }
 
-  DEBUG ((DEBUG_INFO, "SignalEndOfS3Resume - Exit (%r)\n", Status));
-  return Status;
+  DEBUG ((DEBUG_INFO, "Signal %g to SMM - Exit (%r)\n", HandlerType, Status));
+  return;
 }
 
 /**
@@ -464,11 +472,11 @@ S3ResumeBootOs (
   PERF_END_EX (NULL, "EndOfPeiPpi", NULL, 0, PERF_INMODULE_END_ID);
 
   //
-  // Signal EndOfS3Resume event.
+  // Signal EndOfS3Resume to SMM.
   //
   PERF_START_EX (NULL, "EndOfS3Resume", NULL, 0, PERF_INMODULE_START_ID);
 
-  SignalEndOfS3Resume ();
+  SignalToSmmByCommunication ();
 
   PERF_END_EX (NULL, "EndOfS3Resume", NULL, 0, PERF_INMODULE_END_ID);
 
@@ -787,6 +795,16 @@ S3ResumeExecuteBootScript (
 Status = SmmAccess->Lock ((EFI_PEI_SERVICES 
**)GetPeiServicesTablePointer (), SmmAccess, Index);
   }
 }
+
+//
+// Install S3SmmInitDone PPI.
+//
+Status = PeiServicesInstallPpi ();
+ASSERT_EFI_ERROR (Status);
+//
+// Signal S3SmmInitDone to SMM.
+//
+SignalToSmmByCommunication ();
   }
 
   if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf 
b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
index 9522ede726f4..47fecd7d6d80 100644
--- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
+++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
@@ -78,6 +78,9 @@ [Guids]
   gEfiAcpiVariableGuid
   gEfiAcpiS3ContextGuid ## SOMETIMES_CONSUMES ## 
UNDEFINED # LockBox
   gEdkiiEndOfS3ResumeGuid   ## SOMETIMES_CONSUMES ## 
UNDEFINED # Used to do smm communication
+  ## SOMETIMES_PRODUCES ## UNDEFINED # Install PPI
+  ## SOMETIMES_CONSUMES ## UNDEFINED # Used to do smm communication
+  gEdkiiS3SmmInitDoneGuid
 
 [Ppis]
   gEfiPeiReadOnlyVariable2PpiGuid   ## CONSUMES
-- 
2.7.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 2/3] MdeModulePkg PiSmmCore: Register SMI handler to install S3SmmInitDone

2018-03-01 Thread Star Zeng
Cc: Jiewen Yao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng 
---
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.c   | 62 ++-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h   | 26 -
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf |  3 +-
 3 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c 
b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
index d2f0207b5c83..686b9b45a556 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
@@ -1,7 +1,7 @@
 /** @file
   SMM Core Main Entry Point
 
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2018, 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
@@ -87,6 +87,7 @@ SMM_CORE_SMI_HANDLERS  mSmmCoreSmiHandlers[] = {
   { SmmExitBootServicesHandler, ,  NULL, 
FALSE },
   { SmmReadyToBootHandler,  ,   NULL, 
FALSE },
   { SmmEndOfDxeHandler, , NULL, 
TRUE },
+  { SmmS3SmmInitDoneHandler,,NULL, 
FALSE },
   { SmmEndOfS3ResumeHandler,,NULL, 
FALSE },
   { NULL,   NULL,NULL, 
FALSE }
 };
@@ -472,6 +473,65 @@ SmmEndOfDxeHandler (
 }
 
 /**
+  Software SMI handler that is called when the S3SmmInitDone signal is 
triggered.
+  This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are 
informed that
+  S3 SMM initialization has been done.
+
+  @param  DispatchHandle  The unique handle assigned to this handler by 
SmiHandlerRegister().
+  @param  Context Points to an optional handler context which was 
specified when the handler was registered.
+  @param  CommBuffer  A pointer to a collection of data in memory that will
+  be conveyed from a non-SMM environment into an SMM 
environment.
+  @param  CommBufferSize  The size of the CommBuffer.
+
+  @return Status Code
+
+**/
+EFI_STATUS
+EFIAPI
+SmmS3SmmInitDoneHandler (
+  IN EFI_HANDLE  DispatchHandle,
+  IN CONST VOID  *Context,OPTIONAL
+  IN OUT VOID*CommBuffer, OPTIONAL
+  IN OUT UINTN   *CommBufferSize  OPTIONAL
+  )
+{
+  EFI_STATUS  Status;
+  EFI_HANDLE  SmmHandle;
+
+  DEBUG ((DEBUG_INFO, "SmmS3SmmInitDoneHandler\n"));
+
+  if (!mDuringS3Resume) {
+DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
+return EFI_SUCCESS;
+  }
+
+  //
+  // Install SMM S3SmmInitDone protocol
+  //
+  SmmHandle = NULL;
+  Status = SmmInstallProtocolInterface (
+ ,
+ ,
+ EFI_NATIVE_INTERFACE,
+ NULL
+ );
+  ASSERT_EFI_ERROR (Status);
+
+  //
+  // Uninstall the protocol here because the comsumer just hook the
+  // installation event.
+  //
+  Status = SmmUninstallProtocolInterface (
+   SmmHandle,
+   ,
+   NULL
+   );
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}
+
+/**
   Software SMI handler that is called when the EndOfS3Resume signal is 
triggered.
   This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are 
informed that
   S3 resume has finished.
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h 
b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
index 8c10d833e2ae..2f6032646f46 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
@@ -2,7 +2,7 @@
   The internal header file includes the common header files, defines
   internal structure and functions used by SmmCore module.
 
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2018, 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
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -811,6 +812,29 @@ SmmReadyToBootHandler (
   );
 
 /**
+  Software SMI handler that is called when the S3SmmInitDone signal is 
triggered.
+  This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are 
informed that
+  S3 SMM initialization has been done.
+
+  @param  DispatchHandle  The unique handle assigned to this handler by 
SmiHandlerRegister().
+  @param  Context Points to an optional handler context which was 
specified when the handler was registered.
+  @param  CommBuffer  A pointer to a collection of data in memory that will
+  be conveyed from a non-SMM environment into an SMM 
environment.
+  @param  CommBufferSize  The size of the CommBuffer.
+
+  

[edk2] [PATCH 0/3] Add S3SmmInitDone point

2018-03-01 Thread Star Zeng
Add gEdkiiS3SmmInitDoneGuid, after S3 SMM initialization is done and
before S3 boot script is executed, this GUID is installed as PPI in
PEI and protocol in SMM environment. It allows for PEIMs or SMM
drivers to hook this point and do the required tasks.

S3Resume will install the PPI and signal to SMM by communication,
and then PiSmmCore will install the protocol.

Star Zeng (3):
  MdeModulePkg: Add S3SmmInitDone definition
  MdeModulePkg PiSmmCore: Register SMI handler to install S3SmmInitDone
  UefiCpuPkg S3ResumePei: Signal S3SmmInitDone

 MdeModulePkg/Core/PiSmmCore/PiSmmCore.c| 62 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h| 26 -
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf  |  3 +-
 MdeModulePkg/Include/Guid/S3SmmInitDone.h  | 27 ++
 MdeModulePkg/MdeModulePkg.dec  |  3 ++
 UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c  | 42 ++-
 .../Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf   |  3 ++
 7 files changed, 151 insertions(+), 15 deletions(-)
 create mode 100644 MdeModulePkg/Include/Guid/S3SmmInitDone.h

-- 
2.7.0.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] Can you set a PCD value DSC default per ModuleType?

2018-03-01 Thread Andrew Fish
Sorry for a FeatureFlag, obviously anything dynamic needs to be generic.

Thanks,

Andrew Fish

> On Mar 1, 2018, at 8:05 PM, Andrew Fish  wrote:
> 
> Can you set a PCD value DSC default per ModuleType? If not why not?
> 
> Thanks,
> 
> Andrew Fish
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] Can you set a PCD value DSC default per ModuleType?

2018-03-01 Thread Andrew Fish
Can you set a PCD value DSC default per ModuleType? If not why not?

Thanks,

Andrew Fish
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdeModulePkg/DebugLibReportStatusCode: Fix hang if format is too long

2018-03-01 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: Ni, Ruiyu
> Sent: Thursday, March 1, 2018 2:34 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming 
> Subject: [PATCH] MdeModulePkg/DebugLibReportStatusCode: Fix hang if format is 
> too long
> 
> The previous commit 137ed15511e2045a7333e33ae7f1e873ce1961dd
> * MdeModulePkg/DebugLib: Print partial when format string is too long
> copies partial format string to DEBUG_INFO buffer but when parsing
> the format modifier, the original format string is still used.
> 
> The patch fixes this issue.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni 
> Cc: Liming Gao 
> ---
>  MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> index 16a1d206fb..96c9b30987 100644
> --- a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> +++ b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> @@ -126,6 +126,11 @@ DebugPrint (
>// Here we will process the variable arguments and pack them in this area.
>//
>VA_START (VaListMarker, Format);
> +
> +  //
> +  // Use the actual format string.
> +  //
> +  Format = FormatString;
>for (; *Format != '\0'; Format++) {
>  //
>  // Only format with prefix % is processed.
> --
> 2.16.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] BaseTools: report error if flag in LABEL() invalid

2018-03-01 Thread Zhu, Yonghong
Reviewed-by: Yonghong Zhu 

Best Regards,
Zhu Yonghong


-Original Message-
From: Feng, YunhuaX 
Sent: Thursday, March 01, 2018 4:22 PM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong ; Gao, Liming 
Subject: [PATCH] BaseTools: report error if flag in LABEL() invalid

Flag in LABEL() is not valid C variable name, will report error

Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/Common/Expression.py | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Expression.py 
b/BaseTools/Source/Python/Common/Expression.py
index f1516d5c7b..40e6d32280 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -117,10 +117,16 @@ def SplitPcdValueString(String):
 raise BadExpression(ERR_STRING_TOKEN % Item)
 if Item:
 RetList.append(Item)
 return RetList
 
+def IsValidCString(Str):
+ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
+if not ValidString.match(Str):
+return False
+return True
+
 ## ReplaceExprMacro
 #
 def ReplaceExprMacro(String, Macros, ExceptionList = None):
 StrList = SplitString(String)
 for i, String in enumerate(StrList):
@@ -883,17 +889,17 @@ class ValueExpressionEx(ValueExpression):
 ReOffset = re.compile('OFFSET_OF\((\w+)\)')
 LabelOffset = 0
 for Index, Item in enumerate(PcdValueList):
 # compute byte offset of every LABEL
 Item = Item.strip()
-try:
-LabelList = ReLabel.findall(Item)
+LabelList = ReLabel.findall(Item)
+if LabelList:
 for Label in LabelList:
+if not IsValidCString(Label):
+raise BadExpression('%s is 
+ invalid c variable string' % Label)
 if Label not in LabelDict.keys():
 LabelDict[Label] = str(LabelOffset)
-except:
-pass
 if Item.startswith('UINT8'):
 LabelOffset = LabelOffset + 1
 elif Item.startswith('UINT16'):
 LabelOffset = LabelOffset + 2
 elif Item.startswith('UINT32'):
--
2.12.2.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 0/4] implement runtime debug output protocl

2018-03-01 Thread Zeng, Star
Sorry, I did not follow up the thread for DxeRuntimeDebugLibSerialPort.

For this thread, do you think it is feasible below for the case?

Use PeiDxeDebugLibReportStatusCode -> RuntimeDxeReportStatusCodeLib -> 
ReportStatusCodeRouterRuntimeDxe

ReportStatusCodeRouterRuntimeDxe will produce gEfiRscHandlerProtocolGuid 
protocol.
Like StatusCodeHandlerRuntimeDxe, consumer of gEfiRscHandlerProtocolGuid 
protocol can register handler to show debug message and etc.


Thanks,
Star
-Original Message-
From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org] 
Sent: Friday, March 2, 2018 2:12 AM
To: edk2-devel@lists.01.org
Cc: ler...@redhat.com; leif.lindh...@linaro.org; heyi@linaro.org; Zeng, 
Star ; Dong, Eric ; Kinney, Michael D 
; Gao, Liming ; Ard 
Biesheuvel 
Subject: [PATCH 0/4] implement runtime debug output protocl

As discussed on list, MMIO based UARTs cannot be used at runtime without taking 
special precautions to register the MMIO region and switch to the virtual 
address when accessing it at runtime.

So extend the recently introduced DxeRuntimeDebugLibSerialPort library by 
invoking the proposed RuntimeDebugOutput protocol at runtime if one is 
available, and providing an implementation of this protocol for PL011.

Ard Biesheuvel (4):
  MdePkg: move DxeRuntimeDebugLibSerialPort to MdeModulePkg
  MdeModulePkg: introduce runtime debug output protocol
  MdeModulePkg/DxeRuntimeDebugLibSerialPort: invoke
RuntimeDebugOutputProtocol
  ArmPlatformPkg: add PL011 UART runtime debug driver

 ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c 
| 144 ++
 
ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf
   |  62 
 ArmVirtPkg/ArmVirt.dsc.inc 
|   2 +-
 MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h 
|  58 
 {MdePkg => MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c   
| 155 +---
 {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
 |   5 +
 {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
 |   0
 MdeModulePkg/MdeModulePkg.dec  
|   4 +
 8 files changed, 412 insertions(+), 18 deletions(-)  create mode 100644 
ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c
 create mode 100644 
ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf
 create mode 100644 MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h
 rename {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c (70%)  rename 
{MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
 (88%)  rename {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
 (100%)

--
2.11.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550: Prevent truncating constant values.

2018-03-01 Thread Zeng, Star
Marvin,

Sorry.

What is the warning message?
We still need to use "(UINT16)~(UINT16)(BIT0 | BIT1)"?
All the truncations want to get the value "0xFFFC", right?
So could we try to directly use "0xFFFC"?

Liming and Mike,
Do you have any concern about it?


Thanks,
Star
-Original Message-
From: Marvin Häuser [mailto:marvin.haeu...@outlook.com] 
Sent: Friday, March 2, 2018 1:35 AM
To: edk2-devel@lists.01.org
Cc: Zeng, Star ; Ni, Ruiyu ; 
ler...@redhat.com; Dong, Eric ; Zeng, Star 

Subject: RE: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550: Prevent 
truncating constant values.

The Base.h changes making BIT definitions unsigned have been denied.
Is a V2 needed for this patch? I verified again that casting the result of the 
inversion triggers the warning, except when casted before doing so, at least by 
VS2017.

Thanks,
Marvin.

> -Original Message-
> From: Zeng, Star 
> Sent: Wednesday, February 28, 2018 3:44 AM
> To: marvin.haeu...@outlook.com; edk2-devel@lists.01.org
> Cc: Ni, Ruiyu ; Laszlo Ersek ; 
> Dong, Eric ; Zeng, Star 
> Subject: RE: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550:
> Prevent truncating constant values.
> 
> Could simply use 0xFFFC for this case?
> 
> Thanks,
> Star
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Marvin H?user
> Sent: Wednesday, February 28, 2018 2:56 AM
> To: edk2-devel@lists.01.org
> Cc: Ni, Ruiyu ; Laszlo Ersek ; 
> Dong, Eric ; Zeng, Star 
> Subject: Re: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550:
> Prevent truncating constant values.
> 
> Hey Laszlo,
> 
> Thanks for your... detailed explanation. :) I actually submitted 
> another patch to prevent what you explained - "[edk2] [PATCH 1/2] 
> MdePkg/Base.h:
> Ensure safe bitwise operations.", which marks all BIT defines (and 
> more) as unsigned.
> Most definitely I should have mentioned it in the commit message or 
> held it back till that patch will be accepted (or denied?), seems like 
> I forgot about that.
> Would you still prefer your suggestion even when the Base.h patch is 
> merged? After all, int might happen to be even larger than INT32, if 
> I'm not mistaken.
> 
> I'm quite sure VS2015x86 issued the warning despite that commit being 
> applied locally. It seems to always warn when a constant is truncated, 
> explicitely or implicitely, to give you the change to increase its size:
> https://msdn.microsoft.com/en-us/library/sz5z1byt.aspx
> 
> Thanks again for your comprehensive review!
> 
> Best regards,
> Marvin.
> 
> > -Original Message-
> > From: Laszlo Ersek 
> > Sent: Tuesday, February 27, 2018 7:35 PM
> > To: Marvin Häuser ; edk2- 
> > de...@lists.01.org
> > Cc: ruiyu...@intel.com; eric.d...@intel.com; star.z...@intel.com
> > Subject: Re: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550:
> > Prevent truncating constant values.
> >
> > Hi Marvin,
> >
> > On 02/27/18 17:49, Marvin Häuser wrote:
> > > The toolcahin VS2015x86 issues warnings when truncating constant 
> > > values. Explicitely cast such to avoid it.
> > >
> > > Contributed-under: TianoCore Contribution Agreement 1.1
> > > Signed-off-by: Marvin Haeuser 
> > > ---
> > >
> > > MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550
> > > .c
> > > | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git
> > >
> >
> a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > >
> >
> b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > > index 0ccac96f419c..10eca6c0a7aa 100644
> > > ---
> > >
> >
> a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > > +++
> > b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib165
> > > +++ 50.c
> > > @@ -366,7 +366,7 @@ GetSerialRegisterBase (
> > >//
> > >if (DeviceInfo->PowerManagementStatusAndControlRegister != 0x00) {
> > >  if ((PciRead16 (PciLibAddress + DeviceInfo-
> > >PowerManagementStatusAndControlRegister) & (BIT0 | BIT1)) != 0x00) {
> > > -  PciAnd16 (PciLibAddress + DeviceInfo-
> > >PowerManagementStatusAndControlRegister, (UINT16)~(BIT0 | BIT1));
> > > +  PciAnd16 (PciLibAddress +
> > > + DeviceInfo->PowerManagementStatusAndControlRegister,
> > > + (UINT16)~(UINT16)(BIT0 | BIT1));
> > >//
> > >// If PCI UART was not in D0, then make sure FIFOs are 
> > > enabled, but do
> > not reset FIFOs
> > >//
> > > @@ -402,7 +402,7 @@ GetSerialRegisterBase (
> > >  //
> > >  if (DeviceInfo->PowerManagementStatusAndControlRegister != 
> > > 0x00)
> {
> > >if ((PciRead16 (PciLibAddress + 

Re: [edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the poll function.

2018-03-01 Thread Wu, Jiaxin
Yes, I agree with you. But we still can't raise time event to TPL_NOTIFY, 
because in the notify callback function, Udp protocol will be called to 
retransmit the packet while it's not allowed to call UDP in the TPL_NOTIFY.



> -Original Message-
> From: Fu, Siyuan
> Sent: Friday, March 2, 2018 9:24 AM
> To: Wu, Jiaxin ; edk2-devel@lists.01.org
> Cc: Wang, Fan ; Ye, Ting 
> Subject: RE: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the
> poll function.
> 
> Jiaxin,
> 
> There will be problem if someone calls Mtftp.Start() at TPL Callback to
> send/receive a file with your patch. In such case the RestoreTpl() won't be
> able to restore the TPL to application level so it will still while loop in 
> the Poll.
> 
> BestRegards
> Fu Siyuan
> 
> > -Original Message-
> > From: Wu, Jiaxin
> > Sent: Friday, March 2, 2018 9:18 AM
> > To: Fu, Siyuan ; edk2-devel@lists.01.org
> > Cc: Wang, Fan ; Ye, Ting 
> > Subject: RE: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before
> the
> > poll function.
> >
> > It's not actual hang but always running at while-poll function in the TPL
> > call back level , meanwhile, the while condition depends on another time
> > event that running on the same TPL. If so, the time event might have no
> > chance to be triggered. So, the code will never run out of while () {}:
> >
> >   while (Token->Status == EFI_NOT_READY) {
> > This->Poll (This);
> >   }
> >
> >
> > Thanks,
> > Jiaxin
> >
> > > -Original Message-
> > > From: Fu, Siyuan
> > > Sent: Thursday, March 1, 2018 7:03 PM
> > > To: Wu, Jiaxin ; edk2-devel@lists.01.org
> > > Cc: Wang, Fan ; Ye, Ting 
> > > Subject: RE: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before
> the
> > > poll function.
> > >
> > > Hi, Jiaxin
> > >
> > > Do you mean the code which calls MTFTP4->Poll() at TPL_CALLBACK will
> > > cause system hang? This should not happen because all network protocol
> > > should be able to run at TPL_CALLBACK.
> > >
> > > BestRegards
> > > Fu Siyuan
> > >
> > >
> > > > -Original Message-
> > > > From: Wu, Jiaxin
> > > > Sent: Thursday, March 1, 2018 5:38 PM
> > > > To: edk2-devel@lists.01.org
> > > > Cc: Wang, Fan ; Fu, Siyuan
> ;
> > > Ye,
> > > > Ting 
> > > > Subject: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before
> the
> > > poll
> > > > function.
> > > >
> > > > This patch is to fix the hang issue, which was enrolled by the commit
> > of
> > > > 39b0867d.
> > > > The TPL should be restored before calling poll function at
> > TPL_CALLBACK.
> > > >
> > > > Cc: Wang Fan 
> > > > Cc: Fu Siyuan 
> > > > Cc: Ye Ting 
> > > > Contributed-under: TianoCore Contribution Agreement 1.0
> > > > Signed-off-by: Jiaxin Wu 
> > > > ---
> > > >  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c | 9
> > > ++---
> > > >  1 file changed, 6 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git
> a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > > b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > > index f5f9e6d8f7..64e0463dd9 100644
> > > > --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > > +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > > @@ -507,24 +507,27 @@ Mtftp4Start (
> > > >if (EFI_ERROR (Status)) {
> > > >  Status = EFI_DEVICE_ERROR;
> > > >  goto ON_ERROR;
> > > >}
> > > >
> > > > +  //
> > > > +  // Restore the TPL now, don't call poll function at TPL_CALLBACK.
> > > > +  //
> > > > +  gBS->RestoreTPL (OldTpl);
> > > > +
> > > >if (Token->Event != NULL) {
> > > > -gBS->RestoreTPL (OldTpl);
> > > >  return EFI_SUCCESS;
> > > >}
> > > >
> > > >//
> > > >// Return immediately for asynchronous operation or poll the
> > > >// instance for synchronous operation.
> > > >//
> > > >while (Token->Status == EFI_NOT_READY) {
> > > >  This->Poll (This);
> > > >}
> > > > -
> > > > -  gBS->RestoreTPL (OldTpl);
> > > > +
> > > >return Token->Status;
> > > >
> > > >  ON_ERROR:
> > > >Mtftp4CleanOperation (Instance, Status);
> > > >gBS->RestoreTPL (OldTpl);
> > > > --
> > > > 2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the poll function.

2018-03-01 Thread Fu, Siyuan
Jiaxin, 

There will be problem if someone calls Mtftp.Start() at TPL Callback to 
send/receive a file with your patch. In such case the RestoreTpl() won't be 
able to restore the TPL to application level so it will still while loop in the 
Poll.

BestRegards
Fu Siyuan

> -Original Message-
> From: Wu, Jiaxin
> Sent: Friday, March 2, 2018 9:18 AM
> To: Fu, Siyuan ; edk2-devel@lists.01.org
> Cc: Wang, Fan ; Ye, Ting 
> Subject: RE: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the
> poll function.
> 
> It's not actual hang but always running at while-poll function in the TPL
> call back level , meanwhile, the while condition depends on another time
> event that running on the same TPL. If so, the time event might have no
> chance to be triggered. So, the code will never run out of while () {}:
> 
>   while (Token->Status == EFI_NOT_READY) {
> This->Poll (This);
>   }
> 
> 
> Thanks,
> Jiaxin
> 
> > -Original Message-
> > From: Fu, Siyuan
> > Sent: Thursday, March 1, 2018 7:03 PM
> > To: Wu, Jiaxin ; edk2-devel@lists.01.org
> > Cc: Wang, Fan ; Ye, Ting 
> > Subject: RE: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the
> > poll function.
> >
> > Hi, Jiaxin
> >
> > Do you mean the code which calls MTFTP4->Poll() at TPL_CALLBACK will
> > cause system hang? This should not happen because all network protocol
> > should be able to run at TPL_CALLBACK.
> >
> > BestRegards
> > Fu Siyuan
> >
> >
> > > -Original Message-
> > > From: Wu, Jiaxin
> > > Sent: Thursday, March 1, 2018 5:38 PM
> > > To: edk2-devel@lists.01.org
> > > Cc: Wang, Fan ; Fu, Siyuan ;
> > Ye,
> > > Ting 
> > > Subject: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the
> > poll
> > > function.
> > >
> > > This patch is to fix the hang issue, which was enrolled by the commit
> of
> > > 39b0867d.
> > > The TPL should be restored before calling poll function at
> TPL_CALLBACK.
> > >
> > > Cc: Wang Fan 
> > > Cc: Fu Siyuan 
> > > Cc: Ye Ting 
> > > Contributed-under: TianoCore Contribution Agreement 1.0
> > > Signed-off-by: Jiaxin Wu 
> > > ---
> > >  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c | 9
> > ++---
> > >  1 file changed, 6 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > index f5f9e6d8f7..64e0463dd9 100644
> > > --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > > @@ -507,24 +507,27 @@ Mtftp4Start (
> > >if (EFI_ERROR (Status)) {
> > >  Status = EFI_DEVICE_ERROR;
> > >  goto ON_ERROR;
> > >}
> > >
> > > +  //
> > > +  // Restore the TPL now, don't call poll function at TPL_CALLBACK.
> > > +  //
> > > +  gBS->RestoreTPL (OldTpl);
> > > +
> > >if (Token->Event != NULL) {
> > > -gBS->RestoreTPL (OldTpl);
> > >  return EFI_SUCCESS;
> > >}
> > >
> > >//
> > >// Return immediately for asynchronous operation or poll the
> > >// instance for synchronous operation.
> > >//
> > >while (Token->Status == EFI_NOT_READY) {
> > >  This->Poll (This);
> > >}
> > > -
> > > -  gBS->RestoreTPL (OldTpl);
> > > +
> > >return Token->Status;
> > >
> > >  ON_ERROR:
> > >Mtftp4CleanOperation (Instance, Status);
> > >gBS->RestoreTPL (OldTpl);
> > > --
> > > 2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] Maintainers.txt: Add Jiewen to be co-maintainer of SecurityPkg.

2018-03-01 Thread Zhang, Chao B
Reviewed-by: Chao Zhang 

-Original Message-
From: Zhang, Chao B 
Sent: Wednesday, February 28, 2018 2:19 PM
To: edk2-devel@lists.01.org
Cc: Yao, Jiewen ; Zhang, Chao B 
Subject: [PATCH] Maintainers.txt: Add Jiewen to be co-maintainer of SecurityPkg.

From: Jiewen Yao 

Cc: Chao B Zhang 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jiewen Yao 
---
 Maintainers.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Maintainers.txt b/Maintainers.txt index 74f2538..e103f85 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -217,6 +217,7 @@ M: Kelly Steele   SecurityPkg
 W: https://github.com/tianocore/tianocore.github.io/wiki/SecurityPkg
 M: Chao Zhang 
+M: Jiewen Yao 
 
 ShellBinPkg
 W: https://github.com/tianocore/tianocore.github.io/wiki/ShellPkg
--
2.7.4.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the poll function.

2018-03-01 Thread Wu, Jiaxin
It's not actual hang but always running at while-poll function in the TPL call 
back level , meanwhile, the while condition depends on another time event that 
running on the same TPL. If so, the time event might have no chance to be 
triggered. So, the code will never run out of while () {}:

  while (Token->Status == EFI_NOT_READY) {
This->Poll (This);
  }


Thanks,
Jiaxin

> -Original Message-
> From: Fu, Siyuan
> Sent: Thursday, March 1, 2018 7:03 PM
> To: Wu, Jiaxin ; edk2-devel@lists.01.org
> Cc: Wang, Fan ; Ye, Ting 
> Subject: RE: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the
> poll function.
> 
> Hi, Jiaxin
> 
> Do you mean the code which calls MTFTP4->Poll() at TPL_CALLBACK will
> cause system hang? This should not happen because all network protocol
> should be able to run at TPL_CALLBACK.
> 
> BestRegards
> Fu Siyuan
> 
> 
> > -Original Message-
> > From: Wu, Jiaxin
> > Sent: Thursday, March 1, 2018 5:38 PM
> > To: edk2-devel@lists.01.org
> > Cc: Wang, Fan ; Fu, Siyuan ;
> Ye,
> > Ting 
> > Subject: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the
> poll
> > function.
> >
> > This patch is to fix the hang issue, which was enrolled by the commit of
> > 39b0867d.
> > The TPL should be restored before calling poll function at TPL_CALLBACK.
> >
> > Cc: Wang Fan 
> > Cc: Fu Siyuan 
> > Cc: Ye Ting 
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Jiaxin Wu 
> > ---
> >  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c | 9
> ++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > index f5f9e6d8f7..64e0463dd9 100644
> > --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> > @@ -507,24 +507,27 @@ Mtftp4Start (
> >if (EFI_ERROR (Status)) {
> >  Status = EFI_DEVICE_ERROR;
> >  goto ON_ERROR;
> >}
> >
> > +  //
> > +  // Restore the TPL now, don't call poll function at TPL_CALLBACK.
> > +  //
> > +  gBS->RestoreTPL (OldTpl);
> > +
> >if (Token->Event != NULL) {
> > -gBS->RestoreTPL (OldTpl);
> >  return EFI_SUCCESS;
> >}
> >
> >//
> >// Return immediately for asynchronous operation or poll the
> >// instance for synchronous operation.
> >//
> >while (Token->Status == EFI_NOT_READY) {
> >  This->Poll (This);
> >}
> > -
> > -  gBS->RestoreTPL (OldTpl);
> > +
> >return Token->Status;
> >
> >  ON_ERROR:
> >Mtftp4CleanOperation (Instance, Status);
> >gBS->RestoreTPL (OldTpl);
> > --
> > 2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 00/20] OvmfPkg: SEV: decrypt the initial SMRAM save state map for SMBASE relocation

2018-03-01 Thread Brijesh Singh


On 3/1/18 6:03 PM, Laszlo Ersek wrote:
> Repo:   https://github.com/lersek/edk2.git
> Branch: sev_smram_save_state_map
>
> This patch series replaces the following patch from Brijesh:
>
>   [PATCH v2 1/2] OvmfPkg/AmdSevDxe: Clear the C-bit from SMM Saved State
>   20180228161415.28723-2-brijesh.singh@amd.com">http://mid.mail-archive.com/20180228161415.28723-2-brijesh.singh@amd.com
>   https://lists.01.org/pipermail/edk2-devel/2018-February/022016.html
>
> The series modifies four modules under OvmfPkg:
> - MemEncryptSevLib
> - PlatformPei
> - SmmCpuFeaturesLib
> - AmdSevDxe
>
> Patches 01 through 16 are cleanups for these modules, without change in
> functionality. The series is formatted with 20 lines of context, for
> simplifying the review of these patches.
>
> Patches 17 through 20 (one patch per module listed above) implement
> $SUBJECT:
>
> - MemEncryptSevLib gets a new helper function used by the other three
>   modules.
>
> - PlatformPei makes sure that DXE stays out of the page(s) where the
>   initial SMRAM save state map lives.
>
> - SmmCpuFeaturesLib and AmdSevDxe basically do what they did in
>   Brijesh's patch, just better separated, and with minor tweaks.
>
> The series is bisectable.
>
> I regression-tested my usual non-SEV guests (with Brijesh's v2 2/2 patch
> applied on top, from the above-referenced series), which covers i440fx
> (no SMM, X64), q35 (SMM, IA32 and IA32X64), Fedora and Windows, normal
> boot and S3.
>
> I also tried to test the series with SEV guests (again with Brijesh's v2
> 2/2 patch applied on top). Unfortunately, I didn't get good results with
> or without SMM. Without SMM, the guest OS boots to a point, but then it
> gets stuck with the CPU spinning. With SMM, OVMF gets stuck in SMBASE
> relocation.

To boot the SEV guest with SMM support we need this KVM patch, without
this we will get either #UD or some undefined behavior.

https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?id=7607b7174405aec7441ff6c970833c463114040a

It's strange that you are having trouble booting SEV guest without SMM
support. It's possible that we might have some mismatch kernel kvm +
qemu + ovmf patches.
>
> I should mention however that my SEV host setup dates back to November
> 2017, including host kernel, QEMU and guest OS. I suppose all those
> components have seen many changes since, on the respective upstream
> lists. I'll have to work with Brijesh to update my SEV host to the
> latest bits.
>
> Until then, Brijesh, can you please test this series? Thank you!


Sure, I will try the series tomorrow morning. thank you so much for the
cleanup and remaining SMM work.


>
> Cc: Ard Biesheuvel 
> Cc: Brijesh Singh 
> Cc: Jordan Justen 
>
> Cheers
> Laszlo
>
> Laszlo Ersek (20):
>   OvmfPkg/MemEncryptSevLib: rewrap to 79 characters width
>   OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevIsEnabled() decl
>   OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevClearPageEncMask()
> decl
>   OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevSetPageEncMask() decl
>   OvmfPkg/MemEncryptSevLib: clean up SetMemoryEncDec() comment block
>   OvmfPkg/MemEncryptSevLib: clean up
> InternalMemEncryptSevSetMemoryDecrypted() decl
>   OvmfPkg/MemEncryptSevLib: clean up
> InternalMemEncryptSevSetMemoryEncrypted() decl
>   OvmfPkg/MemEncryptSevLib: sort #includes, and entries in INF file
> sections
>   OvmfPkg/PlatformPei: sort #includes in "AmdSev.c"
>   OvmfPkg/SmmCpuFeaturesLib: rewrap to 79 columns
>   OvmfPkg/SmmCpuFeaturesLib: upper-case the "static" keyword
>   OvmfPkg/SmmCpuFeaturesLib: sort #includes, and entries in INF file
> sections
>   OvmfPkg/SmmCpuFeaturesLib: remove unneeded #includes and
> LibraryClasses
>   OvmfPkg/AmdSevDxe: rewrap to 79 characters width
>   OvmfPkg/AmdSevDxe: sort #includes, and entries in INF file sections
>   OvmfPkg/AmdSevDxe: refresh #includes and LibraryClasses
>   OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map
>   OvmfPkg/PlatformPei: SEV: allocate pages of initial SMRAM save state
> map
>   OvmfPkg/SmmCpuFeaturesLib: SEV: encrypt+free pages of init. save state
> map
>   OvmfPkg/AmdSevDxe: decrypt the pages of the initial SMRAM save state
> map
>
>  OvmfPkg/AmdSevDxe/AmdSevDxe.c   |  88 ++-
>  OvmfPkg/AmdSevDxe/AmdSevDxe.inf |  25 +-
>  OvmfPkg/Include/Library/MemEncryptSevLib.h  |  89 ++-
>  OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf   |  17 +-
>  OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c|  72 ++-
>  OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c |  66 +-
>  OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c |  74 ++-
>  OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c| 172 --
>  OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h| 137 +++--
>  

Re: [edk2] [PATCH 01/20] OvmfPkg/MemEncryptSevLib: rewrap to 79 characters width

2018-03-01 Thread Kinney, Michael D
Laszlo,

Sorting #includes looks strange to me.

We usually include the top level environment include
first (e.g. ) and then the libs, protocols,
ppis, GUIDs grouped together.

If it is a lib module, the produced libs are listed
first followed by the consumed libs.

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-
> boun...@lists.01.org] On Behalf Of Laszlo Ersek
> Sent: Thursday, March 1, 2018 4:04 PM
> To: edk2-devel-01 
> Cc: Justen, Jordan L ;
> Brijesh Singh ; Ard Biesheuvel
> 
> Subject: [edk2] [PATCH 01/20] OvmfPkg/MemEncryptSevLib:
> rewrap to 79 characters width
> 
> There are many overlong lines; it's hard to work with
> the library like
> this. Rewrap all files to 79 columns.
> 
> Cc: Ard Biesheuvel 
> Cc: Brijesh Singh 
> Cc: Jordan Justen 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Laszlo Ersek 
> ---
> 
> OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL
> ib.inf   |   7 +-
>  OvmfPkg/Include/Library/MemEncryptSevLib.h
> |  20 ++-
> 
> OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.
> h| 111 --
> 
> OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSev
> Lib.c|  34 +++--
> 
> OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibIn
> ternal.c |   8 +-
> 
> OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevL
> ib.c |  58 ---
> 
> OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.
> c| 158 +---
>  7 files changed, 253 insertions(+), 143 deletions(-)
> 
> diff --git
> a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSe
> vLib.inf
> b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSe
> vLib.inf
> index 3cfd80a28c1d..81b075194ace 100644
> ---
> a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSe
> vLib.inf
> +++
> b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSe
> vLib.inf
> @@ -1,45 +1,48 @@
>  ## @file
>  #  Library provides the helper functions for SEV guest
>  #
>  # Copyright (c) 2017 Advanced Micro Devices. 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.
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR
> +#  IMPLIED.
>  #
>  #
>  ##
> 
>  [Defines]
>INF_VERSION= 1.25
>BASE_NAME  = MemEncryptSevLib
>FILE_GUID  = c1594631-3888-4be4-
> 949f-9c630dbc842b
>MODULE_TYPE= BASE
>VERSION_STRING = 1.0
>LIBRARY_CLASS  =
> MemEncryptSevLib|PEIM DXE_DRIVER DXE_RUNTIME_DRIVER
> DXE_SMM_DRIVER UEFI_DRIVER
> 
>  #
> -# The following information is for reference only and
> not required by the build tools.
> +# The following information is for reference only and
> not required by the build
> +# tools.
>  #
>  # VALID_ARCHITECTURES   = IA32 X64
>  #
> 
>  [Packages]
>MdePkg/MdePkg.dec
>MdeModulePkg/MdeModulePkg.dec
>OvmfPkg/OvmfPkg.dec
>UefiCpuPkg/UefiCpuPkg.dec
> 
>  [Sources.X64]
>MemEncryptSevLibInternal.c
>X64/MemEncryptSevLib.c
>X64/VirtualMemory.c
> 
>  [Sources.IA32]
>MemEncryptSevLibInternal.c
>Ia32/MemEncryptSevLib.c
> 
>  [LibraryClasses]
> diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h
> b/OvmfPkg/Include/Library/MemEncryptSevLib.h
> index b6753762423e..4f3ba9f22cb4 100644
> --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h
> +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h
> @@ -18,64 +18,68 @@
>  #define _MEM_ENCRYPT_SEV_LIB_H_
> 
>  #include 
> 
>  /**
>Returns a boolean to indicate whether SEV is enabled
> 
>@retval TRUE   SEV is active
>@retval FALSE  SEV is not enabled
>**/
>  BOOLEAN
>  EFIAPI
>  MemEncryptSevIsEnabled (
>VOID
>);
> 
>  /**
>This function clears memory encryption bit for the
> memory region specified
>by BaseAddress and Number of pages from the current
> page table context.
> 
> -  @param[in]  BaseAddress   The physical
> address that is the start address
> -of a memory
> region.
> -  @param[in]  NumberOfPages The number of
> pages from start memory region.
> +  @param[in]  BaseAddress   The physical
> address that is the start
> +address of a
> memory region.
> +  @param[in]  NumberOfPages The number of
> pages from start memory
> + 

[edk2] [PATCH 19/20] OvmfPkg/SmmCpuFeaturesLib: SEV: encrypt+free pages of init. save state map

2018-03-01 Thread Laszlo Ersek
Based on the following patch from Brijesh Singh :

  [PATCH v2 1/2] OvmfPkg/AmdSevDxe: Clear the C-bit from SMM Saved State
  20180228161415.28723-2-brijesh.singh@amd.com">http://mid.mail-archive.com/20180228161415.28723-2-brijesh.singh@amd.com
  https://lists.01.org/pipermail/edk2-devel/2018-February/022016.html

Once PiSmmCpuDxeSmm relocates SMBASE for all VCPUs, the pages of the
initial SMRAM save state map can be re-encrypted (including zeroing them
out after setting the C-bit on them), and they can be released to DXE for
general use (undoing the allocation that we did in PlatformPei's
AmdSevInitialize() function).

The decryption of the same pages (which will occur chronologically
earlier) is implemented in the next patch; hence the "re-encryption" part
of this patch is currently a no-op. The series is structured like this in
order to be bisection-friendly. If the decryption patch preceded this
patch, then an info leak would be created while standing between the
patches.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf |  2 ++
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c   | 38 

 2 files changed, 40 insertions(+)

diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 5184abbf21bd..7c2aaa890b5e 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -19,21 +19,23 @@ [Defines]
   BASE_NAME  = SmmCpuFeaturesLib
   MODULE_UNI_FILE= SmmCpuFeaturesLib.uni
   FILE_GUID  = AC9991BE-D77A-464C-A8DE-A873DB8A4836
   MODULE_TYPE= DXE_SMM_DRIVER
   VERSION_STRING = 1.0
   LIBRARY_CLASS  = SmmCpuFeaturesLib
   CONSTRUCTOR= SmmCpuFeaturesLibConstructor
 
 [Sources]
   SmmCpuFeaturesLib.c
 
 [Packages]
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [LibraryClasses]
   BaseLib
   BaseMemoryLib
   DebugLib
+  MemEncryptSevLib
   SmmServicesTableLib
+  UefiBootServicesTableLib
diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
index 13d929a983be..59c319e01bfb 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
@@ -1,39 +1,41 @@
 /** @file
   The CPU specific programming for PiSmmCpuDxeSmm module.
 
   Copyright (c) 2010 - 2015, 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 
 #include 
 #include 
 
 //
 // EFER register LMA bit
 //
 #define LMA BIT10
 
 /**
   The constructor function
 
   @param[in]  ImageHandle  The firmware allocated handle for the EFI image.
   @param[in]  SystemTable  A pointer to the EFI System Table.
 
   @retval EFI_SUCCESS  The constructor always returns EFI_SUCCESS.
 
 **/
 EFI_STATUS
 EFIAPI
 SmmCpuFeaturesLibConstructor (
@@ -168,40 +170,76 @@ SmmCpuFeaturesHookReturnFromSmm (
 if ((CpuSaveState->x64.AutoHALTRestart & BIT0) != 0) {
   CpuSaveState->x64.AutoHALTRestart &= ~BIT0;
 }
   }
   return OriginalInstructionPointer;
 }
 
 /**
   Hook point in normal execution mode that allows the one CPU that was elected
   as monarch during System Management Mode initialization to perform additional
   initialization actions immediately after all of the CPUs have processed their
   first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE
   into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().
 **/
 VOID
 EFIAPI
 SmmCpuFeaturesSmmRelocationComplete (
   VOID
   )
 {
+  EFI_STATUS Status;
+  UINTN  MapPagesBase;
+  UINTN  MapPagesCount;
+
+  if (!MemEncryptSevIsEnabled ()) {
+return;
+  }
+
+  //
+  // Now that SMBASE relocation is complete, re-encrypt the original SMRAM save
+  // state map's container pages, and release the pages to DXE. (The pages were
+  // allocated in PlatformPei.)
+  //
+  Status = MemEncryptSevLocateInitialSmramSaveStateMapPages (
+ ,
+ 
+ );
+  ASSERT_EFI_ERROR (Status);
+
+  Status = MemEncryptSevSetPageEncMask (
+ 0, 

[edk2] [PATCH 20/20] OvmfPkg/AmdSevDxe: decrypt the pages of the initial SMRAM save state map

2018-03-01 Thread Laszlo Ersek
Based on the following patch from Brijesh Singh :

  [PATCH v2 1/2] OvmfPkg/AmdSevDxe: Clear the C-bit from SMM Saved State
  20180228161415.28723-2-brijesh.singh@amd.com">http://mid.mail-archive.com/20180228161415.28723-2-brijesh.singh@amd.com
  https://lists.01.org/pipermail/edk2-devel/2018-February/022016.html

Original commit message from Brijesh:

> When OVMF is built with SMM, SMMSaved State area (SMM_DEFAULT_SMBASE +
> SMRAM_SAVE_STATE_MAP_OFFSET) contains data which need to be accessed by
> both guest and hypervisor. Since the data need to be accessed by both
> hence we must map the SMMSaved State area as unencrypted (i.e C-bit
> cleared).
>
> This patch clears the SavedStateArea address before SMBASE relocation.
> Currently, we do not clear the SavedStateArea address after SMBASE is
> relocated due to the following reasons:
>
> 1) Guest BIOS never access the relocated SavedStateArea.
>
> 2) The C-bit works on page-aligned address, but the SavedStateArea
> address is not a page-aligned. Theoretically, we could roundup the
> address and clear the C-bit of aligned address but looking carefully we
> found that some portion of the page contains code -- which will causes a
> bigger issue for the SEV guest. When SEV is enabled, all the code must
> be encrypted otherwise hardware will cause trap.

Changes by Laszlo:

- separate AmdSevDxe bits from SmmCpuFeaturesLib bits;

- spell out PcdLib dependency with #include and in LibraryClasses;

- replace (SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET) calculation
  with call to new MemEncryptSevLocateInitialSmramSaveStateMapPages()
  function;

- consequently, pass page-aligned BaseAddress to
  MemEncryptSevClearPageEncMask();

- zero the pages before clearing the C-bit;

- pass Flush=TRUE to MemEncryptSevClearPageEncMask();

- harden the treatment of MemEncryptSevClearPageEncMask() failure.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/AmdSevDxe/AmdSevDxe.inf |  6 +++
 OvmfPkg/AmdSevDxe/AmdSevDxe.c   | 53 
 2 files changed, 59 insertions(+)

diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
index 3aff7e292053..b7e7da002d5e 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
@@ -15,28 +15,34 @@
 #
 #**/
 
 [Defines]
   INF_VERSION= 1.25
   BASE_NAME  = AmdSevDxe
   FILE_GUID  = 2ec9da37-ee35-4de9-86c5-6d9a81dc38a7
   MODULE_TYPE= DXE_DRIVER
   VERSION_STRING = 1.0
   ENTRY_POINT= AmdSevDxeEntryPoint
 
 [Sources]
   AmdSevDxe.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
+  BaseLib
+  BaseMemoryLib
   DebugLib
   DxeServicesTableLib
   MemEncryptSevLib
   MemoryAllocationLib
+  PcdLib
   UefiDriverEntryPoint
 
 [Depex]
   TRUE
+
+[FeaturePcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
index 8f02d0627e02..c697580ad5b8 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
@@ -1,42 +1,45 @@
 /** @file
 
   AMD Sev Dxe driver. This driver is dispatched early in DXE, due to being list
   in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when SEV
   is enabled.
 
   Copyright (c) 2017, AMD Inc. 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 
 
 EFI_STATUS
 EFIAPI
 AmdSevDxeEntryPoint (
   IN EFI_HANDLE ImageHandle,
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
   EFI_STATUS   Status;
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *AllDescMap;
   UINTNNumEntries;
   UINTNIndex;
 
   //
   // Do nothing when SEV is not enabled
   //
   if (!MemEncryptSevIsEnabled ()) {
 return EFI_UNSUPPORTED;
   }
 
@@ -51,22 +54,72 @@ AmdSevDxeEntryPoint (
   if (!EFI_ERROR (Status)) {
 for (Index = 0; Index < NumEntries; Index++) {
   CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc;
 
   Desc = [Index];
   if (Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo ||
   Desc->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
 Status = MemEncryptSevClearPageEncMask (
0,

[edk2] [PATCH 17/20] OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map

2018-03-01 Thread Laszlo Ersek
In the next three patches, we're going to modify three modules under
OvmfPkg. When OVMF is built with -D SMM_REQUIRE and runs in an SEV guest,
each affected module will have to know the page range that covers the
initial (pre-SMBASE relocation) SMRAM save state map. Add a helper
function to MemEncryptSevLib that calculates the "base address" and
"number of pages" constants for this page range.

(In a RELEASE build -- i.e., with assertions disabled and optimization
enabled --, the helper function can be compiled to store two constants
determined at compile time.)

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf   |  4 ++
 OvmfPkg/Include/Library/MemEncryptSevLib.h  | 23 +
 OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c | 51 

 3 files changed, 78 insertions(+)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf 
b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
index 2f0a2392a7ad..464fe1f33e66 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
@@ -34,20 +34,24 @@ [Packages]
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [Sources.X64]
   MemEncryptSevLibInternal.c
   X64/MemEncryptSevLib.c
   X64/VirtualMemory.c
 
 [Sources.IA32]
   Ia32/MemEncryptSevLib.c
   MemEncryptSevLibInternal.c
 
 [LibraryClasses]
   BaseLib
   CacheMaintenanceLib
   CpuLib
   DebugLib
   MemoryAllocationLib
+  PcdLib
+
+[FeaturePcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h 
b/OvmfPkg/Include/Library/MemEncryptSevLib.h
index e5ebb4401818..1e2ec8641d46 100644
--- a/OvmfPkg/Include/Library/MemEncryptSevLib.h
+++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h
@@ -69,21 +69,44 @@ MemEncryptSevClearPageEncMask (
   address of a memory region.
   @param[in]  NumPagesThe number of pages from start memory
   region.
   @param[in]  Flush   Flush the caches before setting the bit
   (mostly TRUE except MMIO addresses)
 
   @retval RETURN_SUCCESS  The attributes were set for the memory
   region.
   @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
   @retval RETURN_UNSUPPORTED  Setting the memory encryption attribute
   is not supported
 **/
 RETURN_STATUS
 EFIAPI
 MemEncryptSevSetPageEncMask (
   IN PHYSICAL_ADDRESS Cr3BaseAddress,
   IN PHYSICAL_ADDRESS BaseAddress,
   IN UINTNNumPages,
   IN BOOLEAN  Flush
   );
+
+
+/**
+  Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
+  Save State Map.
+
+  @param[out] BaseAddress The base address of the lowest-address page that
+  covers the initial SMRAM Save State Map.
+
+  @param[out] NumberOfPages   The number of pages in the page range that covers
+  the initial SMRAM Save State Map.
+
+  @retval RETURN_SUCCESS  BaseAddress and NumberOfPages have been set on
+  output.
+
+  @retval RETURN_UNSUPPORTED  SMM is unavailable.
+**/
+RETURN_STATUS
+EFIAPI
+MemEncryptSevLocateInitialSmramSaveStateMapPages (
+  OUT UINTN *BaseAddress,
+  OUT UINTN *NumberOfPages
+  );
 #endif // _MEM_ENCRYPT_SEV_LIB_H_
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
index 7078ab0d3f46..b92ba50c616c 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
@@ -1,42 +1,46 @@
 /** @file
 
   Secure Encrypted Virtualization (SEV) library helper function
 
   Copyright (c) 2017, AMD Incorporated. 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 
+#include 
+#include 
+#include 
 
 STATIC BOOLEAN mSevStatus = FALSE;
 STATIC BOOLEAN mSevStatusChecked = FALSE;
 
 /**
 
   Returns a boolean to indicate 

[edk2] [PATCH 16/20] OvmfPkg/AmdSevDxe: refresh #includes and LibraryClasses

2018-03-01 Thread Laszlo Ersek
List those and only those libraries that are used.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 4 +---
 OvmfPkg/AmdSevDxe/AmdSevDxe.c   | 4 
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
index d4a0a2635d2e..3aff7e292053 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
@@ -15,30 +15,28 @@
 #
 #**/
 
 [Defines]
   INF_VERSION= 1.25
   BASE_NAME  = AmdSevDxe
   FILE_GUID  = 2ec9da37-ee35-4de9-86c5-6d9a81dc38a7
   MODULE_TYPE= DXE_DRIVER
   VERSION_STRING = 1.0
   ENTRY_POINT= AmdSevDxeEntryPoint
 
 [Sources]
   AmdSevDxe.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
-  BaseLib
   DebugLib
   DxeServicesTableLib
   MemEncryptSevLib
-  UefiBootServicesTableLib
+  MemoryAllocationLib
   UefiDriverEntryPoint
-  UefiLib
 
 [Depex]
   TRUE
diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
index 9ac13acb8b22..8f02d0627e02 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
@@ -1,46 +1,42 @@
 /** @file
 
   AMD Sev Dxe driver. This driver is dispatched early in DXE, due to being list
   in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when SEV
   is enabled.
 
   Copyright (c) 2017, AMD Inc. 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 
-#include 
 
 EFI_STATUS
 EFIAPI
 AmdSevDxeEntryPoint (
   IN EFI_HANDLE ImageHandle,
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
   EFI_STATUS   Status;
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *AllDescMap;
   UINTNNumEntries;
   UINTNIndex;
 
   //
   // Do nothing when SEV is not enabled
   //
   if (!MemEncryptSevIsEnabled ()) {
 return EFI_UNSUPPORTED;
   }
 
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 18/20] OvmfPkg/PlatformPei: SEV: allocate pages of initial SMRAM save state map

2018-03-01 Thread Laszlo Ersek
In the next two patches, we'll temporarily decrypt the pages containing
the initial SMRAM save state map, for SMBASE relocation. (Unlike the
separate, relocated SMRAM save state map of each VCPU, the original,
shared map behaves similarly to a "common buffer" between guest and host.)
The decryption will occur near the beginning of the DXE phase, in
AmdSevDxe, and the re-encryption will occur in PiSmmCpuDxeSmm, via OVMF's
SmmCpuFeaturesLib instance.

There is a non-trivial time gap between these two points, and the DXE
phase might use the pages overlapping the initial SMRAM save state map for
arbitrary purposes meanwhile. In order to prevent any information leak
towards the hypervisor, make sure the DXE phase puts nothing in those
pages until re-encryption is done.

Creating a memalloc HOB for the area in question is safe:

- the temporary SEC/PEI RAM (stack and heap) is based at
  PcdOvmfSecPeiTempRamBase, which is above 8MB,

- the permanent PEI RAM (installed in PlatformPei's PublishPeiMemory()
  function) never starts below PcdOvmfDxeMemFvBase, which is also above
  8MB.

The allocated pages can be released to the DXE phase after SMBASE
relocation and re-encryption are complete.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/PlatformPei/AmdSev.c | 29 
 1 file changed, 29 insertions(+)

diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index 1509f260fb0b..2e14eaf8c3cc 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -1,38 +1,39 @@
 /**@file
   Initialize Secure Encrypted Virtualization (SEV) support
 
   Copyright (c) 2017, Advanced Micro Devices. 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.
 
 **/
 //
 // The package level header files this module uses
 //
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "Platform.h"
 
 /**
 
   Function checks if SEV support is available, if present then it sets
   the dynamic PcdPteMemoryEncryptionAddressOrMask with memory encryption mask.
 
   **/
 VOID
 AmdSevInitialize (
   VOID
   )
 {
   CPUID_MEMORY_ENCRYPTION_INFO_EBX  Ebx;
@@ -49,21 +50,49 @@ AmdSevInitialize (
   //
   // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position)
   //
   AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, , NULL, NULL);
   EncryptionMask = LShiftU64 (1, Ebx.Bits.PtePosBits);
 
   //
   // Set Memory Encryption Mask PCD
   //
   PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask);
   ASSERT_RETURN_ERROR (PcdStatus);
 
   DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask));
 
   //
   // Set Pcd to Deny the execution of option ROM when security
   // violation.
   //
   PcdStatus = PcdSet32S (PcdOptionRomImageVerificationPolicy, 0x4);
   ASSERT_RETURN_ERROR (PcdStatus);
+
+  //
+  // When SMM is required, cover the pages containing the initial SMRAM Save
+  // State Map with a memory allocation HOB:
+  //
+  // There's going to be a time interval between our decrypting those pages for
+  // SMBASE relocation and re-encrypting the same pages after SMBASE
+  // relocation. We shall ensure that the DXE phase stay away from those pages
+  // until after re-encryption, in order to prevent an information leak to the
+  // hypervisor.
+  //
+  if (FeaturePcdGet (PcdSmmSmramRequire) && (mBootMode != BOOT_ON_S3_RESUME)) {
+RETURN_STATUS LocateMapStatus;
+UINTN MapPagesBase;
+UINTN MapPagesCount;
+
+LocateMapStatus = MemEncryptSevLocateInitialSmramSaveStateMapPages (
+,
+
+);
+ASSERT_RETURN_ERROR (LocateMapStatus);
+
+BuildMemoryAllocationHob (
+  MapPagesBase,  // BaseAddress
+  EFI_PAGES_TO_SIZE (MapPagesCount), // Length
+  EfiBootServicesData// MemoryType
+  );
+  }
 }
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 05/20] OvmfPkg/MemEncryptSevLib: clean up SetMemoryEncDec() comment block

2018-03-01 Thread Laszlo Ersek
Document the "Cr3BaseAddress" parameter, and correct several parameter
references.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
index 65b8babaac44..aed92127629f 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
@@ -531,55 +531,57 @@ DisableReadOnlyPageWriteProtect (
   VOID
   )
 {
   AsmWriteCr0 (AsmReadCr0() & ~BIT16);
 }
 
 /**
  Enable Write Protect on pages marked as read-only.
 **/
 VOID
 EnableReadOnlyPageWriteProtect (
   VOID
   )
 {
   AsmWriteCr0 (AsmReadCr0() | BIT16);
 }
 
 
 /**
   This function either sets or clears memory encryption bit for the memory
-  region specified by PhysicalAddress and length from the current page table
+  region specified by PhysicalAddress and Length from the current page table
   context.
 
-  The function iterates through the physicalAddress one page at a time, and set
+  The function iterates through the PhysicalAddress one page at a time, and set
   or clears the memory encryption mask in the page table. If it encounters
   that a given physical address range is part of large page then it attempts to
   change the attribute at one go (based on size), otherwise it splits the
   large pages into smaller (e.g 2M page into 4K pages) and then try to set or
   clear the encryption bit on the smallest page size.
 
+  @param[in]  Cr3BaseAddress  Cr3 Base Address (if zero then use
+  current CR3)
   @param[in]  PhysicalAddress The physical address that is the start
   address of a memory region.
   @param[in]  Length  The length of memory region
   @param[in]  ModeSet or Clear mode
-  @param[in]  Flush   Flush the caches before applying the
+  @param[in]  CacheFlush  Flush the caches before applying the
   encryption mask
 
   @retval RETURN_SUCCESS  The attributes were cleared for the
   memory region.
   @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
   @retval RETURN_UNSUPPORTED  Setting the memory encyrption attribute
   is not supported
 **/
 
 STATIC
 RETURN_STATUS
 EFIAPI
 SetMemoryEncDec (
   INPHYSICAL_ADDRESS Cr3BaseAddress,
   INPHYSICAL_ADDRESS PhysicalAddress,
   INUINTNLength,
   INMAP_RANGE_MODE   Mode,
   INBOOLEAN  CacheFlush
   )
 {
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 09/20] OvmfPkg/PlatformPei: sort #includes in "AmdSev.c"

2018-03-01 Thread Laszlo Ersek
No functional changes.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/PlatformPei/AmdSev.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index ad31b69fb032..1509f260fb0b 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -1,44 +1,43 @@
 /**@file
   Initialize Secure Encrypted Virtualization (SEV) support
 
   Copyright (c) 2017, Advanced Micro Devices. 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.
 
 **/
 //
 // The package level header files this module uses
 //
-#include 
-
 #include 
+#include 
 #include 
-#include 
+#include 
 #include 
-#include 
+#include 
 
 #include "Platform.h"
 
 /**
 
   Function checks if SEV support is available, if present then it sets
   the dynamic PcdPteMemoryEncryptionAddressOrMask with memory encryption mask.
 
   **/
 VOID
 AmdSevInitialize (
   VOID
   )
 {
   CPUID_MEMORY_ENCRYPTION_INFO_EBX  Ebx;
   UINT64EncryptionMask;
   RETURN_STATUS PcdStatus;
 
   //
   // Check if SEV is enabled
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 06/20] OvmfPkg/MemEncryptSevLib: clean up InternalMemEncryptSevSetMemoryDecrypted() decl

2018-03-01 Thread Laszlo Ersek
The declaration and the definition(s) of the function should have
identical leading comments and/or identical parameter lists. Document the
"Cr3BaseAddress" parameter, and correct several parameter references.
Replace a "set" reference to the C-bit with a "clear" reference.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h | 14 --
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c |  6 --
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
index 7dd1bbe0eb26..646a9781d04a 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
@@ -171,61 +171,63 @@ typedef union {
 #define PTE_OFFSET(x)   ( (x >> 12) & PAGETABLE_ENTRY_MASK)
 #define PAGING_1G_ADDRESS_MASK_64   0x000FC000ull
 
 #define PAGE_TABLE_POOL_ALIGNMENT   BASE_2MB
 #define PAGE_TABLE_POOL_UNIT_SIZE   SIZE_2MB
 #define PAGE_TABLE_POOL_UNIT_PAGES  \
   EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)
 #define PAGE_TABLE_POOL_ALIGN_MASK  \
   (~(EFI_PHYSICAL_ADDRESS)(PAGE_TABLE_POOL_ALIGNMENT - 1))
 
 typedef struct {
   VOID*NextPool;
   UINTN   Offset;
   UINTN   FreePages;
 } PAGE_TABLE_POOL;
 
 
 
 /**
   This function clears memory encryption bit for the memory region specified by
-  PhysicalAddress and length from the current page table context.
+  PhysicalAddress and Length from the current page table context.
 
+  @param[in]  Cr3BaseAddress  Cr3 Base Address (if zero then use
+  current CR3)
   @param[in]  PhysicalAddress The physical address that is the start
   address of a memory region.
   @param[in]  Length  The length of memory region
   @param[in]  Flush   Flush the caches before applying the
   encryption mask
 
   @retval RETURN_SUCCESS  The attributes were cleared for the
   memory region.
   @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
-  @retval RETURN_UNSUPPORTED  Setting the memory encyrption attribute
+  @retval RETURN_UNSUPPORTED  Clearing the memory encyrption attribute
   is not supported
 **/
 RETURN_STATUS
 EFIAPI
 InternalMemEncryptSevSetMemoryDecrypted (
-  IN  PHYSICAL_ADDRESS Cr3BaseAddress,
-  IN  PHYSICAL_ADDRESS PhysicalAddress,
-  IN  UINT64   Length,
-  IN  BOOLEAN  CacheFlush
+  IN  PHYSICAL_ADDRESSCr3BaseAddress,
+  IN  PHYSICAL_ADDRESSPhysicalAddress,
+  IN  UINTN   Length,
+  IN  BOOLEAN Flush
   );
 
 /**
   This function sets memory encryption bit for the memory region specified by
   PhysicalAddress and length from the current page table context.
 
   @param[in]  PhysicalAddress The physical address that is the start
   address of a memory region.
   @param[in]  Length  The length of memory region
   @param[in]  Flush   Flush the caches before applying the
   encryption mask
 
   @retval RETURN_SUCCESS  The attributes were cleared for the
   memory region.
   @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
   @retval RETURN_UNSUPPORTED  Setting the memory encyrption attribute
   is not supported
 **/
 RETURN_STATUS
 EFIAPI
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
index aed92127629f..3f7704801c9c 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
@@ -809,52 +809,54 @@ SetMemoryEncDec (
   }
 
   //
   // Flush TLB
   //
   CpuFlushTlb();
 
 Done:
   //
   // Restore page table write protection, if any.
   //
   if (IsWpEnabled) {
 EnableReadOnlyPageWriteProtect ();
   }
 
   return Status;
 }
 
 /**
   This function clears memory encryption bit for the memory region specified by
-  PhysicalAddress and length from the current page table context.
+  PhysicalAddress and Length from the current page table context.
 
+  @param[in]  Cr3BaseAddress  Cr3 Base Address (if zero then use
+  current CR3)
   @param[in]  PhysicalAddress The physical address that is the start
   address of a 

[edk2] [PATCH 07/20] OvmfPkg/MemEncryptSevLib: clean up InternalMemEncryptSevSetMemoryEncrypted() decl

2018-03-01 Thread Laszlo Ersek
The declaration and the definition(s) of the function should have
identical leading comments and/or identical parameter lists. Document the
"Cr3BaseAddress" parameter, and correct several parameter references.
Replace a "clear" reference to the C-bit with a "set" reference.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h | 16 +---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c |  8 +---
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
index 646a9781d04a..67ff69122d73 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
@@ -198,44 +198,46 @@ typedef struct {
   @param[in]  Flush   Flush the caches before applying the
   encryption mask
 
   @retval RETURN_SUCCESS  The attributes were cleared for the
   memory region.
   @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
   @retval RETURN_UNSUPPORTED  Clearing the memory encyrption attribute
   is not supported
 **/
 RETURN_STATUS
 EFIAPI
 InternalMemEncryptSevSetMemoryDecrypted (
   IN  PHYSICAL_ADDRESSCr3BaseAddress,
   IN  PHYSICAL_ADDRESSPhysicalAddress,
   IN  UINTN   Length,
   IN  BOOLEAN Flush
   );
 
 /**
   This function sets memory encryption bit for the memory region specified by
-  PhysicalAddress and length from the current page table context.
+  PhysicalAddress and Length from the current page table context.
 
+  @param[in]  Cr3BaseAddress  Cr3 Base Address (if zero then use
+  current CR3)
   @param[in]  PhysicalAddress The physical address that is the start
   address of a memory region.
   @param[in]  Length  The length of memory region
   @param[in]  Flush   Flush the caches before applying the
   encryption mask
 
-  @retval RETURN_SUCCESS  The attributes were cleared for the
-  memory region.
+  @retval RETURN_SUCCESS  The attributes were set for the memory
+  region.
   @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
   @retval RETURN_UNSUPPORTED  Setting the memory encyrption attribute
   is not supported
 **/
 RETURN_STATUS
 EFIAPI
 InternalMemEncryptSevSetMemoryEncrypted (
-  IN  PHYSICAL_ADDRESS Cr3BaseAddress,
-  IN  PHYSICAL_ADDRESS PhysicalAddress,
-  IN  UINT64   Length,
-  IN  BOOLEAN  CacheFlush
+  IN  PHYSICAL_ADDRESSCr3BaseAddress,
+  IN  PHYSICAL_ADDRESSPhysicalAddress,
+  IN  UINTN   Length,
+  IN  BOOLEAN Flush
   );
 
 #endif
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
index 3f7704801c9c..39b246048f1f 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
@@ -846,50 +846,52 @@ RETURN_STATUS
 EFIAPI
 InternalMemEncryptSevSetMemoryDecrypted (
   IN  PHYSICAL_ADDRESSCr3BaseAddress,
   IN  PHYSICAL_ADDRESSPhysicalAddress,
   IN  UINTN   Length,
   IN  BOOLEAN Flush
   )
 {
 
   return SetMemoryEncDec (
Cr3BaseAddress,
PhysicalAddress,
Length,
ClearCBit,
Flush
);
 }
 
 /**
   This function sets memory encryption bit for the memory region specified by
-  PhysicalAddress and length from the current page table context.
+  PhysicalAddress and Length from the current page table context.
 
+  @param[in]  Cr3BaseAddress  Cr3 Base Address (if zero then use
+  current CR3)
   @param[in]  PhysicalAddress The physical address that is the start
   address of a memory region.
   @param[in]  Length  The length of memory region
   @param[in]  Flush   Flush the caches before applying the
   encryption mask
 
-  @retval RETURN_SUCCESS  The attributes were cleared for the
-  memory region.
+  @retval RETURN_SUCCESS  The attributes were set for the memory
+ 

[edk2] [PATCH 02/20] OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevIsEnabled() decl

2018-03-01 Thread Laszlo Ersek
The declaration and the definition(s) of the function should have
identical leading comments and/or identical parameter lists. Also remove
any excess space in the comment block, and unindent the trailing "**/" if
necessary.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Include/Library/MemEncryptSevLib.h  | 4 ++--
 OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h 
b/OvmfPkg/Include/Library/MemEncryptSevLib.h
index 4f3ba9f22cb4..88b272ebedef 100644
--- a/OvmfPkg/Include/Library/MemEncryptSevLib.h
+++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h
@@ -5,43 +5,43 @@
   Copyright (c) 2017, AMD Incorporated. 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.
 
 **/
 
 #ifndef _MEM_ENCRYPT_SEV_LIB_H_
 #define _MEM_ENCRYPT_SEV_LIB_H_
 
 #include 
 
 /**
   Returns a boolean to indicate whether SEV is enabled
 
-  @retval TRUE   SEV is active
+  @retval TRUE   SEV is enabled
   @retval FALSE  SEV is not enabled
-  **/
+**/
 BOOLEAN
 EFIAPI
 MemEncryptSevIsEnabled (
   VOID
   );
 
 /**
   This function clears memory encryption bit for the memory region specified
   by BaseAddress and Number of pages from the current page table context.
 
   @param[in]  BaseAddress   The physical address that is the start
 address of a memory region.
   @param[in]  NumberOfPages The number of pages from start memory
 region.
   @param[in]  Flush Flush the caches before clearing the bit
 (mostly TRUE except MMIO addresses)
 
   @retval RETURN_SUCCESSThe attributes were cleared for the memory
 region.
   @retval RETURN_INVALID_PARAMETER  Number of pages is zero.
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
index ff561236d819..44c2c98a6afc 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
@@ -50,41 +50,40 @@ InternalMemEncryptSevIsEnabled (
 //
 // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported)
 //
 AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, , NULL, NULL, NULL);
 
 if (Eax.Bits.SevBit) {
   //
   // Check MSR_0xC0010131 Bit 0 (Sev Enabled)
   //
   Msr.Uint32 = AsmReadMsr32 (MSR_SEV_STATUS);
   if (Msr.Bits.SevBit) {
 return TRUE;
   }
 }
   }
 
   return FALSE;
 }
 
 /**
-
   Returns a boolean to indicate whether SEV is enabled
 
   @retval TRUE   SEV is enabled
   @retval FALSE  SEV is not enabled
-  **/
+**/
 BOOLEAN
 EFIAPI
 MemEncryptSevIsEnabled (
   VOID
   )
 {
   if (mSevStatusChecked) {
 return mSevStatus;
   }
 
   mSevStatus = InternalMemEncryptSevIsEnabled();
   mSevStatusChecked = TRUE;
 
   return mSevStatus;
 }
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 04/20] OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevSetPageEncMask() decl

2018-03-01 Thread Laszlo Ersek
The declaration and the definition(s) of the function should have
identical leading comments and/or identical parameter lists. Replace any
leftover "clear" references to the C-bit with "set" references. Also
remove any excess space in the comment block, and unindent the trailing
"**/" if necessary. Correct several parameter references.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Include/Library/MemEncryptSevLib.h   | 32 
+++-
 OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c | 32 
++--
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c  | 17 +--
 3 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h 
b/OvmfPkg/Include/Library/MemEncryptSevLib.h
index 2d574dd30676..e5ebb4401818 100644
--- a/OvmfPkg/Include/Library/MemEncryptSevLib.h
+++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h
@@ -44,44 +44,46 @@ MemEncryptSevIsEnabled (
   @param[in]  Flush   Flush the caches before clearing the bit
   (mostly TRUE except MMIO addresses)
 
   @retval RETURN_SUCCESS  The attributes were cleared for the
   memory region.
   @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
   @retval RETURN_UNSUPPORTED  Clearing the memory encryption attribute
   is not supported
 **/
 RETURN_STATUS
 EFIAPI
 MemEncryptSevClearPageEncMask (
   IN PHYSICAL_ADDRESS Cr3BaseAddress,
   IN PHYSICAL_ADDRESS BaseAddress,
   IN UINTNNumPages,
   IN BOOLEAN  Flush
   );
 
 /**
   This function sets memory encryption bit for the memory region specified by
-  BaseAddress and Number of pages from the current page table context.
+  BaseAddress and NumPages from the current page table context.
 
-  @param[in]  BaseAddress   The physical address that is the start
-address of a memory region.
-  @param[in]  NumberOfPages The number of pages from start memory
-region.
-  @param[in]  Flush Flush the caches before clearing the bit
-(mostly TRUE except MMIO addresses)
+  @param[in]  Cr3BaseAddress  Cr3 Base Address (if zero then use
+  current CR3)
+  @param[in]  BaseAddress The physical address that is the start
+  address of a memory region.
+  @param[in]  NumPagesThe number of pages from start memory
+  region.
+  @param[in]  Flush   Flush the caches before setting the bit
+  (mostly TRUE except MMIO addresses)
 
-  @retval RETURN_SUCCESSThe attributes were set for the memory
-region.
-  @retval RETURN_INVALID_PARAMETER  Number of pages is zero.
-  @retval RETURN_UNSUPPORTEDClearing memory encryption attribute is not
-supported
-  **/
+  @retval RETURN_SUCCESS  The attributes were set for the memory
+  region.
+  @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
+  @retval RETURN_UNSUPPORTED  Setting the memory encryption attribute
+  is not supported
+**/
 RETURN_STATUS
 EFIAPI
 MemEncryptSevSetPageEncMask (
   IN PHYSICAL_ADDRESS Cr3BaseAddress,
   IN PHYSICAL_ADDRESS BaseAddress,
-  IN UINTNNumberOfPages,
-  IN BOOLEAN  CacheFlush
+  IN UINTNNumPages,
+  IN BOOLEAN  Flush
   );
 #endif // _MEM_ENCRYPT_SEV_LIB_H_
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
index d6067c52aacd..614c97b23bb6 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
@@ -40,51 +40,51 @@
   @retval RETURN_UNSUPPORTED  Clearing the memory encryption attribute
   is not supported
 **/
 RETURN_STATUS
 EFIAPI
 MemEncryptSevClearPageEncMask (
   IN PHYSICAL_ADDRESS Cr3BaseAddress,
   IN PHYSICAL_ADDRESS BaseAddress,
   IN UINTNNumPages,
   IN BOOLEAN  Flush
   )
 {
   //
   // Memory encryption bit is not accessible in 32-bit mode
   //
   return RETURN_UNSUPPORTED;
 }
 
 /**
   This function sets memory encryption bit for the memory region specified by
-  BaseAddress 

[edk2] [PATCH 15/20] OvmfPkg/AmdSevDxe: sort #includes, and entries in INF file sections

2018-03-01 Thread Laszlo Ersek
Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 10 +-
 OvmfPkg/AmdSevDxe/AmdSevDxe.c   |  9 -
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
index 2ed778979373..d4a0a2635d2e 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
@@ -10,35 +10,35 @@
 #  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.
 #
 #**/
 
 [Defines]
   INF_VERSION= 1.25
   BASE_NAME  = AmdSevDxe
   FILE_GUID  = 2ec9da37-ee35-4de9-86c5-6d9a81dc38a7
   MODULE_TYPE= DXE_DRIVER
   VERSION_STRING = 1.0
   ENTRY_POINT= AmdSevDxeEntryPoint
 
 [Sources]
   AmdSevDxe.c
 
 [Packages]
-  MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
   BaseLib
-  UefiLib
-  UefiDriverEntryPoint
-  UefiBootServicesTableLib
-  DxeServicesTableLib
   DebugLib
+  DxeServicesTableLib
   MemEncryptSevLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+  UefiLib
 
 [Depex]
   TRUE
diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
index 065d7381b35b..9ac13acb8b22 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
@@ -1,47 +1,46 @@
 /** @file
 
   AMD Sev Dxe driver. This driver is dispatched early in DXE, due to being list
   in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when SEV
   is enabled.
 
   Copyright (c) 2017, AMD Inc. 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 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 EFI_STATUS
 EFIAPI
 AmdSevDxeEntryPoint (
   IN EFI_HANDLE ImageHandle,
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
   EFI_STATUS   Status;
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *AllDescMap;
   UINTNNumEntries;
   UINTNIndex;
 
   //
   // Do nothing when SEV is not enabled
   //
   if (!MemEncryptSevIsEnabled ()) {
 return EFI_UNSUPPORTED;
   }
 
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 08/20] OvmfPkg/MemEncryptSevLib: sort #includes, and entries in INF file sections

2018-03-01 Thread Laszlo Ersek
Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf   | 6 +++---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h| 4 ++--
 OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c| 4 ++--
 OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c | 4 ++--
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c | 4 ++--
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c| 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf 
b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
index 81b075194ace..2f0a2392a7ad 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
@@ -14,40 +14,40 @@
 #
 #
 ##
 
 [Defines]
   INF_VERSION= 1.25
   BASE_NAME  = MemEncryptSevLib
   FILE_GUID  = c1594631-3888-4be4-949f-9c630dbc842b
   MODULE_TYPE= BASE
   VERSION_STRING = 1.0
   LIBRARY_CLASS  = MemEncryptSevLib|PEIM DXE_DRIVER 
DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER
 
 #
 # The following information is for reference only and not required by the build
 # tools.
 #
 # VALID_ARCHITECTURES   = IA32 X64
 #
 
 [Packages]
-  MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [Sources.X64]
   MemEncryptSevLibInternal.c
   X64/MemEncryptSevLib.c
   X64/VirtualMemory.c
 
 [Sources.IA32]
-  MemEncryptSevLibInternal.c
   Ia32/MemEncryptSevLib.c
+  MemEncryptSevLibInternal.c
 
 [LibraryClasses]
   BaseLib
-  CpuLib
   CacheMaintenanceLib
+  CpuLib
   DebugLib
   MemoryAllocationLib
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
index 67ff69122d73..95a08f3558e9 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
@@ -3,47 +3,47 @@
   Virtual Memory Management Services to set or clear the memory encryption bit
 
   Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
   Copyright (c) 2017, AMD Incorporated. 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.
 
   Code is derived from MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h
 
 **/
 
 #ifndef __VIRTUAL_MEMORY__
 #define __VIRTUAL_MEMORY__
 
-#include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
-#include 
 #define SYS_CODE64_SEL 0x38
 
 #pragma pack(1)
 
 //
 // Page-Map Level-4 Offset (PML4) and
 // Page-Directory-Pointer Offset (PDPE) entries 4K & 2MB
 //
 
 typedef union {
   struct {
 UINT64  Present:1;// 0 = Not present in memory,
   //   1 = Present in memory
 UINT64  ReadWrite:1;  // 0 = Read-Only, 1= Read/Write
 UINT64  UserSupervisor:1; // 0 = Supervisor, 1=User
 UINT64  WriteThrough:1;   // 0 = Write-Back caching,
   //   1 = Write-Through caching
 UINT64  CacheDisabled:1;  // 0 = Cached, 1=Non-Cached
 UINT64  Accessed:1;   // 0 = Not accessed,
   //   1 = Accessed (set by CPU)
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
index 614c97b23bb6..5d909c17b0bc 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
@@ -1,42 +1,42 @@
 /** @file
 
   Secure Encrypted Virtualization (SEV) library helper function
 
   Copyright (c) 2017, AMD Incorporated. 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 
 

[edk2] [PATCH 00/20] OvmfPkg: SEV: decrypt the initial SMRAM save state map for SMBASE relocation

2018-03-01 Thread Laszlo Ersek
Repo:   https://github.com/lersek/edk2.git
Branch: sev_smram_save_state_map

This patch series replaces the following patch from Brijesh:

  [PATCH v2 1/2] OvmfPkg/AmdSevDxe: Clear the C-bit from SMM Saved State
  20180228161415.28723-2-brijesh.singh@amd.com">http://mid.mail-archive.com/20180228161415.28723-2-brijesh.singh@amd.com
  https://lists.01.org/pipermail/edk2-devel/2018-February/022016.html

The series modifies four modules under OvmfPkg:
- MemEncryptSevLib
- PlatformPei
- SmmCpuFeaturesLib
- AmdSevDxe

Patches 01 through 16 are cleanups for these modules, without change in
functionality. The series is formatted with 20 lines of context, for
simplifying the review of these patches.

Patches 17 through 20 (one patch per module listed above) implement
$SUBJECT:

- MemEncryptSevLib gets a new helper function used by the other three
  modules.

- PlatformPei makes sure that DXE stays out of the page(s) where the
  initial SMRAM save state map lives.

- SmmCpuFeaturesLib and AmdSevDxe basically do what they did in
  Brijesh's patch, just better separated, and with minor tweaks.

The series is bisectable.

I regression-tested my usual non-SEV guests (with Brijesh's v2 2/2 patch
applied on top, from the above-referenced series), which covers i440fx
(no SMM, X64), q35 (SMM, IA32 and IA32X64), Fedora and Windows, normal
boot and S3.

I also tried to test the series with SEV guests (again with Brijesh's v2
2/2 patch applied on top). Unfortunately, I didn't get good results with
or without SMM. Without SMM, the guest OS boots to a point, but then it
gets stuck with the CPU spinning. With SMM, OVMF gets stuck in SMBASE
relocation.

I should mention however that my SEV host setup dates back to November
2017, including host kernel, QEMU and guest OS. I suppose all those
components have seen many changes since, on the respective upstream
lists. I'll have to work with Brijesh to update my SEV host to the
latest bits.

Until then, Brijesh, can you please test this series? Thank you!

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 

Cheers
Laszlo

Laszlo Ersek (20):
  OvmfPkg/MemEncryptSevLib: rewrap to 79 characters width
  OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevIsEnabled() decl
  OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevClearPageEncMask()
decl
  OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevSetPageEncMask() decl
  OvmfPkg/MemEncryptSevLib: clean up SetMemoryEncDec() comment block
  OvmfPkg/MemEncryptSevLib: clean up
InternalMemEncryptSevSetMemoryDecrypted() decl
  OvmfPkg/MemEncryptSevLib: clean up
InternalMemEncryptSevSetMemoryEncrypted() decl
  OvmfPkg/MemEncryptSevLib: sort #includes, and entries in INF file
sections
  OvmfPkg/PlatformPei: sort #includes in "AmdSev.c"
  OvmfPkg/SmmCpuFeaturesLib: rewrap to 79 columns
  OvmfPkg/SmmCpuFeaturesLib: upper-case the "static" keyword
  OvmfPkg/SmmCpuFeaturesLib: sort #includes, and entries in INF file
sections
  OvmfPkg/SmmCpuFeaturesLib: remove unneeded #includes and
LibraryClasses
  OvmfPkg/AmdSevDxe: rewrap to 79 characters width
  OvmfPkg/AmdSevDxe: sort #includes, and entries in INF file sections
  OvmfPkg/AmdSevDxe: refresh #includes and LibraryClasses
  OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map
  OvmfPkg/PlatformPei: SEV: allocate pages of initial SMRAM save state
map
  OvmfPkg/SmmCpuFeaturesLib: SEV: encrypt+free pages of init. save state
map
  OvmfPkg/AmdSevDxe: decrypt the pages of the initial SMRAM save state
map

 OvmfPkg/AmdSevDxe/AmdSevDxe.c   |  88 ++-
 OvmfPkg/AmdSevDxe/AmdSevDxe.inf |  25 +-
 OvmfPkg/Include/Library/MemEncryptSevLib.h  |  89 ++-
 OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf   |  17 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c|  72 ++-
 OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c |  66 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c |  74 ++-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c| 172 --
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h| 137 +++--
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c   | 650 

 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf |  13 +-
 OvmfPkg/PlatformPei/AmdSev.c|  36 +-
 12 files changed, 1067 insertions(+), 372 deletions(-)

-- 
2.14.1.3.gb7cf6e02401b

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 14/20] OvmfPkg/AmdSevDxe: rewrap to 79 characters width

2018-03-01 Thread Laszlo Ersek
There are many overlong lines; it's hard to work with the module like
this. Rewrap all files to 79 columns.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 11 +++
 OvmfPkg/AmdSevDxe/AmdSevDxe.c   | 30 +++-
 2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
index 41635a57a454..2ed778979373 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf
@@ -1,33 +1,34 @@
 #/** @file
 #
 #  Driver clears the encryption attribute from MMIO regions when SEV is enabled
 #
 #  Copyright (c) 2017, AMD Inc. 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
+#  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.
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
 #
 #**/
 
 [Defines]
   INF_VERSION= 1.25
   BASE_NAME  = AmdSevDxe
   FILE_GUID  = 2ec9da37-ee35-4de9-86c5-6d9a81dc38a7
   MODULE_TYPE= DXE_DRIVER
   VERSION_STRING = 1.0
   ENTRY_POINT= AmdSevDxeEntryPoint
 
 [Sources]
   AmdSevDxe.c
 
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
index e472096320ea..065d7381b35b 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
@@ -1,75 +1,77 @@
 /** @file
 
   AMD Sev Dxe driver. This driver is dispatched early in DXE, due to being list
-  in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when SEV 
is
-  enabled.
+  in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when SEV
+  is enabled.
 
   Copyright (c) 2017, AMD Inc. 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
+  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.
+  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 
 #include 
 
 EFI_STATUS
 EFIAPI
 AmdSevDxeEntryPoint (
   IN EFI_HANDLE ImageHandle,
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
   EFI_STATUS   Status;
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *AllDescMap;
   UINTNNumEntries;
   UINTNIndex;
 
   //
   // Do nothing when SEV is not enabled
   //
   if (!MemEncryptSevIsEnabled ()) {
 return EFI_UNSUPPORTED;
   }
 
   //
   // Iterate through the GCD map and clear the C-bit from MMIO and NonExistent
-  // memory space. The NonExistent memory space will be used for mapping the 
MMIO
-  // space added later (eg PciRootBridge). By clearing both known MMIO and
+  // memory space. The NonExistent memory space will be used for mapping the
+  // MMIO space added later (eg PciRootBridge). By clearing both known MMIO and
   // NonExistent memory space can gurantee that current and furture MMIO adds
   // will have C-bit cleared.
   //
   Status = gDS->GetMemorySpaceMap (, );
   if (!EFI_ERROR (Status)) {
 for (Index = 0; Index < NumEntries; Index++) {
   CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc;
 
   Desc = [Index];
   if (Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo ||
   Desc->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
-Status = MemEncryptSevClearPageEncMask (0,
-  

[edk2] [PATCH 13/20] OvmfPkg/SmmCpuFeaturesLib: remove unneeded #includes and LibraryClasses

2018-03-01 Thread Laszlo Ersek
Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 1 -
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c   | 2 --
 2 files changed, 3 deletions(-)

diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 9448bb166671..5184abbf21bd 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -19,22 +19,21 @@ [Defines]
   BASE_NAME  = SmmCpuFeaturesLib
   MODULE_UNI_FILE= SmmCpuFeaturesLib.uni
   FILE_GUID  = AC9991BE-D77A-464C-A8DE-A873DB8A4836
   MODULE_TYPE= DXE_SMM_DRIVER
   VERSION_STRING = 1.0
   LIBRARY_CLASS  = SmmCpuFeaturesLib
   CONSTRUCTOR= SmmCpuFeaturesLibConstructor
 
 [Sources]
   SmmCpuFeaturesLib.c
 
 [Packages]
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [LibraryClasses]
   BaseLib
   BaseMemoryLib
   DebugLib
-  PcdLib
   SmmServicesTableLib
diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
index 75b9ce0e2b12..13d929a983be 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
@@ -1,39 +1,37 @@
 /** @file
   The CPU specific programming for PiSmmCpuDxeSmm module.
 
   Copyright (c) 2010 - 2015, 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 
 #include 
 #include 
 
 //
 // EFER register LMA bit
 //
 #define LMA BIT10
 
 /**
   The constructor function
 
   @param[in]  ImageHandle  The firmware allocated handle for the EFI image.
   @param[in]  SystemTable  A pointer to the EFI System Table.
 
   @retval EFI_SUCCESS  The constructor always returns EFI_SUCCESS.
 
 **/
 EFI_STATUS
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 01/20] OvmfPkg/MemEncryptSevLib: rewrap to 79 characters width

2018-03-01 Thread Laszlo Ersek
There are many overlong lines; it's hard to work with the library like
this. Rewrap all files to 79 columns.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf   |   7 +-
 OvmfPkg/Include/Library/MemEncryptSevLib.h  |  20 ++-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h| 111 
--
 OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c|  34 +++--
 OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c |   8 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c |  58 ---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c| 158 
+---
 7 files changed, 253 insertions(+), 143 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf 
b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
index 3cfd80a28c1d..81b075194ace 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
@@ -1,45 +1,48 @@
 ## @file
 #  Library provides the helper functions for SEV guest
 #
 # Copyright (c) 2017 Advanced Micro Devices. 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.
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
 #
 #
 ##
 
 [Defines]
   INF_VERSION= 1.25
   BASE_NAME  = MemEncryptSevLib
   FILE_GUID  = c1594631-3888-4be4-949f-9c630dbc842b
   MODULE_TYPE= BASE
   VERSION_STRING = 1.0
   LIBRARY_CLASS  = MemEncryptSevLib|PEIM DXE_DRIVER 
DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER
 
 #
-# The following information is for reference only and not required by the 
build tools.
+# The following information is for reference only and not required by the build
+# tools.
 #
 # VALID_ARCHITECTURES   = IA32 X64
 #
 
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
   OvmfPkg/OvmfPkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [Sources.X64]
   MemEncryptSevLibInternal.c
   X64/MemEncryptSevLib.c
   X64/VirtualMemory.c
 
 [Sources.IA32]
   MemEncryptSevLibInternal.c
   Ia32/MemEncryptSevLib.c
 
 [LibraryClasses]
diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h 
b/OvmfPkg/Include/Library/MemEncryptSevLib.h
index b6753762423e..4f3ba9f22cb4 100644
--- a/OvmfPkg/Include/Library/MemEncryptSevLib.h
+++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h
@@ -18,64 +18,68 @@
 #define _MEM_ENCRYPT_SEV_LIB_H_
 
 #include 
 
 /**
   Returns a boolean to indicate whether SEV is enabled
 
   @retval TRUE   SEV is active
   @retval FALSE  SEV is not enabled
   **/
 BOOLEAN
 EFIAPI
 MemEncryptSevIsEnabled (
   VOID
   );
 
 /**
   This function clears memory encryption bit for the memory region specified
   by BaseAddress and Number of pages from the current page table context.
 
-  @param[in]  BaseAddress   The physical address that is the start 
address
-of a memory region.
-  @param[in]  NumberOfPages The number of pages from start memory 
region.
+  @param[in]  BaseAddress   The physical address that is the start
+address of a memory region.
+  @param[in]  NumberOfPages The number of pages from start memory
+region.
   @param[in]  Flush Flush the caches before clearing the bit
 (mostly TRUE except MMIO addresses)
 
-  @retval RETURN_SUCCESSThe attributes were cleared for the memory 
region.
+  @retval RETURN_SUCCESSThe attributes were cleared for the memory
+region.
   @retval RETURN_INVALID_PARAMETER  Number of pages is zero.
   @retval RETURN_UNSUPPORTEDClearing memory encryption attribute is not
 supported
   **/
 RETURN_STATUS
 EFIAPI
 MemEncryptSevClearPageEncMask (
   IN PHYSICAL_ADDRESS Cr3BaseAddress,
   IN PHYSICAL_ADDRESS BaseAddress,
   IN UINTNNumberOfPages,
   IN BOOLEAN  CacheFlush
   );
 
 /**
   This function sets memory encryption bit for the memory region specified by
   BaseAddress and Number of pages from the 

[edk2] [PATCH 10/20] OvmfPkg/SmmCpuFeaturesLib: rewrap to 79 columns

2018-03-01 Thread Laszlo Ersek
There are many overlong lines; it's hard to work with the library like
this. Rewrap all files to 79 columns.

(

The rewrapping of the "mSmmCpuRegisterRanges" and "mSmmCpuWidthOffset"
arrays was verified by hexdumping the arrays in
SmmCpuFeaturesLibConstructor(), both before and after the patch, and
comparing the dumps.

Contents of "mSmmCpuRegisterRanges", IA32 build:

> mSmmCpuRegisterRanges: {
> mSmmCpuRegisterRanges: 00 04 00 00 00 0A 00 00 00 07 00 00 00 14 00 00 00
> mSmmCpuRegisterRanges: 10 2E 00 00 00 1B 00 00 00 33 00 00 00 36 00 00 00
> mSmmCpuRegisterRanges: 20 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> mSmmCpuRegisterRanges: }

Contents of "mSmmCpuRegisterRanges", X64 build:

> mSmmCpuRegisterRanges: {
> mSmmCpuRegisterRanges: 00 04 00 00 00 0A 00 00 00 07 00 00 00 00 00 00 00
> mSmmCpuRegisterRanges: 10 14 00 00 00 2E 00 00 00 1B 00 00 00 00 00 00 00
> mSmmCpuRegisterRanges: 20 33 00 00 00 36 00 00 00 04 00 00 00 00 00 00 00
> mSmmCpuRegisterRanges: 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> mSmmCpuRegisterRanges: }

Contents of "mSmmCpuWidthOffset", both IA32 and X64 builds:

> mSmmCpuWidthOffset: {
> mSmmCpuWidthOffset: 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 68 02
> mSmmCpuWidthOffset: 10 6C 02 00 00 00 08 00 00 88 02 8C 02 00 00 00 08
> mSmmCpuWidthOffset: 20 00 00 78 02 7C 02 00 00 00 00 00 00 64 02 68 02
> mSmmCpuWidthOffset: 30 00 00 00 00 00 00 84 02 88 02 00 00 00 00 00 00
> mSmmCpuWidthOffset: 40 74 02 78 02 00 00 00 00 00 00 00 00 04 00 00 00
> mSmmCpuWidthOffset: 50 04 04 A8 03 00 02 00 00 00 00 04 04 AC 03 10 02
> mSmmCpuWidthOffset: 60 00 00 00 00 04 04 B0 03 20 02 00 00 00 00 04 04
> mSmmCpuWidthOffset: 70 B4 03 30 02 00 00 00 00 04 04 B8 03 40 02 00 00
> mSmmCpuWidthOffset: 80 00 00 04 04 BC 03 50 02 00 00 00 00 00 04 00 00
> mSmmCpuWidthOffset: 90 70 02 00 00 00 00 04 04 C4 03 90 02 00 00 00 00
> mSmmCpuWidthOffset: A0 04 08 C8 03 60 03 64 03 00 00 04 08 CC 03 68 03
> mSmmCpuWidthOffset: B0 6C 03 00 00 00 08 00 00 B8 03 BC 03 01 00 00 08
> mSmmCpuWidthOffset: C0 00 00 B0 03 B4 03 01 00 00 08 00 00 A8 03 AC 03
> mSmmCpuWidthOffset: D0 01 00 00 08 00 00 A0 03 A4 03 01 00 00 08 00 00
> mSmmCpuWidthOffset: E0 98 03 9C 03 01 00 00 08 00 00 90 03 94 03 01 00
> mSmmCpuWidthOffset: F0 00 08 00 00 88 03 8C 03 01 00 00 08 00 00 80 03
> mSmmCpuWidthOffset: 000100 84 03 01 00 04 08 D0 03 F8 03 FC 03 01 00 04 08
> mSmmCpuWidthOffset: 000110 DC 03 E0 03 E4 03 01 00 04 08 D4 03 F0 03 F4 03
> mSmmCpuWidthOffset: 000120 01 00 04 08 D8 03 E8 03 EC 03 01 00 04 08 E0 03
> mSmmCpuWidthOffset: 000130 D8 03 DC 03 01 00 04 08 E4 03 D0 03 D4 03 01 00
> mSmmCpuWidthOffset: 000140 04 08 E8 03 C8 03 CC 03 01 00 04 08 EC 03 C0 03
> mSmmCpuWidthOffset: 000150 C4 03 01 00 04 08 F0 03 78 03 7C 03 01 00 04 08
> mSmmCpuWidthOffset: 000160 F4 03 70 03 74 03 01 00 04 08 FC 03 58 03 5C 03
> mSmmCpuWidthOffset: 000170 00 00 04 08 F8 03 50 03 54 03 00 00 00 04 00 00
> mSmmCpuWidthOffset: 000180 48 03 4C 03 00 00
> mSmmCpuWidthOffset: }

)

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf |  10 +-
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c   | 594 

 2 files changed, 489 insertions(+), 115 deletions(-)

diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 31edf3a9c1fd..75b24606b9df 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -1,31 +1,33 @@
 ## @file
 #  The CPU specific programming for PiSmmCpuDxeSmm module.
 #
 #  Copyright (c) 2009 - 2015, 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
+#
+#  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.
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
 #
 ##
 
 [Defines]
   INF_VERSION= 0x00010005
   BASE_NAME  = SmmCpuFeaturesLib
   MODULE_UNI_FILE= SmmCpuFeaturesLib.uni
   FILE_GUID  = AC9991BE-D77A-464C-A8DE-A873DB8A4836

[edk2] [PATCH 12/20] OvmfPkg/SmmCpuFeaturesLib: sort #includes, and entries in INF file sections

2018-03-01 Thread Laszlo Ersek
Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 2 +-
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c   | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 75b24606b9df..9448bb166671 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -18,23 +18,23 @@ [Defines]
   INF_VERSION= 0x00010005
   BASE_NAME  = SmmCpuFeaturesLib
   MODULE_UNI_FILE= SmmCpuFeaturesLib.uni
   FILE_GUID  = AC9991BE-D77A-464C-A8DE-A873DB8A4836
   MODULE_TYPE= DXE_SMM_DRIVER
   VERSION_STRING = 1.0
   LIBRARY_CLASS  = SmmCpuFeaturesLib
   CONSTRUCTOR= SmmCpuFeaturesLibConstructor
 
 [Sources]
   SmmCpuFeaturesLib.c
 
 [Packages]
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [LibraryClasses]
   BaseLib
   BaseMemoryLib
-  PcdLib
   DebugLib
+  PcdLib
   SmmServicesTableLib
diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
index 6b9924e49426..75b9ce0e2b12 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
@@ -1,42 +1,42 @@
 /** @file
   The CPU specific programming for PiSmmCpuDxeSmm module.
 
   Copyright (c) 2010 - 2015, 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 
+#include 
+#include 
 #include 
-#include 
+#include 
 #include 
 
 //
 // EFER register LMA bit
 //
 #define LMA BIT10
 
 /**
   The constructor function
 
   @param[in]  ImageHandle  The firmware allocated handle for the EFI image.
   @param[in]  SystemTable  A pointer to the EFI System Table.
 
   @retval EFI_SUCCESS  The constructor always returns EFI_SUCCESS.
 
 **/
 EFI_STATUS
 EFIAPI
 SmmCpuFeaturesLibConstructor (
   IN EFI_HANDLEImageHandle,
-- 
2.14.1.3.gb7cf6e02401b


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 03/20] OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevClearPageEncMask() decl

2018-03-01 Thread Laszlo Ersek
The declaration and the definition(s) of the function should have
identical leading comments and/or identical parameter lists. Also remove
any excess space in the comment block, and unindent the trailing "**/" if
necessary. Correct several parameter references.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Include/Library/MemEncryptSevLib.h   | 34 
+++-
 OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c | 34 
++--
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c  |  7 ++--
 3 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h 
b/OvmfPkg/Include/Library/MemEncryptSevLib.h
index 88b272ebedef..2d574dd30676 100644
--- a/OvmfPkg/Include/Library/MemEncryptSevLib.h
+++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h
@@ -15,63 +15,65 @@
 **/
 
 #ifndef _MEM_ENCRYPT_SEV_LIB_H_
 #define _MEM_ENCRYPT_SEV_LIB_H_
 
 #include 
 
 /**
   Returns a boolean to indicate whether SEV is enabled
 
   @retval TRUE   SEV is enabled
   @retval FALSE  SEV is not enabled
 **/
 BOOLEAN
 EFIAPI
 MemEncryptSevIsEnabled (
   VOID
   );
 
 /**
-  This function clears memory encryption bit for the memory region specified
-  by BaseAddress and Number of pages from the current page table context.
+  This function clears memory encryption bit for the memory region specified by
+  BaseAddress and NumPages from the current page table context.
 
-  @param[in]  BaseAddress   The physical address that is the start
-address of a memory region.
-  @param[in]  NumberOfPages The number of pages from start memory
-region.
-  @param[in]  Flush Flush the caches before clearing the bit
-(mostly TRUE except MMIO addresses)
+  @param[in]  Cr3BaseAddress  Cr3 Base Address (if zero then use
+  current CR3)
+  @param[in]  BaseAddress The physical address that is the start
+  address of a memory region.
+  @param[in]  NumPagesThe number of pages from start memory
+  region.
+  @param[in]  Flush   Flush the caches before clearing the bit
+  (mostly TRUE except MMIO addresses)
 
-  @retval RETURN_SUCCESSThe attributes were cleared for the memory
-region.
-  @retval RETURN_INVALID_PARAMETER  Number of pages is zero.
-  @retval RETURN_UNSUPPORTEDClearing memory encryption attribute is not
-supported
-  **/
+  @retval RETURN_SUCCESS  The attributes were cleared for the
+  memory region.
+  @retval RETURN_INVALID_PARAMETERNumber of pages is zero.
+  @retval RETURN_UNSUPPORTED  Clearing the memory encryption attribute
+  is not supported
+**/
 RETURN_STATUS
 EFIAPI
 MemEncryptSevClearPageEncMask (
   IN PHYSICAL_ADDRESS Cr3BaseAddress,
   IN PHYSICAL_ADDRESS BaseAddress,
-  IN UINTNNumberOfPages,
-  IN BOOLEAN  CacheFlush
+  IN UINTNNumPages,
+  IN BOOLEAN  Flush
   );
 
 /**
   This function sets memory encryption bit for the memory region specified by
   BaseAddress and Number of pages from the current page table context.
 
   @param[in]  BaseAddress   The physical address that is the start
 address of a memory region.
   @param[in]  NumberOfPages The number of pages from start memory
 region.
   @param[in]  Flush Flush the caches before clearing the bit
 (mostly TRUE except MMIO addresses)
 
   @retval RETURN_SUCCESSThe attributes were set for the memory
 region.
   @retval RETURN_INVALID_PARAMETER  Number of pages is zero.
   @retval RETURN_UNSUPPORTEDClearing memory encryption attribute is not
 supported
   **/
 RETURN_STATUS
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
index d1130df2d0e7..d6067c52aacd 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
@@ -5,64 +5,64 @@
   Copyright (c) 2017, AMD Incorporated. All rights reserved.
 
   This program and the accompanying materials are licensed and made available
   

[edk2] [PATCH 11/20] OvmfPkg/SmmCpuFeaturesLib: upper-case the "static" keyword

2018-03-01 Thread Laszlo Ersek
In edk2, the "static" keyword is spelled "STATIC". Also let "STATIC" stand
alone on a line in function definitions.

Cc: Ard Biesheuvel 
Cc: Brijesh Singh 
Cc: Jordan Justen 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c 
b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
index a876a6e34751..6b9924e49426 100644
--- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
+++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
@@ -427,61 +427,61 @@ typedef struct {
 ///
 /// Structure used to build a lookup table to retrieve the widths and offsets
 /// associated with each supported EFI_SMM_SAVE_STATE_REGISTER value
 ///
 
 #define SMM_SAVE_STATE_REGISTER_FIRST_INDEX 1
 
 typedef struct {
   UINT8   Width32;
   UINT8   Width64;
   UINT16  Offset32;
   UINT16  Offset64Lo;
   UINT16  Offset64Hi;
   BOOLEAN Writeable;
 } CPU_SMM_SAVE_STATE_LOOKUP_ENTRY;
 
 ///
 /// Table used by GetRegisterIndex() to convert an EFI_SMM_SAVE_STATE_REGISTER
 /// value to an index into a table of type CPU_SMM_SAVE_STATE_LOOKUP_ENTRY
 ///
-static CONST CPU_SMM_SAVE_STATE_REGISTER_RANGE mSmmCpuRegisterRanges[] = {
+STATIC CONST CPU_SMM_SAVE_STATE_REGISTER_RANGE mSmmCpuRegisterRanges[] = {
   SMM_REGISTER_RANGE (
 EFI_SMM_SAVE_STATE_REGISTER_GDTBASE,
 EFI_SMM_SAVE_STATE_REGISTER_LDTINFO
 ),
   SMM_REGISTER_RANGE (
 EFI_SMM_SAVE_STATE_REGISTER_ES,
 EFI_SMM_SAVE_STATE_REGISTER_RIP
 ),
   SMM_REGISTER_RANGE (
 EFI_SMM_SAVE_STATE_REGISTER_RFLAGS,
 EFI_SMM_SAVE_STATE_REGISTER_CR4
 ),
   { (EFI_SMM_SAVE_STATE_REGISTER)0, (EFI_SMM_SAVE_STATE_REGISTER)0, 0 }
 };
 
 ///
 /// Lookup table used to retrieve the widths and offsets associated with each
 /// supported EFI_SMM_SAVE_STATE_REGISTER value
 ///
-static CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmCpuWidthOffset[] = {
+STATIC CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY mSmmCpuWidthOffset[] = {
   {
 0,// Width32
 0,// Width64
 0,// Offset32
 0,// Offset64Lo
 0,// Offset64Hi
 FALSE // Writeable
   }, // Reserved
 
   //
   // CPU Save State registers defined in PI SMM CPU Protocol.
   //
   {
 0,// Width32
 8,// Width64
 0,// Offset32
 SMM_CPU_OFFSET (x64._GDTRBase),   // Offset64Lo
 SMM_CPU_OFFSET (x64._GDTRBase) + 4,   // Offset64Hi
 FALSE // Writeable
   }, // EFI_SMM_SAVE_STATE_REGISTER_GDTBASE = 4
@@ -816,41 +816,42 @@ static CONST CPU_SMM_SAVE_STATE_LOOKUP_ENTRY 
mSmmCpuWidthOffset[] = {
 0,// Offset32
 SMM_CPU_OFFSET (x64._CR4),// Offset64Lo
 SMM_CPU_OFFSET (x64._CR4) + 4,// Offset64Hi
 FALSE // Writeable
   }, // EFI_SMM_SAVE_STATE_REGISTER_CR4 = 54
 };
 
 //
 // No support for I/O restart
 //
 
 /**
   Read information from the CPU save state.
 
   @param  Register  Specifies the CPU register to read form the save state.
 
   @retval 0   Register is not valid
   @retval >0  Index into mSmmCpuWidthOffset[] associated with Register
 
 **/
-static UINTN
+STATIC
+UINTN
 GetRegisterIndex (
   IN EFI_SMM_SAVE_STATE_REGISTER  Register
   )
 {
   UINTN  Index;
   UINTN  Offset;
 
   for (Index = 0, Offset = SMM_SAVE_STATE_REGISTER_FIRST_INDEX;
mSmmCpuRegisterRanges[Index].Length != 0;
Index++) {
 if (Register >= mSmmCpuRegisterRanges[Index].Start &&
 Register <= mSmmCpuRegisterRanges[Index].End) {
   return Register - mSmmCpuRegisterRanges[Index].Start + Offset;
 }
 Offset += mSmmCpuRegisterRanges[Index].Length;
   }
   return 0;
 }
 
 /**
@@ -859,41 +860,42 @@ GetRegisterIndex (
   This function abstracts the differences that whether the CPU Save State
   register is in the IA32 CPU Save State Map or X64 CPU Save State Map.
 
   This function supports reading a CPU Save State register in SMBase relocation
   handler.
 
   @param[in]  CpuIndex   Specifies the zero-based index of the CPU save
  state.
   @param[in]  RegisterIndex  Index into mSmmCpuWidthOffset[] look up table.
   @param[in]  Width  The number of bytes to read from the CPU save
  state.
   @param[out] Buffer Upon return, this holds the CPU register value
  read from the save state.
 
   @retval EFI_SUCCESS  

[edk2] [PATCH 2/4] MdeModulePkg: introduce runtime debug output protocol

2018-03-01 Thread Ard Biesheuvel
Introduce a EDK2 specific protocol that may be invoked to produce
debug output at runtime. This may be used, e.g., by DebugLib library
class implementations called from DXE_RUNTIME_DRIVER modules, which
may only be able to produce debug output at boot time, and will be
able to defer to this protocol to produce debug output at runtime as
well.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h | 58 
 MdeModulePkg/MdeModulePkg.dec  |  4 ++
 2 files changed, 62 insertions(+)

diff --git a/MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h 
b/MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h
new file mode 100644
index ..ac6e0c27d86d
--- /dev/null
+++ b/MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h
@@ -0,0 +1,58 @@
+/** @file
+  Protocol for emitting debug output at runtime. May be consumed by DebugLib
+  implementations that can only produce output safely at boot time.
+
+  Copyright (c) 2018, Linaro, Ltd. 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.
+
+**/
+
+#ifndef __EDK2_RUNTIME_DEBUG_OUTPUT_H__
+#define __EDK2_RUNTIME_DEBUG_OUTPUT_H__
+
+#define EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL_GUID \
+  { 0x3f4fe308, 0x2284, 0x4ca2, { 0xbe, 0x2c, 0x2d, 0xa8, 0xdf, 0x7a, 0xec, 
0xd6 } }
+
+typedef struct _EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL 
EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL;
+
+/**
+  Write data from buffer to debug output device
+
+  Writes NumberOfBytes data bytes from Buffer to the debug output device.
+  The number of bytes actually written to the device is returned.
+  If the return value is less than NumberOfBytes, then the write operation
+  failed.
+  If NumberOfBytes is zero, then return 0.
+
+  @param  Buffer   Pointer to the data buffer to be written.
+  @param  NumberOfBytesNumber of bytes to written to the device.
+
+  @retval 0NumberOfBytes is 0.
+  @retval >0   The number of bytes written to the serial device.
+   If this value is less than NumberOfBytes, then the
+   write operation failed.
+
+**/
+typedef
+UINTN
+(EFIAPI *RUNTIME_DEBUG_OUTPUT_WRITE) (
+  IN  EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL  *This,
+  IN  UINT8   *Buffer,
+  IN  UINTN   NumberOfBytes
+  );
+
+
+struct _EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL {
+  RUNTIME_DEBUG_OUTPUT_WRITEWrite;
+};
+
+extern EFI_GUID gEdkiiRuntimeDebugOutputProtocolGuid;
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index ba0585936b6e..faaf189fe464 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -592,6 +592,10 @@ [Protocols]
   gEdkiiPlatformSpecificResetFilterProtocolGuid  = { 0x695d7835, 0x8d47, 
0x4c11, { 0xab, 0x22, 0xfa, 0x8a, 0xcc, 0xe7, 0xae, 0x7a } }
   ## Include/Protocol/PlatformSpecificResetHandler.h
   gEdkiiPlatformSpecificResetHandlerProtocolGuid = { 0x2df6ba0b, 0x7092, 
0x440d, { 0xbd, 0x4, 0xfb, 0x9, 0x1e, 0xc3, 0xf3, 0xc1 } }
+
+  ## Include/Protocol/RuntimeDebugOutput.h
+  gEdkiiRuntimeDebugOutputProtocolGuid = { 0x3f4fe308, 0x2284, 0x4ca2, { 0xbe, 
0x2c, 0x2d, 0xa8, 0xdf, 0x7a, 0xec, 0xd6 } }
+
 #
 # [Error.gEfiMdeModulePkgTokenSpaceGuid]
 #   0x8001 | Invalid value provided.
-- 
2.11.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 3/4] MdeModulePkg/DxeRuntimeDebugLibSerialPort: invoke RuntimeDebugOutputProtocol

2018-03-01 Thread Ard Biesheuvel
Extend the functionality of DxeRuntimeDebugLibSerialPort by invoking
any available RuntimeDebugOutputProtocol to emit debug output at
runtime rather than staying silent.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c   
| 155 +---
 
MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
 |   5 +
 2 files changed, 143 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c 
b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
index e1266f77fa41..b5460f10ebb6 100644
--- a/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
+++ b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
@@ -25,10 +25,16 @@
 #include 
 #include 
 #include 
+#include 
 
 STATIC EFI_EVENT  mEfiExitBootServicesEvent;
+STATIC EFI_EVENT  mEfiVirtualAddressChangeEvent;
+STATIC EFI_EVENT  mRegisterRuntimeDebugOutputProtocolEvent;
+STATIC VOID   *mRegisterProtocolRegistration;
 STATIC BOOLEANmEfiAtRuntime = FALSE;
 
+STATIC EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL   *mRuntimeOutput = NULL;
+
 //
 // Define the maximum debug and assert message length that this library 
supports
 //
@@ -53,6 +59,58 @@ ExitBootServicesEvent (
 }
 
 /**
+  Attach to the RuntimeDebugOutputProtocol as soon as it gets registered
+
+  @param[in]  Event   The Event that is being processed.
+  @param[in]  Context The Event Context.
+
+**/
+STATIC
+VOID
+EFIAPI
+RegisterRuntimeDebugOutputProtocolEvent (
+  IN EFI_EVENTEvent,
+  IN VOID *Context
+  )
+{
+  EFI_STATUS  Status;
+  EFI_BOOT_SERVICES   *BS;
+
+  BS = Context;
+
+  Status = BS->LocateProtocol (,
+ mRegisterProtocolRegistration,
+ (VOID **));
+  if (EFI_ERROR (Status)) {
+return;
+  }
+
+  BS->CloseEvent (Event);
+}
+
+/**
+  Fix up virtual address of the runtime debug output protocol
+
+  @param[in]  Event   The Event that is being processed.
+  @param[in]  Context The Event Context.
+
+**/
+STATIC
+VOID
+EFIAPI
+VirtualAddressChangeEvent (
+  IN EFI_EVENTEvent,
+  IN VOID *Context
+  )
+{
+  EFI_RUNTIME_SERVICES  *RT;
+
+  RT = Context;
+
+  RT->ConvertPointer (0x0, (VOID **));
+}
+
+/**
   The constructor function to initialize the Serial Port library and
   register a callback for the ExitBootServices event.
 
@@ -70,17 +128,64 @@ DxeRuntimeDebugLibSerialPortConstructor (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_STATUSStatus;
+  EFI_STATUS  Status;
+  EFI_BOOT_SERVICES   *BS;
 
   Status = SerialPortInitialize ();
   if (EFI_ERROR (Status)) {
 return Status;
   }
 
-  return SystemTable->BootServices->CreateEventEx (EVT_NOTIFY_SIGNAL,
-  TPL_NOTIFY, ExitBootServicesEvent, NULL,
-  ,
-  );
+  BS = SystemTable->BootServices;
+
+  Status = BS->CreateEvent (EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
+ RegisterRuntimeDebugOutputProtocolEvent, BS,
+ );
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  //
+  // Register for protocol notifications on this event
+  //
+  Status = BS->RegisterProtocolNotify (,
+ mRegisterRuntimeDebugOutputProtocolEvent,
+ );
+  if (EFI_ERROR (Status)) {
+goto CloseProtocolEvent;
+  }
+
+  //
+  // Kick the event so we will perform an initial pass of
+  // current installed drivers
+  //
+  BS->SignalEvent (mRegisterRuntimeDebugOutputProtocolEvent);
+
+  Status = BS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
+ ExitBootServicesEvent, NULL,
+ ,
+ );
+  if (EFI_ERROR (Status)) {
+goto CloseProtocolEvent;
+  }
+
+  Status = BS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
+ VirtualAddressChangeEvent, SystemTable->RuntimeServices,
+ ,
+ );
+  if (EFI_ERROR (Status)) {
+goto CloseExitBootServicesEvent;
+  }
+
+  return EFI_SUCCESS;
+
+CloseExitBootServicesEvent:
+  BS->CloseEvent (mEfiExitBootServicesEvent);
+
+CloseProtocolEvent:
+  BS->CloseEvent (mRegisterRuntimeDebugOutputProtocolEvent);
+
+  return Status;
 }
 
 /**
@@ -100,7 +205,29 @@ DxeRuntimeDebugLibSerialPortDestructor (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  return SystemTable->BootServices->CloseEvent (mEfiExitBootServicesEvent);
+  EFI_BOOT_SERVICES   *BS;
+
+  BS = SystemTable->BootServices;
+
+  BS->CloseEvent (mRegisterRuntimeDebugOutputProtocolEvent);
+  BS->CloseEvent (mEfiExitBootServicesEvent);
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+UINTN
+DebugWriteOutput (
+  IN  UINT8   *Buffer,
+  IN  UINTN   NumberOfBytes
+  )
+{
+  if (!mEfiAtRuntime) {
+return SerialPortWrite (Buffer, NumberOfBytes);
+  } else 

[edk2] [PATCH 1/4] MdePkg: move DxeRuntimeDebugLibSerialPort to MdeModulePkg

2018-03-01 Thread Ard Biesheuvel
Before making enhancements to DxeRuntimeDebugLibSerialPort involving
EDK2 specific protocols, move the driver from MdePkg to MdeModulePkg,
which permits such EDK2 specific deviations from the PI spec.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 ArmVirtPkg/ArmVirt.dsc.inc 
| 2 +-
 {MdePkg => MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c   
| 0
 {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
 | 0
 {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
 | 0
 4 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index cde514958da2..8f411fde1f8b 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -232,7 +232,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER]
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
 !if $(TARGET) != RELEASE
-  
DebugLib|MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
+  
DebugLib|MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
 !endif
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
diff --git a/MdePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c 
b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
similarity index 100%
rename from MdePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
rename to MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
diff --git 
a/MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf 
b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
similarity index 100%
rename from 
MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
rename to 
MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
diff --git 
a/MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni 
b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
similarity index 100%
rename from 
MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
rename to 
MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
-- 
2.11.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 4/4] ArmPlatformPkg: add PL011 UART runtime debug driver

2018-03-01 Thread Ard Biesheuvel
Implement the new runtime debug output protocol on top of a PL011 UART.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c 
  | 144 
 
ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf
 |  62 +
 2 files changed, 206 insertions(+)

diff --git 
a/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c
 
b/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c
new file mode 100644
index ..155b2c50d463
--- /dev/null
+++ 
b/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c
@@ -0,0 +1,144 @@
+/** @file
+  Runtime driver to produce debug output on a PL011 UART
+
+  Copyright (c) 2018, Linaro, Ltd. 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 
+
+STATIC UINTNmUartBase;
+STATIC EFI_EVENTmVirtualAddressChangeEvent;
+
+/**
+  Write data from buffer to debug output device
+
+  Writes NumberOfBytes data bytes from Buffer to the debug output device.
+  The number of bytes actually written to the device is returned.
+  If the return value is less than NumberOfBytes, then the write operation
+  failed.
+  If NumberOfBytes is zero, then return 0.
+
+  @param  Buffer   Pointer to the data buffer to be written.
+  @param  NumberOfBytesNumber of bytes to written to the device.
+
+  @retval 0NumberOfBytes is 0.
+  @retval >0   The number of bytes written to the serial device.
+   If this value is less than NumberOfBytes, then the
+   write operation failed.
+
+**/
+STATIC
+UINTN
+PL011RuntimeDebugOutputWrite (
+  IN  EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL  *This,
+  IN  UINT8   *Buffer,
+  IN  UINTN   NumberOfBytes
+  )
+{
+  return PL011UartWrite (mUartBase, Buffer, NumberOfBytes);
+}
+
+STATIC EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL mRuntimeDebugOutput = {
+  PL011RuntimeDebugOutputWrite
+};
+
+/**
+  Fixup internal data so that EFI can be called in virtual mode.
+
+  @param[in]Event   The Event that is being processed
+  @param[in]Context Event Context
+**/
+STATIC
+VOID
+EFIAPI
+VirtualNotifyEvent (
+  IN EFI_EVENTEvent,
+  IN VOID *Context
+  )
+{
+  EfiConvertPointer (0x0, (VOID **));
+}
+
+EFI_STATUS
+EFIAPI
+PL011RuntimeDebugOutputDxeEntry (
+  IN EFI_HANDLEImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+  EFI_HANDLE  Handle;
+  UINT64  BaudRate;
+  UINT32  ReceiveFifoDepth;
+  EFI_PARITY_TYPE Parity;
+  UINT8   DataBits;
+  EFI_STOP_BITS_TYPE  StopBits;
+
+  mUartBase= (UINTN)FixedPcdGet64 (PcdSerialRegisterBase);
+  BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate);
+  ReceiveFifoDepth = 0; // Use default FIFO depth
+  Parity   = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);
+  DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);
+  StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 
(PcdUartDefaultStopBits);
+
+  Status = PL011UartInitializePort (mUartBase, FixedPcdGet32 
(PL011UartClkInHz),
+ , , , , );
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  //
+  // Register for the virtual address change event
+  //
+  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
+  VirtualNotifyEvent, NULL, ,
+  );
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  //
+  // Declare the UART MMIO region as EFI_MEMORY_RUNTIME
+  //
+  Status = gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo, mUartBase,
+  SIZE_4KB, EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
+  if (EFI_ERROR (Status)) {
+goto CloseEvent;
+  }
+
+  Status = gDS->SetMemorySpaceAttributes (mUartBase, SIZE_4KB,
+  EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
+  if (EFI_ERROR (Status)) {
+goto CloseEvent;
+  }
+
+  Handle = NULL;
+  Status = gBS->InstallMultipleProtocolInterfaces (,
+  , ,
+  NULL);
+  if (EFI_ERROR (Status)) {
+goto CloseEvent;
+  }
+
+  return EFI_SUCCESS;
+
+CloseEvent:
+  gBS->CloseEvent (mVirtualAddressChangeEvent);
+
+  return Status;
+}
diff --git 
a/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf
 

[edk2] [PATCH 0/4] implement runtime debug output protocl

2018-03-01 Thread Ard Biesheuvel
As discussed on list, MMIO based UARTs cannot be used at runtime without
taking special precautions to register the MMIO region and switch to the
virtual address when accessing it at runtime.

So extend the recently introduced DxeRuntimeDebugLibSerialPort library by
invoking the proposed RuntimeDebugOutput protocol at runtime if one is
available, and providing an implementation of this protocol for PL011.

Ard Biesheuvel (4):
  MdePkg: move DxeRuntimeDebugLibSerialPort to MdeModulePkg
  MdeModulePkg: introduce runtime debug output protocol
  MdeModulePkg/DxeRuntimeDebugLibSerialPort: invoke
RuntimeDebugOutputProtocol
  ArmPlatformPkg: add PL011 UART runtime debug driver

 ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c 
| 144 ++
 
ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf
   |  62 
 ArmVirtPkg/ArmVirt.dsc.inc 
|   2 +-
 MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h 
|  58 
 {MdePkg => MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c   
| 155 +---
 {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
 |   5 +
 {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
 |   0
 MdeModulePkg/MdeModulePkg.dec  
|   4 +
 8 files changed, 412 insertions(+), 18 deletions(-)
 create mode 100644 
ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c
 create mode 100644 
ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf
 create mode 100644 MdeModulePkg/Include/Protocol/RuntimeDebugOutput.h
 rename {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c (70%)
 rename {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf
 (88%)
 rename {MdePkg => 
MdeModulePkg}/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.uni
 (100%)

-- 
2.11.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550: Prevent truncating constant values.

2018-03-01 Thread Marvin Häuser
The Base.h changes making BIT definitions unsigned have been denied.
Is a V2 needed for this patch? I verified again that casting the result of the 
inversion triggers the warning, except when casted before doing so, at least by 
VS2017.

Thanks,
Marvin.

> -Original Message-
> From: Zeng, Star 
> Sent: Wednesday, February 28, 2018 3:44 AM
> To: marvin.haeu...@outlook.com; edk2-devel@lists.01.org
> Cc: Ni, Ruiyu ; Laszlo Ersek ;
> Dong, Eric ; Zeng, Star 
> Subject: RE: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550:
> Prevent truncating constant values.
> 
> Could simply use 0xFFFC for this case?
> 
> Thanks,
> Star
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Marvin H?user
> Sent: Wednesday, February 28, 2018 2:56 AM
> To: edk2-devel@lists.01.org
> Cc: Ni, Ruiyu ; Laszlo Ersek ;
> Dong, Eric ; Zeng, Star 
> Subject: Re: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550:
> Prevent truncating constant values.
> 
> Hey Laszlo,
> 
> Thanks for your... detailed explanation. :) I actually submitted another patch
> to prevent what you explained - "[edk2] [PATCH 1/2] MdePkg/Base.h:
> Ensure safe bitwise operations.", which marks all BIT defines (and more) as
> unsigned.
> Most definitely I should have mentioned it in the commit message or held it
> back till that patch will be accepted (or denied?), seems like I forgot about
> that.
> Would you still prefer your suggestion even when the Base.h patch is
> merged? After all, int might happen to be even larger than INT32, if I'm not
> mistaken.
> 
> I'm quite sure VS2015x86 issued the warning despite that commit being
> applied locally. It seems to always warn when a constant is truncated,
> explicitely or implicitely, to give you the change to increase its size:
> https://msdn.microsoft.com/en-us/library/sz5z1byt.aspx
> 
> Thanks again for your comprehensive review!
> 
> Best regards,
> Marvin.
> 
> > -Original Message-
> > From: Laszlo Ersek 
> > Sent: Tuesday, February 27, 2018 7:35 PM
> > To: Marvin Häuser ; edk2-
> > de...@lists.01.org
> > Cc: ruiyu...@intel.com; eric.d...@intel.com; star.z...@intel.com
> > Subject: Re: [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550:
> > Prevent truncating constant values.
> >
> > Hi Marvin,
> >
> > On 02/27/18 17:49, Marvin Häuser wrote:
> > > The toolcahin VS2015x86 issues warnings when truncating constant
> > > values. Explicitely cast such to avoid it.
> > >
> > > Contributed-under: TianoCore Contribution Agreement 1.1
> > > Signed-off-by: Marvin Haeuser 
> > > ---
> > >
> > > MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > > | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git
> > >
> >
> a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > >
> >
> b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > > index 0ccac96f419c..10eca6c0a7aa 100644
> > > ---
> > >
> >
> a/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.c
> > > +++
> > b/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib165
> > > +++ 50.c
> > > @@ -366,7 +366,7 @@ GetSerialRegisterBase (
> > >//
> > >if (DeviceInfo->PowerManagementStatusAndControlRegister != 0x00) {
> > >  if ((PciRead16 (PciLibAddress + DeviceInfo-
> > >PowerManagementStatusAndControlRegister) & (BIT0 | BIT1)) != 0x00) {
> > > -  PciAnd16 (PciLibAddress + DeviceInfo-
> > >PowerManagementStatusAndControlRegister, (UINT16)~(BIT0 | BIT1));
> > > +  PciAnd16 (PciLibAddress +
> > > + DeviceInfo->PowerManagementStatusAndControlRegister,
> > > + (UINT16)~(UINT16)(BIT0 | BIT1));
> > >//
> > >// If PCI UART was not in D0, then make sure FIFOs are
> > > enabled, but do
> > not reset FIFOs
> > >//
> > > @@ -402,7 +402,7 @@ GetSerialRegisterBase (
> > >  //
> > >  if (DeviceInfo->PowerManagementStatusAndControlRegister != 0x00)
> {
> > >if ((PciRead16 (PciLibAddress + DeviceInfo-
> > >PowerManagementStatusAndControlRegister) & (BIT0 | BIT1)) != 0x00) {
> > > -PciAnd16 (PciLibAddress + DeviceInfo-
> > >PowerManagementStatusAndControlRegister, (UINT16)~(BIT0 | BIT1));
> > > +PciAnd16 (PciLibAddress +
> > > + DeviceInfo->PowerManagementStatusAndControlRegister,
> > > + (UINT16)~(UINT16)(BIT0 | BIT1));
> > >}
> > >  }
> > >
> > >
> >
> > I find these warnings -- which I can only make up in my mind, since
> > the commit message does not contain them -- bizarre. More precisely, I
> > find the fact bizarre that the patch suppresses those warnings. Here's
> > my
> > argument:
> >
> > The expression (BIT0 | BIT1) has type "int". (Or, if you will,
> > 

Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations.

2018-03-01 Thread Marvin Häuser
Hey Mike,

Thanks for your reply.
Under these circumstances I will not submit a V2. I hope you find a decent set 
of tests to be performed.

Regards,
Marvin.

> -Original Message-
> From: Kinney, Michael D 
> Sent: Thursday, March 1, 2018 6:19 PM
> To: Marvin Häuser ; edk2-
> de...@lists.01.org; Kinney, Michael D 
> Cc: ler...@redhat.com; Gao, Liming 
> Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
> operations.
> 
> Marvin,
> 
> Thanks.  I agree that there may be some compiler behavior assumptions.
> 
> I would prefer we add to Base.h tests for the expected behavior
> assumptions and break the build if the compiler does not adhere to those
> assumptions.  We have already added these to verify the size of base types
> and the size of enums.
> 
> /**
>   Verifies the storage size of a given data type.
> 
>   This macro generates a divide by zero error or a zero size array 
> declaration in
>   the preprocessor if the size is incorrect.  These are declared as "extern" 
> so
>   the space for these arrays will not be in the modules.
> 
>   @param  TYPE  The date type to determine the size of.
>   @param  Size  The expected size for the TYPE.
> 
> **/
> #define VERIFY_SIZE_OF(TYPE, Size) extern UINT8
> _VerifySizeof##TYPE[(sizeof(TYPE) == (Size)) / (sizeof(TYPE) == (Size))]
> 
> //
> // Verify that ProcessorBind.h produced UEFI Data Types that are compliant
> with // Section 2.3.1 of the UEFI 2.3 Specification.
> //
> VERIFY_SIZE_OF (BOOLEAN, 1);
> VERIFY_SIZE_OF (INT8, 1);
> VERIFY_SIZE_OF (UINT8, 1);
> VERIFY_SIZE_OF (INT16, 2);
> VERIFY_SIZE_OF (UINT16, 2);
> VERIFY_SIZE_OF (INT32, 4);
> VERIFY_SIZE_OF (UINT32, 4);
> VERIFY_SIZE_OF (INT64, 8);
> VERIFY_SIZE_OF (UINT64, 8);
> VERIFY_SIZE_OF (CHAR8, 1);
> VERIFY_SIZE_OF (CHAR16, 2);
> 
> //
> // The following three enum types are used to verify that the compiler //
> configuration for enum types is compliant with Section 2.3.1 of the // UEFI 
> 2.3
> Specification. These enum types and enum values are not // intended to be
> used. A prefix of '__' is used avoid conflicts with // other types.
> //
> typedef enum {
>   __VerifyUint8EnumValue = 0xff
> } __VERIFY_UINT8_ENUM_SIZE;
> 
> typedef enum {
>   __VerifyUint16EnumValue = 0x
> } __VERIFY_UINT16_ENUM_SIZE;
> 
> typedef enum {
>   __VerifyUint32EnumValue = 0x
> } __VERIFY_UINT32_ENUM_SIZE;
> 
> VERIFY_SIZE_OF (__VERIFY_UINT8_ENUM_SIZE, 4); VERIFY_SIZE_OF
> (__VERIFY_UINT16_ENUM_SIZE, 4); VERIFY_SIZE_OF
> (__VERIFY_UINT32_ENUM_SIZE, 4);
> 
> 
> Mike
> 
> 
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-
> > boun...@lists.01.org] On Behalf Of Marvin Häuser
> > Sent: Thursday, March 1, 2018 3:11 AM
> > To: edk2-devel@lists.01.org; Kinney, Michael D
> > 
> > Cc: ler...@redhat.com; Gao, Liming
> > 
> > Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
> > operations.
> >
> >
> > > -Original Message-
> > > From: Kinney, Michael D 
> > > Sent: Thursday, March 1, 2018 2:42 AM
> > > To: Marvin Häuser ; edk2-
> > > de...@lists.01.org; Kinney, Michael D
> > 
> > > Cc: ler...@redhat.com; Gao, Liming
> > 
> > > Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure
> > safe bitwise
> > > operations.
> > >
> > > Hi Marvin,
> > >
> > > Yes.  I have been reading the thread.
> > >
> > > Lots of really good analysis.
> > >
> > > However, it does not make sense to me to add 'u' to
> > the smaller BITxx,
> > > BASExx, and SIZExx macros if we have constants in
> > other places that do not
> > > add the 'u'. I think this patch may increase the
> > inconsistency of the whole
> > > tree.
> >
> > Basically applying this to the BIT definitions first was to see
> > whether the concept is percepted as a whole.
> > Of course this should be applied to all definitions that are at some
> > point used as a mask, which I continued to do locally.
> >
> > >
> > > If we don’t make this change, what types of issues do
> > we need to fix and
> > > what would the fix entail?
> >
> > To be honest, actual issues are very unlikely to happen as all
> > architectures supported by the specification use two-complements for
> > negative values.
> > Furthermore, all currently supported compilers implement bitwise
> > operations for signed integers seemingly the same way as for unsigned
> > types.
> > However, if either will change in the future, code will silently break
> > as in many mask operations will return values not intended by the
> > code.
> >
> > If you are not interested in the solution concepts previously
> > discussed, I propose as least a Unit Test to verify the operations
> > used in praxis work out fine.
> >
> > Thanks,
> > Marvin.
> >
> > >
> > > Mike
> > >
> > > > -Original Message-
> > 

Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations.

2018-03-01 Thread Kinney, Michael D
Marvin,

Thanks.  I agree that there may be some compiler behavior assumptions.

I would prefer we add to Base.h tests for the expected behavior 
assumptions and break the build if the compiler does not adhere
to those assumptions.  We have already added these to verify the
size of base types and the size of enums.

/**
  Verifies the storage size of a given data type.

  This macro generates a divide by zero error or a zero size array declaration 
in
  the preprocessor if the size is incorrect.  These are declared as "extern" so
  the space for these arrays will not be in the modules.

  @param  TYPE  The date type to determine the size of.
  @param  Size  The expected size for the TYPE.

**/
#define VERIFY_SIZE_OF(TYPE, Size) extern UINT8 
_VerifySizeof##TYPE[(sizeof(TYPE) == (Size)) / (sizeof(TYPE) == (Size))]

//
// Verify that ProcessorBind.h produced UEFI Data Types that are compliant with
// Section 2.3.1 of the UEFI 2.3 Specification.
//
VERIFY_SIZE_OF (BOOLEAN, 1);
VERIFY_SIZE_OF (INT8, 1);
VERIFY_SIZE_OF (UINT8, 1);
VERIFY_SIZE_OF (INT16, 2);
VERIFY_SIZE_OF (UINT16, 2);
VERIFY_SIZE_OF (INT32, 4);
VERIFY_SIZE_OF (UINT32, 4);
VERIFY_SIZE_OF (INT64, 8);
VERIFY_SIZE_OF (UINT64, 8);
VERIFY_SIZE_OF (CHAR8, 1);
VERIFY_SIZE_OF (CHAR16, 2);

//
// The following three enum types are used to verify that the compiler
// configuration for enum types is compliant with Section 2.3.1 of the 
// UEFI 2.3 Specification. These enum types and enum values are not 
// intended to be used. A prefix of '__' is used avoid conflicts with
// other types.
//
typedef enum {
  __VerifyUint8EnumValue = 0xff
} __VERIFY_UINT8_ENUM_SIZE;

typedef enum {
  __VerifyUint16EnumValue = 0x
} __VERIFY_UINT16_ENUM_SIZE;

typedef enum {
  __VerifyUint32EnumValue = 0x
} __VERIFY_UINT32_ENUM_SIZE;

VERIFY_SIZE_OF (__VERIFY_UINT8_ENUM_SIZE, 4);
VERIFY_SIZE_OF (__VERIFY_UINT16_ENUM_SIZE, 4);
VERIFY_SIZE_OF (__VERIFY_UINT32_ENUM_SIZE, 4);


Mike


> -Original Message-
> From: edk2-devel [mailto:edk2-devel-
> boun...@lists.01.org] On Behalf Of Marvin Häuser
> Sent: Thursday, March 1, 2018 3:11 AM
> To: edk2-devel@lists.01.org; Kinney, Michael D
> 
> Cc: ler...@redhat.com; Gao, Liming
> 
> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure
> safe bitwise operations.
> 
> 
> > -Original Message-
> > From: Kinney, Michael D 
> > Sent: Thursday, March 1, 2018 2:42 AM
> > To: Marvin Häuser ; edk2-
> > de...@lists.01.org; Kinney, Michael D
> 
> > Cc: ler...@redhat.com; Gao, Liming
> 
> > Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure
> safe bitwise
> > operations.
> >
> > Hi Marvin,
> >
> > Yes.  I have been reading the thread.
> >
> > Lots of really good analysis.
> >
> > However, it does not make sense to me to add 'u' to
> the smaller BITxx,
> > BASExx, and SIZExx macros if we have constants in
> other places that do not
> > add the 'u'. I think this patch may increase the
> inconsistency of the whole
> > tree.
> 
> Basically applying this to the BIT definitions first
> was to see whether the concept is percepted as a whole.
> Of course this should be applied to all definitions
> that are at some point used as a mask, which I
> continued to do locally.
> 
> >
> > If we don’t make this change, what types of issues do
> we need to fix and
> > what would the fix entail?
> 
> To be honest, actual issues are very unlikely to happen
> as all architectures supported by the specification use
> two-complements for negative values.
> Furthermore, all currently supported compilers
> implement bitwise operations for signed integers
> seemingly the same way as for unsigned types.
> However, if either will change in the future, code will
> silently break as in many mask operations will return
> values not intended by the code.
> 
> If you are not interested in the solution concepts
> previously discussed, I propose as least a Unit Test to
> verify the operations used in praxis work out fine.
> 
> Thanks,
> Marvin.
> 
> >
> > Mike
> >
> > > -Original Message-
> > > From: Marvin Häuser
> [mailto:marvin.haeu...@outlook.com]
> > > Sent: Wednesday, February 28, 2018 10:52 AM
> > > To: edk2-devel@lists.01.org; Kinney, Michael D
> > > 
> > > Cc: ler...@redhat.com; Gao, Liming
> > > 
> > > Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h:
> Ensure safe bitwise
> > > operations.
> > >
> > > Hey Mike,
> > >
> > > You are right, the patch was premature because I
> did not consider any
> > > 'incorrect' or 'clever' usages of these
> definitions.
> > > The problem is not primarily undefined behavior,
> but
> > > implementation-defined behavior.
> > > Any bitwise operation to a signed integer results
> in
> > > implementation-defined behavior, which compilers
> usually do not warn
> > > about, while well-defined behavior is 

Re: [edk2] [PATCH] ShellPkg/UefiShellDebug1CommandsLib: remove I/O address limit from 'mm'

2018-03-01 Thread Ard Biesheuvel
On 1 March 2018 at 15:09, Carsey, Jaben  wrote:
> Good catch. I wonder why that arbitrary restriction originated.
>
> Reviewed-by: Jaben Carsey 
>

Thanks

Pushed as 23b53ede358d


>> -Original Message-
>> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
>> Ard Biesheuvel
>> Sent: Thursday, March 01, 2018 1:39 AM
>> To: edk2-devel@lists.01.org
>> Cc: Ni, Ruiyu ; Carsey, Jaben
>> ; heyi@linaro.org; Ard Biesheuvel
>> 
>> Subject: [edk2] [PATCH] ShellPkg/UefiShellDebug1CommandsLib: remove
>> I/O address limit from 'mm'
>> Importance: High
>>
>> Neither the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL nor the
>> EFI_CPU_IO2_PROTOCOL
>> impose any restrictions when it comes to the range of valid I/O
>> addresses. Even so, the 'mm' command in -IO mode refuses to perform
>> accesses to addresses >= 0x.
>>
>> It is not up to 'mm' to impose this restriction, so remove it.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Ard Biesheuvel 
>> ---
>>  ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c   
>> | 11 -
>> --
>>
>> ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Commands
>> Lib.uni |  2 --
>>  2 files changed, 13 deletions(-)
>>
>> diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
>> b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
>> index 9f97f1d345f7..d1fd42b1cd4d 100644
>> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
>> +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
>> @@ -525,12 +525,6 @@ ShellCommandRunMm (
>>goto Done;
>>  }
>>
>> -if ((AccessType == ShellMmIo) && (Address + Size > MAX_UINT16 + 1)) {
>> -  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
>> (STR_MM_IO_ADDRESS_RANGE), gShellDebug1HiiHandle, L"mm");
>> -  ShellStatus = SHELL_INVALID_PARAMETER;
>> -  goto Done;
>> -}
>> -
>>  //
>>  // locate IO protocol interface
>>  //
>> @@ -592,11 +586,6 @@ ShellCommandRunMm (
>>  //
>>  Complete = FALSE;
>>  do {
>> -  if ((AccessType == ShellMmIo) && (Address + Size > MAX_UINT16 + 1)) {
>> -ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
>> (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle, L"mm");
>> -break;
>> -  }
>> -
>>ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, TRUE, Address,
>> Size, );
>>ShellPrintHiiEx (-1, -1, NULL, mShellMmAccessTypeStr[AccessType],
>> gShellDebug1HiiHandle);
>>ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS),
>> gShellDebug1HiiHandle, Address);
>> diff --git
>> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
>> dsLib.uni
>> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
>> dsLib.uni
>> index b6a133a45444..011a7bfc2db6 100644
>> ---
>> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
>> dsLib.uni
>> +++
>> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
>> dsLib.uni
>> @@ -128,7 +128,6 @@
>>
>>  #string STR_MM_NOT_ALIGNED#language en-US "%H%s%N: Address
>> parameter %016LX is not aligned.\r\n"
>>  #string STR_MM_PCIE_ADDRESS_RANGE #language en-US "%H%s%N:
>> Address parameter %016LX is not a valid PCI/PCIE address.\r\n"
>> -#string STR_MM_IO_ADDRESS_RANGE   #language en-US "%H%s%N: IO
>> address out of range 0 - 0x\r\n"
>>  #string STR_MM_MMIO   #language en-US "%HMMIO%N"
>>  #string STR_MM_IO #language en-US "%HIO%N"
>>  #string STR_MM_PCI#language en-US "%HPCI%N"
>> @@ -136,7 +135,6 @@
>>  #string STR_MM_PCIE   #language en-US "%HPCIE%N"
>>  #string STR_MM_ADDRESS#language en-US "  0x%016lx : "
>>  #string STR_MM_BUF#language en-US "0x%0*lx"
>> -#string STR_MM_ADDRESS_RANGE2 #language en-US "%H%s%N: IO
>> address out of range\r\n"
>>  #string STR_MM_ERROR  #language en-US "%H%s%N: Input had
>> incorrect format\r\n"
>>
>>  #string STR_SETVAR_PRINT  #language en-US "%g - %s - %04x Bytes\r\n"
>> --
>> 2.11.0
>>
>> ___
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 6/7] ovmf: link with Tcg2ConfigDxe module

2018-03-01 Thread Stefan Berger

On 02/26/2018 04:58 AM, Laszlo Ersek wrote:

On 02/23/18 14:23, marcandre.lur...@redhat.com wrote:

From: Marc-André Lureau 

The module allows to tweak and interact with the TPM. Note that many
actions are broken due to implementation of qemu TPM (providing it's
own ACPI table), and the lack of PPI implementation.

CC: Laszlo Ersek 
CC: Stefan Berger 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Marc-André Lureau 
---
  OvmfPkg/OvmfPkgX64.dsc | 2 ++
  OvmfPkg/OvmfPkgX64.fdf | 1 +
  2 files changed, 3 insertions(+)

diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 9bd0709f98..2281bd5ff8 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -669,6 +669,8 @@
NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf
NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf
}
+
+  SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf
  !endif
  
  !if $(SECURE_BOOT_ENABLE) == TRUE

diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index b8dd7ecae4..985404850f 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -399,6 +399,7 @@ INF  
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
  
  !if $(TPM2_ENABLE) == TRUE

  INF  SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf
+INF  SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf
  !endif
  
  



Please drop this patch.

In my earlier investigation I wrote, Tcg2ConfigDxe "[p]rovides a Setup
TUI interface to configure the TPM. IIUC, it can also save the
configured TPM type for subsequent boots (see Tcg2ConfigPei.inf above)".

The INF file itself says "This module is only for reference only, each
platform should have its own setup page."

And Jiewen wrote earlier, "Tcg2ConfigPei/Dxe are platform sample driver.
A platform may have its own version based upon platform requirement. For
example, if a platform supports fTPM, it may use another Tcg2Config driver."

Given that OVMF lacks PEI-phase variable access, and that I consequently
suggested cloning, and seriously trimming, Tcg2ConfigPei, it makes no
sense to include an HII dialog that sets a variable for PEI phase
consumption. Also, as you say, many of the exposed operations are broken
due to lack of PPI support. So let's just postpone the inclusion of this
driver, for now.


Just FYI: The PPI support for the OS requires ACPI and, as it is 
currently implemented, SMF where UEFI variables are manipulated. Some 
menu items in the TPM 2 menu (also TPM 1.2) also require these UEFI 
variables of the PPI interface so that UEFI can react on the menu 
choices upon re.


   Stefan

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Qemu-devel] [PATCH 0/7] RFC: ovmf: preliminary TPM2 support

2018-03-01 Thread Stefan Berger

On 02/23/2018 10:55 AM, Laszlo Ersek wrote:

On 02/23/18 14:23, marcandre.lur...@redhat.com wrote:

From: Marc-André Lureau 

Hi,

The following series adds basic TPM2 support for OVMF-on-QEMU (I
haven't tested TPM1, for lack of interest). It links with the modules
to initializes the device in PEI phase, and do measurements (both PEI
and DXE). The Tcg2Dxe module provides the Tcg2 protocol which allows
the guest to access the measurement log and other facilities.

DxeTpm2MeasureBootLib seems to do its job at measuring images that are
not measured in PEI phase (such as PCI PXE rom)

Tcg2ConfigDxe is mostly interesting for debugging for now.

A major lack is the support for Physical Present Interface (PPI, more
below).

Linux guests seem to work fine. But windows guest generally complains
about the lack of PPI interface (most HLK tests require it, tpm.msc
admin interactions too). I haven't done "real" use-cases tests, as I
lack experience with TPM usage. Any help appreciated to test the TPM.

Tcg2ConfigPei requires variable access, therefore
 must be solved
first. I used "[edk2] [PATCH v2 0/8] OvmfPkg: add the Variable PEIM,
defragment the UEFI memmap" as a base for this series.

I build edk2 with:

$ build -DTPM2_ENABLE -DSECURE_BOOT_ENABLE  -DMEM_VARSTORE_EMU_ENABLE=FALSE

I test with qemu & swtpm/libtpms (tpm2 branches, swtpm_setup.sh --tpm2 
--tpm-state tpmstatedir)

$ swtpm socket --tpmstate tpmstatedir --ctrl type=unixio,path=tpmsock  --tpm2 &
$ qemu .. -chardev socket,id=chrtpm,path=tpmsock -tpmdev 
emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0

Thanks for this work -- extra thanks for the instructions regarding the
software TPM backend.


Please use the tpm2-preview.v2 branch of swtpm and the 
tpm2-preview.rev146.v2 branch of libtpms. I had to change the way the 
state is serialized, so unfortunately you will also have to remove the 
tpm2-00.permall files.


   Stefan

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] ShellPkg/UefiShellDebug1CommandsLib: remove I/O address limit from 'mm'

2018-03-01 Thread Carsey, Jaben
Good catch. I wonder why that arbitrary restriction originated.

Reviewed-by: Jaben Carsey 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Ard Biesheuvel
> Sent: Thursday, March 01, 2018 1:39 AM
> To: edk2-devel@lists.01.org
> Cc: Ni, Ruiyu ; Carsey, Jaben
> ; heyi@linaro.org; Ard Biesheuvel
> 
> Subject: [edk2] [PATCH] ShellPkg/UefiShellDebug1CommandsLib: remove
> I/O address limit from 'mm'
> Importance: High
> 
> Neither the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL nor the
> EFI_CPU_IO2_PROTOCOL
> impose any restrictions when it comes to the range of valid I/O
> addresses. Even so, the 'mm' command in -IO mode refuses to perform
> accesses to addresses >= 0x.
> 
> It is not up to 'mm' to impose this restriction, so remove it.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel 
> ---
>  ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c   | 
> 11 -
> --
> 
> ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Commands
> Lib.uni |  2 --
>  2 files changed, 13 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
> index 9f97f1d345f7..d1fd42b1cd4d 100644
> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
> +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
> @@ -525,12 +525,6 @@ ShellCommandRunMm (
>goto Done;
>  }
> 
> -if ((AccessType == ShellMmIo) && (Address + Size > MAX_UINT16 + 1)) {
> -  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_MM_IO_ADDRESS_RANGE), gShellDebug1HiiHandle, L"mm");
> -  ShellStatus = SHELL_INVALID_PARAMETER;
> -  goto Done;
> -}
> -
>  //
>  // locate IO protocol interface
>  //
> @@ -592,11 +586,6 @@ ShellCommandRunMm (
>  //
>  Complete = FALSE;
>  do {
> -  if ((AccessType == ShellMmIo) && (Address + Size > MAX_UINT16 + 1)) {
> -ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle, L"mm");
> -break;
> -  }
> -
>ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, TRUE, Address,
> Size, );
>ShellPrintHiiEx (-1, -1, NULL, mShellMmAccessTypeStr[AccessType],
> gShellDebug1HiiHandle);
>ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS),
> gShellDebug1HiiHandle, Address);
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.uni
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.uni
> index b6a133a45444..011a7bfc2db6 100644
> ---
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.uni
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.uni
> @@ -128,7 +128,6 @@
> 
>  #string STR_MM_NOT_ALIGNED#language en-US "%H%s%N: Address
> parameter %016LX is not aligned.\r\n"
>  #string STR_MM_PCIE_ADDRESS_RANGE #language en-US "%H%s%N:
> Address parameter %016LX is not a valid PCI/PCIE address.\r\n"
> -#string STR_MM_IO_ADDRESS_RANGE   #language en-US "%H%s%N: IO
> address out of range 0 - 0x\r\n"
>  #string STR_MM_MMIO   #language en-US "%HMMIO%N"
>  #string STR_MM_IO #language en-US "%HIO%N"
>  #string STR_MM_PCI#language en-US "%HPCI%N"
> @@ -136,7 +135,6 @@
>  #string STR_MM_PCIE   #language en-US "%HPCIE%N"
>  #string STR_MM_ADDRESS#language en-US "  0x%016lx : "
>  #string STR_MM_BUF#language en-US "0x%0*lx"
> -#string STR_MM_ADDRESS_RANGE2 #language en-US "%H%s%N: IO
> address out of range\r\n"
>  #string STR_MM_ERROR  #language en-US "%H%s%N: Input had
> incorrect format\r\n"
> 
>  #string STR_SETVAR_PRINT  #language en-US "%g - %s - %04x Bytes\r\n"
> --
> 2.11.0
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 4/7] ovmf: link with Tcg2Pei module

2018-03-01 Thread Marc-André Lureau
Hi

On Mon, Feb 26, 2018 at 10:38 AM, Laszlo Ersek  wrote:
> On 02/23/18 14:23, marcandre.lur...@redhat.com wrote:
>> From: Marc-André Lureau 
>>
>> This module will initialize TPM device, measure reported FVs and BIOS
>> version.
>>
>> CC: Laszlo Ersek 
>> CC: Stefan Berger 
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Marc-André Lureau 
>> ---
>>  OvmfPkg/OvmfPkgX64.dsc | 7 +++
>>  OvmfPkg/OvmfPkgX64.fdf | 1 +
>>  2 files changed, 8 insertions(+)
>>
>> diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
>> index b5cbe8430f..34a7c2778e 100644
>> --- a/OvmfPkg/OvmfPkgX64.dsc
>> +++ b/OvmfPkg/OvmfPkgX64.dsc
>> @@ -279,6 +279,8 @@
>>PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
>>QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
>>  !if $(TPM2_ENABLE)
>> +  BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
>> +  
>> HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf
>>
>> Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLibDTpm.inf
>>Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
>>  !endif
>> @@ -647,6 +649,11 @@
>>
>>  !if $(TPM2_ENABLE) == TRUE
>>SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
>> +  SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf {
>> +
>> +  NULL|SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.inf
>> +  
>> NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf
>> +  }
>>  !endif
>>
>>  !if $(SECURE_BOOT_ENABLE) == TRUE
>> diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
>> index dc35d0a1f7..9558142a42 100644
>> --- a/OvmfPkg/OvmfPkgX64.fdf
>> +++ b/OvmfPkg/OvmfPkgX64.fdf
>> @@ -170,6 +170,7 @@ INF  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
>>  !endif
>>  !if $(TPM2_ENABLE) == TRUE
>>  INF  SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
>> +INF  SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
>>  !endif
>>
>>  
>> 
>>
>
> Would it be possible to drop SHA1 (include SHA256 only) by setting
> PcdTpm2HashMask to value 2? Or SHA1 required for some other reason? (If
> so please mention it in the commit message.)
>

afaik, it's not strictly required, and apparently the support is being
dropped. I'll remove it.

btw, now I understand your comment about read-only variable not being
used by PEI module. I'll add a preliminary patch dropping it from
depex ;)

thanks

-- 
Marc-André Lureau
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2 2/2] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Clear C-bit when SEV is active

2018-03-01 Thread Brijesh Singh



On 02/28/2018 01:41 PM, Laszlo Ersek wrote:

On 02/28/18 17:14, Brijesh Singh wrote:

Commit:24e4ad7 (OvmfPkg: Add AmdSevDxe driver) added a driver which runs
early in DXE phase and clears the C-bit from all MMIO regions (including
Qemu Flash).


(1) This appears incorrect / inexact; AmdSevDxe is dispatched from
APRIORI DXE before the flash driver is dispatched, and the MMIO GCD
entry is only added by the flash driver. So in this case, AmdSevDxe
clears the C-bit on a NonExistent entry that will later be split and
accommodate the flash MMIO range.



Okay, I will update it.



When SMM is enabled, we build two sets of page tables; first
page table is used when executing code in non SMM mode (SMM-less-pgtable)
and second page table is used when we are executing code in SMM mode
(SMM-pgtable).

During boot time, AmdSevDxe driver clears the C-bit from the
SMM-less-pgtable. But when SMM is enabled, Qemu Flash services are used
from SMM mode.

In this patch we explicitly clear the C-bit from Qemu flash MMIO range
before we probe the flash. When OVMF is built with SMM_REQUIRE then
call to initialize the flash services happen after the SMM-pgtable is
created and processor is serving the first SMI. At this time we will
have access to the SMM-pgtable.


(2) Please replace "is serving" with "has served".



Will do



Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh 
---
  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf  |  1 +
  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h |  7 +
  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c | 12 +++
  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c | 33 

  OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c |  6 
  5 files changed, 59 insertions(+)

diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf 
b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf
index ba2d3679a46d..d365e27cbe59 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf
@@ -53,6 +53,7 @@ [LibraryClasses]
DevicePathLib
DxeServicesTableLib
MemoryAllocationLib
+  MemEncryptSevLib
PcdLib
SmmServicesTableLib
UefiBootServicesTableLib
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h 
b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
index 8d83dca7a52c..6c4099c140e8 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
@@ -88,5 +88,12 @@ QemuFlashConvertPointers (
VOID
);
  
+VOID

+BeforeFlashProbe (
+  EFI_PHYSICAL_ADDRESSBaseAddress,
+  UINTN   FdBlockSize,
+  UINTN   FdBlockCount
+  );
+
  #endif


(3) Sorry that I'm again requesting a name change for this function. Can
we call it QemuFlashBeforeProbe()? To be consistent with the other
function names in this header file.

(4) Please add "IN" decorators (also to the function definitions).



Will do

  
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c

index 63b308658e36..a4614de3c901 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
@@ -155,3 +155,15 @@ InstallVirtualAddressChangeHandler (
);
ASSERT_EFI_ERROR (Status);
  }
+
+VOID
+BeforeFlashProbe (
+  EFI_PHYSICAL_ADDRESSBaseAddress,
+  UINTN   FdBlockSize,
+  UINTN   FdBlockCount
+  )
+{
+  //
+  // Do nothing
+  //
+}


(5) This function definition should go into the existent file
"QemuFlashDxe.c".



I will look into it.





diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c 
b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c
index e0617f2503a2..a6cad5af223b 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c
@@ -17,6 +17,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  
@@ -67,3 +68,35 @@ InstallVirtualAddressChangeHandler (

// Nothing.
//
  }
+
+VOID
+BeforeFlashProbe (
+  EFI_PHYSICAL_ADDRESSBaseAddress,
+  UINTN   FdBlockSize,
+  UINTN   FdBlockCount
+  )
+{
+  EFI_STATUS  Status;
+
+  ASSERT (FeaturePcdGet (PcdSmmSmramRequire));
+
+  if (!MemEncryptSevIsEnabled()) {
+return;
+  }
+
+  //
+  // When SEV is enabled, AmdSevDxe runs early in DXE phase and clears the 
C-bit
+  // from the MMIO space (including flash ranges) but the driver runs in non 
SMM


(6) Please update the comment according to (1).



Will do



+  // context hence it cleared 

Re: [edk2] [PATCH 2/7] ovmf: link with Tcg2ConfigPei module

2018-03-01 Thread Marc-André Lureau
Hi

On Fri, Feb 23, 2018 at 6:31 PM, Laszlo Ersek  wrote:
> On 02/23/18 14:23, marcandre.lur...@redhat.com wrote:
>> From: Marc-André Lureau 
>>
>> This module initializes TPM device type based on variable and
>> detection.
>
> (1) I suggest we say the following here:
>
> "The Tcg2ConfigPei module informs the firmware globally about the TPM
> device type, by setting the PcdTpmInstanceGuid PCD to the appropriate
> GUID value. The original module under SecurityPkg can perform device
> detection, or read a cached value from a non-volatile UEFI variable.
> OvmfPkg's clone of the module always performs the hardware detection."
>

ok

> Becase...
>
>> The module requires VariablePei, which is built with
>> MEM_VARSTORE_EMU_ENABLE=FALSE.
>
> (2) ... as I hinted in my response to your blurb, and also as suggested
> by "Tcg2ConfigPei.inf", we should clone Tcg2ConfigPei for OVMF, and
> *trim it* quite a bit.
>
> - The new location should be "OvmfPkg/Tcg/Tcg2Config/".
>
> - We need not copy the ".uni" file (also drop MODULE_UNI_FILE from the
> INF file)
>
> - Re-generate FILE_GUID in the INF file with "uuidgen"
>
> - Remove all PEI-phase variable access; always perform the hw detection.
>
> - I would even suggest removing support for TPM1.2. Just check whether
> TPM2 is available or not.
>

ok

>
> (3) Ultimately, this is what the module should do:
>
> - Check the QEMU hardware for TPM2 availability only
>
> - If found, set the dynamic PCD "PcdTpmInstanceGuid" to
>This is what informs the rest of
>   the firmware about the TPM type.
>
> - Install the gEfiTpmDeviceSelectedGuid PPI. This action permits the
>   PEI_CORE to dispatch the Tcg2Pei module, which consumes the above PCD.
>   In effect, the gEfiTpmDeviceSelectedGuid PPI serializes the setting
>   and the consumption of the "TPM type" PCD.
>
> - If no TPM2 was found, install gPeiTpmInitializationDonePpiGuid.
>   (Normally this is performed by Tcg2Pei, but Tcg2Pei doesn't do it if
>   no TPM2 is available. So in that case our Tcg2ConfigPei must do it.)

ok

>
> (4) Regarding the TPM detection itself. It looks like DetectTpmDevice()
> [SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c] calls a number of TPM1.2
> functions. If the earliest one fails, it assumes "no TPM" at all, but if
> only a later call fails, it deduces, from the 1.2 failure, that TPM2 exists.
>
> I think we can do better than this, in our Tcg2ConfigPei clone:
>
> - We should call Tpm2RequestUseTpm() directly, from
> "SecurityPkg/Include/Library/Tpm2DeviceLib.h".
>
> - And, Tpm2Startup(), from
> "SecurityPkg/Include/Library/Tpm2CommandLib.h", will be called by Tcg2Pei.

ok

>
> (5) Finally, there's no need to set "PcdTpmInitializationPolicy" to
> anything. I don't see it consumed by any module that we should include
> in OVMF. (More on this below.)
>

ok

>
> (6) Now, I realize Tcg2Pei *apparently* depends on
> gEfiPeiReadOnlyVariable2PpiGuid (i.e., read-only variable access in the
> PEI phase) as well. That's a bug in the INF file (the [depex] section).
> If you grep the Tcg2Pei module source for the GUID, the [depex] section
> is the only hit. Can you please submit a separate patch that removes it
> from the depex?

I don't get how you came to that conclusion, both
SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c and
SecurityPkg/Tcg/Tcg2Config/TpmDetection.c match. Apparently, the
variable is used in s3 mode, in DetectTpmDevice().

I'll drop it from OvmfPkg version for now.

>
>
>> CC: Laszlo Ersek 
>> CC: Stefan Berger 
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Marc-André Lureau 
>> ---
>>  OvmfPkg/OvmfPkgX64.dsc | 20 
>>  OvmfPkg/OvmfPkgX64.fdf |  3 +++
>>  2 files changed, 23 insertions(+)
>
> Is there any particular reason to exclude the Ia32 and Ia32X64 builds?
>
> If not, then please modify all three sets of dsc/fdf files identically.

I'd rather keep this as a TODO item for now, since we are not close to
a final version, and it's annoying to have to fix each files etc..

>
>> diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
>> index 32c57b04e1..b5cbe8430f 100644
>> --- a/OvmfPkg/OvmfPkgX64.dsc
>> +++ b/OvmfPkg/OvmfPkgX64.dsc
>> @@ -40,6 +40,7 @@
>
> (7) Please implement the following git settings in your edk2 clone:
>
> https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-guide-for-edk2-contributors-and-maintainers#contrib-05
>
> (in particular "xfuncname")
>
> and
>
> https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-guide-for-edk2-contributors-and-maintainers#contrib-09
>
> This will help reviewers see what section of the DSC / FDF / INI / DEC
> files are modified by a patch hunk.
>

done

>>DEFINE SMM_REQUIRE = FALSE
>>DEFINE TLS_ENABLE  = FALSE
>>DEFINE MEM_VARSTORE_EMU_ENABLE = TRUE
>> +  DEFINE TPM2_ENABLE 

[edk2] [PATCH edk2-platforms] Silicon/SynQuacer/DeviceTree: use more specific PMU 'compatible string

2018-03-01 Thread Ard Biesheuvel
Replace the PMU compatible string "arm,armv8-pmuv3" with the more
accurate "arm,cortex-a53-pmu", potentially making more event types
available.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi 
b/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi
index fdaccb984483..2db7de3d5b96 100644
--- a/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi
+++ b/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi
@@ -379,7 +379,7 @@
 };
 
 pmu {
-compatible = "arm,armv8-pmuv3";
+compatible = "arm,cortex-a53-pmu";
 interrupts =  ;
 };
 
-- 
2.11.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] BaseTools: Dsc/Fdf conditional statement parse issue

2018-03-01 Thread Feng, YunhuaX

Set PCD value with --pcd argument not replace
DSC/Fdf PCD value.

Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1

Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/GenFds/FdfParser.py | 4 
 BaseTools/Source/Python/Workspace/MetaFileParser.py | 4 
 2 files changed, 8 insertions(+)

diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py 
b/BaseTools/Source/Python/GenFds/FdfParser.py
index 44a3564c7c..fc2b409847 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -923,10 +923,14 @@ class FdfParser:
 if ScopeMacro:
 MacroDict.update(ScopeMacro)
 
 MacroDict.update(GlobalData.gGlobalDefines)
 MacroDict.update(GlobalData.gCommandLineDefines)
+if GlobalData.BuildOptionPcd:
+for Item in GlobalData.BuildOptionPcd:
+PcdName, TmpValue = Item.split("=")
+MacroDict[PcdName.strip()] = TmpValue
 # Highest priority
 
 return MacroDict
 
 def __EvaluateConditional(self, Expression, Line, Op = None, Value = None):
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py 
b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 95ea6fb45a..6809003d98 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1241,10 +1241,14 @@ class DscParser(MetaFileParser):
 Macros.update(GlobalData.gPlatformDefines)
 Macros.update(GlobalData.gCommandLineDefines)
 # PCD cannot be referenced in macro definition
 if self._ItemType not in [MODEL_META_DATA_DEFINE, 
MODEL_META_DATA_GLOBAL_DEFINE]:
 Macros.update(self._Symbols)
+if GlobalData.BuildOptionPcd:
+for Item in GlobalData.BuildOptionPcd:
+PcdName, TmpValue = Item.split("=")
+Macros[PcdName.strip()] = TmpValue
 return Macros
 
 def _PostProcess(self):
 Processer = {
 MODEL_META_DATA_SECTION_HEADER  :   
self.__ProcessSectionHeader,
-- 
2.12.2.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 2/6] OvmfPkg/PciHostBridgeLib: Init PCI aperture to 0

2018-03-01 Thread Ni, Ruiyu

On 3/1/2018 6:20 PM, Laszlo Ersek wrote:

On 03/01/18 07:57, Heyi Guo wrote:

Use ZeroMem to initialize all fields in temporary
PCI_ROOT_BRIDGE_APERTURE variables to zero. This is not mandatory but
is helpful for future extension: when we add new fields to
PCI_ROOT_BRIDGE_APERTURE and the default value of these fields can
safely be zero, this code will not suffer from an additional
change.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Heyi Guo 

Cc: Jordan Justen 
Cc: Anthony Perard 
Cc: Julien Grall 
Cc: Ruiyu Ni 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
---
  OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 
  OvmfPkg/Library/PciHostBridgeLib/XenSupport.c   | 5 +
  2 files changed, 9 insertions(+)


I also suggest a different subject line:

OvmfPkg/PciHostBridgeLib: clear PCI_ROOT_BRIDGE_APERTURE vars for (re)init

(74 chars)


I sometimes tries very hard to make the subject line be <= 70 chars.
74 is acceptable?



Thanks
Laszlo




--
Thanks,
Ray
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] BaseTools: Dsc conditional statement parse issue

2018-03-01 Thread Feng, YunhuaX
Set PCD value with --pcd argument not replace
DSC PCD value.

Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1

Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/Workspace/MetaFileParser.py | 5 +
 1 file changed, 5 insertions(+)

diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py 
b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 95ea6fb45a..69a591b8f3 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1601,10 +1601,15 @@ class DscParser(MetaFileParser):
 if ValList[Index] == 'False':
 ValList[Index] = '0'
 
 if (not self._DirectiveEvalStack) or (False not in 
self._DirectiveEvalStack):
 GlobalData.gPlatformPcds[TAB_SPLIT.join(self._ValueList[0:2])] = 
PcdValue
+if GlobalData.BuildOptionPcd:
+for Item in GlobalData.BuildOptionPcd:
+PcdName, TmpValue = Item.split("=")
+if PcdName.strip() == TAB_SPLIT.join(self._ValueList[0:2]):
+PcdValue = TmpValue
 self._Symbols[TAB_SPLIT.join(self._ValueList[0:2])] = PcdValue
 try:
 self._ValueList[2] = '|'.join(ValList)
 except Exception:
 print ValList
-- 
2.12.2.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch] BaseTools: Fix the bug for display incorrect *M flag in report

2018-03-01 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Yonghong Zhu
> Sent: Thursday, March 1, 2018 1:56 PM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [Patch] BaseTools: Fix the bug for display incorrect *M flag 
> in report
> 
> The root cause is the byte array value in the driver Pcd, some bytes
> have additional space character, while the value in DSC file doesn't
> have this space, it cause the string compare return false, so we remove
> the extra space.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Yonghong Zhu 
> ---
>  BaseTools/Source/Python/Common/String.py | 20 ++--
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/Common/String.py 
> b/BaseTools/Source/Python/Common/String.py
> index 5e50bef..696be4c 100644
> --- a/BaseTools/Source/Python/Common/String.py
> +++ b/BaseTools/Source/Python/Common/String.py
> @@ -815,38 +815,38 @@ def GetHelpTextList(HelpTextClassList):
>  return List
> 
>  def StringToArray(String):
>  if isinstance(String, unicode):
>  if len(unicode) == 0:
> -return "{0x00, 0x00}"
> -return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C) for C 
> in String])
> +return "{0x00,0x00}"
> +return "{%s,0x00,0x00}" % ",".join(["0x%02x,0x00" % ord(C) for C in 
> String])
>  elif String.startswith('L"'):
>  if String == "L\"\"":
> -return "{0x00, 0x00}"
> +return "{0x00,0x00}"
>  else:
> -return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C) 
> for C in String[2:-1]])
> +return "{%s,0x00,0x00}" % ",".join(["0x%02x,0x00" % ord(C) for C 
> in String[2:-1]])
>  elif String.startswith('"'):
>  if String == "\"\"":
>  return "{0x00,0x00}"
>  else:
>  StringLen = len(String[1:-1])
>  if StringLen % 2:
> -return "{%s, 0x00}" % ", ".join(["0x%02x" % ord(C) for C in 
> String[1:-1]])
> +return "{%s,0x00}" % ",".join(["0x%02x" % ord(C) for C in 
> String[1:-1]])
>  else:
> -return "{%s, 0x00,0x00}" % ", ".join(["0x%02x" % ord(C) for 
> C in String[1:-1]])
> +return "{%s,0x00,0x00}" % ",".join(["0x%02x" % ord(C) for C 
> in String[1:-1]])
>  elif String.startswith('{'):
>  StringLen = len(String.split(","))
>  if StringLen % 2:
> -return "{%s, 0x00}" % ", ".join([ C for C in 
> String[1:-1].split(',')])
> +return "{%s,0x00}" % ",".join([ C.strip() for C in 
> String[1:-1].split(',')])
>  else:
> -return "{%s}" % ", ".join([ C for C in String[1:-1].split(',')])
> +return "{%s}" % ",".join([ C.strip() for C in 
> String[1:-1].split(',')])
> 
>  else:
>  if len(String.split()) % 2:
> -return '{%s, 0}' % ', '.join(String.split())
> +return '{%s,0}' % ','.join(String.split())
>  else:
> -return '{%s, 0,0}' % ', '.join(String.split())
> +return '{%s,0,0}' % ','.join(String.split())
> 
>  def StringArrayLength(String):
>  if isinstance(String, unicode):
>  return (len(String) + 1) * 2 + 1;
>  elif String.startswith('L"'):
> --
> 2.6.1.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch] BaseTools: update DNS_DEVICE_PATH/URI_DEVICE_PATH definition

2018-03-01 Thread Gao, Liming
Reviewed-by: Liming Gao 

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
> Yonghong Zhu
> Sent: Thursday, March 1, 2018 4:17 PM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [Patch] BaseTools: update DNS_DEVICE_PATH/URI_DEVICE_PATH 
> definition
> 
> Update this two definition to align with MdePkg.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Yonghong Zhu 
> ---
>  BaseTools/Source/C/Include/Protocol/DevicePath.h | 13 ++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/BaseTools/Source/C/Include/Protocol/DevicePath.h 
> b/BaseTools/Source/C/Include/Protocol/DevicePath.h
> index a5d8eea..68bb37e 100644
> --- a/BaseTools/Source/C/Include/Protocol/DevicePath.h
> +++ b/BaseTools/Source/C/Include/Protocol/DevicePath.h
> @@ -3,11 +3,11 @@
> 
>The device path represents a programmatic path to a device,
>from a software point of view. The path must persist from boot to boot, so
>it can not contain things like PCI bus numbers that change from boot to 
> boot.
> 
> -Copyright (c) 2017, Intel Corporation. All rights reserved.
> +Copyright (c) 2017 - 2018, 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 that accompanies this 
> distribution.
>  The full text of the license may be found at
>  http://opensource.org/licenses/bsd-license.php.
> 
> @@ -36,10 +36,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
> EXPRESS OR IMPLIED.
>  ///
>  #define DEVICE_PATH_PROTOCOL  EFI_DEVICE_PATH_PROTOCOL_GUID
> 
>  #pragma pack(1)
> 
> +#if defined(_MSC_EXTENSIONS)
> +//
> +// Disable warning when last field of data structure is a zero sized array.
> +//
> +#pragma warning ( disable : 4200 )
> +#endif
> +
>  /**
>This protocol can be used on any device handle to obtain generic 
> path/location
>information concerning the physical device or logical device. If the 
> handle does
>not logically map to a physical device, the handle may not necessarily 
> support
>the device path protocol. The device path describes the location of the 
> device
> @@ -828,11 +835,11 @@ typedef struct {
>///
>UINT8   IsIPv6;
>///
>/// Instance of the DNS server address.
>///
> -  EFI_IP_ADDRESS  DnsServerIp[1024];
> +  EFI_IP_ADDRESS  DnsServerIp[];
>  } DNS_DEVICE_PATH;
> 
>  ///
>  /// Uniform Resource Identifiers (URI) Device Path SubType
>  ///
> @@ -840,11 +847,11 @@ typedef struct {
>  typedef struct {
>EFI_DEVICE_PATH_PROTOCOLHeader;
>///
>/// Instance of the URI pursuant to RFC 3986.
>///
> -  CHAR8   Uri[1024];
> +  CHAR8   Uri[];
>  } URI_DEVICE_PATH;
> 
>  ///
>  /// Universal Flash Storage (UFS) Device Path SubType.
>  ///
> --
> 2.6.1.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations.

2018-03-01 Thread Marvin Häuser

> -Original Message-
> From: Laszlo Ersek 
> Sent: Thursday, March 1, 2018 11:40 AM
> To: Marvin Häuser ; edk2-
> de...@lists.01.org
> Cc: michael.d.kin...@intel.com; liming@intel.com
> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
> operations.
> 
> On 02/28/18 22:07, Marvin Häuser wrote:
> > One comment is inline.
> >
> > Thank you in advance,
> > Marvin.
> >
> >> -Original Message-
> >> From: edk2-devel  On Behalf Of
> >> Marvin Häuser
> >> Sent: Wednesday, February 28, 2018 7:46 PM
> >> To: edk2-devel@lists.01.org; Laszlo Ersek 
> >> Cc: michael.d.kin...@intel.com; liming@intel.com
> >> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
> >> operations.
> >>
> >> I have just locally updated all BIT defines to use the ULL prefix and
> >> added casts to defines using them.
> >> I did that to ensure that 1) inversions always produce the correct
> >> value and 2) assignments never result in implicit casts to a smaller
> >> int, which would raise a warning.
> >>
> >> After I was done doing it for MdePkg, a build showed that (N)ASM
> >> files consumed these definitions.
> >>
> >> I only see a bunch of possible solutions to that:
> >> * Prohibit the usage of such defines in assembly code (which I would
> >> strongly dislike).
> >> * Introduce a "DEFINE_BIT" macro which produces one definition for C
> >> code and one for assembly.
> >
> > I only just realized that including C headers was not a NASM feature, but it
> is actually edk2 invoking the PP.
> > Might the best solution just be to introduce a casting macro, which casts
> when it's invoked for a C compiler and doesn't when it's invoked for an
> assembler?
> > Basically would require nothing else than adding a "-
> D__EDK2_ASSEMBLER__" or something alike to the PP flags when applicable.
> >
> > Any opinion on that?
> 
> Sigh, I don't know what to answer. On one hand (if we can get it to work
> without regressions) I like the idea of making all BITx macros ULL. On the
> other hand, defining the same macro with different replacement text,
> dependent on whether the including source code is assembly or C, looks
> dirty. I can't really put my finger on it, but I feel such dual definitions 
> could
> cause issues or confusion. If BaseTools people are OK with the dual
> definition, I guess I could live with it.

Indeed it is dirty, however I don't think there is any choice but the smallest 
devil.
Leaving them signed might become dangerous, relying on suffixes is not a proper 
solution considering the new 128-bit type and casting results in the sharing 
issue between C and NASM.
Actually I would abandon the "two definitions" concept as of the idea of 
introducing __EDK2_ASSEMBLER__.

The solution I think would be the best to ensure a safe and forward-compatible 
is:
1) Cast all generic defines that might be used as masks to the highest 
available integer type (macro), including BITx.
2) Introduce a casting macro which would roughly look like this and apply it to 
all "named bit" definitions:

#ifdef __EDK2_ASSEMLER__
  #define PP_CAST(Value, Type) (Value)
#else
  #define PP_CAST(Value, Type) ((Type)(Value))
#endif

This way:
* Bit operations on all types of unsigned integers are safe and well-defined.
* One can intuitively use inverses for both generic and "named" masks.
* One can continue to intuitively assign "named bits" to variables of their 
type (except for when integer promotion happens as part of an OP, of course, 
but this is unrelated).
* Code not casting correctly will raise compile-time errors.

The only alternative worth arguing I see is scrapping it all and introducing 
Unit Tests. However, should a Unit Test ever fail a specific compiler, we would 
be back here again.

Regards,
Marvin.

> 
> Thanks,
> Laszlo
> 
> >
> >> * Rely on 'ULL' always producing the biggest possible value
> >> (including the 128- bit range new to the spec) or documenting an
> >> exception for it, and insist on the caller casting (which I would find 
> >> quite
> ugly).
> >> * Scrap the patch and continue to rely on
> >> compiler-/architecture-specific behavior, which could cause issues
> seemingly randomly.
> >>
> >> Thanks,
> >> Marvin.
> >>
> >>> -Original Message-
> >>> From: edk2-devel  On Behalf Of
> >>> Marvin Häuser
> >>> Sent: Wednesday, February 28, 2018 3:21 PM
> >>> To: edk2-devel@lists.01.org; Laszlo Ersek 
> >>> Cc: michael.d.kin...@intel.com; liming@intel.com
> >>> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
> >>> operations.
> >>>
> >>> Hey Laszlo,
> >>>
> >>> I cut your rant because it is not strictly related to this patch.
> >>> However, thank you for composing it nevertheless because it was an
> >> interesting read!
> >>> Comments are inline.
> >>>
> >>> Michael, Liming,
> >>> Do you have any comments regarding 

Re: [edk2] [PATCH edk2-platforms v2 0/7] SynQuacer ACPI support

2018-03-01 Thread Ard Biesheuvel
On 1 March 2018 at 11:23, Graeme Gregory (Linaro)
 wrote:
> On Wed, Feb 28, 2018 at 07:24:14PM +, Ard Biesheuvel wrote:
>> This implements ACPI support for the SynQuacer platforms.
>>
>> Changes since v1:
>> - improve commit log (#1, #2)
>> - replace bare numbers with symbolic constants (#2)
>> - add Leif's R-b (#4)
>> - add patches #6 and #7
>>
>> Note that supporting ACPI on this SoC is non-trivial, due to the quirky
>> DesignWare RCs and the pre-ITS that sits between the PCIe RCs and the GICv3.
>> However, the most important issue has been addressed by modifying the static
>> SMMU mapping that sits between the CPUs and the PCIe config space, working
>> around the ghosting issue that occurs on these RCs, due the complete lack of
>> type 0 config TLP filtering by the [non-existent] root port. (This was tested
>> using the 20180226-LB1.1-ACPI-ramfw.bin SCP firmware image, which is not 
>> [yet]
>> installed by default on DeveloperBox hardware)
>>
>> That leaves the MSI issue, which is worked around by limiting MSI support to 
>> a
>> single RC. In the presented configuration, this is RC #1, which connects to 
>> the
>> x16 slot [and nothing else] on the DeveloperBox PCB. The onboard PCIe devices
>> (XHCI + SATA) work without problem using wired interrupts only, and so RC #0
>> has MSI support disabled. This means cards that require MSI support should
>> be inserted into the x16 slot, which is likely to be the preferred slot in
>> such cases anwyay (e.g., when using NVME or high end networking plugin cards)
>>
>> Patch #1 fixes a minor issue in the slot-to-BDF mapping.
>>
>> Patch #2 modifies the static PCIe window configuration so it can be described
>> using ACPI as well as DT.
>>
>> Patch #3 introduces the static ACPI tables that describe the fixed platform
>> devices and peripherals to the OS.
>>
>> Patch #4 adds a menu option to the platform driver to make ACPI vs DT user
>> selectable.
>>
>> Patch #5 adds support for describing the eMMC controller using a SSDT table
>> which is only installed if eMMC support is enabled.
>>
>> Patch #6 adds a _STA method implementation to the PCIe RC devices so that
>> they are only exposed to the OS when running on a platform that has one of
>> the several ECAM workarounds enabled. Otherwise, we can still boot via ACPI
>> using platform devices, but the PCIe RCs are unavailable.
>>
>> Patch #7 extends the _STA method for PCI0 to take the presence detect GPIO
>> into account. This is necessary because on the SynQuacer evaluation board,
>> any attempt to access the device registers will lock up the system if no
>> card is inserted into the slot.
>>
>> Note that driver support for the eMMC and network controller only landed in
>> v4.15, but when using a SATA driver and a plugin network card that does have
>> driver support, these patches should allow the SynQuacer based platforms to
>> boot stock Debian Stretch/Fedora/Centos etc installers.
>>
>
> The ACPI parts look good to me.
>
> Reviewed-by: Graeme Gregory 
>

Cheers.

I'll hold off on merging this until Heyi's PciHostBridgeDxe patches
are in (which are in pretty good shape now)
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH edk2-platforms v2 0/7] SynQuacer ACPI support

2018-03-01 Thread Graeme Gregory (Linaro)
On Wed, Feb 28, 2018 at 07:24:14PM +, Ard Biesheuvel wrote:
> This implements ACPI support for the SynQuacer platforms.
> 
> Changes since v1:
> - improve commit log (#1, #2)
> - replace bare numbers with symbolic constants (#2)
> - add Leif's R-b (#4)
> - add patches #6 and #7
> 
> Note that supporting ACPI on this SoC is non-trivial, due to the quirky
> DesignWare RCs and the pre-ITS that sits between the PCIe RCs and the GICv3.
> However, the most important issue has been addressed by modifying the static
> SMMU mapping that sits between the CPUs and the PCIe config space, working
> around the ghosting issue that occurs on these RCs, due the complete lack of
> type 0 config TLP filtering by the [non-existent] root port. (This was tested
> using the 20180226-LB1.1-ACPI-ramfw.bin SCP firmware image, which is not [yet]
> installed by default on DeveloperBox hardware)
> 
> That leaves the MSI issue, which is worked around by limiting MSI support to a
> single RC. In the presented configuration, this is RC #1, which connects to 
> the
> x16 slot [and nothing else] on the DeveloperBox PCB. The onboard PCIe devices
> (XHCI + SATA) work without problem using wired interrupts only, and so RC #0
> has MSI support disabled. This means cards that require MSI support should
> be inserted into the x16 slot, which is likely to be the preferred slot in
> such cases anwyay (e.g., when using NVME or high end networking plugin cards)
> 
> Patch #1 fixes a minor issue in the slot-to-BDF mapping.
> 
> Patch #2 modifies the static PCIe window configuration so it can be described
> using ACPI as well as DT.
> 
> Patch #3 introduces the static ACPI tables that describe the fixed platform
> devices and peripherals to the OS.
> 
> Patch #4 adds a menu option to the platform driver to make ACPI vs DT user
> selectable.
> 
> Patch #5 adds support for describing the eMMC controller using a SSDT table
> which is only installed if eMMC support is enabled.
> 
> Patch #6 adds a _STA method implementation to the PCIe RC devices so that
> they are only exposed to the OS when running on a platform that has one of
> the several ECAM workarounds enabled. Otherwise, we can still boot via ACPI
> using platform devices, but the PCIe RCs are unavailable.
> 
> Patch #7 extends the _STA method for PCI0 to take the presence detect GPIO
> into account. This is necessary because on the SynQuacer evaluation board,
> any attempt to access the device registers will lock up the system if no
> card is inserted into the slot.
> 
> Note that driver support for the eMMC and network controller only landed in
> v4.15, but when using a SATA driver and a plugin network card that does have
> driver support, these patches should allow the SynQuacer based platforms to
> boot stock Debian Stretch/Fedora/Centos etc installers.
> 

The ACPI parts look good to me.

Reviewed-by: Graeme Gregory 

> Ard Biesheuvel (7):
>   Platform/Socionext/DeveloperBox: fix PCIe slot to B/D/F mapping
>   Silicon/SynQuacer: tweak PCI I/O windows for ACPI/Linux support
>   Silicon/SynQuacer: add ACPI drivers and tables
>   Silicon/SynQuacer/PlatformDxe: add option to enable ACPI mode
>   Silicon/SynQuacer/PlatformDxe: add ACPI description of eMMC
>   Silicon/SynQuacer/AcpiTables: disable PCI RCs if ECAM ghosts are
> detected
>   Silicon/SynQuacer/AcpiTables: take presence detect of PCI0 into
> account
> 
>  Platform/Socionext/DeveloperBox/DeveloperBox.dsc 
> |   2 +
>  Platform/Socionext/DeveloperBox/DeveloperBox.fdf 
> |  14 +
>  Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc 
> |   2 +
>  Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.fdf 
> |  14 +
>  Silicon/Socionext/SynQuacer/Acpi.dsc.inc 
> |  48 +++
>  Silicon/Socionext/SynQuacer/AcpiTables/AcpiSsdtRootPci.asl   
> | 317 
>  Silicon/Socionext/SynQuacer/AcpiTables/AcpiTables.h  
> |  73 +
>  Silicon/Socionext/SynQuacer/AcpiTables/AcpiTables.inf
> |  65 
>  Silicon/Socionext/SynQuacer/AcpiTables/Dsdt.asl  
> | 187 
>  Silicon/Socionext/SynQuacer/AcpiTables/Fadt.aslc 
> |  91 ++
>  Silicon/Socionext/SynQuacer/AcpiTables/Gtdt.aslc 
> |  93 ++
>  Silicon/Socionext/SynQuacer/AcpiTables/Iort.aslc 
> | 101 +++
>  Silicon/Socionext/SynQuacer/AcpiTables/Madt.aslc 
> | 182 +++
>  

Re: [edk2] [PATCH] BaseTools: GlobalData.gConfDirectory is None when run GenFds

2018-03-01 Thread Zhu, Yonghong
Reviewed-by: Yonghong Zhu  

Best Regards,
Zhu Yonghong


-Original Message-
From: Feng, YunhuaX 
Sent: Thursday, March 01, 2018 10:23 AM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong ; Gao, Liming 
Subject: [PATCH] BaseTools: GlobalData.gConfDirectory is None when run GenFds

When run GenFds,  GlobalData.gConfDirectory is None, On Linux 
self._ToolChainFamily default Value is "MSFT", and then generate the wrong 
PcdValueInit Makefile

Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/GenFds/GenFds.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/GenFds/GenFds.py 
b/BaseTools/Source/Python/GenFds/GenFds.py
index dcba9f24cb..1c601d94b4 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -1,9 +1,9 @@
 ## @file
 # generate flash image
 #
-#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
+#  Copyright (c) 2007 - 2018, 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
@@ -162,10 +162,12 @@ def main():
 ConfDirectoryPath = os.path.normcase(os.environ["CONF_PATH"])
 else:
 # Get standard WORKSPACE/Conf, use the absolute path to the 
WORKSPACE/Conf
 ConfDirectoryPath = 
mws.join(GenFdsGlobalVariable.WorkSpaceDir, 'Conf')
 GenFdsGlobalVariable.ConfDir = ConfDirectoryPath
+if not GlobalData.gConfDirectory:
+GlobalData.gConfDirectory = GenFdsGlobalVariable.ConfDir
 BuildConfigurationFile = 
os.path.normpath(os.path.join(ConfDirectoryPath, "target.txt"))
 if os.path.isfile(BuildConfigurationFile) == True:
 TargetTxt = TargetTxtClassObject.TargetTxtClassObject()
 TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
 # if no build target given in command line, get it from target.txt
--
2.12.2.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] How to handle pflash backed OVMF FW upgrade and live migration best?

2018-03-01 Thread Thomas Lamprecht
Hi,

I'm currently evaluating how to update the firmware (OVMF) code image
without impacting a KVM/QEMU VM on live migration. I.e., the FW code lives
under /usr/share/OVMF/OVMF_CODE.fd and gets passed to the QEMU command with:

qemu-binary [...] -drive 
"if=pflash,unit=0,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd"

Now if the target node has an updated version of OVMF the VM does not really
likes that, as from its POV it gets effectively another code image loaded
from one moment at the other without any notice.

So my questions is if it would make sense to see this read-only pflash
content as "VM state" and send it over during live migration? This would
make migration way easier. Else we need to save all FW files and track which
one the VM is using, so that when starting the migration target VM we pass
along the correct pflash drive file. Sending over a pflash drive could maybe
only get done when a special flag is set for the pflash drive?

As said I can work around in our management stack, but saving the FW image
and tracking which VM uses what version, and that cluster wide, may get
quite a headache and we would need to keep all older OVMF binaries around...

If I'm missing something and there's already an easy way for this I'd be
very happy to hear from it.

Besides qemu-discuss I posted it to edk2-devel as there maybe more people
are in the QEMU and OVMF user intersection. :)

cheers,
Thomas


___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] BaseTools: Fix eval parse string issue

2018-03-01 Thread Zhu, Yonghong
Reviewed-by: Yonghong Zhu  

Best Regards,
Zhu Yonghong


-Original Message-
From: Feng, YunhuaX 
Sent: Thursday, March 01, 2018 10:16 AM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong ; Gao, Liming 
Subject: [PATCH] BaseTools: Fix eval parse string issue

eval argument start with " or ', but it is unicode string, will encounter error:
List = list(eval(Value)) # translate escape character
  File "", line 1
'jà=îµ¢Ã"Fà
 ^
SyntaxError: EOL while scanning string literal

Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1

Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/Common/Misc.py | 30 ++
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Misc.py 
b/BaseTools/Source/Python/Common/Misc.py
index a7e7797d04..af374d804d 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1552,37 +1552,59 @@ def ParseFieldValue (Value):
 raise BadExpression('%s' % Message)
 Value, Size = ParseFieldValue(Value)
 return Value, 16
 if Value.startswith('L"') and Value.endswith('"'):
 # Unicode String
-List = list(eval(Value[1:]))  # translate escape character
+# translate escape character
+Value = Value[1:]
+try:
+Value = eval(Value)
+except:
+Value = Value[1:-1]
+List = list(Value)
 List.reverse()
 Value = 0
 for Char in List:
 Value = (Value << 16) | ord(Char)
 return Value, (len(List) + 1) * 2
 if Value.startswith('"') and Value.endswith('"'):
 # ASCII String
-List = list(eval(Value))  # translate escape character
+# translate escape character
+try:
+Value = eval(Value)
+except:
+Value = Value[1:-1]
+List = list(Value)
 List.reverse()
 Value = 0
 for Char in List:
 Value = (Value << 8) | ord(Char)
 return Value, len(List) + 1
 if Value.startswith("L'") and Value.endswith("'"):
 # Unicode Character Constant
-List = list(eval(Value[1:])) # translate escape character
+# translate escape character
+Value = Value[1:]
+try:
+Value = eval(Value)
+except:
+Value = Value[1:-1]
+List = list(Value)
 if len(List) == 0:
 raise BadExpression('Length %s is %s' % (Value, len(List)))
 List.reverse()
 Value = 0
 for Char in List:
 Value = (Value << 16) | ord(Char)
 return Value, len(List) * 2
 if Value.startswith("'") and Value.endswith("'"):
 # Character constant
-List = list(eval(Value)) # translate escape character
+# translate escape character
+try:
+Value = eval(Value)
+except:
+Value = Value[1:-1]
+List = list(Value)
 if len(List) == 0:
 raise BadExpression('Length %s is %s' % (Value, len(List)))
 List.reverse()
 Value = 0
 for Char in List:
--
2.12.2.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations.

2018-03-01 Thread Marvin Häuser

> -Original Message-
> From: Kinney, Michael D 
> Sent: Thursday, March 1, 2018 2:42 AM
> To: Marvin Häuser ; edk2-
> de...@lists.01.org; Kinney, Michael D 
> Cc: ler...@redhat.com; Gao, Liming 
> Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
> operations.
> 
> Hi Marvin,
> 
> Yes.  I have been reading the thread.
> 
> Lots of really good analysis.
> 
> However, it does not make sense to me to add 'u' to the smaller BITxx,
> BASExx, and SIZExx macros if we have constants in other places that do not
> add the 'u'. I think this patch may increase the inconsistency of the whole
> tree.

Basically applying this to the BIT definitions first was to see whether the 
concept is percepted as a whole.
Of course this should be applied to all definitions that are at some point used 
as a mask, which I continued to do locally.

> 
> If we don’t make this change, what types of issues do we need to fix and
> what would the fix entail?

To be honest, actual issues are very unlikely to happen as all architectures 
supported by the specification use two-complements for negative values.
Furthermore, all currently supported compilers implement bitwise operations for 
signed integers seemingly the same way as for unsigned types.
However, if either will change in the future, code will silently break as in 
many mask operations will return values not intended by the code.

If you are not interested in the solution concepts previously discussed, I 
propose as least a Unit Test to verify the operations used in praxis work out 
fine.

Thanks,
Marvin.

> 
> Mike
> 
> > -Original Message-
> > From: Marvin Häuser [mailto:marvin.haeu...@outlook.com]
> > Sent: Wednesday, February 28, 2018 10:52 AM
> > To: edk2-devel@lists.01.org; Kinney, Michael D
> > 
> > Cc: ler...@redhat.com; Gao, Liming
> > 
> > Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
> > operations.
> >
> > Hey Mike,
> >
> > You are right, the patch was premature because I did not consider any
> > 'incorrect' or 'clever' usages of these definitions.
> > The problem is not primarily undefined behavior, but
> > implementation-defined behavior.
> > Any bitwise operation to a signed integer results in
> > implementation-defined behavior, which compilers usually do not warn
> > about, while well-defined behavior is desirable.
> >
> > Have you read Laszlo's comments? They are quite good at showing up
> > what logics might be and are relied on, which however are not
> > guaranteed to be the case for
> > non-x86 architectures,
> > or even for x86 in case a development team decides to change this
> > behavior some day or a new toolchain not having adopted them in the
> > first place should be added.
> >
> > Furthermore, I don't think inconsistency between the definitions
> > generally is desirable.
> >
> > Thanks,
> > Marvin.
> >
> > > -Original Message-
> > > From: Kinney, Michael D 
> > > Sent: Wednesday, February 28, 2018 7:37 PM
> > > To: Marvin Häuser ; edk2-
> > > de...@lists.01.org; Laszlo Ersek ;
> > Kinney, Michael D
> > > 
> > > Cc: Gao, Liming 
> > > Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure
> > safe bitwise
> > > operations.
> > >
> > > Hi Marvin,
> > >
> > > I do not think add 'u' to the BITxx defines does not
> > seem to be a complete
> > > solution.  Code can use integer constants in lots of
> > places including other
> > > #defines or inline in expressions.
> > >
> > > If we follow your suggestion wouldn’t we need to add
> > 'u' to every constant
> > > that does not start with a '-'
> > > and might potentially be used with a bit operation?
> > >
> > > Compilers are doing a good job of finding undefined
> > behavior.  Isn’t that
> > > sufficient to fix the issues identified?
> > >
> > > Mike
> > >
> > > > -Original Message-
> > > > From: Marvin Häuser
> > [mailto:marvin.haeu...@outlook.com]
> > > > Sent: Wednesday, February 28, 2018 6:21 AM
> > > > To: edk2-devel@lists.01.org; Laszlo Ersek
> > 
> > > > Cc: Kinney, Michael D ;
> > Gao, Liming
> > > > 
> > > > Subject: RE: [edk2] [PATCH 1/2] MdePkg/Base.h:
> > Ensure safe bitwise
> > > > operations.
> > > >
> > > > Hey Laszlo,
> > > >
> > > > I cut your rant because it is not strictly related
> > to this patch.
> > > > However, thank you for composing it nevertheless
> > because it was an
> > > > interesting read!
> > > > Comments are inline.
> > > >
> > > > Michael, Liming,
> > > > Do you have any comments regarding the discussion?
> > > > Thanks in advance.
> > > >
> > > > Best regards,
> > > > Marvin.
> > > >
> > > > > -Original Message-
> > > > > From: Laszlo Ersek 

Re: [edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the poll function.

2018-03-01 Thread Fu, Siyuan
Hi, Jiaxin

Do you mean the code which calls MTFTP4->Poll() at TPL_CALLBACK will cause 
system hang? This should not happen because all network protocol should be able 
to run at TPL_CALLBACK.

BestRegards
Fu Siyuan


> -Original Message-
> From: Wu, Jiaxin
> Sent: Thursday, March 1, 2018 5:38 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Fan ; Fu, Siyuan ; Ye,
> Ting 
> Subject: [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the poll
> function.
> 
> This patch is to fix the hang issue, which was enrolled by the commit of
> 39b0867d.
> The TPL should be restored before calling poll function at TPL_CALLBACK.
> 
> Cc: Wang Fan 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiaxin Wu 
> ---
>  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> index f5f9e6d8f7..64e0463dd9 100644
> --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
> @@ -507,24 +507,27 @@ Mtftp4Start (
>if (EFI_ERROR (Status)) {
>  Status = EFI_DEVICE_ERROR;
>  goto ON_ERROR;
>}
> 
> +  //
> +  // Restore the TPL now, don't call poll function at TPL_CALLBACK.
> +  //
> +  gBS->RestoreTPL (OldTpl);
> +
>if (Token->Event != NULL) {
> -gBS->RestoreTPL (OldTpl);
>  return EFI_SUCCESS;
>}
> 
>//
>// Return immediately for asynchronous operation or poll the
>// instance for synchronous operation.
>//
>while (Token->Status == EFI_NOT_READY) {
>  This->Poll (This);
>}
> -
> -  gBS->RestoreTPL (OldTpl);
> +
>return Token->Status;
> 
>  ON_ERROR:
>Mtftp4CleanOperation (Instance, Status);
>gBS->RestoreTPL (OldTpl);
> --
> 2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [Patch] NetworkPkg/Udp6Dxe: Fix the failure to leave one multicast group address.

2018-03-01 Thread Fu, Siyuan


Reviewed-by: Fu Siyuan 



> -Original Message-
> From: Wu, Jiaxin
> Sent: Thursday, March 1, 2018 5:38 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Fan ; Fu, Siyuan ; Ye,
> Ting 
> Subject: [Patch] NetworkPkg/Udp6Dxe: Fix the failure to leave one
> multicast group address.
> 
> The issue was enrolled by the commit of ceec3638. One of the change in the
> commit
> was to return the status from NetMapIterate in Udp6Groups function. But it
> should
> not return EFI_ABORTED directly in case McastIp is not NULL, which means
> to terminate
> the iteration and leave the McastIp successfully.
> 
> Cc: Wang Fan 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiaxin Wu 
> ---
>  NetworkPkg/Udp6Dxe/Udp6Main.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/NetworkPkg/Udp6Dxe/Udp6Main.c b/NetworkPkg/Udp6Dxe/Udp6Main.c
> index 1d7f0acbc7..e9d94dd00c 100644
> --- a/NetworkPkg/Udp6Dxe/Udp6Main.c
> +++ b/NetworkPkg/Udp6Dxe/Udp6Main.c
> @@ -380,10 +380,13 @@ Udp6Groups (
> 
>  Status = NetMapInsertTail (>McastIps, (VOID *) McastIp,
> NULL);
>} else {
> 
>  Status = NetMapIterate (>McastIps, Udp6LeaveGroup,
> MulticastAddress);
> +if ((MulticastAddress != NULL) && (Status == EFI_ABORTED)) {
> +  Status = EFI_SUCCESS;
> +}
>}
> 
>  ON_EXIT:
> 
>gBS->RestoreTPL (OldTpl);
> --
> 2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 2/6] OvmfPkg/PciHostBridgeLib: Init PCI aperture to 0

2018-03-01 Thread Guo Heyi
On Thu, Mar 01, 2018 at 11:17:30AM +0100, Laszlo Ersek wrote:
> Hello Heyi,
> 
> On 03/01/18 07:57, Heyi Guo wrote:
> > Use ZeroMem to initialize all fields in temporary
> > PCI_ROOT_BRIDGE_APERTURE variables to zero. This is not mandatory but
> > is helpful for future extension: when we add new fields to
> > PCI_ROOT_BRIDGE_APERTURE and the default value of these fields can
> > safely be zero, this code will not suffer from an additional
> > change.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Heyi Guo 
> >
> > Cc: Jordan Justen 
> > Cc: Anthony Perard 
> > Cc: Julien Grall 
> > Cc: Ruiyu Ni 
> > Cc: Laszlo Ersek 
> > Cc: Ard Biesheuvel 
> > ---
> >  OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 
> >  OvmfPkg/Library/PciHostBridgeLib/XenSupport.c   | 5 +
> >  2 files changed, 9 insertions(+)
> >
> > diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c 
> > b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> > index ff837035caff..4a650a4c6df9 100644
> > --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> > +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> > @@ -217,6 +217,10 @@ PciHostBridgeGetRootBridges (
> >PCI_ROOT_BRIDGE_APERTURE Mem;
> >PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
> >
> > +  ZeroMem (, sizeof (Io));
> > +  ZeroMem (, sizeof (Mem));
> > +  ZeroMem (, sizeof (MemAbove4G));
> > +
> >if (PcdGetBool (PcdPciDisableBusEnumeration)) {
> >  return ScanForRootBridges (Count);
> >}
> 
> This is OK. (Although for a trivial perf improvement, you could move the
> ZeroMem() calls after the PcdGetBool() / return. Not necessary, up to
> you.)
> 
> However:
> 
> > diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c 
> > b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> > index 31c63ae19e0a..aaf101dfcb0e 100644
> > --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> > +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> > @@ -193,6 +193,11 @@ ScanForRootBridges (
> >
> >*NumberOfRootBridges = 0;
> >RootBridges = NULL;
> > +  ZeroMem (, sizeof (Io));
> > +  ZeroMem (, sizeof (Mem));
> > +  ZeroMem (, sizeof (MemAbove4G));
> > +  ZeroMem (, sizeof (PMem));
> > +  ZeroMem (, sizeof (PMemAbove4G));
> >
> >//
> >// After scanning all the PCI devices on the PCI root bridge's primary 
> > bus,
> >
> 
> these ZeroMem() calls are not in the correct place. Please move them
> into the "PrimaryBus" loop just underneath. That loop works like this:
> 
> For each primary bus:
> 
>   (1) set all of the aperture variables to "nonexistent":
> 
> Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = 
> MAX_UINT64;
> Io.Limit = Mem.Limit = MemAbove4G.Limit = PMem.Limit = PMemAbove4G.Limit 
> = 0;
> 
>   (2) accumulate the BARs of the devices on the bus into the aperture
>   variables
> 
>   (3) call InitRootBridge() with the aperture variables
> 
> 
> That is, the ZeroMem() calls that you are adding have to be part of step
> (1). So, please replace the assignments
> 
> Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = 
> MAX_UINT64;
> Io.Limit = Mem.Limit = MemAbove4G.Limit = PMem.Limit = PMemAbove4G.Limit 
> = 0;
> 
> with
> 
> ZeroMem (, sizeof (Io));
> ZeroMem (, sizeof (Mem));
> ZeroMem (, sizeof (MemAbove4G));
> ZeroMem (, sizeof (PMem));
> ZeroMem (, sizeof (PMemAbove4G));
> Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = 
> MAX_UINT64;

Will it cause functional issue?

My idea of making the change is like this:

1. ZeroMem() is used to initialize all fields of APERTURE to 0; it can make it
   in the current place of the patch;

2. In the loop, some fields may be changed by the end of each iteration, and it
   is the responsibility of the existing code to re-initialize the changed 
fields
   to expected values explicitly. It seems not necessary to re-initialize the 
other
   fields which will not be changed.

However, your advice may be better that merges the initialization code together.
I can make the change in the next version of patch.

Thanks,
Heyi

> 
> Thanks!
> Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations.

2018-03-01 Thread Laszlo Ersek
On 02/28/18 22:07, Marvin Häuser wrote:
> One comment is inline.
> 
> Thank you in advance,
> Marvin.
> 
>> -Original Message-
>> From: edk2-devel  On Behalf Of Marvin
>> Häuser
>> Sent: Wednesday, February 28, 2018 7:46 PM
>> To: edk2-devel@lists.01.org; Laszlo Ersek 
>> Cc: michael.d.kin...@intel.com; liming@intel.com
>> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
>> operations.
>>
>> I have just locally updated all BIT defines to use the ULL prefix and added
>> casts to defines using them.
>> I did that to ensure that 1) inversions always produce the correct value and 
>> 2)
>> assignments never result in implicit casts to a smaller int, which would 
>> raise a
>> warning.
>>
>> After I was done doing it for MdePkg, a build showed that (N)ASM files
>> consumed these definitions.
>>
>> I only see a bunch of possible solutions to that:
>> * Prohibit the usage of such defines in assembly code (which I would strongly
>> dislike).
>> * Introduce a "DEFINE_BIT" macro which produces one definition for C code
>> and one for assembly.
> 
> I only just realized that including C headers was not a NASM feature, but it 
> is actually edk2 invoking the PP.
> Might the best solution just be to introduce a casting macro, which casts 
> when it's invoked for a C compiler and doesn't when it's invoked for an 
> assembler?
> Basically would require nothing else than adding a "-D__EDK2_ASSEMBLER__" or 
> something alike to the PP flags when applicable.
> 
> Any opinion on that?

Sigh, I don't know what to answer. On one hand (if we can get it to work
without regressions) I like the idea of making all BITx macros ULL. On
the other hand, defining the same macro with different replacement text,
dependent on whether the including source code is assembly or C, looks
dirty. I can't really put my finger on it, but I feel such dual
definitions could cause issues or confusion. If BaseTools people are OK
with the dual definition, I guess I could live with it.

Thanks,
Laszlo

> 
>> * Rely on 'ULL' always producing the biggest possible value (including the 
>> 128-
>> bit range new to the spec) or documenting an exception for it, and insist on
>> the caller casting (which I would find quite ugly).
>> * Scrap the patch and continue to rely on compiler-/architecture-specific
>> behavior, which could cause issues seemingly randomly.
>>
>> Thanks,
>> Marvin.
>>
>>> -Original Message-
>>> From: edk2-devel  On Behalf Of Marvin
>>> Häuser
>>> Sent: Wednesday, February 28, 2018 3:21 PM
>>> To: edk2-devel@lists.01.org; Laszlo Ersek 
>>> Cc: michael.d.kin...@intel.com; liming@intel.com
>>> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
>>> operations.
>>>
>>> Hey Laszlo,
>>>
>>> I cut your rant because it is not strictly related to this patch.
>>> However, thank you for composing it nevertheless because it was an
>> interesting read!
>>> Comments are inline.
>>>
>>> Michael, Liming,
>>> Do you have any comments regarding the discussion? Thanks in advance.
>>>
>>> Best regards,
>>> Marvin.
>>>
 -Original Message-
 From: Laszlo Ersek 
 Sent: Wednesday, February 28, 2018 2:57 PM
 To: Marvin Häuser ; edk2-
 de...@lists.01.org
 Cc: michael.d.kin...@intel.com; liming@intel.com
 Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise
 operations.

 On 02/28/18 12:43, Marvin Häuser wrote:
>>> [...]
> as edk2 does not support vendor extensions such as __int128 anyway.

 Not *yet*, I guess :) UEFI 2.7 does list UINT128 / INT128, in table
 5, "Common UEFI Data Types". I believe those typedefs may have been
>>> added for RISC-V.
>>>
>>> Oh yikes, I have not noticed that before. Besides that I wonder how
>>> that will be implemented by edk2 for non-RISC-V platforms, maybe that
>>> should be considered?
>>> As ridiculous as it sounds, maybe some kind of UINT_MAX type (now
>>> UINT64, later UINT128) should be introduced and any BIT or bitmask
>>> definition being explicitly casted to that?
>>> Are BIT definitions or masks occasionally used in preprocessor operations?
>>> That might break after all.
>>> Anyway, if that idea would be approved, there really would have to be
>>> a note regarding this design in some of the EDK2 specifications,
>>> probably C Code Style.
>>>
>>> [...]

> -1) The 'truncating constant value' warning would probably need to
> be disabled globally, however I don't understand how an explicit
> cast is a problem anyway.
>
> Did I overlook anything contra regarding that?

 Hmmm... Do you think it could have a performance impact on 32-bit
 platforms? (I don't think so, at least not in optimized / RELEASE
 builds.)
>>>
>>> I don't think any proper optimizer would not optimize this. After all,
>>> it can not 

Re: [edk2] [PATCH v5 2/6] OvmfPkg/PciHostBridgeLib: Init PCI aperture to 0

2018-03-01 Thread Guo Heyi
Thanks; I got some trouble in making the subject short and clear :)

Regards,
Heyi

On Thu, Mar 01, 2018 at 11:20:22AM +0100, Laszlo Ersek wrote:
> On 03/01/18 07:57, Heyi Guo wrote:
> > Use ZeroMem to initialize all fields in temporary
> > PCI_ROOT_BRIDGE_APERTURE variables to zero. This is not mandatory but
> > is helpful for future extension: when we add new fields to
> > PCI_ROOT_BRIDGE_APERTURE and the default value of these fields can
> > safely be zero, this code will not suffer from an additional
> > change.
> > 
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Heyi Guo 
> > 
> > Cc: Jordan Justen 
> > Cc: Anthony Perard 
> > Cc: Julien Grall 
> > Cc: Ruiyu Ni 
> > Cc: Laszlo Ersek 
> > Cc: Ard Biesheuvel 
> > ---
> >  OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 
> >  OvmfPkg/Library/PciHostBridgeLib/XenSupport.c   | 5 +
> >  2 files changed, 9 insertions(+)
> 
> I also suggest a different subject line:
> 
> OvmfPkg/PciHostBridgeLib: clear PCI_ROOT_BRIDGE_APERTURE vars for (re)init
> 
> (74 chars)
> 
> Thanks
> Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch] BaseTools: Fixed build failed issue.

2018-03-01 Thread BobCF
Case 1. A Pcd has no default sku setting in DSC.
Case 2. Build as Single SKU.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng 
Cc: Liming Gao 
---
 BaseTools/Source/Python/Workspace/DscBuildData.py | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py 
b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 06d2f2fbcd..9dcdcfcf1c 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1304,14 +1304,14 @@ class DscBuildData(PlatformBuildClassObject):
 if str_pcd_dec:
 str_pcd_obj_str = StructurePcd()
 str_pcd_obj_str.copy(str_pcd_dec)
 if str_pcd_obj:
 str_pcd_obj_str.copy(str_pcd_obj)
-if str_pcd_obj.Type in 
[self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], 
self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
-str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: 
str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, 
str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in 
DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
-else:
-str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: 
str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, 
str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in 
DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
+if str_pcd_obj.Type in 
[self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], 
self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
+str_pcd_obj_str.DefaultFromDSC = 
{skuname:{defaultstore: 
str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, 
str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in 
DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
+else:
+str_pcd_obj_str.DefaultFromDSC = 
{skuname:{defaultstore: 
str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, 
str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in 
DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
 for str_pcd_data in StrPcdSet[str_pcd]:
 if str_pcd_data[3] in SkuIds:
 str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], 
str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else 
str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], 
self.MetaFile.File if self.WorkspaceDir not in self.MetaFile.File else 
self.MetaFile.File[len(self.WorkspaceDir) if 
self.WorkspaceDir.endswith(os.path.sep) else 
len(self.WorkspaceDir)+1:],LineNo=str_pcd_data[5])
 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
 else:
@@ -1729,10 +1729,13 @@ class DscBuildData(PlatformBuildClassObject):
 CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % ('DEFAULT', 
'STANDARD')
 inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]
 if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD'):
 pcddefaultvalue = 
Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if 
Pcd.DefaultFromDSC else Pcd.DefaultValue
 else:
+if not Pcd.DscRawValue:
+# handle the case that structure pcd is not appear in DSC
+self.CopyDscRawValue(Pcd)
 pcddefaultvalue = 
Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName)
 for FieldList in 
[pcddefaultvalue,inherit_OverrideValues.get(DefaultStoreName)]:
 if not FieldList:
 continue
 if pcddefaultvalue and FieldList == pcddefaultvalue:
@@ -1925,12 +1928,12 @@ class DscBuildData(PlatformBuildClassObject):
 CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s 
\n" % (skuname, defaultstorenameitem)
 CApp = CApp + 
self.GenerateInitValueStatement(Pcd,skuname,defaultstorenameitem)
 if skuname == SkuName:
 break
 else:
-CApp = CApp + "// SkuName: DEFAULT,  DefaultStoreName: 
STANDARD \n"
-CApp = CApp + 
self.GenerateInitValueStatement(Pcd,"DEFAULT","STANDARD")
+CApp = CApp + "// SkuName: %s,  DefaultStoreName: STANDARD \n" 
% self.SkuIdMgr.SystemSkuId
+CApp = CApp + 
self.GenerateInitValueStatement(Pcd,self.SkuIdMgr.SystemSkuId,"STANDARD")
 CApp = CApp + self.GenerateCommandLineValueStatement(Pcd)
 #
 # Set new PCD value and size
 #
 CApp = CApp + '  PcdSetPtr (%s, %s, %s, %s, Size, (UINT8 
*)Pcd);\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, 
Pcd.TokenCName)
@@ -2292,10 +2295,14 @@ class 

[edk2] [Patch] BaseTools: Fixed Pcd value override issue.

2018-03-01 Thread BobCF
The Pcd value override in commandline.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng 
Cc: Liming Gao 
---
 .../Source/Python/Workspace/BuildClassObject.py|   4 +
 BaseTools/Source/Python/Workspace/DscBuildData.py  | 136 ++---
 BaseTools/Source/Python/build/build.py |   2 +-
 3 files changed, 121 insertions(+), 21 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py 
b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index edf2bdf4b9..711ba492ef 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -127,10 +127,12 @@ class StructurePcd(PcdClassObject):
 self.StructName = None
 self.PcdDefineLineNo = 0
 self.PkgPath = ""
 self.DefaultValueFromDec = ""
 self.ValueChain = dict()
+self.PcdValueFromComm = ""
+self.PcdFieldValueFromComm = collections.OrderedDict({})
 def __repr__(self):
 return self.TypeName
 
 def AddDefaultValue (self, FieldName, Value, FileName="", LineNo=0):
 if FieldName in self.DefaultValues:
@@ -186,10 +188,12 @@ class StructurePcd(PcdClassObject):
 self.FlexibleFieldName = PcdObject.FlexibleFieldName if 
PcdObject.FlexibleFieldName else self.FlexibleFieldName
 self.StructName = PcdObject.DatumType if PcdObject.DatumType else 
self.StructName
 self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if 
PcdObject.PcdDefineLineNo else self.PcdDefineLineNo
 self.PkgPath = PcdObject.PkgPath if PcdObject.PkgPath else 
self.PkgPath
 self.ValueChain = PcdObject.ValueChain if PcdObject.ValueChain 
else self.ValueChain
+self.PcdValueFromComm = PcdObject.PcdValueFromComm if 
PcdObject.PcdValueFromComm else self.PcdValueFromComm
+self.PcdFieldValueFromComm = PcdObject.PcdFieldValueFromComm if 
PcdObject.PcdFieldValueFromComm else self.PcdFieldValueFromComm
 
 ## LibraryClassObject
 #
 # This Class defines LibraryClassObject used in BuildDatabase
 #
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py 
b/BaseTools/Source/Python/Workspace/DscBuildData.py
index a5089a900b..06d2f2fbcd 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1131,14 +1131,15 @@ class DscBuildData(PlatformBuildClassObject):
 
self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT))
 self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII))
 self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))
 
 self._Pcds = self.CompletePcdValues(self._Pcds)
+self._Pcds = self.OverrideByFdfCommOverAll(self._Pcds)
 self._Pcds = self.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST, 
self._Pcds)
 self._Pcds = self.CompleteHiiPcdsDefaultStores(self._Pcds)
 self._Pcds = self._FilterPcdBySkuUsage(self._Pcds)
-self._Pcds = self.OverrideByFdfCommOverAll(self._Pcds)
+
 self.RecoverCommandLinePcd()
 return self._Pcds
 
 def _dumpPcdInfo(self,Pcds):
 for pcd in Pcds:
@@ -1201,24 +1202,28 @@ class DscBuildData(PlatformBuildClassObject):
 structure_pcd_data[(item[0],item[1])] = []
 structure_pcd_data[(item[0],item[1])].append(item)
 
 return structure_pcd_data
 def OverrideByFdfComm(self,StruPcds):
-StructurePcdInCom = {(item[0],item[1],item[2] ):(item[3],item[4]) for 
item in GlobalData.BuildOptionPcd if len(item) == 5 and (item[1],item[0]) in 
StruPcds } if GlobalData.BuildOptionPcd else {}
+StructurePcdInCom = OrderedDict()
+for item in GlobalData.BuildOptionPcd:
+if len(item) == 5 and (item[1],item[0]) in StruPcds:
+StructurePcdInCom[(item[0],item[1],item[2] )] = 
(item[3],item[4])
 GlobalPcds = set([(item[0],item[1]) for item in 
StructurePcdInCom.keys()])
 for Pcd in StruPcds.values():
 if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) not in GlobalPcds:
 continue
-FieldValues = {item[2]:StructurePcdInCom[item] for item in 
StructurePcdInCom if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) == 
(item[0],item[1]) and item[2]}
-for sku in Pcd.SkuOverrideValues:
-for defaultstore in Pcd.SkuOverrideValues[sku]:
-for field in FieldValues:
-if field not in 
Pcd.SkuOverrideValues[sku][defaultstore]:
-Pcd.SkuOverrideValues[sku][defaultstore][field] = 
["","",""]
-Pcd.SkuOverrideValues[sku][defaultstore][field][0] = 
FieldValues[field][0]
-Pcd.SkuOverrideValues[sku][defaultstore][field][1] = 
FieldValues[field][1][0]
-

Re: [edk2] [PATCH v5 2/6] OvmfPkg/PciHostBridgeLib: Init PCI aperture to 0

2018-03-01 Thread Laszlo Ersek
On 03/01/18 07:57, Heyi Guo wrote:
> Use ZeroMem to initialize all fields in temporary
> PCI_ROOT_BRIDGE_APERTURE variables to zero. This is not mandatory but
> is helpful for future extension: when we add new fields to
> PCI_ROOT_BRIDGE_APERTURE and the default value of these fields can
> safely be zero, this code will not suffer from an additional
> change.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Heyi Guo 
> 
> Cc: Jordan Justen 
> Cc: Anthony Perard 
> Cc: Julien Grall 
> Cc: Ruiyu Ni 
> Cc: Laszlo Ersek 
> Cc: Ard Biesheuvel 
> ---
>  OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 
>  OvmfPkg/Library/PciHostBridgeLib/XenSupport.c   | 5 +
>  2 files changed, 9 insertions(+)

I also suggest a different subject line:

OvmfPkg/PciHostBridgeLib: clear PCI_ROOT_BRIDGE_APERTURE vars for (re)init

(74 chars)

Thanks
Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 2/6] OvmfPkg/PciHostBridgeLib: Init PCI aperture to 0

2018-03-01 Thread Laszlo Ersek
Hello Heyi,

On 03/01/18 07:57, Heyi Guo wrote:
> Use ZeroMem to initialize all fields in temporary
> PCI_ROOT_BRIDGE_APERTURE variables to zero. This is not mandatory but
> is helpful for future extension: when we add new fields to
> PCI_ROOT_BRIDGE_APERTURE and the default value of these fields can
> safely be zero, this code will not suffer from an additional
> change.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Heyi Guo 
>
> Cc: Jordan Justen 
> Cc: Anthony Perard 
> Cc: Julien Grall 
> Cc: Ruiyu Ni 
> Cc: Laszlo Ersek 
> Cc: Ard Biesheuvel 
> ---
>  OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 
>  OvmfPkg/Library/PciHostBridgeLib/XenSupport.c   | 5 +
>  2 files changed, 9 insertions(+)
>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c 
> b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index ff837035caff..4a650a4c6df9 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -217,6 +217,10 @@ PciHostBridgeGetRootBridges (
>PCI_ROOT_BRIDGE_APERTURE Mem;
>PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
>
> +  ZeroMem (, sizeof (Io));
> +  ZeroMem (, sizeof (Mem));
> +  ZeroMem (, sizeof (MemAbove4G));
> +
>if (PcdGetBool (PcdPciDisableBusEnumeration)) {
>  return ScanForRootBridges (Count);
>}

This is OK. (Although for a trivial perf improvement, you could move the
ZeroMem() calls after the PcdGetBool() / return. Not necessary, up to
you.)

However:

> diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c 
> b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> index 31c63ae19e0a..aaf101dfcb0e 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> @@ -193,6 +193,11 @@ ScanForRootBridges (
>
>*NumberOfRootBridges = 0;
>RootBridges = NULL;
> +  ZeroMem (, sizeof (Io));
> +  ZeroMem (, sizeof (Mem));
> +  ZeroMem (, sizeof (MemAbove4G));
> +  ZeroMem (, sizeof (PMem));
> +  ZeroMem (, sizeof (PMemAbove4G));
>
>//
>// After scanning all the PCI devices on the PCI root bridge's primary bus,
>

these ZeroMem() calls are not in the correct place. Please move them
into the "PrimaryBus" loop just underneath. That loop works like this:

For each primary bus:

  (1) set all of the aperture variables to "nonexistent":

Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = 
MAX_UINT64;
Io.Limit = Mem.Limit = MemAbove4G.Limit = PMem.Limit = PMemAbove4G.Limit = 
0;

  (2) accumulate the BARs of the devices on the bus into the aperture
  variables

  (3) call InitRootBridge() with the aperture variables


That is, the ZeroMem() calls that you are adding have to be part of step
(1). So, please replace the assignments

Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = 
MAX_UINT64;
Io.Limit = Mem.Limit = MemAbove4G.Limit = PMem.Limit = PMemAbove4G.Limit = 
0;

with

ZeroMem (, sizeof (Io));
ZeroMem (, sizeof (Mem));
ZeroMem (, sizeof (MemAbove4G));
ZeroMem (, sizeof (PMem));
ZeroMem (, sizeof (PMemAbove4G));
Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = 
MAX_UINT64;

Thanks!
Laszlo
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] ShellPkg/UefiShellDebug1CommandsLib: remove I/O address limit from 'mm'

2018-03-01 Thread Ard Biesheuvel
Neither the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL nor the EFI_CPU_IO2_PROTOCOL
impose any restrictions when it comes to the range of valid I/O
addresses. Even so, the 'mm' command in -IO mode refuses to perform
accesses to addresses >= 0x.

It is not up to 'mm' to impose this restriction, so remove it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c   | 
11 ---
 ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni |  
2 --
 2 files changed, 13 deletions(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c 
b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
index 9f97f1d345f7..d1fd42b1cd4d 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
@@ -525,12 +525,6 @@ ShellCommandRunMm (
   goto Done;
 }
 
-if ((AccessType == ShellMmIo) && (Address + Size > MAX_UINT16 + 1)) {
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MM_IO_ADDRESS_RANGE), 
gShellDebug1HiiHandle, L"mm");
-  ShellStatus = SHELL_INVALID_PARAMETER;
-  goto Done;
-}
-
 //
 // locate IO protocol interface
 //
@@ -592,11 +586,6 @@ ShellCommandRunMm (
 //
 Complete = FALSE;
 do {
-  if ((AccessType == ShellMmIo) && (Address + Size > MAX_UINT16 + 1)) {
-ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE2), 
gShellDebug1HiiHandle, L"mm");
-break;
-  }
-
   ShellMmAccess (AccessType, PciRootBridgeIo, CpuIo, TRUE, Address, Size, 
);
   ShellPrintHiiEx (-1, -1, NULL, mShellMmAccessTypeStr[AccessType], 
gShellDebug1HiiHandle);
   ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), 
gShellDebug1HiiHandle, Address);
diff --git 
a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni 
b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
index b6a133a45444..011a7bfc2db6 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
@@ -128,7 +128,6 @@
 
 #string STR_MM_NOT_ALIGNED#language en-US "%H%s%N: Address parameter 
%016LX is not aligned.\r\n"
 #string STR_MM_PCIE_ADDRESS_RANGE #language en-US "%H%s%N: Address parameter 
%016LX is not a valid PCI/PCIE address.\r\n"
-#string STR_MM_IO_ADDRESS_RANGE   #language en-US "%H%s%N: IO address out of 
range 0 - 0x\r\n"
 #string STR_MM_MMIO   #language en-US "%HMMIO%N"
 #string STR_MM_IO #language en-US "%HIO%N"
 #string STR_MM_PCI#language en-US "%HPCI%N"
@@ -136,7 +135,6 @@
 #string STR_MM_PCIE   #language en-US "%HPCIE%N"
 #string STR_MM_ADDRESS#language en-US "  0x%016lx : "
 #string STR_MM_BUF#language en-US "0x%0*lx"
-#string STR_MM_ADDRESS_RANGE2 #language en-US "%H%s%N: IO address out of 
range\r\n"
 #string STR_MM_ERROR  #language en-US "%H%s%N: Input had incorrect 
format\r\n"
 
 #string STR_SETVAR_PRINT  #language en-US "%g - %s - %04x Bytes\r\n"
-- 
2.11.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch] NetworkPkg/Udp6Dxe: Fix the failure to leave one multicast group address.

2018-03-01 Thread Jiaxin Wu
The issue was enrolled by the commit of ceec3638. One of the change in the 
commit
was to return the status from NetMapIterate in Udp6Groups function. But it 
should
not return EFI_ABORTED directly in case McastIp is not NULL, which means to 
terminate
the iteration and leave the McastIp successfully.

Cc: Wang Fan 
Cc: Fu Siyuan 
Cc: Ye Ting 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu 
---
 NetworkPkg/Udp6Dxe/Udp6Main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/NetworkPkg/Udp6Dxe/Udp6Main.c b/NetworkPkg/Udp6Dxe/Udp6Main.c
index 1d7f0acbc7..e9d94dd00c 100644
--- a/NetworkPkg/Udp6Dxe/Udp6Main.c
+++ b/NetworkPkg/Udp6Dxe/Udp6Main.c
@@ -380,10 +380,13 @@ Udp6Groups (
 
 Status = NetMapInsertTail (>McastIps, (VOID *) McastIp, NULL);
   } else {
 
 Status = NetMapIterate (>McastIps, Udp6LeaveGroup, 
MulticastAddress);
+if ((MulticastAddress != NULL) && (Status == EFI_ABORTED)) {
+  Status = EFI_SUCCESS;
+} 
   }
 
 ON_EXIT:
 
   gBS->RestoreTPL (OldTpl);
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch] MdeModulePkg/Mtftp4Dxe: Restore the TPL before the poll function.

2018-03-01 Thread Jiaxin Wu
This patch is to fix the hang issue, which was enrolled by the commit of 
39b0867d.
The TPL should be restored before calling poll function at TPL_CALLBACK.

Cc: Wang Fan 
Cc: Fu Siyuan 
Cc: Ye Ting 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu 
---
 MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c 
b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
index f5f9e6d8f7..64e0463dd9 100644
--- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
+++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
@@ -507,24 +507,27 @@ Mtftp4Start (
   if (EFI_ERROR (Status)) {
 Status = EFI_DEVICE_ERROR;
 goto ON_ERROR;
   }
 
+  //
+  // Restore the TPL now, don't call poll function at TPL_CALLBACK.
+  //
+  gBS->RestoreTPL (OldTpl);
+
   if (Token->Event != NULL) {
-gBS->RestoreTPL (OldTpl);
 return EFI_SUCCESS;
   }
 
   //
   // Return immediately for asynchronous operation or poll the
   // instance for synchronous operation.
   //
   while (Token->Status == EFI_NOT_READY) {
 This->Poll (This);
   }
-
-  gBS->RestoreTPL (OldTpl);
+  
   return Token->Status;
 
 ON_ERROR:
   Mtftp4CleanOperation (Instance, Status);
   gBS->RestoreTPL (OldTpl);
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v5 0/6] Add translation support to generic PciHostBridge

2018-03-01 Thread Ard Biesheuvel
On 1 March 2018 at 06:57, Heyi Guo  wrote:
> Patch v5 inherits the code from RFC v4; we don't restart the version number 
> for
> RFC to PATCH change.
>
> v5:
> - Patch 4/6: Modify the code according to the comments from Ray.
> - Patch 1/6 and 2/6 are totally new. They add initialization for all fields of
>   PCI_ROOT_BRIDGE_APERTURE temporary variables in PciHostBridgeLib instances, 
> so
>   that they will not suffer from extension of PCI_ROOT_BRIDGE_APERTURE
>   structure.
> - Generate a separate patch (3/6) for PciHostBridgeLib.h change. Though it is 
> a
>   prerequisite for patch 4/6, it does not change the code in PciHostBridge
>   driver and won't cause any build failure or functional issue.
>
>
> v4:
> - Modify the code according to the comments from Ray, Laszlo and Ard (Please 
> see
>   the notes of Patch 1/3)
> - Ignore translation of bus in CreateRootBridge.
>
>
> v3:
> - Keep definition of Translation consistent in EDKII code: Translation = 
> device
>   address - host address.
> - Patch 2/2 is split into 2 patches (2/3 and 3/3).
> - Refine comments and commit messages to make the code easier to understand.
>
>
> v2:
> Changs are made according to the discussion on the mailing list, including:
>
> - PciRootBridgeIo->Configuration should return CPU view address, as well as
>   PciIo->GetBarAttributes, and Translation Offset should be equal to PCI view
>   address - CPU view address.
> - Add translation offset to PCI_ROOT_BRIDGE_APERTURE structure definition.
> - PciHostBridge driver internally used Base Address is still based on PCI view
>   address, and translation offset = CPU view - PCI view, which follows the
>   definition in ACPI, and not the same as that in UEFI spec.
>

Heyi,

Thanks again for taking the time to implement this.

I have applied the patches and they appear to work on my SynQuacer
system, which has two PCIe RCs of which one uses translation for the
I/O space

I.e.,

PCI0 has 0x0..0x mapped to MMIO offset 0x67f0
PCI1 has 0x0..0x mapped to MMIO offset 0x77f0

The only problem I am hitting now is that the 'mm' shell command has a
hard coded 16-bit limit for IO space, which we should probably fix as
well.

If I remove this limit, I can correctly access the I/O space of PCI1 like this:

Shell> mm 77f00010
MEM  0x77F00010 : 0x00 >
MEM  0x77F00011 : 0x03 >
MEM  0x77F00012 : 0x00 >
MEM  0x77F00013 : 0x00 >
MEM  0x77F00014 : 0x00 >
MEM  0x77F00015 : 0xF0 >
MEM  0x77F00016 : 0x35 >
MEM  0x77F00017 : 0xFD > q

Shell> mm 10010 -io
IO  0x00010010 : 0x00 >
IO  0x00010011 : 0x03 >
IO  0x00010012 : 0x00 >
IO  0x00010013 : 0x00 >
IO  0x00010014 : 0x00 >
IO  0x00010015 : 0xF0 >
IO  0x00010016 : 0x35 >
IO  0x00010017 : 0xFD > q

Tested-by: Ard Biesheuvel 


> Cc: Ruiyu Ni 
> Cc: Ard Biesheuvel 
> Cc: Star Zeng 
> Cc: Eric Dong 
> Cc: Laszlo Ersek 
> Cc: Michael D Kinney 
> Cc: Maurice Ma 
> Cc: Prince Agyeman 
> Cc: Benjamin You 
> Cc: Jordan Justen 
> Cc: Anthony Perard 
> Cc: Julien Grall 
>
> Heyi Guo (6):
>   CorebootPayloadPkg/PciHostBridgeLib: Init PCI aperture to 0
>   OvmfPkg/PciHostBridgeLib: Init PCI aperture to 0
>   MdeModulePkg/PciHostBridgeLib.h: add address Translation
>   MdeModulePkg/PciHostBridgeDxe: Add support for address translation
>   MdeModulePkg/PciBus: convert host address to device address
>   MdeModulePkg/PciBus: return CPU address for GetBarAttributes
>
>  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.h  |  21 
>  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostResource.h|   3 +
>  MdeModulePkg/Include/Library/PciHostBridgeLib.h|  19 +++
>  CorebootPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c |   5 +
>  MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c |  12 +-
>  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c  | 129 
> +---
>  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c| 118 
> --
>  OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c|   4 +
>  OvmfPkg/Library/PciHostBridgeLib/XenSupport.c  |   5 +
>  9 files changed, 288 insertions(+), 28 deletions(-)
>
> --
> 2.7.4
>
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] BaseTools: report error if flag in LABEL() invalid

2018-03-01 Thread Feng, YunhuaX
Flag in LABEL() is not valid C variable name, will
report error

Cc: Liming Gao 
Cc: Yonghong Zhu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng 
---
 BaseTools/Source/Python/Common/Expression.py | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Expression.py 
b/BaseTools/Source/Python/Common/Expression.py
index f1516d5c7b..40e6d32280 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -117,10 +117,16 @@ def SplitPcdValueString(String):
 raise BadExpression(ERR_STRING_TOKEN % Item)
 if Item:
 RetList.append(Item)
 return RetList
 
+def IsValidCString(Str):
+ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
+if not ValidString.match(Str):
+return False
+return True
+
 ## ReplaceExprMacro
 #
 def ReplaceExprMacro(String, Macros, ExceptionList = None):
 StrList = SplitString(String)
 for i, String in enumerate(StrList):
@@ -883,17 +889,17 @@ class ValueExpressionEx(ValueExpression):
 ReOffset = re.compile('OFFSET_OF\((\w+)\)')
 LabelOffset = 0
 for Index, Item in enumerate(PcdValueList):
 # compute byte offset of every LABEL
 Item = Item.strip()
-try:
-LabelList = ReLabel.findall(Item)
+LabelList = ReLabel.findall(Item)
+if LabelList:
 for Label in LabelList:
+if not IsValidCString(Label):
+raise BadExpression('%s is invalid c 
variable string' % Label)
 if Label not in LabelDict.keys():
 LabelDict[Label] = str(LabelOffset)
-except:
-pass
 if Item.startswith('UINT8'):
 LabelOffset = LabelOffset + 1
 elif Item.startswith('UINT16'):
 LabelOffset = LabelOffset + 2
 elif Item.startswith('UINT32'):
-- 
2.12.2.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch] BaseTools: update DNS_DEVICE_PATH/URI_DEVICE_PATH definition

2018-03-01 Thread Yonghong Zhu
Update this two definition to align with MdePkg.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu 
---
 BaseTools/Source/C/Include/Protocol/DevicePath.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/C/Include/Protocol/DevicePath.h 
b/BaseTools/Source/C/Include/Protocol/DevicePath.h
index a5d8eea..68bb37e 100644
--- a/BaseTools/Source/C/Include/Protocol/DevicePath.h
+++ b/BaseTools/Source/C/Include/Protocol/DevicePath.h
@@ -3,11 +3,11 @@
 
   The device path represents a programmatic path to a device,
   from a software point of view. The path must persist from boot to boot, so
   it can not contain things like PCI bus numbers that change from boot to boot.
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2017 - 2018, 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 that accompanies this distribution.
 The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php.
 
@@ -36,10 +36,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 ///
 #define DEVICE_PATH_PROTOCOL  EFI_DEVICE_PATH_PROTOCOL_GUID
 
 #pragma pack(1)
 
+#if defined(_MSC_EXTENSIONS)
+//
+// Disable warning when last field of data structure is a zero sized array.
+//
+#pragma warning ( disable : 4200 )
+#endif
+
 /**
   This protocol can be used on any device handle to obtain generic 
path/location
   information concerning the physical device or logical device. If the handle 
does
   not logically map to a physical device, the handle may not necessarily 
support
   the device path protocol. The device path describes the location of the 
device
@@ -828,11 +835,11 @@ typedef struct {
   ///
   UINT8   IsIPv6;
   ///
   /// Instance of the DNS server address.
   ///
-  EFI_IP_ADDRESS  DnsServerIp[1024];
+  EFI_IP_ADDRESS  DnsServerIp[];
 } DNS_DEVICE_PATH;
 
 ///
 /// Uniform Resource Identifiers (URI) Device Path SubType
 ///
@@ -840,11 +847,11 @@ typedef struct {
 typedef struct {
   EFI_DEVICE_PATH_PROTOCOLHeader;
   ///
   /// Instance of the URI pursuant to RFC 3986.
   ///
-  CHAR8   Uri[1024];
+  CHAR8   Uri[];
 } URI_DEVICE_PATH;
 
 ///
 /// Universal Flash Storage (UFS) Device Path SubType.
 ///
-- 
2.6.1.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel