aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/apos/dev.h16
-rw-r--r--include/apos/dmem.h19
-rw-r--r--include/apos/mem.h24
-rw-r--r--include/apos/mem_regions.h36
-rw-r--r--include/apos/pmem.h17
-rw-r--r--include/apos/tcb.h16
-rw-r--r--include/apos/types.h17
-rw-r--r--include/apos/vmem.h78
-rw-r--r--include/arch/arch.h (renamed from include/apos/arch.h)2
-rw-r--r--include/arch/cpu.h (renamed from include/apos/cpu.h)3
-rw-r--r--include/arch/irq.h (renamed from include/apos/irq.h)0
-rw-r--r--include/arch/vmem.h22
12 files changed, 134 insertions, 116 deletions
diff --git a/include/apos/dev.h b/include/apos/dev.h
deleted file mode 100644
index 1e710a1..0000000
--- a/include/apos/dev.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef APOS_DEV_H
-#define APOS_DEV_H
-
-#include <apos/types.h>
-#include <apos/vmem.h>
-
-extern pm_t __pre_base;
-extern pm_t __pre_top;
-extern pm_t __post_base;
-extern pm_t __post_top;
-
-void init_devmem(pm_t ram_base, pm_t ram_top);
-vm_t alloc_devmem(struct tcb *t, pm_t dev_start, size_t bytes, uint8_t flags);
-void free_devmem(struct tcb *t, vm_t dev_start);
-
-#endif /* APOS_DEV_H */
diff --git a/include/apos/dmem.h b/include/apos/dmem.h
new file mode 100644
index 0000000..936a902
--- /dev/null
+++ b/include/apos/dmem.h
@@ -0,0 +1,19 @@
+#ifndef APOS_DEV_H
+#define APOS_DEV_H
+
+#include <apos/types.h>
+#include <apos/vmem.h>
+
+extern pm_t __pre_base;
+extern pm_t __pre_top;
+extern pm_t __post_base;
+extern pm_t __post_top;
+
+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, uint8_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, uint8_t flags, enum mm_order t);
+stat_t dev_alloc_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, uint8_t flags, enum mm_order t);
+
+#endif /* APOS_DEV_H */
diff --git a/include/apos/mem.h b/include/apos/mem.h
index e935fe4..01edcf6 100644
--- a/include/apos/mem.h
+++ b/include/apos/mem.h
@@ -2,6 +2,7 @@
#define APOS_MEM_H
#include <apos/utils.h>
+#include <apos/types.h>
#include <pages.h>
#define MM_OINFO_WIDTH (sizeof(mm_info_t) * 8)
@@ -29,6 +30,14 @@
#define __o_container(idx) ((idx) / MM_OINFO_WIDTH)
#define __o_bit(idx) ((idx) & (MM_OINFO_WIDTH - 1))
+#define __va(x) (((char *)(x)) + VM_DMAP - RAM_BASE)
+#define __pa(x) (((char *)(x)) + RAM_BASE - VM_DMAP)
+#define __page(x) ((x) / BASE_PAGE_SIZE)
+#define __addr(x) ((x) * BASE_PAGE_SIZE)
+#define __pages(x) (aligned((x), BASE_PAGE_SIZE) ? __page((x)) : __page((x) + BASE_PAGE_SIZE))
+#define __bytes(x) (__addr(x))
+
+
extern size_t __mm_shifts[10];
extern size_t __mm_widths[10];
extern size_t __mm_sizes[10];
@@ -36,6 +45,21 @@ extern size_t __mm_sizes[10];
extern size_t __mm_page_shift;
extern size_t __mm_max_order;
+#define ORDERS_NUM 10
+enum mm_order {
+ MM_O0,
+ MM_O1,
+ MM_O2,
+ MM_O3,
+ MM_O4,
+ MM_O5,
+ MM_O6,
+ MM_O7,
+ MM_O8,
+ MM_O9,
+};
+
+typedef ssize_t pnum_t;
void init_mem(size_t max_order, size_t shifts[10], size_t page_shift);
enum mm_mode get_mmode(void *fdt);
diff --git a/include/apos/mem_regions.h b/include/apos/mem_regions.h
new file mode 100644
index 0000000..eb81e63
--- /dev/null
+++ b/include/apos/mem_regions.h
@@ -0,0 +1,36 @@
+#ifndef APOS_MEM_REGIONS_H
+#define APOS_MEM_REGIONS_H
+
+#include <apos/types.h>
+#include <apos/sp_tree.h>
+
+#define mem_container(ptr)\
+ container_of(ptr, struct sp_mem, sp_n)
+
+struct sp_reg_root {
+ struct sp_root free_regions;
+ struct sp_root used_regions;
+};
+
+struct sp_mem {
+ struct sp_node sp_n;
+
+ struct sp_mem *next;
+ struct sp_mem *prev;
+
+ char flags;
+
+ vm_t end;
+ vm_t start;
+};
+
+stat_t sp_mem_init(struct sp_reg_root *r, vm_t start, size_t arena_size);
+vm_t alloc_region(struct sp_reg_root *r, size_t size, size_t *actual_size);
+vm_t alloc_fixed_region(struct sp_reg_root *r, vm_t start, size_t size, size_t *actual_size);
+stat_t free_region(struct sp_reg_root *r, vm_t start);
+
+struct sp_mem *sp_used_find(struct sp_reg_root *r, vm_t start);
+struct sp_mem *sp_find_used_closest(struct sp_reg_root *r, vm_t start);
+struct sp_mem *sp_find_free(struct sp_reg_root *r, size_t size, size_t *align);
+
+#endif /* APOS_MEM_REGIONS_H */
diff --git a/include/apos/pmem.h b/include/apos/pmem.h
index 2850f22..0f58e1c 100644
--- a/include/apos/pmem.h
+++ b/include/apos/pmem.h
@@ -4,23 +4,6 @@
#include <apos/mem.h>
#include <apos/types.h>
-#define ORDERS_NUM 10
-enum mm_order {
- MM_O0,
- MM_O1,
- MM_O2,
- MM_O3,
- MM_O4,
- MM_O5,
- MM_O6,
- MM_O7,
- MM_O8,
- MM_O9,
-};
-
-typedef size_t pm_t;
-typedef ssize_t pnum_t;
-
/* arch */
int arch_pmem_conf(void *fdt, size_t *max_order, size_t *base_bits, size_t bits[ORDERS_NUM]);
diff --git a/include/apos/tcb.h b/include/apos/tcb.h
index 0a07d7b..4872bd0 100644
--- a/include/apos/tcb.h
+++ b/include/apos/tcb.h
@@ -1,21 +1,9 @@
#ifndef APOS_TCB_H
#define APOS_TCB_H
-struct tcb;
-struct sp_reg_root;
-
-#include <tcb.h>
-#include <vmem.h>
-#include <apos/vmem.h>
+#include <apos/mem_regions.h>
#include <apos/types.h>
-#include <apos/sp_tree.h>
-
-typedef size_t id_t;
-
-struct sp_reg_root {
- struct sp_root free_regions;
- struct sp_root used_regions;
-};
+#include <tcb.h> /* arch-specific data */
struct tcb {
struct sp_node sp_n;
diff --git a/include/apos/types.h b/include/apos/types.h
index 7cc4e28..7d690de 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -175,4 +175,21 @@ typedef intmax_t ssize_t;
#define NULL 0
+/* some common types used throughout the kernel */
+typedef int_fast8_t stat_t;
+typedef uint_fast32_t id_t;
+typedef uint_fast8_t mflags_t;
+
+/* error types (should this go somewhere else? */
+/* negative error codes are reserved for general usage, positive error codes are
+ * allowed to be function-specific. */
+enum {
+ ERR_ADDR = -3, /* illegal address */
+ ERR_ALIGN = -2, /* wrong alignment */
+ ERR_NF = -1, /* not found */
+ OK = 0, /* OK */
+};
+
+#include <types.h> /* arch-specific type definitions (pm_t/vm_t etc) */
+
#endif /* APOS_TYPES_H */
diff --git a/include/apos/vmem.h b/include/apos/vmem.h
index 8057631..bd6b89e 100644
--- a/include/apos/vmem.h
+++ b/include/apos/vmem.h
@@ -1,89 +1,31 @@
#ifndef APOS_VMEM_H
#define APOS_VMEM_H
-struct sp_mem;
-
-/* arch-specific data */
-#include <vmem.h>
-
-/* common */
-#include <apos/pmem.h>
#include <apos/tcb.h>
+#include <apos/pmem.h>
#include <apos/sp_tree.h>
-
-struct sp_mem {
- struct sp_node sp_n;
-
- struct sp_mem *next;
- struct sp_mem *prev;
-
- char flags;
-
- vm_t end;
- vm_t start;
-};
-
-#define mem_container(ptr)\
- container_of(ptr, struct sp_mem, sp_n)
-
-#define __va(x) (((char *)(x)) + VM_DMAP - RAM_BASE)
-#define __pa(x) (((char *)(x)) + RAM_BASE - VM_DMAP)
-#define __page(x) ((x) / BASE_PAGE_SIZE)
-#define __addr(x) ((x) * BASE_PAGE_SIZE)
-#define __pages(x) (aligned((x), BASE_PAGE_SIZE) ? __page((x)) : __page((x) + BASE_PAGE_SIZE))
-#define __bytes(x) (__addr(x))
-
-/* general overview of the different functions:
- * internally they all work with pages, but they are called and return usable
- * addresses, though within page bounds of course.
- */
-
-/* defined by arch */
-void map_vmem(struct vm_branch *branch,
- pm_t paddr, vm_t vaddr, uint8_t flags, enum mm_order order);
-
-void unmap_vmem(struct vm_branch *branch, vm_t vaddr);
-
-int mod_vmem(struct vm_branch *branch, vm_t vaddr, pm_t paddr, uint8_t flags);
-int stat_vmem(struct vm_branch *branch, vm_t vaddr, pm_t *paddr,
- enum mm_order *order, uint8_t *flags);
-
-int setup_kernel_io(struct vm_branch *b, vm_t paddr);
-void populate_root_branch(struct vm_branch *b);
-struct vm_branch *init_vmem(void *fdt);
-
-void flush_tlb();
-void flush_tlb_all();
-
-/* defined in common */
-
-int sp_mem_init(struct sp_reg_root *r, vm_t start, size_t nums);
-
-vm_t alloc_region(struct sp_reg_root *r, size_t size, size_t *actual_size);
-vm_t alloc_fixed_region(struct sp_reg_root *r, vm_t start, size_t size, size_t *actual_size);
-void free_region(struct sp_reg_root *r, vm_t start);
+#include <arch/vmem.h>
vm_t alloc_uvmem(struct tcb *r, size_t size, uint8_t flags);
vm_t alloc_fixed_uvmem(struct tcb *r, vm_t start, size_t size, uint8_t flags);
-void free_uvmem(struct tcb *r, vm_t a);
+
+stat_t free_uvmem(struct tcb *r, vm_t a);
+stat_t init_uvmem(struct tcb *r, vm_t base, vm_t top);
vm_t map_fill_region(struct vm_branch *b,
int (*vmem_handler)(struct vm_branch *, pm_t *, vm_t, uint8_t, enum mm_order),
pm_t offset, vm_t start, size_t bytes, uint8_t flags);
+stat_t alloc_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, uint8_t flags, enum mm_order order);
+stat_t free_uvmem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, uint8_t flags, enum mm_order order);
+
#define map_allocd_region(b, start, bytes, flags)\
- map_fill_region(b, &alloc_mem_wrapper, 0, start, bytes, flags)
+ map_fill_region(b, &alloc_uvmem_wrapper, 0, start, bytes, flags)
#define unmap_freed_region(b, start, bytes)\
- map_fill_region(b, &free_mem_wrapper, 0, start, bytes, 0)
-
-int alloc_mem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, uint8_t flags, enum mm_order order);
-int free_mem_wrapper(struct vm_branch *b, pm_t *offset, vm_t vaddr, uint8_t flags, enum mm_order order);
+ map_fill_region(b, &free_uvmem_wrapper, 0, start, bytes, 0)
size_t uvmem_size();
void set_uvmem_size(size_t s);
-/* not entirely sure if this is clean enough, but it'll do for now. */
-struct sp_mem *sp_used_find(struct sp_reg_root *r, vm_t start);
-
#endif /* APOS_VMEM_H */
diff --git a/include/apos/arch.h b/include/arch/arch.h
index b846876..1933555 100644
--- a/include/apos/arch.h
+++ b/include/arch/arch.h
@@ -1,6 +1,8 @@
#ifndef APOS_ARCH_H
#define APOS_ARCH_H
+/* functions that an arch has to provide */
+
void arch_setup(void *fdt);
#endif /* APOS_ARCH_H */
diff --git a/include/apos/cpu.h b/include/arch/cpu.h
index 81fb07e..c53a4d6 100644
--- a/include/apos/cpu.h
+++ b/include/arch/cpu.h
@@ -1,7 +1,8 @@
#ifndef APOS_CPU_H
#define APOS_CPU_H
-#include <apos/tcb.h>
+#include <apos/types.h>
+#include <cpu.h>
id_t cpu_id();
/* TODO: add more cpu handling functions */
diff --git a/include/apos/irq.h b/include/arch/irq.h
index 3ce6556..3ce6556 100644
--- a/include/apos/irq.h
+++ b/include/arch/irq.h
diff --git a/include/arch/vmem.h b/include/arch/vmem.h
new file mode 100644
index 0000000..8aec154
--- /dev/null
+++ b/include/arch/vmem.h
@@ -0,0 +1,22 @@
+#ifndef APOS_ARCH_PAGES_H
+#define APOS_ARCH_PAGES_H
+
+#include <vmem.h>
+
+void map_vmem(struct vm_branch *branch,
+ pm_t paddr, vm_t vaddr, uint8_t flags, enum mm_order order);
+
+void unmap_vmem(struct vm_branch *branch, vm_t vaddr);
+
+int mod_vmem(struct vm_branch *branch, vm_t vaddr, pm_t paddr, uint8_t flags);
+int stat_vmem(struct vm_branch *branch, vm_t vaddr, pm_t *paddr,
+ enum mm_order *order, uint8_t *flags);
+
+void flush_tlb();
+void flush_tlb_all();
+
+void populate_root_branch(struct vm_branch *b);
+int setup_kernel_io(struct vm_branch *b, vm_t paddr);
+struct vm_branch *init_vmem(void *fdt);
+
+#endif /* APOS_ARCH_PAGES_H */