irqflags.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 Regents of the University of California
  4. */
  5. #ifndef _ASM_RISCV_IRQFLAGS_H
  6. #define _ASM_RISCV_IRQFLAGS_H
  7. #include <asm/processor.h>
  8. #include <asm/csr.h>
  9. /* read interrupt enabled status */
  10. static inline unsigned long arch_local_save_flags(void)
  11. {
  12. return csr_read(CSR_STATUS);
  13. }
  14. /* unconditionally enable interrupts */
  15. static inline void arch_local_irq_enable(void)
  16. {
  17. csr_set(CSR_STATUS, SR_IE);
  18. }
  19. /* unconditionally disable interrupts */
  20. static inline void arch_local_irq_disable(void)
  21. {
  22. csr_clear(CSR_STATUS, SR_IE);
  23. }
  24. /* get status and disable interrupts */
  25. static inline unsigned long arch_local_irq_save(void)
  26. {
  27. return csr_read_clear(CSR_STATUS, SR_IE);
  28. }
  29. /* test flags */
  30. static inline int arch_irqs_disabled_flags(unsigned long flags)
  31. {
  32. return !(flags & SR_IE);
  33. }
  34. /* test hardware interrupt enable bit */
  35. static inline int arch_irqs_disabled(void)
  36. {
  37. return arch_irqs_disabled_flags(arch_local_save_flags());
  38. }
  39. /* set interrupt enabled status */
  40. static inline void arch_local_irq_restore(unsigned long flags)
  41. {
  42. csr_set(CSR_STATUS, flags & SR_IE);
  43. }
  44. #endif /* _ASM_RISCV_IRQFLAGS_H */