Xenomai  3.1
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/xenomai/wrappers.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,15,0)
42 #define get_compat_sigset(set, compat) \
43 ({ \
44  compat_sigset_t set32; \
45  int ret; \
46  \
47  ret = cobalt_copy_from_user(&set32, compat, sizeof(compat_sigset_t)); \
48  if (!ret) \
49  sigset_from_compat(set, &set32); \
50  ret; \
51 })
52 
53 #define put_compat_sigset(compat, set, size) \
54 ({ \
55  compat_sigset_t set32; \
56  \
57  sigset_to_compat(&set32, set); \
58  cobalt_copy_to_user(compat, &set32, size); \
59 })
60 #endif /* < 4.15 */
61 
62 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
63 #define raw_copy_to_user(__to, __from, __n) __copy_to_user_inatomic(__to, __from, __n)
64 #define raw_copy_from_user(__to, __from, __n) __copy_from_user_inatomic(__to, __from, __n)
65 #define raw_put_user(__from, __to) __put_user_inatomic(__from, __to)
66 #define raw_get_user(__to, __from) __get_user_inatomic(__to, __from)
67 #endif
68 
69 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
70 #define in_ia32_syscall() (current_thread_info()->status & TS_COMPAT)
71 #endif
72 
73 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
74 #define cobalt_gpiochip_dev(__gc) ((__gc)->dev)
75 #else
76 #define cobalt_gpiochip_dev(__gc) ((__gc)->parent)
77 #endif
78 
79 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
80 #define cobalt_get_restart_block(p) (&task_thread_info(p)->restart_block)
81 #else
82 #define cobalt_get_restart_block(p) (&(p)->restart_block)
83 #endif
84 
85 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)
86 #define user_msghdr msghdr
87 #endif
88 
89 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0)
90 #include <linux/netdevice.h>
91 
92 #undef alloc_netdev
93 #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
94  alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1)
95 
96 #include <linux/trace_seq.h>
97 
98 static inline unsigned char *
99 trace_seq_buffer_ptr(struct trace_seq *s)
100 {
101  return s->buffer + s->len;
102 }
103 
104 #endif /* < 3.17 */
105 
106 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)
107 #define smp_mb__before_atomic() smp_mb()
108 #define smp_mb__after_atomic() smp_mb()
109 #endif /* < 3.16 */
110 
111 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
112 #define raw_cpu_ptr(v) __this_cpu_ptr(v)
113 #endif /* < 3.15 */
114 
115 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
116 #include <linux/pci.h>
117 
118 #ifdef CONFIG_PCI
119 #define pci_enable_msix_range COBALT_BACKPORT(pci_enable_msix_range)
120 #ifdef CONFIG_PCI_MSI
121 int pci_enable_msix_range(struct pci_dev *dev,
122  struct msix_entry *entries,
123  int minvec, int maxvec);
124 #else /* !CONFIG_PCI_MSI */
125 static inline
126 int pci_enable_msix_range(struct pci_dev *dev,
127  struct msix_entry *entries,
128  int minvec, int maxvec)
129 {
130  return -ENOSYS;
131 }
132 #endif /* !CONFIG_PCI_MSI */
133 #endif /* CONFIG_PCI */
134 #endif /* < 3.14 */
135 
136 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
137 #include <linux/dma-mapping.h>
138 #include <linux/hwmon.h>
139 
140 #define dma_set_mask_and_coherent COBALT_BACKPORT(dma_set_mask_and_coherent)
141 static inline
142 int dma_set_mask_and_coherent(struct device *dev, u64 mask)
143 {
144  int rc = dma_set_mask(dev, mask);
145  if (rc == 0)
146  dma_set_coherent_mask(dev, mask);
147  return rc;
148 }
149 
150 #ifdef CONFIG_HWMON
151 #define hwmon_device_register_with_groups \
152  COBALT_BACKPORT(hwmon_device_register_with_groups)
153 struct device *
154 hwmon_device_register_with_groups(struct device *dev, const char *name,
155  void *drvdata,
156  const struct attribute_group **groups);
157 
158 #define devm_hwmon_device_register_with_groups \
159  COBALT_BACKPORT(devm_hwmon_device_register_with_groups)
160 struct device *
161 devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
162  void *drvdata,
163  const struct attribute_group **groups);
164 #endif /* !CONFIG_HWMON */
165 
166 #define reinit_completion(__x) INIT_COMPLETION(*(__x))
167 
168 #endif /* < 3.13 */
169 
170 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
171 #define DEVICE_ATTR_RW(_name) __ATTR_RW(_name)
172 #define DEVICE_ATTR_RO(_name) __ATTR_RO(_name)
173 #define DEVICE_ATTR_WO(_name) __ATTR_WO(_name)
174 #endif /* < 3.11 */
175 
176 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
177 #error "Xenomai/cobalt requires Linux kernel 3.10 or above"
178 #endif /* < 3.10 */
179 
180 #endif /* _COBALT_ASM_GENERIC_WRAPPERS_H */