sp1: bpt: Add helper to obtain memory map entry
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -36,6 +36,20 @@ bpt_get_protovar(struct bpt_protovar *res)
|
|||||||
return ops.get_protovar(res);
|
return ops.get_protovar(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
bpt_mem_entry_i(size_t index, struct mem_entry *res)
|
||||||
|
{
|
||||||
|
if (res == NULL) {
|
||||||
|
return STATUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ops.mem_entry_i == NULL) {
|
||||||
|
return STATUS_IO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ops.mem_entry_i(index, res);
|
||||||
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
bpt_init(void)
|
bpt_init(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,13 @@
|
|||||||
#include <lib/limine.h>
|
#include <lib/limine.h>
|
||||||
#include <lib/printf.h>
|
#include <lib/printf.h>
|
||||||
|
|
||||||
|
/* Memory map request */
|
||||||
|
static struct limine_memmap_response *memmap_resp = NULL;
|
||||||
|
static volatile struct limine_memmap_request memmap_req = {
|
||||||
|
.id = LIMINE_MEMMAP_REQUEST,
|
||||||
|
.revision = 0
|
||||||
|
};
|
||||||
|
|
||||||
/* HHDM request */
|
/* HHDM request */
|
||||||
static struct limine_hhdm_response *hhdm_resp = NULL;
|
static struct limine_hhdm_response *hhdm_resp = NULL;
|
||||||
static volatile struct limine_hhdm_request hhdm_req = {
|
static volatile struct limine_hhdm_request hhdm_req = {
|
||||||
@@ -36,6 +43,34 @@ limine_get_protovar(struct bpt_protovar *res)
|
|||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Obtain a memory map entry by index
|
||||||
|
*
|
||||||
|
* @index: Index of memory map entry to obtain
|
||||||
|
* @res: Result is written here
|
||||||
|
*/
|
||||||
|
static status_t
|
||||||
|
limine_mem_entry_i(size_t index, struct mem_entry *res)
|
||||||
|
{
|
||||||
|
struct limine_memmap_entry *entry;
|
||||||
|
|
||||||
|
if (res == NULL) {
|
||||||
|
return STATUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't overflow */
|
||||||
|
if (index >= memmap_resp->entry_count) {
|
||||||
|
return STATUS_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 1:1 */
|
||||||
|
entry = memmap_resp->entries[index];
|
||||||
|
res->base = entry->base;
|
||||||
|
res->length = entry->length;
|
||||||
|
res->type = entry->type;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
bpt_init_limine(struct bpt_ops *ops)
|
bpt_init_limine(struct bpt_ops *ops)
|
||||||
{
|
{
|
||||||
@@ -44,6 +79,9 @@ bpt_init_limine(struct bpt_ops *ops)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hhdm_resp = hhdm_req.response;
|
hhdm_resp = hhdm_req.response;
|
||||||
|
memmap_resp = memmap_req.response;
|
||||||
|
|
||||||
ops->get_protovar = limine_get_protovar;
|
ops->get_protovar = limine_get_protovar;
|
||||||
|
ops->mem_entry_i = limine_mem_entry_i;
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,34 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/status.h>
|
#include <sys/status.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Memory map entry 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_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Represents a memory map entry
|
||||||
|
*
|
||||||
|
* @base: Entry base address
|
||||||
|
* @length: Entry length
|
||||||
|
* @type: Entry type
|
||||||
|
*/
|
||||||
|
struct mem_entry {
|
||||||
|
uintptr_t base;
|
||||||
|
size_t length;
|
||||||
|
mem_type_t type;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The protovar stores a list of information passed
|
* The protovar stores a list of information passed
|
||||||
* by the bootloader.
|
* by the bootloader.
|
||||||
@@ -30,6 +58,7 @@ struct bpt_protovar {
|
|||||||
*/
|
*/
|
||||||
struct bpt_ops {
|
struct bpt_ops {
|
||||||
status_t(*get_protovar)(struct bpt_protovar *res);
|
status_t(*get_protovar)(struct bpt_protovar *res);
|
||||||
|
status_t(*mem_entry_i)(size_t index, struct mem_entry *res);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -39,6 +68,13 @@ struct bpt_ops {
|
|||||||
*/
|
*/
|
||||||
status_t bpt_get_protovar(struct bpt_protovar *res);
|
status_t bpt_get_protovar(struct bpt_protovar *res);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Obtain a memory map entry by index
|
||||||
|
*
|
||||||
|
* Returns STATUS_NOT_FOUND on failure
|
||||||
|
*/
|
||||||
|
status_t bpt_mem_entry_i(size_t index, struct mem_entry *res);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the boot protocol translation layer
|
* Initialize the boot protocol translation layer
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user