lowlevel_init.S 4.8 KB

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