cache-tauros2.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * arch/arm/mm/cache-tauros2.c - Tauros2 L2 cache controller support
  3. *
  4. * Copyright (C) 2008 Marvell Semiconductor
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. *
  10. * References:
  11. * - PJ1 CPU Core Datasheet,
  12. * Document ID MV-S104837-01, Rev 0.7, January 24 2008.
  13. * - PJ4 CPU Core Datasheet,
  14. * Document ID MV-S105190-00, Rev 0.7, March 14 2008.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <asm/cacheflush.h>
  20. #include <asm/cp15.h>
  21. #include <asm/cputype.h>
  22. #include <asm/hardware/cache-tauros2.h>
  23. /*
  24. * When Tauros2 is used on a CPU that supports the v7 hierarchical
  25. * cache operations, the cache handling code in proc-v7.S takes care
  26. * of everything, including handling DMA coherency.
  27. *
  28. * So, we only need to register outer cache operations here if we're
  29. * being used on a pre-v7 CPU, and we only need to build support for
  30. * outer cache operations into the kernel image if the kernel has been
  31. * configured to support a pre-v7 CPU.
  32. */
  33. #ifdef CONFIG_CPU_32v5
  34. /*
  35. * Low-level cache maintenance operations.
  36. */
  37. static inline void tauros2_clean_pa(unsigned long addr)
  38. {
  39. __asm__("mcr p15, 1, %0, c7, c11, 3" : : "r" (addr));
  40. }
  41. static inline void tauros2_clean_inv_pa(unsigned long addr)
  42. {
  43. __asm__("mcr p15, 1, %0, c7, c15, 3" : : "r" (addr));
  44. }
  45. static inline void tauros2_inv_pa(unsigned long addr)
  46. {
  47. __asm__("mcr p15, 1, %0, c7, c7, 3" : : "r" (addr));
  48. }
  49. /*
  50. * Linux primitives.
  51. *
  52. * Note that the end addresses passed to Linux primitives are
  53. * noninclusive.
  54. */
  55. #define CACHE_LINE_SIZE 32
  56. static void tauros2_inv_range(unsigned long start, unsigned long end)
  57. {
  58. /*
  59. * Clean and invalidate partial first cache line.
  60. */
  61. if (start & (CACHE_LINE_SIZE - 1)) {
  62. tauros2_clean_inv_pa(start & ~(CACHE_LINE_SIZE - 1));
  63. start = (start | (CACHE_LINE_SIZE - 1)) + 1;
  64. }
  65. /*
  66. * Clean and invalidate partial last cache line.
  67. */
  68. if (end & (CACHE_LINE_SIZE - 1)) {
  69. tauros2_clean_inv_pa(end & ~(CACHE_LINE_SIZE - 1));
  70. end &= ~(CACHE_LINE_SIZE - 1);
  71. }
  72. /*
  73. * Invalidate all full cache lines between 'start' and 'end'.
  74. */
  75. while (start < end) {
  76. tauros2_inv_pa(start);
  77. start += CACHE_LINE_SIZE;
  78. }
  79. dsb();
  80. }
  81. static void tauros2_clean_range(unsigned long start, unsigned long end)
  82. {
  83. start &= ~(CACHE_LINE_SIZE - 1);
  84. while (start < end) {
  85. tauros2_clean_pa(start);
  86. start += CACHE_LINE_SIZE;
  87. }
  88. dsb();
  89. }
  90. static void tauros2_flush_range(unsigned long start, unsigned long end)
  91. {
  92. start &= ~(CACHE_LINE_SIZE - 1);
  93. while (start < end) {
  94. tauros2_clean_inv_pa(start);
  95. start += CACHE_LINE_SIZE;
  96. }
  97. dsb();
  98. }
  99. static void tauros2_disable(void)
  100. {
  101. __asm__ __volatile__ (
  102. "mcr p15, 1, %0, c7, c11, 0 @L2 Cache Clean All\n\t"
  103. "mrc p15, 0, %0, c1, c0, 0\n\t"
  104. "bic %0, %0, #(1 << 26)\n\t"
  105. "mcr p15, 0, %0, c1, c0, 0 @Disable L2 Cache\n\t"
  106. : : "r" (0x0));
  107. }
  108. static void tauros2_resume(void)
  109. {
  110. __asm__ __volatile__ (
  111. "mcr p15, 1, %0, c7, c7, 0 @L2 Cache Invalidate All\n\t"
  112. "mrc p15, 0, %0, c1, c0, 0\n\t"
  113. "orr %0, %0, #(1 << 26)\n\t"
  114. "mcr p15, 0, %0, c1, c0, 0 @Enable L2 Cache\n\t"
  115. : : "r" (0x0));
  116. }
  117. #endif
  118. static inline u32 __init read_extra_features(void)
  119. {
  120. u32 u;
  121. __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (u));
  122. return u;
  123. }
  124. static inline void __init write_extra_features(u32 u)
  125. {
  126. __asm__("mcr p15, 1, %0, c15, c1, 0" : : "r" (u));
  127. }
  128. static inline int __init cpuid_scheme(void)
  129. {
  130. return !!((processor_id & 0x000f0000) == 0x000f0000);
  131. }
  132. static inline u32 __init read_mmfr3(void)
  133. {
  134. u32 mmfr3;
  135. __asm__("mrc p15, 0, %0, c0, c1, 7\n" : "=r" (mmfr3));
  136. return mmfr3;
  137. }
  138. static inline u32 __init read_actlr(void)
  139. {
  140. u32 actlr;
  141. __asm__("mrc p15, 0, %0, c1, c0, 1\n" : "=r" (actlr));
  142. return actlr;
  143. }
  144. static inline void __init write_actlr(u32 actlr)
  145. {
  146. __asm__("mcr p15, 0, %0, c1, c0, 1\n" : : "r" (actlr));
  147. }
  148. static void enable_extra_feature(unsigned int features)
  149. {
  150. u32 u;
  151. u = read_extra_features();
  152. if (features & CACHE_TAUROS2_PREFETCH_ON)
  153. u &= ~0x01000000;
  154. else
  155. u |= 0x01000000;
  156. pr_info("Tauros2: %s L2 prefetch.\n",
  157. (features & CACHE_TAUROS2_PREFETCH_ON)
  158. ? "Enabling" : "Disabling");
  159. if (features & CACHE_TAUROS2_LINEFILL_BURST8)
  160. u |= 0x00100000;
  161. else
  162. u &= ~0x00100000;
  163. pr_info("Tauros2: %s line fill burt8.\n",
  164. (features & CACHE_TAUROS2_LINEFILL_BURST8)
  165. ? "Enabling" : "Disabling");
  166. write_extra_features(u);
  167. }
  168. static void __init tauros2_internal_init(unsigned int features)
  169. {
  170. char *mode = NULL;
  171. enable_extra_feature(features);
  172. #ifdef CONFIG_CPU_32v5
  173. if ((processor_id & 0xff0f0000) == 0x56050000) {
  174. u32 feat;
  175. /*
  176. * v5 CPUs with Tauros2 have the L2 cache enable bit
  177. * located in the CPU Extra Features register.
  178. */
  179. feat = read_extra_features();
  180. if (!(feat & 0x00400000)) {
  181. pr_info("Tauros2: Enabling L2 cache.\n");
  182. write_extra_features(feat | 0x00400000);
  183. }
  184. mode = "ARMv5";
  185. outer_cache.inv_range = tauros2_inv_range;
  186. outer_cache.clean_range = tauros2_clean_range;
  187. outer_cache.flush_range = tauros2_flush_range;
  188. outer_cache.disable = tauros2_disable;
  189. outer_cache.resume = tauros2_resume;
  190. }
  191. #endif
  192. #ifdef CONFIG_CPU_32v7
  193. /*
  194. * Check whether this CPU has support for the v7 hierarchical
  195. * cache ops. (PJ4 is in its v7 personality mode if the MMFR3
  196. * register indicates support for the v7 hierarchical cache
  197. * ops.)
  198. *
  199. * (Although strictly speaking there may exist CPUs that
  200. * implement the v7 cache ops but are only ARMv6 CPUs (due to
  201. * not complying with all of the other ARMv7 requirements),
  202. * there are no real-life examples of Tauros2 being used on
  203. * such CPUs as of yet.)
  204. */
  205. if (cpuid_scheme() && (read_mmfr3() & 0xf) == 1) {
  206. u32 actlr;
  207. /*
  208. * When Tauros2 is used in an ARMv7 system, the L2
  209. * enable bit is located in the Auxiliary System Control
  210. * Register (which is the only register allowed by the
  211. * ARMv7 spec to contain fine-grained cache control bits).
  212. */
  213. actlr = read_actlr();
  214. if (!(actlr & 0x00000002)) {
  215. pr_info("Tauros2: Enabling L2 cache.\n");
  216. write_actlr(actlr | 0x00000002);
  217. }
  218. mode = "ARMv7";
  219. }
  220. #endif
  221. if (mode == NULL) {
  222. pr_crit("Tauros2: Unable to detect CPU mode.\n");
  223. return;
  224. }
  225. pr_info("Tauros2: L2 cache support initialised "
  226. "in %s mode.\n", mode);
  227. }
  228. #ifdef CONFIG_OF
  229. static const struct of_device_id tauros2_ids[] __initconst = {
  230. { .compatible = "marvell,tauros2-cache"},
  231. {}
  232. };
  233. #endif
  234. void __init tauros2_init(unsigned int features)
  235. {
  236. #ifdef CONFIG_OF
  237. struct device_node *node;
  238. int ret;
  239. unsigned int f;
  240. node = of_find_matching_node(NULL, tauros2_ids);
  241. if (!node) {
  242. pr_info("Not found marvell,tauros2-cache, disable it\n");
  243. return;
  244. }
  245. ret = of_property_read_u32(node, "marvell,tauros2-cache-features", &f);
  246. if (ret) {
  247. pr_info("Not found marvell,tauros-cache-features property, "
  248. "disable extra features\n");
  249. features = 0;
  250. } else
  251. features = f;
  252. #endif
  253. tauros2_internal_init(features);
  254. }