121 lines
2.4 KiB
C
121 lines
2.4 KiB
C
/*++
|
|
|
|
Copyright (c) 2024, Quinn Stephens.
|
|
Provided under the BSD 3-Clause license.
|
|
|
|
Module Name:
|
|
|
|
mmpa.c
|
|
|
|
Abstract:
|
|
|
|
Provides memory manager page routines.
|
|
|
|
--*/
|
|
|
|
#include "bootlib.h"
|
|
#include "mm.h"
|
|
|
|
ULONG PapMinimumAllocationCount;
|
|
ULONGLONG PapMinimumPhysicalPage;
|
|
ULONGLONG PapMaximumPhysicalPage;
|
|
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlFwAllocationTracker;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlBadMemory;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlTruncatedMemory;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlPersistentMemory;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlReservedAllocated;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlMappedAllocated;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlMappedUnallocated;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedAllocated;
|
|
BOOT_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedUnallocated;
|
|
|
|
FORCEINLINE
|
|
VOID
|
|
InitializeList (
|
|
IN PBOOT_MEMORY_DESCRIPTOR_LIST List
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Initializes a MDL.
|
|
|
|
Arguments:
|
|
|
|
List - the MDL to initialize.
|
|
|
|
Return Value:
|
|
|
|
None.
|
|
|
|
--*/
|
|
|
|
{
|
|
List->Head = NULL;
|
|
List->Current = NULL;
|
|
List->Type = MDL_TYPE_PHYSICAL;
|
|
}
|
|
|
|
NTSTATUS
|
|
MmPaInitialize (
|
|
IN PBOOT_MEMORY_INFO MemoryInfo,
|
|
IN ULONG MinimumAllocation
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Initializes the page allocator.
|
|
|
|
Arguments:
|
|
|
|
MemoryInfo - pointer to the memory info structure.
|
|
|
|
MinimumAllocation - minimum amount of pages to grow the pool by at a time.
|
|
|
|
Return Value:
|
|
|
|
STATUS_SUCCESS if successful,
|
|
|
|
--*/
|
|
|
|
{
|
|
(VOID)MemoryInfo;
|
|
|
|
DebugPrint(L"Initializing page allocator...\r\n");
|
|
|
|
//
|
|
// Initialize page allocator settings.
|
|
//
|
|
PapMinimumAllocationCount = MinimumAllocation;
|
|
PapMinimumPhysicalPage = 1;
|
|
PapMaximumPhysicalPage = MAXULONGLONG >> PAGE_SHIFT;
|
|
DebugPrintf(L"Maximum physical page: %x %x\r\n", (ULONG)(PapMaximumPhysicalPage >> 32), (ULONG)(PapMaximumPhysicalPage));
|
|
|
|
//
|
|
// Initialize MDLs.
|
|
//
|
|
InitializeList(&MmMdlFwAllocationTracker);
|
|
InitializeList(&MmMdlBadMemory);
|
|
InitializeList(&MmMdlTruncatedMemory);
|
|
InitializeList(&MmMdlPersistentMemory);
|
|
InitializeList(&MmMdlReservedAllocated);;
|
|
InitializeList(&MmMdlMappedAllocated);
|
|
InitializeList(&MmMdlMappedUnallocated);
|
|
InitializeList(&MmMdlUnmappedAllocated);
|
|
InitializeList(&MmMdlUnmappedUnallocated);
|
|
|
|
//
|
|
// Get the firmware memory map.
|
|
//
|
|
// Status = MmFwGetMemoryMap(&MmMdlUnmappedUnallocated, 0x03);
|
|
// if (!NT_SUCCESS(Status)) {
|
|
// return Status;
|
|
// }
|
|
|
|
return STATUS_SUCCESS;
|
|
}
|