Rev 1430 | Rev 1964 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1430 | Rev 1870 | ||
---|---|---|---|
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 | * 'kernel.h' contains some often-used function prototypes etc |
5 | * 'kernel.h' contains some often-used function prototypes etc |
6 | */ |
6 | */ |
7 | 7 | ||
8 | #ifdef __KERNEL__ |
8 | #ifdef __KERNEL__ |
9 | 9 | ||
10 | #include |
10 | #include |
11 | #include |
11 | #include |
12 | #include |
12 | #include |
13 | #include |
13 | #include |
14 | 14 | ||
15 | #define USHORT_MAX ((u16)(~0U)) |
15 | #define USHORT_MAX ((u16)(~0U)) |
16 | #define SHORT_MAX ((s16)(USHORT_MAX>>1)) |
16 | #define SHORT_MAX ((s16)(USHORT_MAX>>1)) |
17 | #define SHORT_MIN (-SHORT_MAX - 1) |
17 | #define SHORT_MIN (-SHORT_MAX - 1) |
18 | #define INT_MAX ((int)(~0U>>1)) |
18 | #define INT_MAX ((int)(~0U>>1)) |
19 | #define INT_MIN (-INT_MAX - 1) |
19 | #define INT_MIN (-INT_MAX - 1) |
20 | #define UINT_MAX (~0U) |
20 | #define UINT_MAX (~0U) |
21 | #define LONG_MAX ((long)(~0UL>>1)) |
21 | #define LONG_MAX ((long)(~0UL>>1)) |
22 | #define LONG_MIN (-LONG_MAX - 1) |
22 | #define LONG_MIN (-LONG_MAX - 1) |
23 | #define ULONG_MAX (~0UL) |
23 | #define ULONG_MAX (~0UL) |
24 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
24 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
25 | #define LLONG_MIN (-LLONG_MAX - 1) |
25 | #define LLONG_MIN (-LLONG_MAX - 1) |
26 | #define ULLONG_MAX (~0ULL) |
26 | #define ULLONG_MAX (~0ULL) |
27 | 27 | ||
28 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
28 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
29 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
29 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
30 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
30 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
31 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
31 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * upper_32_bits - return bits 32-63 of a number |
34 | * upper_32_bits - return bits 32-63 of a number |
35 | * @n: the number we're accessing |
35 | * @n: the number we're accessing |
36 | * |
36 | * |
37 | * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress |
37 | * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress |
38 | * the "right shift count >= width of type" warning when that quantity is |
38 | * the "right shift count >= width of type" warning when that quantity is |
39 | * 32-bits. |
39 | * 32-bits. |
40 | */ |
40 | */ |
41 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
41 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
42 | 42 | ||
43 | /** |
43 | /** |
44 | * lower_32_bits - return bits 0-31 of a number |
44 | * lower_32_bits - return bits 0-31 of a number |
45 | * @n: the number we're accessing |
45 | * @n: the number we're accessing |
46 | */ |
46 | */ |
47 | #define lower_32_bits(n) ((u32)(n)) |
47 | #define lower_32_bits(n) ((u32)(n)) |
48 | 48 | ||
49 | 49 | ||
50 | #define KERN_EMERG "<0>" /* system is unusable */ |
50 | #define KERN_EMERG "<0>" /* system is unusable */ |
51 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
51 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
52 | #define KERN_CRIT "<2>" /* critical conditions */ |
52 | #define KERN_CRIT "<2>" /* critical conditions */ |
53 | #define KERN_ERR "<3>" /* error conditions */ |
53 | #define KERN_ERR "<3>" /* error conditions */ |
54 | #define KERN_WARNING "<4>" /* warning conditions */ |
54 | #define KERN_WARNING "<4>" /* warning conditions */ |
55 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
55 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
56 | #define KERN_INFO "<6>" /* informational */ |
56 | #define KERN_INFO "<6>" /* informational */ |
57 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
57 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
58 | 58 | ||
59 | //int printk(const char *fmt, ...); |
59 | //int printk(const char *fmt, ...); |
60 | 60 | ||
61 | #define printk(fmt, arg...) dbgprintf(fmt , ##arg) |
61 | #define printk(fmt, arg...) dbgprintf(fmt , ##arg) |
62 | 62 | ||
63 | 63 | ||
64 | /* |
64 | /* |
65 | * min()/max()/clamp() macros that also do |
65 | * min()/max()/clamp() macros that also do |
66 | * strict type-checking.. See the |
66 | * strict type-checking.. See the |
67 | * "unnecessary" pointer comparison. |
67 | * "unnecessary" pointer comparison. |
68 | */ |
68 | */ |
69 | #define min(x, y) ({ \ |
69 | #define min(x, y) ({ \ |
70 | typeof(x) _min1 = (x); \ |
70 | typeof(x) _min1 = (x); \ |
71 | typeof(y) _min2 = (y); \ |
71 | typeof(y) _min2 = (y); \ |
72 | (void) (&_min1 == &_min2); \ |
72 | (void) (&_min1 == &_min2); \ |
73 | _min1 < _min2 ? _min1 : _min2; }) |
73 | _min1 < _min2 ? _min1 : _min2; }) |
74 | 74 | ||
75 | #define max(x, y) ({ \ |
75 | #define max(x, y) ({ \ |
76 | typeof(x) _max1 = (x); \ |
76 | typeof(x) _max1 = (x); \ |
77 | typeof(y) _max2 = (y); \ |
77 | typeof(y) _max2 = (y); \ |
78 | (void) (&_max1 == &_max2); \ |
78 | (void) (&_max1 == &_max2); \ |
79 | _max1 > _max2 ? _max1 : _max2; }) |
79 | _max1 > _max2 ? _max1 : _max2; }) |
80 | 80 | ||
81 | /* |
81 | /* |
82 | * ..and if you can't take the strict |
82 | * ..and if you can't take the strict |
83 | * types, you can specify one yourself. |
83 | * types, you can specify one yourself. |
84 | * |
84 | * |
85 | * Or not use min/max/clamp at all, of course. |
85 | * Or not use min/max/clamp at all, of course. |
86 | */ |
86 | */ |
87 | #define min_t(type, x, y) ({ \ |
87 | #define min_t(type, x, y) ({ \ |
88 | type __min1 = (x); \ |
88 | type __min1 = (x); \ |
89 | type __min2 = (y); \ |
89 | type __min2 = (y); \ |
90 | __min1 < __min2 ? __min1: __min2; }) |
90 | __min1 < __min2 ? __min1: __min2; }) |
91 | 91 | ||
92 | #define max_t(type, x, y) ({ \ |
92 | #define max_t(type, x, y) ({ \ |
93 | type __max1 = (x); \ |
93 | type __max1 = (x); \ |
94 | type __max2 = (y); \ |
94 | type __max2 = (y); \ |
95 | __max1 > __max2 ? __max1: __max2; }) |
95 | __max1 > __max2 ? __max1: __max2; }) |
96 | 96 | ||
97 | /** |
97 | /** |
98 | * container_of - cast a member of a structure out to the containing structure |
98 | * container_of - cast a member of a structure out to the containing structure |
99 | * @ptr: the pointer to the member. |
99 | * @ptr: the pointer to the member. |
100 | * @type: the type of the container struct this is embedded in. |
100 | * @type: the type of the container struct this is embedded in. |
101 | * @member: the name of the member within the struct. |
101 | * @member: the name of the member within the struct. |
102 | * |
102 | * |
103 | */ |
103 | */ |
104 | #define container_of(ptr, type, member) ({ \ |
104 | #define container_of(ptr, type, member) ({ \ |
105 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
105 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
106 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
106 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
107 | 107 | ||
108 | 108 | ||
109 | static inline void *kcalloc(size_t n, size_t size, uint32_t flags) |
109 | static inline void *kcalloc(size_t n, size_t size, uint32_t flags) |
110 | { |
110 | { |
111 | if (n != 0 && size > ULONG_MAX / n) |
111 | if (n != 0 && size > ULONG_MAX / n) |
112 | return NULL; |
112 | return NULL; |
113 | return kzalloc(n * size, 0); |
113 | return kzalloc(n * size, 0); |
114 | } |
114 | } |
- | 115 | ||
- | 116 | extern const char hex_asc[]; |
|
- | 117 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
|
- | 118 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
|
- | 119 | ||
- | 120 | static inline char *pack_hex_byte(char *buf, u8 byte) |
|
- | 121 | { |
|
- | 122 | *buf++ = hex_asc_hi(byte); |
|
- | 123 | *buf++ = hex_asc_lo(byte); |
|
- | 124 | return buf; |
|
- | 125 | } |
|
- | 126 | ||
115 | 127 | ||
116 | void free (void *ptr); |
128 | void free (void *ptr); |
117 | 129 | ||
118 | #endif /* __KERNEL__ */ |
130 | #endif /* __KERNEL__ */ |
119 | 131 | ||
120 | typedef unsigned long pgprotval_t; |
132 | typedef unsigned long pgprotval_t; |
121 | 133 | ||
122 | typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; |
134 | typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; |
123 | 135 | ||
124 | struct file {}; |
136 | struct file {}; |
125 | struct vm_area_struct {}; |
137 | struct vm_area_struct {}; |
126 | struct address_space {}; |
138 | struct address_space {}; |
127 | 139 | ||
128 | struct device |
140 | struct device |
129 | { |
141 | { |
130 | struct device *parent; |
142 | struct device *parent; |
131 | void *driver_data; |
143 | void *driver_data; |
132 | }; |
144 | }; |
133 | 145 | ||
134 | static inline void dev_set_drvdata(struct device *dev, void *data) |
146 | static inline void dev_set_drvdata(struct device *dev, void *data) |
135 | { |
147 | { |
136 | dev->driver_data = data; |
148 | dev->driver_data = data; |
137 | } |
149 | } |
138 | 150 | ||
139 | static inline void *dev_get_drvdata(struct device *dev) |
151 | static inline void *dev_get_drvdata(struct device *dev) |
140 | { |
152 | { |
141 | return dev->driver_data; |
153 | return dev->driver_data; |
142 | } |
154 | } |
143 | 155 | ||
144 | #define preempt_disable() do { } while (0) |
156 | #define preempt_disable() do { } while (0) |
145 | #define preempt_enable_no_resched() do { } while (0) |
157 | #define preempt_enable_no_resched() do { } while (0) |
146 | #define preempt_enable() do { } while (0) |
158 | #define preempt_enable() do { } while (0) |
147 | #define preempt_check_resched() do { } while (0) |
159 | #define preempt_check_resched() do { } while (0) |
148 | 160 | ||
149 | #define preempt_disable_notrace() do { } while (0) |
161 | #define preempt_disable_notrace() do { } while (0) |
150 | #define preempt_enable_no_resched_notrace() do { } while (0) |
162 | #define preempt_enable_no_resched_notrace() do { } while (0) |
151 | #define preempt_enable_notrace() do { } while (0) |
163 | #define preempt_enable_notrace() do { } while (0) |
152 | 164 | ||
153 | 165 | ||
154 | #endif>>7>6>5>4>3>2>1>0> |
166 | #endif>>7>6>5>4>3>2>1>0> |