Skip to content

Commit 6ba045f

Browse files
jchandra-brcmralfbaechle
authored andcommitted
MIPS: Move generated code to .text for microMIPS
Prepare of a next patch which will call tlbmiss_handler_setup_pgd on microMIPS. MicroMIPS complains if the called code s not in the .text section. To fix this we generate code into space reserved in arch/mips/mm/tlb-funcs.S While there, move the rest of the generated functions (handle_tlbl, handle_tlbs, handle_tlbm) to the same file. Signed-off-by: Jayachandran C <[email protected]> Cc: [email protected] Patchwork: https://patchwork.linux-mips.org/patch/5542/ Signed-off-by: Ralf Baechle <[email protected]>
1 parent 1990e54 commit 6ba045f

File tree

4 files changed

+83
-46
lines changed

4 files changed

+83
-46
lines changed

arch/mips/include/asm/mmu_context.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@
2828

2929
#define TLBMISS_HANDLER_SETUP_PGD(pgd) \
3030
do { \
31-
void (*tlbmiss_handler_setup_pgd)(unsigned long); \
32-
extern u32 tlbmiss_handler_setup_pgd_array[16]; \
33-
\
34-
tlbmiss_handler_setup_pgd = \
35-
(__typeof__(tlbmiss_handler_setup_pgd)) tlbmiss_handler_setup_pgd_array; \
31+
extern void tlbmiss_handler_setup_pgd(unsigned long); \
3632
tlbmiss_handler_setup_pgd((unsigned long)(pgd)); \
3733
} while (0)
3834

arch/mips/mm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
obj-y += cache.o dma-default.o extable.o fault.o \
66
gup.o init.o mmap.o page.o page-funcs.o \
7-
tlbex.o tlbex-fault.o uasm-mips.o
7+
tlbex.o tlbex-fault.o tlb-funcs.o uasm-mips.o
88

99
obj-$(CONFIG_32BIT) += ioremap.o pgtable-32.o
1010
obj-$(CONFIG_64BIT) += pgtable-64.o

arch/mips/mm/tlb-funcs.S

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file is subject to the terms and conditions of the GNU General Public
3+
* License. See the file "COPYING" in the main directory of this archive
4+
* for more details.
5+
*
6+
* Micro-assembler generated tlb handler functions.
7+
*
8+
* Copyright (C) 2013 Broadcom Corporation.
9+
*
10+
* Based on mm/page-funcs.c
11+
* Copyright (C) 2012 MIPS Technologies, Inc.
12+
* Copyright (C) 2012 Ralf Baechle <[email protected]>
13+
*/
14+
#include <asm/asm.h>
15+
#include <asm/regdef.h>
16+
17+
#define FASTPATH_SIZE 128
18+
19+
LEAF(tlbmiss_handler_setup_pgd)
20+
.space 16 * 4
21+
END(tlbmiss_handler_setup_pgd)
22+
EXPORT(tlbmiss_handler_setup_pgd_end)
23+
24+
LEAF(handle_tlbm)
25+
.space FASTPATH_SIZE * 4
26+
END(handle_tlbm)
27+
EXPORT(handle_tlbm_end)
28+
29+
LEAF(handle_tlbs)
30+
.space FASTPATH_SIZE * 4
31+
END(handle_tlbs)
32+
EXPORT(handle_tlbs_end)
33+
34+
LEAF(handle_tlbl)
35+
.space FASTPATH_SIZE * 4
36+
END(handle_tlbl)
37+
EXPORT(handle_tlbl_end)

arch/mips/mm/tlbex.c

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,27 +1455,25 @@ static void __cpuinit build_r4000_tlb_refill_handler(void)
14551455
dump_handler("r4000_tlb_refill", (u32 *)ebase, 64);
14561456
}
14571457

1458-
/*
1459-
* 128 instructions for the fastpath handler is generous and should
1460-
* never be exceeded.
1461-
*/
1462-
#define FASTPATH_SIZE 128
1458+
extern u32 handle_tlbl[], handle_tlbl_end[];
1459+
extern u32 handle_tlbs[], handle_tlbs_end[];
1460+
extern u32 handle_tlbm[], handle_tlbm_end[];
14631461

1464-
u32 handle_tlbl[FASTPATH_SIZE] __cacheline_aligned;
1465-
u32 handle_tlbs[FASTPATH_SIZE] __cacheline_aligned;
1466-
u32 handle_tlbm[FASTPATH_SIZE] __cacheline_aligned;
14671462
#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
1468-
u32 tlbmiss_handler_setup_pgd_array[16] __cacheline_aligned;
1463+
extern u32 tlbmiss_handler_setup_pgd[], tlbmiss_handler_setup_pgd_end[];
14691464

14701465
static void __cpuinit build_r4000_setup_pgd(void)
14711466
{
14721467
const int a0 = 4;
14731468
const int a1 = 5;
14741469
u32 *p = tlbmiss_handler_setup_pgd_array;
1470+
const int tlbmiss_handler_setup_pgd_size =
1471+
tlbmiss_handler_setup_pgd_end - tlbmiss_handler_setup_pgd;
14751472
struct uasm_label *l = labels;
14761473
struct uasm_reloc *r = relocs;
14771474

1478-
memset(tlbmiss_handler_setup_pgd_array, 0, sizeof(tlbmiss_handler_setup_pgd_array));
1475+
memset(tlbmiss_handler_setup_pgd, 0, tlbmiss_handler_setup_pgd_size *
1476+
sizeof(tlbmiss_handler_setup_pgd[0]));
14791477
memset(labels, 0, sizeof(labels));
14801478
memset(relocs, 0, sizeof(relocs));
14811479

@@ -1503,15 +1501,15 @@ static void __cpuinit build_r4000_setup_pgd(void)
15031501
uasm_i_jr(&p, 31);
15041502
UASM_i_MTC0(&p, a0, c0_kscratch(), pgd_reg);
15051503
}
1506-
if (p - tlbmiss_handler_setup_pgd_array > ARRAY_SIZE(tlbmiss_handler_setup_pgd_array))
1507-
panic("tlbmiss_handler_setup_pgd_array space exceeded");
1504+
if (p >= tlbmiss_handler_setup_pgd_end)
1505+
panic("tlbmiss_handler_setup_pgd space exceeded");
1506+
15081507
uasm_resolve_relocs(relocs, labels);
1509-
pr_debug("Wrote tlbmiss_handler_setup_pgd_array (%u instructions).\n",
1510-
(unsigned int)(p - tlbmiss_handler_setup_pgd_array));
1508+
pr_debug("Wrote tlbmiss_handler_setup_pgd (%u instructions).\n",
1509+
(unsigned int)(p - tlbmiss_handler_setup_pgd));
15111510

1512-
dump_handler("tlbmiss_handler",
1513-
tlbmiss_handler_setup_pgd_array,
1514-
ARRAY_SIZE(tlbmiss_handler_setup_pgd_array));
1511+
dump_handler("tlbmiss_handler", tlbmiss_handler_setup_pgd,
1512+
tlbmiss_handler_setup_pgd_size);
15151513
}
15161514
#endif
15171515

@@ -1756,10 +1754,11 @@ build_r3000_tlbchange_handler_head(u32 **p, unsigned int pte,
17561754
static void __cpuinit build_r3000_tlb_load_handler(void)
17571755
{
17581756
u32 *p = handle_tlbl;
1757+
const int handle_tlbl_size = handle_tlbl_end - handle_tlbl;
17591758
struct uasm_label *l = labels;
17601759
struct uasm_reloc *r = relocs;
17611760

1762-
memset(handle_tlbl, 0, sizeof(handle_tlbl));
1761+
memset(handle_tlbl, 0, handle_tlbl_size * sizeof(handle_tlbl[0]));
17631762
memset(labels, 0, sizeof(labels));
17641763
memset(relocs, 0, sizeof(relocs));
17651764

@@ -1773,23 +1772,24 @@ static void __cpuinit build_r3000_tlb_load_handler(void)
17731772
uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff);
17741773
uasm_i_nop(&p);
17751774

1776-
if ((p - handle_tlbl) > FASTPATH_SIZE)
1775+
if (p >= handle_tlbl_end)
17771776
panic("TLB load handler fastpath space exceeded");
17781777

17791778
uasm_resolve_relocs(relocs, labels);
17801779
pr_debug("Wrote TLB load handler fastpath (%u instructions).\n",
17811780
(unsigned int)(p - handle_tlbl));
17821781

1783-
dump_handler("r3000_tlb_load", handle_tlbl, ARRAY_SIZE(handle_tlbl));
1782+
dump_handler("r3000_tlb_load", handle_tlbl, handle_tlbl_size);
17841783
}
17851784

17861785
static void __cpuinit build_r3000_tlb_store_handler(void)
17871786
{
17881787
u32 *p = handle_tlbs;
1788+
const int handle_tlbs_size = handle_tlbs_end - handle_tlbs;
17891789
struct uasm_label *l = labels;
17901790
struct uasm_reloc *r = relocs;
17911791

1792-
memset(handle_tlbs, 0, sizeof(handle_tlbs));
1792+
memset(handle_tlbs, 0, handle_tlbs_size * sizeof(handle_tlbs[0]));
17931793
memset(labels, 0, sizeof(labels));
17941794
memset(relocs, 0, sizeof(relocs));
17951795

@@ -1803,23 +1803,24 @@ static void __cpuinit build_r3000_tlb_store_handler(void)
18031803
uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
18041804
uasm_i_nop(&p);
18051805

1806-
if ((p - handle_tlbs) > FASTPATH_SIZE)
1806+
if (p >= handle_tlbs)
18071807
panic("TLB store handler fastpath space exceeded");
18081808

18091809
uasm_resolve_relocs(relocs, labels);
18101810
pr_debug("Wrote TLB store handler fastpath (%u instructions).\n",
18111811
(unsigned int)(p - handle_tlbs));
18121812

1813-
dump_handler("r3000_tlb_store", handle_tlbs, ARRAY_SIZE(handle_tlbs));
1813+
dump_handler("r3000_tlb_store", handle_tlbs, handle_tlbs_size);
18141814
}
18151815

18161816
static void __cpuinit build_r3000_tlb_modify_handler(void)
18171817
{
18181818
u32 *p = handle_tlbm;
1819+
const int handle_tlbm_size = handle_tlbm_end - handle_tlbm;
18191820
struct uasm_label *l = labels;
18201821
struct uasm_reloc *r = relocs;
18211822

1822-
memset(handle_tlbm, 0, sizeof(handle_tlbm));
1823+
memset(handle_tlbm, 0, handle_tlbm_size * sizeof(handle_tlbm[0]));
18231824
memset(labels, 0, sizeof(labels));
18241825
memset(relocs, 0, sizeof(relocs));
18251826

@@ -1833,14 +1834,14 @@ static void __cpuinit build_r3000_tlb_modify_handler(void)
18331834
uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
18341835
uasm_i_nop(&p);
18351836

1836-
if ((p - handle_tlbm) > FASTPATH_SIZE)
1837+
if (p >= handle_tlbm_end)
18371838
panic("TLB modify handler fastpath space exceeded");
18381839

18391840
uasm_resolve_relocs(relocs, labels);
18401841
pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n",
18411842
(unsigned int)(p - handle_tlbm));
18421843

1843-
dump_handler("r3000_tlb_modify", handle_tlbm, ARRAY_SIZE(handle_tlbm));
1844+
dump_handler("r3000_tlb_modify", handle_tlbm, handle_tlbm_size);
18441845
}
18451846
#endif /* CONFIG_MIPS_PGD_C0_CONTEXT */
18461847

@@ -1904,11 +1905,12 @@ build_r4000_tlbchange_handler_tail(u32 **p, struct uasm_label **l,
19041905
static void __cpuinit build_r4000_tlb_load_handler(void)
19051906
{
19061907
u32 *p = handle_tlbl;
1908+
const int handle_tlbl_size = handle_tlbl_end - handle_tlbl;
19071909
struct uasm_label *l = labels;
19081910
struct uasm_reloc *r = relocs;
19091911
struct work_registers wr;
19101912

1911-
memset(handle_tlbl, 0, sizeof(handle_tlbl));
1913+
memset(handle_tlbl, 0, handle_tlbl_size * sizeof(handle_tlbl[0]));
19121914
memset(labels, 0, sizeof(labels));
19131915
memset(relocs, 0, sizeof(relocs));
19141916

@@ -2047,24 +2049,25 @@ static void __cpuinit build_r4000_tlb_load_handler(void)
20472049
uasm_i_j(&p, (unsigned long)tlb_do_page_fault_0 & 0x0fffffff);
20482050
uasm_i_nop(&p);
20492051

2050-
if ((p - handle_tlbl) > FASTPATH_SIZE)
2052+
if (p >= handle_tlbl_end)
20512053
panic("TLB load handler fastpath space exceeded");
20522054

20532055
uasm_resolve_relocs(relocs, labels);
20542056
pr_debug("Wrote TLB load handler fastpath (%u instructions).\n",
20552057
(unsigned int)(p - handle_tlbl));
20562058

2057-
dump_handler("r4000_tlb_load", handle_tlbl, ARRAY_SIZE(handle_tlbl));
2059+
dump_handler("r4000_tlb_load", handle_tlbl, handle_tlbl_size);
20582060
}
20592061

20602062
static void __cpuinit build_r4000_tlb_store_handler(void)
20612063
{
20622064
u32 *p = handle_tlbs;
2065+
const int handle_tlbs_size = handle_tlbs_end - handle_tlbs;
20632066
struct uasm_label *l = labels;
20642067
struct uasm_reloc *r = relocs;
20652068
struct work_registers wr;
20662069

2067-
memset(handle_tlbs, 0, sizeof(handle_tlbs));
2070+
memset(handle_tlbs, 0, handle_tlbs_size * sizeof(handle_tlbs[0]));
20682071
memset(labels, 0, sizeof(labels));
20692072
memset(relocs, 0, sizeof(relocs));
20702073

@@ -2101,24 +2104,25 @@ static void __cpuinit build_r4000_tlb_store_handler(void)
21012104
uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
21022105
uasm_i_nop(&p);
21032106

2104-
if ((p - handle_tlbs) > FASTPATH_SIZE)
2107+
if (p >= handle_tlbs_end)
21052108
panic("TLB store handler fastpath space exceeded");
21062109

21072110
uasm_resolve_relocs(relocs, labels);
21082111
pr_debug("Wrote TLB store handler fastpath (%u instructions).\n",
21092112
(unsigned int)(p - handle_tlbs));
21102113

2111-
dump_handler("r4000_tlb_store", handle_tlbs, ARRAY_SIZE(handle_tlbs));
2114+
dump_handler("r4000_tlb_store", handle_tlbs, handle_tlbs_size);
21122115
}
21132116

21142117
static void __cpuinit build_r4000_tlb_modify_handler(void)
21152118
{
21162119
u32 *p = handle_tlbm;
2120+
const int handle_tlbm_size = handle_tlbm_end - handle_tlbm;
21172121
struct uasm_label *l = labels;
21182122
struct uasm_reloc *r = relocs;
21192123
struct work_registers wr;
21202124

2121-
memset(handle_tlbm, 0, sizeof(handle_tlbm));
2125+
memset(handle_tlbm, 0, handle_tlbm_size * sizeof(handle_tlbm[0]));
21222126
memset(labels, 0, sizeof(labels));
21232127
memset(relocs, 0, sizeof(relocs));
21242128

@@ -2156,14 +2160,14 @@ static void __cpuinit build_r4000_tlb_modify_handler(void)
21562160
uasm_i_j(&p, (unsigned long)tlb_do_page_fault_1 & 0x0fffffff);
21572161
uasm_i_nop(&p);
21582162

2159-
if ((p - handle_tlbm) > FASTPATH_SIZE)
2163+
if (p >= handle_tlbm_end)
21602164
panic("TLB modify handler fastpath space exceeded");
21612165

21622166
uasm_resolve_relocs(relocs, labels);
21632167
pr_debug("Wrote TLB modify handler fastpath (%u instructions).\n",
21642168
(unsigned int)(p - handle_tlbm));
21652169

2166-
dump_handler("r4000_tlb_modify", handle_tlbm, ARRAY_SIZE(handle_tlbm));
2170+
dump_handler("r4000_tlb_modify", handle_tlbm, handle_tlbm_size);
21672171
}
21682172

21692173
void __cpuinit build_tlb_refill_handler(void)
@@ -2235,13 +2239,13 @@ void __cpuinit build_tlb_refill_handler(void)
22352239
void __cpuinit flush_tlb_handlers(void)
22362240
{
22372241
local_flush_icache_range((unsigned long)handle_tlbl,
2238-
(unsigned long)handle_tlbl + sizeof(handle_tlbl));
2242+
(unsigned long)handle_tlbl_end);
22392243
local_flush_icache_range((unsigned long)handle_tlbs,
2240-
(unsigned long)handle_tlbs + sizeof(handle_tlbs));
2244+
(unsigned long)handle_tlbs_end);
22412245
local_flush_icache_range((unsigned long)handle_tlbm,
2242-
(unsigned long)handle_tlbm + sizeof(handle_tlbm));
2246+
(unsigned long)handle_tlbm_end);
22432247
#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
2244-
local_flush_icache_range((unsigned long)tlbmiss_handler_setup_pgd_array,
2245-
(unsigned long)tlbmiss_handler_setup_pgd_array + sizeof(handle_tlbm));
2248+
local_flush_icache_range((unsigned long)tlbmiss_handler_setup_pgd,
2249+
(unsigned long)tlbmiss_handler_setup_pgd_end);
22462250
#endif
22472251
}

0 commit comments

Comments
 (0)