003-MIPS-Refactor-clear_page-and-copy_page-functions.patch 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.
  5. Remove usage of the '__attribute__((alias("...")))' hack that aliased
  6. to integer arrays containing micro-assembled instructions. This hack
  7. breaks when building a microMIPS kernel. It also makes the code much
  8. easier to understand.
  9. [ralf@linux-mips.org: Added back export of the clear_page and copy_page
  10. symbols so certain modules will work again. Also fixed build with
  11. CONFIG_SIBYTE_DMA_PAGEOPS enabled.]
  12. Signed-off-by: Steven J. Hill <sjhill@mips.com>
  13. Cc: linux-mips@linux-mips.org
  14. Patchwork: https://patchwork.linux-mips.org/patch/3866/
  15. Acked-by: David Daney <david.daney@cavium.com>
  16. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  17. ---
  18. arch/mips/kernel/mips_ksyms.c | 8 ++++-
  19. arch/mips/mm/Makefile | 4 +--
  20. arch/mips/mm/page-funcs.S | 50 ++++++++++++++++++++++++++++++
  21. arch/mips/mm/page.c | 67 +++++++++++------------------------------
  22. 4 files changed, 77 insertions(+), 52 deletions(-)
  23. create mode 100644 arch/mips/mm/page-funcs.S
  24. --- a/arch/mips/kernel/mips_ksyms.c
  25. +++ b/arch/mips/kernel/mips_ksyms.c
  26. @@ -5,7 +5,7 @@
  27. * License. See the file "COPYING" in the main directory of this archive
  28. * for more details.
  29. *
  30. - * Copyright (C) 1996, 97, 98, 99, 2000, 01, 03, 04, 05 by Ralf Baechle
  31. + * Copyright (C) 1996, 97, 98, 99, 2000, 01, 03, 04, 05, 12 by Ralf Baechle
  32. * Copyright (C) 1999, 2000, 01 Silicon Graphics, Inc.
  33. */
  34. #include <linux/interrupt.h>
  35. @@ -35,6 +35,12 @@ EXPORT_SYMBOL(memmove);
  36. EXPORT_SYMBOL(kernel_thread);
  37. /*
  38. + * Functions that operate on entire pages. Mostly used by memory management.
  39. + */
  40. +EXPORT_SYMBOL(clear_page);
  41. +EXPORT_SYMBOL(copy_page);
  42. +
  43. +/*
  44. * Userspace access stuff.
  45. */
  46. EXPORT_SYMBOL(__copy_user);
  47. --- a/arch/mips/mm/Makefile
  48. +++ b/arch/mips/mm/Makefile
  49. @@ -3,8 +3,8 @@
  50. #
  51. obj-y += cache.o dma-default.o extable.o fault.o \
  52. - gup.o init.o mmap.o page.o tlbex.o \
  53. - tlbex-fault.o uasm.o
  54. + gup.o init.o mmap.o page.o page-funcs.o \
  55. + tlbex.o tlbex-fault.o uasm.o
  56. obj-$(CONFIG_32BIT) += ioremap.o pgtable-32.o
  57. obj-$(CONFIG_64BIT) += pgtable-64.o
  58. --- /dev/null
  59. +++ b/arch/mips/mm/page-funcs.S
  60. @@ -0,0 +1,50 @@
  61. +/*
  62. + * This file is subject to the terms and conditions of the GNU General Public
  63. + * License. See the file "COPYING" in the main directory of this archive
  64. + * for more details.
  65. + *
  66. + * Micro-assembler generated clear_page/copy_page functions.
  67. + *
  68. + * Copyright (C) 2012 MIPS Technologies, Inc.
  69. + * Copyright (C) 2012 Ralf Baechle <ralf@linux-mips.org>
  70. + */
  71. +#include <asm/asm.h>
  72. +#include <asm/regdef.h>
  73. +
  74. +#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
  75. +#define cpu_clear_page_function_name clear_page_cpu
  76. +#define cpu_copy_page_function_name copy_page_cpu
  77. +#else
  78. +#define cpu_clear_page_function_name clear_page
  79. +#define cpu_copy_page_function_name copy_page
  80. +#endif
  81. +
  82. +/*
  83. + * Maximum sizes:
  84. + *
  85. + * R4000 128 bytes S-cache: 0x058 bytes
  86. + * R4600 v1.7: 0x05c bytes
  87. + * R4600 v2.0: 0x060 bytes
  88. + * With prefetching, 16 word strides 0x120 bytes
  89. + */
  90. +EXPORT(__clear_page_start)
  91. +LEAF(cpu_clear_page_function_name)
  92. +1: j 1b /* Dummy, will be replaced. */
  93. + .space 288
  94. +END(cpu_clear_page_function_name)
  95. +EXPORT(__clear_page_end)
  96. +
  97. +/*
  98. + * Maximum sizes:
  99. + *
  100. + * R4000 128 bytes S-cache: 0x11c bytes
  101. + * R4600 v1.7: 0x080 bytes
  102. + * R4600 v2.0: 0x07c bytes
  103. + * With prefetching, 16 word strides 0x540 bytes
  104. + */
  105. +EXPORT(__copy_page_start)
  106. +LEAF(cpu_copy_page_function_name)
  107. +1: j 1b /* Dummy, will be replaced. */
  108. + .space 1344
  109. +END(cpu_copy_page_function_name)
  110. +EXPORT(__copy_page_end)
  111. --- a/arch/mips/mm/page.c
  112. +++ b/arch/mips/mm/page.c
  113. @@ -6,6 +6,7 @@
  114. * Copyright (C) 2003, 04, 05 Ralf Baechle (ralf@linux-mips.org)
  115. * Copyright (C) 2007 Maciej W. Rozycki
  116. * Copyright (C) 2008 Thiemo Seufer
  117. + * Copyright (C) 2012 MIPS Technologies, Inc.
  118. */
  119. #include <linux/init.h>
  120. #include <linux/kernel.h>
  121. @@ -72,45 +73,6 @@ static struct uasm_reloc __cpuinitdata r
  122. #define cpu_is_r4600_v1_x() ((read_c0_prid() & 0xfffffff0) == 0x00002010)
  123. #define cpu_is_r4600_v2_x() ((read_c0_prid() & 0xfffffff0) == 0x00002020)
  124. -/*
  125. - * Maximum sizes:
  126. - *
  127. - * R4000 128 bytes S-cache: 0x058 bytes
  128. - * R4600 v1.7: 0x05c bytes
  129. - * R4600 v2.0: 0x060 bytes
  130. - * With prefetching, 16 word strides 0x120 bytes
  131. - */
  132. -
  133. -static u32 clear_page_array[0x120 / 4];
  134. -
  135. -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
  136. -void clear_page_cpu(void *page) __attribute__((alias("clear_page_array")));
  137. -#else
  138. -void clear_page(void *page) __attribute__((alias("clear_page_array")));
  139. -#endif
  140. -
  141. -EXPORT_SYMBOL(clear_page);
  142. -
  143. -/*
  144. - * Maximum sizes:
  145. - *
  146. - * R4000 128 bytes S-cache: 0x11c bytes
  147. - * R4600 v1.7: 0x080 bytes
  148. - * R4600 v2.0: 0x07c bytes
  149. - * With prefetching, 16 word strides 0x540 bytes
  150. - */
  151. -static u32 copy_page_array[0x540 / 4];
  152. -
  153. -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
  154. -void
  155. -copy_page_cpu(void *to, void *from) __attribute__((alias("copy_page_array")));
  156. -#else
  157. -void copy_page(void *to, void *from) __attribute__((alias("copy_page_array")));
  158. -#endif
  159. -
  160. -EXPORT_SYMBOL(copy_page);
  161. -
  162. -
  163. static int pref_bias_clear_store __cpuinitdata;
  164. static int pref_bias_copy_load __cpuinitdata;
  165. static int pref_bias_copy_store __cpuinitdata;
  166. @@ -283,10 +245,15 @@ static inline void __cpuinit build_clear
  167. }
  168. }
  169. +extern u32 __clear_page_start;
  170. +extern u32 __clear_page_end;
  171. +extern u32 __copy_page_start;
  172. +extern u32 __copy_page_end;
  173. +
  174. void __cpuinit build_clear_page(void)
  175. {
  176. int off;
  177. - u32 *buf = (u32 *)&clear_page_array;
  178. + u32 *buf = &__clear_page_start;
  179. struct uasm_label *l = labels;
  180. struct uasm_reloc *r = relocs;
  181. int i;
  182. @@ -357,17 +324,17 @@ void __cpuinit build_clear_page(void)
  183. uasm_i_jr(&buf, RA);
  184. uasm_i_nop(&buf);
  185. - BUG_ON(buf > clear_page_array + ARRAY_SIZE(clear_page_array));
  186. + BUG_ON(buf > &__clear_page_end);
  187. uasm_resolve_relocs(relocs, labels);
  188. pr_debug("Synthesized clear page handler (%u instructions).\n",
  189. - (u32)(buf - clear_page_array));
  190. + (u32)(buf - &__clear_page_start));
  191. pr_debug("\t.set push\n");
  192. pr_debug("\t.set noreorder\n");
  193. - for (i = 0; i < (buf - clear_page_array); i++)
  194. - pr_debug("\t.word 0x%08x\n", clear_page_array[i]);
  195. + for (i = 0; i < (buf - &__clear_page_start); i++)
  196. + pr_debug("\t.word 0x%08x\n", (&__clear_page_start)[i]);
  197. pr_debug("\t.set pop\n");
  198. }
  199. @@ -428,7 +395,7 @@ static inline void build_copy_store_pref
  200. void __cpuinit build_copy_page(void)
  201. {
  202. int off;
  203. - u32 *buf = (u32 *)&copy_page_array;
  204. + u32 *buf = &__copy_page_start;
  205. struct uasm_label *l = labels;
  206. struct uasm_reloc *r = relocs;
  207. int i;
  208. @@ -596,21 +563,23 @@ void __cpuinit build_copy_page(void)
  209. uasm_i_jr(&buf, RA);
  210. uasm_i_nop(&buf);
  211. - BUG_ON(buf > copy_page_array + ARRAY_SIZE(copy_page_array));
  212. + BUG_ON(buf > &__copy_page_end);
  213. uasm_resolve_relocs(relocs, labels);
  214. pr_debug("Synthesized copy page handler (%u instructions).\n",
  215. - (u32)(buf - copy_page_array));
  216. + (u32)(buf - &__copy_page_start));
  217. pr_debug("\t.set push\n");
  218. pr_debug("\t.set noreorder\n");
  219. - for (i = 0; i < (buf - copy_page_array); i++)
  220. - pr_debug("\t.word 0x%08x\n", copy_page_array[i]);
  221. + for (i = 0; i < (buf - &__copy_page_start); i++)
  222. + pr_debug("\t.word 0x%08x\n", (&__copy_page_start)[i]);
  223. pr_debug("\t.set pop\n");
  224. }
  225. #ifdef CONFIG_SIBYTE_DMA_PAGEOPS
  226. +extern void clear_page_cpu(void *page);
  227. +extern void copy_page_cpu(void *to, void *from);
  228. /*
  229. * Pad descriptors to cacheline, since each is exclusively owned by a