public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Subject: [PATCH v2 2/8] OvmfPkg/PlatformPei: prepare for PcdQ35TsegMbytes becoming dynamic
Date: Tue,  4 Jul 2017 18:56:23 +0200	[thread overview]
Message-ID: <20170704165629.13610-3-lersek@redhat.com> (raw)
In-Reply-To: <20170704165629.13610-1-lersek@redhat.com>

In one of the next patches we'll turn PcdQ35TsegMbytes into a dynamic PCD,
to be set by PlatformPei. Introduce the Q35TsegMbytesInitialization()
function and the "mQ35TsegMbytes" global variable to support this.

Q35TsegMbytesInitialization() manages the PCD and caches its final value
into "mQ35TsegMbytes". Call Q35TsegMbytesInitialization() from
InitializePlatform() just in time for the current PCD consumers,
PublishPeiMemory(), InitializeRamRegions() and QemuInitializeRam() --
which is called from InitializeRamRegions() -- to be rebased on top of
"mQ35TsegMbytes".

Call Q35TsegMbytesInitialization() only when PcdSmmSmramRequire is TRUE,
given that PcdQ35TsegMbytes is consumed in that case only.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.h  |  5 +++++
 OvmfPkg/PlatformPei/MemDetect.c | 17 ++++++++++++++---
 OvmfPkg/PlatformPei/Platform.c  |  4 ++++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 18f42c3f0ea8..d2d627b221c4 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -49,14 +49,19 @@ AddReservedMemoryBaseSizeHob (
   );
 
 VOID
 AddressWidthInitialization (
   VOID
   );
 
+VOID
+Q35TsegMbytesInitialization (
+  VOID
+  );
+
 EFI_STATUS
 PublishPeiMemory (
   VOID
   );
 
 UINT32
 GetSystemMemorySizeBelow4gb (
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 78a8e0de346c..886d23622665 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -38,14 +38,25 @@ Module Name:
 #include "Cmos.h"
 
 UINT8 mPhysMemAddressWidth;
 
 STATIC UINT32 mS3AcpiReservedMemoryBase;
 STATIC UINT32 mS3AcpiReservedMemorySize;
 
+STATIC UINT16 mQ35TsegMbytes;
+
+VOID
+Q35TsegMbytesInitialization (
+  VOID
+  )
+{
+  mQ35TsegMbytes = PcdGet16 (PcdQ35TsegMbytes);
+}
+
+
 UINT32
 GetSystemMemorySizeBelow4gb (
   VOID
   )
 {
   UINT8 Cmos0x34;
   UINT8 Cmos0x35;
@@ -344,15 +355,15 @@ PublishPeiMemory (
   UINT32                      PeiMemoryCap;
 
   LowerMemorySize = GetSystemMemorySizeBelow4gb ();
   if (FeaturePcdGet (PcdSmmSmramRequire)) {
     //
     // TSEG is chipped from the end of low RAM
     //
-    LowerMemorySize -= FixedPcdGet16 (PcdQ35TsegMbytes) * SIZE_1MB;
+    LowerMemorySize -= mQ35TsegMbytes * SIZE_1MB;
   }
 
   //
   // If S3 is supported, then the S3 permanent PEI memory is placed next,
   // downwards. Its size is primarily dictated by CpuMpPei. The formula below
   // is an approximation.
   //
@@ -452,15 +463,15 @@ QemuInitializeRam (
     // Create memory HOBs
     //
     AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);
 
     if (FeaturePcdGet (PcdSmmSmramRequire)) {
       UINT32 TsegSize;
 
-      TsegSize = FixedPcdGet16 (PcdQ35TsegMbytes) * SIZE_1MB;
+      TsegSize = mQ35TsegMbytes * SIZE_1MB;
       AddMemoryRangeHob (BASE_1MB, LowerMemorySize - TsegSize);
       AddReservedMemoryBaseSizeHob (LowerMemorySize - TsegSize, TsegSize,
         TRUE);
     } else {
       AddMemoryRangeHob (BASE_1MB, LowerMemorySize);
     }
 
@@ -601,15 +612,15 @@ InitializeRamRegions (
     if (FeaturePcdGet (PcdSmmSmramRequire)) {
       UINT32 TsegSize;
 
       //
       // Make sure the TSEG area that we reported as a reserved memory resource
       // cannot be used for reserved memory allocations.
       //
-      TsegSize = FixedPcdGet16 (PcdQ35TsegMbytes) * SIZE_1MB;
+      TsegSize = mQ35TsegMbytes * SIZE_1MB;
       BuildMemoryAllocationHob (
         GetSystemMemorySizeBelow4gb() - TsegSize,
         TsegSize,
         EfiReservedMemoryType
         );
     }
   }
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 3e9fda7c7ab0..b8a28450d6c5 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -641,14 +641,18 @@ InitializePlatform (
   }
 
   S3Verification ();
   BootModeInitialization ();
   AddressWidthInitialization ();
   MaxCpuCountInitialization ();
 
+  if (FeaturePcdGet (PcdSmmSmramRequire)) {
+    Q35TsegMbytesInitialization ();
+  }
+
   PublishPeiMemory ();
 
   InitializeRamRegions ();
 
   if (mXen) {
     DEBUG ((EFI_D_INFO, "Xen was detected\n"));
     InitializeXen ();
-- 
2.13.1.3.g8be5a757fa67




  parent reply	other threads:[~2017-07-04 16:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-04 16:56 [PATCH v2 0/8] OvmfPkg: recognize an extended TSEG when QEMU offers it Laszlo Ersek
2017-07-04 16:56 ` [PATCH v2 1/8] OvmfPkg: widen PcdQ35TsegMbytes to UINT16 Laszlo Ersek
2017-07-04 16:56 ` Laszlo Ersek [this message]
2017-07-04 16:56 ` [PATCH v2 3/8] OvmfPkg/SmmAccess: prepare for PcdQ35TsegMbytes becoming dynamic Laszlo Ersek
2017-07-04 16:56 ` [PATCH v2 4/8] OvmfPkg: make PcdQ35TsegMbytes dynamic Laszlo Ersek
2017-07-04 16:56 ` [PATCH v2 5/8] OvmfPkg/IndustryStandard/Q35MchIch9.h: add extended TSEG size macros Laszlo Ersek
2017-07-04 16:56 ` [PATCH v2 6/8] OvmfPkg/SmmAccess: support extended TSEG size Laszlo Ersek
2017-07-04 16:56 ` [PATCH v2 7/8] OvmfPkg/PlatformPei: honor extended TSEG in PcdQ35TsegMbytes if available Laszlo Ersek
2017-07-04 16:56 ` [PATCH v2 8/8] OvmfPkg: mention the extended TSEG near the PcdQ35TsegMbytes declaration Laszlo Ersek
2017-07-05 17:31 ` [PATCH v2 0/8] OvmfPkg: recognize an extended TSEG when QEMU offers it Jordan Justen
2017-07-05 18:03   ` Laszlo Ersek
2017-07-05 20:43 ` Laszlo Ersek

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=20170704165629.13610-3-lersek@redhat.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