blob: 9f7c56609e535b27365cd24777491de4d9a70c67 [file] [log] [blame]
Paul Mundtec723fbe2006-12-07 20:33:38 +09001#ifndef __ASM_SH_ATOMIC_IRQ_H
2#define __ASM_SH_ATOMIC_IRQ_H
3
David Howellse839ca52012-03-28 18:30:03 +01004#include <linux/irqflags.h>
5
Paul Mundtec723fbe2006-12-07 20:33:38 +09006/*
7 * To get proper branch prediction for the main line, we must branch
8 * forward to code at the end of this object's .text section, then
9 * branch back to restart the operation.
10 */
11static inline void atomic_add(int i, atomic_t *v)
12{
13 unsigned long flags;
14
Matt Fleming0c50f6f2009-06-13 22:23:27 +010015 raw_local_irq_save(flags);
Matt Fleming84fdf6c2009-01-20 21:14:38 +000016 v->counter += i;
Matt Fleming0c50f6f2009-06-13 22:23:27 +010017 raw_local_irq_restore(flags);
Paul Mundtec723fbe2006-12-07 20:33:38 +090018}
19
20static inline void atomic_sub(int i, atomic_t *v)
21{
22 unsigned long flags;
23
Matt Fleming0c50f6f2009-06-13 22:23:27 +010024 raw_local_irq_save(flags);
Matt Fleming84fdf6c2009-01-20 21:14:38 +000025 v->counter -= i;
Matt Fleming0c50f6f2009-06-13 22:23:27 +010026 raw_local_irq_restore(flags);
Paul Mundtec723fbe2006-12-07 20:33:38 +090027}
28
29static inline int atomic_add_return(int i, atomic_t *v)
30{
31 unsigned long temp, flags;
32
Matt Fleming0c50f6f2009-06-13 22:23:27 +010033 raw_local_irq_save(flags);
Matt Fleming84fdf6c2009-01-20 21:14:38 +000034 temp = v->counter;
Paul Mundtec723fbe2006-12-07 20:33:38 +090035 temp += i;
Matt Fleming84fdf6c2009-01-20 21:14:38 +000036 v->counter = temp;
Matt Fleming0c50f6f2009-06-13 22:23:27 +010037 raw_local_irq_restore(flags);
Paul Mundtec723fbe2006-12-07 20:33:38 +090038
39 return temp;
40}
41
42static inline int atomic_sub_return(int i, atomic_t *v)
43{
44 unsigned long temp, flags;
45
Matt Fleming0c50f6f2009-06-13 22:23:27 +010046 raw_local_irq_save(flags);
Matt Fleming84fdf6c2009-01-20 21:14:38 +000047 temp = v->counter;
Paul Mundtec723fbe2006-12-07 20:33:38 +090048 temp -= i;
Matt Fleming84fdf6c2009-01-20 21:14:38 +000049 v->counter = temp;
Matt Fleming0c50f6f2009-06-13 22:23:27 +010050 raw_local_irq_restore(flags);
Paul Mundtec723fbe2006-12-07 20:33:38 +090051
52 return temp;
53}
54
55static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
56{
57 unsigned long flags;
58
Matt Fleming0c50f6f2009-06-13 22:23:27 +010059 raw_local_irq_save(flags);
Matt Fleming84fdf6c2009-01-20 21:14:38 +000060 v->counter &= ~mask;
Matt Fleming0c50f6f2009-06-13 22:23:27 +010061 raw_local_irq_restore(flags);
Paul Mundtec723fbe2006-12-07 20:33:38 +090062}
63
64static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
65{
66 unsigned long flags;
67
Matt Fleming0c50f6f2009-06-13 22:23:27 +010068 raw_local_irq_save(flags);
Matt Fleming84fdf6c2009-01-20 21:14:38 +000069 v->counter |= mask;
Matt Fleming0c50f6f2009-06-13 22:23:27 +010070 raw_local_irq_restore(flags);
Paul Mundtec723fbe2006-12-07 20:33:38 +090071}
72
73#endif /* __ASM_SH_ATOMIC_IRQ_H */