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 |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 8 | * arch_local_irq_*() functions from the lowlevel headers. |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 9 | */ |
| 10 | #ifndef _ASM_IRQFLAGS_H |
| 11 | #define _ASM_IRQFLAGS_H |
| 12 | |
David S. Miller | b4f4372 | 2008-11-23 21:55:29 -0800 | [diff] [blame] | 13 | #include <asm/pil.h> |
| 14 | |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 15 | #ifndef __ASSEMBLY__ |
| 16 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 17 | static inline unsigned long arch_local_save_flags(void) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 18 | { |
| 19 | unsigned long flags; |
| 20 | |
| 21 | __asm__ __volatile__( |
| 22 | "rdpr %%pil, %0" |
| 23 | : "=r" (flags) |
| 24 | ); |
| 25 | |
| 26 | return flags; |
| 27 | } |
| 28 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 29 | static inline void arch_local_irq_restore(unsigned long flags) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 30 | { |
| 31 | __asm__ __volatile__( |
| 32 | "wrpr %0, %%pil" |
| 33 | : /* no output */ |
| 34 | : "r" (flags) |
| 35 | : "memory" |
| 36 | ); |
| 37 | } |
| 38 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 39 | static inline void arch_local_irq_disable(void) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 40 | { |
| 41 | __asm__ __volatile__( |
David S. Miller | b4f4372 | 2008-11-23 21:55:29 -0800 | [diff] [blame] | 42 | "wrpr %0, %%pil" |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 43 | : /* no outputs */ |
David S. Miller | b4f4372 | 2008-11-23 21:55:29 -0800 | [diff] [blame] | 44 | : "i" (PIL_NORMAL_MAX) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 45 | : "memory" |
| 46 | ); |
| 47 | } |
| 48 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 49 | static inline void arch_local_irq_enable(void) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 50 | { |
| 51 | __asm__ __volatile__( |
| 52 | "wrpr 0, %%pil" |
| 53 | : /* no outputs */ |
| 54 | : /* no inputs */ |
| 55 | : "memory" |
| 56 | ); |
| 57 | } |
| 58 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 59 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 60 | { |
| 61 | return (flags > 0); |
| 62 | } |
| 63 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 64 | static inline int arch_irqs_disabled(void) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 65 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 66 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 67 | } |
| 68 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 69 | static inline unsigned long arch_local_irq_save(void) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 70 | { |
David S. Miller | 0c25e9e | 2010-04-12 22:21:52 -0700 | [diff] [blame] | 71 | unsigned long flags, tmp; |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 72 | |
David S. Miller | 0c25e9e | 2010-04-12 22:21:52 -0700 | [diff] [blame] | 73 | /* Disable interrupts to PIL_NORMAL_MAX unless we already |
| 74 | * are using PIL_NMI, in which case PIL_NMI is retained. |
David S. Miller | c011f80 | 2010-04-13 01:50:43 -0700 | [diff] [blame] | 75 | * |
| 76 | * The only values we ever program into the %pil are 0, |
| 77 | * PIL_NORMAL_MAX and PIL_NMI. |
| 78 | * |
| 79 | * Since PIL_NMI is the largest %pil value and all bits are |
| 80 | * set in it (0xf), it doesn't matter what PIL_NORMAL_MAX |
| 81 | * actually is. |
David S. Miller | 0c25e9e | 2010-04-12 22:21:52 -0700 | [diff] [blame] | 82 | */ |
| 83 | __asm__ __volatile__( |
| 84 | "rdpr %%pil, %0\n\t" |
| 85 | "or %0, %2, %1\n\t" |
| 86 | "wrpr %1, 0x0, %%pil" |
| 87 | : "=r" (flags), "=r" (tmp) |
| 88 | : "i" (PIL_NORMAL_MAX) |
| 89 | : "memory" |
| 90 | ); |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 91 | |
| 92 | return flags; |
| 93 | } |
| 94 | |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 95 | #endif /* (__ASSEMBLY__) */ |
| 96 | |
| 97 | #endif /* !(_ASM_IRQFLAGS_H) */ |