ptos: mm: Add physical memory groundwork
Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: Physical memory management
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <mm/pm.h>
|
||||
#include <ke/bpal.h>
|
||||
#include <ex/trace.h>
|
||||
|
||||
#define DTRACE(Fmt, ...) \
|
||||
TRACE("[ PM ]: " Fmt, ##__VA_ARGS__)
|
||||
|
||||
/* Safe macro to get region string */
|
||||
#define PM_REGION(TYPE) \
|
||||
((TYPE) >= NELEM(PmRegionTable)) \
|
||||
? "bad type" \
|
||||
: PmRegionTable[(TYPE)]
|
||||
|
||||
/*
|
||||
* Table of known memory regions
|
||||
*/
|
||||
static const CHAR *PmRegionTable[] = {
|
||||
[MEMORY_USABLE] = "available",
|
||||
[MEMORY_RESERVED] = "reserved",
|
||||
[MEMORY_ACPI_RECLAIM] = "acpi reclaimable",
|
||||
[MEMORY_ACPI_NVS] = "acpi nv-sleep",
|
||||
[MEMORY_BAD] = "bad",
|
||||
[MEMORY_BOOTLOADER] = "bootloader",
|
||||
[MEMORY_KERNEL] = "system",
|
||||
[MEMORY_FRAMEBUFFER] = "vram",
|
||||
[MEMORY_ACPI_TABLES] = "acpi tables"
|
||||
};
|
||||
|
||||
/*
|
||||
* Probe physical memory for usable regions and list
|
||||
* installed memory.
|
||||
*/
|
||||
static VOID
|
||||
PmProbe(VOID)
|
||||
{
|
||||
PT_STATUS Status;
|
||||
BPAL_HANDLE BpalHandle;
|
||||
MEMMAP_ENTRY Entry;
|
||||
UPTR Start, End;
|
||||
USIZE Index;
|
||||
|
||||
/*
|
||||
* We obtain memory map entries from the BPAL layer as it is provided
|
||||
* by the bootloader which got it from firmware.
|
||||
*/
|
||||
KeBpalGetHandle(&BpalHandle);
|
||||
|
||||
/* Iterate each memory entry */
|
||||
for (Index = 0;; ++Index) {
|
||||
Status = BpalHandle.MemEntryIdx(Index, &Entry);
|
||||
|
||||
/* Are we out of entries to fetch? */
|
||||
if (PT_ERROR(Status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
Start = Entry.Base;
|
||||
End = Start + Entry.Length;
|
||||
DTRACE(
|
||||
"%p - %p : %s\n",
|
||||
Start,
|
||||
End,
|
||||
PM_REGION(Entry.Type)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
MmPmInit(VOID)
|
||||
{
|
||||
DTRACE("probing physical memory...\n");
|
||||
PmProbe();
|
||||
}
|
||||
Reference in New Issue
Block a user