/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Synthesize TLB refill handlers at runtime. * * Copyright (C) 2004, 2005, 2006, 2008 Thiemo Seufer * Copyright (C) 2005, 2007, 2008, 2009 Maciej W. Rozycki * Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org) * Copyright (C) 2008, 2009 Cavium Networks, Inc. * Copyright (C) 2011 MIPS Technologies, Inc. * * ... and the days got worse and worse and now you see * I've gone completely out of my mind. * * They're coming to take me a away haha * they're coming to take me a away hoho hihi haha * to the funny farm where code is beautiful all the time ... * * (Condolences to Napoleon XIV)
*/
/* * TLB load/store/modify handlers. * * Only the fastpath gets synthesized at runtime, the slowpath for * do_page_fault remains normal asm.
*/ externvoid tlb_do_page_fault_0(void); externvoid tlb_do_page_fault_1(void);
struct work_registers { int r1; int r2; int r3;
};
staticint use_bbit_insns(void)
{ switch (current_cpu_type()) { case CPU_CAVIUM_OCTEON: case CPU_CAVIUM_OCTEON_PLUS: case CPU_CAVIUM_OCTEON2: case CPU_CAVIUM_OCTEON3: return 1; default: return 0;
}
}
staticint use_lwx_insns(void)
{ switch (current_cpu_type()) { case CPU_CAVIUM_OCTEON2: case CPU_CAVIUM_OCTEON3: return 1; default: return 0;
}
} #ifdefined(CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE) && \
CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0 staticbool scratchpad_available(void)
{ returntrue;
} staticint scratchpad_offset(int i)
{ /* * CVMSEG starts at address -32768 and extends for * CAVIUM_OCTEON_CVMSEG_SIZE 128 byte cache lines.
*/
i += 1; /* Kernel use starts at the top and works down. */ return CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128 - (8 * i) - 32768;
} #else staticbool scratchpad_available(void)
{ returnfalse;
} staticint scratchpad_offset(int i)
{
BUG(); /* Really unreachable, but evidently some GCC want this. */ return 0;
} #endif /* * Found by experiment: At least some revisions of the 4kc throw under * some circumstances a machine check exception, triggered by invalid * values in the index register. Delaying the tlbp instruction until * after the next branch, plus adding an additional nop in front of * tlbwi/tlbwr avoids the invalid index register values. Nobody knows * why; it's not an issue caused by the core RTL. *
*/ staticint m4kc_tlbp_war(void)
{ return current_cpu_type() == CPU_4KC;
}
/* * pgtable bits are assigned dynamically depending on processor feature * and statically based on kernel configuration. This spits out the actual * values the kernel is using. Required to make sense from disassembled * TLB exception handlers.
*/ staticvoid output_pgtable_bits_defines(void)
{ #define pr_define(fmt, ...) \
pr_debug("#define " fmt, ##__VA_ARGS__)
/* The worst case length of the handler is around 18 instructions for * R3000-style TLBs and up to 63 instructions for R4000-style TLBs. * Maximum space available is 32 instructions for R3000 and 64 * instructions for R4000. * * We deliberately chose a buffer size of 128, so we won't scribble * over anything important on overflow before we panic.
*/ static u32 tlb_handler[128];
/* simply assume worst case size for labels and relocs */ staticstruct uasm_label labels[128]; staticstruct uasm_reloc relocs[128];
/* * CONFIG_MIPS_PGD_C0_CONTEXT implies 64 bit and lack of pgd_current, * we cannot do r3000 under these circumstances. * * The R3000 TLB handler is simple.
*/ staticvoid build_r3000_tlb_refill_handler(void)
{ long pgdc = (long)pgd_current;
u32 *p;
memset(tlb_handler, 0, sizeof(tlb_handler));
p = tlb_handler;
/* * The R4000 TLB handler is much more complicated. We have two * consecutive handler areas with 32 instructions space each. * Since they aren't used at the same time, we can overflow in the * other one.To keep things simple, we first assume linear space, * then we relocate it to the final handler layout as needed.
*/ static u32 final_handler[64];
/* * Hazards * * From the IDT errata for the QED RM5230 (Nevada), processor revision 1.0: * 2. A timing hazard exists for the TLBP instruction. * * stalling_instruction * TLBP * * The JTLB is being read for the TLBP throughout the stall generated by the * previous instruction. This is not really correct as the stalling instruction * can modify the address used to access the JTLB. The failure symptom is that * the TLBP instruction will use an address created for the stalling instruction * and not the address held in C0_ENHI and thus report the wrong results. * * The software work-around is to not allow the instruction preceding the TLBP * to stall - make it an NOP or some other instruction guaranteed not to stall. * * Errata 2 will not be fixed. This errata is also on the R5000. * * As if we MIPS hackers wouldn't know how to nop pipelines happy ...
*/ staticvoid __maybe_unused build_tlb_probe_entry(u32 **p)
{ switch (current_cpu_type()) { /* Found by experiment: R4600 v2.0/R4700 needs this, too. */ case CPU_R4600: case CPU_R4700: case CPU_R5000: case CPU_NEVADA:
uasm_i_nop(p);
uasm_i_tlbp(p); break;
switch (wmode) { case tlb_random: tlbw = uasm_i_tlbwr; break; case tlb_indexed: tlbw = uasm_i_tlbwi; break;
}
if (cpu_has_mips_r2_r6) { if (cpu_has_mips_r2_exec_hazard)
uasm_i_ehb(p);
tlbw(p); return;
}
switch (current_cpu_type()) { case CPU_R4000PC: case CPU_R4000SC: case CPU_R4000MC: case CPU_R4400PC: case CPU_R4400SC: case CPU_R4400MC: /* * This branch uses up a mtc0 hazard nop slot and saves * two nops after the tlbw instruction.
*/
uasm_bgezl_hazard(p, r, hazard_instance);
tlbw(p);
uasm_bgezl_label(l, p, hazard_instance);
hazard_instance++;
uasm_i_nop(p); break;
case CPU_R4600: case CPU_R4700:
uasm_i_nop(p);
tlbw(p);
uasm_i_nop(p); break;
case CPU_R5000: case CPU_NEVADA:
uasm_i_nop(p); /* QED specifies 2 nops hazard */
uasm_i_nop(p); /* QED specifies 2 nops hazard */
tlbw(p); break;
case CPU_R4300: case CPU_5KC: case CPU_TX49XX: case CPU_PR4450:
uasm_i_nop(p);
tlbw(p); break;
case CPU_R10000: case CPU_R12000: case CPU_R14000: case CPU_R16000: case CPU_4KC: case CPU_4KEC: case CPU_M14KC: case CPU_M14KEC: case CPU_SB1: case CPU_SB1A: case CPU_4KSC: case CPU_20KC: case CPU_25KF: case CPU_BMIPS32: case CPU_BMIPS3300: case CPU_BMIPS4350: case CPU_BMIPS4380: case CPU_BMIPS5000: case CPU_LOONGSON2EF: case CPU_LOONGSON64: case CPU_R5500: if (m4kc_tlbp_war())
uasm_i_nop(p);
fallthrough; case CPU_ALCHEMY:
tlbw(p); break;
case CPU_RM7000:
uasm_i_nop(p);
uasm_i_nop(p);
uasm_i_nop(p);
uasm_i_nop(p);
tlbw(p); break;
staticvoid build_restore_pagemask(u32 **p, struct uasm_reloc **r, unsignedint tmp, enum label_id lid, int restore_scratch)
{ if (restore_scratch) { /* * Ensure the MFC0 below observes the value written to the * KScratch register by the prior MTC0.
*/ if (scratch_reg >= 0)
uasm_i_ehb(p);
/* * Check if Huge PTE is present, if so then jump to LABEL.
*/ staticvoid
build_is_huge_pte(u32 **p, struct uasm_reloc **r, unsignedint tmp, unsignedint pmd, int lid)
{
UASM_i_LW(p, tmp, 0, pmd); if (use_bbit_insns()) {
uasm_il_bbit1(p, r, tmp, ilog2(_PAGE_HUGE), lid);
} else {
uasm_i_andi(p, tmp, tmp, _PAGE_HUGE);
uasm_il_bnez(p, r, tmp, lid);
}
}
staticvoid build_huge_update_entries(u32 **p, unsignedint pte, unsignedint tmp)
{ int small_sequence;
/* * A huge PTE describes an area the size of the * configured huge page size. This is twice the * of the large TLB entry size we intend to use. * A TLB entry half the size of the configured * huge page size is configured into entrylo0 * and entrylo1 to cover the contiguous huge PTE * address space.
*/
small_sequence = (HPAGE_SIZE >> 7) < 0x10000;
/* We can clobber tmp. It isn't used after this.*/ if (!small_sequence)
uasm_i_lui(p, tmp, HPAGE_SIZE >> (7 + 16));
build_convert_pte_to_entrylo(p, pte);
UASM_i_MTC0(p, pte, C0_ENTRYLO0); /* load it */ /* convert to entrylo1 */ if (small_sequence)
UASM_i_ADDIU(p, pte, pte, HPAGE_SIZE >> 7); else
UASM_i_ADDU(p, pte, pte, tmp);
#ifdef CONFIG_64BIT /* * TMP and PTR are scratch. * TMP will be clobbered, PTR will hold the pmd entry.
*/ void build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r, unsignedint tmp, unsignedint ptr)
{ #ifndef CONFIG_MIPS_PGD_C0_CONTEXT long pgdc = (long)pgd_current; #endif /* * The vmalloc handling is not in the hotpath.
*/
uasm_i_dmfc0(p, tmp, C0_BADVADDR);
if (check_for_high_segbits) { /* * The kernel currently implicitly assumes that the * MIPS SEGBITS parameter for the processor is * (PGDIR_SHIFT+PGDIR_BITS) or less, and will never * allocate virtual addresses outside the maximum * range for SEGBITS = (PGDIR_SHIFT+PGDIR_BITS). But * that doesn't prevent user code from accessing the * higher xuseg addresses. Here, we make sure that * everything but the lower xuseg addresses goes down * the module_alloc/vmalloc path.
*/
uasm_i_dsrl_safe(p, ptr, tmp, PGDIR_SHIFT + PGD_TABLE_ORDER + PAGE_SHIFT - 3);
uasm_il_bnez(p, r, ptr, label_vmalloc);
} else {
uasm_il_bltz(p, r, tmp, label_vmalloc);
} /* No uasm_i_nop needed here, since the next insn doesn't touch TMP. */
if (pgd_reg != -1) { /* pgd is in pgd_reg */ if (cpu_has_ldpte)
UASM_i_MFC0(p, ptr, C0_PWBASE); else
UASM_i_MFC0(p, ptr, c0_kscratch(), pgd_reg);
} else { #ifdefined(CONFIG_MIPS_PGD_C0_CONTEXT) /* * &pgd << 11 stored in CONTEXT [23..63].
*/
UASM_i_MFC0(p, ptr, C0_CONTEXT);
/* * BVADDR is the faulting address, PTR is scratch. * PTR will hold the pgd for vmalloc.
*/ staticvoid
build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r, unsignedint bvaddr, unsignedint ptr, enum vmalloc64_mode mode)
{ long swpd = (long)swapper_pg_dir; int single_insn_swpd; int did_vmalloc_branch = 0;
if (mode != not_refill && check_for_high_segbits) { if (single_insn_swpd) {
uasm_il_bltz(p, r, bvaddr, label_vmalloc_done);
uasm_i_lui(p, ptr, uasm_rel_hi(swpd));
did_vmalloc_branch = 1; /* fall through */
} else {
uasm_il_bgez(p, r, bvaddr, label_large_segbits_fault);
}
} if (!did_vmalloc_branch) { if (single_insn_swpd) {
uasm_il_b(p, r, label_vmalloc_done);
uasm_i_lui(p, ptr, uasm_rel_hi(swpd));
} else {
UASM_i_LA_mostly(p, ptr, swpd);
uasm_il_b(p, r, label_vmalloc_done); if (uasm_in_compat_space_p(swpd))
uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(swpd)); else
uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(swpd));
}
} if (mode != not_refill && check_for_high_segbits) {
uasm_l_large_segbits_fault(l, *p);
if (mode == refill_scratch && scratch_reg >= 0)
uasm_i_ehb(p);
/* * We get here if we are an xsseg address, or if we are * an xuseg address above (PGDIR_SHIFT+PGDIR_BITS) boundary. * * Ignoring xsseg (assume disabled so would generate * (address errors?), the only remaining possibility * is the upper xuseg addresses. On processors with * TLB_SEGBITS <= PGDIR_SHIFT+PGDIR_BITS, these * addresses would have taken an address error. We try * to mimic that here by taking a load/istream page * fault.
*/ if (IS_ENABLED(CONFIG_CPU_LOONGSON3_WORKAROUNDS))
uasm_i_sync(p, 0);
UASM_i_LA(p, ptr, (unsignedlong)tlb_do_page_fault_0);
uasm_i_jr(p, ptr);
/* * TMP and PTR are scratch. * TMP will be clobbered, PTR will hold the pgd entry.
*/ void build_get_pgde32(u32 **p, unsignedint tmp, unsignedint ptr)
{ if (pgd_reg != -1) { /* pgd is in pgd_reg */
uasm_i_mfc0(p, ptr, c0_kscratch(), pgd_reg);
uasm_i_mfc0(p, tmp, C0_BADVADDR); /* get faulting address */
} else { long pgdc = (long)pgd_current;
/* 32 bit SMP has smp_processor_id() stored in CONTEXT. */ #ifdef CONFIG_SMP
uasm_i_mfc0(p, ptr, SMP_CPUID_REG);
UASM_i_LA_mostly(p, tmp, pgdc);
uasm_i_srl(p, ptr, ptr, SMP_CPUID_PTRSHIFT);
uasm_i_addu(p, ptr, tmp, ptr); #else
UASM_i_LA_mostly(p, ptr, pgdc); #endif
uasm_i_mfc0(p, tmp, C0_BADVADDR); /* get faulting address */
uasm_i_lw(p, ptr, uasm_rel_lo(pgdc), ptr);
}
uasm_i_srl(p, tmp, tmp, PGDIR_SHIFT); /* get pgd only bits */
uasm_i_sll(p, tmp, tmp, PGD_T_LOG2);
uasm_i_addu(p, ptr, ptr, tmp); /* add in pgd offset */
}
EXPORT_SYMBOL_GPL(build_get_pgde32);
void build_get_ptep(u32 **p, unsignedint tmp, unsignedint ptr)
{ /* * Bug workaround for the Nevada. It seems as if under certain * circumstances the move from cp0_context might produce a * bogus result when the mfc0 instruction and its consumer are * in a different cacheline or a load instruction, probably any * memory reference, is between them.
*/ switch (current_cpu_type()) { case CPU_NEVADA:
UASM_i_LW(p, ptr, 0, ptr);
GET_CONTEXT(p, tmp); /* get context reg */ break;
if (use_lwx_insns()) {
UASM_i_LWX(p, ptr, scratch, ptr);
} else {
uasm_i_daddu(p, ptr, ptr, scratch); /* add in pmd offset */
UASM_i_LW(p, ptr, 0, ptr);
} /* ptr contains a pointer to PMD entry */ /* tmp contains the address */ #endif
#ifndef __PAGETABLE_PMD_FOLDED /* get pmd offset in bytes */
uasm_i_dsrl_safe(p, scratch, tmp, PMD_SHIFT - 3);
uasm_i_andi(p, scratch, scratch, (PTRS_PER_PMD - 1) << 3);
GET_CONTEXT(p, tmp); /* get context reg */
if (use_lwx_insns()) {
UASM_i_LWX(p, scratch, scratch, ptr);
} else {
uasm_i_daddu(p, ptr, ptr, scratch); /* add in pmd offset */
UASM_i_LW(p, scratch, 0, ptr);
} #endif /* Adjust the context during the load latency. */
build_adjust_context(p, tmp);
#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
uasm_il_bbit1(p, r, scratch, ilog2(_PAGE_HUGE), label_tlb_huge_update); /* * The in the LWX case we don't want to do the load in the * delay slot. It cannot issue in the same cycle and may be * speculative and unneeded.
*/ if (use_lwx_insns())
uasm_i_nop(p); #endif/* CONFIG_MIPS_HUGE_TLB_SUPPORT */
/* build_update_entries */ if (use_lwx_insns()) {
even = ptr;
odd = tmp;
UASM_i_LWX(p, even, scratch, tmp);
UASM_i_ADDIU(p, tmp, tmp, sizeof(pte_t));
UASM_i_LWX(p, odd, scratch, tmp);
} else {
UASM_i_ADDU(p, ptr, scratch, tmp); /* add in offset */
even = tmp;
odd = ptr;
UASM_i_LW(p, even, 0, ptr); /* get even pte */
UASM_i_LW(p, odd, sizeof(pte_t), ptr); /* get odd pte */
} if (cpu_has_rixi) {
uasm_i_drotr(p, even, even, ilog2(_PAGE_GLOBAL));
UASM_i_MTC0(p, even, C0_ENTRYLO0); /* load it */
uasm_i_drotr(p, odd, odd, ilog2(_PAGE_GLOBAL));
} else {
uasm_i_dsrl_safe(p, even, even, ilog2(_PAGE_GLOBAL));
UASM_i_MTC0(p, even, C0_ENTRYLO0); /* load it */
uasm_i_dsrl_safe(p, odd, odd, ilog2(_PAGE_GLOBAL));
}
UASM_i_MTC0(p, odd, C0_ENTRYLO1); /* load it */
/* * For a 64-bit kernel, we are using the 64-bit XTLB refill exception * because EXL == 0. If we wrap, we can also use the 32 instruction * slots before the XTLB refill exception handler which belong to the * unused TLB refill exception.
*/ #define MIPS64_REFILL_INSNS 32
/* * Overflow check: For the 64bit handler, we need at least one * free instruction slot for the wrap-around branch. In worst * case, if the intended insertion point is a delay slot, we * need three, with the second nop'ed and the third being * unused.
*/ switch (boot_cpu_type()) { default: if (sizeof(long) == 4) {
fallthrough; case CPU_LOONGSON2EF: /* Loongson2 ebase is different than r4k, we have more space */ if ((p - tlb_handler) > 64)
panic("TLB refill handler space exceeded"); /* * Now fold the handler in the TLB refill handler space.
*/
f = final_handler; /* Simplest case, just copy the handler. */
uasm_copy_handler(relocs, labels, tlb_handler, p, f);
final_len = p - tlb_handler; break;
} else { if (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 1)
|| (((p - tlb_handler) > (MIPS64_REFILL_INSNS * 2) - 3)
&& uasm_insn_has_bdelay(relocs,
tlb_handler + MIPS64_REFILL_INSNS - 3)))
panic("TLB refill handler space exceeded"); /* * Now fold the handler in the TLB refill handler space.
*/
f = final_handler + MIPS64_REFILL_INSNS; if ((p - tlb_handler) <= MIPS64_REFILL_INSNS) { /* Just copy the handler. */
uasm_copy_handler(relocs, labels, tlb_handler, p, f);
final_len = p - tlb_handler;
} else { #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT constenum label_id ls = label_tlb_huge_update; #else constenum label_id ls = label_vmalloc; #endif
u32 *split; int ov = 0; int i;
for (i = 0; i < ARRAY_SIZE(labels) && labels[i].lab != ls; i++)
;
BUG_ON(i == ARRAY_SIZE(labels));
split = labels[i].addr;
/* * See if we have overflown one way or the other.
*/ if (split > tlb_handler + MIPS64_REFILL_INSNS ||
split < p - MIPS64_REFILL_INSNS)
ov = 1;
if (ov) { /* * Split two instructions before the end. One * for the branch and one for the instruction * in the delay slot.
*/
split = tlb_handler + MIPS64_REFILL_INSNS - 2;
/* * If the branch would fall in a delay slot, * we must back up an additional instruction * so that it is no longer in a delay slot.
*/ if (uasm_insn_has_bdelay(relocs, split - 1))
split--;
} /* Copy first part of the handler. */
uasm_copy_handler(relocs, labels, tlb_handler, split, f);
f += split - tlb_handler;
/* PGD << 11 in c0_Context */ /* * If it is a ckseg0 address, convert to a physical * address. Shifting right by 29 and adding 4 will * result in zero for these addresses. *
*/
UASM_i_SRA(&p, a1, a0, 29);
UASM_i_ADDIU(&p, a1, a1, 4);
uasm_il_bnez(&p, &r, a1, label_tlbl_goaround1);
uasm_i_nop(&p);
uasm_i_dinsm(&p, a0, 0, 29, 64 - 29);
uasm_l_tlbl_goaround1(&l, p);
UASM_i_SLL(&p, a0, a0, 11);
UASM_i_MTC0(&p, a0, C0_CONTEXT);
uasm_i_jr(&p, 31);
uasm_i_ehb(&p);
} else { /* PGD in c0_KScratch */ if (cpu_has_ldpte)
UASM_i_MTC0(&p, a0, C0_PWBASE); else
UASM_i_MTC0(&p, a0, c0_kscratch(), pgd_reg);
uasm_i_jr(&p, 31);
uasm_i_ehb(&p);
} #else #ifdef CONFIG_SMP /* Save PGD to pgd_current[smp_processor_id()] */
UASM_i_CPUID_MFC0(&p, a1, SMP_CPUID_REG);
UASM_i_SRL_SAFE(&p, a1, a1, SMP_CPUID_PTRSHIFT);
UASM_i_LA_mostly(&p, a2, pgdc);
UASM_i_ADDU(&p, a2, a2, a1);
UASM_i_SW(&p, a0, uasm_rel_lo(pgdc), a2); #else
UASM_i_LA_mostly(&p, a2, pgdc);
UASM_i_SW(&p, a0, uasm_rel_lo(pgdc), a2); #endif/* SMP */
/* if pgd_reg is allocated, save PGD also to scratch register */ if (pgd_reg != -1) {
UASM_i_MTC0(&p, a0, c0_kscratch(), pgd_reg);
uasm_i_jr(&p, 31);
uasm_i_ehb(&p);
} else {
uasm_i_jr(&p, 31);
uasm_i_nop(&p);
} #endif if (p >= (u32 *)tlbmiss_handler_setup_pgd_end)
panic("tlbmiss_handler_setup_pgd space exceeded");
/* * Check if PTE is present, if not then jump to LABEL. PTR points to * the page table where this PTE is located, PTE will be re-loaded * with its original value.
*/ staticvoid
build_pte_present(u32 **p, struct uasm_reloc **r, int pte, int ptr, int scratch, enum label_id lid)
{ int t = scratch >= 0 ? scratch : pte; int cur = pte;
if (cpu_has_rixi) { if (use_bbit_insns()) {
uasm_il_bbit0(p, r, pte, ilog2(_PAGE_PRESENT), lid);
uasm_i_nop(p);
} else { if (_PAGE_PRESENT_SHIFT) {
uasm_i_srl(p, t, cur, _PAGE_PRESENT_SHIFT);
cur = t;
}
uasm_i_andi(p, t, cur, 1);
uasm_il_beqz(p, r, t, lid); if (pte == t) /* You lose the SMP race :-(*/
iPTE_LW(p, pte, ptr);
}
} else { if (_PAGE_PRESENT_SHIFT) {
uasm_i_srl(p, t, cur, _PAGE_PRESENT_SHIFT);
cur = t;
}
uasm_i_andi(p, t, cur,
(_PAGE_PRESENT | _PAGE_NO_READ) >> _PAGE_PRESENT_SHIFT);
uasm_i_xori(p, t, t, _PAGE_PRESENT >> _PAGE_PRESENT_SHIFT);
uasm_il_bnez(p, r, t, lid); if (pte == t) /* You lose the SMP race :-(*/
iPTE_LW(p, pte, ptr);
}
}
/* Make PTE valid, store result in PTR. */ staticvoid
build_make_valid(u32 **p, struct uasm_reloc **r, unsignedint pte, unsignedint ptr, unsignedint scratch)
{ unsignedint mode = _PAGE_VALID | _PAGE_ACCESSED;
iPTE_SW(p, r, pte, ptr, mode, scratch);
}
/* * Check if PTE can be written to, if not branch to LABEL. Regardless * restore PTE with value from PTR when done.
*/ staticvoid
build_pte_writable(u32 **p, struct uasm_reloc **r, unsignedint pte, unsignedint ptr, int scratch, enum label_id lid)
{ int t = scratch >= 0 ? scratch : pte; int cur = pte;
if (_PAGE_PRESENT_SHIFT) {
uasm_i_srl(p, t, cur, _PAGE_PRESENT_SHIFT);
cur = t;
}
uasm_i_andi(p, t, cur,
(_PAGE_PRESENT | _PAGE_WRITE) >> _PAGE_PRESENT_SHIFT);
uasm_i_xori(p, t, t,
(_PAGE_PRESENT | _PAGE_WRITE) >> _PAGE_PRESENT_SHIFT);
uasm_il_bnez(p, r, t, lid); if (pte == t) /* You lose the SMP race :-(*/
iPTE_LW(p, pte, ptr); else
uasm_i_nop(p);
}
/* Make PTE writable, update software status bits as well, then store * at PTR.
*/ staticvoid
build_make_write(u32 **p, struct uasm_reloc **r, unsignedint pte, unsignedint ptr, unsignedint scratch)
{ unsignedint mode = (_PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID
| _PAGE_DIRTY);
iPTE_SW(p, r, pte, ptr, mode, scratch);
}
/* * Check if PTE can be modified, if not branch to LABEL. Regardless * restore PTE with value from PTR when done.
*/ staticvoid
build_pte_modifiable(u32 **p, struct uasm_reloc **r, unsignedint pte, unsignedint ptr, int scratch, enum label_id lid)
{ if (use_bbit_insns()) {
uasm_il_bbit0(p, r, pte, ilog2(_PAGE_WRITE), lid);
uasm_i_nop(p);
} else { int t = scratch >= 0 ? scratch : pte;
uasm_i_srl(p, t, pte, _PAGE_WRITE_SHIFT);
uasm_i_andi(p, t, t, 1);
uasm_il_beqz(p, r, t, lid); if (pte == t) /* You lose the SMP race :-(*/
iPTE_LW(p, pte, ptr);
}
}
/* * This places the pte into ENTRYLO0 and writes it with tlbwi. * Then it returns.
*/ staticvoid
build_r3000_pte_reload_tlbwi(u32 **p, unsignedint pte, unsignedint tmp)
{
uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */
uasm_i_mfc0(p, tmp, C0_EPC); /* cp0 delay */
uasm_i_tlbwi(p);
uasm_i_jr(p, tmp);
uasm_i_rfe(p); /* branch delay */
}
/* * This places the pte into ENTRYLO0 and writes it with tlbwi * or tlbwr as appropriate. This is because the index register * may have the probe fail bit set as a result of a trap on a * kseg2 access, i.e. without refill. Then it returns.
*/ staticvoid
build_r3000_tlb_reload_write(u32 **p, struct uasm_label **l, struct uasm_reloc **r, unsignedint pte, unsignedint tmp)
{
uasm_i_mfc0(p, tmp, C0_INDEX);
uasm_i_mtc0(p, pte, C0_ENTRYLO0); /* cp0 delay */
uasm_il_bltz(p, r, tmp, label_r3000_write_probe_fail); /* cp0 delay */
uasm_i_mfc0(p, tmp, C0_EPC); /* branch delay */
uasm_i_tlbwi(p); /* cp0 delay */
uasm_i_jr(p, tmp);
uasm_i_rfe(p); /* branch delay */
uasm_l_r3000_write_probe_fail(l, *p);
uasm_i_tlbwr(p); /* cp0 delay */
uasm_i_jr(p, tmp);
uasm_i_rfe(p); /* branch delay */
}
staticbool cpu_has_tlbex_tlbp_race(void)
{ /* * When a Hardware Table Walker is running it can replace TLB entries * at any time, leading to a race between it & the CPU.
*/ if (cpu_has_htw) returntrue;
/* * If the CPU shares FTLB RAM with its siblings then our entry may be * replaced at any time by a sibling performing a write to the FTLB.
*/ if (cpu_has_shared_ftlb_ram) returntrue;
/* In all other cases there ought to be no race condition to handle */ returnfalse;
}
#ifdef CONFIG_64BIT
build_get_pmde64(p, l, r, wr.r1, wr.r2); /* get pmd in ptr */ #else
build_get_pgde32(p, wr.r1, wr.r2); /* get pgd in ptr */ #endif
#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT /* * For huge tlb entries, pmd doesn't contain an address but * instead contains the tlb pte. Check the PAGE_HUGE bit and * see if we need to jump to huge tlb processing.
*/
build_is_huge_pte(p, r, wr.r1, wr.r2, label_tlb_huge_update); #endif
if (cpu_has_rixi && !cpu_has_rixiex) { /* * If the page is not _PAGE_VALID, RI or XI could not * have triggered it. Skip the expensive test..
*/ if (use_bbit_insns()) {
uasm_il_bbit0(&p, &r, wr.r1, ilog2(_PAGE_VALID),
label_tlbl_goaround1);
} else {
uasm_i_andi(&p, wr.r3, wr.r1, _PAGE_VALID);
uasm_il_beqz(&p, &r, wr.r3, label_tlbl_goaround1);
}
uasm_i_nop(&p);
/* * Warn if something may race with us & replace the TLB entry * before we read it here. Everything with such races should * also have dedicated RiXi exception handlers, so this * shouldn't be hit.
*/
WARN(cpu_has_tlbex_tlbp_race(), "Unhandled race in RiXi path");
uasm_i_tlbr(&p);
if (cpu_has_mips_r2_exec_hazard)
uasm_i_ehb(&p);
/* Examine entrylo 0 or 1 based on ptr. */ if (use_bbit_insns()) {
uasm_i_bbit0(&p, wr.r2, ilog2(sizeof(pte_t)), 8);
} else {
uasm_i_andi(&p, wr.r3, wr.r2, sizeof(pte_t));
uasm_i_beqz(&p, wr.r3, 8);
} /* load it in the delay slot*/
UASM_i_MFC0(&p, wr.r3, C0_ENTRYLO0); /* load it if ptr is odd */
UASM_i_MFC0(&p, wr.r3, C0_ENTRYLO1); /* * If the entryLo (now in wr.r3) is valid (bit 1), RI or * XI must have triggered it.
*/ if (use_bbit_insns()) {
uasm_il_bbit1(&p, &r, wr.r3, 1, label_nopage_tlbl);
uasm_i_nop(&p);
uasm_l_tlbl_goaround1(&l, p);
} else {
uasm_i_andi(&p, wr.r3, wr.r3, 2);
uasm_il_bnez(&p, &r, wr.r3, label_nopage_tlbl);
uasm_i_nop(&p);
}
uasm_l_tlbl_goaround1(&l, p);
}
build_make_valid(&p, &r, wr.r1, wr.r2, wr.r3);
build_r4000_tlbchange_handler_tail(&p, &l, &r, wr.r1, wr.r2);
#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT /* * This is the entry point when build_r4000_tlbchange_handler_head * spots a huge page.
*/
uasm_l_tlb_huge_update(&l, p);
iPTE_LW(&p, wr.r1, wr.r2);
build_pte_present(&p, &r, wr.r1, wr.r2, wr.r3, label_nopage_tlbl);
build_tlb_probe_entry(&p);
if (cpu_has_rixi && !cpu_has_rixiex) { /* * If the page is not _PAGE_VALID, RI or XI could not * have triggered it. Skip the expensive test..
*/ if (use_bbit_insns()) {
uasm_il_bbit0(&p, &r, wr.r1, ilog2(_PAGE_VALID),
label_tlbl_goaround2);
} else {
uasm_i_andi(&p, wr.r3, wr.r1, _PAGE_VALID);
uasm_il_beqz(&p, &r, wr.r3, label_tlbl_goaround2);
}
uasm_i_nop(&p);
/* * Warn if something may race with us & replace the TLB entry * before we read it here. Everything with such races should * also have dedicated RiXi exception handlers, so this * shouldn't be hit.
*/
WARN(cpu_has_tlbex_tlbp_race(), "Unhandled race in RiXi path");
uasm_i_tlbr(&p);
if (cpu_has_mips_r2_exec_hazard)
uasm_i_ehb(&p);
/* Examine entrylo 0 or 1 based on ptr. */ if (use_bbit_insns()) {
uasm_i_bbit0(&p, wr.r2, ilog2(sizeof(pte_t)), 8);
} else {
uasm_i_andi(&p, wr.r3, wr.r2, sizeof(pte_t));
uasm_i_beqz(&p, wr.r3, 8);
} /* load it in the delay slot*/
UASM_i_MFC0(&p, wr.r3, C0_ENTRYLO0); /* load it if ptr is odd */
UASM_i_MFC0(&p, wr.r3, C0_ENTRYLO1); /* * If the entryLo (now in wr.r3) is valid (bit 1), RI or * XI must have triggered it.
*/ if (use_bbit_insns()) {
uasm_il_bbit0(&p, &r, wr.r3, 1, label_tlbl_goaround2);
} else {
uasm_i_andi(&p, wr.r3, wr.r3, 2);
uasm_il_beqz(&p, &r, wr.r3, label_tlbl_goaround2);
} if (PM_DEFAULT_MASK == 0)
uasm_i_nop(&p); /* * We clobbered C0_PAGEMASK, restore it. On the other branch * it is restored in build_huge_tlb_write_entry.
*/
build_restore_pagemask(&p, &r, wr.r3, label_nopage_tlbl, 0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.