Changes in kernel/genarch/src/mm/page_ht.c [fdaad75d:d99c1d2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/mm/page_ht.c
rfdaad75d rd99c1d2 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Virtual Address Translation (VAT) for global page hash table. 36 36 */ 37 37 … … 52 52 #include <align.h> 53 53 54 static size_t hash(unative_t[]); 55 static bool compare(unative_t[], size_t, link_t *); 56 static void remove_callback(link_t *); 57 58 static void ht_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int); 59 static void ht_mapping_remove(as_t *, uintptr_t); 60 static pte_t *ht_mapping_find(as_t *, uintptr_t); 54 static size_t hash(unative_t key[]); 55 static bool compare(unative_t key[], size_t keys, link_t *item); 56 static void remove_callback(link_t *item); 57 58 static void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, 59 int flags); 60 static void ht_mapping_remove(as_t *as, uintptr_t page); 61 static pte_t *ht_mapping_find(as_t *as, uintptr_t page); 61 62 62 63 /** … … 64 65 * after address space lock and after any address space area 65 66 * locks. 66 *67 67 */ 68 68 mutex_t page_ht_lock; 69 69 70 /** Page hash table.71 * 70 /** 71 * Page hash table. 72 72 * The page hash table may be accessed only when page_ht_lock is held. 73 *74 73 */ 75 74 hash_table_t page_ht; … … 94 93 * 95 94 * @return Index into page hash table. 96 *97 95 */ 98 96 size_t hash(unative_t key[]) … … 100 98 as_t *as = (as_t *) key[KEY_AS]; 101 99 uintptr_t page = (uintptr_t) key[KEY_PAGE]; 100 size_t index; 102 101 103 102 /* … … 105 104 * of occurring. Least significant bits of VPN compose the 106 105 * hash index. 107 * 108 */ 109 size_t index = ((page >> PAGE_WIDTH) & (PAGE_HT_ENTRIES - 1)); 106 */ 107 index = ((page >> PAGE_WIDTH) & (PAGE_HT_ENTRIES - 1)); 110 108 111 109 /* … … 113 111 * similar addresses. Least significant bits compose the 114 112 * hash index. 115 *116 113 */ 117 114 index |= ((unative_t) as) & (PAGE_HT_ENTRIES - 1); … … 122 119 /** Compare page hash table item with page and/or address space. 123 120 * 124 * @param key 121 * @param key Array of one or two keys (i.e. page and/or address space). 125 122 * @param keys Number of keys passed. 126 123 * @param item Item to compare the keys with. 127 124 * 128 125 * @return true on match, false otherwise. 129 *130 126 */ 131 127 bool compare(unative_t key[], size_t keys, link_t *item) 132 128 { 129 pte_t *t; 130 133 131 ASSERT(item); 134 ASSERT(keys > 0); 135 ASSERT(keys <= PAGE_HT_KEYS); 136 132 ASSERT((keys > 0) && (keys <= PAGE_HT_KEYS)); 133 137 134 /* 138 135 * Convert item to PTE. 139 * 140 */141 pte_t *pte = hash_table_get_instance(item, pte_t, link); 142 143 if (keys == PAGE_HT_KEYS)144 return (key[KEY_AS] == (uintptr_t) pte->as) &&145 (key[KEY_PAGE] == pte->page);146 147 return (key[KEY_AS] == (uintptr_t) pte->as);136 */ 137 t = hash_table_get_instance(item, pte_t, link); 138 139 if (keys == PAGE_HT_KEYS) { 140 return (key[KEY_AS] == (uintptr_t) t->as) && 141 (key[KEY_PAGE] == t->page); 142 } else { 143 return (key[KEY_AS] == (uintptr_t) t->as); 144 } 148 145 } 149 146 … … 151 148 * 152 149 * @param item Page hash table item being removed. 153 *154 150 */ 155 151 void remove_callback(link_t *item) 156 152 { 153 pte_t *t; 154 157 155 ASSERT(item); 158 156 159 157 /* 160 158 * Convert item to PTE. 161 * 162 */ 163 pte_t *pte = hash_table_get_instance(item, pte_t, link); 164 165 free(pte); 159 */ 160 t = hash_table_get_instance(item, pte_t, link); 161 162 free(t); 166 163 } 167 164 … … 169 166 * 170 167 * Map virtual address page to physical address frame 171 * using flags. 172 * 173 * @param as Address space to which page belongs. 174 * @param page Virtual address of the page to be mapped. 168 * using flags. 169 * 170 * The page table must be locked and interrupts must be disabled. 171 * 172 * @param as Address space to which page belongs. 173 * @param page Virtual address of the page to be mapped. 175 174 * @param frame Physical address of memory frame to which the mapping is done. 176 175 * @param flags Flags to be used for mapping. 177 * 178 */ 179 void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, 180 unsigned int flags) 181 { 176 */ 177 void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags) 178 { 179 pte_t *t; 182 180 unative_t key[2] = { 183 181 (uintptr_t) as, 184 182 page = ALIGN_DOWN(page, PAGE_SIZE) 185 183 }; 186 187 ASSERT(page_table_locked(as));188 184 189 185 if (!hash_table_find(&page_ht, key)) { 190 pte_t *pte= (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);191 ASSERT( pte!= NULL);192 193 pte->g = (flags & PAGE_GLOBAL) != 0;194 pte->x = (flags & PAGE_EXEC) != 0;195 pte->w = (flags & PAGE_WRITE) != 0;196 pte->k = !(flags & PAGE_USER);197 pte->c = (flags & PAGE_CACHEABLE) != 0;198 pte->p = !(flags & PAGE_NOT_PRESENT);199 pte->a = false;200 pte->d = false;201 202 pte->as = as;203 pte->page = ALIGN_DOWN(page, PAGE_SIZE);204 pte->frame = ALIGN_DOWN(frame, FRAME_SIZE);205 206 hash_table_insert(&page_ht, key, & pte->link);186 t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC); 187 ASSERT(t != NULL); 188 189 t->g = (flags & PAGE_GLOBAL) != 0; 190 t->x = (flags & PAGE_EXEC) != 0; 191 t->w = (flags & PAGE_WRITE) != 0; 192 t->k = !(flags & PAGE_USER); 193 t->c = (flags & PAGE_CACHEABLE) != 0; 194 t->p = !(flags & PAGE_NOT_PRESENT); 195 t->a = false; 196 t->d = false; 197 198 t->as = as; 199 t->page = ALIGN_DOWN(page, PAGE_SIZE); 200 t->frame = ALIGN_DOWN(frame, FRAME_SIZE); 201 202 hash_table_insert(&page_ht, key, &t->link); 207 203 } 208 204 } … … 214 210 * this call visible. 215 211 * 216 * @param as Address space to wich page belongs. 212 * The page table must be locked and interrupts must be disabled. 213 * 214 * @param as Address space to wich page belongs. 217 215 * @param page Virtual address of the page to be demapped. 218 *219 216 */ 220 217 void ht_mapping_remove(as_t *as, uintptr_t page) … … 224 221 page = ALIGN_DOWN(page, PAGE_SIZE) 225 222 }; 226 227 ASSERT(page_table_locked(as));228 223 229 224 /* … … 239 234 * Find mapping for virtual page. 240 235 * 241 * @param as Address space to wich page belongs. 236 * The page table must be locked and interrupts must be disabled. 237 * 238 * @param as Address space to wich page belongs. 242 239 * @param page Virtual page. 243 240 * 244 241 * @return NULL if there is no such mapping; requested mapping otherwise. 245 *246 242 */ 247 243 pte_t *ht_mapping_find(as_t *as, uintptr_t page) 248 244 { 245 link_t *hlp; 246 pte_t *t = NULL; 249 247 unative_t key[2] = { 250 248 (uintptr_t) as, 251 249 page = ALIGN_DOWN(page, PAGE_SIZE) 252 250 }; 253 254 ASSERT(page_table_locked(as)); 255 256 link_t *cur = hash_table_find(&page_ht, key); 257 if (cur) 258 return hash_table_get_instance(cur, pte_t, link); 259 260 return NULL; 251 252 hlp = hash_table_find(&page_ht, key); 253 if (hlp) 254 t = hash_table_get_instance(hlp, pte_t, link); 255 256 return t; 261 257 } 262 258
Note:
See TracChangeset
for help on using the changeset viewer.