Re: [edk2] [PATCH] UefiCpuPkg SecCore: Fix operands of different size in bitwise operation

2017-08-01 Thread Wu, Hao A
Reviewed-by: Hao Wu 


Best Regards,
Hao Wu


> -Original Message-
> From: Zeng, Star
> Sent: Wednesday, August 02, 2017 10:10 AM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star; Wu, Hao A; Gao, Liming; Fan, Jeff
> Subject: [PATCH] UefiCpuPkg SecCore: Fix operands of different size in bitwise
> operation
> 
> It is introduced by 9e9ca2100f22be29f1a53129d741f4305ff34a71.
> 
> Cc: Hao Wu 
> Cc: Liming Gao 
> Cc: Jeff Fan 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Star Zeng 
> ---
>  UefiCpuPkg/SecCore/SecMain.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/SecCore/SecMain.c b/UefiCpuPkg/SecCore/SecMain.c
> index e9e243ca0585..173bbfcfcba4 100644
> --- a/UefiCpuPkg/SecCore/SecMain.c
> +++ b/UefiCpuPkg/SecCore/SecMain.c
> @@ -281,7 +281,7 @@ SecStartupPhase2(
>  // will be built based on them in PEI phase.
>  //
>  SecCoreData->PeiTemporaryRamBase = (VOID *)(((UINTN)SecCoreData-
> >PeiTemporaryRamBase + 7) & ~0x07);
> -SecCoreData->PeiTemporaryRamSize &= ~0x07;
> +SecCoreData->PeiTemporaryRamSize &= ~(UINTN)0x07;
>} else {
>  //
>  // No addition PPI, PpiList directly point to the common PPI list.
> --
> 2.7.0.windows.1

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


Re: [edk2] [PATCH] MdePkg: Add PcdPciExpressRegionLength PCD Token

2017-08-01 Thread Gao, Liming
Felix:
  Could you attach your patch?

>-Original Message-
>From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
>Felix Poludov
>Sent: Wednesday, August 02, 2017 4:56 AM
>To: edk2-devel@lists.01.org
>Subject: [edk2] [PATCH] MdePkg: Add PcdPciExpressRegionLength PCD Token
>
>Add PcdPciExpressRegionLength PCD Token to MdePkg.
>The new token can be used in conjunction with PcdPciExpressBaseAddress
>PCD token to describe PCI Express MMIO region.
>
>Contributed-under: TianoCore Contribution Agreement 1.0
>Signed-off-by: Felix Polyudov 
>---
>
>
>Please consider the environment before printing this email.
>
>The information contained in this message may be confidential and
>proprietary to American Megatrends, Inc.  This communication is intended to
>be read only by the individual or entity to whom it is addressed or by their
>designee. If the reader of this message is not the intended recipient, you are
>on notice that any distribution of this message, in any form, is strictly
>prohibited.  Please promptly notify the sender by reply e-mail or by telephone
>at 770-246-8600, and then delete or destroy all copies of the transmission.
>___
>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] [PATCH] UefiCpuPkg SecCore: Fix operands of different size in bitwise operation

2017-08-01 Thread Star Zeng
It is introduced by 9e9ca2100f22be29f1a53129d741f4305ff34a71.

Cc: Hao Wu 
Cc: Liming Gao 
Cc: Jeff Fan 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng 
---
 UefiCpuPkg/SecCore/SecMain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UefiCpuPkg/SecCore/SecMain.c b/UefiCpuPkg/SecCore/SecMain.c
index e9e243ca0585..173bbfcfcba4 100644
--- a/UefiCpuPkg/SecCore/SecMain.c
+++ b/UefiCpuPkg/SecCore/SecMain.c
@@ -281,7 +281,7 @@ SecStartupPhase2(
 // will be built based on them in PEI phase.
 //
 SecCoreData->PeiTemporaryRamBase = (VOID 
*)(((UINTN)SecCoreData->PeiTemporaryRamBase + 7) & ~0x07);
-SecCoreData->PeiTemporaryRamSize &= ~0x07;
+SecCoreData->PeiTemporaryRamSize &= ~(UINTN)0x07;
   } else {
 //
 // No addition PPI, PpiList directly point to the common PPI list.
-- 
2.7.0.windows.1

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


Re: [edk2] [PATCH v1 2/4] OvmfPkg: IommuDxe: Provide support for mapping BusMasterCommonBuffer operation

2017-08-01 Thread Brijesh Singh
Thanks Laszlo.


On 8/1/17 4:59 PM, Laszlo Ersek wrote:
> On 07/31/17 21:31, Brijesh Singh wrote:
> +  
[Snip]
>> The function is used for mapping and unmapping the Host buffer with
>> +  BusMasterCommonBuffer. Since the buffer can be accessed equally by the
>> +  processor and the DMA bus master hence we can not use the bounce buffer.
>> +
>> +  The function changes the underlying encryption mask of the pages that 
>> maps the
>> +  host buffer. It also ensures that buffer contents are updated with the 
>> desired
>> +  state.
>> +
>> +**/
>> +STATIC
>> +EFI_STATUS
>> +SetBufferAsEncDec (
>> +  IN MAP_INFO *MapInfo,
>> +  IN BOOLEAN  Enc
>> +  )
>> +{
>> +  EFI_STATUSStatus;
>> +  EFI_PHYSICAL_ADDRESS  TempBuffer;
>> +
>> +  //
>> +  // Allocate an intermediate buffer to hold the host buffer contents
>> +  //
>> +  Status = gBS->AllocatePages (
>> +  AllocateAnyPages,
>> +  EfiBootServicesData,
>> +  MapInfo->NumberOfPages,
>> +  &TempBuffer
>> +  );
>> +  if (EFI_ERROR (Status)) {
>> +return Status;
>> +  }
> This is not right. This function is called (indirectly) from
> IoMmuUnmap(), which is the function that we'll call (also indirectly)
> from the ExitBootServices() callbacks. That means we cannot allocate or
> release dynamic memory here. This is why I suggested the page-sized
> static buffer, and page-wise copying.
>
> More on this later, below the end of this function.

Agree with your point, see more below

>> +
>> +  //
>> +  // If the host buffer has C-bit cleared, then make sure the intermediate
>> +  // buffer matches with same encryption mask.
>> +  //
>> +  if (!Enc) {
>> +Status = MemEncryptSevClearPageEncMask (0, MapInfo->DeviceAddress,
>> +   MapInfo->NumberOfPages, TRUE);
>> +ASSERT_EFI_ERROR (Status);
>> +  }
> As a separate issue, I don't think this is right. The auxiliary buffer
> that we use for in-place encryption or decryption should *always* be
> encrypted. (I mentioned this in my email, "Introduce a static UINT8
> array with EFI_PAGE_SIZE bytes (this will always remain in encrypted
> memory).", but I guess it was easy to miss.)

See more below

>> +
>> +  //
>> +  // Copy the data from host buffer into a temporary buffer. At this
>> +  // time both host and intermediate buffer will have same encryption
>> +  // mask.
>> +  //
> The comment should say "copy original buffer into temporary buffer".
> "host" buffer is very confusing here, as the virtualization host is
> exactly what may not yet have access to the buffer. In PCI bus master
> terminology, "host buffer" is valid, I think, but saying just "host
> buffer" is very confusing.

Will do.

> Also, "same encryption mask" is not desirable (see above), so please
> remove that sentence.
>
>> +  CopyMem (
>> +(VOID *) (UINTN) TempBuffer,
>> +(VOID *) (UINTN)MapInfo->HostAddress,
>> +MapInfo->NumberOfBytes);
>> +
>> +  //
>> +  // Now change the encryption mask of the host buffer
>> +  //
>> +  if (Enc) {
>> +Status = MemEncryptSevSetPageEncMask (0, MapInfo->HostAddress,
>> +   MapInfo->NumberOfPages, TRUE);
>> +ASSERT_EFI_ERROR (Status);
> What guarantees that this function call will never fail?
>
> If it fails, we should propagate the error (the function prototype
> allows for that), and roll back partial changes along the way.
>
> If there is no way to undo partial actions when
> MemEncryptSevSetPageEncMask() fails, then the ASSERT() is fine, but we
> need an additional CpuDeadLoop() as well.

I will propagate the error.
>> +  } else {
>> +Status = MemEncryptSevClearPageEncMask (0, MapInfo->HostAddress,
>> +   MapInfo->NumberOfPages, TRUE);
>> +ASSERT_EFI_ERROR (Status);
>> +  }
>> +
>> +  //
>> +  // Copy the data from intermediate buffer into host buffer. At this
>> +  // time encryption masks will be different on host and intermediate
>> +  // buffer and the hardware will perform encryption/decryption on
>> +  // accesses.
>> +  //
>> +  CopyMem (
>> +(VOID *) (UINTN)MapInfo->HostAddress,
>> +(VOID *) (UINTN)TempBuffer,
>> +MapInfo->NumberOfBytes);
>> +
>> +  //
>> +  // Restore the encryption mask of the intermediate buffer
>> +  //
>> +  if (!Enc) {
>> +Status = MemEncryptSevSetPageEncMask (0, MapInfo->DeviceAddress,
>> +   MapInfo->NumberOfPages, TRUE);
>> +ASSERT_EFI_ERROR (Status);
>> +  }
> Again, the intermediate buffer should always remain encrypted.
>
>> +
>> +  //
>> +  // Free the intermediate buffer
>> +  //
>> +  gBS->FreePages (TempBuffer, MapInfo->NumberOfPages);
>> +  return EFI_SUCCESS;
>> +}
> In summary for this function: I've now read section "7.10.8
> Encrypt-in-Place" of AMD pub #24593. Earlier I wrote,
>
> Introduce a static UINT8 array with EFI_PAGE_SIZE bytes (this
> will always remain in encrypted memory). Update the C bit with a
> single function call for the entire range (like now) -- this w

Re: [edk2] issue about booting centos fail with edk2

2017-08-01 Thread Ard Biesheuvel
On 1 August 2017 at 23:29, Laszlo Ersek  wrote:
> On 08/01/17 19:23, Ard Biesheuvel wrote:
>> On 1 August 2017 at 16:42, Laszlo Ersek  wrote:
>>> On 08/01/17 10:34, Zhu Yijun wrote:
 Thanks for your reply!

 On 2017/8/1 3:02, Laszlo Ersek wrote:
> On 07/31/17 02:27, Zhu Yijun wrote:
>> Hi all,
>>
>> I install a CentOS-7-aarch64 guest img by qemu cdrom, but it hung at 
>> UEFI probability.
>>
>> Basic info:
>> libvirt 1.3.5
>> QEMU 2.6.2
>> UEFI: master branch with commit "688c7d2 BaseTools: Fix the bug that 
>> warn() function with only 1 argument"
>>
>> Config pflash and two disks in xml:
>>
>> ...
>> 
>> hvm
>> > type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw
>> 
>>   
>>   ...
>>   
>>   
>>   
>>   
>>   
>> 
>> 
>>   
>>   
>>   
>>   
>> 
>> ...
>>
>> I found it failed at "Match (Translated, TranslatedSize, 
>> ActiveOption[Idx].BootOption->FilePath)" function in 
>> "SetBootOrderFromQemu", the UEFI debug info as follow:
> No, that's not where the problem is. See below:
>
>> start-console-fail.log
>> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
>> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
>>
>>
>> Synchronous Exception at 0x0002384B1104
>> PC 0x0002384B1104
>> PC 0x0002384A916C
>> PC 0x0002384CA2D0
>> PC 0x00023EEB7DF8 (0x00023EEB1000+0x6DF8) [ 1] DxeCore.dll
>> PC 0x00023BD1568C (0x00023BD02000+0x0001368C) [ 2] BdsDxe.dll
>> PC 0x00023BD03F98 (0x00023BD02000+0x1F98) [ 2] BdsDxe.dll
>> PC 0x00023BD05640 (0x00023BD02000+0x3640) [ 2] BdsDxe.dll
>> PC 0x00023EEB3704 (0x00023EEB1000+0x2704) [ 3] DxeCore.dll
>> PC 0x00023EEB27C8 (0x00023EEB1000+0x17C8) [ 3] DxeCore.dll
>> PC 0x00023EEB2024 (0x00023EEB1000+0x1024) [ 3] DxeCore.dll
>> [ 1] 
>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> [ 2] 
>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> [ 3] 
>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>>
>>   X0 0x0002384A9000   X1 0x0002384B2990   X2 0x00023AAFDF98  
>>  X3 0x00023BFF0018
>>   X4 0x   X5 0x0007   X6 0x000238533300  
>>  X7 0x
>>   X8 0x00023C01F548   X9 0x0002  X10 0x0002384A8000  
>> X11 0x0002384C5FFF
>>  X12 0x  X13 0x0008  X14 0x259511BDAEB1F36C  
>> X15 0x1378CC1DF3F5DDBB
>>  X16 0x00023EEB0BE0  X17 0x  X18 0x  
>> X19 0x0013
>>  X20 0x  X21 0x  X22 0x  
>> X23 0x
>>  X24 0x  X25 0x  X26 0x  
>> X27 0x
>>  X28 0x   FP 0x00023EEB0A40   LR 0x0002384A916C
>>
>>   V0 0xAFAFAFAFAFAFAFAF AFAFAFAFAFAFAFAF   V1 0x63702F66 
>> 
>>   V2 0x40697363732F3340 6567646972622D69   V3 0x 
>> 
>>   V4 0x    V5 0x4010040140100401 
>> 4010040140100401
>>   V6 0x    V7 0x 
>> 
>>   V8 0x    V9 0x 
>> 
>>  V10 0x   V11 0x 
>> 
>>  V12 0x   V13 0x 
>> 
>>  V14 0x   V15 0x 
>> 
>>  V16 0x   V17 0x 
>> 
>>  V18 0x   V19 0x 
>> 
>>  V20 0x   V21 0x 
>> 
>>  V22 0x   V23 0x 
>> 
>>  V24 0x   V25 0x 
>> 
>>  V26 0x   V27 0x 
>> 
>>  V28 0x   V29 0x 
>> 
>>  V30 0x   V31 0x 
>> 
>>
>>   SP 0x00023EEB0A40  ELR 0x0002384B1104  SPSR 0x6205  FPSR 
>> 0

Re: [edk2] issue about booting centos fail with edk2

2017-08-01 Thread Laszlo Ersek
On 08/01/17 19:23, Ard Biesheuvel wrote:
> On 1 August 2017 at 16:42, Laszlo Ersek  wrote:
>> On 08/01/17 10:34, Zhu Yijun wrote:
>>> Thanks for your reply!
>>>
>>> On 2017/8/1 3:02, Laszlo Ersek wrote:
 On 07/31/17 02:27, Zhu Yijun wrote:
> Hi all,
>
> I install a CentOS-7-aarch64 guest img by qemu cdrom, but it hung at 
> UEFI probability.
>
> Basic info:
> libvirt 1.3.5
> QEMU 2.6.2
> UEFI: master branch with commit "688c7d2 BaseTools: Fix the bug that 
> warn() function with only 1 argument"
>
> Config pflash and two disks in xml:
>
> ...
> 
> hvm
>  type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw
> 
>   
>   ...
>   
>   
>   
>   
>   
> 
> 
>   
>   
>   
>   
> 
> ...
>
> I found it failed at "Match (Translated, TranslatedSize, 
> ActiveOption[Idx].BootOption->FilePath)" function in 
> "SetBootOrderFromQemu", the UEFI debug info as follow:
 No, that's not where the problem is. See below:

> start-console-fail.log
> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
>
>
> Synchronous Exception at 0x0002384B1104
> PC 0x0002384B1104
> PC 0x0002384A916C
> PC 0x0002384CA2D0
> PC 0x00023EEB7DF8 (0x00023EEB1000+0x6DF8) [ 1] DxeCore.dll
> PC 0x00023BD1568C (0x00023BD02000+0x0001368C) [ 2] BdsDxe.dll
> PC 0x00023BD03F98 (0x00023BD02000+0x1F98) [ 2] BdsDxe.dll
> PC 0x00023BD05640 (0x00023BD02000+0x3640) [ 2] BdsDxe.dll
> PC 0x00023EEB3704 (0x00023EEB1000+0x2704) [ 3] DxeCore.dll
> PC 0x00023EEB27C8 (0x00023EEB1000+0x17C8) [ 3] DxeCore.dll
> PC 0x00023EEB2024 (0x00023EEB1000+0x1024) [ 3] DxeCore.dll
> [ 1] 
> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
> [ 2] 
> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
> [ 3] 
> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>
>   X0 0x0002384A9000   X1 0x0002384B2990   X2 0x00023AAFDF98   
> X3 0x00023BFF0018
>   X4 0x   X5 0x0007   X6 0x000238533300   
> X7 0x
>   X8 0x00023C01F548   X9 0x0002  X10 0x0002384A8000  
> X11 0x0002384C5FFF
>  X12 0x  X13 0x0008  X14 0x259511BDAEB1F36C  
> X15 0x1378CC1DF3F5DDBB
>  X16 0x00023EEB0BE0  X17 0x  X18 0x  
> X19 0x0013
>  X20 0x  X21 0x  X22 0x  
> X23 0x
>  X24 0x  X25 0x  X26 0x  
> X27 0x
>  X28 0x   FP 0x00023EEB0A40   LR 0x0002384A916C
>
>   V0 0xAFAFAFAFAFAFAFAF AFAFAFAFAFAFAFAF   V1 0x63702F66 
> 
>   V2 0x40697363732F3340 6567646972622D69   V3 0x 
> 
>   V4 0x    V5 0x4010040140100401 
> 4010040140100401
>   V6 0x    V7 0x 
> 
>   V8 0x    V9 0x 
> 
>  V10 0x   V11 0x 
> 
>  V12 0x   V13 0x 
> 
>  V14 0x   V15 0x 
> 
>  V16 0x   V17 0x 
> 
>  V18 0x   V19 0x 
> 
>  V20 0x   V21 0x 
> 
>  V22 0x   V23 0x 
> 
>  V24 0x   V25 0x 
> 
>  V26 0x   V27 0x 
> 
>  V28 0x   V29 0x 
> 
>  V30 0x   V31 0x 
> 
>
>   SP 0x00023EEB0A40  ELR 0x0002384B1104  SPSR 0x6205  FPSR 
> 0x
>  ESR 0x0200  FAR 0x1DE7EC7EDBADC0DE
>
>  ESR : EC 0x00  IL 0x1  ISS 0x
>
> Stack dump:
>   23EEB0940: C0E0

Re: [edk2] [PATCH v1 2/4] OvmfPkg: IommuDxe: Provide support for mapping BusMasterCommonBuffer operation

2017-08-01 Thread Laszlo Ersek
On 07/31/17 21:31, Brijesh Singh wrote:
> The current implementation was making assumption that AllocateBuffer()
> returns a buffer with C-bit cleared. Hence when we were asked to
> Map() with BusMasterCommonBuffer, we do not change the C-bit on
> host buffer.
> 
> In previous patch, we changed the AllocateBuffer() to not clear
> C-bit during allocation. The patch adds support for handling the
> BusMasterCommonBuffer operations when SEV is active.
> 
> A typical DMA Bus master Common Operation follows the below step:
> 
> 1. Client calls AllocateBuffer() to allocate a common buffer
> 2. Client fill some data in common buffer (optional)
> 3. Client calls Map() with BusMasterCommonBuffer
> 4. Programs the DMA bus master with the device address returned by Map()
> 5. The common buffer can now be accessed equally by the processor and
>the DMA bus master.
> 6. Client calls Unmap()
> 7. Client calls FreeBuffer()
> 
> In order to handle steps #2 (in which common buffer may contain
> data), we perform in-place encryption to ensure that device
> address returned by the Map() contains the correct data after
> we clear the C-bit during Map().
> 
> In my measurement I do not see any noticable perform degradation when
> performing in-place encryption/decryption on common buffer.
> 
> Suggested-by: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Cc: Laszlo Ersek 
> Cc: Jordan Justen 
> Signed-off-by: Brijesh Singh 
> ---
>  OvmfPkg/IoMmuDxe/AmdSevIoMmu.c | 190 +---
>  1 file changed, 164 insertions(+), 26 deletions(-)
> 
> diff --git a/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c b/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
> index cc3c979d4484..5ae54482fffe 100644
> --- a/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
> +++ b/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
> @@ -28,7 +28,127 @@ typedef struct {
>EFI_PHYSICAL_ADDRESS  DeviceAddress;
>  } MAP_INFO;
>  
> -#define NO_MAPPING (VOID *) (UINTN) -1
> +/**
> +
> +  The function is used for mapping and unmapping the Host buffer with
> +  BusMasterCommonBuffer. Since the buffer can be accessed equally by the
> +  processor and the DMA bus master hence we can not use the bounce buffer.
> +
> +  The function changes the underlying encryption mask of the pages that maps 
> the
> +  host buffer. It also ensures that buffer contents are updated with the 
> desired
> +  state.
> +
> +**/
> +STATIC
> +EFI_STATUS
> +SetBufferAsEncDec (
> +  IN MAP_INFO *MapInfo,
> +  IN BOOLEAN  Enc
> +  )
> +{
> +  EFI_STATUSStatus;
> +  EFI_PHYSICAL_ADDRESS  TempBuffer;
> +
> +  //
> +  // Allocate an intermediate buffer to hold the host buffer contents
> +  //
> +  Status = gBS->AllocatePages (
> +  AllocateAnyPages,
> +  EfiBootServicesData,
> +  MapInfo->NumberOfPages,
> +  &TempBuffer
> +  );
> +  if (EFI_ERROR (Status)) {
> +return Status;
> +  }

This is not right. This function is called (indirectly) from
IoMmuUnmap(), which is the function that we'll call (also indirectly)
from the ExitBootServices() callbacks. That means we cannot allocate or
release dynamic memory here. This is why I suggested the page-sized
static buffer, and page-wise copying.

More on this later, below the end of this function.

> +
> +  //
> +  // If the host buffer has C-bit cleared, then make sure the intermediate
> +  // buffer matches with same encryption mask.
> +  //
> +  if (!Enc) {
> +Status = MemEncryptSevClearPageEncMask (0, MapInfo->DeviceAddress,
> +   MapInfo->NumberOfPages, TRUE);
> +ASSERT_EFI_ERROR (Status);
> +  }

As a separate issue, I don't think this is right. The auxiliary buffer
that we use for in-place encryption or decryption should *always* be
encrypted. (I mentioned this in my email, "Introduce a static UINT8
array with EFI_PAGE_SIZE bytes (this will always remain in encrypted
memory).", but I guess it was easy to miss.)

> +
> +  //
> +  // Copy the data from host buffer into a temporary buffer. At this
> +  // time both host and intermediate buffer will have same encryption
> +  // mask.
> +  //

The comment should say "copy original buffer into temporary buffer".
"host" buffer is very confusing here, as the virtualization host is
exactly what may not yet have access to the buffer. In PCI bus master
terminology, "host buffer" is valid, I think, but saying just "host
buffer" is very confusing.

Also, "same encryption mask" is not desirable (see above), so please
remove that sentence.

> +  CopyMem (
> +(VOID *) (UINTN) TempBuffer,
> +(VOID *) (UINTN)MapInfo->HostAddress,
> +MapInfo->NumberOfBytes);
> +
> +  //
> +  // Now change the encryption mask of the host buffer
> +  //
> +  if (Enc) {
> +Status = MemEncryptSevSetPageEncMask (0, MapInfo->HostAddress,
> +   MapInfo->NumberOfPages, TRUE);
> +ASSERT_EFI_ERROR (Status);

What guarantees that this function call will never fail?

If it fails, we should propaga

[edk2] [PATCH] MdePkg: Add PcdPciExpressRegionLength PCD Token

2017-08-01 Thread Felix Poludov
Add PcdPciExpressRegionLength PCD Token to MdePkg.
The new token can be used in conjunction with PcdPciExpressBaseAddress PCD 
token to describe PCI Express MMIO region.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Felix Polyudov 
---


Please consider the environment before printing this email.

The information contained in this message may be confidential and proprietary 
to American Megatrends, Inc.  This communication is intended to be read only by 
the individual or entity to whom it is addressed or by their designee. If the 
reader of this message is not the intended recipient, you are on notice that 
any distribution of this message, in any form, is strictly prohibited.  Please 
promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and 
then delete or destroy all copies of the transmission.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v1 2/4] OvmfPkg: IommuDxe: Provide support for mapping BusMasterCommonBuffer operation

2017-08-01 Thread Laszlo Ersek
On 07/31/17 22:27, Brijesh Singh wrote:
> 
> 
> On 07/31/2017 02:49 PM, Ard Biesheuvel wrote:
>> On 31 July 2017 at 20:31, Brijesh Singh  wrote:
>>> The current implementation was making assumption that AllocateBuffer()
>>> returns a buffer with C-bit cleared. Hence when we were asked to
>>> Map() with BusMasterCommonBuffer, we do not change the C-bit on
>>> host buffer.
>>>
>>> In previous patch, we changed the AllocateBuffer() to not clear
>>> C-bit during allocation. The patch adds support for handling the
>>> BusMasterCommonBuffer operations when SEV is active.
>>>
>>> A typical DMA Bus master Common Operation follows the below step:
>>>
>>> 1. Client calls AllocateBuffer() to allocate a common buffer
>>> 2. Client fill some data in common buffer (optional)
>>> 3. Client calls Map() with BusMasterCommonBuffer
>>> 4. Programs the DMA bus master with the device address returned by Map()
>>> 5. The common buffer can now be accessed equally by the processor and
>>> the DMA bus master.
>>> 6. Client calls Unmap()
>>> 7. Client calls FreeBuffer()
>>>
>>> In order to handle steps #2 (in which common buffer may contain
>>> data), we perform in-place encryption to ensure that device
>>> address returned by the Map() contains the correct data after
>>> we clear the C-bit during Map().
>>>
>>> In my measurement I do not see any noticable perform degradation when
>>> performing in-place encryption/decryption on common buffer.
>>>
>>> Suggested-by: Laszlo Ersek 
>>> Contributed-under: TianoCore Contribution Agreement 1.0
>>> Cc: Laszlo Ersek 
>>> Cc: Jordan Justen 
>>> Signed-off-by: Brijesh Singh 
>>> ---
>>>   OvmfPkg/IoMmuDxe/AmdSevIoMmu.c | 190 +---
>>>   1 file changed, 164 insertions(+), 26 deletions(-)
>>>
>>
>> Hello Brijesh,
>>
>> I haven't looked in detail at the existing code, but please don't
>> conflate the device address with the address of a bounce buffer. These
>> are very different things, although the confusion is understandable
>> (and precedented) when not used to dealing with non-1:1 DMA.
>>
>> The device address is what gets programmed into the device's DMA
>> registers. If there is a fixed [non-zero] offset between the device's
>> view of memory and the host's (as may be the case with PCI, or
>> generally when using an IOMMU), then the device is the only one who
>> should attempt to perform memory accesses using this address. So
>> please void SetMem() or other CPU dereferences involving the device
>> address, and treat it as an opaque handle instead.
>>
> 
>> In your case, you are dealing with a bounce buffer. So call it bounce
>> buffer in the MapInfo struct. Imagine when dealing with a non-linear
>> host to PCI mapping, you will still need to perform an additional
>> translation to derive the device address from the bounce buffer
>> address.
>>
> 
> Agreed.
> 
> Initially, AmdSevIoMmu.c code was derived from PciRootBridgeIo and MAP_INFO
> structure was literally copied. I will probably send a separate patch
> to fix the structure member and update the comments to reflect its true
> meaning.

Yes, we should call it "PlainTextAddress" or something similar.

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


Re: [edk2] [PATCH v1 1/4] OvmfPkg: IommuDxe: Do not clear C-bit in Allocate() and Free()

2017-08-01 Thread Laszlo Ersek
On 07/31/17 21:31, Brijesh Singh wrote:
> As per the discussion [1], the buffer allocated using IOMMU->AllocateBuffer()
> need not result in a buffer that is immediately usable for the
> DMA device operation. Client is required to call Map() unconditionally
> with BusMasterCommonBuffer before performing the desired DMA bus
> master operation.
> 
> [1]https://lists.01.org/pipermail/edk2-devel/2017-July/012652.html
> 
> Suggested-by: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Cc: Jordan Justen 
> Cc: Laszlo Ersek 
> Cc: Ard Biesheuvel 
> Signed-off-by: Brijesh Singh 
> ---
>  OvmfPkg/IoMmuDxe/AmdSevIoMmu.c | 14 --
>  1 file changed, 14 deletions(-)
> 
> diff --git a/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c b/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
> index 9e78058b7242..cc3c979d4484 100644
> --- a/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
> +++ b/OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
> @@ -333,12 +333,6 @@ IoMmuAllocateBuffer (
>);
>if (!EFI_ERROR (Status)) {
>  *HostAddress = (VOID *) (UINTN) PhysicalAddress;
> -
> -//
> -// Clear memory encryption mask
> -//
> -Status = MemEncryptSevClearPageEncMask (0, PhysicalAddress, Pages, TRUE);
> -ASSERT_EFI_ERROR(Status);
>}
>  
>DEBUG ((DEBUG_VERBOSE, "%a Address 0x%Lx Pages 0x%Lx\n", __FUNCTION__, 
> PhysicalAddress, Pages));
> @@ -365,14 +359,6 @@ IoMmuFreeBuffer (
>IN  VOID *HostAddress
>)
>  {
> -  EFI_STATUS  Status;
> -
> -  //
> -  // Set memory encryption mask
> -  //
> -  Status = MemEncryptSevSetPageEncMask (0, 
> (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, Pages, TRUE);
> -  ASSERT_EFI_ERROR(Status);
> -
>DEBUG ((DEBUG_VERBOSE, "%a Address 0x%Lx Pages 0x%Lx\n", __FUNCTION__, 
> (UINTN)HostAddress, Pages));
>return gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress, Pages);
>  }
> 

This looks good to me, but "IommuDxe" in the subject should be spelled
"IoMmuDxe". With that change,

Reviewed-by: Laszlo Ersek 

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


[edk2] [PATCH] UefiCpuPkg: ApicLib

2017-08-01 Thread Leo Duran
Ths patch uses the max possible thread count on AMD processors to
decode location data without modification of the InitialApicId.
Functionality scales better, and the code is much easier to understand.

Leo Duran (1):
  UefiCpuPkg: ApicLib

 UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c | 64 ++
 .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c| 64 ++
 2 files changed, 32 insertions(+), 96 deletions(-)

-- 
2.7.4

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


Re: [edk2] [PATCH v4 0/2] UefiCpuPkg: Add CPUID support for AMD.

2017-08-01 Thread Duran, Leo


> -Original Message-
> From: Duran, Leo
> Sent: Friday, June 16, 2017 5:57 PM
> To: edk2-devel@lists.01.org
> Cc: Duran, Leo 
> Subject: [PATCH v4 0/2] UefiCpuPkg: Add CPUID support for AMD.

Please ignore this PATCH v4.

PATCH v3 of this series has been merged upstream:
commit 061ead7a2dcc ("UefiCpuPkg: Modify GetProcessorLocationByApicId() to 
support AMD.").

I will push a new patch today that incorporates cleanups from PATCH v4, 
and provide enhanced functionality.

Leo.
> 
> This patch-set requires and builds upon this submission:
> https://lists.01.org/pipermail/edk2-devel/2017-May/010867.html
> 
> Changes since v3:
> - Check AMD signature before checking CPUID_Fn8000_001E.
> 
> Changes since v2:
> - Account for actual thread count (e.g., SMT disabled).
> 
> Changes since v1:
> - Revert to (MaxCoresPerPackage = 1) when CPUID is not explicit.
> 
> Leo Duran (2):
>   UefiCpuPkg: Add CPUID definitions for AMD.
>   UefiCpuPkg: Modify GetProcessorLocationByApicId() to support AMD.
> 
>  UefiCpuPkg/Include/Register/Amd/Cpuid.h| 599
> -
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c | 140 +++--
>  .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c| 140 +++--
>  3 files changed, 806 insertions(+), 73 deletions(-)
> 
> --
> 2.7.4

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


Re: [edk2] issue about booting centos fail with edk2

2017-08-01 Thread Ard Biesheuvel
On 1 August 2017 at 16:42, Laszlo Ersek  wrote:
> On 08/01/17 10:34, Zhu Yijun wrote:
>> Thanks for your reply!
>>
>> On 2017/8/1 3:02, Laszlo Ersek wrote:
>>> On 07/31/17 02:27, Zhu Yijun wrote:
 Hi all,

 I install a CentOS-7-aarch64 guest img by qemu cdrom, but it hung at 
 UEFI probability.

 Basic info:
 libvirt 1.3.5
 QEMU 2.6.2
 UEFI: master branch with commit "688c7d2 BaseTools: Fix the bug that 
 warn() function with only 1 argument"

 Config pflash and two disks in xml:

 ...
 
 hvm
 >>> type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw
 
   
   ...
   
   
   
   
   
 
 
   
   
   
   
 
 ...

 I found it failed at "Match (Translated, TranslatedSize, 
 ActiveOption[Idx].BootOption->FilePath)" function in 
 "SetBootOrderFromQemu", the UEFI debug info as follow:
>>> No, that's not where the problem is. See below:
>>>
 start-console-fail.log
 FSOpen: Open '\EFI\BOOT\fallback.efi' Success
 FSOpen: Open '\EFI\BOOT\fallback.efi' Success


 Synchronous Exception at 0x0002384B1104
 PC 0x0002384B1104
 PC 0x0002384A916C
 PC 0x0002384CA2D0
 PC 0x00023EEB7DF8 (0x00023EEB1000+0x6DF8) [ 1] DxeCore.dll
 PC 0x00023BD1568C (0x00023BD02000+0x0001368C) [ 2] BdsDxe.dll
 PC 0x00023BD03F98 (0x00023BD02000+0x1F98) [ 2] BdsDxe.dll
 PC 0x00023BD05640 (0x00023BD02000+0x3640) [ 2] BdsDxe.dll
 PC 0x00023EEB3704 (0x00023EEB1000+0x2704) [ 3] DxeCore.dll
 PC 0x00023EEB27C8 (0x00023EEB1000+0x17C8) [ 3] DxeCore.dll
 PC 0x00023EEB2024 (0x00023EEB1000+0x1024) [ 3] DxeCore.dll
 [ 1] 
 /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
 [ 2] 
 /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
 [ 3] 
 /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll

   X0 0x0002384A9000   X1 0x0002384B2990   X2 0x00023AAFDF98   
 X3 0x00023BFF0018
   X4 0x   X5 0x0007   X6 0x000238533300   
 X7 0x
   X8 0x00023C01F548   X9 0x0002  X10 0x0002384A8000  
 X11 0x0002384C5FFF
  X12 0x  X13 0x0008  X14 0x259511BDAEB1F36C  
 X15 0x1378CC1DF3F5DDBB
  X16 0x00023EEB0BE0  X17 0x  X18 0x  
 X19 0x0013
  X20 0x  X21 0x  X22 0x  
 X23 0x
  X24 0x  X25 0x  X26 0x  
 X27 0x
  X28 0x   FP 0x00023EEB0A40   LR 0x0002384A916C

   V0 0xAFAFAFAFAFAFAFAF AFAFAFAFAFAFAFAF   V1 0x63702F66 
 
   V2 0x40697363732F3340 6567646972622D69   V3 0x 
 
   V4 0x    V5 0x4010040140100401 
 4010040140100401
   V6 0x    V7 0x 
 
   V8 0x    V9 0x 
 
  V10 0x   V11 0x 
 
  V12 0x   V13 0x 
 
  V14 0x   V15 0x 
 
  V16 0x   V17 0x 
 
  V18 0x   V19 0x 
 
  V20 0x   V21 0x 
 
  V22 0x   V23 0x 
 
  V24 0x   V25 0x 
 
  V26 0x   V27 0x 
 
  V28 0x   V29 0x 
 
  V30 0x   V31 0x 
 

   SP 0x00023EEB0A40  ELR 0x0002384B1104  SPSR 0x6205  FPSR 
 0x
  ESR 0x0200  FAR 0x1DE7EC7EDBADC0DE

  ESR : EC 0x00  IL 0x1  ISS 0x

 Stack dump:
   23EEB0940: C0E00148 0002384A9000 0002384CA254 
 
   23EEB0960: 00023EEB0BC0 00023AC006C0 F2503EEB0BC0 
 0002384B6018
  

Re: [edk2] [PATCH v4 4/4] EmbeddedPkg: add Android boot device path and guid

2017-08-01 Thread Leif Lindholm
Right, so this one confused me a bit, since it looked like it was
breaking bisect again. It does, which caused me to take a closer
look.

First of all, you need to add
EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf to
EmbeddedPkg/EmbeddedPkg.dsc [Components.common].

Once done, you should be able to build the application standalone with
 build -a AARCH64 -t GCC5 -p EmbeddedPkg/EmbeddedPkg.dsc -m 
EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf

For this to work, you also need to add a AndroidBootImgLib mapping to
[LibraryClasses.common].

Once that is done, the modifications here need to be squashed into
3/4.

/
Leif

On Tue, Aug 01, 2017 at 05:29:01PM +0800, Jun Nie wrote:
> The device path specifies where to load android boot image.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jun Nie 
> ---
>  EmbeddedPkg/EmbeddedPkg.dec | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec
> index 4cd528a..8ad2a84 100644
> --- a/EmbeddedPkg/EmbeddedPkg.dec
> +++ b/EmbeddedPkg/EmbeddedPkg.dec
> @@ -80,6 +80,7 @@
>gAndroidFastbootPlatformProtocolGuid =  { 0x524685a0, 0x89a0, 0x11e3, 
> {0x9d, 0x4d, 0xbf, 0xa9, 0xf6, 0xa4, 0x03, 0x08}}
>gUsbDeviceProtocolGuid =  { 0x021bd2ca, 0x51d2, 0x11e3, {0x8e, 0x56, 0xb7, 
> 0x54, 0x17, 0xc7,  0x0b, 0x44 }}
>gPlatformGpioProtocolGuid = { 0x52ce9845, 0x5af4, 0x43e2, {0xba, 0xfd, 
> 0x23, 0x08, 0x12, 0x54, 0x7a, 0xc2 }}
> +  gAndroidBootImgProtocolGuid = { 0x9859bb19, 0x407c, 0x4f8b, {0xbc, 0xe1, 
> 0xf8, 0xda, 0x65, 0x65, 0xf4, 0xa5 }}
>  
>  [PcdsFeatureFlag.common]
>gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|FALSE|BOOLEAN|0x0001
> @@ -181,6 +182,7 @@
>
> gEmbeddedTokenSpaceGuid.PcdAndroidFastbootUsbProductId|0xbeef|UINT32|0x0023
>gEmbeddedTokenSpaceGuid.PcdAndroidFastbootTcpPort|1234|UINT32|0x0024
>  
> +  gEmbeddedTokenSpaceGuid.PcdAndroidBootDevicePath|L""|VOID*|0x0057
>  
>  [PcdsFixedAtBuild.ARM]
>gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32|UINT8|0x0010
> -- 
> 1.9.1
> 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v4 3/4] EmbeddedPkg/AndroidBoot: boot android kernel from storage

2017-08-01 Thread Leif Lindholm
On Tue, Aug 01, 2017 at 05:29:00PM +0800, Jun Nie wrote:
> Add an android kernel loader that could load kernel from storage
> device. This patch is derived from Haojian's code as below link.
> https://patches.linaro.org/patch/94683/
> 
> This android boot image BDS add addtitional cmdline/dtb/ramfs
> support besides kernel that is introduced by Android boot header.

This is nearly there - it's a big improvement, but a few more
comments below.

> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jun Nie 
> ---
>  .../Application/AndroidBoot/AndroidBootApp.c   | 140 +++
>  .../Application/AndroidBoot/AndroidBootApp.inf |  64 +++
>  EmbeddedPkg/Include/Library/AndroidBootImgLib.h|  17 +
>  EmbeddedPkg/Include/Protocol/AndroidBootImg.h  |  47 +++
>  .../Library/AndroidBootImgLib/AndroidBootImgLib.c  | 444 
> +
>  .../AndroidBootImgLib/AndroidBootImgLib.inf|  48 +++
>  6 files changed, 760 insertions(+)
>  create mode 100644 EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
>  create mode 100644 EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf
>  create mode 100644 EmbeddedPkg/Include/Protocol/AndroidBootImg.h
>  create mode 100644 EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
>  create mode 100644 
> EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf
> 
> diff --git a/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c 
> b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
> new file mode 100644
> index 000..5069819
> --- /dev/null
> +++ b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
> @@ -0,0 +1,140 @@
> +/** @file
> +
> +  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
> +  Copyright (c) 2017, Linaro. 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 
> +
> +/* Validate the node is media hard drive type */
> +EFI_STATUS
> +ValidateAndroidMediaDevicePath (
> +  IN EFI_DEVICE_PATH  *DevicePath
> +  )
> +{
> +  EFI_DEVICE_PATH_PROTOCOL*Node, *NextNode;
> +
> +  NextNode = DevicePath;
> +  while (NextNode != NULL) {
> +Node = NextNode;
> +if (IS_DEVICE_PATH_NODE (Node, MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP)) {
> +  return EFI_SUCCESS;
> +}
> +NextNode = NextDevicePathNode (Node);
> +  }
> +  return EFI_INVALID_PARAMETER;
> +}
> +
> +EFI_STATUS
> +EFIAPI
> +AndroidBootAppEntryPoint (
> +  IN EFI_HANDLEImageHandle,
> +  IN EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  EFI_STATUS  Status;
> +  CHAR16  *BootPathStr;
> +  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;
> +  EFI_DEVICE_PATH *DevicePath;
> +  EFI_BLOCK_IO_PROTOCOL   *BlockIo;
> +  UINT32  MediaId, BlockSize;
> +  VOID*Buffer;
> +  EFI_HANDLE  Handle;
> +  UINTN   BootImgSize;
> +
> +  BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);
> +  ASSERT (BootPathStr != NULL);
> +  Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL,
> +(VOID **)&EfiDevicePathFromTextProtocol);
> +  ASSERT_EFI_ERROR(Status);
> +  DevicePath = (EFI_DEVICE_PATH 
> *)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr);
> +  ASSERT (DevicePath != NULL);
> +
> +  Status = ValidateAndroidMediaDevicePath (DevicePath);
> +  if (EFI_ERROR (Status)) {
> +return Status;
> +  }
> +
> +  Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid,
> +  &DevicePath, &Handle);
> +  if (EFI_ERROR (Status)) {
> +return Status;
> +  }
> +
> +  Status = gBS->OpenProtocol (
> +  Handle,
> +  &gEfiBlockIoProtocolGuid,
> +  (VOID **) &BlockIo,
> +  gImageHandle,
> +  NULL,
> +  EFI_OPEN_PROTOCOL_GET_PROTOCOL
> +  );
> +  if (EFI_ERROR (Status)) {
> +DEBUG ((EFI_D_ERROR, "Failed to get BlockIo: %r\n", Status));

BaseTools/Scripts/PatchCheck.py warns about this and other occurrences
of EFI_D_*:
 * EFI_D_ERROR was used, but DEBUG_ERROR is now recommended

Can you update all occurrences of this on added or modified lines to
DEBUG_*?

> +return Status;
> +  }
> +
> +  MediaId = BlockIo->Medi

Re: [edk2] issue about booting centos fail with edk2

2017-08-01 Thread Laszlo Ersek
On 08/01/17 10:34, Zhu Yijun wrote:
> Thanks for your reply!
> 
> On 2017/8/1 3:02, Laszlo Ersek wrote:
>> On 07/31/17 02:27, Zhu Yijun wrote:
>>> Hi all,
>>>  
>>> I install a CentOS-7-aarch64 guest img by qemu cdrom, but it hung at 
>>> UEFI probability.
>>> 
>>> Basic info:
>>> libvirt 1.3.5
>>> QEMU 2.6.2
>>> UEFI: master branch with commit "688c7d2 BaseTools: Fix the bug that 
>>> warn() function with only 1 argument"
>>> 
>>> Config pflash and two disks in xml:
>>> 
>>> ...
>>> 
>>> hvm
>>> >> type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw
>>> 
>>>   
>>>   ...
>>>   
>>>   
>>>   
>>>   
>>>   
>>> 
>>> 
>>>   
>>>   
>>>   
>>>   
>>> 
>>> ...
>>> 
>>> I found it failed at "Match (Translated, TranslatedSize, 
>>> ActiveOption[Idx].BootOption->FilePath)" function in 
>>> "SetBootOrderFromQemu", the UEFI debug info as follow:
>> No, that's not where the problem is. See below:
>>
>>> start-console-fail.log
>>> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
>>> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
>>>
>>>
>>> Synchronous Exception at 0x0002384B1104
>>> PC 0x0002384B1104
>>> PC 0x0002384A916C
>>> PC 0x0002384CA2D0
>>> PC 0x00023EEB7DF8 (0x00023EEB1000+0x6DF8) [ 1] DxeCore.dll
>>> PC 0x00023BD1568C (0x00023BD02000+0x0001368C) [ 2] BdsDxe.dll
>>> PC 0x00023BD03F98 (0x00023BD02000+0x1F98) [ 2] BdsDxe.dll
>>> PC 0x00023BD05640 (0x00023BD02000+0x3640) [ 2] BdsDxe.dll
>>> PC 0x00023EEB3704 (0x00023EEB1000+0x2704) [ 3] DxeCore.dll
>>> PC 0x00023EEB27C8 (0x00023EEB1000+0x17C8) [ 3] DxeCore.dll
>>> PC 0x00023EEB2024 (0x00023EEB1000+0x1024) [ 3] DxeCore.dll
>>> [ 1] 
>>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>>> [ 2] 
>>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>>> [ 3] 
>>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>>>
>>>   X0 0x0002384A9000   X1 0x0002384B2990   X2 0x00023AAFDF98   
>>> X3 0x00023BFF0018
>>>   X4 0x   X5 0x0007   X6 0x000238533300   
>>> X7 0x
>>>   X8 0x00023C01F548   X9 0x0002  X10 0x0002384A8000  
>>> X11 0x0002384C5FFF
>>>  X12 0x  X13 0x0008  X14 0x259511BDAEB1F36C  
>>> X15 0x1378CC1DF3F5DDBB
>>>  X16 0x00023EEB0BE0  X17 0x  X18 0x  
>>> X19 0x0013
>>>  X20 0x  X21 0x  X22 0x  
>>> X23 0x
>>>  X24 0x  X25 0x  X26 0x  
>>> X27 0x
>>>  X28 0x   FP 0x00023EEB0A40   LR 0x0002384A916C  
>>>
>>>   V0 0xAFAFAFAFAFAFAFAF AFAFAFAFAFAFAFAF   V1 0x63702F66 
>>> 
>>>   V2 0x40697363732F3340 6567646972622D69   V3 0x 
>>> 
>>>   V4 0x    V5 0x4010040140100401 
>>> 4010040140100401
>>>   V6 0x    V7 0x 
>>> 
>>>   V8 0x    V9 0x 
>>> 
>>>  V10 0x   V11 0x 
>>> 
>>>  V12 0x   V13 0x 
>>> 
>>>  V14 0x   V15 0x 
>>> 
>>>  V16 0x   V17 0x 
>>> 
>>>  V18 0x   V19 0x 
>>> 
>>>  V20 0x   V21 0x 
>>> 
>>>  V22 0x   V23 0x 
>>> 
>>>  V24 0x   V25 0x 
>>> 
>>>  V26 0x   V27 0x 
>>> 
>>>  V28 0x   V29 0x 
>>> 
>>>  V30 0x   V31 0x 
>>> 
>>>
>>>   SP 0x00023EEB0A40  ELR 0x0002384B1104  SPSR 0x6205  FPSR 
>>> 0x
>>>  ESR 0x0200  FAR 0x1DE7EC7EDBADC0DE
>>>
>>>  ESR : EC 0x00  IL 0x1  ISS 0x
>>>
>>> Stack dump:
>>>   23EEB0940: C0E00148 0002384A9000 0002384CA254 
>>> 
>>>   23EEB0960: 00023EEB0BC0 00023AC006C0 F2503EEB0BC0 
>>> 0002384B6018
>>>   23EEB0980: 00023EEB0BC0  C0E0 
>>> 0148
>>>   23EEB09A0: 0148 10020A8C 00023

Re: [edk2] [PATCH v4 2/4] EmbeddedPkg/AndroidFastboot: split android boot header

2017-08-01 Thread Leif Lindholm
On Tue, Aug 01, 2017 at 05:28:59PM +0800, Jun Nie wrote:
> Split android boot header definition to share code among
> different applications and libraries.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jun Nie 
> ---
>  .../Application/AndroidFastboot/AndroidBootImg.c   | 35 +++
>  .../AndroidFastboot/AndroidFastbootApp.h   |  1 +
>  .../AndroidFastboot/Arm/BootAndroidBootImg.c   |  2 +-
>  EmbeddedPkg/Include/Library/AndroidBootImgLib.h| 50 
> ++
>  4 files changed, 57 insertions(+), 31 deletions(-)
>  create mode 100644 EmbeddedPkg/Include/Library/AndroidBootImgLib.h
> 
> diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c 
> b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
> index f3e770b..2f7f093 100644
> --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
> +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
> @@ -14,32 +14,6 @@
>  
>  #include "AndroidFastbootApp.h"
>  
> -#define BOOT_MAGIC"ANDROID!"
> -#define BOOT_MAGIC_LENGTH sizeof (BOOT_MAGIC) - 1
> -
> -// Check Val (unsigned) is a power of 2 (has only one bit set)
> -#define IS_POWER_OF_2(Val) (Val != 0 && ((Val & (Val - 1)) == 0))
> -
> -// No documentation for this really - sizes of fields has been determined
> -// empirically.
> -#pragma pack(1)
> -typedef struct {
> -  CHAR8   BootMagic[BOOT_MAGIC_LENGTH];
> -  UINT32  KernelSize;
> -  UINT32  KernelAddress;
> -  UINT32  RamdiskSize;
> -  UINT32  RamdiskAddress;
> -  UINT32  SecondStageBootloaderSize;
> -  UINT32  SecondStageBootloaderAddress;
> -  UINT32  KernelTaggsAddress;
> -  UINT32  PageSize;
> -  UINT32  Reserved[2];
> -  CHAR8   ProductName[16];
> -  CHAR8   KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];
> -  UINT32  Id[32];
> -} ANDROID_BOOTIMG_HEADER;
> -#pragma pack()
> -
>  // Find the kernel and ramdisk in an Android boot.img.
>  // return EFI_INVALID_PARAMTER if the boot.img is invalid (i.e. doesn't have 
> the
>  //  right magic value),
> @@ -64,7 +38,8 @@ ParseAndroidBootImg (
>  
>Header = (ANDROID_BOOTIMG_HEADER *) BootImg;
>  
> -  if (AsciiStrnCmp (Header->BootMagic, BOOT_MAGIC, BOOT_MAGIC_LENGTH) != 0) {
> +  if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC,
> +ANDROID_BOOT_MAGIC_LENGTH) != 0) {
>  return EFI_INVALID_PARAMETER;
>}
>  
> @@ -72,7 +47,7 @@ ParseAndroidBootImg (
>  return EFI_NOT_FOUND;
>}
>  
> -  ASSERT (IS_POWER_OF_2 (Header->PageSize));
> +  ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));

So, this change uses the macro that is now only introduced in patch
2/4, and hence this patch breaks bisect.

Could you move this change to 3/4 instead?

>  
>*KernelSize = Header->KernelSize;
>*Kernel = BootImgBytePtr + Header->PageSize;
> @@ -84,8 +59,8 @@ ParseAndroidBootImg (
>   + ALIGN_VALUE (Header->KernelSize, Header->PageSize));
>}
>  
> -  AsciiStrnCpyS (KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs,
> -BOOTIMG_KERNEL_ARGS_SIZE);
> +  AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, 
> Header->KernelArgs,
> +ANDROID_BOOTIMG_KERNEL_ARGS_SIZE);
>  
>return EFI_SUCCESS;
>  }
> diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h 
> b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h
> index f62660f..e4c5aa3 100644
> --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h
> +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h
> @@ -15,6 +15,7 @@
>  #ifndef __ANDROID_FASTBOOT_APP_H__
>  #define __ANDROID_FASTBOOT_APP_H__
>  
> +#include 
>  #include 
>  #include 
>  #include 
> diff --git a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c 
> b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
> index f446cce..1d9024b 100644
> --- a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
> +++ b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
> @@ -112,7 +112,7 @@ BootAndroidBootImg (
>)
>  {
>EFI_STATUS  Status;
> -  CHAR8   KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];
> +  CHAR8   
> KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
>VOID   *Kernel;
>UINTN   KernelSize;
>VOID   *Ramdisk;
> diff --git a/EmbeddedPkg/Include/Library/AndroidBootImgLib.h 
> b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h
> new file mode 100644
> index 000..8116c7c
> --- /dev/null
> +++ b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h
> @@ -0,0 +1,50 @@
> +/** @file
> +
> +  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
> +  Copyright (c) 2017, Linaro.
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD 
> License
> +  which accompanies this distrib

Re: [edk2] [PATCH v4 1/4] ArmPkg: Move IS_DEVICE_PATH_NODE for sharing

2017-08-01 Thread Leif Lindholm
On Tue, Aug 01, 2017 at 05:28:58PM +0800, Jun Nie wrote:
> Move IS_DEVICE_PATH_NODE into header to share it.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jun Nie 

Reviewed-by: Leif Lindholm 
Pushed as edc65fc4d8.

> ---
>  ArmPkg/Include/Library/BdsLib.h | 3 +++
>  ArmPkg/Library/BdsLib/BdsFilePath.c | 3 ---
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/ArmPkg/Include/Library/BdsLib.h b/ArmPkg/Include/Library/BdsLib.h
> index c58f47e..4528c2e 100644
> --- a/ArmPkg/Include/Library/BdsLib.h
> +++ b/ArmPkg/Include/Library/BdsLib.h
> @@ -15,6 +15,9 @@
>  #ifndef __BDS_ENTRY_H__
>  #define __BDS_ENTRY_H__
>  
> +#define IS_DEVICE_PATH_NODE(node,type,subtype)\
> +(((node)->Type == (type)) && ((node)->SubType == (subtype)))
> +
>  /**
>This is defined by the UEFI specs, don't change it
>  **/
> diff --git a/ArmPkg/Library/BdsLib/BdsFilePath.c 
> b/ArmPkg/Library/BdsLib/BdsFilePath.c
> index f9d8c4c..41557bb 100644
> --- a/ArmPkg/Library/BdsLib/BdsFilePath.c
> +++ b/ArmPkg/Library/BdsLib/BdsFilePath.c
> @@ -24,9 +24,6 @@
>  #include 
>  #include 
>  
> -
> -#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && 
> ((node)->SubType == (subtype)))
> -
>  /* Type and defines to set up the DHCP4 options */
>  
>  typedef struct {
> -- 
> 1.9.1
> 
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/DisplayEngine: Fix incorrect display issue

2017-08-01 Thread Dandan Bi
In a form, some new menus may be dynamically inserted between highlight
menu and previous top of screen menu when some question are refreshed.
So the highlight menu and previous top of screen menu perhaps can't be
shown in one page. Existing codes miss to handle this case then will
cause incorrect display.This patch is to fix this display issue.

Cc: Eric Dong 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi 
---
 .../Universal/DisplayEngineDxe/FormDisplay.c   | 43 +++---
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c 
b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
index dc4ae4b..f4025e9 100644
--- a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
+++ b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
@@ -1759,10 +1759,41 @@ FindTopOfScreenMenuOption (
 
   return NewPos;
 }
 
 /**
+  Calculate the distance between two menus and include the skip value of 
StartMenu.
+
+  @param  StartMenu The link_entry pointer to startt menu.
+  @param  EndMenu   The link_entry pointer to end menu.
+
+**/
+UINTN
+GetDistanceBetweenMenus(
+  IN LIST_ENTRY  *StartMenu,
+  IN LIST_ENTRY  *EndMenu
+)
+{
+  LIST_ENTRY *Link;
+  UI_MENU_OPTION *MenuOption;
+  UINTN  Distance;
+
+  Distance = 0;
+
+  Link = StartMenu;
+  while (Link != EndMenu) {
+MenuOption = MENU_OPTION_FROM_LINK (Link);
+if (MenuOption->Row == 0) {
+  UpdateOptionSkipLines (MenuOption);
+}
+Distance += MenuOption->Skip;
+Link = Link->BackLink;
+  }
+  return Distance;
+}
+
+/**
   Find the first menu which will be show at the top.
 
   @param  FormData   The data info for this form.
   @param  TopOfScreenThe link_entry pointer to top menu.
   @param  HighlightMenu  The menu which will be highlight.
@@ -1804,25 +1835,25 @@ FindTopMenu (
 
   //
   // Found the last time highlight menu.
   //
   *TopOfScreen = FindTopOfScreenMenuOption();
-  if (*TopOfScreen != NULL) {
+  if (*TopOfScreen != NULL && (GetDistanceBetweenMenus 
(*HighlightMenu,*TopOfScreen) + 1 <= BottomRow - TopRow)) {
 //
-// Found the last time selectable top of screen menu.
+// Found the last time selectable top of screen menu, and the 
highlight menu and top of screen menu or part of the screen menu can be shown 
in one page.
 //
 AdjustDateAndTimePosition(TRUE, TopOfScreen);
 MenuOption = MENU_OPTION_FROM_LINK (*TopOfScreen);
 UpdateOptionSkipLines (MenuOption);
 
 *SkipValue = gHighligthMenuInfo.SkipValue;
   } else {
 //
-// Not found last time top of screen menu, so base on current 
highlight menu
-// to find the new top of screen menu.
-// Make the current highlight menu at the bottom of the form to 
calculate the
-// top of screen menu.
+// Case1:not found last time top of screen menu.
+// Case2:the distance between highlight menu and top of screen menu 
are beyond the screen scope, such as some menus are inserted when question is 
refreshed.
+// so base on current highlight menu to find the new top of screen 
menu.
+// Make the current highlight menu at the bottom of the form to 
calculate the top of screen menu.
 //
 if (MenuOption->Skip >= BottomRow - TopRow) {
   *TopOfScreen = *HighlightMenu;
   TmpValue = 0;
 } else {
-- 
1.9.5.msysgit.1

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


[edk2] [PATCH v4 4/4] EmbeddedPkg: add Android boot device path and guid

2017-08-01 Thread Jun Nie
The device path specifies where to load android boot image.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jun Nie 
---
 EmbeddedPkg/EmbeddedPkg.dec | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec
index 4cd528a..8ad2a84 100644
--- a/EmbeddedPkg/EmbeddedPkg.dec
+++ b/EmbeddedPkg/EmbeddedPkg.dec
@@ -80,6 +80,7 @@
   gAndroidFastbootPlatformProtocolGuid =  { 0x524685a0, 0x89a0, 0x11e3, {0x9d, 
0x4d, 0xbf, 0xa9, 0xf6, 0xa4, 0x03, 0x08}}
   gUsbDeviceProtocolGuid =  { 0x021bd2ca, 0x51d2, 0x11e3, {0x8e, 0x56, 0xb7, 
0x54, 0x17, 0xc7,  0x0b, 0x44 }}
   gPlatformGpioProtocolGuid = { 0x52ce9845, 0x5af4, 0x43e2, {0xba, 0xfd, 0x23, 
0x08, 0x12, 0x54, 0x7a, 0xc2 }}
+  gAndroidBootImgProtocolGuid = { 0x9859bb19, 0x407c, 0x4f8b, {0xbc, 0xe1, 
0xf8, 0xda, 0x65, 0x65, 0xf4, 0xa5 }}
 
 [PcdsFeatureFlag.common]
   gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|FALSE|BOOLEAN|0x0001
@@ -181,6 +182,7 @@
   
gEmbeddedTokenSpaceGuid.PcdAndroidFastbootUsbProductId|0xbeef|UINT32|0x0023
   gEmbeddedTokenSpaceGuid.PcdAndroidFastbootTcpPort|1234|UINT32|0x0024
 
+  gEmbeddedTokenSpaceGuid.PcdAndroidBootDevicePath|L""|VOID*|0x0057
 
 [PcdsFixedAtBuild.ARM]
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|32|UINT8|0x0010
-- 
1.9.1

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


[edk2] [PATCH v4 2/4] EmbeddedPkg/AndroidFastboot: split android boot header

2017-08-01 Thread Jun Nie
Split android boot header definition to share code among
different applications and libraries.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jun Nie 
---
 .../Application/AndroidFastboot/AndroidBootImg.c   | 35 +++
 .../AndroidFastboot/AndroidFastbootApp.h   |  1 +
 .../AndroidFastboot/Arm/BootAndroidBootImg.c   |  2 +-
 EmbeddedPkg/Include/Library/AndroidBootImgLib.h| 50 ++
 4 files changed, 57 insertions(+), 31 deletions(-)
 create mode 100644 EmbeddedPkg/Include/Library/AndroidBootImgLib.h

diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c 
b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
index f3e770b..2f7f093 100644
--- a/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
+++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
@@ -14,32 +14,6 @@
 
 #include "AndroidFastbootApp.h"
 
-#define BOOT_MAGIC"ANDROID!"
-#define BOOT_MAGIC_LENGTH sizeof (BOOT_MAGIC) - 1
-
-// Check Val (unsigned) is a power of 2 (has only one bit set)
-#define IS_POWER_OF_2(Val) (Val != 0 && ((Val & (Val - 1)) == 0))
-
-// No documentation for this really - sizes of fields has been determined
-// empirically.
-#pragma pack(1)
-typedef struct {
-  CHAR8   BootMagic[BOOT_MAGIC_LENGTH];
-  UINT32  KernelSize;
-  UINT32  KernelAddress;
-  UINT32  RamdiskSize;
-  UINT32  RamdiskAddress;
-  UINT32  SecondStageBootloaderSize;
-  UINT32  SecondStageBootloaderAddress;
-  UINT32  KernelTaggsAddress;
-  UINT32  PageSize;
-  UINT32  Reserved[2];
-  CHAR8   ProductName[16];
-  CHAR8   KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];
-  UINT32  Id[32];
-} ANDROID_BOOTIMG_HEADER;
-#pragma pack()
-
 // Find the kernel and ramdisk in an Android boot.img.
 // return EFI_INVALID_PARAMTER if the boot.img is invalid (i.e. doesn't have 
the
 //  right magic value),
@@ -64,7 +38,8 @@ ParseAndroidBootImg (
 
   Header = (ANDROID_BOOTIMG_HEADER *) BootImg;
 
-  if (AsciiStrnCmp (Header->BootMagic, BOOT_MAGIC, BOOT_MAGIC_LENGTH) != 0) {
+  if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC,
+ANDROID_BOOT_MAGIC_LENGTH) != 0) {
 return EFI_INVALID_PARAMETER;
   }
 
@@ -72,7 +47,7 @@ ParseAndroidBootImg (
 return EFI_NOT_FOUND;
   }
 
-  ASSERT (IS_POWER_OF_2 (Header->PageSize));
+  ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
 
   *KernelSize = Header->KernelSize;
   *Kernel = BootImgBytePtr + Header->PageSize;
@@ -84,8 +59,8 @@ ParseAndroidBootImg (
  + ALIGN_VALUE (Header->KernelSize, Header->PageSize));
   }
 
-  AsciiStrnCpyS (KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs,
-BOOTIMG_KERNEL_ARGS_SIZE);
+  AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, 
Header->KernelArgs,
+ANDROID_BOOTIMG_KERNEL_ARGS_SIZE);
 
   return EFI_SUCCESS;
 }
diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h 
b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h
index f62660f..e4c5aa3 100644
--- a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h
+++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.h
@@ -15,6 +15,7 @@
 #ifndef __ANDROID_FASTBOOT_APP_H__
 #define __ANDROID_FASTBOOT_APP_H__
 
+#include 
 #include 
 #include 
 #include 
diff --git a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c 
b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
index f446cce..1d9024b 100644
--- a/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
+++ b/EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
@@ -112,7 +112,7 @@ BootAndroidBootImg (
   )
 {
   EFI_STATUS  Status;
-  CHAR8   KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];
+  CHAR8   
KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
   VOID   *Kernel;
   UINTN   KernelSize;
   VOID   *Ramdisk;
diff --git a/EmbeddedPkg/Include/Library/AndroidBootImgLib.h 
b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h
new file mode 100644
index 000..8116c7c
--- /dev/null
+++ b/EmbeddedPkg/Include/Library/AndroidBootImgLib.h
@@ -0,0 +1,50 @@
+/** @file
+
+  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
+  Copyright (c) 2017, Linaro.
+
+  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 __ABOOTIMG_H__
+#define __ABOOTIMG_H__
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define ANDROID_BOOTIMG_KERNEL_ARGS_SIZE  512
+
+#define ANDROID_BOOT_MAGIC   

[edk2] [PATCH v4 1/4] ArmPkg: Move IS_DEVICE_PATH_NODE for sharing

2017-08-01 Thread Jun Nie
Move IS_DEVICE_PATH_NODE into header to share it.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jun Nie 
---
 ArmPkg/Include/Library/BdsLib.h | 3 +++
 ArmPkg/Library/BdsLib/BdsFilePath.c | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ArmPkg/Include/Library/BdsLib.h b/ArmPkg/Include/Library/BdsLib.h
index c58f47e..4528c2e 100644
--- a/ArmPkg/Include/Library/BdsLib.h
+++ b/ArmPkg/Include/Library/BdsLib.h
@@ -15,6 +15,9 @@
 #ifndef __BDS_ENTRY_H__
 #define __BDS_ENTRY_H__
 
+#define IS_DEVICE_PATH_NODE(node,type,subtype)\
+(((node)->Type == (type)) && ((node)->SubType == (subtype)))
+
 /**
   This is defined by the UEFI specs, don't change it
 **/
diff --git a/ArmPkg/Library/BdsLib/BdsFilePath.c 
b/ArmPkg/Library/BdsLib/BdsFilePath.c
index f9d8c4c..41557bb 100644
--- a/ArmPkg/Library/BdsLib/BdsFilePath.c
+++ b/ArmPkg/Library/BdsLib/BdsFilePath.c
@@ -24,9 +24,6 @@
 #include 
 #include 
 
-
-#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && 
((node)->SubType == (subtype)))
-
 /* Type and defines to set up the DHCP4 options */
 
 typedef struct {
-- 
1.9.1

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


[edk2] [PATCH v4 3/4] EmbeddedPkg/AndroidBoot: boot android kernel from storage

2017-08-01 Thread Jun Nie
Add an android kernel loader that could load kernel from storage
device. This patch is derived from Haojian's code as below link.
https://patches.linaro.org/patch/94683/

This android boot image BDS add addtitional cmdline/dtb/ramfs
support besides kernel that is introduced by Android boot header.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jun Nie 
---
 .../Application/AndroidBoot/AndroidBootApp.c   | 140 +++
 .../Application/AndroidBoot/AndroidBootApp.inf |  64 +++
 EmbeddedPkg/Include/Library/AndroidBootImgLib.h|  17 +
 EmbeddedPkg/Include/Protocol/AndroidBootImg.h  |  47 +++
 .../Library/AndroidBootImgLib/AndroidBootImgLib.c  | 444 +
 .../AndroidBootImgLib/AndroidBootImgLib.inf|  48 +++
 6 files changed, 760 insertions(+)
 create mode 100644 EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
 create mode 100644 EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.inf
 create mode 100644 EmbeddedPkg/Include/Protocol/AndroidBootImg.h
 create mode 100644 EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
 create mode 100644 EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf

diff --git a/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c 
b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
new file mode 100644
index 000..5069819
--- /dev/null
+++ b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
@@ -0,0 +1,140 @@
+/** @file
+
+  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
+  Copyright (c) 2017, Linaro. 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 
+
+/* Validate the node is media hard drive type */
+EFI_STATUS
+ValidateAndroidMediaDevicePath (
+  IN EFI_DEVICE_PATH  *DevicePath
+  )
+{
+  EFI_DEVICE_PATH_PROTOCOL*Node, *NextNode;
+
+  NextNode = DevicePath;
+  while (NextNode != NULL) {
+Node = NextNode;
+if (IS_DEVICE_PATH_NODE (Node, MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP)) {
+  return EFI_SUCCESS;
+}
+NextNode = NextDevicePathNode (Node);
+  }
+  return EFI_INVALID_PARAMETER;
+}
+
+EFI_STATUS
+EFIAPI
+AndroidBootAppEntryPoint (
+  IN EFI_HANDLEImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+  CHAR16  *BootPathStr;
+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;
+  EFI_DEVICE_PATH *DevicePath;
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;
+  UINT32  MediaId, BlockSize;
+  VOID*Buffer;
+  EFI_HANDLE  Handle;
+  UINTN   BootImgSize;
+
+  BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);
+  ASSERT (BootPathStr != NULL);
+  Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL,
+(VOID **)&EfiDevicePathFromTextProtocol);
+  ASSERT_EFI_ERROR(Status);
+  DevicePath = (EFI_DEVICE_PATH 
*)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr);
+  ASSERT (DevicePath != NULL);
+
+  Status = ValidateAndroidMediaDevicePath (DevicePath);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid,
+  &DevicePath, &Handle);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  Status = gBS->OpenProtocol (
+  Handle,
+  &gEfiBlockIoProtocolGuid,
+  (VOID **) &BlockIo,
+  gImageHandle,
+  NULL,
+  EFI_OPEN_PROTOCOL_GET_PROTOCOL
+  );
+  if (EFI_ERROR (Status)) {
+DEBUG ((EFI_D_ERROR, "Failed to get BlockIo: %r\n", Status));
+return Status;
+  }
+
+  MediaId = BlockIo->Media->MediaId;
+  BlockSize = BlockIo->Media->BlockSize;
+  Buffer = AllocatePages (EFI_SIZE_TO_PAGES (sizeof(ANDROID_BOOTIMG_HEADER)));
+  if (Buffer == NULL) {
+return EFI_BUFFER_TOO_SMALL;
+  }
+  /* Load header of boot.img */
+  Status = BlockIo->ReadBlocks (
+  BlockIo,
+  MediaId,
+  0,
+  BlockSize,
+  Buffer
+  );
+  Status = AndroidBootImgGetImgSize (Buffer, &BootImgSize);
+  if (EFI_ERROR (Status)) {
+DEBUG ((EFI_D_ERROR, "Failed to get AndroidBootImg Size: %r\n", Status));
+retu

Re: [edk2] [PATCH 0/3] Add SecPerformancePpiCallBack to get SEC performance data in SecCore

2017-08-01 Thread Gao, Liming
Reviewed-by: Liming Gao 

>-Original Message-
>From: Zeng, Star
>Sent: Monday, July 31, 2017 11:32 AM
>To: edk2-devel@lists.01.org
>Cc: Zeng, Star ; Gao, Liming ;
>Fan, Jeff 
>Subject: [PATCH 0/3] Add SecPerformancePpiCallBack to get SEC performance
>data in SecCore
>
>Current SEC performance data getting code in FirmwarePerformancePei
>may get wrong SEC performance data if FirmwarePerformancePei executes
>after memory discovered, it can be removed after
>SecPerformancePpiCallBack
>is added in SecCore.
>
>Cc: Liming Gao 
>Cc: Jeff Fan 
>
>Star Zeng (3):
>  UefiCpuPkg SecCore: Adjust PeiTemporaryRamBase&Size to be 8byte
>aligned
>  UefiCpuPkg SecCore: Add SecPerformancePpiCallBack
>  MdeModulePkg FirmwarePerfPei: Remove SEC performance data getting
>code
>
> .../FirmwarePerformancePei.c   | 39 ++--
> .../FirmwarePerformancePei.inf |  9 +---
> .../FirmwarePerformancePei.uni |  6 +--
> UefiCpuPkg/SecCore/SecCore.inf |  7 +++
> UefiCpuPkg/SecCore/SecMain.c   | 53 +-
> UefiCpuPkg/SecCore/SecMain.h   | 25 +-
> 6 files changed, 89 insertions(+), 50 deletions(-)
>
>--
>2.7.0.windows.1

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


[edk2] Fw: USB Drivers' Asynchronous Transfer Timer Interval

2017-08-01 Thread Alexei Fedorov

Hi,


All USB asynchronous transfer timer intervals defined in Ehci.h, Uhci.h and 
Xhci.h are set to 1ms value as below:


#define EHC_ASYNC_POLL_INTERVAL  EFI_TIMER_PERIOD_MILLISECONDS(1)

#define UHC_ASYNC_POLL_INTERVAL   EFI_TIMER_PERIOD_MILLISECONDS(1)

#define XHC_ASYNC_TIMER_INTERVAL EFI_TIMER_PERIOD_MILLISECONDS(1)


are used to  start the asynchronous interrupt monitor as:

  Status = gBS->SetTimer (Xhc->PollTimer, TimerPeriodic, 
XHC_ASYNC_TIMER_INTERVAL);


, but all h/w platforms, except Hisilicon from OpenPlatformPkg either use 
default PcdTimerPeriod

gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10

from EmbeddedPkg or redefine the same 10 value (e.g. BeagleBoardPkg) which 
gives Timer Interrupt period of 10ms in which case the polling interval will be 
also 10ms but not 1ms as desinged.


There are other cases when TimerPeriodic event is set with 1ms period, see:

edk2\MdeModulePkg\Bus\Ata\AtaAtapiPassThru\AtaAtapiPassThru.c:

  //
  // Set 1ms timer.
  //
  Status = gBS->SetTimer (Instance->TimerEvent, TimerPeriodic, 1);


edk2\MdeModulePkg\Bus\Pci\NvmExpressDxe\NvmExpress.h:
//
// Nvme async transfer timer interval, set by experience.
//
#define NVME_HC_ASYNC_TIMER   EFI_TIMER_PERIOD_MILLISECONDS 
(1)

edk2\MdeModulePkg\Bus\Pci\SdMmcPciHcDxe\SdMmcPciHcDxe.h:
//
// SD/MMC async transfer timer interval, set by experience.
// The unit is 100us, takes 1ms as interval.
//
#define SD_MMC_HC_ASYNC_TIMER   EFI_TIMER_PERIOD_MILLISECONDS(1)

, etc.


Any comments on that?


Alexei.



IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] issue about booting centos fail with edk2

2017-08-01 Thread Zhu Yijun
Thanks for your reply!

On 2017/8/1 3:02, Laszlo Ersek wrote:
> On 07/31/17 02:27, Zhu Yijun wrote:
>> Hi all,
>>  
>> I install a CentOS-7-aarch64 guest img by qemu cdrom, but it hung at 
>> UEFI probability.
>> 
>> Basic info:
>> libvirt 1.3.5
>> QEMU 2.6.2
>> UEFI: master branch with commit "688c7d2 BaseTools: Fix the bug that 
>> warn() function with only 1 argument"
>> 
>> Config pflash and two disks in xml:
>> 
>> ...
>> 
>> hvm
>> > type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw
>> 
>>   
>>   ...
>>   
>>   
>>   
>>   
>>   
>> 
>> 
>>   
>>   
>>   
>>   
>> 
>> ...
>> 
>> I found it failed at "Match (Translated, TranslatedSize, 
>> ActiveOption[Idx].BootOption->FilePath)" function in "SetBootOrderFromQemu", 
>> the UEFI debug info as follow:
> No, that's not where the problem is. See below:
>
>> start-console-fail.log
>> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
>> FSOpen: Open '\EFI\BOOT\fallback.efi' Success
>>
>>
>> Synchronous Exception at 0x0002384B1104
>> PC 0x0002384B1104
>> PC 0x0002384A916C
>> PC 0x0002384CA2D0
>> PC 0x00023EEB7DF8 (0x00023EEB1000+0x6DF8) [ 1] DxeCore.dll
>> PC 0x00023BD1568C (0x00023BD02000+0x0001368C) [ 2] BdsDxe.dll
>> PC 0x00023BD03F98 (0x00023BD02000+0x1F98) [ 2] BdsDxe.dll
>> PC 0x00023BD05640 (0x00023BD02000+0x3640) [ 2] BdsDxe.dll
>> PC 0x00023EEB3704 (0x00023EEB1000+0x2704) [ 3] DxeCore.dll
>> PC 0x00023EEB27C8 (0x00023EEB1000+0x17C8) [ 3] DxeCore.dll
>> PC 0x00023EEB2024 (0x00023EEB1000+0x1024) [ 3] DxeCore.dll
>> [ 1] 
>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>> [ 2] 
>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
>> [ 3] 
>> /root/rpmbuild/BUILD/edk2-2.6.0/Build/ArmVirtQemu-AARCH64/DEBUG_GCC49/AARCH64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
>>
>>   X0 0x0002384A9000   X1 0x0002384B2990   X2 0x00023AAFDF98   X3 
>> 0x00023BFF0018
>>   X4 0x   X5 0x0007   X6 0x000238533300   X7 
>> 0x
>>   X8 0x00023C01F548   X9 0x0002  X10 0x0002384A8000  X11 
>> 0x0002384C5FFF
>>  X12 0x  X13 0x0008  X14 0x259511BDAEB1F36C  X15 
>> 0x1378CC1DF3F5DDBB
>>  X16 0x00023EEB0BE0  X17 0x  X18 0x  X19 
>> 0x0013
>>  X20 0x  X21 0x  X22 0x  X23 
>> 0x
>>  X24 0x  X25 0x  X26 0x  X27 
>> 0x
>>  X28 0x   FP 0x00023EEB0A40   LR 0x0002384A916C  
>>
>>   V0 0xAFAFAFAFAFAFAFAF AFAFAFAFAFAFAFAF   V1 0x63702F66 
>> 
>>   V2 0x40697363732F3340 6567646972622D69   V3 0x 
>> 
>>   V4 0x    V5 0x4010040140100401 
>> 4010040140100401
>>   V6 0x    V7 0x 
>> 
>>   V8 0x    V9 0x 
>> 
>>  V10 0x   V11 0x 
>> 
>>  V12 0x   V13 0x 
>> 
>>  V14 0x   V15 0x 
>> 
>>  V16 0x   V17 0x 
>> 
>>  V18 0x   V19 0x 
>> 
>>  V20 0x   V21 0x 
>> 
>>  V22 0x   V23 0x 
>> 
>>  V24 0x   V25 0x 
>> 
>>  V26 0x   V27 0x 
>> 
>>  V28 0x   V29 0x 
>> 
>>  V30 0x   V31 0x 
>> 
>>
>>   SP 0x00023EEB0A40  ELR 0x0002384B1104  SPSR 0x6205  FPSR 
>> 0x
>>  ESR 0x0200  FAR 0x1DE7EC7EDBADC0DE
>>
>>  ESR : EC 0x00  IL 0x1  ISS 0x
>>
>> Stack dump:
>>   23EEB0940: C0E00148 0002384A9000 0002384CA254 
>> 
>>   23EEB0960: 00023EEB0BC0 00023AC006C0 F2503EEB0BC0 
>> 0002384B6018
>>   23EEB0980: 00023EEB0BC0  C0E0 
>> 0148
>>   23EEB09A0: 0148 10020A8C 0002384B6110 
>> 0002384B6108
>>   23EEB09C0: 0002384B6100 0006 0002384B6058 
>> 0002384B50DF
>>   23EEB09E0: 0002384A9148 000

Re: [edk2] [PATCH v1 1/1] ShellPkg/Ifconfig6: Update error message and add a new line

2017-08-01 Thread Subramanian, Sriram
Reviewed-by: Sriram Subramanian 

-Original Message-
From: Hegde, Nagaraj P 
Sent: Tuesday, August 1, 2017 11:18 AM
To: edk2-devel@lists.01.org
Cc: jaben.car...@intel.com; Subramanian, Sriram ; 
ruiyu...@intel.com; jiaxin...@intel.com
Subject: [PATCH v1 1/1] ShellPkg/Ifconfig6: Update error message and add a new 
line

If DAD failed, we print "It failed to set", print the IPv6
address and exit. We need a better error string
and also, after printing the IPv6 address, we need a new line
else the Shell> prompt will overwrite the IPv6 address. Fixed
these issues in this patch.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hegde Nagaraj P 
---
 ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c  
| 2 ++
 ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.uni 
| 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c 
b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c
index 6d8df8031b..a25d4e5d00 100644
--- a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c
+++ b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c
@@ -2,6 +2,7 @@
   The implementation for Shell command IfConfig6.
 
   Copyright (c) 2016, Intel Corporation. All rights reserved.
+  (C) Copyright 2017 Hewlett Packard Enterprise Development LP
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -1490,6 +1491,7 @@ IfConfig6SetInterfaceInfo (
 &CfgManAddr[Index].Address,
 &CfgManAddr[Index].PrefixLength
 );
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN 
(STR_IFCONFIG6_INFO_NEWLINE), gShellNetwork2HiiHandle);
 }
   }
 
diff --git 
a/ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.uni
 
b/ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.uni
index 5c0fef0ff7..ee2f28717f 100644
--- 
a/ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.uni
+++ 
b/ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.uni
@@ -2,6 +2,7 @@
 
   String definitions for UEFI Shell network 2 commands
   Copyright (c) 2016, Intel Corporation. All rights reserved.
+  (C) Copyright 2017 Hewlett Packard Enterprise Development LP
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions
@@ -92,7 +93,7 @@
   "Hint: 
Please type 'IfConfig6 -?' for help info.\r\n"
 #string STR_IFCONFIG6_ERR_UNKNOWN_COMMAND  #language en-US"Unknown 
commands. Bad command %H%s%N is skipped.\r\n"
   "Hint: 
Please type 'IfConfig6 -?' for help info.\r\n"
-#string STR_IFCONFIG6_ERR_ADDRESS_FAILED   #language en-US"It failed 
to set .\r\n"
+#string STR_IFCONFIG6_ERR_ADDRESS_FAILED   #language en-US"Failed to 
configure IPv6 address: "
 
 
 #string STR_GET_HELP_PING6 #language en-US ""
-- 
2.13.0.windows.1

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


Re: [edk2] [Patch] NetworkPkg/Ip6Dxe: Fix the IPv6 PXE boot option goes missing issue

2017-08-01 Thread Subramanian, Sriram
Reviewed-by: Sriram Subramanian 

-Original Message-
From: Jiaxin Wu [mailto:jiaxin...@intel.com] 
Sent: Sunday, July 30, 2017 7:37 PM
To: edk2-devel@lists.01.org
Cc: Hegde, Nagaraj P ; Subramanian, Sriram 
; Ni Ruiyu ; Ye Ting ; 
Fu Siyuan ; Wu Jiaxin 
Subject: [Patch] NetworkPkg/Ip6Dxe: Fix the IPv6 PXE boot option goes missing 
issue

This patch is to fix the potential issue recorded at Bugzilla 636:
https://bugzilla.tianocore.org/show_bug.cgi?id=636

The issue is caused by the IPv6 policy switching after PXEv6 boot. When IP
policy is changing, the IPv6 children used by PXE.UdpRead() will be destroyed.
Then, PXE Stop() function is called to uninstall the devicePath protocol,
which leads to the IPv6 PXE boot option goes missing.

Through the above analysis, the IP driver should take the responsibility for
the upper layer network stacks recovery by using ConnectController().

Cc: Hegde Nagaraj P 
Cc: Subramanian Sriram 
Cc: Ni Ruiyu 
Cc: Ye Ting 
Cc: Fu Siyuan 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin 
---
 NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c | 72 ---
 1 file changed, 53 insertions(+), 19 deletions(-)

diff --git a/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c 
b/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
index 7c7acc7..f170716 100644
--- a/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
+++ b/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
@@ -45,16 +45,21 @@ VOID
 Ip6ConfigOnPolicyChanged (
   IN IP6_SERVICE*IpSb,
   IN EFI_IP6_CONFIG_POLICY  NewPolicy
   )
 {
-  LIST_ENTRY  *Entry;
-  LIST_ENTRY  *Entry2;
-  LIST_ENTRY  *Next;
-  IP6_INTERFACE   *IpIf;
-  IP6_DAD_ENTRY   *DadEntry;
-  IP6_DELAY_JOIN_LIST   *DelayNode;
+  LIST_ENTRY  *Entry;
+  LIST_ENTRY  *Entry2;
+  LIST_ENTRY  *Next;
+  IP6_INTERFACE   *IpIf;
+  IP6_DAD_ENTRY   *DadEntry;
+  IP6_DELAY_JOIN_LIST *DelayNode;
+  IP6_ADDRESS_INFO*AddrInfo;
+  IP6_PROTOCOL*Instance;
+  BOOLEAN Recovery;
+
+  Recovery = FALSE;
   
   //
   // Currently there are only two policies: Manual and Automatic. Regardless of
   // what transition is going on, i.e., Manual -> Automatic and Automatic ->
   // Manual, we have to free default router list, on-link prefix list, 
autonomous
@@ -78,22 +83,52 @@ Ip6ConfigOnPolicyChanged (
   IP6_LINK_LOCAL_PREFIX_LENGTH,
   &IpSb->LinkLocalAddr
   );
   }
 
-  //
-  // All IPv6 children that use global unicast address as it's source address
-  // should be destryoed now. The survivers are those use the link-local 
address
-  // or the unspecified address as the source address.
-  // TODO: Conduct a check here.
-  Ip6RemoveAddr (
-IpSb,
-&IpSb->DefaultInterface->AddressList,
-&IpSb->DefaultInterface->AddressCount,
-NULL,
-0
-);
+  if (!IsListEmpty (&IpSb->DefaultInterface->AddressList) && 
IpSb->DefaultInterface->AddressCount > 0) {
+//  
+// If any IPv6 children (Instance) in configured state and use global 
unicast address, it will be 
+// destroyed in Ip6RemoveAddr() function later. Then, the upper layer 
driver's Stop() function will be 
+// called, which may break the upper layer network stacks. So, the driver 
should take the responsibility 
+// for the recovery by using ConnectController() after Ip6RemoveAddr(). 
+// Here, just check whether need to recover the upper layer network stacks 
later.
+//
+NET_LIST_FOR_EACH (Entry, &IpSb->DefaultInterface->AddressList) { 
+  AddrInfo = NET_LIST_USER_STRUCT_S (Entry, IP6_ADDRESS_INFO, Link, 
IP6_ADDR_INFO_SIGNATURE);
+  if (!IsListEmpty (&IpSb->Children)) {
+NET_LIST_FOR_EACH (Entry2, &IpSb->Children) {
+  Instance = NET_LIST_USER_STRUCT_S (Entry2, IP6_PROTOCOL, Link, 
IP6_PROTOCOL_SIGNATURE);
+  if ((Instance->State == IP6_STATE_CONFIGED) && EFI_IP6_EQUAL 
(&Instance->ConfigData.StationAddress, &AddrInfo->Address)) {
+Recovery = TRUE;
+break;
+  }
+}
+  }
+}
+
+//
+// All IPv6 children that use global unicast address as it's source address
+// should be destroyed now. The survivers are those use the link-local 
address
+// or the unspecified address as the source address.
+// TODO: Conduct a check here.
+Ip6RemoveAddr (
+  IpSb,
+  &IpSb->DefaultInterface->AddressList,
+  &IpSb->DefaultInterface->AddressCount,
+  NULL,
+  0
+  );
+
+if (IpSb->Controller != NULL && Recovery) {
+  //
+  // ConnectController() to recover the upper layer network stacks.
+  //
+  gBS->ConnectController (IpSb->Controller, NULL, NULL, TRUE);
+}
+  }
+
 
   NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
 //
 // remove all pending delay node and DAD entries for the global addresses.
 //
@@ -128,11 +163,10 @@ Ip6ConfigOnPolicyChanged (
 //
 // delay 1 second
 //
 IpSb->Ticks   = (UINT32) IP6_GET_TICKS 
(IP6_ONE_SECOND_

[edk2] [patch] BaseTools/VfrCompile: Remove the MAX_PATH limitation

2017-08-01 Thread Dandan Bi
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=579

Since we have already used LongFilePath() to convert
file path, so we can remove the MAX_PATH limitation.

Cc: Eric Dong 
Cc: Liming Gao 
Cc: Daniel D�az 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi 
---
 BaseTools/Source/C/VfrCompile/EfiVfr.h|  3 +--
 BaseTools/Source/C/VfrCompile/VfrCompiler.cpp | 24 
 2 files changed, 1 insertion(+), 26 deletions(-)

diff --git a/BaseTools/Source/C/VfrCompile/EfiVfr.h 
b/BaseTools/Source/C/VfrCompile/EfiVfr.h
index d187902..10d1257 100644
--- a/BaseTools/Source/C/VfrCompile/EfiVfr.h
+++ b/BaseTools/Source/C/VfrCompile/EfiVfr.h
@@ -1,9 +1,9 @@
 /** @file
 Defines and prototypes for the UEFI VFR compiler internal use.
 
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, 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 
   

   
@@ -17,11 +17,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 
 #include "Common/UefiBaseTypes.h"
 #include "Common/UefiInternalFormRepresentation.h"
 #include "Common/MdeModuleHii.h"
 
-#define MAX_PATH 255
 #define MAX_VFR_LINE_LEN 4096
 
 #define EFI_IFR_MAX_LENGTH   0xFF
 #define MAX_IFR_EXPRESSION_DEPTH 0x9
 
diff --git a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp 
b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
index e65a925..831f6b5 100644
--- a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
+++ b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
@@ -117,14 +117,10 @@ CVfrCompiler::OptionInitialization (
   Index++;
   if ((Index >= Argc) || (Argv[Index][0] == '-')) {
 DebugError (NULL, 0, 1001, "Missing option", "-o missing output 
directory name");
 goto Fail;
   }
-  if (strlen (Argv[Index]) > MAX_PATH - 1) {
-DebugError (NULL, 0, 1003, "Invalid option value", "Output directory 
name %s is too long", Argv[Index]);
-goto Fail;
-  }
 
   mOptions.OutputDirectory = (CHAR8 *) malloc (strlen (Argv[Index]) + 
strlen ("\\") + 1);
   if (mOptions.OutputDirectory == NULL) {
 DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", 
NULL);
 goto Fail;
@@ -184,14 +180,10 @@ CVfrCompiler::OptionInitialization (
 
   if (Index != Argc - 1) {
 DebugError (NULL, 0, 1001, "Missing option", "VFR file name is not 
specified.");
 goto Fail;
   } else {
-if (strlen (Argv[Index]) > MAX_PATH) {
-  DebugError (NULL, 0, 1003, "Invalid option value", "VFR file name %s is 
too long.", Argv[Index]);
-  goto Fail;
-}
 mOptions.VfrFileName = (CHAR8 *) malloc (strlen (Argv[Index]) + 1);
 if (mOptions.VfrFileName == NULL) {
   DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);
   goto Fail;
 }
@@ -353,14 +345,10 @@ CVfrCompiler::SetBaseFileName (
   if ((pExt = strchr (pFileName, '.')) == NULL) {
 return -1;
   }
 
   *pExt = '\0';
-  if (strlen (pFileName) > MAX_PATH - 1) {
-*pExt = '.';
-return -1;
-  }
 
   mOptions.VfrBaseFileName = (CHAR8 *) malloc (strlen (pFileName) + 1);
   if (mOptions.VfrBaseFileName == NULL) {
 *pExt = '.';
 return -1;
@@ -385,13 +373,10 @@ CVfrCompiler::SetPkgOutputFileName (
 
   Length = strlen (mOptions.OutputDirectory) +
strlen (mOptions.VfrBaseFileName) +
strlen (VFR_PACKAGE_FILENAME_EXTENSION) +
1;
-  if (Length > MAX_PATH) {
-return -1;
-  }
 
   mOptions.PkgOutputFileName = (CHAR8 *) malloc (Length);
   if (mOptions.PkgOutputFileName == NULL) {
 return -1;
   }
@@ -416,13 +401,10 @@ CVfrCompiler::SetCOutputFileName (
 
   Length = strlen (mOptions.OutputDirectory) +
strlen (mOptions.VfrBaseFileName) +
strlen (".c") +
1;
-  if (Length > MAX_PATH) {
-return -1;
-  }
 
   mOptions.COutputFileName = (CHAR8 *) malloc (Length);
   if (mOptions.COutputFileName == NULL) {
 return -1;
   }
@@ -447,13 +429,10 @@ CVfrCompiler::SetPreprocessorOutputFileName (
 
   Length = strlen (mOptions.OutputDirectory) +
strlen (mOptions.VfrBaseFileName) +
strlen (VFR_PREPROCESS_FILENAME_EXTENSION) +
1;
-  if (Length > MAX_PATH) {
-return -1;
-  }
 
   mOptions.PreprocessorOutputFileName = (CHAR8 *) malloc (Length);
   if (mOptions.PreprocessorOutputFileName == NULL) {
 return -1;
   }
@@ -478,13 +457,10 @@ CVfrCompiler::SetRecordListFileName (
 
   Length = strlen (mOptions.OutputDirectory) +
strlen (

[edk2] [Patch 2/3] UefiCpuPkg CpuCommonFeaturesLib: Enable LMCE feature.

2017-08-01 Thread Eric Dong
Cc: Jeff Fan 
Cc: Ruiyu Ni 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong 
---
 .../CpuCommonFeaturesLib/CpuCommonFeatures.h   | 56 +-
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c| 12 +++
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf  |  1 +
 UefiCpuPkg/Library/CpuCommonFeaturesLib/Lmce.c | 90 ++
 4 files changed, 157 insertions(+), 2 deletions(-)
 create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/Lmce.c

diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h 
b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
index c03e5ab..67a44c6 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
@@ -866,8 +866,8 @@ FeatureControlGetConfigData (
CPU_FEATURE_GET_CONFIG_DATA was not provided in
RegisterCpuFeature().
 
-  @retval TRUE Enhanced Intel SpeedStep feature is supported.
-  @retval FALSEEnhanced Intel SpeedStep feature is not supported.
+  @retval TRUE Protected Processor Inventory Number feature is supported.
+  @retval FALSEProtected Processor Inventory Number feature is not 
supported.
 
   @note This service could be called by BSP/APs.
 **/
@@ -909,4 +909,56 @@ PpinInitialize (
   IN BOOLEAN   State
   );
 
+/**
+  Detects if Local machine check exception feature supported on current 
+  processor.
+
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.
+  @param[in]  CpuInfo  A pointer to the 
REGISTER_CPU_FEATURE_INFORMATION
+   structure for the CPU executing this function.
+  @param[in]  ConfigData   A pointer to the configuration buffer returned
+   by CPU_FEATURE_GET_CONFIG_DATA.  NULL if
+   CPU_FEATURE_GET_CONFIG_DATA was not provided in
+   RegisterCpuFeature().
+
+  @retval TRUE Local machine check exception feature is supported.
+  @retval FALSELocal machine check exception feature is not supported.
+
+  @note This service could be called by BSP/APs.
+**/
+BOOLEAN
+EFIAPI
+LmceSupport (
+  IN UINTN ProcessorNumber,
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
+  IN VOID  *ConfigData  OPTIONAL
+  );
+
+/**
+  Initializes Local machine check exception feature to specific state.
+
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.
+  @param[in]  CpuInfo  A pointer to the 
REGISTER_CPU_FEATURE_INFORMATION
+   structure for the CPU executing this function.
+  @param[in]  ConfigData   A pointer to the configuration buffer returned
+   by CPU_FEATURE_GET_CONFIG_DATA.  NULL if
+   CPU_FEATURE_GET_CONFIG_DATA was not provided in
+   RegisterCpuFeature().
+  @param[in]  StateIf TRUE, then the Protected Processor Inventory 
+   Number feature must be enabled.
+   If FALSE, then the Protected Processor 
Inventory 
+   Number feature must be disabled.
+
+  @retval RETURN_SUCCESS   Local machine check exception feature is 
initialized.
+
+**/
+RETURN_STATUS
+EFIAPI
+LmceInitialize (
+  IN UINTN ProcessorNumber,
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
+  IN VOID  *ConfigData,  OPTIONAL
+  IN BOOLEAN   State
+  );
+
 #endif
diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c 
b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
index b88b7d1..4c78209 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
@@ -217,6 +217,18 @@ CpuCommonFeaturesLibConstructor (
);
 ASSERT_EFI_ERROR (Status);
   }
+  if (IsCpuFeatureSupported (CPU_FEATURE_LMCE)) {
+Status = RegisterCpuFeature (
+   "LMCE",
+   NULL,
+   LmceSupport,
+   LmceInitialize,
+   CPU_FEATURE_LMCE,
+   CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEFORE,
+   CPU_FEATURE_END
+   );
+ASSERT_EFI_ERROR (Status);
+  }
 
   return RETURN_SUCCESS;
 }
diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf 
b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
index 202d560..2cca58e 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
@@ -48,6 +48,7 @@
   PendingBreak.c
   X2Apic.c
   Ppin.c
+  Lmce.c
 
 [Packages]
   MdePk

[edk2] [Patch 3/3] UefiCpuPkg PiSmmCpuDxeSmm: Check LMCE capability when wait for AP.

2017-08-01 Thread Eric Dong
Cc: Jeff Fan 
Cc: Ruiyu Ni 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong 
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 57 ++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c 
b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 4ac5e8e..6b66c49 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -196,6 +196,56 @@ AllCpusInSmmWithExceptions (
   return TRUE;
 }
 
+/**
+  Has OS enabled Lmce in the MSR_IA32_MCG_EXT_CTL
+  
+  @retval TRUE Os enable lmce.
+  @retval FALSEOs not enable lmce.
+
+**/
+BOOLEAN
+IsLmceOsEnabled (
+  VOID
+  )
+{
+  MSR_IA32_MCG_CAP_REGISTER  McgCap;
+  MSR_IA32_FEATURE_CONTROL_REGISTER  FeatureCtrl;
+  MSR_IA32_MCG_EXT_CTL_REGISTER  McgExtCtrl;
+
+  McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
+  if (McgCap.Bits.MCG_LMCE_P == 0) {
+return FALSE;
+  }
+
+  FeatureCtrl.Uint64 = AsmReadMsr64 (MSR_IA32_FEATURE_CONTROL);
+  if (FeatureCtrl.Bits.LmceOn == 0) {
+return FALSE;
+  }
+
+  McgExtCtrl.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_EXT_CTL);
+  return (BOOLEAN) (McgExtCtrl.Bits.LMCE_EN == 1);
+}
+
+/**
+  Return if Local machine check exception signaled. 
+
+  Indicates (when set) that a local machine check exception was generated. 
This indicates that the current machine-check event was 
+  delivered to only the logical processor.
+
+  @retval TRUELMCE was signaled.
+  @retval FALSE   LMCE was not signaled.
+
+**/
+BOOLEAN
+IsLmceSignaled (
+  VOID
+  )
+{
+  MSR_IA32_MCG_STATUS_REGISTER McgStatus;
+
+  McgStatus.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_STATUS);
+  return (BOOLEAN) (McgStatus.Bits.LMCE_S == 1);
+}
 
 /**
   Given timeout constraint, wait for all APs to arrive, and insure when this 
function returns, no AP will execute normal mode code before
@@ -209,9 +259,14 @@ SmmWaitForApArrival (
 {
   UINT64Timer;
   UINTN Index;
+  BOOLEAN   LmceEn;
+  BOOLEAN   LmceSignal;
 
   ASSERT (*mSmmMpSyncData->Counter <= mNumberOfCpus);
 
+  LmceEn = IsLmceOsEnabled ();
+  LmceSignal = IsLmceSignaled();
+
   //
   // Platform implementor should choose a timeout value appropriately:
   // - The timeout value should balance the SMM time constrains and the 
likelihood that delayed CPUs are excluded in the SMM run. Note
@@ -227,7 +282,7 @@ SmmWaitForApArrival (
   // Sync with APs 1st timeout
   //
   for (Timer = StartSyncTimer ();
-   !IsSyncTimerTimeout (Timer) &&
+   !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal) &&
!AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | 
ARRIVAL_EXCEPTION_SMI_DISABLED );
) {
 CpuPause ();
-- 
2.7.0.windows.1

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


[edk2] [Patch 0/3] Enable LMCE feature

2017-08-01 Thread Eric Dong
This patch series enable local machine check exception feature and 
used it in wait for ap logic.

Eric Dong (3):
  UefiCpuPkg: Add definition for LMCE feature.
  UefiCpuPkg CpuCommonFeaturesLib: Enable LMCE feature.
  UefiCpuPkg PiSmmCpuDxeSmm: Check LMCE capability when wait for AP.

 .../Include/Library/RegisterCpuFeaturesLib.h   |  1 +
 .../CpuCommonFeaturesLib/CpuCommonFeatures.h   | 56 +-
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c| 12 +++
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf  |  1 +
 UefiCpuPkg/Library/CpuCommonFeaturesLib/Lmce.c | 90 ++
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  | 57 +-
 6 files changed, 214 insertions(+), 3 deletions(-)
 create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/Lmce.c

-- 
2.7.0.windows.1

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


[edk2] [Patch 1/3] UefiCpuPkg: Add definition for LMCE feature.

2017-08-01 Thread Eric Dong
Cc: Jeff Fan 
Cc: Ruiyu Ni 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong 
---
 UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h 
b/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
index 8ea0609..54153f4 100644
--- a/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
+++ b/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
@@ -35,6 +35,7 @@
 #define CPU_FEATURE_FASTSTRINGS 6
 #define CPU_FEATURE_VMX 7
 #define CPU_FEATURE_SMX 8
+#define CPU_FEATURE_LMCE9
 #define CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER   10
 #define CPU_FEATURE_LIMIT_CPUID_MAX_VAL 11
 #define CPU_FEATURE_MCE 12
-- 
2.7.0.windows.1

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


[edk2] [Patch 0/3] Enable Processor trace feature.

2017-08-01 Thread Eric Dong
Enable processor trace feature.
V2 update:
1. Add device capability check logic in Support function.
2. Correct the function comments.

V3 update:
1. Get device capability in Suport function instead of 
   GetConfigData function.

Eric Dong (3):
  UefiCpuPkg: Add Pcds used by processor trace feature.
  UefiCpuPkg: Add Processor Trace feature definition.
  UefiCpuPkg: Enable Processor Trace feature.

 .../Include/Library/RegisterCpuFeaturesLib.h   |   1 +
 .../CpuCommonFeaturesLib/CpuCommonFeatures.h   |  66 +++
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c|  11 +
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf  |   4 +-
 .../Library/CpuCommonFeaturesLib/ProcTrace.c   | 465 +
 UefiCpuPkg/UefiCpuPkg.dec  |   8 +
 6 files changed, 554 insertions(+), 1 deletion(-)
 create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c

-- 
2.7.0.windows.1

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


[edk2] [Patch v3 3/3] UefiCpuPkg: Enable Processor Trace feature.

2017-08-01 Thread Eric Dong
Cc: Jeff Fan 
Cc: Ruiyu Ni 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong 
---
 .../CpuCommonFeaturesLib/CpuCommonFeatures.h   |  66 +++
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c|  11 +
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf  |   4 +-
 .../Library/CpuCommonFeaturesLib/ProcTrace.c   | 465 +
 4 files changed, 545 insertions(+), 1 deletion(-)
 create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/ProcTrace.c

diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h 
b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
index c03e5ab..b4a351c 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h
@@ -909,4 +909,70 @@ PpinInitialize (
   IN BOOLEAN   State
   );
 
+/**
+  Prepares for the data used by CPU feature detection and initialization.
+
+  @param[in]  NumberOfProcessors  The number of CPUs in the platform.
+
+  @return  Pointer to a buffer of CPU related configuration data.
+
+  @note This service could be called by BSP only.
+**/
+VOID *
+EFIAPI
+ProcTraceGetConfigData (
+  IN UINTN  NumberOfProcessors
+  );
+
+/**
+  Detects if Intel Processor Trace feature supported on current processor.
+
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.
+  @param[in]  CpuInfo  A pointer to the 
REGISTER_CPU_FEATURE_INFORMATION
+   structure for the CPU executing this function.
+  @param[in]  ConfigData   A pointer to the configuration buffer returned
+   by CPU_FEATURE_GET_CONFIG_DATA.  NULL if
+   CPU_FEATURE_GET_CONFIG_DATA was not provided in
+   RegisterCpuFeature().
+
+  @retval TRUE Processor Trace feature is supported.
+  @retval FALSEProcessor Trace feature is not supported.
+
+  @note This service could be called by BSP/APs.
+**/
+BOOLEAN
+EFIAPI
+ProcTraceSupport (
+  IN UINTN ProcessorNumber,
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
+  IN VOID  *ConfigData  OPTIONAL
+  );
+
+/**
+  Initializes Intel Processor Trace feature to specific state.
+
+  @param[in]  ProcessorNumber  The index of the CPU executing this function.
+  @param[in]  CpuInfo  A pointer to the 
REGISTER_CPU_FEATURE_INFORMATION
+   structure for the CPU executing this function.
+  @param[in]  ConfigData   A pointer to the configuration buffer returned
+   by CPU_FEATURE_GET_CONFIG_DATA.  NULL if
+   CPU_FEATURE_GET_CONFIG_DATA was not provided in
+   RegisterCpuFeature().
+  @param[in]  StateIf TRUE, then the Protected Processor Inventory 
+   Number feature must be enabled.
+   If FALSE, then the Protected Processor 
Inventory 
+   Number feature must be disabled.
+
+  @retval RETURN_SUCCESS   Intel Processor Trace feature is initialized.
+
+**/
+RETURN_STATUS
+EFIAPI
+ProcTraceInitialize (
+  IN UINTN ProcessorNumber,
+  IN REGISTER_CPU_FEATURE_INFORMATION  *CpuInfo,
+  IN VOID  *ConfigData,  OPTIONAL
+  IN BOOLEAN   State
+  );
+
 #endif
diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c 
b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
index b88b7d1..a4cb260 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c
@@ -217,6 +217,17 @@ CpuCommonFeaturesLibConstructor (
);
 ASSERT_EFI_ERROR (Status);
   }
+  if (IsCpuFeatureSupported (CPU_FEATURE_PROC_TRACE)) {
+Status = RegisterCpuFeature (
+   "Proc Trace",
+   ProcTraceGetConfigData,
+   ProcTraceSupport,
+   ProcTraceInitialize,
+   CPU_FEATURE_PROC_TRACE,
+   CPU_FEATURE_END
+   );
+ASSERT_EFI_ERROR (Status);
+  }
 
   return RETURN_SUCCESS;
 }
diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf 
b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
index 202d560..e9225bb 100644
--- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
+++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
@@ -48,6 +48,7 @@
   PendingBreak.c
   X2Apic.c
   Ppin.c
+  ProcTrace.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -66,4 +67,5 @@
   gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSupport## CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuClockModulationDutyCycle   ## 
SOMETIMES_CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdIsPowerOnReset## 
SOMETIM

[edk2] [Patch v3 2/3] UefiCpuPkg: Add Processor Trace feature definition.

2017-08-01 Thread Eric Dong
Cc: Jeff Fan 
Cc: Ruiyu Ni 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong 
---
 UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h 
b/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
index 8ea0609..462095b 100644
--- a/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
+++ b/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
@@ -70,6 +70,7 @@
 #define CPU_FEATURE_APIC_TPR_UPDATE_MESSAGE (32+9)
 #define CPU_FEATURE_ENERGY_PERFORMANCE_BIAS (32+10)
 #define CPU_FEATURE_PPIN(32+11)
+#define CPU_FEATURE_PROC_TRACE  (32+12)
 
 #define CPU_FEATURE_BEFORE_ALL  BIT27
 #define CPU_FEATURE_AFTER_ALL   BIT28
-- 
2.7.0.windows.1

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


[edk2] [Patch v3 1/3] UefiCpuPkg: Add Pcds used by processor trace feature.

2017-08-01 Thread Eric Dong
Cc: Jeff Fan 
Cc: Ruiyu Ni 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong 
---
 UefiCpuPkg/UefiCpuPkg.dec | 8 
 1 file changed, 8 insertions(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index e5b0334..2ddeab4 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -285,5 +285,13 @@
   # @ValidList   0x8001 | 0
   gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSetting|{0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00}|VOID*|0x0019
 
+  ## Contains the size of memory required when CPU processor trace is enabled.
+  # @Prompt The memory size used for processor trace.
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceMemSize|0x10|UINT32|0x6012
+
+  ## Contains the processor trace output scheme when CPU processor trace is 
enabled.
+  # @Prompt The processor trace output scheme.
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme|0x2|UINT8|0x6015
+
 [UserExtensions.TianoCore."ExtraFiles"]
   UefiCpuPkgExtra.uni
-- 
2.7.0.windows.1

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