daifflags.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2017 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_DAIFFLAGS_H
  17. #define __ASM_DAIFFLAGS_H
  18. #include <linux/irqflags.h>
  19. #define DAIF_PROCCTX 0
  20. #define DAIF_PROCCTX_NOIRQ PSR_I_BIT
  21. /* mask/save/unmask/restore all exceptions, including interrupts. */
  22. static inline void local_daif_mask(void)
  23. {
  24. asm volatile(
  25. "msr daifset, #0xf // local_daif_mask\n"
  26. :
  27. :
  28. : "memory");
  29. trace_hardirqs_off();
  30. }
  31. static inline unsigned long local_daif_save(void)
  32. {
  33. unsigned long flags;
  34. asm volatile(
  35. "mrs %0, daif // local_daif_save\n"
  36. : "=r" (flags)
  37. :
  38. : "memory");
  39. local_daif_mask();
  40. return flags;
  41. }
  42. static inline void local_daif_unmask(void)
  43. {
  44. trace_hardirqs_on();
  45. asm volatile(
  46. "msr daifclr, #0xf // local_daif_unmask"
  47. :
  48. :
  49. : "memory");
  50. }
  51. static inline void local_daif_restore(unsigned long flags)
  52. {
  53. if (!arch_irqs_disabled_flags(flags))
  54. trace_hardirqs_on();
  55. asm volatile(
  56. "msr daif, %0 // local_daif_restore"
  57. :
  58. : "r" (flags)
  59. : "memory");
  60. if (arch_irqs_disabled_flags(flags))
  61. trace_hardirqs_off();
  62. }
  63. #endif