aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/riscv64/include/vmem.h4
-rw-r--r--arch/riscv64/init/init.c11
-rw-r--r--arch/riscv64/kernel/vmem.c57
-rw-r--r--common/debug.c2
-rw-r--r--common/dmem.c4
-rw-r--r--common/main.c2
-rw-r--r--common/mem_regions.c6
-rw-r--r--common/proc.c2
-rw-r--r--common/tcb.c2
-rw-r--r--common/vmem.c6
-rw-r--r--include/apos/debug.h2
-rw-r--r--include/apos/dmem.h4
-rw-r--r--include/apos/mem_regions.h4
-rw-r--r--include/apos/proc.h2
-rw-r--r--include/apos/tcb.h2
-rw-r--r--include/apos/vmem.h6
-rw-r--r--include/arch/vmem.h23
17 files changed, 67 insertions, 72 deletions
diff --git a/arch/riscv64/include/vmem.h b/arch/riscv64/include/vmem.h
index 222d54b..7e8e915 100644
--- a/arch/riscv64/include/vmem.h
+++ b/arch/riscv64/include/vmem.h
@@ -25,8 +25,8 @@ enum mm_mode {
Sv32,
};
-struct vm_branch {
- struct vm_branch *leaf[RISCV_NUM_LEAVES];
+struct vmem {
+ struct vmem *leaf[RISCV_NUM_LEAVES];
};
#endif /* APOS_RISCV_VMAP_H */
diff --git a/arch/riscv64/init/init.c b/arch/riscv64/init/init.c
index 31a9155..bc68ea8 100644
--- a/arch/riscv64/init/init.c
+++ b/arch/riscv64/init/init.c
@@ -6,7 +6,7 @@
#include <csr.h>
/* assume 64 bit for now */
-struct vm_branch *root_branch;
+struct vmem *root_branch;
#define to_pte(a, f) (((a) >> 12) << 10 | (f))
@@ -16,22 +16,21 @@ void init_bootmem()
size_t flags = VM_V | VM_X | VM_R | VM_W;
extern char *__init_start;
- root_branch = (struct vm_branch *)align_down(
+ root_branch = (struct vmem *)align_down(
(uintptr_t)&__init_start - SZ_4K, SZ_4K);
/* direct mapping (temp) */
for (size_t i = 0; i < CSTACK_PAGE; ++i)
- root_branch->leaf[i] =
- (struct vm_branch *)to_pte(SZ_1G * i, flags);
+ root_branch->leaf[i] = (struct vmem *)to_pte(SZ_1G * i, flags);
/* kernel (also sort of direct mapping) */
flags |= VM_G;
for (size_t i = KSTART_PAGE; i < IO_PAGE; ++i)
- root_branch->leaf[i] = (struct vm_branch *)to_pte(
+ root_branch->leaf[i] = (struct vmem *)to_pte(
RAM_BASE + SZ_1G * (i - 256), flags);
/* kernel IO, map to 0 for now, will be updated in the future */
- root_branch->leaf[IO_PAGE] = (struct vm_branch *)to_pte(0, flags);
+ root_branch->leaf[IO_PAGE] = (struct vmem *)to_pte(0, flags);
csr_write(CSR_SATP, SATP_MODE_Sv39 | ((uintptr_t)root_branch >> 12));
}
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index 0285f39..29bc084 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -17,7 +17,7 @@
#define is_leaf(pte) (is_active(pte) && (pte_flags(pte) & ~VM_V))
#define is_branch(pte) (is_active(pte) && !(pte_flags(pte) & ~VM_V))
-static pm_t *__find_vmem(struct vm_branch *b, vm_t v, enum mm_order *o)
+static pm_t *__find_vmem(struct vmem *b, vm_t v, enum mm_order *o)
{
enum mm_order top = __mm_max_order;
if (o)
@@ -36,14 +36,13 @@ static pm_t *__find_vmem(struct vm_branch *b, vm_t v, enum mm_order *o)
return (pm_t *)&b->leaf[idx];
}
- b = (struct vm_branch *)pte_addr(pte);
+ b = (struct vmem *)pte_addr(pte);
} while (top--);
return 0;
}
-stat_t mod_vpage(struct vm_branch *branch, vm_t vaddr, pm_t paddr,
- vmflags_t flags)
+stat_t mod_vpage(struct vmem *branch, vm_t vaddr, pm_t paddr, vmflags_t flags)
{
enum mm_order order;
pm_t *pte = __find_vmem(branch, vaddr, &order);
@@ -63,7 +62,7 @@ stat_t mod_vpage(struct vm_branch *branch, vm_t vaddr, pm_t paddr,
/* huh, should probably add status flags etc. to all my API functions. Damn, I'm
* lazy. */
-stat_t stat_vpage(struct vm_branch *branch, vm_t vaddr, pm_t *paddr,
+stat_t stat_vpage(struct vmem *branch, vm_t vaddr, pm_t *paddr,
enum mm_order *order, vmflags_t *flags)
{
pm_t *pte = __find_vmem(branch, vaddr, order);
@@ -80,29 +79,28 @@ stat_t stat_vpage(struct vm_branch *branch, vm_t vaddr, pm_t *paddr,
return ERR_NF;
}
-static struct vm_branch *__create_leaf()
+static struct vmem *__create_leaf()
{
pm_t new_leaf = alloc_page(MM_KPAGE, 0);
- memset((void *)new_leaf, 0, sizeof(struct vm_branch));
- return (struct vm_branch *)to_pte((pm_t)__pa(new_leaf), VM_V);
+ memset((void *)new_leaf, 0, sizeof(struct vmem));
+ return (struct vmem *)to_pte((pm_t)__pa(new_leaf), VM_V);
}
-static void __destroy_branch(struct vm_branch *b)
+static void __destroy_branch(struct vmem *b)
{
if (!b)
return;
for (size_t i = 0; i < BASE_PAGE_SIZE / sizeof(pm_t); ++i) {
if (is_branch(b->leaf[i]))
- __destroy_branch(
- (struct vm_branch *)pte_addr(b->leaf[i]));
+ __destroy_branch((struct vmem *)pte_addr(b->leaf[i]));
free_page(MM_KPAGE, (pm_t)pte_addr(b->leaf[i]));
}
}
-stat_t map_vpage(struct vm_branch *branch, pm_t paddr, vm_t vaddr,
- vmflags_t flags, enum mm_order order)
+stat_t map_vpage(struct vmem *branch, pm_t paddr, vm_t vaddr, vmflags_t flags,
+ enum mm_order order)
{
enum mm_order top = __mm_max_order;
while (top != order) {
@@ -111,7 +109,7 @@ stat_t map_vpage(struct vm_branch *branch, pm_t paddr, vm_t vaddr,
if (!branch->leaf[idx])
branch->leaf[idx] = __create_leaf();
- branch = (struct vm_branch *)pte_addr(branch->leaf[idx]);
+ branch = (struct vmem *)pte_addr(branch->leaf[idx]);
top--;
}
@@ -121,12 +119,12 @@ stat_t map_vpage(struct vm_branch *branch, pm_t paddr, vm_t vaddr,
__destroy_branch(branch->leaf[idx]);
branch->leaf[idx] =
- (struct vm_branch *)to_pte((pm_t)__pa(paddr), vp_flags(flags));
+ (struct vmem *)to_pte((pm_t)__pa(paddr), vp_flags(flags));
return top == __mm_max_order ? INFO_SEFF : OK;
}
-stat_t unmap_vpage(struct vm_branch *branch, vm_t vaddr)
+stat_t unmap_vpage(struct vmem *branch, vm_t vaddr)
{
pm_t *pte = __find_vmem(branch, vaddr, 0);
if (pte) {
@@ -147,9 +145,9 @@ void flush_tlb_all()
__asm__ volatile("sfence.vma\n" ::: "memory");
}
-static void __start_vmem(struct vm_branch *branch, enum mm_mode m)
+static void __start_vmem(struct vmem *branch, enum mm_mode m)
{
- branch = (struct vm_branch *)__pa(branch);
+ branch = (struct vmem *)__pa(branch);
if (m == Sv32)
csr_write(CSR_SATP,
@@ -165,55 +163,54 @@ static void __start_vmem(struct vm_branch *branch, enum mm_mode m)
/* Sv57 && Sv64 in the future? */
}
-struct vm_branch *init_vmem(void *fdt)
+struct vmem *init_vmem(void *fdt)
{
UNUSED(fdt);
- struct vm_branch *b = create_vmem();
+ struct vmem *b = create_vmem();
/* update which memory branch to use */
__start_vmem(b, Sv39);
return b;
}
-struct vm_branch *create_vmem()
+struct vmem *create_vmem()
{
- struct vm_branch *b = (struct vm_branch *)alloc_page(MM_KPAGE, 0);
+ struct vmem *b = (struct vmem *)alloc_page(MM_KPAGE, 0);
memset(b, 0, MM_KPAGE_SIZE);
populate_kvmem(b);
return b;
}
-stat_t destroy_vmem(struct vm_branch *b)
+stat_t destroy_vmem(struct vmem *b)
{
free_page(MM_KPAGE, (pm_t)b);
return OK;
}
-stat_t populate_kvmem(struct vm_branch *b)
+stat_t populate_kvmem(struct vmem *b)
{
size_t flags = VM_V | VM_R | VM_W | VM_X | VM_G;
for (size_t i = KSTART_PAGE; i < IO_PAGE; ++i)
- b->leaf[i] = (struct vm_branch *)to_pte(
+ b->leaf[i] = (struct vmem *)to_pte(
RAM_BASE + SZ_1G * (i - KSTART_PAGE), flags);
/* map kernel IO to zero for now, this will be overridden later
* (if at all) */
- b->leaf[IO_PAGE] = (struct vm_branch *)to_pte(0, flags);
+ b->leaf[IO_PAGE] = (struct vmem *)to_pte(0, flags);
return OK;
}
#if defined(DEBUG)
-vm_t setup_kernel_io(struct vm_branch *b, vm_t paddr)
+vm_t setup_kernel_io(struct vmem *b, vm_t paddr)
{
/* assume Sv39 for now */
pm_t gigapage = paddr / MM_GPAGE_SIZE;
- b->leaf[IO_PAGE] =
- (struct vm_branch *)to_pte(gigapage, VM_V | VM_R | VM_W);
+ b->leaf[IO_PAGE] = (struct vmem *)to_pte(gigapage, VM_V | VM_R | VM_W);
return -SZ_1G + paddr - (gigapage * MM_GPAGE_SIZE);
}
#endif
-stat_t clone_uvmem(struct vm_branch *r, struct vm_branch *b)
+stat_t clone_uvmem(struct vmem *r, struct vmem *b)
{
/* TODO: error checking? */
for (size_t i = 0; i <= CSTACK_PAGE; ++i)
diff --git a/common/debug.c b/common/debug.c
index 43c9ae5..a008a52 100644
--- a/common/debug.c
+++ b/common/debug.c
@@ -23,7 +23,7 @@ void setup_dmap_dbg()
setup_dbg(dbg_info.dbg_ptr, dbg_info.dev);
}
-void setup_io_dbg(struct vm_branch *b)
+void setup_io_dbg(struct vmem *b)
{
vm_t io_ptr = setup_kernel_io(b, dbg_info.dbg_ptr);
setup_dbg(io_ptr, dbg_info.dev);
diff --git a/common/dmem.c b/common/dmem.c
index 6c207c1..a116547 100644
--- a/common/dmem.c
+++ b/common/dmem.c
@@ -26,7 +26,7 @@ stat_t init_devmem(pm_t ram_base, pm_t ram_top)
return OK;
}
-stat_t dev_alloc_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t dev_alloc_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data)
{
stat_t *status = (stat_t *)data;
@@ -36,7 +36,7 @@ stat_t dev_alloc_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
return OK;
}
-stat_t dev_free_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t dev_free_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data)
{
UNUSED(offset);
diff --git a/common/main.c b/common/main.c
index 7168aeb..b2928be 100644
--- a/common/main.c
+++ b/common/main.c
@@ -18,7 +18,7 @@ void __main main(void *fdt)
setup_arch(fdt);
init_pmem(fdt);
- struct vm_branch *b = init_vmem(fdt);
+ struct vmem *b = init_vmem(fdt);
/* start up debugging in kernel IO */
setup_io_dbg(b);
diff --git a/common/mem_regions.c b/common/mem_regions.c
index 95933d3..e6c4644 100644
--- a/common/mem_regions.c
+++ b/common/mem_regions.c
@@ -161,8 +161,8 @@ struct mem_region *find_used_region(struct mem_region_root *r, vm_t start)
}
static struct mem_region *__create_region(vm_t start, vm_t end,
- struct mem_region *prev,
- struct mem_region *next)
+ struct mem_region *prev,
+ struct mem_region *next)
{
struct mem_region *m = get_mem_node();
m->start = start;
@@ -441,7 +441,7 @@ stat_t free_known_region(struct mem_region_root *r, struct mem_region *m)
* NOTE: not actually optimal, this doesn't bother to go through possible
* permutations etc. which would be slow and I don't want to implement it.
*/
-vm_t map_fill_region(struct vm_branch *b, region_callback_t *mem_handler,
+vm_t map_fill_region(struct vmem *b, region_callback_t *mem_handler,
pm_t offset, vm_t start, size_t bytes, vmflags_t flags,
void *data)
{
diff --git a/common/proc.c b/common/proc.c
index 7721f35..f4c0899 100644
--- a/common/proc.c
+++ b/common/proc.c
@@ -25,7 +25,7 @@ static vm_t __setup_proc_stack(struct tcb *t, size_t bytes)
return alloc_uvmem(t, bytes, VM_V | VM_R | VM_W | VM_U);
}
-stat_t init_proc(void *fdt, struct vm_branch *b)
+stat_t init_proc(void *fdt, struct vmem *b)
{
init_tcbs();
diff --git a/common/tcb.c b/common/tcb.c
index 32c31e1..1e8c648 100644
--- a/common/tcb.c
+++ b/common/tcb.c
@@ -101,7 +101,7 @@ struct tcb *create_proc(struct tcb *p)
static stat_t __destroy_thread_data(struct tcb *t)
{
- /* free vm_branch */
+ /* free vmem */
destroy_vmem(t->b_r);
/* free associated kernel stack and the structure itself */
diff --git a/common/vmem.c b/common/vmem.c
index b665491..7ea83b1 100644
--- a/common/vmem.c
+++ b/common/vmem.c
@@ -118,7 +118,7 @@ stat_t free_uvmem(struct tcb *t, vm_t va)
return status;
}
-stat_t alloc_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t alloc_uvmem_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data)
{
*offset = alloc_page(order, *offset);
@@ -133,7 +133,7 @@ stat_t alloc_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
return (ret == INFO_SEFF) ? OK : ret;
}
-stat_t alloc_shared_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t alloc_shared_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data)
{
if (order != MM_O0)
@@ -148,7 +148,7 @@ stat_t alloc_shared_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
return (ret == INFO_SEFF) ? OK : ret;
}
-stat_t free_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t free_uvmem_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data)
{
UNUSED(flags);
diff --git a/include/apos/debug.h b/include/apos/debug.h
index 25ea132..8df7342 100644
--- a/include/apos/debug.h
+++ b/include/apos/debug.h
@@ -136,7 +136,7 @@ void __fmt(1, 2) dbg(const char *fmt, ...);
void init_dbg(const void *fdt);
void setup_dmap_dbg();
-void setup_io_dbg(struct vm_branch *b);
+void setup_io_dbg(struct vmem *b);
void setup_dbg(pm_t pt, enum serial_dev dev);
struct dbg_info dbg_from_fdt(const void *fdt);
diff --git a/include/apos/dmem.h b/include/apos/dmem.h
index 3ee93b6..59083cb 100644
--- a/include/apos/dmem.h
+++ b/include/apos/dmem.h
@@ -13,9 +13,9 @@ stat_t init_devmem(pm_t ram_base, pm_t ram_top);
vm_t alloc_devmem(struct tcb *t, pm_t dev_start, size_t bytes, vmflags_t flags);
stat_t free_devmem(struct tcb *t, vm_t dev_start);
-stat_t dev_free_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t dev_free_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order t, void *);
-stat_t dev_alloc_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t dev_alloc_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order t, void *);
#endif /* APOS_DEV_H */
diff --git a/include/apos/mem_regions.h b/include/apos/mem_regions.h
index 9f09eff..2d777a9 100644
--- a/include/apos/mem_regions.h
+++ b/include/apos/mem_regions.h
@@ -44,11 +44,11 @@ struct mem_region *find_closest_used_region(struct mem_region_root *r,
struct mem_region *find_free_region(struct mem_region_root *r, size_t size,
size_t *align);
-typedef stat_t region_callback_t(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+typedef stat_t region_callback_t(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order,
void *data);
-vm_t map_fill_region(struct vm_branch *b, region_callback_t *mem_handler,
+vm_t map_fill_region(struct vmem *b, region_callback_t *mem_handler,
pm_t offset, vm_t start, size_t bytes, vmflags_t flags,
void *data);
diff --git a/include/apos/proc.h b/include/apos/proc.h
index e1ea7b6..238e0f6 100644
--- a/include/apos/proc.h
+++ b/include/apos/proc.h
@@ -5,6 +5,6 @@
#include <apos/vmem.h>
stat_t jump_to_userspace(struct tcb *t, int argc, char **argv);
-stat_t init_proc(void *fdt, struct vm_branch *b);
+stat_t init_proc(void *fdt, struct vmem *b);
#endif /* APOS_PROC_H */
diff --git a/include/apos/tcb.h b/include/apos/tcb.h
index f31bf77..439a3c9 100644
--- a/include/apos/tcb.h
+++ b/include/apos/tcb.h
@@ -37,7 +37,7 @@ struct tcb {
vm_t entry;
/* vm root branch */
- struct vm_branch *b_r;
+ struct vmem *b_r;
/* linked list of threads in this process */
struct tcb *next;
diff --git a/include/apos/vmem.h b/include/apos/vmem.h
index 036780f..d55e249 100644
--- a/include/apos/vmem.h
+++ b/include/apos/vmem.h
@@ -16,11 +16,11 @@ stat_t free_uvmem(struct tcb *r, vm_t a);
stat_t init_uvmem(struct tcb *r, vm_t base, vm_t top);
stat_t destroy_uvmem(struct tcb *r);
-stat_t alloc_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t alloc_uvmem_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data);
-stat_t alloc_shared_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t alloc_shared_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data);
-stat_t free_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr,
+stat_t free_uvmem_wrapper(struct vmem *b, pm_t *offset, vm_t vaddr,
vmflags_t flags, enum mm_order order, void *data);
#define map_allocd_region(b, start, bytes, flags, data) \
diff --git a/include/arch/vmem.h b/include/arch/vmem.h
index 5197c67..03bffb3 100644
--- a/include/arch/vmem.h
+++ b/include/arch/vmem.h
@@ -3,28 +3,27 @@
#include <vmem.h>
-stat_t map_vpage(struct vm_branch *branch, pm_t paddr, vm_t vaddr,
- vmflags_t flags, enum mm_order order);
+stat_t map_vpage(struct vmem *branch, pm_t paddr, vm_t vaddr, vmflags_t flags,
+ enum mm_order order);
-stat_t unmap_vpage(struct vm_branch *branch, vm_t vaddr);
+stat_t unmap_vpage(struct vmem *branch, vm_t vaddr);
-stat_t mod_vpage(struct vm_branch *branch, vm_t vaddr, pm_t paddr,
- vmflags_t flags);
-stat_t stat_vpage(struct vm_branch *branch, vm_t vaddr, pm_t *paddr,
+stat_t mod_vpage(struct vmem *branch, vm_t vaddr, pm_t paddr, vmflags_t flags);
+stat_t stat_vpage(struct vmem *branch, vm_t vaddr, pm_t *paddr,
enum mm_order *order, vmflags_t *flags);
void flush_tlb();
void flush_tlb_all();
-stat_t populate_kvmem(struct vm_branch *b);
-struct vm_branch *init_vmem(void *fdt);
+stat_t populate_kvmem(struct vmem *b);
+struct vmem *init_vmem(void *fdt);
#if defined(DEBUG)
-vm_t setup_kernel_io(struct vm_branch *b, vm_t paddr);
+vm_t setup_kernel_io(struct vmem *b, vm_t paddr);
#endif
-struct vm_branch *create_vmem();
-stat_t destroy_vmem(struct vm_branch *);
-stat_t clone_uvmem(struct vm_branch *, struct vm_branch *);
+struct vmem *create_vmem();
+stat_t destroy_vmem(struct vmem *);
+stat_t clone_uvmem(struct vmem *, struct vmem *);
#endif /* APOS_ARCH_PAGES_H */