Merge with 2.3.99-pre1.
[linux-2.6/linux-mips.git] / include / linux / compatmac.h
blob07d8356d075ffe5c9d84ce2d1d5d5a27a5cab17b
1 /*
2 * This header tries to allow you to write 2.3-compatible drivers,
3 * but (using this header) still allows you to run them on 2.2 and
4 * 2.0 kernels.
6 * Sometimes, a #define replaces a "construct" that older kernels
7 * had. For example,
9 * DECLARE_MUTEX(name);
11 * replaces the older
13 * struct semaphore name = MUTEX;
15 * This file then declares the DECLARE_MUTEX macro to compile into the
16 * older version.
18 * In some cases, a macro or function changes the number of arguments.
19 * In that case, there is nothing we can do except define an access
20 * macro that provides the same functionality on both versions of Linux.
22 * This is the case for example with the "get_user" macro 2.0 kernels use:
24 * a = get_user (b);
26 * while newer kernels use
28 * get_user (a,b);
30 * This is unfortunate. We therefore define "Get_user (a,b)" which looks
31 * almost the same as the 2.2+ construct, and translates into the
32 * appropriate sequence for earlier constructs.
34 * Supported by this file are the 2.0 kernels, 2.2 kernels, and the
35 * most recent 2.3 kernel. 2.3 support will be dropped as soon when 2.4
36 * comes out. 2.0 support may someday be dropped. But then again, maybe
37 * not.
39 * I'll try to maintain this, provided that Linus agrees with the setup.
40 * Feel free to mail updates or suggestions.
42 * -- R.E.Wolff@BitWizard.nl
46 #ifndef COMPATMAC_H
47 #define COMPATMAC_H
49 #include <linux/version.h>
51 #if LINUX_VERSION_CODE < 0x020100 /* Less than 2.1.0 */
52 #define TWO_ZERO
53 #else
54 #if LINUX_VERSION_CODE < 0x020200 /* less than 2.2.x */
55 #warning "Please use a 2.2.x kernel. "
56 #else
57 #if LINUX_VERSION_CODE < 0x020300 /* less than 2.3.x */
58 #define TWO_TWO
59 #else
60 #define TWO_THREE
61 #endif
62 #endif
63 #endif
65 #ifdef TWO_ZERO
67 /* Here is the section that makes the 2.2 compatible driver source
68 work for 2.0 too! We mostly try to adopt the "new thingies" from 2.2,
69 and provide for compatibility stuff here if possible. */
71 /* Some 200 days (on intel) */
72 #define MAX_SCHEDULE_TIMEOUT ((long)(~0UL>>1))
74 #include <linux/bios32.h>
76 #define Get_user(a,b) a = get_user(b)
77 #define Put_user(a,b) 0,put_user(a,b)
78 #define copy_to_user(a,b,c) memcpy_tofs(a,b,c)
80 static inline int copy_from_user(void *to,const void *from, int c)
82 memcpy_fromfs(to, from, c);
83 return 0;
86 #define pci_present pcibios_present
87 #define pci_read_config_word pcibios_read_config_word
88 #define pci_read_config_dword pcibios_read_config_dword
90 static inline unsigned char get_irq (unsigned char bus, unsigned char fn)
92 unsigned char t;
93 pcibios_read_config_byte (bus, fn, PCI_INTERRUPT_LINE, &t);
94 return t;
97 static inline void *ioremap(unsigned long base, long length)
99 if (base < 0x100000) return (void *)base;
100 return vremap (base, length);
103 #define my_iounmap(x, b) (((long)x<0x100000)?0:vfree ((void*)x))
105 #define capable(x) suser()
107 #define queue_task queue_task_irq_off
108 #define tty_flip_buffer_push(tty) queue_task(&tty->flip.tqueue, &tq_timer)
109 #define signal_pending(current) (current->signal & ~current->blocked)
110 #define schedule_timeout(to) do {current->timeout = jiffies + (to);schedule ();} while (0)
111 #define time_after(t1,t2) (((long)t1-t2) > 0)
114 #define test_and_set_bit(nr, addr) set_bit(nr, addr)
115 #define test_and_clear_bit(nr, addr) clear_bit(nr, addr)
117 /* Not yet implemented on 2.0 */
118 #define ASYNC_SPD_SHI -1
119 #define ASYNC_SPD_WARP -1
122 /* Ugly hack: the driver_name doesn't exist in 2.0.x . So we define it
123 to the "name" field that does exist. As long as the assignments are
124 done in the right order, there is nothing to worry about. */
125 #define driver_name name
127 /* Should be in a header somewhere. They are in tty.h on 2.2 */
128 #define TTY_HW_COOK_OUT 14 /* Flag to tell ntty what we can handle */
129 #define TTY_HW_COOK_IN 15 /* in hardware - output and input */
131 /* The return type of a "close" routine. */
132 #define INT void
133 #define NO_ERROR /* Nothing */
135 #else
137 /* The 2.2.x compatibility section. */
138 #include <asm/uaccess.h>
141 #define Get_user(a,b) get_user(a,b)
142 #define Put_user(a,b) put_user(a,b)
143 #define get_irq(pdev) pdev->irq
145 #define INT int
146 #define NO_ERROR 0
148 #define my_iounmap(x,b) (iounmap((char *)(b)))
150 #endif
152 #ifndef TWO_THREE
153 /* These are new in 2.3. The source now uses 2.3 syntax, and here is
154 the compatibility define... */
155 #define wait_queue_head_t struct wait_queue *
156 #define DECLARE_MUTEX(name) struct semaphore name = MUTEX
157 #define DECLARE_WAITQUEUE(wait, current) \
158 struct wait_queue wait = { current, NULL }
160 #endif
163 #endif