[0d04024] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 Jakub Jermar
|
---|
[3da11f37] | 3 | * Copyright (c) 2008 Pavel Rimsky
|
---|
[0d04024] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[7008097] | 30 | /** @addtogroup sparc64mm
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[0d04024] | 36 | #include <mm/tlb.h>
|
---|
[f47fd19] | 37 | #include <mm/as.h>
|
---|
| 38 | #include <mm/asid.h>
|
---|
[b4655da] | 39 | #include <arch/sun4v/hypercall.h>
|
---|
[0cfc4d38] | 40 | #include <arch/mm/frame.h>
|
---|
| 41 | #include <arch/mm/page.h>
|
---|
[b4655da] | 42 | #include <arch/mm/tte.h>
|
---|
| 43 | #include <arch/mm/tlb.h>
|
---|
[f47fd19] | 44 | #include <arch/interrupt.h>
|
---|
[e2bf639] | 45 | #include <interrupt.h>
|
---|
[f47fd19] | 46 | #include <arch.h>
|
---|
[0d04024] | 47 | #include <print.h>
|
---|
[d99c1d2] | 48 | #include <typedefs.h>
|
---|
[0cfc4d38] | 49 | #include <config.h>
|
---|
[49b6d32] | 50 | #include <arch/trap/trap.h>
|
---|
[7bb6b06] | 51 | #include <arch/trap/exception.h>
|
---|
[008029d] | 52 | #include <panic.h>
|
---|
[b6fba84] | 53 | #include <arch/asm.h>
|
---|
[3da11f37] | 54 | #include <arch/cpu.h>
|
---|
| 55 | #include <arch/mm/pagesize.h>
|
---|
[387416b] | 56 | #include <genarch/mm/page_ht.h>
|
---|
[02f441c0] | 57 |
|
---|
[29b2bbf] | 58 | #ifdef CONFIG_TSB
|
---|
| 59 | #include <arch/mm/tsb.h>
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
[ba50a34] | 62 | static void itlb_pte_copy(pte_t *);
|
---|
[77f65df] | 63 | static void dtlb_pte_copy(pte_t *, bool);
|
---|
[7008097] | 64 | static void do_fast_instruction_access_mmu_miss_fault(istate_t *, uintptr_t,
|
---|
| 65 | const char *);
|
---|
[77f65df] | 66 | static void do_fast_data_access_mmu_miss_fault(istate_t *, uint64_t,
|
---|
| 67 | const char *);
|
---|
[5e53e02] | 68 | static void do_fast_data_access_protection_fault(istate_t *,
|
---|
| 69 | uint64_t, const char *);
|
---|
| 70 |
|
---|
| 71 | /*
|
---|
| 72 | * The assembly language routine passes a 64-bit parameter to the Data Access
|
---|
| 73 | * MMU Miss and Data Access protection handlers, the parameter encapsulates
|
---|
| 74 | * a virtual address of the faulting page and the faulting context. The most
|
---|
| 75 | * significant 51 bits represent the VA of the faulting page and the least
|
---|
| 76 | * significant 13 vits represent the faulting context. The following macros
|
---|
| 77 | * extract the page and context out of the 64-bit parameter:
|
---|
| 78 | */
|
---|
| 79 |
|
---|
| 80 | /* extracts the VA of the faulting page */
|
---|
| 81 | #define DMISS_ADDRESS(page_and_ctx) (((page_and_ctx) >> 13) << 13)
|
---|
| 82 |
|
---|
| 83 | /* extracts the faulting context */
|
---|
| 84 | #define DMISS_CONTEXT(page_and_ctx) ((page_and_ctx) & 0x1fff)
|
---|
[f47fd19] | 85 |
|
---|
[77f65df] | 86 | /**
|
---|
| 87 | * Descriptions of fault types from the MMU Fault status area.
|
---|
| 88 | *
|
---|
| 89 | * fault_type[i] contains description of error for which the IFT or DFT
|
---|
| 90 | * field of the MMU fault status area is i.
|
---|
| 91 | */
|
---|
[a000878c] | 92 | static const char *fault_types[] = {
|
---|
[77f65df] | 93 | "unknown",
|
---|
| 94 | "fast miss",
|
---|
| 95 | "fast protection",
|
---|
| 96 | "MMU miss",
|
---|
| 97 | "invalid RA",
|
---|
| 98 | "privileged violation",
|
---|
| 99 | "protection violation",
|
---|
| 100 | "NFO access",
|
---|
| 101 | "so page/NFO side effect",
|
---|
| 102 | "invalid VA",
|
---|
| 103 | "invalid ASI",
|
---|
| 104 | "nc atomic",
|
---|
| 105 | "privileged action",
|
---|
| 106 | "unknown",
|
---|
| 107 | "unaligned access",
|
---|
| 108 | "invalid page size"
|
---|
| 109 | };
|
---|
[0d04024] | 110 |
|
---|
[77f65df] | 111 | /** Array of MMU fault status areas. */
|
---|
| 112 | extern mmu_fault_status_area_t mmu_fsas[MAX_NUM_STRANDS];
|
---|
[b4655da] | 113 |
|
---|
[77f65df] | 114 | /*
|
---|
| 115 | * Invalidate all non-locked DTLB and ITLB entries.
|
---|
| 116 | */
|
---|
[0d04024] | 117 | void tlb_arch_init(void)
|
---|
| 118 | {
|
---|
[b4655da] | 119 | tlb_invalidate_all();
|
---|
[97f1691] | 120 | }
|
---|
[b6fba84] | 121 |
|
---|
[97f1691] | 122 | /** Insert privileged mapping into DMMU TLB.
|
---|
| 123 | *
|
---|
[965dc18] | 124 | * @param page Virtual page address.
|
---|
| 125 | * @param frame Physical frame address.
|
---|
| 126 | * @param pagesize Page size.
|
---|
| 127 | * @param locked True for permanent mappings, false otherwise.
|
---|
| 128 | * @param cacheable True if the mapping is cacheable, false otherwise.
|
---|
[97f1691] | 129 | */
|
---|
[2057572] | 130 | void dtlb_insert_mapping(uintptr_t page, uintptr_t frame, int pagesize,
|
---|
| 131 | bool locked, bool cacheable)
|
---|
[97f1691] | 132 | {
|
---|
[77f65df] | 133 | tte_data_t data;
|
---|
| 134 |
|
---|
[02f441c0] | 135 | data.value = 0;
|
---|
| 136 | data.v = true;
|
---|
[77f65df] | 137 | data.nfo = false;
|
---|
| 138 | data.ra = frame >> FRAME_WIDTH;
|
---|
| 139 | data.ie = false;
|
---|
| 140 | data.e = false;
|
---|
[97f1691] | 141 | data.cp = cacheable;
|
---|
[92778f2] | 142 | #ifdef CONFIG_VIRT_IDX_DCACHE
|
---|
[97f1691] | 143 | data.cv = cacheable;
|
---|
[77f65df] | 144 | #endif
|
---|
[02f441c0] | 145 | data.p = true;
|
---|
[77f65df] | 146 | data.x = false;
|
---|
[02f441c0] | 147 | data.w = true;
|
---|
[77f65df] | 148 | data.size = pagesize;
|
---|
| 149 |
|
---|
| 150 | if (locked) {
|
---|
| 151 | __hypercall_fast4(
|
---|
| 152 | MMU_MAP_PERM_ADDR, page, 0, data.value, MMU_FLAG_DTLB);
|
---|
| 153 | } else {
|
---|
| 154 | __hypercall_hyperfast(
|
---|
| 155 | page, ASID_KERNEL, data.value, MMU_FLAG_DTLB, 0,
|
---|
| 156 | MMU_MAP_ADDR);
|
---|
| 157 | }
|
---|
[0d04024] | 158 | }
|
---|
| 159 |
|
---|
[a7961271] | 160 | /** Copy PTE to TLB.
|
---|
| 161 | *
|
---|
[965dc18] | 162 | * @param t Page Table Entry to be copied.
|
---|
| 163 | * @param ro If true, the entry will be created read-only, regardless
|
---|
| 164 | * of its w field.
|
---|
[a7961271] | 165 | */
|
---|
[5e53e02] | 166 | void dtlb_pte_copy(pte_t *t, bool ro)
|
---|
[a7961271] | 167 | {
|
---|
[5e53e02] | 168 | tte_data_t data;
|
---|
| 169 |
|
---|
[a7961271] | 170 | data.value = 0;
|
---|
| 171 | data.v = true;
|
---|
[5e53e02] | 172 | data.nfo = false;
|
---|
| 173 | data.ra = (t->frame) >> FRAME_WIDTH;
|
---|
| 174 | data.ie = false;
|
---|
| 175 | data.e = false;
|
---|
[a7961271] | 176 | data.cp = t->c;
|
---|
[92778f2] | 177 | #ifdef CONFIG_VIRT_IDX_DCACHE
|
---|
[a7961271] | 178 | data.cv = t->c;
|
---|
[5e53e02] | 179 | #endif
|
---|
| 180 | data.p = t->k;
|
---|
| 181 | data.x = false;
|
---|
[a7961271] | 182 | data.w = ro ? false : t->w;
|
---|
[5e53e02] | 183 | data.size = PAGESIZE_8K;
|
---|
| 184 |
|
---|
| 185 | __hypercall_hyperfast(
|
---|
| 186 | t->page, t->as->asid, data.value, MMU_FLAG_DTLB, 0, MMU_MAP_ADDR);
|
---|
[a7961271] | 187 | }
|
---|
[5e53e02] | 188 |
|
---|
[29b2bbf] | 189 | /** Copy PTE to ITLB.
|
---|
| 190 | *
|
---|
[965dc18] | 191 | * @param t Page Table Entry to be copied.
|
---|
[29b2bbf] | 192 | */
|
---|
[ba50a34] | 193 | void itlb_pte_copy(pte_t *t)
|
---|
[f47fd19] | 194 | {
|
---|
[ba50a34] | 195 | tte_data_t data;
|
---|
[a7961271] | 196 |
|
---|
| 197 | data.value = 0;
|
---|
| 198 | data.v = true;
|
---|
[ba50a34] | 199 | data.nfo = false;
|
---|
| 200 | data.ra = (t->frame) >> FRAME_WIDTH;
|
---|
| 201 | data.ie = false;
|
---|
| 202 | data.e = false;
|
---|
[a7961271] | 203 | data.cp = t->c;
|
---|
[ba50a34] | 204 | data.cv = false;
|
---|
| 205 | data.p = t->k;
|
---|
| 206 | data.x = true;
|
---|
[a7961271] | 207 | data.w = false;
|
---|
[ba50a34] | 208 | data.size = PAGESIZE_8K;
|
---|
[a7961271] | 209 |
|
---|
[ba50a34] | 210 | __hypercall_hyperfast(
|
---|
| 211 | t->page, t->as->asid, data.value, MMU_FLAG_ITLB, 0, MMU_MAP_ADDR);
|
---|
[f47fd19] | 212 | }
|
---|
| 213 |
|
---|
[008029d] | 214 | /** ITLB miss handler. */
|
---|
[96b02eb9] | 215 | void fast_instruction_access_mmu_miss(sysarg_t unused, istate_t *istate)
|
---|
[008029d] | 216 | {
|
---|
[ba50a34] | 217 | uintptr_t va = ALIGN_DOWN(istate->tpc, PAGE_SIZE);
|
---|
[a7961271] | 218 | pte_t *t;
|
---|
| 219 |
|
---|
| 220 | page_table_lock(AS, true);
|
---|
[ba50a34] | 221 | t = page_mapping_find(AS, va);
|
---|
| 222 |
|
---|
[a7961271] | 223 | if (t && PTE_EXECUTABLE(t)) {
|
---|
| 224 | /*
|
---|
| 225 | * The mapping was found in the software page hash table.
|
---|
| 226 | * Insert it into ITLB.
|
---|
| 227 | */
|
---|
| 228 | t->a = true;
|
---|
[ba50a34] | 229 | itlb_pte_copy(t);
|
---|
[29b2bbf] | 230 | #ifdef CONFIG_TSB
|
---|
[ba50a34] | 231 | itsb_pte_copy(t);
|
---|
[29b2bbf] | 232 | #endif
|
---|
[a7961271] | 233 | page_table_unlock(AS, true);
|
---|
| 234 | } else {
|
---|
| 235 | /*
|
---|
[771cd22] | 236 | * Forward the page fault to the address space page fault
|
---|
| 237 | * handler.
|
---|
[7008097] | 238 | */
|
---|
[a7961271] | 239 | page_table_unlock(AS, true);
|
---|
[ba50a34] | 240 | if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) {
|
---|
[771cd22] | 241 | do_fast_instruction_access_mmu_miss_fault(istate,
|
---|
[7008097] | 242 | istate->tpc, __func__);
|
---|
[a7961271] | 243 | }
|
---|
| 244 | }
|
---|
[008029d] | 245 | }
|
---|
| 246 |
|
---|
[f47fd19] | 247 | /** DTLB miss handler.
|
---|
| 248 | *
|
---|
[771cd22] | 249 | * Note that some faults (e.g. kernel faults) were already resolved by the
|
---|
| 250 | * low-level, assembly language part of the fast_data_access_mmu_miss handler.
|
---|
[36f19c0] | 251 | *
|
---|
[ba50a34] | 252 | * @param page_and_ctx A 64-bit value describing the fault. The most
|
---|
| 253 | * significant 51 bits of the value contain the virtual
|
---|
| 254 | * address which caused the fault truncated to the page
|
---|
| 255 | * boundary. The least significant 13 bits of the value
|
---|
| 256 | * contain the number of the context in which the fault
|
---|
| 257 | * occurred.
|
---|
[965dc18] | 258 | * @param istate Interrupted state saved on the stack.
|
---|
[f47fd19] | 259 | */
|
---|
[ba50a34] | 260 | void fast_data_access_mmu_miss(uint64_t page_and_ctx, istate_t *istate)
|
---|
[008029d] | 261 | {
|
---|
[f47fd19] | 262 | pte_t *t;
|
---|
[ba50a34] | 263 | uintptr_t va = DMISS_ADDRESS(page_and_ctx);
|
---|
| 264 | uint16_t ctx = DMISS_CONTEXT(page_and_ctx);
|
---|
[7cb53f62] | 265 |
|
---|
[ba50a34] | 266 | if (ctx == ASID_KERNEL) {
|
---|
| 267 | if (va == 0) {
|
---|
[f47fd19] | 268 | /* NULL access in kernel */
|
---|
[ba50a34] | 269 | do_fast_data_access_mmu_miss_fault(istate, page_and_ctx,
|
---|
[3ee8a075] | 270 | __func__);
|
---|
[f47fd19] | 271 | }
|
---|
[ba50a34] | 272 | do_fast_data_access_mmu_miss_fault(istate, page_and_ctx, "Unexpected "
|
---|
[2057572] | 273 | "kernel page fault.");
|
---|
[68656282] | 274 | }
|
---|
| 275 |
|
---|
[f47fd19] | 276 | page_table_lock(AS, true);
|
---|
[ba50a34] | 277 | t = page_mapping_find(AS, va);
|
---|
[f47fd19] | 278 | if (t) {
|
---|
| 279 | /*
|
---|
| 280 | * The mapping was found in the software page hash table.
|
---|
| 281 | * Insert it into DTLB.
|
---|
| 282 | */
|
---|
[a7961271] | 283 | t->a = true;
|
---|
[ba50a34] | 284 | dtlb_pte_copy(t, true);
|
---|
[29b2bbf] | 285 | #ifdef CONFIG_TSB
|
---|
[ba50a34] | 286 | dtsb_pte_copy(t, true);
|
---|
[29b2bbf] | 287 | #endif
|
---|
[f47fd19] | 288 | page_table_unlock(AS, true);
|
---|
| 289 | } else {
|
---|
| 290 | /*
|
---|
[2057572] | 291 | * Forward the page fault to the address space page fault
|
---|
| 292 | * handler.
|
---|
[f47fd19] | 293 | */
|
---|
| 294 | page_table_unlock(AS, true);
|
---|
[ba50a34] | 295 | if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
|
---|
| 296 | do_fast_data_access_mmu_miss_fault(istate, page_and_ctx,
|
---|
[3ee8a075] | 297 | __func__);
|
---|
[f47fd19] | 298 | }
|
---|
| 299 | }
|
---|
[008029d] | 300 | }
|
---|
| 301 |
|
---|
[36f19c0] | 302 | /** DTLB protection fault handler.
|
---|
| 303 | *
|
---|
[5e53e02] | 304 | * @param page_and_ctx A 64-bit value describing the fault. The most
|
---|
| 305 | * significant 51 bits of the value contain the virtual
|
---|
| 306 | * address which caused the fault truncated to the page
|
---|
| 307 | * boundary. The least significant 13 bits of the value
|
---|
| 308 | * contain the number of the context in which the fault
|
---|
| 309 | * occurred.
|
---|
[965dc18] | 310 | * @param istate Interrupted state saved on the stack.
|
---|
[36f19c0] | 311 | */
|
---|
[ba50a34] | 312 | void fast_data_access_protection(uint64_t page_and_ctx, istate_t *istate)
|
---|
[008029d] | 313 | {
|
---|
[e0b241f] | 314 | pte_t *t;
|
---|
[ba50a34] | 315 | uintptr_t va = DMISS_ADDRESS(page_and_ctx);
|
---|
| 316 | uint16_t ctx = DMISS_CONTEXT(page_and_ctx);
|
---|
[e0b241f] | 317 |
|
---|
| 318 | page_table_lock(AS, true);
|
---|
[ba50a34] | 319 | t = page_mapping_find(AS, va);
|
---|
[e0b241f] | 320 | if (t && PTE_WRITABLE(t)) {
|
---|
| 321 | /*
|
---|
[771cd22] | 322 | * The mapping was found in the software page hash table and is
|
---|
| 323 | * writable. Demap the old mapping and insert an updated mapping
|
---|
| 324 | * into DTLB.
|
---|
[e0b241f] | 325 | */
|
---|
| 326 | t->a = true;
|
---|
| 327 | t->d = true;
|
---|
[ba50a34] | 328 | mmu_demap_page(va, ctx, MMU_FLAG_DTLB);
|
---|
| 329 | dtlb_pte_copy(t, false);
|
---|
[29b2bbf] | 330 | #ifdef CONFIG_TSB
|
---|
[ba50a34] | 331 | dtsb_pte_copy(t, false);
|
---|
[29b2bbf] | 332 | #endif
|
---|
[e0b241f] | 333 | page_table_unlock(AS, true);
|
---|
| 334 | } else {
|
---|
| 335 | /*
|
---|
[771cd22] | 336 | * Forward the page fault to the address space page fault
|
---|
| 337 | * handler.
|
---|
[e0b241f] | 338 | */
|
---|
| 339 | page_table_unlock(AS, true);
|
---|
[5e53e02] | 340 | if (as_page_fault(va, PF_ACCESS_WRITE, istate) == AS_PF_FAULT) {
|
---|
| 341 | do_fast_data_access_protection_fault(istate, page_and_ctx,
|
---|
[3ee8a075] | 342 | __func__);
|
---|
[e0b241f] | 343 | }
|
---|
| 344 | }
|
---|
[008029d] | 345 | }
|
---|
| 346 |
|
---|
[77f65df] | 347 | /*
|
---|
| 348 | * On Niagara this function does not work, as supervisor software is isolated
|
---|
| 349 | * from the TLB by the hypervisor and has no chance to investigate the TLB
|
---|
| 350 | * entries.
|
---|
[965dc18] | 351 | */
|
---|
[0d04024] | 352 | void tlb_print(void)
|
---|
| 353 | {
|
---|
[ba50a34] | 354 | printf("Operation not possible on Niagara.\n");
|
---|
[0d04024] | 355 | }
|
---|
[dbb6886] | 356 |
|
---|
[7008097] | 357 | void do_fast_instruction_access_mmu_miss_fault(istate_t *istate, uintptr_t va,
|
---|
[2057572] | 358 | const char *str)
|
---|
[a7961271] | 359 | {
|
---|
[7e752b2] | 360 | fault_if_from_uspace(istate, "%s, address=%p.", str,
|
---|
| 361 | (void *) va);
|
---|
[c15b374] | 362 | panic_memtrap(istate, PF_ACCESS_EXEC, va, str);
|
---|
[a7961271] | 363 | }
|
---|
| 364 |
|
---|
[2057572] | 365 | void do_fast_data_access_mmu_miss_fault(istate_t *istate,
|
---|
[ba50a34] | 366 | uint64_t page_and_ctx, const char *str)
|
---|
[f47fd19] | 367 | {
|
---|
[7e752b2] | 368 | fault_if_from_uspace(istate, "%s, page=%p (asid=%" PRId64 ").", str,
|
---|
| 369 | (void *) DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
|
---|
[c15b374] | 370 | panic_memtrap(istate, PF_ACCESS_UNKNOWN, DMISS_ADDRESS(page_and_ctx),
|
---|
| 371 | str);
|
---|
[f47fd19] | 372 | }
|
---|
| 373 |
|
---|
[2057572] | 374 | void do_fast_data_access_protection_fault(istate_t *istate,
|
---|
[ba50a34] | 375 | uint64_t page_and_ctx, const char *str)
|
---|
[e0b241f] | 376 | {
|
---|
[7e752b2] | 377 | fault_if_from_uspace(istate, "%s, page=%p (asid=%" PRId64 ").", str,
|
---|
| 378 | (void *) DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
|
---|
[7008097] | 379 | panic_memtrap(istate, PF_ACCESS_WRITE, DMISS_ADDRESS(page_and_ctx),
|
---|
[c15b374] | 380 | str);
|
---|
[e0b241f] | 381 | }
|
---|
| 382 |
|
---|
[ba50a34] | 383 | /**
|
---|
| 384 | * Describes the exact condition which caused the last DMMU fault.
|
---|
| 385 | */
|
---|
| 386 | void describe_dmmu_fault(void)
|
---|
[8cee705] | 387 | {
|
---|
[ba50a34] | 388 | uint64_t myid;
|
---|
| 389 | __hypercall_fast_ret1(0, 0, 0, 0, 0, CPU_MYID, &myid);
|
---|
[8cee705] | 390 |
|
---|
[ba50a34] | 391 | ASSERT(mmu_fsas[myid].dft < 16);
|
---|
| 392 |
|
---|
| 393 | printf("condition which caused the fault: %s\n",
|
---|
| 394 | fault_types[mmu_fsas[myid].dft]);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | /** Invalidate all unlocked ITLB and DTLB entries. */
|
---|
| 398 | void tlb_invalidate_all(void)
|
---|
| 399 | {
|
---|
| 400 | uint64_t errno = __hypercall_fast3(MMU_DEMAP_ALL, 0, 0,
|
---|
| 401 | MMU_FLAG_DTLB | MMU_FLAG_ITLB);
|
---|
[7e752b2] | 402 | if (errno != HV_EOK)
|
---|
| 403 | panic("Error code = %" PRIu64 ".\n", errno);
|
---|
[8cee705] | 404 | }
|
---|
| 405 |
|
---|
[771cd22] | 406 | /** Invalidate all ITLB and DTLB entries that belong to specified ASID
|
---|
| 407 | * (Context).
|
---|
[dbb6886] | 408 | *
|
---|
| 409 | * @param asid Address Space ID.
|
---|
| 410 | */
|
---|
| 411 | void tlb_invalidate_asid(asid_t asid)
|
---|
| 412 | {
|
---|
[fd85ae5] | 413 | /* switch to nucleus because we are mapped by the primary context */
|
---|
| 414 | nucleus_enter();
|
---|
[77f65df] | 415 |
|
---|
[3da11f37] | 416 | __hypercall_fast4(MMU_DEMAP_CTX, 0, 0, asid,
|
---|
| 417 | MMU_FLAG_ITLB | MMU_FLAG_DTLB);
|
---|
| 418 |
|
---|
[fd85ae5] | 419 | nucleus_leave();
|
---|
[dbb6886] | 420 | }
|
---|
| 421 |
|
---|
[771cd22] | 422 | /** Invalidate all ITLB and DTLB entries for specified page range in specified
|
---|
| 423 | * address space.
|
---|
[dbb6886] | 424 | *
|
---|
[965dc18] | 425 | * @param asid Address Space ID.
|
---|
| 426 | * @param page First page which to sweep out from ITLB and DTLB.
|
---|
| 427 | * @param cnt Number of ITLB and DTLB entries to invalidate.
|
---|
[dbb6886] | 428 | */
|
---|
[98000fb] | 429 | void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt)
|
---|
[dbb6886] | 430 | {
|
---|
[6c441cf8] | 431 | unsigned int i;
|
---|
[ed166f7] | 432 |
|
---|
[fd85ae5] | 433 | /* switch to nucleus because we are mapped by the primary context */
|
---|
| 434 | nucleus_enter();
|
---|
[3da11f37] | 435 |
|
---|
| 436 | for (i = 0; i < cnt; i++) {
|
---|
| 437 | __hypercall_fast5(MMU_DEMAP_PAGE, 0, 0, page, asid,
|
---|
| 438 | MMU_FLAG_DTLB | MMU_FLAG_ITLB);
|
---|
[4512d7e] | 439 | }
|
---|
[3da11f37] | 440 |
|
---|
[fd85ae5] | 441 | nucleus_leave();
|
---|
[dbb6886] | 442 | }
|
---|
[b45c443] | 443 |
|
---|
[10b890b] | 444 | /** @}
|
---|
[b45c443] | 445 | */
|
---|