wrappers.h 5.39 KB
Newer Older
1
/*
2
 * Copyright (C) 2005-2012 Philippe Gerum <rpm@xenomai.org>.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * Xenomai is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * Xenomai is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Xenomai; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
19
#ifndef _COBALT_ASM_GENERIC_WRAPPERS_H
20

21
#include <linux/xenomai/wrappers.h>
22 23 24 25 26

#ifdef CONFIG_IPIPE_LEGACY
#error "CONFIG_IPIPE_LEGACY must be switched off"
#endif

27
#define COBALT_BACKPORT(__sym) __cobalt_backport_ ##__sym
28

29 30 31
/*
 * To keep the #ifdefery as readable as possible, please:
 *
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 35
 * - group all wrappers for a single kernel revision.
 * - list conditional blocks in order of kernel release, latest first
36 37 38
 * - identify the first kernel release for which the wrapper should
 *   be defined, instead of testing the existence of a preprocessor
 *   symbol, so that obsolete wrappers can be spotted.
39 40
 */

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)
#define get_compat_sigset(set, compat)					\
({									\
	compat_sigset_t set32;						\
	int ret;							\
									\
	ret = cobalt_copy_from_user(&set32, compat, sizeof(compat_sigset_t)); \
	if (!ret)							\
		sigset_from_compat(set, &set32);			\
	ret;								\
})

#define put_compat_sigset(compat, set, size)				\
({									\
	compat_sigset_t set32;						\
									\
	sigset_to_compat(&set32, set);					\
	cobalt_copy_to_user(compat, &set32, size);			\
})
#endif /* < 4.15 */

62 63 64 65 66 67 68
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
#define raw_copy_to_user(__to, __from, __n)	__copy_to_user_inatomic(__to, __from, __n)
#define raw_copy_from_user(__to, __from, __n)	__copy_from_user_inatomic(__to, __from, __n)
#define raw_put_user(__from, __to)		__put_user_inatomic(__from, __to)
#define raw_get_user(__to, __from)		__get_user_inatomic(__to, __from)
#endif

69 70 71 72
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
#define in_ia32_syscall() (current_thread_info()->status & TS_COMPAT)
#endif

73
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
74 75 76 77 78 79 80 81 82 83 84
#define cobalt_gpiochip_dev(__gc)	((__gc)->dev)
#else
#define cobalt_gpiochip_dev(__gc)	((__gc)->parent)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
#define cobalt_get_restart_block(p)	(&task_thread_info(p)->restart_block)
#else
#define cobalt_get_restart_block(p)	(&(p)->restart_block)
#endif

85 86 87 88
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)
#define user_msghdr msghdr
#endif

89 90
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0)
#include <linux/netdevice.h>
91

92 93 94
#undef alloc_netdev
#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
	alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1)
95 96 97 98 99 100 101 102
 
#include <linux/trace_seq.h>

static inline unsigned char *
trace_seq_buffer_ptr(struct trace_seq *s)
{
	return s->buffer + s->len;
}
103

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#endif /* < 3.17 */

#if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)
#define smp_mb__before_atomic()  smp_mb()
#define smp_mb__after_atomic()   smp_mb()
#endif /* < 3.16 */

#if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
#define raw_cpu_ptr(v)	__this_cpu_ptr(v)
#endif /* < 3.15 */

#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
#include <linux/pci.h>

#ifdef CONFIG_PCI
119
#define pci_enable_msix_range COBALT_BACKPORT(pci_enable_msix_range)
120 121
#ifdef CONFIG_PCI_MSI
int pci_enable_msix_range(struct pci_dev *dev,
122 123 124 125 126 127 128 129 130 131 132 133
			  struct msix_entry *entries,
			  int minvec, int maxvec);
#else /* !CONFIG_PCI_MSI */
static inline
int pci_enable_msix_range(struct pci_dev *dev,
			  struct msix_entry *entries,
			  int minvec, int maxvec)
{
	return -ENOSYS;
}
#endif /* !CONFIG_PCI_MSI */
#endif /* CONFIG_PCI */
134
#endif /* < 3.14 */
135

136 137 138 139
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
#include <linux/dma-mapping.h>
#include <linux/hwmon.h>

140 141 142
#define dma_set_mask_and_coherent COBALT_BACKPORT(dma_set_mask_and_coherent)
static inline
int dma_set_mask_and_coherent(struct device *dev, u64 mask)
143 144 145 146 147 148 149 150 151
{
	int rc = dma_set_mask(dev, mask);
	if (rc == 0)
		dma_set_coherent_mask(dev, mask);
	return rc;
}

#ifdef CONFIG_HWMON
#define hwmon_device_register_with_groups \
152
	COBALT_BACKPORT(hwmon_device_register_with_groups)
153 154 155 156 157 158
struct device *
hwmon_device_register_with_groups(struct device *dev, const char *name,
				void *drvdata,
				const struct attribute_group **groups);

#define devm_hwmon_device_register_with_groups \
159
	COBALT_BACKPORT(devm_hwmon_device_register_with_groups)
160 161 162 163
struct device *
devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
				void *drvdata,
				const struct attribute_group **groups);
164 165 166 167 168
#endif /* !CONFIG_HWMON */

#define reinit_completion(__x)	INIT_COMPLETION(*(__x))

#endif /* < 3.13 */
169

170 171 172 173 174
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
#define DEVICE_ATTR_RW(_name)	__ATTR_RW(_name)
#define DEVICE_ATTR_RO(_name)	__ATTR_RO(_name)
#define DEVICE_ATTR_WO(_name)	__ATTR_WO(_name)
#endif /* < 3.11 */
175

176 177 178
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
#error "Xenomai/cobalt requires Linux kernel 3.10 or above"
#endif /* < 3.10 */
179

180
#endif /* _COBALT_ASM_GENERIC_WRAPPERS_H */