123 lines
2.4 KiB
C
123 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;
|
|
|
|
MEMORY_DESCRIPTOR_LIST MmMdlFwAllocationTracker;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlBadMemory;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlTruncatedMemory;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlPersistentMemory;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlReservedAllocated;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlMappedAllocated;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlMappedUnallocated;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlUnmappedAllocated;
|
|
MEMORY_DESCRIPTOR_LIST MmMdlUnmappedUnallocated;
|
|
|
|
FORCEINLINE
|
|
VOID
|
|
InitializeMdl (
|
|
IN PMEMORY_DESCRIPTOR_LIST Mdl
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Initializes a MDL.
|
|
|
|
Arguments:
|
|
|
|
Mdl - the MDL to initialize.
|
|
|
|
Return Value:
|
|
|
|
None.
|
|
|
|
--*/
|
|
|
|
{
|
|
Mdl->Head = NULL;
|
|
Mdl->Current = NULL;
|
|
Mdl->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,
|
|
|
|
--*/
|
|
|
|
{
|
|
NTSTATUS Status;
|
|
|
|
(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.
|
|
//
|
|
InitializeMdl(&MmMdlFwAllocationTracker);
|
|
InitializeMdl(&MmMdlBadMemory);
|
|
InitializeMdl(&MmMdlTruncatedMemory);
|
|
InitializeMdl(&MmMdlPersistentMemory);
|
|
InitializeMdl(&MmMdlReservedAllocated);;
|
|
InitializeMdl(&MmMdlMappedAllocated);
|
|
InitializeMdl(&MmMdlMappedUnallocated);
|
|
InitializeMdl(&MmMdlUnmappedAllocated);
|
|
InitializeMdl(&MmMdlUnmappedUnallocated);
|
|
|
|
//
|
|
// Get the firmware memory map.
|
|
//
|
|
Status = MmFwGetMemoryMap(&MmMdlUnmappedUnallocated, 0x03);
|
|
if (!NT_SUCCESS(Status)) {
|
|
return Status;
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
}
|