public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Liming Gao <liming.gao@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>, Jiewen Yao <jiewen.yao@intel.com>
Subject: [Patch 2/2] MdeModulePkg PiSmmCore: Retrieve Smram base address from system table
Date: Thu,  1 Dec 2016 14:49:34 +0800	[thread overview]
Message-ID: <1480574974-22276-3-git-send-email-liming.gao@intel.com> (raw)
In-Reply-To: <1480574974-22276-1-git-send-email-liming.gao@intel.com>

PiSmmIpl records LoadModuleAtFixAddressSmramBase in LMFAConfigurationTable.
Update PiSmmCore to directly get the address from this system table.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming.gao@intel.com>
---
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h   |  1 +
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf |  2 ++
 MdeModulePkg/Core/PiSmmCore/Pool.c        | 51 ++++++-------------------------
 3 files changed, 13 insertions(+), 41 deletions(-)

diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
index 9b72ded..168fbe9 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
@@ -37,6 +37,7 @@
 #include <Guid/EventGroup.h>
 #include <Guid/EventLegacyBios.h>
 #include <Guid/MemoryProfile.h>
+#include <Guid/LoadModuleAtFixedAddress.h>
 
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
index c256e90..f380fc5 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
@@ -98,6 +98,8 @@
   ## SOMETIMES_PRODUCES   ## GUID # Install protocol
   gEdkiiSmmMemoryProfileGuid
   gEdkiiPiSmmMemoryAttributesTableGuid          ## SOMETIMES_PRODUCES   ## SystemTable
+  ## SOMETIMES_CONSUMES   ## SystemTable
+  gLoadFixedAddressConfigurationTableGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
   PiSmmCoreExtra.uni
diff --git a/MdeModulePkg/Core/PiSmmCore/Pool.c b/MdeModulePkg/Core/PiSmmCore/Pool.c
index b638aad..0006588 100644
--- a/MdeModulePkg/Core/PiSmmCore/Pool.c
+++ b/MdeModulePkg/Core/PiSmmCore/Pool.c
@@ -35,9 +35,8 @@ SmmInitializeMemoryServices (
   )
 {
   UINTN                  Index;
- 	UINT64                 SmmCodeSize;
- 	UINTN                  CurrentSmramRangesIndex;
- 	UINT64                 MaxSize;
+  EFI_STATUS             Status;
+  EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE    *LMFAConfigurationTable;
 
   //
   // Initialize Pool list
@@ -45,45 +44,15 @@ SmmInitializeMemoryServices (
   for (Index = ARRAY_SIZE (mSmmPoolLists); Index > 0;) {
     InitializeListHead (&mSmmPoolLists[--Index]);
   }
-  CurrentSmramRangesIndex = 0;
-  //
-  // If Loading Module At fixed Address feature is enabled, cache the SMRAM base here
-  //
-  if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
-    //
-    // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
-    //
-    SmmCodeSize = LShiftU64 (PcdGet32(PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
-    
-    //
-    // Find the largest SMRAM range between 1MB and 4GB that is at least 256KB - 4K in size
-    //
-    for (Index = 0, MaxSize = SIZE_256KB - EFI_PAGE_SIZE; Index < SmramRangeCount; Index++) {
-      //
-      // Skip any SMRAM region that is already allocated, needs testing, or needs ECC initialization
-      //
-      if ((SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) != 0) {
-        continue;
-      }
-
-      if (SmramRanges[Index].CpuStart >= BASE_1MB) {
-        if ((SmramRanges[Index].CpuStart + SmramRanges[Index].PhysicalSize - 1) <= MAX_ADDRESS) {
-          if (SmramRanges[Index].PhysicalSize >= MaxSize) {
-            MaxSize = SmramRanges[Index].PhysicalSize;
-            CurrentSmramRangesIndex = Index;
-          }
-        }
-      }
-    }
-    gLoadModuleAtFixAddressSmramBase = SmramRanges[CurrentSmramRangesIndex].CpuStart;
-    
-    //
-    // cut out a memory range from this SMRAM range with the size SmmCodeSize to hold SMM driver code
-    // A notable thing is that SMM core is already loaded into this range.
-    //
-    SmramRanges[CurrentSmramRangesIndex].CpuStart     = SmramRanges[CurrentSmramRangesIndex].CpuStart + SmmCodeSize; 
-    SmramRanges[CurrentSmramRangesIndex].PhysicalSize = SmramRanges[CurrentSmramRangesIndex].PhysicalSize - SmmCodeSize;
+
+  Status = EfiGetSystemConfigurationTable (
+            &gLoadFixedAddressConfigurationTableGuid,
+           (VOID **) &LMFAConfigurationTable
+           );
+  if (!EFI_ERROR (Status) && LMFAConfigurationTable != NULL) {
+    gLoadModuleAtFixAddressSmramBase = LMFAConfigurationTable->SmramBase;
   }
+
   //
   // Add Free SMRAM regions
   //
-- 
2.8.0.windows.1



      parent reply	other threads:[~2016-12-01  6:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-01  6:49 [Patch 0/2] MdeModulePkg SmmCore: Fix hang issue when LMFA enable Liming Gao
2016-12-01  6:49 ` [Patch 1/2] MdeModulePkg SmmIpl: Fill Smram range for SMM driver " Liming Gao
2016-12-09 10:20   ` Zeng, Star
2016-12-12  1:48     ` Gao, Liming
2016-12-01  6:49 ` Liming Gao [this message]

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=1480574974-22276-3-git-send-email-liming.gao@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