1 /* Changes made by Lineo Inc. May 2001
3 * Based on: include/asm-m68knommu/uaccess.h
6 #ifndef __BLACKFIN_UACCESS_H
7 #define __BLACKFIN_UACCESS_H
10 * User space memory access functions
12 #include <linux/sched.h>
14 #include <linux/string.h>
16 #include <asm/segment.h>
17 #ifdef CONFIG_ACCESS_CHECK
18 # include <asm/bfin-global.h>
21 #define get_ds() (KERNEL_DS)
22 #define get_fs() (current_thread_info()->addr_limit)
24 static inline void set_fs(mm_segment_t fs
)
26 current_thread_info()->addr_limit
= fs
;
29 #define segment_eq(a,b) ((a) == (b))
32 #define VERIFY_WRITE 1
34 #define access_ok(type, addr, size) _access_ok((unsigned long)(addr), (size))
36 static inline int is_in_rom(unsigned long addr
)
39 * What we are really trying to do is determine if addr is
40 * in an allocated kernel memory region. If not then assume
41 * we cannot free it or otherwise de-allocate it. Ideally
42 * we could restrict this to really being in a ROM or flash,
43 * but that would need to be done on a board by board basis,
46 if ((addr
< _ramstart
) || (addr
>= _ramend
))
49 /* Default case, not in ROM */
54 * The fs value determines whether argument validity checking should be
55 * performed or not. If get_fs() == USER_DS, checking is performed, with
56 * get_fs() == KERNEL_DS, checking is bypassed.
59 #ifndef CONFIG_ACCESS_CHECK
60 static inline int _access_ok(unsigned long addr
, unsigned long size
) { return 1; }
62 #ifdef CONFIG_ACCESS_OK_L1
63 extern int _access_ok(unsigned long addr
, unsigned long size
)__attribute__((l1_text
));
65 extern int _access_ok(unsigned long addr
, unsigned long size
);
70 * The exception table consists of pairs of addresses: the first is the
71 * address of an instruction that is allowed to fault, and the second is
72 * the address at which the program should continue. No registers are
73 * modified, so it is entirely up to the continuation code to figure out
76 * All the routines below use bits of fixup code that are out of line
77 * with the main instruction path. This means when everything is well,
78 * we don't even have to jump over them. Further, they do not intrude
79 * on our cache or tlb entries.
82 struct exception_table_entry
{
83 unsigned long insn
, fixup
;
86 /* Returns 0 if exception not found and fixup otherwise. */
87 extern unsigned long search_exception_table(unsigned long);
90 * These are the main single-value transfer routines. They automatically
91 * use the right size if we just have the right pointer type.
94 #define put_user(x,p) \
97 typeof(*(p)) _x = (x); \
98 typeof(*(p)) *_p = (p); \
99 if (!access_ok(VERIFY_WRITE, _p, sizeof(*(_p)))) {\
103 switch (sizeof (*(_p))) { \
105 __put_user_asm(_x, _p, B); \
108 __put_user_asm(_x, _p, W); \
111 __put_user_asm(_x, _p, ); \
115 _xl = ((long *)&_x)[0]; \
116 _xh = ((long *)&_x)[1]; \
117 __put_user_asm(_xl, ((long *)_p)+0, ); \
118 __put_user_asm(_xh, ((long *)_p)+1, ); \
121 _err = __put_user_bad(); \
128 #define __put_user(x,p) put_user(x,p)
129 static inline int bad_user_access_length(void)
131 panic("bad_user_access_length");
135 #define __put_user_bad() (printk(KERN_INFO "put_user_bad %s:%d %s\n",\
136 __FILE__, __LINE__, __func__),\
137 bad_user_access_length(), (-EFAULT))
140 * Tell gcc we read from memory instead of writing: this is because
141 * we do not write to any memory gcc knows about, so there are no
145 #define __ptr(x) ((unsigned long *)(x))
147 #define __put_user_asm(x,p,bhw) \
148 __asm__ (#bhw"[%1] = %0;\n\t" \
150 :"d" (x),"a" (__ptr(p)) : "memory")
152 #define get_user(x, ptr) \
155 unsigned long _val = 0; \
156 const typeof(*(ptr)) __user *_p = (ptr); \
157 const size_t ptr_size = sizeof(*(_p)); \
158 if (likely(access_ok(VERIFY_READ, _p, ptr_size))) { \
159 BUILD_BUG_ON(ptr_size >= 8); \
160 switch (ptr_size) { \
162 __get_user_asm(_val, _p, B,(Z)); \
165 __get_user_asm(_val, _p, W,(Z)); \
168 __get_user_asm(_val, _p, , ); \
173 x = (typeof(*(ptr)))_val; \
177 #define __get_user(x,p) get_user(x,p)
179 #define __get_user_bad() (bad_user_access_length(), (-EFAULT))
181 #define __get_user_asm(x, ptr, bhw, option) \
183 __asm__ __volatile__ ( \
184 "%0 =" #bhw "[%1]" #option ";" \
186 : "a" (__ptr(ptr))); \
189 #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
190 #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
191 #define __copy_to_user_inatomic __copy_to_user
192 #define __copy_from_user_inatomic __copy_from_user
194 #define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n))\
197 #define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n))\
200 static inline unsigned long __must_check
201 copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
203 if (access_ok(VERIFY_READ
, from
, n
))
210 static inline unsigned long __must_check
211 copy_to_user(void *to
, const void __user
*from
, unsigned long n
)
213 if (access_ok(VERIFY_WRITE
, to
, n
))
221 * Copy a null terminated string from userspace.
224 static inline long __must_check
225 strncpy_from_user(char *dst
, const char *src
, long count
)
228 if (!access_ok(VERIFY_READ
, src
, 1))
230 strncpy(dst
, src
, count
);
231 for (tmp
= dst
; *tmp
&& count
> 0; tmp
++, count
--) ;
236 * Return the size of a string (including the ending 0)
238 * Return 0 on exception, a value greater than N if too long
240 static inline long strnlen_user(const char *src
, long n
)
242 return (strlen(src
) + 1);
245 #define strlen_user(str) strnlen_user(str, 32767)
251 static inline unsigned long __must_check
252 __clear_user(void *to
, unsigned long n
)
258 #define clear_user(to, n) __clear_user(to, n)
260 #endif /* _BLACKFIN_UACCESS_H */