lowlevel_init.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 <mach/arm-mpcore.h>
  11. #include <mach/sbc-regs.h>
  12. #include <mach/ssc-regs.h>
  13. ENTRY(lowlevel_init)
  14. mov r8, lr @ persevere link reg across call
  15. /*
  16. * The UniPhier Boot ROM loads SPL code to the L2 cache.
  17. * But CPUs can only do instruction fetch now because start.S has
  18. * cleared C and M bits.
  19. * First we need to turn on MMU and Dcache again to get back
  20. * data access to L2.
  21. */
  22. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  23. orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache
  24. mcr p15, 0, r0, c1, c0, 0
  25. #ifdef CONFIG_DEBUG_LL
  26. bl debug_ll_init
  27. #endif
  28. /*
  29. * Now we are using the page table embedded in the Boot ROM.
  30. * It is not handy since it is not a straight mapped table for sLD3.
  31. * What we need to do next is to switch over to the page table in SPL.
  32. */
  33. ldr r3, =init_page_table @ page table must be 16KB aligned
  34. /* Disable MMU and Dcache before switching Page Table */
  35. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  36. bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache
  37. mcr p15, 0, r0, c1, c0, 0
  38. bl enable_mmu
  39. #ifdef CONFIG_UNIPHIER_SMP
  40. secondary_startup:
  41. /*
  42. * Entry point for secondary CPUs
  43. *
  44. * The Boot ROM has already enabled MMU for the secondary CPUs as well
  45. * as for the primary one. The MMU table embedded in the Boot ROM
  46. * prohibits the DRAM access, so it is impossible to bring the
  47. * secondary CPUs into DRAM directly. They must jump here into SPL,
  48. * which is run on L2 cache.
  49. *
  50. * Boot Sequence
  51. * [primary CPU] [secondary CPUs]
  52. * start from Boot ROM start from Boot ROM
  53. * jump to SPL sleep in Boot ROM
  54. * kick secondaries ---(sev)---> jump to SPL
  55. * jump to U-Boot main sleep in SPL
  56. * jump to Linux
  57. * kick secondaries ---(sev)---> jump to Linux
  58. */
  59. /* branch by CPU ID */
  60. mrc p15, 0, r0, c0, c0, 5 @ MPIDR (Multiprocessor Affinity Register)
  61. and r0, r0, #0x3
  62. cmp r0, #0x0
  63. beq primary_cpu
  64. /* only for secondary CPUs */
  65. ldr r1, =ROM_BOOT_ROMRSV2 @ The last data access to L2 cache
  66. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  67. orr r0, r0, #CR_I @ Enable ICache
  68. bic r0, r0, #(CR_C | CR_M) @ MMU and Dcache must be disabled
  69. mcr p15, 0, r0, c1, c0, 0 @ before jumping to Linux
  70. mov r0, #0
  71. str r0, [r1]
  72. b 1f
  73. /*
  74. * L2 cache is shared among all the CPUs and it might be disabled by
  75. * the primary one. Before that, the following 5 lines must be cached
  76. * on the Icaches of the secondary CPUs.
  77. */
  78. 0: wfe @ kicked by Linux
  79. 1: ldr r0, [r1]
  80. cmp r0, #0
  81. bxne r0 @ r0: Linux entry for secondary CPUs
  82. b 0b
  83. primary_cpu:
  84. ldr r1, =ROM_BOOT_ROMRSV2
  85. ldr r0, =secondary_startup
  86. str r0, [r1]
  87. ldr r0, [r1] @ make sure str is complete before sev
  88. sev @ kick the secondary CPU
  89. #endif
  90. bl setup_init_ram @ RAM area for temporary stack pointer
  91. mov lr, r8 @ restore link
  92. mov pc, lr @ back to my caller
  93. ENDPROC(lowlevel_init)
  94. ENTRY(enable_mmu)
  95. mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register)
  96. bic r0, r0, #0x37
  97. orr r0, r0, #0x20 @ disable TTBR1
  98. mcr p15, 0, r0, c2, c0, 2
  99. orr r0, r3, #0x8 @ Outer Cacheability for table walks: WBWA
  100. mcr p15, 0, r0, c2, c0, 0 @ TTBR0
  101. mov r0, #0
  102. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
  103. mov r0, #-1 @ manager for all domains (No permission check)
  104. mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register)
  105. dsb
  106. isb
  107. /*
  108. * MMU on:
  109. * TLBs was already invalidated in "../start.S"
  110. * So, we don't need to invalidate it here.
  111. */
  112. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  113. orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable
  114. mcr p15, 0, r0, c1, c0, 0
  115. mov pc, lr
  116. ENDPROC(enable_mmu)
  117. /*
  118. * For PH1-Pro4 or older SoCs, the size of WAY is 32KB.
  119. * It is large enough for tmp RAM.
  120. */
  121. #define BOOT_RAM_SIZE (SZ_32K)
  122. #define BOOT_WAY_BITS (0x00000100) /* way 8 */
  123. ENTRY(setup_init_ram)
  124. /*
  125. * Touch to zero for the boot way
  126. */
  127. 0:
  128. /*
  129. * set SSCOQM, SSCOQAD, SSCOQSZ, SSCOQWN in this order
  130. */
  131. ldr r0, = 0x00408006 @ touch to zero with address range
  132. ldr r1, = SSCOQM
  133. str r0, [r1]
  134. ldr r0, = (CONFIG_SPL_STACK - BOOT_RAM_SIZE) @ base address
  135. ldr r1, = SSCOQAD
  136. str r0, [r1]
  137. ldr r0, = BOOT_RAM_SIZE
  138. ldr r1, = SSCOQSZ
  139. str r0, [r1]
  140. ldr r0, = BOOT_WAY_BITS
  141. ldr r1, = SSCOQWN
  142. str r0, [r1]
  143. ldr r1, = SSCOPPQSEF
  144. ldr r0, [r1]
  145. cmp r0, #0 @ check if the command is successfully set
  146. bne 0b @ try again if an error occurs
  147. ldr r1, = SSCOLPQS
  148. 1:
  149. ldr r0, [r1]
  150. cmp r0, #0x4
  151. bne 1b @ wait until the operation is completed
  152. str r0, [r1] @ clear the complete notification flag
  153. mov pc, lr
  154. ENDPROC(setup_init_ram)