Subversion Repositories Kolibri OS

Rev

Rev 1412 | Rev 1870 | 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
 
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
 * ..and if you can't take the strict
83
 * types, you can specify one yourself.
84
 *
85
 * Or not use min/max/clamp at all, of course.
86
 */
87
#define min_t(type, x, y) ({            \
88
    type __min1 = (x);          \
89
    type __min2 = (y);          \
90
    __min1 < __min2 ? __min1: __min2; })
91
 
92
#define max_t(type, x, y) ({            \
93
    type __max1 = (x);          \
94
    type __max2 = (y);          \
95
    __max1 > __max2 ? __max1: __max2; })
96
 
97
/**
98
 * container_of - cast a member of a structure out to the containing structure
99
 * @ptr:    the pointer to the member.
100
 * @type:   the type of the container struct this is embedded in.
101
 * @member: the name of the member within the struct.
102
 *
103
 */
104
#define container_of(ptr, type, member) ({          \
105
    const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
106
    (type *)( (char *)__mptr - offsetof(type,member) );})
107
 
108
 
109
static inline void *kcalloc(size_t n, size_t size, uint32_t flags)
110
{
111
        if (n != 0 && size > ULONG_MAX / n)
112
                return NULL;
113
        return kzalloc(n * size, 0);
114
}
115
 
1412 serge 116
void free (void *ptr);
117
 
1408 serge 118
#endif /* __KERNEL__ */
119
 
120
typedef unsigned long   pgprotval_t;
121
 
122
typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
123
 
124
struct file {};
125
struct vm_area_struct {};
126
struct address_space {};
127
 
1430 serge 128
struct device
129
{
130
    struct device   *parent;
131
    void            *driver_data;
132
};
133
 
134
static inline void dev_set_drvdata(struct device *dev, void *data)
135
{
136
    dev->driver_data = data;
137
}
138
 
139
static inline void *dev_get_drvdata(struct device *dev)
140
{
141
    return dev->driver_data;
142
}
143
 
1408 serge 144
#define preempt_disable()       do { } while (0)
145
#define preempt_enable_no_resched() do { } while (0)
146
#define preempt_enable()        do { } while (0)
147
#define preempt_check_resched()     do { } while (0)
148
 
149
#define preempt_disable_notrace()       do { } while (0)
150
#define preempt_enable_no_resched_notrace() do { } while (0)
151
#define preempt_enable_notrace()        do { } while (0)
152
 
153
 
154
#endif
155