Changes in kernel/genarch/src/mm/as_pt.c [af863d0:fdaad75d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/mm/as_pt.c
raf863d0 rfdaad75d 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Address space functions for 4-level hierarchical pagetables. 36 36 */ 37 37 … … 43 43 #include <arch/mm/page.h> 44 44 #include <arch/mm/as.h> 45 #include < arch/types.h>45 #include <typedefs.h> 46 46 #include <memstr.h> 47 47 #include <arch.h> 48 48 49 static pte_t *ptl0_create( int flags);50 static void ptl0_destroy(pte_t * page_table);49 static pte_t *ptl0_create(unsigned int); 50 static void ptl0_destroy(pte_t *); 51 51 52 static void pt_lock(as_t *as, bool lock); 53 static void pt_unlock(as_t *as, bool unlock); 52 static void pt_lock(as_t *, bool); 53 static void pt_unlock(as_t *, bool); 54 static bool pt_locked(as_t *); 54 55 55 56 as_operations_t as_pt_operations = { … … 57 58 .page_table_destroy = ptl0_destroy, 58 59 .page_table_lock = pt_lock, 59 .page_table_unlock = pt_unlock 60 .page_table_unlock = pt_unlock, 61 .page_table_locked = pt_locked, 60 62 }; 61 63 … … 67 69 * 68 70 * @return New PTL0. 71 * 69 72 */ 70 pte_t *ptl0_create( int flags)73 pte_t *ptl0_create(unsigned int flags) 71 74 { 72 pte_t *src_ptl0, *dst_ptl0; 73 ipl_t ipl; 74 int table_size; 75 76 dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE, FRAME_KA); 77 table_size = FRAME_SIZE << PTL0_SIZE; 78 79 if (flags & FLAG_AS_KERNEL) { 75 pte_t *dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE, FRAME_KA); 76 size_t table_size = FRAME_SIZE << PTL0_SIZE; 77 78 if (flags & FLAG_AS_KERNEL) 80 79 memsetb(dst_ptl0, table_size, 0); 81 } else { 82 uintptr_t src, dst; 83 80 else { 84 81 /* 85 82 * Copy the kernel address space portion to new PTL0. 83 * 86 84 */ 87 88 ipl = interrupts_disable(); 89 mutex_lock(&AS_KERNEL->lock); 90 src_ptl0 = (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table); 91 92 src = (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)]; 93 dst = (uintptr_t) &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)]; 94 85 86 mutex_lock(&AS_KERNEL->lock); 87 88 pte_t *src_ptl0 = 89 (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table); 90 91 uintptr_t src = 92 (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)]; 93 uintptr_t dst = 94 (uintptr_t) &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)]; 95 95 96 memsetb(dst_ptl0, table_size, 0); 96 memcpy((void *) dst, (void *) src, table_size - (src - (uintptr_t) src_ptl0)); 97 memcpy((void *) dst, (void *) src, 98 table_size - (src - (uintptr_t) src_ptl0)); 99 97 100 mutex_unlock(&AS_KERNEL->lock); 98 interrupts_restore(ipl);99 101 } 100 102 101 103 return (pte_t *) KA2PA((uintptr_t) dst_ptl0); 102 104 } … … 107 109 * 108 110 * @param page_table Physical address of PTL0. 111 * 109 112 */ 110 113 void ptl0_destroy(pte_t *page_table) 111 114 { 112 frame_free((uintptr_t) page_table);115 frame_free((uintptr_t) page_table); 113 116 } 114 117 … … 118 121 * Interrupts must be disabled. 119 122 * 120 * @param as Address space.123 * @param as Address space. 121 124 * @param lock If false, do not attempt to lock the address space. 125 * 122 126 */ 123 127 void pt_lock(as_t *as, bool lock) … … 132 136 * Interrupts must be disabled. 133 137 * 134 * @param as Address space.138 * @param as Address space. 135 139 * @param unlock If false, do not attempt to unlock the address space. 140 * 136 141 */ 137 142 void pt_unlock(as_t *as, bool unlock) … … 141 146 } 142 147 148 /** Test whether page tables are locked. 149 * 150 * @param as Address space where the page tables belong. 151 * 152 * @return True if the page tables belonging to the address soace 153 * are locked, otherwise false. 154 */ 155 bool pt_locked(as_t *as) 156 { 157 return mutex_locked(&as->lock); 158 } 159 143 160 /** @} 144 161 */
Note:
See TracChangeset
for help on using the changeset viewer.