Rev 6936 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6936 | Rev 7143 | ||
---|---|---|---|
1 | #ifndef _LINUX_KERNEL_H |
1 | #ifndef _LINUX_KERNEL_H |
2 | #define _LINUX_KERNEL_H |
2 | #define _LINUX_KERNEL_H |
3 | 3 | ||
4 | 4 | ||
5 | #include |
5 | #include |
6 | #include |
6 | #include |
7 | #include |
7 | #include |
8 | #include |
8 | #include |
9 | #include |
9 | #include |
10 | #include |
10 | #include |
11 | #include |
11 | #include |
12 | #include |
12 | #include |
13 | #include |
13 | #include |
14 | #include |
14 | #include |
15 | #include |
15 | #include |
16 | 16 | ||
17 | #define USHRT_MAX ((u16)(~0U)) |
17 | #define USHRT_MAX ((u16)(~0U)) |
18 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
18 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
19 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
19 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
20 | #define INT_MAX ((int)(~0U>>1)) |
20 | #define INT_MAX ((int)(~0U>>1)) |
21 | #define INT_MIN (-INT_MAX - 1) |
21 | #define INT_MIN (-INT_MAX - 1) |
22 | #define UINT_MAX (~0U) |
22 | #define UINT_MAX (~0U) |
23 | #define LONG_MAX ((long)(~0UL>>1)) |
23 | #define LONG_MAX ((long)(~0UL>>1)) |
24 | #define LONG_MIN (-LONG_MAX - 1) |
24 | #define LONG_MIN (-LONG_MAX - 1) |
25 | #define ULONG_MAX (~0UL) |
25 | #define ULONG_MAX (~0UL) |
26 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
26 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
27 | #define LLONG_MIN (-LLONG_MAX - 1) |
27 | #define LLONG_MIN (-LLONG_MAX - 1) |
28 | #define ULLONG_MAX (~0ULL) |
28 | #define ULLONG_MAX (~0ULL) |
29 | #define SIZE_MAX (~(size_t)0) |
29 | #define SIZE_MAX (~(size_t)0) |
30 | 30 | ||
31 | #define U8_MAX ((u8)~0U) |
31 | #define U8_MAX ((u8)~0U) |
32 | #define S8_MAX ((s8)(U8_MAX>>1)) |
32 | #define S8_MAX ((s8)(U8_MAX>>1)) |
33 | #define S8_MIN ((s8)(-S8_MAX - 1)) |
33 | #define S8_MIN ((s8)(-S8_MAX - 1)) |
34 | #define U16_MAX ((u16)~0U) |
34 | #define U16_MAX ((u16)~0U) |
35 | #define S16_MAX ((s16)(U16_MAX>>1)) |
35 | #define S16_MAX ((s16)(U16_MAX>>1)) |
36 | #define S16_MIN ((s16)(-S16_MAX - 1)) |
36 | #define S16_MIN ((s16)(-S16_MAX - 1)) |
37 | #define U32_MAX ((u32)~0U) |
37 | #define U32_MAX ((u32)~0U) |
38 | #define S32_MAX ((s32)(U32_MAX>>1)) |
38 | #define S32_MAX ((s32)(U32_MAX>>1)) |
39 | #define S32_MIN ((s32)(-S32_MAX - 1)) |
39 | #define S32_MIN ((s32)(-S32_MAX - 1)) |
40 | #define U64_MAX ((u64)~0ULL) |
40 | #define U64_MAX ((u64)~0ULL) |
41 | #define S64_MAX ((s64)(U64_MAX>>1)) |
41 | #define S64_MAX ((s64)(U64_MAX>>1)) |
42 | #define S64_MIN ((s64)(-S64_MAX - 1)) |
42 | #define S64_MIN ((s64)(-S64_MAX - 1)) |
43 | 43 | ||
44 | #define STACK_MAGIC 0xdeadbeef |
44 | #define STACK_MAGIC 0xdeadbeef |
45 | 45 | ||
46 | #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) |
46 | #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) |
47 | 47 | ||
48 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) |
48 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) |
49 | #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) |
49 | #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) |
50 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
50 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
51 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
51 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
52 | 52 | ||
53 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
53 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
54 | 54 | ||
55 | /* |
55 | /* |
56 | * This looks more complex than it should be. But we need to |
56 | * This looks more complex than it should be. But we need to |
57 | * get the type for the ~ right in round_down (it needs to be |
57 | * get the type for the ~ right in round_down (it needs to be |
58 | * as wide as the result!), and we want to evaluate the macro |
58 | * as wide as the result!), and we want to evaluate the macro |
59 | * arguments just once each. |
59 | * arguments just once each. |
60 | */ |
60 | */ |
61 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) |
61 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) |
62 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) |
62 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) |
63 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) |
63 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) |
64 | 64 | ||
65 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
65 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
66 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
66 | #define DIV_ROUND_UP __KERNEL_DIV_ROUND_UP |
67 | #define DIV_ROUND_UP_ULL(ll,d) \ |
67 | #define DIV_ROUND_UP_ULL(ll,d) \ |
68 | ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; }) |
68 | ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; }) |
69 | 69 | ||
70 | #if BITS_PER_LONG == 32 |
70 | #if BITS_PER_LONG == 32 |
71 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) |
71 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) |
72 | #else |
72 | #else |
73 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d) |
73 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d) |
74 | #endif |
74 | #endif |
75 | 75 | ||
76 | /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ |
76 | /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ |
77 | #define roundup(x, y) ( \ |
77 | #define roundup(x, y) ( \ |
78 | { \ |
78 | { \ |
79 | const typeof(y) __y = y; \ |
79 | const typeof(y) __y = y; \ |
80 | (((x) + (__y - 1)) / __y) * __y; \ |
80 | (((x) + (__y - 1)) / __y) * __y; \ |
81 | } \ |
81 | } \ |
82 | ) |
82 | ) |
83 | #define rounddown(x, y) ( \ |
83 | #define rounddown(x, y) ( \ |
84 | { \ |
84 | { \ |
85 | typeof(x) __x = (x); \ |
85 | typeof(x) __x = (x); \ |
86 | __x - (__x % (y)); \ |
86 | __x - (__x % (y)); \ |
87 | } \ |
87 | } \ |
88 | ) |
88 | ) |
89 | 89 | ||
90 | /* |
90 | /* |
91 | * Divide positive or negative dividend by positive divisor and round |
91 | * Divide positive or negative dividend by positive divisor and round |
92 | * to closest integer. Result is undefined for negative divisors and |
92 | * to closest integer. Result is undefined for negative divisors and |
93 | * for negative dividends if the divisor variable type is unsigned. |
93 | * for negative dividends if the divisor variable type is unsigned. |
94 | */ |
94 | */ |
95 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
95 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
96 | { \ |
96 | { \ |
97 | typeof(x) __x = x; \ |
97 | typeof(x) __x = x; \ |
98 | typeof(divisor) __d = divisor; \ |
98 | typeof(divisor) __d = divisor; \ |
99 | (((typeof(x))-1) > 0 || \ |
99 | (((typeof(x))-1) > 0 || \ |
100 | ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ |
100 | ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ |
101 | (((__x) + ((__d) / 2)) / (__d)) : \ |
101 | (((__x) + ((__d) / 2)) / (__d)) : \ |
102 | (((__x) - ((__d) / 2)) / (__d)); \ |
102 | (((__x) - ((__d) / 2)) / (__d)); \ |
103 | } \ |
103 | } \ |
104 | ) |
104 | ) |
105 | /* |
105 | /* |
106 | * Same as above but for u64 dividends. divisor must be a 32-bit |
106 | * Same as above but for u64 dividends. divisor must be a 32-bit |
107 | * number. |
107 | * number. |
108 | */ |
108 | */ |
109 | #define DIV_ROUND_CLOSEST_ULL(x, divisor)( \ |
109 | #define DIV_ROUND_CLOSEST_ULL(x, divisor)( \ |
110 | { \ |
110 | { \ |
111 | typeof(divisor) __d = divisor; \ |
111 | typeof(divisor) __d = divisor; \ |
112 | unsigned long long _tmp = (x) + (__d) / 2; \ |
112 | unsigned long long _tmp = (x) + (__d) / 2; \ |
113 | do_div(_tmp, __d); \ |
113 | do_div(_tmp, __d); \ |
114 | _tmp; \ |
114 | _tmp; \ |
115 | } \ |
115 | } \ |
116 | ) |
116 | ) |
117 | 117 | ||
118 | /* |
118 | /* |
119 | * Multiplies an integer by a fraction, while avoiding unnecessary |
119 | * Multiplies an integer by a fraction, while avoiding unnecessary |
120 | * overflow or loss of precision. |
120 | * overflow or loss of precision. |
121 | */ |
121 | */ |
122 | #define mult_frac(x, numer, denom)( \ |
122 | #define mult_frac(x, numer, denom)( \ |
123 | { \ |
123 | { \ |
124 | typeof(x) quot = (x) / (denom); \ |
124 | typeof(x) quot = (x) / (denom); \ |
125 | typeof(x) rem = (x) % (denom); \ |
125 | typeof(x) rem = (x) % (denom); \ |
126 | (quot * (numer)) + ((rem * (numer)) / (denom)); \ |
126 | (quot * (numer)) + ((rem * (numer)) / (denom)); \ |
127 | } \ |
127 | } \ |
128 | ) |
128 | ) |
129 | 129 | ||
130 | 130 | ||
131 | #define _RET_IP_ (unsigned long)__builtin_return_address(0) |
131 | #define _RET_IP_ (unsigned long)__builtin_return_address(0) |
132 | #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) |
132 | #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) |
133 | 133 | ||
134 | #ifdef CONFIG_LBDAF |
134 | #ifdef CONFIG_LBDAF |
135 | # include |
135 | # include |
136 | # define sector_div(a, b) do_div(a, b) |
136 | # define sector_div(a, b) do_div(a, b) |
137 | #else |
137 | #else |
138 | # define sector_div(n, b)( \ |
138 | # define sector_div(n, b)( \ |
139 | { \ |
139 | { \ |
140 | int _res; \ |
140 | int _res; \ |
141 | _res = (n) % (b); \ |
141 | _res = (n) % (b); \ |
142 | (n) /= (b); \ |
142 | (n) /= (b); \ |
143 | _res; \ |
143 | _res; \ |
144 | } \ |
144 | } \ |
145 | ) |
145 | ) |
146 | #endif |
146 | #endif |
147 | 147 | ||
148 | /** |
148 | /** |
149 | * upper_32_bits - return bits 32-63 of a number |
149 | * upper_32_bits - return bits 32-63 of a number |
150 | * @n: the number we're accessing |
150 | * @n: the number we're accessing |
151 | * |
151 | * |
152 | * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress |
152 | * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress |
153 | * the "right shift count >= width of type" warning when that quantity is |
153 | * the "right shift count >= width of type" warning when that quantity is |
154 | * 32-bits. |
154 | * 32-bits. |
155 | */ |
155 | */ |
156 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
156 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
157 | 157 | ||
158 | /** |
158 | /** |
159 | * lower_32_bits - return bits 0-31 of a number |
159 | * lower_32_bits - return bits 0-31 of a number |
160 | * @n: the number we're accessing |
160 | * @n: the number we're accessing |
161 | */ |
161 | */ |
162 | #define lower_32_bits(n) ((u32)(n)) |
162 | #define lower_32_bits(n) ((u32)(n)) |
163 | 163 | ||
164 | struct completion; |
164 | struct completion; |
165 | struct pt_regs; |
165 | struct pt_regs; |
166 | struct user; |
166 | struct user; |
167 | 167 | ||
168 | #ifdef CONFIG_PREEMPT_VOLUNTARY |
168 | #ifdef CONFIG_PREEMPT_VOLUNTARY |
169 | extern int _cond_resched(void); |
169 | extern int _cond_resched(void); |
170 | # define might_resched() _cond_resched() |
170 | # define might_resched() _cond_resched() |
171 | #else |
171 | #else |
172 | # define might_resched() do { } while (0) |
172 | # define might_resched() do { } while (0) |
173 | #endif |
173 | #endif |
174 | 174 | ||
175 | #ifdef CONFIG_DEBUG_ATOMIC_SLEEP |
175 | #ifdef CONFIG_DEBUG_ATOMIC_SLEEP |
176 | void ___might_sleep(const char *file, int line, int preempt_offset); |
176 | void ___might_sleep(const char *file, int line, int preempt_offset); |
177 | void __might_sleep(const char *file, int line, int preempt_offset); |
177 | void __might_sleep(const char *file, int line, int preempt_offset); |
178 | /** |
178 | /** |
179 | * might_sleep - annotation for functions that can sleep |
179 | * might_sleep - annotation for functions that can sleep |
180 | * |
180 | * |
181 | * this macro will print a stack trace if it is executed in an atomic |
181 | * this macro will print a stack trace if it is executed in an atomic |
182 | * context (spinlock, irq-handler, ...). |
182 | * context (spinlock, irq-handler, ...). |
183 | * |
183 | * |
184 | * This is a useful debugging help to be able to catch problems early and not |
184 | * This is a useful debugging help to be able to catch problems early and not |
185 | * be bitten later when the calling function happens to sleep when it is not |
185 | * be bitten later when the calling function happens to sleep when it is not |
186 | * supposed to. |
186 | * supposed to. |
187 | */ |
187 | */ |
188 | # define might_sleep() \ |
188 | # define might_sleep() \ |
189 | do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) |
189 | do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) |
190 | # define sched_annotate_sleep() (current->task_state_change = 0) |
190 | # define sched_annotate_sleep() (current->task_state_change = 0) |
191 | #else |
191 | #else |
192 | static inline void ___might_sleep(const char *file, int line, |
192 | static inline void ___might_sleep(const char *file, int line, |
193 | int preempt_offset) { } |
193 | int preempt_offset) { } |
194 | static inline void __might_sleep(const char *file, int line, |
194 | static inline void __might_sleep(const char *file, int line, |
195 | int preempt_offset) { } |
195 | int preempt_offset) { } |
196 | # define might_sleep() do { might_resched(); } while (0) |
196 | # define might_sleep() do { might_resched(); } while (0) |
197 | # define sched_annotate_sleep() do { } while (0) |
197 | # define sched_annotate_sleep() do { } while (0) |
198 | #endif |
198 | #endif |
199 | 199 | ||
200 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) |
200 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) |
201 | 201 | ||
202 | /** |
202 | /** |
203 | * abs - return absolute value of an argument |
203 | * abs - return absolute value of an argument |
204 | * @x: the value. If it is unsigned type, it is converted to signed type first. |
204 | * @x: the value. If it is unsigned type, it is converted to signed type first. |
205 | * char is treated as if it was signed (regardless of whether it really is) |
205 | * char is treated as if it was signed (regardless of whether it really is) |
206 | * but the macro's return type is preserved as char. |
206 | * but the macro's return type is preserved as char. |
207 | * |
207 | * |
208 | * Return: an absolute value of x. |
208 | * Return: an absolute value of x. |
209 | */ |
209 | */ |
210 | #define abs(x) __abs_choose_expr(x, long long, \ |
210 | #define abs(x) __abs_choose_expr(x, long long, \ |
211 | __abs_choose_expr(x, long, \ |
211 | __abs_choose_expr(x, long, \ |
212 | __abs_choose_expr(x, int, \ |
212 | __abs_choose_expr(x, int, \ |
213 | __abs_choose_expr(x, short, \ |
213 | __abs_choose_expr(x, short, \ |
214 | __abs_choose_expr(x, char, \ |
214 | __abs_choose_expr(x, char, \ |
215 | __builtin_choose_expr( \ |
215 | __builtin_choose_expr( \ |
216 | __builtin_types_compatible_p(typeof(x), char), \ |
216 | __builtin_types_compatible_p(typeof(x), char), \ |
217 | (char)({ signed char __x = (x); __x<0?-__x:__x; }), \ |
217 | (char)({ signed char __x = (x); __x<0?-__x:__x; }), \ |
218 | ((void)0))))))) |
218 | ((void)0))))))) |
219 | 219 | ||
220 | #define __abs_choose_expr(x, type, other) __builtin_choose_expr( \ |
220 | #define __abs_choose_expr(x, type, other) __builtin_choose_expr( \ |
221 | __builtin_types_compatible_p(typeof(x), signed type) || \ |
221 | __builtin_types_compatible_p(typeof(x), signed type) || \ |
222 | __builtin_types_compatible_p(typeof(x), unsigned type), \ |
222 | __builtin_types_compatible_p(typeof(x), unsigned type), \ |
223 | ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other) |
223 | ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other) |
224 | 224 | ||
225 | /** |
225 | /** |
226 | * reciprocal_scale - "scale" a value into range [0, ep_ro) |
226 | * reciprocal_scale - "scale" a value into range [0, ep_ro) |
227 | * @val: value |
227 | * @val: value |
228 | * @ep_ro: right open interval endpoint |
228 | * @ep_ro: right open interval endpoint |
229 | * |
229 | * |
230 | * Perform a "reciprocal multiplication" in order to "scale" a value into |
230 | * Perform a "reciprocal multiplication" in order to "scale" a value into |
231 | * range [0, ep_ro), where the upper interval endpoint is right-open. |
231 | * range [0, ep_ro), where the upper interval endpoint is right-open. |
232 | * This is useful, e.g. for accessing a index of an array containing |
232 | * This is useful, e.g. for accessing a index of an array containing |
233 | * ep_ro elements, for example. Think of it as sort of modulus, only that |
233 | * ep_ro elements, for example. Think of it as sort of modulus, only that |
234 | * the result isn't that of modulo. ;) Note that if initial input is a |
234 | * the result isn't that of modulo. ;) Note that if initial input is a |
235 | * small value, then result will return 0. |
235 | * small value, then result will return 0. |
236 | * |
236 | * |
237 | * Return: a result based on val in interval [0, ep_ro). |
237 | * Return: a result based on val in interval [0, ep_ro). |
238 | */ |
238 | */ |
239 | static inline u32 reciprocal_scale(u32 val, u32 ep_ro) |
239 | static inline u32 reciprocal_scale(u32 val, u32 ep_ro) |
240 | { |
240 | { |
241 | return (u32)(((u64) val * ep_ro) >> 32); |
241 | return (u32)(((u64) val * ep_ro) >> 32); |
242 | } |
242 | } |
243 | 243 | ||
244 | #if defined(CONFIG_MMU) && \ |
244 | #if defined(CONFIG_MMU) && \ |
245 | (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)) |
245 | (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)) |
246 | #define might_fault() __might_fault(__FILE__, __LINE__) |
246 | #define might_fault() __might_fault(__FILE__, __LINE__) |
247 | void __might_fault(const char *file, int line); |
247 | void __might_fault(const char *file, int line); |
248 | #else |
248 | #else |
249 | static inline void might_fault(void) { } |
249 | static inline void might_fault(void) { } |
250 | #endif |
250 | #endif |
251 | 251 | ||
252 | #define KERN_EMERG "<0>" /* system is unusable */ |
252 | #define KERN_EMERG "<0>" /* system is unusable */ |
253 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
253 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
254 | #define KERN_CRIT "<2>" /* critical conditions */ |
254 | #define KERN_CRIT "<2>" /* critical conditions */ |
255 | #define KERN_ERR "<3>" /* error conditions */ |
255 | #define KERN_ERR "<3>" /* error conditions */ |
256 | #define KERN_WARNING "<4>" /* warning conditions */ |
256 | #define KERN_WARNING "<4>" /* warning conditions */ |
257 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
257 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
258 | #define KERN_INFO "<6>" /* informational */ |
258 | #define KERN_INFO "<6>" /* informational */ |
259 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
259 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
260 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
260 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
261 | extern long simple_strtol(const char *,char **,unsigned int); |
261 | extern long simple_strtol(const char *,char **,unsigned int); |
262 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
262 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
263 | extern long long simple_strtoll(const char *,char **,unsigned int); |
263 | extern long long simple_strtoll(const char *,char **,unsigned int); |
264 | 264 | ||
265 | extern int num_to_str(char *buf, int size, unsigned long long num); |
265 | extern int num_to_str(char *buf, int size, unsigned long long num); |
266 | 266 | ||
267 | /* lib/printf utilities */ |
267 | /* lib/printf utilities */ |
268 | 268 | ||
269 | extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...); |
269 | extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...); |
270 | extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list); |
270 | extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list); |
271 | extern __printf(3, 4) |
271 | extern __printf(3, 4) |
272 | int snprintf(char *buf, size_t size, const char *fmt, ...); |
272 | int snprintf(char *buf, size_t size, const char *fmt, ...); |
273 | extern __printf(3, 0) |
273 | extern __printf(3, 0) |
274 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); |
274 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); |
275 | extern __printf(3, 4) |
275 | extern __printf(3, 4) |
276 | int scnprintf(char *buf, size_t size, const char *fmt, ...); |
276 | int scnprintf(char *buf, size_t size, const char *fmt, ...); |
277 | extern __printf(3, 0) |
277 | extern __printf(3, 0) |
278 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); |
278 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); |
279 | extern __printf(2, 3) |
279 | extern __printf(2, 3) |
280 | char *kasprintf(gfp_t gfp, const char *fmt, ...); |
280 | char *kasprintf(gfp_t gfp, const char *fmt, ...); |
281 | extern __printf(2, 0) |
281 | extern __printf(2, 0) |
282 | char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); |
282 | char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); |
283 | extern __printf(2, 0) |
283 | extern __printf(2, 0) |
284 | const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); |
284 | const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); |
285 | 285 | ||
286 | extern __scanf(2, 3) |
286 | extern __scanf(2, 3) |
287 | int sscanf(const char *, const char *, ...); |
287 | int sscanf(const char *, const char *, ...); |
288 | extern __scanf(2, 0) |
288 | extern __scanf(2, 0) |
289 | int vsscanf(const char *, const char *, va_list); |
289 | int vsscanf(const char *, const char *, va_list); |
290 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
290 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
291 | enum lockdep_ok { |
291 | enum lockdep_ok { |
292 | LOCKDEP_STILL_OK, |
292 | LOCKDEP_STILL_OK, |
293 | LOCKDEP_NOW_UNRELIABLE |
293 | LOCKDEP_NOW_UNRELIABLE |
294 | }; |
294 | }; |
295 | extern void add_taint(unsigned flag, enum lockdep_ok); |
295 | extern void add_taint(unsigned flag, enum lockdep_ok); |
296 | extern int test_taint(unsigned flag); |
296 | extern int test_taint(unsigned flag); |
297 | extern unsigned long get_taint(void); |
297 | extern unsigned long get_taint(void); |
298 | extern int root_mountflags; |
298 | extern int root_mountflags; |
299 | 299 | ||
300 | extern bool early_boot_irqs_disabled; |
300 | extern bool early_boot_irqs_disabled; |
301 | 301 | ||
302 | /* Values used for system_state */ |
302 | /* Values used for system_state */ |
303 | extern enum system_states { |
303 | extern enum system_states { |
304 | SYSTEM_BOOTING, |
304 | SYSTEM_BOOTING, |
305 | SYSTEM_RUNNING, |
305 | SYSTEM_RUNNING, |
306 | SYSTEM_HALT, |
306 | SYSTEM_HALT, |
307 | SYSTEM_POWER_OFF, |
307 | SYSTEM_POWER_OFF, |
308 | SYSTEM_RESTART, |
308 | SYSTEM_RESTART, |
309 | } system_state; |
309 | } system_state; |
310 | 310 | ||
311 | #define TAINT_PROPRIETARY_MODULE 0 |
311 | #define TAINT_PROPRIETARY_MODULE 0 |
312 | #define TAINT_FORCED_MODULE 1 |
312 | #define TAINT_FORCED_MODULE 1 |
313 | #define TAINT_CPU_OUT_OF_SPEC 2 |
313 | #define TAINT_CPU_OUT_OF_SPEC 2 |
314 | #define TAINT_FORCED_RMMOD 3 |
314 | #define TAINT_FORCED_RMMOD 3 |
315 | #define TAINT_MACHINE_CHECK 4 |
315 | #define TAINT_MACHINE_CHECK 4 |
316 | #define TAINT_BAD_PAGE 5 |
316 | #define TAINT_BAD_PAGE 5 |
317 | #define TAINT_USER 6 |
317 | #define TAINT_USER 6 |
318 | #define TAINT_DIE 7 |
318 | #define TAINT_DIE 7 |
319 | #define TAINT_OVERRIDDEN_ACPI_TABLE 8 |
319 | #define TAINT_OVERRIDDEN_ACPI_TABLE 8 |
320 | #define TAINT_WARN 9 |
320 | #define TAINT_WARN 9 |
321 | #define TAINT_CRAP 10 |
321 | #define TAINT_CRAP 10 |
322 | #define TAINT_FIRMWARE_WORKAROUND 11 |
322 | #define TAINT_FIRMWARE_WORKAROUND 11 |
323 | #define TAINT_OOT_MODULE 12 |
323 | #define TAINT_OOT_MODULE 12 |
324 | #define TAINT_UNSIGNED_MODULE 13 |
324 | #define TAINT_UNSIGNED_MODULE 13 |
325 | #define TAINT_SOFTLOCKUP 14 |
325 | #define TAINT_SOFTLOCKUP 14 |
326 | #define TAINT_LIVEPATCH 15 |
326 | #define TAINT_LIVEPATCH 15 |
327 | 327 | ||
328 | extern const char hex_asc[]; |
328 | extern const char hex_asc[]; |
329 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
329 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
330 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
330 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
331 | 331 | ||
332 | static inline char *hex_byte_pack(char *buf, u8 byte) |
332 | static inline char *hex_byte_pack(char *buf, u8 byte) |
333 | { |
333 | { |
334 | *buf++ = hex_asc_hi(byte); |
334 | *buf++ = hex_asc_hi(byte); |
335 | *buf++ = hex_asc_lo(byte); |
335 | *buf++ = hex_asc_lo(byte); |
336 | return buf; |
336 | return buf; |
337 | } |
337 | } |
338 | 338 | ||
339 | extern const char hex_asc_upper[]; |
339 | extern const char hex_asc_upper[]; |
340 | #define hex_asc_upper_lo(x) hex_asc_upper[((x) & 0x0f)] |
340 | #define hex_asc_upper_lo(x) hex_asc_upper[((x) & 0x0f)] |
341 | #define hex_asc_upper_hi(x) hex_asc_upper[((x) & 0xf0) >> 4] |
341 | #define hex_asc_upper_hi(x) hex_asc_upper[((x) & 0xf0) >> 4] |
342 | 342 | ||
343 | static inline char *hex_byte_pack_upper(char *buf, u8 byte) |
343 | static inline char *hex_byte_pack_upper(char *buf, u8 byte) |
344 | { |
344 | { |
345 | *buf++ = hex_asc_upper_hi(byte); |
345 | *buf++ = hex_asc_upper_hi(byte); |
346 | *buf++ = hex_asc_upper_lo(byte); |
346 | *buf++ = hex_asc_upper_lo(byte); |
347 | return buf; |
347 | return buf; |
348 | } |
348 | } |
349 | 349 | ||
350 | extern int hex_to_bin(char ch); |
350 | extern int hex_to_bin(char ch); |
351 | extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); |
351 | extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); |
352 | extern char *bin2hex(char *dst, const void *src, size_t count); |
352 | extern char *bin2hex(char *dst, const void *src, size_t count); |
353 | 353 | ||
354 | bool mac_pton(const char *s, u8 *mac); |
354 | bool mac_pton(const char *s, u8 *mac); |
355 | 355 | ||
356 | /* |
356 | /* |
357 | * General tracing related utility functions - trace_printk(), |
357 | * General tracing related utility functions - trace_printk(), |
358 | * tracing_on/tracing_off and tracing_start()/tracing_stop |
358 | * tracing_on/tracing_off and tracing_start()/tracing_stop |
359 | * |
359 | * |
360 | * Use tracing_on/tracing_off when you want to quickly turn on or off |
360 | * Use tracing_on/tracing_off when you want to quickly turn on or off |
361 | * tracing. It simply enables or disables the recording of the trace events. |
361 | * tracing. It simply enables or disables the recording of the trace events. |
362 | * This also corresponds to the user space /sys/kernel/debug/tracing/tracing_on |
362 | * This also corresponds to the user space /sys/kernel/debug/tracing/tracing_on |
363 | * file, which gives a means for the kernel and userspace to interact. |
363 | * file, which gives a means for the kernel and userspace to interact. |
364 | * Place a tracing_off() in the kernel where you want tracing to end. |
364 | * Place a tracing_off() in the kernel where you want tracing to end. |
365 | * From user space, examine the trace, and then echo 1 > tracing_on |
365 | * From user space, examine the trace, and then echo 1 > tracing_on |
366 | * to continue tracing. |
366 | * to continue tracing. |
367 | * |
367 | * |
368 | * tracing_stop/tracing_start has slightly more overhead. It is used |
368 | * tracing_stop/tracing_start has slightly more overhead. It is used |
369 | * by things like suspend to ram where disabling the recording of the |
369 | * by things like suspend to ram where disabling the recording of the |
370 | * trace is not enough, but tracing must actually stop because things |
370 | * trace is not enough, but tracing must actually stop because things |
371 | * like calling smp_processor_id() may crash the system. |
371 | * like calling smp_processor_id() may crash the system. |
372 | * |
372 | * |
373 | * Most likely, you want to use tracing_on/tracing_off. |
373 | * Most likely, you want to use tracing_on/tracing_off. |
374 | */ |
374 | */ |
375 | 375 | ||
376 | enum ftrace_dump_mode { |
376 | enum ftrace_dump_mode { |
377 | DUMP_NONE, |
377 | DUMP_NONE, |
378 | DUMP_ALL, |
378 | DUMP_ALL, |
379 | DUMP_ORIG, |
379 | DUMP_ORIG, |
380 | }; |
380 | }; |
381 | 381 | ||
382 | #ifdef CONFIG_TRACING |
382 | #ifdef CONFIG_TRACING |
383 | void tracing_on(void); |
383 | void tracing_on(void); |
384 | void tracing_off(void); |
384 | void tracing_off(void); |
385 | int tracing_is_on(void); |
385 | int tracing_is_on(void); |
386 | void tracing_snapshot(void); |
386 | void tracing_snapshot(void); |
387 | void tracing_snapshot_alloc(void); |
387 | void tracing_snapshot_alloc(void); |
388 | 388 | ||
389 | extern void tracing_start(void); |
389 | extern void tracing_start(void); |
390 | extern void tracing_stop(void); |
390 | extern void tracing_stop(void); |
391 | 391 | ||
392 | static inline __printf(1, 2) |
392 | static inline __printf(1, 2) |
393 | void ____trace_printk_check_format(const char *fmt, ...) |
393 | void ____trace_printk_check_format(const char *fmt, ...) |
394 | { |
394 | { |
395 | } |
395 | } |
396 | #define __trace_printk_check_format(fmt, args...) \ |
396 | #define __trace_printk_check_format(fmt, args...) \ |
397 | do { \ |
397 | do { \ |
398 | if (0) \ |
398 | if (0) \ |
399 | ____trace_printk_check_format(fmt, ##args); \ |
399 | ____trace_printk_check_format(fmt, ##args); \ |
400 | } while (0) |
400 | } while (0) |
401 | 401 | ||
402 | /** |
402 | /** |
403 | * trace_printk - printf formatting in the ftrace buffer |
403 | * trace_printk - printf formatting in the ftrace buffer |
404 | * @fmt: the printf format for printing |
404 | * @fmt: the printf format for printing |
405 | * |
405 | * |
406 | * Note: __trace_printk is an internal function for trace_printk and |
406 | * Note: __trace_printk is an internal function for trace_printk and |
407 | * the @ip is passed in via the trace_printk macro. |
407 | * the @ip is passed in via the trace_printk macro. |
408 | * |
408 | * |
409 | * This function allows a kernel developer to debug fast path sections |
409 | * This function allows a kernel developer to debug fast path sections |
410 | * that printk is not appropriate for. By scattering in various |
410 | * that printk is not appropriate for. By scattering in various |
411 | * printk like tracing in the code, a developer can quickly see |
411 | * printk like tracing in the code, a developer can quickly see |
412 | * where problems are occurring. |
412 | * where problems are occurring. |
413 | * |
413 | * |
414 | * This is intended as a debugging tool for the developer only. |
414 | * This is intended as a debugging tool for the developer only. |
415 | * Please refrain from leaving trace_printks scattered around in |
415 | * Please refrain from leaving trace_printks scattered around in |
416 | * your code. (Extra memory is used for special buffers that are |
416 | * your code. (Extra memory is used for special buffers that are |
417 | * allocated when trace_printk() is used) |
417 | * allocated when trace_printk() is used) |
418 | * |
418 | * |
419 | * A little optization trick is done here. If there's only one |
419 | * A little optization trick is done here. If there's only one |
420 | * argument, there's no need to scan the string for printf formats. |
420 | * argument, there's no need to scan the string for printf formats. |
421 | * The trace_puts() will suffice. But how can we take advantage of |
421 | * The trace_puts() will suffice. But how can we take advantage of |
422 | * using trace_puts() when trace_printk() has only one argument? |
422 | * using trace_puts() when trace_printk() has only one argument? |
423 | * By stringifying the args and checking the size we can tell |
423 | * By stringifying the args and checking the size we can tell |
424 | * whether or not there are args. __stringify((__VA_ARGS__)) will |
424 | * whether or not there are args. __stringify((__VA_ARGS__)) will |
425 | * turn into "()\0" with a size of 3 when there are no args, anything |
425 | * turn into "()\0" with a size of 3 when there are no args, anything |
426 | * else will be bigger. All we need to do is define a string to this, |
426 | * else will be bigger. All we need to do is define a string to this, |
427 | * and then take its size and compare to 3. If it's bigger, use |
427 | * and then take its size and compare to 3. If it's bigger, use |
428 | * do_trace_printk() otherwise, optimize it to trace_puts(). Then just |
428 | * do_trace_printk() otherwise, optimize it to trace_puts(). Then just |
429 | * let gcc optimize the rest. |
429 | * let gcc optimize the rest. |
430 | */ |
430 | */ |
431 | 431 | ||
432 | #define trace_printk(fmt, ...) \ |
432 | #define trace_printk(fmt, ...) \ |
433 | do { \ |
433 | do { \ |
434 | char _______STR[] = __stringify((__VA_ARGS__)); \ |
434 | char _______STR[] = __stringify((__VA_ARGS__)); \ |
435 | if (sizeof(_______STR) > 3) \ |
435 | if (sizeof(_______STR) > 3) \ |
436 | do_trace_printk(fmt, ##__VA_ARGS__); \ |
436 | do_trace_printk(fmt, ##__VA_ARGS__); \ |
437 | else \ |
437 | else \ |
438 | trace_puts(fmt); \ |
438 | trace_puts(fmt); \ |
439 | } while (0) |
439 | } while (0) |
440 | 440 | ||
441 | #define do_trace_printk(fmt, args...) \ |
441 | #define do_trace_printk(fmt, args...) \ |
442 | do { \ |
442 | do { \ |
443 | static const char *trace_printk_fmt __used \ |
443 | static const char *trace_printk_fmt __used \ |
444 | __attribute__((section("__trace_printk_fmt"))) = \ |
444 | __attribute__((section("__trace_printk_fmt"))) = \ |
445 | __builtin_constant_p(fmt) ? fmt : NULL; \ |
445 | __builtin_constant_p(fmt) ? fmt : NULL; \ |
446 | \ |
446 | \ |
447 | __trace_printk_check_format(fmt, ##args); \ |
447 | __trace_printk_check_format(fmt, ##args); \ |
448 | \ |
448 | \ |
449 | if (__builtin_constant_p(fmt)) \ |
449 | if (__builtin_constant_p(fmt)) \ |
450 | __trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \ |
450 | __trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \ |
451 | else \ |
451 | else \ |
452 | __trace_printk(_THIS_IP_, fmt, ##args); \ |
452 | __trace_printk(_THIS_IP_, fmt, ##args); \ |
453 | } while (0) |
453 | } while (0) |
454 | 454 | ||
455 | extern __printf(2, 3) |
455 | extern __printf(2, 3) |
456 | int __trace_bprintk(unsigned long ip, const char *fmt, ...); |
456 | int __trace_bprintk(unsigned long ip, const char *fmt, ...); |
457 | 457 | ||
458 | extern __printf(2, 3) |
458 | extern __printf(2, 3) |
459 | int __trace_printk(unsigned long ip, const char *fmt, ...); |
459 | int __trace_printk(unsigned long ip, const char *fmt, ...); |
460 | 460 | ||
461 | /** |
461 | /** |
462 | * trace_puts - write a string into the ftrace buffer |
462 | * trace_puts - write a string into the ftrace buffer |
463 | * @str: the string to record |
463 | * @str: the string to record |
464 | * |
464 | * |
465 | * Note: __trace_bputs is an internal function for trace_puts and |
465 | * Note: __trace_bputs is an internal function for trace_puts and |
466 | * the @ip is passed in via the trace_puts macro. |
466 | * the @ip is passed in via the trace_puts macro. |
467 | * |
467 | * |
468 | * This is similar to trace_printk() but is made for those really fast |
468 | * This is similar to trace_printk() but is made for those really fast |
469 | * paths that a developer wants the least amount of "Heisenbug" affects, |
469 | * paths that a developer wants the least amount of "Heisenbug" affects, |
470 | * where the processing of the print format is still too much. |
470 | * where the processing of the print format is still too much. |
471 | * |
471 | * |
472 | * This function allows a kernel developer to debug fast path sections |
472 | * This function allows a kernel developer to debug fast path sections |
473 | * that printk is not appropriate for. By scattering in various |
473 | * that printk is not appropriate for. By scattering in various |
474 | * printk like tracing in the code, a developer can quickly see |
474 | * printk like tracing in the code, a developer can quickly see |
475 | * where problems are occurring. |
475 | * where problems are occurring. |
476 | * |
476 | * |
477 | * This is intended as a debugging tool for the developer only. |
477 | * This is intended as a debugging tool for the developer only. |
478 | * Please refrain from leaving trace_puts scattered around in |
478 | * Please refrain from leaving trace_puts scattered around in |
479 | * your code. (Extra memory is used for special buffers that are |
479 | * your code. (Extra memory is used for special buffers that are |
480 | * allocated when trace_puts() is used) |
480 | * allocated when trace_puts() is used) |
481 | * |
481 | * |
482 | * Returns: 0 if nothing was written, positive # if string was. |
482 | * Returns: 0 if nothing was written, positive # if string was. |
483 | * (1 when __trace_bputs is used, strlen(str) when __trace_puts is used) |
483 | * (1 when __trace_bputs is used, strlen(str) when __trace_puts is used) |
484 | */ |
484 | */ |
485 | 485 | ||
486 | #define trace_puts(str) ({ \ |
486 | #define trace_puts(str) ({ \ |
487 | static const char *trace_printk_fmt __used \ |
487 | static const char *trace_printk_fmt __used \ |
488 | __attribute__((section("__trace_printk_fmt"))) = \ |
488 | __attribute__((section("__trace_printk_fmt"))) = \ |
489 | __builtin_constant_p(str) ? str : NULL; \ |
489 | __builtin_constant_p(str) ? str : NULL; \ |
490 | \ |
490 | \ |
491 | if (__builtin_constant_p(str)) \ |
491 | if (__builtin_constant_p(str)) \ |
492 | __trace_bputs(_THIS_IP_, trace_printk_fmt); \ |
492 | __trace_bputs(_THIS_IP_, trace_printk_fmt); \ |
493 | else \ |
493 | else \ |
494 | __trace_puts(_THIS_IP_, str, strlen(str)); \ |
494 | __trace_puts(_THIS_IP_, str, strlen(str)); \ |
495 | }) |
495 | }) |
496 | extern int __trace_bputs(unsigned long ip, const char *str); |
496 | extern int __trace_bputs(unsigned long ip, const char *str); |
497 | extern int __trace_puts(unsigned long ip, const char *str, int size); |
497 | extern int __trace_puts(unsigned long ip, const char *str, int size); |
498 | 498 | ||
499 | extern void trace_dump_stack(int skip); |
499 | extern void trace_dump_stack(int skip); |
500 | 500 | ||
501 | /* |
501 | /* |
502 | * The double __builtin_constant_p is because gcc will give us an error |
502 | * The double __builtin_constant_p is because gcc will give us an error |
503 | * if we try to allocate the static variable to fmt if it is not a |
503 | * if we try to allocate the static variable to fmt if it is not a |
504 | * constant. Even with the outer if statement. |
504 | * constant. Even with the outer if statement. |
505 | */ |
505 | */ |
506 | #define ftrace_vprintk(fmt, vargs) \ |
506 | #define ftrace_vprintk(fmt, vargs) \ |
507 | do { \ |
507 | do { \ |
508 | if (__builtin_constant_p(fmt)) { \ |
508 | if (__builtin_constant_p(fmt)) { \ |
509 | static const char *trace_printk_fmt __used \ |
509 | static const char *trace_printk_fmt __used \ |
510 | __attribute__((section("__trace_printk_fmt"))) = \ |
510 | __attribute__((section("__trace_printk_fmt"))) = \ |
511 | __builtin_constant_p(fmt) ? fmt : NULL; \ |
511 | __builtin_constant_p(fmt) ? fmt : NULL; \ |
512 | \ |
512 | \ |
513 | __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \ |
513 | __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \ |
514 | } else \ |
514 | } else \ |
515 | __ftrace_vprintk(_THIS_IP_, fmt, vargs); \ |
515 | __ftrace_vprintk(_THIS_IP_, fmt, vargs); \ |
516 | } while (0) |
516 | } while (0) |
517 | 517 | ||
518 | extern __printf(2, 0) int |
518 | extern __printf(2, 0) int |
519 | __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); |
519 | __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); |
520 | 520 | ||
521 | extern __printf(2, 0) int |
521 | extern __printf(2, 0) int |
522 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); |
522 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); |
523 | 523 | ||
524 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); |
524 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); |
525 | #else |
525 | #else |
526 | static inline void tracing_start(void) { } |
526 | static inline void tracing_start(void) { } |
527 | static inline void tracing_stop(void) { } |
527 | static inline void tracing_stop(void) { } |
528 | static inline void trace_dump_stack(int skip) { } |
528 | static inline void trace_dump_stack(int skip) { } |
529 | 529 | ||
530 | static inline void tracing_on(void) { } |
530 | static inline void tracing_on(void) { } |
531 | static inline void tracing_off(void) { } |
531 | static inline void tracing_off(void) { } |
532 | static inline int tracing_is_on(void) { return 0; } |
532 | static inline int tracing_is_on(void) { return 0; } |
533 | static inline void tracing_snapshot(void) { } |
533 | static inline void tracing_snapshot(void) { } |
534 | static inline void tracing_snapshot_alloc(void) { } |
534 | static inline void tracing_snapshot_alloc(void) { } |
535 | 535 | ||
536 | static inline __printf(1, 2) |
536 | static inline __printf(1, 2) |
537 | int trace_printk(const char *fmt, ...) |
537 | int trace_printk(const char *fmt, ...) |
538 | { |
538 | { |
539 | return 0; |
539 | return 0; |
540 | } |
540 | } |
541 | static __printf(1, 0) inline int |
541 | static __printf(1, 0) inline int |
542 | ftrace_vprintk(const char *fmt, va_list ap) |
542 | ftrace_vprintk(const char *fmt, va_list ap) |
543 | { |
543 | { |
544 | return 0; |
544 | return 0; |
545 | } |
545 | } |
546 | static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } |
546 | static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } |
547 | #endif /* CONFIG_TRACING */ |
547 | #endif /* CONFIG_TRACING */ |
548 | 548 | ||
549 | /* |
549 | /* |
550 | * min()/max()/clamp() macros that also do |
550 | * min()/max()/clamp() macros that also do |
551 | * strict type-checking.. See the |
551 | * strict type-checking.. See the |
552 | * "unnecessary" pointer comparison. |
552 | * "unnecessary" pointer comparison. |
553 | */ |
553 | */ |
554 | #define min(x, y) ({ \ |
554 | #define min(x, y) ({ \ |
555 | typeof(x) _min1 = (x); \ |
555 | typeof(x) _min1 = (x); \ |
556 | typeof(y) _min2 = (y); \ |
556 | typeof(y) _min2 = (y); \ |
557 | (void) (&_min1 == &_min2); \ |
557 | (void) (&_min1 == &_min2); \ |
558 | _min1 < _min2 ? _min1 : _min2; }) |
558 | _min1 < _min2 ? _min1 : _min2; }) |
559 | 559 | ||
560 | #define max(x, y) ({ \ |
560 | #define max(x, y) ({ \ |
561 | typeof(x) _max1 = (x); \ |
561 | typeof(x) _max1 = (x); \ |
562 | typeof(y) _max2 = (y); \ |
562 | typeof(y) _max2 = (y); \ |
563 | (void) (&_max1 == &_max2); \ |
563 | (void) (&_max1 == &_max2); \ |
564 | _max1 > _max2 ? _max1 : _max2; }) |
564 | _max1 > _max2 ? _max1 : _max2; }) |
565 | 565 | ||
566 | #define min3(x, y, z) min((typeof(x))min(x, y), z) |
566 | #define min3(x, y, z) min((typeof(x))min(x, y), z) |
567 | #define max3(x, y, z) max((typeof(x))max(x, y), z) |
567 | #define max3(x, y, z) max((typeof(x))max(x, y), z) |
568 | 568 | ||
569 | /** |
569 | /** |
570 | * min_not_zero - return the minimum that is _not_ zero, unless both are zero |
570 | * min_not_zero - return the minimum that is _not_ zero, unless both are zero |
571 | * @x: value1 |
571 | * @x: value1 |
572 | * @y: value2 |
572 | * @y: value2 |
573 | */ |
573 | */ |
574 | #define min_not_zero(x, y) ({ \ |
574 | #define min_not_zero(x, y) ({ \ |
575 | typeof(x) __x = (x); \ |
575 | typeof(x) __x = (x); \ |
576 | typeof(y) __y = (y); \ |
576 | typeof(y) __y = (y); \ |
577 | __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) |
577 | __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) |
578 | 578 | ||
579 | /** |
579 | /** |
580 | * clamp - return a value clamped to a given range with strict typechecking |
580 | * clamp - return a value clamped to a given range with strict typechecking |
581 | * @val: current value |
581 | * @val: current value |
582 | * @lo: lowest allowable value |
582 | * @lo: lowest allowable value |
583 | * @hi: highest allowable value |
583 | * @hi: highest allowable value |
584 | * |
584 | * |
585 | * This macro does strict typechecking of lo/hi to make sure they are of the |
585 | * This macro does strict typechecking of lo/hi to make sure they are of the |
586 | * same type as val. See the unnecessary pointer comparisons. |
586 | * same type as val. See the unnecessary pointer comparisons. |
587 | */ |
587 | */ |
588 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) |
588 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) |
589 | 589 | ||
590 | /* |
590 | /* |
591 | * ..and if you can't take the strict |
591 | * ..and if you can't take the strict |
592 | * types, you can specify one yourself. |
592 | * types, you can specify one yourself. |
593 | * |
593 | * |
594 | * Or not use min/max/clamp at all, of course. |
594 | * Or not use min/max/clamp at all, of course. |
595 | */ |
595 | */ |
596 | #define min_t(type, x, y) ({ \ |
596 | #define min_t(type, x, y) ({ \ |
597 | type __min1 = (x); \ |
597 | type __min1 = (x); \ |
598 | type __min2 = (y); \ |
598 | type __min2 = (y); \ |
599 | __min1 < __min2 ? __min1: __min2; }) |
599 | __min1 < __min2 ? __min1: __min2; }) |
600 | 600 | ||
601 | #define max_t(type, x, y) ({ \ |
601 | #define max_t(type, x, y) ({ \ |
602 | type __max1 = (x); \ |
602 | type __max1 = (x); \ |
603 | type __max2 = (y); \ |
603 | type __max2 = (y); \ |
604 | __max1 > __max2 ? __max1: __max2; }) |
604 | __max1 > __max2 ? __max1: __max2; }) |
605 | 605 | ||
606 | /** |
606 | /** |
607 | * clamp_t - return a value clamped to a given range using a given type |
607 | * clamp_t - return a value clamped to a given range using a given type |
608 | * @type: the type of variable to use |
608 | * @type: the type of variable to use |
609 | * @val: current value |
609 | * @val: current value |
610 | * @lo: minimum allowable value |
610 | * @lo: minimum allowable value |
611 | * @hi: maximum allowable value |
611 | * @hi: maximum allowable value |
612 | * |
612 | * |
613 | * This macro does no typechecking and uses temporary variables of type |
613 | * This macro does no typechecking and uses temporary variables of type |
614 | * 'type' to make all the comparisons. |
614 | * 'type' to make all the comparisons. |
615 | */ |
615 | */ |
616 | #define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi) |
616 | #define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi) |
617 | 617 | ||
618 | /** |
618 | /** |
619 | * clamp_val - return a value clamped to a given range using val's type |
619 | * clamp_val - return a value clamped to a given range using val's type |
620 | * @val: current value |
620 | * @val: current value |
621 | * @lo: minimum allowable value |
621 | * @lo: minimum allowable value |
622 | * @hi: maximum allowable value |
622 | * @hi: maximum allowable value |
623 | * |
623 | * |
624 | * This macro does no typechecking and uses temporary variables of whatever |
624 | * This macro does no typechecking and uses temporary variables of whatever |
625 | * type the input argument 'val' is. This is useful when val is an unsigned |
625 | * type the input argument 'val' is. This is useful when val is an unsigned |
626 | * type and min and max are literals that will otherwise be assigned a signed |
626 | * type and min and max are literals that will otherwise be assigned a signed |
627 | * integer type. |
627 | * integer type. |
628 | */ |
628 | */ |
629 | #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) |
629 | #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) |
630 | 630 | ||
631 | 631 | ||
632 | /* |
632 | /* |
633 | * swap - swap value of @a and @b |
633 | * swap - swap value of @a and @b |
634 | */ |
634 | */ |
635 | #define swap(a, b) \ |
635 | #define swap(a, b) \ |
636 | do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
636 | do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
637 | 637 | ||
638 | /** |
638 | /** |
639 | * container_of - cast a member of a structure out to the containing structure |
639 | * container_of - cast a member of a structure out to the containing structure |
640 | * @ptr: the pointer to the member. |
640 | * @ptr: the pointer to the member. |
641 | * @type: the type of the container struct this is embedded in. |
641 | * @type: the type of the container struct this is embedded in. |
642 | * @member: the name of the member within the struct. |
642 | * @member: the name of the member within the struct. |
643 | * |
643 | * |
644 | */ |
644 | */ |
645 | #define container_of(ptr, type, member) ({ \ |
645 | #define container_of(ptr, type, member) ({ \ |
646 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
646 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
647 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
647 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
648 | 648 | ||
649 | /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ |
649 | /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ |
650 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
650 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
651 | # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD |
651 | # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD |
652 | #endif |
652 | #endif |
653 | 653 | ||
654 | /* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */ |
654 | /* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */ |
655 | #define VERIFY_OCTAL_PERMISSIONS(perms) \ |
655 | #define VERIFY_OCTAL_PERMISSIONS(perms) \ |
656 | (BUILD_BUG_ON_ZERO((perms) < 0) + \ |
656 | (BUILD_BUG_ON_ZERO((perms) < 0) + \ |
657 | BUILD_BUG_ON_ZERO((perms) > 0777) + \ |
657 | BUILD_BUG_ON_ZERO((perms) > 0777) + \ |
658 | /* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */ \ |
658 | /* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */ \ |
659 | BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) + \ |
659 | BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) + \ |
660 | BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) + \ |
660 | BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) + \ |
661 | /* USER_WRITABLE >= GROUP_WRITABLE */ \ |
661 | /* USER_WRITABLE >= GROUP_WRITABLE */ \ |
662 | BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) + \ |
662 | BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) + \ |
663 | /* OTHER_WRITABLE? Generally considered a bad idea. */ \ |
663 | /* OTHER_WRITABLE? Generally considered a bad idea. */ \ |
664 | BUILD_BUG_ON_ZERO((perms) & 2) + \ |
664 | BUILD_BUG_ON_ZERO((perms) & 2) + \ |
665 | (perms)) |
665 | (perms)) |
666 | 666 | ||
667 | void free (void *ptr); |
667 | void free (void *ptr); |
668 | 668 | ||
669 | typedef unsigned long pgprotval_t; |
669 | typedef unsigned long pgprotval_t; |
670 | 670 | ||
671 | typedef struct |
671 | typedef struct |
672 | { |
672 | { |
673 | u32 code; |
673 | u32 code; |
674 | u32 data[5]; |
674 | u32 data[5]; |
675 | }kevent_t; |
675 | }kevent_t; |
676 | 676 | ||
677 | typedef union |
677 | typedef union |
678 | { |
678 | { |
679 | struct |
679 | struct |
680 | { |
680 | { |
681 | u32 handle; |
681 | u32 handle; |
682 | u32 euid; |
682 | u32 euid; |
683 | }; |
683 | }; |
684 | u64 raw; |
684 | u64 raw; |
685 | }evhandle_t; |
685 | }evhandle_t; |
686 | 686 | ||
687 | struct vm_area_struct {}; |
687 | struct vm_area_struct {}; |
688 | struct address_space {}; |
688 | struct address_space {}; |
689 | 689 | ||
690 | #define in_dbg_master() (0) |
690 | #define in_dbg_master() (0) |
691 | 691 | ||
692 | #define HZ 100 |
692 | #define HZ 100 |
693 | 693 | ||
694 | struct tvec_base; |
694 | struct tvec_base; |
695 | 695 | ||
696 | struct timer_list { |
696 | struct timer_list { |
697 | struct list_head entry; |
697 | struct list_head entry; |
698 | unsigned long expires; |
698 | unsigned long expires; |
699 | 699 | ||
700 | void (*function)(unsigned long); |
700 | void (*function)(unsigned long); |
701 | unsigned long data; |
701 | unsigned long data; |
702 | u32 handle; |
702 | u32 handle; |
703 | }; |
703 | }; |
704 | 704 | ||
705 | #define setup_timer(_timer, _fn, _data) \ |
705 | #define setup_timer(_timer, _fn, _data) \ |
706 | do { \ |
706 | do { \ |
707 | (_timer)->function = (_fn); \ |
707 | (_timer)->function = (_fn); \ |
708 | (_timer)->data = (_data); \ |
708 | (_timer)->data = (_data); \ |
709 | (_timer)->handle = 0; \ |
709 | (_timer)->handle = 0; \ |
710 | } while (0) |
710 | } while (0) |
711 | 711 | ||
712 | int del_timer(struct timer_list *timer); |
712 | int del_timer(struct timer_list *timer); |
713 | 713 | ||
714 | # define del_timer_sync(t) del_timer(t) |
714 | # define del_timer_sync(t) del_timer(t) |
715 | 715 | ||
716 | 716 | ||
717 | #define readb_relaxed(a) __readb(a) |
717 | #define readb_relaxed(a) __readb(a) |
718 | #define readw_relaxed(a) __readw(a) |
718 | #define readw_relaxed(a) __readw(a) |
719 | #define readl_relaxed(a) __readl(a) |
719 | #define readl_relaxed(a) __readl(a) |
720 | #define __raw_readb __readb |
720 | #define __raw_readb __readb |
721 | #define __raw_readw __readw |
721 | #define __raw_readw __readw |
722 | #define __raw_readl __readl |
722 | #define __raw_readl __readl |
723 | 723 | ||
724 | #define __raw_writeb __writeb |
724 | #define __raw_writeb __writeb |
725 | #define __raw_writew __writew |
725 | #define __raw_writew __writew |
726 | #define __raw_writel __writel |
726 | #define __raw_writel __writel |
727 | 727 | ||
728 | #define swap(a, b) \ |
728 | #define swap(a, b) \ |
729 | do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
729 | do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
730 | 730 | ||
731 | 731 | ||
732 | #define mmiowb() barrier() |
732 | #define mmiowb() barrier() |
733 | 733 | ||
734 | #define dev_err(dev, format, arg...) \ |
734 | #define dev_err(dev, format, arg...) \ |
735 | printk("Error %s " format, __func__ , ## arg) |
735 | printk("Error %s " format, __func__ , ## arg) |
736 | 736 | ||
737 | #define dev_warn(dev, format, arg...) \ |
737 | #define dev_warn(dev, format, arg...) \ |
738 | printk("Warning %s " format, __func__ , ## arg) |
738 | printk("Warning %s " format, __func__ , ## arg) |
739 | 739 | ||
740 | #define dev_info(dev, format, arg...) \ |
740 | #define dev_info(dev, format, arg...) \ |
741 | printk("Info %s " format , __func__, ## arg) |
741 | printk("Info %s " format , __func__, ## arg) |
742 | 742 | ||
743 | struct page |
743 | struct page |
744 | { |
744 | { |
745 | unsigned int addr; |
745 | unsigned int addr; |
746 | }; |
746 | }; |
747 | 747 | ||
748 | #define page_to_phys(page) ((dma_addr_t)(page)) |
748 | #define page_to_phys(page) ((dma_addr_t)(page)) |
749 | 749 | ||
750 | struct vm_fault { |
750 | struct vm_fault { |
751 | unsigned int flags; /* FAULT_FLAG_xxx flags */ |
751 | unsigned int flags; /* FAULT_FLAG_xxx flags */ |
752 | pgoff_t pgoff; /* Logical page offset based on vma */ |
752 | pgoff_t pgoff; /* Logical page offset based on vma */ |
753 | void __user *virtual_address; /* Faulting virtual address */ |
753 | void __user *virtual_address; /* Faulting virtual address */ |
754 | 754 | ||
755 | struct page *page; /* ->fault handlers should return a |
755 | struct page *page; /* ->fault handlers should return a |
756 | * page here, unless VM_FAULT_NOPAGE |
756 | * page here, unless VM_FAULT_NOPAGE |
757 | * is set (which is also implied by |
757 | * is set (which is also implied by |
758 | * VM_FAULT_ERROR). |
758 | * VM_FAULT_ERROR). |
759 | */ |
759 | */ |
760 | }; |
760 | }; |
761 | 761 | ||
762 | struct pagelist { |
762 | struct pagelist { |
763 | dma_addr_t *page; |
763 | dma_addr_t *page; |
764 | unsigned int nents; |
764 | unsigned int nents; |
765 | }; |
765 | }; |
766 | 766 | ||
767 | #define page_cache_release(page) FreePage(page_to_phys(page)) |
767 | #define page_cache_release(page) FreePage(page_to_phys(page)) |
768 | 768 | ||
769 | #define alloc_page(gfp_mask) (struct page*)AllocPage() |
769 | #define alloc_page(gfp_mask) (struct page*)AllocPage() |
770 | 770 | ||
771 | #define __free_page(page) FreePage(page_to_phys(page)) |
771 | #define __free_page(page) FreePage(page_to_phys(page)) |
772 | 772 | ||
773 | #define get_page(a) |
773 | #define get_page(a) |
774 | #define put_page(a) |
774 | #define put_page(a) |
775 | 775 | ||
776 | #define IS_ENABLED(a) 0 |
776 | #define IS_ENABLED(a) 0 |
777 | 777 | ||
778 | 778 | ||
779 | 779 | ||
780 | #define cpufreq_quick_get_max(x) GetCpuFreq() |
780 | #define cpufreq_quick_get_max(x) GetCpuFreq() |
781 | 781 | ||
782 | extern unsigned int tsc_khz; |
782 | extern unsigned int tsc_khz; |
783 | 783 | ||
784 | #define on_each_cpu(func,info,wait) \ |
784 | #define on_each_cpu(func,info,wait) \ |
785 | ({ \ |
785 | ({ \ |
786 | func(info); \ |
786 | func(info); \ |
787 | 0; \ |
787 | 0; \ |
788 | }) |
788 | }) |
789 | 789 | ||
790 | - | ||
791 | static inline __must_check long __copy_to_user(void __user *to, |
- | |
792 | const void *from, unsigned long n) |
- | |
793 | { |
- | |
794 | if (__builtin_constant_p(n)) { |
- | |
795 | switch(n) { |
- | |
796 | case 1: |
- | |
797 | *(u8 __force *)to = *(u8 *)from; |
- | |
798 | return 0; |
- | |
799 | case 2: |
- | |
800 | *(u16 __force *)to = *(u16 *)from; |
- | |
801 | return 0; |
- | |
802 | case 4: |
- | |
803 | *(u32 __force *)to = *(u32 *)from; |
- | |
804 | return 0; |
- | |
805 | default: |
- | |
806 | break; |
- | |
807 | } |
- | |
808 | } |
- | |
809 | - | ||
810 | __builtin_memcpy((void __force *)to, from, n); |
- | |
811 | return 0; |
- | |
812 | } |
- | |
813 | - | ||
814 | static __always_inline unsigned long |
- | |
815 | __copy_from_user(void *to, const void __user *from, unsigned long n) |
- | |
816 | { |
- | |
817 | if (__builtin_constant_p(n)) { |
- | |
818 | unsigned long ret; |
- | |
819 | - | ||
820 | switch (n) { |
- | |
821 | case 1: |
- | |
822 | *(u8 __force *)to = *(u8 *)from; |
- | |
823 | return 0; |
- | |
824 | case 2: |
- | |
825 | *(u16 __force *)to = *(u16 *)from; |
- | |
826 | return 0; |
- | |
827 | case 4: |
- | |
828 | *(u32 __force *)to = *(u32 *)from; |
- | |
829 | return 0; |
- | |
830 | default: |
- | |
831 | break; |
- | |
832 | } |
- | |
833 | } |
- | |
834 | __builtin_memcpy((void __force *)to, from, n); |
- | |
835 | } |
- | |
836 | - | ||
837 | static inline long copy_from_user(void *to, |
- | |
838 | const void __user * from, unsigned long n) |
- | |
839 | { |
- | |
840 | return __copy_from_user(to, from, n); |
- | |
841 | } |
- | |
842 | - | ||
843 | static inline long copy_to_user(void __user *to, |
- | |
844 | const void *from, unsigned long n) |
- | |
845 | { |
- | |
846 | return __copy_to_user(to, from, n); |
- | |
847 | } |
- | |
848 | 790 | ||
849 | #define CAP_SYS_ADMIN 21 |
791 | #define CAP_SYS_ADMIN 21 |
850 | 792 | ||
851 | static inline bool capable(int cap) |
793 | static inline bool capable(int cap) |
852 | { |
794 | { |
853 | return true; |
795 | return true; |
854 | } |
796 | } |
855 | 797 | ||
856 | 798 | ||
857 | void *kmap(struct page *page); |
799 | void *kmap(struct page *page); |
858 | void *kmap_atomic(struct page *page); |
800 | void *kmap_atomic(struct page *page); |
859 | void kunmap(struct page *page); |
801 | void kunmap(struct page *page); |
860 | void kunmap_atomic(void *vaddr); |
802 | void kunmap_atomic(void *vaddr); |
861 | 803 | ||
862 | typedef u64 async_cookie_t; |
804 | typedef u64 async_cookie_t; |
863 | - | ||
864 | //#define iowrite32(v, addr) writel((v), (addr)) |
- | |
865 | 805 | ||
866 | #define __init |
806 | #define __init |
867 | 807 | ||
868 | #define CONFIG_PAGE_OFFSET 0 |
808 | #define CONFIG_PAGE_OFFSET 0 |
869 | - | ||
870 | typedef long long __kernel_long_t; |
- | |
871 | typedef unsigned long long __kernel_ulong_t; |
- | |
872 | #define __kernel_long_t __kernel_long_t |
- | |
873 | 809 | ||
874 | #endif>>>>>>7>6>5>4>3>2>1>0>>0?-__x:__x;> |
810 | #endif>>>>>>7>6>5>4>3>2>1>0>>0?-__x:__x;> |