Re: [edk2-devel] [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c

2022-10-30 Thread Ni, Ray
Reviewed-by: Ray Ni 

> -Original Message-
> From: abner.ch...@amd.com 
> Sent: Monday, October 31, 2022 10:49 AM
> To: devel@edk2.groups.io
> Cc: Abdul Lateef Attar ; Garrett Kirkendall
> ; Paul Grimes ; Dong,
> Eric ; Ni, Ray ; Kumar, Rahul R
> 
> Subject: [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header
> file inclusion in SmmStm.c
> 
> From: Abner Chang 
> 
> BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code
> 
> Remove the header files those are already included in
> CpuFeatureLib.h.
> 
> Signed-off-by: Abner Chang 
> Cc: Abdul Lateef Attar 
> Cc: Garrett Kirkendall 
> Cc: Paul Grimes 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Rahul Kumar 
> ---
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> index 4e8f897f5e9..3cf162ada01 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> @@ -7,11 +7,8 @@
>  **/
> 
>  #include 
> -#include 
>  #include 
> -#include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> --
> 2.37.1.windows.1



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




Re: [edk2-devel] [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code

2022-10-30 Thread Ni, Ray
Reviewed-by: Ray Ni 

> -Original Message-
> From: abner.ch...@amd.com 
> Sent: Monday, October 31, 2022 10:49 AM
> To: devel@edk2.groups.io
> Cc: Abdul Lateef Attar ; Garrett Kirkendall
> ; Paul Grimes ; Dong,
> Eric ; Ni, Ray ; Kumar, Rahul R
> 
> Subject: [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch
> dependent code
> 
> From: Abner Chang 
> 
> BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code
> 
> This change stripped away the code that can be
> shared with other archs or vendors from Intel
> implementation and put in to the common file,
> leaves the Intel X86 implementation in the
> IntelSmmCpuFeatureLib. Also updates the header
> file and INF file.
> 
> Signed-off-by: Abner Chang 
> Cc: Abdul Lateef Attar 
> Cc: Garrett Kirkendall 
> Cc: Paul Grimes 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Rahul Kumar 
> ---
>  .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf   |   1 +
>  .../SmmCpuFeaturesLibStm.inf  |   1 +
>  .../StandaloneMmCpuFeaturesLib.inf|   1 +
>  .../SmmCpuFeaturesLib/CpuFeaturesLib.h|   6 +
>  .../IntelSmmCpuFeaturesLib.c  | 206 +
>  .../SmmCpuFeaturesLibCommon.c | 216 ++
>  6 files changed, 227 insertions(+), 204 deletions(-)
>  create mode 100644
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> index 6254a14698a..9ac7dde78f8 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> @@ -20,6 +20,7 @@
>CpuFeaturesLib.h
>IntelSmmCpuFeaturesLib.c
>SmmCpuFeaturesLib.c
> +  SmmCpuFeaturesLibCommon.c
>SmmCpuFeaturesLibNoStm.c
>TraditionalMmCpuFeaturesLib.c
> 
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> index d64d8e66b38..86d367e0a09 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> @@ -20,6 +20,7 @@
>  [Sources]
>CpuFeaturesLib.h
>IntelSmmCpuFeaturesLib.c
> +  SmmCpuFeaturesLibCommon.c
>SmmStm.c
>SmmStm.h
>TraditionalMmCpuFeaturesLib.c
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> index 5935b3e1fd6..b1f60a55055 100644
> ---
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> +++
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> nf
> @@ -21,6 +21,7 @@
>  [Sources]
>CpuFeaturesLib.h
>IntelSmmCpuFeaturesLib.c
> +  SmmCpuFeaturesLibCommon.c
>StandaloneMmCpuFeaturesLib.c
>SmmCpuFeaturesLibNoStm.c
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> index 8a1c2adc5c4..fd3e902547c 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> @@ -9,6 +9,12 @@
>  #ifndef CPU_FEATURES_LIB_H_
>  #define CPU_FEATURES_LIB_H_
> 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
>  /**
>Performs library initialization.
> 
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> index 75a0ec8e948..cb4897b21e3 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> @@ -7,16 +7,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> 
> -#include 
> -#include 
> -#include 
> +#include "CpuFeaturesLib.h"
> +
>  #include 
> -#include 
> -#include 
> -#include 
>  #include 
>  #include 
> -#include "CpuFeaturesLib.h"
> 
>  //
>  // Machine Specific Registers (MSRs)
> @@ -287,64 +282,6 @@ SmmCpuFeaturesInitializeProcessor (
>FinishSmmCpuFeaturesInitializeProcessor ();
>  }
> 
> -/**
> -  This function updates the SMRAM save state on the currently executing
> CPU
> -  to resume execution at a specific address after an RSM instruction.  This
> -  function must evaluate the SMRAM save state to determine the execution
> mode
> -  the RSM instruction resumes and update the resume execution address
> with
> -  either NewInstructionPointer32 or NewInstructionPoint.  The auto HALT
> restart
> -  flag in the SMRAM save state must always be cleared.  This function returns
> -  the value of the instruction pointer from the SMRAM save state that was
> -  replaced.  If this function returns 0, then the SMRAM save state was not
> -  modified.
> -
> -  This function is called during the very first SMI on each CPU after
> -  SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution
> 

Re: [edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file

2022-10-30 Thread Ni, Ray
Reviewed-by: Ray Ni 


From: devel@edk2.groups.io  on behalf of Chang, Abner via 
groups.io 
Sent: Monday, October 31, 2022 10:49
To: devel@edk2.groups.io
Cc: Abdul Lateef Attar; Garrett Kirkendall; Paul Grimes; Dong, Eric; Ni, Ray; 
Kumar, Rahul R
Subject: [edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the 
common C file

From: Abner Chang 

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Rename SmmCpuFeaturesLiCommon.c to
IntelSmmCpuFeaturesLib, because it was developed
specifically for Intel implementation. The code
that can be shared by other archs or vendors
will be stripped away and put in the common
file in the next patch.

Signed-off-by: Abner Chang 
Cc: Abdul Lateef Attar 
Cc: Garrett Kirkendall 
Cc: Paul Grimes 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf  | 2 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf   | 2 +-
 .../Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf| 2 +-
 .../{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c} | 0
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLibCommon.c => 
IntelSmmCpuFeaturesLib.c} (100%)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 7b5cef97008..6254a14698a 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -18,8 +18,8 @@

 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
   TraditionalMmCpuFeaturesLib.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
index 85214ee31cd..d64d8e66b38 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
@@ -19,7 +19,7 @@

 [Sources]
   CpuFeaturesLib.h
-  SmmCpuFeaturesLibCommon.c
+  IntelSmmCpuFeaturesLib.c
   SmmStm.c
   SmmStm.h
   TraditionalMmCpuFeaturesLib.c
diff --git 
a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
index 3eacab48db3..5935b3e1fd6 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -20,8 +20,8 @@

 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   StandaloneMmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c

 [Packages]
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
similarity index 100%
rename from UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
rename to UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
--
2.37.1.windows.1








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




Re: [edk2-devel] [PATCH V2 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file

2022-10-30 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Thanks for catching this!. V3 patch sent.

Abner

> -Original Message-
> From: Ni, Ray 
> Sent: Monday, October 31, 2022 9:59 AM
> To: devel@edk2.groups.io; Chang, Abner 
> Cc: Attar, AbdulLateef (Abdul Lateef) ;
> Kirkendall, Garrett ; Grimes, Paul
> ; Dong, Eric ; Kumar, Rahul
> R 
> Subject: RE: [edk2-devel] [PATCH V2 1/3] UefiCpuPkg/SmmCpuFeaturesLib:
> Rename the common C file
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> This patch will cause build failure because the INF file is not updated after
> rename.
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Chang,
> > Abner via groups.io
> > Sent: Sunday, October 30, 2022 9:02 PM
> > To: devel@edk2.groups.io
> > Cc: Abdul Lateef Attar ; Garrett Kirkendall
> > ; Paul Grimes ;
> Dong,
> > Eric ; Ni, Ray ; Kumar, Rahul R
> > 
> > Subject: [edk2-devel] [PATCH V2 1/3] UefiCpuPkg/SmmCpuFeaturesLib:
> > Rename the common C file
> >
> > From: Abner Chang 
> >
> > BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code
> >
> > Rename SmmCpuFeaturesLiCommon.c to
> > IntelSmmCpuFeaturesLib, because it was developed specifically for
> > Intel implementation. The code that can be shared by other archs or
> > vendors will be stripped away and put in the common file in the next
> > patch.
> >
> > Signed-off-by: Abner Chang 
> > Cc: Abdul Lateef Attar 
> > Cc: Garrett Kirkendall 
> > Cc: Paul Grimes 
> > Cc: Eric Dong 
> > Cc: Ray Ni 
> > Cc: Rahul Kumar 
> > ---
> >  .../{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c}   | 0
> >  1 file changed, 0 insertions(+), 0 deletions(-)  rename
> > UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLibCommon.c
> =>
> > IntelSmmCpuFeaturesLib.c} (100%)
> >
> > diff --git
> >
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> > similarity index 100%
> > rename from
> > UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> > rename to
> > UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> > --
> > 2.37.1.windows.1
> >
> >
> >
> > 
> >


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




Re: [edk2-devel] [PATCH v2] MdeModulePkg/ScsiDiskDxe: Update proper device name for ScsiDisk drive

2022-10-30 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/3559
Commit - 
https://github.com/tianocore/edk2/commit/52199bf5326a8355d28b2d395db483f7c77d5a4d

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao A
> Sent: Friday, October 28, 2022 10:26 AM
> To: devel@edk2.groups.io; go...@ami.com
> Cc: Selvaraj, Sundaresan ; Sambandan, Vasudevan
> 
> Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/ScsiDiskDxe: Update
> proper device name for ScsiDisk drive
> 
> Thanks.
> Reviewed-by: Hao A Wu 
> 
> Will wait a couple of days before merging to see if comments from other
> reviewers.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of
> > Cheripally Gopi via groups.io
> > Sent: Thursday, October 27, 2022 3:07 PM
> > To: devel@edk2.groups.io
> > Cc: Selvaraj, Sundaresan ; Sambandan, Vasudevan
> > ; Cheripally Gopi 
> > Subject: [edk2-devel] [PATCH v2] MdeModulePkg/ScsiDiskDxe: Update
> > proper device name for ScsiDisk drive
> >
> > ScsiDiskDxe driver updates ControllerNameTable with common string
> > "SCSI Disk Device" for all SCSI disks. Due to this, when multiple SCSI
> > disk devices connected, facing difficulty in identifying correct SCSI
> > disk device. As per SCSI spec, standard Inquiry Data is having the
> > fields to know Vendor and Product information. Updated
> > "ControllerNameTable" with Vendor and Product information. So that,
> > device specific name can be retrieved using ComponentName protocol.
> >
> > Cc: Vasudevan Sambandan 
> > Cc: Sundaresan Selvaraj 
> > Signed-off-by: Cheripally Gopi 
> > ---
> >  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c  | 53
> > ++-  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h  |  9
> 
> >  .../Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf  |  2 +
> >  3 files changed, 62 insertions(+), 2 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > index 98e84b4ea8..0928605dc4 100644
> > --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > @@ -2,6 +2,7 @@
> >SCSI disk driver that layers on every SCSI IO protocol in the system.
> >
> >
> >
> >  Copyright (c) 2006 - 2019, Intel Corporation. All rights
> > reserved.
> >
> > +Copyright (c) 1985 - 2022, American Megatrends International LLC.
> >
> >  SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> >
> >
> >  **/
> >
> > @@ -67,6 +68,33 @@ FreeAlignedBuffer (
> >}
> >
> >  }
> >
> >
> >
> > +/**
> >
> > +  Remove trailing spaces from the string.
> >
> > +
> >
> > +  @param String   The ASCII string to remove the trailing spaces.
> >
> > +
> >
> > +  @retval the new length of the string.
> >
> > +**/
> >
> > +UINTN
> >
> > +RemoveTrailingSpaces (
> >
> > +  IN OUT CHAR8  *String
> >
> > +  )
> >
> > +{
> >
> > +  UINTN  Length;
> >
> > +
> >
> > +  Length = AsciiStrLen (String);
> >
> > +  if (Length == 0) {
> >
> > +return 0;
> >
> > +  }
> >
> > +
> >
> > +  while ((Length > 0) && (String[Length-1] == ' ')) {
> >
> > +Length--;
> >
> > +  }
> >
> > +
> >
> > +  String[Length] = '\0';
> >
> > +  return Length;
> >
> > +}
> >
> > +
> >
> >  /**
> >
> >The user Entry Point for module ScsiDisk.
> >
> >
> >
> > @@ -203,6 +231,9 @@ ScsiDiskDriverBindingStart (
> >UINT8 MaxRetry;
> >
> >BOOLEAN   NeedRetry;
> >
> >BOOLEAN   MustReadCapacity;
> >
> > +  CHAR8 VendorStr[VENDOR_IDENTIFICATION_LENGTH + 1];
> >
> > +  CHAR8 ProductStr[PRODUCT_IDENTIFICATION_LENGTH + 1];
> >
> > +  CHAR16DeviceStr[VENDOR_IDENTIFICATION_LENGTH +
> > PRODUCT_IDENTIFICATION_LENGTH + 2];
> >
> >
> >
> >MustReadCapacity = TRUE;
> >
> >
> >
> > @@ -354,19 +385,37 @@ ScsiDiskDriverBindingStart (
> >}
> >
> >  }
> >
> >
> >
> > +CopyMem (
> >
> > +  VendorStr,
> >
> > +  
> > >InquiryData.Reserved_5_95[VENDOR_IDENTIFICATION_OFFSET],
> >
> > +  VENDOR_IDENTIFICATION_LENGTH
> >
> > +  );
> >
> > +VendorStr[VENDOR_IDENTIFICATION_LENGTH] = 0;
> >
> > +RemoveTrailingSpaces (VendorStr);
> >
> > +
> >
> > +CopyMem (
> >
> > +  ProductStr,
> >
> > +  
> > >InquiryData.Reserved_5_95[PRODUCT_IDENTIFICATION_OFFSET],
> >
> > +  PRODUCT_IDENTIFICATION_LENGTH
> >
> > +  );
> >
> > +ProductStr[PRODUCT_IDENTIFICATION_LENGTH] = 0;
> >
> > +RemoveTrailingSpaces (ProductStr);
> >
> > +
> >
> > +UnicodeSPrint (DeviceStr, sizeof (DeviceStr), L"%a %a",
> > + VendorStr,
> > ProductStr);
> >
> > +
> >
> >  ScsiDiskDevice->ControllerNameTable = NULL;
> >
> >  AddUnicodeString2 (
> >
> >"eng",
> >
> >gScsiDiskComponentName.SupportedLanguages,
> >
> >>ControllerNameTable,
> >
> > -  L"SCSI Disk Device",
> >
> > +  

[edk2-devel] [PATCH V3 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c

2022-10-30 Thread Chang, Abner via groups.io
From: Abner Chang 

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Remove the header files those are already included in
CpuFeatureLib.h.

Signed-off-by: Abner Chang 
Cc: Abdul Lateef Attar 
Cc: Garrett Kirkendall 
Cc: Paul Grimes 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
index 4e8f897f5e9..3cf162ada01 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
@@ -7,11 +7,8 @@
 **/
 
 #include 
-#include 
 #include 
-#include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
2.37.1.windows.1



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




[edk2-devel] [PATCH V3 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code

2022-10-30 Thread Chang, Abner via groups.io
From: Abner Chang 

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

This change stripped away the code that can be
shared with other archs or vendors from Intel
implementation and put in to the common file,
leaves the Intel X86 implementation in the
IntelSmmCpuFeatureLib. Also updates the header
file and INF file.

Signed-off-by: Abner Chang 
Cc: Abdul Lateef Attar 
Cc: Garrett Kirkendall 
Cc: Paul Grimes 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
---
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf   |   1 +
 .../SmmCpuFeaturesLibStm.inf  |   1 +
 .../StandaloneMmCpuFeaturesLib.inf|   1 +
 .../SmmCpuFeaturesLib/CpuFeaturesLib.h|   6 +
 .../IntelSmmCpuFeaturesLib.c  | 206 +
 .../SmmCpuFeaturesLibCommon.c | 216 ++
 6 files changed, 227 insertions(+), 204 deletions(-)
 create mode 100644 
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 6254a14698a..9ac7dde78f8 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -20,6 +20,7 @@
   CpuFeaturesLib.h
   IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLib.c
+  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
   TraditionalMmCpuFeaturesLib.c
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
index d64d8e66b38..86d367e0a09 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
@@ -20,6 +20,7 @@
 [Sources]
   CpuFeaturesLib.h
   IntelSmmCpuFeaturesLib.c
+  SmmCpuFeaturesLibCommon.c
   SmmStm.c
   SmmStm.h
   TraditionalMmCpuFeaturesLib.c
diff --git 
a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
index 5935b3e1fd6..b1f60a55055 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -21,6 +21,7 @@
 [Sources]
   CpuFeaturesLib.h
   IntelSmmCpuFeaturesLib.c
+  SmmCpuFeaturesLibCommon.c
   StandaloneMmCpuFeaturesLib.c
   SmmCpuFeaturesLibNoStm.c
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
index 8a1c2adc5c4..fd3e902547c 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
@@ -9,6 +9,12 @@
 #ifndef CPU_FEATURES_LIB_H_
 #define CPU_FEATURES_LIB_H_
 
+#include 
+#include 
+#include 
+#include 
+#include 
+
 /**
   Performs library initialization.
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
index 75a0ec8e948..cb4897b21e3 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
@@ -7,16 +7,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include 
-#include 
-#include 
+#include "CpuFeaturesLib.h"
+
 #include 
-#include 
-#include 
-#include 
 #include 
 #include 
-#include "CpuFeaturesLib.h"
 
 //
 // Machine Specific Registers (MSRs)
@@ -287,64 +282,6 @@ SmmCpuFeaturesInitializeProcessor (
   FinishSmmCpuFeaturesInitializeProcessor ();
 }
 
-/**
-  This function updates the SMRAM save state on the currently executing CPU
-  to resume execution at a specific address after an RSM instruction.  This
-  function must evaluate the SMRAM save state to determine the execution mode
-  the RSM instruction resumes and update the resume execution address with
-  either NewInstructionPointer32 or NewInstructionPoint.  The auto HALT restart
-  flag in the SMRAM save state must always be cleared.  This function returns
-  the value of the instruction pointer from the SMRAM save state that was
-  replaced.  If this function returns 0, then the SMRAM save state was not
-  modified.
-
-  This function is called during the very first SMI on each CPU after
-  SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode
-  to signal that the SMBASE of each CPU has been updated before the default
-  SMBASE address is used for the first SMI to the next CPU.
-
-  @param[in] CpuIndex The index of the CPU to hook.  The value
-  must be between 0 and the NumberOfCpus
-  field in the System Management System 
Table
-  (SMST).
-  @param[in] CpuState Pointer to SMRAM Save State Map for the
-  currently executing CPU.
-  @param[in] NewInstructionPointer32  

[edk2-devel] [PATCH V3 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file

2022-10-30 Thread Chang, Abner via groups.io
From: Abner Chang 

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Rename SmmCpuFeaturesLiCommon.c to
IntelSmmCpuFeaturesLib, because it was developed
specifically for Intel implementation. The code
that can be shared by other archs or vendors
will be stripped away and put in the common
file in the next patch.

Signed-off-by: Abner Chang 
Cc: Abdul Lateef Attar 
Cc: Garrett Kirkendall 
Cc: Paul Grimes 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf  | 2 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf   | 2 +-
 .../Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf| 2 +-
 .../{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c} | 0
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLibCommon.c => 
IntelSmmCpuFeaturesLib.c} (100%)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 7b5cef97008..6254a14698a 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -18,8 +18,8 @@
 
 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
   TraditionalMmCpuFeaturesLib.c
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
index 85214ee31cd..d64d8e66b38 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
@@ -19,7 +19,7 @@
 
 [Sources]
   CpuFeaturesLib.h
-  SmmCpuFeaturesLibCommon.c
+  IntelSmmCpuFeaturesLib.c
   SmmStm.c
   SmmStm.h
   TraditionalMmCpuFeaturesLib.c
diff --git 
a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
index 3eacab48db3..5935b3e1fd6 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -20,8 +20,8 @@
 
 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   StandaloneMmCpuFeaturesLib.c
-  SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
 
 [Packages]
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
similarity index 100%
rename from UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
rename to UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
-- 
2.37.1.windows.1



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




Re: [edk2-devel] [PATCH] RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

2022-10-30 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Hi Igor,
My response in below,

From: Igor Kulchytskyy 
Sent: Monday, October 31, 2022 2:56 AM
To: Chang, Abner ; Nickle Wang ; 
devel@edk2.groups.io
Cc: Nick Ramirez 
Subject: Re: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.

Hi Abner,
"redfish/v1" does not require any authentication. But "redfish/v1" json 
response contains the links to high level resources - systems, chassis etc.
My point was to get the URI to systems from that json response, rather than 
have it hard coded.
[Chang, Abner]
Ah I see. I remember we do have the code on RedfishClinetPkg to determine the 
version under Redfish/. Then concatenate those to Redfish/{version}.
Another way is: We do the authentication check only if the HTTP transfer to 
Redfish service gets 401. Means the upper layer driver (RedfishConfigHandler 
driver? I have to check) invokes RedfishCrendtialLib to create the Basic 
authorization or session Token when the HTTP action to Redfish service returns 
401.

If both auth methods supported, we should go with more secured one - session 
authentication. In this case we do not need to send username and password 
within each request.

[Chang, Abner]
Ok, this make sense to me. So we don't need to provide a BIOS setup option or 
PCD  to the platform for selecting the auth method. We will determine it 
automatically.
Then we can preserve this token secured for each request, but delete it at End 
of DXE.

Abner

Thank you,
Igor

Get Outlook for 
Android

From: Chang, Abner mailto:abner.ch...@amd.com>>
Sent: Sunday, October 30, 2022 11:33:26 AM
To: Nickle Wang mailto:nick...@nvidia.com>>; Igor 
Kulchytskyy mailto:ig...@ami.com>>; 
devel@edk2.groups.io 
mailto:devel@edk2.groups.io>>
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation


[AMD Official Use Only - General]



Does "/redfish/v1" require authentication? I think this solution is ok if 
"/redfish/v1" requires the authentication.

Another thing is how do we determine to use Basic authentication or the session 
token?



Abner



From: Nickle Wang mailto:nick...@nvidia.com>>
Sent: Saturday, October 29, 2022 7:29 AM
To: Igor Kulchytskyy mailto:ig...@ami.com>>; Chang, Abner 
mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: Re: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation



Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.



Hi Igor,



Yes, we should get the URI to computer system collection by parsing 
"/redfish/v1".



Hi Abner,



What do you think about this? And if we like to select authentication method 
for Redfish communication in this way, we need to update RedfishCredentialLib.h 
because now the authentication method is not decided by this low-level library.



Thanks,

Nickle



From: Igor Kulchytskyy mailto:ig...@ami.com>>
Sent: Saturday, October 29, 2022 12:03 AM
To: Nickle Wang mailto:nick...@nvidia.com>>; Chang, Abner 
mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io 
mailto:devel@edk2.groups.io>>
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation



External email: Use caution opening links or attachments


Hi Nickle,
I think this is a good idea to send a request to the URI which requires the 
authentication and then analyze the header of response.
The only thing I would like to discuss is a hardcoded URI - 
"/redfish/v1/Systems".
Shouldn't we parse "redfish/v1" json response and get the URI from "Systems" 
attribute.
That, I think, would be more universal method.
And that is what Redfish specification said, that user should be able to 
iterate from Redfish service root "redfish/v1" to any redfish resource.
Thank you,
Igor



-Original Message-
From: Nickle Wang mailto:nick...@nvidia.com>>
Sent: Friday, October 28, 2022 10:53 AM
To: Igor Kulchytskyy mailto:ig...@ami.com>>; Chang, Abner 
mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io
Cc: Nick Ramirez 

Re: [edk2-devel] [PATCH V2 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file

2022-10-30 Thread Ni, Ray
This patch will cause build failure because the INF file is not updated after 
rename.

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chang,
> Abner via groups.io
> Sent: Sunday, October 30, 2022 9:02 PM
> To: devel@edk2.groups.io
> Cc: Abdul Lateef Attar ; Garrett Kirkendall
> ; Paul Grimes ; Dong,
> Eric ; Ni, Ray ; Kumar, Rahul R
> 
> Subject: [edk2-devel] [PATCH V2 1/3] UefiCpuPkg/SmmCpuFeaturesLib:
> Rename the common C file
> 
> From: Abner Chang 
> 
> BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code
> 
> Rename SmmCpuFeaturesLiCommon.c to
> IntelSmmCpuFeaturesLib, because it was developed
> specifically for Intel implementation. The code
> that can be shared by other archs or vendors
> will be stripped away and put in the common
> file in the next patch.
> 
> Signed-off-by: Abner Chang 
> Cc: Abdul Lateef Attar 
> Cc: Garrett Kirkendall 
> Cc: Paul Grimes 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Rahul Kumar 
> ---
>  .../{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c}   | 0
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  rename
> UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLibCommon.c =>
> IntelSmmCpuFeaturesLib.c} (100%)
> 
> diff --git
> a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> similarity index 100%
> rename from
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
> rename to
> UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95761): https://edk2.groups.io/g/devel/message/95761
Mute This Topic: https://groups.io/mt/94663860/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] ArmPlatformPkg/Drivers/NorFlashDxe:avoid index out of bound

2022-10-30 Thread wenyi,xie via groups.io



On 2022/10/30 18:06, Ard Biesheuvel wrote:
> On Sat, 29 Oct 2022 at 11:29, Wenyi Xie  wrote:
>>
>> The size of array BlockMap is 1 in struct FirmwareVolumeHeader, but in
>> function InitializeFvAndVariableStoreHeaders, BlockMap[1] is been written.
> 
> The size of BlockMap[] is not 1. BlockMap is a flexible array declared
> in an old fashioned way, and because the type definition is covered by
> the spec, we can not change it. Given that this is established idiom,
> compilers don't tend to warn about this.
> 
>> The memory of BlockMap[1] is already allocated, so the code is OK. But
>> it is better to use a new point to assign this memory.
>>
>> Cc: Leif Lindholm 
>> Cc: Ard Biesheuvel 
>> Signed-off-by: Wenyi Xie 
> 
> Thanks for the patch but this driver is going to be deleted soon so no point.
> 
> There is new version of this driver in OvmfPkg/ but given the above, I
> don't think there is anything that needs fixing here.

Thank you for your answering, I got your point and so it seems no necessary to 
change.

Best Regards
Wenyi
> 
>> ---
>>  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c | 10 --
>>  1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c 
>> b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
>> index 0767581308d2..2130e2e76344 100644
>> --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
>> +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
>> @@ -47,6 +47,7 @@ InitializeFvAndVariableStoreHeaders (
>>VOID*Headers;
>>UINTN   HeadersLength;
>>EFI_FIRMWARE_VOLUME_HEADER  *FirmwareVolumeHeader;
>> +  EFI_FV_BLOCK_MAP_ENTRY  *BlockMapEntry;
>>VARIABLE_STORE_HEADER   *VariableStoreHeader;
>>UINT32  NvStorageFtwSpareSize;
>>UINT32  NvStorageFtwWorkingSize;
>> @@ -151,10 +152,15 @@ InitializeFvAndVariableStoreHeaders (
>>FirmwareVolumeHeader->Revision  = EFI_FVH_REVISION;
>>FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 
>> 1;
>>FirmwareVolumeHeader->BlockMap[0].Length= Instance->Media.BlockSize;
>> -  FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;
>> -  FirmwareVolumeHeader->BlockMap[1].Length= 0;
>>FirmwareVolumeHeader->Checksum  = CalculateCheckSum16 
>> ((UINT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength);
>>
>> +  //
>> +  // EFI_FV_BLOCK_MAP_ENTRY
>> +  //
>> +  BlockMapEntry= (EFI_FV_BLOCK_MAP_ENTRY *)((UINTN)Headers + 
>> sizeof (EFI_FIRMWARE_VOLUME_HEADER));
>> +  BlockMapEntry->NumBlocks = 0;
>> +  BlockMapEntry->Length= 0;
>> +
>>//
>>// VARIABLE_STORE_HEADER
>>//
>> --
>> 2.20.1.windows.1
>>
> .
> 


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




[edk2-devel] Event: Tools, CI, Code base construction meeting series - 10/31/2022 #cal-reminder

2022-10-30 Thread Group Notification
*Reminder: Tools, CI, Code base construction meeting series*

*When:*
10/31/2022
4:30pm to 5:30pm
(UTC-07:00) America/Los Angeles

*Where:*
https://github.com/tianocore/edk2/discussions/2614

View Event ( https://edk2.groups.io/g/devel/viewevent?eventid=1610037 )

*Description:*

TianoCore community,

Microsoft and Intel will be hosting a series of open meetings to discuss build, 
CI, tools, and other related topics. If you are interested, have ideas/opinions 
please join us. These meetings will be Monday 4:30pm Pacific Time on Microsoft 
Teams.

MS Teams Link in following discussion: * 
https://github.com/tianocore/edk2/discussions/2614

Anyone is welcome to join.

* tianocore/edk2: EDK II (github.com)
* tianocore/edk2-basetools: EDK II BaseTools Python tools as a PIP module 
(github.com) https://github.com/tianocore/edk2-basetools
* tianocore/edk2-pytool-extensions: Extensions to the edk2 build system 
allowing for a more robust and plugin based build system and tool execution 
environment (github.com) https://github.com/tianocore/edk2-pytool-extensions
* tianocore/edk2-pytool-library: Python library package that supports UEFI 
development (github.com) https://github.com/tianocore/edk2-pytool-library

MS Teams Browser Clients * 
https://docs.microsoft.com/en-us/microsoftteams/get-clients?tabs=Windows#browser-client


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




Re: [edk2-devel] [PATCH] RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

2022-10-30 Thread Igor Kulchytskyy via groups.io
Hi Abner,
"redfish/v1" does not require any authentication. But "redfish/v1" json 
response contains the links to high level resources - systems, chassis etc.
My point was to get the URI to systems from that json response, rather than 
have it hard coded.

If both auth methods supported, we should go with more secured one - session 
authentication. In this case we do not need to send username and password 
within each request.

Thank you,
Igor

Get Outlook for Android

From: Chang, Abner 
Sent: Sunday, October 30, 2022 11:33:26 AM
To: Nickle Wang ; Igor Kulchytskyy ; 
devel@edk2.groups.io 
Cc: Nick Ramirez 
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation


[AMD Official Use Only - General]



Does "/redfish/v1” require authentication? I think this solution is ok if 
"/redfish/v1” requires the authentication.

Another thing is how do we determine to use Basic authentication or the session 
token?



Abner



From: Nickle Wang 
Sent: Saturday, October 29, 2022 7:29 AM
To: Igor Kulchytskyy ; Chang, Abner ; 
devel@edk2.groups.io
Cc: Nick Ramirez 
Subject: Re: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation



Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.



Hi Igor,



Yes, we should get the URI to computer system collection by parsing 
"/redfish/v1".



Hi Abner,



What do you think about this? And if we like to select authentication method 
for Redfish communication in this way, we need to update RedfishCredentialLib.h 
because now the authentication method is not decided by this low-level library.



Thanks,

Nickle



From: Igor Kulchytskyy mailto:ig...@ami.com>>
Sent: Saturday, October 29, 2022 12:03 AM
To: Nickle Wang mailto:nick...@nvidia.com>>; Chang, Abner 
mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io 
mailto:devel@edk2.groups.io>>
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation



External email: Use caution opening links or attachments


Hi Nickle,
I think this is a good idea to send a request to the URI which requires the 
authentication and then analyze the header of response.
The only thing I would like to discuss is a hardcoded URI - 
"/redfish/v1/Systems".
Shouldn't we parse "redfish/v1" json response and get the URI from "Systems" 
attribute.
That, I think, would be more universal method.
And that is what Redfish specification said, that user should be able to 
iterate from Redfish service root "redfish/v1" to any redfish resource.
Thank you,
Igor



-Original Message-
From: Nickle Wang mailto:nick...@nvidia.com>>
Sent: Friday, October 28, 2022 10:53 AM
To: Igor Kulchytskyy mailto:ig...@ami.com>>; Chang, Abner 
mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

Hi Igor, Abner,

Thanks for your comments. A quick summary as below:

- BIOS is not supported to disable bootstrap credential service. For security 
purposes, BIOS should shutdown credential service with its internal control 
mechanism.
- Credential libraries need a cache mechanism to prevent multiple queries to 
BMC. All applications in BIOS share the same credentials.
- The storage of keeping credentials should be deleted before the end of the 
DXE event. So that the credential will not be retrieved by unauthorized user or 
application. (e.g. user can read variable under UEFI shell with dmpstore 
command)

There is one thing remained and I like to have further discussion. For the 
authentication method, do we think that client user can decide what 
authentication method to use regardless of the requirement from server? I am 
thinking a detection mechanism as below:

Issue HTTP GET to "/redfish/v1/Systems" (which normally require authentication) 
without authentication method.
a) if client receive 200 OK, "No Auth" is used and we don't need to get 
credentials
b) if client receive 401 Unauthorized, check the "WWW-Authenticate" field in 
returned HTTP header. "Basic realm" or "X-Auh-Token realm" or both two methods 
will be specified. Then client can know what method to use. Two methods all 
require credential.

Above mechanism can be placed in RedfishCredentailDxe driver so driver will 
know if it needs to call credential lib or not.

Thanks,
Nickle

-Original Message-
From: Igor Kulchytskyy mailto:ig...@ami.com>>
Sent: Friday, October 28, 2022 9:54 PM
To: Chang, Abner mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io; Nickle Wang 
mailto:nick...@nvidia.com>>
Cc: Nick Ramirez 

Re: [edk2-devel] [PATCH] RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

2022-10-30 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Does "/redfish/v1" require authentication? I think this solution is ok if 
"/redfish/v1" requires the authentication.
Another thing is how do we determine to use Basic authentication or the session 
token?

Abner

From: Nickle Wang 
Sent: Saturday, October 29, 2022 7:29 AM
To: Igor Kulchytskyy ; Chang, Abner ; 
devel@edk2.groups.io
Cc: Nick Ramirez 
Subject: Re: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.

Hi Igor,

Yes, we should get the URI to computer system collection by parsing 
"/redfish/v1".

Hi Abner,

What do you think about this? And if we like to select authentication method 
for Redfish communication in this way, we need to update RedfishCredentialLib.h 
because now the authentication method is not decided by this low-level library.

Thanks,
Nickle

From: Igor Kulchytskyy mailto:ig...@ami.com>>
Sent: Saturday, October 29, 2022 12:03 AM
To: Nickle Wang mailto:nick...@nvidia.com>>; Chang, Abner 
mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io 
mailto:devel@edk2.groups.io>>
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

External email: Use caution opening links or attachments


Hi Nickle,
I think this is a good idea to send a request to the URI which requires the 
authentication and then analyze the header of response.
The only thing I would like to discuss is a hardcoded URI - 
"/redfish/v1/Systems".
Shouldn't we parse "redfish/v1" json response and get the URI from "Systems" 
attribute.
That, I think, would be more universal method.
And that is what Redfish specification said, that user should be able to 
iterate from Redfish service root "redfish/v1" to any redfish resource.
Thank you,
Igor



-Original Message-
From: Nickle Wang mailto:nick...@nvidia.com>>
Sent: Friday, October 28, 2022 10:53 AM
To: Igor Kulchytskyy mailto:ig...@ami.com>>; Chang, Abner 
mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

Hi Igor, Abner,

Thanks for your comments. A quick summary as below:

- BIOS is not supported to disable bootstrap credential service. For security 
purposes, BIOS should shutdown credential service with its internal control 
mechanism.
- Credential libraries need a cache mechanism to prevent multiple queries to 
BMC. All applications in BIOS share the same credentials.
- The storage of keeping credentials should be deleted before the end of the 
DXE event. So that the credential will not be retrieved by unauthorized user or 
application. (e.g. user can read variable under UEFI shell with dmpstore 
command)

There is one thing remained and I like to have further discussion. For the 
authentication method, do we think that client user can decide what 
authentication method to use regardless of the requirement from server? I am 
thinking a detection mechanism as below:

Issue HTTP GET to "/redfish/v1/Systems" (which normally require authentication) 
without authentication method.
a) if client receive 200 OK, "No Auth" is used and we don't need to get 
credentials
b) if client receive 401 Unauthorized, check the "WWW-Authenticate" field in 
returned HTTP header. "Basic realm" or "X-Auh-Token realm" or both two methods 
will be specified. Then client can know what method to use. Two methods all 
require credential.

Above mechanism can be placed in RedfishCredentailDxe driver so driver will 
know if it needs to call credential lib or not.

Thanks,
Nickle

-Original Message-
From: Igor Kulchytskyy mailto:ig...@ami.com>>
Sent: Friday, October 28, 2022 9:54 PM
To: Chang, Abner mailto:abner.ch...@amd.com>>; 
devel@edk2.groups.io; Nickle Wang 
mailto:nick...@nvidia.com>>
Cc: Nick Ramirez mailto:nrami...@nvidia.com>>
Subject: RE: [EXTERNAL] RE: [edk2-devel] [PATCH] 
RedfishPkg/RedfishPlatformCredentialLib: IPMI implementation

External email: Use caution opening links or attachments


Hi Abner,
Yes, you are right that NVRAM variables were deprecated by DMTF.
But we can use our own boot time NVRAM variable to keep FW credentials. That 
variable will not be accessible from OS, but since we agreed not to disable 
bootstrap credentials service on exit boot event, then OS may get its own 
credentials.
Or we can save the credentials in memory variable. But in this case if we have 
several instances of the library linked with different modules they will have 
to send their own IPMI command to get credentials.
So, I think it is better to use our own NVRAM boot time variable.
Thank you,

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 30/30] UefiCpuPkg/UefiCpuPkg.ci.yaml: Ignore RISC-V file

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

RISC-V register names do not follow the EDK2 formatting.
So, add it to ignore list for now.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 UefiCpuPkg/UefiCpuPkg.ci.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml b/UefiCpuPkg/UefiCpuPkg.ci.yaml
index a377366798b0..953361ba0479 100644
--- a/UefiCpuPkg/UefiCpuPkg.ci.yaml
+++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml
@@ -27,6 +27,7 @@
 ],
 ## Both file path and directory path are accepted.
 "IgnoreFiles": [
+  "Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib.h"
 ]
 },
 "CompilerPlugin": {
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 28/30] OvmfPkg: RiscVVirt: Add Qemu Virt platform support

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Add infrastructure files to build edk2 for RISC-V qemu virt machine.

- EDK2 will boot as S-mode payload of opensbi.
- It supports building
  either code and variables in unified flash or in two separate drives
  via build time option UNIFIED_NVVARS.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc | 727 
 OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf | 406 +++
 OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf.inc |  66 ++
 OvmfPkg/Platforms/RiscVVirt/VarStore.fdf.inc  |  79 +++
 4 files changed, 1278 insertions(+)

diff --git a/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc 
b/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc
new file mode 100644
index ..33c945f57624
--- /dev/null
+++ b/OvmfPkg/Platforms/RiscVVirt/RiscVVirt.dsc
@@ -0,0 +1,727 @@
+## @file
+#  RISC-V EFI on RiscVVirt RISC-V platform
+#
+#  Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+#  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+
+[Defines]
+  PLATFORM_NAME  = RiscVVirt
+  PLATFORM_GUID  = 39DADB39-1B21-4867-838E-830B6149B9E0
+  PLATFORM_VERSION   = 0.1
+  DSC_SPECIFICATION  = 0x0001001c
+  OUTPUT_DIRECTORY   = Build/$(PLATFORM_NAME)
+  SUPPORTED_ARCHITECTURES= RISCV64
+  BUILD_TARGETS  = DEBUG|RELEASE|NOOPT
+  SKUID_IDENTIFIER   = DEFAULT
+  FLASH_DEFINITION   = OvmfPkg/Platforms/RiscVVirt/RiscVVirt.fdf
+
+  #
+  # Enable below options may cause build error or may not work on
+  # the initial version of RISC-V package
+  # Defines for default states.  These can be changed on the command line.
+  # -D FLAG=VALUE
+  #
+  DEFINE UNIFIED_VARSTORE= TRUE
+  DEFINE SECURE_BOOT_ENABLE  = FALSE
+  DEFINE DEBUG_ON_SERIAL_PORT= TRUE
+
+  #
+  # Network definition
+  #
+  DEFINE NETWORK_SNP_ENABLE   = FALSE
+  DEFINE NETWORK_IP6_ENABLE   = FALSE
+  DEFINE NETWORK_TLS_ENABLE   = TRUE
+  DEFINE NETWORK_HTTP_BOOT_ENABLE = TRUE
+  DEFINE NETWORK_ISCSI_ENABLE = FALSE
+  DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE
+
+[BuildOptions]
+  GCC:RELEASE_*_*_CC_FLAGS   = -DMDEPKG_NDEBUG
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  GCC:*_*_RISCV64_GENFW_FLAGS= --keepexceptiontable
+!endif
+
+[BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER]
+  GCC:  *_*_*_DLINK_FLAGS = -z common-page-size=0x1000
+  MSFT: *_*_*_DLINK_FLAGS = /ALIGN:4096
+
+
+#
+# SKU Identification section - list of all SKU IDs supported by this Platform.
+#
+
+[SkuIds]
+  0|DEFAULT
+
+
+#
+# Library Class section - list of all Library Classes needed by this Platform.
+#
+
+
+!include MdePkg/MdeLibs.dsc.inc
+
+[LibraryClasses]
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+  SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+  
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
+  
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+  
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
+  
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
+  
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
+  
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+  
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+  
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
+  
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
+  

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 29/30] Maintainers.txt: Add entry for OvmfPkg/RiscVVirt

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

RiscVVirt is created to support EDK2 for RISC-V qemu
virt machine platform. Add maintainer entries.

Cc: Andrew Fish 
Cc: Leif Lindholm 
Cc: Michael D Kinney 
Signed-off-by: Sunil V L 
---
 Maintainers.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/Maintainers.txt b/Maintainers.txt
index 8e81ccfdeccf..e4faee5b7684 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -533,6 +533,10 @@ F: OvmfPkg/XenResetVector/
 R: Anthony Perard  [sheep]
 R: Julien Grall  [jgrall]
 
+OvmfPkg: RISC-V Qemu Virt Platform
+F: OvmfPkg/Platforms/RiscVVirt
+R: Sunil V L  [vlsunil]
+
 PcAtChipsetPkg
 F: PcAtChipsetPkg/
 W: https://github.com/tianocore/tianocore.github.io/wiki/PcAtChipsetPkg
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 27/30] OvmfPkg: Add VirtNorFlashPlatformLib library

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Add the VirtNorFlashPlatformLib library for qemu virt machines.

Add two instances of the library. One which uses DT information
and the other which is static. They are copied from
ArmVirtPkg and SbsaQemu. Two PCD variables used by the library
are added in the OvmfPkg.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Daniel Schaefer 
Signed-off-by: Sunil V L 
---
 OvmfPkg/OvmfPkg.dec   |   4 +
 OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.inf |  40 
++
 OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashStaticLib.inf |  30 
+
 OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.c   | 136 

 OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashStaticLib.c   |  40 
++
 5 files changed, 250 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index ba5194114c5c..142c34193d60 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -409,6 +409,10 @@ [PcdsFixedAtBuild]
   #  check to decide whether to abort dispatch of the driver it is linked into.
   gUefiOvmfPkgTokenSpaceGuid.PcdEntryPointOverrideFwCfgVarName|""|VOID*|0x68
 
+  ## The base address and size of the FVMAIN
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvBaseAddress|0|UINT64|0x71
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvSize|0|UINT32|0x72
+
 [PcdsDynamic, PcdsDynamicEx]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
diff --git 
a/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.inf 
b/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.inf
new file mode 100644
index ..5b7a45d15782
--- /dev/null
+++ b/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.inf
@@ -0,0 +1,40 @@
+#/** @file
+#
+#  Component description file for VirtNorFlashDeviceTreeLib module
+#
+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#**/
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = VirtNorFlashDeviceTreeLib
+  FILE_GUID  = 42C30D8E-BFAD-4E77-9041-E7DAAE88DF7A
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = VirtNorFlashPlatformLib
+
+[Sources.common]
+  VirtNorFlashDeviceTreeLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  UefiBootServicesTableLib
+
+[Protocols]
+  gFdtClientProtocolGuid  ## CONSUMES
+
+[Depex]
+  gFdtClientProtocolGuid
+
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvBaseAddress
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFvSize
diff --git a/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashStaticLib.inf 
b/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashStaticLib.inf
new file mode 100644
index ..4e87bd437380
--- /dev/null
+++ b/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashStaticLib.inf
@@ -0,0 +1,30 @@
+#/** @file
+#
+#  Component description file for VirtNorFlashStaticLib module
+#
+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#**/
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = VirtNorFlashStaticLib
+  FILE_GUID  = 064742F1-E531-4D7D-A154-22315889CC23
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = VirtNorFlashPlatformLib
+
+[Sources.common]
+  VirtNorFlashStaticLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
diff --git 
a/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.c 
b/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.c
new file mode 100644
index ..08750e66095d
--- /dev/null
+++ b/OvmfPkg/Library/VirtNorFlashPlatformLib/VirtNorFlashDeviceTreeLib.c
@@ -0,0 +1,136 @@
+/** @file
+
+ Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ **/
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define QEMU_NOR_BLOCK_SIZE  SIZE_256KB
+
+#define MAX_FLASH_BANKS  4
+
+EFI_STATUS
+VirtNorFlashPlatformInitialization (
+  VOID
+  )
+{
+  return EFI_SUCCESS;
+}
+
+VIRT_NOR_FLASH_DESCRIPTION  mNorFlashDevices[MAX_FLASH_BANKS];
+
+EFI_STATUS
+VirtNorFlashPlatformGetDevices (
+  OUT VIRT_NOR_FLASH_DESCRIPTION  **NorFlashDescriptions,
+  OUT UINT32  *Count
+  )
+{
+  FDT_CLIENT_PROTOCOL  *FdtClient;
+  INT32

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 26/30] ArmVirtPkg: Update the references to NvVarStoreFormattedLib

2022-10-30 Thread Sunil V L
The NvVarStoreFormattedLib library is moved to MdeModulePkg.
So, updates its users with the new location.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 
Signed-off-by: Sunil V L 
---
 ArmVirtPkg/ArmVirtKvmTool.dsc| 2 +-
 ArmVirtPkg/ArmVirtQemu.dsc   | 2 +-
 ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc
index c598903b33d2..a9f8b9ec6946 100644
--- a/ArmVirtPkg/ArmVirtKvmTool.dsc
+++ b/ArmVirtPkg/ArmVirtKvmTool.dsc
@@ -258,7 +258,7 @@ [Components.common]
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf {
 
   NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf
-  
NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
+  
NULL|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   }
 
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 1d8b6dc9c04c..cd21fcb760a5 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -383,7 +383,7 @@ [Components.common]
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf {
 
   NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf
-  
NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
+  
NULL|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
   # don't use unaligned CopyMem () on the UEFI varstore NOR flash region
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   }
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index 91119c2df9c4..c9c12827ca88 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -294,7 +294,7 @@ [Components.common]
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf {
 
   NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf
-  
NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
+  
NULL|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
   # don't use unaligned CopyMem () on the UEFI varstore NOR flash region
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   }
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 25/30] EmbeddedPkg/NvVarStoreFormattedLib: Migrate to MdeModulePkg

2022-10-30 Thread Sunil V L
This library is required by NorFlashDxe. Since it will be used by
both virtual and real platforms, migrate this library to
MdeModulePkg.

Cc: Leif Lindholm 
Cc: Ard Biesheuvel 
Cc: Abner Chang 
Cc: Daniel Schaefer 
Cc: Jian J Wang 
Cc: Liming Gao 
Cc: Andrew Fish 
Cc: Michael D Kinney 
Signed-off-by: Sunil V L 
Acked-by: Ard Biesheuvel 
---
 EmbeddedPkg/EmbeddedPkg.dec
 | 3 ---
 MdeModulePkg/MdeModulePkg.dec  
 | 3 +++
 MdeModulePkg/MdeModulePkg.dsc  
 | 2 ++
 {EmbeddedPkg => 
MdeModulePkg}/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf | 1 -
 {EmbeddedPkg => MdeModulePkg}/Include/Guid/NvVarStoreFormatted.h   
 | 0
 {EmbeddedPkg => 
MdeModulePkg}/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.c   | 0
 6 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec
index 341ef5e6a679..b1f5654835f6 100644
--- a/EmbeddedPkg/EmbeddedPkg.dec
+++ b/EmbeddedPkg/EmbeddedPkg.dec
@@ -69,9 +69,6 @@ [Guids.common]
   # HII form set GUID for ConsolePrefDxe driver
   gConsolePrefFormSetGuid = { 0x2d2358b4, 0xe96c, 0x484d, { 0xb2, 0xdd, 0x7c, 
0x2e, 0xdf, 0xc7, 0xd5, 0x6f } }
 
-  ## Include/Guid/NvVarStoreFormatted.h
-  gEdkiiNvVarStoreFormattedGuid = { 0xd1a86e3f, 0x0707, 0x4c35, { 0x83, 0xcd, 
0xdc, 0x2c, 0x29, 0xc8, 0x91, 0xa3 } }
-
 [Protocols.common]
   gHardwareInterruptProtocolGuid =  { 0x2890B3EA, 0x053D, 0x1643, { 0xAD, 
0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } }
   gHardwareInterrupt2ProtocolGuid = { 0x32898322, 0x2da1, 0x474a, { 0xba, 
0xaa, 0xf3, 0xf7, 0xcf, 0x56, 0x94, 0x70 } }
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 58e6ab004882..492bff8b7890 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -412,6 +412,9 @@ [Guids]
   ## Include/Guid/MigratedFvInfo.h
   gEdkiiMigratedFvInfoGuid = { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4, 0xc6, 
0xce, 0xfd, 0x17, 0x98, 0x71 } }
 
+  ## Include/Guid/NvVarStoreFormatted.h
+  gEdkiiNvVarStoreFormattedGuid = { 0xd1a86e3f, 0x0707, 0x4c35, { 0x83, 0xcd, 
0xdc, 0x2c, 0x29, 0xc8, 0x91, 0xa3 } }
+
   #
   # GUID defined in UniversalPayload
   #
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 659482ab737f..4142e1178dcd 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -104,6 +104,7 @@ [LibraryClasses]
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
+  
NvVarStoreFormattedLib|MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
 
 [LibraryClasses.EBC.PEIM]
   IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
@@ -443,6 +444,7 @@ [Components]
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
   MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
+  MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
 
 [Components.IA32, Components.X64, Components.AARCH64]
   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
diff --git 
a/EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf 
b/MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
similarity index 96%
rename from 
EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
rename to MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
index e2eed26c5b2d..5e8cd94cc9e0 100644
--- a/EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
+++ b/MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
@@ -32,7 +32,6 @@ [Sources]
   NvVarStoreFormattedLib.c
 
 [Packages]
-  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
 
diff --git a/EmbeddedPkg/Include/Guid/NvVarStoreFormatted.h 
b/MdeModulePkg/Include/Guid/NvVarStoreFormatted.h
similarity index 100%
rename from EmbeddedPkg/Include/Guid/NvVarStoreFormatted.h
rename to MdeModulePkg/Include/Guid/NvVarStoreFormatted.h
diff --git 
a/EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.c 
b/MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.c
similarity index 100%
rename from EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.c
rename to MdeModulePkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.c
-- 
2.38.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95751): https://edk2.groups.io/g/devel/message/95751
Mute This Topic: https://groups.io/mt/94664340/21656
Group Owner: devel+ow...@edk2.groups.io

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 24/30] ArmVirtPkg: Fix up the paths to PlatformBootManagerLib

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

PlatformBootManagerLib has been moved to OvmfPkg so that other
CPU architectures can reuse. So, update existing paths with the
new location.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 
Signed-off-by: Sunil V L 
---
 ArmVirtPkg/ArmVirtQemu.dsc   | 4 ++--
 ArmVirtPkg/ArmVirtQemuKernel.dsc | 4 ++--
 ArmVirtPkg/ArmVirtPkg.ci.yaml| 1 -
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 2ed1e15a08ca..1d8b6dc9c04c 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -69,7 +69,7 @@ [LibraryClasses.common]
 
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
   BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
-  
PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+  
PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib.inf
   
PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
   
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
@@ -173,7 +173,7 @@ [PcdsFixedAtBuild.common]
 !if $(TTY_TERMINAL) == TRUE
   gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4
   # Set terminal type to TtyTerm, the value encoded is EFI_TTY_TERM_GUID
-  gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, 0x7d, 
0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x94}
+  gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, 
0x7d, 0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x94}
 !else
   gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|1
 !endif
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index d6f4ac5166d7..91119c2df9c4 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -69,7 +69,7 @@ [LibraryClasses.common]
 
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
   BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
-  
PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+  
PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib.inf
   
PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
   
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
@@ -146,7 +146,7 @@ [PcdsFixedAtBuild.common]
 !if $(TTY_TERMINAL) == TRUE
   gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4
   # Set terminal type to TtyTerm, the value encoded is EFI_TTY_TERM_GUID
-  gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, 0x7d, 
0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x94}
+  gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x80, 0x6d, 0x91, 
0x7d, 0xb1, 0x5b, 0x8c, 0x45, 0xa4, 0x8f, 0xe2, 0x5f, 0xdd, 0x51, 0xef, 0x94}
 !else
   gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|1
 !endif
diff --git a/ArmVirtPkg/ArmVirtPkg.ci.yaml b/ArmVirtPkg/ArmVirtPkg.ci.yaml
index 1e799dc4e194..552511c2694e 100644
--- a/ArmVirtPkg/ArmVirtPkg.ci.yaml
+++ b/ArmVirtPkg/ArmVirtPkg.ci.yaml
@@ -24,7 +24,6 @@
 ],
 ## Both file path and directory path are accepted.
 "IgnoreFiles": [
-"Library/PlatformBootManagerLib/PlatformBm.c"
 ]
 },
 ## options defined .pytool/Plugin/CompilerPlugin
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 23/30] ArmVirtPkg/PlatformBootManagerLib: Move to OvmfPkg

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

PlatformBootManagerLib in ArmVirtPkg is required for RISC-V
also. So, move it to OvmfPkg.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Signed-off-by: Sunil V L 
---
 OvmfPkg/OvmfPkg.dec
  | 7 +++
 {ArmVirtPkg/Library/PlatformBootManagerLib => 
OvmfPkg/Library/PlatformBootManagerLibVirt}/PlatformBootManagerLib.inf | 3 +--
 {ArmVirtPkg/Library/PlatformBootManagerLib => 
OvmfPkg/Library/PlatformBootManagerLibVirt}/PlatformBm.h   | 0
 {ArmVirtPkg/Library/PlatformBootManagerLib => 
OvmfPkg/Library/PlatformBootManagerLibVirt}/PlatformBm.c   | 0
 {ArmVirtPkg/Library/PlatformBootManagerLib => 
OvmfPkg/Library/PlatformBootManagerLibVirt}/QemuKernel.c   | 0
 OvmfPkg/OvmfPkg.ci.yaml
  | 1 +
 6 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 7df05770b5d6..ba5194114c5c 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -467,6 +467,13 @@ [PcdsDynamic, PcdsDynamicEx]
   #
   gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|0x0|BOOLEAN|0x69
 
+  #
+  # Binary representation of the GUID that determines the terminal type. The
+  # size must be exactly 16 bytes. The default value corresponds to
+  # EFI_VT_100_GUID.
+  #
+  gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer|{0x65, 0x60, 0xA6, 
0xDF, 0x19, 0xB4, 0xD3, 0x11, 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 
0x4D}|VOID*|0x70
+
 [PcdsFeatureFlag]
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0x1c
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN|0x1d
diff --git 
a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 
b/OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib.inf
similarity index 92%
rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
rename to OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib.inf
index 997eb1a4429f..a747ea3feac0 100644
--- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBootManagerLib.inf
@@ -29,7 +29,6 @@ [Sources]
   QemuKernel.c
 
 [Packages]
-  ArmVirtPkg/ArmVirtPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   OvmfPkg/OvmfPkg.dec
@@ -61,7 +60,7 @@ [FixedPcd]
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits
 
 [Pcd]
-  gArmVirtTokenSpaceGuid.PcdTerminalTypeGuidBuffer
+  gUefiOvmfPkgTokenSpaceGuid.PcdTerminalTypeGuidBuffer
   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
 
 [Guids]
diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.h 
b/OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBm.h
similarity index 100%
rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.h
rename to OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBm.h
diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c 
b/OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBm.c
similarity index 100%
rename from ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
rename to OvmfPkg/Library/PlatformBootManagerLibVirt/PlatformBm.c
diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c 
b/OvmfPkg/Library/PlatformBootManagerLibVirt/QemuKernel.c
similarity index 100%
rename from ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c
rename to OvmfPkg/Library/PlatformBootManagerLibVirt/QemuKernel.c
diff --git a/OvmfPkg/OvmfPkg.ci.yaml b/OvmfPkg/OvmfPkg.ci.yaml
index ff022242b018..c6efb9a8e59e 100644
--- a/OvmfPkg/OvmfPkg.ci.yaml
+++ b/OvmfPkg/OvmfPkg.ci.yaml
@@ -22,6 +22,7 @@
 ],
 ## Both file path and directory path are accepted.
 "IgnoreFiles": [
+"Library/PlatformBootManagerLibVirt/PlatformBm.c"
 ],
 "skip": True
 },
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 22/30] ArmVirtPkg: Fix up the location of PlatformHasAcpiDtDxe

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

PlatformHasAcpiDtDxe is required by other architectures also.
Hence, it is moved to OvmfPkg. So, update the consumers of this
module with the new location.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 
Signed-off-by: Sunil V L 
---
 ArmVirtPkg/ArmVirtCloudHv.dsc  | 2 +-
 ArmVirtPkg/ArmVirtQemu.dsc | 4 ++--
 ArmVirtPkg/ArmVirtQemuKernel.dsc   | 2 +-
 ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf | 2 +-
 ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf   | 2 +-
 ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc   | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc
index 7ca7a391d9cf..c975e139a216 100644
--- a/ArmVirtPkg/ArmVirtCloudHv.dsc
+++ b/ArmVirtPkg/ArmVirtCloudHv.dsc
@@ -198,7 +198,7 @@ [PcdsDynamicDefault.common]
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress|0x0
 
 [PcdsDynamicHii]
-  
gArmVirtTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gArmVirtVariableGuid|0x0|FALSE|NV,BS
+  
gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gOvmfVariableGuid|0x0|FALSE|NV,BS
 
 

 #
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index f77443229e8e..2ed1e15a08ca 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -300,7 +300,7 @@ [PcdsPatchableInModule]
 !endif
 
 [PcdsDynamicHii]
-  
gArmVirtTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gArmVirtVariableGuid|0x0|FALSE|NV,BS
+  
gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gOvmfVariableGuid|0x0|FALSE|NV,BS
 
 !if $(TPM2_CONFIG_ENABLE) == TRUE
   
gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer|L"TCG2_VERSION"|gTcg2ConfigFormSetGuid|0x0|"1.3"|NV,BS
@@ -569,7 +569,7 @@ [Components.common]
   #
   # ACPI Support
   #
-  ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
+  OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
 [Components.AARCH64]
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
   OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf {
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index f5db3ac432f3..d6f4ac5166d7 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -457,7 +457,7 @@ [Components.common]
   #
   # ACPI Support
   #
-  ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
+  OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
 [Components.AARCH64]
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
   OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf {
diff --git a/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf 
b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf
index 4af06b2a6746..7cad40e11f33 100644
--- a/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf
+++ b/ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf
@@ -36,7 +36,7 @@ [Guids]
   gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL
 
 [Pcd]
-  gArmVirtTokenSpaceGuid.PcdForceNoAcpi
+  gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi
 
 [Depex]
   gEfiVariableArchProtocolGuid
diff --git a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf 
b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf
index 1cf25780f830..5888fcdc0b26 100644
--- a/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf
+++ b/ArmVirtPkg/KvmtoolPlatformDxe/KvmtoolPlatformDxe.inf
@@ -37,7 +37,7 @@ [Guids]
   gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL
 
 [Pcd]
-  gArmVirtTokenSpaceGuid.PcdForceNoAcpi
+  gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi
 
 [Depex]
   TRUE
diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc 
b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
index e06ca7424476..8a063bac04ac 100644
--- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
+++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
@@ -141,7 +141,7 @@ [FV.FvMain]
   #
   # ACPI Support
   #
-  INF ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
+  INF OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
 !if $(ARCH) == AARCH64
   INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
   INF 
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 21/30] ArmVirtPkg/PlatformHasAcpiDtDxe: Move to OvmfPkg

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This module is required by other architectures like RISC-V.
Hence, move this to OvmfPkg.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Signed-off-by: Sunil V L 
---
 ArmVirtPkg/ArmVirtPkg.dec | 9 
-
 OvmfPkg/OvmfPkg.dec   | 7 
+++
 {ArmVirtPkg => OvmfPkg}/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf | 3 +--
 {ArmVirtPkg => OvmfPkg}/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c   | 0
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec
index 89d21ec3a364..4645c91a8375 100644
--- a/ArmVirtPkg/ArmVirtPkg.dec
+++ b/ArmVirtPkg/ArmVirtPkg.dec
@@ -34,8 +34,6 @@ [Guids.common]
   gEarly16550UartBaseAddressGuid   = { 0xea67ca3e, 0x1f54, 0x436b, { 0x97, 
0x88, 0xd4, 0xeb, 0x29, 0xc3, 0x42, 0x67 } }
   gArmVirtSystemMemorySizeGuid = { 0x504eccb9, 0x1bf0, 0x4420, { 0x86, 
0x5d, 0xdc, 0x66, 0x06, 0xd4, 0x13, 0xbf } }
 
-  gArmVirtVariableGuid   = { 0x50bea1e5, 0xa2c5, 0x46e9, { 0x9b, 0x3a, 0x59, 
0x59, 0x65, 0x16, 0xb0, 0x0a } }
-
 [PcdsFeatureFlag]
   #
   # Feature Flag PCD that defines whether TPM2 support is enabled
@@ -69,10 +67,3 @@ [PcdsFixedAtBuild, PcdsPatchableInModule]
   # Cloud Hypervisor has no other way to pass Rsdp address to the guest except 
use a PCD.
   #
   gArmVirtTokenSpaceGuid.PcdCloudHvAcpiRsdpBaseAddress|0x0|UINT64|0x0005
-
-[PcdsDynamic]
-  #
-  # Whether to force disable ACPI, regardless of the fw_cfg settings
-  # exposed by QEMU
-  #
-  gArmVirtTokenSpaceGuid.PcdForceNoAcpi|0x0|BOOLEAN|0x0003
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 5f5556c67c6c..7df05770b5d6 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -151,6 +151,7 @@ [Guids]
   gConfidentialComputingSevSnpBlobGuid  = {0x067b1f5f, 0xcf26, 0x44c5, {0x85, 
0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42}}
   gUefiOvmfPkgPlatformInfoGuid  = {0xdec9b486, 0x1f16, 0x47c7, {0x8f, 
0x68, 0xdf, 0x1a, 0x41, 0x88, 0x8b, 0xa5}}
   gVMMBootOrderGuid = {0x668f4529, 0x63d0, 0x4bb5, {0xb6, 
0x5d, 0x6f, 0xbb, 0x9d, 0x36, 0xa4, 0x4a}}
+  gOvmfVariableGuid = {0x50bea1e5, 0xa2c5, 0x46e9, {0x9b, 
0x3a, 0x59, 0x59, 0x65, 0x16, 0xb0, 0x0a}}
 
 [Ppis]
   # PPI whose presence in the PPI database signals that the TPM base address
@@ -460,6 +461,12 @@ [PcdsDynamic, PcdsDynamicEx]
   ## This PCD records LASA field in CC EVENTLOG ACPI table.
   gUefiOvmfPkgTokenSpaceGuid.PcdCcEventlogAcpiTableLasa|0|UINT64|0x67
 
+  #
+  # Whether to force disable ACPI, regardless of the fw_cfg settings
+  # exposed by QEMU
+  #
+  gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|0x0|BOOLEAN|0x69
+
 [PcdsFeatureFlag]
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0x1c
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN|0x1d
diff --git a/ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf 
b/OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
similarity index 89%
rename from ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
rename to OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
index e900aa992661..85873f73b2eb 100644
--- a/ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
+++ b/OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
@@ -19,7 +19,6 @@ [Sources]
   PlatformHasAcpiDtDxe.c
 
 [Packages]
-  ArmVirtPkg/ArmVirtPkg.dec
   EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
@@ -38,7 +37,7 @@ [Guids]
   gEdkiiPlatformHasDeviceTreeGuid ## SOMETIMES_PRODUCES ## PROTOCOL
 
 [Pcd]
-  gArmVirtTokenSpaceGuid.PcdForceNoAcpi
+  gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi
 
 [Depex]
   gEfiVariableArchProtocolGuid
diff --git a/ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c 
b/OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c
similarity index 100%
rename from ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c
rename to OvmfPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.c
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 20/30] UefiCpuPkg: Add CpuTimerDxe module

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This DXE module initializes the timer interrupt handler
and installs the Arch Timer protocol.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Daniel Schaefer 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 UefiCpuPkg/UefiCpuPkg.dsc|   3 +
 UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf   |  51 
 UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h   | 177 
 UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.c   | 294 
 UefiCpuPkg/CpuTimerDxe/CpuTimer.uni  |  14 +
 UefiCpuPkg/CpuTimerDxe/CpuTimerExtra.uni |  12 +
 6 files changed, 551 insertions(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index aaf761fdcf48..a783e261e604 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -187,5 +187,8 @@ [Components.IA32, Components.X64]
 [Components.X64]
   
UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf
 
+[Components.RISCV64]
+  UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf
+
 [BuildOptions]
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
diff --git a/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf 
b/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf
new file mode 100644
index ..d7706328b591
--- /dev/null
+++ b/UefiCpuPkg/CpuTimerDxe/CpuTimerDxe.inf
@@ -0,0 +1,51 @@
+## @file
+# Timer Arch protocol module
+#
+# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x0001001b
+  BASE_NAME  = CpuTimerDxe
+  MODULE_UNI_FILE= CpuTimer.uni
+  FILE_GUID  = 055DDAC6-9142-4013-BF20-FC2E5BC325C9
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  ENTRY_POINT= TimerDriverInitialize
+#
+# The following information is for reference only and not required by the build
+# tools.
+#
+#  VALID_ARCHITECTURES   = RISCV64
+#
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  IoLib
+  CpuLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+
+[LibraryClasses.RISCV64]
+  RiscVSbiLib
+
+[Sources.RISCV64]
+  RiscV64/Timer.h
+  RiscV64/Timer.c
+
+[Protocols]
+  gEfiCpuArchProtocolGuid   ## CONSUMES
+  gEfiTimerArchProtocolGuid ## PRODUCES
+
+[Depex]
+  gEfiCpuArchProtocolGuid
+
+[UserExtensions.TianoCore."ExtraFiles"]
+  CpuTimerExtra.uni
diff --git a/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h 
b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h
new file mode 100644
index ..586eb0cfadb4
--- /dev/null
+++ b/UefiCpuPkg/CpuTimerDxe/RiscV64/Timer.h
@@ -0,0 +1,177 @@
+/** @file
+  RISC-V Timer Architectural Protocol definitions
+
+  Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef TIMER_H_
+#define TIMER_H_
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+//
+// RISC-V use 100us timer.
+// The default timer tick duration is set to 10 ms = 10 * 1000 * 10 100 ns 
units
+//
+#define DEFAULT_TIMER_TICK_DURATION  10
+
+extern VOID
+RiscvSetTimerPeriod (
+  UINT32  TimerPeriod
+  );
+
+//
+// Function Prototypes
+//
+
+/**
+  Initialize the Timer Architectural Protocol driver
+
+  @param ImageHandle ImageHandle of the loaded driver
+  @param SystemTable Pointer to the System Table
+
+  @retval EFI_SUCCESSTimer Architectural Protocol created
+  @retval EFI_OUT_OF_RESOURCES   Not enough resources available to initialize 
driver.
+  @retval EFI_DEVICE_ERROR   A device error occured attempting to 
initialize the driver.
+
+**/
+EFI_STATUS
+EFIAPI
+TimerDriverInitialize (
+  IN EFI_HANDLEImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+;
+
+/**
+
+  This function adjusts the period of timer interrupts to the value specified
+  by TimerPeriod.  If the timer period is updated, then the selected timer
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
+  If an error occurs while attempting to update the timer period, then the
+  timer hardware will be put back in its state prior to this call, and
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt
+  is disabled.  This is not the same as disabling the CPU's interrupts.
+  Instead, it must either turn off the timer hardware, or it must adjust the
+  interrupt controller so that a CPU interrupt is not generated when the timer
+  interrupt fires.
+
+
+  @param ThisThe EFI_TIMER_ARCH_PROTOCOL instance.
+  @param NotifyFunction  The rate to program the timer interrupt in 100 nS 
units.  If
+ the timer hardware is not programmable, then 
EFI_UNSUPPORTED is
+ 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 19/30] UefiCpuPkg/CpuDxe: Add RISCV_EFI_BOOT_PROTOCOL support

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

RISC-V UEFI platforms need to support RISCV_EFI_BOOT_PROTOCOL.
Add the support for this protocol which is defined in the spec:
https://github.com/riscv-non-isa/riscv-uefi/releases/download/1.0.0/RISCV_UEFI_PROTOCOL-spec.pdf

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Daniel Schaefer 
Cc: Abner Chang 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 UefiCpuPkg/UefiCpuPkg.dsc  | 12 ++--
 UefiCpuPkg/CpuDxe/CpuDxe.inf   |  3 +
 UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c | 66 ++--
 3 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index 0e1a99ddc09f..aaf761fdcf48 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -125,9 +125,13 @@ [Components]
   UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf
   UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf
   UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.inf
-
-[Components.IA32, Components.X64]
   UefiCpuPkg/CpuDxe/CpuDxe.inf
+  UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+!if $(TOOL_CHAIN_TAG) != "XCODE5"
+  UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
+!endif
+
+[Components.IA32, Components.X64]
   UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf {
 
   NULL|UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
@@ -144,10 +148,6 @@ [Components.IA32, Components.X64]
   UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
   UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
   UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
-  UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
-!if $(TOOL_CHAIN_TAG) != "XCODE5"
-  UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
-!endif
   UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
   UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
   
UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf
index eddc86a38965..857b84ac3122 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.inf
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf
@@ -74,6 +74,9 @@ [Protocols]
   gEfiMpServiceProtocolGuid ## PRODUCES
   gEfiSmmBase2ProtocolGuid  ## SOMETIMES_CONSUMES
 
+[Protocols.RISCV64]
+  gRiscVEfiBootProtocolGuid ## PRODUCES
+
 [Guids]
   gIdleLoopEventGuid## CONSUMES   ## Event
   gEfiVectorHandoffTableGuid## SOMETIMES_CONSUMES ## 
SystemTable
diff --git a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c 
b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c
index 9f557b776a09..7551e0653603 100644
--- a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c
+++ b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c
@@ -2,6 +2,7 @@
   RISC-V CPU DXE driver.
 
   Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All 
rights reserved.
+  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -12,8 +13,41 @@
 //
 // Global Variables
 //
-STATIC BOOLEAN mInterruptState = FALSE;
-STATIC EFI_HANDLE  mCpuHandle  = NULL;
+STATIC BOOLEAN   mInterruptState = FALSE;
+STATIC EFI_HANDLEmCpuHandle  = NULL;
+STATIC UINTN mBootHartId;
+RISCV_EFI_BOOT_PROTOCOL  gRiscvBootProtocol;
+
+/**
+  Get the boot hartid
+
+  @param  This   Protocol instance structure
+  @param  BootHartId Pointer to the Boot Hart ID variable
+
+  @retval EFI_SUCCESSIf BootHartId is returned
+  @retval EFI_INVALID_PARAMETER  Either "BootHartId" is NULL or "This" is not
+ a valid RISCV_EFI_BOOT_PROTOCOL instance.
+
+**/
+EFI_STATUS
+EFIAPI
+RiscvGetBootHartId (
+  IN RISCV_EFI_BOOT_PROTOCOL  *This,
+  OUT UINTN   *BootHartId
+  )
+{
+  if ((This != ) || (BootHartId == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  *BootHartId = mBootHartId;
+  return EFI_SUCCESS;
+}
+
+RISCV_EFI_BOOT_PROTOCOL  gRiscvBootProtocol = {
+  RISCV_EFI_BOOT_PROTOCOL_LATEST_VERSION,
+  RiscvGetBootHartId
+};
 
 EFI_CPU_ARCH_PROTOCOL  gCpu = {
   CpuFlushCpuDataCache,
@@ -284,15 +318,39 @@ InitializeCpu (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_STATUS  Status;
+  EFI_STATUS  Status;
+  EFI_RISCV_FIRMWARE_CONTEXT  *FirmwareContext;
 
-  InitializeCpuExceptionHandlers(NULL);
+  GetFirmwareContextPointer ();
+  ASSERT (FirmwareContext != NULL);
+  if (FirmwareContext == NULL) {
+DEBUG ((DEBUG_ERROR, "Failed to get the pointer of 
EFI_RISCV_FIRMWARE_CONTEXT\n"));
+return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((DEBUG_INFO, " %a: Firmware Context is at 0x%x.\n", __FUNCTION__, 
FirmwareContext));
+
+  mBootHartId = FirmwareContext->BootHartId;
+  DEBUG ((DEBUG_INFO, " %a: 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 18/30] UefiCpuPkg/CpuDxe: Add support for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This is copied from
edk2-platforms/Silicon/RISC-V/ProcessorPkg/Universal/CpuDxe

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Daniel Schaefer 
Signed-off-by: Sunil V L 
---
 UefiCpuPkg/CpuDxe/CpuDxe.inf   |  10 +
 UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h | 199 +
 UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.c | 307 
 3 files changed, 516 insertions(+)

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf
index 65961813f74b..eddc86a38965 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.inf
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf
@@ -44,6 +44,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
   MtrrLib
   UefiCpuLib
 
+[LibraryClasses.RISCV64]
+  RiscVSbiLib
+
 [Sources.IA32, Sources.X64]
   Ia32X64/CpuDxe.c
   Ia32X64/CpuDxe.h
@@ -62,6 +65,10 @@ [Sources.X64]
   X64/CpuAsm.nasm
   X64/PagingAttribute.c
 
+[Sources.RISCV64]
+  RiscV64/CpuDxe.c
+  RiscV64/CpuDxe.h
+
 [Protocols]
   gEfiCpuArchProtocolGuid   ## PRODUCES
   gEfiMpServiceProtocolGuid ## PRODUCES
@@ -84,6 +91,9 @@ [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask## 
CONSUMES
 
+[Pcd.RISCV64]
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## 
CONSUMES
+
 [Depex]
   TRUE
 
diff --git a/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h 
b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h
new file mode 100644
index ..49f4e119665a
--- /dev/null
+++ b/UefiCpuPkg/CpuDxe/RiscV64/CpuDxe.h
@@ -0,0 +1,199 @@
+/** @file
+  RISC-V CPU DXE module header file.
+
+  Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All 
rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef CPU_DXE_H_
+#define CPU_DXE_H_
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Flush CPU data cache. If the instruction cache is fully coherent
+  with all DMA operations then function can just return EFI_SUCCESS.
+
+  @param  This  Protocol instance structure
+  @param  Start Physical address to start flushing from.
+  @param  LengthNumber of bytes to flush. Round up to chipset
+granularity.
+  @param  FlushType Specifies the type of flush operation to perform.
+
+  @retval EFI_SUCCESS   If cache was flushed
+  @retval EFI_UNSUPPORTED   If flush type is not supported.
+  @retval EFI_DEVICE_ERROR  If requested range could not be flushed.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuFlushCpuDataCache (
+  IN EFI_CPU_ARCH_PROTOCOL  *This,
+  IN EFI_PHYSICAL_ADDRESS   Start,
+  IN UINT64 Length,
+  IN EFI_CPU_FLUSH_TYPE FlushType
+  );
+
+/**
+  Enables CPU interrupts.
+
+  @param  This  Protocol instance structure
+
+  @retval EFI_SUCCESS   If interrupts were enabled in the CPU
+  @retval EFI_DEVICE_ERROR  If interrupts could not be enabled on the CPU.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuEnableInterrupt (
+  IN EFI_CPU_ARCH_PROTOCOL  *This
+  );
+
+/**
+  Disables CPU interrupts.
+
+  @param  This  Protocol instance structure
+
+  @retval EFI_SUCCESS   If interrupts were disabled in the CPU.
+  @retval EFI_DEVICE_ERROR  If interrupts could not be disabled on the CPU.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuDisableInterrupt (
+  IN EFI_CPU_ARCH_PROTOCOL  *This
+  );
+
+/**
+  Return the state of interrupts.
+
+  @param  This   Protocol instance structure
+  @param  State  Pointer to the CPU's current interrupt state
+
+  @retval EFI_SUCCESSIf interrupts were disabled in the CPU.
+  @retval EFI_INVALID_PARAMETER  State is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuGetInterruptState (
+  IN  EFI_CPU_ARCH_PROTOCOL  *This,
+  OUT BOOLEAN*State
+  );
+
+/**
+  Generates an INIT to the CPU.
+
+  @param  This  Protocol instance structure
+  @param  InitType  Type of CPU INIT to perform
+
+  @retval EFI_SUCCESS   If CPU INIT occurred. This value should never be
+seen.
+  @retval EFI_DEVICE_ERROR  If CPU INIT failed.
+  @retval EFI_UNSUPPORTED   Requested type of CPU INIT not supported.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuInit (
+  IN EFI_CPU_ARCH_PROTOCOL  *This,
+  IN EFI_CPU_INIT_TYPE  InitType
+  );
+
+/**
+  Registers a function to be called from the CPU interrupt handler.
+
+  @param  This   Protocol instance structure
+  @param  InterruptType  Defines which interrupt to hook. IA-32
+ valid range is 0x00 through 0xFF
+  @param  InterruptHandler   A pointer to a function of type
+ EFI_CPU_INTERRUPT_HANDLER that is called
+ when a processor interrupt occurs.  A null
+ pointer is an error 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 17/30] UefiCpuPkg/CpuDxe: Refactor to allow other architectures

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Currently, CpuDxe supports only X86 architecture. To add
support for other architectures like RISC-V, this need to
be refactored.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Signed-off-by: Sunil V L 
---
 UefiCpuPkg/CpuDxe/CpuDxe.inf   | 28 +++-
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuDxe.h   |  0
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuGdt.h   |  0
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuMp.h|  0
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuPageTable.h |  0
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuDxe.c   |  0
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuGdt.c   |  0
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuMp.c|  0
 UefiCpuPkg/CpuDxe/{ => Ia32X64}/CpuPageTable.c |  0
 9 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf
index 235241899222..65961813f74b 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.inf
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf
@@ -29,28 +29,30 @@ [LibraryClasses]
   DebugLib
   DxeServicesTableLib
   MemoryAllocationLib
-  MtrrLib
   UefiBootServicesTableLib
   UefiDriverEntryPoint
-  LocalApicLib
-  UefiCpuLib
   UefiLib
   CpuExceptionHandlerLib
   HobLib
   ReportStatusCodeLib
-  MpInitLib
   TimerLib
   PeCoffGetEntryPointLib
 
-[Sources]
-  CpuDxe.c
-  CpuDxe.h
-  CpuGdt.c
-  CpuGdt.h
-  CpuMp.c
-  CpuMp.h
-  CpuPageTable.h
-  CpuPageTable.c
+[LibraryClasses.IA32, LibraryClasses.X64]
+  LocalApicLib
+  MpInitLib
+  MtrrLib
+  UefiCpuLib
+
+[Sources.IA32, Sources.X64]
+  Ia32X64/CpuDxe.c
+  Ia32X64/CpuDxe.h
+  Ia32X64/CpuGdt.c
+  Ia32X64/CpuGdt.h
+  Ia32X64/CpuMp.c
+  Ia32X64/CpuMp.h
+  Ia32X64/CpuPageTable.h
+  Ia32X64/CpuPageTable.c
 
 [Sources.IA32]
   Ia32/CpuAsm.nasm
diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/Ia32X64/CpuDxe.h
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuDxe.h
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuDxe.h
diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/CpuDxe/Ia32X64/CpuGdt.h
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuGdt.h
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuGdt.h
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/Ia32X64/CpuMp.h
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuMp.h
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuMp.h
diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.h 
b/UefiCpuPkg/CpuDxe/Ia32X64/CpuPageTable.h
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuPageTable.h
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuPageTable.h
diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/Ia32X64/CpuDxe.c
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuDxe.c
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuDxe.c
diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/Ia32X64/CpuGdt.c
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuGdt.c
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuGdt.c
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/Ia32X64/CpuMp.c
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuMp.c
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuMp.c
diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c 
b/UefiCpuPkg/CpuDxe/Ia32X64/CpuPageTable.c
similarity index 100%
rename from UefiCpuPkg/CpuDxe/CpuPageTable.c
rename to UefiCpuPkg/CpuDxe/Ia32X64/CpuPageTable.c
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 16/30] UefiCpuPkg/CpuExceptionHandlerLib: Add support for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Daniel Schaefer 
Cc: Abner Chang 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf|   
7 +-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf |   
7 +-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib.h | 
116 +
 UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib.c | 
133 
 UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHandler.S  | 
105 
 5 files changed, 366 insertions(+), 2 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
index 8fdf2b756c2c..b24140d1f26b 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
@@ -18,7 +18,7 @@ [Defines]
 #
 # The following information is for reference only and not required by the 
build tools.
 #
-#  VALID_ARCHITECTURES   = IA32 X64
+#  VALID_ARCHITECTURES   = IA32 X64 RISCV64
 #
 
 [Sources.Ia32]
@@ -38,6 +38,11 @@ [Sources.IA32, Sources.X64]
   Ia32X64/PeiDxeSmmCpuException.c
   Ia32X64/DxeException.c
 
+[Sources.RISCV64]
+  RiscV64/SupervisorTrapHandler.S
+  RiscV64/CpuExceptionHandlerLib.c
+  RiscV64/CpuExceptionHandlerLib.h
+
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
   gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
index 79911b21f62d..60c92ecf65bf 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
@@ -18,7 +18,7 @@ [Defines]
 #
 # The following information is for reference only and not required by the 
build tools.
 #
-#  VALID_ARCHITECTURES   = IA32 X64
+#  VALID_ARCHITECTURES   = IA32 X64 RISCV64
 #
 
 [Sources.Ia32]
@@ -37,6 +37,11 @@ [Sources.IA32, Sources.X64]
   Ia32X64/CpuExceptionCommon.c
   Ia32X64/SecPeiCpuException.c
 
+[Sources.RISCV64]
+  RiscV64/SupervisorTrapHandler.S
+  RiscV64/CpuExceptionHandlerLib.c
+  RiscV64/CpuExceptionHandlerLib.h
+
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib.h 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib.h
new file mode 100644
index ..30f47e87552b
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib.h
@@ -0,0 +1,116 @@
+/** @file
+
+  RISC-V Exception Handler library definition file.
+
+  Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. All 
rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_CPU_EXECPTION_HANDLER_LIB_H_
+#define RISCV_CPU_EXECPTION_HANDLER_LIB_H_
+
+#include 
+
+/**
+  Trap Handler for S-mode
+
+**/
+VOID
+SupervisorModeTrap (
+  VOID
+  );
+
+//
+// Index of SMode trap register
+//
+#define SMODE_TRAP_REGS_zero 0
+#define SMODE_TRAP_REGS_ra   1
+#define SMODE_TRAP_REGS_sp   2
+#define SMODE_TRAP_REGS_gp   3
+#define SMODE_TRAP_REGS_tp   4
+#define SMODE_TRAP_REGS_t0   5
+#define SMODE_TRAP_REGS_t1   6
+#define SMODE_TRAP_REGS_t2   7
+#define SMODE_TRAP_REGS_s0   8
+#define SMODE_TRAP_REGS_s1   9
+#define SMODE_TRAP_REGS_a0   10
+#define SMODE_TRAP_REGS_a1   11
+#define SMODE_TRAP_REGS_a2   12
+#define SMODE_TRAP_REGS_a3   13
+#define SMODE_TRAP_REGS_a4   14
+#define SMODE_TRAP_REGS_a5   15
+#define SMODE_TRAP_REGS_a6   16
+#define SMODE_TRAP_REGS_a7   17
+#define SMODE_TRAP_REGS_s2   18
+#define SMODE_TRAP_REGS_s3   19
+#define SMODE_TRAP_REGS_s4   20
+#define SMODE_TRAP_REGS_s5   21
+#define SMODE_TRAP_REGS_s6   22
+#define SMODE_TRAP_REGS_s7   23
+#define SMODE_TRAP_REGS_s8   24
+#define SMODE_TRAP_REGS_s9   25
+#define SMODE_TRAP_REGS_s10  26
+#define SMODE_TRAP_REGS_s11  27
+#define SMODE_TRAP_REGS_t3   28
+#define SMODE_TRAP_REGS_t4   29
+#define SMODE_TRAP_REGS_t5   30
+#define SMODE_TRAP_REGS_t6   31
+#define SMODE_TRAP_REGS_sepc 32
+#define SMODE_TRAP_REGS_sstatus  33
+#define SMODE_TRAP_REGS_sie  34
+#define SMODE_TRAP_REGS_last 35
+
+#define SMODE_TRAP_REGS_OFFSET(x)  ((SMODE_TRAP_REGS_##x) * __SIZEOF_POINTER__)
+#define SMODE_TRAP_REGS_SIZE  SMODE_TRAP_REGS_OFFSET(last)
+
+#pragma pack(1)
+typedef struct {
+  //
+  // Below are follow the format of EFI_SYSTEM_CONTEXT
+  //
+  UINT64zero;
+  UINT64ra;
+  UINT64

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 15/30] UefiCpuPkg/CpuExceptionHandlerLib: Refactor to allow other architectures

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Currently, the CpuExceptionHandlerLib library supports only X86.
Refactor the library to allow adding other CPU architectures.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Signed-off-by: Sunil V L 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
  | 14 --
 UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
  |  8 
 UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf 
  | 12 +++-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
  |  8 
 
UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
 |  6 +++---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/{ => Ia32X64}/CpuExceptionCommon.h   
  |  0
 UefiCpuPkg/Library/CpuExceptionHandlerLib/{ => Ia32X64}/CpuExceptionCommon.c   
  |  0
 UefiCpuPkg/Library/CpuExceptionHandlerLib/{ => Ia32X64}/DxeException.c 
  |  0
 UefiCpuPkg/Library/CpuExceptionHandlerLib/{ => Ia32X64}/PeiCpuException.c  
  |  0
 UefiCpuPkg/Library/CpuExceptionHandlerLib/{ => 
Ia32X64}/PeiDxeSmmCpuException.c  |  0
 UefiCpuPkg/Library/CpuExceptionHandlerLib/{ => Ia32X64}/SecPeiCpuException.c   
  |  0
 UefiCpuPkg/Library/CpuExceptionHandlerLib/{ => Ia32X64}/SmmException.c 
  |  0
 12 files changed, 26 insertions(+), 22 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
index e7a81bebdb13..8fdf2b756c2c 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
@@ -32,11 +32,11 @@ [Sources.X64]
   X64/ArchExceptionHandler.c
   X64/ArchInterruptDefs.h
 
-[Sources.common]
-  CpuExceptionCommon.h
-  CpuExceptionCommon.c
-  PeiDxeSmmCpuException.c
-  DxeException.c
+[Sources.IA32, Sources.X64]
+  Ia32X64/CpuExceptionCommon.h
+  Ia32X64/CpuExceptionCommon.c
+  Ia32X64/PeiDxeSmmCpuException.c
+  Ia32X64/DxeException.c
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
@@ -56,8 +56,10 @@ [LibraryClasses]
   SerialPortLib
   PrintLib
   SynchronizationLib
-  LocalApicLib
   PeCoffGetEntryPointLib
   MemoryAllocationLib
   DebugLib
+
+[LibraryClasses.IA32, LibraryClasses.X64]
+  LocalApicLib
   VmgExitLib
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
index 7c2ec3b2db4c..af4899e6885e 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
@@ -33,10 +33,10 @@ [Sources.X64]
   X64/ArchInterruptDefs.h
 
 [Sources.common]
-  CpuExceptionCommon.h
-  CpuExceptionCommon.c
-  PeiCpuException.c
-  PeiDxeSmmCpuException.c
+  Ia32X64/CpuExceptionCommon.h
+  Ia32X64/CpuExceptionCommon.c
+  Ia32X64/PeiCpuException.c
+  Ia32X64/PeiDxeSmmCpuException.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
index 6a170286c8fc..79911b21f62d 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
@@ -32,10 +32,10 @@ [Sources.X64]
   X64/ArchExceptionHandler.c
   X64/ArchInterruptDefs.h
 
-[Sources.common]
-  CpuExceptionCommon.h
-  CpuExceptionCommon.c
-  SecPeiCpuException.c
+[Sources.IA32, Sources.X64]
+  Ia32X64/CpuExceptionCommon.h
+  Ia32X64/CpuExceptionCommon.c
+  Ia32X64/SecPeiCpuException.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -46,8 +46,10 @@ [LibraryClasses]
   BaseLib
   SerialPortLib
   PrintLib
-  LocalApicLib
   PeCoffGetEntryPointLib
+
+[LibraryClasses.IA32, LibraryClasses.X64]
+  LocalApicLib
   VmgExitLib
 
 [Pcd]
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
index 9dde07612a04..249446588bfa 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
@@ -33,10 +33,10 @@ [Sources.X64]
   X64/ArchInterruptDefs.h
 
 [Sources.common]
-  CpuExceptionCommon.h
-  CpuExceptionCommon.c
-  PeiDxeSmmCpuException.c
-  SmmException.c
+  Ia32X64/CpuExceptionCommon.h
+  Ia32X64/CpuExceptionCommon.c
+  Ia32X64/PeiDxeSmmCpuException.c
+  Ia32X64/SmmException.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
index 6d2f66504a5b..23200437eb8b 100644
--- 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 14/30] UefiCpuPkg/CpuTimerLib: Add support for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This is mostly copied from
edk2-platforms/Silicon/RISC-V/ProcessorPkg/Library/RiscVTimerLib

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Daniel Schaefer 
Cc: Abner Chang 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf   |   3 +
 UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c | 199 
 2 files changed, 202 insertions(+)

diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf 
b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
index 4b263965ed90..4492ee26caae 100644
--- a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
+++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
@@ -22,6 +22,9 @@ [Sources.IA32, Sources.X64]
   Ia32X64/CpuTimerLib.c
   Ia32X64/BaseCpuTimerLib.c
 
+[Sources.RISCV64]
+  RiscV64/CpuTimerLib.c
+
 [Packages]
   MdePkg/MdePkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
diff --git a/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c 
b/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c
new file mode 100644
index ..9c8efc0f3530
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuTimerLib/RiscV64/CpuTimerLib.c
@@ -0,0 +1,199 @@
+/** @file
+  RISC-V instance of Timer Library.
+
+  Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All 
rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Stalls the CPU for at least the given number of ticks.
+
+  Stalls the CPU for at least the given number of ticks. It's invoked by
+  MicroSecondDelay() and NanoSecondDelay().
+
+  @param  Delay A period of time to delay in ticks.
+
+**/
+VOID
+InternalRiscVTimerDelay (
+  IN UINT32  Delay
+  )
+{
+  UINT32  Ticks;
+  UINT32  Times;
+
+  Times  = Delay >> (RISCV_TIMER_COMPARE_BITS - 2);
+  Delay &= ((1 << (RISCV_TIMER_COMPARE_BITS - 2)) - 1);
+  do {
+//
+// The target timer count is calculated here
+//
+Ticks = RiscVReadTimer () + Delay;
+Delay = 1 << (RISCV_TIMER_COMPARE_BITS - 2);
+while (((Ticks - RiscVReadTimer ()) & (1 << (RISCV_TIMER_COMPARE_BITS - 
1))) == 0) {
+  CpuPause ();
+}
+  } while (Times-- > 0);
+}
+
+/**
+  Stalls the CPU for at least the given number of microseconds.
+
+  Stalls the CPU for the number of microseconds specified by MicroSeconds.
+
+  @param  MicroSeconds  The minimum number of microseconds to delay.
+
+  @return MicroSeconds
+
+**/
+UINTN
+EFIAPI
+MicroSecondDelay (
+  IN UINTN  MicroSeconds
+  )
+{
+  InternalRiscVTimerDelay (
+(UINT32)DivU64x32 (
+  MultU64x32 (
+MicroSeconds,
+PcdGet64 (PcdCpuCoreCrystalClockFrequency)
+),
+  100u
+  )
+);
+  return MicroSeconds;
+}
+
+/**
+  Stalls the CPU for at least the given number of nanoseconds.
+
+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
+
+  @param  NanoSeconds The minimum number of nanoseconds to delay.
+
+  @return NanoSeconds
+
+**/
+UINTN
+EFIAPI
+NanoSecondDelay (
+  IN UINTN  NanoSeconds
+  )
+{
+  InternalRiscVTimerDelay (
+(UINT32)DivU64x32 (
+  MultU64x32 (
+NanoSeconds,
+PcdGet64 (PcdCpuCoreCrystalClockFrequency)
+),
+  10u
+  )
+);
+  return NanoSeconds;
+}
+
+/**
+  Retrieves the current value of a 64-bit free running performance counter.
+
+  Retrieves the current value of a 64-bit free running performance counter. The
+  counter can either count up by 1 or count down by 1. If the physical
+  performance counter counts by a larger increment, then the counter values
+  must be translated. The properties of the counter can be retrieved from
+  GetPerformanceCounterProperties().
+
+  @return The current value of the free running performance counter.
+
+**/
+UINT64
+EFIAPI
+GetPerformanceCounter (
+  VOID
+  )
+{
+  return (UINT64)RiscVReadTimer ();
+}
+
+/**return
+  Retrieves the 64-bit frequency in Hz and the range of performance counter
+  values.
+
+  If StartValue is not NULL, then the value that the performance counter starts
+  with immediately after is it rolls over is returned in StartValue. If
+  EndValue is not NULL, then the value that the performance counter end with
+  immediately before it rolls over is returned in EndValue. The 64-bit
+  frequency of the performance counter in Hz is always returned. If StartValue
+  is less than EndValue, then the performance counter counts up. If StartValue
+  is greater than EndValue, then the performance counter counts down. For
+  example, a 64-bit free running counter that counts up would have a StartValue
+  of 0 and an EndValue of 0x. A 24-bit free running counter
+  that counts down would have a StartValue of 0xFF and an EndValue of 0.
+
+  @param  StartValue  The value the performance counter starts with when it
+

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 13/30] UefiCpuPkg/CpuTimerLib: Refactor to allow other architectures

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Currently, CpuTimerLib library supports only X86 architecture.
Refactor to allow other CPU architectures.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Signed-off-by: Sunil V L 
---
 UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf | 6 +++---
 UefiCpuPkg/Library/CpuTimerLib/{ => Ia32X64}/BaseCpuTimerLib.c | 0
 UefiCpuPkg/Library/CpuTimerLib/{ => Ia32X64}/CpuTimerLib.c | 0
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf 
b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
index de0648de91b5..4b263965ed90 100644
--- a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
+++ b/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf
@@ -18,9 +18,9 @@ [Defines]
   LIBRARY_CLASS  = TimerLib
   MODULE_UNI_FILE= BaseCpuTimerLib.uni
 
-[Sources]
-  CpuTimerLib.c
-  BaseCpuTimerLib.c
+[Sources.IA32, Sources.X64]
+  Ia32X64/CpuTimerLib.c
+  Ia32X64/BaseCpuTimerLib.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c 
b/UefiCpuPkg/Library/CpuTimerLib/Ia32X64/BaseCpuTimerLib.c
similarity index 100%
rename from UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.c
rename to UefiCpuPkg/Library/CpuTimerLib/Ia32X64/BaseCpuTimerLib.c
diff --git a/UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c 
b/UefiCpuPkg/Library/CpuTimerLib/Ia32X64/CpuTimerLib.c
similarity index 100%
rename from UefiCpuPkg/Library/CpuTimerLib/CpuTimerLib.c
rename to UefiCpuPkg/Library/CpuTimerLib/Ia32X64/CpuTimerLib.c
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 12/30] OvmfPkg/PlatformPei: Add support for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This is mostly copied from
edk2-platforms/Platform/RISC-V/PlatformPkg/Universal/Pei/PlatformPei

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Daniel Schaefer 
Cc: Abner Chang 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 OvmfPkg/PlatformPei/PlatformPei.inf |   9 +
 OvmfPkg/PlatformPei/RiscV64/Platform.h  |  97 +
 OvmfPkg/PlatformPei/RiscV64/Fv.c|  81 +
 OvmfPkg/PlatformPei/RiscV64/MemDetect.c | 212 +++
 OvmfPkg/PlatformPei/RiscV64/Platform.c  | 372 
 5 files changed, 771 insertions(+)

diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index c637f621cb1f..5d873c34ca67 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -33,6 +33,12 @@ [Sources.IA32, Sources.X64]
   Ia32X64/Platform.h
   Ia32X64/IntelTdx.c
 
+[Sources.RISCV64]
+  RiscV64/Fv.c
+  RiscV64/MemDetect.c
+  RiscV64/Platform.c
+  RiscV64/Platform.h
+
 [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
   MdePkg/MdePkg.dec
@@ -68,6 +74,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
   QemuFwCfgSimpleParserLib
   MemEncryptSevLib
 
+[LibraryClasses.RISCV64]
+  RiscVSbiLib
+
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize
diff --git a/OvmfPkg/PlatformPei/RiscV64/Platform.h 
b/OvmfPkg/PlatformPei/RiscV64/Platform.h
new file mode 100644
index ..6c23c722a360
--- /dev/null
+++ b/OvmfPkg/PlatformPei/RiscV64/Platform.h
@@ -0,0 +1,97 @@
+/** @file
+  Platform PEI module include file.
+
+  Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef PLATFORM_PEI_H_INCLUDED_
+#define PLATFORM_PEI_H_INCLUDED_
+
+VOID
+AddIoMemoryBaseSizeHob (
+  EFI_PHYSICAL_ADDRESS  MemoryBase,
+  UINT64MemorySize
+  );
+
+VOID
+AddIoMemoryRangeHob (
+  EFI_PHYSICAL_ADDRESS  MemoryBase,
+  EFI_PHYSICAL_ADDRESS  MemoryLimit
+  );
+
+VOID
+AddMemoryBaseSizeHob (
+  EFI_PHYSICAL_ADDRESS  MemoryBase,
+  UINT64MemorySize
+  );
+
+VOID
+AddMemoryRangeHob (
+  EFI_PHYSICAL_ADDRESS  MemoryBase,
+  EFI_PHYSICAL_ADDRESS  MemoryLimit
+  );
+
+VOID
+AddUntestedMemoryBaseSizeHob (
+  EFI_PHYSICAL_ADDRESS  MemoryBase,
+  UINT64MemorySize
+  );
+
+VOID
+AddReservedMemoryBaseSizeHob (
+  EFI_PHYSICAL_ADDRESS  MemoryBase,
+  UINT64MemorySize
+  );
+
+VOID
+AddUntestedMemoryRangeHob (
+  EFI_PHYSICAL_ADDRESS  MemoryBase,
+  EFI_PHYSICAL_ADDRESS  MemoryLimit
+  );
+
+VOID
+AddressWidthInitialization (
+  VOID
+  );
+
+EFI_STATUS
+PublishPeiMemory (
+  VOID
+  );
+
+UINT32
+GetSystemMemorySizeBelow4gb (
+  VOID
+  );
+
+VOID
+InitializeRamRegions (
+  VOID
+  );
+
+EFI_STATUS
+PeiFvInitialization (
+  VOID
+  );
+
+EFI_STATUS
+InitializeXen (
+  VOID
+  );
+
+/**
+  Build processor and platform information for the U5 platform
+
+  @return EFI_SUCCESS Status.
+
+**/
+EFI_STATUS
+BuildRiscVSmbiosHobs (
+  VOID
+  );
+
+#endif // _PLATFORM_PEI_H_INCLUDED_
diff --git a/OvmfPkg/PlatformPei/RiscV64/Fv.c b/OvmfPkg/PlatformPei/RiscV64/Fv.c
new file mode 100644
index ..ff99c1432935
--- /dev/null
+++ b/OvmfPkg/PlatformPei/RiscV64/Fv.c
@@ -0,0 +1,81 @@
+/** @file
+  Build FV related hobs for platform.
+
+  Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "PiPei.h"
+#include "Platform.h"
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Publish PEI & DXE (Decompressed) Memory based FVs to let PEI
+  and DXE know about them.
+
+  @retval EFI_SUCCESS   Platform PEI FVs were initialized successfully.
+
+**/
+EFI_STATUS
+PeiFvInitialization (
+  VOID
+  )
+{
+  DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n"));
+
+  // Create a memory allocation HOB for the DXE FV.
+  //
+  // If "secure" S3 is needed, then SEC will decompress both PEI and DXE
+  // firmware volumes at S3 resume too, hence we need to keep away the OS from
+  // DXEFV as well. Otherwise we only need to keep away DXE itself from the
+  // DXEFV area.
+  //
+  BuildMemoryAllocationHob (
+PcdGet32 (PcdOvmfPeiMemFvBase),
+PcdGet32 (PcdOvmfPeiMemFvSize),
+EfiBootServicesData
+);
+
+  //
+  // Let DXE know about the DXE FV
+  //
+  BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSize));
+  DEBUG ((
+DEBUG_INFO,
+"Platform builds DXE FV at %x, size %x.\n",
+PcdGet32 (PcdOvmfDxeMemFvBase),
+PcdGet32 (PcdOvmfDxeMemFvSize)
+));
+
+  // Create a memory allocation HOB for the DXE FV.
+  //
+  // If "secure" S3 is needed, then SEC will decompress both PEI and DXE
+  // firmware volumes 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 11/30] OvmfPkg/PlatformPei: Refactor to allow other architectures

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Currently, PlatformPei supports only X86 architecture. So,
refactor it to allow other CPU architectures.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Signed-off-by: Sunil V L 
---
 OvmfPkg/PlatformPei/PlatformPei.inf| 34 +++-
 OvmfPkg/PlatformPei/{ => Ia32X64}/Platform.h   |  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/AmdSev.c |  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/ClearCache.c |  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/FeatureControl.c |  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/Fv.c |  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/IntelTdx.c   |  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/MemDetect.c  |  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/MemTypeInfo.c|  0
 OvmfPkg/PlatformPei/{ => Ia32X64}/Platform.c   |  0
 10 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index 3cd83e6ec3e5..c637f621cb1f 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -22,16 +22,16 @@ [Defines]
 #  VALID_ARCHITECTURES   = IA32 X64 EBC
 #
 
-[Sources]
-  AmdSev.c
-  ClearCache.c
-  FeatureControl.c
-  Fv.c
-  MemDetect.c
-  MemTypeInfo.c
-  Platform.c
-  Platform.h
-  IntelTdx.c
+[Sources.IA32, Sources.X64]
+  Ia32X64/AmdSev.c
+  Ia32X64/ClearCache.c
+  Ia32X64/FeatureControl.c
+  Ia32X64/Fv.c
+  Ia32X64/MemDetect.c
+  Ia32X64/MemTypeInfo.c
+  Ia32X64/Platform.c
+  Ia32X64/Platform.h
+  Ia32X64/IntelTdx.c
 
 [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
@@ -57,14 +57,16 @@ [LibraryClasses]
   PeiServicesLib
   PeiServicesTablePointerLib
   PeimEntryPoint
+  PcdLib
+  PlatformInitLib
+
+[LibraryClasses.IA32, LibraryClasses.X64]
+  MtrrLib
+  VmgExitLib
   QemuFwCfgLib
   QemuFwCfgS3Lib
   QemuFwCfgSimpleParserLib
-  MtrrLib
   MemEncryptSevLib
-  PcdLib
-  VmgExitLib
-  PlatformInitLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
@@ -99,7 +101,6 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved
-  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
   gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable
@@ -116,6 +117,9 @@ [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures
   gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask
 
+[Pcd.IA32, Pcd.X64]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
+
 [FixedPcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize
diff --git a/OvmfPkg/PlatformPei/Platform.h 
b/OvmfPkg/PlatformPei/Ia32X64/Platform.h
similarity index 100%
rename from OvmfPkg/PlatformPei/Platform.h
rename to OvmfPkg/PlatformPei/Ia32X64/Platform.h
diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/Ia32X64/AmdSev.c
similarity index 100%
rename from OvmfPkg/PlatformPei/AmdSev.c
rename to OvmfPkg/PlatformPei/Ia32X64/AmdSev.c
diff --git a/OvmfPkg/PlatformPei/ClearCache.c 
b/OvmfPkg/PlatformPei/Ia32X64/ClearCache.c
similarity index 100%
rename from OvmfPkg/PlatformPei/ClearCache.c
rename to OvmfPkg/PlatformPei/Ia32X64/ClearCache.c
diff --git a/OvmfPkg/PlatformPei/FeatureControl.c 
b/OvmfPkg/PlatformPei/Ia32X64/FeatureControl.c
similarity index 100%
rename from OvmfPkg/PlatformPei/FeatureControl.c
rename to OvmfPkg/PlatformPei/Ia32X64/FeatureControl.c
diff --git a/OvmfPkg/PlatformPei/Fv.c b/OvmfPkg/PlatformPei/Ia32X64/Fv.c
similarity index 100%
rename from OvmfPkg/PlatformPei/Fv.c
rename to OvmfPkg/PlatformPei/Ia32X64/Fv.c
diff --git a/OvmfPkg/PlatformPei/IntelTdx.c 
b/OvmfPkg/PlatformPei/Ia32X64/IntelTdx.c
similarity index 100%
rename from OvmfPkg/PlatformPei/IntelTdx.c
rename to OvmfPkg/PlatformPei/Ia32X64/IntelTdx.c
diff --git a/OvmfPkg/PlatformPei/MemDetect.c 
b/OvmfPkg/PlatformPei/Ia32X64/MemDetect.c
similarity index 100%
rename from OvmfPkg/PlatformPei/MemDetect.c
rename to OvmfPkg/PlatformPei/Ia32X64/MemDetect.c
diff --git a/OvmfPkg/PlatformPei/MemTypeInfo.c 
b/OvmfPkg/PlatformPei/Ia32X64/MemTypeInfo.c
similarity index 100%
rename from OvmfPkg/PlatformPei/MemTypeInfo.c
rename to OvmfPkg/PlatformPei/Ia32X64/MemTypeInfo.c
diff --git a/OvmfPkg/PlatformPei/Platform.c 
b/OvmfPkg/PlatformPei/Ia32X64/Platform.c
similarity index 100%
rename from OvmfPkg/PlatformPei/Platform.c
rename to OvmfPkg/PlatformPei/Ia32X64/Platform.c
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 10/30] OvmfPkg/Sec: Add RISC-V support

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Add the SEC module for RISC-V. EDK2 is launched as the payload
for machine mode firmware in RISC-V.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: James Bottomley 
Cc: Min Xu 
Cc: Tom Lendacky 
Cc: Daniel Schaefer 
Cc: Abner Chang 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 OvmfPkg/Sec/SecMain.inf|  16 +-
 OvmfPkg/Sec/RiscV64/SecMain.h  |  64 +++
 OvmfPkg/Sec/RiscV64/SecMain.c  | 573 
 OvmfPkg/Sec/RiscV64/SecEntry.S |  21 +
 4 files changed, 673 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf
index a014bcb4cf1a..96fcc464c0d5 100644
--- a/OvmfPkg/Sec/SecMain.inf
+++ b/OvmfPkg/Sec/SecMain.inf
@@ -18,7 +18,7 @@ [Defines]
 #
 # The following information is for reference only and not required by the 
build tools.
 #
-#  VALID_ARCHITECTURES   = IA32 X64 EBC
+#  VALID_ARCHITECTURES   = IA32 X64 EBC RISCV64
 #
 
 [Sources.IA32, Sources.X64]
@@ -34,6 +34,13 @@ [Sources.IA32]
 [Sources.X64]
   X64/SecEntry.nasm
 
+[Sources.RISCV64]
+  SecMainCommon.c
+  SecMainCommon.h
+  RiscV64/SecEntry.S
+  RiscV64/SecMain.c
+  RiscV64/SecMain.h
+
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
@@ -61,11 +68,17 @@ [LibraryClasses.IA32, LibraryClasses.X64]
   PeiServicesLib
   CcProbeLib
 
+[LibraryClasses.RISCV64]
+  RiscVSbiLib
+
 [Ppis]
   gEfiTemporaryRamSupportPpiGuid# PPI ALWAYS_PRODUCED
   gEfiPeiMpInitLibMpDepPpiGuid
   gEfiPeiMpInitLibUpDepPpiGuid
 
+[Ppis.RISCV64]
+  gEfiTemporaryRamDonePpiGuid  ## PRODUCES
+
 [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
@@ -88,6 +101,7 @@ [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase
   gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
 
 [FeaturePcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
diff --git a/OvmfPkg/Sec/RiscV64/SecMain.h b/OvmfPkg/Sec/RiscV64/SecMain.h
new file mode 100644
index ..6489104a884d
--- /dev/null
+++ b/OvmfPkg/Sec/RiscV64/SecMain.h
@@ -0,0 +1,64 @@
+/** @file
+  Master header file for SecCore.
+
+  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef SEC_MAIN_H_
+#define SEC_MAIN_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "SecMainCommon.h"
+
+/**
+  Entry point to the C language phase of SEC. After the SEC assembly
+  code has initialized some temporary memory and set up the stack,
+  the control is transferred to this function.
+
+  @param SizeOfRam   Size of the temporary memory available for use.
+  @param TempRamBase Base address of temporary ram
+  @param BootFirmwareVolume  Base address of the Boot Firmware Volume.
+**/
+VOID
+NORETURN
+EFIAPI
+SecStartup (
+  IN  UINTN  BootHartId,
+  IN  VOID   *DeviceTreeAddress
+  );
+
+/**
+  Auto-generated function that calls the library constructors for all of the 
module's
+  dependent libraries.  This function must be called by the SEC Core once a 
stack has
+  been established.
+
+**/
+VOID
+EFIAPI
+ProcessLibraryConstructorList (
+  VOID
+  );
+
+#endif
diff --git a/OvmfPkg/Sec/RiscV64/SecMain.c b/OvmfPkg/Sec/RiscV64/SecMain.c
new file mode 100644
index ..3eda37e2976f
--- /dev/null
+++ b/OvmfPkg/Sec/RiscV64/SecMain.c
@@ -0,0 +1,573 @@
+/** @file
+  RISC-V SEC phase module for Qemu Virt.
+
+  Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "SecMain.h"
+
+EFI_STATUS
+EFIAPI
+TemporaryRamMigration (
+  IN CONST EFI_PEI_SERVICES  **PeiServices,
+  IN EFI_PHYSICAL_ADDRESSTemporaryMemoryBase,
+  IN EFI_PHYSICAL_ADDRESSPermanentMemoryBase,
+  IN UINTN   CopySize
+  );
+
+EFI_STATUS
+EFIAPI
+TemporaryRamDone (
+  VOID
+  );
+
+STATIC EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI  mTemporaryRamSupportPpi = {
+  TemporaryRamMigration
+};
+
+STATIC EFI_PEI_TEMPORARY_RAM_DONE_PPI  mTemporaryRamDonePpi = {
+  TemporaryRamDone
+};
+
+STATIC EFI_PEI_PPI_DESCRIPTOR  mPrivateDispatchTable[] = {
+  {
+EFI_PEI_PPI_DESCRIPTOR_PPI,
+,
+
+  },
+  {
+(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+,
+
+  },
+};
+
+/** Temporary RAM migration function.
+
+  This function migrates the data from temporary RAM to permanent
+  memory.
+
+  @param[in]  PeiServices   PEI service
+  @param[in]  TemporaryMemoryBase   Temporary memory base address
+  

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 09/30] OvmfPkg/Sec: Refactor to allow other architectures

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Currently, the Sec module supports only X86 architecture.
Refactor the module to allow other CPU architectures.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: James Bottomley 
Cc: Min Xu 
Cc: Tom Lendacky 
Signed-off-by: Sunil V L 
---
 OvmfPkg/Sec/SecMain.inf |  18 +-
 OvmfPkg/Sec/{ => Ia32X64}/AmdSev.h  |   0
 OvmfPkg/Sec/SecMainCommon.h |  73 ++
 OvmfPkg/Sec/{ => Ia32X64}/AmdSev.c  |   0
 OvmfPkg/Sec/{ => Ia32X64}/SecMain.c | 227 +--
 OvmfPkg/Sec/SecMainCommon.c | 238 
 6 files changed, 323 insertions(+), 233 deletions(-)

diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf
index 561a840f29c5..a014bcb4cf1a 100644
--- a/OvmfPkg/Sec/SecMain.inf
+++ b/OvmfPkg/Sec/SecMain.inf
@@ -21,10 +21,12 @@ [Defines]
 #  VALID_ARCHITECTURES   = IA32 X64 EBC
 #
 
-[Sources]
-  SecMain.c
-  AmdSev.c
-  AmdSev.h
+[Sources.IA32, Sources.X64]
+  SecMainCommon.c
+  SecMainCommon.h
+  Ia32X64/SecMain.c
+  Ia32X64/AmdSev.c
+  Ia32X64/AmdSev.h
 
 [Sources.IA32]
   Ia32/SecEntry.nasm
@@ -42,19 +44,21 @@ [LibraryClasses]
   BaseLib
   DebugLib
   BaseMemoryLib
-  PeiServicesLib
   PcdLib
   CpuLib
-  UefiCpuLib
   DebugAgentLib
   IoLib
   PeCoffLib
   PeCoffGetEntryPointLib
   PeCoffExtraActionLib
   ExtractGuidedSectionLib
+  CpuExceptionHandlerLib
+
+[LibraryClasses.IA32, LibraryClasses.X64]
+  UefiCpuLib
   LocalApicLib
   MemEncryptSevLib
-  CpuExceptionHandlerLib
+  PeiServicesLib
   CcProbeLib
 
 [Ppis]
diff --git a/OvmfPkg/Sec/AmdSev.h b/OvmfPkg/Sec/Ia32X64/AmdSev.h
similarity index 100%
rename from OvmfPkg/Sec/AmdSev.h
rename to OvmfPkg/Sec/Ia32X64/AmdSev.h
diff --git a/OvmfPkg/Sec/SecMainCommon.h b/OvmfPkg/Sec/SecMainCommon.h
new file mode 100644
index ..c3cc16e2c8cf
--- /dev/null
+++ b/OvmfPkg/Sec/SecMainCommon.h
@@ -0,0 +1,73 @@
+/** @file
+  Header file for common functions of Sec.
+
+  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+/**
+  Locates a section within a series of sections
+  with the specified section type.
+
+  The Instance parameter indicates which instance of the section
+  type to return. (0 is first instance, 1 is second...)
+
+  @param[in]   SectionsThe sections to search
+  @param[in]   SizeOfSections  Total size of all sections
+  @param[in]   SectionType The section type to locate
+  @param[in]   InstanceThe section instance number
+  @param[out]  FoundSectionThe FFS section if found
+
+  @retval EFI_SUCCESS   The file and section was found
+  @retval EFI_NOT_FOUND The file and section was not found
+  @retval EFI_VOLUME_CORRUPTED  The firmware volume was corrupted
+
+**/
+EFI_STATUS
+FindFfsSectionInstance (
+  IN  VOID   *Sections,
+  IN  UINTN  SizeOfSections,
+  IN  EFI_SECTION_TYPE   SectionType,
+  IN  UINTN  Instance,
+  OUT EFI_COMMON_SECTION_HEADER  **FoundSection
+  );
+
+/**
+  Locates a FFS file with the specified file type and a section
+  within that file with the specified section type.
+
+  @param[in]   FvThe firmware volume to search
+  @param[in]   FileType  The file type to locate
+  @param[in]   SectionType   The section type to locate
+  @param[out]  FoundSection  The FFS section if found
+
+  @retval EFI_SUCCESS   The file and section was found
+  @retval EFI_NOT_FOUND The file and section was not found
+  @retval EFI_VOLUME_CORRUPTED  The firmware volume was corrupted
+
+**/
+EFI_STATUS
+FindFfsFileAndSection (
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *Fv,
+  IN  EFI_FV_FILETYPE FileType,
+  IN  EFI_SECTION_TYPESectionType,
+  OUT EFI_COMMON_SECTION_HEADER   **FoundSection
+  );
+
+/**
+  Locates the PEI Core entry point address
+
+  @param[in]  Fv The firmware volume to search
+  @param[out] PeiCoreEntryPoint  The entry point of the PEI Core image
+
+  @retval EFI_SUCCESS   The file and section was found
+  @retval EFI_NOT_FOUND The file and section was not found
+  @retval EFI_VOLUME_CORRUPTED  The firmware volume was corrupted
+
+**/
+EFI_STATUS
+FindPeiCoreImageBaseInFv (
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *Fv,
+  OUT  EFI_PHYSICAL_ADDRESS   *PeiCoreImageBase
+  );
diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/Ia32X64/AmdSev.c
similarity index 100%
rename from OvmfPkg/Sec/AmdSev.c
rename to OvmfPkg/Sec/Ia32X64/AmdSev.c
diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/Ia32X64/SecMain.c
similarity index 75%
rename from OvmfPkg/Sec/SecMain.c
rename to OvmfPkg/Sec/Ia32X64/SecMain.c
index 1167d22a68cc..096bab074f35 100644
--- a/OvmfPkg/Sec/SecMain.c
+++ b/OvmfPkg/Sec/Ia32X64/SecMain.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include "AmdSev.h"
+#include "SecMainCommon.h"
 
 #define 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 08/30] OvmfPkg/ResetSystemLib: Add support for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This is mostly copied from
edk2-platforms/Platform/RISC-V/PlatformPkg/Library/ResetSystemLib

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Rebecca Cran 
Cc: Peter Grehan 
Cc: Daniel Schaefer 
Signed-off-by: Sunil V L 
---
 OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf |   6 +
 OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf  |   9 +-
 OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c |  20 +++
 OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c   | 128 

 4 files changed, 162 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf 
b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf
index a554c6b68cfe..9b2afc36dd95 100644
--- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf
+++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf
@@ -25,6 +25,9 @@ [Sources.IA32, Sources.X64]
   Ia32X64/BaseResetShutdown.c
   Ia32X64/ResetSystemLib.c
 
+[Sources.RISCV64]
+  RiscV64/ResetSystemLib.c
+
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
@@ -36,3 +39,6 @@ [LibraryClasses]
   IoLib
   PciLib
   TimerLib
+
+[LibraryClasses.RISCV64]
+  RiscVSbiLib
diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf 
b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
index acf9c6a93552..c012a163c61a 100644
--- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
+++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
@@ -20,13 +20,17 @@ [Defines]
 # The following information is for reference only and not required by the build
 # tools.
 #
-#  VALID_ARCHITECTURES   = IA32 X64
+#  VALID_ARCHITECTURES   = IA32 X64 RISCV64
 #
 
 [Sources.IA32, Sources.X64]
   Ia32X64/DxeResetShutdown.c
   Ia32X64/ResetSystemLib.c
 
+[Sources.RISCV64]
+  RiscV64/ResetSystemLib.c
+  RiscV64/DxeResetShutdown.c
+
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
@@ -39,5 +43,8 @@ [LibraryClasses]
   PcdLib
   TimerLib
 
+[LibraryClasses.RISCV64]
+  RiscVSbiLib
+
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES
diff --git a/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c 
b/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c
new file mode 100644
index ..027e235cad11
--- /dev/null
+++ b/OvmfPkg/Library/ResetSystemLib/RiscV64/DxeResetShutdown.c
@@ -0,0 +1,20 @@
+/** @file
+  DXE Reset System Library Shutdown API implementation for OVMF.
+
+  Copyright (C) 2020, Red Hat, Inc.
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include // CpuDeadLoop()
+#include  // ResetShutdown()
+
+EFI_STATUS
+EFIAPI
+DxeResetInit (
+  IN EFI_HANDLEImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return EFI_SUCCESS;
+}
diff --git a/OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c 
b/OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c
new file mode 100644
index ..14f7653aa8de
--- /dev/null
+++ b/OvmfPkg/Library/ResetSystemLib/RiscV64/ResetSystemLib.c
@@ -0,0 +1,128 @@
+/** @file
+  Reset System Library functions for RISC-V
+
+  Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+
+/**
+  This function causes a system-wide reset (cold reset), in which
+  all circuitry within the system returns to its initial state. This type of 
reset
+  is asynchronous to system operation and operates without regard to
+  cycle boundaries.
+
+  If this function returns, it means that the system does not support cold 
reset.
+**/
+VOID
+EFIAPI
+ResetCold (
+  VOID
+  )
+{
+  // Warm Reset via SBI ecall
+  SbiSystemReset (SBI_SRST_RESET_TYPE_COLD_REBOOT, SBI_SRST_RESET_REASON_NONE);
+}
+
+/**
+  This function causes a system-wide initialization (warm reset), in which all 
processors
+  are set to their initial state. Pending cycles are not corrupted.
+
+  If this function returns, it means that the system does not support warm 
reset.
+**/
+VOID
+EFIAPI
+ResetWarm (
+  VOID
+  )
+{
+  // Warm Reset via SBI ecall
+  SbiSystemReset (SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_NONE);
+}
+
+/**
+  This function causes the system to enter a power state equivalent
+  to the ACPI G2/S5 or G3 states.
+
+  If this function returns, it means that the system does not support shutdown 
reset.
+**/
+VOID
+EFIAPI
+ResetShutdown (
+  VOID
+  )
+{
+  // Shut down via SBI ecall
+  SbiSystemReset (SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE);
+}
+
+/**
+  This function causes a systemwide reset. The exact type of the reset is
+  defined by the EFI_GUID that follows the Null-terminated Unicode string 
passed
+  into ResetData. If the platform does not recognize the EFI_GUID in ResetData
+  the platform must pick a supported reset type to 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 07/30] OvmfPkg/ResetSystemLib: Refactor to allow other architectures.

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Currently, the ResetSystemLib library supports only X86 architecture.
Refactor it to allow adding other CPU architectures like RISC-V.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Rebecca Cran 
Cc: Peter Grehan 
Signed-off-by: Sunil V L 
---
 OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf   | 6 
+++---
 OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf  | 4 
++--
 OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf| 2 +-
 OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf| 6 
+++---
 OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf | 4 
++--
 OvmfPkg/Library/ResetSystemLib/{ => Ia32X64}/BaseResetShutdown.c| 0
 OvmfPkg/Library/ResetSystemLib/{ => Ia32X64}/BaseResetShutdownBhyve.c   | 0
 OvmfPkg/Library/ResetSystemLib/{ => Ia32X64}/DxeResetShutdown.c | 0
 OvmfPkg/Library/ResetSystemLib/{ => Ia32X64}/DxeResetSystemLibMicrovm.c | 0
 OvmfPkg/Library/ResetSystemLib/{ => Ia32X64}/ResetSystemLib.c   | 0
 OvmfPkg/Library/ResetSystemLib/{ => Ia32X64}/ResetSystemLibMicrovm.c| 0
 11 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf 
b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf
index 35d317f1e0b3..a554c6b68cfe 100644
--- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf
+++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf
@@ -21,9 +21,9 @@ [Defines]
 #  VALID_ARCHITECTURES   = IA32 X64
 #
 
-[Sources]
-  BaseResetShutdown.c
-  ResetSystemLib.c
+[Sources.IA32, Sources.X64]
+  Ia32X64/BaseResetShutdown.c
+  Ia32X64/ResetSystemLib.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf 
b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf
index 74124aed38e8..882a8767cfa5 100644
--- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf
+++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibBhyve.inf
@@ -25,8 +25,8 @@ [Defines]
 #
 
 [Sources]
-  BaseResetShutdownBhyve.c
-  ResetSystemLib.c
+  Ia32X64/BaseResetShutdownBhyve.c
+  Ia32X64/ResetSystemLib.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf 
b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf
index 564b1d3022a6..8e73ac256bc7 100644
--- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf
+++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf
@@ -23,7 +23,7 @@ [Defines]
 #
 
 [Sources]
-  ResetSystemLibMicrovm.c
+  Ia32X64/ResetSystemLibMicrovm.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf 
b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
index a9b4ce9a..acf9c6a93552 100644
--- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
+++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
@@ -23,9 +23,9 @@ [Defines]
 #  VALID_ARCHITECTURES   = IA32 X64
 #
 
-[Sources]
-  DxeResetShutdown.c
-  ResetSystemLib.c
+[Sources.IA32, Sources.X64]
+  Ia32X64/DxeResetShutdown.c
+  Ia32X64/ResetSystemLib.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf 
b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
index ac9c2599642c..918c8262fac7 100644
--- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
+++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
@@ -24,8 +24,8 @@ [Defines]
 #
 
 [Sources]
-  ResetSystemLibMicrovm.c
-  DxeResetSystemLibMicrovm.c
+  Ia32X64/ResetSystemLibMicrovm.c
+  Ia32X64/DxeResetSystemLibMicrovm.c
 
 [Packages]
   MdeModulePkg/MdeModulePkg.dec
diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c 
b/OvmfPkg/Library/ResetSystemLib/Ia32X64/BaseResetShutdown.c
similarity index 100%
rename from OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c
rename to OvmfPkg/Library/ResetSystemLib/Ia32X64/BaseResetShutdown.c
diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdownBhyve.c 
b/OvmfPkg/Library/ResetSystemLib/Ia32X64/BaseResetShutdownBhyve.c
similarity index 100%
rename from OvmfPkg/Library/ResetSystemLib/BaseResetShutdownBhyve.c
rename to OvmfPkg/Library/ResetSystemLib/Ia32X64/BaseResetShutdownBhyve.c
diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c 
b/OvmfPkg/Library/ResetSystemLib/Ia32X64/DxeResetShutdown.c
similarity index 100%
rename from OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c
rename to OvmfPkg/Library/ResetSystemLib/Ia32X64/DxeResetShutdown.c
diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c 
b/OvmfPkg/Library/ResetSystemLib/Ia32X64/DxeResetSystemLibMicrovm.c
similarity index 100%
rename from OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c
rename to 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 06/30] OvmfPkg/PlatformInitLib: Add support for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This is copied from
edk2-platforms/Platform/RISC-V/PlatformPkg/Universal/FdtPeim
but added as part of library instead of a separate module.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Daniel Schaefer 
Signed-off-by: Sunil V L 
---
 OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf  |  9 ++-
 OvmfPkg/Include/Library/PlatformInitLib.h|  6 ++
 OvmfPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c | 72 

 3 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf 
b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
index 5d31cad1b670..b3a69bf9582c 100644
--- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
+++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
@@ -19,7 +19,7 @@ [Defines]
 #
 # The following information is for reference only and not required by the 
build tools.
 #
-#  VALID_ARCHITECTURES   = IA32 X64 EBC
+#  VALID_ARCHITECTURES   = IA32 X64 EBC RISCV64
 #
 
 [Sources.IA32, Sources.X64]
@@ -33,6 +33,9 @@ [Sources.IA32]
 [Sources.X64]
   Ia32X64/IntelTdx.c
 
+[Sources.RISCV64]
+  RiscV64/PlatformPeiLib.c
+
 [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
@@ -58,6 +61,10 @@ [LibraryClasses.IA32, LibraryClasses.X64]
 [LibraryClasses.X64]
   TdxLib
 
+[LibraryClasses.RISCV64]
+  RiscVSbiLib
+  FdtLib
+
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
 
diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h 
b/OvmfPkg/Include/Library/PlatformInitLib.h
index c5234bf26d45..1b8d1fad3b49 100644
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
@@ -285,4 +285,10 @@ PlatformInitEmuVariableNvStore (
   IN VOID  *EmuVariableNvStore
   );
 
+EFI_STATUS
+EFIAPI
+PlatformPeim (
+  VOID
+  );
+
 #endif // PLATFORM_INIT_LIB_H_
diff --git a/OvmfPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c 
b/OvmfPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c
new file mode 100644
index ..266d5ddff58e
--- /dev/null
+++ b/OvmfPkg/Library/PlatformInitLib/RiscV64/PlatformPeiLib.c
@@ -0,0 +1,72 @@
+/** @file
+The library call to pass the device tree to DXE via HOB.
+
+Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+//
+ The package level header files this module uses
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+/**
+  @retval EFI_SUCCESSThe address of FDT is passed in HOB.
+  EFI_UNSUPPORTEDCan't locate FDT.
+**/
+EFI_STATUS
+EFIAPI
+PlatformPeim (
+  VOID
+  )
+{
+  EFI_RISCV_FIRMWARE_CONTEXT  *FirmwareContext;
+  VOID*FdtPointer;
+  VOID*Base;
+  VOID*NewBase;
+  UINTN   FdtSize;
+  UINTN   FdtPages;
+  UINT64  *FdtHobData;
+
+  FirmwareContext = NULL;
+  GetFirmwareContextPointer ();
+
+  if (FirmwareContext == NULL) {
+DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", __FUNCTION__));
+return EFI_UNSUPPORTED;
+  }
+
+  FdtPointer = (VOID *)FirmwareContext->FlattenedDeviceTree;
+  if (FdtPointer == NULL) {
+DEBUG ((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __FUNCTION__));
+return EFI_UNSUPPORTED;
+  }
+
+  DEBUG ((DEBUG_INFO, "%a: Build FDT HOB - FDT at address: 0x%x \n", 
__FUNCTION__, FdtPointer));
+  Base = FdtPointer;
+  ASSERT (Base != NULL);
+  ASSERT (fdt_check_header (Base) == 0);
+
+  FdtSize  = fdt_totalsize (Base);
+  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
+  NewBase  = AllocatePages (FdtPages);
+  ASSERT (NewBase != NULL);
+  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
+
+  FdtHobData = BuildGuidHob (, sizeof *FdtHobData);
+  ASSERT (FdtHobData != NULL);
+  *FdtHobData = (UINTN)NewBase;
+
+  return EFI_SUCCESS;
+}
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 05/30] OvmfPkg/PlatformInitLib: Refactor to allow other architectures

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Currently, PlatformInitLib supports only X86 architecture. So,
refactor to allow adding other architectures like RISC-V.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Signed-off-by: Sunil V L 
---
 OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf  | 22 
+++-
 OvmfPkg/Library/PlatformInitLib/{ => Ia32X64}/Cmos.c |  0
 OvmfPkg/Library/PlatformInitLib/{ => Ia32X64}/IntelTdx.c |  0
 OvmfPkg/Library/PlatformInitLib/{ => Ia32X64}/IntelTdxNull.c |  0
 OvmfPkg/Library/PlatformInitLib/{ => Ia32X64}/MemDetect.c|  0
 OvmfPkg/Library/PlatformInitLib/{ => Ia32X64}/Platform.c |  0
 6 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf 
b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
index 86a82ad3e084..5d31cad1b670 100644
--- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
+++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
@@ -22,16 +22,16 @@ [Defines]
 #  VALID_ARCHITECTURES   = IA32 X64 EBC
 #
 
-[Sources]
-  Cmos.c
-  MemDetect.c
-  Platform.c
+[Sources.IA32, Sources.X64]
+  Ia32X64/Cmos.c
+  Ia32X64/MemDetect.c
+  Ia32X64/Platform.c
 
 [Sources.IA32]
-  IntelTdxNull.c
+  Ia32X64/IntelTdxNull.c
 
 [Sources.X64]
-  IntelTdx.c
+  Ia32X64/IntelTdx.c
 
 [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
@@ -45,12 +45,14 @@ [LibraryClasses]
   DebugLib
   IoLib
   HobLib
+  PcdLib
+  PciLib
+
+[LibraryClasses.IA32, LibraryClasses.X64]
+  MtrrLib
   QemuFwCfgLib
   QemuFwCfgSimpleParserLib
   MemoryAllocationLib
-  MtrrLib
-  PcdLib
-  PciLib
   PeiHardwareInfoLib
 
 [LibraryClasses.X64]
@@ -100,5 +102,5 @@ [FixedPcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase
   gUefiOvmfPkgTokenSpaceGuid.PcdCfvRawDataSize
 
-[FeaturePcd]
+[FeaturePcd.IA32, FeaturePcd.X64]
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
diff --git a/OvmfPkg/Library/PlatformInitLib/Cmos.c 
b/OvmfPkg/Library/PlatformInitLib/Ia32X64/Cmos.c
similarity index 100%
rename from OvmfPkg/Library/PlatformInitLib/Cmos.c
rename to OvmfPkg/Library/PlatformInitLib/Ia32X64/Cmos.c
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c 
b/OvmfPkg/Library/PlatformInitLib/Ia32X64/IntelTdx.c
similarity index 100%
rename from OvmfPkg/Library/PlatformInitLib/IntelTdx.c
rename to OvmfPkg/Library/PlatformInitLib/Ia32X64/IntelTdx.c
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c 
b/OvmfPkg/Library/PlatformInitLib/Ia32X64/IntelTdxNull.c
similarity index 100%
rename from OvmfPkg/Library/PlatformInitLib/IntelTdxNull.c
rename to OvmfPkg/Library/PlatformInitLib/Ia32X64/IntelTdxNull.c
diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c 
b/OvmfPkg/Library/PlatformInitLib/Ia32X64/MemDetect.c
similarity index 100%
rename from OvmfPkg/Library/PlatformInitLib/MemDetect.c
rename to OvmfPkg/Library/PlatformInitLib/Ia32X64/MemDetect.c
diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c 
b/OvmfPkg/Library/PlatformInitLib/Ia32X64/Platform.c
similarity index 100%
rename from OvmfPkg/Library/PlatformInitLib/Platform.c
rename to OvmfPkg/Library/PlatformInitLib/Ia32X64/Platform.c
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 04/30] MdePkg: Add BaseRiscVSbiLib Library for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

This library is required to make SBI ecalls from the S-mode EDK2.
This is mostly copied from
edk2-platforms/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 MdePkg/MdePkg.dec  |   4 +
 MdePkg/MdePkg.dsc  |   3 +
 MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf |  25 +++
 MdePkg/Include/Library/BaseRiscVSbiLib.h   | 127 +++
 MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c   | 227 
 5 files changed, 386 insertions(+)

diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index dda1d5e15b9f..df681b2b99a5 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -311,6 +311,10 @@ [LibraryClasses.IA32, LibraryClasses.X64]
   ##  @libraryclass  Provides function to support TDX processing.
   TdxLib|Include/Library/TdxLib.h
 
+[LibraryClasses.RISCV64]
+  ##  @libraryclass  Provides function to make ecalls to SBI
+  BaseRiscVSbiLib|Include/Library/BaseRiscVSbiLib.h
+
 [Guids]
   #
   # GUID defined in UEFI2.1/UEFI2.0/EFI1.1
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 493a13ec9197..c7961a9b03f1 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -189,4 +189,7 @@ [Components.ARM, Components.AARCH64]
   MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicArmVirt.inf
   MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
 
+[Components.RISCV64]
+  MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf
+
 [BuildOptions]
diff --git a/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf 
b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf
new file mode 100644
index ..d03132bf01c1
--- /dev/null
+++ b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf
@@ -0,0 +1,25 @@
+## @file
+# RISC-V Library to call SBI ecalls
+#
+#  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION = 0x0001001b
+  BASE_NAME   = BaseRiscVSbiLib
+  FILE_GUID   = D742CF3D-E600-4009-8FB5-318073008508
+  MODULE_TYPE = BASE
+  VERSION_STRING  = 1.0
+  LIBRARY_CLASS   = RiscVSbiLib
+
+[Sources]
+  BaseRiscVSbiLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  BaseLib
diff --git a/MdePkg/Include/Library/BaseRiscVSbiLib.h 
b/MdePkg/Include/Library/BaseRiscVSbiLib.h
new file mode 100644
index ..e9886187526a
--- /dev/null
+++ b/MdePkg/Include/Library/BaseRiscVSbiLib.h
@@ -0,0 +1,127 @@
+/** @file
+  Library to call the RISC-V SBI ecalls
+
+  Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights 
reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+- Hart - Hardware Thread, similar to a CPU core
+
+  Currently, EDK2 needs to call SBI only to set the time and to do system 
reset.
+
+**/
+
+#ifndef RISCV_SBI_LIB_H_
+#define RISCV_SBI_LIB_H_
+
+#include 
+
+/* SBI Extension IDs */
+#define SBI_EXT_TIME  0x54494D45
+#define SBI_EXT_SRST  0x53525354
+
+/* SBI function IDs for TIME extension*/
+#define SBI_EXT_TIME_SET_TIMER  0x0
+
+/* SBI function IDs for SRST extension */
+#define SBI_EXT_SRST_RESET  0x0
+
+#define SBI_SRST_RESET_TYPE_SHUTDOWN 0x0
+#define SBI_SRST_RESET_TYPE_COLD_REBOOT  0x1
+#define SBI_SRST_RESET_TYPE_WARM_REBOOT  0x2
+#define SBI_SRST_RESET_TYPE_LAST SBI_SRST_RESET_TYPE_WARM_REBOOT
+
+#define SBI_SRST_RESET_REASON_NONE 0x0
+#define SBI_SRST_RESET_REASON_SYSFAIL  0x1
+
+/* SBI return error codes */
+#define SBI_SUCCESS0
+#define SBI_ERR_FAILED -1
+#define SBI_ERR_NOT_SUPPORTED  -2
+#define SBI_ERR_INVALID_PARAM  -3
+#define SBI_ERR_DENIED -4
+#define SBI_ERR_INVALID_ADDRESS-5
+#define SBI_ERR_ALREADY_AVAILABLE  -6
+#define SBI_ERR_ALREADY_STARTED-7
+#define SBI_ERR_ALREADY_STOPPED-8
+
+#define SBI_LAST_ERR  SBI_ERR_ALREADY_STOPPED
+
+typedef struct {
+  UINT64BootHartId;
+  VOID  *PeiServiceTable;// PEI Service table
+  UINT64FlattenedDeviceTree; // Pointer to Flattened Device tree
+} EFI_RISCV_FIRMWARE_CONTEXT;
+
+//
+// EDK2 OpenSBI firmware extension return status.
+//
+typedef struct {
+  UINTNError; ///< SBI status code
+  UINTNValue; ///< Value returned
+} SBI_RET;
+
+VOID
+EFIAPI
+SbiSetTimer (
+  IN  UINT64  Time
+  );
+
+EFI_STATUS
+EFIAPI
+SbiSystemReset (
+  IN  UINTN  ResetType,
+  IN  UINTN  ResetReason
+  );
+
+/**
+  Get firmware context of the calling hart.
+
+  @param[out] FirmwareContext  The firmware context pointer.
+**/
+VOID
+EFIAPI
+GetFirmwareContext (
+  OUT EFI_RISCV_FIRMWARE_CONTEXT  **FirmwareContext
+  );
+
+/**
+  Set firmware context of the calling hart.
+
+  @param[in] FirmwareContext   The firmware context pointer.
+**/
+VOID
+EFIAPI
+SetFirmwareContext (
+  IN 

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 03/30] MdePkg/BaseLib: RISC-V: Add few more helper functions

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Few of the basic helper functions required for any
RISC-V CPU were added in edk2-platforms. To support
qemu virt, they need to be added in BaseLib.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 
Cc: Daniel Schaefer 
Signed-off-by: Sunil V L 
---
 MdePkg/Library/BaseLib/BaseLib.inf  |  2 +
 MdePkg/Include/Library/BaseLib.h| 50 ++
 MdePkg/Library/BaseLib/RiscV64/CpuScratch.S | 31 
 MdePkg/Library/BaseLib/RiscV64/ReadTimer.S  | 23 +
 MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S | 53 ++--
 5 files changed, 155 insertions(+), 4 deletions(-)

diff --git a/MdePkg/Library/BaseLib/BaseLib.inf 
b/MdePkg/Library/BaseLib/BaseLib.inf
index 9ed46a584a14..babbee1ca08b 100644
--- a/MdePkg/Library/BaseLib/BaseLib.inf
+++ b/MdePkg/Library/BaseLib/BaseLib.inf
@@ -401,6 +401,8 @@ [Sources.RISCV64]
   RiscV64/RiscVCpuPause.S   | GCC
   RiscV64/RiscVInterrupt.S  | GCC
   RiscV64/FlushCache.S  | GCC
+  RiscV64/CpuScratch.S  | GCC
+  RiscV64/ReadTimer.S   | GCC
 
 [Sources.LOONGARCH64]
   Math64.c
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index f3f59f21c2ea..b4f4e45a1486 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -151,6 +151,56 @@ typedef struct {
 
 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT  8
 
+VOID
+  RiscVSetSupervisorScratch (
+ UINT64
+ );
+
+UINT64
+RiscVGetSupervisorScratch (
+  VOID
+  );
+
+VOID
+  RiscVSetSupervisorStvec (
+   UINT64
+   );
+
+UINT64
+RiscVGetSupervisorStvec (
+  VOID
+  );
+
+UINT64
+RiscVGetSupervisorTrapCause (
+  VOID
+  );
+
+VOID
+  RiscVSetSupervisorAddressTranslationRegister (
+UINT64
+);
+
+UINT64
+RiscVReadTimer (
+  VOID
+  );
+
+VOID
+RiscVEnableTimerInterrupt (
+  VOID
+  );
+
+VOID
+RiscVDisableTimerInterrupt (
+  VOID
+  );
+
+VOID
+RiscVClearPendingTimerInterrupt (
+  VOID
+  );
+
 #endif // defined (MDE_CPU_RISCV64)
 
 #if defined (MDE_CPU_LOONGARCH64)
diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuScratch.S 
b/MdePkg/Library/BaseLib/RiscV64/CpuScratch.S
new file mode 100644
index ..dd7adc21eb07
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/CpuScratch.S
@@ -0,0 +1,31 @@
+//--
+//
+// CPU scratch register related functions for RISC-V
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//--
+
+#include 
+
+.data
+.align 3
+.section .text
+
+//
+// Set Supervisor mode scratch.
+// @param a0 : Value set to Supervisor mode scratch
+//
+ASM_FUNC (RiscVSetSupervisorScratch)
+csrrw a1, CSR_SSCRATCH, a0
+ret
+
+//
+// Get Supervisor mode scratch.
+// @retval a0 : Value in Supervisor mode scratch
+//
+ASM_FUNC (RiscVGetSupervisorScratch)
+csrr a0, CSR_SSCRATCH
+ret
diff --git a/MdePkg/Library/BaseLib/RiscV64/ReadTimer.S 
b/MdePkg/Library/BaseLib/RiscV64/ReadTimer.S
new file mode 100644
index ..39a06efa51ef
--- /dev/null
+++ b/MdePkg/Library/BaseLib/RiscV64/ReadTimer.S
@@ -0,0 +1,23 @@
+//--
+//
+// Read CPU timer
+//
+// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights 
reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//--
+
+#include 
+
+.data
+.align 3
+.section .text
+
+//
+// Read TIME CSR.
+// @retval a0 : 64-bit timer.
+//
+ASM_FUNC (RiscVReadTimer)
+csrr a0, CSR_TIME
+ret
diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S 
b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
index 87b3468fc7fd..6a1b90a7e45c 100644
--- a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
+++ b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S
@@ -8,13 +8,13 @@
 //
 
//--
 
+#include 
+
 ASM_GLOBAL ASM_PFX(RiscVDisableSupervisorModeInterrupts)
 ASM_GLOBAL ASM_PFX(RiscVEnableSupervisorModeInterrupt)
 ASM_GLOBAL ASM_PFX(RiscVGetSupervisorModeInterrupts)
 
-#define  SSTATUS_SIE 0x0002
-#define  CSR_SSTATUS 0x100
-  #define  SSTATUS_SPP_BIT_POSITION  8
+#define  SSTATUS_SPP_BIT_POSITION  8
 
 //
 // This routine disables supervisor mode interrupt
@@ -53,11 +53,56 @@ InTrap:
   ret
 
 //
+// Set Supervisor mode trap vector.
+// @param a0 : Value set to Supervisor mode trap vector
+//
+ASM_FUNC (RiscVSetSupervisorStvec)
+  

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 02/30] MdePkg: Add RISCV_EFI_BOOT_PROTOCOL related definitions

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

RISC-V UEFI based platforms need to support RISCV_EFI_BOOT_PROTOCOL.
Add this protocol GUID definition and the header file required.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 
Cc: Abner Chang 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 MdePkg/MdePkg.dec   |  5 +++
 MdePkg/Include/Protocol/RiscVBootProtocol.h | 34 
 2 files changed, 39 insertions(+)

diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 4c81cbd75ab2..dda1d5e15b9f 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1918,6 +1918,11 @@ [Protocols]
   #
   ## Include/Protocol/ShellDynamicCommand.h
   gEfiShellDynamicCommandProtocolGuid  = { 0x3c7200e9, 0x005f, 0x4ea4, {0x87, 
0xde, 0xa3, 0xdf, 0xac, 0x8a, 0x27, 0xc3 }}
+  #
+  # Protocols defined for RISC-V systems
+  #
+  ## Include/Protocol/RiscVBootProtocol.h
+  gRiscVEfiBootProtocolGuid  = { 0xccd15fec, 0x6f73, 0x4eec, { 0x83, 0x95, 
0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf }}
 
 #
 # [Error.gEfiMdePkgTokenSpaceGuid]
diff --git a/MdePkg/Include/Protocol/RiscVBootProtocol.h 
b/MdePkg/Include/Protocol/RiscVBootProtocol.h
new file mode 100644
index ..ed223b852d34
--- /dev/null
+++ b/MdePkg/Include/Protocol/RiscVBootProtocol.h
@@ -0,0 +1,34 @@
+/** @file
+  RISC-V Boot Protocol mandatory for RISC-V UEFI platforms.
+
+  @par Revision Reference:
+  The protocol specification can be found at
+  https://github.com/riscv-non-isa/riscv-uefi
+
+  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_BOOT_PROTOCOL_H_
+#define RISCV_BOOT_PROTOCOL_H_
+
+typedef struct _RISCV_EFI_BOOT_PROTOCOL RISCV_EFI_BOOT_PROTOCOL;
+
+#define RISCV_EFI_BOOT_PROTOCOL_REVISION  0x0001
+#define RISCV_EFI_BOOT_PROTOCOL_LATEST_VERSION \
+RISCV_EFI_BOOT_PROTOCOL_REVISION
+
+typedef
+EFI_STATUS
+(EFIAPI *EFI_GET_BOOT_HARTID)(
+  IN RISCV_EFI_BOOT_PROTOCOL   *This,
+  OUT UINTN*BootHartId
+  );
+
+typedef struct _RISCV_EFI_BOOT_PROTOCOL {
+  UINT64 Revision;
+  EFI_GET_BOOT_HARTIDGetBootHartId;
+} RISCV_EFI_BOOT_PROTOCOL;
+
+#endif
-- 
2.38.0



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




[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 01/30] MdePkg/Register: Add register definition header files for RISC-V

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Add register definitions and access routines for RISC-V. These
headers are leveraged from opensbi repo.

Cc: Daniel Schaefer 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 
Signed-off-by: Sunil V L 
Acked-by: Abner Chang 
---
 MdePkg/Include/Register/RiscV64/RiscVEncoding.h | 119 
 MdePkg/Include/Register/RiscV64/RiscVImpl.h |  25 
 2 files changed, 144 insertions(+)

diff --git a/MdePkg/Include/Register/RiscV64/RiscVEncoding.h 
b/MdePkg/Include/Register/RiscV64/RiscVEncoding.h
new file mode 100644
index ..5c2989b797bf
--- /dev/null
+++ b/MdePkg/Include/Register/RiscV64/RiscVEncoding.h
@@ -0,0 +1,119 @@
+/** @file
+  RISC-V CSR encodings
+
+  Copyright (c) 2019, Western Digital Corporation or its affiliates. All 
rights reserved.
+  Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_ENCODING_H_
+#define RISCV_ENCODING_H_
+
+#define MSTATUS_SIE 0x0002UL
+#define MSTATUS_MIE 0x0008UL
+#define MSTATUS_SPIE_SHIFT  5
+#define MSTATUS_SPIE(1UL << MSTATUS_SPIE_SHIFT)
+#define MSTATUS_UBE 0x0040UL
+#define MSTATUS_MPIE0x0080UL
+#define MSTATUS_SPP_SHIFT   8
+#define MSTATUS_SPP (1UL << MSTATUS_SPP_SHIFT)
+#define MSTATUS_MPP_SHIFT   11
+#define MSTATUS_MPP (3UL << MSTATUS_MPP_SHIFT)
+
+#define SSTATUS_SIE MSTATUS_SIE
+#define SSTATUS_SPIE_SHIFT  MSTATUS_SPIE_SHIFT
+#define SSTATUS_SPIEMSTATUS_SPIE
+#define SSTATUS_SPP_SHIFT   MSTATUS_SPP_SHIFT
+#define SSTATUS_SPP MSTATUS_SPP
+
+#define IRQ_S_SOFT1
+#define IRQ_VS_SOFT   2
+#define IRQ_M_SOFT3
+#define IRQ_S_TIMER   5
+#define IRQ_VS_TIMER  6
+#define IRQ_M_TIMER   7
+#define IRQ_S_EXT 9
+#define IRQ_VS_EXT10
+#define IRQ_M_EXT 11
+#define IRQ_S_GEXT12
+#define IRQ_PMU_OVF   13
+
+#define MIP_SSIP(1UL << IRQ_S_SOFT)
+#define MIP_VSSIP   (1UL << IRQ_VS_SOFT)
+#define MIP_MSIP(1UL << IRQ_M_SOFT)
+#define MIP_STIP(1UL << IRQ_S_TIMER)
+#define MIP_VSTIP   (1UL << IRQ_VS_TIMER)
+#define MIP_MTIP(1UL << IRQ_M_TIMER)
+#define MIP_SEIP(1UL << IRQ_S_EXT)
+#define MIP_VSEIP   (1UL << IRQ_VS_EXT)
+#define MIP_MEIP(1UL << IRQ_M_EXT)
+#define MIP_SGEIP   (1UL << IRQ_S_GEXT)
+#define MIP_LCOFIP  (1UL << IRQ_PMU_OVF)
+
+#define SIP_SSIP  MIP_SSIP
+#define SIP_STIP  MIP_STIP
+
+#define PRV_U  0UL
+#define PRV_S  1UL
+#define PRV_M  3UL
+
+#define SATP64_MODE  0xF000ULL
+#define SATP64_ASID  0x0000ULL
+#define SATP64_PPN   0x0FFFULL
+
+#define SATP_MODE_OFF   0UL
+#define SATP_MODE_SV32  1UL
+#define SATP_MODE_SV39  8UL
+#define SATP_MODE_SV48  9UL
+#define SATP_MODE_SV57  10UL
+#define SATP_MODE_SV64  11UL
+
+#define SATP_MODE  SATP64_MODE
+
+/* User Counters/Timers */
+#define CSR_CYCLE  0xc00
+#define CSR_TIME   0xc01
+
+/* Supervisor Trap Setup */
+#define CSR_SSTATUS  0x100
+#define CSR_SEDELEG  0x102
+#define CSR_SIDELEG  0x103
+#define CSR_SIE  0x104
+#define CSR_STVEC0x105
+
+/* Supervisor Configuration */
+#define CSR_SENVCFG  0x10a
+
+/* Supervisor Trap Handling */
+#define CSR_SSCRATCH  0x140
+#define CSR_SEPC  0x141
+#define CSR_SCAUSE0x142
+#define CSR_STVAL 0x143
+#define CSR_SIP   0x144
+
+/* Supervisor Protection and Translation */
+#define CSR_SATP  0x180
+
+/* Trap/Exception Causes */
+#define CAUSE_MISALIGNED_FETCH  0x0
+#define CAUSE_FETCH_ACCESS  0x1
+#define CAUSE_ILLEGAL_INSTRUCTION   0x2
+#define CAUSE_BREAKPOINT0x3
+#define CAUSE_MISALIGNED_LOAD   0x4
+#define CAUSE_LOAD_ACCESS   0x5
+#define CAUSE_MISALIGNED_STORE  0x6
+#define CAUSE_STORE_ACCESS  0x7
+#define CAUSE_USER_ECALL0x8
+#define CAUSE_SUPERVISOR_ECALL  0x9
+#define CAUSE_VIRTUAL_SUPERVISOR_ECALL  0xa
+#define CAUSE_MACHINE_ECALL 0xb
+#define CAUSE_FETCH_PAGE_FAULT  0xc
+#define CAUSE_LOAD_PAGE_FAULT   0xd
+#define CAUSE_STORE_PAGE_FAULT  0xf
+#define CAUSE_FETCH_GUEST_PAGE_FAULT0x14
+#define CAUSE_LOAD_GUEST_PAGE_FAULT 0x15
+#define CAUSE_VIRTUAL_INST_FAULT0x16
+#define CAUSE_STORE_GUEST_PAGE_FAULT0x17
+
+#endif
diff --git a/MdePkg/Include/Register/RiscV64/RiscVImpl.h 
b/MdePkg/Include/Register/RiscV64/RiscVImpl.h
new file mode 100644
index ..ee5c2ba60377
--- /dev/null
+++ b/MdePkg/Include/Register/RiscV64/RiscVImpl.h
@@ -0,0 +1,25 @@
+/** @file
+  RISC-V package definitions.
+
+  Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All 
rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_IMPL_H_
+#define RISCV_IMPL_H_
+
+#include 
+
+#define _ASM_FUNC(Name, Section)\
+  .global   Name  ; \
+  .section  #Section, "ax"; \
+  .type Name, %function   

[edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V5 00/30] Add support for RISC-V virt machine

2022-10-30 Thread Sunil V L
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076

Add support for RISC-V qemu virt machine. Most of the changes are migrated from
edk2-platforms repo and followed the latest guidelines for EDK2 code 
structuring.

The changes at a high level are,

1) MdePkg:
- Add RISC-V register definitions
- Add RISCV_EFI_BOOT_PROTOCOL related definitions
- Add BaseRiscVSbiLib library to make ecall to machine mode firmware

2) UefiCpuPkg:
- Refactor modules/libraries as per latest guidelines
- Add RISC-V support in below modules/libraries.
- CpuTimerLib, CpuExceptionHandlerLib, CpuDxe
- Add new CpuTimerDxe module

3) ArmVirtPkg:
- Migrate below libraries/modules to OvmfPkg
- PlatformBootManagerLib, PlatformHasAcpiDtDxe
- Fix up the consumers of these modules

4) OvmfPkg:
- Refactor the libraries/modules as per latest guidelines
- Add RISC-V support for below libraries/modules.
- Sec, ResetSystemLib, PlatformInitLib, PlatformPei
- Add VirtNorFlashPlatformLib (Copied from ArmVirtPkg and SbsaQemu)
- Add new DSC/FDF files to build for RISC-V virt machine

5) MdeModulePkg/EmbeddedPkg:
- Migrated NvVarStoreFormattedLib from EmbeddedPkg to MdeModulePkg
- Fix up the consumers of NvVarStoreFormattedLib
 
Changes since V4:
1) Rebased and added ACKs
2) Dropped few patches related to VirtNorFlashDxe since they are 
already taken care by Ard.

Changes since V3:
1) Addressed Abner's comments
2) Changed folder name from Ia32_X64 to Ia32X64 as per latest 
guidelines.
2) Rebased

Changes since V2:
1) Fixed issues detected by CI 
(https://github.com/tianocore/edk2/pull/3471)
2) Added an extra patch to fix up the consumers of 
NvVarStoreFormattedLib

Changes since V1:
1) Added couple of patches from Ard to optimize the NorFlashDxe in Ovmf.
   Note: There will be a separate patch series in future to update 
existing
   consumers of NorFlashDxe driver.
2) Migrated NvVarStoreFormattedLib from EmbeddedPkg to MdeModulePkg
3) Created Null instance of the NorFlashPlatformLib library class
4) Moved NorFlashPlatformLib.h from ArmPlatformPkg

These changes are available at: 
https://github.com/vlsunil/edk2/tree/RiscV64QemuVirt

Cc: Abner Chang 
Cc: Daniel Schaefer 
Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 
Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Jordan Justen 
Cc: Gerd Hoffmann 
Cc: Rebecca Cran 
Cc: Peter Grehan 
Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: James Bottomley 
Cc: Min Xu 
Cc: Tom Lendacky 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Andrew Fish 
Cc: Jian J Wang 
Cc: Anup Patel 
Cc: Heinrich Schuchardt 

Sunil V L (30):
  MdePkg/Register: Add register definition header files for RISC-V
  MdePkg: Add RISCV_EFI_BOOT_PROTOCOL related definitions
  MdePkg/BaseLib: RISC-V: Add few more helper functions
  MdePkg: Add BaseRiscVSbiLib Library for RISC-V
  OvmfPkg/PlatformInitLib: Refactor to allow other architectures
  OvmfPkg/PlatformInitLib: Add support for RISC-V
  OvmfPkg/ResetSystemLib: Refactor to allow other architectures.
  OvmfPkg/ResetSystemLib: Add support for RISC-V
  OvmfPkg/Sec: Refactor to allow other architectures
  OvmfPkg/Sec: Add RISC-V support
  OvmfPkg/PlatformPei: Refactor to allow other architectures
  OvmfPkg/PlatformPei: Add support for RISC-V
  UefiCpuPkg/CpuTimerLib: Refactor to allow other architectures
  UefiCpuPkg/CpuTimerLib: Add support for RISC-V
  UefiCpuPkg/CpuExceptionHandlerLib: Refactor to allow other
architectures
  UefiCpuPkg/CpuExceptionHandlerLib: Add support for RISC-V
  UefiCpuPkg/CpuDxe: Refactor to allow other architectures
  UefiCpuPkg/CpuDxe: Add support for RISC-V
  UefiCpuPkg/CpuDxe: Add RISCV_EFI_BOOT_PROTOCOL support
  UefiCpuPkg: Add CpuTimerDxe module
  ArmVirtPkg/PlatformHasAcpiDtDxe: Move to OvmfPkg
  ArmVirtPkg: Fix up the location of PlatformHasAcpiDtDxe
  ArmVirtPkg/PlatformBootManagerLib: Move to OvmfPkg
  ArmVirtPkg: Fix up the paths to PlatformBootManagerLib
  EmbeddedPkg/NvVarStoreFormattedLib: Migrate to MdeModulePkg
  ArmVirtPkg: Update the references to NvVarStoreFormattedLib
  OvmfPkg: Add VirtNorFlashPlatformLib library
  OvmfPkg: RiscVVirt: Add Qemu Virt platform support
  Maintainers.txt: Add entry for OvmfPkg/RiscVVirt
  UefiCpuPkg/UefiCpuPkg.ci.yaml: Ignore RISC-V file

 ArmVirtPkg/ArmVirtPkg.dec  
  |   9 -
 EmbeddedPkg/EmbeddedPkg.dec
  |   3 -
 MdeModulePkg/MdeModulePkg.dec  
  |   3 +
 MdePkg/MdePkg.dec  
  

Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code

2022-10-30 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Hi Ray,
Ok, the V2 send. Which rename SmmCpuFeaturesLiCommon.c to 
IntelSmmCpuFeaturesLib.c in the 1/3 patch.

Thanks
Abner

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ni, Ray via
> groups.io
> Sent: Friday, October 28, 2022 5:26 PM
> To: devel@edk2.groups.io; Chang, Abner 
> Cc: Attar, AbdulLateef (Abdul Lateef) ; Kirkendall,
> Garrett ; Grimes, Paul ;
> Dong, Eric ; Kumar, Rahul R 
> Subject: Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/SmmCpuFeaturesLib:
> Abstract arch dependent code
> 
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
> 
> 
> Can you do rename SmmCpuFeaturesLibCommon.c to
> IntelSmmCpuFeaturesLib.c?
> This helps to keep the change history because I see that almost all content 
> from
> Common.c is moved to Intelxxx.c.
> 
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Chang,
> > Abner via groups.io
> > Sent: Friday, September 30, 2022 5:52 PM
> > To: devel@edk2.groups.io
> > Cc: Abdul Lateef Attar ; Garrett Kirkendall
> > ; Paul Grimes ; Dong,
> > Eric ; Ni, Ray ; Kumar, Rahul R
> > 
> > Subject: [edk2-devel] [PATCH 1/2] UefiCpuPkg/SmmCpuFeaturesLib:
> > Abstract arch dependent code
> >
> > From: Abner Chang 
> >
> > This change strips away Intel X86 implementation and put it in the
> > IntelSmmCpuFeatureLib
> >
> > Signed-off-by: Abner Chang 
> > Cc: Abdul Lateef Attar 
> > Cc: Garrett Kirkendall 
> > Cc: Paul Grimes 
> > Cc: Eric Dong 
> > Cc: Ray Ni 
> > Cc: Rahul Kumar 
> > ---
> >  .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf   |   1 +
> >  .../SmmCpuFeaturesLibStm.inf  |   1 +
> >  .../StandaloneMmCpuFeaturesLib.inf|   1 +
> >  .../SmmCpuFeaturesLib/CpuFeaturesLib.h|   6 +
> >  .../IntelSmmCpuFeaturesLib.c  | 403 ++
> >  .../SmmCpuFeaturesLibCommon.c | 391 +
> >  6 files changed, 413 insertions(+), 390 deletions(-)  create mode
> > 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> >
> > diff --git
> > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> > index 7b5cef97008..9ac7dde78f8 100644
> > --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> > @@ -18,6 +18,7 @@
> >
> >  [Sources]
> >CpuFeaturesLib.h
> > +  IntelSmmCpuFeaturesLib.c
> >SmmCpuFeaturesLib.c
> >SmmCpuFeaturesLibCommon.c
> >SmmCpuFeaturesLibNoStm.c
> > diff --git
> > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> > index 85214ee31cd..86d367e0a09 100644
> > --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> > @@ -19,6 +19,7 @@
> >
> >  [Sources]
> >CpuFeaturesLib.h
> > +  IntelSmmCpuFeaturesLib.c
> >SmmCpuFeaturesLibCommon.c
> >SmmStm.c
> >SmmStm.h
> > diff --git
> > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> > nf
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> > nf
> > index 3eacab48db3..61890205e18 100644
> > ---
> > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> > nf
> > +++
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.i
> > nf
> > @@ -20,6 +20,7 @@
> >
> >  [Sources]
> >CpuFeaturesLib.h
> > +  IntelSmmCpuFeaturesLib.c
> >StandaloneMmCpuFeaturesLib.c
> >SmmCpuFeaturesLibCommon.c
> >SmmCpuFeaturesLibNoStm.c
> > diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> > index 8a1c2adc5c4..fd3e902547c 100644
> > --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
> > @@ -9,6 +9,12 @@
> >  #ifndef CPU_FEATURES_LIB_H_
> >  #define CPU_FEATURES_LIB_H_
> >
> > +#include  #include 
> > +#include  #include 
> > +#include 
> > +
> >  /**
> >Performs library initialization.
> >
> > diff --git
> > a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> > b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> > new file mode 100644
> > index 000..cb4897b21e3
> > --- /dev/null
> > +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
> > @@ -0,0 +1,403 @@
> > +/** @file
> > +Implementation shared across all library instances.
> > +
> > +Copyright (c) 2010 - 2019, Intel Corporation. All rights
> > +reserved. Copyright (c) Microsoft Corporation.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include "CpuFeaturesLib.h"
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +//
> > +// Machine Specific Registers (MSRs)
> > +//
> > 

[edk2-devel] [PATCH V2 3/3] UefiCpuPkg/SmmCpuFeaturesLib: Clean up header file inclusion in SmmStm.c

2022-10-30 Thread Chang, Abner via groups.io
From: Abner Chang 

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Remove the header files those are already included in
CpuFeatureLib.h.

Signed-off-by: Abner Chang 
Cc: Abdul Lateef Attar 
Cc: Garrett Kirkendall 
Cc: Paul Grimes 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
index 4e8f897f5e9..3cf162ada01 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
@@ -7,11 +7,8 @@
 **/
 
 #include 
-#include 
 #include 
-#include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
2.37.1.windows.1



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




[edk2-devel] [PATCH V2 2/3] UefiCpuPkg/SmmCpuFeaturesLib: Abstract arch dependent code

2022-10-30 Thread Chang, Abner via groups.io
From: Abner Chang 

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

This change stripped away the code that can be
shared with other archs or vendors from Intel
implementation and put in to the common file,
leaves the Intel X86 implementation in the
IntelSmmCpuFeatureLib. Also updates the header
file and INF file.

Signed-off-by: Abner Chang 
Cc: Abdul Lateef Attar 
Cc: Garrett Kirkendall 
Cc: Paul Grimes 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
---
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf   |   1 +
 .../SmmCpuFeaturesLibStm.inf  |   1 +
 .../StandaloneMmCpuFeaturesLib.inf|   1 +
 .../SmmCpuFeaturesLib/CpuFeaturesLib.h|   6 +
 .../IntelSmmCpuFeaturesLib.c  | 206 +
 .../SmmCpuFeaturesLibCommon.c | 216 ++
 6 files changed, 227 insertions(+), 204 deletions(-)
 create mode 100644 
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
index 7b5cef97008..9ac7dde78f8 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
@@ -18,6 +18,7 @@
 
 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLib.c
   SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
index 85214ee31cd..86d367e0a09 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
@@ -19,6 +19,7 @@
 
 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   SmmCpuFeaturesLibCommon.c
   SmmStm.c
   SmmStm.h
diff --git 
a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
index 3eacab48db3..61890205e18 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
@@ -20,6 +20,7 @@
 
 [Sources]
   CpuFeaturesLib.h
+  IntelSmmCpuFeaturesLib.c
   StandaloneMmCpuFeaturesLib.c
   SmmCpuFeaturesLibCommon.c
   SmmCpuFeaturesLibNoStm.c
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
index 8a1c2adc5c4..fd3e902547c 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h
@@ -9,6 +9,12 @@
 #ifndef CPU_FEATURES_LIB_H_
 #define CPU_FEATURES_LIB_H_
 
+#include 
+#include 
+#include 
+#include 
+#include 
+
 /**
   Performs library initialization.
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
index 75a0ec8e948..cb4897b21e3 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
@@ -7,16 +7,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include 
-#include 
-#include 
+#include "CpuFeaturesLib.h"
+
 #include 
-#include 
-#include 
-#include 
 #include 
 #include 
-#include "CpuFeaturesLib.h"
 
 //
 // Machine Specific Registers (MSRs)
@@ -287,64 +282,6 @@ SmmCpuFeaturesInitializeProcessor (
   FinishSmmCpuFeaturesInitializeProcessor ();
 }
 
-/**
-  This function updates the SMRAM save state on the currently executing CPU
-  to resume execution at a specific address after an RSM instruction.  This
-  function must evaluate the SMRAM save state to determine the execution mode
-  the RSM instruction resumes and update the resume execution address with
-  either NewInstructionPointer32 or NewInstructionPoint.  The auto HALT restart
-  flag in the SMRAM save state must always be cleared.  This function returns
-  the value of the instruction pointer from the SMRAM save state that was
-  replaced.  If this function returns 0, then the SMRAM save state was not
-  modified.
-
-  This function is called during the very first SMI on each CPU after
-  SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode
-  to signal that the SMBASE of each CPU has been updated before the default
-  SMBASE address is used for the first SMI to the next CPU.
-
-  @param[in] CpuIndex The index of the CPU to hook.  The value
-  must be between 0 and the NumberOfCpus
-  field in the System Management System 
Table
-  (SMST).
-  @param[in] CpuState Pointer to SMRAM Save State Map for the
-  currently executing CPU.
-  @param[in] NewInstructionPointer32  Instruction pointer to use if resuming to
-   

[edk2-devel] [PATCH V2 1/3] UefiCpuPkg/SmmCpuFeaturesLib: Rename the common C file

2022-10-30 Thread Chang, Abner via groups.io
From: Abner Chang 

BZ# 4093: Abstract SmmCpuFeaturesLib for sharing common code

Rename SmmCpuFeaturesLiCommon.c to
IntelSmmCpuFeaturesLib, because it was developed
specifically for Intel implementation. The code
that can be shared by other archs or vendors
will be stripped away and put in the common
file in the next patch.

Signed-off-by: Abner Chang 
Cc: Abdul Lateef Attar 
Cc: Garrett Kirkendall 
Cc: Paul Grimes 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
---
 .../{SmmCpuFeaturesLibCommon.c => IntelSmmCpuFeaturesLib.c}   | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLibCommon.c => 
IntelSmmCpuFeaturesLib.c} (100%)

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
similarity index 100%
rename from UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibCommon.c
rename to UefiCpuPkg/Library/SmmCpuFeaturesLib/IntelSmmCpuFeaturesLib.c
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95722): https://edk2.groups.io/g/devel/message/95722
Mute This Topic: https://groups.io/mt/94663860/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] ArmPlatformPkg/Drivers/NorFlashDxe:avoid index out of bound

2022-10-30 Thread Ard Biesheuvel
On Sat, 29 Oct 2022 at 11:29, Wenyi Xie  wrote:
>
> The size of array BlockMap is 1 in struct FirmwareVolumeHeader, but in
> function InitializeFvAndVariableStoreHeaders, BlockMap[1] is been written.

The size of BlockMap[] is not 1. BlockMap is a flexible array declared
in an old fashioned way, and because the type definition is covered by
the spec, we can not change it. Given that this is established idiom,
compilers don't tend to warn about this.

> The memory of BlockMap[1] is already allocated, so the code is OK. But
> it is better to use a new point to assign this memory.
>
> Cc: Leif Lindholm 
> Cc: Ard Biesheuvel 
> Signed-off-by: Wenyi Xie 

Thanks for the patch but this driver is going to be deleted soon so no point.

There is new version of this driver in OvmfPkg/ but given the above, I
don't think there is anything that needs fixing here.

> ---
>  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c 
> b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
> index 0767581308d2..2130e2e76344 100644
> --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
> +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvb.c
> @@ -47,6 +47,7 @@ InitializeFvAndVariableStoreHeaders (
>VOID*Headers;
>UINTN   HeadersLength;
>EFI_FIRMWARE_VOLUME_HEADER  *FirmwareVolumeHeader;
> +  EFI_FV_BLOCK_MAP_ENTRY  *BlockMapEntry;
>VARIABLE_STORE_HEADER   *VariableStoreHeader;
>UINT32  NvStorageFtwSpareSize;
>UINT32  NvStorageFtwWorkingSize;
> @@ -151,10 +152,15 @@ InitializeFvAndVariableStoreHeaders (
>FirmwareVolumeHeader->Revision  = EFI_FVH_REVISION;
>FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 
> 1;
>FirmwareVolumeHeader->BlockMap[0].Length= Instance->Media.BlockSize;
> -  FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;
> -  FirmwareVolumeHeader->BlockMap[1].Length= 0;
>FirmwareVolumeHeader->Checksum  = CalculateCheckSum16 ((UINT16 
> *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength);
>
> +  //
> +  // EFI_FV_BLOCK_MAP_ENTRY
> +  //
> +  BlockMapEntry= (EFI_FV_BLOCK_MAP_ENTRY *)((UINTN)Headers + 
> sizeof (EFI_FIRMWARE_VOLUME_HEADER));
> +  BlockMapEntry->NumBlocks = 0;
> +  BlockMapEntry->Length= 0;
> +
>//
>// VARIABLE_STORE_HEADER
>//
> --
> 2.20.1.windows.1
>


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