percpu.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef _ASM_POWERPC_PERCPU_H_
  2. #define _ASM_POWERPC_PERCPU_H_
  3. #ifdef __powerpc64__
  4. #include <linux/compiler.h>
  5. /*
  6. * Same as asm-generic/percpu.h, except that we store the per cpu offset
  7. * in the paca. Based on the x86-64 implementation.
  8. */
  9. #ifdef CONFIG_SMP
  10. #include <asm/paca.h>
  11. #define __per_cpu_offset(cpu) (paca[cpu].data_offset)
  12. #define __my_cpu_offset() get_paca()->data_offset
  13. #define per_cpu_offset(x) (__per_cpu_offset(x))
  14. /* Separate out the type, so (int[3], foo) works. */
  15. #define DEFINE_PER_CPU(type, name) \
  16. __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
  17. #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \
  18. __attribute__((__section__(".data.percpu.shared_aligned"))) \
  19. __typeof__(type) per_cpu__##name \
  20. ____cacheline_aligned_in_smp
  21. /* var is in discarded region: offset to particular copy we want */
  22. #define per_cpu(var, cpu) (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset(cpu)))
  23. #define __get_cpu_var(var) (*RELOC_HIDE(&per_cpu__##var, __my_cpu_offset()))
  24. #define __raw_get_cpu_var(var) (*RELOC_HIDE(&per_cpu__##var, local_paca->data_offset))
  25. /* A macro to avoid #include hell... */
  26. #define percpu_modcopy(pcpudst, src, size) \
  27. do { \
  28. unsigned int __i; \
  29. for_each_possible_cpu(__i) \
  30. memcpy((pcpudst)+__per_cpu_offset(__i), \
  31. (src), (size)); \
  32. } while (0)
  33. extern void setup_per_cpu_areas(void);
  34. #else /* ! SMP */
  35. #define DEFINE_PER_CPU(type, name) \
  36. __typeof__(type) per_cpu__##name
  37. #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \
  38. DEFINE_PER_CPU(type, name)
  39. #define per_cpu(var, cpu) (*((void)(cpu), &per_cpu__##var))
  40. #define __get_cpu_var(var) per_cpu__##var
  41. #define __raw_get_cpu_var(var) per_cpu__##var
  42. #endif /* SMP */
  43. #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name
  44. #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var)
  45. #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var)
  46. #else
  47. #include <asm-generic/percpu.h>
  48. #endif
  49. #endif /* _ASM_POWERPC_PERCPU_H_ */