300-ARM-BCM5301X-Disable-MMU-and-Dcache-for-decompression.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. From 26023cdfacaf116545b1087b9d1fe50dc6fbda10 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Wed, 24 Sep 2014 22:14:07 +0200
  4. Subject: [PATCH] ARM: BCM5301X: Disable MMU and Dcache for decompression
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Without this fix kernel was randomly hanging in ~25% of tries during
  9. early init. Hangs used to happen at random places in the start_kernel.
  10. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  11. ---
  12. arch/arm/boot/compressed/Makefile | 5 +
  13. arch/arm/boot/compressed/head-bcm_5301x-mpcore.S | 37 +++++++
  14. arch/arm/boot/compressed/mpcore_cache.S | 118 +++++++++++++++++++++++
  15. 3 files changed, 160 insertions(+)
  16. create mode 100644 arch/arm/boot/compressed/head-bcm_5301x-mpcore.S
  17. create mode 100644 arch/arm/boot/compressed/mpcore_cache.S
  18. --- a/arch/arm/boot/compressed/Makefile
  19. +++ b/arch/arm/boot/compressed/Makefile
  20. @@ -46,6 +46,11 @@ ifeq ($(CONFIG_ARCH_ACORN),y)
  21. OBJS += ll_char_wr.o font.o
  22. endif
  23. +ifeq ($(CONFIG_ARCH_BCM_5301X),y)
  24. +OBJS += head-bcm_5301x-mpcore.o
  25. +OBJS += mpcore_cache.o
  26. +endif
  27. +
  28. ifeq ($(CONFIG_ARCH_SA1100),y)
  29. OBJS += head-sa1100.o
  30. endif
  31. --- /dev/null
  32. +++ b/arch/arm/boot/compressed/head-bcm_5301x-mpcore.S
  33. @@ -0,0 +1,37 @@
  34. +/*
  35. + *
  36. + * Platform specific tweaks. This is merged into head.S by the linker.
  37. + *
  38. + */
  39. +
  40. +#include <linux/linkage.h>
  41. +#include <asm/assembler.h>
  42. +#include <asm/cp15.h>
  43. +
  44. + .section ".start", "ax"
  45. +
  46. +/*
  47. + * This code section is spliced into the head code by the linker
  48. + */
  49. +
  50. +__plat_uncompress_start:
  51. +
  52. + @ Preserve r8/r7 i.e. kernel entry values
  53. + mov r12, r8
  54. +
  55. + @ Clear MMU enable and Dcache enable bits
  56. + mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR
  57. + bic r0, #CR_C|CR_M
  58. + mcr p15, 0, r0, c1, c0, 0 @ Write SCTLR
  59. + nop
  60. +
  61. + @ Call the cache invalidation routine
  62. + bl v7_all_dcache_invalidate
  63. + nop
  64. + mov r0,#0
  65. + ldr r3, =0x19022000 @ L2 cache controller, control reg
  66. + str r0, [r3, #0x100] @ Disable L2 cache
  67. + nop
  68. +
  69. + @ Restore
  70. + mov r8, r12
  71. --- /dev/null
  72. +++ b/arch/arm/boot/compressed/mpcore_cache.S
  73. @@ -0,0 +1,118 @@
  74. +/*****************************************************************************
  75. +* Copyright 2003 - 2008 Broadcom Corporation. All rights reserved.
  76. +*
  77. +* Unless you and Broadcom execute a separate written software license
  78. +* agreement governing use of this software, this software is licensed to you
  79. +* under the terms of the GNU General Public License version 2, available at
  80. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  81. +*
  82. +* Notwithstanding the above, under no circumstances may you combine this
  83. +* software in any way with any other Broadcom software provided under a
  84. +* license other than the GPL, without Broadcom's express prior written
  85. +* consent.
  86. +*****************************************************************************/
  87. +
  88. +#include <linux/linkage.h>
  89. +#include <linux/init.h>
  90. +
  91. + __INIT
  92. +
  93. +/*
  94. + * v7_l1_cache_invalidate
  95. + *
  96. + * Invalidate contents of L1 cache without flushing its contents
  97. + * into outer cache and memory. This is needed when the contents
  98. + * of the cache are unpredictable after power-up.
  99. + *
  100. + * corrupts r0-r6
  101. + */
  102. +
  103. +ENTRY(v7_l1_cache_invalidate)
  104. + mov r0, #0
  105. + mcr p15, 2, r0, c0, c0, 0 @ set cache level to 1
  106. + mrc p15, 1, r0, c0, c0, 0 @ read CLIDR
  107. +
  108. + ldr r1, =0x7fff
  109. + and r2, r1, r0, lsr #13 @ get max # of index size
  110. +
  111. + ldr r1, =0x3ff
  112. + and r3, r1, r0, lsr #3 @ NumWays - 1
  113. + add r2, r2, #1 @ NumSets
  114. +
  115. + and r0, r0, #0x7
  116. + add r0, r0, #4 @ SetShift
  117. +
  118. + clz r1, r3 @ WayShift
  119. + add r4, r3, #1 @ NumWays
  120. +1: sub r2, r2, #1 @ NumSets--
  121. + mov r3, r4 @ Temp = NumWays
  122. +2: subs r3, r3, #1 @ Temp--
  123. + mov r5, r3, lsl r1
  124. + mov r6, r2, lsl r0
  125. + orr r5, r5, r6 @ Reg = (Temp<<WayShift)|(NumSets<<SetShift)
  126. + mcr p15, 0, r5, c7, c6, 2 @ Invalidate line
  127. + bgt 2b
  128. + cmp r2, #0
  129. + bgt 1b
  130. + dsb
  131. + mov r0,#0
  132. + mcr p15,0,r0,c7,c5,0 /* Invalidate icache */
  133. + isb
  134. + mov pc, lr
  135. +ENDPROC(v7_l1_cache_invalidate)
  136. +
  137. +/*
  138. + * v7_all_dcache_invalidate
  139. + *
  140. + * Invalidate without flushing the contents of all cache levels
  141. + * accesible by the current processor core.
  142. + * This is useful when the contents of cache memory are undetermined
  143. + * at power-up.
  144. + * Corrupted registers: r0-r7, r9-r11
  145. + *
  146. + * Based on cache-v7.S: v7_flush_dcache_all()
  147. + */
  148. +
  149. +ENTRY(v7_all_dcache_invalidate)
  150. + mrc p15, 1, r0, c0, c0, 1 @ read clidr
  151. + ands r3, r0, #0x7000000 @ extract loc from clidr
  152. + mov r3, r3, lsr #23 @ left align loc bit field
  153. + beq finished @ if loc is 0, then no need to clean
  154. + mov r10, #0 @ start clean at cache level 0
  155. +loop1:
  156. + add r2, r10, r10, lsr #1 @ work out 3x current cache level
  157. + mov r1, r0, lsr r2 @ extract cache type bits from clidr
  158. + and r1, r1, #7 @ mask of bits for current cache only
  159. + cmp r1, #2 @ see what cache we have at this level
  160. + blt skip @ skip if no cache, or just i-cache
  161. + mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  162. + isb @ isb to sych the new cssr&csidr
  163. + mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  164. + and r2, r1, #7 @ extract the length of the cache lines
  165. + add r2, r2, #4 @ add 4 (line length offset)
  166. + ldr r4, =0x3ff
  167. + ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  168. + clz r5, r4 @ find bit pos of way size increment
  169. + ldr r7, =0x7fff
  170. + ands r7, r7, r1, lsr #13 @ extract max number of the index size
  171. +loop2:
  172. + mov r9, r4 @ create working copy of max way size
  173. +loop3:
  174. + orr r11, r10, r9, lsl r5 @ factor way and cache number into r11
  175. + orr r11, r11, r7, lsl r2 @ factor index number into r11
  176. + mcr p15, 0, r11, c7, c6, 2 @ Invalidate line
  177. + subs r9, r9, #1 @ decrement the way
  178. + bge loop3
  179. + subs r7, r7, #1 @ decrement the index
  180. + bge loop2
  181. +skip:
  182. + add r10, r10, #2 @ increment cache number
  183. + cmp r3, r10
  184. + bgt loop1
  185. +finished:
  186. + mov r10, #0 @ swith back to cache level 0
  187. + mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  188. + dsb
  189. + isb
  190. + mov pc, lr
  191. +ENDPROC(v7_all_dcache_invalidate)