errata_abi_main.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * Copyright (c) 2023-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include "cpu_errata_info.h"
  8. #include <lib/cpus/cpu_ops.h>
  9. #include <lib/cpus/errata.h>
  10. #include <lib/smccc.h>
  11. #include <lib/utils_def.h>
  12. #include <services/errata_abi_svc.h>
  13. #include <smccc_helpers.h>
  14. /*
  15. * Global pointer that points to the specific
  16. * structure based on the MIDR part number
  17. */
  18. struct em_cpu_list *cpu_ptr;
  19. /* Structure array that holds CPU specific errata information */
  20. struct em_cpu_list cpu_list[] = {
  21. #if CORTEX_A78_H_INC
  22. {
  23. .cpu_midr = CORTEX_A78_MIDR,
  24. .cpu_errata_list = {
  25. [0] = {2712571, 0x00, 0x12},
  26. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  27. }
  28. },
  29. #endif /* CORTEX_A78_H_INC */
  30. #if CORTEX_A78_AE_H_INC
  31. {
  32. .cpu_midr = CORTEX_A78_AE_MIDR,
  33. .cpu_errata_list = {
  34. [0] = {2712574, 0x00, 0x02},
  35. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  36. }
  37. },
  38. #endif /* CORTEX_A78_AE_H_INC */
  39. #if CORTEX_A78C_H_INC
  40. {
  41. .cpu_midr = CORTEX_A78C_MIDR,
  42. .cpu_errata_list = {
  43. [0] = {2712575, 0x01, 0x02},
  44. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  45. }
  46. },
  47. #endif /* CORTEX_A78C_H_INC */
  48. #if NEOVERSE_V1_H_INC
  49. {
  50. .cpu_midr = NEOVERSE_V1_MIDR,
  51. .cpu_errata_list = {
  52. [0] = {2701953, 0x00, 0x11},
  53. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  54. }
  55. },
  56. #endif /* NEOVERSE_V1_H_INC */
  57. #if CORTEX_A710_H_INC
  58. {
  59. .cpu_midr = CORTEX_A710_MIDR,
  60. .cpu_errata_list = {
  61. [0] = {2701952, 0x00, 0x21},
  62. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  63. }
  64. },
  65. #endif /* CORTEX_A710_H_INC */
  66. #if NEOVERSE_N2_H_INC
  67. {
  68. .cpu_midr = NEOVERSE_N2_MIDR,
  69. .cpu_errata_list = {
  70. [0] = {2728475, 0x00, 0x02},
  71. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  72. }
  73. },
  74. #endif /* NEOVERSE_N2_H_INC */
  75. #if CORTEX_X2_H_INC
  76. {
  77. .cpu_midr = CORTEX_X2_MIDR,
  78. .cpu_errata_list = {
  79. [0] = {2701952, 0x00, 0x21},
  80. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  81. }
  82. },
  83. #endif /* CORTEX_X2_H_INC */
  84. #if NEOVERSE_V2_H_INC
  85. {
  86. .cpu_midr = NEOVERSE_V2_MIDR,
  87. .cpu_errata_list = {
  88. [0] = {2719103, 0x00, 0x01},
  89. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  90. }
  91. },
  92. #endif /* NEOVERSE_V2_H_INC */
  93. #if CORTEX_X3_H_INC
  94. {
  95. .cpu_midr = CORTEX_X3_MIDR,
  96. .cpu_errata_list = {
  97. [0] = {2701951, 0x00, 0x11},
  98. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  99. }
  100. },
  101. #endif /* CORTEX_X3_H_INC */
  102. #if CORTEX_X4_H_INC
  103. {
  104. .cpu_midr = CORTEX_X4_MIDR,
  105. .cpu_errata_list = {
  106. [0] = {2701112, 0x00, 0x00},
  107. [1 ... ERRATA_LIST_END] = UNDEF_ERRATA,
  108. }
  109. },
  110. #endif /* CORTEX_X4_H_INC */
  111. };
  112. #if ERRATA_NON_ARM_INTERCONNECT
  113. /* Check if the errata is enabled for non-arm interconnect */
  114. static int32_t non_arm_interconnect_errata(uint32_t errata_id, long rev_var)
  115. {
  116. int32_t ret_val = EM_UNKNOWN_ERRATUM;
  117. /* Determine the number of cpu listed in the cpu list */
  118. uint8_t size_cpulist = ARRAY_SIZE(cpu_list);
  119. /* Read the midr reg to extract cpu, revision and variant info */
  120. uint32_t midr_val = read_midr();
  121. for (uint8_t i = 0U; i < size_cpulist; i++) {
  122. cpu_ptr = &cpu_list[i];
  123. /*
  124. * If the cpu partnumber in the cpu list, matches the midr
  125. * part number, check to see if the errata ID matches
  126. */
  127. if (EXTRACT_PARTNUM(midr_val) == EXTRACT_PARTNUM(cpu_ptr->cpu_midr)) {
  128. struct em_cpu *ptr = NULL;
  129. for (int j = 0; j < MAX_PLAT_CPU_ERRATA_ENTRIES; j++) {
  130. ptr = &cpu_ptr->cpu_errata_list[j];
  131. assert(ptr != NULL);
  132. if (errata_id == ptr->em_errata_id) {
  133. if (RXPX_RANGE(rev_var, ptr->em_rxpx_lo, ptr->em_rxpx_hi)) {
  134. ret_val = EM_AFFECTED;
  135. break;
  136. }
  137. ret_val = EM_NOT_AFFECTED;
  138. break;
  139. }
  140. }
  141. break;
  142. }
  143. }
  144. return ret_val;
  145. }
  146. #endif
  147. /* Function to check if the errata exists for the specific CPU and rxpx */
  148. int32_t verify_errata_implemented(uint32_t errata_id, uint32_t forward_flag)
  149. {
  150. int32_t ret_val;
  151. struct cpu_ops *cpu_ops;
  152. struct erratum_entry *entry, *end;
  153. long rev_var;
  154. ret_val = EM_UNKNOWN_ERRATUM;
  155. rev_var = cpu_get_rev_var();
  156. #if ERRATA_NON_ARM_INTERCONNECT
  157. ret_val = non_arm_interconnect_errata(errata_id, rev_var);
  158. if (ret_val != EM_UNKNOWN_ERRATUM) {
  159. return ret_val;
  160. }
  161. #endif
  162. cpu_ops = get_cpu_ops_ptr();
  163. assert(cpu_ops != NULL);
  164. entry = cpu_ops->errata_list_start;
  165. assert(entry != NULL);
  166. end = cpu_ops->errata_list_end;
  167. assert(end != NULL);
  168. end--; /* point to the last erratum entry of the queried cpu */
  169. while ((entry <= end) && (ret_val == EM_UNKNOWN_ERRATUM)) {
  170. if (entry->id == errata_id) {
  171. if (entry->check_func(rev_var)) {
  172. if (entry->chosen)
  173. return EM_HIGHER_EL_MITIGATION;
  174. else
  175. return EM_AFFECTED;
  176. }
  177. return EM_NOT_AFFECTED;
  178. }
  179. entry += 1;
  180. }
  181. return ret_val;
  182. }
  183. /* Predicate indicating that a function id is part of EM_ABI */
  184. bool is_errata_fid(uint32_t smc_fid)
  185. {
  186. return ((smc_fid == ARM_EM_VERSION) ||
  187. (smc_fid == ARM_EM_FEATURES) ||
  188. (smc_fid == ARM_EM_CPU_ERRATUM_FEATURES));
  189. }
  190. bool validate_spsr_mode(void)
  191. {
  192. /* In AArch64, if the caller is EL1, return true */
  193. #if __aarch64__
  194. if (GET_EL(read_spsr_el3()) == MODE_EL1) {
  195. return true;
  196. }
  197. return false;
  198. #else
  199. /* In AArch32, if in system/svc mode, return true */
  200. uint8_t read_el_state = GET_M32(read_spsr());
  201. if ((read_el_state == (MODE32_svc)) || (read_el_state == MODE32_sys)) {
  202. return true;
  203. }
  204. return false;
  205. #endif /* __aarch64__ */
  206. }
  207. uintptr_t errata_abi_smc_handler(uint32_t smc_fid, u_register_t x1,
  208. u_register_t x2, u_register_t x3, u_register_t x4,
  209. void *cookie, void *handle, u_register_t flags)
  210. {
  211. int32_t ret_id = EM_UNKNOWN_ERRATUM;
  212. switch (smc_fid) {
  213. case ARM_EM_VERSION:
  214. SMC_RET1(handle, MAKE_SMCCC_VERSION(
  215. EM_VERSION_MAJOR, EM_VERSION_MINOR
  216. ));
  217. break; /* unreachable */
  218. case ARM_EM_FEATURES:
  219. if (is_errata_fid((uint32_t)x1)) {
  220. SMC_RET1(handle, EM_SUCCESS);
  221. }
  222. SMC_RET1(handle, EM_NOT_SUPPORTED);
  223. break; /* unreachable */
  224. case ARM_EM_CPU_ERRATUM_FEATURES:
  225. /*
  226. * If the forward flag is greater than zero and the calling EL
  227. * is EL1 in AArch64 or in system mode or svc mode in case of AArch32,
  228. * return Invalid Parameters.
  229. */
  230. if (((uint32_t)x2 != 0) && (validate_spsr_mode())) {
  231. SMC_RET1(handle, EM_INVALID_PARAMETERS);
  232. }
  233. ret_id = verify_errata_implemented((uint32_t)x1, (uint32_t)x2);
  234. SMC_RET1(handle, ret_id);
  235. break; /* unreachable */
  236. default:
  237. {
  238. WARN("Unimplemented Errata ABI Service Call: 0x%x\n", smc_fid);
  239. SMC_RET1(handle, EM_UNKNOWN_ERRATUM);
  240. break; /* unreachable */
  241. }
  242. }
  243. }