std_err_record.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2018, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <lib/extensions/ras_arch.h>
  7. #include <lib/utils_def.h>
  8. /*
  9. * Probe for error in memory-mapped registers containing error records
  10. * implemented Standard Error Record format. Upon detecting an error, set probe
  11. * data to the index of the record in error, and return 1; otherwise, return 0.
  12. */
  13. int ser_probe_memmap(uintptr_t base, unsigned int size_num_k, int *probe_data)
  14. {
  15. unsigned int num_records, num_group_regs, i;
  16. uint64_t gsr;
  17. assert(base != 0UL);
  18. /* Only 4K supported for now */
  19. assert(size_num_k == STD_ERR_NODE_SIZE_NUM_K);
  20. num_records = (unsigned int)
  21. (mmio_read_32(ERR_DEVID(base, size_num_k)) & ERR_DEVID_MASK);
  22. /* A group register shows error status for 2^6 error records */
  23. num_group_regs = (num_records >> 6U) + 1U;
  24. /* Iterate through group registers to find a record in error */
  25. for (i = 0; i < num_group_regs; i++) {
  26. gsr = mmio_read_64(ERR_GSR(base, size_num_k, i));
  27. if (gsr == 0ULL)
  28. continue;
  29. /* Return the index of the record in error */
  30. if (probe_data != NULL)
  31. *probe_data = (((int) (i << 6U)) + __builtin_ctzll(gsr));
  32. return 1;
  33. }
  34. return 0;
  35. }
  36. /*
  37. * Probe for error in System Registers where error records are implemented in
  38. * Standard Error Record format. Upon detecting an error, set probe data to the
  39. * index of the record in error, and return 1; otherwise, return 0.
  40. */
  41. int ser_probe_sysreg(unsigned int idx_start, unsigned int num_idx, int *probe_data)
  42. {
  43. unsigned int i;
  44. uint64_t status;
  45. unsigned int max_idx __unused =
  46. ((unsigned int) read_erridr_el1()) & ERRIDR_MASK;
  47. assert(idx_start < max_idx);
  48. assert(check_u32_overflow(idx_start, num_idx) == 0);
  49. assert((idx_start + num_idx - 1U) < max_idx);
  50. for (i = 0; i < num_idx; i++) {
  51. /* Select the error record */
  52. ser_sys_select_record(idx_start + i);
  53. /* Retrieve status register from the error record */
  54. status = read_erxstatus_el1();
  55. /* Check for valid field in status */
  56. if (ERR_STATUS_GET_FIELD(status, V) != 0U) {
  57. if (probe_data != NULL)
  58. *probe_data = (int) i;
  59. return 1;
  60. }
  61. }
  62. return 0;
  63. }