022-atomic64_backport.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --- a/compat/Makefile
  2. +++ b/compat/Makefile
  3. @@ -38,3 +38,8 @@ compat-$(CONFIG_COMPAT_KERNEL_3_1) += \
  4. cordic.o \
  5. crc8.o
  6. +ifndef CONFIG_64BIT
  7. +ifndef CONFIG_GENERIC_ATOMIC64
  8. + compat-y += compat_atomic.o
  9. +endif
  10. +endif
  11. --- a/include/linux/compat-2.6.31.h
  12. +++ b/include/linux/compat-2.6.31.h
  13. @@ -202,6 +202,20 @@ void compat_synchronize_threaded_irq(str
  14. #define skb_walk_frags(skb, iter) \
  15. for (iter = skb_shinfo(skb)->frag_list; iter; iter = iter->next)
  16. +#ifndef CONFIG_64BIT
  17. +
  18. +typedef struct {
  19. + long long counter;
  20. +} atomic64_t;
  21. +
  22. +extern long long atomic64_read(const atomic64_t *v);
  23. +extern long long atomic64_add_return(long long a, atomic64_t *v);
  24. +
  25. +#define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
  26. +
  27. +#endif
  28. +
  29. +
  30. #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */
  31. #endif /* LINUX_26_31_COMPAT_H */
  32. --- /dev/null
  33. +++ b/compat/compat_atomic.c
  34. @@ -0,0 +1,33 @@
  35. +#include <linux/spinlock.h>
  36. +#include <linux/module.h>
  37. +
  38. +#if !defined(CONFIG_X86) && !((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)) && defined(CONFIG_ARM) && !defined(CONFIG_GENERIC_ATOMIC64))
  39. +
  40. +static DEFINE_SPINLOCK(lock);
  41. +
  42. +long long atomic64_read(const atomic64_t *v)
  43. +{
  44. + unsigned long flags;
  45. + long long val;
  46. +
  47. + spin_lock_irqsave(&lock, flags);
  48. + val = v->counter;
  49. + spin_unlock_irqrestore(&lock, flags);
  50. + return val;
  51. +}
  52. +EXPORT_SYMBOL(atomic64_read);
  53. +
  54. +long long atomic64_add_return(long long a, atomic64_t *v)
  55. +{
  56. + unsigned long flags;
  57. + long long val;
  58. +
  59. + spin_lock_irqsave(&lock, flags);
  60. + val = v->counter += a;
  61. + spin_unlock_irqrestore(&lock, flags);
  62. + return val;
  63. +}
  64. +EXPORT_SYMBOL(atomic64_add_return);
  65. +
  66. +#endif
  67. +
  68. --- a/include/linux/compat-3.1.h
  69. +++ b/include/linux/compat-3.1.h
  70. @@ -19,6 +19,18 @@
  71. .prod_id = { NULL, NULL, (v3), NULL }, \
  72. .prod_id_hash = { 0, 0, (vh3), 0 }, }
  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) && !defined(CONFIG_X86) && !((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)) && defined(CONFIG_ARM) && !defined(CONFIG_GENERIC_ATOMIC64))
  82. +#include <asm-generic/atomic64.h>
  83. +#endif
  84. +
  85. #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)) */
  86. #endif /* LINUX_3_1_COMPAT_H */