fvp_r_helpers.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2021, 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 <drivers/arm/fvp/fvp_pwrc.h>
  9. #include <drivers/arm/gicv2.h>
  10. #include <drivers/arm/gicv3.h>
  11. #include <platform_def.h>
  12. .globl plat_secondary_cold_boot_setup
  13. .globl plat_get_my_entrypoint
  14. .globl plat_is_my_cpu_primary
  15. /* -----------------------------------------------------
  16. * void plat_secondary_cold_boot_setup (void);
  17. *
  18. * This function performs any platform specific actions
  19. * needed for a secondary cpu after a cold reset e.g
  20. * mark the cpu's presence, mechanism to place it in a
  21. * holding pen etc.
  22. * TODO: Should we read the PSYS register to make sure
  23. * that the request has gone through.
  24. * -----------------------------------------------------
  25. */
  26. func plat_secondary_cold_boot_setup
  27. /* ---------------------------------------------
  28. * Power down this cpu.
  29. * TODO: Do we need to worry about powering the
  30. * cluster down as well here? That will need
  31. * locks which we won't have unless an elf-
  32. * loader zeroes out the zi section.
  33. * ---------------------------------------------
  34. */
  35. mrs x0, mpidr_el1
  36. mov_imm x1, PWRC_BASE
  37. str w0, [x1, #PPOFFR_OFF]
  38. /* ---------------------------------------------
  39. * There is no sane reason to come out of this
  40. * wfi so panic if we do. This cpu will be pow-
  41. * ered on and reset by the cpu_on pm api
  42. * ---------------------------------------------
  43. */
  44. dsb sy
  45. wfi
  46. no_ret plat_panic_handler
  47. endfunc plat_secondary_cold_boot_setup
  48. /* ---------------------------------------------------------------------
  49. * uintptr_t plat_get_my_entrypoint (void);
  50. *
  51. * Main job of this routine is to distinguish between a cold and warm
  52. * boot. On FVP_R, this information can be queried from the power
  53. * controller. The Power Control SYS Status Register (PSYSR) indicates
  54. * the wake-up reason for the CPU.
  55. *
  56. * For a cold boot, return 0.
  57. * For a warm boot, read the mailbox and return the address it contains.
  58. *
  59. * TODO: PSYSR is a common register and should be
  60. * accessed using locks. Since it is not possible
  61. * to use locks immediately after a cold reset
  62. * we are relying on the fact that after a cold
  63. * reset all cpus will read the same WK field
  64. * ---------------------------------------------------------------------
  65. */
  66. func plat_get_my_entrypoint
  67. /* ---------------------------------------------------------------------
  68. * When bit PSYSR.WK indicates either "Wake by PPONR" or "Wake by GIC
  69. * WakeRequest signal" then it is a warm boot.
  70. * ---------------------------------------------------------------------
  71. */
  72. mrs x2, mpidr_el1
  73. mov_imm x1, PWRC_BASE
  74. str w2, [x1, #PSYSR_OFF]
  75. ldr w2, [x1, #PSYSR_OFF]
  76. ubfx w2, w2, #PSYSR_WK_SHIFT, #PSYSR_WK_WIDTH
  77. cmp w2, #WKUP_PPONR
  78. beq warm_reset
  79. cmp w2, #WKUP_GICREQ
  80. beq warm_reset
  81. /* Cold reset */
  82. mov x0, #0
  83. ret
  84. warm_reset:
  85. /* ---------------------------------------------------------------------
  86. * A mailbox is maintained in the trusted SRAM. It is flushed out of the
  87. * caches after every update using normal memory so it is safe to read
  88. * it here with SO attributes.
  89. * ---------------------------------------------------------------------
  90. */
  91. mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
  92. ldr x0, [x0]
  93. cbz x0, _panic_handler
  94. ret
  95. /* ---------------------------------------------------------------------
  96. * The power controller indicates this is a warm reset but the mailbox
  97. * is empty. This should never happen!
  98. * ---------------------------------------------------------------------
  99. */
  100. _panic_handler:
  101. no_ret plat_panic_handler
  102. endfunc plat_get_my_entrypoint
  103. /* -----------------------------------------------------
  104. * unsigned int plat_is_my_cpu_primary (void);
  105. *
  106. * Find out whether the current cpu is the primary
  107. * cpu.
  108. * -----------------------------------------------------
  109. */
  110. func plat_is_my_cpu_primary
  111. mrs x0, mpidr_el1
  112. mov_imm x1, MPIDR_AFFINITY_MASK
  113. and x0, x0, x1
  114. cmp x0, #FVP_R_PRIMARY_CPU
  115. cset w0, eq
  116. ret
  117. endfunc plat_is_my_cpu_primary