File: /usr/src/linux/include/linux/compatmac.h

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. 
5        *
6        * Sometimes, a #define replaces a "construct" that older kernels
7        * had. For example, 
8        *
9        *       DECLARE_MUTEX(name);
10        *
11        * replaces the older 
12        *
13        *       struct semaphore name = MUTEX;
14        *
15        * This file then declares the DECLARE_MUTEX macro to compile into the 
16        * older version. 
17        * 
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. 
21        * 
22        * This is the case for example with the "get_user" macro 2.0 kernels use:
23        *
24        *          a = get_user (b);
25        *  
26        * while newer kernels use 
27        * 
28        *          get_user (a,b);
29        *
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. 
33        * 
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. 
38        *
39        * I'll try to maintain this, provided that Linus agrees with the setup. 
40        * Feel free to mail updates or suggestions. 
41        *
42        * -- R.E.Wolff@BitWizard.nl
43        *
44        */
45     
46     #ifndef COMPATMAC_H
47     #define COMPATMAC_H
48     
49     #include <linux/version.h>
50     
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
64     
65     #ifdef TWO_ZERO
66     
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. */
70     
71     /* Some 200 days (on intel) */
72     #define MAX_SCHEDULE_TIMEOUT     ((long)(~0UL>>1))
73     
74     #include <linux/bios32.h>
75     
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)
79     
80     static inline int copy_from_user(void *to,const void *from, int c) 
81     {
82       memcpy_fromfs(to, from, c);
83       return 0;
84     }
85     
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
89     
90     static inline unsigned char get_irq (unsigned char bus, unsigned char fn)
91     {
92     	unsigned char t; 
93     	pcibios_read_config_byte (bus, fn, PCI_INTERRUPT_LINE, &t);
94     	return t;
95     }
96     
97     static inline void *ioremap(unsigned long base, long length)
98     {
99     	if (base < 0x100000) return (void *)base;
100     	return vremap (base, length);
101     }
102     
103     #define my_iounmap(x, b)             (((long)x<0x100000)?0:vfree ((void*)x))
104     
105     #define capable(x)                   suser()
106     
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)
111     
112     
113     #define test_and_set_bit(nr, addr)   set_bit(nr, addr)
114     #define test_and_clear_bit(nr, addr) clear_bit(nr, addr)
115     
116     /* Not yet implemented on 2.0 */
117     #define ASYNC_SPD_SHI  -1
118     #define ASYNC_SPD_WARP -1
119     
120     
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 
125     
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       */
129     
130     /* The return type of a "close" routine. */
131     #define INT                   void
132     #define NO_ERROR              /* Nothing */
133     
134     #else
135     
136     /* The 2.2.x compatibility section. */
137     #include <asm/uaccess.h>
138     
139     
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
143     
144     #define INT                   int
145     #define NO_ERROR              0
146     
147     #define my_iounmap(x,b)       (iounmap((char *)(b)))
148     
149     #endif
150     
151     #ifndef TWO_THREE
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 }
158     
159     #endif
160     
161     
162     #endif
163