Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 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 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 11 | #include <linux/types.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 12 | #include <asm/sysreg.h> |
| 13 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 14 | static inline unsigned long arch_local_save_flags(void) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 15 | { |
| 16 | return sysreg_read(SR); |
| 17 | } |
| 18 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 19 | /* |
| 20 | * This will restore ALL status register flags, not only the interrupt |
| 21 | * mask flag. |
| 22 | * |
| 23 | * The empty asm statement informs the compiler of this fact while |
| 24 | * also serving as a barrier. |
| 25 | */ |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 26 | static inline void arch_local_irq_restore(unsigned long flags) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 27 | { |
| 28 | sysreg_write(SR, flags); |
| 29 | asm volatile("" : : : "memory", "cc"); |
| 30 | } |
| 31 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 32 | static inline void arch_local_irq_disable(void) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 33 | { |
| 34 | asm volatile("ssrf %0" : : "n"(SYSREG_GM_OFFSET) : "memory"); |
| 35 | } |
| 36 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 37 | static inline void arch_local_irq_enable(void) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 38 | { |
| 39 | asm volatile("csrf %0" : : "n"(SYSREG_GM_OFFSET) : "memory"); |
| 40 | } |
| 41 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 42 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 43 | { |
| 44 | return (flags & SYSREG_BIT(GM)) != 0; |
| 45 | } |
| 46 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 47 | static inline bool arch_irqs_disabled(void) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 48 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 49 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 50 | } |
| 51 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 52 | static inline unsigned long arch_local_irq_save(void) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 53 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 54 | unsigned long flags = arch_local_save_flags(); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 55 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 56 | arch_local_irq_disable(); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 57 | |
| 58 | return flags; |
| 59 | } |
| 60 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 61 | #endif /* __ASM_AVR32_IRQFLAGS_H */ |