stos: bpal: Add memory map callbacks
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -9,8 +9,37 @@
|
|||||||
#ifndef _KE_BPAL_H_
|
#ifndef _KE_BPAL_H_
|
||||||
#define _KE_BPAL_H_ 1
|
#define _KE_BPAL_H_ 1
|
||||||
|
|
||||||
|
#include <stapi/status.h>
|
||||||
#include <stdef.h>
|
#include <stdef.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Valid memory types
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
MEMORY_USABLE,
|
||||||
|
MEMORY_RESERVED,
|
||||||
|
MEMORY_ACPI_RECLAIM,
|
||||||
|
MEMORY_ACPI_NVS,
|
||||||
|
MEMORY_BAD,
|
||||||
|
MEMORY_BOOTLOADER,
|
||||||
|
MEMORY_KERNEL,
|
||||||
|
MEMORY_FRAMEBUFFER,
|
||||||
|
MEMORY_ACPI_TABLES
|
||||||
|
} MEM_TYPE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Memory map entry
|
||||||
|
*
|
||||||
|
* @Base: Entry base
|
||||||
|
* @Length: Entry length
|
||||||
|
* @Type: Entry type
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
UQUAD Base;
|
||||||
|
UQUAD Length;
|
||||||
|
UQUAD Type;
|
||||||
|
} MEMMAP_ENTRY;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Represents a framebuffer
|
* Represents a framebuffer
|
||||||
*/
|
*/
|
||||||
@@ -33,10 +62,12 @@ typedef struct {
|
|||||||
*
|
*
|
||||||
* @KernelBase: Kernel load base
|
* @KernelBase: Kernel load base
|
||||||
* @Framebuffer: Framebuffer info
|
* @Framebuffer: Framebuffer info
|
||||||
|
* @MemEntryIdx: Callback to get memory map entry by index
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UPTR KernelBase;
|
UPTR KernelBase;
|
||||||
BPAL_FRAMEBUFFER Framebuffer;
|
BPAL_FRAMEBUFFER Framebuffer;
|
||||||
|
ST_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result);
|
||||||
} BPAL_HANDLE;
|
} BPAL_HANDLE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ static struct limine_bootloader_performance_request LoaderPerReq = {
|
|||||||
.revision = 0
|
.revision = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Memory map request */
|
||||||
|
static struct limine_memmap_response *MapResp = NULL;
|
||||||
|
static volatile struct limine_memmap_request MapReq = {
|
||||||
|
.id = LIMINE_MEMMAP_REQUEST_ID,
|
||||||
|
.revision = 0
|
||||||
|
};
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
BpalInitFramebuffer(BPAL_HANDLE *Handle)
|
BpalInitFramebuffer(BPAL_HANDLE *Handle)
|
||||||
{
|
{
|
||||||
@@ -65,6 +72,22 @@ BpalInitFramebuffer(BPAL_HANDLE *Handle)
|
|||||||
Framebuffer->BlueMaskShift = FRAMEBUFFER->blue_mask_shift;
|
Framebuffer->BlueMaskShift = FRAMEBUFFER->blue_mask_shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ST_STATUS
|
||||||
|
LimineMemEntryIdx(USIZE Idx, MEMMAP_ENTRY *Result)
|
||||||
|
{
|
||||||
|
struct limine_memmap_entry *Entry;
|
||||||
|
|
||||||
|
if (Idx >= MapResp->entry_count) {
|
||||||
|
return STATUS_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry = MapResp->entries[Idx];
|
||||||
|
Result->Base = Entry->base;
|
||||||
|
Result->Length = Entry->length;
|
||||||
|
Result->Type = Entry->type;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
KeBpalLimineInit(BPAL_HANDLE *Handle)
|
KeBpalLimineInit(BPAL_HANDLE *Handle)
|
||||||
{
|
{
|
||||||
@@ -72,6 +95,7 @@ KeBpalLimineInit(BPAL_HANDLE *Handle)
|
|||||||
LoaderPerfResp = LoaderPerReq.response;
|
LoaderPerfResp = LoaderPerReq.response;
|
||||||
HHDMResp = HHDMReq.response;
|
HHDMResp = HHDMReq.response;
|
||||||
FbResp = FbReq.response;
|
FbResp = FbReq.response;
|
||||||
|
MapResp = MapReq.response;
|
||||||
|
|
||||||
DTRACE(
|
DTRACE(
|
||||||
"slut handed control by %s %s\n",
|
"slut handed control by %s %s\n",
|
||||||
@@ -91,4 +115,5 @@ KeBpalLimineInit(BPAL_HANDLE *Handle)
|
|||||||
|
|
||||||
BpalInitFramebuffer(Handle);
|
BpalInitFramebuffer(Handle);
|
||||||
Handle->KernelBase = HHDMResp->offset;
|
Handle->KernelBase = HHDMResp->offset;
|
||||||
|
Handle->MemEntryIdx = LimineMemEntryIdx;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user