plat_helpers.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <assert_macros.S>
  9. #include <platform_def.h>
  10. .globl plat_my_core_pos
  11. .globl plat_get_my_entrypoint
  12. .globl platform_mem_init
  13. .globl plat_qemu_calc_core_pos
  14. .globl plat_crash_console_init
  15. .globl plat_crash_console_putc
  16. .globl plat_crash_console_flush
  17. .globl plat_secondary_cold_boot_setup
  18. .globl plat_get_my_entrypoint
  19. .globl plat_is_my_cpu_primary
  20. func plat_my_core_pos
  21. mrs x0, mpidr_el1
  22. b plat_qemu_calc_core_pos
  23. endfunc plat_my_core_pos
  24. /*
  25. * unsigned int plat_qemu_calc_core_pos(u_register_t mpidr);
  26. * With this function: CorePos = (ClusterId * 4) + CoreId
  27. */
  28. func plat_qemu_calc_core_pos
  29. and x1, x0, #MPIDR_CPU_MASK
  30. and x0, x0, #MPIDR_CLUSTER_MASK
  31. add x0, x1, x0, LSR #(MPIDR_AFFINITY_BITS -\
  32. PLATFORM_CPU_PER_CLUSTER_SHIFT)
  33. ret
  34. endfunc plat_qemu_calc_core_pos
  35. /* -----------------------------------------------------
  36. * unsigned int plat_is_my_cpu_primary (void);
  37. *
  38. * Find out whether the current cpu is the primary
  39. * cpu.
  40. * -----------------------------------------------------
  41. */
  42. func plat_is_my_cpu_primary
  43. mrs x0, mpidr_el1
  44. and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
  45. cmp x0, #QEMU_PRIMARY_CPU
  46. cset w0, eq
  47. ret
  48. endfunc plat_is_my_cpu_primary
  49. /* -----------------------------------------------------
  50. * void plat_secondary_cold_boot_setup (void);
  51. *
  52. * This function performs any platform specific actions
  53. * needed for a secondary cpu after a cold reset e.g
  54. * mark the cpu's presence, mechanism to place it in a
  55. * holding pen etc.
  56. * -----------------------------------------------------
  57. */
  58. func plat_secondary_cold_boot_setup
  59. /* Calculate address of our hold entry */
  60. bl plat_my_core_pos
  61. lsl x0, x0, #PLAT_QEMU_HOLD_ENTRY_SHIFT
  62. mov_imm x2, PLAT_QEMU_HOLD_BASE
  63. /* Wait until we have a go */
  64. poll_mailbox:
  65. ldr x1, [x2, x0]
  66. cbz x1, 1f
  67. /* Clear the mailbox again ready for next time. */
  68. mov x1, #PLAT_QEMU_HOLD_STATE_WAIT
  69. str x1, [x2, x0]
  70. /* Jump to the provided entrypoint. */
  71. mov_imm x0, PLAT_QEMU_TRUSTED_MAILBOX_BASE
  72. ldr x1, [x0]
  73. br x1
  74. 1:
  75. wfe
  76. b poll_mailbox
  77. endfunc plat_secondary_cold_boot_setup
  78. func plat_get_my_entrypoint
  79. /* TODO support warm boot */
  80. mov x0, #0
  81. ret
  82. endfunc plat_get_my_entrypoint
  83. func platform_mem_init
  84. ret
  85. endfunc platform_mem_init
  86. /* ---------------------------------------------
  87. * int plat_crash_console_init(void)
  88. * Function to initialize the crash console
  89. * without a C Runtime to print crash report.
  90. * Clobber list : x0, x1, x2
  91. * ---------------------------------------------
  92. */
  93. func plat_crash_console_init
  94. mov_imm x0, PLAT_QEMU_CRASH_UART_BASE
  95. mov_imm x1, PLAT_QEMU_CRASH_UART_CLK_IN_HZ
  96. mov_imm x2, PLAT_QEMU_CONSOLE_BAUDRATE
  97. b console_pl011_core_init
  98. endfunc plat_crash_console_init
  99. /* ---------------------------------------------
  100. * int plat_crash_console_putc(int c)
  101. * Function to print a character on the crash
  102. * console without a C Runtime.
  103. * Clobber list : x1, x2
  104. * ---------------------------------------------
  105. */
  106. func plat_crash_console_putc
  107. mov_imm x1, PLAT_QEMU_CRASH_UART_BASE
  108. b console_pl011_core_putc
  109. endfunc plat_crash_console_putc
  110. /* ---------------------------------------------
  111. * void plat_crash_console_flush(int c)
  112. * Function to force a write of all buffered
  113. * data that hasn't been output.
  114. * Out : void.
  115. * Clobber list : x0, x1
  116. * ---------------------------------------------
  117. */
  118. func plat_crash_console_flush
  119. mov_imm x0, PLAT_QEMU_CRASH_UART_BASE
  120. b console_pl011_core_flush
  121. endfunc plat_crash_console_flush