Rev 1321 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1321 | serge | 1 | #ifndef _LINUX_KERNEL_H |
2 | #define _LINUX_KERNEL_H |
||
1221 | serge | 3 | |
1321 | serge | 4 | /* |
5 | * 'kernel.h' contains some often-used function prototypes etc |
||
6 | */ |
||
7 | |||
8 | #ifdef __KERNEL__ |
||
9 | |||
10 | #include |
||
11 | #include |
||
12 | #include |
||
13 | #include |
||
14 | |||
15 | #define USHORT_MAX ((u16)(~0U)) |
||
16 | #define SHORT_MAX ((s16)(USHORT_MAX>>1)) |
||
17 | #define SHORT_MIN (-SHORT_MAX - 1) |
||
18 | #define INT_MAX ((int)(~0U>>1)) |
||
19 | #define INT_MIN (-INT_MAX - 1) |
||
20 | #define UINT_MAX (~0U) |
||
21 | #define LONG_MAX ((long)(~0UL>>1)) |
||
22 | #define LONG_MIN (-LONG_MAX - 1) |
||
23 | #define ULONG_MAX (~0UL) |
||
24 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
||
25 | #define LLONG_MIN (-LLONG_MAX - 1) |
||
26 | #define ULLONG_MAX (~0ULL) |
||
27 | |||
28 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
||
29 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
||
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) |
||
32 | |||
33 | /** |
||
34 | * upper_32_bits - return bits 32-63 of a number |
||
35 | * @n: the number we're accessing |
||
36 | * |
||
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 |
||
39 | * 32-bits. |
||
40 | */ |
||
41 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
||
42 | |||
43 | /** |
||
44 | * lower_32_bits - return bits 0-31 of a number |
||
45 | * @n: the number we're accessing |
||
46 | */ |
||
47 | #define lower_32_bits(n) ((u32)(n)) |
||
48 | |||
49 | |||
50 | #define KERN_EMERG "<0>" /* system is unusable */ |
||
51 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
||
52 | #define KERN_CRIT "<2>" /* critical conditions */ |
||
53 | #define KERN_ERR "<3>" /* error conditions */ |
||
54 | #define KERN_WARNING "<4>" /* warning conditions */ |
||
55 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
||
56 | #define KERN_INFO "<6>" /* informational */ |
||
57 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
||
58 | |||
59 | //int printk(const char *fmt, ...); |
||
60 | |||
61 | #define printk(fmt, arg...) dbgprintf(fmt , ##arg) |
||
62 | |||
63 | |||
64 | /* |
||
65 | * min()/max()/clamp() macros that also do |
||
66 | * strict type-checking.. See the |
||
67 | * "unnecessary" pointer comparison. |
||
68 | */ |
||
69 | #define min(x, y) ({ \ |
||
70 | typeof(x) _min1 = (x); \ |
||
71 | typeof(y) _min2 = (y); \ |
||
72 | (void) (&_min1 == &_min2); \ |
||
73 | _min1 < _min2 ? _min1 : _min2; }) |
||
74 | |||
75 | #define max(x, y) ({ \ |
||
76 | typeof(x) _max1 = (x); \ |
||
77 | typeof(y) _max2 = (y); \ |
||
78 | (void) (&_max1 == &_max2); \ |
||
79 | _max1 > _max2 ? _max1 : _max2; }) |
||
80 | |||
81 | /** |
||
82 | * container_of - cast a member of a structure out to the containing structure |
||
83 | * @ptr: the pointer to the member. |
||
84 | * @type: the type of the container struct this is embedded in. |
||
85 | * @member: the name of the member within the struct. |
||
86 | * |
||
87 | */ |
||
88 | #define container_of(ptr, type, member) ({ \ |
||
89 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
||
90 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
||
91 | |||
92 | |||
93 | static inline void *kcalloc(size_t n, size_t size, uint32_t flags) |
||
94 | { |
||
95 | if (n != 0 && size > ULONG_MAX / n) |
||
96 | return NULL; |
||
97 | return kzalloc(n * size, 0); |
||
98 | } |
||
99 | |||
100 | #endif /* __KERNEL__ */ |
||
101 | |||
102 | typedef unsigned long pgprotval_t; |
||
103 | |||
104 | typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; |
||
105 | |||
106 | struct file {}; |
||
107 | struct vm_area_struct {}; |
||
108 | struct address_space {}; |
||
109 | |||
1403 | serge | 110 | #define preempt_disable() do { } while (0) |
111 | #define preempt_enable_no_resched() do { } while (0) |
||
112 | #define preempt_enable() do { } while (0) |
||
113 | #define preempt_check_resched() do { } while (0) |
||
114 | |||
115 | #define preempt_disable_notrace() do { } while (0) |
||
116 | #define preempt_enable_no_resched_notrace() do { } while (0) |
||
117 | #define preempt_enable_notrace() do { } while (0) |
||
118 | |||
119 | |||
120 | |||
121 | void free (void *ptr); |
||
122 | |||
1321 | serge | 123 | #endif>7>6>5>4>3>2>1>0> |
124 |