public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: devel@edk2.groups.io
Cc: Andrew Fish <afish@apple.com>, Zhiguang Liu <zhiguang.liu@intel.com>
Subject: [PATCH 1/3] EmulatorPkg/WinHost: pre-allocate "physical" RAM
Date: Sat, 12 Nov 2022 12:00:40 +0800	[thread overview]
Message-ID: <20221112040042.741-2-ray.ni@intel.com> (raw)
In-Reply-To: <20221112040042.741-1-ray.ni@intel.com>

Move the "physical" RAM allocation from WinPeiAutoScan
to main() entrypoint.

This is to prepare the changes for "reset" support.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
---
 EmulatorPkg/Win/Host/WinHost.c | 60 ++++++++++++++--------------------
 1 file changed, 25 insertions(+), 35 deletions(-)

diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c
index 93247c5043..5b780ca8af 100644
--- a/EmulatorPkg/Win/Host/WinHost.c
+++ b/EmulatorPkg/Win/Host/WinHost.c
@@ -8,7 +8,7 @@
   This code produces 128 K of temporary memory for the SEC stack by directly
   allocate memory space with ReadWrite and Execute attribute.
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2016-2020 Hewlett Packard Enterprise Development LP<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
@@ -87,14 +87,6 @@ WinPeiAutoScan (
     return EFI_UNSUPPORTED;
   }
 
-  //
-  // Allocate enough memory space for emulator
-  //
-  gSystemMemory[Index].Memory = (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAlloc (NULL, (SIZE_T)(gSystemMemory[Index].Size), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
-  if (gSystemMemory[Index].Memory == 0) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
   *MemoryBase = gSystemMemory[Index].Memory;
   *MemorySize = gSystemMemory[Index].Size;
 
@@ -457,6 +449,30 @@ Returns:
     exit (1);
   }
 
+  //
+  // Allocate "physical" memory space for emulator. It will be reported out later throuth MemoryAutoScan()
+  //
+  for (Index = 0, Done = FALSE; !Done; Index++) {
+    ASSERT (Index < gSystemMemoryCount);
+    gSystemMemory[Index].Size   = ((UINT64)_wtoi (MemorySizeStr)) * ((UINT64)SIZE_1MB);
+    gSystemMemory[Index].Memory = (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAlloc (NULL, (SIZE_T)(gSystemMemory[Index].Size), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+    if (gSystemMemory[Index].Memory == 0) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    //
+    // Find the next region
+    //
+    for (Index1 = 0; MemorySizeStr[Index1] != '!' && MemorySizeStr[Index1] != 0; Index1++) {
+    }
+
+    if (MemorySizeStr[Index1] == 0) {
+      Done = TRUE;
+    }
+
+    MemorySizeStr = MemorySizeStr + Index1 + 1;
+  }
+
   //
   // Allocate space for gSystemMemory Array
   //
@@ -575,32 +591,6 @@ Returns:
     SecPrint ("\n\r");
   }
 
-  //
-  // Calculate memory regions and store the information in the gSystemMemory
-  //  global for later use. The autosizing code will use this data to
-  //  map this memory into the SEC process memory space.
-  //
-  for (Index = 0, Done = FALSE; !Done; Index++) {
-    //
-    // Save the size of the memory and make a Unicode filename SystemMemory00, ...
-    //
-    gSystemMemory[Index].Size = ((UINT64)_wtoi (MemorySizeStr)) * ((UINT64)SIZE_1MB);
-
-    //
-    // Find the next region
-    //
-    for (Index1 = 0; MemorySizeStr[Index1] != '!' && MemorySizeStr[Index1] != 0; Index1++) {
-    }
-
-    if (MemorySizeStr[Index1] == 0) {
-      Done = TRUE;
-    }
-
-    MemorySizeStr = MemorySizeStr + Index1 + 1;
-  }
-
-  SecPrint ("\n\r");
-
   //
   // Hand off to SEC Core
   //
-- 
2.37.2.windows.2


  reply	other threads:[~2022-11-12  4:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12  4:00 [PATCH 0/3] Add reset support in Emulator/WinHost PEI Ni, Ray
2022-11-12  4:00 ` Ni, Ray [this message]
2022-11-12  4:00 ` [PATCH 2/3] EmulatorPkg/WinHost: XIP for SEC and PEI_CORE Ni, Ray
2022-11-12  4:00 ` [PATCH 3/3] EmulatorPkg/WinHost: Add Reset2 PPI Ni, Ray
2022-11-18  6:31 ` [edk2-devel] [PATCH 0/3] Add reset support in Emulator/WinHost PEI Zhiguang Liu

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=20221112040042.741-2-ray.ni@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