1 /* 2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. 3 ** Distributed under the terms of the NewOS License. 4 */ 5 #ifndef _NEWOS_KERNEL_ARCH_VM_TRANSLATION_MAP_H 6 #define _NEWOS_KERNEL_ARCH_VM_TRANSLATION_MAP_H 7 8 #include <kernel.h> 9 #include <stage2.h> 10 #include <lock.h> 11 12 typedef struct vm_translation_map_struct { 13 struct vm_translation_map_struct *next; 14 struct vm_translation_map_ops_struct *ops; 15 recursive_lock lock; 16 int map_count; 17 struct vm_translation_map_arch_info_struct *arch_data; 18 } vm_translation_map; 19 20 // table of operations the vm may want to do to this mapping 21 typedef struct vm_translation_map_ops_struct { 22 void (*destroy)(vm_translation_map *); 23 int (*lock)(vm_translation_map*); 24 int (*unlock)(vm_translation_map*); 25 int (*map)(vm_translation_map *map, addr va, addr pa, unsigned int attributes); 26 int (*unmap)(vm_translation_map *map, addr start, addr end); 27 int (*query)(vm_translation_map *map, addr va, addr *out_physical, unsigned int *out_flags); 28 addr (*get_mapped_size)(vm_translation_map*); 29 int (*protect)(vm_translation_map *map, addr base, addr top, unsigned int attributes); 30 int (*clear_flags)(vm_translation_map *map, addr va, unsigned int flags); 31 void (*flush)(vm_translation_map *map); 32 int (*get_physical_page)(addr physical_address, addr *out_virtual_address, int flags); 33 int (*put_physical_page)(addr virtual_address); 34 } vm_translation_map_ops; 35 36 int vm_translation_map_create(vm_translation_map *new_map, bool kernel); 37 int vm_translation_map_module_init(kernel_args *ka); 38 int vm_translation_map_module_init2(kernel_args *ka); 39 void vm_translation_map_module_init_post_sem(kernel_args *ka); 40 // quick function to map a page in regardless of map context. Used in VM initialization, 41 // before most vm data structures exist 42 int vm_translation_map_quick_map(kernel_args *ka, addr va, addr pa, unsigned int attributes, addr (*get_free_page)(kernel_args *)); 43 44 // quick function to return the physical pgdir of a mapping, needed for a context switch 45 addr vm_translation_map_get_pgdir(vm_translation_map *map); 46 47 #endif 48 49