-
Notifications
You must be signed in to change notification settings - Fork 2
/
npreal2.h
197 lines (171 loc) · 4.58 KB
/
npreal2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef _NPREAL2_H
#define _NPREAL2_H
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,0))
#define CLEAR_FUNC cleanup_module
#define CLEAR_FUNC_RET void
#else
#define CLEAR_FUNC npreal2_module_exit
#define CLEAR_FUNC_RET static void __exit
#endif
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,0))
#define INIT_FUNC init_module
#define INIT_FUNC_RET int
#else
#define INIT_FUNC npreal2_module_init
#define INIT_FUNC_RET static int __init
#endif
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,0))
#define DRV_VAR (&npvar_sdriver)
#define DRV_VAR_P(x) npvar_sdriver.x
#else
#define DRV_VAR (npvar_sdriver)
#define DRV_VAR_P(x) npvar_sdriver->x
#endif
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,20))
#ifndef INIT_WORK
#define INIT_WORK(_work, _func, _data){ \
(_work)->routine = _func;\
(_work)->data = _data;\
}
#endif
#else
#ifndef INIT_WORK
#define INIT_WORK(_work, _func){ \
(_work)->routine = _func;\
}
#endif
#endif
#ifndef set_current_state
#define set_current_state(x) current->state = x
#endif
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,0))
#define IRQ_RET void
#define IRQ_RETVAL(x)
#else
#define IRQ_RET irqreturn_t
#endif
#if 0
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,0))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,4,0)) // >=2.4.0
#define MXQ_TASK() {\
MOD_INC_USE_COUNT;\
if (schedule_task(&info->tqueue) == 0)\
MOD_DEC_USE_COUNT;\
}
#else // < 2.4.0
#define MXQ_TASK() queue_task(&info->tqueue,&tq_scheduler)
#endif
#else // >=2.6.0
#define MXQ_TASK() schedule_work(&info->tqueue)
#endif
#else
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,0))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,4,0)) // >=2.4.0
#define MXQ_TASK(queue) {\
MOD_INC_USE_COUNT;\
if (schedule_task(queue) == 0)\
MOD_DEC_USE_COUNT;\
}
#else // < 2.4.0
#define MXQ_TASK(queue) queue_task(queue,&tq_scheduler)
#endif
#else // >=2.6.0
#define MXQ_TASK(queue) schedule_work(queue)
#endif
#endif
#if (LINUX_VERSION_CODE < VERSION_CODE(2,6,0))
#define MX_MOD_INC MOD_INC_USE_COUNT
#define MX_MOD_DEC MOD_DEC_USE_COUNT
#else
#define MX_MOD_INC try_module_get(THIS_MODULE)
#define MX_MOD_DEC module_put(THIS_MODULE)
#endif
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,0))
#ifndef ASYNC_CALLOUT_ACTIVE
#define ASYNC_CALLOUT_ACTIVE 0
#endif
#endif
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,0))
#define MX_TTY_DRV(x) tty->driver->x
#else
#define MX_TTY_DRV(x) tty->driver.x
#endif
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,5))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,20))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,26))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,30))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,31))
#define MX_SESSION() task_session(current)
#else
#define MX_SESSION() (pid_t)task_session(current)
#endif
#else
#define MX_SESSION() task_session_nr(current)
#endif
#else
#define MX_SESSION() (pid_t)tty->session
#endif
#else
#define MX_SESSION() current->signal->session
#endif
#else
#define MX_SESSION() current->session
#endif
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,0))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,24))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,30))
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,31))
#define MX_CGRP() task_pgrp(current)
#else
#define MX_CGRP() (pid_t)task_pgrp(current)
#endif
#else
#define MX_CGRP() task_pgrp_nr(current)
#endif
#else
#define MX_CGRP() process_group(current)
#endif
#else
#define MX_CGRP() current->pgrp
#endif
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,6,0))
#define GET_FPAGE __get_free_page
#else
#define GET_FPAGE get_free_page
#endif
#if (LINUX_VERSION_CODE >= VERSION_CODE(2,4,0))
#define DOWN(tx_lock, flags) spin_lock_irqsave(&tx_lock, flags);
#define UP(tx_lock, flags) spin_unlock_irqrestore(&tx_lock, flags);
#else
#define DOWN(tx_lock, flags) down(&tx_lock);
#define UP(tx_lock, flags) up(&tx_lock);
#endif
#ifndef atomic_read
#define atomic_read(v) v
#endif
#ifndef UCHAR
typedef unsigned char UCHAR;
#endif
// Scott: 2005-09-13 begin
// Added the debug print management
#define MX_DEBUG_OFF 0
#define MX_DEBUG_ERROR 1 // 1~19 for ERROR level
#define MX_DEBUG_WARN 20 // 20~39 for WARN level
#define MX_DEBUG_TRACE 40 // 40~59 for TRACE level
#define MX_DEBUG_INFO 60 // 60~79 for INFO level
#define MX_DEBUG_LOUD 80 // 80~ for LOUD level
#ifdef MX_DBG
extern int MXDebugLevel;
#define DBGPRINT(level, fmt, args...) \
{ \
if ((level) <= MXDebugLevel) \
{ \
printk("Real TTY: %s %d> ", __FUNCTION__, __LINE__); \
printk(KERN_DEBUG fmt, ## args); \
} \
}
#else
#define DBGPRINT(level, fmt, args...) while (0) ;
#endif
// Scott: 2005-09-13 end
#endif