stm32mp2_helper.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. #include <drivers/st/stm32_gpio.h>
  8. #include <platform_def.h>
  9. #define GPIO_TX_SHIFT (DEBUG_UART_TX_GPIO_PORT << 1)
  10. .globl platform_mem_init
  11. .globl plat_secondary_cold_boot_setup
  12. .globl plat_is_my_cpu_primary
  13. .globl plat_my_core_pos
  14. .globl plat_crash_console_init
  15. .globl plat_crash_console_flush
  16. .globl plat_crash_console_putc
  17. .globl plat_report_exception
  18. func platform_mem_init
  19. /* Nothing to do, don't need to init SYSRAM */
  20. ret
  21. endfunc platform_mem_init
  22. /* ---------------------------------------------
  23. * void plat_secondary_cold_boot_setup (void);
  24. *
  25. * Set secondary core in WFI waiting for core reset.
  26. * ---------------------------------------------
  27. */
  28. func plat_secondary_cold_boot_setup
  29. dsb sy
  30. 1:
  31. wfi
  32. /*
  33. * This shouldn't be reached, but when a debugger halts the
  34. * secondary core it causes exit from wfi.
  35. * Put back the core in wfi.
  36. */
  37. b 1b
  38. endfunc plat_secondary_cold_boot_setup
  39. /* ----------------------------------------------
  40. * unsigned int plat_is_my_cpu_primary(void);
  41. * This function checks if this is the primary CPU
  42. * ----------------------------------------------
  43. */
  44. func plat_is_my_cpu_primary
  45. mrs x0, mpidr_el1
  46. and x0, x0, #(MPIDR_CPU_MASK)
  47. cmp x0, #STM32MP_PRIMARY_CPU
  48. cset x0, eq
  49. ret
  50. endfunc plat_is_my_cpu_primary
  51. /* -----------------------------------------------------------
  52. * unsigned int plat_stm32mp_get_core_pos(u_register_t mpidr)
  53. * Helper function to calculate the core position.
  54. * With this function: CorePos = (ClusterId * 4) +
  55. * CoreId
  56. * -----------------------------------------------------------
  57. */
  58. func plat_stm32mp_get_core_pos
  59. and x1, x0, #MPIDR_CPU_MASK
  60. and x0, x0, #MPIDR_CLUSTER_MASK
  61. add x0, x1, x0, LSR #6
  62. ret
  63. endfunc plat_stm32mp_get_core_pos
  64. /* -----------------------------------------------------
  65. * unsigned int plat_my_core_pos(void)
  66. * This function uses the plat_stm32mp_get_core_pos()
  67. * definition to get the index of the calling CPU.
  68. * -----------------------------------------------------
  69. */
  70. func plat_my_core_pos
  71. mrs x0, mpidr_el1
  72. b plat_stm32mp_get_core_pos
  73. endfunc plat_my_core_pos
  74. /* ---------------------------------------------
  75. * int plat_crash_console_init(void)
  76. *
  77. * Initialize the crash console without a C Runtime stack.
  78. * ---------------------------------------------
  79. */
  80. func plat_crash_console_init
  81. /* Reset UART peripheral */
  82. mov_imm x1, (RCC_BASE + DEBUG_UART_RST_REG)
  83. ldr x2, =DEBUG_UART_RST_BIT
  84. ldr x0, [x1]
  85. orr x0, x0, x2
  86. str x0, [x1]
  87. 1:
  88. ldr x0, [x1]
  89. tst x0, #DEBUG_UART_RST_BIT
  90. beq 1b
  91. bic x0, x0, #DEBUG_UART_RST_BIT
  92. str x0, [x1]
  93. 2:
  94. ldr x0, [x1]
  95. tst x0, #DEBUG_UART_RST_BIT
  96. bne 2b
  97. /* Enable GPIOs for UART TX */
  98. mov_imm x1, (RCC_BASE + DEBUG_UART_TX_GPIO_BANK_CLK_REG)
  99. ldr w2, [x1]
  100. /* Configure GPIO */
  101. orr w2, w2, #DEBUG_UART_TX_GPIO_BANK_CLK_EN
  102. str w2, [x1]
  103. mov_imm x1, DEBUG_UART_TX_GPIO_BANK_ADDRESS
  104. /* Set GPIO mode alternate */
  105. ldr w2, [x1, #GPIO_MODE_OFFSET]
  106. bic w2, w2, #(GPIO_MODE_MASK << GPIO_TX_SHIFT)
  107. orr w2, w2, #(GPIO_MODE_ALTERNATE << GPIO_TX_SHIFT)
  108. str w2, [x1, #GPIO_MODE_OFFSET]
  109. /* Set GPIO speed low */
  110. ldr w2, [x1, #GPIO_SPEED_OFFSET]
  111. bic w2, w2, #(GPIO_SPEED_MASK << GPIO_TX_SHIFT)
  112. str w2, [x1, #GPIO_SPEED_OFFSET]
  113. /* Set no-pull */
  114. ldr w2, [x1, #GPIO_PUPD_OFFSET]
  115. bic w2, w2, #(GPIO_PULL_MASK << GPIO_TX_SHIFT)
  116. str w2, [x1, #GPIO_PUPD_OFFSET]
  117. /* Set alternate */
  118. #if DEBUG_UART_TX_GPIO_PORT >= GPIO_ALT_LOWER_LIMIT
  119. ldr w2, [x1, #GPIO_AFRH_OFFSET]
  120. bic w2, w2, #(GPIO_ALTERNATE_MASK << \
  121. ((DEBUG_UART_TX_GPIO_PORT - GPIO_ALT_LOWER_LIMIT) << 2))
  122. orr w2, w2, #(DEBUG_UART_TX_GPIO_ALTERNATE << \
  123. ((DEBUG_UART_TX_GPIO_PORT - GPIO_ALT_LOWER_LIMIT) << 2))
  124. str w2, [x1, #GPIO_AFRH_OFFSET]
  125. #else
  126. ldr w2, [x1, #GPIO_AFRL_OFFSET]
  127. bic w2, w2, #(GPIO_ALTERNATE_MASK << (DEBUG_UART_TX_GPIO_PORT << 2))
  128. orr w2, w2, #(DEBUG_UART_TX_GPIO_ALTERNATE << (DEBUG_UART_TX_GPIO_PORT << 2))
  129. str w2, [x1, #GPIO_AFRL_OFFSET]
  130. #endif
  131. /* Clear UART clock flexgen divisors, keep enable bit */
  132. mov_imm x1, (RCC_BASE + DEBUG_UART_PREDIV_CFGR)
  133. mov x2, #0
  134. str w2, [x1]
  135. mov_imm x1, (RCC_BASE + DEBUG_UART_FINDIV_CFGR)
  136. mov x2, #0x40
  137. str w2, [x1]
  138. /* Enable UART clock, with its source */
  139. mov_imm x1, (RCC_BASE + DEBUG_UART_TX_CLKSRC_REG)
  140. mov_imm w2, (DEBUG_UART_TX_CLKSRC | RCC_XBARxCFGR_XBARxEN)
  141. str w2, [x1]
  142. mov_imm x1, (RCC_BASE + DEBUG_UART_TX_EN_REG)
  143. ldr w2, [x1]
  144. orr w2, w2, #DEBUG_UART_TX_EN
  145. str w2, [x1]
  146. mov_imm x0, STM32MP_DEBUG_USART_BASE
  147. mov_imm x1, STM32MP_DEBUG_USART_CLK_FRQ
  148. mov_imm x2, STM32MP_UART_BAUDRATE
  149. b console_stm32_core_init
  150. endfunc plat_crash_console_init
  151. func plat_crash_console_flush
  152. mov_imm x0, STM32MP_DEBUG_USART_BASE
  153. b console_stm32_core_flush
  154. endfunc plat_crash_console_flush
  155. func plat_crash_console_putc
  156. mov_imm x1, STM32MP_DEBUG_USART_BASE
  157. cmp x0, #'\n'
  158. b.ne 1f
  159. mov x15, x30
  160. mov x0, #'\r'
  161. bl console_stm32_core_putc
  162. mov x30, x15
  163. mov x0, #'\n'
  164. 1:
  165. b console_stm32_core_putc
  166. endfunc plat_crash_console_putc
  167. #ifdef IMAGE_BL2
  168. /* ---------------------------------------------
  169. * void plat_report_exception(unsigned int type)
  170. * Function to report an unhandled exception
  171. * with platform-specific means.
  172. * ---------------------------------------------
  173. */
  174. func plat_report_exception
  175. mov x8, x30
  176. adr x4, plat_err_str
  177. bl asm_print_str
  178. adr x4, esr_el3_str
  179. bl asm_print_str
  180. mrs x4, esr_el3
  181. bl asm_print_hex
  182. adr x4, elr_el3_str
  183. bl asm_print_str
  184. mrs x4, elr_el3
  185. bl asm_print_hex
  186. adr x4, far_el3_str
  187. bl asm_print_str
  188. mrs x4, far_el3
  189. bl asm_print_hex
  190. mov x30, x8
  191. ret
  192. endfunc plat_report_exception
  193. .section .rodata.rev_err_str, "aS"
  194. plat_err_str:
  195. .asciz "\nPlatform exception reporting:"
  196. esr_el3_str:
  197. .asciz "\nESR_EL3: "
  198. elr_el3_str:
  199. .asciz "\nELR_EL3: "
  200. far_el3_str:
  201. .asciz "\nFAR_EL3: "
  202. #endif /* IMAGE_BL2 */