Merge branch 'gup_flag-cleanups'
[cascardo/linux.git] / arch / xtensa / include / asm / asm-uaccess.h
1 /*
2  * include/asm-xtensa/uaccess.h
3  *
4  * User space memory access functions
5  *
6  * These routines provide basic accessing functions to the user memory
7  * space for the kernel. This header file provides functions such as:
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License.  See the file "COPYING" in the main directory of this archive
11  * for more details.
12  *
13  * Copyright (C) 2001 - 2005 Tensilica Inc.
14  */
15
16 #ifndef _XTENSA_ASM_UACCESS_H
17 #define _XTENSA_ASM_UACCESS_H
18
19 #include <linux/errno.h>
20 #include <asm/types.h>
21
22 #define VERIFY_READ    0
23 #define VERIFY_WRITE   1
24
25 #include <asm/current.h>
26 #include <asm/asm-offsets.h>
27 #include <asm/processor.h>
28
29 /*
30  * These assembly macros mirror the C macros in asm/uaccess.h.  They
31  * should always have identical functionality.  See
32  * arch/xtensa/kernel/sys.S for usage.
33  */
34
35 #define KERNEL_DS       0
36 #define USER_DS         1
37
38 #define get_ds          (KERNEL_DS)
39
40 /*
41  * get_fs reads current->thread.current_ds into a register.
42  * On Entry:
43  *      <ad>    anything
44  *      <sp>    stack
45  * On Exit:
46  *      <ad>    contains current->thread.current_ds
47  */
48         .macro  get_fs  ad, sp
49         GET_CURRENT(\ad,\sp)
50 #if THREAD_CURRENT_DS > 1020
51         addi    \ad, \ad, TASK_THREAD
52         l32i    \ad, \ad, THREAD_CURRENT_DS - TASK_THREAD
53 #else
54         l32i    \ad, \ad, THREAD_CURRENT_DS
55 #endif
56         .endm
57
58 /*
59  * set_fs sets current->thread.current_ds to some value.
60  * On Entry:
61  *      <at>    anything (temp register)
62  *      <av>    value to write
63  *      <sp>    stack
64  * On Exit:
65  *      <at>    destroyed (actually, current)
66  *      <av>    preserved, value to write
67  */
68         .macro  set_fs  at, av, sp
69         GET_CURRENT(\at,\sp)
70         s32i    \av, \at, THREAD_CURRENT_DS
71         .endm
72
73 /*
74  * kernel_ok determines whether we should bypass addr/size checking.
75  * See the equivalent C-macro version below for clarity.
76  * On success, kernel_ok branches to a label indicated by parameter
77  * <success>.  This implies that the macro falls through to the next
78  * insruction on an error.
79  *
80  * Note that while this macro can be used independently, we designed
81  * in for optimal use in the access_ok macro below (i.e., we fall
82  * through on error).
83  *
84  * On Entry:
85  *      <at>            anything (temp register)
86  *      <success>       label to branch to on success; implies
87  *                      fall-through macro on error
88  *      <sp>            stack pointer
89  * On Exit:
90  *      <at>            destroyed (actually, current->thread.current_ds)
91  */
92
93 #if ((KERNEL_DS != 0) || (USER_DS == 0))
94 # error Assembly macro kernel_ok fails
95 #endif
96         .macro  kernel_ok  at, sp, success
97         get_fs  \at, \sp
98         beqz    \at, \success
99         .endm
100
101 /*
102  * user_ok determines whether the access to user-space memory is allowed.
103  * See the equivalent C-macro version below for clarity.
104  *
105  * On error, user_ok branches to a label indicated by parameter
106  * <error>.  This implies that the macro falls through to the next
107  * instruction on success.
108  *
109  * Note that while this macro can be used independently, we designed
110  * in for optimal use in the access_ok macro below (i.e., we fall
111  * through on success).
112  *
113  * On Entry:
114  *      <aa>    register containing memory address
115  *      <as>    register containing memory size
116  *      <at>    temp register
117  *      <error> label to branch to on error; implies fall-through
118  *              macro on success
119  * On Exit:
120  *      <aa>    preserved
121  *      <as>    preserved
122  *      <at>    destroyed (actually, (TASK_SIZE + 1 - size))
123  */
124         .macro  user_ok aa, as, at, error
125         movi    \at, __XTENSA_UL_CONST(TASK_SIZE)
126         bgeu    \as, \at, \error
127         sub     \at, \at, \as
128         bgeu    \aa, \at, \error
129         .endm
130
131 /*
132  * access_ok determines whether a memory access is allowed.  See the
133  * equivalent C-macro version below for clarity.
134  *
135  * On error, access_ok branches to a label indicated by parameter
136  * <error>.  This implies that the macro falls through to the next
137  * instruction on success.
138  *
139  * Note that we assume success is the common case, and we optimize the
140  * branch fall-through case on success.
141  *
142  * On Entry:
143  *      <aa>    register containing memory address
144  *      <as>    register containing memory size
145  *      <at>    temp register
146  *      <sp>
147  *      <error> label to branch to on error; implies fall-through
148  *              macro on success
149  * On Exit:
150  *      <aa>    preserved
151  *      <as>    preserved
152  *      <at>    destroyed
153  */
154         .macro  access_ok  aa, as, at, sp, error
155         kernel_ok  \at, \sp, .Laccess_ok_\@
156         user_ok    \aa, \as, \at, \error
157 .Laccess_ok_\@:
158         .endm
159
160 #endif  /* _XTENSA_ASM_UACCESS_H */