ls_helpers.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright 2018-2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include <asm_macros.S>
  8. #include <cortex_a53.h>
  9. #include <drivers/console.h>
  10. #include <lib/cpus/aarch64/cortex_a72.h>
  11. #include <platform_def.h>
  12. .globl plat_crash_console_init
  13. .globl plat_crash_console_putc
  14. .globl plat_crash_console_flush
  15. .globl plat_core_pos
  16. .globl plat_my_core_pos
  17. .globl plat_core_mask
  18. .globl plat_my_core_mask
  19. .globl plat_core_pos_by_mpidr
  20. .globl _disable_ldstr_pfetch_A53
  21. .globl _disable_ldstr_pfetch_A72
  22. .global _set_smmu_pagesz_64
  23. /* int plat_crash_console_init(void)
  24. * Function to initialize the crash console
  25. * without a C Runtime to print crash report.
  26. * Clobber list : x0 - x4
  27. */
  28. /* int plat_crash_console_init(void)
  29. * Use normal console by default. Switch it to crash
  30. * mode so serial consoles become active again.
  31. * NOTE: This default implementation will only work for
  32. * crashes that occur after a normal console (marked
  33. * valid for the crash state) has been registered with
  34. * the console framework. To debug crashes that occur
  35. * earlier, the platform has to override these functions
  36. * with an implementation that initializes a console
  37. * driver with hardcoded parameters. See
  38. * docs/porting-guide.rst for more information.
  39. */
  40. func plat_crash_console_init
  41. mov x3, x30
  42. mov x0, #CONSOLE_FLAG_CRASH
  43. bl console_switch_state
  44. mov x0, #1
  45. ret x3
  46. endfunc plat_crash_console_init
  47. /* void plat_crash_console_putc(int character)
  48. * Output through the normal console by default.
  49. */
  50. func plat_crash_console_putc
  51. b console_putc
  52. endfunc plat_crash_console_putc
  53. /* void plat_crash_console_flush(void)
  54. * Flush normal console by default.
  55. */
  56. func plat_crash_console_flush
  57. b console_flush
  58. endfunc plat_crash_console_flush
  59. /* This function implements a part of the critical interface between the psci
  60. * generic layer and the platform that allows the former to query the platform
  61. * to convert an MPIDR to a unique linear index. An error code (-1) is returned
  62. * in case the MPIDR is invalid.
  63. */
  64. func plat_core_pos_by_mpidr
  65. b plat_core_pos
  66. endfunc plat_core_pos_by_mpidr
  67. #if (SYMMETRICAL_CLUSTERS)
  68. /* unsigned int plat_my_core_mask(void)
  69. * generate a mask bit for this core
  70. */
  71. func plat_my_core_mask
  72. mrs x0, MPIDR_EL1
  73. b plat_core_mask
  74. endfunc plat_my_core_mask
  75. /* unsigned int plat_core_mask(u_register_t mpidr)
  76. * generate a lsb-based mask bit for the core specified by mpidr in x0.
  77. *
  78. * SoC core = ((cluster * cpu_per_cluster) + core)
  79. * mask = (1 << SoC core)
  80. */
  81. func plat_core_mask
  82. mov w1, wzr
  83. mov w2, wzr
  84. /* extract cluster */
  85. bfxil w1, w0, #8, #8
  86. /* extract cpu # */
  87. bfxil w2, w0, #0, #8
  88. mov w0, wzr
  89. /* error checking */
  90. cmp w1, #NUMBER_OF_CLUSTERS
  91. b.ge 1f
  92. cmp w2, #CORES_PER_CLUSTER
  93. b.ge 1f
  94. mov w0, #CORES_PER_CLUSTER
  95. mul w1, w1, w0
  96. add w1, w1, w2
  97. mov w2, #0x1
  98. lsl w0, w2, w1
  99. 1:
  100. ret
  101. endfunc plat_core_mask
  102. /*
  103. * unsigned int plat_my_core_pos(void)
  104. * generate a linear core number for this core
  105. */
  106. func plat_my_core_pos
  107. mrs x0, MPIDR_EL1
  108. b plat_core_pos
  109. endfunc plat_my_core_pos
  110. /*
  111. * unsigned int plat_core_pos(u_register_t mpidr)
  112. * Generate a linear core number for the core specified by mpidr.
  113. *
  114. * SoC core = ((cluster * cpu_per_cluster) + core)
  115. * Returns -1 if mpidr invalid
  116. */
  117. func plat_core_pos
  118. mov w1, wzr
  119. mov w2, wzr
  120. bfxil w1, w0, #8, #8 /* extract cluster */
  121. bfxil w2, w0, #0, #8 /* extract cpu # */
  122. mov w0, #-1
  123. /* error checking */
  124. cmp w1, #NUMBER_OF_CLUSTERS
  125. b.ge 1f
  126. cmp w2, #CORES_PER_CLUSTER
  127. b.ge 1f
  128. mov w0, #CORES_PER_CLUSTER
  129. mul w1, w1, w0
  130. add w0, w1, w2
  131. 1:
  132. ret
  133. endfunc plat_core_pos
  134. #endif
  135. /* this function disables the load-store prefetch of the calling core
  136. * Note: this function is for A53 cores ONLY
  137. * in: none
  138. * out: none
  139. * uses x0
  140. */
  141. func _disable_ldstr_pfetch_A53
  142. mrs x0, CORTEX_A53_CPUACTLR_EL1
  143. tst x0, #CORTEX_A53_CPUACTLR_EL1_L1PCTL
  144. b.ne 1f
  145. b 2f
  146. .align 6
  147. 1:
  148. dsb sy
  149. isb
  150. bic x0, x0, #CORTEX_A53_CPUACTLR_EL1_L1PCTL
  151. msr CORTEX_A53_CPUACTLR_EL1, x0
  152. isb
  153. 2:
  154. ret
  155. endfunc _disable_ldstr_pfetch_A53
  156. /* this function disables the load-store prefetch of the calling core
  157. * Note: this function is for A72 cores ONLY
  158. * in: none
  159. * out: none
  160. * uses x0
  161. */
  162. func _disable_ldstr_pfetch_A72
  163. mrs x0, CORTEX_A72_CPUACTLR_EL1
  164. tst x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH
  165. b.eq 1f
  166. b 2f
  167. .align 6
  168. 1:
  169. dsb sy
  170. isb
  171. orr x0, x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH
  172. msr CORTEX_A72_CPUACTLR_EL1, x0
  173. isb
  174. 2:
  175. ret
  176. endfunc _disable_ldstr_pfetch_A72
  177. /*
  178. * Function sets the SACR pagesize to 64k
  179. */
  180. func _set_smmu_pagesz_64
  181. ldr x1, =NXP_SMMU_ADDR
  182. ldr w0, [x1, #0x10]
  183. orr w0, w0, #1 << 16 /* setting to 64K page */
  184. str w0, [x1, #0x10]
  185. ret
  186. endfunc _set_smmu_pagesz_64