/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to driver/compat.h

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-27 00:28:57 UTC
  • Revision ID: csa@suren.me-20150427002857-82fk6r3e8rfgy4wr
First stand-alone ipecamera implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *
3
 
 * @file compat.h
4
 
 * @author Michael Stapelberg
5
 
 * @date 2009-04-05
6
 
 * @brief Contains compatibility definitions for the different linux kernel versions to avoid
7
 
 * putting ifdefs all over the driver code.
8
 
 *
9
 
 */
10
 
#ifndef _COMPAT_H
11
 
#define _COMPAT_H
12
 
 
13
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
14
 
# define __devinit
15
 
# define __devexit
16
 
# define __devinitdata
17
 
#endif
18
 
 
19
 
/* dev_name is the wrapper one needs to use to access what was formerly called
20
 
 * bus_id in struct device. However, before 2.6.27, direct access was necessary,
21
 
 * so we provide our own version. */
22
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
23
 
static inline const char *dev_name(struct device *dev) {
24
 
        return dev->bus_id;
25
 
}
26
 
#endif
27
 
 
28
 
/* SetPageLocked disappeared in v2.6.27 */
29
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
30
 
        #define compat_lock_page SetPageLocked
31
 
        #define compat_unlock_page ClearPageLocked
32
 
#else
33
 
        /* in v2.6.28, __set_page_locked and __clear_page_locked was introduced */
34
 
        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
35
 
                #define compat_lock_page __set_page_locked
36
 
                #define compat_unlock_page __clear_page_locked
37
 
        #else
38
 
                /* However, in v2.6.27 itself, neither of them is there, so
39
 
                 * we need to use our own function fiddling with bits inside
40
 
                 * the page struct :-\ */
41
 
                static inline void compat_lock_page(struct page *page) {
42
 
                        __set_bit(PG_locked, &page->flags);
43
 
                }
44
 
 
45
 
                static inline void compat_unlock_page(struct page *page) {
46
 
                        __clear_bit(PG_locked, &page->flags);
47
 
                }
48
 
        #endif
49
 
#endif
50
 
 
51
 
/* Before 2.6.13, simple_class was the standard interface. Nowadays, it's just called class */
52
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
53
 
 
54
 
        #define class_compat class_simple
55
 
 
56
 
        /* These functions are redirected to their old corresponding functions */
57
 
        #define class_create(module, name) class_simple_create(module, name)
58
 
        #define class_destroy(type) class_simple_destroy(type)
59
 
        #define class_device_destroy(unused, devno) class_simple_device_remove(devno)
60
 
        #define class_device_create(type, unused, devno, devpointer, nameformat, minor, unused) \
61
 
                class_simple_device_add(type, devno, devpointer, nameformat, minor)
62
 
        #define class_set_devdata(classdev, privdata) classdev->class_data = privdata
63
 
        #define DEVICE_ATTR_COMPAT
64
 
        #define sysfs_attr_def_name(name) class_device_attr_##name
65
 
        #define sysfs_attr_def_pointer privdata->class_dev
66
 
        #define SYSFS_GET_FUNCTION(name) ssize_t name(struct class_device *cls, char *buf)
67
 
        #define SYSFS_SET_FUNCTION(name) ssize_t name(struct class_device *cls, const char *buf, size_t count)
68
 
        #define SYSFS_GET_PRIVDATA (pcidriver_privdata_t*)cls->class_data
69
 
 
70
 
#else
71
 
 
72
 
/* In 2.6.26, device.h was changed quite significantly. Luckily, it only affected
73
 
   type/function names, for the most part. */
74
 
//#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
75
 
        #define class_device_attribute device_attribute
76
 
        #define CLASS_DEVICE_ATTR DEVICE_ATTR
77
 
        #define class_device device
78
 
        #define class_data dev
79
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
80
 
        #define class_device_create(type, parent, devno, devpointer, nameformat, minor, privdata) \
81
 
                device_create(type, parent, devno, privdata, nameformat, minor)
82
 
#else
83
 
        #define class_device_create(type, parent, devno, devpointer, nameformat, minor, unused) \
84
 
                device_create(type, parent, devno, nameformat, minor)
85
 
#endif
86
 
        #define class_device_create_file device_create_file
87
 
        #define class_device_remove_file device_remove_file
88
 
        #define class_device_destroy device_destroy
89
 
        #define DEVICE_ATTR_COMPAT struct device_attribute *attr,
90
 
        #define class_set_devdata dev_set_drvdata
91
 
 
92
 
        #define sysfs_attr_def_name(name) dev_attr_##name
93
 
        #define sysfs_attr_def_pointer privdata->class_dev
94
 
        #define SYSFS_GET_FUNCTION(name) ssize_t name(struct device *dev, struct device_attribute *attr, char *buf)
95
 
        #define SYSFS_SET_FUNCTION(name) ssize_t name(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
96
 
        #define SYSFS_GET_PRIVDATA dev_get_drvdata(dev)
97
 
 
98
 
//#endif
99
 
 
100
 
#define class_compat class
101
 
 
102
 
#endif
103
 
 
104
 
/* The arguments of IRQ handlers have been changed in 2.6.19. It's very likely that
105
 
   int irq will disappear somewhen in the future (current is 2.6.29), too. */
106
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
107
 
        #define IRQ_HANDLER_FUNC(name) irqreturn_t name(int irq, void *dev_id)
108
 
#else
109
 
        #define IRQ_HANDLER_FUNC(name) irqreturn_t name(int irq, void *dev_id, struct pt_regs *regs)
110
 
#endif
111
 
 
112
 
/* atomic_inc_return appeared in 2.6.9, at least in CERN scientific linux, provide
113
 
   compatibility wrapper for older kernels */
114
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
115
 
static int atomic_inc_return(atomic_t *variable) {
116
 
        atomic_inc(variable);
117
 
        return atomic_read(variable);
118
 
}
119
 
#endif
120
 
 
121
 
/* sg_set_page is available starting at 2.6.24 */
122
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
123
 
 
124
 
#define sg_set_page(sg, set_page, set_length, set_offset) do { \
125
 
        (sg)->page = set_page; \
126
 
        (sg)->length = set_length; \
127
 
        (sg)->offset = set_offset; \
128
 
} while (0)
129
 
 
130
 
#endif
131
 
 
132
 
/* Before 2.6.20, disable was not an atomic counter, so this check was needed */
133
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
134
 
#define pci_disable_device(pdev) do { \
135
 
        if (pdev->is_enabled) \
136
 
                pci_disable_device(pdev); \
137
 
} while (0)
138
 
#endif
139
 
 
140
 
/* Before 2.6.24, scatter/gather lists did not need to be initialized */
141
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
142
 
        #define sg_init_table(sg, nr_pages)
143
 
#endif
144
 
 
145
 
/* SA_SHIRQ was renamed to IRQF_SHARED in 2.6.24 */
146
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
147
 
        #define request_irq(irq, irq_handler, modname, privdata) request_irq(irq, irq_handler, IRQF_SHARED, modname, privdata)
148
 
#else
149
 
        #define request_irq(irq, irq_handler, modname, privdata) request_irq(irq, irq_handler, SA_SHIRQ, modname, privdata)
150
 
#endif
151
 
 
152
 
/* In 2.6.13, io_remap_page_range was removed in favor for io_remap_pfn_range which works on
153
 
   more platforms and allows more memory space */
154
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
155
 
#define io_remap_pfn_range_compat(vmap, vm_start, bar_addr, bar_length, vm_page_prot) \
156
 
        io_remap_pfn_range(vmap, vm_start, (bar_addr >> PAGE_SHIFT), bar_length, vm_page_prot)
157
 
#else
158
 
#define io_remap_pfn_range_compat(vmap, vm_start, bar_addr, bar_length, vm_page_prot) \
159
 
        io_remap_page_range(vmap, vm_start, bar_addr, bar_length, vm_page_prot)
160
 
#endif
161
 
 
162
 
/* In 2.6.10, remap_pfn_range was introduced, see io_remap_pfn_range_compat */
163
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
164
 
#define remap_pfn_range_compat(vmap, vm_start, bar_addr, bar_length, vm_page_prot) \
165
 
        remap_pfn_range(vmap, vm_start, (bar_addr >> PAGE_SHIFT), bar_length, vm_page_prot)
166
 
 
167
 
#define remap_pfn_range_cpua_compat(vmap, vm_start, cpua, size, vm_page_prot) \
168
 
        remap_pfn_range(vmap, vm_start, page_to_pfn(virt_to_page((void*)cpua)), size, vm_page_prot)
169
 
 
170
 
#else
171
 
#define remap_pfn_range_compat(vmap, vm_start, bar_addr, bar_length, vm_page_prot) \
172
 
        remap_page_range(vmap, vm_start, bar_addr, bar_length, vm_page_prot)
173
 
 
174
 
#define remap_pfn_range_cpua_compat(vmap, vm_start, cpua, size, vm_page_prot) \
175
 
        remap_page_range(vmap, vm_start, virt_to_phys((void*)cpua), size, vm_page_prot)
176
 
#endif
177
 
 
178
 
/**
179
 
 * Go over the pages of the kmem buffer, and mark them as reserved.
180
 
 * This is needed, otherwise mmaping the kernel memory to user space
181
 
 * will fail silently (mmaping /dev/null) when using remap_xx_range.
182
 
 */
183
 
static inline void set_pages_reserved_compat(unsigned long cpua, unsigned long size)
184
 
{
185
 
        /* Starting in 2.6.15, the PG_RESERVED bit was removed.
186
 
           See also http://lwn.net/Articles/161204/ */
187
 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
188
 
        struct page *page, *last_page;
189
 
 
190
 
        page = virt_to_page(cpua);
191
 
        last_page = virt_to_page(cpua + size - 1);
192
 
 
193
 
        for (; page <= last_page; page++)
194
 
               SetPageReserved(page);
195
 
#endif
196
 
}
197
 
 
198
 
#endif