[edk2-devel] [PATCH 20/23] MdePkg: Add AllocatePagesWithMemoryType support in PeiMemoryAllocationLib

Min Xu min.m.xu at intel.com
Sun Aug 15 02:51:47 UTC 2021


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 at intel.com>
> Sent: Friday, August 13, 2021 4:43 AM
> To: Xu, Min M <min.m.xu at intel.com>; devel at edk2.groups.io; Kinney,
> Michael D <michael.d.kinney at intel.com>
> Cc: Liming Gao <gaoliming at byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu at intel.com>; Yao, Jiewen <jiewen.yao at 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 at intel.com>
> > Sent: Thursday, August 12, 2021 4:57 AM
> > To: devel at edk2.groups.io
> > Cc: Xu, Min M <min.m.xu at intel.com>; Kinney, Michael D
> > <michael.d.kinney at intel.com>; Liming Gao <gaoliming at byosoft.com.cn>;
> > Liu, Zhiguang <zhiguang.liu at intel.com>; Yao, Jiewen
> > <jiewen.yao at 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 at intel.com>
> > Cc: Liming Gao <gaoliming at byosoft.com.cn>
> > Cc: Zhiguang Liu <zhiguang.liu at intel.com>
> > Cc: Jiewen Yao <jiewen.yao at intel.com>
> > Signed-off-by: Min Xu <min.m.xu at 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 (#79312): https://edk2.groups.io/g/devel/message/79312
Mute This Topic: https://groups.io/mt/84837917/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