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