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
6 * Sometimes, a #define replaces a "construct" that older kernels
13 * struct semaphore name = MUTEX;
15 * This file then declares the DECLARE_MUTEX macro to compile into the
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:
26 * while newer kernels use
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
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
49 #include <linux/version.h>
51 #if LINUX_VERSION_CODE < 0x020100 /* Less than 2.1.0 */
54 #if LINUX_VERSION_CODE < 0x020200 /* less than 2.2.x */
55 #warning "Please use a 2.2.x kernel. "
57 #if LINUX_VERSION_CODE < 0x020300 /* less than 2.3.x */
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
);
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
)
93 pcibios_read_config_byte (bus
, fn
, PCI_INTERRUPT_LINE
, &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 tty_flip_buffer_push(tty) queue_task(&tty->flip.tqueue, &tq_timer)
108 #define signal_pending(current) (current->signal & ~current->blocked)
109 #define schedule_timeout(to) do {current->timeout = jiffies + (to);schedule ();} while (0)
110 #define time_after(t1,t2) (((long)t1-t2) > 0)
113 #define test_and_set_bit(nr, addr) set_bit(nr, addr)
114 #define test_and_clear_bit(nr, addr) clear_bit(nr, addr)
116 /* Not yet implemented on 2.0 */
117 #define ASYNC_SPD_SHI -1
118 #define ASYNC_SPD_WARP -1
121 /* Ugly hack: the driver_name doesn't exist in 2.0.x . So we define it
122 to the "name" field that does exist. As long as the assignments are
123 done in the right order, there is nothing to worry about. */
124 #define driver_name name
126 /* Should be in a header somewhere. They are in tty.h on 2.2 */
127 #define TTY_HW_COOK_OUT 14 /* Flag to tell ntty what we can handle */
128 #define TTY_HW_COOK_IN 15 /* in hardware - output and input */
130 /* The return type of a "close" routine. */
132 #define NO_ERROR /* Nothing */
136 /* The 2.2.x compatibility section. */
137 #include <asm/uaccess.h>
140 #define Get_user(a,b) get_user(a,b)
141 #define Put_user(a,b) put_user(a,b)
142 #define get_irq(pdev) pdev->irq
147 #define my_iounmap(x,b) (iounmap((char *)(b)))
152 /* These are new in 2.3. The source now uses 2.3 syntax, and here is
153 the compatibility define... */
154 #define wait_queue_head_t struct wait_queue *
155 #define DECLARE_MUTEX(name) struct semaphore name = MUTEX
156 #define DECLARE_WAITQUEUE(wait, current) \
157 struct wait_queue wait = { current, NULL }