msm8916_helpers.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (c) 2021-2023, Stephan Gerhold <stephan@gerhold.net>
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <platform_def.h>
  9. #include <msm8916_mmap.h>
  10. #if PLATFORM_CORE_COUNT > 1
  11. #define APCS_TCM_START_ADDR 0x10
  12. #else
  13. #define APCS_TCM_START_ADDR 0x34
  14. #endif
  15. #define APCS_TCM_REDIRECT_EN_0 BIT_32(0)
  16. .globl plat_crash_console_init
  17. .globl plat_crash_console_putc
  18. .globl plat_crash_console_flush
  19. .globl plat_panic_handler
  20. .globl plat_my_core_pos
  21. .globl plat_get_my_entrypoint
  22. .globl plat_reset_handler
  23. .globl platform_mem_init
  24. .globl msm8916_entry_point
  25. /* -------------------------------------------------
  26. * int plat_crash_console_init(void)
  27. * Initialize the crash console.
  28. * Out: r0 - 1 on success, 0 on error
  29. * Clobber list : r0 - r4
  30. * -------------------------------------------------
  31. */
  32. func plat_crash_console_init
  33. ldr r1, =BLSP_UART_BASE
  34. mov r0, #1
  35. b console_uartdm_core_init
  36. endfunc plat_crash_console_init
  37. /* -------------------------------------------------
  38. * int plat_crash_console_putc(int c)
  39. * Print a character on the crash console.
  40. * In : r0 - character to be printed
  41. * Out: r0 - printed character on success
  42. * Clobber list : r1, r2
  43. * -------------------------------------------------
  44. */
  45. func plat_crash_console_putc
  46. ldr r1, =BLSP_UART_BASE
  47. b console_uartdm_core_putc
  48. endfunc plat_crash_console_putc
  49. /* -------------------------------------------------
  50. * void plat_crash_console_flush(void)
  51. * Force a write of all buffered data that has not
  52. * been output.
  53. * Clobber list : r1, r2
  54. * -------------------------------------------------
  55. */
  56. func plat_crash_console_flush
  57. ldr r1, =BLSP_UART_BASE
  58. b console_uartdm_core_flush
  59. endfunc plat_crash_console_flush
  60. /* -------------------------------------------------
  61. * void plat_panic_handler(void) __dead
  62. * Called when an unrecoverable error occurs.
  63. * -------------------------------------------------
  64. */
  65. func plat_panic_handler
  66. /* Try to shutdown/reset */
  67. ldr r0, =MPM_PS_HOLD
  68. mov r1, #0
  69. str r1, [r0]
  70. 1: b 1b
  71. endfunc plat_panic_handler
  72. /* -------------------------------------------------
  73. * unsigned int plat_my_core_pos(void)
  74. * Out: r0 - index of the calling CPU
  75. * -------------------------------------------------
  76. */
  77. func plat_my_core_pos
  78. .if PLATFORM_CORE_COUNT > 1
  79. ldcopr r1, MPIDR
  80. and r0, r1, #MPIDR_CPU_MASK
  81. .if PLATFORM_CLUSTER_COUNT > 1
  82. and r1, r1, #MPIDR_CLUSTER_MASK
  83. orr r0, r0, r1, LSR #(MPIDR_AFFINITY_BITS - \
  84. PLATFORM_CPU_PER_CLUSTER_SHIFT)
  85. .endif
  86. .else
  87. /* There is just a single core so always 0 */
  88. mov r0, #0
  89. .endif
  90. bx lr
  91. endfunc plat_my_core_pos
  92. /* -------------------------------------------------
  93. * uintptr_t plat_get_my_entrypoint(void)
  94. * Distinguish cold and warm boot and return warm boot
  95. * entry address if available.
  96. * Out: r0 - warm boot entry point or 0 on cold boot
  97. * -------------------------------------------------
  98. */
  99. func plat_get_my_entrypoint
  100. ldr r0, =msm8916_entry_point
  101. ldr r0, [r0]
  102. cmp r0, #0
  103. bxne lr
  104. /*
  105. * Cold boot: Disable TCM redirect to L2 cache as early as
  106. * possible to avoid crashes when making use of the cache.
  107. */
  108. ldr r1, =APCS_CFG(0)
  109. ldr r2, [r1, #APCS_TCM_START_ADDR]
  110. and r2, r2, #~APCS_TCM_REDIRECT_EN_0
  111. str r2, [r1, #APCS_TCM_START_ADDR]
  112. bx lr
  113. endfunc plat_get_my_entrypoint
  114. /* -------------------------------------------------
  115. * void platform_mem_init(void)
  116. * Performs additional memory initialization early
  117. * in the boot process.
  118. * -------------------------------------------------
  119. */
  120. func platform_mem_init
  121. /* Nothing to do here, all memory is already initialized */
  122. bx lr
  123. endfunc platform_mem_init
  124. .data
  125. .align 3
  126. /* -------------------------------------------------
  127. * Warm boot entry point for CPU. Set by PSCI code.
  128. * -------------------------------------------------
  129. */
  130. msm8916_entry_point:
  131. .word 0