summaryrefslogtreecommitdiffstats
path: root/mem/memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'mem/memory.h')
-rw-r--r--mem/memory.h72
1 files changed, 53 insertions, 19 deletions
diff --git a/mem/memory.h b/mem/memory.h
index 41323ed..251c6f5 100644
--- a/mem/memory.h
+++ b/mem/memory.h
@@ -1,36 +1,61 @@
#ifndef JOVE_MEM_H
#define JOVE_MEM_H 1
-#define PAGESIZE 4096ULL
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1 << PAGE_SHIFT)
+#define PAGE_MASK (PAGE_SIZE - 1)
+
#define KiB 1024ULL
#define MiB (KiB * KiB)
#define GiB (MiB * KiB)
#define TiB (GiB * KiB)
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-typedef uintptr_t physptr_t;
+#include "lib/spinlock.h"
+#include "sys/types.h"
+
+typedef struct page_directory
+{
+ spinlock_t lock;
+ size_t id;
+ size_t ref;
+ physptr_t phys;
+ void *virt;
+} page_directory_t;
#include "slab.h"
-/*Linear*/
-void mem_paging_setup(void);
+extern page_directory_t *current_page_directory;
-physptr_t mem_linear_tophys(uintptr_t virt);
+/**Setup the kernel structures responsible for handling physical memory translation.*/
+void mem_paging_setup(void);
-/**Check if pointer is within valid memory.
+/**Check if a given pointer is valid.
* @param ptr pointer to check.
- * @return if the pointer is invalid.*/
+ * @return if the pointer is valid.*/
bool mem_check_ptr(const void *ptr);
-/**Make sure the range indicated is available in memory.
- * If necessary, allocate new pages using the passed flags
- * @param from start of the range.
- * @param to end of the range.
- * @param rw flag to mark page is writeable.
- * @param user flag to mark page as user accessable*/
-void mem_ensure_range(uintptr_t from, uintptr_t to, bool rw, bool user);
+/** Return the physical memory mapping for the given address.
+ * @param pd page directory to get mapping in.
+ * @param addr address to get mapping for.
+ * @return HAL compliant page mapping.*/
+page_mapping_t mem_get_mapping_as(page_directory_t *pd, uintptr_t addr);
+
+/** Return the physical memory mapping for the given address.
+ * @param addr address to get mapping for.
+ * @return HAL compliant page mapping.*/
+page_mapping_t mem_get_mapping(uintptr_t addr);
+
+/** Map a page mapping to a given virtual address.
+ * @param pd pointer to the page directory to edit.
+ * @param mapping mapping to apply.
+ * @param virt virtual address to map to. */
+void mem_set_mapping_as(page_directory_t *pd, page_mapping_t mapping, uintptr_t virt);
+
+/** Map a page mapping to a given virtual address.
+ * @param pd pointer to the page directory to edit.
+ * @param mapping mapping to apply.
+ * @param virt virtual address to map to. */
+void mem_set_mapping(page_mapping_t mapping, uintptr_t virt);
/** Make sure the range indicated is available in memory for specified pd
* If necessary, allocate new pages using the passed flags
@@ -39,7 +64,15 @@ void mem_ensure_range(uintptr_t from, uintptr_t to, bool rw, bool user);
* @param to end of the range
* @param rw flag to mark page is writeable
* @param user flag to mark page as user accessable*/
-void mem_ensure_range_for(void *pd, uintptr_t from, uintptr_t to, bool rw, bool user);
+void mem_ensure_range_as(page_directory_t *pd, uintptr_t from, uintptr_t to, page_flags_t flg);
+
+/**Make sure the range indicated is available in memory
+ * If necessary, allocate new pages using the passed flags
+ * @param from start of the range.
+ * @param to end of the range.
+ * @param rw flag to mark page is writeable.
+ * @param user flag to mark page as user accessable*/
+void mem_ensure_range(uintptr_t from, uintptr_t to, page_flags_t flg);
void mem_slab_setup(void);
void mem_slabcache_new(struct SlabCache *cache, char *name, size_t objsize);
@@ -53,7 +86,8 @@ void mem_free(void *ptr);
/*Physical*/
physptr_t mem_phys_alloc(size_t pages);
-void mem_phys_reserve(physptr_t start, size_t len);
+void mem_phys_reserve(physptr_t start, physptr_t end);
+void mem_phys_release(physptr_t start, physptr_t end);
void mem_setup(void);