summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c')
-rw-r--r--MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
index b3f9df74f1..e540e06e00 100644
--- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
@@ -7,17 +7,14 @@
**/
-
#include <PiPei.h>
-
#include <Library/MemoryAllocationLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
-
/**
Allocates one or more 4KB pages of a certain memory type.
@@ -49,7 +46,7 @@ InternalAllocatePages (
return NULL;
}
- return (VOID *) (UINTN) Memory;
+ return (VOID *)(UINTN)Memory;
}
/**
@@ -145,7 +142,7 @@ FreePages (
EFI_STATUS Status;
ASSERT (Pages != 0);
- Status = PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
+ Status = PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);
ASSERT_EFI_ERROR (Status);
}
@@ -190,23 +187,25 @@ InternalAllocateAlignedPages (
if (Pages == 0) {
return NULL;
}
+
if (Alignment > EFI_PAGE_SIZE) {
//
// Calculate the total number of pages since alignment is larger than page size.
//
- AlignmentMask = Alignment - 1;
- RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
+ AlignmentMask = Alignment - 1;
+ RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
//
// Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
//
ASSERT (RealPages > Pages);
- Status = PeiServicesAllocatePages (MemoryType, RealPages, &Memory);
+ Status = PeiServicesAllocatePages (MemoryType, RealPages, &Memory);
if (EFI_ERROR (Status)) {
return NULL;
}
- AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;
- UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory);
+
+ AlignedMemory = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask;
+ UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);
if (UnalignedPages > 0) {
//
// Free first unaligned page(s).
@@ -214,6 +213,7 @@ InternalAllocateAlignedPages (
Status = PeiServicesFreePages (Memory, UnalignedPages);
ASSERT_EFI_ERROR (Status);
}
+
Memory = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
UnalignedPages = RealPages - Pages - UnalignedPages;
if (UnalignedPages > 0) {
@@ -231,9 +231,11 @@ InternalAllocateAlignedPages (
if (EFI_ERROR (Status)) {
return NULL;
}
- AlignedMemory = (UINTN) Memory;
+
+ AlignedMemory = (UINTN)Memory;
}
- return (VOID *) AlignedMemory;
+
+ return (VOID *)AlignedMemory;
}
/**
@@ -350,7 +352,7 @@ FreeAlignedPages (
EFI_STATUS Status;
ASSERT (Pages != 0);
- Status = PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
+ Status = PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);
ASSERT_EFI_ERROR (Status);
}
@@ -399,13 +401,14 @@ AllocatePool (
IN UINTN AllocationSize
)
{
- EFI_STATUS Status;
- VOID *Buffer;
+ EFI_STATUS Status;
+ VOID *Buffer;
Status = PeiServicesAllocatePool (AllocationSize, &Buffer);
if (EFI_ERROR (Status)) {
Buffer = NULL;
}
+
return Buffer;
}
@@ -477,6 +480,7 @@ InternalAllocateZeroPool (
if (Memory != NULL) {
Memory = ZeroMem (Memory, AllocationSize);
}
+
return Memory;
}
@@ -505,6 +509,7 @@ AllocateZeroPool (
if (Memory != NULL) {
Memory = ZeroMem (Memory, AllocationSize);
}
+
return Memory;
}
@@ -579,12 +584,13 @@ InternalAllocateCopyPool (
VOID *Memory;
ASSERT (Buffer != NULL);
- ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+ ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN)Buffer + 1));
Memory = InternalAllocatePool (PoolType, AllocationSize);
if (Memory != NULL) {
- Memory = CopyMem (Memory, Buffer, AllocationSize);
+ Memory = CopyMem (Memory, Buffer, AllocationSize);
}
+
return Memory;
}
@@ -615,12 +621,13 @@ AllocateCopyPool (
VOID *Memory;
ASSERT (Buffer != NULL);
- ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+ ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN)Buffer + 1));
Memory = AllocatePool (AllocationSize);
if (Memory != NULL) {
- Memory = CopyMem (Memory, Buffer, AllocationSize);
+ Memory = CopyMem (Memory, Buffer, AllocationSize);
}
+
return Memory;
}
@@ -711,10 +718,11 @@ InternalReallocatePool (
VOID *NewBuffer;
NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);
- if (NewBuffer != NULL && OldBuffer != NULL) {
+ if ((NewBuffer != NULL) && (OldBuffer != NULL)) {
CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
FreePool (OldBuffer);
}
+
return NewBuffer;
}
@@ -831,12 +839,10 @@ ReallocateReservedPool (
VOID
EFIAPI
FreePool (
- IN VOID *Buffer
+ IN VOID *Buffer
)
{
//
// PEI phase does not support to free pool, so leave it as NOP.
//
}
-
-