Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * include/asm/irqflags.h |
| 3 | * |
| 4 | * IRQ flags handling |
| 5 | * |
| 6 | * This file gets included from lowlevel asm headers too, to provide |
| 7 | * wrapped versions of the local_irq_*() APIs, based on the |
| 8 | * raw_local_irq_*() functions from the lowlevel headers. |
| 9 | */ |
| 10 | #ifndef _ASM_IRQFLAGS_H |
| 11 | #define _ASM_IRQFLAGS_H |
| 12 | |
| 13 | #ifndef __ASSEMBLY__ |
| 14 | |
| 15 | static inline unsigned long __raw_local_save_flags(void) |
| 16 | { |
| 17 | unsigned long flags; |
| 18 | |
| 19 | __asm__ __volatile__( |
| 20 | "rdpr %%pil, %0" |
| 21 | : "=r" (flags) |
| 22 | ); |
| 23 | |
| 24 | return flags; |
| 25 | } |
| 26 | |
| 27 | #define raw_local_save_flags(flags) \ |
| 28 | do { (flags) = __raw_local_save_flags(); } while (0) |
| 29 | |
| 30 | static inline void raw_local_irq_restore(unsigned long flags) |
| 31 | { |
| 32 | __asm__ __volatile__( |
| 33 | "wrpr %0, %%pil" |
| 34 | : /* no output */ |
| 35 | : "r" (flags) |
| 36 | : "memory" |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | static inline void raw_local_irq_disable(void) |
| 41 | { |
| 42 | __asm__ __volatile__( |
| 43 | "wrpr 15, %%pil" |
| 44 | : /* no outputs */ |
| 45 | : /* no inputs */ |
| 46 | : "memory" |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | static inline void raw_local_irq_enable(void) |
| 51 | { |
| 52 | __asm__ __volatile__( |
| 53 | "wrpr 0, %%pil" |
| 54 | : /* no outputs */ |
| 55 | : /* no inputs */ |
| 56 | : "memory" |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | static inline int raw_irqs_disabled_flags(unsigned long flags) |
| 61 | { |
| 62 | return (flags > 0); |
| 63 | } |
| 64 | |
| 65 | static inline int raw_irqs_disabled(void) |
| 66 | { |
| 67 | unsigned long flags = __raw_local_save_flags(); |
| 68 | |
| 69 | return raw_irqs_disabled_flags(flags); |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * For spinlocks, etc: |
| 74 | */ |
| 75 | static inline unsigned long __raw_local_irq_save(void) |
| 76 | { |
| 77 | unsigned long flags = __raw_local_save_flags(); |
| 78 | |
| 79 | raw_local_irq_disable(); |
| 80 | |
| 81 | return flags; |
| 82 | } |
| 83 | |
| 84 | #define raw_local_irq_save(flags) \ |
| 85 | do { (flags) = __raw_local_irq_save(); } while (0) |
| 86 | |
| 87 | #endif /* (__ASSEMBLY__) */ |
| 88 | |
| 89 | #endif /* !(_ASM_IRQFLAGS_H) */ |