source: mainline/kernel/arch/ia64/src/mm/tlb.c@ 97b8ca9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 97b8ca9 was 346b12a2, checked in by Jakub Jermar <jakub@…>, 9 years ago

Add page_mapping_update()

page_mapping_update() can be used to safely update the accessed and dirty
bits of a PTE in the actual page tables.

  • Property mode set to 100644
File size: 18.3 KB
RevLine 
[36b01bb2]1/*
[df4ed85]2 * Copyright (c) 2006 Jakub Jermar
[36b01bb2]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[5bda2f3e]29/** @addtogroup ia64mm
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[36b01bb2]35/*
36 * TLB management.
37 */
38
39#include <mm/tlb.h>
[a0d74fd]40#include <mm/asid.h>
[9ad03fe]41#include <mm/page.h>
42#include <mm/as.h>
[bc78c75]43#include <arch/mm/tlb.h>
[a0d74fd]44#include <arch/mm/page.h>
[68091bd]45#include <arch/mm/vhpt.h>
[89298e3]46#include <arch/barrier.h>
[2c49fbbe]47#include <arch/interrupt.h>
[7c322bd]48#include <arch/pal/pal.h>
49#include <arch/asm.h>
[2c49fbbe]50#include <panic.h>
[1065603e]51#include <print.h>
[9ad03fe]52#include <arch.h>
[a175a67]53#include <interrupt.h>
[22f0561]54#include <arch/legacyio.h>
[5bda2f3e]55
[ef67bab]56/** Invalidate all TLB entries. */
[36b01bb2]57void tlb_invalidate_all(void)
58{
[ee289cf0]59 ipl_t ipl;
60 uintptr_t adr;
61 uint32_t count1, count2, stride1, stride2;
[5bda2f3e]62
[6c441cf8]63 unsigned int i, j;
[5bda2f3e]64
[ee289cf0]65 adr = PAL_PTCE_INFO_BASE();
66 count1 = PAL_PTCE_INFO_COUNT1();
67 count2 = PAL_PTCE_INFO_COUNT2();
68 stride1 = PAL_PTCE_INFO_STRIDE1();
69 stride2 = PAL_PTCE_INFO_STRIDE2();
[5bda2f3e]70
[ee289cf0]71 ipl = interrupts_disable();
[5bda2f3e]72
[6c441cf8]73 for (i = 0; i < count1; i++) {
74 for (j = 0; j < count2; j++) {
[e7b7be3f]75 asm volatile (
[5bda2f3e]76 "ptc.e %[adr] ;;"
77 :: [adr] "r" (adr)
[ee289cf0]78 );
79 adr += stride2;
[7c322bd]80 }
[ee289cf0]81 adr += stride1;
82 }
[5bda2f3e]83
[ee289cf0]84 interrupts_restore(ipl);
[5bda2f3e]85
[ee289cf0]86 srlz_d();
87 srlz_i();
[5bda2f3e]88
[68091bd]89#ifdef CONFIG_VHPT
[ee289cf0]90 vhpt_invalidate_all();
[5bda2f3e]91#endif
[36b01bb2]92}
93
94/** Invalidate entries belonging to an address space.
95 *
[5bda2f3e]96 * @param asid Address space identifier.
97 *
[36b01bb2]98 */
99void tlb_invalidate_asid(asid_t asid)
100{
[a82500ce]101 tlb_invalidate_all();
[36b01bb2]102}
[bc78c75]103
[a82500ce]104
[98000fb]105void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt)
[a82500ce]106{
[5bda2f3e]107 region_register_t rr;
[d0cf9de]108 bool restore_rr = false;
[1065603e]109 int b = 0;
110 int c = cnt;
[5bda2f3e]111
[7f1c620]112 uintptr_t va;
[1065603e]113 va = page;
[5bda2f3e]114
[9043309c]115 rr.word = rr_read(VA2VRN(page));
116 if ((restore_rr = (rr.map.rid != ASID2RID(asid, VA2VRN(page))))) {
[d0cf9de]117 /*
118 * The selected region register does not contain required RID.
119 * Save the old content of the register and replace the RID.
120 */
[5bda2f3e]121 region_register_t rr0;
122
[d0cf9de]123 rr0 = rr;
[9043309c]124 rr0.map.rid = ASID2RID(asid, VA2VRN(page));
125 rr_write(VA2VRN(page), rr0.word);
[d0cf9de]126 srlz_d();
127 srlz_i();
128 }
129
[5bda2f3e]130 while (c >>= 1)
[1065603e]131 b++;
132 b >>= 1;
[7f1c620]133 uint64_t ps;
[d0cf9de]134
[1065603e]135 switch (b) {
[666773c]136 case 0: /* cnt 1 - 3 */
[ee289cf0]137 ps = PAGE_WIDTH;
138 break;
[666773c]139 case 1: /* cnt 4 - 15 */
140 ps = PAGE_WIDTH + 2;
[9043309c]141 va &= ~((1UL << ps) - 1);
[ee289cf0]142 break;
[666773c]143 case 2: /* cnt 16 - 63 */
144 ps = PAGE_WIDTH + 4;
[9043309c]145 va &= ~((1UL << ps) - 1);
[ee289cf0]146 break;
[666773c]147 case 3: /* cnt 64 - 255 */
148 ps = PAGE_WIDTH + 6;
[9043309c]149 va &= ~((1UL << ps) - 1);
[ee289cf0]150 break;
[666773c]151 case 4: /* cnt 256 - 1023 */
152 ps = PAGE_WIDTH + 8;
[9043309c]153 va &= ~((1UL << ps) - 1);
[ee289cf0]154 break;
[666773c]155 case 5: /* cnt 1024 - 4095 */
156 ps = PAGE_WIDTH + 10;
[9043309c]157 va &= ~((1UL << ps) - 1);
[ee289cf0]158 break;
[666773c]159 case 6: /* cnt 4096 - 16383 */
160 ps = PAGE_WIDTH + 12;
[9043309c]161 va &= ~((1UL << ps) - 1);
[ee289cf0]162 break;
[666773c]163 case 7: /* cnt 16384 - 65535 */
164 case 8: /* cnt 65536 - (256K - 1) */
165 ps = PAGE_WIDTH + 14;
[9043309c]166 va &= ~((1UL << ps) - 1);
[ee289cf0]167 break;
168 default:
[666773c]169 ps = PAGE_WIDTH + 18;
[9043309c]170 va &= ~((1UL << ps) - 1);
[ee289cf0]171 break;
[d0cf9de]172 }
[5bda2f3e]173
[9043309c]174 for (; va < (page + cnt * PAGE_SIZE); va += (1UL << ps))
[5bda2f3e]175 asm volatile (
176 "ptc.l %[va], %[ps] ;;"
177 :: [va]"r" (va),
178 [ps] "r" (ps << 2)
179 );
180
[d0cf9de]181 srlz_d();
182 srlz_i();
183
184 if (restore_rr) {
[9043309c]185 rr_write(VA2VRN(page), rr.word);
[d0cf9de]186 srlz_d();
187 srlz_i();
188 }
[a82500ce]189}
190
[95042fd]191/** Insert data into data translation cache.
192 *
[5bda2f3e]193 * @param va Virtual page address.
194 * @param asid Address space identifier.
195 * @param entry The rest of TLB entry as required by TLB insertion
196 * format.
197 *
[95042fd]198 */
[7f1c620]199void dtc_mapping_insert(uintptr_t va, asid_t asid, tlb_entry_t entry)
[b994a60]200{
[95042fd]201 tc_mapping_insert(va, asid, entry, true);
202}
[bc78c75]203
[95042fd]204/** Insert data into instruction translation cache.
205 *
[5bda2f3e]206 * @param va Virtual page address.
207 * @param asid Address space identifier.
208 * @param entry The rest of TLB entry as required by TLB insertion
209 * format.
[95042fd]210 */
[7f1c620]211void itc_mapping_insert(uintptr_t va, asid_t asid, tlb_entry_t entry)
[b994a60]212{
[95042fd]213 tc_mapping_insert(va, asid, entry, false);
214}
[bc78c75]215
[95042fd]216/** Insert data into instruction or data translation cache.
217 *
[5bda2f3e]218 * @param va Virtual page address.
219 * @param asid Address space identifier.
220 * @param entry The rest of TLB entry as required by TLB insertion
221 * format.
222 * @param dtc If true, insert into data translation cache, use
223 * instruction translation cache otherwise.
224 *
[95042fd]225 */
[7f1c620]226void tc_mapping_insert(uintptr_t va, asid_t asid, tlb_entry_t entry, bool dtc)
[bc78c75]227{
[5bda2f3e]228 region_register_t rr;
[95042fd]229 bool restore_rr = false;
[5bda2f3e]230
[a0d74fd]231 rr.word = rr_read(VA2VRN(va));
232 if ((restore_rr = (rr.map.rid != ASID2RID(asid, VA2VRN(va))))) {
[95042fd]233 /*
234 * The selected region register does not contain required RID.
235 * Save the old content of the register and replace the RID.
236 */
[5bda2f3e]237 region_register_t rr0;
238
[95042fd]239 rr0 = rr;
[a0d74fd]240 rr0.map.rid = ASID2RID(asid, VA2VRN(va));
241 rr_write(VA2VRN(va), rr0.word);
[89298e3]242 srlz_d();
[95042fd]243 srlz_i();
244 }
245
[e7b7be3f]246 asm volatile (
[5bda2f3e]247 "mov r8 = psr ;;\n"
248 "rsm %[mask] ;;\n" /* PSR_IC_MASK */
249 "srlz.d ;;\n"
250 "srlz.i ;;\n"
251 "mov cr.ifa = %[va]\n" /* va */
252 "mov cr.itir = %[word1] ;;\n" /* entry.word[1] */
253 "cmp.eq p6, p7 = %[dtc], r0 ;;\n" /* decide between itc and dtc */
254 "(p6) itc.i %[word0] ;;\n"
255 "(p7) itc.d %[word0] ;;\n"
256 "mov psr.l = r8 ;;\n"
257 "srlz.d ;;\n"
258 :: [mask] "i" (PSR_IC_MASK),
259 [va] "r" (va),
260 [word0] "r" (entry.word[0]),
261 [word1] "r" (entry.word[1]),
262 [dtc] "r" (dtc)
[2c49fbbe]263 : "p6", "p7", "r8"
[95042fd]264 );
265
266 if (restore_rr) {
[a0d74fd]267 rr_write(VA2VRN(va), rr.word);
[95042fd]268 srlz_d();
269 srlz_i();
[bc78c75]270 }
271}
272
[95042fd]273/** Insert data into instruction translation register.
274 *
[5bda2f3e]275 * @param va Virtual page address.
276 * @param asid Address space identifier.
277 * @param entry The rest of TLB entry as required by TLB insertion
278 * format.
279 * @param tr Translation register.
280 *
[95042fd]281 */
[5bda2f3e]282void itr_mapping_insert(uintptr_t va, asid_t asid, tlb_entry_t entry, size_t tr)
[bc78c75]283{
[95042fd]284 tr_mapping_insert(va, asid, entry, false, tr);
[bc78c75]285}
286
[95042fd]287/** Insert data into data translation register.
288 *
[5bda2f3e]289 * @param va Virtual page address.
290 * @param asid Address space identifier.
291 * @param entry The rest of TLB entry as required by TLB insertion
292 * format.
293 * @param tr Translation register.
294 *
[95042fd]295 */
[5bda2f3e]296void dtr_mapping_insert(uintptr_t va, asid_t asid, tlb_entry_t entry, size_t tr)
[95042fd]297{
298 tr_mapping_insert(va, asid, entry, true, tr);
299}
[bc78c75]300
[95042fd]301/** Insert data into instruction or data translation register.
302 *
[5bda2f3e]303 * @param va Virtual page address.
304 * @param asid Address space identifier.
305 * @param entry The rest of TLB entry as required by TLB insertion
306 * format.
307 * @param dtr If true, insert into data translation register, use
308 * instruction translation register otherwise.
309 * @param tr Translation register.
310 *
[95042fd]311 */
[5bda2f3e]312void tr_mapping_insert(uintptr_t va, asid_t asid, tlb_entry_t entry, bool dtr,
[98000fb]313 size_t tr)
[89298e3]314{
[5bda2f3e]315 region_register_t rr;
[95042fd]316 bool restore_rr = false;
[5bda2f3e]317
[a0d74fd]318 rr.word = rr_read(VA2VRN(va));
319 if ((restore_rr = (rr.map.rid != ASID2RID(asid, VA2VRN(va))))) {
[95042fd]320 /*
321 * The selected region register does not contain required RID.
322 * Save the old content of the register and replace the RID.
323 */
[5bda2f3e]324 region_register_t rr0;
325
[95042fd]326 rr0 = rr;
[a0d74fd]327 rr0.map.rid = ASID2RID(asid, VA2VRN(va));
328 rr_write(VA2VRN(va), rr0.word);
[89298e3]329 srlz_d();
[95042fd]330 srlz_i();
[89298e3]331 }
[5bda2f3e]332
[e7b7be3f]333 asm volatile (
[5bda2f3e]334 "mov r8 = psr ;;\n"
335 "rsm %[mask] ;;\n" /* PSR_IC_MASK */
336 "srlz.d ;;\n"
337 "srlz.i ;;\n"
338 "mov cr.ifa = %[va]\n" /* va */
339 "mov cr.itir = %[word1] ;;\n" /* entry.word[1] */
340 "cmp.eq p6, p7 = %[dtr], r0 ;;\n" /* decide between itr and dtr */
341 "(p6) itr.i itr[%[tr]] = %[word0] ;;\n"
342 "(p7) itr.d dtr[%[tr]] = %[word0] ;;\n"
343 "mov psr.l = r8 ;;\n"
344 "srlz.d ;;\n"
345 :: [mask] "i" (PSR_IC_MASK),
346 [va] "r" (va),
347 [word1] "r" (entry.word[1]),
348 [word0] "r" (entry.word[0]),
349 [tr] "r" (tr),
350 [dtr] "r" (dtr)
[2c49fbbe]351 : "p6", "p7", "r8"
[95042fd]352 );
353
354 if (restore_rr) {
[a0d74fd]355 rr_write(VA2VRN(va), rr.word);
[95042fd]356 srlz_d();
357 srlz_i();
358 }
[89298e3]359}
360
[a0d74fd]361/** Insert data into DTLB.
362 *
[5bda2f3e]363 * @param page Virtual page address including VRN bits.
364 * @param frame Physical frame address.
365 * @param dtr If true, insert into data translation register, use data
366 * translation cache otherwise.
367 * @param tr Translation register if dtr is true, ignored otherwise.
368 *
[a0d74fd]369 */
[5bda2f3e]370void dtlb_kernel_mapping_insert(uintptr_t page, uintptr_t frame, bool dtr,
[98000fb]371 size_t tr)
[a0d74fd]372{
373 tlb_entry_t entry;
374
375 entry.word[0] = 0;
376 entry.word[1] = 0;
377
[5bda2f3e]378 entry.p = true; /* present */
[a0d74fd]379 entry.ma = MA_WRITEBACK;
[5bda2f3e]380 entry.a = true; /* already accessed */
381 entry.d = true; /* already dirty */
[a0d74fd]382 entry.pl = PL_KERNEL;
383 entry.ar = AR_READ | AR_WRITE;
384 entry.ppn = frame >> PPN_SHIFT;
385 entry.ps = PAGE_WIDTH;
386
387 if (dtr)
388 dtr_mapping_insert(page, ASID_KERNEL, entry, tr);
389 else
390 dtc_mapping_insert(page, ASID_KERNEL, entry);
391}
392
[208259c]393/** Purge kernel entries from DTR.
394 *
395 * Purge DTR entries used by the kernel.
396 *
[5bda2f3e]397 * @param page Virtual page address including VRN bits.
398 * @param width Width of the purge in bits.
399 *
[208259c]400 */
[98000fb]401void dtr_purge(uintptr_t page, size_t width)
[208259c]402{
[5bda2f3e]403 asm volatile (
404 "ptr.d %[page], %[width]\n"
405 :: [page] "r" (page),
406 [width] "r" (width << 2)
407 );
[208259c]408}
409
410
[9ad03fe]411/** Copy content of PTE into data translation cache.
412 *
[5bda2f3e]413 * @param t PTE.
414 *
[9ad03fe]415 */
416void dtc_pte_copy(pte_t *t)
417{
418 tlb_entry_t entry;
[5bda2f3e]419
[9ad03fe]420 entry.word[0] = 0;
421 entry.word[1] = 0;
422
423 entry.p = t->p;
424 entry.ma = t->c ? MA_WRITEBACK : MA_UNCACHEABLE;
425 entry.a = t->a;
426 entry.d = t->d;
427 entry.pl = t->k ? PL_KERNEL : PL_USER;
428 entry.ar = t->w ? AR_WRITE : AR_READ;
429 entry.ppn = t->frame >> PPN_SHIFT;
430 entry.ps = PAGE_WIDTH;
431
432 dtc_mapping_insert(t->page, t->as->asid, entry);
[5bda2f3e]433
[68091bd]434#ifdef CONFIG_VHPT
435 vhpt_mapping_insert(t->page, t->as->asid, entry);
[5bda2f3e]436#endif
[9ad03fe]437}
438
439/** Copy content of PTE into instruction translation cache.
440 *
[5bda2f3e]441 * @param t PTE.
442 *
[9ad03fe]443 */
444void itc_pte_copy(pte_t *t)
445{
446 tlb_entry_t entry;
[5bda2f3e]447
[9ad03fe]448 entry.word[0] = 0;
449 entry.word[1] = 0;
450
451 ASSERT(t->x);
452
453 entry.p = t->p;
454 entry.ma = t->c ? MA_WRITEBACK : MA_UNCACHEABLE;
455 entry.a = t->a;
456 entry.pl = t->k ? PL_KERNEL : PL_USER;
457 entry.ar = t->x ? (AR_EXECUTE | AR_READ) : AR_READ;
458 entry.ppn = t->frame >> PPN_SHIFT;
459 entry.ps = PAGE_WIDTH;
460
461 itc_mapping_insert(t->page, t->as->asid, entry);
[5bda2f3e]462
[68091bd]463#ifdef CONFIG_VHPT
464 vhpt_mapping_insert(t->page, t->as->asid, entry);
[5bda2f3e]465#endif
[9ad03fe]466}
467
[0fd9b35]468static bool is_kernel_fault(uintptr_t va)
469{
470 region_register_t rr;
471
472 rr.word = rr_read(VA2VRN(va));
473 rid_t rid = rr.map.rid;
474 return (RID2ASID(rid) == ASID_KERNEL) && (VA2VRN(va) == VRN_KERNEL);
475}
476
[9ad03fe]477/** Instruction TLB fault handler for faults with VHPT turned off.
478 *
[9928240]479 * @param n Interruption vector.
[5bda2f3e]480 * @param istate Structure with saved interruption state.
481 *
[9ad03fe]482 */
[9928240]483void alternate_instruction_tlb_fault(unsigned int n, istate_t *istate)
[89298e3]484{
[7f1c620]485 uintptr_t va;
[38dc82d]486 pte_t t;
[9ad03fe]487
[5bda2f3e]488 va = istate->cr_ifa; /* faulting address */
489
[0fd9b35]490 ASSERT(!is_kernel_fault(va));
491
[38dc82d]492 bool found = page_mapping_find(AS, va, true, &t);
493 if (found) {
[9ad03fe]494 /*
495 * The mapping was found in software page hash table.
496 * Insert it into data translation cache.
497 */
[38dc82d]498 itc_pte_copy(&t);
[9ad03fe]499 } else {
500 /*
501 * Forward the page fault to address space page fault handler.
502 */
[1dbc43f]503 as_page_fault(va, PF_ACCESS_EXEC, istate);
[9ad03fe]504 }
[95042fd]505}
[89298e3]506
[46321fb]507static int is_io_page_accessible(int page)
508{
[666773c]509 if (TASK->arch.iomap)
[38f6add]510 return bitmap_get(TASK->arch.iomap, page);
[666773c]511 else
512 return 0;
[46321fb]513}
514
[666773c]515/**
516 * There is special handling of memory mapped legacy io, because of 4KB sized
517 * access for userspace.
[46321fb]518 *
[5bda2f3e]519 * @param va Virtual address of page fault.
520 * @param istate Structure with saved interruption state.
521 *
522 * @return One on success, zero on failure.
[46321fb]523 *
524 */
525static int try_memmap_io_insertion(uintptr_t va, istate_t *istate)
526{
[22f0561]527 if ((va >= LEGACYIO_USER_BASE) && (va < LEGACYIO_USER_BASE + (1 << LEGACYIO_PAGE_WIDTH))) {
[666773c]528 if (TASK) {
[22f0561]529 uint64_t io_page = (va & ((1 << LEGACYIO_PAGE_WIDTH) - 1)) >>
530 LEGACYIO_SINGLE_PAGE_WIDTH;
[5bda2f3e]531
[666773c]532 if (is_io_page_accessible(io_page)) {
533 uint64_t page, frame;
[5bda2f3e]534
[22f0561]535 page = LEGACYIO_USER_BASE +
536 (1 << LEGACYIO_SINGLE_PAGE_WIDTH) * io_page;
537 frame = LEGACYIO_PHYS_BASE +
538 (1 << LEGACYIO_SINGLE_PAGE_WIDTH) * io_page;
[5bda2f3e]539
[46321fb]540 tlb_entry_t entry;
[5bda2f3e]541
[46321fb]542 entry.word[0] = 0;
543 entry.word[1] = 0;
[5bda2f3e]544
545 entry.p = true; /* present */
546 entry.ma = MA_UNCACHEABLE;
547 entry.a = true; /* already accessed */
548 entry.d = true; /* already dirty */
[46321fb]549 entry.pl = PL_USER;
550 entry.ar = AR_READ | AR_WRITE;
[ef5de6d]551 entry.ppn = frame >> PPN_SHIFT;
[22f0561]552 entry.ps = LEGACYIO_SINGLE_PAGE_WIDTH;
[5bda2f3e]553
[ef5de6d]554 dtc_mapping_insert(page, TASK->as->asid, entry);
[46321fb]555 return 1;
[666773c]556 } else {
557 fault_if_from_uspace(istate,
[7e752b2]558 "IO access fault at %p.", (void *) va);
[666773c]559 }
560 }
561 }
[5bda2f3e]562
[46321fb]563 return 0;
564}
565
[9ad03fe]566/** Data TLB fault handler for faults with VHPT turned off.
[a0d74fd]567 *
[9928240]568 * @param n Interruption vector.
[5bda2f3e]569 * @param istate Structure with saved interruption state.
570 *
[a0d74fd]571 */
[9928240]572void alternate_data_tlb_fault(unsigned int n, istate_t *istate)
[95042fd]573{
[93d66ef]574 if (istate->cr_isr.sp) {
[0fd9b35]575 /*
576 * Speculative load. Deffer the exception until a more clever
577 * approach can be used. Currently if we try to find the
578 * mapping for the speculative load while in the kernel, we
579 * might introduce a livelock because of the possibly invalid
580 * values of the address.
581 */
[93d66ef]582 istate->cr_ipsr.ed = true;
583 return;
584 }
585
[5bda2f3e]586 uintptr_t va = istate->cr_ifa; /* faulting address */
[0fd9b35]587 as_t *as = AS;
[a0d74fd]588
[0fd9b35]589 if (is_kernel_fault(va)) {
590 if (va < end_of_identity) {
[a0d74fd]591 /*
[0fd9b35]592 * Create kernel identity mapping for low memory.
[a0d74fd]593 */
[9ad03fe]594 dtlb_kernel_mapping_insert(va, KA2PA(va), false, 0);
[a0d74fd]595 return;
[0fd9b35]596 } else {
597 as = AS_KERNEL;
[a0d74fd]598 }
599 }
[5bda2f3e]600
601
[38dc82d]602 pte_t t;
603 bool found = page_mapping_find(as, va, true, &t);
604 if (found) {
[9ad03fe]605 /*
[f47fd19]606 * The mapping was found in the software page hash table.
[9ad03fe]607 * Insert it into data translation cache.
608 */
[38dc82d]609 dtc_pte_copy(&t);
[9ad03fe]610 } else {
[666773c]611 if (try_memmap_io_insertion(va, istate))
612 return;
[5bda2f3e]613
[9ad03fe]614 /*
[5bda2f3e]615 * Forward the page fault to the address space page fault
[666773c]616 * handler.
[9ad03fe]617 */
[1dbc43f]618 as_page_fault(va, PF_ACCESS_READ, istate);
[9ad03fe]619 }
[95042fd]620}
[89298e3]621
[9ad03fe]622/** Data nested TLB fault handler.
623 *
624 * This fault should not occur.
625 *
[9928240]626 * @param n Interruption vector.
[5bda2f3e]627 * @param istate Structure with saved interruption state.
628 *
[9ad03fe]629 */
[9928240]630void data_nested_tlb_fault(unsigned int n, istate_t *istate)
[95042fd]631{
[5bda2f3e]632 ASSERT(false);
[95042fd]633}
[89298e3]634
[9ad03fe]635/** Data Dirty bit fault handler.
636 *
[9928240]637 * @param n Interruption vector.
[5bda2f3e]638 * @param istate Structure with saved interruption state.
639 *
[9ad03fe]640 */
[9928240]641void data_dirty_bit_fault(unsigned int n, istate_t *istate)
[95042fd]642{
[7f1c620]643 uintptr_t va;
[38dc82d]644 pte_t t;
[0fd9b35]645 as_t *as = AS;
[567807b1]646
[5bda2f3e]647 va = istate->cr_ifa; /* faulting address */
648
[0fd9b35]649 if (is_kernel_fault(va))
650 as = AS_KERNEL;
651
[38dc82d]652 bool found = page_mapping_find(as, va, true, &t);
653
654 ASSERT(found);
655 ASSERT(t.p);
656
657 if (found && t.p && t.w) {
[9ad03fe]658 /*
659 * Update the Dirty bit in page tables and reinsert
660 * the mapping into DTC.
661 */
[38dc82d]662 t.d = true;
663 dtc_pte_copy(&t);
[346b12a2]664 page_mapping_update(as, va, true, &t);
[567807b1]665 } else {
[1dbc43f]666 as_page_fault(va, PF_ACCESS_WRITE, istate);
[9ad03fe]667 }
[95042fd]668}
[89298e3]669
[9ad03fe]670/** Instruction access bit fault handler.
671 *
[9928240]672 * @param n Interruption vector.
[5bda2f3e]673 * @param istate Structure with saved interruption state.
674 *
[9ad03fe]675 */
[9928240]676void instruction_access_bit_fault(unsigned int n, istate_t *istate)
[95042fd]677{
[7f1c620]678 uintptr_t va;
[38dc82d]679 pte_t t;
[5bda2f3e]680
681 va = istate->cr_ifa; /* faulting address */
[0fd9b35]682
683 ASSERT(!is_kernel_fault(va));
[5bda2f3e]684
[38dc82d]685 bool found = page_mapping_find(AS, va, true, &t);
686
687 ASSERT(found);
688 ASSERT(t.p);
689
690 if (found && t.p && t.x) {
[9ad03fe]691 /*
692 * Update the Accessed bit in page tables and reinsert
693 * the mapping into ITC.
694 */
[38dc82d]695 t.a = true;
696 itc_pte_copy(&t);
[346b12a2]697 page_mapping_update(AS, va, true, &t);
[567807b1]698 } else {
[1dbc43f]699 as_page_fault(va, PF_ACCESS_EXEC, istate);
[9ad03fe]700 }
[95042fd]701}
[89298e3]702
[9ad03fe]703/** Data access bit fault handler.
704 *
[9928240]705 * @param n Interruption vector.
[25d7709]706 * @param istate Structure with saved interruption state.
[5bda2f3e]707 *
[9ad03fe]708 */
[9928240]709void data_access_bit_fault(unsigned int n, istate_t *istate)
[95042fd]710{
[7f1c620]711 uintptr_t va;
[38dc82d]712 pte_t t;
[0fd9b35]713 as_t *as = AS;
[5bda2f3e]714
715 va = istate->cr_ifa; /* faulting address */
716
[0fd9b35]717 if (is_kernel_fault(va))
718 as = AS_KERNEL;
719
[38dc82d]720 bool found = page_mapping_find(as, va, true, &t);
721
722 ASSERT(found);
723 ASSERT(t.p);
724
725 if (found && t.p) {
[9ad03fe]726 /*
727 * Update the Accessed bit in page tables and reinsert
728 * the mapping into DTC.
729 */
[38dc82d]730 t.a = true;
731 dtc_pte_copy(&t);
[346b12a2]732 page_mapping_update(as, va, true, &t);
[567807b1]733 } else {
734 if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
[7e752b2]735 fault_if_from_uspace(istate, "Page fault at %p.",
736 (void *) va);
[c15b374]737 panic_memtrap(istate, PF_ACCESS_UNKNOWN, va, NULL);
[567807b1]738 }
[9ad03fe]739 }
[89298e3]740}
741
[925be4e]742/** Data access rights fault handler.
743 *
[9928240]744 * @param n Interruption vector.
[925be4e]745 * @param istate Structure with saved interruption state.
[5bda2f3e]746 *
[925be4e]747 */
[9928240]748void data_access_rights_fault(unsigned int n, istate_t *istate)
[925be4e]749{
750 uintptr_t va;
[38dc82d]751 pte_t t;
[5bda2f3e]752
753 va = istate->cr_ifa; /* faulting address */
[0fd9b35]754
755 ASSERT(!is_kernel_fault(va));
[5bda2f3e]756
[925be4e]757 /*
758 * Assume a write to a read-only page.
759 */
[38dc82d]760 bool found = page_mapping_find(AS, va, true, &t);
761
762 ASSERT(found);
763 ASSERT(t.p);
764 ASSERT(!t.w);
765
[1dbc43f]766 as_page_fault(va, PF_ACCESS_WRITE, istate);
[925be4e]767}
768
[9ad03fe]769/** Page not present fault handler.
770 *
[9928240]771 * @param n Interruption vector.
[25d7709]772 * @param istate Structure with saved interruption state.
[5bda2f3e]773 *
[9ad03fe]774 */
[9928240]775void page_not_present(unsigned int n, istate_t *istate)
[95042fd]776{
[7f1c620]777 uintptr_t va;
[38dc82d]778 pte_t t;
[9ad03fe]779
[5bda2f3e]780 va = istate->cr_ifa; /* faulting address */
781
[0fd9b35]782 ASSERT(!is_kernel_fault(va));
783
[38dc82d]784 bool found = page_mapping_find(AS, va, true, &t);
785
786 ASSERT(found);
[9ad03fe]787
[38dc82d]788 if (t.p) {
[9ad03fe]789 /*
790 * If the Present bit is set in page hash table, just copy it
791 * and update ITC/DTC.
792 */
[38dc82d]793 if (t.x)
794 itc_pte_copy(&t);
[9ad03fe]795 else
[38dc82d]796 dtc_pte_copy(&t);
[9ad03fe]797 } else {
[1dbc43f]798 as_page_fault(va, PF_ACCESS_READ, istate);
[9ad03fe]799 }
[95042fd]800}
[b45c443]801
[9979acb]802void tlb_arch_init(void)
803{
804}
805
806void tlb_print(void)
807{
808}
809
[ee289cf0]810/** @}
[b45c443]811 */
Note: See TracBrowser for help on using the repository browser.