irqflags.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 2006, 2010
  4. * Author(s): Martin Schwidefsky <[email protected]>
  5. */
  6. #ifndef __ASM_IRQFLAGS_H
  7. #define __ASM_IRQFLAGS_H
  8. #include <linux/types.h>
  9. #define ARCH_IRQ_ENABLED (3UL << (BITS_PER_LONG - 8))
  10. /* store then OR system mask. */
  11. #define __arch_local_irq_stosm(__or) \
  12. ({ \
  13. unsigned long __mask; \
  14. asm volatile( \
  15. " stosm %0,%1" \
  16. : "=Q" (__mask) : "i" (__or) : "memory"); \
  17. __mask; \
  18. })
  19. /* store then AND system mask. */
  20. #define __arch_local_irq_stnsm(__and) \
  21. ({ \
  22. unsigned long __mask; \
  23. asm volatile( \
  24. " stnsm %0,%1" \
  25. : "=Q" (__mask) : "i" (__and) : "memory"); \
  26. __mask; \
  27. })
  28. /* set system mask. */
  29. static __always_inline void __arch_local_irq_ssm(unsigned long flags)
  30. {
  31. asm volatile("ssm %0" : : "Q" (flags) : "memory");
  32. }
  33. static __always_inline unsigned long arch_local_save_flags(void)
  34. {
  35. return __arch_local_irq_stnsm(0xff);
  36. }
  37. static __always_inline unsigned long arch_local_irq_save(void)
  38. {
  39. return __arch_local_irq_stnsm(0xfc);
  40. }
  41. static __always_inline void arch_local_irq_disable(void)
  42. {
  43. arch_local_irq_save();
  44. }
  45. static __always_inline void arch_local_irq_enable(void)
  46. {
  47. __arch_local_irq_stosm(0x03);
  48. }
  49. /* This only restores external and I/O interrupt state */
  50. static __always_inline void arch_local_irq_restore(unsigned long flags)
  51. {
  52. /* only disabled->disabled and disabled->enabled is valid */
  53. if (flags & ARCH_IRQ_ENABLED)
  54. arch_local_irq_enable();
  55. }
  56. static __always_inline bool arch_irqs_disabled_flags(unsigned long flags)
  57. {
  58. return !(flags & ARCH_IRQ_ENABLED);
  59. }
  60. static __always_inline bool arch_irqs_disabled(void)
  61. {
  62. return arch_irqs_disabled_flags(arch_local_save_flags());
  63. }
  64. #endif /* __ASM_IRQFLAGS_H */