#define ROS_KERN_MM_H
#include <ros/common.h>
+#include <ros/mman.h>
#include <atomic.h>
#include <sys/queue.h>
#include <slab.h>
struct file;
struct proc; /* preprocessor games */
-/* This might turn into a per-process mem management structure. For now, we're
- * using the proc struct. This would have things like the vmr list/tree, cr3,
- * mem usage stats, something with private memory, etc. Not sure if we'll ever
- * need this. */
-struct mm {
- spinlock_t mm_lock;
-};
-
/* Basic structure defining a region of a process's virtual memory. Note we
* don't refcnt these. Either they are in the TAILQ/tree, or they should be
* freed. There should be no other references floating around. We still need
* VMRs. */
struct vm_region {
TAILQ_ENTRY(vm_region) vm_link;
+ TAILQ_ENTRY(vm_region) vm_pm_link;
struct proc *vm_proc; /* owning process, for now */
- //struct mm *vm_mm; /* owning address space */
uintptr_t vm_base;
uintptr_t vm_end;
int vm_prot;
};
TAILQ_HEAD(vmr_tailq, vm_region); /* Declares 'struct vmr_tailq' */
-#include <process.h> /* preprocessor games */
-
/* VM Region Management Functions. For now, these just maintain themselves -
* anything related to mapping needs to be done by the caller. */
void vmr_init(void);
struct vm_region *find_vmr(struct proc *p, uintptr_t va);
struct vm_region *find_first_vmr(struct proc *p, uintptr_t va);
void isolate_vmrs(struct proc *p, uintptr_t va, size_t len);
-void destroy_vmrs(struct proc *p);
-void duplicate_vmrs(struct proc *p, struct proc *new_p);
+void unmap_and_destroy_vmrs(struct proc *p);
+int duplicate_vmrs(struct proc *p, struct proc *new_p);
void print_vmrs(struct proc *p);
/* mmap() related functions. These manipulate VMRs and change the hardware page
* tables. Any requests below the LOWEST_VA will silently be upped. This may
* be a dynamic proc-specific variable later. */
-#define MMAP_LOWEST_VA 0x00001000
+#define MMAP_LOWEST_VA MiB
void *mmap(struct proc *p, uintptr_t addr, size_t len, int prot, int flags,
int fd, size_t offset);
void *do_mmap(struct proc *p, uintptr_t addr, size_t len, int prot, int flags,
int mprotect(struct proc *p, uintptr_t addr, size_t len, int prot);
int munmap(struct proc *p, uintptr_t addr, size_t len);
int handle_page_fault(struct proc *p, uintptr_t va, int prot);
+unsigned long populate_va(struct proc *p, uintptr_t va, unsigned long nr_pgs);
-/* These assume the memory/proc_lock is held already */
-void *__do_mmap(struct proc *p, uintptr_t addr, size_t len, int prot, int flags,
- struct file *f, size_t offset);
+/* These assume the mm_lock is held already */
int __do_mprotect(struct proc *p, uintptr_t addr, size_t len, int prot);
int __do_munmap(struct proc *p, uintptr_t addr, size_t len);
-int __handle_page_fault(struct proc* p, uintptr_t va, int prot);
+
+/* Kernel Dynamic Memory Mappings */
+/* These two are just about reserving VA space */
+uintptr_t get_vmap_segment(unsigned long num_pages);
+uintptr_t put_vmap_segment(uintptr_t vaddr, unsigned long num_pages);
+/* These two are about actually mapping stuff in some reserved space */
+int map_vmap_segment(uintptr_t vaddr, uintptr_t paddr, unsigned long num_pages,
+ int perm);
+int unmap_vmap_segment(uintptr_t vaddr, unsigned long num_pages);
+/* Helper wrappers, since no one will probably call the *_segment funcs */
+uintptr_t vmap_pmem(uintptr_t paddr, size_t nr_bytes);
+uintptr_t vmap_pmem_nocache(uintptr_t paddr, size_t nr_bytes);
+int vunmap_vmem(uintptr_t vaddr, size_t nr_bytes);
#endif /* !ROS_KERN_MM_H */