cpu_macros.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef CPU_MACROS_S
  7. #define CPU_MACROS_S
  8. #include <arch.h>
  9. #include <lib/cpus/errata_report.h>
  10. #if defined(IMAGE_BL1) || defined(IMAGE_BL32) || (defined(IMAGE_BL2) && BL2_AT_EL3)
  11. #define IMAGE_AT_EL3
  12. #endif
  13. #define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \
  14. (MIDR_PN_MASK << MIDR_PN_SHIFT)
  15. /* The number of CPU operations allowed */
  16. #define CPU_MAX_PWR_DWN_OPS 2
  17. /* Special constant to specify that CPU has no reset function */
  18. #define CPU_NO_RESET_FUNC 0
  19. /* Word size for 32-bit CPUs */
  20. #define CPU_WORD_SIZE 4
  21. /*
  22. * Whether errata status needs reporting. Errata status is printed in debug
  23. * builds for both BL1 and BL32 images.
  24. */
  25. #if (defined(IMAGE_BL1) || defined(IMAGE_BL32)) && DEBUG
  26. # define REPORT_ERRATA 1
  27. #else
  28. # define REPORT_ERRATA 0
  29. #endif
  30. .equ CPU_MIDR_SIZE, CPU_WORD_SIZE
  31. .equ CPU_RESET_FUNC_SIZE, CPU_WORD_SIZE
  32. .equ CPU_PWR_DWN_OPS_SIZE, CPU_WORD_SIZE * CPU_MAX_PWR_DWN_OPS
  33. .equ CPU_ERRATA_FUNC_SIZE, CPU_WORD_SIZE
  34. .equ CPU_ERRATA_LOCK_SIZE, CPU_WORD_SIZE
  35. .equ CPU_ERRATA_PRINTED_SIZE, CPU_WORD_SIZE
  36. #ifndef IMAGE_AT_EL3
  37. .equ CPU_RESET_FUNC_SIZE, 0
  38. #endif
  39. /* The power down core and cluster is needed only in BL32 */
  40. #ifndef IMAGE_BL32
  41. .equ CPU_PWR_DWN_OPS_SIZE, 0
  42. #endif
  43. /* Fields required to print errata status */
  44. #if !REPORT_ERRATA
  45. .equ CPU_ERRATA_FUNC_SIZE, 0
  46. #endif
  47. /* Only BL32 requires mutual exclusion and printed flag. */
  48. #if !(REPORT_ERRATA && defined(IMAGE_BL32))
  49. .equ CPU_ERRATA_LOCK_SIZE, 0
  50. .equ CPU_ERRATA_PRINTED_SIZE, 0
  51. #endif
  52. /*
  53. * Define the offsets to the fields in cpu_ops structure.
  54. * Every offset is defined based on the offset and size of the previous
  55. * field.
  56. */
  57. .equ CPU_MIDR, 0
  58. .equ CPU_RESET_FUNC, CPU_MIDR + CPU_MIDR_SIZE
  59. .equ CPU_PWR_DWN_OPS, CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
  60. .equ CPU_ERRATA_FUNC, CPU_PWR_DWN_OPS + CPU_PWR_DWN_OPS_SIZE
  61. .equ CPU_ERRATA_LOCK, CPU_ERRATA_FUNC + CPU_ERRATA_FUNC_SIZE
  62. .equ CPU_ERRATA_PRINTED, CPU_ERRATA_LOCK + CPU_ERRATA_LOCK_SIZE
  63. .equ CPU_OPS_SIZE, CPU_ERRATA_PRINTED + CPU_ERRATA_PRINTED_SIZE
  64. /*
  65. * Write given expressions as words
  66. *
  67. * _count:
  68. * Write at least _count words. If the given number of expressions
  69. * is less than _count, repeat the last expression to fill _count
  70. * words in total
  71. * _rest:
  72. * Optional list of expressions. _this is for parameter extraction
  73. * only, and has no significance to the caller
  74. *
  75. * Invoked as:
  76. * fill_constants 2, foo, bar, blah, ...
  77. */
  78. .macro fill_constants _count:req, _this, _rest:vararg
  79. .ifgt \_count
  80. /* Write the current expression */
  81. .ifb \_this
  82. .error "Nothing to fill"
  83. .endif
  84. .word \_this
  85. /* Invoke recursively for remaining expressions */
  86. .ifnb \_rest
  87. fill_constants \_count-1, \_rest
  88. .else
  89. fill_constants \_count-1, \_this
  90. .endif
  91. .endif
  92. .endm
  93. /*
  94. * Declare CPU operations
  95. *
  96. * _name:
  97. * Name of the CPU for which operations are being specified
  98. * _midr:
  99. * Numeric value expected to read from CPU's MIDR
  100. * _resetfunc:
  101. * Reset function for the CPU. If there's no CPU reset function,
  102. * specify CPU_NO_RESET_FUNC
  103. * _power_down_ops:
  104. * Comma-separated list of functions to perform power-down
  105. * operatios on the CPU. At least one, and up to
  106. * CPU_MAX_PWR_DWN_OPS number of functions may be specified.
  107. * Starting at power level 0, these functions shall handle power
  108. * down at subsequent power levels. If there aren't exactly
  109. * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be
  110. * used to handle power down at subsequent levels
  111. */
  112. .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
  113. _power_down_ops:vararg
  114. .section .cpu_ops, "a"
  115. .align 2
  116. .type cpu_ops_\_name, %object
  117. .word \_midr
  118. #if defined(IMAGE_AT_EL3)
  119. .word \_resetfunc
  120. #endif
  121. #ifdef IMAGE_BL32
  122. /* Insert list of functions */
  123. fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
  124. #endif
  125. #if REPORT_ERRATA
  126. .ifndef \_name\()_cpu_str
  127. /*
  128. * Place errata reported flag, and the spinlock to arbitrate access to
  129. * it in the data section.
  130. */
  131. .pushsection .data
  132. define_asm_spinlock \_name\()_errata_lock
  133. \_name\()_errata_reported:
  134. .word 0
  135. .popsection
  136. /* Place CPU string in rodata */
  137. .pushsection .rodata
  138. \_name\()_cpu_str:
  139. .asciz "\_name"
  140. .popsection
  141. .endif
  142. /*
  143. * Mandatory errata status printing function for CPUs of
  144. * this class.
  145. */
  146. .word \_name\()_errata_report
  147. #ifdef IMAGE_BL32
  148. /* Pointers to errata lock and reported flag */
  149. .word \_name\()_errata_lock
  150. .word \_name\()_errata_reported
  151. #endif
  152. #endif
  153. .endm
  154. #if REPORT_ERRATA
  155. /*
  156. * Print status of a CPU errata
  157. *
  158. * _chosen:
  159. * Identifier indicating whether or not a CPU errata has been
  160. * compiled in.
  161. * _cpu:
  162. * Name of the CPU
  163. * _id:
  164. * Errata identifier
  165. * _rev_var:
  166. * Register containing the combined value CPU revision and variant
  167. * - typically the return value of cpu_get_rev_var
  168. */
  169. .macro report_errata _chosen, _cpu, _id, _rev_var=r4
  170. /* Stash a string with errata ID */
  171. .pushsection .rodata
  172. \_cpu\()_errata_\_id\()_str:
  173. .asciz "\_id"
  174. .popsection
  175. /* Check whether errata applies */
  176. mov r0, \_rev_var
  177. bl check_errata_\_id
  178. .ifeq \_chosen
  179. /*
  180. * Errata workaround has not been compiled in. If the errata would have
  181. * applied had it been compiled in, print its status as missing.
  182. */
  183. cmp r0, #0
  184. movne r0, #ERRATA_MISSING
  185. .endif
  186. ldr r1, =\_cpu\()_cpu_str
  187. ldr r2, =\_cpu\()_errata_\_id\()_str
  188. bl errata_print_msg
  189. .endm
  190. #endif
  191. /*
  192. * Helper macro that reads the part number of the current CPU and jumps
  193. * to the given label if it matches the CPU MIDR provided.
  194. *
  195. * Clobbers: r0-r1
  196. */
  197. .macro jump_if_cpu_midr _cpu_midr, _label
  198. ldcopr r0, MIDR
  199. ubfx r0, r0, #MIDR_PN_SHIFT, #12
  200. ldr r1, =((\_cpu_midr >> MIDR_PN_SHIFT) & MIDR_PN_MASK)
  201. cmp r0, r1
  202. beq \_label
  203. .endm
  204. #endif /* CPU_MACROS_S */