Discussion:
[edk2] [Patch] MdeModulePkg: Add Memory Capabilities for MMIO and Reserved Range
Liming Gao
2015-06-19 02:46:54 UTC
Permalink
UEFI2.5 spec, GetMemoryMap(), says:
Attribute: Attributes of the memory region that describe the bit mask
of capabilities for that memory region, and not necessarily the current
settings for that memory region.
But, GetMemoryMap() implementation doesn't append memory capabilities
for MMIO and Reserved memory range. This will break UEFI2.5 Properties
Table feature, because Properties Table need return EFI_MEMORY_RO or
EFI_MEMORY_XP capabilities for OS.

This patch appends memory capabilities for those memory range.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <***@intel.com>
---
MdeModulePkg/Core/Dxe/Mem/Page.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index f2efaf1..c50c5bc 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -1663,11 +1663,12 @@ CoreGetMemoryMap (
// Create EFI_MEMORY_DESCRIPTOR for every Reserved and runtime MMIO GCD entries
//
MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);
- MemoryMap->Attribute = GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO;
+ MemoryMap->Attribute = (GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO) |
+ (GcdMapEntry->Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO));

if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType;
} else if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
if ((GcdMapEntry->Attributes & EFI_MEMORY_PORT_IO) == EFI_MEMORY_PORT_IO) {
@@ -1689,11 +1690,12 @@ CoreGetMemoryMap (
// Create EFI_MEMORY_DESCRIPTOR for every Persistent GCD entries
//
MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);
- MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV;
+ MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV |
+ (GcdMapEntry->Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO));
MemoryMap->Type = EfiPersistentMemory;

//
// Check to see if the new Memory Map Descriptor can be merged with an
// existing descriptor if they are adjacent and have the same attributes
--
1.9.5.msysgit.0


------------------------------------------------------------------------------
Yao, Jiewen
2015-06-19 03:39:31 UTC
Permalink
Thanks. Liming

One clarification: EFI_MEMORY_WP is cache attribute, if we think we should add cache attribute, I suggest we add others, like UC, WB, WC.

Reviewed-by: Yao, Jiewen <***@intel.com>

-----Original Message-----
From: Liming Gao [mailto:***@intel.com]
Sent: Friday, June 19, 2015 10:47 AM
To: edk2-***@lists.sourceforge.net
Subject: [edk2] [Patch] MdeModulePkg: Add Memory Capabilities for MMIO and Reserved Range

UEFI2.5 spec, GetMemoryMap(), says:
Attribute: Attributes of the memory region that describe the bit mask of capabilities for that memory region, and not necessarily the current settings for that memory region.
But, GetMemoryMap() implementation doesn't append memory capabilities for MMIO and Reserved memory range. This will break UEFI2.5 Properties Table feature, because Properties Table need return EFI_MEMORY_RO or EFI_MEMORY_XP capabilities for OS.

This patch appends memory capabilities for those memory range.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <***@intel.com>
---
MdeModulePkg/Core/Dxe/Mem/Page.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index f2efaf1..c50c5bc 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -1663,11 +1663,12 @@ CoreGetMemoryMap (
// Create EFI_MEMORY_DESCRIPTOR for every Reserved and runtime MMIO GCD entries
//
MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);
- MemoryMap->Attribute = GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO;
+ MemoryMap->Attribute = (GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO) |
+ (GcdMapEntry->Capabilities &
+ (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO));

if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType;
} else if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
if ((GcdMapEntry->Attributes & EFI_MEMORY_PORT_IO) == EFI_MEMORY_PORT_IO) { @@ -1689,11 +1690,12 @@ CoreGetMemoryMap (
// Create EFI_MEMORY_DESCRIPTOR for every Persistent GCD entries
//
MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);
- MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV;
+ MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV |
+ (GcdMapEntry->Capabilities &
+ (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO));
MemoryMap->Type = EfiPersistentMemory;

//
// Check to see if the new Memory Map Descriptor can be merged with an
// existing descriptor if they are adjacent and have the same attributes
--
1.9.5.msysgit.0
Liming Gao
2015-06-23 10:46:24 UTC
Permalink
UEFI2.5 spec, GetMemoryMap(), says:
Attribute: Attributes of the memory region that describe the bit mask
of capabilities for that memory region, and not necessarily the current
settings for that memory region.
But, GetMemoryMap() implementation doesn't append memory capabilities
for MMIO and Reserved memory range. This will break UEFI2.5 Properties
Table feature, because Properties Table need return EFI_MEMORY_RO or
EFI_MEMORY_XP capabilities for OS.

This patch appends memory capabilities for those memory range.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <***@intel.com>
Reviewed-by: Jiewen Yao <***@intel.com>
---
MdeModulePkg/Core/Dxe/Mem/Page.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index f2efaf1..a285529 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -1663,11 +1663,13 @@ CoreGetMemoryMap (
// Create EFI_MEMORY_DESCRIPTOR for every Reserved and runtime MMIO GCD entries
//
MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);
- MemoryMap->Attribute = GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO;
+ MemoryMap->Attribute = (GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO) |
+ (GcdMapEntry->Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |
+ EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));

if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType;
} else if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
if ((GcdMapEntry->Attributes & EFI_MEMORY_PORT_IO) == EFI_MEMORY_PORT_IO) {
@@ -1689,11 +1691,13 @@ CoreGetMemoryMap (
// Create EFI_MEMORY_DESCRIPTOR for every Persistent GCD entries
//
MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;
MemoryMap->VirtualStart = 0;
MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);
- MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV;
+ MemoryMap->Attribute = GcdMapEntry->Attributes | EFI_MEMORY_NV |
+ (GcdMapEntry->Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |
+ EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));
MemoryMap->Type = EfiPersistentMemory;

//
// Check to see if the new Memory Map Descriptor can be merged with an
// existing descriptor if they are adjacent and have the same attributes
--
1.9.5.msysgit.0
Loading...