aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv/include
diff options
context:
space:
mode:
Diffstat (limited to 'arch/riscv/include')
-rw-r--r--arch/riscv/include/csr.h18
-rw-r--r--arch/riscv/include/pages.h6
-rw-r--r--arch/riscv/include/vmap.h15
-rw-r--r--arch/riscv/include/vmem.h29
4 files changed, 47 insertions, 21 deletions
diff --git a/arch/riscv/include/csr.h b/arch/riscv/include/csr.h
index 694000b..5da0882 100644
--- a/arch/riscv/include/csr.h
+++ b/arch/riscv/include/csr.h
@@ -1,8 +1,22 @@
#ifndef APOS_CSR_H
#define APOS_CSR_H
-#define csr_write(csr, val)
-
#define SATP_MODE_39 0x8000000000000000
+#define SATP_MODE_48 0x9000000000000000
+
+#define CSR_SATP 0x180
+
+/* directly lifted from Linux:/arch/riscv/include/asm/asm.h:9-13 */
+#ifdef __ASSEMBLY__
+#define __ASM_STR(x) x
+#else
+#define __ASM_STR(x) #x
+#endif
+
+#define csr_read(csr, res)\
+ __asm__ ("csrr %0, " __ASM_STR(csr) : "=r" (res) : : "memory")
+
+#define csr_write(csr, val)\
+ __asm__ ("csrw " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory")
#endif /* APOS_CSR_H */
diff --git a/arch/riscv/include/pages.h b/arch/riscv/include/pages.h
index 82ce6c7..8ca396a 100644
--- a/arch/riscv/include/pages.h
+++ b/arch/riscv/include/pages.h
@@ -2,10 +2,6 @@
#define APOS_RISCV_PAGES_H
#include <apos/types.h>
-#include <apos/pmem.h>
-
-/* assume riscv64 for now */
-typedef uint64_t pm_t;
#define MM_KPAGE MM_O0
#define MM_MPAGE MM_O1
@@ -17,4 +13,6 @@ typedef uint64_t pm_t;
#define MM_GPAGE_SIZE SZ_1G
#define MM_TPAGE_SIZE SZ_512G
+typedef uint64_t paddr_t;
+
#endif /* APOS_RISCV_PAGES_H */
diff --git a/arch/riscv/include/vmap.h b/arch/riscv/include/vmap.h
deleted file mode 100644
index aee3725..0000000
--- a/arch/riscv/include/vmap.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef APOS_RISCV_VMAP_H
-#define APOS_RISCV_VMAP_H
-
-#include <apos/sizes.h>
-
-#define VM_V (1 << 0)
-#define VM_R (1 << 1)
-#define VM_W (1 << 2)
-#define VM_X (1 << 3)
-#define VM_U (1 << 4)
-#define VM_G (1 << 5)
-#define VM_A (1 << 6)
-#define VM_D (1 << 7)
-
-#endif /* APOS_RISCV_VMAP_H */
diff --git a/arch/riscv/include/vmem.h b/arch/riscv/include/vmem.h
new file mode 100644
index 0000000..3c27c7b
--- /dev/null
+++ b/arch/riscv/include/vmem.h
@@ -0,0 +1,29 @@
+#ifndef APOS_RISCV_VMAP_H
+#define APOS_RISCV_VMAP_H
+
+#include <apos/sizes.h>
+#include <apos/types.h>
+#include <apos/attrs.h>
+
+#define VM_V (1 << 0)
+#define VM_R (1 << 1)
+#define VM_W (1 << 2)
+#define VM_X (1 << 3)
+#define VM_U (1 << 4)
+#define VM_G (1 << 5)
+#define VM_A (1 << 6)
+#define VM_D (1 << 7)
+
+typedef size_t vaddr_t;
+struct __packed vm_branch_t {
+ struct vm_branch_t *leaf[512];
+};
+
+void map_vmem(struct vm_branch_t *branch,
+ paddr_t paddr, vaddr_t vaddr,
+ uint8_t flags, enum mm_order_t order);
+
+void unmap_vmem(struct vm_branch_t *branch, vaddr_t vaddr, enum mm_order_t order);
+
+
+#endif /* APOS_RISCV_VMAP_H */