gic600ae_fmu.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright (c) 2021-2022, NVIDIA Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /*
  7. * Driver for GIC-600AE Fault Management Unit
  8. */
  9. #include <assert.h>
  10. #include <inttypes.h>
  11. #include <arch_helpers.h>
  12. #include <common/debug.h>
  13. #include <drivers/arm/gic600ae_fmu.h>
  14. #include <drivers/arm/gicv3.h>
  15. /* GIC-600 AE FMU specific register offsets */
  16. /* GIC-600 AE FMU specific macros */
  17. #define FMU_ERRIDR_NUM U(44)
  18. #define FMU_ERRIDR_NUM_MASK U(0xFFFF)
  19. /* Safety mechanisms for GICD block */
  20. static char *gicd_sm_info[] = {
  21. "Reserved",
  22. "GICD dual lockstep error",
  23. "GICD AXI4 slave interface error",
  24. "GICD-PPI AXI4-Stream interface error",
  25. "GICD-ITS AXI4-Stream interface error",
  26. "GICD-SPI-Collator AXI4-Stream interface error",
  27. "GICD AXI4 master interface error",
  28. "SPI RAM DED error",
  29. "SGI RAM DED error",
  30. "Reserved",
  31. "LPI RAM DED error",
  32. "GICD-remote-GICD AXI4-Stream interface error",
  33. "GICD Q-Channel interface error",
  34. "GICD P-Channel interface error",
  35. "SPI RAM address decode error",
  36. "SGI RAM address decode error",
  37. "Reserved",
  38. "LPI RAM address decode error",
  39. "FMU dual lockstep error",
  40. "FMU ping ACK error",
  41. "FMU APB parity error",
  42. "GICD-Wake AXI4-Stream interface error",
  43. "GICD PageOffset or Chip ID error",
  44. "MBIST REQ error",
  45. "SPI RAM SEC error",
  46. "SGI RAM SEC error",
  47. "Reserved",
  48. "LPI RAM SEC error",
  49. "User custom SM0 error",
  50. "User custom SM1 error",
  51. "GICD-ITS Monolithic switch error",
  52. "GICD-ITS Q-Channel interface error",
  53. "GICD-ITS Monolithic interface error",
  54. "GICD FMU ClkGate override"
  55. };
  56. /* Safety mechanisms for PPI block */
  57. static char *ppi_sm_info[] = {
  58. "Reserved",
  59. "PPI dual lockstep error",
  60. "PPI-GICD AXI4-Stream interface error",
  61. "PPI-CPU-IF AXI4-Stream interface error",
  62. "PPI Q-Channel interface error",
  63. "PPI RAM DED error",
  64. "PPI RAM address decode error",
  65. "PPI RAM SEC error",
  66. "PPI User0 SM",
  67. "PPI User1 SM",
  68. "MBIST REQ error",
  69. "PPI interrupt parity protection error",
  70. "PPI FMU ClkGate override"
  71. };
  72. /* Safety mechanisms for ITS block */
  73. static char *its_sm_info[] = {
  74. "Reserved",
  75. "ITS dual lockstep error",
  76. "ITS-GICD AXI4-Stream interface error",
  77. "ITS AXI4 slave interface error",
  78. "ITS AXI4 master interface error",
  79. "ITS Q-Channel interface error",
  80. "ITS RAM DED error",
  81. "ITS RAM address decode error",
  82. "Bypass ACE switch error",
  83. "ITS RAM SEC error",
  84. "ITS User0 SM",
  85. "ITS User1 SM",
  86. "ITS-GICD Monolithic interface error",
  87. "MBIST REQ error",
  88. "ITS FMU ClkGate override"
  89. };
  90. /* Safety mechanisms for SPI Collator block */
  91. static char *spicol_sm_info[] = {
  92. "Reserved",
  93. "SPI Collator dual lockstep error",
  94. "SPI-Collator-GICD AXI4-Stream interface error",
  95. "SPI Collator Q-Channel interface error",
  96. "SPI Collator Q-Channel clock error",
  97. "SPI interrupt parity error"
  98. };
  99. /* Safety mechanisms for Wake Request block */
  100. static char *wkrqst_sm_info[] = {
  101. "Reserved",
  102. "Wake dual lockstep error",
  103. "Wake-GICD AXI4-Stream interface error"
  104. };
  105. /* Helper function to find detailed information for a specific IERR */
  106. static char __unused *ras_ierr_to_str(unsigned int blkid, unsigned int ierr)
  107. {
  108. char *str = NULL;
  109. /* Find the correct record */
  110. switch (blkid) {
  111. case FMU_BLK_GICD:
  112. assert(ierr < ARRAY_SIZE(gicd_sm_info));
  113. str = gicd_sm_info[ierr];
  114. break;
  115. case FMU_BLK_SPICOL:
  116. assert(ierr < ARRAY_SIZE(spicol_sm_info));
  117. str = spicol_sm_info[ierr];
  118. break;
  119. case FMU_BLK_WAKERQ:
  120. assert(ierr < ARRAY_SIZE(wkrqst_sm_info));
  121. str = wkrqst_sm_info[ierr];
  122. break;
  123. case FMU_BLK_ITS0...FMU_BLK_ITS7:
  124. assert(ierr < ARRAY_SIZE(its_sm_info));
  125. str = its_sm_info[ierr];
  126. break;
  127. case FMU_BLK_PPI0...FMU_BLK_PPI31:
  128. assert(ierr < ARRAY_SIZE(ppi_sm_info));
  129. str = ppi_sm_info[ierr];
  130. break;
  131. default:
  132. assert(false);
  133. break;
  134. }
  135. return str;
  136. }
  137. /*
  138. * Probe for error in memory-mapped registers containing error records.
  139. * Upon detecting an error, set probe data to the index of the record
  140. * in error, and return 1; otherwise, return 0.
  141. */
  142. int gic600_fmu_probe(uint64_t base, int *probe_data)
  143. {
  144. uint64_t gsr;
  145. assert(base != 0UL);
  146. /*
  147. * Read ERR_GSR to find the error record 'M'
  148. */
  149. gsr = gic_fmu_read_errgsr(base);
  150. if (gsr == U(0)) {
  151. return 0;
  152. }
  153. /* Return the index of the record in error */
  154. if (probe_data != NULL) {
  155. *probe_data = (int)__builtin_ctzll(gsr);
  156. }
  157. return 1;
  158. }
  159. /*
  160. * The handler function to read RAS records and find the safety
  161. * mechanism with the error.
  162. */
  163. int gic600_fmu_ras_handler(uint64_t base, int probe_data)
  164. {
  165. uint64_t errstatus;
  166. unsigned int blkid = (unsigned int)probe_data, ierr, serr;
  167. assert(base != 0UL);
  168. /*
  169. * FMU_ERRGSR indicates the ID of the GIC
  170. * block that faulted.
  171. */
  172. assert(blkid <= FMU_BLK_PPI31);
  173. /*
  174. * Find more information by reading FMU_ERR<M>STATUS
  175. * register
  176. */
  177. errstatus = gic_fmu_read_errstatus(base, blkid);
  178. /*
  179. * If FMU_ERR<M>STATUS.V is set to 0, no RAS records
  180. * need to be scanned.
  181. */
  182. if ((errstatus & FMU_ERRSTATUS_V_BIT) == U(0)) {
  183. return 0;
  184. }
  185. /*
  186. * FMU_ERR<M>STATUS.IERR indicates which Safety Mechanism
  187. * reported the error.
  188. */
  189. ierr = (errstatus >> FMU_ERRSTATUS_IERR_SHIFT) &
  190. FMU_ERRSTATUS_IERR_MASK;
  191. /*
  192. * FMU_ERR<M>STATUS.SERR indicates architecturally
  193. * defined primary error code.
  194. */
  195. serr = errstatus & FMU_ERRSTATUS_SERR_MASK;
  196. ERROR("**************************************\n");
  197. ERROR("RAS %s Error detected by GIC600 AE FMU\n",
  198. ((errstatus & FMU_ERRSTATUS_UE_BIT) != 0U) ?
  199. "Uncorrectable" : "Corrected");
  200. ERROR("\tStatus = 0x%lx \n", errstatus);
  201. ERROR("\tBlock ID = 0x%x\n", blkid);
  202. ERROR("\tSafety Mechanism ID = 0x%x (%s)\n", ierr,
  203. ras_ierr_to_str(blkid, ierr));
  204. ERROR("\tArchitecturally defined primary error code = 0x%x\n",
  205. serr);
  206. ERROR("**************************************\n");
  207. /* Clear FMU_ERR<M>STATUS */
  208. gic_fmu_write_errstatus(base, probe_data, errstatus);
  209. return 0;
  210. }
  211. /*
  212. * Initialization sequence for the FMU
  213. *
  214. * 1. enable error detection for error records that are passed in the blk_present_mask
  215. * 2. enable MBIST REQ and FMU Clk Gate override safety mechanisms for error records
  216. * that are present on the platform
  217. *
  218. * The platforms are expected to pass `errctlr_ce_en` and `errctlr_ue_en`.
  219. */
  220. void gic600_fmu_init(uint64_t base, uint64_t blk_present_mask,
  221. bool errctlr_ce_en, bool errctlr_ue_en)
  222. {
  223. unsigned int num_blk = gic_fmu_read_erridr(base) & FMU_ERRIDR_NUM_MASK;
  224. uint64_t errctlr;
  225. uint32_t smen;
  226. INFO("GIC600-AE FMU supports %d error records\n", num_blk);
  227. assert(num_blk == FMU_ERRIDR_NUM);
  228. /* sanitize block present mask */
  229. blk_present_mask &= FMU_BLK_PRESENT_MASK;
  230. /* Enable error detection for all error records */
  231. for (unsigned int i = 0U; i < num_blk; i++) {
  232. /*
  233. * Disable all safety mechanisms for blocks that are not
  234. * present and skip the next steps.
  235. */
  236. if ((blk_present_mask & BIT(i)) == 0U) {
  237. gic_fmu_disable_all_sm_blkid(base, i);
  238. continue;
  239. }
  240. /* Read the error record control register */
  241. errctlr = gic_fmu_read_errctlr(base, i);
  242. /* Enable error reporting and logging, if it is disabled */
  243. if ((errctlr & FMU_ERRCTLR_ED_BIT) == 0U) {
  244. errctlr |= FMU_ERRCTLR_ED_BIT;
  245. }
  246. /* Enable client provided ERRCTLR settings */
  247. errctlr |= (errctlr_ce_en ? (FMU_ERRCTLR_CI_BIT | FMU_ERRCTLR_CE_EN_BIT) : 0);
  248. errctlr |= (errctlr_ue_en ? FMU_ERRCTLR_UI_BIT : 0U);
  249. gic_fmu_write_errctlr(base, i, errctlr);
  250. }
  251. /*
  252. * Enable MBIST REQ error and FMU CLK gate override safety mechanisms for
  253. * all blocks
  254. *
  255. * GICD, SMID 23 and SMID 33
  256. * PPI, SMID 10 and SMID 12
  257. * ITS, SMID 13 and SMID 14
  258. */
  259. if ((blk_present_mask & BIT(FMU_BLK_GICD)) != 0U) {
  260. smen = (GICD_MBIST_REQ_ERROR << FMU_SMEN_SMID_SHIFT) |
  261. (FMU_BLK_GICD << FMU_SMEN_BLK_SHIFT) |
  262. FMU_SMEN_EN_BIT;
  263. gic_fmu_write_smen(base, smen);
  264. smen = (GICD_FMU_CLKGATE_ERROR << FMU_SMEN_SMID_SHIFT) |
  265. (FMU_BLK_GICD << FMU_SMEN_BLK_SHIFT) |
  266. FMU_SMEN_EN_BIT;
  267. gic_fmu_write_smen(base, smen);
  268. }
  269. for (unsigned int i = FMU_BLK_PPI0; i < FMU_BLK_PPI31; i++) {
  270. if ((blk_present_mask & BIT(i)) != 0U) {
  271. smen = (PPI_MBIST_REQ_ERROR << FMU_SMEN_SMID_SHIFT) |
  272. (i << FMU_SMEN_BLK_SHIFT) |
  273. FMU_SMEN_EN_BIT;
  274. gic_fmu_write_smen(base, smen);
  275. smen = (PPI_FMU_CLKGATE_ERROR << FMU_SMEN_SMID_SHIFT) |
  276. (i << FMU_SMEN_BLK_SHIFT) |
  277. FMU_SMEN_EN_BIT;
  278. gic_fmu_write_smen(base, smen);
  279. }
  280. }
  281. for (unsigned int i = FMU_BLK_ITS0; i < FMU_BLK_ITS7; i++) {
  282. if ((blk_present_mask & BIT(i)) != 0U) {
  283. smen = (ITS_MBIST_REQ_ERROR << FMU_SMEN_SMID_SHIFT) |
  284. (i << FMU_SMEN_BLK_SHIFT) |
  285. FMU_SMEN_EN_BIT;
  286. gic_fmu_write_smen(base, smen);
  287. smen = (ITS_FMU_CLKGATE_ERROR << FMU_SMEN_SMID_SHIFT) |
  288. (i << FMU_SMEN_BLK_SHIFT) |
  289. FMU_SMEN_EN_BIT;
  290. gic_fmu_write_smen(base, smen);
  291. }
  292. }
  293. }
  294. /*
  295. * This function enable the GICD background ping engine. The GICD sends ping
  296. * messages to each remote GIC block, and expects a PING_ACK back within the
  297. * specified timeout. Pings need to be enabled after programming the timeout
  298. * value.
  299. */
  300. void gic600_fmu_enable_ping(uint64_t base, uint64_t blk_present_mask,
  301. unsigned int timeout_val, unsigned int interval_diff)
  302. {
  303. /*
  304. * Populate the PING Mask to skip a specific block while generating
  305. * background ping messages and enable the ping mechanism.
  306. */
  307. gic_fmu_write_pingmask(base, ~blk_present_mask);
  308. gic_fmu_write_pingctlr(base, (interval_diff << FMU_PINGCTLR_INTDIFF_SHIFT) |
  309. (timeout_val << FMU_PINGCTLR_TIMEOUTVAL_SHIFT) | FMU_PINGCTLR_EN_BIT);
  310. }
  311. /* Print the safety mechanism description for a given block */
  312. void gic600_fmu_print_sm_info(uint64_t base, unsigned int blk, unsigned int smid)
  313. {
  314. if (blk == FMU_BLK_GICD && smid <= FMU_SMID_GICD_MAX) {
  315. INFO("GICD, SMID %d: %s\n", smid, gicd_sm_info[smid]);
  316. }
  317. if (blk == FMU_BLK_SPICOL && smid <= FMU_SMID_SPICOL_MAX) {
  318. INFO("SPI Collator, SMID %d: %s\n", smid, spicol_sm_info[smid]);
  319. }
  320. if (blk == FMU_BLK_WAKERQ && (smid <= FMU_SMID_WAKERQ_MAX)) {
  321. INFO("Wake Request, SMID %d: %s\n", smid, wkrqst_sm_info[smid]);
  322. }
  323. if (((blk >= FMU_BLK_ITS0) && (blk <= FMU_BLK_ITS7)) && (smid <= FMU_SMID_ITS_MAX)) {
  324. INFO("ITS, SMID %d: %s\n", smid, its_sm_info[smid]);
  325. }
  326. if (((blk >= FMU_BLK_PPI0) && (blk <= FMU_BLK_PPI31)) && (smid <= FMU_SMID_PPI_MAX)) {
  327. INFO("PPI, SMID %d: %s\n", smid, ppi_sm_info[smid]);
  328. }
  329. }