111 ULONGLONG LowestAddressValid, HighestAddressValid;
120 &LowestAddressValid);
125 LowestPage = LowestAddressValid >>
PAGE_SHIFT;
128 if (LowestPage <= 0x100000)
137 &HighestAddressValid);
141 HighestPage = HighestAddressValid >>
PAGE_SHIFT;
156 return L"UnmapAlloc";
160 return L"UnmapUnalloc";
168 return L"MapUnalloc";
191 ULONGLONG LocalEndPage, FoundEndPage, LocalVirtualEndPage;
203 ListHead = CurrentList->First;
206 NextEntry = ListHead->
Blink;
211 NextEntry = ListHead->
Flink;
217 while (NextEntry != ListHead)
241 NextEntry = NextEntry->
Blink;
245 NextEntry = NextEntry->
Flink;
250 if (NextEntry == ListHead)
257 (LocalDescriptor.
Flags & 0x0000FFFF);
271 EfiPrintf(
L"EFI memory allocation failure\r\n");
292 (LocalEndPage == FoundEndPage))
298 LocalDescriptor.
Flags |= 0x40000000;
304 FoundDescriptor->
Flags |= 0x40000000;
308 LocalDescriptor.
Flags |= 0x40000000;
317 FoundDescriptor->
Type,
330 LocalVirtualEndPage = LocalDescriptor.
VirtualPage ?
332 if (LocalEndPage != FoundEndPage)
335 FoundDescriptor->
Type,
338 FoundEndPage - LocalEndPage);
357 FoundDescriptor->
Flags = LocalDescriptor.
Flags;
406 EfiPrintf(
L"No RAM found -- backup plan not yet implemented\r\n");
486 Request.VirtualRange.Minimum = 0;
487 Request.VirtualRange.Maximum = 0;
494 Request.BaseRange.Maximum =
Request.BaseRange.Minimum + Pages - 1;
558 ULONG AllocationFlags, CacheAttributes, AddFlags;
587 Request.VirtualRange.Minimum = 0;
588 Request.VirtualRange.Maximum = 0;
598 Request.BaseRange.Maximum =
Request.BaseRange.Minimum + PageRange;
637 EfiPrintf(
L"Failed to get unmapped, unallocated memory!\r\n");
654 AllocationFlags | CacheAttributes,
784 Request.VirtualRange.Minimum = 0;
885 ULONG ExistingDescriptors, FinalOffset;
917 nextEntry = listHead->
Flink;
918 while (listHead != nextEntry)
922 EfiPrintf(
L"Type: %08lX Flags: %08lX Base: 0x%016I64X End: 0x%016I64X\r\n",
928 nextEntry = nextEntry->
Flink;
939 FinalOffset = BootMemoryData->MdListOffset + BootMemoryData->DescriptorOffset;
944 ExistingDescriptors = BootMemoryData->DescriptorCount;
945 while (ExistingDescriptors != 0)
978 ExistingDescriptors--;
1026 BOOLEAN DontFree, HasPageData;
1033 HasPageData =
FALSE;
1056 (PageCount) && (PageCount !=
Descriptor->PageCount))
1108 sizeof(LibraryParameters));
1119 if (!(HasPageData) &&
1123 EfiPrintf(
L"Freeing zero data not yet handled!\r\n");
1230 BOOLEAN DoFirmware, DoPersistent, DoTruncated, DoBad;
1231 BOOLEAN DoReserved, DoUnmapUnalloc, DoUnmapAlloc;
1232 BOOLEAN DoMapAlloc, DoMapUnalloc, DoFirmware2;
1233 ULONG LoopCount, MdListCount, MdListSize, Used;
1240 if (!(
MemoryMap) || !(MemoryParameters))
1332 if (MemoryParameters->BufferSize >=
1344 MemoryParameters->BufferSize = MdListSize;
1350 if (++LoopCount <= 4)
1353 if (MemoryParameters->BufferSize)
1359 MemoryParameters->BufferSize = MdListSize;
1361 if (MemoryParameters->Buffer)
1374 if (MemoryParameters->Buffer)
1390 MemoryParameters->Buffer,
1401 MemoryParameters->Buffer,
1412 MemoryParameters->Buffer,
1423 MemoryParameters->Buffer,
1434 MemoryParameters->Buffer,
1445 MemoryParameters->Buffer,
1456 MemoryParameters->Buffer,
1467 MemoryParameters->Buffer,
1478 MemoryParameters->Buffer,
1489 MemoryParameters->Buffer,
1497 &MemoryParameters->ActualSize);
1587 Request.VirtualRange.Minimum = 0;
1588 Request.VirtualRange.Maximum = 0;
1670 Request.VirtualRange.Minimum = 0;
1671 Request.VirtualRange.Maximum = 0;
1700 *MappingAddress = PreferredAddress;
UINT64 EFI_PHYSICAL_ADDRESS
@ BcdLibraryInteger_AvoidLowPhysicalMemory
@ BcdLibraryInteger_TruncatePhysicalMemory
struct _BL_MEMORY_DESCRIPTOR BL_MEMORY_DESCRIPTOR
NTSTATUS MmMdFreeDescriptor(_In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor)
NTSTATUS MmMdAddDescriptorToList(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, _In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor, _In_ ULONG Flags)
ULONG_PTR MmArchTopOfApplicationAddressSpace
ULONG MmMdCountList(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList)
VOID EfiPrintf(_In_ PWCHAR Format,...)
FORCEINLINE VOID MmMdInitializeListHead(_In_ PBL_MEMORY_DESCRIPTOR_LIST List)
PBL_MEMORY_DESCRIPTOR MmMdInitByteGranularDescriptor(_In_ ULONG Flags, _In_ BL_MEMORY_TYPE Type, _In_ ULONGLONG BasePage, _In_ ULONGLONG VirtualPage, _In_ ULONGLONG PageCount)
#define BL_MM_FLAG_REQUEST_COALESCING
#define BL_MM_INCLUDE_TRUNCATED_MEMORY
#define BL_MM_INCLUDE_FIRMWARE_MEMORY
struct _BL_MEMORY_DESCRIPTOR * PBL_MEMORY_DESCRIPTOR
BL_TRANSLATION_TYPE MmTranslationType
#define BL_MM_INCLUDE_MAPPED_ALLOCATED
PVOID BlMmAllocateHeap(_In_ SIZE_T Size)
#define BL_MM_INCLUDE_UNMAPPED_UNALLOCATED
enum _BL_MEMORY_TYPE BL_MEMORY_TYPE
VOID MmMdRemoveDescriptorFromList(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, _In_ PBL_MEMORY_DESCRIPTOR Entry)
#define BL_MM_REQUEST_DEFAULT_TYPE
#define BL_MM_ADD_DESCRIPTOR_NEVER_COALESCE_FLAG
#define BL_MM_INCLUDE_MAPPED_UNALLOCATED
BL_ADDRESS_RANGE MmArchKsegAddressRange
#define BL_MM_ADD_DESCRIPTOR_COALESCE_FLAG
NTSTATUS MmMdCopyList(_In_ PBL_MEMORY_DESCRIPTOR_LIST DestinationList, _In_ PBL_MEMORY_DESCRIPTOR_LIST SourceList, _In_opt_ PBL_MEMORY_DESCRIPTOR ListDescriptor, _Out_ PULONG ActualCount, _In_ ULONG Count, _In_ ULONG Flags)
#define BL_MM_REMOVE_PHYSICAL_REGION_FLAG
VOID MmMdFreeGlobalDescriptors(VOID)
#define BL_MM_INCLUDE_BAD_MEMORY
#define BL_MM_INCLUDE_ONLY_FIRMWARE_MEMORY
NTSTATUS EfiStall(_In_ ULONG StallTime)
#define BL_MM_ADD_DESCRIPTOR_ALLOCATE_FLAG
#define BL_MM_ADD_DESCRIPTOR_TRUNCATE_FLAG
BL_LIBRARY_PARAMETERS BlpLibraryParameters
#define BL_MM_INCLUDE_PERSISTENT_MEMORY
#define BL_MM_FLAG_USE_FIRMWARE_FOR_MEMORY_MAP_BUFFERS
ULONG MmDescriptorCallTreeCount
NTSTATUS MmFwFreePages(_In_ ULONG BasePage, _In_ ULONG PageCount)
NTSTATUS BlMmMapPhysicalAddressEx(_In_ PVOID *VirtualAddress, _In_ ULONG Attributes, _In_ ULONGLONG Size, _In_ PHYSICAL_ADDRESS PhysicalAddress)
#define BL_MM_REQUEST_TOP_DOWN_TYPE
VOID MmMdFreeList(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList)
BOOLEAN MmMdFindSatisfyingRegion(_In_ PBL_MEMORY_DESCRIPTOR Descriptor, _Out_ PBL_MEMORY_DESCRIPTOR NewDescriptor, _In_ ULONGLONG Pages, _In_ PBL_ADDRESS_RANGE BaseRange, _In_ PBL_ADDRESS_RANGE VirtualRange, _In_ BOOLEAN TopDown, _In_ BL_MEMORY_TYPE MemoryType, _In_ ULONG Flags, _In_ ULONG Alignment)
NTSTATUS MmMdRemoveRegionFromMdlEx(__in PBL_MEMORY_DESCRIPTOR_LIST MdList, __in ULONG Flags, __in ULONGLONG BasePage, __in ULONGLONG PageCount, __in PBL_MEMORY_DESCRIPTOR_LIST NewMdList)
#define BL_MM_INCLUDE_FIRMWARE_MEMORY_2
@ BlMemoryValidCacheAttributeMask
@ BlMemoryValidAllocationAttributeMask
VOID MmMdInitializeList(_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList, _In_ ULONG Type, _In_ PLIST_ENTRY ListHead)
BL_LOADED_APPLICATION_ENTRY BlpApplicationEntry
NTSTATUS MmMdTruncateDescriptors(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, _In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, _In_ ULONGLONG BasePage)
#define BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE
FORCEINLINE PVOID PhysicalAddressToPtr(_In_ PHYSICAL_ADDRESS PhysicalAddress)
#define BL_MM_INCLUDE_NO_FIRMWARE_MEMORY
NTSTATUS BlMmFreeHeap(_In_ PVOID Buffer)
#define BL_MM_INCLUDE_UNMAPPED_ALLOCATED
NTSTATUS MmFwGetMemoryMap(_Out_ PBL_MEMORY_DESCRIPTOR_LIST MemoryMap, _In_ ULONG Flags)
NTSTATUS EfiAllocatePages(_In_ ULONG Type, _In_ ULONG Pages, _Inout_ EFI_PHYSICAL_ADDRESS *Memory)
#define BL_MM_INCLUDE_RESERVED_ALLOCATED
NTSTATUS BlGetBootOptionInteger(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PULONGLONG Value)
PBL_MEMORY_DESCRIPTOR MmMdFindDescriptor(_In_ ULONG WhichList, _In_ ULONG Flags, _In_ ULONGLONG Page)
#define BL_MM_REMOVE_VIRTUAL_REGION_FLAG
BIOS_MEMORY_MAP MemoryMap[32]
#define NT_SUCCESS(StatCode)
#define InitializeListHead(ListHead)
union Alignment_ Alignment
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG AllocationAttributes
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
#define STATUS_NOT_SUPPORTED
#define STATUS_NOT_IMPLEMENTED
struct _BL_PA_REQUEST BL_PA_REQUEST
NTSTATUS MmPapAllocateRegionFromMdl(_In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, _Out_opt_ PBL_MEMORY_DESCRIPTOR Descriptor, _In_ PBL_MEMORY_DESCRIPTOR_LIST CurrentList, _In_ PBL_PA_REQUEST Request, _In_ BL_MEMORY_TYPE Type)
NTSTATUS BlMmGetMemoryMap(_In_ PLIST_ENTRY MemoryMap, _In_ PBL_BUFFER_DESCRIPTOR MemoryParameters, _In_ ULONG WhichTypes, _In_ ULONG Flags)
BOOLEAN PapInitializationStatus
ULONGLONG PapMaximumPhysicalPage
BL_MEMORY_DESCRIPTOR_LIST MmMdlMappedUnallocated
ULONGLONG PapMinimumPhysicalPage
NTSTATUS MmPapAllocatePhysicalPagesInRange(_Inout_ PPHYSICAL_ADDRESS BaseAddress, _In_ BL_MEMORY_TYPE MemoryType, _In_ ULONGLONG Pages, _In_ ULONG Attributes, _In_ ULONG Alignment, _In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, _In_opt_ PBL_ADDRESS_RANGE Range, _In_ ULONG RangeType)
NTSTATUS MmPaReserveSelfMapPages(_Inout_ PPHYSICAL_ADDRESS PhysicalAddress, _In_ ULONG Alignment, _In_ ULONG PageCount)
BL_MEMORY_DESCRIPTOR_LIST MmMdlReservedAllocated
NTSTATUS MmPapAllocatePagesInRange(_Inout_ PVOID *PhysicalAddress, _In_ BL_MEMORY_TYPE MemoryType, _In_ ULONGLONG Pages, _In_ ULONG Attributes, _In_ ULONG Alignment, _In_opt_ PBL_ADDRESS_RANGE Range, _In_ ULONG Type)
BL_MEMORY_DESCRIPTOR_LIST MmMdlBadMemory
NTSTATUS MmPapFreePages(_In_ PVOID Address, _In_ ULONG WhichList)
NTSTATUS BlMmFreePhysicalPages(_In_ PHYSICAL_ADDRESS Address)
BL_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedAllocated
NTSTATUS MmPaReleaseSelfMapPages(_In_ PHYSICAL_ADDRESS Address)
BL_MEMORY_DESCRIPTOR_LIST MmMdlMappingTrackers
NTSTATUS BlMmAllocatePhysicalPages(_In_ PPHYSICAL_ADDRESS Address, _In_ BL_MEMORY_TYPE MemoryType, _In_ ULONGLONG PageCount, _In_ ULONG Attributes, _In_ ULONG Alignment)
NTSTATUS MmPaTruncateMemory(_In_ ULONGLONG BasePage)
BL_MEMORY_DESCRIPTOR_LIST MmMdlTruncatedMemory
struct _BL_PA_REQUEST * PBL_PA_REQUEST
BL_MEMORY_DESCRIPTOR_LIST MmMdlCompleteBadMemory
PWCHAR MmMdListPointerToName(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList)
ULONG PapMinimumAllocationCount
BL_MEMORY_DESCRIPTOR_LIST MmMdlMappedAllocated
BL_MEMORY_DESCRIPTOR_LIST MmMdlFreeVirtual
BL_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedUnallocated
NTSTATUS MmPapFreePhysicalPages(_In_ ULONG WhichList, _In_ ULONGLONG PageCount, _In_ PHYSICAL_ADDRESS Address)
NTSTATUS MmPaAllocatePages(_In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, _In_ PBL_MEMORY_DESCRIPTOR Descriptor, _In_ PBL_MEMORY_DESCRIPTOR_LIST CurrentList, _In_ PBL_PA_REQUEST Request, _In_ BL_MEMORY_TYPE MemoryType)
ULONG MmArchLargePageSize
NTSTATUS BlpMmInitializeConstraints(VOID)
BL_MEMORY_DESCRIPTOR_LIST MmMdlFwAllocationTracker
NTSTATUS MmPaInitialize(__in PBL_MEMORY_DATA BootMemoryData, __in ULONG MinimumAllocationCount)
NTSTATUS MmSelectMappingAddress(_Out_ PVOID *MappingAddress, _In_ PVOID PreferredAddress, _In_ ULONGLONG Size, _In_ ULONG AllocationAttributes, _In_ ULONG Flags, _In_ PHYSICAL_ADDRESS PhysicalAddress)
BL_MEMORY_DESCRIPTOR_LIST MmMdlPersistentMemory
NTSTATUS MmPapPageAllocatorExtend(_In_ ULONG Attributes, _In_ ULONG Alignment, _In_ ULONGLONG PageCount, _In_ ULONGLONG VirtualPage, _In_opt_ PBL_ADDRESS_RANGE Range, _In_opt_ ULONG Type)
#define STATUS_BUFFER_TOO_SMALL
BL_ADDRESS_RANGE BaseRange
BL_ADDRESS_RANGE VirtualRange
struct _LIST_ENTRY * Blink
struct _LIST_ENTRY * Flink
#define FIELD_OFFSET(t, f)
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_INVALID_PARAMETER
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
_Must_inspect_result_ _In_ WDFCMRESLIST List
_Must_inspect_result_ _In_ ULONG Flags
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
_In_opt_ PSECURITY_DESCRIPTOR _Out_ PSECURITY_DESCRIPTOR * NewDescriptor