public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chiu, Chasel" <chasel.chiu@intel.com>
To: "Zeng, Star" <star.zeng@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Wang, Jian J" <jian.j.wang@intel.com>,
	"Wu, Hao A" <hao.a.wu@intel.com>,
	 "Gao, Liming" <liming.gao@intel.com>,
	"Ni, Ruiyu" <ruiyu.ni@intel.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>,
	"Desimone, Nathaniel L" <nathaniel.l.desimone@intel.com>
Subject: Re: [PATCH V2 3/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxFvSupported
Date: Wed, 19 Dec 2018 03:22:09 +0000	[thread overview]
Message-ID: <3C3EFB470A303B4AB093197B6777CCEC501F654C@PGSMSX111.gar.corp.intel.com> (raw)
In-Reply-To: <1545113286-49760-4-git-send-email-star.zeng@intel.com>


Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>


-----Original Message-----
From: Zeng, Star 
Sent: Tuesday, December 18, 2018 2:08 PM
To: edk2-devel@lists.01.org
Cc: Zeng, Star <star.zeng@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>; Gao, Liming <liming.gao@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>
Subject: [PATCH V2 3/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxFvSupported

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

Background as below.

Problem:
As static configuration from the PCDs, the binary PeiCore (for example in FSP binary with dispatch mode) could not predict how many FVs, Files or PPIs for different platforms.

Burden:
Platform developers need configure the PCDs accordingly for different platforms.

To solve the problem and remove the burden, we can update PeiCore to remove the using of PcdPeiCoreMaxFvSupported, PcdPeiCoreMaxPeimPerFv and PcdPeiCoreMaxPpiSupported by extending buffer dynamically for FV, File and PPI management.

This patch removes the using of PcdPeiCoreMaxFvSupported in PeiCore.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
---
 MdeModulePkg/Core/Pei/FwVol/FwVol.c     | 67 ++++++++++++++++++++++++++-------
 MdeModulePkg/Core/Pei/PeiMain.h         | 15 +++++++-
 MdeModulePkg/Core/Pei/PeiMain.inf       |  1 -
 MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 16 ++++----
 4 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c b/MdeModulePkg/Core/Pei/FwVol/FwVol.c
index 5629c9a1ce20..0a67b96bf1e3 100644
--- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c
+++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c
@@ -503,6 +503,10 @@ PeiInitializeFv (
                     );
   ASSERT_EFI_ERROR (Status);
 
+  PrivateData->Fv = AllocateZeroPool (sizeof (PEI_CORE_FV_HANDLE) * 
+ FV_GROWTH_STEP);  ASSERT (PrivateData->Fv != NULL);  
+ PrivateData->MaxFvCount = FV_GROWTH_STEP;
+
   //
   // Update internal PEI_CORE_FV array.
   //
@@ -560,6 +564,7 @@ FirmwareVolmeInfoPpiNotifyCallback (
   VOID                                  *DepexData;
   BOOLEAN                               IsFvInfo2;
   UINTN                                 CurFvCount;
+  VOID                                  *TempPtr;
 
   Status       = EFI_SUCCESS;
   PrivateData  = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); @@ -626,10 +631,21 @@ FirmwareVolmeInfoPpiNotifyCallback (
       }
     }
 
-    if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {
-      DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));
-      DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
-      ASSERT (FALSE);
+    if (PrivateData->FvCount >= PrivateData->MaxFvCount) {
+      //
+      // Run out of room, grow the buffer.
+      //
+      TempPtr = AllocateZeroPool (
+                  sizeof (PEI_CORE_FV_HANDLE) * (PrivateData->MaxFvCount + FV_GROWTH_STEP)
+                  );
+      ASSERT (TempPtr != NULL);
+      CopyMem (
+        TempPtr,
+        PrivateData->Fv,
+        sizeof (PEI_CORE_FV_HANDLE) * PrivateData->MaxFvCount
+        );
+      PrivateData->Fv = TempPtr;
+      PrivateData->MaxFvCount = PrivateData->MaxFvCount + 
+ FV_GROWTH_STEP;
     }
 
     //
@@ -2157,7 +2173,6 @@ FindNextCoreFvHandle (
     }
   }
 
-  ASSERT (Private->FvCount <= PcdGet32 (PcdPeiCoreMaxFvSupported));
   if (Instance >= Private->FvCount) {
     return NULL;
   }
@@ -2205,7 +2220,7 @@ PeiReinitializeFv (
   //
   // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
   //
-  for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {
+  for (Index = 0; Index < PrivateData->FvCount; Index ++) {
     if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {
       PrivateData->Fv[Index].FvPpi = &mPeiFfs2FwVol.Fv;
     }
@@ -2233,7 +2248,7 @@ PeiReinitializeFv (
   //
   // Fixup all FvPpi pointers for the implementation in flash to permanent memory.
   //
-  for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {
+  for (Index = 0; Index < PrivateData->FvCount; Index ++) {
     if (PrivateData->Fv[Index].FvPpi == OldFfsFvPpi) {
       PrivateData->Fv[Index].FvPpi = &mPeiFfs3FwVol.Fv;
     }
@@ -2263,9 +2278,23 @@ AddUnknownFormatFvInfo (
   )
 {
   PEI_CORE_UNKNOW_FORMAT_FV_INFO    *NewUnknownFv;
+  VOID                              *TempPtr;
 
-  if (PrivateData->UnknownFvInfoCount + 1 >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {
-    return EFI_OUT_OF_RESOURCES;
+  if (PrivateData->UnknownFvInfoCount >= PrivateData->MaxUnknownFvInfoCount) {
+    //
+    // Run out of room, grow the buffer.
+    //
+    TempPtr = AllocateZeroPool (
+                sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO) * (PrivateData->MaxUnknownFvInfoCount + FV_GROWTH_STEP)
+                );
+    ASSERT (TempPtr != NULL);
+    CopyMem (
+      TempPtr,
+      PrivateData->UnknownFvInfo,
+      sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO) * PrivateData->MaxUnknownFvInfoCount
+      );
+    PrivateData->UnknownFvInfo = TempPtr;
+    PrivateData->MaxUnknownFvInfoCount = 
+ PrivateData->MaxUnknownFvInfoCount + FV_GROWTH_STEP;
   }
 
   NewUnknownFv = &PrivateData->UnknownFvInfo[PrivateData->UnknownFvInfoCount];
@@ -2368,6 +2397,7 @@ ThirdPartyFvPpiNotifyCallback (
   EFI_PEI_FILE_HANDLE          FileHandle;
   VOID                         *DepexData;
   UINTN                        CurFvCount;
+  VOID                         *TempPtr;
 
   PrivateData  = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
   FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi; @@ -2403,10 +2433,21 @@ ThirdPartyFvPpiNotifyCallback (
       continue;
     }
 
-    if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {
-      DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));
-      DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));
-      ASSERT (FALSE);
+    if (PrivateData->FvCount >= PrivateData->MaxFvCount) {
+      //
+      // Run out of room, grow the buffer.
+      //
+      TempPtr = AllocateZeroPool (
+                  sizeof (PEI_CORE_FV_HANDLE) * (PrivateData->MaxFvCount + FV_GROWTH_STEP)
+                  );
+      ASSERT (TempPtr != NULL);
+      CopyMem (
+        TempPtr,
+        PrivateData->Fv,
+        sizeof (PEI_CORE_FV_HANDLE) * PrivateData->MaxFvCount
+        );
+      PrivateData->Fv = TempPtr;
+      PrivateData->MaxFvCount = PrivateData->MaxFvCount + 
+ FV_GROWTH_STEP;
     }
 
     //
diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMain.h index 195bdc3425b6..b103215d81f7 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.h
+++ b/MdeModulePkg/Core/Pei/PeiMain.h
@@ -107,6 +107,11 @@ typedef struct {
 #define PEIM_STATE_REGISTER_FOR_SHADOW    0x02
 #define PEIM_STATE_DONE                   0x03
 
+//
+// Number of FV instances to grow by each time we run out of room // 
+#define FV_GROWTH_STEP 8
+
 typedef struct {
   EFI_FIRMWARE_VOLUME_HEADER          *FvHeader;
   EFI_PEI_FIRMWARE_VOLUME_PPI         *FvPpi;
@@ -202,16 +207,22 @@ struct _PEI_CORE_INSTANCE {
   UINTN                              FvCount;
 
   ///
-  /// Pointer to the buffer with the PcdPeiCoreMaxFvSupported number of entries.
+  /// The max count of FVs which contains FFS and could be dispatched by PeiCore.
+  ///
+  UINTN                              MaxFvCount;
+
+  ///
+  /// Pointer to the buffer with the MaxFvCount number of entries.
   /// Each entry is for one FV which contains FFS and could be dispatched by PeiCore.
   ///
   PEI_CORE_FV_HANDLE                 *Fv;
 
   ///
-  /// Pointer to the buffer with the PcdPeiCoreMaxFvSupported number of entries.
+  /// Pointer to the buffer with the MaxUnknownFvInfoCount number of entries.
   /// Each entry is for one FV which could not be dispatched by PeiCore.
   ///
   PEI_CORE_UNKNOW_FORMAT_FV_INFO     *UnknownFvInfo;
+  UINTN                              MaxUnknownFvInfoCount;
   UINTN                              UnknownFvInfoCount;
 
   ///
diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf
index d106c3606e97..dd41fe41bc89 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.inf
+++ b/MdeModulePkg/Core/Pei/PeiMain.inf
@@ -104,7 +104,6 @@ [Ppis]
   gEfiSecHobDataPpiGuid                         ## SOMETIMES_CONSUMES
 
 [Pcd]
-  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported                   ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPpiSupported                  ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize                  ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst  ## CONSUMES diff --git a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
index 52adefeb44b4..4869bf18f005 100644
--- a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
+++ b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
@@ -184,13 +184,15 @@ PeiCore (
       OldCoreData->CpuIo = &OldCoreData->ServiceTableShadow.CpuIo;
       if (OldCoreData->HeapOffsetPositive) {
         OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset);
-        OldCoreData->UnknownFvInfo        = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo + OldCoreData->HeapOffset);
+        if (OldCoreData->UnknownFvInfo != NULL) {
+          OldCoreData->UnknownFvInfo      = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo + OldCoreData->HeapOffset);
+        }
         if (OldCoreData->CurrentFvFileHandles != NULL) {
           OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset);
         }
         OldCoreData->PpiData.PpiListPtrs  = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiListPtrs + OldCoreData->HeapOffset);
         OldCoreData->Fv                   = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv + OldCoreData->HeapOffset);
-        for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {
+        for (Index = 0; Index < OldCoreData->FvCount; Index ++) {
           if (OldCoreData->Fv[Index].PeimState != NULL) {
             OldCoreData->Fv[Index].PeimState     = (UINT8 *) OldCoreData->Fv[Index].PeimState + OldCoreData->HeapOffset;
           }
@@ -202,13 +204,15 @@ PeiCore (
         OldCoreData->TempFileHandles      = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->TempFileHandles + OldCoreData->HeapOffset);
       } else {
         OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset);
-        OldCoreData->UnknownFvInfo        = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo - OldCoreData->HeapOffset);
+        if (OldCoreData->UnknownFvInfo != NULL) {
+          OldCoreData->UnknownFvInfo      = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo - OldCoreData->HeapOffset);
+        }
         if (OldCoreData->CurrentFvFileHandles != NULL) {
           OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset);
         }
         OldCoreData->PpiData.PpiListPtrs  = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiListPtrs - OldCoreData->HeapOffset);
         OldCoreData->Fv                   = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv - OldCoreData->HeapOffset);
-        for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {
+        for (Index = 0; Index < OldCoreData->FvCount; Index ++) {
           if (OldCoreData->Fv[Index].PeimState != NULL) {
             OldCoreData->Fv[Index].PeimState     = (UINT8 *) OldCoreData->Fv[Index].PeimState - OldCoreData->HeapOffset;
           }
@@ -339,10 +343,6 @@ PeiCore (
     //
     PrivateData.PpiData.PpiListPtrs  = AllocateZeroPool (sizeof (PEI_PPI_LIST_POINTERS) * PcdGet32 (PcdPeiCoreMaxPpiSupported));
     ASSERT (PrivateData.PpiData.PpiListPtrs != NULL);
-    PrivateData.Fv                   = AllocateZeroPool (sizeof (PEI_CORE_FV_HANDLE) * PcdGet32 (PcdPeiCoreMaxFvSupported));
-    ASSERT (PrivateData.Fv != NULL);
-    PrivateData.UnknownFvInfo        = AllocateZeroPool (sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO) * PcdGet32 (PcdPeiCoreMaxFvSupported));
-    ASSERT (PrivateData.UnknownFvInfo != NULL);
   }
   InitializePpiServices      (&PrivateData,    OldCoreData);
 
--
2.7.0.windows.1



  reply	other threads:[~2018-12-19  3:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-18  6:07 [PATCH V2 0/7] Remove PcdPeiCoreMaxXXX PCDs Star Zeng
2018-12-18  6:08 ` [PATCH V2 1/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxPeimPerFv Star Zeng
2018-12-19  3:21   ` Chiu, Chasel
2018-12-18  6:08 ` [PATCH V2 2/7] SecurityPkg Tcg(2)Pei: Remove the using of PcdPeiCoreMaxFvSupported Star Zeng
2018-12-18  6:08 ` [PATCH V2 3/7] MdeModulePkg PeiCore: " Star Zeng
2018-12-19  3:22   ` Chiu, Chasel [this message]
2018-12-18  6:08 ` [PATCH V2 4/7] MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxPpiSupported Star Zeng
2018-12-19  3:22   ` Chiu, Chasel
2018-12-18  6:08 ` [PATCH V2 5/7] OvmfPkg: Remove PcdPeiCoreMaxXXX PCDs' statement Star Zeng
2018-12-18  6:08 ` [PATCH V2 6/7] Vlv2TbltDevicePkg: " Star Zeng
2018-12-18  6:08 ` [PATCH V2 7/7] MdeModulePkg: Remove PcdPeiCoreMaxXXX PCDs Star Zeng
2018-12-19  3:21   ` Chiu, Chasel
2018-12-18  7:21 ` [PATCH V2 0/7] " Wang, Jian J

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3C3EFB470A303B4AB093197B6777CCEC501F654C@PGSMSX111.gar.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox