blob: 852322f2d1f9987777026622f5dc7ef6063ad959 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __PARISC_UACCESS_H
2#define __PARISC_UACCESS_H
3
4/*
5 * User space memory access functions
6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/cache.h>
Arnd Bergmann5b17e1c2009-05-13 22:56:30 +00009#include <asm-generic/uaccess-unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Helge Deller8dd95c62014-10-21 21:29:09 +020011#include <linux/bug.h>
Al Viroaace8802016-08-20 19:03:37 -040012#include <linux/string.h>
Helge Deller8dd95c62014-10-21 21:29:09 +020013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#define KERNEL_DS ((mm_segment_t){0})
15#define USER_DS ((mm_segment_t){1})
16
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +020017#define segment_eq(a, b) ((a).seg == (b).seg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#define get_ds() (KERNEL_DS)
20#define get_fs() (current_thread_info()->addr_limit)
21#define set_fs(x) (current_thread_info()->addr_limit = (x))
22
23/*
24 * Note that since kernel addresses are in a separate address space on
Jesper Juhle49332b2005-05-01 08:59:08 -070025 * parisc, we don't need to do anything for access_ok().
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 * We just let the page fault handler do the right thing. This also means
27 * that put_user is the same as __put_user, etc.
28 */
29
Helge Deller186ecf12017-03-15 21:48:42 +010030#define access_ok(type, uaddr, size) \
31 ( (uaddr) == (uaddr) )
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define put_user __put_user
34#define get_user __get_user
35
Helge Dellerca72a222006-12-20 00:35:57 +010036#if !defined(CONFIG_64BIT)
Helge Dellerd2ad8242016-04-09 08:27:08 +020037#define LDD_USER(ptr) __get_user_asm64(ptr)
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +020038#define STD_USER(x, ptr) __put_user_asm64(x, ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#else
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +020040#define LDD_USER(ptr) __get_user_asm("ldd", ptr)
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +020041#define STD_USER(x, ptr) __put_user_asm("std", x, ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#endif
43
44/*
Helge Dellercb910c12016-04-08 21:36:06 +020045 * The exception table contains two values: the first is the relative offset to
46 * the address of the instruction that is allowed to fault, and the second is
47 * the relative offset to the address of the fixup routine. Since relative
48 * addresses are used, 32bit values are sufficient even on 64bit kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 */
50
Helge Deller0de79852016-03-23 16:00:46 +010051#define ARCH_HAS_RELATIVE_EXTABLE
Linus Torvalds1da177e2005-04-16 15:20:36 -070052struct exception_table_entry {
Helge Deller0de79852016-03-23 16:00:46 +010053 int insn; /* relative address of insn that is allowed to fault. */
54 int fixup; /* relative address of fixup routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
Helge Deller0b3d6432007-01-28 14:52:57 +010057#define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\
58 ".section __ex_table,\"aw\"\n" \
Helge Deller0de79852016-03-23 16:00:46 +010059 ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \
Helge Deller0b3d6432007-01-28 14:52:57 +010060 ".previous\n"
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
Helge Dellerd19f5e42017-03-25 11:59:15 +010063 * ASM_EXCEPTIONTABLE_ENTRY_EFAULT() creates a special exception table entry
64 * (with lowest bit set) for which the fault handler in fixup_exception() will
65 * load -EFAULT into %r8 for a read or write fault, and zeroes the target
66 * register in case of a read fault in get_user().
67 */
68#define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr )\
69 ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1)
70
71/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * The page fault handler stores, in a per-cpu area, the following information
73 * if a fixup routine is available.
74 */
75struct exception_data {
76 unsigned long fault_ip;
Helge Deller2ef4dfd2016-04-08 18:32:52 +020077 unsigned long fault_gp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 unsigned long fault_space;
79 unsigned long fault_addr;
80};
81
Helge Deller06bff6b2016-04-09 08:26:14 +020082/*
83 * load_sr2() preloads the space register %%sr2 - based on the value of
84 * get_fs() - with either a value of 0 to access kernel space (KERNEL_DS which
85 * is 0), or with the current value of %%sr3 to access user space (USER_DS)
86 * memory. The following __get_user_asm() and __put_user_asm() functions have
87 * %%sr2 hard-coded to access the requested memory.
88 */
89#define load_sr2() \
90 __asm__(" or,= %0,%%r0,%%r0\n\t" \
91 " mfsp %%sr3,%0\n\t" \
92 " mtsp %0,%%sr2\n\t" \
93 : : "r"(get_fs()) : )
94
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +020095#define __get_user(x, ptr) \
96({ \
97 register long __gu_err __asm__ ("r8") = 0; \
Helge Dellerd19f5e42017-03-25 11:59:15 +010098 register long __gu_val; \
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +020099 \
Helge Deller06bff6b2016-04-09 08:26:14 +0200100 load_sr2(); \
101 switch (sizeof(*(ptr))) { \
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200102 case 1: __get_user_asm("ldb", ptr); break; \
103 case 2: __get_user_asm("ldh", ptr); break; \
104 case 4: __get_user_asm("ldw", ptr); break; \
105 case 8: LDD_USER(ptr); break; \
106 default: BUILD_BUG(); break; \
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200107 } \
108 \
109 (x) = (__force __typeof__(*(ptr))) __gu_val; \
110 __gu_err; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111})
112
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200113#define __get_user_asm(ldx, ptr) \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100114 __asm__("1: " ldx " 0(%%sr2,%2),%0\n" \
115 "9:\n" \
116 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 : "=r"(__gu_val), "=r"(__gu_err) \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100118 : "r"(ptr), "1"(__gu_err));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Helge Dellerd2ad8242016-04-09 08:27:08 +0200120#if !defined(CONFIG_64BIT)
121
122#define __get_user_asm64(ptr) \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100123 __asm__(" copy %%r0,%R0\n" \
124 "1: ldw 0(%%sr2,%2),%0\n" \
125 "2: ldw 4(%%sr2,%2),%R0\n" \
126 "9:\n" \
127 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
128 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \
Helge Dellerd2ad8242016-04-09 08:27:08 +0200129 : "=r"(__gu_val), "=r"(__gu_err) \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100130 : "r"(ptr), "1"(__gu_err));
Helge Dellerd2ad8242016-04-09 08:27:08 +0200131
132#endif /* !defined(CONFIG_64BIT) */
133
134
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200135#define __put_user(x, ptr) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136({ \
137 register long __pu_err __asm__ ("r8") = 0; \
138 __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \
139 \
Helge Deller06bff6b2016-04-09 08:26:14 +0200140 load_sr2(); \
141 switch (sizeof(*(ptr))) { \
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200142 case 1: __put_user_asm("stb", __x, ptr); break; \
143 case 2: __put_user_asm("sth", __x, ptr); break; \
144 case 4: __put_user_asm("stw", __x, ptr); break; \
145 case 8: STD_USER(__x, ptr); break; \
Helge Deller8dd95c62014-10-21 21:29:09 +0200146 default: BUILD_BUG(); break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 } \
148 \
149 __pu_err; \
150})
151
152/*
153 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
154 * instead of writing. This is because they do not write to any memory
Carlos O'Donell3fd3a742006-04-22 14:47:21 -0600155 * gcc knows about, so there are no aliasing issues. These macros must
Helge Dellerd19f5e42017-03-25 11:59:15 +0100156 * also be aware that fixups are executed in the context of the fault,
157 * and any registers used there must be listed as clobbers.
158 * r8 is already listed as err.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 */
160
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200161#define __put_user_asm(stx, x, ptr) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 __asm__ __volatile__ ( \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100163 "1: " stx " %2,0(%%sr2,%1)\n" \
164 "9:\n" \
165 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 : "=r"(__pu_err) \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100167 : "r"(ptr), "r"(x), "0"(__pu_err))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Helge Dellerca72a222006-12-20 00:35:57 +0100170#if !defined(CONFIG_64BIT)
Helge Deller94a19812006-12-19 22:33:58 +0100171
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200172#define __put_user_asm64(__val, ptr) do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 __asm__ __volatile__ ( \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100174 "1: stw %2,0(%%sr2,%1)\n" \
175 "2: stw %R2,4(%%sr2,%1)\n" \
176 "9:\n" \
177 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
178 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 : "=r"(__pu_err) \
Helge Dellerd19f5e42017-03-25 11:59:15 +0100180 : "r"(ptr), "r"(__val), "0"(__pu_err)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181} while (0)
182
Helge Dellerca72a222006-12-20 00:35:57 +0100183#endif /* !defined(CONFIG_64BIT) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185
186/*
187 * Complex access routines -- external declarations
188 */
189
James Bottomleyb1195c02012-05-26 09:48:19 +0100190extern long strncpy_from_user(char *, const char __user *, long);
Michael S. Tsirkinb9762e72015-01-06 17:45:34 +0200191extern unsigned lclear_user(void __user *, unsigned long);
192extern long lstrnlen_user(const char __user *, long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193/*
194 * Complex access routines -- macros
195 */
Helge Dellera0ffa8f2013-11-19 23:31:35 +0100196#define user_addr_max() (~0UL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#define strnlen_user lstrnlen_user
199#define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
200#define clear_user lclear_user
201#define __clear_user lclear_user
202
Al Virof64fd182017-03-24 23:11:26 -0400203unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src,
204 unsigned long len);
205unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src,
206 unsigned long len);
207unsigned long __must_check raw_copy_in_user(void __user *dst, const void __user *src,
208 unsigned long len);
209#define INLINE_COPY_TO_USER
210#define INLINE_COPY_FROM_USER
Helge Deller888c31f2010-02-01 19:56:33 +0000211
Helge Dellere4483722009-01-13 20:52:46 +0100212struct pt_regs;
Kyle McMartinc61c25e2008-12-20 02:29:06 +0000213int fixup_exception(struct pt_regs *regs);
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#endif /* __PARISC_UACCESS_H */