27e2edb711978c6d39124438a4a16b9b08135b0c
[openwrt-10.03/.git] / package / mac80211 / patches / 022-atomic64_backport.patch
1 --- a/compat/Makefile
2 +++ b/compat/Makefile
3 @@ -34,3 +34,8 @@ compat-$(CONFIG_COMPAT_KERNEL_2_6_39) +=
4         compat-2.6.39.o \
5         kstrtox.o
6  
7 +ifndef CONFIG_64BIT
8 +ifndef CONFIG_GENERIC_ATOMIC64
9 +  compat-y += compat_atomic.o
10 +endif
11 +endif
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)
17  
18 +#ifndef CONFIG_64BIT
19 +
20 +typedef struct {
21 +       long long counter;
22 +} atomic64_t;
23 +
24 +extern long long atomic64_read(const atomic64_t *v);
25 +extern long long atomic64_add_return(long long a, atomic64_t *v);
26 +
27 +#define atomic64_inc_return(v)          atomic64_add_return(1LL, (v))
28 +
29 +#endif
30 +
31 +
32  #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */
33  
34  #endif /* LINUX_26_31_COMPAT_H */
35 --- /dev/null
36 +++ b/compat/compat_atomic.c
37 @@ -0,0 +1,29 @@
38 +#include <linux/spinlock.h>
39 +#include <linux/module.h>
40 +
41 +static DEFINE_SPINLOCK(lock);
42 +
43 +long long atomic64_read(const atomic64_t *v)
44 +{
45 +    unsigned long flags;
46 +    long long val;
47 +
48 +    spin_lock_irqsave(&lock, flags);
49 +    val = v->counter;
50 +    spin_unlock_irqrestore(&lock, flags);
51 +    return val;
52 +}
53 +EXPORT_SYMBOL(atomic64_read);
54 +
55 +long long atomic64_add_return(long long a, atomic64_t *v)
56 +{
57 +    unsigned long flags;
58 +    long long val;
59 +
60 +    spin_lock_irqsave(&lock, flags);
61 +    val = v->counter += a;
62 +    spin_unlock_irqrestore(&lock, flags);
63 +    return val;
64 +}
65 +EXPORT_SYMBOL(atomic64_add_return);
66 +
67 --- a/include/linux/compat-3.1.h
68 +++ b/include/linux/compat-3.1.h
69 @@ -24,6 +24,18 @@
70  
71  #define genl_dump_check_consistent(...) do {} while(0)
72  
73 +/*
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.
78 + */
79 +#include <asm/atomic.h>
80 +
81 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)) && !defined(ATOMIC64_INIT)
82 +#include <asm-generic/atomic64.h>
83 +#endif
84 +
85  #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)) */
86  
87  #endif /* LINUX_3_1_COMPAT_H */