4 * Copyright (c) 2005 blackfin.uclinux.org
6 * This file is based on
7 * Based on: include/asm-m68knommu/uaccess.h
8 * Changes made by Lineo Inc. May 2001
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #ifndef __BLACKFIN_UACCESS_H
30 #define __BLACKFIN_UACCESS_H
33 * User space memory access functions
35 #include <asm/segment.h>
36 #include <asm/errno.h>
39 #define VERIFY_WRITE 1
41 /* We let the MMU do all checking */
42 static inline int access_ok(int type, const void *addr, unsigned long size)
44 return ((unsigned long)addr < 0x10f00000); /* need final decision - Tony */
47 static inline int verify_area(int type, const void *addr, unsigned long size)
49 return access_ok(type, addr, size) ? 0 : -EFAULT;
53 * The exception table consists of pairs of addresses: the first is the
54 * address of an instruction that is allowed to fault, and the second is
55 * the address at which the program should continue. No registers are
56 * modified, so it is entirely up to the continuation code to figure out
59 * All the routines below use bits of fixup code that are out of line
60 * with the main instruction path. This means when everything is well,
61 * we don't even have to jump over them. Further, they do not intrude
62 * on our cache or tlb entries.
65 struct exception_table_entry {
66 unsigned long insn, fixup;
69 /* Returns 0 if exception not found and fixup otherwise. */
70 extern unsigned long search_exception_table(unsigned long);
73 * These are the main single-value transfer routines. They automatically
74 * use the right size if we just have the right pointer type.
77 #define put_user(x, ptr) \
80 typeof(*(ptr)) __pu_val = (x); \
81 switch (sizeof (*(ptr))) { \
83 __put_user_asm(__pu_err, __pu_val, ptr, B); \
86 __put_user_asm(__pu_err, __pu_val, ptr, W); \
89 __put_user_asm(__pu_err, __pu_val, ptr, ); \
92 __pu_err = __put_user_bad(); \
98 * [pregs] = dregs ==> 32bits
99 * H[pregs] = dregs ==> 16bits
100 * B[pregs] = dregs ==> 8 bits
103 #define __put_user(x, ptr) put_user(x, ptr)
105 static inline int bad_user_access_length(void)
107 panic("bad_user_access_length");
111 #define __put_user_bad() (bad_user_access_length(), (-EFAULT))
114 * Tell gcc we read from memory instead of writing: this is because
115 * we do not write to any memory gcc knows about, so there are no
119 #define __ptr(x) ((unsigned long *)(x))
121 #define __put_user_asm(err,x,ptr,bhw) \
122 __asm__ (#bhw"[%1] = %0;\n\t" \
124 :"d" (x),"a" (__ptr(ptr)) : "memory")
126 #define get_user(x, ptr) \
129 typeof(*(ptr)) __gu_val = 0; \
130 switch (sizeof(*(ptr))) { \
132 __get_user_asm(__gu_err, __gu_val, ptr, B, "=d",(Z)); \
135 __get_user_asm(__gu_err, __gu_val, ptr, W, "=r",(Z)); \
138 __get_user_asm(__gu_err, __gu_val, ptr, , "=r",); \
142 __gu_err = __get_user_bad(); \
149 /* dregs = [pregs] ==> 32bits
150 * H[pregs] ==> 16bits
151 * B[pregs] ==> 8 bits
154 #define __get_user(x, ptr) get_user(x, ptr)
155 #define __get_user_bad() (bad_user_access_length(), (-EFAULT))
157 #define __get_user_asm(err,x,ptr,bhw,reg,option) \
158 __asm__ ("%0 =" #bhw "[%1]"#option";\n\t" \
162 #define copy_from_user(to, from, n) (memcpy(to, from, n), 0)
163 #define copy_to_user(to, from, n) (memcpy(to, from, n), 0)
165 #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
166 #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
168 #define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n)) return retval; })
169 #define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n)) return retval; })
172 * Copy a null terminated string from userspace.
175 static inline long strncpy_from_user(char *dst, const char *src, long count)
178 strncpy(dst, src, count);
179 for (tmp = dst; *tmp && count > 0; tmp++, count--) ;
180 return (tmp - dst); /* DAVIDM should we count a NUL ? check getname */
184 * Return the size of a string (including the ending 0)
186 * Return 0 on exception, a value greater than N if too long
188 static inline long strnlen_user(const char *src, long n)
190 return (strlen(src) + 1); /* DAVIDM make safer */
193 #define strlen_user(str) strnlen_user(str, 32767)
199 static inline unsigned long clear_user(void *to, unsigned long n)