traps.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Based on arch/arm/include/asm/traps.h
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __ASM_TRAP_H
  19. #define __ASM_TRAP_H
  20. #include <linux/list.h>
  21. #include <asm/esr.h>
  22. #include <asm/sections.h>
  23. struct pt_regs;
  24. struct undef_hook {
  25. struct list_head node;
  26. u32 instr_mask;
  27. u32 instr_val;
  28. u64 pstate_mask;
  29. u64 pstate_val;
  30. int (*fn)(struct pt_regs *regs, u32 instr);
  31. };
  32. void register_undef_hook(struct undef_hook *hook);
  33. void unregister_undef_hook(struct undef_hook *hook);
  34. void force_signal_inject(int signal, int code, unsigned long address);
  35. void arm64_notify_segfault(unsigned long addr);
  36. void arm64_force_sig_info(struct siginfo *info, const char *str,
  37. struct task_struct *tsk);
  38. /*
  39. * Move regs->pc to next instruction and do necessary setup before it
  40. * is executed.
  41. */
  42. void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size);
  43. static inline int __in_irqentry_text(unsigned long ptr)
  44. {
  45. return ptr >= (unsigned long)&__irqentry_text_start &&
  46. ptr < (unsigned long)&__irqentry_text_end;
  47. }
  48. static inline int in_exception_text(unsigned long ptr)
  49. {
  50. int in;
  51. in = ptr >= (unsigned long)&__exception_text_start &&
  52. ptr < (unsigned long)&__exception_text_end;
  53. return in ? : __in_irqentry_text(ptr);
  54. }
  55. static inline int in_entry_text(unsigned long ptr)
  56. {
  57. return ptr >= (unsigned long)&__entry_text_start &&
  58. ptr < (unsigned long)&__entry_text_end;
  59. }
  60. /*
  61. * CPUs with the RAS extensions have an Implementation-Defined-Syndrome bit
  62. * to indicate whether this ESR has a RAS encoding. CPUs without this feature
  63. * have a ISS-Valid bit in the same position.
  64. * If this bit is set, we know its not a RAS SError.
  65. * If its clear, we need to know if the CPU supports RAS. Uncategorized RAS
  66. * errors share the same encoding as an all-zeros encoding from a CPU that
  67. * doesn't support RAS.
  68. */
  69. static inline bool arm64_is_ras_serror(u32 esr)
  70. {
  71. WARN_ON(preemptible());
  72. if (esr & ESR_ELx_IDS)
  73. return false;
  74. if (this_cpu_has_cap(ARM64_HAS_RAS_EXTN))
  75. return true;
  76. else
  77. return false;
  78. }
  79. /*
  80. * Return the AET bits from a RAS SError's ESR.
  81. *
  82. * It is implementation defined whether Uncategorized errors are containable.
  83. * We treat them as Uncontainable.
  84. * Non-RAS SError's are reported as Uncontained/Uncategorized.
  85. */
  86. static inline u32 arm64_ras_serror_get_severity(u32 esr)
  87. {
  88. u32 aet = esr & ESR_ELx_AET;
  89. if (!arm64_is_ras_serror(esr)) {
  90. /* Not a RAS error, we can't interpret the ESR. */
  91. return ESR_ELx_AET_UC;
  92. }
  93. /*
  94. * AET is RES0 if 'the value returned in the DFSC field is not
  95. * [ESR_ELx_FSC_SERROR]'
  96. */
  97. if ((esr & ESR_ELx_FSC) != ESR_ELx_FSC_SERROR) {
  98. /* No severity information : Uncategorized */
  99. return ESR_ELx_AET_UC;
  100. }
  101. return aet;
  102. }
  103. bool arm64_is_fatal_ras_serror(struct pt_regs *regs, unsigned int esr);
  104. void __noreturn arm64_serror_panic(struct pt_regs *regs, u32 esr);
  105. #endif