Xenomai  3.0.5
wrappers.h
1 /*
2  * Copyright (C) 2005-2012 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_ASM_GENERIC_WRAPPERS_H
20 
21 #include <linux/version.h>
22 
23 #ifdef CONFIG_IPIPE_LEGACY
24 #error "CONFIG_IPIPE_LEGACY must be switched off"
25 #endif
26 
27 #define COBALT_BACKPORT(__sym) __cobalt_backport_ ##__sym
28 
29 /*
30  * To keep the #ifdefery as readable as possible, please:
31  *
32  * - keep the conditional structure flat, no nesting (e.g. do not fold
33  * the pre-3.11 conditions into the pre-3.14 ones).
34  * - group all wrappers for a single kernel revision.
35  * - list conditional blocks in order of kernel release, latest first
36  * - identify the first kernel release for which the wrapper should
37  * be defined, instead of testing the existence of a preprocessor
38  * symbol, so that obsolete wrappers can be spotted.
39  */
40 
41 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
42 #define in_ia32_syscall() (current_thread_info()->status & TS_COMPAT)
43 #endif
44 
45 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)
46 #define user_msghdr msghdr
47 #endif
48 
49 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0)
50 #include <linux/netdevice.h>
51 
52 #undef alloc_netdev
53 #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
54  alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1)
55 
56 #include <linux/trace_seq.h>
57 
58 static inline unsigned char *
59 trace_seq_buffer_ptr(struct trace_seq *s)
60 {
61  return s->buffer + s->len;
62 }
63 
64 #endif /* < 3.17 */
65 
66 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)
67 #define smp_mb__before_atomic() smp_mb()
68 #define smp_mb__after_atomic() smp_mb()
69 #endif /* < 3.16 */
70 
71 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
72 #define raw_cpu_ptr(v) __this_cpu_ptr(v)
73 #endif /* < 3.15 */
74 
75 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
76 #include <linux/pci.h>
77 
78 #ifdef CONFIG_PCI
79 #define pci_enable_msix_range COBALT_BACKPORT(pci_enable_msix_range)
80 #ifdef CONFIG_PCI_MSI
81 int pci_enable_msix_range(struct pci_dev *dev,
82  struct msix_entry *entries,
83  int minvec, int maxvec);
84 #else /* !CONFIG_PCI_MSI */
85 static inline
86 int pci_enable_msix_range(struct pci_dev *dev,
87  struct msix_entry *entries,
88  int minvec, int maxvec)
89 {
90  return -ENOSYS;
91 }
92 #endif /* !CONFIG_PCI_MSI */
93 #endif /* CONFIG_PCI */
94 #endif /* < 3.14 */
95 
96 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
97 #include <linux/dma-mapping.h>
98 #include <linux/hwmon.h>
99 
100 #define dma_set_mask_and_coherent COBALT_BACKPORT(dma_set_mask_and_coherent)
101 static inline
102 int dma_set_mask_and_coherent(struct device *dev, u64 mask)
103 {
104  int rc = dma_set_mask(dev, mask);
105  if (rc == 0)
106  dma_set_coherent_mask(dev, mask);
107  return rc;
108 }
109 
110 #ifdef CONFIG_HWMON
111 #define hwmon_device_register_with_groups \
112  COBALT_BACKPORT(hwmon_device_register_with_groups)
113 struct device *
114 hwmon_device_register_with_groups(struct device *dev, const char *name,
115  void *drvdata,
116  const struct attribute_group **groups);
117 
118 #define devm_hwmon_device_register_with_groups \
119  COBALT_BACKPORT(devm_hwmon_device_register_with_groups)
120 struct device *
121 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
122  void *drvdata,
123  const struct attribute_group **groups);
124 #endif /* !CONFIG_HWMON */
125 
126 #define reinit_completion(__x) INIT_COMPLETION(*(__x))
127 
128 #endif /* < 3.13 */
129 
130 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
131 #define DEVICE_ATTR_RW(_name) __ATTR_RW(_name)
132 #define DEVICE_ATTR_RO(_name) __ATTR_RO(_name)
133 #define DEVICE_ATTR_WO(_name) __ATTR_WO(_name)
134 #endif /* < 3.11 */
135 
136 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
137 #error "Xenomai/cobalt requires Linux kernel 3.10 or above"
138 #endif /* < 3.10 */
139 
140 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
141 #define cobalt_get_restart_block(p) (&task_thread_info(p)->restart_block)
142 #else
143 #define cobalt_get_restart_block(p) (&(p)->restart_block)
144 #endif
145 
146 #endif /* _COBALT_ASM_GENERIC_WRAPPERS_H */