Re: [edk2] [PATCH v2 02/11] StandaloneMmPkg: add MM_STANDALONE MemoryAllocationLib implementation
Reviewed-by: jiewen@intel.com > -Original Message- > From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org] > Sent: Wednesday, January 16, 2019 12:22 PM > To: edk2-devel@lists.01.org > Cc: Ard Biesheuvel ; Achin Gupta > ; Yao, Jiewen ; Supreeth > Venkatesh ; Leif Lindholm > ; Jagadeesh Ujja ; > Thomas Panakamattam Abraham ; Sami > Mujawar > Subject: [PATCH v2 02/11] StandaloneMmPkg: add MM_STANDALONE > MemoryAllocationLib implementation > > This MemoryAllocationLib code is based on the staging implementation of > StandaloneMmPkg, with the following changes: > - use correct MODULE_TYPE > - include MmServicesTableLib instead of declaring gMmst directly > - update code comments referring to the MM core > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jagadeesh Ujja > Signed-off-by: Ard Biesheuvel > --- > > StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/Standalone > MmMemoryAllocationLib.c | 822 > > StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/Standalone > MmMemoryAllocationLib.inf | 42 + > 2 files changed, 864 insertions(+) > > diff --git > a/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/Standalo > neMmMemoryAllocationLib.c > b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/Standalo > neMmMemoryAllocationLib.c > new file mode 100644 > index ..c7c1282babff > --- /dev/null > +++ > b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/Standalo > neMmMemoryAllocationLib.c > @@ -0,0 +1,822 @@ > +/** @file > + Support routines for memory allocation routines based on Standalone > MM Core internal functions. > + > + Copyright (c) 2015, Intel Corporation. All rights reserved. > + Copyright (c) 2016 - 2018, ARM Limited. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the > BSD License > + which accompanies this distribution. The full text of the license may be > found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > +**/ > + > +#include > + > +#include > +#include > +#include > +#include > + > +/** > + Allocates one or more 4KB pages of a certain memory type. > + > + Allocates the number of 4KB pages of a certain memory type 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 MemoryTypeThe type of memory to allocate. > + @param Pages The number of 4 KB pages to > allocate. > + > + @return A pointer to the allocated buffer or NULL if allocation fails. > + > +**/ > +VOID * > +InternalAllocatePages ( > + IN EFI_MEMORY_TYPE MemoryType, > + IN UINTNPages > + ) > +{ > + EFI_STATUSStatus; > + EFI_PHYSICAL_ADDRESS Memory; > + > + if (Pages == 0) { > +return NULL; > + } > + > + Status = gMmst->MmAllocatePages (AllocateAnyPages, MemoryType, > Pages, ); > + if (EFI_ERROR (Status)) { > +return NULL; > + } > + return (VOID *)(UINTN)Memory; > +} > + > +/** > + Allocates one or more 4KB pages of type EfiBootServicesData. > + > + Allocates the number of 4KB pages of type EfiBootServicesData 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 (EfiRuntimeServicesData, 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 > + ) > +{ > + return InternalAllocatePages (EfiRuntimeServicesData, Pages); > +} > + > +/** > + Allocates one or more 4KB pages of type EfiReservedMemoryType. > + > + Allocates the number of 4KB pages of type EfiReservedMemoryType and > returns a pointer to the > + allocated
[edk2] [PATCH v2 02/11] StandaloneMmPkg: add MM_STANDALONE MemoryAllocationLib implementation
This MemoryAllocationLib code is based on the staging implementation of StandaloneMmPkg, with the following changes: - use correct MODULE_TYPE - include MmServicesTableLib instead of declaring gMmst directly - update code comments referring to the MM core Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jagadeesh Ujja Signed-off-by: Ard Biesheuvel --- StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c | 822 StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.inf | 42 + 2 files changed, 864 insertions(+) diff --git a/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c new file mode 100644 index ..c7c1282babff --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c @@ -0,0 +1,822 @@ +/** @file + Support routines for memory allocation routines based on Standalone MM Core internal functions. + + Copyright (c) 2015, Intel Corporation. All rights reserved. + Copyright (c) 2016 - 2018, ARM Limited. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include + +#include +#include +#include +#include + +/** + Allocates one or more 4KB pages of a certain memory type. + + Allocates the number of 4KB pages of a certain memory type 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 MemoryTypeThe type of memory to allocate. + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +InternalAllocatePages ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTNPages + ) +{ + EFI_STATUSStatus; + EFI_PHYSICAL_ADDRESS Memory; + + if (Pages == 0) { +return NULL; + } + + Status = gMmst->MmAllocatePages (AllocateAnyPages, MemoryType, Pages, ); + if (EFI_ERROR (Status)) { +return NULL; + } + return (VOID *)(UINTN)Memory; +} + +/** + Allocates one or more 4KB pages of type EfiBootServicesData. + + Allocates the number of 4KB pages of type EfiBootServicesData 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 (EfiRuntimeServicesData, 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 + ) +{ + return InternalAllocatePages (EfiRuntimeServicesData, Pages); +} + +/** + Allocates one or more 4KB pages of type EfiReservedMemoryType. + + Allocates the number of 4KB pages of type EfiReservedMemoryType 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 +AllocateReservedPages ( + IN UINTN Pages + ) +{ + return NULL; +} + +/** + Frees one or more 4KB pages that were previously allocated with one of the page allocation + functions in the Memory Allocation Library. + + Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer + must have been allocated on a previous call to the page allocation