irqflags.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2012 Regents of the University of California
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  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. #ifndef _ASM_RISCV_IRQFLAGS_H
  14. #define _ASM_RISCV_IRQFLAGS_H
  15. #include <asm/processor.h>
  16. #include <asm/csr.h>
  17. /* read interrupt enabled status */
  18. static inline unsigned long arch_local_save_flags(void)
  19. {
  20. return csr_read(sstatus);
  21. }
  22. /* unconditionally enable interrupts */
  23. static inline void arch_local_irq_enable(void)
  24. {
  25. csr_set(sstatus, SR_SIE);
  26. }
  27. /* unconditionally disable interrupts */
  28. static inline void arch_local_irq_disable(void)
  29. {
  30. csr_clear(sstatus, SR_SIE);
  31. }
  32. /* get status and disable interrupts */
  33. static inline unsigned long arch_local_irq_save(void)
  34. {
  35. return csr_read_clear(sstatus, SR_SIE);
  36. }
  37. /* test flags */
  38. static inline int arch_irqs_disabled_flags(unsigned long flags)
  39. {
  40. return !(flags & SR_SIE);
  41. }
  42. /* test hardware interrupt enable bit */
  43. static inline int arch_irqs_disabled(void)
  44. {
  45. return arch_irqs_disabled_flags(arch_local_save_flags());
  46. }
  47. /* set interrupt enabled status */
  48. static inline void arch_local_irq_restore(unsigned long flags)
  49. {
  50. csr_set(sstatus, flags & SR_SIE);
  51. }
  52. #endif /* _ASM_RISCV_IRQFLAGS_H */