3 @@ -34,3 +34,8 @@ compat-$(CONFIG_COMPAT_KERNEL_2_6_39) +=
8 +ifndef CONFIG_GENERIC_ATOMIC64
9 + compat-y += compat_atomic.o
12 --- a/include/linux/compat-2.6.31.h
13 +++ b/include/linux/compat-2.6.31.h
14 @@ -199,6 +199,20 @@ void compat_synchronize_threaded_irq(str
15 #define list_entry_rcu(ptr, type, member) \
16 container_of(rcu_dereference(ptr), type, member)
24 +extern long long atomic64_read(const atomic64_t *v);
25 +extern long long atomic64_add_return(long long a, atomic64_t *v);
27 +#define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
32 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */
34 #endif /* LINUX_26_31_COMPAT_H */
36 +++ b/compat/compat_atomic.c
38 +#include <linux/spinlock.h>
39 +#include <linux/module.h>
41 +static DEFINE_SPINLOCK(lock);
43 +long long atomic64_read(const atomic64_t *v)
45 + unsigned long flags;
48 + spin_lock_irqsave(&lock, flags);
50 + spin_unlock_irqrestore(&lock, flags);
53 +EXPORT_SYMBOL(atomic64_read);
55 +long long atomic64_add_return(long long a, atomic64_t *v)
57 + unsigned long flags;
60 + spin_lock_irqsave(&lock, flags);
61 + val = v->counter += a;
62 + spin_unlock_irqrestore(&lock, flags);
65 +EXPORT_SYMBOL(atomic64_add_return);
67 --- a/include/linux/compat-3.1.h
68 +++ b/include/linux/compat-3.1.h
71 #define genl_dump_check_consistent(...) do {} while(0)
74 + * In many versions, several architectures do not seem to include an
75 + * atomic64_t implementation, and do not include the software emulation from
76 + * asm-generic/atomic64_t.
77 + * Detect and handle this here.
79 +#include <asm/atomic.h>
81 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)) && !defined(ATOMIC64_INIT)
82 +#include <asm-generic/atomic64.h>
85 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)) */
87 #endif /* LINUX_3_1_COMPAT_H */