ras_arch.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright (c) 2018, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef RAS_ARCH_H
  8. #define RAS_ARCH_H
  9. /*
  10. * Size of nodes implementing Standard Error Records - currently only 4k is
  11. * supported.
  12. */
  13. #define STD_ERR_NODE_SIZE_NUM_K 4U
  14. /*
  15. * Individual register offsets within an error record in Standard Error Record
  16. * format when error records are accessed through memory-mapped registers.
  17. */
  18. #define ERR_FR(n) (0x0ULL + (64ULL * (n)))
  19. #define ERR_CTLR(n) (0x8ULL + (64ULL * (n)))
  20. #define ERR_STATUS(n) (0x10ULL + (64ULL * (n)))
  21. #define ERR_ADDR(n) (0x18ULL + (64ULL * (n)))
  22. #define ERR_MISC0(n) (0x20ULL + (64ULL * (n)))
  23. #define ERR_MISC1(n) (0x28ULL + (64ULL * (n)))
  24. /* Group Status Register (ERR_STATUS) offset */
  25. #define ERR_GSR(base, size_num_k, n) \
  26. ((base) + (0x380ULL * (size_num_k)) + (8ULL * (n)))
  27. /* Management register offsets */
  28. #define ERR_DEVID(base, size_num_k) \
  29. ((base) + ((0x400ULL * (size_num_k)) - 0x100ULL) + 0xc8ULL)
  30. #define ERR_DEVID_MASK 0xffffUL
  31. /* Standard Error Record status register fields */
  32. #define ERR_STATUS_AV_SHIFT 31
  33. #define ERR_STATUS_AV_MASK U(0x1)
  34. #define ERR_STATUS_V_SHIFT 30
  35. #define ERR_STATUS_V_MASK U(0x1)
  36. #define ERR_STATUS_UE_SHIFT 29
  37. #define ERR_STATUS_UE_MASK U(0x1)
  38. #define ERR_STATUS_ER_SHIFT 28
  39. #define ERR_STATUS_ER_MASK U(0x1)
  40. #define ERR_STATUS_OF_SHIFT 27
  41. #define ERR_STATUS_OF_MASK U(0x1)
  42. #define ERR_STATUS_MV_SHIFT 26
  43. #define ERR_STATUS_MV_MASK U(0x1)
  44. #define ERR_STATUS_CE_SHIFT 24
  45. #define ERR_STATUS_CE_MASK U(0x3)
  46. #define ERR_STATUS_DE_SHIFT 23
  47. #define ERR_STATUS_DE_MASK U(0x1)
  48. #define ERR_STATUS_PN_SHIFT 22
  49. #define ERR_STATUS_PN_MASK U(0x1)
  50. #define ERR_STATUS_UET_SHIFT 20
  51. #define ERR_STATUS_UET_MASK U(0x3)
  52. #define ERR_STATUS_IERR_SHIFT 8
  53. #define ERR_STATUS_IERR_MASK U(0xff)
  54. #define ERR_STATUS_SERR_SHIFT 0
  55. #define ERR_STATUS_SERR_MASK U(0xff)
  56. #define ERR_STATUS_GET_FIELD(_status, _field) \
  57. (((_status) >> ERR_STATUS_ ##_field ##_SHIFT) & ERR_STATUS_ ##_field ##_MASK)
  58. #define ERR_STATUS_CLR_FIELD(_status, _field) \
  59. (_status) &= ~(ERR_STATUS_ ##_field ##_MASK << ERR_STATUS_ ##_field ##_SHIFT)
  60. #define ERR_STATUS_SET_FIELD(_status, _field, _value) \
  61. (_status) |= (((_value) & ERR_STATUS_ ##_field ##_MASK) << ERR_STATUS_ ##_field ##_SHIFT)
  62. #define ERR_STATUS_WRITE_FIELD(_status, _field, _value) do { \
  63. ERR_STATUS_CLR_FIELD(_status, _field, _value); \
  64. ERR_STATUS_SET_FIELD(_status, _field, _value); \
  65. } while (0)
  66. /* Standard Error Record control register fields */
  67. #define ERR_CTLR_WDUI_SHIFT 11
  68. #define ERR_CTLR_WDUI_MASK 0x1
  69. #define ERR_CTLR_RDUI_SHIFT 10
  70. #define ERR_CTLR_RDUI_MASK 0x1
  71. #define ERR_CTLR_DUI_SHIFT ERR_CTLR_RDUI_SHIFT
  72. #define ERR_CTLR_DUI_MASK ERR_CTLR_RDUI_MASK
  73. #define ERR_CTLR_WCFI_SHIFT 9
  74. #define ERR_CTLR_WCFI_MASK 0x1
  75. #define ERR_CTLR_RCFI_SHIFT 8
  76. #define ERR_CTLR_RCFI_MASK 0x1
  77. #define ERR_CTLR_CFI_SHIFT ERR_CTLR_RCFI_SHIFT
  78. #define ERR_CTLR_CFI_MASK ERR_CTLR_RCFI_MASK
  79. #define ERR_CTLR_WUE_SHIFT 7
  80. #define ERR_CTLR_WUE_MASK 0x1
  81. #define ERR_CTLR_WFI_SHIFT 6
  82. #define ERR_CTLR_WFI_MASK 0x1
  83. #define ERR_CTLR_WUI_SHIFT 5
  84. #define ERR_CTLR_WUI_MASK 0x1
  85. #define ERR_CTLR_RUE_SHIFT 4
  86. #define ERR_CTLR_RUE_MASK 0x1
  87. #define ERR_CTLR_UE_SHIFT ERR_CTLR_RUE_SHIFT
  88. #define ERR_CTLR_UE_MASK ERR_CTLR_RUE_MASK
  89. #define ERR_CTLR_RFI_SHIFT 3
  90. #define ERR_CTLR_RFI_MASK 0x1
  91. #define ERR_CTLR_FI_SHIFT ERR_CTLR_RFI_SHIFT
  92. #define ERR_CTLR_FI_MASK ERR_CTLR_RFI_MASK
  93. #define ERR_CTLR_RUI_SHIFT 2
  94. #define ERR_CTLR_RUI_MASK 0x1
  95. #define ERR_CTLR_UI_SHIFT ERR_CTLR_RUI_SHIFT
  96. #define ERR_CTLR_UI_MASK ERR_CTLR_RUI_MASK
  97. #define ERR_CTLR_ED_SHIFT 0
  98. #define ERR_CTLR_ED_MASK 0x1
  99. #define ERR_CTLR_CLR_FIELD(_ctlr, _field) \
  100. (_ctlr) &= ~(ERR_CTLR_ ##_field _MASK << ERR_CTLR_ ##_field ##_SHIFT)
  101. #define ERR_CTLR_SET_FIELD(_ctlr, _field, _value) \
  102. (_ctlr) |= (((_value) & ERR_CTLR_ ##_field ##_MASK) << ERR_CTLR_ ##_field ##_SHIFT)
  103. #define ERR_CTLR_ENABLE_FIELD(_ctlr, _field) \
  104. ERR_CTLR_SET_FIELD(_ctlr, _field, ERR_CTLR_ ##_field ##_MASK)
  105. /* Uncorrected error types for Asynchronous exceptions */
  106. #define ERROR_STATUS_UET_UC 0x0 /* Uncontainable */
  107. #define ERROR_STATUS_UET_UEU 0x1 /* Unrecoverable */
  108. #define ERROR_STATUS_UET_UEO 0x2 /* Restable */
  109. #define ERROR_STATUS_UET_UER 0x3 /* Recoverable */
  110. /* Error types for Synchronous exceptions */
  111. #define ERROR_STATUS_SET_UER 0x0 /* Recoverable */
  112. #define ERROR_STATUS_SET_UEO 0x1 /* Restable */
  113. #define ERROR_STATUS_SET_UC 0x2 /* Uncontainable */
  114. #define ERROR_STATUS_SET_CE 0x3 /* Corrected */
  115. /* Number of architecturally-defined primary error codes */
  116. #define ERROR_STATUS_NUM_SERR U(22)
  117. /* Implementation Defined Syndrome bit in ESR */
  118. #define SERROR_IDS_BIT U(24)
  119. /*
  120. * Asynchronous Error Type in exception syndrome. The field has same values in
  121. * both DISR_EL1 and ESR_EL3 for SError.
  122. */
  123. #define EABORT_AET_SHIFT U(10)
  124. #define EABORT_AET_WIDTH U(3)
  125. #define EABORT_AET_MASK U(0x7)
  126. /* DFSC field in Asynchronous exception syndrome */
  127. #define EABORT_DFSC_SHIFT U(0)
  128. #define EABORT_DFSC_WIDTH U(6)
  129. #define EABORT_DFSC_MASK U(0x3f)
  130. /* Synchronous Error Type in exception syndrome. */
  131. #define EABORT_SET_SHIFT U(11)
  132. #define EABORT_SET_WIDTH U(2)
  133. #define EABORT_SET_MASK U(0x3)
  134. /* DFSC code for SErrors */
  135. #define DFSC_SERROR 0x11
  136. /* I/DFSC code for synchronous external abort */
  137. #define SYNC_EA_FSC 0x10
  138. #ifndef __ASSEMBLER__
  139. #include <arch.h>
  140. #include <arch_helpers.h>
  141. #include <assert.h>
  142. #include <context.h>
  143. #include <lib/mmio.h>
  144. #include <stdint.h>
  145. /*
  146. * Standard Error Record accessors for memory-mapped registers.
  147. */
  148. static inline uint64_t ser_get_feature(uintptr_t base, unsigned int idx)
  149. {
  150. return mmio_read_64(base + ERR_FR(idx));
  151. }
  152. static inline uint64_t ser_get_control(uintptr_t base, unsigned int idx)
  153. {
  154. return mmio_read_64(base + ERR_CTLR(idx));
  155. }
  156. static inline uint64_t ser_get_status(uintptr_t base, unsigned int idx)
  157. {
  158. return mmio_read_64(base + ERR_STATUS(idx));
  159. }
  160. /*
  161. * Error handling agent would write to the status register to clear an
  162. * identified/handled error. Most fields in the status register are
  163. * conditional write-one-to-clear.
  164. *
  165. * Typically, to clear the status, it suffices to write back the same value
  166. * previously read. However, if there were new, higher-priority errors recorded
  167. * on the node since status was last read, writing read value won't clear the
  168. * status. Therefore, an error handling agent must wait on and verify the status
  169. * has indeed been cleared.
  170. */
  171. static inline void ser_set_status(uintptr_t base, unsigned int idx,
  172. uint64_t status)
  173. {
  174. mmio_write_64(base + ERR_STATUS(idx), status);
  175. }
  176. static inline uint64_t ser_get_addr(uintptr_t base, unsigned int idx)
  177. {
  178. return mmio_read_64(base + ERR_ADDR(idx));
  179. }
  180. static inline uint64_t ser_get_misc0(uintptr_t base, unsigned int idx)
  181. {
  182. return mmio_read_64(base + ERR_MISC0(idx));
  183. }
  184. static inline uint64_t ser_get_misc1(uintptr_t base, unsigned int idx)
  185. {
  186. return mmio_read_64(base + ERR_MISC1(idx));
  187. }
  188. /*
  189. * Standard Error Record helpers for System registers.
  190. */
  191. static inline void ser_sys_select_record(unsigned int idx)
  192. {
  193. unsigned int max_idx __unused =
  194. (unsigned int) read_erridr_el1() & ERRIDR_MASK;
  195. assert(idx < max_idx);
  196. write_errselr_el1(idx);
  197. isb();
  198. }
  199. /* Library functions to probe Standard Error Record */
  200. int ser_probe_memmap(uintptr_t base, unsigned int size_num_k, int *probe_data);
  201. int ser_probe_sysreg(unsigned int idx_start, unsigned int num_idx, int *probe_data);
  202. #endif /* __ASSEMBLER__ */
  203. #endif /* RAS_ARCH_H */