compat/nes: Adding pci_zalloc_consistent backport
[compat-rdma/compat.git] / compat / compat-2.6.25.c
1 /*
2  * Copyright 2007-2012  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.25.
9  */
10
11 #include <linux/miscdevice.h>
12 #include <linux/pci.h>
13
14 /*
15  * To backport b718989d correctly pcibios_enable_device()
16  * is required but we don't have access to it on modules
17  * as its an architecture specific routine that is not
18  * exported and as such only core kernel code has access
19  * to it. We implement a sloppy work around for backporting
20  * this.
21  */
22 int pci_enable_device_mem(struct pci_dev *dev)
23 {
24         int bars = pci_select_bars(dev, IORESOURCE_MEM);
25
26         return pci_enable_device_bars(dev, bars);
27 }
28 EXPORT_SYMBOL_GPL(pci_enable_device_mem);
29
30 /**
31  * The following things are out of ./lib/vsprintf.c
32  * The new iwlwifi driver is using them.
33  */
34
35 /**
36  * strict_strtoul - convert a string to an unsigned long strictly
37  * @cp: The string to be converted
38  * @base: The number base to use
39  * @res: The converted result value
40  *
41  * strict_strtoul converts a string to an unsigned long only if the
42  * string is really an unsigned long string, any string containing
43  * any invalid char at the tail will be rejected and -EINVAL is returned,
44  * only a newline char at the tail is acceptible because people generally
45  * change a module parameter in the following way:
46  *
47  *      echo 1024 > /sys/module/e1000/parameters/copybreak
48  *
49  * echo will append a newline to the tail.
50  *
51  * It returns 0 if conversion is successful and *res is set to the converted
52  * value, otherwise it returns -EINVAL and *res is set to 0.
53  *
54  * simple_strtoul just ignores the successive invalid characters and
55  * return the converted value of prefix part of the string.
56  */
57 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
58
59 /**
60  * strict_strtol - convert a string to a long strictly
61  * @cp: The string to be converted
62  * @base: The number base to use
63  * @res: The converted result value
64  *
65  * strict_strtol is similiar to strict_strtoul, but it allows the first
66  * character of a string is '-'.
67  *
68  * It returns 0 if conversion is successful and *res is set to the converted
69  * value, otherwise it returns -EINVAL and *res is set to 0.
70  */
71 int strict_strtol(const char *cp, unsigned int base, long *res);
72
73 #define define_strict_strtoux(type, valtype)                            \
74 int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\
75 {                                                                       \
76         char *tail;                                                     \
77         valtype val;                                                    \
78         size_t len;                                                     \
79                                                                         \
80         *res = 0;                                                       \
81         len = strlen(cp);                                               \
82         if (len == 0)                                                   \
83                 return -EINVAL;                                         \
84                                                                         \
85         val = simple_strtou##type(cp, &tail, base);                     \
86         if ((*tail == '\0') ||                                          \
87                 ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\
88                 *res = val;                                             \
89                 return 0;                                               \
90         }                                                               \
91                                                                         \
92         return -EINVAL;                                                 \
93 }                                                                       \
94
95 #define define_strict_strtox(type, valtype)                             \
96 int strict_strto##type(const char *cp, unsigned int base, valtype *res) \
97 {                                                                       \
98         int ret;                                                        \
99         if (*cp == '-') {                                               \
100                 ret = strict_strtou##type(cp+1, base, res);             \
101                 if (!ret)                                               \
102                         *res = -(*res);                                 \
103         } else                                                          \
104                 ret = strict_strtou##type(cp, base, res);               \
105                                                                         \
106         return ret;                                                     \
107 }                                                                       \
108
109 define_strict_strtoux(l, unsigned long)
110 define_strict_strtox(l, long)
111
112 EXPORT_SYMBOL_GPL(strict_strtoul);
113 EXPORT_SYMBOL_GPL(strict_strtol);
114