diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-11-06 16:46:55 -0400 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-11-09 16:35:33 -0500 |
| commit | 1e82ca830c3ad2fd057b4c4fc5243b0622526473 (patch) | |
| tree | facb2c86e48525b28619f3050a635184b6ecbddf /arch/x86 | |
| parent | f8585fe1fc6f0830f900dad7c8ccc40e17f79644 (diff) | |
refactor: remove all architecture-dependent code from include/
Move the architecture-dependent code to the arch/ subtree.
Diffstat (limited to 'arch/x86')
| -rw-r--r-- | arch/x86/include/asm/atomic.h | 136 | ||||
| -rw-r--r-- | arch/x86/include/asm/irq.h | 15 |
2 files changed, 151 insertions, 0 deletions
diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h new file mode 100644 index 0000000..4bd1fe2 --- /dev/null +++ b/arch/x86/include/asm/atomic.h | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | #ifndef ASM_ATOMIC_H | ||
| 2 | #define ASM_ATOMIC_H | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Most of this code comes straight out of the Linux kernel. | ||
| 6 | * | ||
| 7 | * The terms of the GPL v2 apply. | ||
| 8 | */ | ||
| 9 | |||
| 10 | static inline void barrier(void) | ||
| 11 | { | ||
| 12 | __asm__ __volatile__("mfence": : :"memory"); | ||
| 13 | } | ||
| 14 | |||
| 15 | static __inline__ void cpu_relax(void) | ||
| 16 | { | ||
| 17 | __asm__ __volatile("pause"); | ||
| 18 | } | ||
| 19 | |||
| 20 | typedef struct { int counter; } atomic_t; | ||
| 21 | |||
| 22 | #ifdef __i386__ | ||
| 23 | |||
| 24 | #define ATOMIC_INIT(i) { (i) } | ||
| 25 | |||
| 26 | /** | ||
| 27 | * atomic_read - read atomic variable | ||
| 28 | * @v: pointer of type atomic_t | ||
| 29 | * | ||
| 30 | * Atomically reads the value of @v. | ||
| 31 | */ | ||
| 32 | #define atomic_read(v) ((v)->counter) | ||
| 33 | |||
| 34 | /** | ||
| 35 | * atomic_set - set atomic variable | ||
| 36 | * @v: pointer of type atomic_t | ||
| 37 | * @i: required value | ||
| 38 | * | ||
| 39 | * Atomically sets the value of @v to @i. | ||
| 40 | */ | ||
| 41 | #define atomic_set(v,i) (((v)->counter) = (i)) | ||
| 42 | |||
| 43 | static __inline__ void atomic_add(int i, atomic_t *v) | ||
| 44 | { | ||
| 45 | __asm__ __volatile__( | ||
| 46 | "lock; addl %1,%0" | ||
| 47 | :"+m" (v->counter) | ||
| 48 | :"ir" (i)); | ||
| 49 | } | ||
| 50 | |||
| 51 | /** | ||
| 52 | * atomic_add_return - add and return | ||
| 53 | * @v: pointer of type atomic_t | ||
| 54 | * @i: integer value to add | ||
| 55 | * | ||
| 56 | * Atomically adds @i to @v and returns @i + @v | ||
| 57 | */ | ||
| 58 | static __inline__ int atomic_add_return(int i, atomic_t *v) | ||
| 59 | { | ||
| 60 | int __i; | ||
| 61 | __i = i; | ||
| 62 | __asm__ __volatile__( | ||
| 63 | "lock; xaddl %0, %1" | ||
| 64 | :"+r" (i), "+m" (v->counter) | ||
| 65 | : : "memory"); | ||
| 66 | return i + __i; | ||
| 67 | } | ||
| 68 | |||
| 69 | #define atomic_inc_return(v) (atomic_add_return(1,v)) | ||
| 70 | |||
| 71 | #elif defined(__x86_64__) | ||
| 72 | |||
| 73 | /* almost the same as i386, but extra care must be taken when | ||
| 74 | * specifying clobbered registers | ||
| 75 | */ | ||
| 76 | |||
| 77 | #define ATOMIC_INIT(i) { (i) } | ||
| 78 | |||
| 79 | /** | ||
| 80 | * atomic_read - read atomic variable | ||
| 81 | * @v: pointer of type atomic_t | ||
| 82 | * | ||
| 83 | * Atomically reads the value of @v. | ||
| 84 | */ | ||
| 85 | static inline int atomic_read(const atomic_t *v) | ||
| 86 | { | ||
| 87 | return v->counter; | ||
| 88 | } | ||
| 89 | |||
| 90 | /** | ||
| 91 | * atomic_set - set atomic variable | ||
| 92 | * @v: pointer of type atomic_t | ||
| 93 | * @i: required value | ||
| 94 | * | ||
| 95 | * Atomically sets the value of @v to @i. | ||
| 96 | */ | ||
| 97 | static inline void atomic_set(atomic_t *v, int i) | ||
| 98 | { | ||
| 99 | v->counter = i; | ||
| 100 | } | ||
| 101 | |||
| 102 | /** | ||
| 103 | * atomic_add - add integer to atomic variable | ||
| 104 | * @i: integer value to add | ||
| 105 | * @v: pointer of type atomic_t | ||
| 106 | * | ||
| 107 | * Atomically adds @i to @v. | ||
| 108 | */ | ||
| 109 | static inline void atomic_add(int i, atomic_t *v) | ||
| 110 | { | ||
| 111 | asm volatile("lock; addl %1,%0" | ||
| 112 | : "=m" (v->counter) | ||
| 113 | : "ir" (i), "m" (v->counter)); | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * atomic_add_return - add and return | ||
| 118 | * @i: integer value to add | ||
| 119 | * @v: pointer of type atomic_t | ||
| 120 | * | ||
| 121 | * Atomically adds @i to @v and returns @i + @v | ||
| 122 | */ | ||
| 123 | static inline int atomic_add_return(int i, atomic_t *v) | ||
| 124 | { | ||
| 125 | int __i = i; | ||
| 126 | asm volatile("lock; xaddl %0, %1" | ||
| 127 | : "+r" (i), "+m" (v->counter) | ||
| 128 | : : "memory"); | ||
| 129 | return i + __i; | ||
| 130 | } | ||
| 131 | |||
| 132 | #define atomic_inc_return(v) (atomic_add_return(1, v)) | ||
| 133 | |||
| 134 | #endif | ||
| 135 | |||
| 136 | #endif | ||
diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h new file mode 100644 index 0000000..23f47fd --- /dev/null +++ b/arch/x86/include/asm/irq.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #ifndef ASM_IRQ_H | ||
| 2 | #define ASM_IRQ_H | ||
| 3 | |||
| 4 | /* please, use these only if you _really_ know what you're doing | ||
| 5 | * ... and remember iopl(3) first!! (include sys/io.h) | ||
| 6 | */ | ||
| 7 | static inline void cli(void) { | ||
| 8 | asm volatile("cli": : :"memory"); | ||
| 9 | } | ||
| 10 | |||
| 11 | static inline void sti(void) { | ||
| 12 | asm volatile("sti": : :"memory"); | ||
| 13 | } | ||
| 14 | |||
| 15 | #endif | ||
