diff options
author | Star Zeng <star.zeng@intel.com> | 2016-04-20 17:27:40 +0800 |
---|---|---|
committer | Star Zeng <star.zeng@intel.com> | 2016-04-22 13:39:56 +0800 |
commit | 74a88770337121b046ec5f055d4ae06abc37fa60 (patch) | |
tree | d6c2c1909a8a78c86534eb9a72ff639ee1fb06c9 /MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | |
parent | 925f0d1ae144a0b57b70fe89a26d47660cf488c7 (diff) | |
download | edk2-platforms-74a88770337121b046ec5f055d4ae06abc37fa60.tar.xz |
MdeModulePkg DxeCore: Enhance MemoryAttributesTable installation
Current MemoryAttributesTable will be installed on ReadyToBoot event
at TPL_NOTIFY level, it maybe incorrect when PcdHiiOsRuntimeSupport
= TRUE as HiiDatabaseDxe will have runtime memory allocation for HII
OS runtime support on and after ReadyToBoot. The issue was exposed at
http://article.gmane.org/gmane.comp.bios.edk2.devel/10125.
To make sure the correctness of MemoryAttributesTable, this patch is
to enhance MemoryAttributesTable installation to install
MemoryAttributesTable on ReadyToBoot event at TPL_CALLBACK - 1 level
to make sure it is at the last of ReadyToBoot event, and also hook
runtime memory allocation after ReadyToBoot.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Diffstat (limited to 'MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c')
-rw-r--r-- | MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 88 |
1 files changed, 73 insertions, 15 deletions
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c index 0362212c8b..3706b23247 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -71,18 +71,16 @@ CoreGetMemoryMapPropertiesTable ( );
extern EFI_PROPERTIES_TABLE mPropertiesTable;
+EFI_MEMORY_ATTRIBUTES_TABLE *mMemoryAttributesTable = NULL;
+BOOLEAN mMemoryAttributesTableReadyToBoot = FALSE;
/**
Install MemoryAttributesTable.
- @param[in] Event The Event this notify function registered to.
- @param[in] Context Pointer to the context data registered to the Event.
**/
VOID
-EFIAPI
InstallMemoryAttributesTable (
- EFI_EVENT Event,
- VOID *Context
+ VOID
)
{
UINTN MemoryMapSize;
@@ -97,12 +95,29 @@ InstallMemoryAttributesTable ( EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
EFI_MEMORY_DESCRIPTOR *MemoryAttributesEntry;
+ if (gMemoryMapTerminated) {
+ //
+ // Directly return after MemoryMap terminated.
+ //
+ return;
+ }
+
if ((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) == 0) {
DEBUG ((EFI_D_VERBOSE, "MemoryProtectionAttribute NON_EXECUTABLE_PE_DATA is not set, "));
DEBUG ((EFI_D_VERBOSE, "because Runtime Driver Section Alignment is not %dK.\n", EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10));
return ;
}
+ if (mMemoryAttributesTable == NULL) {
+ //
+ // InstallConfigurationTable here to occupy one entry for MemoryAttributesTable
+ // before GetMemoryMap below, as InstallConfigurationTable may allocate runtime
+ // memory for the new entry.
+ //
+ Status = gBS->InstallConfigurationTable (&gEfiMemoryAttributesTableGuid, (VOID *) (UINTN) MAX_ADDRESS);
+ ASSERT_EFI_ERROR (Status);
+ }
+
MemoryMapSize = 0;
MemoryMap = NULL;
Status = CoreGetMemoryMapPropertiesTable (
@@ -177,8 +192,52 @@ InstallMemoryAttributesTable ( MemoryMap = MemoryMapStart;
FreePool (MemoryMap);
+ //
+ // Update configuratoin table for MemoryAttributesTable.
+ //
Status = gBS->InstallConfigurationTable (&gEfiMemoryAttributesTableGuid, MemoryAttributesTable);
ASSERT_EFI_ERROR (Status);
+
+ if (mMemoryAttributesTable != NULL) {
+ FreePool (mMemoryAttributesTable);
+ }
+ mMemoryAttributesTable = MemoryAttributesTable;
+}
+
+/**
+ Install MemoryAttributesTable on memory allocation.
+
+ @param[in] MemoryType EFI memory type.
+**/
+VOID
+InstallMemoryAttributesTableOnMemoryAllocation (
+ IN EFI_MEMORY_TYPE MemoryType
+ )
+{
+ //
+ // Install MemoryAttributesTable after ReadyToBoot on runtime memory allocation.
+ //
+ if (mMemoryAttributesTableReadyToBoot &&
+ ((MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData))) {
+ InstallMemoryAttributesTable ();
+ }
+}
+
+/**
+ Install MemoryAttributesTable on ReadyToBoot.
+
+ @param[in] Event The Event this notify function registered to.
+ @param[in] Context Pointer to the context data registered to the Event.
+**/
+VOID
+EFIAPI
+InstallMemoryAttributesTableOnReadyToBoot (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ InstallMemoryAttributesTable ();
+ mMemoryAttributesTableReadyToBoot = TRUE;
}
/**
@@ -194,17 +253,16 @@ CoreInitializeMemoryAttributesTable ( EFI_EVENT ReadyToBootEvent;
//
- // Construct the table at ReadyToBoot, because this should be
- // last point to allocate RuntimeCode/RuntimeData.
+ // Construct the table at ReadyToBoot.
//
- Status = gBS->CreateEventEx (
- EVT_NOTIFY_SIGNAL,
- TPL_NOTIFY,
- InstallMemoryAttributesTable,
- NULL,
- &gEfiEventReadyToBootGuid,
- &ReadyToBootEvent
- );
+ Status = CoreCreateEventInternal (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK - 1,
+ InstallMemoryAttributesTableOnReadyToBoot,
+ NULL,
+ &gEfiEventReadyToBootGuid,
+ &ReadyToBootEvent
+ );
ASSERT_EFI_ERROR (Status);
return ;
}
|