Subversion Repositories Kolibri OS

Rev

Rev 1964 | Rev 1970 | 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 
14
 
1964 serge 15
#define USHRT_MAX	((u16)(~0U))
16
#define SHRT_MAX	((s16)(USHRT_MAX>>1))
17
#define SHRT_MIN	((s16)(-SHRT_MAX - 1))
1408 serge 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
#define KERN_EMERG      "<0>"   /* system is unusable                   */
50
#define KERN_ALERT      "<1>"   /* action must be taken immediately     */
51
#define KERN_CRIT       "<2>"   /* critical conditions                  */
52
#define KERN_ERR        "<3>"   /* error conditions                     */
53
#define KERN_WARNING    "<4>"   /* warning conditions                   */
54
#define KERN_NOTICE     "<5>"   /* normal but significant condition     */
55
#define KERN_INFO       "<6>"   /* informational                        */
56
#define KERN_DEBUG      "<7>"   /* debug-level messages                 */
57
 
58
//int printk(const char *fmt, ...);
59
 
60
#define printk(fmt, arg...)    dbgprintf(fmt , ##arg)
61
 
62
 
63
/*
64
 * min()/max()/clamp() macros that also do
65
 * strict type-checking.. See the
66
 * "unnecessary" pointer comparison.
67
 */
68
#define min(x, y) ({                \
69
    typeof(x) _min1 = (x);          \
70
    typeof(y) _min2 = (y);          \
71
    (void) (&_min1 == &_min2);      \
72
    _min1 < _min2 ? _min1 : _min2; })
73
 
74
#define max(x, y) ({                \
75
    typeof(x) _max1 = (x);          \
76
    typeof(y) _max2 = (y);          \
77
    (void) (&_max1 == &_max2);      \
78
    _max1 > _max2 ? _max1 : _max2; })
79
 
80
/*
81
 * ..and if you can't take the strict
82
 * types, you can specify one yourself.
83
 *
84
 * Or not use min/max/clamp at all, of course.
85
 */
86
#define min_t(type, x, y) ({            \
87
    type __min1 = (x);          \
88
    type __min2 = (y);          \
89
    __min1 < __min2 ? __min1: __min2; })
90
 
91
#define max_t(type, x, y) ({            \
92
    type __max1 = (x);          \
93
    type __max2 = (y);          \
94
    __max1 > __max2 ? __max1: __max2; })
95
 
96
/**
97
 * container_of - cast a member of a structure out to the containing structure
98
 * @ptr:    the pointer to the member.
99
 * @type:   the type of the container struct this is embedded in.
100
 * @member: the name of the member within the struct.
101
 *
102
 */
103
#define container_of(ptr, type, member) ({          \
104
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
105
    (type *)( (char *)__mptr - offsetof(type,member) );})
106
 
107
 
108
static inline void *kcalloc(size_t n, size_t size, uint32_t flags)
109
{
110
        if (n != 0 && size > ULONG_MAX / n)
111
                return NULL;
112
        return kzalloc(n * size, 0);
113
}
114
 
1968 serge 115
extern const char hex_asc[];
116
#define hex_asc_lo(x)   hex_asc[((x) & 0x0f)]
117
#define hex_asc_hi(x)   hex_asc[((x) & 0xf0) >> 4]
118
 
119
static inline char *pack_hex_byte(char *buf, u8 byte)
120
{
121
    *buf++ = hex_asc_hi(byte);
122
    *buf++ = hex_asc_lo(byte);
123
    return buf;
124
}
125
 
126
 
1412 serge 127
void free (void *ptr);
128
 
1408 serge 129
#endif /* __KERNEL__ */
130
 
131
typedef unsigned long   pgprotval_t;
132
 
133
typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
134
 
135
struct file {};
136
struct vm_area_struct {};
137
struct address_space {};
138
 
1430 serge 139
struct device
140
{
141
    struct device   *parent;
142
    void            *driver_data;
143
};
144
 
145
static inline void dev_set_drvdata(struct device *dev, void *data)
146
{
147
    dev->driver_data = data;
148
}
149
 
150
static inline void *dev_get_drvdata(struct device *dev)
151
{
152
    return dev->driver_data;
153
}
154
 
1408 serge 155
#define preempt_disable()       do { } while (0)
156
#define preempt_enable_no_resched() do { } while (0)
157
#define preempt_enable()        do { } while (0)
158
#define preempt_check_resched()     do { } while (0)
159
 
160
#define preempt_disable_notrace()       do { } while (0)
161
#define preempt_enable_no_resched_notrace() do { } while (0)
162
#define preempt_enable_notrace()        do { } while (0)
163
 
1964 serge 164
#define in_dbg_master() (0)
1408 serge 165
 
166
#endif
167