compat: Fix autoconf probe for pcie_mpss
[~emulex/for-vlad/old/compat.git] / compat / compat-2.6.28.c
1 /*
2  * Copyright 2007       Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * Compatibility file for Linux wireless for kernels 2.6.28.
9  */
10
11 #include <linux/compat.h>
12 #include <linux/tty.h>
13 #include <asm/poll.h>
14
15 /* 2.6.28 compat code goes here */
16
17 void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
18 {
19         /*
20          * Make sure the BAR is actually a memory resource, not an IO resource
21          */
22         if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
23                 WARN_ON(1);
24                 return NULL;
25         }
26         return ioremap_nocache(pci_resource_start(pdev, bar),
27                                      pci_resource_len(pdev, bar));
28 }
29 EXPORT_SYMBOL_GPL(pci_ioremap_bar);
30
31 static unsigned long round_jiffies_common(unsigned long j, int cpu,
32                 bool force_up)
33 {
34         int rem;
35         unsigned long original = j;
36
37         /*
38          * We don't want all cpus firing their timers at once hitting the
39          * same lock or cachelines, so we skew each extra cpu with an extra
40          * 3 jiffies. This 3 jiffies came originally from the mm/ code which
41          * already did this.
42          * The skew is done by adding 3*cpunr, then round, then subtract this
43          * extra offset again.
44          */
45         j += cpu * 3;
46
47         rem = j % HZ;
48
49         /*
50          * If the target jiffie is just after a whole second (which can happen
51          * due to delays of the timer irq, long irq off times etc etc) then
52          * we should round down to the whole second, not up. Use 1/4th second
53          * as cutoff for this rounding as an extreme upper bound for this.
54          * But never round down if @force_up is set.
55          */
56         if (rem < HZ/4 && !force_up) /* round down */
57                 j = j - rem;
58         else /* round up */
59                 j = j - rem + HZ;
60
61         /* now that we have rounded, subtract the extra skew again */
62         j -= cpu * 3;
63
64         if (j <= jiffies) /* rounding ate our timeout entirely; */
65                 return original;
66         return j;
67 }
68
69 /**
70  * round_jiffies_up - function to round jiffies up to a full second
71  * @j: the time in (absolute) jiffies that should be rounded
72  *
73  * This is the same as round_jiffies() except that it will never
74  * round down.  This is useful for timeouts for which the exact time
75  * of firing does not matter too much, as long as they don't fire too
76  * early.
77  */
78 unsigned long round_jiffies_up(unsigned long j)
79 {
80         return round_jiffies_common(j, raw_smp_processor_id(), true);
81 }
82 EXPORT_SYMBOL_GPL(round_jiffies_up);
83
84 void v2_6_28_skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
85                 int size)
86 {
87         skb_fill_page_desc(skb, i, page, off, size);
88         skb->len += size;
89         skb->data_len += size;
90         skb->truesize += size;
91 }
92 EXPORT_SYMBOL_GPL(v2_6_28_skb_add_rx_frag);
93
94 void tty_write_unlock(struct tty_struct *tty)
95 {
96         mutex_unlock(&tty->atomic_write_lock);
97         wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
98 }
99
100 int tty_write_lock(struct tty_struct *tty, int ndelay)
101 {
102         if (!mutex_trylock(&tty->atomic_write_lock)) {
103                 if (ndelay)
104                         return -EAGAIN;
105                 if (mutex_lock_interruptible(&tty->atomic_write_lock))
106                         return -ERESTARTSYS;
107         }
108         return 0;
109 }
110
111 /**
112  *      send_prio_char          -       send priority character
113  *
114  *      Send a high priority character to the tty even if stopped
115  *
116  *      Locking: none for xchar method, write ordering for write method.
117  */
118
119 static int send_prio_char(struct tty_struct *tty, char ch)
120 {
121         int     was_stopped = tty->stopped;
122
123 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26))
124         if (tty->ops->send_xchar) {
125                 tty->ops->send_xchar(tty, ch);
126 #else
127         if (tty->driver->send_xchar) {
128                 tty->driver->send_xchar(tty, ch);
129 #endif
130                 return 0;
131         }
132
133         if (tty_write_lock(tty, 0) < 0)
134                 return -ERESTARTSYS;
135
136         if (was_stopped)
137                 start_tty(tty);
138 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26))
139         tty->ops->write(tty, &ch, 1);
140 #else
141         tty->driver->write(tty, &ch, 1);
142 #endif
143         if (was_stopped)
144                 stop_tty(tty);
145         tty_write_unlock(tty);
146         return 0;
147 }
148
149 int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
150                        unsigned int cmd, unsigned long arg)
151 {
152 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26))
153         unsigned long flags;
154 #endif
155         int retval;
156
157         switch (cmd) {
158         case TCXONC:
159                 retval = tty_check_change(tty);
160                 if (retval)
161                         return retval;
162                 switch (arg) {
163                 case TCOOFF:
164                         if (!tty->flow_stopped) {
165                                 tty->flow_stopped = 1;
166                                 stop_tty(tty);
167                         }
168                         break;
169                 case TCOON:
170                         if (tty->flow_stopped) {
171                                 tty->flow_stopped = 0;
172                                 start_tty(tty);
173                         }
174                         break;
175                 case TCIOFF:
176                         if (STOP_CHAR(tty) != __DISABLED_CHAR)
177                                 return send_prio_char(tty, STOP_CHAR(tty));
178                         break;
179                 case TCION:
180                         if (START_CHAR(tty) != __DISABLED_CHAR)
181                                 return send_prio_char(tty, START_CHAR(tty));
182                         break;
183                 default:
184                         return -EINVAL;
185                 }
186                 return 0;
187         case TCFLSH:
188                 return tty_perform_flush(tty, arg);
189         case TIOCPKT:
190         {
191                 int pktmode;
192
193                 if (tty->driver->type != TTY_DRIVER_TYPE_PTY ||
194                     tty->driver->subtype != PTY_TYPE_MASTER)
195                         return -ENOTTY;
196                 if (get_user(pktmode, (int __user *) arg))
197                         return -EFAULT;
198 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26))
199                 spin_lock_irqsave(&tty->ctrl_lock, flags);
200 #endif
201                 if (pktmode) {
202                         if (!tty->packet) {
203                                 tty->packet = 1;
204                                 tty->link->ctrl_status = 0;
205                         }
206                 } else
207                         tty->packet = 0;
208 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26))
209                 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
210 #endif
211                 return 0;
212         }
213         default:
214                 /* Try the mode commands */
215                 return tty_mode_ioctl(tty, file, cmd, arg);
216         }
217 }
218 EXPORT_SYMBOL_GPL(n_tty_ioctl_helper);
219
220 /**
221  * pci_wake_from_d3 - enable/disable device to wake up from D3_hot or D3_cold
222  * @dev: PCI device to prepare
223  * @enable: True to enable wake-up event generation; false to disable
224  *
225  * Many drivers want the device to wake up the system from D3_hot or D3_cold
226  * and this function allows them to set that up cleanly - pci_enable_wake()
227  * should not be called twice in a row to enable wake-up due to PCI PM vs ACPI
228  * ordering constraints.
229  *
230  * This function only returns error code if the device is not capable of
231  * generating PME# from both D3_hot and D3_cold, and the platform is unable to
232  * enable wake-up power for it.
233  */
234 int pci_wake_from_d3(struct pci_dev *dev, bool enable)
235 {
236         return pci_pme_capable(dev, PCI_D3cold) ?
237                         pci_enable_wake(dev, PCI_D3cold, enable) :
238                         pci_enable_wake(dev, PCI_D3hot, enable);
239 }
240 EXPORT_SYMBOL_GPL(pci_wake_from_d3);
241