mirror of https://github.com/acidanthera/audk.git
MdePkg/MemoryAllocationLib: Add Allocate(Aligned)CodePages
This commit is contained in:
parent
e23139949b
commit
091bca8bc8
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "ProcessorBind.h"
|
|
||||||
#include <PrePi.h>
|
#include <PrePi.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -23,38 +22,6 @@ SecWinNtPeiLoadFile (
|
||||||
IN EFI_PHYSICAL_ADDRESS *EntryPoint
|
IN EFI_PHYSICAL_ADDRESS *EntryPoint
|
||||||
);
|
);
|
||||||
|
|
||||||
STATIC
|
|
||||||
VOID *
|
|
||||||
EFIAPI
|
|
||||||
AllocateCodePages (
|
|
||||||
IN UINTN Pages
|
|
||||||
)
|
|
||||||
{
|
|
||||||
VOID *Alloc;
|
|
||||||
EFI_PEI_HOB_POINTERS Hob;
|
|
||||||
|
|
||||||
Alloc = AllocatePages (Pages);
|
|
||||||
if (Alloc == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the HOB we just created, and change the type to EfiBootServicesCode
|
|
||||||
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
|
|
||||||
while (Hob.Raw != NULL) {
|
|
||||||
if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == (UINTN)Alloc) {
|
|
||||||
Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode;
|
|
||||||
return Alloc;
|
|
||||||
}
|
|
||||||
|
|
||||||
Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (Hob));
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT (FALSE);
|
|
||||||
|
|
||||||
FreePages (Alloc, Pages);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LoadUefiImage (
|
LoadUefiImage (
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <Library/EmuThunkLib.h>
|
#include <Library/EmuThunkLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocates one or more 4KB pages of a certain memory type.
|
Allocates one or more 4KB pages of a certain memory type.
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <Library/MemoryProfileLib.h>
|
#include <Library/MemoryProfileLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiRuntimeServicesCode;
|
||||||
|
|
||||||
EFI_SMRAM_DESCRIPTOR *mSmmCoreMemoryAllocLibSmramRanges = NULL;
|
EFI_SMRAM_DESCRIPTOR *mSmmCoreMemoryAllocLibSmramRanges = NULL;
|
||||||
UINTN mSmmCoreMemoryAllocLibSmramRangeCount = 0;
|
UINTN mSmmCoreMemoryAllocLibSmramRangeCount = 0;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <Library/PhaseMemoryAllocationLib.h>
|
#include <Library/PhaseMemoryAllocationLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocates one or more 4KB pages of a certain memory type.
|
Allocates one or more 4KB pages of a certain memory type.
|
||||||
|
|
|
@ -143,6 +143,36 @@ AllocateReservedPages (
|
||||||
return Buffer;
|
return Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allocates one or more 4KB pages of type EfiBootServicesCode.
|
||||||
|
|
||||||
|
Allocates the number of 4KB pages of type EfiBootServicesCode 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
|
||||||
|
AllocateCodePages (
|
||||||
|
IN UINTN Pages
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_PHYSICAL_ADDRESS Memory;
|
||||||
|
|
||||||
|
Status = PhaseAllocatePages (AllocateAnyPages, gPhaseDefaultCodeType, Pages, &Memory);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (VOID *)(UINTN)Memory;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Frees one or more 4KB pages that were previously allocated with one of the page allocation
|
Frees one or more 4KB pages that were previously allocated with one of the page allocation
|
||||||
functions in the Memory Allocation Library.
|
functions in the Memory Allocation Library.
|
||||||
|
@ -342,6 +372,16 @@ AllocateAlignedReservedPages (
|
||||||
return Buffer;
|
return Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID *
|
||||||
|
EFIAPI
|
||||||
|
AllocateAlignedCodePages (
|
||||||
|
IN UINTN Pages,
|
||||||
|
IN UINTN Alignment
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return InternalAllocateAlignedPages (gPhaseDefaultCodeType, Pages, Alignment);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Frees one or more 4KB pages that were previously allocated with one of the aligned page
|
Frees one or more 4KB pages that were previously allocated with one of the aligned page
|
||||||
allocation functions in the Memory Allocation Library.
|
allocation functions in the Memory Allocation Library.
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "DxeCoreMemoryAllocationServices.h"
|
#include "DxeCoreMemoryAllocationServices.h"
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocates one or more 4KB pages of a certain memory type.
|
Allocates one or more 4KB pages of a certain memory type.
|
||||||
|
|
|
@ -71,6 +71,25 @@ AllocateReservedPages (
|
||||||
IN UINTN Pages
|
IN UINTN Pages
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allocates one or more 4KB pages of type EfiBootServicesCode.
|
||||||
|
|
||||||
|
Allocates the number of 4KB pages of type EfiBootServicesCode 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
|
||||||
|
AllocateCodePages (
|
||||||
|
IN UINTN Pages
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Frees one or more 4KB pages that were previously allocated with one of the page allocation
|
Frees one or more 4KB pages that were previously allocated with one of the page allocation
|
||||||
functions in the Memory Allocation Library.
|
functions in the Memory Allocation Library.
|
||||||
|
@ -170,6 +189,31 @@ AllocateAlignedReservedPages (
|
||||||
IN UINTN Alignment
|
IN UINTN Alignment
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allocates one or more 4KB pages of type EfiBootServicesCode at a specified alignment.
|
||||||
|
|
||||||
|
Allocates the number of 4KB pages specified by Pages of type EfiBootServicesCode with an
|
||||||
|
alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
|
||||||
|
returned. If there is not enough memory at the specified alignment remaining to satisfy the
|
||||||
|
request, then NULL is returned.
|
||||||
|
|
||||||
|
If Alignment is not a power of two and Alignment is not zero, then ASSERT().
|
||||||
|
If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
|
||||||
|
|
||||||
|
@param Pages The number of 4 KB pages to allocate.
|
||||||
|
@param Alignment The requested alignment of the allocation. Must be a power of two.
|
||||||
|
If Alignment is zero, then byte alignment is used.
|
||||||
|
|
||||||
|
@return A pointer to the allocated buffer or NULL if allocation fails.
|
||||||
|
|
||||||
|
**/
|
||||||
|
VOID *
|
||||||
|
EFIAPI
|
||||||
|
AllocateAlignedCodePages (
|
||||||
|
IN UINTN Pages,
|
||||||
|
IN UINTN Alignment
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Frees one or more 4KB pages that were previously allocated with one of the aligned page
|
Frees one or more 4KB pages that were previously allocated with one of the aligned page
|
||||||
allocation functions in the Memory Allocation Library.
|
allocation functions in the Memory Allocation Library.
|
||||||
|
|
|
@ -114,4 +114,9 @@ PhaseFreePool (
|
||||||
///
|
///
|
||||||
extern CONST EFI_MEMORY_TYPE gPhaseDefaultDataType;
|
extern CONST EFI_MEMORY_TYPE gPhaseDefaultDataType;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The memory type to allocate for calls to AllocateCodePages().
|
||||||
|
///
|
||||||
|
extern CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <Library/HobLib.h>
|
#include <Library/HobLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocates one or more 4KB pages of a certain memory type.
|
Allocates one or more 4KB pages of a certain memory type.
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiRuntimeServicesCode;
|
||||||
|
|
||||||
EFI_SMRAM_DESCRIPTOR *mSmramRanges;
|
EFI_SMRAM_DESCRIPTOR *mSmramRanges;
|
||||||
UINTN mSmramRangeCount;
|
UINTN mSmramRangeCount;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocates one or more 4KB pages of a certain memory type.
|
Allocates one or more 4KB pages of a certain memory type.
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "StandaloneMmCoreMemoryAllocationServices.h"
|
#include "StandaloneMmCoreMemoryAllocationServices.h"
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiRuntimeServicesCode;
|
||||||
|
|
||||||
EFI_MM_SYSTEM_TABLE *gMmst = NULL;
|
EFI_MM_SYSTEM_TABLE *gMmst = NULL;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <Library/MmServicesTableLib.h>
|
#include <Library/MmServicesTableLib.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiRuntimeServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiRuntimeServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocates one or more 4KB pages of a certain memory type.
|
Allocates one or more 4KB pages of a certain memory type.
|
||||||
|
|
|
@ -1688,33 +1688,6 @@ ConfigSmmCodeAccessCheck (
|
||||||
PERF_FUNCTION_END ();
|
PERF_FUNCTION_END ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Allocate pages for code.
|
|
||||||
|
|
||||||
@param[in] Pages Number of pages to be allocated.
|
|
||||||
|
|
||||||
@return Allocated memory.
|
|
||||||
**/
|
|
||||||
VOID *
|
|
||||||
AllocateCodePages (
|
|
||||||
IN UINTN Pages
|
|
||||||
)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status;
|
|
||||||
EFI_PHYSICAL_ADDRESS Memory;
|
|
||||||
|
|
||||||
if (Pages == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status = gSmst->SmmAllocatePages (AllocateAnyPages, EfiRuntimeServicesCode, Pages, &Memory);
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (VOID *)(UINTN)Memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Perform the remaining tasks.
|
Perform the remaining tasks.
|
||||||
|
|
||||||
|
|
|
@ -1019,18 +1019,6 @@ AllocatePageTableMemory (
|
||||||
IN UINTN Pages
|
IN UINTN Pages
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
Allocate pages for code.
|
|
||||||
|
|
||||||
@param[in] Pages Number of pages to be allocated.
|
|
||||||
|
|
||||||
@return Allocated memory.
|
|
||||||
**/
|
|
||||||
VOID *
|
|
||||||
AllocateCodePages (
|
|
||||||
IN UINTN Pages
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// S3 related global variable and function prototype.
|
// S3 related global variable and function prototype.
|
||||||
//
|
//
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <Guid/MemoryAllocationHob.h>
|
#include <Guid/MemoryAllocationHob.h>
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Add a new HOB to the HOB List.
|
Add a new HOB to the HOB List.
|
||||||
|
|
|
@ -8,43 +8,6 @@
|
||||||
|
|
||||||
#include "UefiPayloadEntry.h"
|
#include "UefiPayloadEntry.h"
|
||||||
|
|
||||||
/**
|
|
||||||
Allocate pages for code.
|
|
||||||
|
|
||||||
@param[in] Pages Number of pages to be allocated.
|
|
||||||
|
|
||||||
@return Allocated memory.
|
|
||||||
**/
|
|
||||||
VOID *
|
|
||||||
AllocateCodePages (
|
|
||||||
IN UINTN Pages
|
|
||||||
)
|
|
||||||
{
|
|
||||||
VOID *Alloc;
|
|
||||||
EFI_PEI_HOB_POINTERS Hob;
|
|
||||||
|
|
||||||
Alloc = AllocatePages (Pages);
|
|
||||||
if (Alloc == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the HOB we just created, and change the type to EfiBootServicesCode
|
|
||||||
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
|
|
||||||
while (Hob.Raw != NULL) {
|
|
||||||
if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == (UINTN)Alloc) {
|
|
||||||
Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode;
|
|
||||||
return Alloc;
|
|
||||||
}
|
|
||||||
|
|
||||||
Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (Hob));
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT (FALSE);
|
|
||||||
|
|
||||||
FreePages (Alloc, Pages);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Loads and relocates a PE/COFF image
|
Loads and relocates a PE/COFF image
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ typedef struct {
|
||||||
} PAGE_HEAD;
|
} PAGE_HEAD;
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultDataType = EfiBootServicesData;
|
||||||
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_MEMORY_TYPE gPhaseDefaultCodeType = EfiBootServicesCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocates one or more 4KB pages of a certain memory type.
|
Allocates one or more 4KB pages of a certain memory type.
|
||||||
|
|
Loading…
Reference in New Issue