psci_helpers.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. #include <assert_macros.S>
  8. #include <cpu_macros.S>
  9. #include <lib/psci/psci.h>
  10. #include <platform_def.h>
  11. .globl psci_do_pwrdown_cache_maintenance
  12. .globl psci_do_pwrup_cache_maintenance
  13. .globl psci_power_down_wfi
  14. /* -----------------------------------------------------------------------
  15. * void psci_do_pwrdown_cache_maintenance(unsigned int power level);
  16. *
  17. * This function performs cache maintenance for the specified power
  18. * level. The levels of cache affected are determined by the power
  19. * level which is passed as the argument i.e. level 0 results
  20. * in a flush of the L1 cache. Both the L1 and L2 caches are flushed
  21. * for a higher power level.
  22. *
  23. * Additionally, this function also ensures that stack memory is correctly
  24. * flushed out to avoid coherency issues due to a change in its memory
  25. * attributes after the data cache is disabled.
  26. * -----------------------------------------------------------------------
  27. */
  28. func psci_do_pwrdown_cache_maintenance
  29. stp x29, x30, [sp,#-16]!
  30. stp x19, x20, [sp,#-16]!
  31. /* ---------------------------------------------
  32. * Invoke CPU-specific power down operations for
  33. * the appropriate level
  34. * ---------------------------------------------
  35. */
  36. bl prepare_cpu_pwr_dwn
  37. /* ---------------------------------------------
  38. * Do stack maintenance by flushing the used
  39. * stack to the main memory and invalidating the
  40. * remainder.
  41. * ---------------------------------------------
  42. */
  43. bl plat_get_my_stack
  44. /* ---------------------------------------------
  45. * Calculate and store the size of the used
  46. * stack memory in x1.
  47. * ---------------------------------------------
  48. */
  49. mov x19, x0
  50. mov x1, sp
  51. sub x1, x0, x1
  52. mov x0, sp
  53. bl flush_dcache_range
  54. /* ---------------------------------------------
  55. * Calculate and store the size of the unused
  56. * stack memory in x1. Calculate and store the
  57. * stack base address in x0.
  58. * ---------------------------------------------
  59. */
  60. sub x0, x19, #PLATFORM_STACK_SIZE
  61. sub x1, sp, x0
  62. bl inv_dcache_range
  63. ldp x19, x20, [sp], #16
  64. ldp x29, x30, [sp], #16
  65. ret
  66. endfunc psci_do_pwrdown_cache_maintenance
  67. /* -----------------------------------------------------------------------
  68. * void psci_do_pwrup_cache_maintenance(void);
  69. *
  70. * This function performs cache maintenance after this cpu is powered up.
  71. * Currently, this involves managing the used stack memory before turning
  72. * on the data cache.
  73. * -----------------------------------------------------------------------
  74. */
  75. func psci_do_pwrup_cache_maintenance
  76. stp x29, x30, [sp,#-16]!
  77. /* ---------------------------------------------
  78. * Ensure any inflight stack writes have made it
  79. * to main memory.
  80. * ---------------------------------------------
  81. */
  82. dmb st
  83. /* ---------------------------------------------
  84. * Calculate and store the size of the used
  85. * stack memory in x1. Calculate and store the
  86. * stack base address in x0.
  87. * ---------------------------------------------
  88. */
  89. bl plat_get_my_stack
  90. mov x1, sp
  91. sub x1, x0, x1
  92. mov x0, sp
  93. bl inv_dcache_range
  94. /* ---------------------------------------------
  95. * Enable the data cache.
  96. * ---------------------------------------------
  97. */
  98. mrs x0, sctlr_el3
  99. orr x0, x0, #SCTLR_C_BIT
  100. msr sctlr_el3, x0
  101. isb
  102. ldp x29, x30, [sp], #16
  103. ret
  104. endfunc psci_do_pwrup_cache_maintenance
  105. /* -----------------------------------------------------------------------
  106. * void psci_power_down_wfi(void);
  107. * This function is called to indicate to the power controller that it
  108. * is safe to power down this cpu. It should not exit the wfi and will
  109. * be released from reset upon power up.
  110. * -----------------------------------------------------------------------
  111. */
  112. func psci_power_down_wfi
  113. apply_erratum cortex_a510, ERRATUM(2684597), ERRATA_A510_2684597
  114. dsb sy // ensure write buffer empty
  115. 1:
  116. wfi
  117. b 1b
  118. endfunc psci_power_down_wfi