1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef __LINUX_MTD_COMPATMAC_H__
18#define __LINUX_MTD_COMPATMAC_H__
19
20#include <linux/config.h>
21#include <linux/module.h>
22#ifndef LINUX_VERSION_CODE
23#include <linux/version.h>
24#endif
25
26#ifndef VERSION_CODE
27# define VERSION_CODE(vers,rel,seq) ( ((vers)<<16) | ((rel)<<8) | (seq) )
28#endif
29#ifndef KERNEL_VERSION
30# define KERNEL_VERSION(a,b,c) VERSION_CODE(a,b,c)
31#endif
32
33#if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0)
34# error "This kernel is too old: not supported by this file"
35#endif
36
37#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
38#include <linux/types.h>
39
40#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
41#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
42
43typedef struct wait_queue * wait_queue_head_t;
44
45#define DECLARE_WAITQUEUE(x,y) struct wait_queue x = {y,NULL}
46#define DECLARE_WAIT_QUEUE_HEAD(x) struct wait_queue *x = NULL
47#define init_waitqueue_head init_waitqueue
48#define DECLARE_MUTEX(x) struct semaphore x = MUTEX
49#define DECLARE_MUTEX_LOCKED(x) struct semaphore x = MUTEX_LOCKED
50
51
52# include <asm/segment.h>
53# define access_ok(t,a,sz) (verify_area((t),(a),(sz)) ? 0 : 1)
54# define verify_area_20 verify_area
55# define copy_to_user(t,f,n) (memcpy_tofs(t,f,n), 0)
56# define __copy_to_user(t,f,n) copy_to_user((t),(f),(n))
57# define copy_to_user_ret(t,f,n,r) copy_to_user((t),(f),(n))
58# define copy_from_user(t,f,n) (memcpy_fromfs((t),(f),(n)), 0)
59# define __copy_from_user(t,f,n) copy_from_user((t),(f),(n))
60# define copy_from_user_ret(t,f,n,r) copy_from_user((t),(f),(n))
61
62# define Put_user(val,add) (put_user((val),(add)), 0)
63# define __PUT_USER(val,add) PUT_USER((val),(add))
64# define PUT_USER_RET(val,add,ret) PUT_USER((val),(add))
65# define GET_USER(dest,add) ((dest)=get_user((add)), 0)
66# define __GET_USER(dest,add) GET_USER((dest),(add))
67# define GET_USER_RET(dest,add,ret) GET_USER((dest),(add))
68
69#define ioremap(offset,size) vremap(offset,size)
70#define iounmap(adr)
71
72#define EXPORT_SYMBOL(s)
73#define EXPORT_SYMBOL_NOVERS(s)
74
75
76
77#if LINUX_VERSION_CODE < VERSION_CODE(2,1,10)
78
79# include <asm/byteorder.h>
80# ifdef __LITTLE_ENDIAN
81# define cpu_to_le16(x) (x)
82# define cpu_to_le32(x) (x)
83# define cpu_to_be16(x) htons((x))
84# define cpu_to_be32(x) htonl((x))
85# else
86# define cpu_to_be16(x) (x)
87# define cpu_to_be32(x) (x)
88 extern inline __u16 cpu_to_le16(__u16 x) { return (x<<8) | (x>>8);}
89 extern inline __u32 cpu_to_le32(__u32 x) { return((x>>24) |
90 ((x>>8)&0xff00) | ((x<<8)&0xff0000) | (x<<24));}
91# endif
92
93# define le16_to_cpu(x) cpu_to_le16(x)
94# define le32_to_cpu(x) cpu_to_le32(x)
95# define be16_to_cpu(x) cpu_to_be16(x)
96# define be32_to_cpu(x) cpu_to_be32(x)
97
98#endif
99
100#if LINUX_VERSION_CODE < VERSION_CODE(2,1,43)
101# define cpu_to_le16p(addr) (cpu_to_le16(*(addr)))
102# define cpu_to_le32p(addr) (cpu_to_le32(*(addr)))
103# define cpu_to_be16p(addr) (cpu_to_be16(*(addr)))
104# define cpu_to_be32p(addr) (cpu_to_be32(*(addr)))
105
106 extern inline void cpu_to_le16s(__u16 *a) {*a = cpu_to_le16(*a);}
107 extern inline void cpu_to_le32s(__u16 *a) {*a = cpu_to_le32(*a);}
108 extern inline void cpu_to_be16s(__u16 *a) {*a = cpu_to_be16(*a);}
109 extern inline void cpu_to_be32s(__u16 *a) {*a = cpu_to_be32(*a);}
110
111# define le16_to_cpup(x) cpu_to_le16p(x)
112# define le32_to_cpup(x) cpu_to_le32p(x)
113# define be16_to_cpup(x) cpu_to_be16p(x)
114# define be32_to_cpup(x) cpu_to_be32p(x)
115
116# define le16_to_cpus(x) cpu_to_le16s(x)
117# define le32_to_cpus(x) cpu_to_le32s(x)
118# define be16_to_cpus(x) cpu_to_be16s(x)
119# define be32_to_cpus(x) cpu_to_be32s(x)
120#endif
121
122
123#ifndef __BIT_TYPES_DEFINED__
124#define __BIT_TYPES_DEFINED__
125
126typedef __u8 u_int8_t;
127typedef __s8 int8_t;
128typedef __u16 u_int16_t;
129typedef __s16 int16_t;
130typedef __u32 u_int32_t;
131typedef __s32 int32_t;
132
133#endif
134
135#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
136 typedef struct { } spinlock_t;
137 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
138#else
139 typedef struct { int gcc_is_buggy; } spinlock_t;
140 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
141#endif
142
143#define spin_lock_init(lock) do { } while(0)
144#define spin_lock(lock) (void)(lock)
145#define spin_trylock(lock) (1)
146#define spin_unlock_wait(lock) do { } while(0)
147#define spin_unlock(lock) do { } while(0)
148#define spin_lock_irq(lock) cli()
149#define spin_unlock_irq(lock) sti()
150
151#define spin_lock_irqsave(lock, flags) \
152 do { save_flags(flags); cli(); } while (0)
153#define spin_unlock_irqrestore(lock, flags) \
154 restore_flags(flags)
155
156
157
158#define tty_flip_buffer_push(tty) queue_task_irq_off(&tty->flip.tqueue, &tq_timer)
159#define signal_pending(current) (current->signal & ~current->blocked)
160#define schedule_timeout(to) do {current->timeout = jiffies + (to);schedule ();} while (0)
161#define time_after(t1,t2) (((long)t1-t2) > 0)
162
163#else
164 #include <linux/compatmac.h>
165#endif
166
167
168#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
169#include <linux/vmalloc.h>
170#endif
171
172
173#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,18)
174# define __USE_OLD_SYMTAB__
175# define EXPORT_NO_SYMBOLS register_symtab(NULL);
176# define REGISTER_SYMTAB(tab) register_symtab(tab)
177#else
178# define REGISTER_SYMTAB(tab)
179#endif
180
181#ifdef __USE_OLD_SYMTAB__
182# define __MODULE_STRING(s)
183# define MODULE_PARM(v,t)
184# define MODULE_PARM_DESC(v,t)
185# define MODULE_AUTHOR(n)
186# define MODULE_DESCRIPTION(d)
187# define MODULE_SUPPORTED_DEVICE(n)
188#endif
189
190
191
192
193
194#if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,22)
195# include <linux/poll.h>
196#else
197# define __USE_OLD_SELECT__
198#endif
199
200
201#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
202# define lseek_t long long
203# define lseek_off_t long long
204#else
205# define lseek_t int
206# define lseek_off_t off_t
207#endif
208
209
210
211#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0) || defined(__alpha__)
212# define count_t unsigned long
213# define read_write_t long
214#else
215# define count_t int
216# define read_write_t int
217#endif
218
219
220#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,31)
221# define release_t void
222# define release_return(x) return
223#else
224# define release_t int
225# define release_return(x) return (x)
226#endif
227
228#if LINUX_VERSION_CODE < 0x20300
229#define __exit
230#endif
231#if LINUX_VERSION_CODE < 0x20200
232#define __init
233#else
234#include <linux/init.h>
235#endif
236
237#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
238#define init_MUTEX(x) do {*(x) = MUTEX;} while (0)
239#define init_MUTEX_LOCKED(x) do {*(x) = MUTEX_LOCKED;} while (0)
240#endif
241
242#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
243#define RQFUNC_ARG void
244#define blkdev_dequeue_request(req) do {CURRENT = req->next;} while (0)
245#else
246#define RQFUNC_ARG request_queue_t *q
247#endif
248
249#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,32)
250#define blk_cleanup_queue(nr) do {blk_dev[nr].request_fn = 0;} while(0)
251#define BLK_DEFAULT_QUEUE(nr) (blk_dev[nr].request_fn)
252#define blk_init_queue(q, rq) do {q = rq;} while(0)
253#endif
254
255#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0)
256#ifdef CONFIG_MODULES
257#define __MOD_INC_USE_COUNT(mod) \
258 (atomic_inc(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
259#define __MOD_DEC_USE_COUNT(mod) \
260 (atomic_dec(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED)
261#else
262#define __MOD_INC_USE_COUNT(mod)
263#define __MOD_DEC_USE_COUNT(mod)
264#endif
265#endif
266
267
268#ifndef HAVE_INTER_MODULE
269static inline void *inter_module_get(char *x) {return NULL;}
270static inline void *inter_module_get_request(char *x, char *y) {return NULL;}
271static inline void inter_module_put(const char *x) {}
272static inline void inter_module_register(const char *x, struct module *y, const void *z) {}
273static inline void inter_module_unregister(const char *x) {}
274#endif
275
276#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
277
278#define DECLARE_WAIT_QUEUE_HEAD(x) struct wait_queue *x = NULL
279#define init_waitqueue_head init_waitqueue
280
281#endif
282
283#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
284
285static inline int try_inc_mod_count(struct module *mod)
286{
287#ifdef CONFIG_MODULES
288 if (mod)
289 __MOD_INC_USE_COUNT(mod);
290#endif
291 return 1;
292}
293#endif
294
295
296
297
298
299
300
301
302#include <asm/byteorder.h>
303
304#ifndef __constant_cpu_to_le16
305
306#ifdef __BIG_ENDIAN
307#define __constant_cpu_to_le64(x) ___swab64((x))
308#define __constant_le64_to_cpu(x) ___swab64((x))
309#define __constant_cpu_to_le32(x) ___swab32((x))
310#define __constant_le32_to_cpu(x) ___swab32((x))
311#define __constant_cpu_to_le16(x) ___swab16((x))
312#define __constant_le16_to_cpu(x) ___swab16((x))
313#define __constant_cpu_to_be64(x) ((__u64)(x))
314#define __constant_be64_to_cpu(x) ((__u64)(x))
315#define __constant_cpu_to_be32(x) ((__u32)(x))
316#define __constant_be32_to_cpu(x) ((__u32)(x))
317#define __constant_cpu_to_be16(x) ((__u16)(x))
318#define __constant_be16_to_cpu(x) ((__u16)(x))
319#else
320#ifdef __LITTLE_ENDIAN
321#define __constant_cpu_to_le64(x) ((__u64)(x))
322#define __constant_le64_to_cpu(x) ((__u64)(x))
323#define __constant_cpu_to_le32(x) ((__u32)(x))
324#define __constant_le32_to_cpu(x) ((__u32)(x))
325#define __constant_cpu_to_le16(x) ((__u16)(x))
326#define __constant_le16_to_cpu(x) ((__u16)(x))
327#define __constant_cpu_to_be64(x) ___swab64((x))
328#define __constant_be64_to_cpu(x) ___swab64((x))
329#define __constant_cpu_to_be32(x) ___swab32((x))
330#define __constant_be32_to_cpu(x) ___swab32((x))
331#define __constant_cpu_to_be16(x) ___swab16((x))
332#define __constant_be16_to_cpu(x) ___swab16((x))
333#else
334#error No (recognised) endianness defined (unless it,s PDP)
335#endif
336#endif
337
338#endif
339
340#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
341 #define mod_init_t int __init
342 #define mod_exit_t void
343#else
344 #define mod_init_t static int __init
345 #define mod_exit_t static void __exit
346#endif
347
348#ifndef THIS_MODULE
349#ifdef MODULE
350#define THIS_MODULE (&__this_module)
351#else
352#define THIS_MODULE (NULL)
353#endif
354#endif
355
356#if LINUX_VERSION_CODE < 0x20300
357#include <linux/interrupt.h>
358#define spin_lock_bh(lock) do {start_bh_atomic();spin_lock(lock);}while(0)
359#define spin_unlock_bh(lock) do {spin_unlock(lock);end_bh_atomic();}while(0)
360#else
361#include <asm/softirq.h>
362#include <linux/spinlock.h>
363#endif
364
365#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
366#define set_current_state(state_value) \
367 do { current->state = (state_value); } while (0)
368#endif
369
370#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0)
371static inline int invalidate_device(kdev_t dev, int do_sync) {
372
373 if (do_sync)
374 fsync_dev(dev);
375
376 invalidate_buffers(dev);
377 return 0;
378}
379#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
380static inline int invalidate_device(kdev_t dev, int do_sync) {
381 struct super_block *sb = get_super(dev);
382 int res = 0;
383
384 if (do_sync)
385 fsync_dev(dev);
386
387 if (sb)
388 res = invalidate_inodes(sb);
389
390 invalidate_buffers(dev);
391 return res;
392}
393#endif
394
395#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
396#undef min
397#undef max
398#undef min_t
399#undef max_t
400
401
402
403
404
405#define min(x,y) ({ \
406 const typeof(x) _x = (x); \
407 const typeof(y) _y = (y); \
408 (void) (&_x == &_y); \
409 _x < _y ? _x : _y; })
410
411#define max(x,y) ({ \
412 const typeof(x) _x = (x); \
413 const typeof(y) _y = (y); \
414 (void) (&_x == &_y); \
415 _x > _y ? _x : _y; })
416
417
418
419
420
421
422
423#define min_t(type,x,y) \
424 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
425#define max_t(type,x,y) \
426 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
427#endif
428
429#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,7)
430struct completion {
431 struct semaphore s;
432};
433
434#define complete(c) up(&(c)->s)
435#define wait_for_completion(c) down(&(c)->s)
436#define init_completion(c) init_MUTEX_LOCKED(&(c)->s);
437
438#endif
439
440#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9)
441
442#define complete_and_exit(c, r) do { complete(c); do_exit(r); } while(0)
443#endif
444
445#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9) || \
446 (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) && !defined(__rh_config_h__))
447
448#include <linux/genhd.h>
449
450static inline void add_gendisk(struct gendisk *gp)
451{
452 gp->next = gendisk_head;
453 gendisk_head = gp;
454}
455
456static inline void del_gendisk(struct gendisk *gp)
457{
458 struct gendisk *gd, **gdp;
459
460 for (gdp = &gendisk_head; *gdp; gdp = &((*gdp)->next))
461 if (*gdp == gp) {
462 gd = *gdp; *gdp = gd->next;
463 break;
464 }
465}
466#endif
467
468#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) && defined(MODULE)
469
470#define module_init(func) \
471mod_init_t init_module(void) { \
472 return func(); \
473}
474
475#define module_exit(func) \
476mod_exit_t cleanup_module(void) { \
477 return func(); \
478}
479#endif
480
481#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9) || \
482 (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) && !defined(__rh_config_h__))
483#define MODULE_LICENSE(x)
484#endif
485
486
487
488#if 0 && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,5)
489#include <linux/sched.h>
490static inline void __recalc_sigpending(void)
491{
492 recalc_sigpending(current);
493}
494#undef recalc_sigpending
495#define recalc_sigpending() __recalc_sigpending ()
496#endif
497
498#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,5)
499#define parent_ino(d) ((d)->d_parent->d_inode->i_ino)
500#endif
501
502#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,3)
503#define need_resched() (current->need_resched)
504#define cond_resched() do { if need_resched() schedule(); } while(0)
505#endif
506
507#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19)
508#ifndef yield
509#define yield() do { set_current_state(TASK_RUNNING); schedule(); } while(0)
510#endif
511#ifndef minor
512#define major(d) (MAJOR(to_kdev_t(d)))
513#define minor(d) (MINOR(to_kdev_t(d)))
514#endif
515#ifndef mk_kdev
516#define mk_kdev(ma,mi) MKDEV(ma,mi)
517#define kdev_t_to_nr(x) (x)
518#endif
519#endif
520
521#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
522
523#define set_user_nice(tsk, n) do { (tsk)->priority = 20-(n); } while(0)
524#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,4,21) && !defined(RED_HAT_LINUX_KERNEL)
525#define set_user_nice(tsk, n) do { (tsk)->nice = n; } while(0)
526#endif
527
528#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,21)
529#define rq_data_dir(x) ((x)->cmd)
530#endif
531
532#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
533
534#define IS_REQ_CMD(req) (1)
535
536#define QUEUE_LOCK(q) (&io_request_lock)
537
538#define BLK_INIT_QUEUE(q, req, lock) blk_init_queue((q), (req))
539
540#else
541
542#define IS_REQ_CMD(req) ((req)->flags & REQ_CMD)
543
544#define QUEUE_LOCK(q) ((q)->queue_lock)
545
546#define BLK_INIT_QUEUE(q, req, lock) blk_init_queue((q), (req), (lock))
547
548#endif
549
550
551
552
553
554
555#if LINUX_VERSION_CODE < 0x20300
556#define QUEUE_PLUGGED (blk_dev[MAJOR_NR].plug_tq.sync)
557#elif LINUX_VERSION_CODE < 0x20500
558#define QUEUE_PLUGGED (blk_dev[MAJOR_NR].request_queue.plugged)
559#else
560#define QUEUE_PLUGGED (blk_queue_plugged(QUEUE))
561#endif
562
563#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,14)
564#define BLK_INC_USE_COUNT MOD_INC_USE_COUNT
565#define BLK_DEC_USE_COUNT MOD_DEC_USE_COUNT
566#else
567#define BLK_INC_USE_COUNT do {} while(0)
568#define BLK_DEC_USE_COUNT do {} while(0)
569#endif
570
571#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,12)
572#define PageUptodate(x) Page_Uptodate(x)
573#endif
574
575#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,48)
576#define get_seconds() CURRENT_TIME
577#endif
578
579#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,53)
580#define generic_file_readonly_mmap generic_file_mmap
581#endif
582
583#endif
584