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...@intel.com> > Sent: Thursday, August 12, 2021 4:57 AM > To: devel@edk2.groups.io > Cc: Xu, Min M <min.m...@intel.com>; Kinney, Michael D > <michael.d.kin...@intel.com>; Liming Gao <gaolim...@byosoft.com.cn>; > Liu, Zhiguang <zhiguang....@intel.com>; Yao, Jiewen <jiewen....@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.kin...@intel.com> > Cc: Liming Gao <gaolim...@byosoft.com.cn> > Cc: Zhiguang Liu <zhiguang....@intel.com> > Cc: Jiewen Yao <jiewen....@intel.com> > Signed-off-by: Min Xu <min.m...@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 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79206): https://edk2.groups.io/g/devel/message/79206 Mute This Topic: https://groups.io/mt/84837917/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-