irqflags.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  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. #ifndef __ASM_AVR32_IRQFLAGS_H
  9. #define __ASM_AVR32_IRQFLAGS_H
  10. #include <asm/sysreg.h>
  11. static inline unsigned long __raw_local_save_flags(void)
  12. {
  13. return sysreg_read(SR);
  14. }
  15. #define raw_local_save_flags(x) \
  16. do { (x) = __raw_local_save_flags(); } while (0)
  17. /*
  18. * This will restore ALL status register flags, not only the interrupt
  19. * mask flag.
  20. *
  21. * The empty asm statement informs the compiler of this fact while
  22. * also serving as a barrier.
  23. */
  24. static inline void raw_local_irq_restore(unsigned long flags)
  25. {
  26. sysreg_write(SR, flags);
  27. asm volatile("" : : : "memory", "cc");
  28. }
  29. static inline void raw_local_irq_disable(void)
  30. {
  31. asm volatile("ssrf %0" : : "n"(SYSREG_GM_OFFSET) : "memory");
  32. }
  33. static inline void raw_local_irq_enable(void)
  34. {
  35. asm volatile("csrf %0" : : "n"(SYSREG_GM_OFFSET) : "memory");
  36. }
  37. static inline int raw_irqs_disabled_flags(unsigned long flags)
  38. {
  39. return (flags & SYSREG_BIT(GM)) != 0;
  40. }
  41. static inline int raw_irqs_disabled(void)
  42. {
  43. unsigned long flags = __raw_local_save_flags();
  44. return raw_irqs_disabled_flags(flags);
  45. }
  46. static inline unsigned long __raw_local_irq_save(void)
  47. {
  48. unsigned long flags = __raw_local_save_flags();
  49. raw_local_irq_disable();
  50. return flags;
  51. }
  52. #define raw_local_irq_save(flags) \
  53. do { (flags) = __raw_local_irq_save(); } while (0)
  54. #endif /* __ASM_AVR32_IRQFLAGS_H */