1 From c022630633624a75b3b58f43dd3c6cc896a56cff Mon Sep 17 00:00:00 2001
2 From: "Steven J. Hill" <sjhill@mips.com>
3 Date: Fri, 6 Jul 2012 21:56:01 +0200
4 Subject: [PATCH] MIPS: Refactor 'clear_page' and 'copy_page' functions.
6 Remove usage of the '__attribute__((alias("...")))' hack that aliased
7 to integer arrays containing micro-assembled instructions. This hack
8 breaks when building a microMIPS kernel. It also makes the code much
11 [ralf@linux-mips.org: Added back export of the clear_page and copy_page
12 symbols so certain modules will work again. Also fixed build with
13 CONFIG_SIBYTE_DMA_PAGEOPS enabled.]
15 Signed-off-by: Steven J. Hill <sjhill@mips.com>
16 Cc: linux-mips@linux-mips.org
17 Patchwork: https://patchwork.linux-mips.org/patch/3866/
18 Acked-by: David Daney <david.daney@cavium.com>
19 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
21 arch/mips/kernel/mips_ksyms.c | 8 ++++-
22 arch/mips/mm/Makefile | 4 +--
23 arch/mips/mm/page-funcs.S | 50 ++++++++++++++++++++++++++++++
24 arch/mips/mm/page.c | 67 +++++++++++------------------------------
25 4 files changed, 77 insertions(+), 52 deletions(-)
26 create mode 100644 arch/mips/mm/page-funcs.S
28 --- a/arch/mips/kernel/mips_ksyms.c
29 +++ b/arch/mips/kernel/mips_ksyms.c
31 * License. See the file "COPYING" in the main directory of this archive
34 - * Copyright (C) 1996, 97, 98, 99, 2000, 01, 03, 04, 05 by Ralf Baechle
35 + * Copyright (C) 1996, 97, 98, 99, 2000, 01, 03, 04, 05, 12 by Ralf Baechle
36 * Copyright (C) 1999, 2000, 01 Silicon Graphics, Inc.
38 #include <linux/interrupt.h>
39 @@ -35,6 +35,12 @@ EXPORT_SYMBOL(memmove);
40 EXPORT_SYMBOL(kernel_thread);
43 + * Functions that operate on entire pages. Mostly used by memory management.
45 +EXPORT_SYMBOL(clear_page);
46 +EXPORT_SYMBOL(copy_page);
49 * Userspace access stuff.
51 EXPORT_SYMBOL(__copy_user);
52 --- a/arch/mips/mm/Makefile
53 +++ b/arch/mips/mm/Makefile
57 obj-y += cache.o dma-default.o extable.o fault.o \
58 - gup.o init.o mmap.o page.o tlbex.o \
59 - tlbex-fault.o uasm.o
60 + gup.o init.o mmap.o page.o page-funcs.o \
61 + tlbex.o tlbex-fault.o uasm.o
63 obj-$(CONFIG_32BIT) += ioremap.o pgtable-32.o
64 obj-$(CONFIG_64BIT) += pgtable-64.o
66 +++ b/arch/mips/mm/page-funcs.S
69 + * This file is subject to the terms and conditions of the GNU General Public
70 + * License. See the file "COPYING" in the main directory of this archive
73 + * Micro-assembler generated clear_page/copy_page functions.
75 + * Copyright (C) 2012 MIPS Technologies, Inc.
76 + * Copyright (C) 2012 Ralf Baechle <ralf@linux-mips.org>
79 +#include <asm/regdef.h>
81 +#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
82 +#define cpu_clear_page_function_name clear_page_cpu
83 +#define cpu_copy_page_function_name copy_page_cpu
85 +#define cpu_clear_page_function_name clear_page
86 +#define cpu_copy_page_function_name copy_page
92 + * R4000 128 bytes S-cache: 0x058 bytes
93 + * R4600 v1.7: 0x05c bytes
94 + * R4600 v2.0: 0x060 bytes
95 + * With prefetching, 16 word strides 0x120 bytes
97 +EXPORT(__clear_page_start)
98 +LEAF(cpu_clear_page_function_name)
99 +1: j 1b /* Dummy, will be replaced. */
101 +END(cpu_clear_page_function_name)
102 +EXPORT(__clear_page_end)
107 + * R4000 128 bytes S-cache: 0x11c bytes
108 + * R4600 v1.7: 0x080 bytes
109 + * R4600 v2.0: 0x07c bytes
110 + * With prefetching, 16 word strides 0x540 bytes
112 +EXPORT(__copy_page_start)
113 +LEAF(cpu_copy_page_function_name)
114 +1: j 1b /* Dummy, will be replaced. */
116 +END(cpu_copy_page_function_name)
117 +EXPORT(__copy_page_end)
118 --- a/arch/mips/mm/page.c
119 +++ b/arch/mips/mm/page.c
121 * Copyright (C) 2003, 04, 05 Ralf Baechle (ralf@linux-mips.org)
122 * Copyright (C) 2007 Maciej W. Rozycki
123 * Copyright (C) 2008 Thiemo Seufer
124 + * Copyright (C) 2012 MIPS Technologies, Inc.
126 #include <linux/init.h>
127 #include <linux/kernel.h>
128 @@ -72,45 +73,6 @@ static struct uasm_reloc __cpuinitdata r
129 #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
130 #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
135 - * R4000 128 bytes S-cache: 0x058 bytes
136 - * R4600 v1.7: 0x05c bytes
137 - * R4600 v2.0: 0x060 bytes
138 - * With prefetching, 16 word strides 0x120 bytes
141 -static u32 clear_page_array[0x120 / 4];
143 -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
144 -void clear_page_cpu(void *page) __attribute__((alias("clear_page_array")));
146 -void clear_page(void *page) __attribute__((alias("clear_page_array")));
149 -EXPORT_SYMBOL(clear_page);
154 - * R4000 128 bytes S-cache: 0x11c bytes
155 - * R4600 v1.7: 0x080 bytes
156 - * R4600 v2.0: 0x07c bytes
157 - * With prefetching, 16 word strides 0x540 bytes
159 -static u32 copy_page_array[0x540 / 4];
161 -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
163 -copy_page_cpu(void *to, void *from) __attribute__((alias("copy_page_array")));
165 -void copy_page(void *to, void *from) __attribute__((alias("copy_page_array")));
168 -EXPORT_SYMBOL(copy_page);
171 static int pref_bias_clear_store __cpuinitdata;
172 static int pref_bias_copy_load __cpuinitdata;
173 static int pref_bias_copy_store __cpuinitdata;
174 @@ -283,10 +245,15 @@ static inline void __cpuinit build_clear
178 +extern u32 __clear_page_start;
179 +extern u32 __clear_page_end;
180 +extern u32 __copy_page_start;
181 +extern u32 __copy_page_end;
183 void __cpuinit build_clear_page(void)
186 - u32 *buf = (u32 *)&clear_page_array;
187 + u32 *buf = &__clear_page_start;
188 struct uasm_label *l = labels;
189 struct uasm_reloc *r = relocs;
191 @@ -357,17 +324,17 @@ void __cpuinit build_clear_page(void)
195 - BUG_ON(buf > clear_page_array + ARRAY_SIZE(clear_page_array));
196 + BUG_ON(buf > &__clear_page_end);
198 uasm_resolve_relocs(relocs, labels);
200 pr_debug("Synthesized clear page handler (%u instructions).\n",
201 - (u32)(buf - clear_page_array));
202 + (u32)(buf - &__clear_page_start));
204 pr_debug("\t.set push\n");
205 pr_debug("\t.set noreorder\n");
206 - for (i = 0; i < (buf - clear_page_array); i++)
207 - pr_debug("\t.word 0x%08x\n", clear_page_array[i]);
208 + for (i = 0; i < (buf - &__clear_page_start); i++)
209 + pr_debug("\t.word 0x%08x\n", (&__clear_page_start)[i]);
210 pr_debug("\t.set pop\n");
213 @@ -428,7 +395,7 @@ static inline void build_copy_store_pref
214 void __cpuinit build_copy_page(void)
217 - u32 *buf = (u32 *)©_page_array;
218 + u32 *buf = &__copy_page_start;
219 struct uasm_label *l = labels;
220 struct uasm_reloc *r = relocs;
222 @@ -596,21 +563,23 @@ void __cpuinit build_copy_page(void)
226 - BUG_ON(buf > copy_page_array + ARRAY_SIZE(copy_page_array));
227 + BUG_ON(buf > &__copy_page_end);
229 uasm_resolve_relocs(relocs, labels);
231 pr_debug("Synthesized copy page handler (%u instructions).\n",
232 - (u32)(buf - copy_page_array));
233 + (u32)(buf - &__copy_page_start));
235 pr_debug("\t.set push\n");
236 pr_debug("\t.set noreorder\n");
237 - for (i = 0; i < (buf - copy_page_array); i++)
238 - pr_debug("\t.word 0x%08x\n", copy_page_array[i]);
239 + for (i = 0; i < (buf - &__copy_page_start); i++)
240 + pr_debug("\t.word 0x%08x\n", (&__copy_page_start)[i]);
241 pr_debug("\t.set pop\n");
244 #ifdef CONFIG_SIBYTE_DMA_PAGEOPS
245 +extern void clear_page_cpu(void *page);
246 +extern void copy_page_cpu(void *to, void *from);
249 * Pad descriptors to cacheline, since each is exclusively owned by a