[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 |
|
---|
[10b890b] | 30 | /** @addtogroup sparc64mm
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[0d04024] | 36 | #include <arch/mm/tlb.h>
|
---|
| 37 | #include <mm/tlb.h>
|
---|
[f47fd19] | 38 | #include <mm/as.h>
|
---|
| 39 | #include <mm/asid.h>
|
---|
[b4655da] | 40 | #include <arch/sun4v/hypercall.h>
|
---|
[0cfc4d38] | 41 | #include <arch/mm/frame.h>
|
---|
| 42 | #include <arch/mm/page.h>
|
---|
[b4655da] | 43 | #include <arch/mm/tte.h>
|
---|
| 44 | #include <arch/mm/tlb.h>
|
---|
[f47fd19] | 45 | #include <arch/interrupt.h>
|
---|
[e2bf639] | 46 | #include <interrupt.h>
|
---|
[f47fd19] | 47 | #include <arch.h>
|
---|
[0d04024] | 48 | #include <print.h>
|
---|
[dbb6886] | 49 | #include <arch/types.h>
|
---|
[0cfc4d38] | 50 | #include <config.h>
|
---|
[49b6d32] | 51 | #include <arch/trap/trap.h>
|
---|
[7bb6b06] | 52 | #include <arch/trap/exception.h>
|
---|
[008029d] | 53 | #include <panic.h>
|
---|
[b6fba84] | 54 | #include <arch/asm.h>
|
---|
[3da11f37] | 55 | #include <arch/cpu.h>
|
---|
| 56 | #include <arch/mm/pagesize.h>
|
---|
[02f441c0] | 57 |
|
---|
[29b2bbf] | 58 | #ifdef CONFIG_TSB
|
---|
| 59 | #include <arch/mm/tsb.h>
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
[5e53e02] | 62 | void dtlb_pte_copy(pte_t *t, bool ro);
|
---|
[ba50a34] | 63 | static void itlb_pte_copy(pte_t *);
|
---|
[965dc18] | 64 | static void do_fast_instruction_access_mmu_miss_fault(istate_t *, const char *);
|
---|
[5e53e02] | 65 | void do_fast_data_access_mmu_miss_fault(istate_t *istate,
|
---|
| 66 | uint64_t page_and_ctx, const char *str);
|
---|
| 67 | static void do_fast_data_access_protection_fault(istate_t *,
|
---|
| 68 | uint64_t, const char *);
|
---|
| 69 |
|
---|
| 70 | /*
|
---|
| 71 | * The assembly language routine passes a 64-bit parameter to the Data Access
|
---|
| 72 | * MMU Miss and Data Access protection handlers, the parameter encapsulates
|
---|
| 73 | * a virtual address of the faulting page and the faulting context. The most
|
---|
| 74 | * significant 51 bits represent the VA of the faulting page and the least
|
---|
| 75 | * significant 13 vits represent the faulting context. The following macros
|
---|
| 76 | * extract the page and context out of the 64-bit parameter:
|
---|
| 77 | */
|
---|
| 78 |
|
---|
| 79 | /* extracts the VA of the faulting page */
|
---|
| 80 | #define DMISS_ADDRESS(page_and_ctx) (((page_and_ctx) >> 13) << 13)
|
---|
| 81 |
|
---|
| 82 | /* extracts the faulting context */
|
---|
| 83 | #define DMISS_CONTEXT(page_and_ctx) ((page_and_ctx) & 0x1fff)
|
---|
[f47fd19] | 84 |
|
---|
[b6fba84] | 85 | char *context_encoding[] = {
|
---|
| 86 | "Primary",
|
---|
| 87 | "Secondary",
|
---|
| 88 | "Nucleus",
|
---|
| 89 | "Reserved"
|
---|
| 90 | };
|
---|
[0d04024] | 91 |
|
---|
[b4655da] | 92 | /** Invalidate all unlocked ITLB and DTLB entries. */
|
---|
| 93 | void tlb_invalidate_all(void)
|
---|
| 94 | {
|
---|
| 95 | uint64_t errno = __hypercall_fast3(MMU_DEMAP_ALL, 0, 0,
|
---|
| 96 | MMU_FLAG_DTLB | MMU_FLAG_ITLB);
|
---|
| 97 | if (errno != EOK) {
|
---|
| 98 | panic("Error code = %d.\n", errno);
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[0d04024] | 102 | void tlb_arch_init(void)
|
---|
| 103 | {
|
---|
[b4655da] | 104 | tlb_invalidate_all();
|
---|
[97f1691] | 105 | }
|
---|
[b6fba84] | 106 |
|
---|
[97f1691] | 107 | /** Insert privileged mapping into DMMU TLB.
|
---|
| 108 | *
|
---|
[965dc18] | 109 | * @param page Virtual page address.
|
---|
| 110 | * @param frame Physical frame address.
|
---|
| 111 | * @param pagesize Page size.
|
---|
| 112 | * @param locked True for permanent mappings, false otherwise.
|
---|
| 113 | * @param cacheable True if the mapping is cacheable, false otherwise.
|
---|
[97f1691] | 114 | */
|
---|
[2057572] | 115 | void dtlb_insert_mapping(uintptr_t page, uintptr_t frame, int pagesize,
|
---|
| 116 | bool locked, bool cacheable)
|
---|
[97f1691] | 117 | {
|
---|
[b4655da] | 118 | #if 0
|
---|
[97f1691] | 119 | tlb_tag_access_reg_t tag;
|
---|
| 120 | tlb_data_t data;
|
---|
| 121 | page_address_t pg;
|
---|
| 122 | frame_address_t fr;
|
---|
[b6fba84] | 123 |
|
---|
[97f1691] | 124 | pg.address = page;
|
---|
| 125 | fr.address = frame;
|
---|
[02f441c0] | 126 |
|
---|
[965dc18] | 127 | tag.context = ASID_KERNEL;
|
---|
[02f441c0] | 128 | tag.vpn = pg.vpn;
|
---|
| 129 |
|
---|
| 130 | dtlb_tag_access_write(tag.value);
|
---|
| 131 |
|
---|
| 132 | data.value = 0;
|
---|
| 133 | data.v = true;
|
---|
[97f1691] | 134 | data.size = pagesize;
|
---|
[02f441c0] | 135 | data.pfn = fr.pfn;
|
---|
[97f1691] | 136 | data.l = locked;
|
---|
| 137 | data.cp = cacheable;
|
---|
[92778f2] | 138 | #ifdef CONFIG_VIRT_IDX_DCACHE
|
---|
[97f1691] | 139 | data.cv = cacheable;
|
---|
[92778f2] | 140 | #endif /* CONFIG_VIRT_IDX_DCACHE */
|
---|
[02f441c0] | 141 | data.p = true;
|
---|
| 142 | data.w = true;
|
---|
[d681c17] | 143 | data.g = false;
|
---|
[02f441c0] | 144 |
|
---|
| 145 | dtlb_data_in_write(data.value);
|
---|
[b4655da] | 146 | #endif
|
---|
[0d04024] | 147 | }
|
---|
| 148 |
|
---|
[a7961271] | 149 | /** Copy PTE to TLB.
|
---|
| 150 | *
|
---|
[965dc18] | 151 | * @param t Page Table Entry to be copied.
|
---|
| 152 | * @param ro If true, the entry will be created read-only, regardless
|
---|
| 153 | * of its w field.
|
---|
[a7961271] | 154 | */
|
---|
[5e53e02] | 155 | void dtlb_pte_copy(pte_t *t, bool ro)
|
---|
[a7961271] | 156 | {
|
---|
[5e53e02] | 157 | tte_data_t data;
|
---|
| 158 |
|
---|
[a7961271] | 159 | data.value = 0;
|
---|
| 160 | data.v = true;
|
---|
[5e53e02] | 161 | data.nfo = false;
|
---|
| 162 | data.ra = (t->frame) >> FRAME_WIDTH;
|
---|
| 163 | data.ie = false;
|
---|
| 164 | data.e = false;
|
---|
[a7961271] | 165 | data.cp = t->c;
|
---|
[92778f2] | 166 | #ifdef CONFIG_VIRT_IDX_DCACHE
|
---|
[a7961271] | 167 | data.cv = t->c;
|
---|
[5e53e02] | 168 | #endif
|
---|
| 169 | data.p = t->k;
|
---|
| 170 | data.x = false;
|
---|
[a7961271] | 171 | data.w = ro ? false : t->w;
|
---|
[5e53e02] | 172 | data.size = PAGESIZE_8K;
|
---|
| 173 |
|
---|
| 174 | __hypercall_hyperfast(
|
---|
| 175 | t->page, t->as->asid, data.value, MMU_FLAG_DTLB, 0, MMU_MAP_ADDR);
|
---|
[a7961271] | 176 | }
|
---|
[5e53e02] | 177 |
|
---|
[a7961271] | 178 |
|
---|
[29b2bbf] | 179 | /** Copy PTE to ITLB.
|
---|
| 180 | *
|
---|
[965dc18] | 181 | * @param t Page Table Entry to be copied.
|
---|
[29b2bbf] | 182 | */
|
---|
[ba50a34] | 183 | void itlb_pte_copy(pte_t *t)
|
---|
[f47fd19] | 184 | {
|
---|
[ba50a34] | 185 | tte_data_t data;
|
---|
[a7961271] | 186 |
|
---|
| 187 | data.value = 0;
|
---|
| 188 | data.v = true;
|
---|
[ba50a34] | 189 | data.nfo = false;
|
---|
| 190 | data.ra = (t->frame) >> FRAME_WIDTH;
|
---|
| 191 | data.ie = false;
|
---|
| 192 | data.e = false;
|
---|
[a7961271] | 193 | data.cp = t->c;
|
---|
[ba50a34] | 194 | data.cv = false;
|
---|
| 195 | data.p = t->k;
|
---|
| 196 | data.x = true;
|
---|
[a7961271] | 197 | data.w = false;
|
---|
[ba50a34] | 198 | data.size = PAGESIZE_8K;
|
---|
[a7961271] | 199 |
|
---|
[ba50a34] | 200 | __hypercall_hyperfast(
|
---|
| 201 | t->page, t->as->asid, data.value, MMU_FLAG_ITLB, 0, MMU_MAP_ADDR);
|
---|
[f47fd19] | 202 | }
|
---|
| 203 |
|
---|
[008029d] | 204 | /** ITLB miss handler. */
|
---|
[36f19c0] | 205 | void fast_instruction_access_mmu_miss(unative_t unused, istate_t *istate)
|
---|
[008029d] | 206 | {
|
---|
[ba50a34] | 207 | uintptr_t va = ALIGN_DOWN(istate->tpc, PAGE_SIZE);
|
---|
[a7961271] | 208 | pte_t *t;
|
---|
| 209 |
|
---|
| 210 | page_table_lock(AS, true);
|
---|
[ba50a34] | 211 | t = page_mapping_find(AS, va);
|
---|
| 212 |
|
---|
[a7961271] | 213 | if (t && PTE_EXECUTABLE(t)) {
|
---|
| 214 | /*
|
---|
| 215 | * The mapping was found in the software page hash table.
|
---|
| 216 | * Insert it into ITLB.
|
---|
| 217 | */
|
---|
| 218 | t->a = true;
|
---|
[ba50a34] | 219 | itlb_pte_copy(t);
|
---|
[29b2bbf] | 220 | #ifdef CONFIG_TSB
|
---|
[ba50a34] | 221 | itsb_pte_copy(t);
|
---|
[29b2bbf] | 222 | #endif
|
---|
[a7961271] | 223 | page_table_unlock(AS, true);
|
---|
| 224 | } else {
|
---|
| 225 | /*
|
---|
[771cd22] | 226 | * Forward the page fault to the address space page fault
|
---|
| 227 | * handler.
|
---|
[a7961271] | 228 | */
|
---|
| 229 | page_table_unlock(AS, true);
|
---|
[ba50a34] | 230 | if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) {
|
---|
[771cd22] | 231 | do_fast_instruction_access_mmu_miss_fault(istate,
|
---|
[3ee8a075] | 232 | __func__);
|
---|
[a7961271] | 233 | }
|
---|
| 234 | }
|
---|
[008029d] | 235 | }
|
---|
| 236 |
|
---|
[f47fd19] | 237 | /** DTLB miss handler.
|
---|
| 238 | *
|
---|
[771cd22] | 239 | * Note that some faults (e.g. kernel faults) were already resolved by the
|
---|
| 240 | * low-level, assembly language part of the fast_data_access_mmu_miss handler.
|
---|
[36f19c0] | 241 | *
|
---|
[ba50a34] | 242 | * @param page_and_ctx A 64-bit value describing the fault. The most
|
---|
| 243 | * significant 51 bits of the value contain the virtual
|
---|
| 244 | * address which caused the fault truncated to the page
|
---|
| 245 | * boundary. The least significant 13 bits of the value
|
---|
| 246 | * contain the number of the context in which the fault
|
---|
| 247 | * occurred.
|
---|
[965dc18] | 248 | * @param istate Interrupted state saved on the stack.
|
---|
[f47fd19] | 249 | */
|
---|
[ba50a34] | 250 | void fast_data_access_mmu_miss(uint64_t page_and_ctx, istate_t *istate)
|
---|
[008029d] | 251 | {
|
---|
[f47fd19] | 252 | pte_t *t;
|
---|
[ba50a34] | 253 | uintptr_t va = DMISS_ADDRESS(page_and_ctx);
|
---|
| 254 | uint16_t ctx = DMISS_CONTEXT(page_and_ctx);
|
---|
[7cb53f62] | 255 |
|
---|
[ba50a34] | 256 | if (ctx == ASID_KERNEL) {
|
---|
| 257 | if (va == 0) {
|
---|
[f47fd19] | 258 | /* NULL access in kernel */
|
---|
[ba50a34] | 259 | do_fast_data_access_mmu_miss_fault(istate, page_and_ctx,
|
---|
[3ee8a075] | 260 | __func__);
|
---|
[f47fd19] | 261 | }
|
---|
[ba50a34] | 262 | do_fast_data_access_mmu_miss_fault(istate, page_and_ctx, "Unexpected "
|
---|
[2057572] | 263 | "kernel page fault.");
|
---|
[68656282] | 264 | }
|
---|
| 265 |
|
---|
[f47fd19] | 266 | page_table_lock(AS, true);
|
---|
[ba50a34] | 267 | t = page_mapping_find(AS, va);
|
---|
[f47fd19] | 268 | if (t) {
|
---|
| 269 | /*
|
---|
| 270 | * The mapping was found in the software page hash table.
|
---|
| 271 | * Insert it into DTLB.
|
---|
| 272 | */
|
---|
[a7961271] | 273 | t->a = true;
|
---|
[ba50a34] | 274 | dtlb_pte_copy(t, true);
|
---|
[29b2bbf] | 275 | #ifdef CONFIG_TSB
|
---|
[ba50a34] | 276 | dtsb_pte_copy(t, true);
|
---|
[29b2bbf] | 277 | #endif
|
---|
[f47fd19] | 278 | page_table_unlock(AS, true);
|
---|
| 279 | } else {
|
---|
| 280 | /*
|
---|
[2057572] | 281 | * Forward the page fault to the address space page fault
|
---|
| 282 | * handler.
|
---|
[f47fd19] | 283 | */
|
---|
| 284 | page_table_unlock(AS, true);
|
---|
[ba50a34] | 285 | if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
|
---|
| 286 | do_fast_data_access_mmu_miss_fault(istate, page_and_ctx,
|
---|
[3ee8a075] | 287 | __func__);
|
---|
[f47fd19] | 288 | }
|
---|
| 289 | }
|
---|
[5e53e02] | 290 | asm volatile ("sethi 0x41941, %g0");
|
---|
[008029d] | 291 | }
|
---|
| 292 |
|
---|
[36f19c0] | 293 | /** DTLB protection fault handler.
|
---|
| 294 | *
|
---|
[5e53e02] | 295 | * @param page_and_ctx A 64-bit value describing the fault. The most
|
---|
| 296 | * significant 51 bits of the value contain the virtual
|
---|
| 297 | * address which caused the fault truncated to the page
|
---|
| 298 | * boundary. The least significant 13 bits of the value
|
---|
| 299 | * contain the number of the context in which the fault
|
---|
| 300 | * occurred.
|
---|
[965dc18] | 301 | * @param istate Interrupted state saved on the stack.
|
---|
[36f19c0] | 302 | */
|
---|
[ba50a34] | 303 | void fast_data_access_protection(uint64_t page_and_ctx, istate_t *istate)
|
---|
[008029d] | 304 | {
|
---|
[e0b241f] | 305 | pte_t *t;
|
---|
[ba50a34] | 306 | uintptr_t va = DMISS_ADDRESS(page_and_ctx);
|
---|
| 307 | uint16_t ctx = DMISS_CONTEXT(page_and_ctx);
|
---|
[e0b241f] | 308 |
|
---|
| 309 | page_table_lock(AS, true);
|
---|
[ba50a34] | 310 | t = page_mapping_find(AS, va);
|
---|
[e0b241f] | 311 | if (t && PTE_WRITABLE(t)) {
|
---|
| 312 | /*
|
---|
[771cd22] | 313 | * The mapping was found in the software page hash table and is
|
---|
| 314 | * writable. Demap the old mapping and insert an updated mapping
|
---|
| 315 | * into DTLB.
|
---|
[e0b241f] | 316 | */
|
---|
| 317 | t->a = true;
|
---|
| 318 | t->d = true;
|
---|
[ba50a34] | 319 | mmu_demap_page(va, ctx, MMU_FLAG_DTLB);
|
---|
| 320 | dtlb_pte_copy(t, false);
|
---|
[29b2bbf] | 321 | #ifdef CONFIG_TSB
|
---|
[ba50a34] | 322 | dtsb_pte_copy(t, false);
|
---|
[29b2bbf] | 323 | #endif
|
---|
[e0b241f] | 324 | page_table_unlock(AS, true);
|
---|
| 325 | } else {
|
---|
| 326 | /*
|
---|
[771cd22] | 327 | * Forward the page fault to the address space page fault
|
---|
| 328 | * handler.
|
---|
[e0b241f] | 329 | */
|
---|
| 330 | page_table_unlock(AS, true);
|
---|
[5e53e02] | 331 | if (as_page_fault(va, PF_ACCESS_WRITE, istate) == AS_PF_FAULT) {
|
---|
| 332 | do_fast_data_access_protection_fault(istate, page_and_ctx,
|
---|
[3ee8a075] | 333 | __func__);
|
---|
[e0b241f] | 334 | }
|
---|
| 335 | }
|
---|
[008029d] | 336 | }
|
---|
| 337 |
|
---|
[5e53e02] | 338 |
|
---|
[965dc18] | 339 | /** Print TLB entry (for debugging purposes).
|
---|
| 340 | *
|
---|
| 341 | * The diag field has been left out in order to make this function more generic
|
---|
| 342 | * (there is no diag field in US3 architeture).
|
---|
| 343 | *
|
---|
| 344 | * @param i TLB entry number
|
---|
| 345 | * @param t TLB entry tag
|
---|
| 346 | * @param d TLB entry data
|
---|
| 347 | */
|
---|
[0d04024] | 348 | void tlb_print(void)
|
---|
| 349 | {
|
---|
[ba50a34] | 350 | printf("Operation not possible on Niagara.\n");
|
---|
[0d04024] | 351 | }
|
---|
[dbb6886] | 352 |
|
---|
[2057572] | 353 | void do_fast_instruction_access_mmu_miss_fault(istate_t *istate,
|
---|
| 354 | const char *str)
|
---|
[a7961271] | 355 | {
|
---|
[f651e80] | 356 | fault_if_from_uspace(istate, "%s.", str);
|
---|
[7bb6b06] | 357 | dump_istate(istate);
|
---|
[f651e80] | 358 | panic("%s.", str);
|
---|
[a7961271] | 359 | }
|
---|
| 360 |
|
---|
[2057572] | 361 | void do_fast_data_access_mmu_miss_fault(istate_t *istate,
|
---|
[ba50a34] | 362 | uint64_t page_and_ctx, const char *str)
|
---|
[f47fd19] | 363 | {
|
---|
[ba50a34] | 364 | if (DMISS_CONTEXT(page_and_ctx)) {
|
---|
| 365 | fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d)\n", str, DMISS_ADDRESS(page_and_ctx),
|
---|
| 366 | DMISS_CONTEXT(page_and_ctx));
|
---|
[36f19c0] | 367 | }
|
---|
[7bb6b06] | 368 | dump_istate(istate);
|
---|
[5e53e02] | 369 | printf("Faulting page: %p, ASID=%d\n", DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
|
---|
| 370 | panic("%s\n", str);
|
---|
[f47fd19] | 371 | }
|
---|
| 372 |
|
---|
[2057572] | 373 | void do_fast_data_access_protection_fault(istate_t *istate,
|
---|
[ba50a34] | 374 | uint64_t page_and_ctx, const char *str)
|
---|
[e0b241f] | 375 | {
|
---|
[ba50a34] | 376 | if (DMISS_CONTEXT(page_and_ctx)) {
|
---|
| 377 | fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d)\n", str, DMISS_ADDRESS(page_and_ctx),
|
---|
| 378 | DMISS_CONTEXT(page_and_ctx));
|
---|
[36f19c0] | 379 | }
|
---|
[ba50a34] | 380 | printf("Faulting page: %p, ASID=%d\n", DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
|
---|
[7bb6b06] | 381 | dump_istate(istate);
|
---|
[5e53e02] | 382 | panic("%s\n", str);
|
---|
[e0b241f] | 383 | }
|
---|
| 384 |
|
---|
[ba50a34] | 385 | /**
|
---|
| 386 | * Describes the exact condition which caused the last DMMU fault.
|
---|
| 387 | */
|
---|
| 388 | void describe_dmmu_fault(void)
|
---|
[8cee705] | 389 | {
|
---|
[ba50a34] | 390 | #if 0
|
---|
| 391 | uint64_t myid;
|
---|
| 392 | __hypercall_fast_ret1(0, 0, 0, 0, 0, CPU_MYID, &myid);
|
---|
[8cee705] | 393 |
|
---|
[ba50a34] | 394 | ASSERT(mmu_fsas[myid].dft < 16);
|
---|
| 395 |
|
---|
| 396 | printf("condition which caused the fault: %s\n",
|
---|
| 397 | fault_types[mmu_fsas[myid].dft]);
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | /** Invalidate all unlocked ITLB and DTLB entries. */
|
---|
| 401 | void tlb_invalidate_all(void)
|
---|
| 402 | {
|
---|
| 403 | uint64_t errno = __hypercall_fast3(MMU_DEMAP_ALL, 0, 0,
|
---|
| 404 | MMU_FLAG_DTLB | MMU_FLAG_ITLB);
|
---|
| 405 | if (errno != EOK) {
|
---|
| 406 | panic("Error code = %d.\n", errno);
|
---|
| 407 | }
|
---|
[965dc18] | 408 | #endif
|
---|
[8cee705] | 409 | }
|
---|
| 410 |
|
---|
[771cd22] | 411 | /** Invalidate all ITLB and DTLB entries that belong to specified ASID
|
---|
| 412 | * (Context).
|
---|
[dbb6886] | 413 | *
|
---|
| 414 | * @param asid Address Space ID.
|
---|
| 415 | */
|
---|
| 416 | void tlb_invalidate_asid(asid_t asid)
|
---|
| 417 | {
|
---|
[fd85ae5] | 418 | /* switch to nucleus because we are mapped by the primary context */
|
---|
| 419 | nucleus_enter();
|
---|
[3da11f37] | 420 | __hypercall_fast4(MMU_DEMAP_CTX, 0, 0, asid,
|
---|
| 421 | MMU_FLAG_ITLB | MMU_FLAG_DTLB);
|
---|
| 422 |
|
---|
[fd85ae5] | 423 | nucleus_leave();
|
---|
[dbb6886] | 424 | }
|
---|
| 425 |
|
---|
[771cd22] | 426 | /** Invalidate all ITLB and DTLB entries for specified page range in specified
|
---|
| 427 | * address space.
|
---|
[dbb6886] | 428 | *
|
---|
[965dc18] | 429 | * @param asid Address Space ID.
|
---|
| 430 | * @param page First page which to sweep out from ITLB and DTLB.
|
---|
| 431 | * @param cnt Number of ITLB and DTLB entries to invalidate.
|
---|
[dbb6886] | 432 | */
|
---|
[98000fb] | 433 | void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt)
|
---|
[dbb6886] | 434 | {
|
---|
[6c441cf8] | 435 | unsigned int i;
|
---|
[ed166f7] | 436 |
|
---|
[fd85ae5] | 437 | /* switch to nucleus because we are mapped by the primary context */
|
---|
| 438 | nucleus_enter();
|
---|
[3da11f37] | 439 |
|
---|
| 440 | for (i = 0; i < cnt; i++) {
|
---|
| 441 | __hypercall_fast5(MMU_DEMAP_PAGE, 0, 0, page, asid,
|
---|
| 442 | MMU_FLAG_DTLB | MMU_FLAG_ITLB);
|
---|
[4512d7e] | 443 | }
|
---|
[3da11f37] | 444 |
|
---|
[fd85ae5] | 445 | nucleus_leave();
|
---|
[dbb6886] | 446 | }
|
---|
[b45c443] | 447 |
|
---|
[10b890b] | 448 | /** @}
|
---|
[b45c443] | 449 | */
|
---|