cpu_macros.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2016-2024, 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 <lib/cpus/cpu_ops.h>
  9. #include <lib/cpus/errata.h>
  10. /*
  11. * Write given expressions as words
  12. *
  13. * _count:
  14. * Write at least _count words. If the given number of expressions
  15. * is less than _count, repeat the last expression to fill _count
  16. * words in total
  17. * _rest:
  18. * Optional list of expressions. _this is for parameter extraction
  19. * only, and has no significance to the caller
  20. *
  21. * Invoked as:
  22. * fill_constants 2, foo, bar, blah, ...
  23. */
  24. .macro fill_constants _count:req, _this, _rest:vararg
  25. .ifgt \_count
  26. /* Write the current expression */
  27. .ifb \_this
  28. .error "Nothing to fill"
  29. .endif
  30. .word \_this
  31. /* Invoke recursively for remaining expressions */
  32. .ifnb \_rest
  33. fill_constants \_count-1, \_rest
  34. .else
  35. fill_constants \_count-1, \_this
  36. .endif
  37. .endif
  38. .endm
  39. /*
  40. * Declare CPU operations
  41. *
  42. * _name:
  43. * Name of the CPU for which operations are being specified
  44. * _midr:
  45. * Numeric value expected to read from CPU's MIDR
  46. * _resetfunc:
  47. * Reset function for the CPU. If there's no CPU reset function,
  48. * specify CPU_NO_RESET_FUNC
  49. * _power_down_ops:
  50. * Comma-separated list of functions to perform power-down
  51. * operatios on the CPU. At least one, and up to
  52. * CPU_MAX_PWR_DWN_OPS number of functions may be specified.
  53. * Starting at power level 0, these functions shall handle power
  54. * down at subsequent power levels. If there aren't exactly
  55. * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be
  56. * used to handle power down at subsequent levels
  57. */
  58. .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
  59. _power_down_ops:vararg
  60. .section .cpu_ops, "a"
  61. .align 2
  62. .type cpu_ops_\_name, %object
  63. .word \_midr
  64. #if defined(IMAGE_AT_EL3)
  65. .word \_resetfunc
  66. #endif
  67. #ifdef IMAGE_BL32
  68. /* Insert list of functions */
  69. fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
  70. #endif
  71. /*
  72. * It is possible (although unlikely) that a cpu may have no errata in
  73. * code. In that case the start label will not be defined. The list is
  74. * inteded to be used in a loop, so define it as zero-length for
  75. * predictable behaviour. Since this macro is always called at the end
  76. * of the cpu file (after all errata have been parsed) we can be sure
  77. * that we are at the end of the list. Some cpus call the macro twice,
  78. * so only do this once.
  79. */
  80. .pushsection .rodata.errata_entries
  81. .ifndef \_name\()_errata_list_start
  82. \_name\()_errata_list_start:
  83. .endif
  84. /* some call this multiple times, so only do this once */
  85. .ifndef \_name\()_errata_list_end
  86. \_name\()_errata_list_end:
  87. .endif
  88. .popsection
  89. /* and now put them in cpu_ops */
  90. .word \_name\()_errata_list_start
  91. .word \_name\()_errata_list_end
  92. #if REPORT_ERRATA
  93. .ifndef \_name\()_cpu_str
  94. /*
  95. * Place errata reported flag, and the spinlock to arbitrate access to
  96. * it in the data section.
  97. */
  98. .pushsection .data
  99. define_asm_spinlock \_name\()_errata_lock
  100. \_name\()_errata_reported:
  101. .word 0
  102. .popsection
  103. /* Place CPU string in rodata */
  104. .pushsection .rodata
  105. \_name\()_cpu_str:
  106. .asciz "\_name"
  107. .popsection
  108. .endif
  109. .word \_name\()_cpu_str
  110. #ifdef IMAGE_BL32
  111. /* Pointers to errata lock and reported flag */
  112. .word \_name\()_errata_lock
  113. .word \_name\()_errata_reported
  114. #endif
  115. #endif
  116. .endm
  117. /*
  118. * Helper macro that reads the part number of the current CPU and jumps
  119. * to the given label if it matches the CPU MIDR provided.
  120. *
  121. * Clobbers: r0-r1
  122. */
  123. .macro jump_if_cpu_midr _cpu_midr, _label
  124. ldcopr r0, MIDR
  125. ubfx r0, r0, #MIDR_PN_SHIFT, #12
  126. ldr r1, =((\_cpu_midr >> MIDR_PN_SHIFT) & MIDR_PN_MASK)
  127. cmp r0, r1
  128. beq \_label
  129. .endm
  130. /*
  131. * NOTE an erratum and CVE id could clash. However, both numbers are very large
  132. * and the probablity is minuscule. Working around this makes code very
  133. * complicated and extremely difficult to read so it is not considered. In the
  134. * unlikely event that this does happen, prepending the CVE id with a 0 should
  135. * resolve the conflict
  136. */
  137. /*
  138. * Add an entry for this erratum to the errata framework
  139. *
  140. * _cpu:
  141. * Name of cpu as given to declare_cpu_ops
  142. *
  143. * _cve:
  144. * Whether erratum is a CVE. CVE year if yes, 0 otherwise
  145. *
  146. * _id:
  147. * Erratum or CVE number. Please combine with the previous field with the
  148. * ERRATUM or CVE macros
  149. *
  150. * _chosen:
  151. * Compile time flag on whether the erratum is included
  152. *
  153. * _special:
  154. * The special non-standard name of an erratum
  155. */
  156. .macro add_erratum_entry _cpu:req, _cve:req, _id:req, _chosen:req, _special
  157. .pushsection .rodata.errata_entries
  158. .align 2
  159. .ifndef \_cpu\()_errata_list_start
  160. \_cpu\()_errata_list_start:
  161. .endif
  162. /* unused on AArch32, maintain for portability */
  163. .word 0
  164. /* TODO(errata ABI): this prevents all checker functions from
  165. * being optimised away. Can be done away with unless the ABI
  166. * needs them */
  167. .ifnb \_special
  168. .word check_errata_\_special
  169. .elseif \_cve
  170. .word check_errata_cve_\_cve\()_\_id
  171. .else
  172. .word check_errata_\_id
  173. .endif
  174. /* Will fit CVEs with up to 10 character in the ID field */
  175. .word \_id
  176. .hword \_cve
  177. .byte \_chosen
  178. /* TODO(errata ABI): mitigated field for known but unmitigated
  179. * errata*/
  180. .byte 0x1
  181. .popsection
  182. .endm
  183. #endif /* CPU_MACROS_S */