Subversion Repositories Kolibri OS

Rev

Rev 1870 | Rev 1968 | 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
 
1412 serge 115
void free (void *ptr);
116
 
1408 serge 117
#endif /* __KERNEL__ */
118
 
119
typedef unsigned long   pgprotval_t;
120
 
121
typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
122
 
123
struct file {};
124
struct vm_area_struct {};
125
struct address_space {};
126
 
1430 serge 127
struct device
128
{
129
    struct device   *parent;
130
    void            *driver_data;
131
};
132
 
133
static inline void dev_set_drvdata(struct device *dev, void *data)
134
{
135
    dev->driver_data = data;
136
}
137
 
138
static inline void *dev_get_drvdata(struct device *dev)
139
{
140
    return dev->driver_data;
141
}
142
 
1408 serge 143
#define preempt_disable()       do { } while (0)
144
#define preempt_enable_no_resched() do { } while (0)
145
#define preempt_enable()        do { } while (0)
146
#define preempt_check_resched()     do { } while (0)
147
 
148
#define preempt_disable_notrace()       do { } while (0)
149
#define preempt_enable_no_resched_notrace() do { } while (0)
150
#define preempt_enable_notrace()        do { } while (0)
151
 
1964 serge 152
#define in_dbg_master() (0)
1408 serge 153
 
154
#endif
155