Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 1 | #ifndef __ASM_SH_ATOMIC_IRQ_H |
| 2 | #define __ASM_SH_ATOMIC_IRQ_H |
| 3 | |
| 4 | /* |
| 5 | * To get proper branch prediction for the main line, we must branch |
| 6 | * forward to code at the end of this object's .text section, then |
| 7 | * branch back to restart the operation. |
| 8 | */ |
| 9 | static inline void atomic_add(int i, atomic_t *v) |
| 10 | { |
| 11 | unsigned long flags; |
| 12 | |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 13 | raw_local_irq_save(flags); |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 14 | v->counter += i; |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 15 | raw_local_irq_restore(flags); |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | static inline void atomic_sub(int i, atomic_t *v) |
| 19 | { |
| 20 | unsigned long flags; |
| 21 | |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 22 | raw_local_irq_save(flags); |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 23 | v->counter -= i; |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 24 | raw_local_irq_restore(flags); |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | static inline int atomic_add_return(int i, atomic_t *v) |
| 28 | { |
| 29 | unsigned long temp, flags; |
| 30 | |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 31 | raw_local_irq_save(flags); |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 32 | temp = v->counter; |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 33 | temp += i; |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 34 | v->counter = temp; |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 35 | raw_local_irq_restore(flags); |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 36 | |
| 37 | return temp; |
| 38 | } |
| 39 | |
| 40 | static inline int atomic_sub_return(int i, atomic_t *v) |
| 41 | { |
| 42 | unsigned long temp, flags; |
| 43 | |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 44 | raw_local_irq_save(flags); |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 45 | temp = v->counter; |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 46 | temp -= i; |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 47 | v->counter = temp; |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 48 | raw_local_irq_restore(flags); |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 49 | |
| 50 | return temp; |
| 51 | } |
| 52 | |
| 53 | static inline void atomic_clear_mask(unsigned int mask, atomic_t *v) |
| 54 | { |
| 55 | unsigned long flags; |
| 56 | |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 57 | raw_local_irq_save(flags); |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 58 | v->counter &= ~mask; |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 59 | raw_local_irq_restore(flags); |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static inline void atomic_set_mask(unsigned int mask, atomic_t *v) |
| 63 | { |
| 64 | unsigned long flags; |
| 65 | |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 66 | raw_local_irq_save(flags); |
Matt Fleming | 84fdf6c | 2009-01-20 21:14:38 +0000 | [diff] [blame] | 67 | v->counter |= mask; |
Matt Fleming | 0c50f6f | 2009-06-13 22:23:27 +0100 | [diff] [blame] | 68 | raw_local_irq_restore(flags); |
Paul Mundt | ec723fbe | 2006-12-07 20:33:38 +0900 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | #endif /* __ASM_SH_ATOMIC_IRQ_H */ |