Re: [PATCH 20/23] MdePkg: Add AllocatePagesWithMemoryType support in PeiMemoryAllocationLib


Min Xu
 

Thanks much for the reminder. You're right. I will update my code in the next version.

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@intel.com>
Sent: Friday, August 13, 2021 4:43 AM
To: Xu, Min M <min.m.xu@intel.com>; devel@edk2.groups.io; Kinney,
Michael D <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>; Liu, Zhiguang
<zhiguang.liu@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>
Subject: RE: [PATCH 20/23] MdePkg: Add AllocatePagesWithMemoryType
support in PeiMemoryAllocationLib

Hi Min,

This patch adds a new API to the lib class.

That type of change requires updates to all the lib instances.

In the design of the MemoryAllocationLib, of a type specific allocation was
needed, a new API was added for that type. What memory types are needed
that require this new API.

If a variety of memory types are required, then why not just use the
PeiServicesLib API:

EFI_STATUS
EFIAPI
PeiServicesAllocatePages (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
OUT EFI_PHYSICAL_ADDRESS *Memory
);

Thanks,

Mike

-----Original Message-----
From: Xu, Min M <min.m.xu@intel.com>
Sent: Thursday, August 12, 2021 4:57 AM
To: devel@edk2.groups.io
Cc: Xu, Min M <min.m.xu@intel.com>; Kinney, Michael D
<michael.d.kinney@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
Liu, Zhiguang <zhiguang.liu@intel.com>; Yao, Jiewen
<jiewen.yao@intel.com>
Subject: [PATCH 20/23] MdePkg: Add AllocatePagesWithMemoryType
support
in PeiMemoryAllocationLib

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429

Allocates one or more 4KB pages of given type MemoryType.

Allocates the number of 4KB pages of MemoryType and returns a pointer
to the allocated buffer. The buffer returned is aligned on a 4KB boundary.
If Pages is 0, then NULL is returned. If there is not enough memory
remaining to satisfy the request, then NULL is returned.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
MdePkg/Include/Library/MemoryAllocationLib.h | 21 +++++++++++++++
.../MemoryAllocationLib.c | 27 +++++++++++++++++++
2 files changed, 48 insertions(+)

diff --git a/MdePkg/Include/Library/MemoryAllocationLib.h
b/MdePkg/Include/Library/MemoryAllocationLib.h
index 65a30cf146dd..2bdc0592ef3e 100644
--- a/MdePkg/Include/Library/MemoryAllocationLib.h
+++ b/MdePkg/Include/Library/MemoryAllocationLib.h
@@ -484,4 +484,25 @@ FreePool (
IN VOID *Buffer
);

+/**
+ Allocates one or more 4KB pages of given type MemoryType.
+
+ Allocates the number of 4KB pages of MemoryType and returns a
+ pointer to the allocated buffer. The buffer returned is aligned on
+ a 4KB boundary. If Pages is 0, then NULL is returned. If there is
+ not enough memory remaining to satisfy the request, then NULL is
returned.
+
+ @param MemoryType Type of memory to use for this allocation.
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocatePagesWithMemoryType (
+ IN UINTN MemoryType,
+ IN UINTN Pages
+ );
+
#endif
diff --git
a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
index b3f9df74f139..dcb313349729 100644
--- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
@@ -839,4 +839,31 @@ FreePool (
//
}

+/**
+ Allocates one or more 4KB pages of given type MemoryType.

+ Allocates the number of 4KB pages of MemoryType and returns a
+ pointer to the allocated buffer. The buffer returned is aligned on
+ a 4KB boundary. If Pages is 0, then NULL is returned. If there is
+ not enough memory remaining to satisfy the request, then NULL is
returned.
+
+ @param MemoryType Type of memory to use for this allocation.
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocatePagesWithMemoryType (
+ IN UINTN MemoryType,
+ IN UINTN Pages
+ )
+{
+ if (MemoryType >= EfiMaxMemoryType) {
+ ASSERT (FALSE);
+ return NULL;
+ }
+
+ return InternalAllocatePages (MemoryType, Pages); }
--
2.29.2.windows.2

Join devel@edk2.groups.io to automatically receive all group messages.