lowlevel_init.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <config.h>
  7. #include <linux/linkage.h>
  8. #include <linux/sizes.h>
  9. #include <asm/system.h>
  10. #include "ssc-regs.h"
  11. ENTRY(lowlevel_init)
  12. mov r8, lr @ persevere link reg across call
  13. /*
  14. * The UniPhier Boot ROM loads SPL code to the L2 cache.
  15. * But CPUs can only do instruction fetch now because start.S has
  16. * cleared C and M bits.
  17. * First we need to turn on MMU and Dcache again to get back
  18. * data access to L2.
  19. */
  20. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  21. orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache
  22. mcr p15, 0, r0, c1, c0, 0
  23. #ifdef CONFIG_DEBUG_LL
  24. bl debug_ll_init
  25. #endif
  26. bl setup_init_ram @ RAM area for stack and page talbe
  27. /*
  28. * Now we are using the page table embedded in the Boot ROM.
  29. * It is not handy since it is not a straight mapped table for sLD3.
  30. * Also, the access to the external bus is prohibited. What we need
  31. * to do next is to create a page table and switch over to it.
  32. */
  33. bl create_page_table
  34. bl v7_flush_dcache_all
  35. /* Disable MMU and Dcache before switching Page Table */
  36. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  37. bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache
  38. mcr p15, 0, r0, c1, c0, 0
  39. bl enable_mmu
  40. mov lr, r8 @ restore link
  41. mov pc, lr @ back to my caller
  42. ENDPROC(lowlevel_init)
  43. ENTRY(enable_mmu)
  44. mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register)
  45. bic r0, r0, #0x37
  46. orr r0, r0, #0x20 @ disable TTBR1
  47. mcr p15, 0, r0, c2, c0, 2
  48. orr r0, r12, #0x8 @ Outer Cacheability for table walks: WBWA
  49. mcr p15, 0, r0, c2, c0, 0 @ TTBR0
  50. mov r0, #0
  51. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
  52. mov r0, #-1 @ manager for all domains (No permission check)
  53. mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register)
  54. dsb
  55. isb
  56. /*
  57. * MMU on:
  58. * TLBs was already invalidated in "../start.S"
  59. * So, we don't need to invalidate it here.
  60. */
  61. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  62. orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable
  63. mcr p15, 0, r0, c1, c0, 0
  64. mov pc, lr
  65. ENDPROC(enable_mmu)
  66. /*
  67. * For PH1-Pro4 or older SoCs, the size of WAY is 32KB.
  68. * It is large enough for tmp RAM.
  69. */
  70. #define BOOT_RAM_SIZE (SZ_32K)
  71. #define BOOT_RAM_BASE ((CONFIG_SPL_STACK) - (BOOT_RAM_SIZE))
  72. #define BOOT_WAY_BITS (0x00000100) /* way 8 */
  73. ENTRY(setup_init_ram)
  74. /*
  75. * Touch to zero for the boot way
  76. */
  77. 0:
  78. /*
  79. * set SSCOQM, SSCOQAD, SSCOQSZ, SSCOQWN in this order
  80. */
  81. ldr r0, = 0x00408006 @ touch to zero with address range
  82. ldr r1, = SSCOQM
  83. str r0, [r1]
  84. ldr r0, = BOOT_RAM_BASE
  85. ldr r1, = SSCOQAD
  86. str r0, [r1]
  87. ldr r0, = BOOT_RAM_SIZE
  88. ldr r1, = SSCOQSZ
  89. str r0, [r1]
  90. ldr r0, = BOOT_WAY_BITS
  91. ldr r1, = SSCOQWN
  92. str r0, [r1]
  93. ldr r1, = SSCOPPQSEF
  94. ldr r0, [r1]
  95. cmp r0, #0 @ check if the command is successfully set
  96. bne 0b @ try again if an error occurs
  97. ldr r1, = SSCOLPQS
  98. 1:
  99. ldr r0, [r1]
  100. cmp r0, #0x4
  101. bne 1b @ wait until the operation is completed
  102. str r0, [r1] @ clear the complete notification flag
  103. mov pc, lr
  104. ENDPROC(setup_init_ram)
  105. #define DEVICE 0x00002002 /* Non-shareable Device */
  106. #define NORMAL 0x0000000e /* Normal Memory Write-Back, No Write-Allocate */
  107. ENTRY(create_page_table)
  108. ldr r0, = DEVICE
  109. ldr r1, = BOOT_RAM_BASE
  110. mov r12, r1 @ r12 is preserved during D-cache flush
  111. 0: str r0, [r1], #4 @ specify all the sections as Device
  112. adds r0, r0, #0x00100000
  113. bcc 0b
  114. ldr r0, = NORMAL
  115. str r0, [r12] @ mark the first section as Normal
  116. add r0, r0, #0x00100000
  117. str r0, [r12, #4] @ mark the second section as Normal
  118. mov pc, lr
  119. ENDPROC(create_page_table)
  120. /* We don't use Thumb instructions for now */
  121. #define ARM(x...) x
  122. #define THUMB(x...)
  123. /*
  124. * v7_flush_dcache_all()
  125. *
  126. * Flush the whole D-cache.
  127. *
  128. * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
  129. *
  130. * - mm - mm_struct describing address space
  131. *
  132. * Note: copied from arch/arm/mm/cache-v7.S of Linux 4.4
  133. */
  134. ENTRY(v7_flush_dcache_all)
  135. dmb @ ensure ordering with previous memory accesses
  136. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  137. mov r3, r0, lsr #23 @ move LoC into position
  138. ands r3, r3, #7 << 1 @ extract LoC*2 from clidr
  139. beq finished @ if loc is 0, then no need to clean
  140. start_flush_levels:
  141. mov r10, #0 @ start clean at cache level 0
  142. flush_levels:
  143. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  144. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  145. and r1, r1, #7 @ mask of the bits for current cache only
  146. cmp r1, #2 @ see what cache we have at this level
  147. blt skip @ skip if no cache, or just i-cache
  148. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  149. isb @ isb to sych the new cssr&csidr
  150. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  151. and r2, r1, #7 @ extract the length of the cache lines
  152. add r2, r2, #4 @ add 4 (line length offset)
  153. movw r4, #0x3ff
  154. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  155. clz r5, r4 @ find bit position of way size increment
  156. movw r7, #0x7fff
  157. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  158. loop1:
  159. mov r9, r7 @ create working copy of max index
  160. loop2:
  161. ARM( orr r11, r10, r4, lsl r5 ) @ factor way and cache number into r11
  162. THUMB( lsl r6, r4, r5 )
  163. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  164. ARM( orr r11, r11, r9, lsl r2 ) @ factor index number into r11
  165. THUMB( lsl r6, r9, r2 )
  166. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  167. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  168. subs r9, r9, #1 @ decrement the index
  169. bge loop2
  170. subs r4, r4, #1 @ decrement the way
  171. bge loop1
  172. skip:
  173. add r10, r10, #2 @ increment cache number
  174. cmp r3, r10
  175. bgt flush_levels
  176. finished:
  177. mov r10, #0 @ swith back to cache level 0
  178. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  179. dsb st
  180. isb
  181. mov pc, lr
  182. ENDPROC(v7_flush_dcache_all)