xref: /dflybsd-src/sys/dev/drm/include/asm/uaccess.h (revision 6f3edb89fae4ddaab1dddd2a985e4f5af9762da9)
15e6a4268SFrançois Tigeot /*-
25e6a4268SFrançois Tigeot  * Copyright (c) 2010 Isilon Systems, Inc.
35e6a4268SFrançois Tigeot  * Copyright (c) 2010 iX Systems, Inc.
45e6a4268SFrançois Tigeot  * Copyright (c) 2010 Panasas, Inc.
5be4c44ceSFrançois Tigeot  * Copyright (c) 2015-2020 François Tigeot <ftigeot@wolfpond.org>
65e6a4268SFrançois Tigeot  * All rights reserved.
75e6a4268SFrançois Tigeot  *
85e6a4268SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
95e6a4268SFrançois Tigeot  * modification, are permitted provided that the following conditions
105e6a4268SFrançois Tigeot  * are met:
115e6a4268SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
125e6a4268SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
135e6a4268SFrançois Tigeot  *    disclaimer.
145e6a4268SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
155e6a4268SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
165e6a4268SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
175e6a4268SFrançois Tigeot  *
185e6a4268SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
195e6a4268SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
205e6a4268SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
215e6a4268SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
225e6a4268SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
235e6a4268SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245e6a4268SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255e6a4268SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
265e6a4268SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
275e6a4268SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
285e6a4268SFrançois Tigeot  */
295e6a4268SFrançois Tigeot #ifndef _ASM_UACCESS_H_
305e6a4268SFrançois Tigeot #define _ASM_UACCESS_H_
315e6a4268SFrançois Tigeot 
32b82fa94eSFrançois Tigeot #define	get_user(_x, _p)	-copyin((_p), &(_x), sizeof(*(_p)))
33b82fa94eSFrançois Tigeot 
345e6a4268SFrançois Tigeot static inline long
copy_to_user(void * to,const void * from,unsigned long n)355e6a4268SFrançois Tigeot copy_to_user(void *to, const void *from, unsigned long n)
365e6a4268SFrançois Tigeot {
375e6a4268SFrançois Tigeot 	if (copyout(from, to, n) != 0)
385e6a4268SFrançois Tigeot 		return n;
395e6a4268SFrançois Tigeot 	return 0;
405e6a4268SFrançois Tigeot }
415e6a4268SFrançois Tigeot 
425e6a4268SFrançois Tigeot static inline long
copy_from_user(void * to,const void * from,unsigned long n)435e6a4268SFrançois Tigeot copy_from_user(void *to, const void *from, unsigned long n)
445e6a4268SFrançois Tigeot {
455e6a4268SFrançois Tigeot 	if (copyin(from, to, n) != 0)
465e6a4268SFrançois Tigeot 		return n;
475e6a4268SFrançois Tigeot 	return 0;
485e6a4268SFrançois Tigeot }
495e6a4268SFrançois Tigeot 
505205d08bSFrançois Tigeot static inline int
__copy_to_user(void * to,const void * from,unsigned len)515205d08bSFrançois Tigeot __copy_to_user(void *to, const void *from, unsigned len)
525205d08bSFrançois Tigeot {
535205d08bSFrançois Tigeot 	if (copyout(from, to, len))
545205d08bSFrançois Tigeot 		return len;
555205d08bSFrançois Tigeot 	return 0;
565205d08bSFrançois Tigeot }
575205d08bSFrançois Tigeot 
585205d08bSFrançois Tigeot static inline unsigned long
__copy_from_user(void * to,const void * from,unsigned len)595205d08bSFrançois Tigeot __copy_from_user(void *to, const void *from, unsigned len)
605205d08bSFrançois Tigeot {
615205d08bSFrançois Tigeot 	if (copyin(from, to, len))
625205d08bSFrançois Tigeot 		return len;
635205d08bSFrançois Tigeot 	return 0;
645205d08bSFrançois Tigeot }
655205d08bSFrançois Tigeot 
665205d08bSFrançois Tigeot static inline int
__copy_from_user_inatomic(void * dst,const void __user * src,unsigned size)67ed88fbfaSFrançois Tigeot __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
68ed88fbfaSFrançois Tigeot {
69ed88fbfaSFrançois Tigeot 	if (copyin_nofault(src, dst, size))
70ed88fbfaSFrançois Tigeot 		return size;
71ed88fbfaSFrançois Tigeot 	return 0;
72ed88fbfaSFrançois Tigeot }
73ed88fbfaSFrançois Tigeot 
74ed88fbfaSFrançois Tigeot static inline int
__copy_to_user_inatomic(void __user * to,const void * from,unsigned n)755205d08bSFrançois Tigeot __copy_to_user_inatomic(void __user *to, const void *from, unsigned n)
765205d08bSFrançois Tigeot {
775205d08bSFrançois Tigeot 	return (copyout_nofault(from, to, n) != 0 ? n : 0);
785205d08bSFrançois Tigeot }
795205d08bSFrançois Tigeot 
805205d08bSFrançois Tigeot static inline unsigned long
__copy_from_user_inatomic_nocache(void * to,const void __user * from,unsigned long n)815205d08bSFrançois Tigeot __copy_from_user_inatomic_nocache(void *to, const void __user *from,
825205d08bSFrançois Tigeot     unsigned long n)
835205d08bSFrançois Tigeot {
845205d08bSFrançois Tigeot 	/*
855205d08bSFrançois Tigeot 	 * XXXKIB.  Equivalent Linux function is implemented using
865205d08bSFrançois Tigeot 	 * MOVNTI for aligned moves.  For unaligned head and tail,
875205d08bSFrançois Tigeot 	 * normal move is performed.  As such, it is not incorrect, if
885205d08bSFrançois Tigeot 	 * only somewhat slower, to use normal copyin.  All uses
895205d08bSFrançois Tigeot 	 * except shmem_pwrite_fast() have the destination mapped WC.
905205d08bSFrançois Tigeot 	 */
915205d08bSFrançois Tigeot 	return ((copyin_nofault(__DECONST(void *, from), to, n) != 0 ? n : 0));
925205d08bSFrançois Tigeot }
935205d08bSFrançois Tigeot 
942cecdd68SFrançois Tigeot #define __get_user(x, ptr)	get_user((x), (ptr))
952cecdd68SFrançois Tigeot 
96be4c44ceSFrançois Tigeot #define __put_user(value, uptr)						\
978621f407SFrançois Tigeot ({									\
98be4c44ceSFrançois Tigeot 	__typeof(*(uptr)) __tmpval = (value);				\
99be4c44ceSFrançois Tigeot 	__copy_to_user_inatomic((uptr), &__tmpval, sizeof(__tmpval));	\
1008621f407SFrançois Tigeot })
1018621f407SFrançois Tigeot 
102be4c44ceSFrançois Tigeot #define put_user(_x, _p)	__put_user(_x, _p)
103be4c44ceSFrançois Tigeot 
104*6f3edb89SFrançois Tigeot #define unsafe_put_user(x, ptr, err) do { \
105*6f3edb89SFrançois Tigeot 	if (unlikely(__put_user(x, ptr))) \
106*6f3edb89SFrançois Tigeot 		goto err; \
107*6f3edb89SFrançois Tigeot } while (0)
108*6f3edb89SFrançois Tigeot 
1092cecdd68SFrançois Tigeot #define user_access_begin()
1102cecdd68SFrançois Tigeot #define user_access_end()
1112cecdd68SFrançois Tigeot 
1125e6a4268SFrançois Tigeot #endif	/* _ASM_UACCESS_H_ */
113