Skip to content

Commit 3d8bfdd

Browse files
David Daneyralfbaechle
authored andcommitted
MIPS: Use C0_KScratch (if present) to hold PGD pointer.
Decide at runtime to use either Context or KScratch to hold the PGD pointer. Signed-off-by: David Daney <ddaney@caviumnetworks.com> To: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/1876/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent c42aef0 commit 3d8bfdd

3 files changed

Lines changed: 108 additions & 18 deletions

File tree

‎arch/mips/include/asm/mmu_context.h‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@
2929
#define TLBMISS_HANDLER_SETUP_PGD(pgd) \
3030
tlbmiss_handler_setup_pgd((unsigned long)(pgd))
3131

32-
static inline void tlbmiss_handler_setup_pgd(unsigned long pgd)
33-
{
34-
/* Check for swapper_pg_dir and convert to physical address. */
35-
if ((pgd & CKSEG3) == CKSEG0)
36-
pgd = CPHYSADDR(pgd);
37-
write_c0_context(pgd << 11);
38-
}
32+
extern void tlbmiss_handler_setup_pgd(unsigned long pgd);
3933

4034
#define TLBMISS_HANDLER_SETUP() \
4135
do { \

‎arch/mips/kernel/traps.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,6 @@ void __cpuinit per_cpu_trap_init(void)
15921592
#endif /* CONFIG_MIPS_MT_SMTC */
15931593

15941594
cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
1595-
TLBMISS_HANDLER_SETUP();
15961595

15971596
atomic_inc(&init_mm.mm_count);
15981597
current->active_mm = &init_mm;
@@ -1614,6 +1613,7 @@ void __cpuinit per_cpu_trap_init(void)
16141613
write_c0_wired(0);
16151614
}
16161615
#endif /* CONFIG_MIPS_MT_SMTC */
1616+
TLBMISS_HANDLER_SETUP();
16171617
}
16181618

16191619
/* Install CPU exception handler */

‎arch/mips/mm/tlbex.c‎

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
#include <linux/smp.h>
2727
#include <linux/string.h>
2828
#include <linux/init.h>
29+
#include <linux/cache.h>
2930

30-
#include <asm/mmu_context.h>
31+
#include <asm/cacheflush.h>
32+
#include <asm/pgtable.h>
3133
#include <asm/war.h>
3234
#include <asm/uasm.h>
3335

@@ -173,11 +175,38 @@ static struct uasm_reloc relocs[128] __cpuinitdata;
173175
static int check_for_high_segbits __cpuinitdata;
174176
#endif
175177

176-
#ifndef CONFIG_MIPS_PGD_C0_CONTEXT
178+
#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
179+
180+
static unsigned int kscratch_used_mask __cpuinitdata;
181+
182+
static int __cpuinit allocate_kscratch(void)
183+
{
184+
int r;
185+
unsigned int a = cpu_data[0].kscratch_mask & ~kscratch_used_mask;
186+
187+
r = ffs(a);
188+
189+
if (r == 0)
190+
return -1;
191+
192+
r--; /* make it zero based */
193+
194+
kscratch_used_mask |= (1 << r);
195+
196+
return r;
197+
}
198+
199+
static int pgd_reg __cpuinitdata;
200+
201+
#else /* !CONFIG_MIPS_PGD_C0_CONTEXT*/
177202
/*
178203
* CONFIG_MIPS_PGD_C0_CONTEXT implies 64 bit and lack of pgd_current,
179204
* we cannot do r3000 under these circumstances.
205+
*
206+
* Declare pgd_current here instead of including mmu_context.h to avoid type
207+
* conflicts for tlbmiss_handler_setup_pgd
180208
*/
209+
extern unsigned long pgd_current[];
181210

182211
/*
183212
* The R3000 TLB handler is simple.
@@ -573,13 +602,22 @@ build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
573602
/* No uasm_i_nop needed here, since the next insn doesn't touch TMP. */
574603

575604
#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
576-
/*
577-
* &pgd << 11 stored in CONTEXT [23..63].
578-
*/
579-
UASM_i_MFC0(p, ptr, C0_CONTEXT);
580-
uasm_i_dins(p, ptr, 0, 0, 23); /* Clear lower 23 bits of context. */
581-
uasm_i_ori(p, ptr, ptr, 0x540); /* 1 0 1 0 1 << 6 xkphys cached */
582-
uasm_i_drotr(p, ptr, ptr, 11);
605+
if (pgd_reg != -1) {
606+
/* pgd is in pgd_reg */
607+
UASM_i_MFC0(p, ptr, 31, pgd_reg);
608+
} else {
609+
/*
610+
* &pgd << 11 stored in CONTEXT [23..63].
611+
*/
612+
UASM_i_MFC0(p, ptr, C0_CONTEXT);
613+
614+
/* Clear lower 23 bits of context. */
615+
uasm_i_dins(p, ptr, 0, 0, 23);
616+
617+
/* 1 0 1 0 1 << 6 xkphys cached */
618+
uasm_i_ori(p, ptr, ptr, 0x540);
619+
uasm_i_drotr(p, ptr, ptr, 11);
620+
}
583621
#elif defined(CONFIG_SMP)
584622
# ifdef CONFIG_MIPS_MT_SMTC
585623
/*
@@ -1014,6 +1052,55 @@ static void __cpuinit build_r4000_tlb_refill_handler(void)
10141052
u32 handle_tlbl[FASTPATH_SIZE] __cacheline_aligned;
10151053
u32 handle_tlbs[FASTPATH_SIZE] __cacheline_aligned;
10161054
u32 handle_tlbm[FASTPATH_SIZE] __cacheline_aligned;
1055+
#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
1056+
u32 tlbmiss_handler_setup_pgd[16] __cacheline_aligned;
1057+
1058+
static void __cpuinit build_r4000_setup_pgd(void)
1059+
{
1060+
const int a0 = 4;
1061+
const int a1 = 5;
1062+
u32 *p = tlbmiss_handler_setup_pgd;
1063+
struct uasm_label *l = labels;
1064+
struct uasm_reloc *r = relocs;
1065+
1066+
memset(tlbmiss_handler_setup_pgd, 0, sizeof(tlbmiss_handler_setup_pgd));
1067+
memset(labels, 0, sizeof(labels));
1068+
memset(relocs, 0, sizeof(relocs));
1069+
1070+
pgd_reg = allocate_kscratch();
1071+
1072+
if (pgd_reg == -1) {
1073+
/* PGD << 11 in c0_Context */
1074+
/*
1075+
* If it is a ckseg0 address, convert to a physical
1076+
* address. Shifting right by 29 and adding 4 will
1077+
* result in zero for these addresses.
1078+
*
1079+
*/
1080+
UASM_i_SRA(&p, a1, a0, 29);
1081+
UASM_i_ADDIU(&p, a1, a1, 4);
1082+
uasm_il_bnez(&p, &r, a1, label_tlbl_goaround1);
1083+
uasm_i_nop(&p);
1084+
uasm_i_dinsm(&p, a0, 0, 29, 64 - 29);
1085+
uasm_l_tlbl_goaround1(&l, p);
1086+
UASM_i_SLL(&p, a0, a0, 11);
1087+
uasm_i_jr(&p, 31);
1088+
UASM_i_MTC0(&p, a0, C0_CONTEXT);
1089+
} else {
1090+
/* PGD in c0_KScratch */
1091+
uasm_i_jr(&p, 31);
1092+
UASM_i_MTC0(&p, a0, 31, pgd_reg);
1093+
}
1094+
if (p - tlbmiss_handler_setup_pgd > ARRAY_SIZE(tlbmiss_handler_setup_pgd))
1095+
panic("tlbmiss_handler_setup_pgd space exceeded");
1096+
uasm_resolve_relocs(relocs, labels);
1097+
pr_debug("Wrote tlbmiss_handler_setup_pgd (%u instructions).\n",
1098+
(unsigned int)(p - tlbmiss_handler_setup_pgd));
1099+
1100+
dump_handler(tlbmiss_handler_setup_pgd,
1101+
ARRAY_SIZE(tlbmiss_handler_setup_pgd));
1102+
}
1103+
#endif
10171104

10181105
static void __cpuinit
10191106
iPTE_LW(u32 **p, unsigned int pte, unsigned int ptr)
@@ -1161,6 +1248,8 @@ build_pte_modifiable(u32 **p, struct uasm_reloc **r,
11611248
}
11621249

11631250
#ifndef CONFIG_MIPS_PGD_C0_CONTEXT
1251+
1252+
11641253
/*
11651254
* R3000 style TLB load/store/modify handlers.
11661255
*/
@@ -1623,13 +1712,16 @@ void __cpuinit build_tlb_refill_handler(void)
16231712
break;
16241713

16251714
default:
1626-
build_r4000_tlb_refill_handler();
16271715
if (!run_once) {
1716+
#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
1717+
build_r4000_setup_pgd();
1718+
#endif
16281719
build_r4000_tlb_load_handler();
16291720
build_r4000_tlb_store_handler();
16301721
build_r4000_tlb_modify_handler();
16311722
run_once++;
16321723
}
1724+
build_r4000_tlb_refill_handler();
16331725
}
16341726
}
16351727

@@ -1641,4 +1733,8 @@ void __cpuinit flush_tlb_handlers(void)
16411733
(unsigned long)handle_tlbs + sizeof(handle_tlbs));
16421734
local_flush_icache_range((unsigned long)handle_tlbm,
16431735
(unsigned long)handle_tlbm + sizeof(handle_tlbm));
1736+
#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
1737+
local_flush_icache_range((unsigned long)tlbmiss_handler_setup_pgd,
1738+
(unsigned long)tlbmiss_handler_setup_pgd + sizeof(handle_tlbm));
1739+
#endif
16441740
}

0 commit comments

Comments
 (0)