Re: [edk2-devel] [PATCH edk2 v3 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2022-05-13 Thread Ming Huang
Hi Sami,

Sorry for the late reply.

https://github.com/waip23/edk2/tree/upstread-fix-mm-issue
branch: upstread-fix-mm-issue

Regards,

Ming Huang

在 4/6/22 5:03 PM, Sami Mujawar 写道:
> Hi Ming,
> 
> I am not sure if this is an issue at my end, but I cannot apply this patch 
> series, can you check, please?
> Also, is it possible to share these patches on a Github branch.
> 
> Regards,
> 
> Sami Mujawar
> 
> On 30/03/2022, 10:37, "Ming Huang"  wrote:
> 
> Hi,
> 
> Any comment about this series?
> 
> 在 12/31/21 7:06 PM, Ming Huang 写道:
> > There are two scene communicate with StandaloneMm(MM):
> > 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
> >   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
> > 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
> >   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
> > 
> > For now, the second scene will failed because check buffer address.
> > This patch add CheckBufferAddr() to support check address for secure
> > buffer.
> > 
> > Signed-off-by: Ming Huang 
> > ---
> >  StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 54 
> +++-
> >  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21 
> >  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
> >  3 files changed, 63 insertions(+), 13 deletions(-)
> > 
> > diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> > index 5dfaf9d751..d0ba415671 100644
> > --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> > @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext 
> = NULL;
> >  
> >  // Descriptor with whereabouts of memory used for communication with 
> the normal world
> >  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
> > +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
> >  
> >  MP_INFORMATION_HOB_DATA *mMpInformationHobData;
> >  
> > @@ -60,6 +61,42 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
> >  
> >  STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
> >  
> > +STATIC
> > +EFI_STATUS
> > +CheckBufferAddr (
> > +  IN UINTN BufferAddr
> > +  )
> > +{
> > +  UINT64 NsCommBufferEnd;
> > +  UINT64 SCommBufferEnd;
> > +  UINT64 CommBufferEnd;
> > +
> > +  NsCommBufferEnd = mNsCommBuffer.PhysicalStart + 
> mNsCommBuffer.PhysicalSize;
> > +  SCommBufferEnd = mSCommBuffer.PhysicalStart + 
> mSCommBuffer.PhysicalSize;
> > +
> > +  if ((BufferAddr >= mNsCommBuffer.PhysicalStart) &&
> > +  (BufferAddr < NsCommBufferEnd)) {
> > +CommBufferEnd = NsCommBufferEnd;
> > +  } else if ((BufferAddr >= mSCommBuffer.PhysicalStart) &&
> > + (BufferAddr < SCommBufferEnd)) {
> > +CommBufferEnd = SCommBufferEnd;
> > +  } else {
> > +return EFI_ACCESS_DENIED;
> > +  }
> > +
> > +  if ((CommBufferEnd - BufferAddr) < sizeof 
> (EFI_MM_COMMUNICATE_HEADER)) {
> > +return EFI_ACCESS_DENIED;
> > +  }
> > +
> > +  // perform bounds check.
> > +  if ((CommBufferEnd - BufferAddr - sizeof 
> (EFI_MM_COMMUNICATE_HEADER)) <
> > +  ((EFI_MM_COMMUNICATE_HEADER *) BufferAddr)->MessageLength) {
> > +return EFI_ACCESS_DENIED;
> > +  }
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> >  /**
> >The PI Standalone MM entry point for the TF-A CPU driver.
> >  
> > @@ -104,25 +141,16 @@ PiMmStandaloneArmTfCpuDriverEntry (
> >  return EFI_INVALID_PARAMETER;
> >}
> >  
> > -  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
> > -return EFI_ACCESS_DENIED;
> > -  }
> > -
> > -  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
> > -  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
> > -return EFI_INVALID_PARAMETER;
> > +  Status = CheckBufferAddr (NsCommBufferAddr);
> > +  if (EFI_ERROR (Status)) {
> > +DEBUG ((DEBUG_ERROR, "Check Buffer failed: %r\n", Status));
> > +return Status;
> >}
>

Re: [edk2-devel] [PATCH v1 2/2] StandaloneMmPkg: Fix HOB space and heap space conflicted issue

2022-05-12 Thread Ming Huang



在 5/3/22 5:10 PM, Ard Biesheuvel 写道:
> On Wed, 9 Feb 2022 at 13:26, Ming Huang  wrote:
>>
>> The heap space will be rewrote if a StandloneMmPkg module create HOB
>> by BuildGuidHob() interface and write data to HOB space.
> 
> Can you elaborate? What is supposed to happen and why, and what is
> happening instead?

I tried my best to explain the issue:

-<--HandOffHob->EfiFreeMemoryTop
|   |
|   |
|   |
|   |
|   |
|   |
|  mMmMemoryMap |
|---|<--HandOffHob->EfiFreeMemoryBottom
|  HobEnd   |
|---|<--HandOffHob->EfiEndOfHobList
|   |
|  Hob #1   |
-<--MmHobStart
1 The mMmMemoryMap which use for free page is on above the HobEnd.
2 Create a hob by BuildGuidHob(), the HobEnd will move up and cover
  the structure or list using by free page.

After this patch, there is a pre-allocation space for creating hob.

-<--HandOffHob->EfiFreeMemoryTop
|   |
|   |
|   |
|   |
| mMmMemoryMap  |
|---|<--HandOffHob->EfiFreeMemoryBottom
|  Hob free space   | by PcdMemoryHobSize
|---|
|  HobEnd   |
|---|<--HandOffHob->EfiEndOfHobList
|   |
|  Hob #1   |
-<--MmHobStart

> 
>> Add a PCD PcdMemoryHobSize for pre-allocation a space to create HOB to
>> fix this issue.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  StandaloneMmPkg/Core/StandaloneMmCore.c   | 17 -
>>  StandaloneMmPkg/Core/StandaloneMmCore.inf |  3 +++
>>  StandaloneMmPkg/StandaloneMmPkg.dec   |  2 ++
>>  3 files changed, 21 insertions(+), 1 deletion(-)
>>
>> diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c 
>> b/StandaloneMmPkg/Core/StandaloneMmCore.c
>> index d221f1d111..1cf259d946 100644
>> --- a/StandaloneMmPkg/Core/StandaloneMmCore.c
>> +++ b/StandaloneMmPkg/Core/StandaloneMmCore.c
>> @@ -512,6 +512,9 @@ StandaloneMmMain (
>>EFI_MMRAM_DESCRIPTOR*MmramRanges;
>>UINTN   MmramRangeCount;
>>EFI_HOB_FIRMWARE_VOLUME *BfvHob;
>> +  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHobNew;
>> +  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHobOrg;
>> +  UINT64  MaxHobSize = PcdGet64 (PcdMemoryHobSize);
>>
>>ProcessLibraryConstructorList (HobStart, );
>>
>> @@ -619,10 +622,22 @@ StandaloneMmMain (
>>//
>>HobSize = GetHobListSize (HobStart);
>>DEBUG ((DEBUG_INFO, "HobSize - 0x%x\n", HobSize));
>> -  MmHobStart = AllocatePool (HobSize);
>> +  ASSERT (HobSize <= MaxHobSize);
>> +  MmHobStart = AllocatePool (MaxHobSize);
>>DEBUG ((DEBUG_INFO, "MmHobStart - 0x%x\n", MmHobStart));
>>ASSERT (MmHobStart != NULL);
>>CopyMem (MmHobStart, HobStart, HobSize);
>> +  //
>> +  // Initlialize the new HOB table
>> +  //
>> +  HandOffHobOrg = (EFI_HOB_HANDOFF_INFO_TABLE *)HobStart;
>> +  HandOffHobNew = (EFI_HOB_HANDOFF_INFO_TABLE *)MmHobStart;
>> +  HandOffHobNew->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)MmHobStart +
>> +(HandOffHobOrg->EfiEndOfHobList - (EFI_PHYSICAL_ADDRESS)HobStart);
>> +  HandOffHobNew->EfiFreeMemoryBottom = HandOffHobNew->EfiEndOfHobList +
>> +   sizeof (EFI_HOB_GENERIC_HEADER);
>> +  HandOffHobNew->EfiFreeMemoryTop = (EFI_PHYSICAL_ADDRESS)MmHobStart + 
>> MaxHobSize;
>> +
>>Status = MmInstallConfigurationTable (, , 
>> MmHobStart, HobSize);
>>ASSERT_EFI_ERROR (Status);
>>
>> diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf 
>> b/StandaloneMmPkg/Core/StandaloneMmCore.inf
>> index c44b9ff333..37e6135d73 100644
>> --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf
>> +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf
>> @@ -76,6 +76,9 @@
>>gEfiEventExitBootServicesGuid
>>gEfiEventReadyToBootGuid
>>
>> +[FixedPcd]
>> +  gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize
>> +
>>  #
>>  # This configuration fails for CLANGPDB, which does not support PIE in the 
>> GCC
>>  # sense. Such however is required for ARM family StandaloneMmCore
>> diff --git a/S

Re: [edk2-devel] [PATCH edk2 v3 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2022-04-10 Thread Ming Huang
Hi Sami,

I am sure this is an issue for RAS case using Standalone MM.

Please refer Omkar's comments for v1 (12/9/21, 1:46 AM):
-
Hi Ming,

Thanks for this patch. This patch helps to resolve Standalone MM issue while 
exercising RAS use case.
Few comments mentioned inline.

- Omkar
-

Regards,

Ming Huang


在 4/6/22 5:03 PM, Sami Mujawar 写道:
> Hi Ming,
> 
> I am not sure if this is an issue at my end, but I cannot apply this patch 
> series, can you check, please?
> Also, is it possible to share these patches on a Github branch.
> 
> Regards,
> 
> Sami Mujawar
> 
> On 30/03/2022, 10:37, "Ming Huang"  wrote:
> 
> Hi,
> 
> Any comment about this series?
> 
> 在 12/31/21 7:06 PM, Ming Huang 写道:
> > There are two scene communicate with StandaloneMm(MM):
> > 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
> >   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
> > 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
> >   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
> > 
> > For now, the second scene will failed because check buffer address.
> > This patch add CheckBufferAddr() to support check address for secure
> > buffer.
> > 
> > Signed-off-by: Ming Huang 
> > ---
> >  StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 54 
> +++-
> >  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21 
> >  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
> >  3 files changed, 63 insertions(+), 13 deletions(-)
> > 
> > diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> > index 5dfaf9d751..d0ba415671 100644
> > --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> > @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext 
> = NULL;
> >  
> >  // Descriptor with whereabouts of memory used for communication with 
> the normal world
> >  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
> > +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
> >  
> >  MP_INFORMATION_HOB_DATA *mMpInformationHobData;
> >  
> > @@ -60,6 +61,42 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
> >  
> >  STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
> >  
> > +STATIC
> > +EFI_STATUS
> > +CheckBufferAddr (
> > +  IN UINTN BufferAddr
> > +  )
> > +{
> > +  UINT64 NsCommBufferEnd;
> > +  UINT64 SCommBufferEnd;
> > +  UINT64 CommBufferEnd;
> > +
> > +  NsCommBufferEnd = mNsCommBuffer.PhysicalStart + 
> mNsCommBuffer.PhysicalSize;
> > +  SCommBufferEnd = mSCommBuffer.PhysicalStart + 
> mSCommBuffer.PhysicalSize;
> > +
> > +  if ((BufferAddr >= mNsCommBuffer.PhysicalStart) &&
> > +  (BufferAddr < NsCommBufferEnd)) {
> > +CommBufferEnd = NsCommBufferEnd;
> > +  } else if ((BufferAddr >= mSCommBuffer.PhysicalStart) &&
> > + (BufferAddr < SCommBufferEnd)) {
> > +CommBufferEnd = SCommBufferEnd;
> > +  } else {
> > +return EFI_ACCESS_DENIED;
> > +  }
> > +
> > +  if ((CommBufferEnd - BufferAddr) < sizeof 
> (EFI_MM_COMMUNICATE_HEADER)) {
> > +return EFI_ACCESS_DENIED;
> > +  }
> > +
> > +  // perform bounds check.
> > +  if ((CommBufferEnd - BufferAddr - sizeof 
> (EFI_MM_COMMUNICATE_HEADER)) <
> > +  ((EFI_MM_COMMUNICATE_HEADER *) BufferAddr)->MessageLength) {
> > +return EFI_ACCESS_DENIED;
> > +  }
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> >  /**
> >The PI Standalone MM entry point for the TF-A CPU driver.
> >  
> > @@ -104,25 +141,16 @@ PiMmStandaloneArmTfCpuDriverEntry (
> >  return EFI_INVALID_PARAMETER;
> >}
> >  
> > -  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
> > -return EFI_ACCESS_DENIED;
> > -  }
> > -
> > -  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
> > -  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {

Re: [edk2-devel] [PATCH edk2 v3 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2022-03-30 Thread Ming Huang
Hi,

Any comment about this series?

在 12/31/21 7:06 PM, Ming Huang 写道:
> There are two scene communicate with StandaloneMm(MM):
> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
> 
> For now, the second scene will failed because check buffer address.
> This patch add CheckBufferAddr() to support check address for secure
> buffer.
> 
> Signed-off-by: Ming Huang 
> ---
>  StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 54 
> +++-
>  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21 
>  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>  3 files changed, 63 insertions(+), 13 deletions(-)
> 
> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> index 5dfaf9d751..d0ba415671 100644
> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL;
>  
>  // Descriptor with whereabouts of memory used for communication with the 
> normal world
>  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>  
>  MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>  
> @@ -60,6 +61,42 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
>  
>  STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>  
> +STATIC
> +EFI_STATUS
> +CheckBufferAddr (
> +  IN UINTN BufferAddr
> +  )
> +{
> +  UINT64 NsCommBufferEnd;
> +  UINT64 SCommBufferEnd;
> +  UINT64 CommBufferEnd;
> +
> +  NsCommBufferEnd = mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize;
> +  SCommBufferEnd = mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize;
> +
> +  if ((BufferAddr >= mNsCommBuffer.PhysicalStart) &&
> +  (BufferAddr < NsCommBufferEnd)) {
> +CommBufferEnd = NsCommBufferEnd;
> +  } else if ((BufferAddr >= mSCommBuffer.PhysicalStart) &&
> + (BufferAddr < SCommBufferEnd)) {
> +CommBufferEnd = SCommBufferEnd;
> +  } else {
> +return EFI_ACCESS_DENIED;
> +  }
> +
> +  if ((CommBufferEnd - BufferAddr) < sizeof (EFI_MM_COMMUNICATE_HEADER)) {
> +return EFI_ACCESS_DENIED;
> +  }
> +
> +  // perform bounds check.
> +  if ((CommBufferEnd - BufferAddr - sizeof (EFI_MM_COMMUNICATE_HEADER)) <
> +  ((EFI_MM_COMMUNICATE_HEADER *) BufferAddr)->MessageLength) {
> +return EFI_ACCESS_DENIED;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
>  /**
>The PI Standalone MM entry point for the TF-A CPU driver.
>  
> @@ -104,25 +141,16 @@ PiMmStandaloneArmTfCpuDriverEntry (
>  return EFI_INVALID_PARAMETER;
>}
>  
> -  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
> -return EFI_ACCESS_DENIED;
> -  }
> -
> -  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
> -  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
> -return EFI_INVALID_PARAMETER;
> +  Status = CheckBufferAddr (NsCommBufferAddr);
> +  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "Check Buffer failed: %r\n", Status));
> +return Status;
>}
>  
>// Find out the size of the buffer passed
>NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
> NsCommBufferAddr)->MessageLength +
>  sizeof (EFI_MM_COMMUNICATE_HEADER);
>  
> -  // perform bounds check.
> -  if (NsCommBufferAddr + NsCommBufferSize >=
> -  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
> -return EFI_ACCESS_DENIED;
> -  }
> -
>GuidedEventContext = NULL;
>// Now that the secure world can see the normal world buffer, allocate
>// memory to copy the communication buffer to the secure world.
> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c 
> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
> index fd9c59b4da..96dad20dd1 100644
> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
> @@ -107,6 +107,7 @@ StandaloneMmCpuInitialize (
>UINTNIndex;
>UINTNArraySize;
>VOID*HobStart;
> +  EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHob;
>  
>ASSERT (SystemTable != NULL);
>mMmst = SystemTable;
> @@ -186,6 +187,26 @@ StandaloneMmCpuInitialize (
>CopyMem (, NsCommBuf

Re: [edk2-devel] [PATCH v1 0/2] Fix StandaloneMmPkg HOB issue

2022-03-30 Thread Ming Huang
Hi,

Any comment about this series?

在 2/9/22 8:25 PM, Ming Huang 写道:
> Fix two issues in StandaloneMmPkg HOB.
> 
> Ming Huang (2):
>   StandaloneMmPkg/Hob: Assert or return NULL for create hob failed
>   StandaloneMmPkg: Fix HOB space and heap space conflicted issue
> 
>  StandaloneMmPkg/Core/StandaloneMmCore.c | 17 -
>  StandaloneMmPkg/Core/StandaloneMmCore.inf   |  3 +++
>  .../Arm/StandaloneMmCoreHobLib.c|  6 ++
>  .../StandaloneMmHobLib/StandaloneMmHobLib.c |  3 +++
>  StandaloneMmPkg/StandaloneMmPkg.dec |  2 ++
>  5 files changed, 30 insertions(+), 1 deletion(-)
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#88258): https://edk2.groups.io/g/devel/message/88258
Mute This Topic: https://groups.io/mt/89020084/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3] MdePkg/Include: Add ARM specific definitions for CPER

2022-02-15 Thread Ming Huang
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3838

These definitions are added according UEFI spec 2.9.

Signed-off-by: Ming Huang 
---
 MdePkg/Include/Guid/Cper.h | 522 +
 1 file changed, 522 insertions(+)

diff --git a/MdePkg/Include/Guid/Cper.h b/MdePkg/Include/Guid/Cper.h
index deb96d4af9..249e40d8d7 100644
--- a/MdePkg/Include/Guid/Cper.h
+++ b/MdePkg/Include/Guid/Cper.h
@@ -736,6 +736,528 @@ typedef struct {
 
 #endif
 
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+///
+/// ARM and AARCH64 Specific definitions.
+///
+
+///
+/// The validation bit mask indicates which fields in the processor error
+/// structure are valid.
+///@{
+#define EFI_ERROR_SECTION_MPIDR_VALID   BIT0
+#define EFI_ERROR_SECTION_AFFINITY_LEVEL_VALID  BIT1
+#define EFI_ERROR_SECTION_RUNNING_STATE_VALID   BIT2
+#define EFI_ERROR_SECTION_VENDOR_SPEC_VALID BIT3
+///@}
+
+//
+// ARM Processor Error Section
+//
+typedef struct {
+  UINT32  ValidFields;
+  UINT16  ErrorInfoNum;
+  UINT16  ContextInfoNum;
+  UINT32  SectionLength;
+  UINT8   AffinityLevel;
+  UINT8   Reserved[3];
+  UINT64  Mpidr;
+  UINT64  Midr;
+  UINT32  RunningState;
+  UINT32  PsciState;
+} EFI_ARM_PROCESSOR_ERROR_SECTION;
+
+///
+/// The validation bit mask indicates which fields in the processor error data
+/// structure are valid.
+///@{
+#define EFI_ERROR_DATA_MULTIPLE_ERROR_VALID  BIT0
+#define EFI_ERROR_DATA_FLAGS_VALID   BIT1
+#define EFI_ERROR_DATA_ERROR_INFO_VALID  BIT2
+#define EFI_ERROR_DATA_VIRTUAL_ADDRESS_VALID BIT3
+#define EFI_ERROR_DATA_PHYSICAL_ADDRESS_VALIDBIT3
+///@}
+
+///
+/// The Type error in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_TYPE_CACHE0
+#define EFI_ERROR_DATA_TYPE_TLB  1
+#define EFI_ERROR_DATA_TYPE_BUS  2
+#define EFI_ERROR_DATA_TYPE_VENDOR_SPEC  3
+///@}
+
+///
+/// The options of multiple error in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_ERROR_SINGLE  0
+#define EFI_ERROR_DATA_ERROR_MULTIPLE1
+///@}
+
+///
+/// The options of flags in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_FLAG_FIRST_ERROR   BIT0
+#define EFI_ERROR_DATA_FLAG_LAST_ERRORBIT1
+#define EFI_ERROR_DATA_FLAG_PROPAGATEDBIT2
+#define EFI_ERROR_DATA_FLAG_OVERFLOW  BIT3
+///@}
+
+//
+// ARM Processor Error Information Structure
+//
+typedef struct {
+  UINT8   Version;
+  UINT8   Length;
+  UINT16  ValidFields;
+  UINT8   Type;
+  UINT16  MultipleError;
+  UINT8   Flags;
+  UINT64  ErrorInfo;
+  UINT64  VirtualFaultAddress;
+  UINT64  PhysicalFaultAddress;
+} EFI_ARM_PROCESSOR_ERROR_DATA;
+
+//
+///
+/// The validation bit mask indicates which fields in the Cache info structure
+/// are valid.
+///@{
+#define EFI_CACHE_INFO_TRANSACTION_TYPE_VALID   BIT0
+#define EFI_CACHE_INFO_OPERATION_VALID  BIT1
+#define EFI_CACHE_INFO_LEVEL_VALID  BIT2
+#define EFI_CACHE_INFO_CONTEXT_CORRUPT_VALIDBIT3
+#define EFI_CACHE_INFO_CORRECTED_VALID  BIT4
+#define EFI_CACHE_INFO_PRECISE_PC_VALID BIT5
+#define EFI_CACHE_INFO_RESTARTABLE_PC_VALID BIT6
+///@}
+
+///
+/// Type of cache error in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_ERROR_TYPE_INSTRUCTION   0
+#define EFI_CACHE_INFO_ERROR_TYPE_DATA_ACCESS   1
+#define EFI_CACHE_INFO_ERROR_TYPE_GENERIC   2
+///@}
+
+///
+/// Type of cache operation that caused the error in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC 0
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC_READ1
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC_WRITE   2
+#define EFI_CACHE_INFO_OPERATION_TYPE_DATA_READ   3
+#define EFI_CACHE_INFO_OPERATION_TYPE_DATA_WRITE  4
+#define EFI_CACHE_INFO_OPERATION_TYPE_INSTRUCTION_FETCH   5
+#define EFI_CACHE_INFO_OPERATION_TYPE_PREFETCH6
+#define EFI_CACHE_INFO_OPERATION_TYPE_EVICTION7
+#define EFI_CACHE_INFO_OPERATION_TYPE_SNOOPING8
+#define EFI_CACHE_INFO_OPERATION_TYPE_SNOOPED 9
+#define EFI_CACHE_INFO_OPERATION_TYPE_MANAGEMENT  10
+///@}
+
+///
+/// Options of Processor context in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_CONTEXT_NOT_CORRUPTED   0
+#define EFI_CACHE_INFO_CONTEXT_CORRUPTED   1
+///@}
+
+///
+/// Error severity in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_ERROR_SEVERITY_UNCORRECTED  0
+#define EFI_CACHE_INFO_ERROR_SEVERITY_CORRECTED1
+///@}
+
+//
+// ARM Processor Cache Error Structure
+//
+typedef struct {
+  UINT64  ValidBit:16;
+  UINT64  CacheType:2;
+  UINT64  Operation:4;
+  UINT64  CacheLevel:3;
+  UINT64  ContextCorrupt:1;
+  UINT64  Corrected:1;
+  UINT64  PrecisePc:1;
+  UINT64

Re: [edk2-devel] [PATCH v2 1/1] MdePkg/Include: Add ARM specific definitions for CPER

2022-02-13 Thread Ming Huang



在 2/11/22 9:12 AM, gaoliming 写道:
> Ming:
>  You can refer to wiki 
> https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Development-Process
>  to know how to create PR. 

I have create PR:
https://github.com/tianocore/edk2/pull/2519

> 
>  You can refer to wiki 
> https://github.com/tianocore/tianocore.github.io/wiki/Reporting-issues to 
> know how to apply for Bugzilla account. 

I had sended email to apply for Bugzilla account via my email: 
wai...@foxmail.com.
I have not reveived the reply by now.

> 
> Thanks
> Liming
>> -邮件原件-
>> 发件人: devel@edk2.groups.io  代表 Ming Huang
>> 发送时间: 2022年2月10日 18:01
>> 收件人: gaoliming ; devel@edk2.groups.io;
>> sami.muja...@arm.com; ardb+tianoc...@kernel.org; jiewen@intel.com;
>> supreeth.venkat...@arm.com
>> 抄送: ming.hua...@outlook.com
>> 主题: Re: [edk2-devel] [PATCH v2 1/1] MdePkg/Include: Add ARM specific
>> definitions for CPER
>>
>> Hi Liming,
>>
>> I can't log in to bugzilla. How can I register a new account?
>> I have not created pull request for this change and I don't know how to do
>> that.
>> I am sorry.
>>
>> Best Regards.
>>
>> 在 2/10/22 9:19 AM, gaoliming 写道:
>>> Ming:
>>>   Can you submit one BZ in https://bugzilla.tianocore.org/ for this change?
>>>
>>>   Have you created pull request to verify this change in Edk2 CI?
>>>
>>>   Now, we are on soft feature freeze for new stable tag 202202. So, this
>>> change may be merged after this stable tag.
>>>
>>> Thanks
>>> Liming
>>>> -邮件原件-
>>>> 发件人: devel@edk2.groups.io  代表 Ming
>> Huang
>>>> 发送时间: 2022年2月9日 9:55
>>>> 收件人: devel@edk2.groups.io; sami.muja...@arm.com;
>>>> ardb+tianoc...@kernel.org; jiewen@intel.com;
>>>> supreeth.venkat...@arm.com
>>>> 抄送: ming.hua...@outlook.com; Ming Huang
>>>> 
>>>> 主题: [edk2-devel] [PATCH v2 1/1] MdePkg/Include: Add ARM specific
>>>> definitions for CPER
>>>>
>>>> These definitions are added according UEFI spec.
>>>>
>>>> Signed-off-by: Ming Huang 
>>>> ---
>>>>  MdePkg/Include/Guid/Cper.h | 522 
>>>>  1 file changed, 522 insertions(+)
>>>>
>>>> diff --git a/MdePkg/Include/Guid/Cper.h b/MdePkg/Include/Guid/Cper.h
>>>> index deb96d4af9..eef584de03 100644
>>>> --- a/MdePkg/Include/Guid/Cper.h
>>>> +++ b/MdePkg/Include/Guid/Cper.h
>>>> @@ -736,6 +736,528 @@ typedef struct {
>>>>
>>>>  #endif
>>>>
>>>> +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
>>>> +///
>>>> +/// ARM and AARCH64 Specific definitions.
>>>> +///
>>>> +
>>>> +///
>>>> +/// The validation bit mask indicates which fields in the processor error
>>>> +/// structure are valid.
>>>> +///@{
>>>> +#define EFI_ERROR_SECTION_MPIDR_VALID   BIT0
>>>> +#define EFI_ERROR_SECTION_AFFINITY_LEVEL_VALID  BIT1
>>>> +#define EFI_ERROR_SECTION_RUNNING_STATE_VALID   BIT2
>>>> +#define EFI_ERROR_SECTION_VENDOR_SPEC_VALID BIT3
>>>> +///@}
>>>> +
>>>> +//
>>>> +// ARM Processor Error Section
>>>> +//
>>>> +typedef struct {
>>>> +  UINT32  ValidFields;
>>>> +  UINT16  ErrorInfoNum;
>>>> +  UINT16  ContextInfoNum;
>>>> +  UINT32  SectionLength;
>>>> +  UINT8   AffinityLevel;
>>>> +  UINT8   Reserved[3];
>>>> +  UINT64  Mpidr;
>>>> +  UINT64  Midr;
>>>> +  UINT32  RunningState;
>>>> +  UINT32  PsciState;
>>>> +} EFI_ARM_PROCESSOR_ERROR_SECTION;
>>>> +
>>>> +///
>>>> +/// The validation bit mask indicates which fields in the processor error
>>> data
>>>> +/// structure are valid.
>>>> +///@{
>>>> +#define EFI_ERROR_DATA_MULTIPLE_ERROR_VALID  BIT0
>>>> +#define EFI_ERROR_DATA_FLAGS_VALID   BIT1
>>>> +#define EFI_ERROR_DATA_ERROR_INFO_VALID  BIT2
>>>> +#define EFI_ERROR_DATA_VIRTUAL_ADDRESS_VALID BIT3
>>>> +#define EFI_ERROR_DATA_PHYSICAL_ADDRESS_VALIDBIT3
>>>> +///@}
>>>> +
>>>> +///
>>>> +/// The Type error in the processor error data structure.
>>>> +///@{
>>>> +#define EFI_ERROR_DATA_TYPE_CACHE0
>

Re: [edk2-devel] [PATCH v2 1/1] MdePkg/Include: Add ARM specific definitions for CPER

2022-02-10 Thread Ming Huang



在 2/10/22 8:28 PM, Sami Mujawar 写道:
> Hi Ming,
> 
> Thank you for this patch.
> 
> I have a few comments, marked inline as [SAMI].
> 
> With those addressed,
> 
> Reviewed-by: Sami Mujawar 
> 
> Regards,
> 
> Sami Mujawar
> 
> On 09/02/2022 01:54 AM, Ming Huang wrote:
>> These definitions are added according UEFI spec.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>   MdePkg/Include/Guid/Cper.h | 522 
>>   1 file changed, 522 insertions(+)
>>
>> diff --git a/MdePkg/Include/Guid/Cper.h b/MdePkg/Include/Guid/Cper.h
>> index deb96d4af9..eef584de03 100644
>> --- a/MdePkg/Include/Guid/Cper.h
>> +++ b/MdePkg/Include/Guid/Cper.h
>> @@ -736,6 +736,528 @@ typedef struct {
>>     #endif
>>   +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
>> +///
>> +/// ARM and AARCH64 Specific definitions.
>> +///
>> +
>> +///
>> +/// The validation bit mask indicates which fields in the processor error
>> +/// structure are valid.
>> +///@{
>> +#define EFI_ERROR_SECTION_MPIDR_VALID   BIT0
>> +#define EFI_ERROR_SECTION_AFFINITY_LEVEL_VALID  BIT1
>> +#define EFI_ERROR_SECTION_RUNNING_STATE_VALID   BIT2
>> +#define EFI_ERROR_SECTION_VENDOR_SPEC_VALID BIT3
>> +///@}
>> +
>> +//
>> +// ARM Processor Error Section
>> +//
>> +typedef struct {
>> +  UINT32  ValidFields;
>> +  UINT16  ErrorInfoNum;
>> +  UINT16  ContextInfoNum;
>> +  UINT32  SectionLength;
>> +  UINT8   AffinityLevel;
>> +  UINT8   Reserved[3];
>> +  UINT64  Mpidr;
>> +  UINT64  Midr;
>> +  UINT32  RunningState;
>> +  UINT32  PsciState;
>> +} EFI_ARM_PROCESSOR_ERROR_SECTION;
>> +
>> +///
>> +/// The validation bit mask indicates which fields in the processor error 
>> data
>> +/// structure are valid.
>> +///@{
>> +#define EFI_ERROR_DATA_MULTIPLE_ERROR_VALID  BIT0
>> +#define EFI_ERROR_DATA_FLAGS_VALID   BIT1
>> +#define EFI_ERROR_DATA_ERROR_INFO_VALID  BIT2
>> +#define EFI_ERROR_DATA_VIRTUAL_ADDRESS_VALID BIT3
>> +#define EFI_ERROR_DATA_PHYSICAL_ADDRESS_VALID    BIT3
>> +///@}
>> +
>> +///
>> +/// The Type error in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_TYPE_CACHE    0
>> +#define EFI_ERROR_DATA_TYPE_TLB  1
>> +#define EFI_ERROR_DATA_TYPE_BUS  2
>> +#define EFI_ERROR_DATA_TYPE_VENDOR_SPEC  3
> [SAMI] The UEFI specification version 2.9 is not clear about the values for 
> the Type fields. However, I have raised this concern so that the 
> specification can be updated. [/SAMI]
>> +///@}
>> +
>> +///
>> +/// The options of multiple error in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_ERROR_SINGLE  0
>> +#define EFI_ERROR_DATA_ERROR_MULTIPLE    1
>> +///@}
>> +
>> +///
>> +/// The options of flags in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_FLAG_FIRST_ERROR   BIT0
>> +#define EFI_ERROR_DATA_FLAG_LAST_ERROR    BIT1
>> +#define EFI_ERROR_DATA_FLAG_PROPAGATED    BIT2
>> +#define EFI_ERROR_DATA_FLAG_OVERFLOW  BIT3
>> +///@}
>> +
>> +//
>> +// ARM Processor Error Information Structure
>> +//
>> +typedef struct {
>> +  UINT8   Version;
>> +  UINT8   Length;
>> +  UINT16  ValidFields;
>> +  UINT8   Type;
>> +  UINT16  MultipleError;
>> +  UINT8   Flags;
>> +  UINT64  ErrorInfo;
>> +  UINT64  VirtualFaultAddress;
>> +  UINT64  PhysicalFaultAddress;
>> +} EFI_ARM_PROCESSOR_ERROR_DATA;
>> +
>> +//
>> +///
>> +/// The validation bit mask indicates which fields in the Cache info 
>> structure
>> +/// are valid.
>> +///@{
>> +#define EFI_CACHE_INFO_TRANSACTION_TYPE_VALID   BIT0
>> +#define EFI_CACHE_INFO_OPERATION_VALID  BIT1
>> +#define EFI_CACHE_INFO_LEVEL_VALID  BIT2
>> +#define EFI_CACHE_INFO_CONTEXT_CORRUPT_VALID    BIT3
>> +#define EFI_CACHE_INFO_CORRECTED_VALID  BIT4
>> +#define EFI_CACHE_INFO_PRECISE_PC_VALID BIT5
>> +#define EFI_CACHE_INFO_RESTARTABLE_PC_VALID BIT6
>> +///@}
>> +
>> +///
>> +/// Type of cache error in the Cache info structure
>> +///@{
>> +#define EFI_CACHE_INFO_ERROR_TYPE_INSTRUCTION   0
>> +#define EFI_CACHE_INFO_ERROR_TYPE_DATA_ACCESS   1
>> +#define EFI

Re: [edk2-devel] [PATCH v2 1/1] MdePkg/Include: Add ARM specific definitions for CPER

2022-02-10 Thread Ming Huang
Hi Liming,

I can't log in to bugzilla. How can I register a new account?
I have not created pull request for this change and I don't know how to do that.
I am sorry.

Best Regards.

在 2/10/22 9:19 AM, gaoliming 写道:
> Ming:
>   Can you submit one BZ in https://bugzilla.tianocore.org/ for this change? 
>   
>   Have you created pull request to verify this change in Edk2 CI?
> 
>   Now, we are on soft feature freeze for new stable tag 202202. So, this
> change may be merged after this stable tag. 
> 
> Thanks
> Liming
>> -邮件原件-----
>> 发件人: devel@edk2.groups.io  代表 Ming Huang
>> 发送时间: 2022年2月9日 9:55
>> 收件人: devel@edk2.groups.io; sami.muja...@arm.com;
>> ardb+tianoc...@kernel.org; jiewen@intel.com;
>> supreeth.venkat...@arm.com
>> 抄送: ming.hua...@outlook.com; Ming Huang
>> 
>> 主题: [edk2-devel] [PATCH v2 1/1] MdePkg/Include: Add ARM specific
>> definitions for CPER
>>
>> These definitions are added according UEFI spec.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  MdePkg/Include/Guid/Cper.h | 522 
>>  1 file changed, 522 insertions(+)
>>
>> diff --git a/MdePkg/Include/Guid/Cper.h b/MdePkg/Include/Guid/Cper.h
>> index deb96d4af9..eef584de03 100644
>> --- a/MdePkg/Include/Guid/Cper.h
>> +++ b/MdePkg/Include/Guid/Cper.h
>> @@ -736,6 +736,528 @@ typedef struct {
>>
>>  #endif
>>
>> +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
>> +///
>> +/// ARM and AARCH64 Specific definitions.
>> +///
>> +
>> +///
>> +/// The validation bit mask indicates which fields in the processor error
>> +/// structure are valid.
>> +///@{
>> +#define EFI_ERROR_SECTION_MPIDR_VALID   BIT0
>> +#define EFI_ERROR_SECTION_AFFINITY_LEVEL_VALID  BIT1
>> +#define EFI_ERROR_SECTION_RUNNING_STATE_VALID   BIT2
>> +#define EFI_ERROR_SECTION_VENDOR_SPEC_VALID BIT3
>> +///@}
>> +
>> +//
>> +// ARM Processor Error Section
>> +//
>> +typedef struct {
>> +  UINT32  ValidFields;
>> +  UINT16  ErrorInfoNum;
>> +  UINT16  ContextInfoNum;
>> +  UINT32  SectionLength;
>> +  UINT8   AffinityLevel;
>> +  UINT8   Reserved[3];
>> +  UINT64  Mpidr;
>> +  UINT64  Midr;
>> +  UINT32  RunningState;
>> +  UINT32  PsciState;
>> +} EFI_ARM_PROCESSOR_ERROR_SECTION;
>> +
>> +///
>> +/// The validation bit mask indicates which fields in the processor error
> data
>> +/// structure are valid.
>> +///@{
>> +#define EFI_ERROR_DATA_MULTIPLE_ERROR_VALID  BIT0
>> +#define EFI_ERROR_DATA_FLAGS_VALID   BIT1
>> +#define EFI_ERROR_DATA_ERROR_INFO_VALID  BIT2
>> +#define EFI_ERROR_DATA_VIRTUAL_ADDRESS_VALID BIT3
>> +#define EFI_ERROR_DATA_PHYSICAL_ADDRESS_VALIDBIT3
>> +///@}
>> +
>> +///
>> +/// The Type error in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_TYPE_CACHE0
>> +#define EFI_ERROR_DATA_TYPE_TLB  1
>> +#define EFI_ERROR_DATA_TYPE_BUS  2
>> +#define EFI_ERROR_DATA_TYPE_VENDOR_SPEC  3
>> +///@}
>> +
>> +///
>> +/// The options of multiple error in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_ERROR_SINGLE  0
>> +#define EFI_ERROR_DATA_ERROR_MULTIPLE1
>> +///@}
>> +
>> +///
>> +/// The options of flags in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_FLAG_FIRST_ERROR   BIT0
>> +#define EFI_ERROR_DATA_FLAG_LAST_ERRORBIT1
>> +#define EFI_ERROR_DATA_FLAG_PROPAGATEDBIT2
>> +#define EFI_ERROR_DATA_FLAG_OVERFLOW  BIT3
>> +///@}
>> +
>> +//
>> +// ARM Processor Error Information Structure
>> +//
>> +typedef struct {
>> +  UINT8   Version;
>> +  UINT8   Length;
>> +  UINT16  ValidFields;
>> +  UINT8   Type;
>> +  UINT16  MultipleError;
>> +  UINT8   Flags;
>> +  UINT64  ErrorInfo;
>> +  UINT64  VirtualFaultAddress;
>> +  UINT64  PhysicalFaultAddress;
>> +} EFI_ARM_PROCESSOR_ERROR_DATA;
>> +
>> +//
>> +///
>> +/// The validation bit mask indicates which fields in the Cache info
> structure
>> +/// are valid.
>> +///@{
>> +#define EFI_CACHE_INFO_TRANSACTION_TYPE_VALID   BIT0
>> +#define EFI_CACHE_INFO_OPERATION_VALID  BIT1
>> +#define EFI_CACHE_INFO_LEVEL_VALID  BIT2
>> +#define EFI_CACHE_INFO_CONTEXT_CORRUPT_VALIDBIT3

[edk2-devel] [PATCH v1 2/2] StandaloneMmPkg: Fix HOB space and heap space conflicted issue

2022-02-09 Thread Ming Huang
The heap space will be rewrote if a StandloneMmPkg module create HOB
by BuildGuidHob() interface and write data to HOB space.
Add a PCD PcdMemoryHobSize for pre-allocation a space to create HOB to
fix this issue.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Core/StandaloneMmCore.c   | 17 -
 StandaloneMmPkg/Core/StandaloneMmCore.inf |  3 +++
 StandaloneMmPkg/StandaloneMmPkg.dec   |  2 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c 
b/StandaloneMmPkg/Core/StandaloneMmCore.c
index d221f1d111..1cf259d946 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.c
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.c
@@ -512,6 +512,9 @@ StandaloneMmMain (
   EFI_MMRAM_DESCRIPTOR*MmramRanges;
   UINTN   MmramRangeCount;
   EFI_HOB_FIRMWARE_VOLUME *BfvHob;
+  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHobNew;
+  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHobOrg;
+  UINT64  MaxHobSize = PcdGet64 (PcdMemoryHobSize);
 
   ProcessLibraryConstructorList (HobStart, );
 
@@ -619,10 +622,22 @@ StandaloneMmMain (
   //
   HobSize = GetHobListSize (HobStart);
   DEBUG ((DEBUG_INFO, "HobSize - 0x%x\n", HobSize));
-  MmHobStart = AllocatePool (HobSize);
+  ASSERT (HobSize <= MaxHobSize);
+  MmHobStart = AllocatePool (MaxHobSize);
   DEBUG ((DEBUG_INFO, "MmHobStart - 0x%x\n", MmHobStart));
   ASSERT (MmHobStart != NULL);
   CopyMem (MmHobStart, HobStart, HobSize);
+  //
+  // Initlialize the new HOB table
+  //
+  HandOffHobOrg = (EFI_HOB_HANDOFF_INFO_TABLE *)HobStart;
+  HandOffHobNew = (EFI_HOB_HANDOFF_INFO_TABLE *)MmHobStart;
+  HandOffHobNew->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)MmHobStart +
+(HandOffHobOrg->EfiEndOfHobList - (EFI_PHYSICAL_ADDRESS)HobStart);
+  HandOffHobNew->EfiFreeMemoryBottom = HandOffHobNew->EfiEndOfHobList +
+   sizeof (EFI_HOB_GENERIC_HEADER);
+  HandOffHobNew->EfiFreeMemoryTop = (EFI_PHYSICAL_ADDRESS)MmHobStart + 
MaxHobSize;
+
   Status = MmInstallConfigurationTable (, , 
MmHobStart, HobSize);
   ASSERT_EFI_ERROR (Status);
 
diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf 
b/StandaloneMmPkg/Core/StandaloneMmCore.inf
index c44b9ff333..37e6135d73 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.inf
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf
@@ -76,6 +76,9 @@
   gEfiEventExitBootServicesGuid
   gEfiEventReadyToBootGuid
 
+[FixedPcd]
+  gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize
+
 #
 # This configuration fails for CLANGPDB, which does not support PIE in the GCC
 # sense. Such however is required for ARM family StandaloneMmCore
diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec 
b/StandaloneMmPkg/StandaloneMmPkg.dec
index 46784d94e4..cf554676e2 100644
--- a/StandaloneMmPkg/StandaloneMmPkg.dec
+++ b/StandaloneMmPkg/StandaloneMmPkg.dec
@@ -48,3 +48,5 @@
   gEfiStandaloneMmNonSecureBufferGuid  = { 0xf00497e3, 0xbfa2, 0x41a1, { 
0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }}
   gEfiArmTfCpuDriverEpDescriptorGuid   = { 0x6ecbd5a1, 0xc0f8, 0x4702, { 
0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }}
 
+[PcdsFixedAtBuild]
+  gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize|0x|UINT64|0x0004
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86527): https://edk2.groups.io/g/devel/message/86527
Mute This Topic: https://groups.io/mt/89020085/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v1 1/2] StandaloneMmPkg/Hob: Assert or return NULL for create hob failed

2022-02-09 Thread Ming Huang
The rare case (create hob failed) should be considered. Assert for
StandaloneMmCoreHobLib and return NULL for StandaloneMmobLib.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c | 
6 ++
 StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c | 
3 +++
 2 files changed, 9 insertions(+)

diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c 
b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c
index 1550e1babc..d27e5ceaa4 100644
--- 
a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c
+++ 
b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c
@@ -89,6 +89,7 @@ BuildModuleHob (
 );
 
   Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof 
(EFI_HOB_MEMORY_ALLOCATION_MODULE));
+  ASSERT (Hob != NULL);
 
   CopyGuid (&(Hob->MemoryAllocationHeader.Name), 
);
   Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
@@ -167,6 +168,7 @@ BuildGuidHob (
   ASSERT (DataLength <= (0x - sizeof (EFI_HOB_GUID_TYPE)));
 
   Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16)(sizeof 
(EFI_HOB_GUID_TYPE) + DataLength));
+  ASSERT (Hob != NULL);
   CopyGuid (>Name, Guid);
   return Hob + 1;
 }
@@ -226,6 +228,7 @@ BuildFvHob (
   EFI_HOB_FIRMWARE_VOLUME  *Hob;
 
   Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));
+  ASSERT (Hob != NULL);
 
   Hob->BaseAddress = BaseAddress;
   Hob->Length  = Length;
@@ -255,6 +258,7 @@ BuildFv2Hob (
   EFI_HOB_FIRMWARE_VOLUME2  *Hob;
 
   Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));
+  ASSERT (Hob != NULL);
 
   Hob->BaseAddress = BaseAddress;
   Hob->Length  = Length;
@@ -282,6 +286,7 @@ BuildCpuHob (
   EFI_HOB_CPU  *Hob;
 
   Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));
+  ASSERT (Hob != NULL);
 
   Hob->SizeOfMemorySpace = SizeOfMemorySpace;
   Hob->SizeOfIoSpace = SizeOfIoSpace;
@@ -319,6 +324,7 @@ BuildMemoryAllocationHob (
 );
 
   Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof 
(EFI_HOB_MEMORY_ALLOCATION));
+  ASSERT (Hob != NULL);
 
   ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
   Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
diff --git a/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c 
b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c
index ee61bdd227..4acd44ceb3 100644
--- a/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c
@@ -396,6 +396,9 @@ BuildGuidHob (
   ASSERT (DataLength <= (0x - sizeof (EFI_HOB_GUID_TYPE)));
 
   Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16)(sizeof 
(EFI_HOB_GUID_TYPE) + DataLength));
+  if (Hob == NULL) {
+return NULL;
+  }
   CopyGuid (>Name, Guid);
   return Hob + 1;
 }
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86525): https://edk2.groups.io/g/devel/message/86525
Mute This Topic: https://groups.io/mt/89020083/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v1 0/2] Fix StandaloneMmPkg HOB issue

2022-02-09 Thread Ming Huang
Fix two issues in StandaloneMmPkg HOB.

Ming Huang (2):
  StandaloneMmPkg/Hob: Assert or return NULL for create hob failed
  StandaloneMmPkg: Fix HOB space and heap space conflicted issue

 StandaloneMmPkg/Core/StandaloneMmCore.c | 17 -
 StandaloneMmPkg/Core/StandaloneMmCore.inf   |  3 +++
 .../Arm/StandaloneMmCoreHobLib.c|  6 ++
 .../StandaloneMmHobLib/StandaloneMmHobLib.c |  3 +++
 StandaloneMmPkg/StandaloneMmPkg.dec |  2 ++
 5 files changed, 30 insertions(+), 1 deletion(-)

-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86526): https://edk2.groups.io/g/devel/message/86526
Mute This Topic: https://groups.io/mt/89020084/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v1 1/1] StandaloneMmPkg: Fix HOB space and heap space conflicted issue

2022-02-09 Thread Ming Huang
Abandon this patch, send a new one for fixing this issue.

在 2/8/22 10:43 AM, Ming Huang 写道:
> The heap space will be rewrote if a StandloneMmPkg module create HOB
> by BuildGuidHob() interface and write data to HOB space.
> Add a PCD PcdMemoryHobSize for pre-allocation a space to create HOB to
> fix this issue.
> 
> Signed-off-by: Ming Huang 
> ---
>  StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c   
>  | 11 ++-
>  
> StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
>  |  4 
>  StandaloneMmPkg/StandaloneMmPkg.dec  
>  |  2 ++
>  3 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git 
> a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
> b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
> index eb0c1f82db..c9fb46c532 100644
> --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
> +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
> @@ -68,13 +68,14 @@ CreateHobListFromBootInfo (
>EFI_PROCESSOR_INFORMATION*ProcInfoBuffer;
>EFI_SECURE_PARTITION_CPU_INFO*CpuInfo;
>ARM_TF_CPU_DRIVER_EP_DESCRIPTOR  *CpuDriverEntryPointDesc;
> +  UINT64   MaxHobSize = PcdGet64 (PcdMemoryHobSize);
>  
>// Create a hoblist with a PHIT and EOH
>HobStart = HobConstructor (
> (VOID *)(UINTN)PayloadBootInfo->SpMemBase,
> (UINTN)PayloadBootInfo->SpMemLimit - 
> PayloadBootInfo->SpMemBase,
> (VOID *)(UINTN)PayloadBootInfo->SpHeapBase,
> -   (VOID *)(UINTN)(PayloadBootInfo->SpHeapBase + 
> PayloadBootInfo->SpHeapSize)
> +   (VOID *)(UINTN)(PayloadBootInfo->SpHeapBase +MaxHobSize)
> );
>  
>// Check that the Hoblist starts at the bottom of the Heap
> @@ -192,13 +193,13 @@ CreateHobListFromBootInfo (
>// Base and size of heap memory shared by all cpus
>MmramRanges[4].PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart;
>MmramRanges[4].CpuStart  = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart;
> -  MmramRanges[4].PhysicalSize  = HobStart->EfiFreeMemoryBottom - 
> (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart;
> +  MmramRanges[4].PhysicalSize  = MaxHobSize;
>MmramRanges[4].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
>  
>// Base and size of heap memory shared by all cpus
> -  MmramRanges[5].PhysicalStart = HobStart->EfiFreeMemoryBottom;
> -  MmramRanges[5].CpuStart  = HobStart->EfiFreeMemoryBottom;
> -  MmramRanges[5].PhysicalSize  = HobStart->EfiFreeMemoryTop - 
> HobStart->EfiFreeMemoryBottom;
> +  MmramRanges[5].PhysicalStart = HobStart->EfiFreeMemoryTop;
> +  MmramRanges[5].CpuStart  = HobStart->EfiFreeMemoryTop;
> +  MmramRanges[5].PhysicalSize  = PayloadBootInfo->SpHeapSize - MaxHobSize;
>MmramRanges[5].RegionState   = EFI_CACHEABLE;
>  
>return HobStart;
> diff --git 
> a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
>  
> b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
> index 75cfb98c0e..c469ac2cca 100644
> --- 
> a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
> +++ 
> b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
> @@ -40,6 +40,7 @@
>  [LibraryClasses]
>BaseLib
>DebugLib
> +  PcdLib
>  
>  [LibraryClasses.ARM, LibraryClasses.AARCH64]
>StandaloneMmMmuLib
> @@ -54,6 +55,9 @@
>  [FeaturePcd.ARM, FeaturePcd.AARCH64]
>gArmTokenSpaceGuid.PcdFfaEnable
>  
> +[FixedPcd]
> +  gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize
> +
>  #
>  # This configuration fails for CLANGPDB, which does not support PIE in the 
> GCC
>  # sense. Such however is required for ARM family StandaloneMmCore
> diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec 
> b/StandaloneMmPkg/StandaloneMmPkg.dec
> index 46784d94e4..cf554676e2 100644
> --- a/StandaloneMmPkg/StandaloneMmPkg.dec
> +++ b/StandaloneMmPkg/StandaloneMmPkg.dec
> @@ -48,3 +48,5 @@
>gEfiStandaloneMmNonSecureBufferGuid  = { 0xf00497e3, 0xbfa2, 0x41a1, { 
> 0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }}
>gEfiArmTfCpuDriverEpDescriptorGuid   = { 0x6ecbd5a1, 0xc0f8, 0x4702, { 
> 0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }}
>  
> +[PcdsFixedAtBuild]
> +  
> gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize|0x|UINT64|0x0004


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86524): https://edk2.groups.io/g/devel/message/86524
Mute This Topic: https://groups.io/mt/88988964/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 1/1] MdePkg/Include: Add ARM specific definitions for CPER

2022-02-08 Thread Ming Huang
These definitions are added according UEFI spec.

Signed-off-by: Ming Huang 
---
 MdePkg/Include/Guid/Cper.h | 522 
 1 file changed, 522 insertions(+)

diff --git a/MdePkg/Include/Guid/Cper.h b/MdePkg/Include/Guid/Cper.h
index deb96d4af9..eef584de03 100644
--- a/MdePkg/Include/Guid/Cper.h
+++ b/MdePkg/Include/Guid/Cper.h
@@ -736,6 +736,528 @@ typedef struct {
 
 #endif
 
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+///
+/// ARM and AARCH64 Specific definitions.
+///
+
+///
+/// The validation bit mask indicates which fields in the processor error
+/// structure are valid.
+///@{
+#define EFI_ERROR_SECTION_MPIDR_VALID   BIT0
+#define EFI_ERROR_SECTION_AFFINITY_LEVEL_VALID  BIT1
+#define EFI_ERROR_SECTION_RUNNING_STATE_VALID   BIT2
+#define EFI_ERROR_SECTION_VENDOR_SPEC_VALID BIT3
+///@}
+
+//
+// ARM Processor Error Section
+//
+typedef struct {
+  UINT32  ValidFields;
+  UINT16  ErrorInfoNum;
+  UINT16  ContextInfoNum;
+  UINT32  SectionLength;
+  UINT8   AffinityLevel;
+  UINT8   Reserved[3];
+  UINT64  Mpidr;
+  UINT64  Midr;
+  UINT32  RunningState;
+  UINT32  PsciState;
+} EFI_ARM_PROCESSOR_ERROR_SECTION;
+
+///
+/// The validation bit mask indicates which fields in the processor error data
+/// structure are valid.
+///@{
+#define EFI_ERROR_DATA_MULTIPLE_ERROR_VALID  BIT0
+#define EFI_ERROR_DATA_FLAGS_VALID   BIT1
+#define EFI_ERROR_DATA_ERROR_INFO_VALID  BIT2
+#define EFI_ERROR_DATA_VIRTUAL_ADDRESS_VALID BIT3
+#define EFI_ERROR_DATA_PHYSICAL_ADDRESS_VALIDBIT3
+///@}
+
+///
+/// The Type error in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_TYPE_CACHE0
+#define EFI_ERROR_DATA_TYPE_TLB  1
+#define EFI_ERROR_DATA_TYPE_BUS  2
+#define EFI_ERROR_DATA_TYPE_VENDOR_SPEC  3
+///@}
+
+///
+/// The options of multiple error in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_ERROR_SINGLE  0
+#define EFI_ERROR_DATA_ERROR_MULTIPLE1
+///@}
+
+///
+/// The options of flags in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_FLAG_FIRST_ERROR   BIT0
+#define EFI_ERROR_DATA_FLAG_LAST_ERRORBIT1
+#define EFI_ERROR_DATA_FLAG_PROPAGATEDBIT2
+#define EFI_ERROR_DATA_FLAG_OVERFLOW  BIT3
+///@}
+
+//
+// ARM Processor Error Information Structure
+//
+typedef struct {
+  UINT8   Version;
+  UINT8   Length;
+  UINT16  ValidFields;
+  UINT8   Type;
+  UINT16  MultipleError;
+  UINT8   Flags;
+  UINT64  ErrorInfo;
+  UINT64  VirtualFaultAddress;
+  UINT64  PhysicalFaultAddress;
+} EFI_ARM_PROCESSOR_ERROR_DATA;
+
+//
+///
+/// The validation bit mask indicates which fields in the Cache info structure
+/// are valid.
+///@{
+#define EFI_CACHE_INFO_TRANSACTION_TYPE_VALID   BIT0
+#define EFI_CACHE_INFO_OPERATION_VALID  BIT1
+#define EFI_CACHE_INFO_LEVEL_VALID  BIT2
+#define EFI_CACHE_INFO_CONTEXT_CORRUPT_VALIDBIT3
+#define EFI_CACHE_INFO_CORRECTED_VALID  BIT4
+#define EFI_CACHE_INFO_PRECISE_PC_VALID BIT5
+#define EFI_CACHE_INFO_RESTARTABLE_PC_VALID BIT6
+///@}
+
+///
+/// Type of cache error in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_ERROR_TYPE_INSTRUCTION   0
+#define EFI_CACHE_INFO_ERROR_TYPE_DATA_ACCESS   1
+#define EFI_CACHE_INFO_ERROR_TYPE_GENERIC   2
+///@}
+
+///
+/// Type of cache operation that caused the error in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC 0
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC_READ1
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC_WRITE   2
+#define EFI_CACHE_INFO_OPERATION_TYPE_DATA_READ   3
+#define EFI_CACHE_INFO_OPERATION_TYPE_DATA_WRITE  4
+#define EFI_CACHE_INFO_OPERATION_TYPE_INSTRUCTION_FETCH   5
+#define EFI_CACHE_INFO_OPERATION_TYPE_PREFETCH6
+#define EFI_CACHE_INFO_OPERATION_TYPE_EVICTION7
+#define EFI_CACHE_INFO_OPERATION_TYPE_SNOOPING8
+#define EFI_CACHE_INFO_OPERATION_TYPE_SNOOPED 9
+#define EFI_CACHE_INFO_OPERATION_TYPE_MANAGEMENT  10
+///@}
+
+///
+/// Options of Processor context in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_CONTEXT_NOT_CORRUPTED   0
+#define EFI_CACHE_INFO_CONTEXT_CORRUPTED   1
+///@}
+
+///
+/// Error severity in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_ERROR_SEVERITY_UnCORRECTED  0
+#define EFI_CACHE_INFO_ERROR_SEVERITY_CORRECTED1
+///@}
+
+//
+// ARM Processor Cache Error Structure
+//
+typedef struct {
+  UINT64  ValidBit:16;
+  UINT64  CacheType:2;
+  UINT64  Operation:4;
+  UINT64  CacheLevel:3;
+  UINT64  ContextCorrupt:1;
+  UINT64  Corrected:1;
+  UINT64  PrecisePc:1;
+  UINT64  RestartablePc:1;
+  UINT64  Reserved:35;
+} EFI_ARM_PROCESSOR_CACHE_ERROR_INFO

Re: [edk2-devel] [PATCH v1 1/1] MdePkg/Include: Add ARM specific definitions for CPER

2022-02-08 Thread Ming Huang



在 2/9/22 1:01 AM, Ard Biesheuvel 写道:
> On Tue, 8 Feb 2022 at 07:16, Ming Huang  wrote:
>>
>> These definitions are added according UEFI spec.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  MdePkg/Include/Guid/Cper.h | 544 
>>  1 file changed, 544 insertions(+)
>>
>> diff --git a/MdePkg/Include/Guid/Cper.h b/MdePkg/Include/Guid/Cper.h
>> index deb96d4af9..715d3b6bb0 100644
>> --- a/MdePkg/Include/Guid/Cper.h
>> +++ b/MdePkg/Include/Guid/Cper.h
>> @@ -736,6 +736,550 @@ typedef struct {
>>
>>  #endif
>>
>> +#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
>> +///
>> +/// ARM and AARCH64 Specific definitions.
>> +///
>> +
>> +///
>> +/// The validation bit mask indicates which fields in the processor error
>> +/// structure are valid.
>> +///@{
>> +#define EFI_ERROR_SECTION_MPIDR_VALID   BIT0
>> +#define EFI_ERROR_SECTION_AFFINITY_LEVEL_VALID  BIT1
>> +#define EFI_ERROR_SECTION_RUNNING_STATE_VALID   BIT2
>> +#define EFI_ERROR_SECTION_VENDOR_SPEC_VALID BIT3
>> +///@}
>> +
>> +//
>> +// ARM Processor Error Section
>> +//
>> +typedef struct {
>> +   UINT32  ValidFields;
>> +   UINT16  ErrorInfoNum;
>> +   UINT16  ContextInfoNum;
>> +   UINT32  SectionLength;
>> +   UINT8 AffinityLevel;
>> +   UINT8 Reserved[3];
> 
> Please use consistent indentation.

Modify it in v2.

> 
>> +   UINT64  Mpidr;
>> +   UINT64  Midr;
>> +   UINT32  RunningState;
>> +   UINT32  PsciState;
>> +} EFI_ARM_PROCESSOR_ERROR_SECTION;
>> +
>> +///
>> +/// The validation bit mask indicates which fields in the processor error 
>> data
>> +/// structure are valid.
>> +///@{
>> +#define EFI_ERROR_DATA_MULTIPLE_ERROR_VALID  BIT0
>> +#define EFI_ERROR_DATA_FLAGS_VALID   BIT1
>> +#define EFI_ERROR_DATA_ERROR_INFO_VALID  BIT2
>> +#define EFI_ERROR_DATA_VIRTUAL_ADDRESS_VALID BIT3
>> +#define EFI_ERROR_DATA_PHYSICAL_ADDRESS_VALIDBIT3
>> +///@}
>> +
>> +///
>> +/// The Type error in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_TYPE_CACHE0
>> +#define EFI_ERROR_DATA_TYPE_TLB  1
>> +#define EFI_ERROR_DATA_TYPE_BUS  2
>> +#define EFI_ERROR_DATA_TYPE_VENDOR_SPEC  3
>> +///@}
>> +
>> +///
>> +/// The options of multiple error in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_ERROR_SINGLE  0
>> +#define EFI_ERROR_DATA_ERROR_MULTIPLE1
>> +///@}
>> +
>> +///
>> +/// The options of flags in the processor error data structure.
>> +///@{
>> +#define EFI_ERROR_DATA_FLAG_FIRST_ERROR   BIT0
>> +#define EFI_ERROR_DATA_FLAG_LAST_ERRORBIT1
>> +#define EFI_ERROR_DATA_FLAG_PROPAGATEDBIT2
>> +#define EFI_ERROR_DATA_FLAG_OVERFLOW  BIT3
>> +///@}
>> +
>> +//
>> +// ARM Processor Error Information Structure
>> +//
>> +typedef struct {
>> +   UINT8 Version;
>> +   UINT8 Length;
>> +   UINT16  ValidFields;
>> +   UINT8 Type;
>> +   UINT16  MultipleError;
>> +   UINT8 Flags;
> 
> Here too

Modify it in v2.

> 
>> +   UINT64  ErrorInfo;
>> +   UINT64  VirtualFaultAddress;
>> +   UINT64  PhysicalFaultAddress;
>> +} EFI_ARM_PROCESSOR_ERROR_DATA;
>> +
>> +//
>> +///
>> +/// The validation bit mask indicates which fields in the Cache info 
>> structure
>> +/// are valid.
>> +///@{
>> +#define EFI_CACHE_INFO_TRANSACTION_TYPE_VALID   BIT0
>> +#define EFI_CACHE_INFO_OPERATION_VALID  BIT1
>> +#define EFI_CACHE_INFO_LEVEL_VALID  BIT2
>> +#define EFI_CACHE_INFO_CONTEXT_CORRUPT_VALIDBIT3
>> +#define EFI_CACHE_INFO_CORRECTED_VALID  BIT4
>> +#define EFI_CACHE_INFO_PRECISE_PC_VALID BIT5
>> +#define EFI_CACHE_INFO_RESTARTABLE_PC_VALID BIT6
>> +///@}
>> +
>> +///
>> +/// Type of cache error in the Cache info structure
>> +///@{
>> +#define EFI_CACHE_INFO_ERROR_TYPE_INSTRUCTION   0
>> +#define EFI_CACHE_INFO_ERROR_TYPE_DATA_ACCESS   1
>> +#define EFI_CACHE_INFO_ERROR_TYPE_GENERIC   2
>> +///@}
>> +
>> +///
>> +/// Type of cache operation that caused the error in the Cache info 
>&g

[edk2-devel] [PATCH v1 1/1] MdePkg/Include: Add ARM specific definitions for CPER

2022-02-07 Thread Ming Huang
These definitions are added according UEFI spec.

Signed-off-by: Ming Huang 
---
 MdePkg/Include/Guid/Cper.h | 544 
 1 file changed, 544 insertions(+)

diff --git a/MdePkg/Include/Guid/Cper.h b/MdePkg/Include/Guid/Cper.h
index deb96d4af9..715d3b6bb0 100644
--- a/MdePkg/Include/Guid/Cper.h
+++ b/MdePkg/Include/Guid/Cper.h
@@ -736,6 +736,550 @@ typedef struct {
 
 #endif
 
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+///
+/// ARM and AARCH64 Specific definitions.
+///
+
+///
+/// The validation bit mask indicates which fields in the processor error
+/// structure are valid.
+///@{
+#define EFI_ERROR_SECTION_MPIDR_VALID   BIT0
+#define EFI_ERROR_SECTION_AFFINITY_LEVEL_VALID  BIT1
+#define EFI_ERROR_SECTION_RUNNING_STATE_VALID   BIT2
+#define EFI_ERROR_SECTION_VENDOR_SPEC_VALID BIT3
+///@}
+
+//
+// ARM Processor Error Section
+//
+typedef struct {
+   UINT32  ValidFields;
+   UINT16  ErrorInfoNum;
+   UINT16  ContextInfoNum;
+   UINT32  SectionLength;
+   UINT8 AffinityLevel;
+   UINT8 Reserved[3];
+   UINT64  Mpidr;
+   UINT64  Midr;
+   UINT32  RunningState;
+   UINT32  PsciState;
+} EFI_ARM_PROCESSOR_ERROR_SECTION;
+
+///
+/// The validation bit mask indicates which fields in the processor error data
+/// structure are valid.
+///@{
+#define EFI_ERROR_DATA_MULTIPLE_ERROR_VALID  BIT0
+#define EFI_ERROR_DATA_FLAGS_VALID   BIT1
+#define EFI_ERROR_DATA_ERROR_INFO_VALID  BIT2
+#define EFI_ERROR_DATA_VIRTUAL_ADDRESS_VALID BIT3
+#define EFI_ERROR_DATA_PHYSICAL_ADDRESS_VALIDBIT3
+///@}
+
+///
+/// The Type error in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_TYPE_CACHE0
+#define EFI_ERROR_DATA_TYPE_TLB  1
+#define EFI_ERROR_DATA_TYPE_BUS  2
+#define EFI_ERROR_DATA_TYPE_VENDOR_SPEC  3
+///@}
+
+///
+/// The options of multiple error in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_ERROR_SINGLE  0
+#define EFI_ERROR_DATA_ERROR_MULTIPLE1
+///@}
+
+///
+/// The options of flags in the processor error data structure.
+///@{
+#define EFI_ERROR_DATA_FLAG_FIRST_ERROR   BIT0
+#define EFI_ERROR_DATA_FLAG_LAST_ERRORBIT1
+#define EFI_ERROR_DATA_FLAG_PROPAGATEDBIT2
+#define EFI_ERROR_DATA_FLAG_OVERFLOW  BIT3
+///@}
+
+//
+// ARM Processor Error Information Structure
+//
+typedef struct {
+   UINT8 Version;
+   UINT8 Length;
+   UINT16  ValidFields;
+   UINT8 Type;
+   UINT16  MultipleError;
+   UINT8 Flags;
+   UINT64  ErrorInfo;
+   UINT64  VirtualFaultAddress;
+   UINT64  PhysicalFaultAddress;
+} EFI_ARM_PROCESSOR_ERROR_DATA;
+
+//
+///
+/// The validation bit mask indicates which fields in the Cache info structure
+/// are valid.
+///@{
+#define EFI_CACHE_INFO_TRANSACTION_TYPE_VALID   BIT0
+#define EFI_CACHE_INFO_OPERATION_VALID  BIT1
+#define EFI_CACHE_INFO_LEVEL_VALID  BIT2
+#define EFI_CACHE_INFO_CONTEXT_CORRUPT_VALIDBIT3
+#define EFI_CACHE_INFO_CORRECTED_VALID  BIT4
+#define EFI_CACHE_INFO_PRECISE_PC_VALID BIT5
+#define EFI_CACHE_INFO_RESTARTABLE_PC_VALID BIT6
+///@}
+
+///
+/// Type of cache error in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_ERROR_TYPE_INSTRUCTION   0
+#define EFI_CACHE_INFO_ERROR_TYPE_DATA_ACCESS   1
+#define EFI_CACHE_INFO_ERROR_TYPE_GENERIC   2
+///@}
+
+///
+/// Type of cache operation that caused the error in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC 0
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC_READ1
+#define EFI_CACHE_INFO_OPERATION_TYPE_GENERIC_WRITE   2
+#define EFI_CACHE_INFO_OPERATION_TYPE_DATA_READ   3
+#define EFI_CACHE_INFO_OPERATION_TYPE_DATA_WRITE  4
+#define EFI_CACHE_INFO_OPERATION_TYPE_INSTRUCTION_FETCH   5
+#define EFI_CACHE_INFO_OPERATION_TYPE_PREFETCH6
+#define EFI_CACHE_INFO_OPERATION_TYPE_EVICTION7
+#define EFI_CACHE_INFO_OPERATION_TYPE_SNOOPING8
+#define EFI_CACHE_INFO_OPERATION_TYPE_SNOOPED 9
+#define EFI_CACHE_INFO_OPERATION_TYPE_MANAGEMENT  10
+///@}
+
+///
+/// Options of Processor context in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_CONTEXT_NOT_CORRUPTED   0
+#define EFI_CACHE_INFO_CONTEXT_CORRUPTED   1
+///@}
+
+///
+/// Error severity in the Cache info structure
+///@{
+#define EFI_CACHE_INFO_ERROR_SEVERITY_UnCORRECTED  0
+#define EFI_CACHE_INFO_ERROR_SEVERITY_CORRECTED1
+///@}
+
+//
+// ARM Processor Cache Error Structure
+//
+typedef struct {
+   UINT64  ValidBit:16;
+  UINT64  CacheType:2;
+  UINT64  Operation:4;
+  UINT64  CacheLevel:3;
+  UINT64  ContextCorrupt:1;
+  UINT64  Corrected:1;
+  UINT64

[edk2-devel] [PATCH v1 1/1] StandaloneMmPkg: Fix HOB space and heap space conflicted issue

2022-02-07 Thread Ming Huang
The heap space will be rewrote if a StandloneMmPkg module create HOB
by BuildGuidHob() interface and write data to HOB space.
Add a PCD PcdMemoryHobSize for pre-allocation a space to create HOB to
fix this issue.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
   | 11 ++-
 
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
 |  4 
 StandaloneMmPkg/StandaloneMmPkg.dec
   |  2 ++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
index eb0c1f82db..c9fb46c532 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
@@ -68,13 +68,14 @@ CreateHobListFromBootInfo (
   EFI_PROCESSOR_INFORMATION*ProcInfoBuffer;
   EFI_SECURE_PARTITION_CPU_INFO*CpuInfo;
   ARM_TF_CPU_DRIVER_EP_DESCRIPTOR  *CpuDriverEntryPointDesc;
+  UINT64   MaxHobSize = PcdGet64 (PcdMemoryHobSize);
 
   // Create a hoblist with a PHIT and EOH
   HobStart = HobConstructor (
(VOID *)(UINTN)PayloadBootInfo->SpMemBase,
(UINTN)PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase,
(VOID *)(UINTN)PayloadBootInfo->SpHeapBase,
-   (VOID *)(UINTN)(PayloadBootInfo->SpHeapBase + 
PayloadBootInfo->SpHeapSize)
+   (VOID *)(UINTN)(PayloadBootInfo->SpHeapBase +MaxHobSize)
);
 
   // Check that the Hoblist starts at the bottom of the Heap
@@ -192,13 +193,13 @@ CreateHobListFromBootInfo (
   // Base and size of heap memory shared by all cpus
   MmramRanges[4].PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart;
   MmramRanges[4].CpuStart  = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart;
-  MmramRanges[4].PhysicalSize  = HobStart->EfiFreeMemoryBottom - 
(EFI_PHYSICAL_ADDRESS)(UINTN)HobStart;
+  MmramRanges[4].PhysicalSize  = MaxHobSize;
   MmramRanges[4].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
 
   // Base and size of heap memory shared by all cpus
-  MmramRanges[5].PhysicalStart = HobStart->EfiFreeMemoryBottom;
-  MmramRanges[5].CpuStart  = HobStart->EfiFreeMemoryBottom;
-  MmramRanges[5].PhysicalSize  = HobStart->EfiFreeMemoryTop - 
HobStart->EfiFreeMemoryBottom;
+  MmramRanges[5].PhysicalStart = HobStart->EfiFreeMemoryTop;
+  MmramRanges[5].CpuStart  = HobStart->EfiFreeMemoryTop;
+  MmramRanges[5].PhysicalSize  = PayloadBootInfo->SpHeapSize - MaxHobSize;
   MmramRanges[5].RegionState   = EFI_CACHEABLE;
 
   return HobStart;
diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
index 75cfb98c0e..c469ac2cca 100644
--- 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
+++ 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
@@ -40,6 +40,7 @@
 [LibraryClasses]
   BaseLib
   DebugLib
+  PcdLib
 
 [LibraryClasses.ARM, LibraryClasses.AARCH64]
   StandaloneMmMmuLib
@@ -54,6 +55,9 @@
 [FeaturePcd.ARM, FeaturePcd.AARCH64]
   gArmTokenSpaceGuid.PcdFfaEnable
 
+[FixedPcd]
+  gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize
+
 #
 # This configuration fails for CLANGPDB, which does not support PIE in the GCC
 # sense. Such however is required for ARM family StandaloneMmCore
diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec 
b/StandaloneMmPkg/StandaloneMmPkg.dec
index 46784d94e4..cf554676e2 100644
--- a/StandaloneMmPkg/StandaloneMmPkg.dec
+++ b/StandaloneMmPkg/StandaloneMmPkg.dec
@@ -48,3 +48,5 @@
   gEfiStandaloneMmNonSecureBufferGuid  = { 0xf00497e3, 0xbfa2, 0x41a1, { 
0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }}
   gEfiArmTfCpuDriverEpDescriptorGuid   = { 0x6ecbd5a1, 0xc0f8, 0x4702, { 
0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }}
 
+[PcdsFixedAtBuild]
+  gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize|0x|UINT64|0x0004
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86438): https://edk2.groups.io/g/devel/message/86438
Mute This Topic: https://groups.io/mt/88988964/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH edk2 v3 0/3] Fix several issues in StanaloneMmPkg

2022-01-22 Thread Ming Huang
Hi,

Any comment about this series ?

在 12/31/21 7:06 PM, Ming Huang 写道:
> Changes since v2:
> Modify CheckBufferAddr() function.
> 
> Ming Huang (3):
>   StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field
>   StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR
>   StandaloneMmPkg: Fix check buffer address failed issue from TF-A
> 
>  .../Drivers/StandaloneMmCpu/EventHandle.c | 60 ++-
>  .../Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 33 --
>  .../Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>  .../Library/Arm/StandaloneMmCoreEntryPoint.h  |  2 +-
>  .../Arm/CreateHobList.c   |  2 +-
>  .../Arm/StandaloneMmCoreEntryPoint.c  |  2 +-
>  6 files changed, 75 insertions(+), 25 deletions(-)
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85961): https://edk2.groups.io/g/devel/message/85961
Mute This Topic: https://groups.io/mt/88052137/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v3 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-31 Thread Ming Huang
There are two scene communicate with StandaloneMm(MM):
1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
  specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
  specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;

For now, the second scene will failed because check buffer address.
This patch add CheckBufferAddr() to support check address for secure
buffer.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 54 
+++-
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21 
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
 3 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
index 5dfaf9d751..d0ba415671 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
@@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL;
 
 // Descriptor with whereabouts of memory used for communication with the 
normal world
 EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
+EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
 
 MP_INFORMATION_HOB_DATA *mMpInformationHobData;
 
@@ -60,6 +61,42 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
 
 STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
 
+STATIC
+EFI_STATUS
+CheckBufferAddr (
+  IN UINTN BufferAddr
+  )
+{
+  UINT64 NsCommBufferEnd;
+  UINT64 SCommBufferEnd;
+  UINT64 CommBufferEnd;
+
+  NsCommBufferEnd = mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize;
+  SCommBufferEnd = mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize;
+
+  if ((BufferAddr >= mNsCommBuffer.PhysicalStart) &&
+  (BufferAddr < NsCommBufferEnd)) {
+CommBufferEnd = NsCommBufferEnd;
+  } else if ((BufferAddr >= mSCommBuffer.PhysicalStart) &&
+ (BufferAddr < SCommBufferEnd)) {
+CommBufferEnd = SCommBufferEnd;
+  } else {
+return EFI_ACCESS_DENIED;
+  }
+
+  if ((CommBufferEnd - BufferAddr) < sizeof (EFI_MM_COMMUNICATE_HEADER)) {
+return EFI_ACCESS_DENIED;
+  }
+
+  // perform bounds check.
+  if ((CommBufferEnd - BufferAddr - sizeof (EFI_MM_COMMUNICATE_HEADER)) <
+  ((EFI_MM_COMMUNICATE_HEADER *) BufferAddr)->MessageLength) {
+return EFI_ACCESS_DENIED;
+  }
+
+  return EFI_SUCCESS;
+}
+
 /**
   The PI Standalone MM entry point for the TF-A CPU driver.
 
@@ -104,25 +141,16 @@ PiMmStandaloneArmTfCpuDriverEntry (
 return EFI_INVALID_PARAMETER;
   }
 
-  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
-return EFI_ACCESS_DENIED;
-  }
-
-  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
-  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
-return EFI_INVALID_PARAMETER;
+  Status = CheckBufferAddr (NsCommBufferAddr);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Check Buffer failed: %r\n", Status));
+return Status;
   }
 
   // Find out the size of the buffer passed
   NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
NsCommBufferAddr)->MessageLength +
 sizeof (EFI_MM_COMMUNICATE_HEADER);
 
-  // perform bounds check.
-  if (NsCommBufferAddr + NsCommBufferSize >=
-  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
-return EFI_ACCESS_DENIED;
-  }
-
   GuidedEventContext = NULL;
   // Now that the secure world can see the normal world buffer, allocate
   // memory to copy the communication buffer to the secure world.
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
index fd9c59b4da..96dad20dd1 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
@@ -107,6 +107,7 @@ StandaloneMmCpuInitialize (
   UINTNIndex;
   UINTNArraySize;
   VOID*HobStart;
+  EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHob;
 
   ASSERT (SystemTable != NULL);
   mMmst = SystemTable;
@@ -186,6 +187,26 @@ StandaloneMmCpuInitialize (
   CopyMem (, NsCommBufMmramRange, sizeof(EFI_MMRAM_DESCRIPTOR));
   DEBUG ((DEBUG_INFO, "mNsCommBuffer: 0x%016lx - 0x%lx\n", 
mNsCommBuffer.CpuStart, mNsCommBuffer.PhysicalSize));
 
+  Status = GetGuidedHobData (
+ HobStart,
+ ,
+ (VOID **) 
+ );
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "MmramRangesHob data extraction failed - 0x%x\n", 
Status));
+return Status;
+  }
+
+  //
+  // As CreateHobListFromBootInfo(), the base and size of buffer shared with
+  // privileged Secure world software is in second one.
+  //
+  CopyMem (
+,
+>Descriptor[0] + 1,
+sizeof(EFI_MMRAM_DESCRIPTOR)
+  );
+
   //
   // Extract 

[edk2-devel] [PATCH edk2 v3 2/3] StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR

2021-12-31 Thread Ming Huang
DEBUG_ERROR should be used in error branch.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c |  6 +++---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 12 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
index 165d696f99..5dfaf9d751 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
@@ -95,7 +95,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
   //
   if ((ARM_SMC_ID_MM_COMMUNICATE != EventId) &&
   (ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ != EventId)) {
-DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId));
+DEBUG ((DEBUG_ERROR, "UnRecognized Event - 0x%x\n", EventId));
 return EFI_INVALID_PARAMETER;
   }
 
@@ -133,7 +133,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
 );
 
   if (Status != EFI_SUCCESS) {
-DEBUG ((DEBUG_INFO, "Mem alloc failed - 0x%x\n", EventId));
+DEBUG ((DEBUG_ERROR, "Mem alloc failed - 0x%x\n", EventId));
 return EFI_OUT_OF_RESOURCES;
   }
 
@@ -156,7 +156,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
   mMmst->CpuSaveState = NULL;
 
   if (mMmEntryPoint == NULL) {
-DEBUG ((DEBUG_INFO, "Mm Entry point Not Found\n"));
+DEBUG ((DEBUG_ERROR, "Mm Entry point Not Found\n"));
 return EFI_UNSUPPORTED;
   }
 
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
index 10097f792f..fd9c59b4da 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
@@ -143,7 +143,7 @@ StandaloneMmCpuInitialize (
 
   // Bail out if the Hoblist could not be found
   if (Index >= mMmst->NumberOfTableEntries) {
-DEBUG ((DEBUG_INFO, "Hoblist not found - 0x%x\n", Index));
+DEBUG ((DEBUG_ERROR, "Hoblist not found - 0x%x\n", Index));
 return EFI_OUT_OF_RESOURCES;
   }
 
@@ -158,7 +158,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "ArmTfCpuDriverEpDesc HOB data extraction failed - 
0x%x\n", Status));
+DEBUG ((DEBUG_ERROR, "ArmTfCpuDriverEpDesc HOB data extraction failed - 
0x%x\n", Status));
 return Status;
   }
 
@@ -176,7 +176,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "NsCommBufMmramRange HOB data extraction failed - 
0x%x\n", Status));
+DEBUG ((DEBUG_ERROR, "NsCommBufMmramRange HOB data extraction failed - 
0x%x\n", Status));
 return Status;
   }
 
@@ -195,7 +195,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "MpInformationHob extraction failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "MpInformationHob extraction failed - 0x%x\n", 
Status));
 return Status;
   }
 
@@ -213,7 +213,7 @@ StandaloneMmCpuInitialize (
 (VOID **) 
 );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "mMpInformationHobData mem alloc failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "mMpInformationHobData mem alloc failed - 0x%x\n", 
Status));
 return Status;
   }
 
@@ -243,7 +243,7 @@ StandaloneMmCpuInitialize (
 (VOID **) 
 );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", 
Status));
 return Status;
   }
   return Status;
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85242): https://edk2.groups.io/g/devel/message/85242
Mute This Topic: https://groups.io/mt/88052138/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v3 1/3] StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field

2021-12-31 Thread Ming Huang
TF-A: TrustedFirmware-A
SPM: Secure Partition Manager(MM)

In TF-A, the name of this field is sp_shared_buf_size. This field is
the size of range for transmit data from TF-A to standaloneMM when
SPM enable.

SpPcpuSharedBufSize is pass from TF-A while StandaloneMM initialize.
So, SpPcpuSharedBufSize should be rename to SpSharedBufSize and this field
should no multiply by PayloadBootInfo->NumCpus;

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h   
 | 2 +-
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
 | 2 +-
 
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
 | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h 
b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
index c44f7066c6..f1683ecb61 100644
--- a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
+++ b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
@@ -41,7 +41,7 @@ typedef struct {
   UINT64SpPcpuStackSize;
   UINT64SpHeapSize;
   UINT64SpNsCommBufSize;
-  UINT64SpPcpuSharedBufSize;
+  UINT64SpSharedBufSize;
   UINT32NumSpMemRegions;
   UINT32NumCpus;
   EFI_SECURE_PARTITION_CPU_INFO *CpuInfo;
diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
index 85f8194687..93773c9fe8 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
@@ -173,7 +173,7 @@ CreateHobListFromBootInfo (
   // Base and size of buffer shared with privileged Secure world software
   MmramRanges[1].PhysicalStart = PayloadBootInfo->SpSharedBufBase;
   MmramRanges[1].CpuStart  = PayloadBootInfo->SpSharedBufBase;
-  MmramRanges[1].PhysicalSize  = PayloadBootInfo->SpPcpuSharedBufSize * 
PayloadBootInfo->NumCpus;
+  MmramRanges[1].PhysicalSize  = PayloadBootInfo->SpSharedBufSize;
   MmramRanges[1].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
 
   // Base and size of buffer used for synchronous communication with Normal
diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
index 49cf51a789..5db7019dda 100644
--- 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
+++ 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
@@ -87,7 +87,7 @@ GetAndPrintBootinformation (
   DEBUG ((DEBUG_INFO, "SpPcpuStackSize - 0x%x\n", 
PayloadBootInfo->SpPcpuStackSize));
   DEBUG ((DEBUG_INFO, "SpHeapSize  - 0x%x\n", 
PayloadBootInfo->SpHeapSize));
   DEBUG ((DEBUG_INFO, "SpNsCommBufSize - 0x%x\n", 
PayloadBootInfo->SpNsCommBufSize));
-  DEBUG ((DEBUG_INFO, "SpPcpuSharedBufSize - 0x%x\n", 
PayloadBootInfo->SpPcpuSharedBufSize));
+  DEBUG ((DEBUG_INFO, "SpSharedBufSize - 0x%x\n", 
PayloadBootInfo->SpSharedBufSize));
 
   DEBUG ((DEBUG_INFO, "NumCpus - 0x%x\n", PayloadBootInfo->NumCpus));
   DEBUG ((DEBUG_INFO, "CpuInfo - 0x%p\n", PayloadBootInfo->CpuInfo));
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85243): https://edk2.groups.io/g/devel/message/85243
Mute This Topic: https://groups.io/mt/88052139/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v3 0/3] Fix several issues in StanaloneMmPkg

2021-12-31 Thread Ming Huang
Changes since v2:
Modify CheckBufferAddr() function.

Ming Huang (3):
  StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field
  StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR
  StandaloneMmPkg: Fix check buffer address failed issue from TF-A

 .../Drivers/StandaloneMmCpu/EventHandle.c | 60 ++-
 .../Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 33 --
 .../Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
 .../Library/Arm/StandaloneMmCoreEntryPoint.h  |  2 +-
 .../Arm/CreateHobList.c   |  2 +-
 .../Arm/StandaloneMmCoreEntryPoint.c  |  2 +-
 6 files changed, 75 insertions(+), 25 deletions(-)

-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85241): https://edk2.groups.io/g/devel/message/85241
Mute This Topic: https://groups.io/mt/88052137/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH edk2 v1 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-31 Thread Ming Huang



在 12/30/21 8:27 PM, Marvin Häuser 写道:
> 
> 
> On 25.12.21 03:09, Ming Huang wrote:
>>
>> 在 12/24/21 9:52 PM, Marvin Häuser 写道:
>>> On 24.12.21 02:18, Ming Huang wrote:
>>>> 在 12/23/21 7:05 PM, Marvin Häuser 写道:
>>>>> On 23.12.21 11:46, Ming Huang wrote:
>>>>>> 在 12/16/21 5:15 PM, Marvin Häuser 写道:
>>>>>>> Hey all,
>>>>>>>
>>>>>>>> On 15. Dec 2021, at 16:02, Ming Huang  
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> 
>>>>>>>>
>>>>>>>>> On 12/9/21 1:46 AM, Omkar Anand Kulkarni wrote:
>>>>>>>>> Hi Ming,
>>>>>>>>> Thanks for this patch. This patch helps to resolve Standalone MM 
>>>>>>>>> issue while exercising RAS use case.
>>>>>>>>> Few comments mentioned inline.
>>>>>>>>> - Omkar
>>>>>>>>>> On 10/15/21 2:39 PM, Ming Huang via groups.io wrote:
>>>>>>>>>> There are two scene communicate with StandaloneMm(MM):
>>>>>>>>>> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>>>>>>>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
>>>>>>>>>> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>>>>>>>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
>>>>>>>>>> For now, the second scene will failed because check buffer address.
>>>>>>>>>> This patch add CheckBufferAddr() to support check address for secure 
>>>>>>>>>> buffer.
>>>>>>>>>> Signed-off-by: Ming Huang 
>>>>>>>>>> ---
>>>>>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 70
>>>>>>>>>> 
>>>>>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21
>>>>>>>>>> ++
>>>>>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>>>>>>>>>> 3 files changed, 79 insertions(+), 13 deletions(-)
>>>>>>>>>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>>>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>>>> index 5dfaf9d751..63fab1bd78 100644
>>>>>>>>>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>>>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>>>> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER
>>>>>>>>>> **PerCpuGuidedEventContext = NULL;
>>>>>>>>>> // Descriptor with whereabouts of memory used for communication with
>>>>>>>>>> the normal world  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
>>>>>>>>>> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>>>>>>>>>> MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>>>>>>>>>> @@ -60,6 +61,58 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig =
>>>>>>>>>> {
>>>>>>>>>> STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>>>>>>>>>> +STATIC
>>>>>>>>>> +EFI_STATUS
>>>>>>>>>> +CheckBufferAddr (
>>>>>>>>>> +  IN UINTN CommBufferAddr
>>>>>>>>>> +  )
>>>>>>>>>> +{
>>>>>>>>>> +  UINTN  CommBufferSize;
>>>>>>>>>> +  EFI_STATUS Status;
>>>>>>>>>> +
>>>>>>>>>> +  Status =  EFI_SUCCESS;
>>>>>>>>>> +  if (CommBufferAddr < mNsCommBuffer.PhysicalStart) {
>>>>>>>>>> +    Status = EFI_ACCESS_DENIED;
>>>>>>>>>> +  }
>>>>>>>>>> +
>>>>>>>>>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>>>>>>>>>> +  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>>>>>>>>>> +    Status =  EFI_INVALID_PARAMETER;
>>>>>>

Re: [edk2-devel] [PATCH edk2 v1 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-24 Thread Ming Huang



在 12/24/21 9:52 PM, Marvin Häuser 写道:
> On 24.12.21 02:18, Ming Huang wrote:
>>
>> 在 12/23/21 7:05 PM, Marvin Häuser 写道:
>>> On 23.12.21 11:46, Ming Huang wrote:
>>>> 在 12/16/21 5:15 PM, Marvin Häuser 写道:
>>>>> Hey all,
>>>>>
>>>>>> On 15. Dec 2021, at 16:02, Ming Huang  
>>>>>> wrote:
>>>>>>
>>>>>> 
>>>>>>
>>>>>>> On 12/9/21 1:46 AM, Omkar Anand Kulkarni wrote:
>>>>>>> Hi Ming,
>>>>>>> Thanks for this patch. This patch helps to resolve Standalone MM issue 
>>>>>>> while exercising RAS use case.
>>>>>>> Few comments mentioned inline.
>>>>>>> - Omkar
>>>>>>>> On 10/15/21 2:39 PM, Ming Huang via groups.io wrote:
>>>>>>>> There are two scene communicate with StandaloneMm(MM):
>>>>>>>> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>>>>>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
>>>>>>>> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>>>>>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
>>>>>>>> For now, the second scene will failed because check buffer address.
>>>>>>>> This patch add CheckBufferAddr() to support check address for secure 
>>>>>>>> buffer.
>>>>>>>> Signed-off-by: Ming Huang 
>>>>>>>> ---
>>>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 70
>>>>>>>> 
>>>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21
>>>>>>>> ++
>>>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>>>>>>>> 3 files changed, 79 insertions(+), 13 deletions(-)
>>>>>>>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>> index 5dfaf9d751..63fab1bd78 100644
>>>>>>>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>>>> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER
>>>>>>>> **PerCpuGuidedEventContext = NULL;
>>>>>>>> // Descriptor with whereabouts of memory used for communication with
>>>>>>>> the normal world  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
>>>>>>>> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>>>>>>>> MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>>>>>>>> @@ -60,6 +61,58 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig =
>>>>>>>> {
>>>>>>>> STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>>>>>>>> +STATIC
>>>>>>>> +EFI_STATUS
>>>>>>>> +CheckBufferAddr (
>>>>>>>> +  IN UINTN CommBufferAddr
>>>>>>>> +  )
>>>>>>>> +{
>>>>>>>> +  UINTN  CommBufferSize;
>>>>>>>> +  EFI_STATUS Status;
>>>>>>>> +
>>>>>>>> +  Status =  EFI_SUCCESS;
>>>>>>>> +  if (CommBufferAddr < mNsCommBuffer.PhysicalStart) {
>>>>>>>> +    Status = EFI_ACCESS_DENIED;
>>>>>>>> +  }
>>>>>>>> +
>>>>>>>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>>>>>>>> +  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>>>>>>>> +    Status =  EFI_INVALID_PARAMETER;
>>>>>>> Single space after "Status = "
>>>>>> Modify it in v2.
>>>>>>
>>>>>>> - Omkar
>>>>>>>> +  }
>>>>>>>> +
>>>>>>>> +  // Find out the size of the buffer passed  CommBufferSize =
>>>>>>>> + ((EFI_MM_COMMUNICATE_HEADER *) CommBufferAddr)->MessageLength
>>>>>>>> +
>>>>>>>> +    sizeof (EFI_MM_COMMUNICATE_HEADER);
>>>>>>>> +
>>>>>>>> +  // perform bounds check.
>>

Re: [edk2-devel] [PATCH edk2 v1 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-23 Thread Ming Huang



在 12/23/21 7:05 PM, Marvin Häuser 写道:
> On 23.12.21 11:46, Ming Huang wrote:
>>
>> 在 12/16/21 5:15 PM, Marvin Häuser 写道:
>>> Hey all,
>>>
>>>> On 15. Dec 2021, at 16:02, Ming Huang  wrote:
>>>>
>>>> 
>>>>
>>>>> On 12/9/21 1:46 AM, Omkar Anand Kulkarni wrote:
>>>>> Hi Ming,
>>>>> Thanks for this patch. This patch helps to resolve Standalone MM issue 
>>>>> while exercising RAS use case.
>>>>> Few comments mentioned inline.
>>>>> - Omkar
>>>>>> On 10/15/21 2:39 PM, Ming Huang via groups.io wrote:
>>>>>> There are two scene communicate with StandaloneMm(MM):
>>>>>> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>>>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
>>>>>> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>>>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
>>>>>> For now, the second scene will failed because check buffer address.
>>>>>> This patch add CheckBufferAddr() to support check address for secure 
>>>>>> buffer.
>>>>>> Signed-off-by: Ming Huang 
>>>>>> ---
>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 70
>>>>>> 
>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21
>>>>>> ++
>>>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>>>>>> 3 files changed, 79 insertions(+), 13 deletions(-)
>>>>>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>> index 5dfaf9d751..63fab1bd78 100644
>>>>>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>>>> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER
>>>>>> **PerCpuGuidedEventContext = NULL;
>>>>>> // Descriptor with whereabouts of memory used for communication with
>>>>>> the normal world  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
>>>>>> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>>>>>> MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>>>>>> @@ -60,6 +61,58 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig =
>>>>>> {
>>>>>> STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>>>>>> +STATIC
>>>>>> +EFI_STATUS
>>>>>> +CheckBufferAddr (
>>>>>> +  IN UINTN CommBufferAddr
>>>>>> +  )
>>>>>> +{
>>>>>> +  UINTN  CommBufferSize;
>>>>>> +  EFI_STATUS Status;
>>>>>> +
>>>>>> +  Status =  EFI_SUCCESS;
>>>>>> +  if (CommBufferAddr < mNsCommBuffer.PhysicalStart) {
>>>>>> +    Status = EFI_ACCESS_DENIED;
>>>>>> +  }
>>>>>> +
>>>>>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>>>>>> +  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>>>>>> +    Status =  EFI_INVALID_PARAMETER;
>>>>> Single space after "Status = "
>>>> Modify it in v2.
>>>>
>>>>> - Omkar
>>>>>> +  }
>>>>>> +
>>>>>> +  // Find out the size of the buffer passed  CommBufferSize =
>>>>>> + ((EFI_MM_COMMUNICATE_HEADER *) CommBufferAddr)->MessageLength
>>>>>> +
>>>>>> +    sizeof (EFI_MM_COMMUNICATE_HEADER);
>>>>>> +
>>>>>> +  // perform bounds check.
>>>>>> +  if (CommBufferAddr + CommBufferSize >=
>>>>>> +  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
>>>>>> +    Status =  EFI_ACCESS_DENIED;
>>>>> Single space after "Status = "
>>>> Modify it in v2.
>>>>
>>>>> - Omkar
>>>>>> +  }
>>>>>> +
>>>>>> +  if (!EFI_ERROR (Status)) {
>>>>> In case of error this function call will not return from here. It will 
>>>>> execute the code below comparing the MM Communicate buffer address with 
>>>>> the Secure buffer addres

Re: [edk2-devel] [PATCH edk2 v1 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-23 Thread Ming Huang



在 12/16/21 5:15 PM, Marvin Häuser 写道:
> Hey all,
> 
>> On 15. Dec 2021, at 16:02, Ming Huang  wrote:
>>
>> 
>>
>>> On 12/9/21 1:46 AM, Omkar Anand Kulkarni wrote:
>>> Hi Ming,
>>> Thanks for this patch. This patch helps to resolve Standalone MM issue 
>>> while exercising RAS use case.
>>> Few comments mentioned inline.
>>> - Omkar
>>>> On 10/15/21 2:39 PM, Ming Huang via groups.io wrote:
>>>> There are two scene communicate with StandaloneMm(MM):
>>>> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
>>>> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>>>> specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
>>>> For now, the second scene will failed because check buffer address.
>>>> This patch add CheckBufferAddr() to support check address for secure 
>>>> buffer.
>>>> Signed-off-by: Ming Huang 
>>>> ---
>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 70
>>>> 
>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21
>>>> ++
>>>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>>>> 3 files changed, 79 insertions(+), 13 deletions(-)
>>>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>> index 5dfaf9d751..63fab1bd78 100644
>>>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>>>> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER
>>>> **PerCpuGuidedEventContext = NULL;
>>>> // Descriptor with whereabouts of memory used for communication with
>>>> the normal world  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
>>>> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>>>> MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>>>> @@ -60,6 +61,58 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig =
>>>> {
>>>> STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>>>> +STATIC
>>>> +EFI_STATUS
>>>> +CheckBufferAddr (
>>>> +  IN UINTN CommBufferAddr
>>>> +  )
>>>> +{
>>>> +  UINTN  CommBufferSize;
>>>> +  EFI_STATUS Status;
>>>> +
>>>> +  Status =  EFI_SUCCESS;
>>>> +  if (CommBufferAddr < mNsCommBuffer.PhysicalStart) {
>>>> +Status = EFI_ACCESS_DENIED;
>>>> +  }
>>>> +
>>>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>>>> +  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>>>> +Status =  EFI_INVALID_PARAMETER;
>>> Single space after "Status = "
>>
>> Modify it in v2.
>>
>>> - Omkar
>>>> +  }
>>>> +
>>>> +  // Find out the size of the buffer passed  CommBufferSize =
>>>> + ((EFI_MM_COMMUNICATE_HEADER *) CommBufferAddr)->MessageLength
>>>> +
>>>> +sizeof (EFI_MM_COMMUNICATE_HEADER);
>>>> +
>>>> +  // perform bounds check.
>>>> +  if (CommBufferAddr + CommBufferSize >=
>>>> +  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
>>>> +Status =  EFI_ACCESS_DENIED;
>>> Single space after "Status = "
>>
>> Modify it in v2.
>>
>>> - Omkar
>>>> +  }
>>>> +
>>>> +  if (!EFI_ERROR (Status)) {
>>> In case of error this function call will not return from here. It will 
>>> execute the code below comparing the MM Communicate buffer address with the 
>>> Secure buffer address, which may cause wrong return type being returned. 
>>> Can you check this, please?
>>> - Omkar
>>>> +return EFI_SUCCESS;
>>>> +  }
>>>> +
>>>> +  Status =  EFI_SUCCESS;
>>>> +  if (CommBufferAddr < mSCommBuffer.PhysicalStart) {
>>>> +Status = EFI_ACCESS_DENIED;
>>>> +  }
>>>> +
>>>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>>>> +  (mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize)) {
>>>> +Status =  EFI_INVALID_PARAMETER;
>>>> +  }
>>>> +
>>>> +  // perform bounds check.
>>>> +  if (CommBufferAddr + CommBu

Re: [edk2-devel] [PATCH edk2 v2 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-23 Thread Ming Huang
Hi Marvin,

Apologize for missing your email. My thunderbird is odd that your email did't 
show in the thread.
Reply your comment in that email.

Thanks.

- Ming

在 12/22/21 9:01 PM, Marvin Häuser 写道:
> Hey Ming,
> 
> Please check 
> https://edk2.groups.io/g/devel/message/84973?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Arecentpostdate%2Fsticky%2C%2CMarvin%2C20%2C2%2C0%2C86334815
> While a few comments were cosmetical, there is an invalid memory access 
> outlined too, which persists in this patch.
> 
> For the future, this should also check buffer alignment before casting (lets 
> hope my corresponding patch passes review within this decade...).
> 
> Best regards,
> Marvin
> 
> On 21.12.21 16:06, Ming Huang wrote:
>> There are two scene communicate with StandaloneMm(MM):
>> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>>    specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
>> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>>    specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
>>
>> For now, the second scene will failed because check buffer address.
>> This patch add CheckBufferAddr() to support check address for secure
>> buffer.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>   StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 59 
>> +++-
>>   StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21 +++
>>   StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>>   3 files changed, 68 insertions(+), 13 deletions(-)
>>
>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> index 5dfaf9d751..ba8639a26a 100644
>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = 
>> NULL;
>>     // Descriptor with whereabouts of memory used for communication with the 
>> normal world
>>   EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
>> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>>     MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>>   @@ -60,6 +61,47 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
>>     STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>>   +STATIC
>> +EFI_STATUS
>> +CheckBufferAddr (
>> +  IN UINTN CommBufferAddr
>> +  )
>> +{
>> +  UINTN  CommBufferSize;
>> +  EFI_STATUS Status;
>> +  UINT64 NsCommBufferEnd;
>> +  UINT64 SCommBufferEnd;
>> +  UINT64 CommBufferEnd;
>> +
>> +  Status = EFI_SUCCESS;
>> +  NsCommBufferEnd = mNsCommBuffer.PhysicalStart + 
>> mNsCommBuffer.PhysicalSize;
>> +  SCommBufferEnd = mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize;
>> +
>> +  if ((CommBufferAddr >= mNsCommBuffer.PhysicalStart) &&
>> +  (CommBufferAddr < NsCommBufferEnd)) {
>> +    CommBufferEnd = NsCommBufferEnd;
>> +  } else if ((CommBufferAddr >= mSCommBuffer.PhysicalStart) &&
>> + (CommBufferAddr <= SCommBufferEnd)) {
>> +    CommBufferEnd = SCommBufferEnd;
>> +  } else {
>> +    return EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >= 
>> CommBufferEnd) {
>> +    Status = EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  // Find out the size of the buffer passed
>> +  CommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
>> CommBufferAddr)->MessageLength +
>> +    sizeof (EFI_MM_COMMUNICATE_HEADER);
>> +  // perform bounds check.
>> +  if (CommBufferAddr + CommBufferSize >= CommBufferEnd) {
>> +    Status = EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  return Status;
>> +}
>> +
>>   /**
>>     The PI Standalone MM entry point for the TF-A CPU driver.
>>   @@ -104,25 +146,16 @@ PiMmStandaloneArmTfCpuDriverEntry (
>>   return EFI_INVALID_PARAMETER;
>>     }
>>   -  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
>> -    return EFI_ACCESS_DENIED;
>> -  }
>> -
>> -  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>> -  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>> -    return EFI_INVALID_PARAMETER;
>> +  Status = CheckBufferAddr (NsCommBufferAddr);
>> +  if (EFI_ERROR (Status)) {
>> +    DEBUG ((DEBUG_ERROR, "Check Buffer failed: %r\n", Status));
>> +    return Status;
>>     }
>>       // Find out the size of the buffer passed
>>     NsCommBufferSiz

[edk2-devel] [PATCH edk2 v2 2/3] StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR

2021-12-21 Thread Ming Huang
DEBUG_ERROR should be used in error branch.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c |  6 +++---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 12 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
index 165d696f99..5dfaf9d751 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
@@ -95,7 +95,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
   //
   if ((ARM_SMC_ID_MM_COMMUNICATE != EventId) &&
   (ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ != EventId)) {
-DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId));
+DEBUG ((DEBUG_ERROR, "UnRecognized Event - 0x%x\n", EventId));
 return EFI_INVALID_PARAMETER;
   }
 
@@ -133,7 +133,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
 );
 
   if (Status != EFI_SUCCESS) {
-DEBUG ((DEBUG_INFO, "Mem alloc failed - 0x%x\n", EventId));
+DEBUG ((DEBUG_ERROR, "Mem alloc failed - 0x%x\n", EventId));
 return EFI_OUT_OF_RESOURCES;
   }
 
@@ -156,7 +156,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
   mMmst->CpuSaveState = NULL;
 
   if (mMmEntryPoint == NULL) {
-DEBUG ((DEBUG_INFO, "Mm Entry point Not Found\n"));
+DEBUG ((DEBUG_ERROR, "Mm Entry point Not Found\n"));
 return EFI_UNSUPPORTED;
   }
 
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
index 10097f792f..fd9c59b4da 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
@@ -143,7 +143,7 @@ StandaloneMmCpuInitialize (
 
   // Bail out if the Hoblist could not be found
   if (Index >= mMmst->NumberOfTableEntries) {
-DEBUG ((DEBUG_INFO, "Hoblist not found - 0x%x\n", Index));
+DEBUG ((DEBUG_ERROR, "Hoblist not found - 0x%x\n", Index));
 return EFI_OUT_OF_RESOURCES;
   }
 
@@ -158,7 +158,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "ArmTfCpuDriverEpDesc HOB data extraction failed - 
0x%x\n", Status));
+DEBUG ((DEBUG_ERROR, "ArmTfCpuDriverEpDesc HOB data extraction failed - 
0x%x\n", Status));
 return Status;
   }
 
@@ -176,7 +176,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "NsCommBufMmramRange HOB data extraction failed - 
0x%x\n", Status));
+DEBUG ((DEBUG_ERROR, "NsCommBufMmramRange HOB data extraction failed - 
0x%x\n", Status));
 return Status;
   }
 
@@ -195,7 +195,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "MpInformationHob extraction failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "MpInformationHob extraction failed - 0x%x\n", 
Status));
 return Status;
   }
 
@@ -213,7 +213,7 @@ StandaloneMmCpuInitialize (
 (VOID **) 
 );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "mMpInformationHobData mem alloc failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "mMpInformationHobData mem alloc failed - 0x%x\n", 
Status));
 return Status;
   }
 
@@ -243,7 +243,7 @@ StandaloneMmCpuInitialize (
 (VOID **) 
 );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", 
Status));
 return Status;
   }
   return Status;
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85134): https://edk2.groups.io/g/devel/message/85134
Mute This Topic: https://groups.io/mt/87878746/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v2 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-21 Thread Ming Huang
There are two scene communicate with StandaloneMm(MM):
1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
  specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
  specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;

For now, the second scene will failed because check buffer address.
This patch add CheckBufferAddr() to support check address for secure
buffer.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 59 
+++-
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21 +++
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
 3 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
index 5dfaf9d751..ba8639a26a 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
@@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL;
 
 // Descriptor with whereabouts of memory used for communication with the 
normal world
 EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
+EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
 
 MP_INFORMATION_HOB_DATA *mMpInformationHobData;
 
@@ -60,6 +61,47 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
 
 STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
 
+STATIC
+EFI_STATUS
+CheckBufferAddr (
+  IN UINTN CommBufferAddr
+  )
+{
+  UINTN  CommBufferSize;
+  EFI_STATUS Status;
+  UINT64 NsCommBufferEnd;
+  UINT64 SCommBufferEnd;
+  UINT64 CommBufferEnd;
+
+  Status = EFI_SUCCESS;
+  NsCommBufferEnd = mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize;
+  SCommBufferEnd = mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize;
+
+  if ((CommBufferAddr >= mNsCommBuffer.PhysicalStart) &&
+  (CommBufferAddr < NsCommBufferEnd)) {
+CommBufferEnd = NsCommBufferEnd;
+  } else if ((CommBufferAddr >= mSCommBuffer.PhysicalStart) &&
+ (CommBufferAddr <= SCommBufferEnd)) {
+CommBufferEnd = SCommBufferEnd;
+  } else {
+return EFI_ACCESS_DENIED;
+  }
+
+  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >= CommBufferEnd) {
+Status = EFI_INVALID_PARAMETER;
+  }
+
+  // Find out the size of the buffer passed
+  CommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
CommBufferAddr)->MessageLength +
+sizeof (EFI_MM_COMMUNICATE_HEADER);
+  // perform bounds check.
+  if (CommBufferAddr + CommBufferSize >= CommBufferEnd) {
+Status = EFI_ACCESS_DENIED;
+  }
+
+  return Status;
+}
+
 /**
   The PI Standalone MM entry point for the TF-A CPU driver.
 
@@ -104,25 +146,16 @@ PiMmStandaloneArmTfCpuDriverEntry (
 return EFI_INVALID_PARAMETER;
   }
 
-  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
-return EFI_ACCESS_DENIED;
-  }
-
-  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
-  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
-return EFI_INVALID_PARAMETER;
+  Status = CheckBufferAddr (NsCommBufferAddr);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Check Buffer failed: %r\n", Status));
+return Status;
   }
 
   // Find out the size of the buffer passed
   NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
NsCommBufferAddr)->MessageLength +
 sizeof (EFI_MM_COMMUNICATE_HEADER);
 
-  // perform bounds check.
-  if (NsCommBufferAddr + NsCommBufferSize >=
-  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
-return EFI_ACCESS_DENIED;
-  }
-
   GuidedEventContext = NULL;
   // Now that the secure world can see the normal world buffer, allocate
   // memory to copy the communication buffer to the secure world.
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
index fd9c59b4da..96dad20dd1 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
@@ -107,6 +107,7 @@ StandaloneMmCpuInitialize (
   UINTNIndex;
   UINTNArraySize;
   VOID*HobStart;
+  EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHob;
 
   ASSERT (SystemTable != NULL);
   mMmst = SystemTable;
@@ -186,6 +187,26 @@ StandaloneMmCpuInitialize (
   CopyMem (, NsCommBufMmramRange, sizeof(EFI_MMRAM_DESCRIPTOR));
   DEBUG ((DEBUG_INFO, "mNsCommBuffer: 0x%016lx - 0x%lx\n", 
mNsCommBuffer.CpuStart, mNsCommBuffer.PhysicalSize));
 
+  Status = GetGuidedHobData (
+ HobStart,
+ ,
+ (VOID **) 
+ );
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "MmramRangesHob data extraction failed - 0x%x\n", 
Status));
+return Status;
+  }
+
+  //
+  // As CreateHobListFromBootInfo(), the 

[edk2-devel] [PATCH edk2 v2 1/3] StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field

2021-12-21 Thread Ming Huang
TF-A: TrustedFirmware-A
SPM: Secure Partition Manager(MM)

In TF-A, the name of this field is sp_shared_buf_size. This field is
the size of range for transmit data from TF-A to standaloneMM when
SPM enable.

SpPcpuSharedBufSize is pass from TF-A while StandaloneMM initialize.
So, SpPcpuSharedBufSize should be rename to SpSharedBufSize and this field
should no multiply by PayloadBootInfo->NumCpus;

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h   
 | 2 +-
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
 | 2 +-
 
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
 | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h 
b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
index c44f7066c6..f1683ecb61 100644
--- a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
+++ b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
@@ -41,7 +41,7 @@ typedef struct {
   UINT64SpPcpuStackSize;
   UINT64SpHeapSize;
   UINT64SpNsCommBufSize;
-  UINT64SpPcpuSharedBufSize;
+  UINT64SpSharedBufSize;
   UINT32NumSpMemRegions;
   UINT32NumCpus;
   EFI_SECURE_PARTITION_CPU_INFO *CpuInfo;
diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
index 85f8194687..93773c9fe8 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
@@ -173,7 +173,7 @@ CreateHobListFromBootInfo (
   // Base and size of buffer shared with privileged Secure world software
   MmramRanges[1].PhysicalStart = PayloadBootInfo->SpSharedBufBase;
   MmramRanges[1].CpuStart  = PayloadBootInfo->SpSharedBufBase;
-  MmramRanges[1].PhysicalSize  = PayloadBootInfo->SpPcpuSharedBufSize * 
PayloadBootInfo->NumCpus;
+  MmramRanges[1].PhysicalSize  = PayloadBootInfo->SpSharedBufSize;
   MmramRanges[1].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
 
   // Base and size of buffer used for synchronous communication with Normal
diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
index 49cf51a789..5db7019dda 100644
--- 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
+++ 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
@@ -87,7 +87,7 @@ GetAndPrintBootinformation (
   DEBUG ((DEBUG_INFO, "SpPcpuStackSize - 0x%x\n", 
PayloadBootInfo->SpPcpuStackSize));
   DEBUG ((DEBUG_INFO, "SpHeapSize  - 0x%x\n", 
PayloadBootInfo->SpHeapSize));
   DEBUG ((DEBUG_INFO, "SpNsCommBufSize - 0x%x\n", 
PayloadBootInfo->SpNsCommBufSize));
-  DEBUG ((DEBUG_INFO, "SpPcpuSharedBufSize - 0x%x\n", 
PayloadBootInfo->SpPcpuSharedBufSize));
+  DEBUG ((DEBUG_INFO, "SpSharedBufSize - 0x%x\n", 
PayloadBootInfo->SpSharedBufSize));
 
   DEBUG ((DEBUG_INFO, "NumCpus - 0x%x\n", PayloadBootInfo->NumCpus));
   DEBUG ((DEBUG_INFO, "CpuInfo - 0x%p\n", PayloadBootInfo->CpuInfo));
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85135): https://edk2.groups.io/g/devel/message/85135
Mute This Topic: https://groups.io/mt/87878747/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v2 0/3] Fix several issues in StanaloneMmPkg

2021-12-21 Thread Ming Huang
Changes since v1:
Modify CheckBufferAddr() function.

Ming Huang (3):
  StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field
  StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR
  StandaloneMmPkg: Fix check buffer address failed issue from TF-A

 .../Drivers/StandaloneMmCpu/EventHandle.c | 65 ++-
 .../Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 33 --
 .../Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
 .../Library/Arm/StandaloneMmCoreEntryPoint.h  |  2 +-
 .../Arm/CreateHobList.c   |  2 +-
 .../Arm/StandaloneMmCoreEntryPoint.c  |  2 +-
 6 files changed, 80 insertions(+), 25 deletions(-)

-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85132): https://edk2.groups.io/g/devel/message/85132
Mute This Topic: https://groups.io/mt/87878743/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH edk2 v1 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-21 Thread Ming Huang



在 12/9/21 1:46 AM, Omkar Anand Kulkarni 写道:
> Hi Ming,
> 
> Thanks for this patch. This patch helps to resolve Standalone MM issue while 
> exercising RAS use case.
> Few comments mentioned inline.
> 
> - Omkar
> 
> 
>  On 10/15/21 2:39 PM, Ming Huang via groups.io wrote:
>> There are two scene communicate with StandaloneMm(MM):
>> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>>   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
>> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>>   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
>>
>> For now, the second scene will failed because check buffer address.
>> This patch add CheckBufferAddr() to support check address for secure buffer.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 70
>> 
>>  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21
>> ++
>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>>  3 files changed, 79 insertions(+), 13 deletions(-)
>>
>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> index 5dfaf9d751..63fab1bd78 100644
>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER
>> **PerCpuGuidedEventContext = NULL;
>>
>>  // Descriptor with whereabouts of memory used for communication with
>> the normal world  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
>> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>>
>>  MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>>
>> @@ -60,6 +61,58 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig =
>> {
>>
>>  STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>>
>> +STATIC
>> +EFI_STATUS
>> +CheckBufferAddr (
>> +  IN UINTN CommBufferAddr
>> +  )
>> +{
>> +  UINTN  CommBufferSize;
>> +  EFI_STATUS Status;
>> +
>> +  Status =  EFI_SUCCESS;
>> +  if (CommBufferAddr < mNsCommBuffer.PhysicalStart) {
>> +Status = EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>> +  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>> +Status =  EFI_INVALID_PARAMETER;
> 
> Single space after "Status = "
> 
> - Omkar
> 
> 
>> +  }
>> +
>> +  // Find out the size of the buffer passed  CommBufferSize =
>> + ((EFI_MM_COMMUNICATE_HEADER *) CommBufferAddr)->MessageLength
>> +
>> +sizeof (EFI_MM_COMMUNICATE_HEADER);
>> +
>> +  // perform bounds check.
>> +  if (CommBufferAddr + CommBufferSize >=
>> +  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
>> +Status =  EFI_ACCESS_DENIED;
> 
> Single space after "Status = "
> 
> - Omkar
> 
>> +  }
>> +
>> +  if (!EFI_ERROR (Status)) {
> 
> 
> In case of error this function call will not return from here. It will 
> execute the code below comparing the MM Communicate buffer address with the 
> Secure buffer address, which may cause wrong return type being returned. Can 
> you check this, please?
> 
> - Omkar
> 
> 
>> +return EFI_SUCCESS;
>> +  }
>> +
>> +  Status =  EFI_SUCCESS;
>> +  if (CommBufferAddr < mSCommBuffer.PhysicalStart) {
>> +Status = EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>> +  (mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize)) {
>> +Status =  EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  // perform bounds check.
>> +  if (CommBufferAddr + CommBufferSize >=
>> +  mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize) {
>> +Status =  EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  return Status;
>> +}
>> +
> 
> 
> CheckBufferAddr() function performs validity and overflow checks on the 
> Communication buffers. These checks are same for both the non-secure
> MM communicate buffer and secure buffer shared between EL3 and S-EL0. Can 
> this code be combined ( example below)? This will help mitigate the above 
> mentioned return type issue as well.
> 
> STATIC
> EFI_STATUS
> CheckBufferAddr (
>   IN UINTN CommBufferAddr
>   )
> {
>   UINTNCommBufferSize;
>   EFI_STATUS   Status;
>   EFI_MMRAM_DESCRIPTOR CommBuffer;
> 
>   if (Com

Re: [edk2-devel] [PATCH edk2 v1 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-12-15 Thread Ming Huang



On 12/9/21 1:46 AM, Omkar Anand Kulkarni wrote:
> Hi Ming,
> 
> Thanks for this patch. This patch helps to resolve Standalone MM issue while 
> exercising RAS use case.
> Few comments mentioned inline.
> 
> - Omkar
> 
> 
>  On 10/15/21 2:39 PM, Ming Huang via groups.io wrote:
>> There are two scene communicate with StandaloneMm(MM):
>> 1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
>>   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
>> 2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
>>   specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;
>>
>> For now, the second scene will failed because check buffer address.
>> This patch add CheckBufferAddr() to support check address for secure buffer.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 70
>> 
>>  StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21
>> ++
>> StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>>  3 files changed, 79 insertions(+), 13 deletions(-)
>>
>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> index 5dfaf9d751..63fab1bd78 100644
>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
>> @@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER
>> **PerCpuGuidedEventContext = NULL;
>>
>>  // Descriptor with whereabouts of memory used for communication with
>> the normal world  EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
>> +EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
>>
>>  MP_INFORMATION_HOB_DATA *mMpInformationHobData;
>>
>> @@ -60,6 +61,58 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig =
>> {
>>
>>  STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
>>
>> +STATIC
>> +EFI_STATUS
>> +CheckBufferAddr (
>> +  IN UINTN CommBufferAddr
>> +  )
>> +{
>> +  UINTN  CommBufferSize;
>> +  EFI_STATUS Status;
>> +
>> +  Status =  EFI_SUCCESS;
>> +  if (CommBufferAddr < mNsCommBuffer.PhysicalStart) {
>> +Status = EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>> +  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>> +Status =  EFI_INVALID_PARAMETER;
> 
> Single space after "Status = "

Modify it in v2.

> 
> - Omkar
> 
> 
>> +  }
>> +
>> +  // Find out the size of the buffer passed  CommBufferSize =
>> + ((EFI_MM_COMMUNICATE_HEADER *) CommBufferAddr)->MessageLength
>> +
>> +sizeof (EFI_MM_COMMUNICATE_HEADER);
>> +
>> +  // perform bounds check.
>> +  if (CommBufferAddr + CommBufferSize >=
>> +  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
>> +Status =  EFI_ACCESS_DENIED;
> 
> Single space after "Status = "

Modify it in v2.

> 
> - Omkar
> 
>> +  }
>> +
>> +  if (!EFI_ERROR (Status)) {
> 
> 
> In case of error this function call will not return from here. It will 
> execute the code below comparing the MM Communicate buffer address with the 
> Secure buffer address, which may cause wrong return type being returned. Can 
> you check this, please?
> 
> - Omkar
> 
> 
>> +return EFI_SUCCESS;
>> +  }
>> +
>> +  Status =  EFI_SUCCESS;
>> +  if (CommBufferAddr < mSCommBuffer.PhysicalStart) {
>> +Status = EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>> +  (mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize)) {
>> +Status =  EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  // perform bounds check.
>> +  if (CommBufferAddr + CommBufferSize >=
>> +  mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize) {
>> +Status =  EFI_ACCESS_DENIED;
>> +  }
>> +
>> +  return Status;
>> +}
>> +
> 
> 
> CheckBufferAddr() function performs validity and overflow checks on the 
> Communication buffers. These checks are same for both the non-secure
> MM communicate buffer and secure buffer shared between EL3 and S-EL0. Can 
> this code be combined ( example below)? This will help mitigate the above 
> mentioned return type issue as well.

Your example is a good idea to solve this case. I may modify it like below in 
v2:

STATIC
EFI_STATUS
CheckBufferAddr (
  IN UINTN CommBufferAddr
  )
{
  UINTN  CommBufferSize;
  EFI

Re: [edk2-devel] [PATCH edk2 v1 0/3] Fix several issues in StanaloneMmPkg

2021-12-05 Thread Ming Huang
Hi Sami,

Any comments about this series?

Thanks,
Ming

On 11/5/21 6:51 PM, Sami Mujawar wrote:
> Hi Ming,
>
> Apologies for the delay. I will look at this patch series next week.
>
> Regards,
>
> Sami Mujawar
>
> On 01/11/2021, 14:19, "Ming Huang"  wrote:
>
> Hi,
>
> Any comments about this series?
>
> On 10/15/21 5:06 PM, Ming Huang wrote:
> > Fix issues in StandaloneMmPkg for supporting communicate from
> > TF-A with secure buffer.
> > 
> > Ming Huang (3):
> >   StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field
> >   StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR
> >   StandaloneMmPkg: Fix check buffer address failed issue from TF-A
> > 
> >  .../Drivers/StandaloneMmCpu/EventHandle.c | 76 +++
> >  .../Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 33 ++--
> >  .../Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
> >  .../Library/Arm/StandaloneMmCoreEntryPoint.h  |  2 +-
> >  .../Arm/CreateHobList.c   |  2 +-
> >  .../Arm/StandaloneMmCoreEntryPoint.c  |  2 +-
> >  6 files changed, 91 insertions(+), 25 deletions(-)
> > 
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#84363): https://edk2.groups.io/g/devel/message/84363
Mute This Topic: https://groups.io/mt/86334813/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH edk2 v1 0/3] Fix several issues in StanaloneMmPkg

2021-11-01 Thread Ming Huang
Hi,

Any comments about this series?

On 10/15/21 5:06 PM, Ming Huang wrote:
> Fix issues in StandaloneMmPkg for supporting communicate from
> TF-A with secure buffer.
> 
> Ming Huang (3):
>   StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field
>   StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR
>   StandaloneMmPkg: Fix check buffer address failed issue from TF-A
> 
>  .../Drivers/StandaloneMmCpu/EventHandle.c | 76 +++
>  .../Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 33 ++--
>  .../Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
>  .../Library/Arm/StandaloneMmCoreEntryPoint.h  |  2 +-
>  .../Arm/CreateHobList.c   |  2 +-
>  .../Arm/StandaloneMmCoreEntryPoint.c  |  2 +-
>  6 files changed, 91 insertions(+), 25 deletions(-)
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#83001): https://edk2.groups.io/g/devel/message/83001
Mute This Topic: https://groups.io/mt/86334813/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v1 1/3] StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field

2021-10-15 Thread Ming Huang
TF-A: TrustedFirmware-A
SPM: Secure Partition Manager(MM)

In TF-A, the name of this field is sp_shared_buf_size. This field is
the size of range for transmit data from TF-A to standaloneMM when
SPM enable.

SpPcpuSharedBufSize is pass from TF-A while StandaloneMM initialize.
So, SpPcpuSharedBufSize should be rename to SpSharedBufSize and this field
should no multiply by PayloadBootInfo->NumCpus;

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h   
 | 2 +-
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
 | 2 +-
 
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
 | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h 
b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
index c44f7066c6..f1683ecb61 100644
--- a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
+++ b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
@@ -41,7 +41,7 @@ typedef struct {
   UINT64SpPcpuStackSize;
   UINT64SpHeapSize;
   UINT64SpNsCommBufSize;
-  UINT64SpPcpuSharedBufSize;
+  UINT64SpSharedBufSize;
   UINT32NumSpMemRegions;
   UINT32NumCpus;
   EFI_SECURE_PARTITION_CPU_INFO *CpuInfo;
diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
index 85f8194687..93773c9fe8 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
@@ -173,7 +173,7 @@ CreateHobListFromBootInfo (
   // Base and size of buffer shared with privileged Secure world software
   MmramRanges[1].PhysicalStart = PayloadBootInfo->SpSharedBufBase;
   MmramRanges[1].CpuStart  = PayloadBootInfo->SpSharedBufBase;
-  MmramRanges[1].PhysicalSize  = PayloadBootInfo->SpPcpuSharedBufSize * 
PayloadBootInfo->NumCpus;
+  MmramRanges[1].PhysicalSize  = PayloadBootInfo->SpSharedBufSize;
   MmramRanges[1].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
 
   // Base and size of buffer used for synchronous communication with Normal
diff --git 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
index 49cf51a789..5db7019dda 100644
--- 
a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
+++ 
b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
@@ -87,7 +87,7 @@ GetAndPrintBootinformation (
   DEBUG ((DEBUG_INFO, "SpPcpuStackSize - 0x%x\n", 
PayloadBootInfo->SpPcpuStackSize));
   DEBUG ((DEBUG_INFO, "SpHeapSize  - 0x%x\n", 
PayloadBootInfo->SpHeapSize));
   DEBUG ((DEBUG_INFO, "SpNsCommBufSize - 0x%x\n", 
PayloadBootInfo->SpNsCommBufSize));
-  DEBUG ((DEBUG_INFO, "SpPcpuSharedBufSize - 0x%x\n", 
PayloadBootInfo->SpPcpuSharedBufSize));
+  DEBUG ((DEBUG_INFO, "SpSharedBufSize - 0x%x\n", 
PayloadBootInfo->SpSharedBufSize));
 
   DEBUG ((DEBUG_INFO, "NumCpus - 0x%x\n", PayloadBootInfo->NumCpus));
   DEBUG ((DEBUG_INFO, "CpuInfo - 0x%p\n", PayloadBootInfo->CpuInfo));
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#82128): https://edk2.groups.io/g/devel/message/82128
Mute This Topic: https://groups.io/mt/86334819/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v1 3/3] StandaloneMmPkg: Fix check buffer address failed issue from TF-A

2021-10-15 Thread Ming Huang
There are two scene communicate with StandaloneMm(MM):
1 edk2 -> TF-A -> MM, communicate MM use non-secure buffer which
  specify by EFI_SECURE_PARTITION_BOOT_INFO.SpNsCommBufBase;
2 RAS scene: fiq -> TF-A -> MM, use secure buffer which
  specify by EFI_SECURE_PARTITION_BOOT_INFO.SpShareBufBase;

For now, the second scene will failed because check buffer address.
This patch add CheckBufferAddr() to support check address for secure
buffer.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c | 70 

 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 21 ++
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
 3 files changed, 79 insertions(+), 13 deletions(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
index 5dfaf9d751..63fab1bd78 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
@@ -50,6 +50,7 @@ EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL;
 
 // Descriptor with whereabouts of memory used for communication with the 
normal world
 EFI_MMRAM_DESCRIPTOR  mNsCommBuffer;
+EFI_MMRAM_DESCRIPTOR  mSCommBuffer;
 
 MP_INFORMATION_HOB_DATA *mMpInformationHobData;
 
@@ -60,6 +61,58 @@ EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = {
 
 STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL;
 
+STATIC
+EFI_STATUS
+CheckBufferAddr (
+  IN UINTN CommBufferAddr
+  )
+{
+  UINTN  CommBufferSize;
+  EFI_STATUS Status;
+
+  Status =  EFI_SUCCESS;
+  if (CommBufferAddr < mNsCommBuffer.PhysicalStart) {
+Status = EFI_ACCESS_DENIED;
+  }
+
+  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
+  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
+Status =  EFI_INVALID_PARAMETER;
+  }
+
+  // Find out the size of the buffer passed
+  CommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
CommBufferAddr)->MessageLength +
+sizeof (EFI_MM_COMMUNICATE_HEADER);
+
+  // perform bounds check.
+  if (CommBufferAddr + CommBufferSize >=
+  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
+Status =  EFI_ACCESS_DENIED;
+  }
+
+  if (!EFI_ERROR (Status)) {
+return EFI_SUCCESS;
+  }
+
+  Status =  EFI_SUCCESS;
+  if (CommBufferAddr < mSCommBuffer.PhysicalStart) {
+Status = EFI_ACCESS_DENIED;
+  }
+
+  if ((CommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
+  (mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize)) {
+Status =  EFI_INVALID_PARAMETER;
+  }
+
+  // perform bounds check.
+  if (CommBufferAddr + CommBufferSize >=
+  mSCommBuffer.PhysicalStart + mSCommBuffer.PhysicalSize) {
+Status =  EFI_ACCESS_DENIED;
+  }
+
+  return Status;
+}
+
 /**
   The PI Standalone MM entry point for the TF-A CPU driver.
 
@@ -104,25 +157,16 @@ PiMmStandaloneArmTfCpuDriverEntry (
 return EFI_INVALID_PARAMETER;
   }
 
-  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
-return EFI_ACCESS_DENIED;
-  }
-
-  if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
-  (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
-return EFI_INVALID_PARAMETER;
+  Status = CheckBufferAddr (NsCommBufferAddr);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Check Buffer failed: %r\n", Status));
+return Status;
   }
 
   // Find out the size of the buffer passed
   NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) 
NsCommBufferAddr)->MessageLength +
 sizeof (EFI_MM_COMMUNICATE_HEADER);
 
-  // perform bounds check.
-  if (NsCommBufferAddr + NsCommBufferSize >=
-  mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) {
-return EFI_ACCESS_DENIED;
-  }
-
   GuidedEventContext = NULL;
   // Now that the secure world can see the normal world buffer, allocate
   // memory to copy the communication buffer to the secure world.
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
index fd9c59b4da..96dad20dd1 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
@@ -107,6 +107,7 @@ StandaloneMmCpuInitialize (
   UINTNIndex;
   UINTNArraySize;
   VOID*HobStart;
+  EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHob;
 
   ASSERT (SystemTable != NULL);
   mMmst = SystemTable;
@@ -186,6 +187,26 @@ StandaloneMmCpuInitialize (
   CopyMem (, NsCommBufMmramRange, sizeof(EFI_MMRAM_DESCRIPTOR));
   DEBUG ((DEBUG_INFO, "mNsCommBuffer: 0x%016lx - 0x%lx\n", 
mNsCommBuffer.CpuStart, mNsCommBuffer.PhysicalSize));
 
+  Status = GetGuidedHobData (
+ HobStart,
+ ,
+ (VOID **) 
+ );
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "MmramRan

[edk2-devel] [PATCH edk2 v1 0/3] Fix several issues in StanaloneMmPkg

2021-10-15 Thread Ming Huang
Fix issues in StandaloneMmPkg for supporting communicate from
TF-A with secure buffer.

Ming Huang (3):
  StandaloneMmPkg: Fix issue about SpPcpuSharedBufSize field
  StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR
  StandaloneMmPkg: Fix check buffer address failed issue from TF-A

 .../Drivers/StandaloneMmCpu/EventHandle.c | 76 +++
 .../Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 33 ++--
 .../Drivers/StandaloneMmCpu/StandaloneMmCpu.h |  1 +
 .../Library/Arm/StandaloneMmCoreEntryPoint.h  |  2 +-
 .../Arm/CreateHobList.c   |  2 +-
 .../Arm/StandaloneMmCoreEntryPoint.c  |  2 +-
 6 files changed, 91 insertions(+), 25 deletions(-)

-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#82125): https://edk2.groups.io/g/devel/message/82125
Mute This Topic: https://groups.io/mt/86334813/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v1 2/3] StandaloneMmPkg: Replace DEBUG_INFO with DEBUG_ERROR

2021-10-15 Thread Ming Huang
DEBUG_ERROR should be used in error branch.

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c |  6 +++---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c | 12 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
index 165d696f99..5dfaf9d751 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c
@@ -95,7 +95,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
   //
   if ((ARM_SMC_ID_MM_COMMUNICATE != EventId) &&
   (ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ != EventId)) {
-DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId));
+DEBUG ((DEBUG_ERROR, "UnRecognized Event - 0x%x\n", EventId));
 return EFI_INVALID_PARAMETER;
   }
 
@@ -133,7 +133,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
 );
 
   if (Status != EFI_SUCCESS) {
-DEBUG ((DEBUG_INFO, "Mem alloc failed - 0x%x\n", EventId));
+DEBUG ((DEBUG_ERROR, "Mem alloc failed - 0x%x\n", EventId));
 return EFI_OUT_OF_RESOURCES;
   }
 
@@ -156,7 +156,7 @@ PiMmStandaloneArmTfCpuDriverEntry (
   mMmst->CpuSaveState = NULL;
 
   if (mMmEntryPoint == NULL) {
-DEBUG ((DEBUG_INFO, "Mm Entry point Not Found\n"));
+DEBUG ((DEBUG_ERROR, "Mm Entry point Not Found\n"));
 return EFI_UNSUPPORTED;
   }
 
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
index 10097f792f..fd9c59b4da 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c
@@ -143,7 +143,7 @@ StandaloneMmCpuInitialize (
 
   // Bail out if the Hoblist could not be found
   if (Index >= mMmst->NumberOfTableEntries) {
-DEBUG ((DEBUG_INFO, "Hoblist not found - 0x%x\n", Index));
+DEBUG ((DEBUG_ERROR, "Hoblist not found - 0x%x\n", Index));
 return EFI_OUT_OF_RESOURCES;
   }
 
@@ -158,7 +158,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "ArmTfCpuDriverEpDesc HOB data extraction failed - 
0x%x\n", Status));
+DEBUG ((DEBUG_ERROR, "ArmTfCpuDriverEpDesc HOB data extraction failed - 
0x%x\n", Status));
 return Status;
   }
 
@@ -176,7 +176,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "NsCommBufMmramRange HOB data extraction failed - 
0x%x\n", Status));
+DEBUG ((DEBUG_ERROR, "NsCommBufMmramRange HOB data extraction failed - 
0x%x\n", Status));
 return Status;
   }
 
@@ -195,7 +195,7 @@ StandaloneMmCpuInitialize (
  (VOID **) 
  );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "MpInformationHob extraction failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "MpInformationHob extraction failed - 0x%x\n", 
Status));
 return Status;
   }
 
@@ -213,7 +213,7 @@ StandaloneMmCpuInitialize (
 (VOID **) 
 );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "mMpInformationHobData mem alloc failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "mMpInformationHobData mem alloc failed - 0x%x\n", 
Status));
 return Status;
   }
 
@@ -243,7 +243,7 @@ StandaloneMmCpuInitialize (
 (VOID **) 
 );
   if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_INFO, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", 
Status));
+DEBUG ((DEBUG_ERROR, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", 
Status));
 return Status;
   }
   return Status;
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#82126): https://edk2.groups.io/g/devel/message/82126
Mute This Topic: https://groups.io/mt/86334814/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v1] ArmPkg/Smbios: Fix max cache size 2 wrong issue

2021-10-14 Thread Ming Huang
As SMBIOS spec, bit-31 of maximum cache size 2 should be 1
for 64K granularity.

Signed-off-by: Ming Huang 
---
 ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c 
b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c
index fb484086a4..4b409ff745 100644
--- a/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c
+++ b/ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c
@@ -219,7 +219,7 @@ ConfigureCacheArchitectureInformation (
 CacheSize32 = CacheSize16;
   } else if ((CacheSize64 / 64) < MAX_INT16) {
 CacheSize16 = (1 << 15) | (CacheSize64 / 64);
-CacheSize32 = CacheSize16;
+CacheSize32 = (1 << 31) | (CacheSize64 / 64);
   } else {
 if ((CacheSize64 / 1024) <= 2047) {
   CacheSize32 = CacheSize64;
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81976): https://edk2.groups.io/g/devel/message/81976
Mute This Topic: https://groups.io/mt/86307250/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [Patch] StandaloneMmPkg: Fixed communicating from TF-A failed issue

2021-06-17 Thread Ming Huang



On 6/16/21 10:10 PM, Ard Biesheuvel wrote:
> On Wed, 16 Jun 2021 at 07:30, Omkar Kulkarni  wrote:
>>
>>
>> On 6/10/21 6:44 AM, Ming Huang via groups.io wrote:
>>> On 6/9/21 3:10 PM, Ard Biesheuvel wrote:
>>>> On Tue, 8 Jun 2021 at 16:21, Ming Huang 
>>> wrote:
>>>>>
>>>>> TF-A: TrustedFirmware-a
>>>>> SPM: Secure Partition Manager(MM)
>>>>>
>>>>> For AArch64, when SPM enable in TF-A, TF-A may communicate to MM
>>> with
>>>>> buffer address (PLAT_SPM_BUF_BASE). The address is different from
>>>>> PcdMmBufferBase which use in edk2.
>>>>
>>>> Then why do we have PcdMmBufferBase?
>>>
>>> ArmPkg use this Pcd for the base address of non-secure communication
>>> buffer.
>>>
>>>>
>>>> Is it possible to set PcdMmBufferBase to the correct value?
>>>
>>> The secure communication may interrupt the non-secure communication. if
>>> we use the same address (PcdMmBufferBase and PLAT_SPM_BUF_BASE), the
>>> date in communication buffer may be corrupted.
>>>
>>> Best Regards,
>>> Ming
>>
>> In case where an interrupt handler executing from EL3 makes a call into 
>> StandaloneMM, the handler in EL3 makes an spm call into StandaloneMM using 
>> PLAT_SPM_BUF_BASE buffer base address. This PLAT_SPM_BUF_BASE is a shared 
>> buffer between EL3 and S-EL0. This is where the following check fails and 
>> leads to spm call failure. So this change would help resolve this issue.
>>
> 
> But is it the right fix? Why would EDK2 even be aware of how EL3 and
> S-EL0 communicate with each other, and where the buffer is located?

The root cause for this problem is that the StandaloneMmPkg and TF-A
are not full cooperative.
PLAT_SPM_BUF_BASE is not dynamic buffer just like PcdMmBufferBase.

Please refer PcdMmBufferBase comments in 
edk2-platforms/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc: 
  #
  # Set the base address and size of the buffer used
  # for communication between the Normal world edk2
  # with StandaloneMm image at S-EL0 through MM_COMMUNICATE.
  # This buffer gets allocated in ATF and since we do not have
  # a mechanism currently to communicate the base address and
  # size of this buffer from ATF, hard-code it here
  #
  ## MM Communicate
  gArmTokenSpaceGuid.PcdMmBufferBase|0xFF60
  gArmTokenSpaceGuid.PcdMmBufferSize|0x1


Best Regards,
Ming

> 
> 
>>>
>>>>
>>>>> Checking address will let TF-A communicate failed to MM. So remove
>>>>> below checking code:
>>>>> if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
>>>>>   return EFI_ACCESS_DENIED;
>>>>> }
>>>>>
>>>>> Signed-off-by: Ming Huang 
>>>>> ---
>>>>>  StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c |
>>> 4
>>>>> 
>>>>>  1 file changed, 4 deletions(-)
>>>>>
>>>>> diff --git
>>>>> a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>>>>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>>>>> index 63fbe26642..fe98d3181d 100644
>>>>> ---
>>> a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>>>>> +++
>>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>>>>> @@ -103,10 +103,6 @@ PiMmStandaloneArmTfCpuDriverEntry (
>>>>>  return EFI_INVALID_PARAMETER;
>>>>>}
>>>>>
>>>>> -  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
>>>>> -return EFI_ACCESS_DENIED;
>>>>> -  }
>>>>> -
>>>>>if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>>>>>(mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>>>>>  return EFI_INVALID_PARAMETER;
>>>>> --
>>>>> 2.17.1
>>>>>
>>>
>>>
>>> 
>>>
>>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#76734): https://edk2.groups.io/g/devel/message/76734
Mute This Topic: https://groups.io/mt/83396678/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [Patch] StandaloneMmPkg: Fixed communicating from TF-A failed issue

2021-06-09 Thread Ming Huang



On 6/9/21 3:10 PM, Ard Biesheuvel wrote:
> On Tue, 8 Jun 2021 at 16:21, Ming Huang  wrote:
>>
>> TF-A: TrustedFirmware-a
>> SPM: Secure Partition Manager(MM)
>>
>> For AArch64, when SPM enable in TF-A, TF-A may communicate to MM
>> with buffer address (PLAT_SPM_BUF_BASE). The address is different
>> from PcdMmBufferBase which use in edk2.
> 
> Then why do we have PcdMmBufferBase?

ArmPkg use this Pcd for the base address of non-secure communication buffer.

> 
> Is it possible to set PcdMmBufferBase to the correct value?

The secure communication may interrupt the non-secure communication. if we
use the same address (PcdMmBufferBase and PLAT_SPM_BUF_BASE), the date in
communication buffer may be corrupted.

Best Regards,
Ming

> 
>> Checking address will let TF-A communicate failed to MM. So remove
>> below checking code:
>> if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
>>   return EFI_ACCESS_DENIED;
>> }
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c | 4 
>>  1 file changed, 4 deletions(-)
>>
>> diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c 
>> b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>> index 63fbe26642..fe98d3181d 100644
>> --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>> +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
>> @@ -103,10 +103,6 @@ PiMmStandaloneArmTfCpuDriverEntry (
>>  return EFI_INVALID_PARAMETER;
>>}
>>
>> -  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
>> -return EFI_ACCESS_DENIED;
>> -  }
>> -
>>if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
>>(mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
>>  return EFI_INVALID_PARAMETER;
>> --
>> 2.17.1
>>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#76291): https://edk2.groups.io/g/devel/message/76291
Mute This Topic: https://groups.io/mt/83396678/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [Patch] StandaloneMmPkg: Fixed communicating from TF-A failed issue

2021-06-08 Thread Ming Huang
TF-A: TrustedFirmware-a
SPM: Secure Partition Manager(MM)

For AArch64, when SPM enable in TF-A, TF-A may communicate to MM
with buffer address (PLAT_SPM_BUF_BASE). The address is different
from PcdMmBufferBase which use in edk2.
Checking address will let TF-A communicate failed to MM. So remove
below checking code:
if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
  return EFI_ACCESS_DENIED;
}

Signed-off-by: Ming Huang 
---
 StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c 
b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
index 63fbe26642..fe98d3181d 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
@@ -103,10 +103,6 @@ PiMmStandaloneArmTfCpuDriverEntry (
 return EFI_INVALID_PARAMETER;
   }
 
-  if (NsCommBufferAddr < mNsCommBuffer.PhysicalStart) {
-return EFI_ACCESS_DENIED;
-  }
-
   if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >=
   (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) {
 return EFI_INVALID_PARAMETER;
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#76222): https://edk2.groups.io/g/devel/message/76222
Mute This Topic: https://groups.io/mt/83396678/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v2 2/2] ArmPkg/ArmGicLib: Fix GICR_IPRIORITYR address wrong issue

2021-02-24 Thread Ming Huang
The register address of GICR_IPRIORITYR is in SGI_base frame. Add
IPRIORITY_ADDRESS macro for getting GICR_IPRIORITYR address. Otherwise
GIC RAS error(Uncorrected software error) may report in ArmGicDxe.

Signed-off-by: Ming Huang 
Reviewed-by: Leif Lindholm 
---
 ArmPkg/Drivers/ArmGic/ArmGicLib.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c 
b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
index 5d04ed3dac..6b01c88206 100644
--- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
+++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
@@ -30,6 +30,9 @@
 #define ICENABLER_ADDRESS(base,offset) ((base) + \
   ARM_GICR_CTLR_FRAME_SIZE + ARM_GICR_ICENABLER + 4 * (offset))
 
+#define IPRIORITY_ADDRESS(base,offset) ((base) + \
+  ARM_GICR_CTLR_FRAME_SIZE + ARM_GIC_ICDIPR + 4 * (offset))
+
 /**
  *
  * Return whether the Source interrupt index refers to a shared interrupt (SPI)
@@ -236,7 +239,7 @@ ArmGicSetInterruptPriority (
 }
 
 MmioAndThenOr32 (
-  GicCpuRedistributorBase + ARM_GIC_ICDIPR + (4 * RegOffset),
+  IPRIORITY_ADDRESS (GicCpuRedistributorBase, RegOffset),
   ~(0xff << RegShift),
   Priority << RegShift
   );
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72176): https://edk2.groups.io/g/devel/message/72176
Mute This Topic: https://groups.io/mt/80895010/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v2 1/2] ArmPkg/ArmGicLib: Fix two macros issue for offset parameter

2021-02-24 Thread Ming Huang
Modify two macros to put "offset" in parentheses and remove
parentheses from "4 * offset".

Signed-off-by: Ming Huang 
---
 ArmPkg/Drivers/ArmGic/ArmGicLib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c 
b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
index 8ef32b33a1..5d04ed3dac 100644
--- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
+++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
@@ -25,10 +25,10 @@
+ ARM_GICR_SGI_RESERVED_FRAME_SIZE)
 
 #define ISENABLER_ADDRESS(base,offset) ((base) + \
-  ARM_GICR_CTLR_FRAME_SIZE +  ARM_GICR_ISENABLER + (4 * offset))
+  ARM_GICR_CTLR_FRAME_SIZE + ARM_GICR_ISENABLER + 4 * (offset))
 
 #define ICENABLER_ADDRESS(base,offset) ((base) + \
-  ARM_GICR_CTLR_FRAME_SIZE +  ARM_GICR_ICENABLER + (4 * offset))
+  ARM_GICR_CTLR_FRAME_SIZE + ARM_GICR_ICENABLER + 4 * (offset))
 
 /**
  *
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72177): https://edk2.groups.io/g/devel/message/72177
Mute This Topic: https://groups.io/mt/80895011/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v2 0/2] Fix two issue in ArmGicLib

2021-02-24 Thread Ming Huang
The first patch is prepare for the second one.

Ming Huang (2):
  ArmPkg/ArmGicLib: Fix two macros issue for offset parameter
  ArmPkg/ArmGicLib: Fix GICR_IPRIORITYR address wrong issue

 ArmPkg/Drivers/ArmGic/ArmGicLib.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72175): https://edk2.groups.io/g/devel/message/72175
Mute This Topic: https://groups.io/mt/80895009/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH edk2 v2 1/1] ArmPkg/ArmGic: Fix GICR_IPRIORITYR address wrong issue

2021-02-24 Thread Ming Huang



On 2/24/21 7:49 PM, Leif Lindholm wrote:
> Hi Ming,
> 
> Thanks for this.
> However, just after I sent my reply, Heyi suggested another
> improvement to this patch. Can you please implement that, and submit a
> v2?

OK, I will implement that in v2.
As one issue in my email filter, I miss Heyi's email, sorry for that.

Thanks,
Ming

> 
> Best Regards,
> 
> Leif
> 
> On Wed, Feb 24, 2021 at 16:26:33 +0800, Ming Huang wrote:
>>
>>
>> On 2/23/21 8:58 PM, Leif Lindholm wrote:
>>> On Tue, Feb 23, 2021 at 13:42:49 +0100, Ard Biesheuvel wrote:
>>>> On Tue, 23 Feb 2021 at 12:07, Ming Huang  
>>>> wrote:
>>>>>
>>>>> The register address of GICR_IPRIORITYR is in SGI_base frame. Add
>>>>> IPRIORITY_ADDRESS macro for getting GICR_IPRIORITYR address. Otherwise
>>>>> GIC RAS error(Uncorrected software error) may report in ArmGicDxe.
>>>>
>>>> NOTE: missing sign-off
>>>>
>>>> Patch seems fine to me
>>>>
>>>> Tested-by: Ard Biesheuvel  # QEMU/kvm guest on ThunderX2
>>>
>>> Also looks good in QEMU.
>>> Reviewed-by: Leif Lindholm 
>>>
>>> Ming, can you confirm that the contribution conforms to the developer
>>> certificate of origin by replyint with your Signed-off-by: ?
>>
>> Sorry, I miss the Signed-off-by.
>> please help to add my Signed-off-by:
>> Signed-off-by: Ming Huang 
>>
>> Thanks,
>> Ming
>>
>>>
>>>>
>>>>
>>>>
>>>>> ---
>>>>>  ArmPkg/Drivers/ArmGic/ArmGicLib.c | 5 -
>>>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c 
>>>>> b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>>>>> index 8ef32b33a1..b4d3965acb 100644
>>>>> --- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>>>>> +++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>>>>> @@ -30,6 +30,9 @@
>>>>>  #define ICENABLER_ADDRESS(base,offset) ((base) + \
>>>>>ARM_GICR_CTLR_FRAME_SIZE +  ARM_GICR_ICENABLER + (4 * offset))
>>>>>
>>>>> +#define IPRIORITY_ADDRESS(base,offset) ((base) + \
>>>>> +  ARM_GICR_CTLR_FRAME_SIZE +  ARM_GIC_ICDIPR + (4 * offset))
>>>>> +
>>>>>  /**
>>>>>   *
>>>>>   * Return whether the Source interrupt index refers to a shared 
>>>>> interrupt (SPI)
>>>>> @@ -236,7 +239,7 @@ ArmGicSetInterruptPriority (
>>>>>  }
>>>>>
>>>>>  MmioAndThenOr32 (
>>>>> -  GicCpuRedistributorBase + ARM_GIC_ICDIPR + (4 * RegOffset),
>>>>> +  IPRIORITY_ADDRESS (GicCpuRedistributorBase, RegOffset),
>>>>>~(0xff << RegShift),
>>>>>Priority << RegShift
>>>>>);
>>>>> --
>>>>> 2.17.1
>>>>>
>>
>>
>> 
>>
>>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72173): https://edk2.groups.io/g/devel/message/72173
Mute This Topic: https://groups.io/mt/80848339/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH edk2 v2 1/1] ArmPkg/ArmGic: Fix GICR_IPRIORITYR address wrong issue

2021-02-24 Thread Ming Huang



On 2/23/21 8:58 PM, Leif Lindholm wrote:
> On Tue, Feb 23, 2021 at 13:42:49 +0100, Ard Biesheuvel wrote:
>> On Tue, 23 Feb 2021 at 12:07, Ming Huang  wrote:
>>>
>>> The register address of GICR_IPRIORITYR is in SGI_base frame. Add
>>> IPRIORITY_ADDRESS macro for getting GICR_IPRIORITYR address. Otherwise
>>> GIC RAS error(Uncorrected software error) may report in ArmGicDxe.
>>
>> NOTE: missing sign-off
>>
>> Patch seems fine to me
>>
>> Tested-by: Ard Biesheuvel  # QEMU/kvm guest on ThunderX2
> 
> Also looks good in QEMU.
> Reviewed-by: Leif Lindholm 
> 
> Ming, can you confirm that the contribution conforms to the developer
> certificate of origin by replyint with your Signed-off-by: ?

Sorry, I miss the Signed-off-by.
please help to add my Signed-off-by:
Signed-off-by: Ming Huang 

Thanks,
Ming

> 
>>
>>
>>
>>> ---
>>>  ArmPkg/Drivers/ArmGic/ArmGicLib.c | 5 -
>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c 
>>> b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>>> index 8ef32b33a1..b4d3965acb 100644
>>> --- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>>> +++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>>> @@ -30,6 +30,9 @@
>>>  #define ICENABLER_ADDRESS(base,offset) ((base) + \
>>>ARM_GICR_CTLR_FRAME_SIZE +  ARM_GICR_ICENABLER + (4 * offset))
>>>
>>> +#define IPRIORITY_ADDRESS(base,offset) ((base) + \
>>> +  ARM_GICR_CTLR_FRAME_SIZE +  ARM_GIC_ICDIPR + (4 * offset))
>>> +
>>>  /**
>>>   *
>>>   * Return whether the Source interrupt index refers to a shared interrupt 
>>> (SPI)
>>> @@ -236,7 +239,7 @@ ArmGicSetInterruptPriority (
>>>  }
>>>
>>>  MmioAndThenOr32 (
>>> -  GicCpuRedistributorBase + ARM_GIC_ICDIPR + (4 * RegOffset),
>>> +  IPRIORITY_ADDRESS (GicCpuRedistributorBase, RegOffset),
>>>~(0xff << RegShift),
>>>Priority << RegShift
>>>);
>>> --
>>> 2.17.1
>>>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72147): https://edk2.groups.io/g/devel/message/72147
Mute This Topic: https://groups.io/mt/80848339/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v2 1/1] ArmPkg/ArmGic: Fix GICR_IPRIORITYR address wrong issue

2021-02-23 Thread Ming Huang
The register address of GICR_IPRIORITYR is in SGI_base frame. Add
IPRIORITY_ADDRESS macro for getting GICR_IPRIORITYR address. Otherwise
GIC RAS error(Uncorrected software error) may report in ArmGicDxe.
---
 ArmPkg/Drivers/ArmGic/ArmGicLib.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c 
b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
index 8ef32b33a1..b4d3965acb 100644
--- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
+++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
@@ -30,6 +30,9 @@
 #define ICENABLER_ADDRESS(base,offset) ((base) + \
   ARM_GICR_CTLR_FRAME_SIZE +  ARM_GICR_ICENABLER + (4 * offset))
 
+#define IPRIORITY_ADDRESS(base,offset) ((base) + \
+  ARM_GICR_CTLR_FRAME_SIZE +  ARM_GIC_ICDIPR + (4 * offset))
+
 /**
  *
  * Return whether the Source interrupt index refers to a shared interrupt (SPI)
@@ -236,7 +239,7 @@ ArmGicSetInterruptPriority (
 }
 
 MmioAndThenOr32 (
-  GicCpuRedistributorBase + ARM_GIC_ICDIPR + (4 * RegOffset),
+  IPRIORITY_ADDRESS (GicCpuRedistributorBase, RegOffset),
   ~(0xff << RegShift),
   Priority << RegShift
   );
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72045): https://edk2.groups.io/g/devel/message/72045
Mute This Topic: https://groups.io/mt/80848339/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH edk2 v1 1/1] ArmPkg/ArmGicLib: Fix GICR_IPRIORITYR address wrong issue

2021-02-22 Thread Ming Huang



On 2/22/21 8:52 PM, Leif Lindholm wrote:
> Hi Ming,
> 
> On Sat, Feb 20, 2021 at 15:08:39 +0800, Ming Huang wrote:
>> The address of GICR_IPRIORITYR is in SGI_base frame. ARM_GICR_CTLR_FRAME_SIZE
>> should add to GicCpuRedistributorBase for GICR_IPRIORITYR. Otherwise RAS
>> error(Uncorrected software error) will reported in ArmGicDxe.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  ArmPkg/Drivers/ArmGic/ArmGicLib.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c 
>> b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>> index 8ef32b33a1..7a54972455 100644
>> --- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>> +++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
>> @@ -235,6 +235,9 @@ ArmGicSetInterruptPriority (
>>return;
>>  }
>>  
>> +// The address of GICR_IPRIORITYR is in SGI_base frame.
>> +// ARM_GICR_CTLR_FRAME_SIZE should add to GicCpuRedistributorBase for 
>> GICR_IPRIORITYR.
>> +GicCpuRedistributorBase += ARM_GICR_CTLR_FRAME_SIZE;
> 
> I agree with the error report, but not the fix.
> Changing the value of a variable called GicCpuRedistributorBase to
> something that is not the base address of the redistributor makes the
> code confusing.
> 
> If you look at the subsequent function, ArmGicEnableInterrupt, it
> resolvess the same situation using the ISENABLER_ADDRESS macro
> defined at the top of the file:
> 
> #define ISENABLER_ADDRESS(base,offset) ((base) + \
>   ARM_GICR_CTLR_FRAME_SIZE +  ARM_GICR_ISENABLER + (4 * offset))
> 
> I would suggest creating an IPRIORITY_ADDRESS macro by the same
> pattern and using that.
> 
> Would that solution be OK with you?

Good idea. Thanks for your solution.
Modify it in v2.

Thanks,
Ming

> 
> Best Regards,
> 
> Leif
> 
>>  MmioAndThenOr32 (
>>GicCpuRedistributorBase + ARM_GIC_ICDIPR + (4 * RegOffset),
>>~(0xff << RegShift),
>> -- 
>> 2.17.1
>>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72017): https://edk2.groups.io/g/devel/message/72017
Mute This Topic: https://groups.io/mt/80789081/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2 v1 1/1] ArmPkg/ArmGicLib: Fix GICR_IPRIORITYR address wrong issue

2021-02-20 Thread Ming Huang
The address of GICR_IPRIORITYR is in SGI_base frame. ARM_GICR_CTLR_FRAME_SIZE
should add to GicCpuRedistributorBase for GICR_IPRIORITYR. Otherwise RAS
error(Uncorrected software error) will reported in ArmGicDxe.

Signed-off-by: Ming Huang 
---
 ArmPkg/Drivers/ArmGic/ArmGicLib.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ArmPkg/Drivers/ArmGic/ArmGicLib.c 
b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
index 8ef32b33a1..7a54972455 100644
--- a/ArmPkg/Drivers/ArmGic/ArmGicLib.c
+++ b/ArmPkg/Drivers/ArmGic/ArmGicLib.c
@@ -235,6 +235,9 @@ ArmGicSetInterruptPriority (
   return;
 }
 
+// The address of GICR_IPRIORITYR is in SGI_base frame.
+// ARM_GICR_CTLR_FRAME_SIZE should add to GicCpuRedistributorBase for 
GICR_IPRIORITYR.
+GicCpuRedistributorBase += ARM_GICR_CTLR_FRAME_SIZE;
 MmioAndThenOr32 (
   GicCpuRedistributorBase + ARM_GIC_ICDIPR + (4 * RegOffset),
   ~(0xff << RegShift),
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#71885): https://edk2.groups.io/g/devel/message/71885
Mute This Topic: https://groups.io/mt/80789081/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH] MdePkg: Remove code wrapped by DISABLE_NEW_DEPRECATED_INTERFACES

2020-08-21 Thread Ming Huang via groups.io
Hi, Leif

For Hisilicon platform, Wenyi(xiewen...@huawei.com) will send out patches later.

Thanks
Ming

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

View/Reply Online (#64527): https://edk2.groups.io/g/devel/message/64527
Mute This Topic: https://groups.io/mt/74688627/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



答复: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-07-22 Thread Ming Huang via groups.io
Hi Guomin,

Ok, it will take some time to do this.

Thanks
Ming

-邮件原件-
发件人: Jiang, Guomin [mailto:guomin.ji...@intel.com] 
发送时间: 2020年7月22日 14:49
收件人: Huangming (Mark) ; devel@edk2.groups.io; Wang, 
Jian J ; Wu, Hao A ; Gao, Liming 

抄送: Lidongzhan ; Songdongkuang 
; wanghuiqiang ; qiuliangen 
; Shenlimei ; xiewenyi (A) 
; John Garry 
主题: RE: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move 
FindVariable after AutoUpdateLangVariable

Hi Ming,

Can you try the newest edk2?

Thanks
Guomin
> -Original Message-
> From: Huangming (Mark) 
> Sent: Wednesday, July 22, 2020 2:44 PM
> To: Jiang, Guomin ; devel@edk2.groups.io; 
> Wang, Jian J ; Wu, Hao A ; 
> Gao, Liming 
> Cc: Lidongzhan ; Songdongkuang 
> ; wanghuiqiang ; 
> qiuliangen ; Shenlimei ; 
> xiewenyi (A) ; John Garry 
> 
> Subject: 答复: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable:
> Move FindVariable after AutoUpdateLangVariable
> 
> Hi GuoMin,
> 
> I don't think the new change can fix this issue(id=2667). We use older 
> edk2 version which don't have SynchronizeRuntimeVariableCache().
> 
> Thanks
> Ming
> 
> -邮件原件-
> 发件人: Jiang, Guomin [mailto:guomin.ji...@intel.com]
> 发送时间: 2020年7月22日 8:47
> 收件人: Huangming (Mark) ; devel@edk2.groups.io; 
> Wang, Jian J ; Wu, Hao A ; 
> Gao, Liming 
> 抄送: Lidongzhan ; Songdongkuang 
> ; wanghuiqiang ; 
> qiuliangen ; Shenlimei ; 
> xiewenyi (A) ; John Garry 
> 
> 主题: RE: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move 
> FindVariable after AutoUpdateLangVariable
> 
> Hi Ming,
> 
> The new posted change
> https://edk2.groups.io/g/devel/topic/75412007#62327 may be helpful for 
> this issue.
> 
> Can you add the change in your code and verify it?
> 
> Thanks
> Guomin
> > -Original Message-
> > From: Ming Huang 
> > Sent: Friday, July 3, 2020 8:49 PM
> > To: Jiang, Guomin ; devel@edk2.groups.io; 
> > Wang, Jian J ; Wu, Hao A 
> > ; Gao, Liming 
> > Cc: lidongz...@huawei.com; songdongku...@huawei.com; 
> > wanghuiqi...@huawei.com; qiulian...@huawei.com;
> shenli...@huawei.com;
> > xiewen...@huawei.com; john.ga...@huawei.com
> > Subject: Re: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable:
> > Move FindVariable after AutoUpdateLangVariable
> >
> >
> >
> > 在 2020/7/1 8:22, Jiang, Guomin 写道:
> > > So I think the key point is why AutoUpdateLangVariable() return 
> > > success
> > rather than fail, if is it reasonable for this case or we need other 
> > error handing?
> >
> > I don't think AutoUpdateLangVariable() should return fail while 
> > occur reclaim internal in AutoUpdateLangVariable () function. The 
> > problem is the
> > Variable(VARIABLE_POINTER_TRACK) get by FindVariable is invald in 
> > this situation and this Variable will be pass to UpdateVariable().
> >
> >   if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
> > Status = AuthVariableLibProcessVariable (VariableName, 
> > VendorGuid, Data, DataSize, Attributes);
> >   } else {
> > // This Variable is invald while occur reclaim internal in 
> > AutoUpdateLangVariable ()
> > Status = UpdateVariable (VariableName, VendorGuid, Data, 
> > DataSize, Attributes, 0, 0, , NULL);
> >   }
> >
> > >
> > > I am glad to help you but I can't reproduce it until now, can you 
> > > provide a
> > step to reproduce it in simulation platform.
> >
> > I am not familiar with simulation platform. We reproduct this issue 
> > in our board once.
> > For accelerating reproduction this issue, Add Reclaim() to
> > AutoUpdateLangVariable() for test.
> >
> > Thanks,
> > Ming
> >
> > >
> > > If it is urgent, I suggest that discuss with your internal team 
> > > first and explain
> > that we need consider the risk check it into edk2.
> > >
> > > Best Regards
> > > Guomin
> > >
> > >> -Original Message-
> > >> From: devel@edk2.groups.io  On Behalf Of
> Ming
> > >> Huang via groups.io
> > >> Sent: Tuesday, June 30, 2020 8:26 PM
> > >> To: Jiang, Guomin ; devel@edk2.groups.io; 
> > >> Wang, Jian J ; Wu, Hao A 
> > >> ; Gao, Liming 
> > >> Cc: lidongz...@huawei.com; songdongku...@huawei.com; 
> > >> wanghuiqi...@huawei.com; qiulian...@huawei.com;
> > shenli...@huawei.com;
> > >> xiewen...@huawei.com
> > >> Subject: Re: [edk2-devel] [PATCH edk2 v1 1/1]
> MdeModulePkg/Variable:
> > >> Move FindVariable after AutoUpdateLan

答复: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-07-22 Thread Ming Huang via groups.io
Hi GuoMin,

I don't think the new change can fix this issue(id=2667). We use older edk2 
version which don't have 
SynchronizeRuntimeVariableCache().

Thanks
Ming

-邮件原件-
发件人: Jiang, Guomin [mailto:guomin.ji...@intel.com] 
发送时间: 2020年7月22日 8:47
收件人: Huangming (Mark) ; devel@edk2.groups.io; Wang, 
Jian J ; Wu, Hao A ; Gao, Liming 

抄送: Lidongzhan ; Songdongkuang 
; wanghuiqiang ; qiuliangen 
; Shenlimei ; xiewenyi (A) 
; John Garry 
主题: RE: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move 
FindVariable after AutoUpdateLangVariable

Hi Ming,

The new posted change https://edk2.groups.io/g/devel/topic/75412007#62327 may 
be helpful for this issue.

Can you add the change in your code and verify it?

Thanks
Guomin
> -Original Message-
> From: Ming Huang 
> Sent: Friday, July 3, 2020 8:49 PM
> To: Jiang, Guomin ; devel@edk2.groups.io; 
> Wang, Jian J ; Wu, Hao A ; 
> Gao, Liming 
> Cc: lidongz...@huawei.com; songdongku...@huawei.com; 
> wanghuiqi...@huawei.com; qiulian...@huawei.com; shenli...@huawei.com; 
> xiewen...@huawei.com; john.ga...@huawei.com
> Subject: Re: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable:
> Move FindVariable after AutoUpdateLangVariable
> 
> 
> 
> 在 2020/7/1 8:22, Jiang, Guomin 写道:
> > So I think the key point is why AutoUpdateLangVariable() return 
> > success
> rather than fail, if is it reasonable for this case or we need other 
> error handing?
> 
> I don't think AutoUpdateLangVariable() should return fail while occur 
> reclaim internal in AutoUpdateLangVariable () function. The problem is 
> the
> Variable(VARIABLE_POINTER_TRACK) get by FindVariable is invald in this 
> situation and this Variable will be pass to UpdateVariable().
> 
>   if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
> Status = AuthVariableLibProcessVariable (VariableName, VendorGuid, 
> Data, DataSize, Attributes);
>   } else {
> // This Variable is invald while occur reclaim internal in 
> AutoUpdateLangVariable ()
> Status = UpdateVariable (VariableName, VendorGuid, Data, DataSize, 
> Attributes, 0, 0, , NULL);
>   }
> 
> >
> > I am glad to help you but I can't reproduce it until now, can you 
> > provide a
> step to reproduce it in simulation platform.
> 
> I am not familiar with simulation platform. We reproduct this issue in 
> our board once.
> For accelerating reproduction this issue, Add Reclaim() to
> AutoUpdateLangVariable() for test.
> 
> Thanks,
> Ming
> 
> >
> > If it is urgent, I suggest that discuss with your internal team 
> > first and explain
> that we need consider the risk check it into edk2.
> >
> > Best Regards
> > Guomin
> >
> >> -Original Message-
> >> From: devel@edk2.groups.io  On Behalf Of Ming 
> >> Huang via groups.io
> >> Sent: Tuesday, June 30, 2020 8:26 PM
> >> To: Jiang, Guomin ; devel@edk2.groups.io; 
> >> Wang, Jian J ; Wu, Hao A 
> >> ; Gao, Liming 
> >> Cc: lidongz...@huawei.com; songdongku...@huawei.com; 
> >> wanghuiqi...@huawei.com; qiulian...@huawei.com;
> shenli...@huawei.com;
> >> xiewen...@huawei.com
> >> Subject: Re: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable:
> >> Move FindVariable after AutoUpdateLangVariable
> >>
> >>
> >>
> >> 在 2020/6/30 8:58, Jiang, Guomin 写道:
> >>> Hi Huang,
> >>>
> >>> >From issue statement, I guess that
> >>> 1. AutoUpdateLangVariable() invoked, and it will invoke
> >>> FindVariable() first, at the same time, reclaim occur and 
> >>> Variable.CurrPtr is invalid, it return
> >> with success 2. UpdateVariable() is invoked when The old Lang's 
> >> State is valid and the new Lang's State is also valid.
> >>> 3. In the situation, FindVariable() checked Lang's State and only 
> >>> enable one
> >> Lang's State. But it didn't in fact.
> >>> 4. BmForEachVariable() deadloop in the situation.
> >>>
> >>> Am I right?
> >>
> >> Yes, right.
> >>
> >> Thanks,
> >> Ming
> >>
> >>>
> >>>> -Original Message-
> >>>> From: devel@edk2.groups.io  On Behalf Of
> Ming
> >>>> Huang via groups.io
> >>>> Sent: Monday, June 29, 2020 2:06 PM
> >>>> To: devel@edk2.groups.io; Wang, Jian J ; 
> >>>> Wu, Hao A ; Gao, Liming 
> >>>> 
> >>>> Cc: lidongz...@huawei.com; huangmin...@huawei.com; 
> >>>> songdongku...@huawei.com; wanghuiqi...@huawei.com; 
> >>>> qiulian...@h

Re: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-07-03 Thread Ming Huang via groups.io



在 2020/7/1 8:22, Jiang, Guomin 写道:
> So I think the key point is why AutoUpdateLangVariable() return success 
> rather than fail, if is it reasonable for this case or we need other error 
> handing?

I don't think AutoUpdateLangVariable() should return fail while occur reclaim 
internal in AutoUpdateLangVariable ()
function. The problem is the Variable(VARIABLE_POINTER_TRACK) get by 
FindVariable is invald in this situation and
this Variable will be pass to UpdateVariable().

  if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
Status = AuthVariableLibProcessVariable (VariableName, VendorGuid, Data, 
DataSize, Attributes);
  } else {
// This Variable is invald while occur reclaim internal in 
AutoUpdateLangVariable ()
Status = UpdateVariable (VariableName, VendorGuid, Data, DataSize, 
Attributes, 0, 0, , NULL);
  }

> 
> I am glad to help you but I can't reproduce it until now, can you provide a 
> step to reproduce it in simulation platform.

I am not familiar with simulation platform. We reproduct this issue in our 
board once.
For accelerating reproduction this issue, Add Reclaim() to 
AutoUpdateLangVariable() for test.

Thanks,
Ming

> 
> If it is urgent, I suggest that discuss with your internal team first and 
> explain that we need consider the risk check it into edk2.
> 
> Best Regards
> Guomin
> 
>> -Original Message-----
>> From: devel@edk2.groups.io  On Behalf Of Ming
>> Huang via groups.io
>> Sent: Tuesday, June 30, 2020 8:26 PM
>> To: Jiang, Guomin ; devel@edk2.groups.io; Wang,
>> Jian J ; Wu, Hao A ; Gao,
>> Liming 
>> Cc: lidongz...@huawei.com; songdongku...@huawei.com;
>> wanghuiqi...@huawei.com; qiulian...@huawei.com;
>> shenli...@huawei.com; xiewen...@huawei.com
>> Subject: Re: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable:
>> Move FindVariable after AutoUpdateLangVariable
>>
>>
>>
>> 在 2020/6/30 8:58, Jiang, Guomin 写道:
>>> Hi Huang,
>>>
>>> >From issue statement, I guess that
>>> 1. AutoUpdateLangVariable() invoked, and it will invoke FindVariable()
>>> first, at the same time, reclaim occur and Variable.CurrPtr is invalid, it 
>>> return
>> with success 2. UpdateVariable() is invoked when The old Lang's State is 
>> valid
>> and the new Lang's State is also valid.
>>> 3. In the situation, FindVariable() checked Lang's State and only enable one
>> Lang's State. But it didn't in fact.
>>> 4. BmForEachVariable() deadloop in the situation.
>>>
>>> Am I right?
>>
>> Yes, right.
>>
>> Thanks,
>> Ming
>>
>>>
>>>> -Original Message-
>>>> From: devel@edk2.groups.io  On Behalf Of Ming
>>>> Huang via groups.io
>>>> Sent: Monday, June 29, 2020 2:06 PM
>>>> To: devel@edk2.groups.io; Wang, Jian J ; Wu,
>>>> Hao A ; Gao, Liming 
>>>> Cc: lidongz...@huawei.com; huangmin...@huawei.com;
>>>> songdongku...@huawei.com; wanghuiqi...@huawei.com;
>>>> qiulian...@huawei.com; shenli...@huawei.com;
>> xiewen...@huawei.com
>>>> Subject: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable:
>> Move
>>>> FindVariable after AutoUpdateLangVariable
>>>>
>>>> When occur reclaim in AutoUpdateLangVariable(), the CurrPtr of
>>>> Variable is invalid. The State will be update with wrong position
>>>> after UpdateVariable in this situation and two valid PlatformLang or Lang
>> variables will exist.
>>>> BmForEachVariable() will enter endless loop while exist two valid
>>>> PlatformLang variables. So FindVariable() should be invoked atfer
>>>> AutoUpdateLangVariable().
>>>>
>>>> https://bugzilla.tianocore.org/show_bug.cgi?id=2667
>>>>
>>>> Signed-off-by: Ming Huang 
>>>> ---
>>>>  MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26
>>>> ++--
>>>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>>>
>>>> diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> index 1e71fc6..0cec981 100644
>>>> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> @@ -2741,6 +2741,19 @@ VariableServiceSetVariable (
>>>>  mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN)
>>>> NextVariable - (UINTN) Point;
>>>>}
>>>>
>>>> +  if (!FeatureP

Re: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-06-30 Thread Ming Huang via groups.io



在 2020/6/30 8:58, Jiang, Guomin 写道:
> Hi Huang,
> 
>>From issue statement, I guess that
> 1. AutoUpdateLangVariable() invoked, and it will invoke FindVariable() first, 
> at the same time, reclaim occur and Variable.CurrPtr is invalid, it return 
> with success
> 2. UpdateVariable() is invoked when The old Lang's State is valid and the new 
> Lang's State is also valid.
> 3. In the situation, FindVariable() checked Lang's State and only enable one 
> Lang's State. But it didn't in fact.
> 4. BmForEachVariable() deadloop in the situation.
> 
> Am I right?

Yes, right.

Thanks,
Ming

> 
>> -Original Message-----
>> From: devel@edk2.groups.io  On Behalf Of Ming
>> Huang via groups.io
>> Sent: Monday, June 29, 2020 2:06 PM
>> To: devel@edk2.groups.io; Wang, Jian J ; Wu, Hao A
>> ; Gao, Liming 
>> Cc: lidongz...@huawei.com; huangmin...@huawei.com;
>> songdongku...@huawei.com; wanghuiqi...@huawei.com;
>> qiulian...@huawei.com; shenli...@huawei.com; xiewen...@huawei.com
>> Subject: [edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move
>> FindVariable after AutoUpdateLangVariable
>>
>> When occur reclaim in AutoUpdateLangVariable(), the CurrPtr of Variable is
>> invalid. The State will be update with wrong position after UpdateVariable in
>> this situation and two valid PlatformLang or Lang variables will exist.
>> BmForEachVariable() will enter endless loop while exist two valid
>> PlatformLang variables. So FindVariable() should be invoked atfer
>> AutoUpdateLangVariable().
>>
>> https://bugzilla.tianocore.org/show_bug.cgi?id=2667
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26
>> ++--
>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>
>> diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> index 1e71fc6..0cec981 100644
>> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> @@ -2741,6 +2741,19 @@ VariableServiceSetVariable (
>>  mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN)
>> NextVariable - (UINTN) Point;
>>}
>>
>> +  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
>> +//
>> +// Hook the operation of setting PlatformLangCodes/PlatformLang and
>> LangCodes/Lang.
>> +//
>> +Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
>> +if (EFI_ERROR (Status)) {
>> +  //
>> +  // The auto update operation failed, directly return to avoid
>> inconsistency between PlatformLang and Lang.
>> +  //
>> +  goto Done;
>> +}
>> +  }
>> +
>>//
>>// Check whether the input variable is already existed.
>>//
>> @@ -2763,19 +2776,6 @@ VariableServiceSetVariable (
>>  }
>>}
>>
>> -  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
>> -//
>> -// Hook the operation of setting PlatformLangCodes/PlatformLang and
>> LangCodes/Lang.
>> -//
>> -Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
>> -if (EFI_ERROR (Status)) {
>> -  //
>> -  // The auto update operation failed, directly return to avoid 
>> inconsistency
>> between PlatformLang and Lang.
>> -  //
>> -  goto Done;
>> -}
>> -  }
>> -
>>if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
>>  Status = AuthVariableLibProcessVariable (VariableName, VendorGuid,
>> Data, DataSize, Attributes);
>>} else {
>> --
>> 2.8.1
>>
>>
>> 
> 
> 
> 


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

View/Reply Online (#61854): https://edk2.groups.io/g/devel/message/61854
Mute This Topic: https://groups.io/mt/75186349/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2 v1 0/1] Fix a infrequent issue in variable

2020-06-29 Thread Ming Huang via groups.io
https://bugzilla.tianocore.org/show_bug.cgi?id=2667


Ming Huang (1):
  MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26 ++--
 1 file changed, 13 insertions(+), 13 deletions(-)

-- 
2.8.1


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

View/Reply Online (#61785): https://edk2.groups.io/g/devel/message/61785
Mute This Topic: https://groups.io/mt/75186348/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-06-29 Thread Ming Huang via groups.io
When occur reclaim in AutoUpdateLangVariable(), the CurrPtr of
Variable is invalid. The State will be update with wrong position
after UpdateVariable in this situation and two valid PlatformLang or
Lang variables will exist. BmForEachVariable() will enter endless loop
while exist two valid PlatformLang variables. So FindVariable() should
be invoked atfer AutoUpdateLangVariable().

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

Signed-off-by: Ming Huang 
---
 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26 ++--
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c 
b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 1e71fc6..0cec981 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -2741,6 +2741,19 @@ VariableServiceSetVariable (
 mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) 
NextVariable - (UINTN) Point;
   }
 
+  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
+//
+// Hook the operation of setting PlatformLangCodes/PlatformLang and 
LangCodes/Lang.
+//
+Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
+if (EFI_ERROR (Status)) {
+  //
+  // The auto update operation failed, directly return to avoid 
inconsistency between PlatformLang and Lang.
+  //
+  goto Done;
+}
+  }
+
   //
   // Check whether the input variable is already existed.
   //
@@ -2763,19 +2776,6 @@ VariableServiceSetVariable (
 }
   }
 
-  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
-//
-// Hook the operation of setting PlatformLangCodes/PlatformLang and 
LangCodes/Lang.
-//
-Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
-if (EFI_ERROR (Status)) {
-  //
-  // The auto update operation failed, directly return to avoid 
inconsistency between PlatformLang and Lang.
-  //
-  goto Done;
-}
-  }
-
   if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
 Status = AuthVariableLibProcessVariable (VariableName, VendorGuid, Data, 
DataSize, Attributes);
   } else {
-- 
2.8.1


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

View/Reply Online (#61786): https://edk2.groups.io/g/devel/message/61786
Mute This Topic: https://groups.io/mt/75186349/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [RFC edk2 v1 0/1] Fix a infrequent issue in variable

2020-06-28 Thread Ming Huang via groups.io
Hi Guomin,

Ok, I will send patch out today.

Thanks,
Ming

在 2020/6/29 11:03, Jiang, Guomin 写道:
> Hi Huang,
> 
> Could you send the normal patch rather than RFC?
> 
> Best Regards
> Guomin
> 
>> -Original Message-
>> From: devel@edk2.groups.io  On Behalf Of Ming
>> Huang
>> Sent: Monday, May 25, 2020 7:34 PM
>> To: devel@edk2.groups.io; Wang, Jian J ; Wu, Hao A
>> ; Gao, Liming 
>> Cc: lidongz...@huawei.com; huangmin...@huawei.com;
>> songdongku...@huawei.com; wanghuiqi...@huawei.com;
>> qiulian...@huawei.com; shenli...@huawei.com
>> Subject: [edk2-devel] [RFC edk2 v1 0/1] Fix a infrequent issue in variable
>>
>> https://bugzilla.tianocore.org/show_bug.cgi?id=2667
>>
>> Ming Huang (1):
>>   MdeModulePkg/Variable: Move FindVariable after
>> AutoUpdateLangVariable
>>
>>  MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26
>> ++--
>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>
>> --
>> 2.8.1
>>
>>
>> 
> 
> 
> 


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

View/Reply Online (#61783): https://edk2.groups.io/g/devel/message/61783
Mute This Topic: https://groups.io/mt/74462884/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH edk2-platforms v3 3/4] Silicon/Hisilicon/Acpi: Add update sas address feature

2020-06-17 Thread Ming Huang



在 2020/6/17 19:07, Leif Lindholm 写道:
> On Wed, Jun 17, 2020 at 10:07:39 +0800, Ming Huang wrote:
>>
>>
>> 在 2020/6/16 22:20, Leif Lindholm 写道:
>>> One remaining question, then this set is ready to go in:
>>>
>>> On Tue, Jun 09, 2020 at 21:27:24 +0800, Ming Huang wrote:
>>>> The updating sas address feature is similar with apdating mac address.
>>>> Modify updating dsdt flow for add this feature.
>>>>
>>>> Signed-off-by: Ming Huang 
>>>> ---
>>>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
>>>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   1 +
>>>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 292 
>>>> +++-
>>>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|   2 +-
>>>>  4 files changed, 227 insertions(+), 70 deletions(-)
>>>>
>>>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
>>>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>>>> index c45a0bb..9cdf710 100644
>>>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>>>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>>>> @@ -46,7 +46,7 @@ UpdateAcpiDsdt (
>>>>  return;
>>>>}
>>>>
>>>> -  Status = EthMacInit ();
>>>> +  Status = UpdateAcpiDsdtTable ();
>>>>if (EFI_ERROR (Status)) {
>>>>  DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
>>>> Status));
>>>>}
>>>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
>>>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>>>> index 866ff75..856309a 100644
>>>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>>>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>>>> @@ -46,6 +46,7 @@
>>>>gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
>>>>gEfiAcpiSdtProtocolGuid   # PROTOCOL ALWAYS_CONSUMED
>>>>gHisiBoardNicProtocolGuid   # PROTOCOL 
>>>> ALWAYS_CONSUMED
>>>> +  gHisiSasConfigProtocolGuid
>>>>
>>>>  [FeaturePcd]
>>>>gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol
>>>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
>>>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>>>> index cd98506..841c94e 100644
>>>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>>>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>>>> @@ -1,7 +1,7 @@
>>>>  /** @file
>>>>
>>>>Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
>>>> reserved.
>>>> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>>>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>>>>Copyright (c) 2015, Linaro Limited. All rights reserved.
>>>>SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>
>>>> @@ -23,6 +23,7 @@
>>>>  #include 
>>>>  #include 
>>>>  #include 
>>>> +#include 
>>>>  #include 
>>>>  #include 
>>>>  #include 
>>>> @@ -32,6 +33,7 @@
>>>>  #include 
>>>>
>>>>  #include 
>>>> +#include 
>>>>
>>>>  // Turn on debug message by enabling below define
>>>>  //#define ACPI_DEBUG
>>>> @@ -45,17 +47,27 @@
>>>>  #define EFI_ACPI_MAX_NUM_TABLES 20
>>>>  #define DSDT_SIGNATURE  0x54445344
>>>>
>>>> -#define D03_ACPI_ETH_ID "HISI00C2"
>>>> -
>>>>  #define ACPI_ETH_MAC_KEY"local-mac-address"
>>>> +#define ACPI_ETH_SAS_KEY"sas-addr"
>>>>
>>>>  #define PREFIX_VARIABLE_NAMEL"MAC"
>>>>  #define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
>>>> -#define MAC_MAX_LEN 30
>>>> +#define ADDRESS_MAX_LEN 30
>>>> +
>>>> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>>>> +
>>&g

Re: [edk2-devel] [PATCH edk2-platforms v3 3/4] Silicon/Hisilicon/Acpi: Add update sas address feature

2020-06-16 Thread Ming Huang



在 2020/6/16 22:20, Leif Lindholm 写道:
> One remaining question, then this set is ready to go in:
> 
> On Tue, Jun 09, 2020 at 21:27:24 +0800, Ming Huang wrote:
>> The updating sas address feature is similar with apdating mac address.
>> Modify updating dsdt flow for add this feature.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   1 +
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 292 
>> +++-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|   2 +-
>>  4 files changed, 227 insertions(+), 70 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index c45a0bb..9cdf710 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -46,7 +46,7 @@ UpdateAcpiDsdt (
>>  return;
>>}
>>
>> -  Status = EthMacInit ();
>> +  Status = UpdateAcpiDsdtTable ();
>>if (EFI_ERROR (Status)) {
>>  DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
>> Status));
>>}
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> index 866ff75..856309a 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> @@ -46,6 +46,7 @@
>>gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
>>gEfiAcpiSdtProtocolGuid   # PROTOCOL ALWAYS_CONSUMED
>>gHisiBoardNicProtocolGuid   # PROTOCOL 
>> ALWAYS_CONSUMED
>> +  gHisiSasConfigProtocolGuid
>>
>>  [FeaturePcd]
>>gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> index cd98506..841c94e 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> @@ -1,7 +1,7 @@
>>  /** @file
>>
>>Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
>> reserved.
>> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>>Copyright (c) 2015, Linaro Limited. All rights reserved.
>>SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>> @@ -23,6 +23,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -32,6 +33,7 @@
>>  #include 
>>
>>  #include 
>> +#include 
>>
>>  // Turn on debug message by enabling below define
>>  //#define ACPI_DEBUG
>> @@ -45,17 +47,27 @@
>>  #define EFI_ACPI_MAX_NUM_TABLES 20
>>  #define DSDT_SIGNATURE  0x54445344
>>
>> -#define D03_ACPI_ETH_ID "HISI00C2"
>> -
>>  #define ACPI_ETH_MAC_KEY"local-mac-address"
>> +#define ACPI_ETH_SAS_KEY"sas-addr"
>>
>>  #define PREFIX_VARIABLE_NAMEL"MAC"
>>  #define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
>> -#define MAC_MAX_LEN 30
>> +#define ADDRESS_MAX_LEN 30
>> +
>> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>> +
>> +typedef enum {
>> +  DsdtDeviceUnknown,
>> +  DsdtDeviceLan,
>> +  DsdtDeviceSas
>> +} DSDT_DEVICE_TYPE;
>>
>> -EFI_STATUS GetEnvMac(
>> -  IN  UINTNMacNextID,
>> -  IN OUT  UINT8*MacBuffer)
>> +STATIC
>> +EFI_STATUS
>> +GetEnvMac(
>> +  IN UINTNMacNextID,
>> +  IN OUT UINT8*MacBuffer
>> +  )
>>  {
>>EFI_MAC_ADDRESS Mac;
>>EFI_STATUS Status;
>> @@ -89,12 +101,121 @@ EFI_STATUS GetEnvMac(
>>return EFI_SUCCESS;
>>  }
>>
>> -EFI_STATUS _SearchReplacePackageMACAddress(
>> +STATIC
>> +EFI_STATUS
>> +GetSasAddress (
>> +  IN UINT8Index,
>> +  IN OUT UINT8*SasAddrBuffer
>> +  )
>> +{
>> +  EFI_STATUS Status;
>&g

[edk2-devel] [PATCH edk2-platforms v2 0/2] Optimize Smbios type 9

2020-06-09 Thread Ming Huang
Main change since v1:
1 Add some commit messages.

Ming Huang (2):
  Silicon/Hisilicon/Smbios: correct coding style issue in type 9
  Silicon/Hisilicon/Smbios: Optimize type 9

 Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 325 
+++-
 1 file changed, 174 insertions(+), 151 deletions(-)

-- 
2.8.1


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

View/Reply Online (#60974): https://edk2.groups.io/g/devel/message/60974
Mute This Topic: https://groups.io/mt/74774164/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2-platforms v2 2/2] Silicon/Hisilicon/Smbios: Optimize type 9

2020-06-09 Thread Ming Huang
Break down AddSmbiosType9Entry to three funtions for optimizing
Smbios type 9.

Signed-off-by: Ming Huang 
Reviewed-by: Leif Lindholm 
---
 Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 173 
+++-
 1 file changed, 95 insertions(+), 78 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c 
b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
index 2398c6b..57e049a 100644
--- a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
+++ b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
@@ -75,38 +75,16 @@ UpdateSmbiosType9Info (
   return;
 }
 
-EFI_STATUS
-EFIAPI
-AddSmbiosType9Entry (
-  IN EFI_HANDLEImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+STATIC
+VOID
+EmptySmbiosType9 (
+  EFI_SMBIOS_PROTOCOL *Smbios
   )
 {
   EFI_STATUS  Status;
   EFI_SMBIOS_TYPE SmbiosType;
   EFI_SMBIOS_HANDLE   SmbiosHandle;
-  EFI_SMBIOS_PROTOCOL *Smbios;
   EFI_SMBIOS_TABLE_HEADER *Record;
-  SMBIOS_TABLE_TYPE9  *Type9Record;
-  SMBIOS_TABLE_TYPE9  *SmbiosRecord = NULL;
-  CHAR8   *OptionalStrStart;
-
-  UINT8   SmbiosAddType9Number;
-  UINT8   Index;
-
-  CHAR16  *SlotDesignation = NULL;
-  UINTN   SlotDesignationStrLen;
-
-  Status = gBS->LocateProtocol (
-  ,
-  NULL,
-  (VOID **) 
-  );
-  if (EFI_ERROR (Status)) {
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] LocateProtocol Failed. Status : %r\n",
-__FUNCTION__, __LINE__, Status));
-  return Status;
-  }
 
   do {
 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
@@ -122,76 +100,115 @@ AddSmbiosType9Entry (
 }
   } while (SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED);
 
-  SmbiosAddType9Number = OemGetPcieSlotNumber ();
+  return;
+}
 
-  for (Index = 0; Index < SmbiosAddType9Number; Index++) {
-if (gPcieSlotInfo[Index].Hdr.Type != EFI_SMBIOS_TYPE_SYSTEM_SLOTS) {
-  continue;
-}
+STATIC
+EFI_STATUS
+AddSmbiosType9Record (
+  EFI_SMBIOS_PROTOCOL *Smbios,
+  SMBIOS_TABLE_TYPE9  *Type9Record
+  )
+{
+  EFI_STATUS  Status;
+  EFI_SMBIOS_HANDLE   SmbiosHandle;
+  SMBIOS_TABLE_TYPE9  *SmbiosRecord;
+  CHAR8   *OptionalStrStart;
+  CHAR16  
SlotDesignation[SMBIOS_STRING_MAX_LENGTH];
+  UINTN   SlotStrLen;
+
+  SlotStrLen = UnicodeSPrint (
+ SlotDesignation,
+ SMBIOS_STRING_MAX_LENGTH * 2,
+ L"PCIE Slot%d",
+ Type9Record->SlotID);
+
+  //
+  // Two zeros following the last string.
+  //
+  SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE9) + SlotStrLen + 
1 + 1);
+  if (SmbiosRecord == NULL) {
+DEBUG ((DEBUG_ERROR, "AllocateZeroPool Failed for SmbiosRecord.\n"));
+return EFI_OUT_OF_RESOURCES;
+  }
 
-Type9Record = [Index];
+  (VOID)CopyMem (SmbiosRecord, Type9Record, sizeof (SMBIOS_TABLE_TYPE9));
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9);
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
+  (VOID)UnicodeStrToAsciiStr (SlotDesignation, OptionalStrStart);
 
-UpdateSmbiosType9Info (Type9Record);
-SlotDesignation = AllocateZeroPool ((sizeof (CHAR16)) * 
SMBIOS_STRING_MAX_LENGTH);
-if (SlotDesignation == NULL) {
-  Status = EFI_OUT_OF_RESOURCES;
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] AllocateZeroPool Failed. Status : %r\n",
-__FUNCTION__, __LINE__, Status));
+  //
+  // Now we have got the full smbios record, call smbios protocol to add this 
record.
+  //
+  SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
+  Status = Smbios->Add (Smbios, NULL, , (EFI_SMBIOS_TABLE_HEADER 
*)SmbiosRecord);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Add Smbios Type09 Failed! %r\n", Status));
+  }
 
-  goto Exit;
-}
+  FreePool (SmbiosRecord);
+  return Status;
+}
 
-SlotDesignationStrLen = UnicodeSPrint (
-  SlotDesignation,
-  SMBIOS_STRING_MAX_LENGTH - 1,
-  L"PCIE Slot%d",
-  Type9Record->SlotID);
-
-//
-// Two zeros following the last string.
-//
-SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE9) + 
SlotDesignationStrLen + 1 + 1);
-if (SmbiosRecord == NULL) {
-  Status = EFI_OUT_OF_RESOURCES;
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] AllocateZeroPool Failed. Status : %r\n",
-__FUNCTION__, __LINE__, Status));
+STATIC
+VOID
+HandleSmbiosType9 (
+  EFI_SMBIO

[edk2-devel] [PATCH edk2-platforms v2 1/2] Silicon/Hisilicon/Smbios: correct coding style issue in type 9

2020-06-09 Thread Ming Huang
The main changes are whitespace/indentation fixing and wrapping
of long lines and changing some macros from EFI_D_ERROR to DEBUG_ERROR.
This patch is prepare for optimizing Smbios type 9.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 286 
++--
 1 file changed, 146 insertions(+), 140 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c 
b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
index 87a06a2..2398c6b 100644
--- a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
+++ b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
@@ -1,6 +1,6 @@
 /** @file
 *
-*  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+*  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
 *  Copyright (c) 2015, Linaro Limited. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -14,178 +14,184 @@ extern UINT8 OemGetPcieSlotNumber ();
 
 VOID
 EFIAPI
-UpdateSmbiosType9Info(
+UpdateSmbiosType9Info (
   IN OUT SMBIOS_TABLE_TYPE9 *Type9Record
 )
 {
-EFI_STATUS Status;
-UINTN  HandleIndex;
-EFI_HANDLE*HandleBuffer;
-UINTN  HandleCount;
-EFI_PCI_IO_PROTOCOL   *PciIo;
-UINTN  SegmentNumber;
-UINTN  BusNumber;
-UINTN  DeviceNumber;
-UINTN  FunctionNumber;
-UINTN  Index;
-REPORT_PCIEDIDVID2BMC  ReportPcieDidVid[PCIEDEVICE_REPORT_MAX];
-
-GetPciDidVid ((VOID *) ReportPcieDidVid);
-
-Status = gBS->LocateHandleBuffer (
-  ByProtocol,
-  ,
-  NULL,
-  ,
-  
-  );
-if(EFI_ERROR(Status)) {
-DEBUG((EFI_D_ERROR, " Locate gEfiPciIoProtocol Failed.\n"));
-gBS->FreePool ((VOID *)HandleBuffer);
-return;
+  EFI_STATUS Status;
+  UINTN  HandleIndex;
+  EFI_HANDLE*HandleBuffer;
+  UINTN  HandleCount;
+  EFI_PCI_IO_PROTOCOL   *PciIo;
+  UINTN  SegmentNumber;
+  UINTN  BusNumber;
+  UINTN  DeviceNumber;
+  UINTN  FunctionNumber;
+  UINTN  Index;
+  REPORT_PCIEDIDVID2BMC  ReportPcieDidVid[PCIEDEVICE_REPORT_MAX];
+
+  GetPciDidVid ((VOID *)ReportPcieDidVid);
+
+  Status = gBS->LocateHandleBuffer (
+  ByProtocol,
+  ,
+  NULL,
+  ,
+  
+  );
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " Locate gEfiPciIoProtocol Failed.\n"));
+gBS->FreePool ((VOID *)HandleBuffer);
+return;
+  }
+
+  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
+Status = gBS->HandleProtocol (
+HandleBuffer[HandleIndex],
+,
+(VOID **)
+);
+if (EFI_ERROR (Status)) {
+  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Status : %r\n", __FUNCTION__, __LINE__, 
Status));
+  continue;
 }
-for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
-Status = gBS->HandleProtocol (
-HandleBuffer[HandleIndex],
-,
-(VOID **)
-);
-if (EFI_ERROR (Status)) {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] Status : %r\n", __FUNCTION__, 
__LINE__, Status));
-continue;
-}
-(VOID)PciIo->GetLocation(PciIo, , , 
, );
-for(Index = 0; Index < sizeof(ReportPcieDidVid) / 
sizeof(REPORT_PCIEDIDVID2BMC); Index++){
-if (Type9Record->SlotID == ReportPcieDidVid[Index].Slot + 1) {
-if((BusNumber == ReportPcieDidVid[Index].Bus) && (DeviceNumber 
== ReportPcieDidVid[Index].Device)) {
-DEBUG((EFI_D_ERROR,"PCIe device plot in slot Seg %d  bdf 
%d %d %d\r\n",SegmentNumber,BusNumber,DeviceNumber,FunctionNumber));
-Type9Record->SegmentGroupNum   = SegmentNumber;
-Type9Record->BusNum= BusNumber;
-Type9Record->DevFuncNum= (DeviceNumber << 3) | 
FunctionNumber;
-Type9Record->CurrentUsage  = SlotU

Re: [edk2-devel] [PATCH edk2-platforms v1 1/2] Silicon/Hisilicon/Smbios: correct coding style issue in type 9

2020-06-09 Thread Ming Huang



在 2020/6/8 23:41, Leif Lindholm 写道:
> On Mon, Jun 08, 2020 at 22:09:56 +0800, Ming Huang wrote:
>> This patch is prepare for optimizing Smbios type 9.
> 
> How?
> The commit message should describe what the patch does.
> 
> (Yes, I can see with "git diff -w" that this is mainly
> whitespace/indentation fixes and wrapping of long lines, but the
> message should state this.)
> 
> Also, This patch changes from EFI_D_ERROR to DEBUG_ERROR. This is
> absolutely an improvement, but needs to be mentioned in commit
> message.

Ok, I will add it in v2.

Thanks,
Ming

> 
> Regards,
> 
> Leif
> 
>> Signed-off-by: Ming Huang 
>> ---
>>  Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 286 
>> ++--
>>  1 file changed, 146 insertions(+), 140 deletions(-)
>>
>> diff --git 
>> a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c 
>> b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
>> index 87a06a2..2398c6b 100644
>> --- a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
>> +++ b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
>> @@ -1,6 +1,6 @@
>>  /** @file
>>  *
>> -*  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> +*  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>>  *  Copyright (c) 2015, Linaro Limited. All rights reserved.
>>  *
>>  *  SPDX-License-Identifier: BSD-2-Clause-Patent
>> @@ -14,178 +14,184 @@ extern UINT8 OemGetPcieSlotNumber ();
>>
>>  VOID
>>  EFIAPI
>> -UpdateSmbiosType9Info(
>> +UpdateSmbiosType9Info (
>>IN OUT SMBIOS_TABLE_TYPE9 *Type9Record
>>  )
>>  {
>> -EFI_STATUS Status;
>> -UINTN  HandleIndex;
>> -EFI_HANDLE*HandleBuffer;
>> -UINTN  HandleCount;
>> -EFI_PCI_IO_PROTOCOL   *PciIo;
>> -UINTN  SegmentNumber;
>> -UINTN  BusNumber;
>> -UINTN  DeviceNumber;
>> -UINTN  FunctionNumber;
>> -UINTN  Index;
>> -REPORT_PCIEDIDVID2BMC  
>> ReportPcieDidVid[PCIEDEVICE_REPORT_MAX];
>> -
>> -GetPciDidVid ((VOID *) ReportPcieDidVid);
>> -
>> -Status = gBS->LocateHandleBuffer (
>> -  ByProtocol,
>> -  ,
>> -  NULL,
>> -  ,
>> -  
>> -  );
>> -if(EFI_ERROR(Status)) {
>> -DEBUG((EFI_D_ERROR, " Locate gEfiPciIoProtocol Failed.\n"));
>> -gBS->FreePool ((VOID *)HandleBuffer);
>> -return;
>> +  EFI_STATUS Status;
>> +  UINTN  HandleIndex;
>> +  EFI_HANDLE*HandleBuffer;
>> +  UINTN  HandleCount;
>> +  EFI_PCI_IO_PROTOCOL   *PciIo;
>> +  UINTN  SegmentNumber;
>> +  UINTN  BusNumber;
>> +  UINTN  DeviceNumber;
>> +  UINTN  FunctionNumber;
>> +  UINTN  Index;
>> +  REPORT_PCIEDIDVID2BMC  
>> ReportPcieDidVid[PCIEDEVICE_REPORT_MAX];
>> +
>> +  GetPciDidVid ((VOID *)ReportPcieDidVid);
>> +
>> +  Status = gBS->LocateHandleBuffer (
>> +  ByProtocol,
>> +  ,
>> +  NULL,
>> +  ,
>> +  
>> +  );
>> +  if (EFI_ERROR (Status)) {
>> +DEBUG ((DEBUG_ERROR, " Locate gEfiPciIoProtocol Failed.\n"));
>> +gBS->FreePool ((VOID *)HandleBuffer);
>> +return;
>> +  }
>> +
>> +  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
>> +Status = gBS->HandleProtocol (
>> +HandleBuffer[HandleIndex],
>> +,
>> +(VOID **)
>> +);
>> +if (EFI_ERROR (Status)) {
>> +  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Status : %r\n", __FUNCTION__, 
>> __LINE__, Status));
>> +  continue;
>>  }
>> -for (HandleIndex 

[edk2-devel] [PATCH edk2-platforms v3 3/4] Silicon/Hisilicon/Acpi: Add update sas address feature

2020-06-09 Thread Ming Huang
The updating sas address feature is similar with apdating mac address.
Modify updating dsdt flow for add this feature.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   1 +
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 292 
+++-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|   2 +-
 4 files changed, 227 insertions(+), 70 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index c45a0bb..9cdf710 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -46,7 +46,7 @@ UpdateAcpiDsdt (
 return;
   }
 
-  Status = EthMacInit ();
+  Status = UpdateAcpiDsdtTable ();
   if (EFI_ERROR (Status)) {
 DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
Status));
   }
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 866ff75..856309a 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -46,6 +46,7 @@
   gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
   gEfiAcpiSdtProtocolGuid   # PROTOCOL ALWAYS_CONSUMED
   gHisiBoardNicProtocolGuid   # PROTOCOL 
ALWAYS_CONSUMED
+  gHisiSasConfigProtocolGuid
 
 [FeaturePcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
index cd98506..841c94e 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
   Copyright (c) 2015, Linaro Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -32,6 +33,7 @@
 #include 
 
 #include 
+#include 
 
 // Turn on debug message by enabling below define
 //#define ACPI_DEBUG
@@ -45,17 +47,27 @@
 #define EFI_ACPI_MAX_NUM_TABLES 20
 #define DSDT_SIGNATURE  0x54445344
 
-#define D03_ACPI_ETH_ID "HISI00C2"
-
 #define ACPI_ETH_MAC_KEY"local-mac-address"
+#define ACPI_ETH_SAS_KEY"sas-addr"
 
 #define PREFIX_VARIABLE_NAMEL"MAC"
 #define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
-#define MAC_MAX_LEN 30
+#define ADDRESS_MAX_LEN 30
+
+CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
+
+typedef enum {
+  DsdtDeviceUnknown,
+  DsdtDeviceLan,
+  DsdtDeviceSas
+} DSDT_DEVICE_TYPE;
 
-EFI_STATUS GetEnvMac(
-  IN  UINTNMacNextID,
-  IN OUT  UINT8*MacBuffer)
+STATIC
+EFI_STATUS
+GetEnvMac(
+  IN UINTNMacNextID,
+  IN OUT UINT8*MacBuffer
+  )
 {
   EFI_MAC_ADDRESS Mac;
   EFI_STATUS Status;
@@ -89,12 +101,121 @@ EFI_STATUS GetEnvMac(
   return EFI_SUCCESS;
 }
 
-EFI_STATUS _SearchReplacePackageMACAddress(
+STATIC
+EFI_STATUS
+GetSasAddress (
+  IN UINT8Index,
+  IN OUT UINT8*SasAddrBuffer
+  )
+{
+  EFI_STATUS Status;
+  HISI_SAS_CONFIG_PROTOCOL *HisiSasConf;
+
+  if (SasAddrBuffer == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  Status = gBS->LocateProtocol (, NULL, (VOID 
**));
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Locate Sas Config Protocol failed %r\n", Status));
+SasAddrBuffer[0] = 0x50;
+SasAddrBuffer[1] = 0x01;
+SasAddrBuffer[2] = 0x88;
+SasAddrBuffer[3] = 0x20;
+SasAddrBuffer[4] = 0x16;
+SasAddrBuffer[5] = 0x00;
+SasAddrBuffer[6] = 0x00;
+SasAddrBuffer[7] = Index;
+return Status;
+  }
+
+  return HisiSasConf->GetAddr (Index, SasAddrBuffer);
+}
+
+STATIC
+EFI_STATUS
+UpdateAddressInOption (
+  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
+  IN EFI_ACPI_HANDLEChildHandle,
+  IN UINTN  DevNextID,
+  IN DSDT_DEVICE_TYPE   FoundDev
+  )
+{
+  EFI_STATUS  Status;
+  EFI_ACPI_DATA_TYPE  DataType;
+  CONST VOID  *Buffer;
+  UINTN   DataSize;
+  UINTN   Count;
+  EFI_ACPI_HANDLE CurrentHandle;
+  UINT8   *AddressBuffer;
+  UINT8   AddressByte;
+
+  AddressByte = 0;
+  AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
+  if (AddressBuffer == NULL) {
+DEBUG

[edk2-devel] [PATCH edk2-platforms v3 0/4] Improve D0x

2020-06-09 Thread Ming Huang
Main changes since v2:
1 Remove needless three lines.


Ming Huang (4):
  Silicon/Hisilicon: Change updating dsdt in ready to boot event
  Silicon/Hisilicon: Add HISI_SAS_CONFIG_PROTOCOL
  Silicon/Hisilicon/Acpi: Add update sas address feature
  Silicon/Hisilicon: Rename EthMac files

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |  58 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   7 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 500 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 656 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
 Silicon/Hisilicon/HisiPkg.dec |   1 +
 Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h|  43 ++
 8 files changed, 775 insertions(+), 522 deletions(-)
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
 create mode 100644 Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h

-- 
2.8.1


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

View/Reply Online (#60970): https://edk2.groups.io/g/devel/message/60970
Mute This Topic: https://groups.io/mt/74773829/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2-platforms v3 4/4] Silicon/Hisilicon: Rename EthMac files

2020-06-09 Thread Ming Huang
As not only update mac address feature in EthMac files, so rename
them to UpdateDsdt.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 656 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 656 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
 6 files changed, 674 insertions(+), 674 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index 9cdf710..34a1dc9 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 #include 
-#include "EthMac.h"
+#include "UpdateDsdt.h"
 
 EFI_EVENT   mUpdateAcpiDsdtTableEvent;
 
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 856309a..efb7ff3 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -18,7 +18,7 @@
 
 [Sources]
   AcpiPlatform.c
-  EthMac.c
+  UpdateDsdt.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
deleted file mode 100644
index 841c94e..000
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ /dev/null
@@ -1,656 +0,0 @@
-/** @file
-
-  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
-  Copyright (c) 2015, Linaro Limited. All rights reserved.
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-  This driver is called to initialize the FW part of the PHY in preparation
-  for the OS.
-
-**/
-
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-// Turn on debug message by enabling below define
-//#define ACPI_DEBUG
-
-#ifdef ACPI_DEBUG
-#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
-#else
-#define DBG(arg...)
-#endif
-
-#define EFI_ACPI_MAX_NUM_TABLES 20
-#define DSDT_SIGNATURE  0x54445344
-
-#define ACPI_ETH_MAC_KEY"local-mac-address"
-#define ACPI_ETH_SAS_KEY"sas-addr"
-
-#define PREFIX_VARIABLE_NAMEL"MAC"
-#define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
-#define ADDRESS_MAX_LEN 30
-
-CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
-
-typedef enum {
-  DsdtDeviceUnknown,
-  DsdtDeviceLan,
-  DsdtDeviceSas
-} DSDT_DEVICE_TYPE;
-
-STATIC
-EFI_STATUS
-GetEnvMac(
-  IN UINTNMacNextID,
-  IN OUT UINT8*MacBuffer
-  )
-{
-  EFI_MAC_ADDRESS Mac;
-  EFI_STATUS Status;
-  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
-
-  Status = gBS->LocateProtocol(, NULL, (VOID 
**));
-  if(EFI_ERROR(Status))
-  {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, 
__LINE__, Status));
-return Status;
-  }
-
-  Status = OemNic->GetMac(, MacNextID);
-  if(EFI_ERROR(Status))
-  {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, 
__LINE__, Status));
-return Status;
-  }
-
-  CopyMem (MacBuffer, , 6);
-  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
-MacNextID,
-MacBuffer[0],
-MacBuffer[1],
-MacBuffer[2],
-MacBuffer[3],
-MacBuffer[4],
-MacBuffer[5]
-));
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-GetSasAddress (
-  IN UINT8Index,
-  IN OUT UINT8*SasAddrBuffer
-  )
-{
-  EFI_STATUS Status;
-  HISI_SAS_CONFIG_PROTOCOL *HisiSasConf;
-
-  if (SasAddrBuffer == NULL) {
-return EFI_INVALID_PARAMETER;
-  }
-
-  Status = gBS->LocateProtocol (, NULL, (VOID 
**));
-  if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_ERROR, "Locate Sas Config Protocol failed %r\n", Status));
-SasAddrBuffer[0] = 0x50;
-SasAddrBuffer[1] = 0x01;
-SasAddrBuffer[2] = 0x88;
-SasAddrBuffer[3] = 0x20;
-SasAddrBuffer[4] = 0x16;
-SasAddrBuffer[5] = 0x00;
-SasAddrBuffer[6] = 0x00;
-SasAddrBuffer[7] = Index;
-return Status;
-  }
-
-  return HisiSasConf->GetAddr (Index, SasAddrBuffer);
-}
-
-STATIC
-EFI_STATUS
-UpdateAddressInOption (
-  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
-  IN EFI_ACPI_HANDLEChildHandle,
-  IN UINTN  

[edk2-devel] [PATCH edk2-platforms v3 2/4] Silicon/Hisilicon: Add HISI_SAS_CONFIG_PROTOCOL

2020-06-09 Thread Ming Huang
Add HISI_SAS_CONFIG_PROTOCOL, provide get sas address interface,
this is prepare for adding update sas address feature.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/HisiPkg.dec  |  1 +
 Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h | 43 
 2 files changed, 44 insertions(+)

diff --git a/Silicon/Hisilicon/HisiPkg.dec b/Silicon/Hisilicon/HisiPkg.dec
index 63f50f7..051b5b8 100644
--- a/Silicon/Hisilicon/HisiPkg.dec
+++ b/Silicon/Hisilicon/HisiPkg.dec
@@ -34,6 +34,7 @@
   gHisiPlatformSasProtocolGuid = {0x20e9829f, 0x3a2c, 0x479a, {0x9a, 0x93, 
0x45, 0x7d, 0x13, 0x50, 0x96, 0x6d}}
   gHisiSnpPlatformProtocolGuid = {0x81321f27, 0xff58, 0x4a1d, {0x99, 0x97, 
0xd, 0xcc, 0xfa, 0x82, 0xf4, 0x6f}}
   gHisiInstalledAcpiProtocolGuid = {0x31505f6a, 0xe496, 0x4c7e, {0xba, 0xbb, 
0x71, 0x7b, 0xe2, 0xc4, 0xb4, 0x59}}
+  gHisiSasConfigProtocolGuid = {0x3A236669, 0x, 0x4d04, {0xb2, 0x83, 0x7, 
0x9f, 0x3c, 0xc4, 0x71, 0x66}}
 
 [Guids]
   gHisiTokenSpaceGuid = {0xc8bc553e, 0x12bf, 0x11e6, {0x97, 0x4f, 0x87, 0xf7, 
0x7c, 0xfd, 0x52, 0x1d}}
diff --git a/Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h 
b/Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h
new file mode 100644
index 000..6b850c8
--- /dev/null
+++ b/Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h
@@ -0,0 +1,43 @@
+/** @file
+
+  Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef HISI_SAS_CONFIG_H_
+#define HISI_SAS_CONFIG_H_
+
+typedef struct{
+  UINT32 CtrlId;
+  BOOLEANEnable;
+  UINT32 Bar32;
+  UINT64 ResetBase;
+  UINTN  Segment;
+  UINTN  Bus;
+  UINTN  Device;
+  UINTN  Fun;
+} SAS_CONTROLLER_DATA;
+
+typedef
+VOID *
+(EFIAPI *HISI_SAS_GET_CONTROLLER_DATA) (
+  VOID
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *HISI_SAS_GET_ADDRESS) (
+  IN UINT8 Index,
+  IN OUT UINT8 *SasAddrBuffer
+  );
+
+typedef struct {
+  HISI_SAS_GET_ADDRESS GetAddr;
+  HISI_SAS_GET_CONTROLLER_DATA GetControllerData;
+} HISI_SAS_CONFIG_PROTOCOL;
+
+extern EFI_GUID gHisiSasConfigProtocolGuid;
+
+#endif
-- 
2.8.1


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

View/Reply Online (#60969): https://edk2.groups.io/g/devel/message/60969
Mute This Topic: https://groups.io/mt/74773828/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2-platforms v3 1/4] Silicon/Hisilicon: Change updating dsdt in ready to boot event

2020-06-09 Thread Ming Huang
The dsdt need be updated before boot to OS, so change the updating
to ready to boot event and can remove the needless dependence.

Signed-off-by: Ming Huang 
Reviewed-by: Leif Lindholm 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  | 56 
+++-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |  4 +-
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index b888cb1..c45a0bb 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
   Copyright (c) 2015, Linaro Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -23,6 +23,38 @@
 #include 
 #include "EthMac.h"
 
+EFI_EVENT   mUpdateAcpiDsdtTableEvent;
+
+VOID
+EFIAPI
+UpdateAcpiDsdt (
+  IN EFI_EVENT Event,
+  IN VOID  *Context
+  )
+{
+  EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
+  EFI_STATUS  Status;
+
+  Status = gBS->LocateProtocol (
+  ,
+  NULL,
+  (VOID**)
+  );
+
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " Unable to locate ACPI table protocol\n"));
+return;
+  }
+
+  Status = EthMacInit ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
Status));
+  }
+
+  gBS->CloseEvent (Event);
+  return;
+}
+
 EFI_STATUS
 EFIAPI
 AcpiPlatformEntryPoint (
@@ -30,5 +62,25 @@ AcpiPlatformEntryPoint (
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
-  return EthMacInit();
+  EFI_STATUS Status;
+
+  //
+  // Register notify function
+  //
+  Status = gBS->CreateEventEx (
+  EVT_NOTIFY_SIGNAL,
+  TPL_CALLBACK,
+  UpdateAcpiDsdt,
+  NULL,
+  ,
+  
+  );
+
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Create ReadyToBoot event for UpdateAcpiDsdt 
failed.\n"));
+  } else {
+DEBUG ((DEBUG_INFO, "Create ReadyToBoot event for UpdateAcpiDsdt 
success.\n"));
+  }
+
+  return Status;
 }
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 53da731..866ff75 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -1,7 +1,7 @@
 ## @file
 #
 #  Copyright (c) 2014, Applied Micro Curcuit Corp. All rights reserved.
-#  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+#  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
 #  Copyright (c) 2015, Linaro Limited. All rights reserved.
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -62,5 +62,5 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision
 
 [Depex]
-  gEfiAcpiTableProtocolGuid AND gEfiAcpiSdtProtocolGuid AND 
gHisiBoardNicProtocolGuid AND gHisiInstalledAcpiProtocolGuid
+  TRUE
 
-- 
2.8.1


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

View/Reply Online (#60968): https://edk2.groups.io/g/devel/message/60968
Mute This Topic: https://groups.io/mt/74773826/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH edk2 v2 3/5] Silicon/Hisilicon/Acpi: Add update sas address feature

2020-06-09 Thread Ming Huang



在 2020/6/9 1:15, Leif Lindholm 写道:
> Hi Ming,
> 
> On Wed, May 27, 2020 at 22:33:56 +0800, Ming Huang wrote:
>> The updating sas address feature is similar with apdating mac address.
>> Modify updating dsdt flow for add this feature.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   1 +
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 297 
>> +++-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|   2 +-
>>  4 files changed, 232 insertions(+), 70 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index c45a0bb..9cdf710 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -46,7 +46,7 @@ UpdateAcpiDsdt (
>>  return;
>>}
>>
>> -  Status = EthMacInit ();
>> +  Status = UpdateAcpiDsdtTable ();
>>if (EFI_ERROR (Status)) {
>>  DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
>> Status));
>>}
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> index 866ff75..856309a 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> @@ -46,6 +46,7 @@
>>gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
>>gEfiAcpiSdtProtocolGuid   # PROTOCOL ALWAYS_CONSUMED
>>gHisiBoardNicProtocolGuid   # PROTOCOL 
>> ALWAYS_CONSUMED
>> +  gHisiSasConfigProtocolGuid
>>
>>  [FeaturePcd]
>>gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> index cd98506..6afdddf 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> @@ -1,7 +1,7 @@
>>  /** @file
>>
>>Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
>> reserved.
>> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>>Copyright (c) 2015, Linaro Limited. All rights reserved.
>>SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>> @@ -23,6 +23,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -32,6 +33,7 @@
>>  #include 
>>
>>  #include 
>> +#include 
>>
>>  // Turn on debug message by enabling below define
>>  //#define ACPI_DEBUG
>> @@ -45,17 +47,27 @@
>>  #define EFI_ACPI_MAX_NUM_TABLES 20
>>  #define DSDT_SIGNATURE  0x54445344
>>
>> -#define D03_ACPI_ETH_ID "HISI00C2"
>> -
>>  #define ACPI_ETH_MAC_KEY"local-mac-address"
>> +#define ACPI_ETH_SAS_KEY"sas-addr"
>>
>>  #define PREFIX_VARIABLE_NAMEL"MAC"
>>  #define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
>> -#define MAC_MAX_LEN 30
>> +#define ADDRESS_MAX_LEN 30
>> +
>> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>>
>> -EFI_STATUS GetEnvMac(
>> -  IN  UINTNMacNextID,
>> -  IN OUT  UINT8*MacBuffer)
>> +typedef enum {
>> +  DsdtDeviceUnknown,
>> +  DsdtDeviceLan,
>> +  DsdtDeviceSas
>> +} DSDT_DEVICE_TYPE;
>> +
>> +STATIC
>> +EFI_STATUS
>> +GetEnvMac(
>> +  IN UINTNMacNextID,
>> +  IN OUT UINT8*MacBuffer
>> +  )
>>  {
>>EFI_MAC_ADDRESS Mac;
>>EFI_STATUS Status;
>> @@ -89,12 +101,126 @@ EFI_STATUS GetEnvMac(
>>return EFI_SUCCESS;
>>  }
>>
>> -EFI_STATUS _SearchReplacePackageMACAddress(
>> +STATIC
>> +EFI_STATUS
>> +GetSasAddress (
>> +  IN UINT8Index,
>> +  IN OUT UINT8*SasAddrBuffer
>> +  )
>> +{
>> +  EFI_STATUS Status;
>> +  HISI_SAS_CONFIG_PROTOCOL *HisiSasConf;
>>

[edk2-devel] [PATCH edk2-platforms v1 2/2] Silicon/Hisilicon/Smbios: Optimize type 9

2020-06-08 Thread Ming Huang
Break down AddSmbiosType9Entry to three funtions for optimizing
Smbios type 9.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 173 
+++-
 1 file changed, 95 insertions(+), 78 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c 
b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
index 2398c6b..57e049a 100644
--- a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
+++ b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
@@ -75,38 +75,16 @@ UpdateSmbiosType9Info (
   return;
 }
 
-EFI_STATUS
-EFIAPI
-AddSmbiosType9Entry (
-  IN EFI_HANDLEImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+STATIC
+VOID
+EmptySmbiosType9 (
+  EFI_SMBIOS_PROTOCOL *Smbios
   )
 {
   EFI_STATUS  Status;
   EFI_SMBIOS_TYPE SmbiosType;
   EFI_SMBIOS_HANDLE   SmbiosHandle;
-  EFI_SMBIOS_PROTOCOL *Smbios;
   EFI_SMBIOS_TABLE_HEADER *Record;
-  SMBIOS_TABLE_TYPE9  *Type9Record;
-  SMBIOS_TABLE_TYPE9  *SmbiosRecord = NULL;
-  CHAR8   *OptionalStrStart;
-
-  UINT8   SmbiosAddType9Number;
-  UINT8   Index;
-
-  CHAR16  *SlotDesignation = NULL;
-  UINTN   SlotDesignationStrLen;
-
-  Status = gBS->LocateProtocol (
-  ,
-  NULL,
-  (VOID **) 
-  );
-  if (EFI_ERROR (Status)) {
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] LocateProtocol Failed. Status : %r\n",
-__FUNCTION__, __LINE__, Status));
-  return Status;
-  }
 
   do {
 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
@@ -122,76 +100,115 @@ AddSmbiosType9Entry (
 }
   } while (SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED);
 
-  SmbiosAddType9Number = OemGetPcieSlotNumber ();
+  return;
+}
 
-  for (Index = 0; Index < SmbiosAddType9Number; Index++) {
-if (gPcieSlotInfo[Index].Hdr.Type != EFI_SMBIOS_TYPE_SYSTEM_SLOTS) {
-  continue;
-}
+STATIC
+EFI_STATUS
+AddSmbiosType9Record (
+  EFI_SMBIOS_PROTOCOL *Smbios,
+  SMBIOS_TABLE_TYPE9  *Type9Record
+  )
+{
+  EFI_STATUS  Status;
+  EFI_SMBIOS_HANDLE   SmbiosHandle;
+  SMBIOS_TABLE_TYPE9  *SmbiosRecord;
+  CHAR8   *OptionalStrStart;
+  CHAR16  
SlotDesignation[SMBIOS_STRING_MAX_LENGTH];
+  UINTN   SlotStrLen;
+
+  SlotStrLen = UnicodeSPrint (
+ SlotDesignation,
+ SMBIOS_STRING_MAX_LENGTH * 2,
+ L"PCIE Slot%d",
+ Type9Record->SlotID);
+
+  //
+  // Two zeros following the last string.
+  //
+  SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE9) + SlotStrLen + 
1 + 1);
+  if (SmbiosRecord == NULL) {
+DEBUG ((DEBUG_ERROR, "AllocateZeroPool Failed for SmbiosRecord.\n"));
+return EFI_OUT_OF_RESOURCES;
+  }
 
-Type9Record = [Index];
+  (VOID)CopyMem (SmbiosRecord, Type9Record, sizeof (SMBIOS_TABLE_TYPE9));
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9);
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
+  (VOID)UnicodeStrToAsciiStr (SlotDesignation, OptionalStrStart);
 
-UpdateSmbiosType9Info (Type9Record);
-SlotDesignation = AllocateZeroPool ((sizeof (CHAR16)) * 
SMBIOS_STRING_MAX_LENGTH);
-if (SlotDesignation == NULL) {
-  Status = EFI_OUT_OF_RESOURCES;
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] AllocateZeroPool Failed. Status : %r\n",
-__FUNCTION__, __LINE__, Status));
+  //
+  // Now we have got the full smbios record, call smbios protocol to add this 
record.
+  //
+  SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
+  Status = Smbios->Add (Smbios, NULL, , (EFI_SMBIOS_TABLE_HEADER 
*)SmbiosRecord);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Add Smbios Type09 Failed! %r\n", Status));
+  }
 
-  goto Exit;
-}
+  FreePool (SmbiosRecord);
+  return Status;
+}
 
-SlotDesignationStrLen = UnicodeSPrint (
-  SlotDesignation,
-  SMBIOS_STRING_MAX_LENGTH - 1,
-  L"PCIE Slot%d",
-  Type9Record->SlotID);
-
-//
-// Two zeros following the last string.
-//
-SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE9) + 
SlotDesignationStrLen + 1 + 1);
-if (SmbiosRecord == NULL) {
-  Status = EFI_OUT_OF_RESOURCES;
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] AllocateZeroPool Failed. Status : %r\n",
-__FUNCTION__, __LINE__, Status));
+STATIC
+VOID
+HandleSmbiosType9 (
+  EFI_SMBIOS_PROTOCOL 

[edk2-devel] [PATCH edk2-platforms v1 0/2] Optimize type 9

2020-06-08 Thread Ming Huang
Break down AddSmbiosType9Entry to three funtions for optimizing
Smbios type 9.


Ming Huang (2):
  Silicon/Hisilicon/Smbios: correct coding style issue in type 9
  Silicon/Hisilicon/Smbios: Optimize type 9

 Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 325 
+++-
 1 file changed, 174 insertions(+), 151 deletions(-)

-- 
2.8.1


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

View/Reply Online (#60878): https://edk2.groups.io/g/devel/message/60878
Mute This Topic: https://groups.io/mt/74755014/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2-platforms v1 1/2] Silicon/Hisilicon/Smbios: correct coding style issue in type 9

2020-06-08 Thread Ming Huang
This patch is prepare for optimizing Smbios type 9.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 286 
++--
 1 file changed, 146 insertions(+), 140 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c 
b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
index 87a06a2..2398c6b 100644
--- a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
+++ b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c
@@ -1,6 +1,6 @@
 /** @file
 *
-*  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+*  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
 *  Copyright (c) 2015, Linaro Limited. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -14,178 +14,184 @@ extern UINT8 OemGetPcieSlotNumber ();
 
 VOID
 EFIAPI
-UpdateSmbiosType9Info(
+UpdateSmbiosType9Info (
   IN OUT SMBIOS_TABLE_TYPE9 *Type9Record
 )
 {
-EFI_STATUS Status;
-UINTN  HandleIndex;
-EFI_HANDLE*HandleBuffer;
-UINTN  HandleCount;
-EFI_PCI_IO_PROTOCOL   *PciIo;
-UINTN  SegmentNumber;
-UINTN  BusNumber;
-UINTN  DeviceNumber;
-UINTN  FunctionNumber;
-UINTN  Index;
-REPORT_PCIEDIDVID2BMC  ReportPcieDidVid[PCIEDEVICE_REPORT_MAX];
-
-GetPciDidVid ((VOID *) ReportPcieDidVid);
-
-Status = gBS->LocateHandleBuffer (
-  ByProtocol,
-  ,
-  NULL,
-  ,
-  
-  );
-if(EFI_ERROR(Status)) {
-DEBUG((EFI_D_ERROR, " Locate gEfiPciIoProtocol Failed.\n"));
-gBS->FreePool ((VOID *)HandleBuffer);
-return;
+  EFI_STATUS Status;
+  UINTN  HandleIndex;
+  EFI_HANDLE*HandleBuffer;
+  UINTN  HandleCount;
+  EFI_PCI_IO_PROTOCOL   *PciIo;
+  UINTN  SegmentNumber;
+  UINTN  BusNumber;
+  UINTN  DeviceNumber;
+  UINTN  FunctionNumber;
+  UINTN  Index;
+  REPORT_PCIEDIDVID2BMC  ReportPcieDidVid[PCIEDEVICE_REPORT_MAX];
+
+  GetPciDidVid ((VOID *)ReportPcieDidVid);
+
+  Status = gBS->LocateHandleBuffer (
+  ByProtocol,
+  ,
+  NULL,
+  ,
+  
+  );
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " Locate gEfiPciIoProtocol Failed.\n"));
+gBS->FreePool ((VOID *)HandleBuffer);
+return;
+  }
+
+  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
+Status = gBS->HandleProtocol (
+HandleBuffer[HandleIndex],
+,
+(VOID **)
+);
+if (EFI_ERROR (Status)) {
+  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Status : %r\n", __FUNCTION__, __LINE__, 
Status));
+  continue;
 }
-for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
-Status = gBS->HandleProtocol (
-HandleBuffer[HandleIndex],
-,
-(VOID **)
-);
-if (EFI_ERROR (Status)) {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] Status : %r\n", __FUNCTION__, 
__LINE__, Status));
-continue;
-}
-(VOID)PciIo->GetLocation(PciIo, , , 
, );
-for(Index = 0; Index < sizeof(ReportPcieDidVid) / 
sizeof(REPORT_PCIEDIDVID2BMC); Index++){
-if (Type9Record->SlotID == ReportPcieDidVid[Index].Slot + 1) {
-if((BusNumber == ReportPcieDidVid[Index].Bus) && (DeviceNumber 
== ReportPcieDidVid[Index].Device)) {
-DEBUG((EFI_D_ERROR,"PCIe device plot in slot Seg %d  bdf 
%d %d %d\r\n",SegmentNumber,BusNumber,DeviceNumber,FunctionNumber));
-Type9Record->SegmentGroupNum   = SegmentNumber;
-Type9Record->BusNum= BusNumber;
-Type9Record->DevFuncNum= (DeviceNumber << 3) | 
FunctionNumber;
-Type9Record->CurrentUsage  = SlotUsageInUse;
-break;
-}
-}
+(VOID)PciIo->GetLocation (PciIo, , , 
, );
+for (Index = 0; Index < sizeo

[edk2-devel] [PATCH edk2 v2 0/5] Improve D0x

2020-05-27 Thread Ming Huang
Main changes since v1:
1 Add HISI_SAS_CONFIG_PROTOCOL;
2 Declare missing GUID dependency;
3 Other modifications as comments.

Ming Huang (5):
  Silicon/Hisilicon: Change updating dsdt in ready to boot event
  Silicon/Hisilicon: Add HISI_SAS_CONFIG_PROTOCOL
  Silicon/Hisilicon/Acpi: Add update sas address feature
  Silicon/Hisilicon: Rename EthMac files
  Silicon/Hisilicon/FlashFvbDxe: Declare missing GUID dependency

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |  58 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   7 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 500 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 661 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
 Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf |   1 +
 Silicon/Hisilicon/HisiPkg.dec |   1 +
 Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h|  43 ++
 9 files changed, 781 insertions(+), 522 deletions(-)
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
 create mode 100644 Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h

-- 
2.8.1


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

View/Reply Online (#60355): https://edk2.groups.io/g/devel/message/60355
Mute This Topic: https://groups.io/mt/74501289/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2 v2 3/5] Silicon/Hisilicon/Acpi: Add update sas address feature

2020-05-27 Thread Ming Huang
The updating sas address feature is similar with apdating mac address.
Modify updating dsdt flow for add this feature.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   1 +
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 297 
+++-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|   2 +-
 4 files changed, 232 insertions(+), 70 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index c45a0bb..9cdf710 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -46,7 +46,7 @@ UpdateAcpiDsdt (
 return;
   }
 
-  Status = EthMacInit ();
+  Status = UpdateAcpiDsdtTable ();
   if (EFI_ERROR (Status)) {
 DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
Status));
   }
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 866ff75..856309a 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -46,6 +46,7 @@
   gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
   gEfiAcpiSdtProtocolGuid   # PROTOCOL ALWAYS_CONSUMED
   gHisiBoardNicProtocolGuid   # PROTOCOL 
ALWAYS_CONSUMED
+  gHisiSasConfigProtocolGuid
 
 [FeaturePcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
index cd98506..6afdddf 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
   Copyright (c) 2015, Linaro Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -32,6 +33,7 @@
 #include 
 
 #include 
+#include 
 
 // Turn on debug message by enabling below define
 //#define ACPI_DEBUG
@@ -45,17 +47,27 @@
 #define EFI_ACPI_MAX_NUM_TABLES 20
 #define DSDT_SIGNATURE  0x54445344
 
-#define D03_ACPI_ETH_ID "HISI00C2"
-
 #define ACPI_ETH_MAC_KEY"local-mac-address"
+#define ACPI_ETH_SAS_KEY"sas-addr"
 
 #define PREFIX_VARIABLE_NAMEL"MAC"
 #define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
-#define MAC_MAX_LEN 30
+#define ADDRESS_MAX_LEN 30
+
+CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
 
-EFI_STATUS GetEnvMac(
-  IN  UINTNMacNextID,
-  IN OUT  UINT8*MacBuffer)
+typedef enum {
+  DsdtDeviceUnknown,
+  DsdtDeviceLan,
+  DsdtDeviceSas
+} DSDT_DEVICE_TYPE;
+
+STATIC
+EFI_STATUS
+GetEnvMac(
+  IN UINTNMacNextID,
+  IN OUT UINT8*MacBuffer
+  )
 {
   EFI_MAC_ADDRESS Mac;
   EFI_STATUS Status;
@@ -89,12 +101,126 @@ EFI_STATUS GetEnvMac(
   return EFI_SUCCESS;
 }
 
-EFI_STATUS _SearchReplacePackageMACAddress(
+STATIC
+EFI_STATUS
+GetSasAddress (
+  IN UINT8Index,
+  IN OUT UINT8*SasAddrBuffer
+  )
+{
+  EFI_STATUS Status;
+  HISI_SAS_CONFIG_PROTOCOL *HisiSasConf;
+
+  if (SasAddrBuffer == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  Status = gBS->LocateProtocol (, NULL, (VOID 
**));
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Locate Sas Config Protocol failed %r\n", Status));
+SasAddrBuffer[0] = 0x50;
+SasAddrBuffer[1] = 0x01;
+SasAddrBuffer[2] = 0x88;
+SasAddrBuffer[3] = 0x20;
+SasAddrBuffer[4] = 0x16;
+SasAddrBuffer[5] = 0x00;
+SasAddrBuffer[6] = 0x00;
+SasAddrBuffer[7] = Index;
+return Status;
+  }
+
+  return HisiSasConf->GetAddr (Index, SasAddrBuffer);
+}
+
+STATIC
+EFI_STATUS
+UpdateAddressInOption (
+  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
+  IN EFI_ACPI_HANDLEChildHandle,
+  IN UINTN  DevNextID,
+  IN DSDT_DEVICE_TYPE   FoundDev
+  )
+{
+  EFI_STATUS  Status;
+  EFI_ACPI_DATA_TYPE  DataType;
+  CONST UINT8 *Data;
+  CONST VOID  *Buffer;
+  UINTN   DataSize;
+  UINTN   Count;
+  EFI_ACPI_HANDLE CurrentHandle;
+  UINT8   *AddressBuffer;
+  UINT8   AddressByte;
+
+  AddressByte = 0;
+  AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
+  if (AddressBuffer 

Re: [edk2-devel] [RFC edk2-platforms v1 0/3] Improve D0x

2020-05-27 Thread Ming Huang



在 2020/5/27 2:09, Leif Lindholm 写道:
> On trying to build the resulting output, I found the build breaks with
> /work/git/edk2-platforms/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.c:
> In function ‘FlashFvbInitialize’:
> /work/git/edk2-platforms/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.c:1231:20:
> error: ‘gEfiEventVirtualAddressChangeGuid’ undeclared (first use in
> this function); did you mean ‘EfiSetVirtualAddressMap’?
>,
>  ^
>  
> EfiSetVirtualAddressMap
> 
> The error would appear identical to that resolved by
> commit a327627dd3f9edc113b1de6d897222d0517834db
> 
> Could you please provide a corresponding fix?

Ok, I will add a patch in v2.

Thanks,
Ming

> 
> Best Regards,
> 
> Leif
> 
> On Thu, May 21, 2020 at 22:43:01 +0800, Ming Huang wrote:
>> Main Changes:
>> Add update sas address feature in AcpiPlatformDxe.
>>
>> Ming Huang (3):
>>   Silicon/Hisilicon: Change updating dsdt in ready to boot event
>>   Silicon/Hisilicon/Acpi: Add update sas address feature
>>   Silicon/Hisilicon: Rename EthMac files
>>
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |  62 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 500 
>> 
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 612 
>> 
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
>>  6 files changed, 689 insertions(+), 525 deletions(-)
>>  delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>>  delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>>  create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
>>  create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
>>
>> -- 
>> 2.8.1
>>
> 
> .
> 


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

View/Reply Online (#60346): https://edk2.groups.io/g/devel/message/60346
Mute This Topic: https://groups.io/mt/74377142/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event

2020-05-27 Thread Ming Huang



在 2020/5/27 1:40, Leif Lindholm 写道:
> Please call your patches PATCH. RFC is when a potential solution
> is put up for discussion, not for changing platform code.

Modify it in v2.

> 
> On Thu, May 21, 2020 at 22:43:02 +0800, Ming Huang wrote:
>> The better time for updating dsdt is in ready to boot event,
>> so change the updating time.
> 
> The commit message should explain *why* it is better.

Modify it in v2.

> 
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c | 60 
>> ++--
>>  1 file changed, 56 insertions(+), 4 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index b888cb1..1ab55bc 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -1,8 +1,8 @@
>>  /** @file
>>
>> -  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
>> reserved.
>> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> -  Copyright (c) 2015, Linaro Limited. All rights reserved.
>> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights 
>> reserved.
>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
> 
> Only the Hisilicon copyright should be updated (or a Huawei one added,
> given that this is the address used for submitting).

Ok, just modify Hisilicon copyright in v2.

Thanks,
Ming

> 
> /
> Leif
> 
>>SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>>  **/
>> @@ -23,6 +23,38 @@
>>  #include 
>>  #include "EthMac.h"
>>
>> +EFI_EVENT   mUpdateAcpiDsdtTableEvent;
>> +
>> +VOID
>> +EFIAPI
>> +UpdateAcpiDsdt (
>> +  IN EFI_EVENT Event,
>> +  IN VOID  *Context
>> +  )
>> +{
>> +  EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
>> +  EFI_STATUS  Status;
>> +
>> +  Status = gBS->LocateProtocol (
>> +  ,
>> +  NULL,
>> +  (VOID**)
>> +  );
>> +
>> +  if (EFI_ERROR (Status)) {
>> +DEBUG ((DEBUG_ERROR, " Unable to locate ACPI table protocol\n"));
>> +return;
>> +  }
>> +
>> +  Status = EthMacInit ();
>> +  if (EFI_ERROR (Status)) {
>> +DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
>> Status));
>> +  }
>> +
>> +  gBS->CloseEvent (Event);
>> +  return;
>> +}
>> +
>>  EFI_STATUS
>>  EFIAPI
>>  AcpiPlatformEntryPoint (
>> @@ -30,5 +62,25 @@ AcpiPlatformEntryPoint (
>>IN EFI_SYSTEM_TABLE   *SystemTable
>>)
>>  {
>> -  return EthMacInit();
>> +  EFI_STATUS Status;
>> +
>> +  //
>> +  // Register notify function
>> +  //
>> +  Status = gBS->CreateEventEx (
>> +  EVT_NOTIFY_SIGNAL,
>> +  TPL_CALLBACK,
>> +  UpdateAcpiDsdt,
>> +  NULL,
>> +  ,
>> +  
>> +  );
>> +
>> +  if (EFI_ERROR (Status)) {
>> +DEBUG ((DEBUG_ERROR, "Create ReadyToBoot event for UpdateAcpiDsdt 
>> failed.\n"));
>> +  } else {
>> +DEBUG ((DEBUG_INFO, "Create ReadyToBoot event for UpdateAcpiDsdt 
>> success.\n"));
>> +  }
>> +
>> +  return Status;
>>  }
>> -- 
>> 2.8.1
>>
> 
> .
> 


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

View/Reply Online (#60352): https://edk2.groups.io/g/devel/message/60352
Mute This Topic: https://groups.io/mt/74377144/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature

2020-05-27 Thread Ming Huang



在 2020/5/27 2:49, Leif Lindholm 写道:
> On Thu, May 21, 2020 at 22:43:03 +0800, Ming Huang wrote:
>> The updating sas address feature is similar with apdating mac address.
>> Modify updating dsdt flow for add this feature.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c |   2 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c   | 200 
>> +++-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h   |   2 +-
>>  3 files changed, 158 insertions(+), 46 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index 1ab55bc..d3ea051 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -46,7 +46,7 @@ UpdateAcpiDsdt (
>>  return;
>>}
>>
>> -  Status = EthMacInit ();
>> +  Status = UpdateAcpiDsdtTable ();
>>if (EFI_ERROR (Status)) {
>>  DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
>> Status));
>>}
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> index cd98506..205f2f9 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> @@ -1,8 +1,8 @@
>>  /** @file
>>
>> -  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
>> reserved.
>> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> -  Copyright (c) 2015, Linaro Limited. All rights reserved.
>> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights 
>> reserved.
>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
> 
> Same comment as for 1/3.

Modify it in v2.

> 
>>SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>>This driver is called to initialize the FW part of the PHY in preparation
>> @@ -30,6 +30,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
> 
> Good lord this include block is a mess.
> Nevertheless, a less offensive place to insert this new header would
> be between
> #include 
> and
> #include 
> .

Ok, modify it in v2.

> 
>>
>>  #include 
>>
>> @@ -45,13 +46,20 @@
>>  #define EFI_ACPI_MAX_NUM_TABLES 20
>>  #define DSDT_SIGNATURE  0x54445344
>>
>> -#define D03_ACPI_ETH_ID "HISI00C2"
>> -
>>  #define ACPI_ETH_MAC_KEY"local-mac-address"
>> +#define ACPI_ETH_SAS_KEY "sas-addr"
> 
> Please consider column alignment.
> 
>>
>>  #define PREFIX_VARIABLE_NAMEL"MAC"
>>  #define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
>> -#define MAC_MAX_LEN 30
>> +#define ADDRESS_MAX_LEN 30
> 
> Please consider column alignment.

Ok, modify it in v2.

> 
>>
>> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>> +
>> +typedef enum {
>> +  DsdtDeviceUnknown,
>> +  DsdtDeviceLan,
>> +  DsdtDeviceSas
>> +} DSDT_DEVICE_TYPE;
>>
>>  EFI_STATUS GetEnvMac(
>>IN  UINTNMacNextID,
>> @@ -89,12 +97,35 @@ EFI_STATUS GetEnvMac(
>>return EFI_SUCCESS;
>>  }
>>
>> -EFI_STATUS _SearchReplacePackageMACAddress(
>> +EFI_STATUS GetSasAddress (
> 
> Function name should be on separate line.
> If only used in this module, function should also be STATIC.

Ok, modify it in v2.

> 
>> +  IN UINT8Index,
>> +  IN OUT UINT8*SasAddrBuffer
>> +  )
>> +{
>> +  if (SasAddrBuffer == NULL) {
>> +  return EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  SasAddrBuffer[0] = 0x50;
>> +  SasAddrBuffer[1] = 0x01;
>> +  SasAddrBuffer[2] = 0x88;
>> +  SasAddrBuffer[3] = 0x20;
>> +  SasAddrBuffer[4] = 0x16;
>> +  SasAddrBuffer[5] = 0x00;
>> +  SasAddrBuffer[6] = 0x00;
>> +  SasAddrBuffer[7] = Index;
> 
> What does the above do?
> What are the hardcoded values?

In v2, add a protocol interface to get sas address and this SasAddrBuffer 
assignment
will only in error branch.

> 
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +EFI_STATUS _SearchReplacePac

[edk2-devel] [PATCH edk2 v2 5/5] Silicon/Hisilicon/FlashFvbDxe: Declare missing GUID dependency

2020-05-27 Thread Ming Huang
FlashFvbDxe depends on gEfiEventVirtualAddressChangeGuid, but got
away with not declaring it in its INF because of a transitive
dependency. However, this dependency got dropped in core EDK2,
resulting in build failures of the D0x platform.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf 
b/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf
index 23591b8..1119361 100644
--- a/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf
+++ b/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.inf
@@ -38,6 +38,7 @@
   UefiRuntimeLib
 
 [Guids]
+  gEfiEventVirtualAddressChangeGuid
   gEfiSystemNvDataFvGuid
   gEfiVariableGuid
 
-- 
2.8.1


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

View/Reply Online (#60348): https://edk2.groups.io/g/devel/message/60348
Mute This Topic: https://groups.io/mt/74501285/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2 v2 1/5] Silicon/Hisilicon: Change updating dsdt in ready to boot event

2020-05-27 Thread Ming Huang
The dsdt need be updated before boot to OS, so change the updating
to ready to boot event and can remove the needless dependence.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  | 56 
+++-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |  4 +-
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index b888cb1..c45a0bb 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
   Copyright (c) 2015, Linaro Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -23,6 +23,38 @@
 #include 
 #include "EthMac.h"
 
+EFI_EVENT   mUpdateAcpiDsdtTableEvent;
+
+VOID
+EFIAPI
+UpdateAcpiDsdt (
+  IN EFI_EVENT Event,
+  IN VOID  *Context
+  )
+{
+  EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
+  EFI_STATUS  Status;
+
+  Status = gBS->LocateProtocol (
+  ,
+  NULL,
+  (VOID**)
+  );
+
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " Unable to locate ACPI table protocol\n"));
+return;
+  }
+
+  Status = EthMacInit ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
Status));
+  }
+
+  gBS->CloseEvent (Event);
+  return;
+}
+
 EFI_STATUS
 EFIAPI
 AcpiPlatformEntryPoint (
@@ -30,5 +62,25 @@ AcpiPlatformEntryPoint (
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
-  return EthMacInit();
+  EFI_STATUS Status;
+
+  //
+  // Register notify function
+  //
+  Status = gBS->CreateEventEx (
+  EVT_NOTIFY_SIGNAL,
+  TPL_CALLBACK,
+  UpdateAcpiDsdt,
+  NULL,
+  ,
+  
+  );
+
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Create ReadyToBoot event for UpdateAcpiDsdt 
failed.\n"));
+  } else {
+DEBUG ((DEBUG_INFO, "Create ReadyToBoot event for UpdateAcpiDsdt 
success.\n"));
+  }
+
+  return Status;
 }
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 53da731..866ff75 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -1,7 +1,7 @@
 ## @file
 #
 #  Copyright (c) 2014, Applied Micro Curcuit Corp. All rights reserved.
-#  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+#  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
 #  Copyright (c) 2015, Linaro Limited. All rights reserved.
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -62,5 +62,5 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision
 
 [Depex]
-  gEfiAcpiTableProtocolGuid AND gEfiAcpiSdtProtocolGuid AND 
gHisiBoardNicProtocolGuid AND gHisiInstalledAcpiProtocolGuid
+  TRUE
 
-- 
2.8.1


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

View/Reply Online (#60350): https://edk2.groups.io/g/devel/message/60350
Mute This Topic: https://groups.io/mt/74501287/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [RFC edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-05-27 Thread Ming Huang
Hi Guomin,

This patch change the position of invoking the FindVariable() function to
after AutoUpdateLangVariable() invoked.

Thanks,
Ming

在 2020/5/27 8:12, Jiang, Guomin 写道:
> Hi Huangming,
> 
> I will clarify it when I am free, please be patient.
> 
> If it is urgent for you, I suggest that you can use your patch temporarily.
> 
> Any other thing, I check your patch in the mail, it seem that not any change 
> in code, can you double confirm it?
> 
> Best Regards
>> -Original Message-
>> From: Ming Huang 
>> Sent: Tuesday, May 26, 2020 2:08 PM
>> To: Jiang, Guomin ; devel@edk2.groups.io; Wang,
>> Jian J ; Wu, Hao A ; Gao,
>> Liming 
>> Cc: lidongz...@huawei.com; songdongku...@huawei.com;
>> wanghuiqi...@huawei.com; qiulian...@huawei.com;
>> shenli...@huawei.com
>> Subject: Re: [edk2-devel] [RFC edk2 v1 1/1] MdeModulePkg/Variable: Move
>> FindVariable after AutoUpdateLangVariable
>>
>>
>>
>> 在 2020/5/26 8:39, Jiang, Guomin 写道:
>>> Hi Huangming,
>>>
>>> I am taking the bugzilla and I am sorry that I haven't provide you with
>> productive comment.
>>>
>>> I am still busy until August.
>>>
>>> I just want to know that:
>>> 1. Have you verified that the symptom will disappear after invoked
>> FindVariable() function?
>>
>> Yes, the symptom will disappeare after add this patch.
>>
>>> 2. Is it your suggestion that the FindVariable() need to be invoked but you
>> have no idea that how to fix it?
>>
>> This patch can fix this issue, and I guess this issue was resulted by adding
>> AutoUpdateLangVariable feature.
>> I hope this patch can be merged to edk2 master.
>>
>> Thanks
>> Ming
>>
>>>
>>> Best Regards
>>> Guomin
>>>> -Original Message-
>>>> From: devel@edk2.groups.io  On Behalf Of Ming
>>>> Huang
>>>> Sent: Monday, May 25, 2020 7:34 PM
>>>> To: devel@edk2.groups.io; Wang, Jian J ; Wu,
>>>> Hao A ; Gao, Liming 
>>>> Cc: lidongz...@huawei.com; huangmin...@huawei.com;
>>>> songdongku...@huawei.com; wanghuiqi...@huawei.com;
>>>> qiulian...@huawei.com; shenli...@huawei.com
>>>> Subject: [edk2-devel] [RFC edk2 v1 1/1] MdeModulePkg/Variable: Move
>>>> FindVariable after AutoUpdateLangVariable
>>>>
>>>> When occur reclaim in AutoUpdateLangVariable(), the CurrPtr of
>>>> Variable is invalid. The State will be update with wrong position
>>>> after UpdateVariable in this situation and two valid PlatformLang or Lang
>> variables will exist.
>>>> BmForEachVariable() will enter endless loop while exist two valid
>>>> PlatformLang variables. So FindVariable() should be invoked atfer
>>>> AutoUpdateLangVariable().
>>>>
>>>> https://bugzilla.tianocore.org/show_bug.cgi?id=2667
>>>>
>>>> Signed-off-by: Ming Huang 
>>>> ---
>>>>  MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26
>>>> ++--
>>>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>>>
>>>> diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> index 1e71fc6..0cec981 100644
>>>> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>>> @@ -2741,6 +2741,19 @@ VariableServiceSetVariable (
>>>>  mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN)
>>>> NextVariable - (UINTN) Point;
>>>>}
>>>>
>>>> +  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
>>>> +//
>>>> +// Hook the operation of setting PlatformLangCodes/PlatformLang
>>>> + and
>>>> LangCodes/Lang.
>>>> +//
>>>> +Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
>>>> +if (EFI_ERROR (Status)) {
>>>> +  //
>>>> +  // The auto update operation failed, directly return to avoid
>>>> inconsistency between PlatformLang and Lang.
>>>> +  //
>>>> +  goto Done;
>>>> +}
>>>> +  }
>>>> +
>>>>//
>>>>// Check whether the input variable is already existed.
>>>>//
>>>> @@ -2763,19 +2776,6 @@ VariableServiceSetVariable (
>>>>  }
>>

[edk2-devel] [PATCH edk2 v2 4/5] Silicon/Hisilicon: Rename EthMac files

2020-05-27 Thread Ming Huang
As not only update mac address feature in EthMac files, so rename
them to UpdateDsdt.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 661 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 661 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
 6 files changed, 679 insertions(+), 679 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index 9cdf710..34a1dc9 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 #include 
-#include "EthMac.h"
+#include "UpdateDsdt.h"
 
 EFI_EVENT   mUpdateAcpiDsdtTableEvent;
 
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 856309a..efb7ff3 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -18,7 +18,7 @@
 
 [Sources]
   AcpiPlatform.c
-  EthMac.c
+  UpdateDsdt.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
deleted file mode 100644
index 6afdddf..000
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ /dev/null
@@ -1,661 +0,0 @@
-/** @file
-
-  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
-  Copyright (c) 2015, Linaro Limited. All rights reserved.
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-  This driver is called to initialize the FW part of the PHY in preparation
-  for the OS.
-
-**/
-
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-// Turn on debug message by enabling below define
-//#define ACPI_DEBUG
-
-#ifdef ACPI_DEBUG
-#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
-#else
-#define DBG(arg...)
-#endif
-
-#define EFI_ACPI_MAX_NUM_TABLES 20
-#define DSDT_SIGNATURE  0x54445344
-
-#define ACPI_ETH_MAC_KEY"local-mac-address"
-#define ACPI_ETH_SAS_KEY"sas-addr"
-
-#define PREFIX_VARIABLE_NAMEL"MAC"
-#define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
-#define ADDRESS_MAX_LEN 30
-
-CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
-
-typedef enum {
-  DsdtDeviceUnknown,
-  DsdtDeviceLan,
-  DsdtDeviceSas
-} DSDT_DEVICE_TYPE;
-
-STATIC
-EFI_STATUS
-GetEnvMac(
-  IN UINTNMacNextID,
-  IN OUT UINT8*MacBuffer
-  )
-{
-  EFI_MAC_ADDRESS Mac;
-  EFI_STATUS Status;
-  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
-
-  Status = gBS->LocateProtocol(, NULL, (VOID 
**));
-  if(EFI_ERROR(Status))
-  {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, 
__LINE__, Status));
-return Status;
-  }
-
-  Status = OemNic->GetMac(, MacNextID);
-  if(EFI_ERROR(Status))
-  {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, 
__LINE__, Status));
-return Status;
-  }
-
-  CopyMem (MacBuffer, , 6);
-  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
-MacNextID,
-MacBuffer[0],
-MacBuffer[1],
-MacBuffer[2],
-MacBuffer[3],
-MacBuffer[4],
-MacBuffer[5]
-));
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-EFI_STATUS
-GetSasAddress (
-  IN UINT8Index,
-  IN OUT UINT8*SasAddrBuffer
-  )
-{
-  EFI_STATUS Status;
-  HISI_SAS_CONFIG_PROTOCOL *HisiSasConf;
-
-  if (SasAddrBuffer == NULL) {
-return EFI_INVALID_PARAMETER;
-  }
-
-  Status = gBS->LocateProtocol (, NULL, (VOID 
**));
-  if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_ERROR, "Locate Sas Config Protocol failed %r\n", Status));
-SasAddrBuffer[0] = 0x50;
-SasAddrBuffer[1] = 0x01;
-SasAddrBuffer[2] = 0x88;
-SasAddrBuffer[3] = 0x20;
-SasAddrBuffer[4] = 0x16;
-SasAddrBuffer[5] = 0x00;
-SasAddrBuffer[6] = 0x00;
-SasAddrBuffer[7] = Index;
-return Status;
-  }
-
-  return HisiSasConf->GetAddr (Index, SasAddrBuffer);
-}
-
-STATIC
-EFI_STATUS
-UpdateAddressInOption (
-  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
-  IN EFI_ACPI_HANDLEChildHandle,
-  IN UINTN   

[edk2-devel] [PATCH edk2 v2 2/5] Silicon/Hisilicon: Add HISI_SAS_CONFIG_PROTOCOL

2020-05-27 Thread Ming Huang
Add HISI_SAS_CONFIG_PROTOCOL, provide get sas address interface,
this is prepare for adding update sas address feature.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/HisiPkg.dec  |  1 +
 Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h | 43 
 2 files changed, 44 insertions(+)

diff --git a/Silicon/Hisilicon/HisiPkg.dec b/Silicon/Hisilicon/HisiPkg.dec
index 63f50f7..051b5b8 100644
--- a/Silicon/Hisilicon/HisiPkg.dec
+++ b/Silicon/Hisilicon/HisiPkg.dec
@@ -34,6 +34,7 @@
   gHisiPlatformSasProtocolGuid = {0x20e9829f, 0x3a2c, 0x479a, {0x9a, 0x93, 
0x45, 0x7d, 0x13, 0x50, 0x96, 0x6d}}
   gHisiSnpPlatformProtocolGuid = {0x81321f27, 0xff58, 0x4a1d, {0x99, 0x97, 
0xd, 0xcc, 0xfa, 0x82, 0xf4, 0x6f}}
   gHisiInstalledAcpiProtocolGuid = {0x31505f6a, 0xe496, 0x4c7e, {0xba, 0xbb, 
0x71, 0x7b, 0xe2, 0xc4, 0xb4, 0x59}}
+  gHisiSasConfigProtocolGuid = {0x3A236669, 0x, 0x4d04, {0xb2, 0x83, 0x7, 
0x9f, 0x3c, 0xc4, 0x71, 0x66}}
 
 [Guids]
   gHisiTokenSpaceGuid = {0xc8bc553e, 0x12bf, 0x11e6, {0x97, 0x4f, 0x87, 0xf7, 
0x7c, 0xfd, 0x52, 0x1d}}
diff --git a/Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h 
b/Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h
new file mode 100644
index 000..6b850c8
--- /dev/null
+++ b/Silicon/Hisilicon/Include/Protocol/HisiSasConfig.h
@@ -0,0 +1,43 @@
+/** @file
+
+  Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef HISI_SAS_CONFIG_H_
+#define HISI_SAS_CONFIG_H_
+
+typedef struct{
+  UINT32 CtrlId;
+  BOOLEANEnable;
+  UINT32 Bar32;
+  UINT64 ResetBase;
+  UINTN  Segment;
+  UINTN  Bus;
+  UINTN  Device;
+  UINTN  Fun;
+} SAS_CONTROLLER_DATA;
+
+typedef
+VOID *
+(EFIAPI *HISI_SAS_GET_CONTROLLER_DATA) (
+  VOID
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI *HISI_SAS_GET_ADDRESS) (
+  IN UINT8 Index,
+  IN OUT UINT8 *SasAddrBuffer
+  );
+
+typedef struct {
+  HISI_SAS_GET_ADDRESS GetAddr;
+  HISI_SAS_GET_CONTROLLER_DATA GetControllerData;
+} HISI_SAS_CONFIG_PROTOCOL;
+
+extern EFI_GUID gHisiSasConfigProtocolGuid;
+
+#endif
-- 
2.8.1


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

View/Reply Online (#60351): https://edk2.groups.io/g/devel/message/60351
Mute This Topic: https://groups.io/mt/74501288/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files

2020-05-27 Thread Ming Huang



在 2020/5/27 2:50, Leif Lindholm 写道:
> On Thu, May 21, 2020 at 22:43:04 +0800, Ming Huang wrote:
>> As not only update mac address feature in EthMac files, so rename
>> them to UpdateDsdt.
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 612 
>> 
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 612 
>> 
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
>>  6 files changed, 633 insertions(+), 633 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index d3ea051..fd67677 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -21,7 +21,7 @@
>>  #include 
>>  #include 
>>  #include 
>> -#include "EthMac.h"
>> +#include "UpdateDsdt.h"
>>
>>  EFI_EVENT   mUpdateAcpiDsdtTableEvent;
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> index 53da731..a2b669d 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> @@ -1,8 +1,8 @@
>>  ## @file
>>  #
>> -#  Copyright (c) 2014, Applied Micro Curcuit Corp. All rights reserved.
>> -#  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> -#  Copyright (c) 2015, Linaro Limited. All rights reserved.
>> +#  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corp. All rights 
>> reserved.
>> +#  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>> +#  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
> 
> Same comment on copyright as on 1/3 and 2/3.

Modify it in v2.

Thanks,
Ming

> 
> /
> Leif
> 
>>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
>>  #
>>  ##
>> @@ -18,7 +18,7 @@
>>
>>  [Sources]
>>AcpiPlatform.c
>> -  EthMac.c
>> +  UpdateDsdt.c
>>
>>  [Packages]
>>MdePkg/MdePkg.dec
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
>> b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> deleted file mode 100644
>> index 205f2f9..000
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> +++ /dev/null
>> @@ -1,612 +0,0 @@
>> -/** @file
>> -
>> -  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights 
>> reserved.
>> -  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
>> -  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
>> -  SPDX-License-Identifier: BSD-2-Clause-Patent
>> -
>> -  This driver is called to initialize the FW part of the PHY in preparation
>> -  for the OS.
>> -
>> -**/
>> -
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -#include 
>> -
>> -#include 
>> -
>> -// Turn on debug message by enabling below define
>> -//#define ACPI_DEBUG
>> -
>> -#ifdef ACPI_DEBUG
>> -#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
>> -#else
>> -#define DBG(arg...)
>> -#endif
>> -
>> -#define EFI_ACPI_MAX_NUM_TABLES 20
>> -#define DSDT_SIGNATURE  0x54445344
>> -
>> -#define ACPI_ETH_MAC_KEY"local-mac-address"
>> -#define ACPI_ETH_SAS_KEY "sas-addr"
>> -
>> -#define PREFIX_VARIABLE_NAMEL"MAC"
>> -#define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
>> -#define ADDRESS_MAX_LEN 30
>> -
>> -CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>> -
>> -typedef enum {
>> -  DsdtDeviceUnknown,
>> -  DsdtDeviceLan,
>> -  DsdtDeviceSas
>> -

Re: [edk2-devel] [RFC edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-05-26 Thread Ming Huang



在 2020/5/26 8:39, Jiang, Guomin 写道:
> Hi Huangming,
> 
> I am taking the bugzilla and I am sorry that I haven't provide you with 
> productive comment.
> 
> I am still busy until August.
> 
> I just want to know that:
> 1. Have you verified that the symptom will disappear after invoked 
> FindVariable() function?

Yes, the symptom will disappeare after add this patch.

> 2. Is it your suggestion that the FindVariable() need to be invoked but you 
> have no idea that how to fix it?

This patch can fix this issue, and I guess this issue was resulted by adding 
AutoUpdateLangVariable feature.
I hope this patch can be merged to edk2 master.

Thanks
Ming

> 
> Best Regards
> Guomin
>> -Original Message-----
>> From: devel@edk2.groups.io  On Behalf Of Ming
>> Huang
>> Sent: Monday, May 25, 2020 7:34 PM
>> To: devel@edk2.groups.io; Wang, Jian J ; Wu, Hao A
>> ; Gao, Liming 
>> Cc: lidongz...@huawei.com; huangmin...@huawei.com;
>> songdongku...@huawei.com; wanghuiqi...@huawei.com;
>> qiulian...@huawei.com; shenli...@huawei.com
>> Subject: [edk2-devel] [RFC edk2 v1 1/1] MdeModulePkg/Variable: Move
>> FindVariable after AutoUpdateLangVariable
>>
>> When occur reclaim in AutoUpdateLangVariable(), the CurrPtr of Variable is
>> invalid. The State will be update with wrong position after UpdateVariable in
>> this situation and two valid PlatformLang or Lang variables will exist.
>> BmForEachVariable() will enter endless loop while exist two valid
>> PlatformLang variables. So FindVariable() should be invoked atfer
>> AutoUpdateLangVariable().
>>
>> https://bugzilla.tianocore.org/show_bug.cgi?id=2667
>>
>> Signed-off-by: Ming Huang 
>> ---
>>  MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26
>> ++--
>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>
>> diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> index 1e71fc6..0cec981 100644
>> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> @@ -2741,6 +2741,19 @@ VariableServiceSetVariable (
>>  mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN)
>> NextVariable - (UINTN) Point;
>>}
>>
>> +  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
>> +//
>> +// Hook the operation of setting PlatformLangCodes/PlatformLang and
>> LangCodes/Lang.
>> +//
>> +Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
>> +if (EFI_ERROR (Status)) {
>> +  //
>> +  // The auto update operation failed, directly return to avoid
>> inconsistency between PlatformLang and Lang.
>> +  //
>> +  goto Done;
>> +}
>> +  }
>> +
>>//
>>// Check whether the input variable is already existed.
>>//
>> @@ -2763,19 +2776,6 @@ VariableServiceSetVariable (
>>  }
>>}
>>
>> -  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
>> -//
>> -// Hook the operation of setting PlatformLangCodes/PlatformLang and
>> LangCodes/Lang.
>> -//
>> -Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
>> -if (EFI_ERROR (Status)) {
>> -  //
>> -  // The auto update operation failed, directly return to avoid 
>> inconsistency
>> between PlatformLang and Lang.
>> -  //
>> -  goto Done;
>> -}
>> -  }
>> -
>>if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
>>  Status = AuthVariableLibProcessVariable (VariableName, VendorGuid,
>> Data, DataSize, Attributes);
>>} else {
>> --
>> 2.8.1
>>
>>
>> 
> 
> 
> 


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

View/Reply Online (#60261): https://edk2.groups.io/g/devel/message/60261
Mute This Topic: https://groups.io/mt/74462883/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [RFC edk2 v1 0/1] Fix a infrequent issue in variable

2020-05-25 Thread Ming Huang
https://bugzilla.tianocore.org/show_bug.cgi?id=2667

Ming Huang (1):
  MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26 ++--
 1 file changed, 13 insertions(+), 13 deletions(-)

-- 
2.8.1


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

View/Reply Online (#60222): https://edk2.groups.io/g/devel/message/60222
Mute This Topic: https://groups.io/mt/74462884/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [RFC edk2 v1 1/1] MdeModulePkg/Variable: Move FindVariable after AutoUpdateLangVariable

2020-05-25 Thread Ming Huang
When occur reclaim in AutoUpdateLangVariable(), the CurrPtr of
Variable is invalid. The State will be update with wrong position
after UpdateVariable in this situation and two valid PlatformLang or
Lang variables will exist. BmForEachVariable() will enter endless loop
while exist two valid PlatformLang variables. So FindVariable() should
be invoked atfer AutoUpdateLangVariable().

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

Signed-off-by: Ming Huang 
---
 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 26 ++--
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c 
b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 1e71fc6..0cec981 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -2741,6 +2741,19 @@ VariableServiceSetVariable (
 mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) 
NextVariable - (UINTN) Point;
   }
 
+  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
+//
+// Hook the operation of setting PlatformLangCodes/PlatformLang and 
LangCodes/Lang.
+//
+Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
+if (EFI_ERROR (Status)) {
+  //
+  // The auto update operation failed, directly return to avoid 
inconsistency between PlatformLang and Lang.
+  //
+  goto Done;
+}
+  }
+
   //
   // Check whether the input variable is already existed.
   //
@@ -2763,19 +2776,6 @@ VariableServiceSetVariable (
 }
   }
 
-  if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
-//
-// Hook the operation of setting PlatformLangCodes/PlatformLang and 
LangCodes/Lang.
-//
-Status = AutoUpdateLangVariable (VariableName, Data, DataSize);
-if (EFI_ERROR (Status)) {
-  //
-  // The auto update operation failed, directly return to avoid 
inconsistency between PlatformLang and Lang.
-  //
-  goto Done;
-}
-  }
-
   if (mVariableModuleGlobal->VariableGlobal.AuthSupport) {
 Status = AuthVariableLibProcessVariable (VariableName, VendorGuid, Data, 
DataSize, Attributes);
   } else {
-- 
2.8.1


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

View/Reply Online (#60221): https://edk2.groups.io/g/devel/message/60221
Mute This Topic: https://groups.io/mt/74462883/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event

2020-05-21 Thread Ming Huang
The better time for updating dsdt is in ready to boot event,
so change the updating time.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c | 60 
++--
 1 file changed, 56 insertions(+), 4 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index b888cb1..1ab55bc 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -1,8 +1,8 @@
 /** @file
 
-  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
-  Copyright (c) 2015, Linaro Limited. All rights reserved.
+  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights 
reserved.
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
+  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -23,6 +23,38 @@
 #include 
 #include "EthMac.h"
 
+EFI_EVENT   mUpdateAcpiDsdtTableEvent;
+
+VOID
+EFIAPI
+UpdateAcpiDsdt (
+  IN EFI_EVENT Event,
+  IN VOID  *Context
+  )
+{
+  EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
+  EFI_STATUS  Status;
+
+  Status = gBS->LocateProtocol (
+  ,
+  NULL,
+  (VOID**)
+  );
+
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " Unable to locate ACPI table protocol\n"));
+return;
+  }
+
+  Status = EthMacInit ();
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
Status));
+  }
+
+  gBS->CloseEvent (Event);
+  return;
+}
+
 EFI_STATUS
 EFIAPI
 AcpiPlatformEntryPoint (
@@ -30,5 +62,25 @@ AcpiPlatformEntryPoint (
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
-  return EthMacInit();
+  EFI_STATUS Status;
+
+  //
+  // Register notify function
+  //
+  Status = gBS->CreateEventEx (
+  EVT_NOTIFY_SIGNAL,
+  TPL_CALLBACK,
+  UpdateAcpiDsdt,
+  NULL,
+  ,
+  
+  );
+
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "Create ReadyToBoot event for UpdateAcpiDsdt 
failed.\n"));
+  } else {
+DEBUG ((DEBUG_INFO, "Create ReadyToBoot event for UpdateAcpiDsdt 
success.\n"));
+  }
+
+  return Status;
 }
-- 
2.8.1


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

View/Reply Online (#60035): https://edk2.groups.io/g/devel/message/60035
Mute This Topic: https://groups.io/mt/74377144/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files

2020-05-21 Thread Ming Huang
As not only update mac address feature in EthMac files, so rename
them to UpdateDsdt.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 612 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 612 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
 6 files changed, 633 insertions(+), 633 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index d3ea051..fd67677 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 #include 
-#include "EthMac.h"
+#include "UpdateDsdt.h"
 
 EFI_EVENT   mUpdateAcpiDsdtTableEvent;
 
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 53da731..a2b669d 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -1,8 +1,8 @@
 ## @file
 #
-#  Copyright (c) 2014, Applied Micro Curcuit Corp. All rights reserved.
-#  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
-#  Copyright (c) 2015, Linaro Limited. All rights reserved.
+#  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corp. All rights 
reserved.
+#  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
+#  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -18,7 +18,7 @@
 
 [Sources]
   AcpiPlatform.c
-  EthMac.c
+  UpdateDsdt.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
deleted file mode 100644
index 205f2f9..000
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ /dev/null
@@ -1,612 +0,0 @@
-/** @file
-
-  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
-  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-  This driver is called to initialize the FW part of the PHY in preparation
-  for the OS.
-
-**/
-
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-
-// Turn on debug message by enabling below define
-//#define ACPI_DEBUG
-
-#ifdef ACPI_DEBUG
-#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
-#else
-#define DBG(arg...)
-#endif
-
-#define EFI_ACPI_MAX_NUM_TABLES 20
-#define DSDT_SIGNATURE  0x54445344
-
-#define ACPI_ETH_MAC_KEY"local-mac-address"
-#define ACPI_ETH_SAS_KEY "sas-addr"
-
-#define PREFIX_VARIABLE_NAMEL"MAC"
-#define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
-#define ADDRESS_MAX_LEN 30
-
-CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
-
-typedef enum {
-  DsdtDeviceUnknown,
-  DsdtDeviceLan,
-  DsdtDeviceSas
-} DSDT_DEVICE_TYPE;
-
-EFI_STATUS GetEnvMac(
-  IN  UINTNMacNextID,
-  IN OUT  UINT8*MacBuffer)
-{
-  EFI_MAC_ADDRESS Mac;
-  EFI_STATUS Status;
-  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
-
-  Status = gBS->LocateProtocol(, NULL, (VOID 
**));
-  if(EFI_ERROR(Status))
-  {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, 
__LINE__, Status));
-return Status;
-  }
-
-  Status = OemNic->GetMac(, MacNextID);
-  if(EFI_ERROR(Status))
-  {
-DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, 
__LINE__, Status));
-return Status;
-  }
-
-  CopyMem (MacBuffer, , 6);
-  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
-MacNextID,
-MacBuffer[0],
-MacBuffer[1],
-MacBuffer[2],
-MacBuffer[3],
-MacBuffer[4],
-MacBuffer[5]
-));
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS GetSasAddress (
-  IN UINT8Index,
-  IN OUT UINT8*SasAddrBuffer
-  )
-{
-  if (SasAddrBuffer == NULL) {
-  return EFI_INVALID_PARAMETER;
-  }
-
-  SasAddrBuffer[0] = 0x50;
-  SasAddrBuffer[1] = 0x01;
-  SasAddrBuffer[2] = 0x88;
-  SasAddrBuffer[3] = 0x20;
-  SasAddrBuffer[4] = 0x16;
-  SasAddrBuffer[5] = 0x00;
-  SasAddrBuffer[6] = 0x00;
-  SasAddrBuffer[7] = 

[edk2-devel] [RFC edk2-platforms v1 0/3] Improve D0x

2020-05-21 Thread Ming Huang
Main Changes:
Add update sas address feature in AcpiPlatformDxe.

Ming Huang (3):
  Silicon/Hisilicon: Change updating dsdt in ready to boot event
  Silicon/Hisilicon/Acpi: Add update sas address feature
  Silicon/Hisilicon: Rename EthMac files

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c  |  62 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c| 500 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h|  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c| 612 

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h|  16 +
 6 files changed, 689 insertions(+), 525 deletions(-)
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h

-- 
2.8.1


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

View/Reply Online (#60033): https://edk2.groups.io/g/devel/message/60033
Mute This Topic: https://groups.io/mt/74377142/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature

2020-05-21 Thread Ming Huang
The updating sas address feature is similar with apdating mac address.
Modify updating dsdt flow for add this feature.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c   | 200 
+++-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h   |   2 +-
 3 files changed, 158 insertions(+), 46 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index 1ab55bc..d3ea051 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -46,7 +46,7 @@ UpdateAcpiDsdt (
 return;
   }
 
-  Status = EthMacInit ();
+  Status = UpdateAcpiDsdtTable ();
   if (EFI_ERROR (Status)) {
 DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", 
Status));
   }
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c 
b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
index cd98506..205f2f9 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
@@ -1,8 +1,8 @@
 /** @file
 
-  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights 
reserved.
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.
-  Copyright (c) 2015, Linaro Limited. All rights reserved.
+  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights 
reserved.
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.
+  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   This driver is called to initialize the FW part of the PHY in preparation
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -45,13 +46,20 @@
 #define EFI_ACPI_MAX_NUM_TABLES 20
 #define DSDT_SIGNATURE  0x54445344
 
-#define D03_ACPI_ETH_ID "HISI00C2"
-
 #define ACPI_ETH_MAC_KEY"local-mac-address"
+#define ACPI_ETH_SAS_KEY "sas-addr"
 
 #define PREFIX_VARIABLE_NAMEL"MAC"
 #define PREFIX_VARIABLE_NAME_COMPAT L"RGMII_MAC"
-#define MAC_MAX_LEN 30
+#define ADDRESS_MAX_LEN 30
+
+CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
+
+typedef enum {
+  DsdtDeviceUnknown,
+  DsdtDeviceLan,
+  DsdtDeviceSas
+} DSDT_DEVICE_TYPE;
 
 EFI_STATUS GetEnvMac(
   IN  UINTNMacNextID,
@@ -89,12 +97,35 @@ EFI_STATUS GetEnvMac(
   return EFI_SUCCESS;
 }
 
-EFI_STATUS _SearchReplacePackageMACAddress(
+EFI_STATUS GetSasAddress (
+  IN UINT8Index,
+  IN OUT UINT8*SasAddrBuffer
+  )
+{
+  if (SasAddrBuffer == NULL) {
+  return EFI_INVALID_PARAMETER;
+  }
+
+  SasAddrBuffer[0] = 0x50;
+  SasAddrBuffer[1] = 0x01;
+  SasAddrBuffer[2] = 0x88;
+  SasAddrBuffer[3] = 0x20;
+  SasAddrBuffer[4] = 0x16;
+  SasAddrBuffer[5] = 0x00;
+  SasAddrBuffer[6] = 0x00;
+  SasAddrBuffer[7] = Index;
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS _SearchReplacePackageAddress(
   IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
   IN EFI_ACPI_HANDLEChildHandle,
   IN UINTN  Level,
   IN OUT BOOLEAN*Found,
-  IN UINTN  MacNextID)
+  IN UINTN  DevNextID,
+  IN DSDT_DEVICE_TYPE   FoundDev
+  )
 {
   // ASL template for ethernet driver:
 /*
@@ -117,12 +148,18 @@ EFI_STATUS _SearchReplacePackageMACAddress(
   UINTN   Count;
   EFI_ACPI_HANDLE CurrentHandle;
   EFI_ACPI_HANDLE NextHandle;
-  UINT8   MACBuffer[MAC_MAX_LEN];
+  EFI_ACPI_HANDLE Level1Handle;
+  UINT8   *AddressBuffer;
+  UINT8   AddressByte = 0;
 
   DBG("In Level:%d\n", Level);
+  Level1Handle = NULL;
   Status = EFI_SUCCESS;
   for (CurrentHandle = NULL; ;) {
 Status = AcpiTableProtocol->GetChild(ChildHandle, );
+if (Level == 1) {
+  Level1Handle = CurrentHandle;
+}
 if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
break;
 
@@ -143,11 +180,14 @@ EFI_STATUS _SearchReplacePackageMACAddress(
   DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
 
   Data = Buffer;
-  if (DataType != EFI_ACPI_DATA_TYPE_STRING
-  || AsciiStrCmp((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0)
+  if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
+((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
+(AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
+ChildHandle = Level1Handle;
 continue;
+  }
 
-  DBG("_DSD Key Type %d. Found MAC address key\n", DataType);
+  DBG("_DSD Key Type %d. Found address key\n", DataType);
 
   //
   // We fo

[edk2-devel] [RFC edk2-platforms v3 3/3] Silicon/Hisilicon: Add RX8900RealTimeClockLib

2020-05-19 Thread Ming Huang
There are some boards base on D06, but use RX8900 RTC,
so upstream the RX8900RealTimeClockLib.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h  |  
39 ++
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c   | 
468 
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.inf |  
33 ++
 3 files changed, 540 insertions(+)

diff --git 
a/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h 
b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h
new file mode 100644
index 000..ac2be7e
--- /dev/null
+++ b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h
@@ -0,0 +1,39 @@
+/** @file
+
+  Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RX8900_REAL_TIME_CLOCK_H__
+#define RX8900_REAL_TIME_CLOCK_H__
+
+#define RX8900_REGADDR_SECONDS 0x00
+#define RX8900_REGADDR_MIUTES  0x01
+#define RX8900_REGADDR_HOURS   0x02
+#define RX8900_REGADDR_DAY 0x03
+#define RX8900_REGADDR_DATE0x04
+#define RX8900_REGADDR_MONTH   0x05
+#define RX8900_REGADDR_YEAR0x06
+#define RX8900_REGADDR_RAM 0x07
+#define RX8900_REGADDR_ALARMMIN0x08
+#define RX8900_REGADDR_ALARMHOUR   0x09
+#define RX8900_REGADDR_ALARMDAY0x0A
+#define RX8900_REGADDR_ALARMWEEK   0x0A
+#define RX8900_REGADDR_TIMECOUNTER_0   0x0B
+#define RX8900_REGADDR_TIMECOUNTER_1   0x0C
+#define RX8900_REGADDR_EXTENSIONREG0x0D
+#define RX8900_REGADDR_FLAGREG 0x0E
+#define RX8900_REGADDR_CONTRLREG   0xF
+#define RX8900_REGADDR_BACKUP_FUN  0x18
+
+#define RX8900_VDETOFF_SWOFF   0x0C
+#define TEMPERATURE_COMPENSATION_2S0x40
+#define OUTPUT_FREQUENCY_32768 0x0C
+#define FLAG_REG_DEFAULT   0x00
+#define RX8900_RAM_REG_DEFAULT 0x5A
+
+#define EFI_TIMEOFFSET_TIMEZONE0x5A0
+
+#endif
diff --git 
a/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c 
b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
new file mode 100644
index 000..b6c9e67
--- /dev/null
+++ b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
@@ -0,0 +1,468 @@
+/** @file
+
+  Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "RX8900RealTimeClock.h"
+
+extern I2C_DEVICE gRtcDevice;
+
+STATIC BOOLEAN   mRX8900Initialized = FALSE;
+STATIC CONST CHAR16  mTimeZoneVariableName[] = L"RX8900RtcTimeZone";
+STATIC CONST CHAR16  mDaylightVariableName[] = L"RX8900RtcDaylight";
+
+EFI_STATUS
+InitializeRX8900 (
+  VOID
+  )
+{
+  EFI_STATUSStatus;
+  unsigned char writeTemp;
+
+  Status = SwitchRtcI2cChannelAndLock ();
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  Status = I2CInit (gRtcDevice.Socket, gRtcDevice.Port, Normal);
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  writeTemp = RX8900_VDETOFF_SWOFF;
+  Status = I2CWrite (, RX8900_REGADDR_BACKUP_FUN, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+  writeTemp = TEMPERATURE_COMPENSATION_2S;
+  Status = I2CWrite (, RX8900_REGADDR_CONTRLREG, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+  writeTemp = OUTPUT_FREQUENCY_32768;
+  Status = I2CWrite (, RX8900_REGADDR_EXTENSIONREG, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  writeTemp = FLAG_REG_DEFAULT;
+  Status = I2CWrite (, RX8900_REGADDR_FLAGREG, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+  writeTemp = RX8900_RAM_REG_DEFAULT;
+  Status = I2CWrite (, RX8900_REGADDR_RAM, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  mRX8900Initialized = TRUE;
+
+  EXIT:
+
+  ReleaseOwnershipOfRtc ();
+  return Status;
+}
+
+STATIC
+INT16
+GetTimeZone (
+  VOID
+  )
+{
+  EFI_STATUS  Status;
+  INT16   TimeZone;
+  UINTN   Size;
+
+  TimeZone = EFI_UNSPECIFIED_TIMEZONE;
+  Size = sizeof (TimeZone);
+  Status = EfiGetVariable (
+ (CHAR16 *)mTimeZoneVariableName,
+ ,
+ NULL,
+ ,
+ (VOID *)
+ );
+
+  if (EFI_ERROR (Status)) {
+TimeZone = EFI_UNSPECIFIED_TIMEZONE;
+// The time zone variable does not exist in non-volatile storage, so 
create it.
+Status = EfiSetVariable (
+   (CHAR16 *)mTimeZoneVariableName,
+   ,
+   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
+   Size,
+   (VOID *)
+   );
+
+if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "Failed to save %s variable, Status = %r\n",

[edk2-devel] [RFC edk2-platforms v3 0/3] Improve D0x

2020-05-19 Thread Ming Huang
Changes since v2:
1 Drop the Contributed-under tags.
2 revert the renaming.


Ming Huang (3):
  Silicon/Hisilicon: Fix a typo issue in M41T83RealTimeClockLib
  Hisilicon/Library: Move two functions to RtcHelperLib
  Silicon/Hisilicon: Add RX8900RealTimeClockLib

 Platform/Hisilicon/D06/D06.dsc  |  
 1 +
 Silicon/Hisilicon/Include/Library/RtcHelperLib.h|  
29 ++
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h  |  
 7 -
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c   |  
92 +---
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf |  
 1 +
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h  |  
39 ++
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c   | 
468 
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.inf |  
33 ++
 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c   |  
94 
 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf |  
32 ++
 10 files changed, 704 insertions(+), 92 deletions(-)
 create mode 100644 Silicon/Hisilicon/Include/Library/RtcHelperLib.h
 create mode 100644 
Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h
 create mode 100644 
Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
 create mode 100644 
Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.inf
 create mode 100644 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c
 create mode 100644 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf

-- 
2.8.1


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

View/Reply Online (#59826): https://edk2.groups.io/g/devel/message/59826
Mute This Topic: https://groups.io/mt/74326373/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [RFC edk2-platforms v3 2/3] Hisilicon/Library: Move two functions to RtcHelperLib

2020-05-19 Thread Ming Huang
The functions of acquiring ownership of RTC will be used for other
RTC library, so move them to RtcHelperLib. Rename them by add leading
Oem for uniform.

Signed-off-by: Ming Huang 
---
 Platform/Hisilicon/D06/D06.dsc  |  
1 +
 Silicon/Hisilicon/Include/Library/RtcHelperLib.h| 
29 ++
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h  |  
7 --
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c   | 
80 +
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf |  
1 +
 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c   | 
94 
 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf | 
32 +++
 7 files changed, 158 insertions(+), 86 deletions(-)

diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc
index 000a4ee..eb20224 100644
--- a/Platform/Hisilicon/D06/D06.dsc
+++ b/Platform/Hisilicon/D06/D06.dsc
@@ -54,6 +54,7 @@
   CpldIoLib|Silicon/Hisilicon/Library/CpldIoLib/CpldIoLib.inf
 
   TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf
+  RtcHelperLib|Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf
   
RealTimeClockLib|Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
   OemMiscLib|Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.inf
   
OemAddressMapLib|Platform/Hisilicon/D06/Library/OemAddressMapD06/OemAddressMapD06.inf
diff --git a/Silicon/Hisilicon/Include/Library/RtcHelperLib.h 
b/Silicon/Hisilicon/Include/Library/RtcHelperLib.h
new file mode 100644
index 000..39dbc96
--- /dev/null
+++ b/Silicon/Hisilicon/Include/Library/RtcHelperLib.h
@@ -0,0 +1,29 @@
+/** @file
+
+  Copyright (c) 2018, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RTC_HELPER_LIB_H__
+#define RTC_HELPER_LIB_H__
+
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_30_MS3
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_1000_MICROSECOND 1000
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_2_MICROSECOND2
+
+EFI_STATUS
+SwitchRtcI2cChannelAndLock (
+  VOID
+  );
+
+VOID
+ReleaseOwnershipOfRtc (
+  VOID
+  );
+
+#endif
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
index 81ff459..09329c4 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
@@ -10,13 +10,6 @@
 #ifndef __M41T83_REAL_TIME_CLOCK_H__
 #define __M41T83_REAL_TIME_CLOCK_H__
 
-// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_30_MS3
-// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_1000_MICROSECOND 1000
-// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_2_MICROSECOND2
-
 #define M41T83_REGADDR_DOTSECONDS   0x00
 #define M41T83_REGADDR_SECONDS  0x01
 #define M41T83_REGADDR_MINUTES  0x02
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
index f339bcc..5f94658 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
@@ -11,10 +11,9 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,70 +25,6 @@ extern I2C_DEVICE gRtcDevice;
 
 STATIC EFI_LOCK  mRtcLock;
 
-EFI_STATUS
-SwitchRtcI2cChannelAndLock (
-  VOID
-  )
-{
-  UINT8   Temp;
-  UINT8   Count;
-
-  for (Count = 0; Count < 100; Count++) {
-// To get the other side's state is idle first
-Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG);
-if ((Temp & BIT3) != 0) {
-  (VOID) MicroSecondDelay (RTC_DELAY_30_MS);
-  // Try 100 times, if BMC has not released the bus, return preemption 
failed
-  if (Count == 99) {
-if (!EfiAtRuntime ()) {
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state 100 times 
fail!\n",
-__FUNCTION__, __LINE__));
-}
-return EFI_DEVICE_ERROR;
-  }
-  continue;
-}
-
-// if BMC free the bus, can be set 1 preemption
-Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG);
-Temp = Temp | CPU_GET_I2C_CONTROL;
-// CPU occupied RTC I2C State
-WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp);
-(VOID) MicroSecondDelay (RTC_DE

[edk2-devel] [RFC edk2-platforms v3 1/3] Silicon/Hisilicon: Fix a typo issue in M41T83RealTimeClockLib

2020-05-19 Thread Ming Huang
There is a typo issue in M41T83RealTimeClockLib. The MACROSECOND
should be MICROSECOND.

Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h|  4 
++--
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c | 14 
+++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
index 67b8657..81ff459 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
@@ -13,9 +13,9 @@
 // The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
 #define RTC_DELAY_30_MS3
 // The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_1000_MACROSECOND 1000
+#define RTC_DELAY_1000_MICROSECOND 1000
 // The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_2_MACROSECOND2
+#define RTC_DELAY_2_MICROSECOND2
 
 #define M41T83_REGADDR_DOTSECONDS   0x00
 #define M41T83_REGADDR_SECONDS  0x01
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
index 5131ce7..f339bcc 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
@@ -55,7 +55,7 @@ SwitchRtcI2cChannelAndLock (
 Temp = Temp | CPU_GET_I2C_CONTROL;
 // CPU occupied RTC I2C State
 WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp);
-(VOID) MicroSecondDelay (RTC_DELAY_2_MACROSECOND);
+(VOID) MicroSecondDelay (RTC_DELAY_2_MICROSECOND);
 Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG);
 // Is preempt success
 if(CPU_GET_I2C_CONTROL == (Temp & CPU_GET_I2C_CONTROL)) {
@@ -109,7 +109,7 @@ RtcRead (
   EFI_STATUS  Status;
 
   Status = I2CRead (, Address, Size, Data);
-  MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
   return Status;
 }
 
@@ -132,7 +132,7 @@ RtcWrite (
   EFI_STATUS  Status;
 
   Status = I2CWrite (, Address, Size, Data);
-  MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
   return Status;
 }
 
@@ -164,7 +164,7 @@ InitializeM41T83 (
   }
 
   Status = I2CInit (gRtcDevice.Socket, gRtcDevice.Port, Normal);
-  MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
   if (EFI_ERROR (Status)) {
 if (!EfiAtRuntime ()) {
   EfiReleaseLock ();
@@ -181,7 +181,7 @@ InitializeM41T83 (
 return Status;
   }
 
-  MicroSecondDelay(RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay(RTC_DELAY_1000_MICROSECOND);
 
   // Set ST at Power up to clear Oscillator fail detection(OF)
   Status = RtcRead (M41T83_REGADDR_SECONDS, 1, );
@@ -272,7 +272,7 @@ LibSetTime (
   if (EFI_ERROR (Status)) {
 return Status;
   }
-  (VOID)MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  (VOID)MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
 
   SetMem (, sizeof (RTC_M41T83_TIME), 0);
 
@@ -376,7 +376,7 @@ LibGetTime (
 return Status;
   }
 
-  MicroSecondDelay(RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay(RTC_DELAY_1000_MICROSECOND);
 
   SetMem (, sizeof (RTC_M41T83_TIME), 0);
   SetMem (Time , sizeof (EFI_TIME), 0);
-- 
2.8.1


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

View/Reply Online (#59827): https://edk2.groups.io/g/devel/message/59827
Mute This Topic: https://groups.io/mt/74326374/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [RFC edk2-platforms v2 2/3] Hisilicon/Library: Move two functions to RtcHelperLib

2020-05-19 Thread Ming Huang



在 2020/5/19 20:16, Leif Lindholm 写道:
> On Tue, May 19, 2020 at 19:08:40 +0800, Ming Huang wrote:
>> The functions of acquiring ownership of RTC will be used for other
>> RTC library, so move them to RtcHelperLib. Rename them by add leading
>> Oem for uniform.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.1
> 
> We don't use this anymore - it is not required now the codebase is
> under BSD+Patent. Please drop the tag from v3.

Ok.

> 
>> Signed-off-by: Ming Huang 
>> ---
>>  Platform/Hisilicon/D06/D06.dsc  
>> |  1 +
>>  Silicon/Hisilicon/Include/Library/RtcHelperLib.h
>> | 29 ++
>>  Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h  
>> |  7 --
>>  Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c   
>> | 92 ++-
>>  Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf 
>> |  1 +
>>  Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c   
>> | 94 
>>  Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf 
>> | 32 +++
>>  7 files changed, 164 insertions(+), 92 deletions(-)
>>
>> diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc
>> index 000a4ee..eb20224 100644
>> --- a/Platform/Hisilicon/D06/D06.dsc
>> +++ b/Platform/Hisilicon/D06/D06.dsc
>> @@ -54,6 +54,7 @@
>>CpldIoLib|Silicon/Hisilicon/Library/CpldIoLib/CpldIoLib.inf
>>
>>TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf
>> +  RtcHelperLib|Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf
>>
>> RealTimeClockLib|Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
>>OemMiscLib|Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.inf
>>
>> OemAddressMapLib|Platform/Hisilicon/D06/Library/OemAddressMapD06/OemAddressMapD06.inf
>> diff --git a/Silicon/Hisilicon/Include/Library/RtcHelperLib.h 
>> b/Silicon/Hisilicon/Include/Library/RtcHelperLib.h
>> new file mode 100644
>> index 000..29ec900
>> --- /dev/null
>> +++ b/Silicon/Hisilicon/Include/Library/RtcHelperLib.h
>> @@ -0,0 +1,29 @@
>> +/** @file
>> +
>> +  Copyright (c) 2018, Hisilicon Limited. All rights reserved.
>> +
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> +
>> +**/
>> +
>> +#ifndef RTC_HELPER_LIB_H__
>> +#define RTC_HELPER_LIB_H__
>> +
>> +// The delay is need for cpld and I2C. This is a empirical value. 
>> MemoryFence is no need.
>> +#define RTC_DELAY_30_MS3
>> +// The delay is need for cpld and I2C. This is a empirical value. 
>> MemoryFence is no need.
>> +#define RTC_DELAY_1000_MICROSECOND 1000
>> +// The delay is need for cpld and I2C. This is a empirical value. 
>> MemoryFence is no need.
>> +#define RTC_DELAY_2_MICROSECOND2
>> +
>> +EFI_STATUS
>> +OemSwitchRtcI2cChannelAndLock (
>> +  VOID
>> +  );
>> +
>> +VOID
>> +OemReleaseOwnershipOfRtc (
> 
> These two helper functions have been renamed since v1, which is now
> being obscured by the move. If you want to rename them, that should be
> a separate patch submitted *after* this set has been merged.
> 
> Undoing this will mean changes to both 2/3 and 3/3, so please send a
> v3 also dropping the Contributed-under tags - including in v1 which is
> otherwise fine.

Ok, I will send v3 out soon.

Thanks,
Ming

> 
> /
> Leif
> 
>> +  VOID
>> +  );
>> +
>> +#endif
>> diff --git 
>> a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h 
>> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
>> index 81ff459..09329c4 100644
>> --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
>> +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
>> @@ -10,13 +10,6 @@
>>  #ifndef __M41T83_REAL_TIME_CLOCK_H__
>>  #define __M41T83_REAL_TIME_CLOCK_H__
>>
>> -// The delay is need for cpld and I2C. This is a empirical value. 
>> MemoryFence is no need.
>> -#define RTC_DELAY_30_MS3
>> -// The delay is need for cpld and I2C. This is a empirical value. 
>> MemoryFence is no need.
>> -#define RTC_DELAY_1000_MICROSECOND 1000
>> -// The delay is need for cpld and I2C. This is a empirical value. 
>> MemoryFence is no need.
>> -#define RTC_DELAY_2_MICROSECOND2
>> -
>>  #define M

[edk2-devel] [RFC edk2-platforms v2 3/3] Silicon/Hisilicon: Add RX8900RealTimeClockLib

2020-05-19 Thread Ming Huang
There are some boards base on D06, but use RX8900 RTC,
so upstream the RX8900RealTimeClockLib.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h  |  
39 ++
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c   | 
468 
 Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.inf |  
33 ++
 3 files changed, 540 insertions(+)

diff --git 
a/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h 
b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h
new file mode 100644
index 000..ac2be7e
--- /dev/null
+++ b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClock.h
@@ -0,0 +1,39 @@
+/** @file
+
+  Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RX8900_REAL_TIME_CLOCK_H__
+#define RX8900_REAL_TIME_CLOCK_H__
+
+#define RX8900_REGADDR_SECONDS 0x00
+#define RX8900_REGADDR_MIUTES  0x01
+#define RX8900_REGADDR_HOURS   0x02
+#define RX8900_REGADDR_DAY 0x03
+#define RX8900_REGADDR_DATE0x04
+#define RX8900_REGADDR_MONTH   0x05
+#define RX8900_REGADDR_YEAR0x06
+#define RX8900_REGADDR_RAM 0x07
+#define RX8900_REGADDR_ALARMMIN0x08
+#define RX8900_REGADDR_ALARMHOUR   0x09
+#define RX8900_REGADDR_ALARMDAY0x0A
+#define RX8900_REGADDR_ALARMWEEK   0x0A
+#define RX8900_REGADDR_TIMECOUNTER_0   0x0B
+#define RX8900_REGADDR_TIMECOUNTER_1   0x0C
+#define RX8900_REGADDR_EXTENSIONREG0x0D
+#define RX8900_REGADDR_FLAGREG 0x0E
+#define RX8900_REGADDR_CONTRLREG   0xF
+#define RX8900_REGADDR_BACKUP_FUN  0x18
+
+#define RX8900_VDETOFF_SWOFF   0x0C
+#define TEMPERATURE_COMPENSATION_2S0x40
+#define OUTPUT_FREQUENCY_32768 0x0C
+#define FLAG_REG_DEFAULT   0x00
+#define RX8900_RAM_REG_DEFAULT 0x5A
+
+#define EFI_TIMEOFFSET_TIMEZONE0x5A0
+
+#endif
diff --git 
a/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c 
b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
new file mode 100644
index 000..713bb7f
--- /dev/null
+++ b/Silicon/Hisilicon/Library/RX8900RealTimeClockLib/RX8900RealTimeClockLib.c
@@ -0,0 +1,468 @@
+/** @file
+
+  Copyright (c) 2020, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "RX8900RealTimeClock.h"
+
+extern I2C_DEVICE gRtcDevice;
+
+STATIC BOOLEAN   mRX8900Initialized = FALSE;
+STATIC CONST CHAR16  mTimeZoneVariableName[] = L"RX8900RtcTimeZone";
+STATIC CONST CHAR16  mDaylightVariableName[] = L"RX8900RtcDaylight";
+
+EFI_STATUS
+InitializeRX8900 (
+  VOID
+  )
+{
+  EFI_STATUSStatus;
+  unsigned char writeTemp;
+
+  Status = OemSwitchRtcI2cChannelAndLock ();
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  Status = I2CInit (gRtcDevice.Socket, gRtcDevice.Port, Normal);
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  writeTemp = RX8900_VDETOFF_SWOFF;
+  Status = I2CWrite (, RX8900_REGADDR_BACKUP_FUN, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+  writeTemp = TEMPERATURE_COMPENSATION_2S;
+  Status = I2CWrite (, RX8900_REGADDR_CONTRLREG, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+  writeTemp = OUTPUT_FREQUENCY_32768;
+  Status = I2CWrite (, RX8900_REGADDR_EXTENSIONREG, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  writeTemp = FLAG_REG_DEFAULT;
+  Status = I2CWrite (, RX8900_REGADDR_FLAGREG, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+  writeTemp = RX8900_RAM_REG_DEFAULT;
+  Status = I2CWrite (, RX8900_REGADDR_RAM, 1, );
+  if (EFI_ERROR (Status)) {
+goto EXIT;
+  }
+
+  mRX8900Initialized = TRUE;
+
+  EXIT:
+
+  OemReleaseOwnershipOfRtc ();
+  return Status;
+}
+
+STATIC
+INT16
+GetTimeZone (
+  VOID
+  )
+{
+  EFI_STATUS  Status;
+  INT16   TimeZone;
+  UINTN   Size;
+
+  TimeZone = EFI_UNSPECIFIED_TIMEZONE;
+  Size = sizeof (TimeZone);
+  Status = EfiGetVariable (
+ (CHAR16 *)mTimeZoneVariableName,
+ ,
+ NULL,
+ ,
+ (VOID *)
+ );
+
+  if (EFI_ERROR (Status)) {
+TimeZone = EFI_UNSPECIFIED_TIMEZONE;
+// The time zone variable does not exist in non-volatile storage, so 
create it.
+Status = EfiSetVariable (
+   (CHAR16 *)mTimeZoneVariableName,
+   ,
+   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
+   Size,
+   (VOID *)
+   );
+
+if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INF

[edk2-devel] [RFC edk2-platforms v2 1/3] Silicon/Hisilicon: Fix a typo issue in M41T83RealTimeClockLib

2020-05-19 Thread Ming Huang
There is a typo issue in M41T83RealTimeClockLib. The MACROSECOND
should be MICROSECOND.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ming Huang 
---
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h|  4 
++--
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c | 14 
+++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
index 67b8657..81ff459 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
@@ -13,9 +13,9 @@
 // The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
 #define RTC_DELAY_30_MS3
 // The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_1000_MACROSECOND 1000
+#define RTC_DELAY_1000_MICROSECOND 1000
 // The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_2_MACROSECOND2
+#define RTC_DELAY_2_MICROSECOND2
 
 #define M41T83_REGADDR_DOTSECONDS   0x00
 #define M41T83_REGADDR_SECONDS  0x01
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
index 5131ce7..f339bcc 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
@@ -55,7 +55,7 @@ SwitchRtcI2cChannelAndLock (
 Temp = Temp | CPU_GET_I2C_CONTROL;
 // CPU occupied RTC I2C State
 WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp);
-(VOID) MicroSecondDelay (RTC_DELAY_2_MACROSECOND);
+(VOID) MicroSecondDelay (RTC_DELAY_2_MICROSECOND);
 Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG);
 // Is preempt success
 if(CPU_GET_I2C_CONTROL == (Temp & CPU_GET_I2C_CONTROL)) {
@@ -109,7 +109,7 @@ RtcRead (
   EFI_STATUS  Status;
 
   Status = I2CRead (, Address, Size, Data);
-  MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
   return Status;
 }
 
@@ -132,7 +132,7 @@ RtcWrite (
   EFI_STATUS  Status;
 
   Status = I2CWrite (, Address, Size, Data);
-  MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
   return Status;
 }
 
@@ -164,7 +164,7 @@ InitializeM41T83 (
   }
 
   Status = I2CInit (gRtcDevice.Socket, gRtcDevice.Port, Normal);
-  MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
   if (EFI_ERROR (Status)) {
 if (!EfiAtRuntime ()) {
   EfiReleaseLock ();
@@ -181,7 +181,7 @@ InitializeM41T83 (
 return Status;
   }
 
-  MicroSecondDelay(RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay(RTC_DELAY_1000_MICROSECOND);
 
   // Set ST at Power up to clear Oscillator fail detection(OF)
   Status = RtcRead (M41T83_REGADDR_SECONDS, 1, );
@@ -272,7 +272,7 @@ LibSetTime (
   if (EFI_ERROR (Status)) {
 return Status;
   }
-  (VOID)MicroSecondDelay (RTC_DELAY_1000_MACROSECOND);
+  (VOID)MicroSecondDelay (RTC_DELAY_1000_MICROSECOND);
 
   SetMem (, sizeof (RTC_M41T83_TIME), 0);
 
@@ -376,7 +376,7 @@ LibGetTime (
 return Status;
   }
 
-  MicroSecondDelay(RTC_DELAY_1000_MACROSECOND);
+  MicroSecondDelay(RTC_DELAY_1000_MICROSECOND);
 
   SetMem (, sizeof (RTC_M41T83_TIME), 0);
   SetMem (Time , sizeof (EFI_TIME), 0);
-- 
2.8.1


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

View/Reply Online (#59806): https://edk2.groups.io/g/devel/message/59806
Mute This Topic: https://groups.io/mt/74322488/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [RFC edk2-platforms v2 2/3] Hisilicon/Library: Move two functions to RtcHelperLib

2020-05-19 Thread Ming Huang
The functions of acquiring ownership of RTC will be used for other
RTC library, so move them to RtcHelperLib. Rename them by add leading
Oem for uniform.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ming Huang 
---
 Platform/Hisilicon/D06/D06.dsc  |  
1 +
 Silicon/Hisilicon/Include/Library/RtcHelperLib.h| 
29 ++
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h  |  
7 --
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c   | 
92 ++-
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf |  
1 +
 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.c   | 
94 
 Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf | 
32 +++
 7 files changed, 164 insertions(+), 92 deletions(-)

diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc
index 000a4ee..eb20224 100644
--- a/Platform/Hisilicon/D06/D06.dsc
+++ b/Platform/Hisilicon/D06/D06.dsc
@@ -54,6 +54,7 @@
   CpldIoLib|Silicon/Hisilicon/Library/CpldIoLib/CpldIoLib.inf
 
   TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf
+  RtcHelperLib|Silicon/Hisilicon/Library/RtcHelperLib/RtcHelperLib.inf
   
RealTimeClockLib|Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
   OemMiscLib|Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.inf
   
OemAddressMapLib|Platform/Hisilicon/D06/Library/OemAddressMapD06/OemAddressMapD06.inf
diff --git a/Silicon/Hisilicon/Include/Library/RtcHelperLib.h 
b/Silicon/Hisilicon/Include/Library/RtcHelperLib.h
new file mode 100644
index 000..29ec900
--- /dev/null
+++ b/Silicon/Hisilicon/Include/Library/RtcHelperLib.h
@@ -0,0 +1,29 @@
+/** @file
+
+  Copyright (c) 2018, Hisilicon Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RTC_HELPER_LIB_H__
+#define RTC_HELPER_LIB_H__
+
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_30_MS3
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_1000_MICROSECOND 1000
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_2_MICROSECOND2
+
+EFI_STATUS
+OemSwitchRtcI2cChannelAndLock (
+  VOID
+  );
+
+VOID
+OemReleaseOwnershipOfRtc (
+  VOID
+  );
+
+#endif
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
index 81ff459..09329c4 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
@@ -10,13 +10,6 @@
 #ifndef __M41T83_REAL_TIME_CLOCK_H__
 #define __M41T83_REAL_TIME_CLOCK_H__
 
-// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_30_MS3
-// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_1000_MICROSECOND 1000
-// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
-#define RTC_DELAY_2_MICROSECOND2
-
 #define M41T83_REGADDR_DOTSECONDS   0x00
 #define M41T83_REGADDR_SECONDS  0x01
 #define M41T83_REGADDR_MINUTES  0x02
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
index f339bcc..db356ca 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c
@@ -11,10 +11,9 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,70 +25,6 @@ extern I2C_DEVICE gRtcDevice;
 
 STATIC EFI_LOCK  mRtcLock;
 
-EFI_STATUS
-SwitchRtcI2cChannelAndLock (
-  VOID
-  )
-{
-  UINT8   Temp;
-  UINT8   Count;
-
-  for (Count = 0; Count < 100; Count++) {
-// To get the other side's state is idle first
-Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG);
-if ((Temp & BIT3) != 0) {
-  (VOID) MicroSecondDelay (RTC_DELAY_30_MS);
-  // Try 100 times, if BMC has not released the bus, return preemption 
failed
-  if (Count == 99) {
-if (!EfiAtRuntime ()) {
-  DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state 100 times 
fail!\n",
-__FUNCTION__, __LINE__));
-}
-return EFI_DEVICE_ERROR;
-  }
-  continue;
-}
-
-// if BMC free the bus, can be set 1 preemption
-Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG);
-Temp = Temp | CPU_GET_I2C_CONTROL;
-// CPU occupied RTC I2C State
-WriteCpldReg (CPL

  1   2   >