[edk2-devel] [PATCH V5 1/8] EmbeddedPkg: Add AllocateRuntimePages in PrePiMemoryAllocationLib

Min Xu min.m.xu at intel.com
Tue Sep 6 04:35:53 UTC 2022


From: Min M Xu <min.m.xu at intel.com>

AllocateRuntimePages is used to allocate one or more 4KB pages of
type EfiRuntimeServicesData.

Cc: Leif Lindholm <quic_llindhol at quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore at kernel.org>
Cc: Abner Chang <abner.chang at hpe.com>
Cc: Daniel Schaefer <daniel.schaefer at hpe.com>
Cc: Gerd Hoffmann <kraxel at redhat.com>
Reviewed-by: Ard Biesheuvel <ardb+tianocore at kernel.org>
Acked-by: Gerd Hoffmann <kraxel at redhat.com>
Signed-off-by: Min Xu <min.m.xu at intel.com>
---
 EmbeddedPkg/Include/Library/PrePiLib.h        | 19 ++++++
 .../MemoryAllocationLib.c                     | 65 ++++++++++++++-----
 2 files changed, 68 insertions(+), 16 deletions(-)

diff --git a/EmbeddedPkg/Include/Library/PrePiLib.h b/EmbeddedPkg/Include/Library/PrePiLib.h
index 7b2cea296f1c..3741b08c4478 100644
--- a/EmbeddedPkg/Include/Library/PrePiLib.h
+++ b/EmbeddedPkg/Include/Library/PrePiLib.h
@@ -665,6 +665,25 @@ AllocatePages (
   IN UINTN  Pages
   );
 
+/**
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData.
+
+  Allocates the number of 4KB pages of type EfiRuntimeServicesData 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  Pages                 The number of 4 KB pages to allocate.
+
+  @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimePages (
+  IN UINTN  Pages
+  );
+
 /**
   Allocates a buffer of type EfiBootServicesData.
 
diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
index 78f8da5e9527..2cc2a7112197 100644
--- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
@@ -14,23 +14,12 @@
 #include <Library/PrePiLib.h>
 #include <Library/DebugLib.h>
 
-/**
-  Allocates one or more 4KB pages of type EfiBootServicesData.
-
-  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  Pages                 The number of 4 KB pages to allocate.
-
-  @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
+STATIC
 VOID *
 EFIAPI
-AllocatePages (
-  IN UINTN  Pages
+InternalAllocatePages (
+  IN UINTN            Pages,
+  IN EFI_MEMORY_TYPE  MemoryType
   )
 {
   EFI_PEI_HOB_POINTERS  Hob;
@@ -65,12 +54,56 @@ AllocatePages (
     BuildMemoryAllocationHob (
       Hob.HandoffInformationTable->EfiFreeMemoryTop,
       Pages * EFI_PAGE_SIZE,
-      EfiBootServicesData
+      MemoryType
       );
     return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop;
   }
 }
 
+/**
+  Allocates one or more 4KB pages of type EfiBootServicesData.
+
+  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  Pages                 The number of 4 KB pages to allocate.
+
+  @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocatePages (
+  IN UINTN  Pages
+  )
+{
+  return InternalAllocatePages (Pages, EfiBootServicesData);
+}
+
+/**
+  Allocates one or more 4KB pages of type EfiRuntimeServicesData.
+
+  Allocates the number of 4KB pages of type EfiRuntimeServicesData 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  Pages                 The number of 4 KB pages to allocate.
+
+  @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimePages (
+  IN UINTN  Pages
+  )
+{
+  return InternalAllocatePages (Pages, EfiRuntimeServicesData);
+}
+
 /**
   Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
 
-- 
2.29.2.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#93172): https://edk2.groups.io/g/devel/message/93172
Mute This Topic: https://groups.io/mt/93494904/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list