Changes in kernel/arch/mips32/src/mm/tlb.c [976c434:1dbc43f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/mips32/src/mm/tlb.c
r976c434 r1dbc43f 48 48 #include <symtab.h> 49 49 50 #define VPN_SHIFT 12 51 #define ADDR2VPN(a) ((a) >> VPN_SHIFT) 52 #define ADDR2VPN2(a) (ADDR2VPN((a)) >> 1) 53 #define VPN2ADDR(vpn) ((vpn) << VPN_SHIFT) 54 #define VPN22ADDR(vpn2) (VPN2ADDR(vpn2) << 1) 55 56 #define BANK_SELECT_BIT(a) (((a) >> PAGE_WIDTH) & 1) 57 50 static pte_t *find_mapping_and_check(uintptr_t, int, istate_t *); 58 51 59 52 /** Initialize TLB. … … 91 84 { 92 85 entry_lo_t lo; 86 entry_hi_t hi; 87 asid_t asid; 93 88 uintptr_t badvaddr; 94 89 pte_t *pte; 95 90 96 91 badvaddr = cp0_badvaddr_read(); 97 98 pte = page_mapping_find(AS, badvaddr, true); 99 if (pte && pte->p) { 92 asid = AS->asid; 93 94 pte = find_mapping_and_check(badvaddr, PF_ACCESS_READ, istate); 95 if (pte) { 100 96 /* 101 97 * Record access to PTE. … … 103 99 pte->a = 1; 104 100 101 tlb_prepare_entry_hi(&hi, asid, badvaddr); 105 102 tlb_prepare_entry_lo(&lo, pte->g, pte->p, pte->d, 106 103 pte->cacheable, pte->pfn); … … 109 106 * New entry is to be inserted into TLB 110 107 */ 111 if (BANK_SELECT_BIT(badvaddr) == 0) { 108 cp0_entry_hi_write(hi.value); 109 if ((badvaddr / PAGE_SIZE) % 2 == 0) { 112 110 cp0_entry_lo0_write(lo.value); 113 111 cp0_entry_lo1_write(0); … … 118 116 cp0_pagemask_write(TLB_PAGE_MASK_16K); 119 117 tlbwr(); 120 return; 121 } 122 123 (void) as_page_fault(badvaddr, PF_ACCESS_READ, istate); 118 } 124 119 } 125 120 … … 130 125 void tlb_invalid(istate_t *istate) 131 126 { 132 entry_lo_t lo;133 127 tlb_index_t index; 134 128 uintptr_t badvaddr; 129 entry_lo_t lo; 130 entry_hi_t hi; 135 131 pte_t *pte; 132 133 badvaddr = cp0_badvaddr_read(); 136 134 137 135 /* 138 136 * Locate the faulting entry in TLB. 139 137 */ 138 hi.value = cp0_entry_hi_read(); 139 tlb_prepare_entry_hi(&hi, hi.asid, badvaddr); 140 cp0_entry_hi_write(hi.value); 140 141 tlbp(); 141 142 index.value = cp0_index_read(); 142 143 143 #if defined(PROCESSOR_4Kc)144 /*145 * This can happen on a 4Kc when Status.EXL is 1 and there is a TLB miss.146 * EXL is 1 when interrupts are disabled. The combination of a TLB miss147 * and disabled interrupts is possible in copy_to/from_uspace().148 */149 if (index.p) {150 tlb_refill(istate);151 return;152 }153 #endif154 155 144 ASSERT(!index.p); 156 145 157 badvaddr = cp0_badvaddr_read(); 158 159 pte = page_mapping_find(AS, badvaddr, true); 160 if (pte && pte->p) { 146 pte = find_mapping_and_check(badvaddr, PF_ACCESS_READ, istate); 147 if (pte) { 161 148 /* 162 149 * Read the faulting TLB entry. … … 175 162 * The entry is to be updated in TLB. 176 163 */ 177 if ( BANK_SELECT_BIT(badvaddr)== 0)164 if ((badvaddr / PAGE_SIZE) % 2 == 0) 178 165 cp0_entry_lo0_write(lo.value); 179 166 else 180 167 cp0_entry_lo1_write(lo.value); 168 cp0_pagemask_write(TLB_PAGE_MASK_16K); 181 169 tlbwi(); 182 return; 183 } 184 185 (void) as_page_fault(badvaddr, PF_ACCESS_READ, istate); 170 } 186 171 } 187 172 … … 192 177 void tlb_modified(istate_t *istate) 193 178 { 194 entry_lo_t lo;195 179 tlb_index_t index; 196 180 uintptr_t badvaddr; 181 entry_lo_t lo; 182 entry_hi_t hi; 197 183 pte_t *pte; 184 185 badvaddr = cp0_badvaddr_read(); 198 186 199 187 /* 200 188 * Locate the faulting entry in TLB. 201 189 */ 190 hi.value = cp0_entry_hi_read(); 191 tlb_prepare_entry_hi(&hi, hi.asid, badvaddr); 192 cp0_entry_hi_write(hi.value); 202 193 tlbp(); 203 194 index.value = cp0_index_read(); … … 208 199 ASSERT(!index.p); 209 200 210 badvaddr = cp0_badvaddr_read(); 211 212 pte = page_mapping_find(AS, badvaddr, true); 213 if (pte && pte->p && pte->w) { 201 pte = find_mapping_and_check(badvaddr, PF_ACCESS_WRITE, istate); 202 if (pte) { 214 203 /* 215 204 * Read the faulting TLB entry. … … 229 218 * The entry is to be updated in TLB. 230 219 */ 231 if ( BANK_SELECT_BIT(badvaddr)== 0)220 if ((badvaddr / PAGE_SIZE) % 2 == 0) 232 221 cp0_entry_lo0_write(lo.value); 233 222 else 234 223 cp0_entry_lo1_write(lo.value); 224 cp0_pagemask_write(TLB_PAGE_MASK_16K); 235 225 tlbwi(); 236 return; 237 } 238 239 (void) as_page_fault(badvaddr, PF_ACCESS_WRITE, istate); 226 } 227 } 228 229 /** Try to find PTE for faulting address. 230 * 231 * @param badvaddr Faulting virtual address. 232 * @param access Access mode that caused the fault. 233 * @param istate Pointer to interrupted state. 234 * 235 * @return PTE on success, NULL otherwise. 236 */ 237 pte_t *find_mapping_and_check(uintptr_t badvaddr, int access, istate_t *istate) 238 { 239 entry_hi_t hi; 240 pte_t *pte; 241 242 hi.value = cp0_entry_hi_read(); 243 244 ASSERT(hi.asid == AS->asid); 245 246 /* 247 * Check if the mapping exists in page tables. 248 */ 249 pte = page_mapping_find(AS, badvaddr, true); 250 if (pte && pte->p && (pte->w || access != PF_ACCESS_WRITE)) { 251 /* 252 * Mapping found in page tables. 253 * Immediately succeed. 254 */ 255 return pte; 256 } 257 258 /* 259 * Mapping not found in page tables. 260 * Resort to higher-level page fault handler. 261 */ 262 if (as_page_fault(badvaddr, access, istate) == AS_PF_OK) { 263 pte = page_mapping_find(AS, badvaddr, true); 264 ASSERT(pte && pte->p); 265 ASSERT(pte->w || access != PF_ACCESS_WRITE); 266 return pte; 267 } 268 269 return NULL; 240 270 } 241 271 … … 254 284 void tlb_prepare_entry_hi(entry_hi_t *hi, asid_t asid, uintptr_t addr) 255 285 { 256 hi->value = 0; 257 hi->vpn2 = ADDR2VPN2(ALIGN_DOWN(addr, PAGE_SIZE)); 286 hi->value = ALIGN_DOWN(addr, PAGE_SIZE * 2); 258 287 hi->asid = asid; 259 288 } … … 262 291 void tlb_print(void) 263 292 { 264 page_mask_t mask , mask_save;265 entry_lo_t lo0, lo 0_save, lo1, lo1_save;293 page_mask_t mask; 294 entry_lo_t lo0, lo1; 266 295 entry_hi_t hi, hi_save; 267 296 unsigned int i; 268 297 269 298 hi_save.value = cp0_entry_hi_read(); 270 lo0_save.value = cp0_entry_lo0_read(); 271 lo1_save.value = cp0_entry_lo1_read(); 272 mask_save.value = cp0_pagemask_read(); 273 274 printf("[nr] [asid] [vpn2 ] [mask] [gvdc] [pfn ]\n"); 299 300 printf("[nr] [asid] [vpn2] [mask] [gvdc] [pfn ]\n"); 275 301 276 302 for (i = 0; i < TLB_ENTRY_COUNT; i++) { … … 283 309 lo1.value = cp0_entry_lo1_read(); 284 310 285 printf("%-4u %-6u % 0#10x %-#6x %1u%1u%1u%1u %0#10x\n",286 i, hi.asid, VPN22ADDR(hi.vpn2), mask.mask,287 lo0.g, lo0.v, lo0.d, lo0.c, lo0.pfn << FRAME_WIDTH);288 printf(" %1u%1u%1u%1u %0#10x\n",289 lo1.g, lo1.v, lo1.d, lo1.c, lo1.pfn << FRAME_WIDTH);311 printf("%-4u %-6u %#6x %#6x %1u%1u%1u%1u %#6x\n", 312 i, hi.asid, hi.vpn2, mask.mask, 313 lo0.g, lo0.v, lo0.d, lo0.c, lo0.pfn); 314 printf(" %1u%1u%1u%1u %#6x\n", 315 lo1.g, lo1.v, lo1.d, lo1.c, lo1.pfn); 290 316 } 291 317 292 318 cp0_entry_hi_write(hi_save.value); 293 cp0_entry_lo0_write(lo0_save.value);294 cp0_entry_lo1_write(lo1_save.value);295 cp0_pagemask_write(mask_save.value);296 319 } 297 320 … … 299 322 void tlb_invalidate_all(void) 300 323 { 324 ipl_t ipl; 301 325 entry_lo_t lo0, lo1; 302 326 entry_hi_t hi_save; 303 327 int i; 304 328 305 ASSERT(interrupts_disabled());306 307 329 hi_save.value = cp0_entry_hi_read(); 330 ipl = interrupts_disable(); 308 331 309 332 for (i = TLB_WIRED; i < TLB_ENTRY_COUNT; i++) { … … 323 346 } 324 347 348 interrupts_restore(ipl); 325 349 cp0_entry_hi_write(hi_save.value); 326 350 } … … 332 356 void tlb_invalidate_asid(asid_t asid) 333 357 { 358 ipl_t ipl; 334 359 entry_lo_t lo0, lo1; 335 360 entry_hi_t hi, hi_save; 336 361 int i; 337 362 338 ASSERT(interrupts_disabled());339 363 ASSERT(asid != ASID_INVALID); 340 364 341 365 hi_save.value = cp0_entry_hi_read(); 366 ipl = interrupts_disable(); 342 367 343 368 for (i = 0; i < TLB_ENTRY_COUNT; i++) { … … 361 386 } 362 387 388 interrupts_restore(ipl); 363 389 cp0_entry_hi_write(hi_save.value); 364 390 } … … 374 400 { 375 401 unsigned int i; 402 ipl_t ipl; 376 403 entry_lo_t lo0, lo1; 377 404 entry_hi_t hi, hi_save; 378 405 tlb_index_t index; 379 380 ASSERT(interrupts_disabled());381 406 382 407 if (asid == ASID_INVALID) … … 384 409 385 410 hi_save.value = cp0_entry_hi_read(); 411 ipl = interrupts_disable(); 386 412 387 413 for (i = 0; i < cnt + 1; i += 2) { 414 hi.value = 0; 388 415 tlb_prepare_entry_hi(&hi, asid, page + i * PAGE_SIZE); 389 416 cp0_entry_hi_write(hi.value); … … 412 439 } 413 440 441 interrupts_restore(ipl); 414 442 cp0_entry_hi_write(hi_save.value); 415 443 }
Note:
See TracChangeset
for help on using the changeset viewer.