xref: /freebsd-src/sys/compat/linuxkpi/common/include/linux/compat.h (revision c0b8047bdc13040eafb162c4b7b5dba11034ff4b)
18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky  * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Panasas, Inc.
51e3db1deSHans Petter Selasky  * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky  * All rights reserved.
78d59ecb2SHans Petter Selasky  *
88d59ecb2SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky  * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky  * are met:
118d59ecb2SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky  *    disclaimer.
148d59ecb2SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky  *
188d59ecb2SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky  */
29307f78f3SVladimir Kondratyev #ifndef	_LINUXKPI_LINUX_COMPAT_H_
30307f78f3SVladimir Kondratyev #define	_LINUXKPI_LINUX_COMPAT_H_
318d59ecb2SHans Petter Selasky 
321e3db1deSHans Petter Selasky #include <sys/param.h>
331e3db1deSHans Petter Selasky #include <sys/proc.h>
341e3db1deSHans Petter Selasky #include <sys/malloc.h>
351e3db1deSHans Petter Selasky 
36ebe5cf35SHans Petter Selasky struct domainset;
373ce12630SHans Petter Selasky struct thread;
383ce12630SHans Petter Selasky struct task_struct;
393ce12630SHans Petter Selasky 
401e3db1deSHans Petter Selasky extern int linux_alloc_current(struct thread *, int flags);
411e3db1deSHans Petter Selasky extern void linux_free_current(struct task_struct *);
42ebe5cf35SHans Petter Selasky extern struct domainset *linux_get_vm_domain_set(int node);
431e3db1deSHans Petter Selasky 
44*c0b8047bSVladimir Kondratyev #define	__current_unallocated(td)	\
45*c0b8047bSVladimir Kondratyev 	__predict_false((td)->td_lkpi_task == NULL)
46*c0b8047bSVladimir Kondratyev 
471e3db1deSHans Petter Selasky static inline void
linux_set_current(struct thread * td)481e3db1deSHans Petter Selasky linux_set_current(struct thread *td)
491e3db1deSHans Petter Selasky {
50*c0b8047bSVladimir Kondratyev 	if (__current_unallocated(td))
51983ed4f9SMatt Macy 		lkpi_alloc_current(td, M_WAITOK);
521e3db1deSHans Petter Selasky }
531e3db1deSHans Petter Selasky 
541e3db1deSHans Petter Selasky static inline int
linux_set_current_flags(struct thread * td,int flags)551e3db1deSHans Petter Selasky linux_set_current_flags(struct thread *td, int flags)
561e3db1deSHans Petter Selasky {
57*c0b8047bSVladimir Kondratyev 	if (__current_unallocated(td))
58983ed4f9SMatt Macy 		return (lkpi_alloc_current(td, flags));
591e3db1deSHans Petter Selasky 	return (0);
601e3db1deSHans Petter Selasky }
613ce12630SHans Petter Selasky 
6237cda283SEmmanuel Vadot #define	compat_ptr(x)		((void *)(uintptr_t)x)
6337cda283SEmmanuel Vadot #define	ptr_to_compat(x)	((uintptr_t)x)
6437cda283SEmmanuel Vadot 
65*c0b8047bSVladimir Kondratyev typedef void fpu_safe_exec_cb_t(void *ctx);
66*c0b8047bSVladimir Kondratyev void lkpi_fpu_safe_exec(fpu_safe_exec_cb_t func, void *ctx);
67*c0b8047bSVladimir Kondratyev 
68307f78f3SVladimir Kondratyev #endif	/* _LINUXKPI_LINUX_COMPAT_H_ */
69