Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * OpenRISC Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Linux architectural port borrowing liberally from similar works of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * others.  All original copyrights apply as per the original source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * declaration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * OpenRISC implementation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * et al.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #ifndef __ASM_OPENRISC_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define __ASM_OPENRISC_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * User space memory access functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/prefetch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * The fs value determines whether argument validity checking should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * performed or not.  If get_fs() == USER_DS, checking is performed, with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * get_fs() == KERNEL_DS, checking is bypassed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * For historical reasons, these macros are grossly misnamed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /* addr_limit is the maximum accessible address for the task. we misuse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * the KERNEL_DS and USER_DS values to both assign and compare the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * addr_limit values through the equally misnamed get/set_fs macros.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * (see above)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define KERNEL_DS	(~0UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define USER_DS		(TASK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define get_fs()	(current_thread_info()->addr_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define set_fs(x)	(current_thread_info()->addr_limit = (x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define uaccess_kernel()	(get_fs() == KERNEL_DS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* Ensure that the range from addr to addr+size is all within the process'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * address space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static inline int __range_ok(unsigned long addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	const mm_segment_t fs = get_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return size <= fs && addr <= (fs - size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define access_ok(addr, size)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) ({ 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	__chk_user_ptr(addr);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	__range_ok((unsigned long)(addr), (size));			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * These are the main single-value transfer routines.  They automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * use the right size if we just have the right pointer type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * This gets kind of ugly. We want to return _two_ values in "get_user()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * and yet we don't want to do any pointers, because that is too much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * of a performance impact. Thus we have a few rather ugly macros here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * and hide all the uglyness from the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * The "__xxx" versions of the user access functions are versions that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * do not verify the address space, that must have been done previously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * with a separate "access_ok()" call (this is used when we do multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * accesses to the same area of user memory).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * As we use the same address space for kernel and user data on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * PowerPC, we can just do these as direct assignments.  (Of course, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * exception handling means that it's no longer "just"...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #define get_user(x, ptr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	__get_user_check((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define put_user(x, ptr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	__put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define __get_user(x, ptr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	__get_user_nocheck((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #define __put_user(x, ptr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	__put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) extern long __put_user_bad(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #define __put_user_nocheck(x, ptr, size)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) ({							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	long __pu_err;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	__put_user_size((x), (ptr), (size), __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	__pu_err;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define __put_user_check(x, ptr, size)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	long __pu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	__typeof__(*(ptr)) __user *__pu_addr = (ptr);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (access_ok(__pu_addr, size))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		__put_user_size((x), __pu_addr, (size), __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	__pu_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define __put_user_size(x, ptr, size, retval)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	retval = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	switch (size) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case 1: __put_user_asm(x, ptr, retval, "l.sb"); break;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	case 2: __put_user_asm(x, ptr, retval, "l.sh"); break;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	case 4: __put_user_asm(x, ptr, retval, "l.sw"); break;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case 8: __put_user_asm2(x, ptr, retval); break;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	default: __put_user_bad();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct __large_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	unsigned long buf[100];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define __m(x) (*(struct __large_struct *)(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * We don't tell gcc that we are accessing memory, but this is OK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * because we do not write to any memory gcc knows about, so there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * are no aliasing issues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define __put_user_asm(x, addr, err, op)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	__asm__ __volatile__(					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		"1:	"op" 0(%2),%1\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		".section .fixup,\"ax\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		"3:	l.addi %0,r0,%3\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		"	l.j 2b\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		"	l.nop\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		".previous\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		".section __ex_table,\"a\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		"	.align 2\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		"	.long 1b,3b\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		".previous"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		: "=r"(err)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		: "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define __put_user_asm2(x, addr, err)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	__asm__ __volatile__(					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		"1:	l.sw 0(%2),%1\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		"2:	l.sw 4(%2),%H1\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		"3:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		".section .fixup,\"ax\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		"4:	l.addi %0,r0,%3\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		"	l.j 3b\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		"	l.nop\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		".previous\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		".section __ex_table,\"a\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		"	.align 2\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		"	.long 1b,4b\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		"	.long 2b,4b\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		".previous"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		: "=r"(err)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		: "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define __get_user_nocheck(x, ptr, size)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	long __gu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	__get_user_size((x), (ptr), (size), __gu_err);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	__gu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define __get_user_check(x, ptr, size)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	long __gu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (access_ok(__gu_addr, size))					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		__get_user_size((x), __gu_addr, (size), __gu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	else								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		(x) = (__typeof__(*(ptr))) 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	__gu_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) extern long __get_user_bad(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define __get_user_size(x, ptr, size, retval)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	retval = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	switch (size) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	case 1: __get_user_asm(x, ptr, retval, "l.lbz"); break;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	case 2: __get_user_asm(x, ptr, retval, "l.lhz"); break;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	case 4: __get_user_asm(x, ptr, retval, "l.lwz"); break;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	case 8: __get_user_asm2(x, ptr, retval); break;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	default: (x) = (__typeof__(*(ptr)))__get_user_bad();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #define __get_user_asm(x, addr, err, op)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	unsigned long __gu_tmp;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	__asm__ __volatile__(				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		"1:	"op" %1,0(%2)\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		"2:\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		".section .fixup,\"ax\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		"3:	l.addi %0,r0,%3\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		"	l.addi %1,r0,0\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		"	l.j 2b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		"	l.nop\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		".previous\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		".section __ex_table,\"a\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		"	.align 2\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		"	.long 1b,3b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		".previous"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		: "=r"(err), "=r"(__gu_tmp)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		: "r"(addr), "i"(-EFAULT), "0"(err));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	(x) = (__typeof__(*(addr)))__gu_tmp;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define __get_user_asm2(x, addr, err)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	unsigned long long __gu_tmp;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	__asm__ __volatile__(				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		"1:	l.lwz %1,0(%2)\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		"2:	l.lwz %H1,4(%2)\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		"3:\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		".section .fixup,\"ax\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		"4:	l.addi %0,r0,%3\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		"	l.addi %1,r0,0\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		"	l.addi %H1,r0,0\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		"	l.j 3b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		"	l.nop\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		".previous\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		".section __ex_table,\"a\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		"	.align 2\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		"	.long 1b,4b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		"	.long 2b,4b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		".previous"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		: "=r"(err), "=&r"(__gu_tmp)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		: "r"(addr), "i"(-EFAULT), "0"(err));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	(x) = (__typeof__(*(addr)))(			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		(__typeof__((x)-(x)))__gu_tmp);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* more complex routines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) extern unsigned long __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) __copy_tofrom_user(void *to, const void *from, unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) raw_copy_from_user(void *to, const void __user *from, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return __copy_tofrom_user(to, (__force const void *)from, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) raw_copy_to_user(void __user *to, const void *from, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return __copy_tofrom_user((__force void *)to, from, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #define INLINE_COPY_FROM_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #define INLINE_COPY_TO_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) extern unsigned long __clear_user(void __user *addr, unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static inline __must_check unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) clear_user(void __user *addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (likely(access_ok(addr, size)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		size = __clear_user(addr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #define user_addr_max() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	(uaccess_kernel() ? ~0UL : TASK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) extern long strncpy_from_user(char *dest, const char __user *src, long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) extern __must_check long strnlen_user(const char __user *str, long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #endif /* __ASM_OPENRISC_UACCESS_H */