[36b01bb2] | 1 | /*
|
---|
| 2 | * Copyright (C) 2006 Jakub Jermar
|
---|
| 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 |
|
---|
| 29 | /*
|
---|
| 30 | * TLB management.
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | #include <mm/tlb.h>
|
---|
[a0d74fd] | 34 | #include <mm/asid.h>
|
---|
[9ad03fe] | 35 | #include <mm/page.h>
|
---|
| 36 | #include <mm/as.h>
|
---|
[bc78c75] | 37 | #include <arch/mm/tlb.h>
|
---|
[a0d74fd] | 38 | #include <arch/mm/page.h>
|
---|
[68091bd] | 39 | #include <arch/mm/vhpt.h>
|
---|
[89298e3] | 40 | #include <arch/barrier.h>
|
---|
[2c49fbbe] | 41 | #include <arch/interrupt.h>
|
---|
[7c322bd] | 42 | #include <arch/pal/pal.h>
|
---|
| 43 | #include <arch/asm.h>
|
---|
[95042fd] | 44 | #include <typedefs.h>
|
---|
[2c49fbbe] | 45 | #include <panic.h>
|
---|
[1065603e] | 46 | #include <print.h>
|
---|
[9ad03fe] | 47 | #include <arch.h>
|
---|
[a175a67] | 48 | #include <interrupt.h>
|
---|
[36b01bb2] | 49 |
|
---|
[ef67bab] | 50 | /** Invalidate all TLB entries. */
|
---|
[36b01bb2] | 51 | void tlb_invalidate_all(void)
|
---|
| 52 | {
|
---|
[1065603e] | 53 | ipl_t ipl;
|
---|
[7c322bd] | 54 | __address adr;
|
---|
[1065603e] | 55 | __u32 count1, count2, stride1, stride2;
|
---|
[7c322bd] | 56 |
|
---|
| 57 | int i,j;
|
---|
| 58 |
|
---|
[1065603e] | 59 | adr = PAL_PTCE_INFO_BASE();
|
---|
| 60 | count1 = PAL_PTCE_INFO_COUNT1();
|
---|
| 61 | count2 = PAL_PTCE_INFO_COUNT2();
|
---|
| 62 | stride1 = PAL_PTCE_INFO_STRIDE1();
|
---|
| 63 | stride2 = PAL_PTCE_INFO_STRIDE2();
|
---|
[7c322bd] | 64 |
|
---|
[1065603e] | 65 | ipl = interrupts_disable();
|
---|
| 66 |
|
---|
| 67 | for(i = 0; i < count1; i++) {
|
---|
| 68 | for(j = 0; j < count2; j++) {
|
---|
| 69 | __asm__ volatile (
|
---|
| 70 | "ptc.e %0 ;;"
|
---|
[7c322bd] | 71 | :
|
---|
[1065603e] | 72 | : "r" (adr)
|
---|
[7c322bd] | 73 | );
|
---|
[1065603e] | 74 | adr += stride2;
|
---|
[7c322bd] | 75 | }
|
---|
[1065603e] | 76 | adr += stride1;
|
---|
[7c322bd] | 77 | }
|
---|
| 78 |
|
---|
[1065603e] | 79 | interrupts_restore(ipl);
|
---|
[7c322bd] | 80 |
|
---|
| 81 | srlz_d();
|
---|
| 82 | srlz_i();
|
---|
[68091bd] | 83 | #ifdef CONFIG_VHPT
|
---|
| 84 | vhpt_invalidate_all();
|
---|
| 85 | #endif
|
---|
[36b01bb2] | 86 | }
|
---|
| 87 |
|
---|
| 88 | /** Invalidate entries belonging to an address space.
|
---|
| 89 | *
|
---|
| 90 | * @param asid Address space identifier.
|
---|
| 91 | */
|
---|
| 92 | void tlb_invalidate_asid(asid_t asid)
|
---|
| 93 | {
|
---|
[a82500ce] | 94 | tlb_invalidate_all();
|
---|
[36b01bb2] | 95 | }
|
---|
[bc78c75] | 96 |
|
---|
[a82500ce] | 97 |
|
---|
[9bda3af6] | 98 | void tlb_invalidate_pages(asid_t asid, __address page, count_t cnt)
|
---|
[a82500ce] | 99 | {
|
---|
[d0cf9de] | 100 | region_register rr;
|
---|
| 101 | bool restore_rr = false;
|
---|
[1065603e] | 102 | int b = 0;
|
---|
| 103 | int c = cnt;
|
---|
[9bda3af6] | 104 |
|
---|
| 105 | __address va;
|
---|
[1065603e] | 106 | va = page;
|
---|
[d0cf9de] | 107 |
|
---|
| 108 | rr.word = rr_read(VA2VRN(va));
|
---|
| 109 | if ((restore_rr = (rr.map.rid != ASID2RID(asid, VA2VRN(va))))) {
|
---|
| 110 | /*
|
---|
| 111 | * The selected region register does not contain required RID.
|
---|
| 112 | * Save the old content of the register and replace the RID.
|
---|
| 113 | */
|
---|
| 114 | region_register rr0;
|
---|
| 115 |
|
---|
| 116 | rr0 = rr;
|
---|
| 117 | rr0.map.rid = ASID2RID(asid, VA2VRN(va));
|
---|
| 118 | rr_write(VA2VRN(va), rr0.word);
|
---|
| 119 | srlz_d();
|
---|
| 120 | srlz_i();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[1065603e] | 123 | while(c >>= 1)
|
---|
| 124 | b++;
|
---|
| 125 | b >>= 1;
|
---|
[d0cf9de] | 126 | __u64 ps;
|
---|
| 127 |
|
---|
[1065603e] | 128 | switch (b) {
|
---|
[d0cf9de] | 129 | case 0: /*cnt 1-3*/
|
---|
[1065603e] | 130 | ps = PAGE_WIDTH;
|
---|
[d0cf9de] | 131 | break;
|
---|
| 132 | case 1: /*cnt 4-15*/
|
---|
[9bda3af6] | 133 | /*cnt=((cnt-1)/4)+1;*/
|
---|
[1065603e] | 134 | ps = PAGE_WIDTH+2;
|
---|
| 135 | va &= ~((1<<ps)-1);
|
---|
[d0cf9de] | 136 | break;
|
---|
| 137 | case 2: /*cnt 16-63*/
|
---|
[9bda3af6] | 138 | /*cnt=((cnt-1)/16)+1;*/
|
---|
[1065603e] | 139 | ps = PAGE_WIDTH+4;
|
---|
| 140 | va &= ~((1<<ps)-1);
|
---|
[d0cf9de] | 141 | break;
|
---|
| 142 | case 3: /*cnt 64-255*/
|
---|
[9bda3af6] | 143 | /*cnt=((cnt-1)/64)+1;*/
|
---|
[1065603e] | 144 | ps = PAGE_WIDTH+6;
|
---|
| 145 | va &= ~((1<<ps)-1);
|
---|
[d0cf9de] | 146 | break;
|
---|
| 147 | case 4: /*cnt 256-1023*/
|
---|
[9bda3af6] | 148 | /*cnt=((cnt-1)/256)+1;*/
|
---|
[1065603e] | 149 | ps = PAGE_WIDTH+8;
|
---|
| 150 | va &= ~((1<<ps)-1);
|
---|
[d0cf9de] | 151 | break;
|
---|
| 152 | case 5: /*cnt 1024-4095*/
|
---|
[9bda3af6] | 153 | /*cnt=((cnt-1)/1024)+1;*/
|
---|
[1065603e] | 154 | ps = PAGE_WIDTH+10;
|
---|
| 155 | va &= ~((1<<ps)-1);
|
---|
[d0cf9de] | 156 | break;
|
---|
| 157 | case 6: /*cnt 4096-16383*/
|
---|
[9bda3af6] | 158 | /*cnt=((cnt-1)/4096)+1;*/
|
---|
[1065603e] | 159 | ps = PAGE_WIDTH+12;
|
---|
| 160 | va &= ~((1<<ps)-1);
|
---|
[d0cf9de] | 161 | break;
|
---|
| 162 | case 7: /*cnt 16384-65535*/
|
---|
| 163 | case 8: /*cnt 65536-(256K-1)*/
|
---|
[9bda3af6] | 164 | /*cnt=((cnt-1)/16384)+1;*/
|
---|
[1065603e] | 165 | ps = PAGE_WIDTH+14;
|
---|
| 166 | va &= ~((1<<ps)-1);
|
---|
[d0cf9de] | 167 | break;
|
---|
| 168 | default:
|
---|
[9bda3af6] | 169 | /*cnt=((cnt-1)/(16384*16))+1;*/
|
---|
[d0cf9de] | 170 | ps=PAGE_WIDTH+18;
|
---|
| 171 | va&=~((1<<ps)-1);
|
---|
| 172 | break;
|
---|
| 173 | }
|
---|
[9bda3af6] | 174 | /*cnt+=(page!=va);*/
|
---|
[1065603e] | 175 | for(; va<(page+cnt*(PAGE_SIZE)); va += (1<<ps)) {
|
---|
| 176 | __asm__ volatile (
|
---|
[9bda3af6] | 177 | "ptc.l %0,%1;;"
|
---|
| 178 | :
|
---|
[1065603e] | 179 | : "r" (va), "r" (ps<<2)
|
---|
[9bda3af6] | 180 | );
|
---|
[d0cf9de] | 181 | }
|
---|
| 182 | srlz_d();
|
---|
| 183 | srlz_i();
|
---|
| 184 |
|
---|
| 185 | if (restore_rr) {
|
---|
| 186 | rr_write(VA2VRN(va), rr.word);
|
---|
| 187 | srlz_d();
|
---|
| 188 | srlz_i();
|
---|
| 189 | }
|
---|
[a82500ce] | 190 | }
|
---|
| 191 |
|
---|
[95042fd] | 192 | /** Insert data into data translation cache.
|
---|
| 193 | *
|
---|
| 194 | * @param va Virtual page address.
|
---|
| 195 | * @param asid Address space identifier.
|
---|
| 196 | * @param entry The rest of TLB entry as required by TLB insertion format.
|
---|
| 197 | */
|
---|
[b994a60] | 198 | void dtc_mapping_insert(__address va, asid_t asid, tlb_entry_t entry)
|
---|
| 199 | {
|
---|
[95042fd] | 200 | tc_mapping_insert(va, asid, entry, true);
|
---|
| 201 | }
|
---|
[bc78c75] | 202 |
|
---|
[95042fd] | 203 | /** Insert data into instruction translation cache.
|
---|
| 204 | *
|
---|
| 205 | * @param va Virtual page address.
|
---|
| 206 | * @param asid Address space identifier.
|
---|
| 207 | * @param entry The rest of TLB entry as required by TLB insertion format.
|
---|
| 208 | */
|
---|
[b994a60] | 209 | void itc_mapping_insert(__address va, asid_t asid, tlb_entry_t entry)
|
---|
| 210 | {
|
---|
[95042fd] | 211 | tc_mapping_insert(va, asid, entry, false);
|
---|
| 212 | }
|
---|
[bc78c75] | 213 |
|
---|
[95042fd] | 214 | /** Insert data into instruction or data translation cache.
|
---|
| 215 | *
|
---|
| 216 | * @param va Virtual page address.
|
---|
| 217 | * @param asid Address space identifier.
|
---|
| 218 | * @param entry The rest of TLB entry as required by TLB insertion format.
|
---|
| 219 | * @param dtc If true, insert into data translation cache, use instruction translation cache otherwise.
|
---|
| 220 | */
|
---|
| 221 | void tc_mapping_insert(__address va, asid_t asid, tlb_entry_t entry, bool dtc)
|
---|
[bc78c75] | 222 | {
|
---|
| 223 | region_register rr;
|
---|
[95042fd] | 224 | bool restore_rr = false;
|
---|
[bc78c75] | 225 |
|
---|
[a0d74fd] | 226 | rr.word = rr_read(VA2VRN(va));
|
---|
| 227 | if ((restore_rr = (rr.map.rid != ASID2RID(asid, VA2VRN(va))))) {
|
---|
[95042fd] | 228 | /*
|
---|
| 229 | * The selected region register does not contain required RID.
|
---|
| 230 | * Save the old content of the register and replace the RID.
|
---|
| 231 | */
|
---|
[bc78c75] | 232 | region_register rr0;
|
---|
[95042fd] | 233 |
|
---|
| 234 | rr0 = rr;
|
---|
[a0d74fd] | 235 | rr0.map.rid = ASID2RID(asid, VA2VRN(va));
|
---|
| 236 | rr_write(VA2VRN(va), rr0.word);
|
---|
[89298e3] | 237 | srlz_d();
|
---|
[95042fd] | 238 | srlz_i();
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | __asm__ volatile (
|
---|
| 242 | "mov r8=psr;;\n"
|
---|
[2c49fbbe] | 243 | "rsm %0;;\n" /* PSR_IC_MASK */
|
---|
[95042fd] | 244 | "srlz.d;;\n"
|
---|
| 245 | "srlz.i;;\n"
|
---|
| 246 | "mov cr.ifa=%1\n" /* va */
|
---|
| 247 | "mov cr.itir=%2;;\n" /* entry.word[1] */
|
---|
| 248 | "cmp.eq p6,p7 = %4,r0;;\n" /* decide between itc and dtc */
|
---|
| 249 | "(p6) itc.i %3;;\n"
|
---|
| 250 | "(p7) itc.d %3;;\n"
|
---|
| 251 | "mov psr.l=r8;;\n"
|
---|
| 252 | "srlz.d;;\n"
|
---|
| 253 | :
|
---|
[2c49fbbe] | 254 | : "i" (PSR_IC_MASK), "r" (va), "r" (entry.word[1]), "r" (entry.word[0]), "r" (dtc)
|
---|
| 255 | : "p6", "p7", "r8"
|
---|
[95042fd] | 256 | );
|
---|
| 257 |
|
---|
| 258 | if (restore_rr) {
|
---|
[a0d74fd] | 259 | rr_write(VA2VRN(va), rr.word);
|
---|
[95042fd] | 260 | srlz_d();
|
---|
| 261 | srlz_i();
|
---|
[bc78c75] | 262 | }
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[95042fd] | 265 | /** Insert data into instruction translation register.
|
---|
| 266 | *
|
---|
| 267 | * @param va Virtual page address.
|
---|
| 268 | * @param asid Address space identifier.
|
---|
| 269 | * @param entry The rest of TLB entry as required by TLB insertion format.
|
---|
| 270 | * @param tr Translation register.
|
---|
| 271 | */
|
---|
| 272 | void itr_mapping_insert(__address va, asid_t asid, tlb_entry_t entry, index_t tr)
|
---|
[bc78c75] | 273 | {
|
---|
[95042fd] | 274 | tr_mapping_insert(va, asid, entry, false, tr);
|
---|
[bc78c75] | 275 | }
|
---|
| 276 |
|
---|
[95042fd] | 277 | /** Insert data into data translation register.
|
---|
| 278 | *
|
---|
| 279 | * @param va Virtual page address.
|
---|
| 280 | * @param asid Address space identifier.
|
---|
| 281 | * @param entry The rest of TLB entry as required by TLB insertion format.
|
---|
| 282 | * @param tr Translation register.
|
---|
| 283 | */
|
---|
| 284 | void dtr_mapping_insert(__address va, asid_t asid, tlb_entry_t entry, index_t tr)
|
---|
| 285 | {
|
---|
| 286 | tr_mapping_insert(va, asid, entry, true, tr);
|
---|
| 287 | }
|
---|
[bc78c75] | 288 |
|
---|
[95042fd] | 289 | /** Insert data into instruction or data translation register.
|
---|
| 290 | *
|
---|
| 291 | * @param va Virtual page address.
|
---|
| 292 | * @param asid Address space identifier.
|
---|
| 293 | * @param entry The rest of TLB entry as required by TLB insertion format.
|
---|
| 294 | * @param dtc If true, insert into data translation register, use instruction translation register otherwise.
|
---|
| 295 | * @param tr Translation register.
|
---|
| 296 | */
|
---|
| 297 | void tr_mapping_insert(__address va, asid_t asid, tlb_entry_t entry, bool dtr, index_t tr)
|
---|
[89298e3] | 298 | {
|
---|
| 299 | region_register rr;
|
---|
[95042fd] | 300 | bool restore_rr = false;
|
---|
[89298e3] | 301 |
|
---|
[a0d74fd] | 302 | rr.word = rr_read(VA2VRN(va));
|
---|
| 303 | if ((restore_rr = (rr.map.rid != ASID2RID(asid, VA2VRN(va))))) {
|
---|
[95042fd] | 304 | /*
|
---|
| 305 | * The selected region register does not contain required RID.
|
---|
| 306 | * Save the old content of the register and replace the RID.
|
---|
| 307 | */
|
---|
[89298e3] | 308 | region_register rr0;
|
---|
[95042fd] | 309 |
|
---|
| 310 | rr0 = rr;
|
---|
[a0d74fd] | 311 | rr0.map.rid = ASID2RID(asid, VA2VRN(va));
|
---|
| 312 | rr_write(VA2VRN(va), rr0.word);
|
---|
[89298e3] | 313 | srlz_d();
|
---|
[95042fd] | 314 | srlz_i();
|
---|
[89298e3] | 315 | }
|
---|
| 316 |
|
---|
[95042fd] | 317 | __asm__ volatile (
|
---|
| 318 | "mov r8=psr;;\n"
|
---|
[2c49fbbe] | 319 | "rsm %0;;\n" /* PSR_IC_MASK */
|
---|
[95042fd] | 320 | "srlz.d;;\n"
|
---|
| 321 | "srlz.i;;\n"
|
---|
| 322 | "mov cr.ifa=%1\n" /* va */
|
---|
| 323 | "mov cr.itir=%2;;\n" /* entry.word[1] */
|
---|
| 324 | "cmp.eq p6,p7=%5,r0;;\n" /* decide between itr and dtr */
|
---|
| 325 | "(p6) itr.i itr[%4]=%3;;\n"
|
---|
| 326 | "(p7) itr.d dtr[%4]=%3;;\n"
|
---|
| 327 | "mov psr.l=r8;;\n"
|
---|
| 328 | "srlz.d;;\n"
|
---|
| 329 | :
|
---|
[2c49fbbe] | 330 | : "i" (PSR_IC_MASK), "r" (va), "r" (entry.word[1]), "r" (entry.word[0]), "r" (tr), "r" (dtr)
|
---|
| 331 | : "p6", "p7", "r8"
|
---|
[95042fd] | 332 | );
|
---|
| 333 |
|
---|
| 334 | if (restore_rr) {
|
---|
[a0d74fd] | 335 | rr_write(VA2VRN(va), rr.word);
|
---|
[95042fd] | 336 | srlz_d();
|
---|
| 337 | srlz_i();
|
---|
| 338 | }
|
---|
[89298e3] | 339 | }
|
---|
| 340 |
|
---|
[a0d74fd] | 341 | /** Insert data into DTLB.
|
---|
| 342 | *
|
---|
[208259c] | 343 | * @param page Virtual page address including VRN bits.
|
---|
| 344 | * @param frame Physical frame address.
|
---|
[a0d74fd] | 345 | * @param dtr If true, insert into data translation register, use data translation cache otherwise.
|
---|
| 346 | * @param tr Translation register if dtr is true, ignored otherwise.
|
---|
| 347 | */
|
---|
[9ad03fe] | 348 | void dtlb_kernel_mapping_insert(__address page, __address frame, bool dtr, index_t tr)
|
---|
[a0d74fd] | 349 | {
|
---|
| 350 | tlb_entry_t entry;
|
---|
| 351 |
|
---|
| 352 | entry.word[0] = 0;
|
---|
| 353 | entry.word[1] = 0;
|
---|
| 354 |
|
---|
| 355 | entry.p = true; /* present */
|
---|
| 356 | entry.ma = MA_WRITEBACK;
|
---|
| 357 | entry.a = true; /* already accessed */
|
---|
| 358 | entry.d = true; /* already dirty */
|
---|
| 359 | entry.pl = PL_KERNEL;
|
---|
| 360 | entry.ar = AR_READ | AR_WRITE;
|
---|
| 361 | entry.ppn = frame >> PPN_SHIFT;
|
---|
| 362 | entry.ps = PAGE_WIDTH;
|
---|
| 363 |
|
---|
| 364 | if (dtr)
|
---|
| 365 | dtr_mapping_insert(page, ASID_KERNEL, entry, tr);
|
---|
| 366 | else
|
---|
| 367 | dtc_mapping_insert(page, ASID_KERNEL, entry);
|
---|
| 368 | }
|
---|
| 369 |
|
---|
[208259c] | 370 | /** Purge kernel entries from DTR.
|
---|
| 371 | *
|
---|
| 372 | * Purge DTR entries used by the kernel.
|
---|
| 373 | *
|
---|
| 374 | * @param page Virtual page address including VRN bits.
|
---|
| 375 | * @param width Width of the purge in bits.
|
---|
| 376 | */
|
---|
| 377 | void dtr_purge(__address page, count_t width)
|
---|
| 378 | {
|
---|
| 379 | __asm__ volatile ("ptr.d %0, %1\n" : : "r" (page), "r" (width<<2));
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 |
|
---|
[9ad03fe] | 383 | /** Copy content of PTE into data translation cache.
|
---|
| 384 | *
|
---|
| 385 | * @param t PTE.
|
---|
| 386 | */
|
---|
| 387 | void dtc_pte_copy(pte_t *t)
|
---|
| 388 | {
|
---|
| 389 | tlb_entry_t entry;
|
---|
| 390 |
|
---|
| 391 | entry.word[0] = 0;
|
---|
| 392 | entry.word[1] = 0;
|
---|
| 393 |
|
---|
| 394 | entry.p = t->p;
|
---|
| 395 | entry.ma = t->c ? MA_WRITEBACK : MA_UNCACHEABLE;
|
---|
| 396 | entry.a = t->a;
|
---|
| 397 | entry.d = t->d;
|
---|
| 398 | entry.pl = t->k ? PL_KERNEL : PL_USER;
|
---|
| 399 | entry.ar = t->w ? AR_WRITE : AR_READ;
|
---|
| 400 | entry.ppn = t->frame >> PPN_SHIFT;
|
---|
| 401 | entry.ps = PAGE_WIDTH;
|
---|
| 402 |
|
---|
| 403 | dtc_mapping_insert(t->page, t->as->asid, entry);
|
---|
[68091bd] | 404 | #ifdef CONFIG_VHPT
|
---|
| 405 | vhpt_mapping_insert(t->page, t->as->asid, entry);
|
---|
| 406 | #endif
|
---|
[9ad03fe] | 407 | }
|
---|
| 408 |
|
---|
| 409 | /** Copy content of PTE into instruction translation cache.
|
---|
| 410 | *
|
---|
| 411 | * @param t PTE.
|
---|
| 412 | */
|
---|
| 413 | void itc_pte_copy(pte_t *t)
|
---|
| 414 | {
|
---|
| 415 | tlb_entry_t entry;
|
---|
| 416 |
|
---|
| 417 | entry.word[0] = 0;
|
---|
| 418 | entry.word[1] = 0;
|
---|
| 419 |
|
---|
| 420 | ASSERT(t->x);
|
---|
| 421 |
|
---|
| 422 | entry.p = t->p;
|
---|
| 423 | entry.ma = t->c ? MA_WRITEBACK : MA_UNCACHEABLE;
|
---|
| 424 | entry.a = t->a;
|
---|
| 425 | entry.pl = t->k ? PL_KERNEL : PL_USER;
|
---|
| 426 | entry.ar = t->x ? (AR_EXECUTE | AR_READ) : AR_READ;
|
---|
| 427 | entry.ppn = t->frame >> PPN_SHIFT;
|
---|
| 428 | entry.ps = PAGE_WIDTH;
|
---|
| 429 |
|
---|
| 430 | itc_mapping_insert(t->page, t->as->asid, entry);
|
---|
[68091bd] | 431 | #ifdef CONFIG_VHPT
|
---|
| 432 | vhpt_mapping_insert(t->page, t->as->asid, entry);
|
---|
| 433 | #endif
|
---|
[9ad03fe] | 434 | }
|
---|
| 435 |
|
---|
| 436 | /** Instruction TLB fault handler for faults with VHPT turned off.
|
---|
| 437 | *
|
---|
| 438 | * @param vector Interruption vector.
|
---|
[25d7709] | 439 | * @param istate Structure with saved interruption state.
|
---|
[9ad03fe] | 440 | */
|
---|
[25d7709] | 441 | void alternate_instruction_tlb_fault(__u64 vector, istate_t *istate)
|
---|
[89298e3] | 442 | {
|
---|
[9ad03fe] | 443 | region_register rr;
|
---|
[567807b1] | 444 | rid_t rid;
|
---|
[9ad03fe] | 445 | __address va;
|
---|
| 446 | pte_t *t;
|
---|
| 447 |
|
---|
[25d7709] | 448 | va = istate->cr_ifa; /* faulting address */
|
---|
[567807b1] | 449 | rr.word = rr_read(VA2VRN(va));
|
---|
| 450 | rid = rr.map.rid;
|
---|
| 451 |
|
---|
[2299914] | 452 | page_table_lock(AS, true);
|
---|
[9ad03fe] | 453 | t = page_mapping_find(AS, va);
|
---|
| 454 | if (t) {
|
---|
| 455 | /*
|
---|
| 456 | * The mapping was found in software page hash table.
|
---|
| 457 | * Insert it into data translation cache.
|
---|
| 458 | */
|
---|
| 459 | itc_pte_copy(t);
|
---|
[2299914] | 460 | page_table_unlock(AS, true);
|
---|
[9ad03fe] | 461 | } else {
|
---|
| 462 | /*
|
---|
| 463 | * Forward the page fault to address space page fault handler.
|
---|
| 464 | */
|
---|
[2299914] | 465 | page_table_unlock(AS, true);
|
---|
[567807b1] | 466 | if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) {
|
---|
[a175a67] | 467 | fault_if_from_uspace(istate,"Page fault at %P",va);
|
---|
[567807b1] | 468 | panic("%s: va=%p, rid=%d, iip=%p\n", __FUNCTION__, va, rid, istate->cr_iip);
|
---|
[9ad03fe] | 469 | }
|
---|
| 470 | }
|
---|
[95042fd] | 471 | }
|
---|
[89298e3] | 472 |
|
---|
[9ad03fe] | 473 | /** Data TLB fault handler for faults with VHPT turned off.
|
---|
[a0d74fd] | 474 | *
|
---|
| 475 | * @param vector Interruption vector.
|
---|
[25d7709] | 476 | * @param istate Structure with saved interruption state.
|
---|
[a0d74fd] | 477 | */
|
---|
[25d7709] | 478 | void alternate_data_tlb_fault(__u64 vector, istate_t *istate)
|
---|
[95042fd] | 479 | {
|
---|
[a0d74fd] | 480 | region_register rr;
|
---|
| 481 | rid_t rid;
|
---|
| 482 | __address va;
|
---|
[9ad03fe] | 483 | pte_t *t;
|
---|
[a0d74fd] | 484 |
|
---|
[25d7709] | 485 | va = istate->cr_ifa; /* faulting address */
|
---|
[a0d74fd] | 486 | rr.word = rr_read(VA2VRN(va));
|
---|
| 487 | rid = rr.map.rid;
|
---|
| 488 | if (RID2ASID(rid) == ASID_KERNEL) {
|
---|
| 489 | if (VA2VRN(va) == VRN_KERNEL) {
|
---|
| 490 | /*
|
---|
| 491 | * Provide KA2PA(identity) mapping for faulting piece of
|
---|
| 492 | * kernel address space.
|
---|
| 493 | */
|
---|
[9ad03fe] | 494 | dtlb_kernel_mapping_insert(va, KA2PA(va), false, 0);
|
---|
[a0d74fd] | 495 | return;
|
---|
| 496 | }
|
---|
| 497 | }
|
---|
[b994a60] | 498 |
|
---|
[2299914] | 499 | page_table_lock(AS, true);
|
---|
[9ad03fe] | 500 | t = page_mapping_find(AS, va);
|
---|
| 501 | if (t) {
|
---|
| 502 | /*
|
---|
| 503 | * The mapping was found in software page hash table.
|
---|
| 504 | * Insert it into data translation cache.
|
---|
| 505 | */
|
---|
| 506 | dtc_pte_copy(t);
|
---|
[2299914] | 507 | page_table_unlock(AS, true);
|
---|
[9ad03fe] | 508 | } else {
|
---|
| 509 | /*
|
---|
| 510 | * Forward the page fault to address space page fault handler.
|
---|
| 511 | */
|
---|
[2299914] | 512 | page_table_unlock(AS, true);
|
---|
[567807b1] | 513 | if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
|
---|
[a175a67] | 514 | fault_if_from_uspace(istate,"Page fault at %P",va);
|
---|
[cf85e24c] | 515 | panic("%s: va=%p, rid=%d, iip=%p\n", __FUNCTION__, va, rid, istate->cr_iip);
|
---|
[9ad03fe] | 516 | }
|
---|
| 517 | }
|
---|
[95042fd] | 518 | }
|
---|
[89298e3] | 519 |
|
---|
[9ad03fe] | 520 | /** Data nested TLB fault handler.
|
---|
| 521 | *
|
---|
| 522 | * This fault should not occur.
|
---|
| 523 | *
|
---|
| 524 | * @param vector Interruption vector.
|
---|
[25d7709] | 525 | * @param istate Structure with saved interruption state.
|
---|
[9ad03fe] | 526 | */
|
---|
[25d7709] | 527 | void data_nested_tlb_fault(__u64 vector, istate_t *istate)
|
---|
[95042fd] | 528 | {
|
---|
| 529 | panic("%s\n", __FUNCTION__);
|
---|
| 530 | }
|
---|
[89298e3] | 531 |
|
---|
[9ad03fe] | 532 | /** Data Dirty bit fault handler.
|
---|
| 533 | *
|
---|
| 534 | * @param vector Interruption vector.
|
---|
[25d7709] | 535 | * @param istate Structure with saved interruption state.
|
---|
[9ad03fe] | 536 | */
|
---|
[25d7709] | 537 | void data_dirty_bit_fault(__u64 vector, istate_t *istate)
|
---|
[95042fd] | 538 | {
|
---|
[567807b1] | 539 | region_register rr;
|
---|
| 540 | rid_t rid;
|
---|
| 541 | __address va;
|
---|
[9ad03fe] | 542 | pte_t *t;
|
---|
[567807b1] | 543 |
|
---|
| 544 | va = istate->cr_ifa; /* faulting address */
|
---|
| 545 | rr.word = rr_read(VA2VRN(va));
|
---|
| 546 | rid = rr.map.rid;
|
---|
[9ad03fe] | 547 |
|
---|
[2299914] | 548 | page_table_lock(AS, true);
|
---|
[567807b1] | 549 | t = page_mapping_find(AS, va);
|
---|
[9ad03fe] | 550 | ASSERT(t && t->p);
|
---|
[567807b1] | 551 | if (t && t->p && t->w) {
|
---|
[9ad03fe] | 552 | /*
|
---|
| 553 | * Update the Dirty bit in page tables and reinsert
|
---|
| 554 | * the mapping into DTC.
|
---|
| 555 | */
|
---|
| 556 | t->d = true;
|
---|
| 557 | dtc_pte_copy(t);
|
---|
[567807b1] | 558 | } else {
|
---|
| 559 | if (as_page_fault(va, PF_ACCESS_WRITE, istate) == AS_PF_FAULT) {
|
---|
[a175a67] | 560 | fault_if_from_uspace(istate,"Page fault at %P",va);
|
---|
[567807b1] | 561 | panic("%s: va=%p, rid=%d, iip=%p\n", __FUNCTION__, va, rid, istate->cr_iip);
|
---|
| 562 | t->d = true;
|
---|
| 563 | dtc_pte_copy(t);
|
---|
| 564 | }
|
---|
[9ad03fe] | 565 | }
|
---|
[2299914] | 566 | page_table_unlock(AS, true);
|
---|
[95042fd] | 567 | }
|
---|
[89298e3] | 568 |
|
---|
[9ad03fe] | 569 | /** Instruction access bit fault handler.
|
---|
| 570 | *
|
---|
| 571 | * @param vector Interruption vector.
|
---|
[25d7709] | 572 | * @param istate Structure with saved interruption state.
|
---|
[9ad03fe] | 573 | */
|
---|
[25d7709] | 574 | void instruction_access_bit_fault(__u64 vector, istate_t *istate)
|
---|
[95042fd] | 575 | {
|
---|
[567807b1] | 576 | region_register rr;
|
---|
| 577 | rid_t rid;
|
---|
| 578 | __address va;
|
---|
| 579 | pte_t *t;
|
---|
| 580 |
|
---|
| 581 | va = istate->cr_ifa; /* faulting address */
|
---|
| 582 | rr.word = rr_read(VA2VRN(va));
|
---|
| 583 | rid = rr.map.rid;
|
---|
[9ad03fe] | 584 |
|
---|
[2299914] | 585 | page_table_lock(AS, true);
|
---|
[567807b1] | 586 | t = page_mapping_find(AS, va);
|
---|
[9ad03fe] | 587 | ASSERT(t && t->p);
|
---|
[567807b1] | 588 | if (t && t->p && t->x) {
|
---|
[9ad03fe] | 589 | /*
|
---|
| 590 | * Update the Accessed bit in page tables and reinsert
|
---|
| 591 | * the mapping into ITC.
|
---|
| 592 | */
|
---|
| 593 | t->a = true;
|
---|
| 594 | itc_pte_copy(t);
|
---|
[567807b1] | 595 | } else {
|
---|
| 596 | if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) {
|
---|
[a175a67] | 597 | fault_if_from_uspace(istate,"Page fault at %P",va);
|
---|
[567807b1] | 598 | panic("%s: va=%p, rid=%d, iip=%p\n", __FUNCTION__, va, rid, istate->cr_iip);
|
---|
| 599 | t->a = true;
|
---|
| 600 | itc_pte_copy(t);
|
---|
| 601 | }
|
---|
[9ad03fe] | 602 | }
|
---|
[2299914] | 603 | page_table_unlock(AS, true);
|
---|
[95042fd] | 604 | }
|
---|
[89298e3] | 605 |
|
---|
[9ad03fe] | 606 | /** Data access bit fault handler.
|
---|
| 607 | *
|
---|
| 608 | * @param vector Interruption vector.
|
---|
[25d7709] | 609 | * @param istate Structure with saved interruption state.
|
---|
[9ad03fe] | 610 | */
|
---|
[25d7709] | 611 | void data_access_bit_fault(__u64 vector, istate_t *istate)
|
---|
[95042fd] | 612 | {
|
---|
[567807b1] | 613 | region_register rr;
|
---|
| 614 | rid_t rid;
|
---|
| 615 | __address va;
|
---|
[9ad03fe] | 616 | pte_t *t;
|
---|
| 617 |
|
---|
[567807b1] | 618 | va = istate->cr_ifa; /* faulting address */
|
---|
| 619 | rr.word = rr_read(VA2VRN(va));
|
---|
| 620 | rid = rr.map.rid;
|
---|
| 621 |
|
---|
[2299914] | 622 | page_table_lock(AS, true);
|
---|
[567807b1] | 623 | t = page_mapping_find(AS, va);
|
---|
[9ad03fe] | 624 | ASSERT(t && t->p);
|
---|
| 625 | if (t && t->p) {
|
---|
| 626 | /*
|
---|
| 627 | * Update the Accessed bit in page tables and reinsert
|
---|
| 628 | * the mapping into DTC.
|
---|
| 629 | */
|
---|
| 630 | t->a = true;
|
---|
| 631 | dtc_pte_copy(t);
|
---|
[567807b1] | 632 | } else {
|
---|
| 633 | if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
|
---|
[a175a67] | 634 | fault_if_from_uspace(istate,"Page fault at %P",va);
|
---|
[567807b1] | 635 | panic("%s: va=%p, rid=%d, iip=%p\n", __FUNCTION__, va, rid, istate->cr_iip);
|
---|
| 636 | t->a = true;
|
---|
| 637 | itc_pte_copy(t);
|
---|
| 638 | }
|
---|
[9ad03fe] | 639 | }
|
---|
[2299914] | 640 | page_table_unlock(AS, true);
|
---|
[89298e3] | 641 | }
|
---|
| 642 |
|
---|
[9ad03fe] | 643 | /** Page not present fault handler.
|
---|
| 644 | *
|
---|
| 645 | * @param vector Interruption vector.
|
---|
[25d7709] | 646 | * @param istate Structure with saved interruption state.
|
---|
[9ad03fe] | 647 | */
|
---|
[25d7709] | 648 | void page_not_present(__u64 vector, istate_t *istate)
|
---|
[95042fd] | 649 | {
|
---|
[9ad03fe] | 650 | region_register rr;
|
---|
[567807b1] | 651 | rid_t rid;
|
---|
[9ad03fe] | 652 | __address va;
|
---|
| 653 | pte_t *t;
|
---|
| 654 |
|
---|
[25d7709] | 655 | va = istate->cr_ifa; /* faulting address */
|
---|
[567807b1] | 656 | rr.word = rr_read(VA2VRN(va));
|
---|
| 657 | rid = rr.map.rid;
|
---|
| 658 |
|
---|
[2299914] | 659 | page_table_lock(AS, true);
|
---|
[9ad03fe] | 660 | t = page_mapping_find(AS, va);
|
---|
| 661 | ASSERT(t);
|
---|
| 662 |
|
---|
| 663 | if (t->p) {
|
---|
| 664 | /*
|
---|
| 665 | * If the Present bit is set in page hash table, just copy it
|
---|
| 666 | * and update ITC/DTC.
|
---|
| 667 | */
|
---|
| 668 | if (t->x)
|
---|
| 669 | itc_pte_copy(t);
|
---|
| 670 | else
|
---|
| 671 | dtc_pte_copy(t);
|
---|
[2299914] | 672 | page_table_unlock(AS, true);
|
---|
[9ad03fe] | 673 | } else {
|
---|
[2299914] | 674 | page_table_unlock(AS, true);
|
---|
[567807b1] | 675 | if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
|
---|
[a175a67] | 676 | fault_if_from_uspace(istate,"Page fault at %P",va);
|
---|
[567807b1] | 677 | panic("%s: va=%p, rid=%d\n", __FUNCTION__, va, rid);
|
---|
[9ad03fe] | 678 | }
|
---|
| 679 | }
|
---|
[95042fd] | 680 | }
|
---|