TianoCore EDK2 master
Loading...
Searching...
No Matches
Allocate.c
Go to the documentation of this file.
1
10#include <PiDxe.h>
11#include <Library/HobLib.h>
14
30VOID *
31EFIAPI
33 IN EFI_MEMORY_TYPE MemoryType,
34 IN UINTN Pages
35 )
36{
37 EFI_STATUS Status;
38 EFI_ALLOCATE_TYPE AllocType;
41
42 if (Pages == 0) {
43 return NULL;
44 }
45
46 AllocType = AllocateAnyPages;
47 //
48 // A X64 build of DXE may be combined with a 32-bit build of PEI, and so we
49 // need to check the memory limit set by PEI, and allocate below 4 GB if the
50 // limit is set to 4 GB or lower.
51 //
53 if (PhitHob->EfiFreeMemoryTop <= MAX_UINT32) {
54 AllocType = AllocateMaxAddress;
55 Memory = MAX_UINT32;
56 }
57
58 Status = gBS->AllocatePages (AllocType, MemoryType, Pages, &Memory);
59 if (EFI_ERROR (Status)) {
60 return NULL;
61 }
62
63 return (VOID *)(UINTN)Memory;
64}
UINT64 UINTN
VOID *EFIAPI AllocatePeiAccessiblePages(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages)
Definition: Allocate.c:31
VOID *EFIAPI GetHobList(VOID)
Definition: HobLib.c:76
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_BOOT_SERVICES * gBS
EFI_MEMORY_TYPE
EFI_ALLOCATE_TYPE
Definition: UefiSpec.h:29
@ AllocateMaxAddress
Definition: UefiSpec.h:38
@ AllocateAnyPages
Definition: UefiSpec.h:33
EFI_PHYSICAL_ADDRESS EfiFreeMemoryTop
Definition: PiHob.h:88