Re: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new EfiFindAcpiTableBySignature() API

2018-09-02 Thread Ni, Ruiyu
That's fine to be in UefiLib. It's already a combo library.

But I do recommend we think about how to handle multiple tables with same 
signature.
When we are adding new APIs, we not only need to evaluate the existing real 
case, but also
we need to generalize the real cases and try to think about the more flexible 
interface.


Thanks/Ray

> -Original Message-
> From: Zeng, Star
> Sent: Monday, September 3, 2018 11:26 AM
> To: Yao, Jiewen ; Ni, Ruiyu ;
> Kinney, Michael D 
> Cc: edk2-devel@lists.01.org; Younas khan ;
> Gao, Liming ; Zeng, Star 
> Subject: RE: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new
> EfiFindAcpiTableBySignature() API
> 
> Good idea.
> 
> I did consider DSDT and multiple SSDTs cases. But I did not find any real case
> for them.
> So I made the code simply for current cases, and the code can be easily
> enhanced later for DSDT, a new API can be added later for multiple SSDTs.
> 
> About adding the new API in UefiLib VS new library class, I did also consider 
> it
> and even created code for new library class
> (g...@github.com:lzeng14/edk2.git branch
> FindAcpiTableBySignature_UefiAcpiTableLib).
> But I remember I did discuss it with Mike and Jiewen, we recommended
> UefiLib as it will do not require any platform change.
> 
> 
> 
> Thanks,
> Star
> -Original Message-
> From: Yao, Jiewen
> Sent: Saturday, September 1, 2018 7:04 AM
> To: Ni, Ruiyu 
> Cc: Zeng, Star ; edk2-devel@lists.01.org; Kinney,
> Michael D ; Younas khan
> ; Gao, Liming 
> Subject: RE: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new
> EfiFindAcpiTableBySignature() API
> 
> Good idea on LocateNextAcpiTable().
> 
> 
> > -Original Message-
> > From: Ni, Ruiyu
> > Sent: Saturday, September 1, 2018 12:29 AM
> > To: Yao, Jiewen 
> > Cc: Zeng, Star ; edk2-devel@lists.01.org; Kinney,
> > Michael D ; Younas khan
> > ; Gao, Liming 
> > Subject: Re: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new
> > EfiFindAcpiTableBySignature() API
> >
> > I think LocateNextAcpiTable() is more proper to handle the multiple
> > tables with same signature. It will carry three parameters, one is the
> > table header stored in configuration table, one is the signature, another is
> the previous located table.
> > Can we return a common table header other than void*?
> >
> > Is there better place other than UefiLib?
> > Do we need to add a new library class like AcpiLib?
> >
> > 发自我的 iPhone
> >
> > > 在 2018年8月31日,下午8:00,Yao, Jiewen 
> 写
> > 道:
> > >
> > > Good enhancement.
> > >
> > > I have 2 additional thought:
> > >
> > > 1) How to handle DSDT?
> > > We have special code to handle FACS, but no DSDT.
> > >
> > > 2) How to handle SSDT or other multiple ACPI tables?
> > > We may have multiple SSDT. Usually, it is identified as OEMID.
> > > Do we want to provide similar function for them?
> > >
> > > Anyway, just *additional* thought. :-) Current implementation is
> > > good enough for check in.
> > >
> > > Reviewed-by: jiewen@intel.com
> > >
> > > Thank you
> > > Yao Jiewen
> > >
> > >
> > >> -Original Message-
> > >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf
> > >> Of
> > Star
> > >> Zeng
> > >> Sent: Friday, August 31, 2018 7:29 PM
> > >> To: edk2-devel@lists.01.org
> > >> Cc: Kinney, Michael D ; Younas khan
> > >> ; Yao, Jiewen
> ;
> > Gao,
> > >> Liming ; Zeng, Star 
> > >> Subject: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new
> > >> EfiFindAcpiTableBySignature() API
> > >>
> > >> https://bugzilla.tianocore.org/show_bug.cgi?id=967
> > >> Request to add a library function for GetAcpiTable() in order to
> > >> get ACPI table using signature as input.
> > >>
> > >> After evaluation, we found there are many duplicated code to find
> > >> ACPI table by signature in different modules.
> > >>
> > >> This patch adds new EfiFindAcpiTableBySignature() API in UefiLib
> > >> for the request and also the following patch to remove the
> > >> duplicated code.
> > >>
> > >> Cc: Younas khan 
> > >> Cc: Michael D Kinney 
> > >> Cc: Liming Gao 
> > >> Cc: Jiewen Yao 
> > >> Contributed-under: TianoCore Contribution Agreement 1.1
> > >> Signed-off-by: Star Zeng 
> > >> ---
> > >> MdePkg/Include/Library/UefiLib.h   |  17 +++
> > >> MdePkg/Library/UefiLib/Acpi.c  | 226
> > >> +
> > >> MdePkg/Library/UefiLib/UefiLib.inf |   3 +
> > >> 3 files changed, 246 insertions(+)
> > >> create mode 100644 MdePkg/Library/UefiLib/Acpi.c
> > >>
> > >> diff --git a/MdePkg/Include/Library/UefiLib.h
> > >> b/MdePkg/Include/Library/UefiLib.h
> > >> index f80067f11103..8dd25f324fd2 100644
> > >> --- a/MdePkg/Include/Library/UefiLib.h
> > >> +++ b/MdePkg/Include/Library/UefiLib.h
> > >> @@ -1595,4 +1595,21 @@ EfiOpenFileByDevicePath (
> > >>  IN UINT64OpenMode,
> > >>  IN UINT64Attributes
> > >>  );
> > >> +
> > >> +/**
> > >> +  This function finds ACPI table by signature.
> > >> +  It will find the table in gEfiAcpi20TableGuid system
> > >> 

Re: [edk2] [PATCH 0/4] Add PEI Stack Guard feature

2018-09-02 Thread Wang, Jian J
Here're the tests I've done:

* Emulate stack overflow by calling a function recursively, for all BSP and 
APs, and
  check the RSP and CR2 to see if they're close in exception message.
* OS boot (x64): Fedora 26, Ubuntu 18.04, Windows 10, Windows 7 (Platform: OVMF)

Regards,
Jian

From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Yao, 
Jiewen
Sent: Monday, September 03, 2018 12:15 PM
To: edk2-devel ; edk2-devel@lists.01.org
Subject: Re: [edk2] [PATCH 0/4] Add PEI Stack Guard feature

Hi
Would you please add more description on what test has been done for this patch?

Thank you
Yao Jiewen

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org]
> Sent: Monday, September 3, 2018 11:16 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH 0/4] Add PEI Stack Guard feature
>
> This patch series try to add PEI Stack Guard feature. Please refer to
> following trackers for details.
>
> The machanism behind this feature is the same as Stack Guard for UEFI
> drivers, and similiar implementation is also employed.
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1126
>  https://bugzilla.tianocore.org/show_bug.cgi?id=1137
>
> Jian J Wang (4):
>   MdeModulePkg/DxeIpl: disable paging before creating new page table
>   UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI
> exceptions
>   UefiCpuPkg/MpInitLib: fix register restore issue in AP wakeup
>   UefiCpuPkg/CpuMpPei: support stack guard feature
>
>  MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c|  10 +
>  UefiCpuPkg/CpuMpPei/CpuMpPei.c | 269 -
>  UefiCpuPkg/CpuMpPei/CpuMpPei.h |  14 +
>  UefiCpuPkg/CpuMpPei/CpuMpPei.inf   |  11 +-
>  UefiCpuPkg/CpuMpPei/CpuPaging.c| 637
> +
>  .../CpuExceptionHandlerLib/PeiCpuException.c   |  27 +-
>  .../PeiCpuExceptionHandlerLib.inf  |   4 +
>  UefiCpuPkg/Library/MpInitLib/MpLib.c   |   8 +-
>  8 files changed, 962 insertions(+), 18 deletions(-)
>  create mode 100644 UefiCpuPkg/CpuMpPei/CpuPaging.c
>
> --
> 2.16.2.windows.1
>
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 7/7] MdeModulePkg/SdMmcPciHcDxe: Execute card detect only for RemovableSlot

2018-09-02 Thread Marcin Wojtas
Some devices can be non removable (such as eMMC) and checking
Present State Register on host controller may falsely return
an information that device is not present. Execute this
check conditionally on the SloType field value.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index 50c1e74..174efa9 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -678,12 +678,18 @@ SdMmcPciHcDriverBindingStart (
 //
 // Check whether there is a SD/MMC card attached
 //
-Status = SdMmcHcCardDetect (PciIo, Slot, );
-if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {
-  continue;
-} else if (!MediaPresent) {
-  DEBUG ((DEBUG_INFO, "SdMmcHcCardDetect: No device attached in 
Slot[%d]!!!\n", Slot));
-  continue;
+if (Private->Slot[Slot].SlotType == RemovableSlot) {
+  Status = SdMmcHcCardDetect (PciIo, Slot, );
+  if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {
+continue;
+  } else if (!MediaPresent) {
+DEBUG ((
+  DEBUG_INFO,
+  "SdMmcHcCardDetect: No device attached in Slot[%d]!!!\n",
+  Slot
+  ));
+continue;
+  }
 }
 
 Status = SdMmcHcInitHost (Private, Slot);
-- 
2.7.4

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


[edk2] [PATCH 5/7] MdeModulePkg/SdMmcPciHcDxe: Adjust eMMC clock and bus width sequence

2018-09-02 Thread Marcin Wojtas
According to JESD84-B50-1 chapter A.6 (documentation about eMMC4.5
standard) step "Changing the data bus width" (A.6.3) should be
execute after step "Switching to high-speed mode" (A.6.2).

This patch fixes the bus-width/clock-setting sequence
in EmmcSwitchToHighSpeed ().

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
index e5e0c89..8615caa 100755
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
@@ -748,10 +748,6 @@ EmmcSwitchToHighSpeed (
 
   Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
 
-  Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, IsDdr, BusWidth);
-  if (EFI_ERROR (Status)) {
-return Status;
-  }
   //
   // Set to Hight Speed timing
   //
@@ -799,6 +795,11 @@ EmmcSwitchToHighSpeed (
 return Status;
   }
 
+  Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, IsDdr, BusWidth);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
   if (mOverride != NULL && mOverride->SwitchClockFreqPost != NULL) {
 Status = mOverride->SwitchClockFreqPost (
   Private->ControllerHandle,
-- 
2.7.4

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


[edk2] [PATCH 4/7] MdeModulePkg/SdMmcPciHcDxe: Allow overriding base clock frequency

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

Some SdMmc host controllers are run by clocks with different
frequency than it is reflected in Capabilities Register 1.
Because the bitfield is only 8 bits wide, a maximum value
that could be obtained from hardware is 255MHz.

In case the actual frequency exceeds 255MHz, the 8-bit BaseClkFreq
member of SD_MMC_HC_SLOT_CAP structure occurs to be not sufficient
to be used for setting the clock speed in SdMmcHcClockSupply
function.

This patch adds new UINT32 array ('BaseClkFreq[]') to
SD_MMC_HC_PRIVATE_DATA structure for specifying
the input clock speed for each slot of the host controller.
All routines that are used for clock configuration are
updated accordingly.

This patch also adds new BaseClockFreq callback to SdMmcOverride
protocol which allows to change new bigger BaseClkFreq
field.

The patch reuses original commit from edk2-platforms:
20f6f144d3a8 ("Marvell/Drivers: XenonDxe: Allow overriding base clock
frequency")

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h |  6 +
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h   | 12 +
 MdeModulePkg/Include/Protocol/SdMmcOverride.h  | 26 +++
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c|  4 +--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c  |  4 +--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 19 +-
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c   | 27 +++-
 7 files changed, 76 insertions(+), 22 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h
index c683600..8c1a589 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h
@@ -118,6 +118,12 @@ typedef struct {
   UINT64  MaxCurrent[SD_MMC_HC_MAX_SLOT];
 
   UINT32  ControllerVersion;
+
+  //
+  // Some controllers may require to override base clock frequency
+  // value stored in Capabilities Register 1.
+  //
+  UINT32  BaseClkFreq[SD_MMC_HC_MAX_SLOT];
 } SD_MMC_HC_PRIVATE_DATA;
 
 #define SD_MMC_HC_TRB_SIG SIGNATURE_32 ('T', 'R', 'B', 'T')
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
index 525828c..01ff9f2 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
@@ -178,12 +178,14 @@ typedef struct {
 
   @param[in]  SlotThe slot number of the SD card to send the 
command to.
   @param[in]  Capability  The buffer to store the capability data.
+  @param[in]  BaseClkFreq The base clock frequency of host controller in 
MHz.
 
 **/
 VOID
 DumpCapabilityReg (
   IN UINT8Slot,
-  IN SD_MMC_HC_SLOT_CAP   *Capability
+  IN SD_MMC_HC_SLOT_CAP   *Capability,
+  IN UINT32   BaseClkFreq
   );
 
 /**
@@ -436,7 +438,7 @@ SdMmcHcStopClock (
   @param[in] PciIo  The PCI IO protocol instance.
   @param[in] Slot   The slot number of the SD card to send the command 
to.
   @param[in] ClockFreq  The max clock frequency to be set. The unit is KHz.
-  @param[in] Capability The capability of the slot.
+  @param[in] BaseClkFreqThe base clock frequency of host controller in MHz.
 
   @retval EFI_SUCCESS   The clock is supplied successfully.
   @retval OthersThe clock isn't supplied successfully.
@@ -447,7 +449,7 @@ SdMmcHcClockSupply (
   IN EFI_PCI_IO_PROTOCOL*PciIo,
   IN UINT8  Slot,
   IN UINT64 ClockFreq,
-  IN SD_MMC_HC_SLOT_CAP Capability
+  IN UINT32 BaseClkFreq
   );
 
 /**
@@ -495,7 +497,7 @@ SdMmcHcSetBusWidth (
 
   @param[in] PciIo  The PCI IO protocol instance.
   @param[in] Slot   The slot number of the SD card to send the command 
to.
-  @param[in] Capability The capability of the slot.
+  @param[in] BaseClkFreqThe base clock frequency of host controller in MHz.
 
   @retval EFI_SUCCESS   The clock is supplied successfully.
   @retval OthersThe clock isn't supplied successfully.
@@ -505,7 +507,7 @@ EFI_STATUS
 SdMmcHcInitClockFreq (
   IN EFI_PCI_IO_PROTOCOL*PciIo,
   IN UINT8  Slot,
-  IN SD_MMC_HC_SLOT_CAP Capability
+  IN UINT32 BaseClkFreq
   );
 
 /**
diff --git a/MdeModulePkg/Include/Protocol/SdMmcOverride.h 
b/MdeModulePkg/Include/Protocol/SdMmcOverride.h
index 6ba1c43..941c04d 100644
--- a/MdeModulePkg/Include/Protocol/SdMmcOverride.h
+++ b/MdeModulePkg/Include/Protocol/SdMmcOverride.h
@@ -120,6 +120,28 @@ EFI_STATUS
   IN  SD_MMC_UHS_TIMING   Timing
   );
 
+/**
+
+  Callback that allow to override base clock frequency with value
+  higher then 255MHz
+
+  @param[in]  ControllerHandle  The 

[edk2] [PATCH 2/7] MdeModulePkg/SdMmcPciHcDxe: Add UhsSignaling to SdMmcOverride protocol

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

Some SD Host Controlers use different values in Host Control 2 Register
to select UHS Mode. This patch adds new UhsSignaling callback to
the SdMmcOverride protocol. UHS signaling configuration is moved
to a common, default routine (SdMmcHcUhsSignaling),
which is called when SdMmcOverride does not cover this functionality.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h |  50 +++
 MdeModulePkg/Include/Protocol/SdMmcOverride.h|  26 
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c  | 150 
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c|  36 +++--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c |  69 +
 5 files changed, 263 insertions(+), 68 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
index e3fadb5..525828c 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
@@ -68,6 +68,39 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #define SD_MMC_HC_HOST_CTRL1_HS_ENABLE  (1 << 2)
 
 //
+// SD Host Controler bits to HOST_CTRL2 register
+//
+#define SD_MMC_HC_CTRL_UHS_MASK   0x0007
+#define SD_MMC_HC_CTRL_UHS_SDR12  0x
+#define SD_MMC_HC_CTRL_UHS_SDR25  0x0001
+#define SD_MMC_HC_CTRL_UHS_SDR50  0x0002
+#define SD_MMC_HC_CTRL_UHS_SDR104 0x0003
+#define SD_MMC_HC_CTRL_UHS_DDR50  0x0004
+#define SD_MMC_HC_CTRL_MMC_DDR52  0x0004
+#define SD_MMC_HC_CTRL_MMC_SDR50  0x0002
+#define SD_MMC_HC_CTRL_MMC_SDR25  0x0001
+#define SD_MMC_HC_CTRL_MMC_SDR12  0x
+#define SD_MMC_HC_CTRL_HS200  0x0003
+#define SD_MMC_HC_CTRL_HS400  0x0005
+
+//
+// Timing modes for uhs
+//
+typedef enum {
+  SdMmcUhsSdr12,
+  SdMmcUhsSdr25,
+  SdMmcUhsSdr50,
+  SdMmcUhsSdr104,
+  SdMmcUhsDdr50,
+  SdMmcMmcDdr52,
+  SdMmcMmcSdr50,
+  SdMmcMmcSdr25,
+  SdMmcMmcSdr12,
+  SdMmcMmcHs200,
+  SdMmcMmcHs400,
+} SD_MMC_UHS_TIMING;
+
+//
 // The transfer modes supported by SD Host Controller
 // Simplified Spec 3.0 Table 1-2
 //
@@ -513,4 +546,21 @@ SdMmcHcInitTimeoutCtrl (
   IN UINT8  Slot
   );
 
+/**
+  Set SD Host Controler control 2 registry according to selected speed.
+
+  @param[in] PciIo  The PCI IO protocol instance.
+  @param[in] Slot   The slot number of the SD card to send the command 
to.
+  @param[in] Timing The timing to select.
+
+  @retval EFI_SUCCESS   The timing is set successfully.
+  @retval OthersThe timing isn't set successfully.
+**/
+EFI_STATUS
+SdMmcHcUhsSignaling (
+  IN EFI_PCI_IO_PROTOCOL*PciIo,
+  IN UINT8  Slot,
+  IN SD_MMC_UHS_TIMING  Timing
+  );
+
 #endif
diff --git a/MdeModulePkg/Include/Protocol/SdMmcOverride.h 
b/MdeModulePkg/Include/Protocol/SdMmcOverride.h
index 0766252..a7a57e8 100644
--- a/MdeModulePkg/Include/Protocol/SdMmcOverride.h
+++ b/MdeModulePkg/Include/Protocol/SdMmcOverride.h
@@ -17,6 +17,7 @@
 #ifndef __SD_MMC_OVERRIDE_H__
 #define __SD_MMC_OVERRIDE_H__
 
+#include 
 #include 
 
 #define EDKII_SD_MMC_OVERRIDE_PROTOCOL_GUID \
@@ -77,6 +78,27 @@ EFI_STATUS
   IN  EDKII_SD_MMC_PHASE_TYPE PhaseType
   );
 
+/**
+
+  Override function for uhs signaling
+
+  @param[in]  ControllerHandle  The EFI_HANDLE of the controller.
+  @param[in]  Slot  The 0 based slot index.
+  @param[in]  TimingThe timing which should be set by
+host controller.
+
+  @retval EFI_SUCCESS   The override function completed successfully.
+  @retval EFI_NOT_FOUND The specified controller or slot does not 
exist.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI * EDKII_SD_MMC_UHS_SIGNALING) (
+  IN  EFI_HANDLE  ControllerHandle,
+  IN  UINT8   Slot,
+  IN  SD_MMC_UHS_TIMING   Timing
+  );
+
 struct _EDKII_SD_MMC_OVERRIDE {
   //
   // Protocol version of this implementation
@@ -90,6 +112,10 @@ struct _EDKII_SD_MMC_OVERRIDE {
   // Callback to invoke SD/MMC override hooks
   //
   EDKII_SD_MMC_NOTIFY_PHASE NotifyPhase;
+  //
+  // Callback to override SD/MMC host controller uhs signaling
+  //
+  EDKII_SD_MMC_UHS_SIGNALINGUhsSignaling;
 };
 
 extern EFI_GUID gEdkiiSdMmcOverrideProtocolGuid;
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
index b3903b4..d285249 100755
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
@@ -740,10 +740,13 @@ EmmcSwitchToHighSpeed (
   IN UINT8  BusWidth
   )
 {
-  EFI_STATUS  Status;
-  UINT8   HsTiming;
-  UINT8   HostCtrl1;
-  UINT8   HostCtrl2;
+  EFI_STATUS  

[edk2] [PATCH 6/7] MdeModulePkg/SdMmcPciHcDxe: Fix SdMmcHcReset to set only necesery bits

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

SdMmcHcReset used to set all bits of Software Reset Register to 1
including reserved ones.

Now only first bit is set which means "Software Reset for All".

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index e7c51e6..c9a0acc 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -459,8 +459,8 @@ SdMmcHcReset (
   }
 
   PciIo   = Private->PciIo;
-  SwReset = 0xFF;
-  Status  = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_SW_RST, FALSE, sizeof 
(SwReset), );
+  SwReset = BIT0;
+  Status  = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_SW_RST, sizeof (SwReset), 
);
 
   if (EFI_ERROR (Status)) {
 DEBUG ((DEBUG_ERROR, "SdMmcHcReset: write full 1 fails: %r\n", Status));
@@ -472,7 +472,7 @@ SdMmcHcReset (
  Slot,
  SD_MMC_HC_SW_RST,
  sizeof (SwReset),
- 0xFF,
+ BIT0,
  0x00,
  SD_MMC_HC_GENERIC_TIMEOUT
  );
-- 
2.7.4

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


[edk2] [platforms: PATCH 4/7] Marvell/Armada70x0Db: Introduce board description library

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

This patch implements ArmadaBoarDescLib library for
Armada7040 Development Board and add to it ArmadaBoardDescSdMmcGet
function with description of connected Xenon host controllers.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc 
 |  3 +
 
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
 | 34 ++
 
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
   | 66 
 3 files changed, 103 insertions(+)
 create mode 100644 
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
 create mode 100644 
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c

diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc 
b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
index e0bf447..a935f36 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
@@ -54,6 +54,9 @@
 [Components.AARCH64]
   Silicon/Marvell/Armada7k8k/AcpiTables/Armada70x0Db.inf
 
+[LibraryClasses.common]
+  
ArmadaBoardDescLib|Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
+
 

 #
 # Pcd Section - list of all EDK II PCD Entries defined by this Platform
diff --git 
a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
 
b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
new file mode 100644
index 000..b26f55b
--- /dev/null
+++ 
b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
@@ -0,0 +1,34 @@
+## @file
+#
+#  Copyright (C) 2018, Marvell International Ltd. and its affiliates
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION= 0x0001001A
+  BASE_NAME  = Armada70x0DbBoardDescLib
+  FILE_GUID  = 3164c8d9-19d4-4ad6-8196-cea094b1ddf1
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = ArmadaBoardDescLib
+
+[Sources]
+  Armada70x0DbBoardDescLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  DebugLib
+  IoLib
diff --git 
a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
 
b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
new file mode 100644
index 000..dd5e3a0
--- /dev/null
+++ 
b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
@@ -0,0 +1,66 @@
+/**
+*
+*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
+*
+*  This program and the accompanying materials are licensed and made available
+*  under the terms and conditions of the BSD License which accompanies this
+*  distribution. The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+*
+**/
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+//
+// Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
+//
+STATIC
+MV_BOARD_SDMMC_DESC mSdMmcDescTemplate[] = {
+  { /* eMMC 0xF06E */
+0, /* SOC will be filled by MvBoardDescDxe */
+0, /* SdMmcDevCount will be filled by MvBoardDescDxe */
+FALSE, /* Xenon1v8Enabled */
+FALSE, /* Xenon8BitBusEnabled */
+TRUE,  /* XenonSlowModeEnabled */
+0x40,  /* XenonTuningStepDivisor */
+EmbeddedSlot /* SlotType */
+  },
+  { /* SD/MMC 0xF278 */
+0, /* SOC will be filled by MvBoardDescDxe */
+0, /* SdMmcDevCount will be filled by MvBoardDescDxe */
+FALSE, /* Xenon1v8Enabled */
+FALSE, /* Xenon8BitBusEnabled */
+FALSE, /* XenonSlowModeEnabled */
+0x19,  /* XenonTuningStepDivisor */
+EmbeddedSlot /* SlotType */
+  }
+};
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescSdMmcGet (
+  IN OUT UINTN   *SdMmcDevCount,
+  IN OUT MV_BOARD_SDMMC_DESC **SdMmcDesc
+  )
+{
+  *SdMmcDevCount = ARRAY_SIZE (mSdMmcDescTemplate);
+
+  *SdMmcDesc = AllocateCopyPool (sizeof (mSdMmcDescTemplate),
+ );
+  if (*SdMmcDesc == NULL) {
+DEBUG ((DEBUG_ERROR, 

[edk2] [PATCH 3/7] MdeModulePkg/SdMmcPciHcDxe: Add SwitchClockFreqPost to SdMmcOverride

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

Some SD Host Controlers need to do additional opperations after clock
frequency switch.

This patch add new callback to SdMmcOverride protocol.
The SwitchClockFreqPost callback is called after EmmcSwitchClockFreq
and SdMmcHcClockSupply.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 MdeModulePkg/Include/Protocol/SdMmcOverride.h   | 33 ++--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c | 57 
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c   | 17 ++
 3 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Include/Protocol/SdMmcOverride.h 
b/MdeModulePkg/Include/Protocol/SdMmcOverride.h
index a7a57e8..6ba1c43 100644
--- a/MdeModulePkg/Include/Protocol/SdMmcOverride.h
+++ b/MdeModulePkg/Include/Protocol/SdMmcOverride.h
@@ -99,23 +99,48 @@ EFI_STATUS
   IN  SD_MMC_UHS_TIMING   Timing
   );
 
+/**
+
+  Additional operations specific for host controller
+
+  @param[in]  ControllerHandle  The EFI_HANDLE of the controller.
+  @param[in]  Slot  The 0 based slot index.
+  @param[in]  TimingThe timing which should be set by
+host controller.
+
+  @retval EFI_SUCCESS   The override function completed successfully.
+  @retval EFI_NOT_FOUND The specified controller or slot does not 
exist.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI * EDKII_SD_MMC_POST_CLOCK_FREQ_SWITCH) (
+  IN  EFI_HANDLE  ControllerHandle,
+  IN  UINT8   Slot,
+  IN  SD_MMC_UHS_TIMING   Timing
+  );
+
 struct _EDKII_SD_MMC_OVERRIDE {
   //
   // Protocol version of this implementation
   //
-  UINTN Version;
+  UINTNVersion;
   //
   // Callback to override SD/MMC host controller capability bits
   //
-  EDKII_SD_MMC_CAPABILITY   Capability;
+  EDKII_SD_MMC_CAPABILITY  Capability;
   //
   // Callback to invoke SD/MMC override hooks
   //
-  EDKII_SD_MMC_NOTIFY_PHASE NotifyPhase;
+  EDKII_SD_MMC_NOTIFY_PHASENotifyPhase;
   //
   // Callback to override SD/MMC host controller uhs signaling
   //
-  EDKII_SD_MMC_UHS_SIGNALINGUhsSignaling;
+  EDKII_SD_MMC_UHS_SIGNALING   UhsSignaling;
+  //
+  // Callback to add host controller specific operations after SwitchClockFreq
+  //
+  EDKII_SD_MMC_POST_CLOCK_FREQ_SWITCH  SwitchClockFreqPost;
 };
 
 extern EFI_GUID gEdkiiSdMmcOverrideProtocolGuid;
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
index d285249..78ee3a5 100755
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
@@ -795,6 +795,26 @@ EmmcSwitchToHighSpeed (
 
   HsTiming = 1;
   Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, 
ClockFreq);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  if (mOverride != NULL && mOverride->SwitchClockFreqPost != NULL) {
+Status = mOverride->SwitchClockFreqPost (
+  Private->ControllerHandle,
+  Slot,
+  Timing
+  );
+if (EFI_ERROR (Status)) {
+  DEBUG ((
+DEBUG_ERROR,
+"%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
+__FUNCTION__,
+Status
+));
+  return Status;
+}
+  }
 
   return Status;
 }
@@ -881,6 +901,23 @@ EmmcSwitchToHS200 (
 return Status;
   }
 
+  if (mOverride != NULL && mOverride->SwitchClockFreqPost != NULL) {
+Status = mOverride->SwitchClockFreqPost (
+  Private->ControllerHandle,
+  Slot,
+  Timing
+  );
+if (EFI_ERROR (Status)) {
+  DEBUG ((
+DEBUG_ERROR,
+"%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
+__FUNCTION__,
+Status
+));
+  return Status;
+}
+  }
+
   Status = EmmcTuningClkForHs200 (PciIo, PassThru, Slot, BusWidth);
 
   return Status;
@@ -964,6 +1001,26 @@ EmmcSwitchToHS400 (
 
   HsTiming = 3;
   Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, 
ClockFreq);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
+  if (mOverride != NULL && mOverride->SwitchClockFreqPost != NULL) {
+Status = mOverride->SwitchClockFreqPost (
+  Private->ControllerHandle,
+  Slot,
+  Timing
+  );
+if (EFI_ERROR (Status)) {
+  DEBUG ((
+DEBUG_ERROR,
+"%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
+__FUNCTION__,
+Status
+));
+  return Status;
+}
+  }
 
   return Status;
 }
diff --git 

[edk2] [platforms: PATCH 6/7] Marvell/Drivers: MvBoardDesc: Extend information for SdMmc

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

Extend MvBoardDescSdMmcGet function to fill MV_BOARD_SDMMC_DESC
with Xenon specific info obtained from ArmadaBoardDescLib.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf |  1 +
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c   | 24 +---
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf 
b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
index 41f72d6..0b93948 100644
--- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
+++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
@@ -47,6 +47,7 @@
   Silicon/Marvell/Marvell.dec
 
 [LibraryClasses]
+  ArmadaBoardDescLib
   ArmadaSoCDescLib
   DebugLib
   MemoryAllocationLib
diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c 
b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
index 39dc06c..f71bfc4 100644
--- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
+++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
@@ -270,6 +270,7 @@ MvBoardDescSdMmcGet (
 {
   UINT8 *SdMmcDeviceEnabled;
   UINTN SdMmcCount, SdMmcDeviceTableSize, SdMmcIndex, Index;
+  UINTN SdMmcDevCount;
   MV_BOARD_SDMMC_DESC *BoardDesc;
   MV_SOC_SDMMC_DESC *SoCDesc;
   EFI_STATUS Status;
@@ -280,6 +281,13 @@ MvBoardDescSdMmcGet (
 return Status;
   }
 
+  /* Get per-board configuration of the controllers */
+  Status = ArmadaBoardDescSdMmcGet (, );
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: ArmadaBoardDescSdMmcGet filed\n", __FUNCTION__));
+return Status;
+  }
+
   /*
* Obtain table with enabled SDMMC controllers
* which is represented as an array of UINT8 values
@@ -294,18 +302,12 @@ MvBoardDescSdMmcGet (
   SdMmcDeviceTableSize = PcdGetSize (PcdPciESdhci);
 
   /* Check if PCD with SDMMC controllers is correctly defined */
-  if (SdMmcDeviceTableSize > SdMmcCount) {
+  if ((SdMmcDeviceTableSize > SdMmcCount) ||
+  (SdMmcDeviceTableSize < SdMmcDevCount)) {
 DEBUG ((DEBUG_ERROR, "%a: Wrong PcdPciESdhci format\n", __FUNCTION__));
 return EFI_INVALID_PARAMETER;
   }
 
-  /* Allocate and fill board description */
-  BoardDesc = AllocateZeroPool (SdMmcDeviceTableSize * sizeof 
(MV_BOARD_SDMMC_DESC));
-  if (BoardDesc == NULL) {
-DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
-return EFI_OUT_OF_RESOURCES;
-  }
-
   SdMmcIndex = 0;
   for (Index = 0; Index < SdMmcDeviceTableSize; Index++) {
 if (!SdMmcDeviceEnabled[Index]) {
@@ -313,6 +315,12 @@ MvBoardDescSdMmcGet (
   continue;
 }
 
+if (SdMmcIndex >= SdMmcDevCount) {
+  DEBUG ((DEBUG_ERROR,
+"%a: More enabled devices than returned by ArmadaBoardDescSdMmcGet\n",
+__FUNCTION__));
+  return EFI_INVALID_PARAMETER;
+}
 BoardDesc[SdMmcIndex].SoC = [Index];
 SdMmcIndex++;
   }
-- 
2.7.4

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


[edk2] [platforms: PATCH 5/7] Marvell/Armada80x0Db: Introduce board description library

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

This patch implements ArmadaBoarDescLib library for
Armada8040 Development Board and add to it ArmadaBoardDescSdMmcGet
function with description of connected Xenon host controllers.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc 
 |  3 +
 
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
 | 34 ++
 
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
   | 66 
 3 files changed, 103 insertions(+)
 create mode 100644 
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
 create mode 100644 
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c

diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc 
b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
index 92e2dc8..42f7bd3 100644
--- a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
@@ -54,6 +54,9 @@
 [Components.AARCH64]
   Silicon/Marvell/Armada7k8k/AcpiTables/Armada80x0Db.inf
 
+[LibraryClasses.common]
+  
ArmadaBoardDescLib|Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
+
 

 #
 # Pcd Section - list of all EDK II PCD Entries defined by this Platform
diff --git 
a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
 
b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
new file mode 100644
index 000..2d39d96
--- /dev/null
+++ 
b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
@@ -0,0 +1,34 @@
+## @file
+#
+#  Copyright (C) 2018, Marvell International Ltd. and its affiliates
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION= 0x0001001A
+  BASE_NAME  = Armada80x0DbBoardDescLib
+  FILE_GUID  = fee9e874-1481-4b4f-9882-966bd0d1310f
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = ArmadaBoardDescLib
+
+[Sources]
+  Armada80x0DbBoardDescLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  DebugLib
+  IoLib
diff --git 
a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
 
b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
new file mode 100644
index 000..00d696d
--- /dev/null
+++ 
b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
@@ -0,0 +1,66 @@
+/**
+*
+*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
+*
+*  This program and the accompanying materials are licensed and made available
+*  under the terms and conditions of the BSD License which accompanies this
+*  distribution. The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+*
+**/
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+//
+// Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
+//
+STATIC
+MV_BOARD_SDMMC_DESC mSdMmcDescTemplate[] = {
+  { /* eMMC 0xF06E */
+0, /* SOC will be filled by MvBoardDescDxe */
+0, /* SdMmcDevCount will be filled by MvBoardDescDxe */
+TRUE,  /* Xenon1v8Enabled */
+TRUE,  /* Xenon8BitBusEnabled */
+TRUE,  /* XenonSlowModeEnabled */
+0x40,  /* XenonTuningStepDivisor */
+EmbeddedSlot /* SlotType */
+  },
+  { /* SD/MMC 0xF278 */
+0, /* SOC will be filled by MvBoardDescDxe */
+0, /* SdMmcDevCount will be filled by MvBoardDescDxe */
+FALSE, /* Xenon1v8Enabled */
+FALSE, /* Xenon8BitBusEnabled */
+FALSE, /* XenonSlowModeEnabled */
+0x19,  /* XenonTuningStepDivisor */
+EmbeddedSlot /* SlotType */
+  }
+};
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescSdMmcGet (
+  IN OUT UINTN   *SdMmcDevCount,
+  IN OUT MV_BOARD_SDMMC_DESC **SdMmcDesc
+  )
+{
+  *SdMmcDevCount = ARRAY_SIZE (mSdMmcDescTemplate);
+
+  *SdMmcDesc = AllocateCopyPool (sizeof (mSdMmcDescTemplate),
+ );
+  if (*SdMmcDesc == NULL) {
+DEBUG ((DEBUG_ERROR, 

[edk2] [platforms: PATCH 2/7] Marvell/Library: ArmadaBoardDescLib: Extend SDMMC information

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

Added fields specific for Xenon host controller and declaration
of ArmadaBoardDescSdMmcGet function.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h 
b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
index ee8e06e..4bb7a43 100644
--- a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
+++ b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
@@ -14,6 +14,8 @@
 #ifndef __ARMADA_BOARD_DESC_LIB_H__
 #define __ARMADA_BOARD_DESC_LIB_H__
 
+#include 
+
 #include 
 
 //
@@ -57,7 +59,12 @@ typedef struct {
 //
 typedef struct {
   MV_SOC_SDMMC_DESC *SoC;
-  UINTN  SdMmcDevCount;
+  UINTNSdMmcDevCount;
+  BOOLEAN  Xenon1v8Enabled;
+  BOOLEAN  Xenon8BitBusEnabled;
+  BOOLEAN  XenonSlowModeEnabled;
+  UINT8XenonTuningStepDivisor;
+  EFI_SD_MMC_SLOT_TYPE SlotType;
 } MV_BOARD_SDMMC_DESC;
 
 //
@@ -84,4 +91,12 @@ typedef struct {
   UINTN UtmiDevCount;
   UINTN UtmiPortType;
 } MV_BOARD_UTMI_DESC;
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescSdMmcGet (
+  IN OUT UINTN   *SdMmcDevCount,
+  IN OUT MV_BOARD_SDMMC_DESC **SdMmcDesc
+  );
+
 #endif /* __ARMADA_SOC_DESC_LIB_H__ */
-- 
2.7.4

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


[edk2] [platforms: PATCH 0/7] Armada7k8k Xenon driver rework

2018-09-02 Thread Marcin Wojtas
Hi,

This patchset adds one improvement for the Synquacer controller,
so that it can handle any SdMmcOverride protocol extending
in future. Other than that a huge rework of the Xenon
SdMmc controller is done - main changes:
- Describe per-board configration using MvBoardDescLib infrastructure
- Use this description in the Xenon driver and update its PHY
  configuration
- Switch to generic EDK2 SdMmc driver and use extended SdMmcOverride
  protocol

Patches are available in the github:
https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/commits/xenon-upstream-r20180902

Generic driver patches with fixes and extended SdMmcOverride protocol:
https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/commits/sdmmc-override-upstream-r20180902

I'm looking forward to the comments and remarks.

Best regards,
Marcin

Tomasz Michalec (7):
  Silicon/SynQuacer/PlatformDxe: Modify initialization of SdMmcOverride
  Marvell/Library: ArmadaBoardDescLib: Extend SDMMC information
  SolidRun/Armada80x0McBin: Introduce board description library
  Marvell/Armada70x0Db: Introduce board description library
  Marvell/Armada80x0Db: Introduce board description library
  Marvell/Drivers: MvBoardDesc: Extend information for SdMmc
  Marvell/Drivers: XenonDxe: Switch to use generic SdMmcPciHcDxe

 Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc  
   |3 +-
 Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc 
   |3 +
 Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc 
   |3 +
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc  
   |3 +
 Silicon/Marvell/Armada7k8k/Armada7k8k.fdf  
   |3 +-
 
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
   |   34 +
 
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
   |   34 +
 
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
 |   34 +
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf   
   |1 +
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/{SdMmcPciHcDxe.inf => XenonDxe.inf} 
   |   33 +-
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/SdMmcPciHcDxe.h 
   |  791 
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/SdMmcPciHci.h   
   |  550 --
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonPciHci.h   
   |  151 ++
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdMmcOverride.h
   |   53 +
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdhci.h
   |   84 +-
 Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h   
   |   17 +-
 
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
 |   66 +
 
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
 |   66 +
 
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
   |   66 +
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c 
   |   24 +-
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/ComponentName.c 
   |  211 ---
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/EmmcDevice.c
   | 1164 
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/SdDevice.c  
   | 1190 
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/SdMmcPciHcDxe.c 
   | 1320 --
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/SdMmcPciHci.c   
   | 1928 
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonPciHci.c   
   |  321 
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdMmcOverride.c
   |  455 +
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdhci.c
   |  397 ++--
 Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c 
   |   20 +-
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/SdMmcPciHcDxe.uni   
   |   23 -
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/SdMmcPciHcDxeExtra.uni  
   |   19 -
 31 files changed, 1686 insertions(+), 7381 deletions(-)
 create mode 100644 
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
 create mode 100644 
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
 create mode 100644 

[edk2] [platforms: PATCH 3/7] SolidRun/Armada80x0McBin: Introduce board description library

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

This patch implements ArmadaBoarDescLib library for
Armada80x0McBin comunity board and add to it ArmadaBoardDescSdMmcGet
function with description of connected Xenon host controllers.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc  
   |  3 +
 
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
 | 34 ++
 
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
   | 66 
 3 files changed, 103 insertions(+)
 create mode 100644 
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
 create mode 100644 
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c

diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc 
b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
index 52e2b9b..077224d 100644
--- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
@@ -55,6 +55,9 @@
 [Components.AARCH64]
   Silicon/Marvell/Armada7k8k/AcpiTables/Armada80x0McBin.inf
 
+[LibraryClasses.common]
+  
ArmadaBoardDescLib|Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
+
 

 #
 # Pcd Section - list of all EDK II PCD Entries defined by this Platform
diff --git 
a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
 
b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
new file mode 100644
index 000..63a4f66
--- /dev/null
+++ 
b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
@@ -0,0 +1,34 @@
+## @file
+#
+#  Copyright (C) 2018, Marvell International Ltd. and its affiliates
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION= 0x0001001A
+  BASE_NAME  = ArmadaMcBinBoardDescLib
+  FILE_GUID  = 8208558f-5f33-46e2-b5c5-43354384389e
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = ArmadaBoardDescLib
+
+[Sources]
+  Armada80x0McBinBoardDescLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  DebugLib
+  IoLib
diff --git 
a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
 
b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
new file mode 100644
index 000..9e38ce0
--- /dev/null
+++ 
b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
@@ -0,0 +1,66 @@
+/**
+*
+*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
+*
+*  This program and the accompanying materials are licensed and made available
+*  under the terms and conditions of the BSD License which accompanies this
+*  distribution. The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+*
+**/
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+//
+// Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
+//
+STATIC
+MV_BOARD_SDMMC_DESC mMcBinSdMmcDescTemplate[] = {
+  { /* eMMC 0xF06E */
+0, /* SOC will be filled by MvBoardDescDxe */
+0, /* SdMmcDevCount will be filled by MvBoardDescDxe */
+FALSE, /* Xenon1v8Enabled */
+TRUE,  /* Xenon8BitBusEnabled */
+TRUE,  /* XenonSlowModeEnabled */
+0x40,  /* XenonTuningStepDivisor */
+EmbeddedSlot /* SlotType */
+  },
+  { /* SD/MMC 0xF278 */
+0, /* SOC will be filled by MvBoardDescDxe */
+0, /* SdMmcDevCount will be filled by MvBoardDescDxe */
+FALSE, /* Xenon1v8Enabled */
+FALSE, /* Xenon8BitBusEnabled */
+FALSE, /* XenonSlowModeEnabled */
+0x19,  /* XenonTuningStepDivisor */
+EmbeddedSlot /* SlotType */
+  }
+};
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescSdMmcGet (
+  IN OUT UINTN   *SdMmcDevCount,
+  IN OUT MV_BOARD_SDMMC_DESC **SdMmcDesc
+  )
+{
+  *SdMmcDevCount = ARRAY_SIZE 

[edk2] [PATCH 1/7] MdeModulePkg/SdMmcPciHcDxe: Fix HS200 operation

2018-09-02 Thread Marcin Wojtas
When switching to any of high speed modes (HS, HS200, HS400)
there is need to set HS_ENABLE bit in Host Control 1 register
which allow Host Controller to output CMD and DAT lines on
both edges of clock. In Linux it is done after switching bus
width in sdhci_set_ios().

Also according to JESD84-B50-1 chapter 6.6.4 "HS200 timing mode
selection" (documentation about eMMC4.5 standard) there is
no need to disable clock when switching to HS200.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h |  5 
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c  | 30 +++-
 2 files changed, 9 insertions(+), 26 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
index e389d52..e3fadb5 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
@@ -63,6 +63,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #define SD_MMC_HC_CTRL_VER0xFE
 
 //
+// SD Host Control 1 Register bits description
+//
+#define SD_MMC_HC_HOST_CTRL1_HS_ENABLE  (1 << 2)
+
+//
 // The transfer modes supported by SD Host Controller
 // Simplified Spec 3.0 Table 1-2
 //
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
index c5fd214..b3903b4 100755
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
@@ -816,8 +816,8 @@ EmmcSwitchToHS200 (
 {
   EFI_STATUS  Status;
   UINT8   HsTiming;
+  UINT8   HostCtrl1;
   UINT8   HostCtrl2;
-  UINT16  ClockCtrl;
 
   if ((BusWidth != 4) && (BusWidth != 8)) {
 return EFI_INVALID_PARAMETER;
@@ -828,12 +828,10 @@ EmmcSwitchToHS200 (
 return Status;
   }
   //
-  // Set to HS200/SDR104 timing
-  //
-  //
-  // Stop bus clock at first
+  // Set to High Speed timing
   //
-  Status = SdMmcHcStopClock (PciIo, Slot);
+  HostCtrl1 = SD_MMC_HC_HOST_CTRL1_HS_ENABLE;
+  Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1, sizeof 
(HostCtrl1), );
   if (EFI_ERROR (Status)) {
 return Status;
   }
@@ -853,26 +851,6 @@ EmmcSwitchToHS200 (
   if (EFI_ERROR (Status)) {
 return Status;
   }
-  //
-  // Wait Internal Clock Stable in the Clock Control register to be 1 before 
set SD Clock Enable bit
-  //
-  Status = SdMmcHcWaitMmioSet (
- PciIo,
- Slot,
- SD_MMC_HC_CLOCK_CTRL,
- sizeof (ClockCtrl),
- BIT1,
- BIT1,
- SD_MMC_HC_GENERIC_TIMEOUT
- );
-  if (EFI_ERROR (Status)) {
-return Status;
-  }
-  //
-  // Set SD Clock Enable in the Clock Control register to 1
-  //
-  ClockCtrl = BIT2;
-  Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_CLOCK_CTRL, sizeof 
(ClockCtrl), );
 
   HsTiming = 2;
   Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, 
ClockFreq);
-- 
2.7.4

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


[edk2] [platforms: PATCH 1/7] Silicon/SynQuacer/PlatformDxe: Modify initialization of SdMmcOverride

2018-09-02 Thread Marcin Wojtas
From: Tomasz Michalec 

This patch changes way the EDKII_SD_MMC_OVERRIDE protocol
sturcture is allocated. Using AllocateZeroPool and then
seting callbacks in the structure allow driver to be immune to
adding new callbacks in SdMmcOveride protocol in future.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas 
---
 Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c | 20 
+---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c 
b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c
index e0987c9..1ad8b88 100644
--- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c
+++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c
@@ -59,6 +59,8 @@
 
 STATIC EFI_HANDLE mSdMmcControllerHandle;
 
+STATIC EDKII_SD_MMC_OVERRIDE   *mSdMmcOverride;
+
 STATIC EFI_ACPI_DESCRIPTION_HEADER  *mSsdt;
 STATIC UINTNmSsdtSize;
 STATIC VOID *mEventRegistration;
@@ -180,12 +182,6 @@ SynQuacerSdMmcNotifyPhase (
   return EFI_SUCCESS;
 }
 
-STATIC EDKII_SD_MMC_OVERRIDE mSdMmcOverride = {
-  EDKII_SD_MMC_OVERRIDE_PROTOCOL_VERSION,
-  SynQuacerSdMmcCapability,
-  SynQuacerSdMmcNotifyPhase,
-};
-
 STATIC
 VOID
 EFIAPI
@@ -255,10 +251,20 @@ RegisterEmmc (
  SYNQUACER_EMMC_BASE, SYNQUACER_EMMC_BASE_SZ);
   ASSERT_EFI_ERROR (Status);
 
+  mSdMmcOverride = AllocateZeroPool (sizeof (EDKII_SD_MMC_OVERRIDE));
+  if (mSdMmcOverride == NULL) {
+DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
+return EFI_OUT_OF_RESOURCES;
+  }
+
+  mSdMmcOverride->Version = EDKII_SD_MMC_OVERRIDE_PROTOCOL_VERSION;
+  mSdMmcOverride->Capability = SynQuacerSdMmcCapability;
+  mSdMmcOverride->NotifyPhase = SynQuacerSdMmcNotifyPhase;
+
   Handle = NULL;
   Status = gBS->InstallProtocolInterface (,
   ,
-  EFI_NATIVE_INTERFACE, (VOID **));
+  EFI_NATIVE_INTERFACE, mSdMmcOverride);
   ASSERT_EFI_ERROR (Status);
 
   return EFI_SUCCESS;
-- 
2.7.4

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


[edk2] [PATCH 0/7] SdMmc fixes and SdMmcOverride extension

2018-09-02 Thread Marcin Wojtas
Hi,

This patchset extends SdMmcOverride protocol with new callbacks:
* UhsSignaling - allow writing custom values to HostControl2 register
* SwitchClockFreqPost - perform additional opperations after clock switch
* BaseClockFreq - allow overriding base clock frequency
Also a couple of fixes for MMC, card detection and reset are submitted.
More details can be found in the commit messages.

Patches are available in the github:
https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/commits/sdmmc-override-upstream-r20180902

Please note that extending SdMmcOverride protocol was impacting
so far the only user of it (Synquacer controller). In paralel
edk2-platforms patchset, a patch can be found:
("Silicon/SynQuacer/PlatformDxe: Modify initialization of SdMmcOverride")
which immunizes for above and future extensions of the protocol:
https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/commits/xenon-upstream-r20180902

I'm looking forward to the comments and remarks.

Best regards,
Marcin

Marcin Wojtas (3):
  MdeModulePkg/SdMmcPciHcDxe: Fix HS200 operation
  MdeModulePkg/SdMmcPciHcDxe: Adjust eMMC clock and bus width sequence
  MdeModulePkg/SdMmcPciHcDxe: Execute card detect only for RemovableSlot

Tomasz Michalec (4):
  MdeModulePkg/SdMmcPciHcDxe: Add UhsSignaling to SdMmcOverride protocol
  MdeModulePkg/SdMmcPciHcDxe: Add SwitchClockFreqPost to SdMmcOverride
  MdeModulePkg/SdMmcPciHcDxe: Allow overriding base clock frequency
  MdeModulePkg/SdMmcPciHcDxe: Fix SdMmcHcReset to set only necesery bits

 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h |   6 +
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h   |  67 +-
 MdeModulePkg/Include/Protocol/SdMmcOverride.h  |  83 ++-
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c| 246 +---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c  |  55 -
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c |  37 ++-
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c   | 102 ++--
 7 files changed, 467 insertions(+), 129 deletions(-)

-- 
2.7.4

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


Re: [edk2] [PATCH 0/4] Add PEI Stack Guard feature

2018-09-02 Thread Yao, Jiewen
Hi
Would you please add more description on what test has been done for this patch?

Thank you
Yao Jiewen

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org]
> Sent: Monday, September 3, 2018 11:16 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH 0/4] Add PEI Stack Guard feature
> 
> This patch series try to add PEI Stack Guard feature. Please refer to
> following trackers for details.
> 
> The machanism behind this feature is the same as Stack Guard for UEFI
> drivers, and similiar implementation is also employed.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1126
>  https://bugzilla.tianocore.org/show_bug.cgi?id=1137
> 
> Jian J Wang (4):
>   MdeModulePkg/DxeIpl: disable paging before creating new page table
>   UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI
> exceptions
>   UefiCpuPkg/MpInitLib: fix register restore issue in AP wakeup
>   UefiCpuPkg/CpuMpPei: support stack guard feature
> 
>  MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c|  10 +
>  UefiCpuPkg/CpuMpPei/CpuMpPei.c | 269 -
>  UefiCpuPkg/CpuMpPei/CpuMpPei.h |  14 +
>  UefiCpuPkg/CpuMpPei/CpuMpPei.inf   |  11 +-
>  UefiCpuPkg/CpuMpPei/CpuPaging.c| 637
> +
>  .../CpuExceptionHandlerLib/PeiCpuException.c   |  27 +-
>  .../PeiCpuExceptionHandlerLib.inf  |   4 +
>  UefiCpuPkg/Library/MpInitLib/MpLib.c   |   8 +-
>  8 files changed, 962 insertions(+), 18 deletions(-)
>  create mode 100644 UefiCpuPkg/CpuMpPei/CpuPaging.c
> 
> --
> 2.16.2.windows.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdePkg: Update the comments in dec

2018-09-02 Thread shenglei
Correct the directory of a header file in comments.

Cc: Michael D Kinney 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: shenglei 
Reviewed-by: Liming Gao 
---
 MdePkg/MdePkg.dec | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 94ad814dc9..ddc621e076 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -767,7 +767,7 @@
   #
   # GUID defined in PI1.6
   #
-  ## Include/Guid/DiskInfo.h
+  ## Include/Protocol/DiskInfo.h
   gEfiDiskInfoSdMmcInterfaceGuid  = { 0x8deec992, 0xd39c, 0x4a5c, { 0xab, 
0x6b, 0x98, 0x6e, 0x14, 0x24, 0x2b, 0x9d }}
 
   #
-- 
2.18.0.windows.1

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


Re: [edk2] [PATCH 6/6] UefiCpuPkg PiSmmCpuDxeSmm: Use new EfiFindAcpiTableBySignature()

2018-09-02 Thread Zeng, Star
Thanks Laszlo. :)

Star
-Original Message-
From: Laszlo Ersek [mailto:ler...@redhat.com] 
Sent: Saturday, September 1, 2018 4:34 AM
To: Zeng, Star ; edk2-devel@lists.01.org
Cc: Ni, Ruiyu ; Dong, Eric ; Younas 
khan ; Gao, Liming ; Yao, 
Jiewen ; Kinney, Michael D 
Subject: Re: [edk2] [PATCH 6/6] UefiCpuPkg PiSmmCpuDxeSmm: Use new 
EfiFindAcpiTableBySignature()

On 08/31/18 13:29, Star Zeng wrote:
> https://bugzilla.tianocore.org/show_bug.cgi?id=967
> Request to add a library function for GetAcpiTable() in order to get 
> ACPI table using signature as input.
> 
> After evaluation, we found there are many duplicated code to find ACPI 
> table by signature in different modules.
> 
> This patch updates PiSmmCpuDxeSmm to use new
> EfiFindAcpiTableBySignature() and remove the duplicated code.
> 
> Cc: Younas khan 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Cc: Jiewen Yao 
> Cc: Ruiyu Ni 
> Cc: Eric Dong 
> Cc: Laszlo Ersek 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng 
> ---
>  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |  4 +-
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 84 
> ++
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h |  3 +-
>  3 files changed, 6 insertions(+), 85 deletions(-)
> 
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf 
> b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
> index a7fb7b0b1482..0fdc1b134ea3 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
> @@ -4,7 +4,7 @@
>  # This SMM driver performs SMM initialization, deploy SMM Entry 
> Vector,  # provides CPU specific services in SMM.
>  #
> -# Copyright (c) 2009 - 2016, Intel Corporation. All rights 
> reserved.
> +# Copyright (c) 2009 - 2018, Intel Corporation. All rights 
> +reserved.
>  # Copyright (c) 2017, AMD Incorporated. All rights reserved.  #  
> # This program and the accompanying materials @@ -114,8 +114,6 @@ 
> [Protocols]  [Guids]
>gEfiAcpiVariableGuid ## SOMETIMES_CONSUMES ## HOB # it 
> is used for S3 boot.
>gEfiGlobalVariableGuid   ## SOMETIMES_PRODUCES ## 
> Variable:L"SmmProfileData"
> -  gEfiAcpi20TableGuid  ## SOMETIMES_CONSUMES ## 
> SystemTable
> -  gEfiAcpi10TableGuid  ## SOMETIMES_CONSUMES ## 
> SystemTable
>gEdkiiPiSmmMemoryAttributesTableGuid ## CONSUMES ## SystemTable
>gEfiMemoryAttributesTableGuid## CONSUMES ## SystemTable
>  
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c 
> b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> index a743cf64f907..df643b72c517 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> @@ -1,7 +1,7 @@
>  /** @file
>  Enable SMM profile.
>  
> -Copyright (c) 2012 - 2017, Intel Corporation. All rights 
> reserved.
> +Copyright (c) 2012 - 2018, Intel Corporation. All rights 
> +reserved.
>  Copyright (c) 2017, AMD Incorporated. All rights reserved.
>  
>  This program and the accompanying materials @@ -726,84 +726,6 @@ 
> InitPaging (  }
>  
>  /**
> -  To find FADT in ACPI tables.
> -
> -  @param AcpiTableGuid   The GUID used to find ACPI table in UEFI 
> ConfigurationTable.
> -
> -  @return  FADT table pointer.
> -**/
> -EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE  * 
> -FindAcpiFadtTableByAcpiGuid (
> -  IN EFI_GUID  *AcpiTableGuid
> -  )
> -{
> -  EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *Rsdp;
> -  EFI_ACPI_DESCRIPTION_HEADER   *Rsdt;
> -  EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;
> -  UINTN Index;
> -  UINT32Data32;
> -  Rsdp  = NULL;
> -  Rsdt  = NULL;
> -  Fadt  = NULL;
> -  //
> -  // found ACPI table RSD_PTR from system table
> -  //
> -  for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
> -if (CompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), 
> AcpiTableGuid)) {
> -  //
> -  // A match was found.
> -  //
> -  Rsdp = gST->ConfigurationTable[Index].VendorTable;
> -  break;
> -}
> -  }
> -
> -  if (Rsdp == NULL) {
> -return NULL;
> -  }
> -
> -  Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->RsdtAddress;
> -  if (Rsdt == NULL || Rsdt->Signature != 
> EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
> -return NULL;
> -  }
> -
> -  for (Index = sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < 
> Rsdt->Length; Index = Index + sizeof (UINT32)) {
> -
> -Data32  = *(UINT32 *) ((UINT8 *) Rsdt + Index);
> -Fadt= (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) (UINT32 *) 
> (UINTN) Data32;
> -if (Fadt->Header.Signature == 
> EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
> -  break;
> -}
> -  }
> -
> -  if (Fadt == NULL || Fadt->Header.Signature != 
> EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
> -return NULL;
> -  }
> -
> -  return Fadt;
> -}
> -
> -/**
> -  

Re: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new EfiFindAcpiTableBySignature() API

2018-09-02 Thread Zeng, Star
Good idea.

I did consider DSDT and multiple SSDTs cases. But I did not find any real case 
for them.
So I made the code simply for current cases, and the code can be easily 
enhanced later for DSDT, a new API can be added later for multiple SSDTs.

About adding the new API in UefiLib VS new library class, I did also consider 
it and even created code for new library class 
(g...@github.com:lzeng14/edk2.git branch 
FindAcpiTableBySignature_UefiAcpiTableLib).
But I remember I did discuss it with Mike and Jiewen, we recommended UefiLib as 
it will do not require any platform change.



Thanks,
Star
-Original Message-
From: Yao, Jiewen 
Sent: Saturday, September 1, 2018 7:04 AM
To: Ni, Ruiyu 
Cc: Zeng, Star ; edk2-devel@lists.01.org; Kinney, Michael 
D ; Younas khan ; Gao, 
Liming 
Subject: RE: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new 
EfiFindAcpiTableBySignature() API

Good idea on LocateNextAcpiTable().


> -Original Message-
> From: Ni, Ruiyu
> Sent: Saturday, September 1, 2018 12:29 AM
> To: Yao, Jiewen 
> Cc: Zeng, Star ; edk2-devel@lists.01.org; Kinney, 
> Michael D ; Younas khan 
> ; Gao, Liming 
> Subject: Re: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new
> EfiFindAcpiTableBySignature() API
> 
> I think LocateNextAcpiTable() is more proper to handle the multiple 
> tables with same signature. It will carry three parameters, one is the 
> table header stored in configuration table, one is the signature, another is 
> the previous located table.
> Can we return a common table header other than void*?
> 
> Is there better place other than UefiLib?
> Do we need to add a new library class like AcpiLib?
> 
> 发自我的 iPhone
> 
> > 在 2018年8月31日,下午8:00,Yao, Jiewen  写
> 道:
> >
> > Good enhancement.
> >
> > I have 2 additional thought:
> >
> > 1) How to handle DSDT?
> > We have special code to handle FACS, but no DSDT.
> >
> > 2) How to handle SSDT or other multiple ACPI tables?
> > We may have multiple SSDT. Usually, it is identified as OEMID.
> > Do we want to provide similar function for them?
> >
> > Anyway, just *additional* thought. :-) Current implementation is 
> > good enough for check in.
> >
> > Reviewed-by: jiewen@intel.com
> >
> > Thank you
> > Yao Jiewen
> >
> >
> >> -Original Message-
> >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf 
> >> Of
> Star
> >> Zeng
> >> Sent: Friday, August 31, 2018 7:29 PM
> >> To: edk2-devel@lists.01.org
> >> Cc: Kinney, Michael D ; Younas khan 
> >> ; Yao, Jiewen ;
> Gao,
> >> Liming ; Zeng, Star 
> >> Subject: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new
> >> EfiFindAcpiTableBySignature() API
> >>
> >> https://bugzilla.tianocore.org/show_bug.cgi?id=967
> >> Request to add a library function for GetAcpiTable() in order to 
> >> get ACPI table using signature as input.
> >>
> >> After evaluation, we found there are many duplicated code to find 
> >> ACPI table by signature in different modules.
> >>
> >> This patch adds new EfiFindAcpiTableBySignature() API in UefiLib 
> >> for the request and also the following patch to remove the 
> >> duplicated code.
> >>
> >> Cc: Younas khan 
> >> Cc: Michael D Kinney 
> >> Cc: Liming Gao 
> >> Cc: Jiewen Yao 
> >> Contributed-under: TianoCore Contribution Agreement 1.1
> >> Signed-off-by: Star Zeng 
> >> ---
> >> MdePkg/Include/Library/UefiLib.h   |  17 +++
> >> MdePkg/Library/UefiLib/Acpi.c  | 226
> >> +
> >> MdePkg/Library/UefiLib/UefiLib.inf |   3 +
> >> 3 files changed, 246 insertions(+)
> >> create mode 100644 MdePkg/Library/UefiLib/Acpi.c
> >>
> >> diff --git a/MdePkg/Include/Library/UefiLib.h
> >> b/MdePkg/Include/Library/UefiLib.h
> >> index f80067f11103..8dd25f324fd2 100644
> >> --- a/MdePkg/Include/Library/UefiLib.h
> >> +++ b/MdePkg/Include/Library/UefiLib.h
> >> @@ -1595,4 +1595,21 @@ EfiOpenFileByDevicePath (
> >>  IN UINT64OpenMode,
> >>  IN UINT64Attributes
> >>  );
> >> +
> >> +/**
> >> +  This function finds ACPI table by signature.
> >> +  It will find the table in gEfiAcpi20TableGuid system 
> >> +configuration table
> first,
> >> +  and then gEfiAcpi10TableGuid system configuration table.
> >> +
> >> +  @param Signature  ACPI table signature.
> >> +
> >> +  @return ACPI table or NULL if not found.
> >> +
> >> +**/
> >> +VOID *
> >> +EFIAPI
> >> +EfiFindAcpiTableBySignature (
> >> +  IN UINT32 Signature
> >> +  );
> >> +
> >> #endif
> >> diff --git a/MdePkg/Library/UefiLib/Acpi.c 
> >> b/MdePkg/Library/UefiLib/Acpi.c new file mode 100644 index 
> >> ..5cb93966b59f
> >> --- /dev/null
> >> +++ b/MdePkg/Library/UefiLib/Acpi.c
> >> @@ -0,0 +1,226 @@
> >> +/** @file
> >> +  This module provides help function for finding ACPI table.
> >> +
> >> +  Copyright (c) 2018, Intel Corporation. All rights reserved.  
> >> + This program and the accompanying materials  are licensed and 
> >> + made available under the terms and conditions of the
> BSD
> >> License
> >> +  which 

[edk2] [PATCH 1/4] MdeModulePkg/DxeIpl: disable paging before creating new page table

2018-09-02 Thread Jian J Wang
PEI Stack Guard needs to enable paging before DxeIpl. This might cause
#GP in the transition from 32-bit PEI to 64-bit DXE due to the code
trying to write CR3 register with PML4 page table while the processor
is enabled with PAE paging.

Simply disabling paging before updating CR3 can solve this conflict.
There's no such issue for 64-bit PEI so this change applies only to
32-bit code.

Cc: Star Zeng 
Cc: Ruiyu Ni 
Cc: Jiewen Yao 
Cc: "Ware, Ryan R" 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c 
b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
index 8a939b6c24..d28baa3615 100644
--- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
@@ -325,6 +325,11 @@ HandOffToDxeCore (
 PERF_EVENT_SIGNAL_END (gEndOfPeiSignalPpi.Guid);
 ASSERT_EFI_ERROR (Status);
 
+//
+// Paging might be already enabled. To avoid conflict configuration,
+// disable paging first anyway.
+//
+AsmWriteCr0 (AsmReadCr0 () & (~BIT31));
 AsmWriteCr3 (PageTables);
 
 //
@@ -445,6 +450,11 @@ HandOffToDxeCore (
 ASSERT_EFI_ERROR (Status);
 
 if (BuildPageTablesIa32Pae) {
+  //
+  // Paging might be already enabled. To avoid conflict configuration,
+  // disable paging first anyway.
+  //
+  AsmWriteCr0 (AsmReadCr0 () & (~BIT31));
   AsmWriteCr3 (PageTables);
   //
   // Set Physical Address Extension (bit 5 of CR4).
-- 
2.16.2.windows.1

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


[edk2] [PATCH 4/4] UefiCpuPkg/CpuMpPei: support stack guard feature

2018-09-02 Thread Jian J Wang
This feature is the same as Stack Guard enabled in driver CpuDxe but
applies to PEI phase. Due to the specialty in PEI module dispatching,
this driver is changed to do the actual initialization in notify
callback of event gEfiPeiMemoryDiscoveredPpiGuid. This can let the
stack guard apply to as most PEI drivers as possible.

To let Stack Guard work, some simple page table management code are
introduced to setup Guard page at base of stack for each processor.

Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Ruiyu Ni 
Cc: Jiewen Yao 
Cc: Star Zeng 
Cc: "Ware, Ryan R" 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 UefiCpuPkg/CpuMpPei/CpuMpPei.c   | 269 -
 UefiCpuPkg/CpuMpPei/CpuMpPei.h   |  14 +
 UefiCpuPkg/CpuMpPei/CpuMpPei.inf |  11 +-
 UefiCpuPkg/CpuMpPei/CpuPaging.c  | 637 +++
 4 files changed, 916 insertions(+), 15 deletions(-)
 create mode 100644 UefiCpuPkg/CpuMpPei/CpuPaging.c

diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index 7c94d5a6d7..e3762daf39 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -409,25 +409,225 @@ PeiWhoAmI (
 }
 
 /**
-  The Entry point of the MP CPU PEIM.
+  Get GDT register value.
 
-  This function will wakeup APs and collect CPU AP count and install the
-  Mp Service Ppi.
+  This function is mainly for AP purpose because AP may have different GDT
+  table than BSP.
 
-  @param  FileHandleHandle of the file being invoked.
-  @param  PeiServices   Describes the list of possible PEI Services.
+  @param[in,out] Buffer  The pointer to private data buffer.
 
-  @retval EFI_SUCCESS   MpServicePpi is installed successfully.
+**/
+VOID
+EFIAPI
+GetGdtr (
+  IN OUT VOID *Buffer
+  )
+{
+  AsmReadGdtr ((IA32_DESCRIPTOR *)Buffer);
+}
+
+/**
+  Initializes CPU exceptions handlers for the sake of stack switch requirement.
+
+  This function is a wrapper of InitializeCpuExceptionHandlersEx. It's mainly
+  for the sake of AP's init because of EFI_AP_PROCEDURE API requirement.
+
+  @param[in,out] Buffer  The pointer to private data buffer.
 
 **/
-EFI_STATUS
+VOID
 EFIAPI
-CpuMpPeimInit (
-  IN   EFI_PEI_FILE_HANDLE  FileHandle,
+InitializeExceptionStackSwitchHandlers (
+  IN OUT VOID *Buffer
+  )
+{
+  CPU_EXCEPTION_INIT_DATA   *EssData;
+  IA32_DESCRIPTOR   Idtr;
+  EFI_STATUSStatus;
+
+  EssData = Buffer;
+  //
+  // We don't plan to replace IDT table with a new one, but we should not 
assume
+  // the AP's IDT is the same as BSP's IDT either.
+  //
+  AsmReadIdtr ();
+  EssData->Ia32.IdtTable = (VOID *)Idtr.Base;
+  EssData->Ia32.IdtTableSize = Idtr.Limit + 1;
+  Status = InitializeCpuExceptionHandlersEx (NULL, EssData);
+  ASSERT_EFI_ERROR (Status);
+}
+
+/**
+  Initializes MP exceptions handlers for the sake of stack switch requirement.
+
+  This function will allocate required resources required to setup stack switch
+  and pass them through CPU_EXCEPTION_INIT_DATA to each logic processor.
+
+**/
+VOID
+InitializeMpExceptionStackSwitchHandlers (
+  VOID
+  )
+{
+  EFI_STATUS  Status;
+  UINTN   Index;
+  UINTN   Bsp;
+  UINTN   ExceptionNumber;
+  UINTN   OldGdtSize;
+  UINTN   NewGdtSize;
+  UINTN   NewStackSize;
+  IA32_DESCRIPTOR Gdtr;
+  CPU_EXCEPTION_INIT_DATA EssData;
+  UINT8   *GdtBuffer;
+  UINT8   *StackTop;
+  UINTN   NumberOfProcessors;
+
+  if (!PcdGetBool (PcdCpuStackGuard)) {
+return;
+  }
+
+  MpInitLibGetNumberOfProcessors(, NULL);
+  MpInitLibWhoAmI ();
+
+  ExceptionNumber = FixedPcdGetSize (PcdCpuStackSwitchExceptionList);
+  NewStackSize = FixedPcdGet32 (PcdCpuKnownGoodStackSize) * ExceptionNumber;
+
+  Status = PeiServicesAllocatePool (
+ NewStackSize * NumberOfProcessors,
+ (VOID **)
+ );
+  ASSERT(StackTop != NULL);
+  if (EFI_ERROR (Status)) {
+ASSERT_EFI_ERROR (Status);
+return;
+  }
+  StackTop += NewStackSize  * NumberOfProcessors;
+
+  //
+  // The default exception handlers must have been initialized. Let's just skip
+  // it in this method.
+  //
+  EssData.Ia32.Revision = CPU_EXCEPTION_INIT_DATA_REV;
+  EssData.Ia32.InitDefaultHandlers = FALSE;
+
+  EssData.Ia32.StackSwitchExceptions = 
FixedPcdGetPtr(PcdCpuStackSwitchExceptionList);
+  EssData.Ia32.StackSwitchExceptionNumber = ExceptionNumber;
+  EssData.Ia32.KnownGoodStackSize = FixedPcdGet32(PcdCpuKnownGoodStackSize);
+
+  //
+  // Initialize Gdtr to suppress incorrect compiler/analyzer warnings.
+  //
+  Gdtr.Base = 0;
+  Gdtr.Limit = 0;
+  for (Index = 0; Index < NumberOfProcessors; ++Index) {
+//
+// To support stack switch, we need to re-construct GDT but not IDT.
+//
+if 

[edk2] [PATCH 2/4] UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI exceptions

2018-09-02 Thread Jian J Wang
Stack Guard needs to setup stack switch capability to allow exception
handler to be called with good stack if stack overflow is detected.
This patch update InitializeCpuExceptionHandlersEx() to allow pass
extra initialization data used to setup exception stack switch for
specified exceptions.

Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Ruiyu Ni 
Cc: Jiewen Yao 
Cc: Star Zeng 
Cc: "Ware, Ryan R" 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 .../CpuExceptionHandlerLib/PeiCpuException.c   | 27 +-
 .../PeiCpuExceptionHandlerLib.inf  |  4 
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
index 6f271983f2..5687c98c0d 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
@@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include 
 #include 
 #include 
+#include 
 
 CONST UINTNmDoFarReturnFlag  = 0;
 
@@ -208,5 +209,29 @@ InitializeCpuExceptionHandlersEx (
   IN CPU_EXCEPTION_INIT_DATA*InitData OPTIONAL
   )
 {
-  return InitializeCpuExceptionHandlers (VectorInfo);
+  EFI_STATUSStatus;
+
+  //
+  // To avoid repeat initialization of default handlers, the caller should pass
+  // an extended init data with InitDefaultHandlers set to FALSE. There's no
+  // need to call this method to just initialize default handlers. Call non-ex
+  // version instead; or this method must be implemented as a simple wrapper of
+  // non-ex version of it, if this version has to be called.
+  //
+  if (InitData == NULL || InitData->Ia32.InitDefaultHandlers) {
+Status = InitializeCpuExceptionHandlers (VectorInfo);
+  } else {
+Status = EFI_SUCCESS;
+  }
+
+  if (!EFI_ERROR (Status)) {
+//
+// Initializing stack switch is only necessary for Stack Guard 
functionality.
+//
+if (PcdGetBool (PcdCpuStackGuard) && InitData != NULL) {
+  Status = ArchSetupExcpetionStack (InitData);
+}
+  }
+
+  return  Status;
 }
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
index 783260e39a..0ea44b3052 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
@@ -60,3 +60,7 @@
   HobLib
   MemoryAllocationLib
   SynchronizationLib
+
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
+
-- 
2.16.2.windows.1

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


[edk2] [PATCH 0/4] Add PEI Stack Guard feature

2018-09-02 Thread Jian J Wang
This patch series try to add PEI Stack Guard feature. Please refer to
following trackers for details.

The machanism behind this feature is the same as Stack Guard for UEFI
drivers, and similiar implementation is also employed.

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

Jian J Wang (4):
  MdeModulePkg/DxeIpl: disable paging before creating new page table
  UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI
exceptions
  UefiCpuPkg/MpInitLib: fix register restore issue in AP wakeup
  UefiCpuPkg/CpuMpPei: support stack guard feature

 MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c|  10 +
 UefiCpuPkg/CpuMpPei/CpuMpPei.c | 269 -
 UefiCpuPkg/CpuMpPei/CpuMpPei.h |  14 +
 UefiCpuPkg/CpuMpPei/CpuMpPei.inf   |  11 +-
 UefiCpuPkg/CpuMpPei/CpuPaging.c| 637 +
 .../CpuExceptionHandlerLib/PeiCpuException.c   |  27 +-
 .../PeiCpuExceptionHandlerLib.inf  |   4 +
 UefiCpuPkg/Library/MpInitLib/MpLib.c   |   8 +-
 8 files changed, 962 insertions(+), 18 deletions(-)
 create mode 100644 UefiCpuPkg/CpuMpPei/CpuPaging.c

-- 
2.16.2.windows.1

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


[edk2] [PATCH 3/4] UefiCpuPkg/MpInitLib: fix register restore issue in AP wakeup

2018-09-02 Thread Jian J Wang
The conflict issues are introduced by Stack Guard feature enabled for
PEI.

The first is CR0 which should be restored after CR3 and CR4.
Another is TR which should not be passed from BSP to AP during init
phase.

Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Ruiyu Ni 
Cc: Jiewen Yao 
Cc: Star Zeng 
Cc: "Ware, Ryan R" 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 377876643f..709fbc1575 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -217,9 +217,9 @@ RestoreVolatileRegisters (
   CPUID_VERSION_INFO_EDXVersionInfoEdx;
   IA32_TSS_DESCRIPTOR   *Tss;
 
-  AsmWriteCr0 (VolatileRegisters->Cr0);
   AsmWriteCr3 (VolatileRegisters->Cr3);
   AsmWriteCr4 (VolatileRegisters->Cr4);
+  AsmWriteCr0 (VolatileRegisters->Cr0);
 
   if (IsRestoreDr) {
 AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, );
@@ -1558,7 +1558,7 @@ MpInitLibInitialize (
   ApLoopMode  = GetApLoopMode ();
 
   //
-  // Save BSP's Control registers for APs
+  // Save BSP's Control registers for APs.
   //
   SaveVolatileRegisters ();
 
@@ -1656,6 +1656,10 @@ MpInitLibInitialize (
   //
   CopyMem ((VOID *)ApIdtBase, (VOID *)VolatileRegisters.Idtr.Base, 
VolatileRegisters.Idtr.Limit + 1);
   VolatileRegisters.Idtr.Base = ApIdtBase;
+  //
+  // Don't pass BSP's TR to APs to avoid AP init failure.
+  //
+  VolatileRegisters.Tr = 0;
   CopyMem (>CpuData[0].VolatileRegisters, , 
sizeof (VolatileRegisters));
   //
   // Set BSP basic information
-- 
2.16.2.windows.1

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


[edk2] [Patch][edk2-platforms/devel-IntelAtomProcessorE3900] BIOS Logo Change.

2018-09-02 Thread zwei4
Add board specific code to show OEM specific logo.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: David Wei 
CC: Mike Wu  
CC: Mang Guo 
---
 .../Board/AuroraGlacier/BoardInitPostMem/BoardInit.c   | 1 +
 .../Board/AuroraGlacier/BoardInitPostMem/BoardInitPostMem.inf  | 2 ++
 .../Board/BensonGlacier/BoardInitPostMem/BoardInit.c   | 1 +
 .../Board/BensonGlacier/BoardInitPostMem/BoardInitPostMem.inf  | 2 ++
 .../BroxtonPlatformPkg/Board/LeafHill/BoardInitPostMem/BoardInit.c | 1 +
 .../Board/LeafHill/BoardInitPostMem/BoardInitPostMem.inf   | 2 ++
 .../BroxtonPlatformPkg/Board/MinnowBoard3/BoardInitPostMem/BoardInit.c | 1 +
 .../Board/MinnowBoard3/BoardInitPostMem/BoardInitPostMem.inf   | 2 ++
 .../Board/MinnowBoard3Module/BoardInitPostMem/BoardInit.c  | 3 ++-
 .../Board/MinnowBoard3Module/BoardInitPostMem/BoardInitPostMem.inf | 2 ++
 Platform/BroxtonPlatformPkg/Board/UP2/BoardInitPostMem/BoardInit.c | 1 +
 .../BroxtonPlatformPkg/Board/UP2/BoardInitPostMem/BoardInitPostMem.inf | 2 ++
 .../Common/Library/PeiFspPolicyInitLib/PeiFspPolicyInitLib.inf | 1 +
 .../Common/Library/PeiFspPolicyInitLib/PeiFspSaPolicyInitLib.c | 3 ++-
 .../Common/PlatformSettings/PlatformPostMemPei/PlatformPostMemPei.inf  | 1 +
 Platform/BroxtonPlatformPkg/PlatformPkg.dec| 3 +++
 16 files changed, 26 insertions(+), 2 deletions(-)

diff --git 
a/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInit.c 
b/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInit.c
index 2f33bfe21e..302edb8301 100644
--- 
a/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInit.c
+++ 
b/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInit.c
@@ -110,6 +110,7 @@ AuroraGlacierPostMemInitCallback (
   //
   BufferSize = sizeof (EFI_GUID);
   PcdSetPtr(PcdBoardVbtFileGuid, , (UINT8 
*));
+  PcdSetPtr(PcdOemLogoFileGuid, , (UINT8 *));
 
   //
   // Set PcdSueCreek
diff --git 
a/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInitPostMem.inf
 
b/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInitPostMem.inf
index 73205d7e79..8fe5ea7e95 100644
--- 
a/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInitPostMem.inf
+++ 
b/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardInitPostMem.inf
@@ -63,6 +63,7 @@
   gPlatformModuleTokenSpaceGuid.PcdFabId
   gPlatformModuleTokenSpaceGuid.PcdResetType
   gPlatformModuleTokenSpaceGuid.PcdBoardVbtFileGuid
+  gPlatformModuleTokenSpaceGuid.PcdOemLogoFileGuid
   gPlatformModuleTokenSpaceGuid.PcdSueCreek
   gPlatformModuleTokenSpaceGuid.PcdMaxPkgCState
   gPlatformModuleTokenSpaceGuid.PcdTi3100AudioCodecEnable
@@ -84,6 +85,7 @@
   gEfiTpmDeviceInstanceTpm20DtpmGuid
   gTpmDeviceInstanceTpm20PttPtpGuid
   gPeiAuroraGlacierVbtGuid
+  gPeiLogoGuid
 
 [Ppis]
   gBoardPostMemInitStartGuid
diff --git 
a/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInit.c 
b/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInit.c
index aabb350e85..60d2324d95 100644
--- 
a/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInit.c
+++ 
b/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInit.c
@@ -110,6 +110,7 @@ BensonGlacierPostMemInitCallback (
   //
   BufferSize = sizeof (EFI_GUID);
   PcdSetPtr(PcdBoardVbtFileGuid, , (UINT8 
*));
+  PcdSetPtr(PcdOemLogoFileGuid, , (UINT8 *));
 
   //
   // Set PcdSueCreek
diff --git 
a/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInitPostMem.inf
 
b/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInitPostMem.inf
index 3a804b9558..782bf0d2bd 100644
--- 
a/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInitPostMem.inf
+++ 
b/Platform/BroxtonPlatformPkg/Board/BensonGlacier/BoardInitPostMem/BoardInitPostMem.inf
@@ -63,6 +63,7 @@
   gPlatformModuleTokenSpaceGuid.PcdFabId
   gPlatformModuleTokenSpaceGuid.PcdResetType
   gPlatformModuleTokenSpaceGuid.PcdBoardVbtFileGuid
+  gPlatformModuleTokenSpaceGuid.PcdOemLogoFileGuid
   gPlatformModuleTokenSpaceGuid.PcdSueCreek
   gPlatformModuleTokenSpaceGuid.PcdMaxPkgCState
   gPlatformModuleTokenSpaceGuid.PcdTi3100AudioCodecEnable
@@ -84,6 +85,7 @@
   gEfiTpmDeviceInstanceTpm20DtpmGuid
   gTpmDeviceInstanceTpm20PttPtpGuid
   gPeiBensonGlacierVbtGuid
+  gPeiLogoGuid
 
 [Ppis]
   gBoardPostMemInitStartGuid
diff --git 
a/Platform/BroxtonPlatformPkg/Board/LeafHill/BoardInitPostMem/BoardInit.c 
b/Platform/BroxtonPlatformPkg/Board/LeafHill/BoardInitPostMem/BoardInit.c
index fdf2c7eaab..5c53ff135a 100644
--- a/Platform/BroxtonPlatformPkg/Board/LeafHill/BoardInitPostMem/BoardInit.c
+++ b/Platform/BroxtonPlatformPkg/Board/LeafHill/BoardInitPostMem/BoardInit.c
@@ -119,6 +119,7 @@ LeafHillPostMemInitCallback (
   //
   

[edk2] [PATCH] EmulatorPkg/PlatformBmLib: Fix GCC build failure

2018-09-02 Thread Ruiyu Ni
Some local variables are initialized but never used.
GCC complains about that. The patch fixes this issue.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni 
Cc: Dandan Bi 
---
 EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c 
b/EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
index 5b39776..b07226f 100644
--- a/EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
+++ b/EmulatorPkg/Library/PlatformBmLib/PlatformBmMemoryTest.c
@@ -41,26 +41,15 @@ PlatformBootManagerMemoryTest (
   EFI_GENERIC_MEMORY_TEST_PROTOCOL  *GenMemoryTest;
   UINT64TestedMemorySize;
   UINT64TotalMemorySize;
-  UINT64PreviousValue;
   BOOLEAN   ErrorOut;
   BOOLEAN   TestAbort;
   EFI_INPUT_KEY Key;
-  CHAR16*StrTotalMemory;
-  CHAR16*Pos;
-  UINTN StrTotalMemorySize;
 
   ReturnStatus = EFI_SUCCESS;
   ZeroMem (, sizeof (EFI_INPUT_KEY));
 
-  StrTotalMemorySize = 128;
-  Pos = AllocateZeroPool (StrTotalMemorySize);
-  ASSERT (Pos != NULL);
-
-  StrTotalMemory= Pos;
-
   TestedMemorySize  = 0;
   TotalMemorySize   = 0;
-  PreviousValue = 0;
   ErrorOut  = FALSE;
   TestAbort = FALSE;
 
@@ -72,7 +61,6 @@ PlatformBootManagerMemoryTest (
   (VOID **) 
   );
   if (EFI_ERROR (Status)) {
-FreePool (Pos);
 return EFI_SUCCESS;
   }
 
@@ -89,7 +77,6 @@ PlatformBootManagerMemoryTest (
 // do the test, and then the status of EFI_NO_MEDIA will be returned by
 // "MemoryTestInit". So it does not need to test memory again, just return.
 //
-FreePool (Pos);
 return EFI_SUCCESS;
   }
 
@@ -128,6 +115,5 @@ PlatformBootManagerMemoryTest (
 Done:
   DEBUG ((DEBUG_INFO, "%d bytes of system memory tested OK\r\n", 
TotalMemorySize));
 
-  FreePool (Pos);
   return ReturnStatus;
 }
-- 
2.7.4

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


Re: [edk2] [PATCH 2/2] UefiCpuPkg/CpuExceptionHandlerLib: Avoid calling PEI services from AP

2018-09-02 Thread Wang, Jian J
Validated-by: Jian J Wang 
Reviewed-by: Jian J Wang 

> -Original Message-
> From: Ni, Ruiyu
> Sent: Friday, August 31, 2018 4:36 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Jian J ; Fan Jeff 
> Subject: [PATCH 2/2] UefiCpuPkg/CpuExceptionHandlerLib: Avoid calling PEI
> services from AP
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1128
> 
> When an exception happens in AP, system hangs at
> GetPeiServicesTablePointer(), complaining the PeiServices retrieved
> from memory before IDT is NULL.
> 
> Due to the following commit:
> c563077a380437c114aba4c95be65eb963ebc1f3
> * UefiCpuPkg/MpInitLib: Avoid calling PEI services from AP
> the IDT used by AP no longer preserve PeiServices pointer in the
> very beginning.
> But the implementation of PeiExceptionHandlerLib still assumes
> the PeiServices pointer is there, so the assertion happens.
> 
> The patch fixes the exception handler library to not call
> PEI services from AP.
> 
> The patch duplicates the #0 exception stub header in an allocated
> pool but with extra 4-byte/8-byte to store the exception handler
> data which was originally stored in HOB.
> When AP exception happens, the code gets the exception handler data
> from the exception handler for #0.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni 
> Cc: Jian J Wang 
> Cc: Fan Jeff 
> ---
>  .../CpuExceptionHandlerLib/CpuExceptionCommon.h|  7 +-
>  .../CpuExceptionHandlerLib/PeiCpuException.c   | 77 
> +++---
>  2 files changed, 55 insertions(+), 29 deletions(-)
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> index e10d9379d5..459f06ac84 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> @@ -1,7 +1,7 @@
>  /** @file
>Common header file for CPU Exception Handler Library.
> 
> -  Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.
> +  Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD
> License
>which accompanies this distribution.  The full text of the license may be 
> found
> at
> @@ -43,11 +43,6 @@
> 
>  #include "ArchInterruptDefs.h"
> 
> -#define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \
> -  { \
> -0xb21d9148, 0x9211, 0x4d8f, { 0xad, 0xd3, 0x66, 0xb1, 0x89, 0xc9, 0x2c,
> 0x83 } \
> -  }
> -
>  #define CPU_STACK_SWITCH_EXCEPTION_NUMBER \
>FixedPcdGetSize (PcdCpuStackSwitchExceptionList)
> 
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> index 6f271983f2..5dd8423d2f 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuException.c
> @@ -1,7 +1,7 @@
>  /** @file
>CPU exception handler library implementation for PEIM module.
> 
> -Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
> +Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
>  This program and the accompanying materials are licensed and made available
> under
>  the terms and conditions of the BSD License that accompanies this 
> distribution.
>  The full text of the license may be found at
> @@ -20,10 +20,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
> 
>  CONST UINTNmDoFarReturnFlag  = 0;
> 
> -EFI_GUID mCpuExceptrionHandlerLibHobGuid =
> CPU_EXCEPTION_HANDLER_LIB_HOB_GUID;
> +typedef struct {
> +  UINT8   ExceptionStubHeader[HOOKAFTER_STUB_SIZE];
> +  EXCEPTION_HANDLER_DATA  *ExceptionHandlerData;
> +} EXCEPTION0_STUB_HEADER;
> 
>  /**
> -  Get exception handler data pointer from GUIDed HOb.
> +  Get exception handler data pointer from IDT[0].
> +
> +  The exception #0 stub header is duplicated in an allocated pool with extra 
> 4-
> byte/8-byte to store the
> +  exception handler data. The new allocated memory layout follows structure
> EXCEPTION0_STUB_HEADER.
> +  The code assumes that all processors uses the same exception handler for #0
> exception.
> 
>@return  pointer to exception handler data.
>  **/
> @@ -32,18 +39,50 @@ GetExceptionHandlerData (
>VOID
>)
>  {
> -  EFI_HOB_GUID_TYPE   *GuidHob;
> -  VOID*DataInHob;
> -  EXCEPTION_HANDLER_DATA  *ExceptionHandlerData;
> +  IA32_DESCRIPTOR  IdtDescriptor;
> +  IA32_IDT_GATE_DESCRIPTOR *IdtTable;
> +  EXCEPTION0_STUB_HEADER   *Exception0StubHeader;
> +
> +  AsmReadIdtr ();
> +  IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
> +
> +  Exception0StubHeader = (EXCEPTION0_STUB_HEADER *)ArchGetIdtHandler
> ([0]);
> +  return Exception0StubHeader->ExceptionHandlerData;
> +}
> 
> -  ExceptionHandlerData = 

[edk2] [Patch] BaseTools: Involve Dec default value to calculate Maxsize

2018-09-02 Thread BobCF
Involve Dec default value to calculate Maxsize for structure PCD

Cc: Liming Gao 
Cc: Yonghong Zhu 
Cc: Jaben Carsey 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng 
---
 .../Source/Python/Workspace/BuildClassObject.py| 34 +++---
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py 
b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index 88465c59ea..b2e5309a90 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -66,35 +66,35 @@ class PcdClassObject(object):
 self.DscDefaultValue = Value
 self.PcdValueFromComm = ""
 self.PcdValueFromFdf = ""
 self.DefinitionPosition = ("","")
 
+@staticmethod
+def GetPcdMaxSizeWorker(PcdString, MaxSize):
+if PcdString.startswith("{") and PcdString.endswith("}"):
+return  max([len(PcdString.split(",")),MaxSize])
+
+if PcdString.startswith("\"") or PcdString.startswith("\'"):
+return  max([len(PcdString)-2+1,MaxSize])
+
+if PcdString.startswith("L\""):
+return  max([2*(len(PcdString)-3+1),MaxSize])
+
+return max([len(PcdString),MaxSize])
+
 ## Get the maximum number of bytes
 def GetPcdMaxSize(self):
 if self.DatumType in TAB_PCD_NUMERIC_TYPES:
 return MAX_SIZE_TYPE[self.DatumType]
 
 MaxSize = int(self.MaxDatumSize, 10) if self.MaxDatumSize else 0
 if self.PcdValueFromFdf:
-if self.PcdValueFromFdf.startswith("{") and 
self.PcdValueFromFdf.endswith("}"):
-MaxSize =  max([len(self.PcdValueFromFdf.split(",")),MaxSize])
-elif self.PcdValueFromFdf.startswith("\"") or 
self.PcdValueFromFdf.startswith("\'"):
-MaxSize =  max([len(self.PcdValueFromFdf)-2+1,MaxSize])
-elif self.PcdValueFromFdf.startswith("L\""):
-MaxSize =  max([2*(len(self.PcdValueFromFdf)-3+1),MaxSize])
-else:
-MaxSize = max([len(self.PcdValueFromFdf),MaxSize])
-
+MaxSize = self.GetPcdMaxSizeWorker(self.PcdValueFromFdf,MaxSize)
 if self.PcdValueFromComm:
-if self.PcdValueFromComm.startswith("{") and 
self.PcdValueFromComm.endswith("}"):
-return max([len(self.PcdValueFromComm.split(",")), MaxSize])
-elif self.PcdValueFromComm.startswith("\"") or 
self.PcdValueFromComm.startswith("\'"):
-return max([len(self.PcdValueFromComm)-2+1, MaxSize])
-elif self.PcdValueFromComm.startswith("L\""):
-return max([2*(len(self.PcdValueFromComm)-3+1), MaxSize])
-else:
-return max([len(self.PcdValueFromComm), MaxSize])
+MaxSize = self.GetPcdMaxSizeWorker(self.PcdValueFromComm,MaxSize)
+if hasattr(self, "DefaultValueFromDec"):
+MaxSize = 
self.GetPcdMaxSizeWorker(self.DefaultValueFromDec,MaxSize)
 return MaxSize
 
 ## Get the number of bytes
 def GetPcdSize(self):
 if self.DatumType in TAB_PCD_NUMERIC_TYPES:
-- 
2.16.2.windows.1

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