pandora: defconfig: update
[pandora-kernel.git] / include / linux / percpu-defs.h
1 #ifndef _LINUX_PERCPU_DEFS_H
2 #define _LINUX_PERCPU_DEFS_H
3
4 /*
5  * Base implementations of per-CPU variable declarations and definitions, where
6  * the section in which the variable is to be placed is provided by the
7  * 'sec' argument.  This may be used to affect the parameters governing the
8  * variable's storage.
9  *
10  * NOTE!  The sections for the DECLARE and for the DEFINE must match, lest
11  * linkage errors occur due the compiler generating the wrong code to access
12  * that section.
13  */
14 #define __PCPU_ATTRS(sec)                                               \
15         __percpu __attribute__((section(PER_CPU_BASE_SECTION sec)))     \
16         PER_CPU_ATTRIBUTES
17
18 #define __PCPU_DUMMY_ATTRS                                              \
19         __attribute__((section(".discard"), unused))
20
21 /*
22  * Macro which verifies @ptr is a percpu pointer without evaluating
23  * @ptr.  This is to be used in percpu accessors to verify that the
24  * input parameter is a percpu pointer.
25  */
26 #define __verify_pcpu_ptr(ptr)  do {                                    \
27         const void __percpu *__vpp_verify = (typeof(ptr))NULL;          \
28         (void)__vpp_verify;                                             \
29 } while (0)
30
31 #ifdef CONFIG_PAGE_TABLE_ISOLATION
32 #define USER_MAPPED_SECTION "..user_mapped"
33 #else
34 #define USER_MAPPED_SECTION ""
35 #endif
36
37 /*
38  * s390 and alpha modules require percpu variables to be defined as
39  * weak to force the compiler to generate GOT based external
40  * references for them.  This is necessary because percpu sections
41  * will be located outside of the usually addressable area.
42  *
43  * This definition puts the following two extra restrictions when
44  * defining percpu variables.
45  *
46  * 1. The symbol must be globally unique, even the static ones.
47  * 2. Static percpu variables cannot be defined inside a function.
48  *
49  * Archs which need weak percpu definitions should define
50  * ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary.
51  *
52  * To ensure that the generic code observes the above two
53  * restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak
54  * definition is used for all cases.
55  */
56 #if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU)
57 /*
58  * __pcpu_scope_* dummy variable is used to enforce scope.  It
59  * receives the static modifier when it's used in front of
60  * DEFINE_PER_CPU() and will trigger build failure if
61  * DECLARE_PER_CPU() is used for the same variable.
62  *
63  * __pcpu_unique_* dummy variable is used to enforce symbol uniqueness
64  * such that hidden weak symbol collision, which will cause unrelated
65  * variables to share the same address, can be detected during build.
66  */
67 #define DECLARE_PER_CPU_SECTION(type, name, sec)                        \
68         extern __PCPU_DUMMY_ATTRS char __pcpu_scope_##name;             \
69         extern __PCPU_ATTRS(sec) __typeof__(type) name
70
71 #define DEFINE_PER_CPU_SECTION(type, name, sec)                         \
72         __PCPU_DUMMY_ATTRS char __pcpu_scope_##name;                    \
73         extern __PCPU_DUMMY_ATTRS char __pcpu_unique_##name;            \
74         __PCPU_DUMMY_ATTRS char __pcpu_unique_##name;                   \
75         __PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES __weak                 \
76         __typeof__(type) name
77 #else
78 /*
79  * Normal declaration and definition macros.
80  */
81 #define DECLARE_PER_CPU_SECTION(type, name, sec)                        \
82         extern __PCPU_ATTRS(sec) __typeof__(type) name
83
84 #define DEFINE_PER_CPU_SECTION(type, name, sec)                         \
85         __PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES                        \
86         __typeof__(type) name
87 #endif
88
89 /*
90  * Variant on the per-CPU variable declaration/definition theme used for
91  * ordinary per-CPU variables.
92  */
93 #define DECLARE_PER_CPU(type, name)                                     \
94         DECLARE_PER_CPU_SECTION(type, name, "")
95
96 #define DEFINE_PER_CPU(type, name)                                      \
97         DEFINE_PER_CPU_SECTION(type, name, "")
98
99 #define DECLARE_PER_CPU_USER_MAPPED(type, name)                         \
100         DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION)
101
102 #define DEFINE_PER_CPU_USER_MAPPED(type, name)                          \
103         DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION)
104
105 /*
106  * Declaration/definition used for per-CPU variables that must come first in
107  * the set of variables.
108  */
109 #define DECLARE_PER_CPU_FIRST(type, name)                               \
110         DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
111
112 #define DEFINE_PER_CPU_FIRST(type, name)                                \
113         DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
114
115 /*
116  * Declaration/definition used for per-CPU variables that must be cacheline
117  * aligned under SMP conditions so that, whilst a particular instance of the
118  * data corresponds to a particular CPU, inefficiencies due to direct access by
119  * other CPUs are reduced by preventing the data from unnecessarily spanning
120  * cachelines.
121  *
122  * An example of this would be statistical data, where each CPU's set of data
123  * is updated by that CPU alone, but the data from across all CPUs is collated
124  * by a CPU processing a read from a proc file.
125  */
126 #define DECLARE_PER_CPU_SHARED_ALIGNED(type, name)                      \
127         DECLARE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
128         ____cacheline_aligned_in_smp
129
130 #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name)                       \
131         DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
132         ____cacheline_aligned_in_smp
133
134 #define DECLARE_PER_CPU_SHARED_ALIGNED_USER_MAPPED(type, name)          \
135         DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION PER_CPU_SHARED_ALIGNED_SECTION) \
136         ____cacheline_aligned_in_smp
137
138 #define DEFINE_PER_CPU_SHARED_ALIGNED_USER_MAPPED(type, name)           \
139         DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION PER_CPU_SHARED_ALIGNED_SECTION) \
140         ____cacheline_aligned_in_smp
141
142 #define DECLARE_PER_CPU_ALIGNED(type, name)                             \
143         DECLARE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION)    \
144         ____cacheline_aligned
145
146 #define DEFINE_PER_CPU_ALIGNED(type, name)                              \
147         DEFINE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION)     \
148         ____cacheline_aligned
149
150 /*
151  * Declaration/definition used for per-CPU variables that must be page aligned.
152  */
153 #define DECLARE_PER_CPU_PAGE_ALIGNED(type, name)                        \
154         DECLARE_PER_CPU_SECTION(type, name, "..page_aligned")           \
155         __aligned(PAGE_SIZE)
156
157 #define DEFINE_PER_CPU_PAGE_ALIGNED(type, name)                         \
158         DEFINE_PER_CPU_SECTION(type, name, "..page_aligned")            \
159         __aligned(PAGE_SIZE)
160 /*
161  * Declaration/definition used for per-CPU variables that must be page aligned and need to be mapped in user mode.
162  */
163 #define DECLARE_PER_CPU_PAGE_ALIGNED_USER_MAPPED(type, name)            \
164         DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION"..page_aligned") \
165         __aligned(PAGE_SIZE)
166
167 #define DEFINE_PER_CPU_PAGE_ALIGNED_USER_MAPPED(type, name)             \
168         DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION"..page_aligned") \
169         __aligned(PAGE_SIZE)
170
171 /*
172  * Declaration/definition used for per-CPU variables that must be read mostly.
173  */
174 #define DECLARE_PER_CPU_READ_MOSTLY(type, name)                         \
175         DECLARE_PER_CPU_SECTION(type, name, "..readmostly")
176
177 #define DEFINE_PER_CPU_READ_MOSTLY(type, name)                          \
178         DEFINE_PER_CPU_SECTION(type, name, "..readmostly")
179
180 /*
181  * Intermodule exports for per-CPU variables.  sparse forgets about
182  * address space across EXPORT_SYMBOL(), change EXPORT_SYMBOL() to
183  * noop if __CHECKER__.
184  */
185 #ifndef __CHECKER__
186 #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(var)
187 #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(var)
188 #else
189 #define EXPORT_PER_CPU_SYMBOL(var)
190 #define EXPORT_PER_CPU_SYMBOL_GPL(var)
191 #endif
192
193 #endif /* _LINUX_PERCPU_DEFS_H */