Subversion Repositories Kolibri OS

Rev

Rev 1968 | Rev 2005 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1408 serge 1
#ifndef _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__
9
 
10
#include 
11
#include 
12
#include 
13
#include 
1970 serge 14
#include 
1408 serge 15
 
1964 serge 16
#define USHRT_MAX	((u16)(~0U))
17
#define SHRT_MAX	((s16)(USHRT_MAX>>1))
18
#define SHRT_MIN	((s16)(-SHRT_MAX - 1))
1408 serge 19
#define INT_MAX     ((int)(~0U>>1))
20
#define INT_MIN     (-INT_MAX - 1)
21
#define UINT_MAX    (~0U)
22
#define LONG_MAX    ((long)(~0UL>>1))
23
#define LONG_MIN    (-LONG_MAX - 1)
24
#define ULONG_MAX   (~0UL)
25
#define LLONG_MAX   ((long long)(~0ULL>>1))
26
#define LLONG_MIN   (-LLONG_MAX - 1)
27
#define ULLONG_MAX  (~0ULL)
28
 
29
#define ALIGN(x,a)      __ALIGN_MASK(x,(typeof(x))(a)-1)
30
#define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
31
#define PTR_ALIGN(p, a)     ((typeof(p))ALIGN((unsigned long)(p), (a)))
32
#define IS_ALIGNED(x, a)        (((x) & ((typeof(x))(a) - 1)) == 0)
33
 
34
/**
35
 * upper_32_bits - return bits 32-63 of a number
36
 * @n: the number we're accessing
37
 *
38
 * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
39
 * the "right shift count >= width of type" warning when that quantity is
40
 * 32-bits.
41
 */
42
#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
43
 
44
/**
45
 * lower_32_bits - return bits 0-31 of a number
46
 * @n: the number we're accessing
47
 */
48
#define lower_32_bits(n) ((u32)(n))
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                 */
1970 serge 58
extern const char hex_asc[];
59
#define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
60
#define hex_asc_hi(x)	hex_asc[((x) & 0xf0) >> 4]
1408 serge 61
 
1970 serge 62
static inline char *pack_hex_byte(char *buf, u8 byte)
63
{
64
	*buf++ = hex_asc_hi(byte);
65
	*buf++ = hex_asc_lo(byte);
66
	return buf;
67
}
68
 
69
extern int hex_to_bin(char ch);
70
extern void hex2bin(u8 *dst, const char *src, size_t count);
71
 
72
 
1408 serge 73
//int printk(const char *fmt, ...);
74
 
75
#define printk(fmt, arg...)    dbgprintf(fmt , ##arg)
76
 
77
 
78
/*
79
 * min()/max()/clamp() macros that also do
80
 * strict type-checking.. See the
81
 * "unnecessary" pointer comparison.
82
 */
83
#define min(x, y) ({                \
84
    typeof(x) _min1 = (x);          \
85
    typeof(y) _min2 = (y);          \
86
    (void) (&_min1 == &_min2);      \
87
    _min1 < _min2 ? _min1 : _min2; })
88
 
89
#define max(x, y) ({                \
90
    typeof(x) _max1 = (x);          \
91
    typeof(y) _max2 = (y);          \
92
    (void) (&_max1 == &_max2);      \
93
    _max1 > _max2 ? _max1 : _max2; })
94
 
1970 serge 95
#define min3(x, y, z) ({			\
96
	typeof(x) _min1 = (x);			\
97
	typeof(y) _min2 = (y);			\
98
	typeof(z) _min3 = (z);			\
99
	(void) (&_min1 == &_min2);		\
100
	(void) (&_min1 == &_min3);		\
101
	_min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \
102
		(_min2 < _min3 ? _min2 : _min3); })
103
 
104
#define max3(x, y, z) ({			\
105
	typeof(x) _max1 = (x);			\
106
	typeof(y) _max2 = (y);			\
107
	typeof(z) _max3 = (z);			\
108
	(void) (&_max1 == &_max2);		\
109
	(void) (&_max1 == &_max3);		\
110
	_max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \
111
		(_max2 > _max3 ? _max2 : _max3); })
112
 
113
/**
114
 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
115
 * @x: value1
116
 * @y: value2
117
 */
118
#define min_not_zero(x, y) ({			\
119
	typeof(x) __x = (x);			\
120
	typeof(y) __y = (y);			\
121
	__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
122
 
123
/**
124
 * clamp - return a value clamped to a given range with strict typechecking
125
 * @val: current value
126
 * @min: minimum allowable value
127
 * @max: maximum allowable value
128
 *
129
 * This macro does strict typechecking of min/max to make sure they are of the
130
 * same type as val.  See the unnecessary pointer comparisons.
131
 */
132
#define clamp(val, min, max) ({			\
133
	typeof(val) __val = (val);		\
134
	typeof(min) __min = (min);		\
135
	typeof(max) __max = (max);		\
136
	(void) (&__val == &__min);		\
137
	(void) (&__val == &__max);		\
138
	__val = __val < __min ? __min: __val;	\
139
	__val > __max ? __max: __val; })
140
 
1408 serge 141
/*
142
 * ..and if you can't take the strict
143
 * types, you can specify one yourself.
144
 *
145
 * Or not use min/max/clamp at all, of course.
146
 */
147
#define min_t(type, x, y) ({            \
148
    type __min1 = (x);          \
149
    type __min2 = (y);          \
150
    __min1 < __min2 ? __min1: __min2; })
151
 
152
#define max_t(type, x, y) ({            \
153
    type __max1 = (x);          \
154
    type __max2 = (y);          \
155
    __max1 > __max2 ? __max1: __max2; })
156
 
157
/**
158
 * container_of - cast a member of a structure out to the containing structure
159
 * @ptr:    the pointer to the member.
160
 * @type:   the type of the container struct this is embedded in.
161
 * @member: the name of the member within the struct.
162
 *
163
 */
164
#define container_of(ptr, type, member) ({          \
165
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
166
    (type *)( (char *)__mptr - offsetof(type,member) );})
167
 
168
 
169
static inline void *kcalloc(size_t n, size_t size, uint32_t flags)
170
{
171
        if (n != 0 && size > ULONG_MAX / n)
172
                return NULL;
173
        return kzalloc(n * size, 0);
174
}
175
 
1968 serge 176
 
1412 serge 177
void free (void *ptr);
178
 
1408 serge 179
#endif /* __KERNEL__ */
180
 
181
typedef unsigned long   pgprotval_t;
182
 
183
typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
184
 
185
struct file {};
186
struct vm_area_struct {};
187
struct address_space {};
188
 
1430 serge 189
struct device
190
{
191
    struct device   *parent;
192
    void            *driver_data;
193
};
194
 
195
static inline void dev_set_drvdata(struct device *dev, void *data)
196
{
197
    dev->driver_data = data;
198
}
199
 
200
static inline void *dev_get_drvdata(struct device *dev)
201
{
202
    return dev->driver_data;
203
}
204
 
1408 serge 205
#define preempt_disable()       do { } while (0)
206
#define preempt_enable_no_resched() do { } while (0)
207
#define preempt_enable()        do { } while (0)
208
#define preempt_check_resched()     do { } while (0)
209
 
210
#define preempt_disable_notrace()       do { } while (0)
211
#define preempt_enable_no_resched_notrace() do { } while (0)
212
#define preempt_enable_notrace()        do { } while (0)
213
 
1964 serge 214
#define in_dbg_master() (0)
1408 serge 215
 
216
#endif
217