irqflags_64.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/asm/irqflags.h
  4. *
  5. * IRQ flags handling
  6. *
  7. * This file gets included from lowlevel asm headers too, to provide
  8. * wrapped versions of the local_irq_*() APIs, based on the
  9. * arch_local_irq_*() functions from the lowlevel headers.
  10. */
  11. #ifndef _ASM_IRQFLAGS_H
  12. #define _ASM_IRQFLAGS_H
  13. #include <asm/pil.h>
  14. #ifndef __ASSEMBLY__
  15. static inline notrace unsigned long arch_local_save_flags(void)
  16. {
  17. unsigned long flags;
  18. __asm__ __volatile__(
  19. "rdpr %%pil, %0"
  20. : "=r" (flags)
  21. );
  22. return flags;
  23. }
  24. static inline notrace void arch_local_irq_restore(unsigned long flags)
  25. {
  26. __asm__ __volatile__(
  27. "wrpr %0, %%pil"
  28. : /* no output */
  29. : "r" (flags)
  30. : "memory"
  31. );
  32. }
  33. static inline notrace void arch_local_irq_disable(void)
  34. {
  35. __asm__ __volatile__(
  36. "wrpr %0, %%pil"
  37. : /* no outputs */
  38. : "i" (PIL_NORMAL_MAX)
  39. : "memory"
  40. );
  41. }
  42. static inline notrace void arch_local_irq_enable(void)
  43. {
  44. __asm__ __volatile__(
  45. "wrpr 0, %%pil"
  46. : /* no outputs */
  47. : /* no inputs */
  48. : "memory"
  49. );
  50. }
  51. static inline notrace int arch_irqs_disabled_flags(unsigned long flags)
  52. {
  53. return (flags > 0);
  54. }
  55. static inline notrace int arch_irqs_disabled(void)
  56. {
  57. return arch_irqs_disabled_flags(arch_local_save_flags());
  58. }
  59. static inline notrace unsigned long arch_local_irq_save(void)
  60. {
  61. unsigned long flags, tmp;
  62. /* Disable interrupts to PIL_NORMAL_MAX unless we already
  63. * are using PIL_NMI, in which case PIL_NMI is retained.
  64. *
  65. * The only values we ever program into the %pil are 0,
  66. * PIL_NORMAL_MAX and PIL_NMI.
  67. *
  68. * Since PIL_NMI is the largest %pil value and all bits are
  69. * set in it (0xf), it doesn't matter what PIL_NORMAL_MAX
  70. * actually is.
  71. */
  72. __asm__ __volatile__(
  73. "rdpr %%pil, %0\n\t"
  74. "or %0, %2, %1\n\t"
  75. "wrpr %1, 0x0, %%pil"
  76. : "=r" (flags), "=r" (tmp)
  77. : "i" (PIL_NORMAL_MAX)
  78. : "memory"
  79. );
  80. return flags;
  81. }
  82. #endif /* (__ASSEMBLY__) */
  83. #endif /* !(_ASM_IRQFLAGS_H) */