-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Richard Kuo <rkuo@codeaurora.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
- Loading branch information
Richard Kuo
authored and
Linus Torvalds
committed
Nov 1, 2011
1 parent
dd472da
commit 7567746
Showing
6 changed files
with
705 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* User memory access support for Hexagon | ||
* | ||
* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 and | ||
* only version 2 as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef _ASM_UACCESS_H | ||
#define _ASM_UACCESS_H | ||
/* | ||
* User space memory access functions | ||
*/ | ||
#include <linux/sched.h> | ||
#include <linux/mm.h> | ||
#include <asm/segment.h> | ||
#include <asm/sections.h> | ||
|
||
/* | ||
* access_ok: - Checks if a user space pointer is valid | ||
* @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that | ||
* %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe | ||
* to write to a block, it is always safe to read from it. | ||
* @addr: User space pointer to start of block to check | ||
* @size: Size of block to check | ||
* | ||
* Context: User context only. This function may sleep. | ||
* | ||
* Checks if a pointer to a block of memory in user space is valid. | ||
* | ||
* Returns true (nonzero) if the memory block *may* be valid, false (zero) | ||
* if it is definitely invalid. | ||
* | ||
* User address space in Hexagon, like x86, goes to 0xbfffffff, so the | ||
* simple MSB-based tests used by MIPS won't work. Some further | ||
* optimization is probably possible here, but for now, keep it | ||
* reasonably simple and not *too* slow. After all, we've got the | ||
* MMU for backup. | ||
*/ | ||
#define VERIFY_READ 0 | ||
#define VERIFY_WRITE 1 | ||
|
||
#define __access_ok(addr, size) \ | ||
((get_fs().seg == KERNEL_DS.seg) || \ | ||
(((unsigned long)addr < get_fs().seg) && \ | ||
(unsigned long)size < (get_fs().seg - (unsigned long)addr))) | ||
|
||
/* | ||
* When a kernel-mode page fault is taken, the faulting instruction | ||
* address is checked against a table of exception_table_entries. | ||
* Each entry is a tuple of the address of an instruction that may | ||
* be authorized to fault, and the address at which execution should | ||
* be resumed instead of the faulting instruction, so as to effect | ||
* a workaround. | ||
*/ | ||
|
||
/* Assembly somewhat optimized copy routines */ | ||
unsigned long __copy_from_user_hexagon(void *to, const void __user *from, | ||
unsigned long n); | ||
unsigned long __copy_to_user_hexagon(void __user *to, const void *from, | ||
unsigned long n); | ||
|
||
#define __copy_from_user(to, from, n) __copy_from_user_hexagon(to, from, n) | ||
#define __copy_to_user(to, from, n) __copy_to_user_hexagon(to, from, n) | ||
|
||
/* | ||
* XXX todo: some additonal performance gain is possible by | ||
* implementing __copy_to/from_user_inatomic, which is much | ||
* like __copy_to/from_user, but performs slightly less checking. | ||
*/ | ||
|
||
__kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count); | ||
#define __clear_user(a, s) __clear_user_hexagon((a), (s)) | ||
|
||
#define __strncpy_from_user(dst, src, n) hexagon_strncpy_from_user(dst, src, n) | ||
|
||
/* get around the ifndef in asm-generic/uaccess.h */ | ||
#define __strnlen_user __strnlen_user | ||
|
||
extern long __strnlen_user(const char __user *src, long n); | ||
|
||
static inline long hexagon_strncpy_from_user(char *dst, const char __user *src, | ||
long n); | ||
|
||
#include <asm-generic/uaccess.h> | ||
|
||
/* Todo: an actual accelerated version of this. */ | ||
static inline long hexagon_strncpy_from_user(char *dst, const char __user *src, | ||
long n) | ||
{ | ||
long res = __strnlen_user(src, n); | ||
|
||
/* return from strnlen can't be zero -- that would be rubbish. */ | ||
|
||
if (res > n) { | ||
copy_from_user(dst, src, n); | ||
return n; | ||
} else { | ||
copy_from_user(dst, src, res); | ||
return res-1; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* User memory copy functions for kernel | ||
* | ||
* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 and | ||
* only version 2 as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
/* | ||
* The right way to do this involves valignb | ||
* The easy way to do this is only speed up src/dest similar alignment. | ||
*/ | ||
|
||
/* | ||
* Copy to/from user are the same, except that for packets with a load and | ||
* a store, I don't know how to tell which kind of exception we got. | ||
* Therefore, we duplicate the function, and handle faulting addresses | ||
* differently for each function | ||
*/ | ||
|
||
/* | ||
* copy from user: loads can fault | ||
*/ | ||
#define src_sav r13 | ||
#define dst_sav r12 | ||
#define src_dst_sav r13:12 | ||
#define d_dbuf r15:14 | ||
#define w_dbuf r15 | ||
|
||
#define dst r0 | ||
#define src r1 | ||
#define bytes r2 | ||
#define loopcount r5 | ||
|
||
#define FUNCNAME __copy_from_user_hexagon | ||
#include "copy_user_template.S" | ||
|
||
/* LOAD FAULTS from COPY_FROM_USER */ | ||
|
||
/* Alignment loop. r2 has been updated. Return it. */ | ||
.falign | ||
1009: | ||
2009: | ||
4009: | ||
{ | ||
r0 = r2 | ||
jumpr r31 | ||
} | ||
/* Normal copy loops. Do epilog. Use src-src_sav to compute distance */ | ||
/* X - (A - B) == X + B - A */ | ||
.falign | ||
8089: | ||
{ | ||
memd(dst) = d_dbuf | ||
r2 += sub(src_sav,src) | ||
} | ||
{ | ||
r0 = r2 | ||
jumpr r31 | ||
} | ||
.falign | ||
4089: | ||
{ | ||
memw(dst) = w_dbuf | ||
r2 += sub(src_sav,src) | ||
} | ||
{ | ||
r0 = r2 | ||
jumpr r31 | ||
} | ||
.falign | ||
2089: | ||
{ | ||
memh(dst) = w_dbuf | ||
r2 += sub(src_sav,src) | ||
} | ||
{ | ||
r0 = r2 | ||
jumpr r31 | ||
} | ||
.falign | ||
1089: | ||
{ | ||
memb(dst) = w_dbuf | ||
r2 += sub(src_sav,src) | ||
} | ||
{ | ||
r0 = r2 | ||
jumpr r31 | ||
} | ||
|
||
/* COPY FROM USER: only loads can fail */ | ||
|
||
.section __ex_table,"a" | ||
.long 1000b,1009b | ||
.long 2000b,2009b | ||
.long 4000b,4009b | ||
.long 8080b,8089b | ||
.long 4080b,4089b | ||
.long 2080b,2089b | ||
.long 1080b,1089b | ||
.previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* User memory copying routines for the Hexagon Kernel | ||
* | ||
* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 and | ||
* only version 2 as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
/* The right way to do this involves valignb | ||
* The easy way to do this is only speed up src/dest similar alignment. | ||
*/ | ||
|
||
/* | ||
* Copy to/from user are the same, except that for packets with a load and | ||
* a store, I don't know how to tell which kind of exception we got. | ||
* Therefore, we duplicate the function, and handle faulting addresses | ||
* differently for each function | ||
*/ | ||
|
||
/* | ||
* copy to user: stores can fault | ||
*/ | ||
#define src_sav r13 | ||
#define dst_sav r12 | ||
#define src_dst_sav r13:12 | ||
#define d_dbuf r15:14 | ||
#define w_dbuf r15 | ||
|
||
#define dst r0 | ||
#define src r1 | ||
#define bytes r2 | ||
#define loopcount r5 | ||
|
||
#define FUNCNAME __copy_to_user_hexagon | ||
#include "copy_user_template.S" | ||
|
||
/* STORE FAULTS from COPY_TO_USER */ | ||
.falign | ||
1109: | ||
2109: | ||
4109: | ||
/* Alignment loop. r2 has been updated. Return it. */ | ||
{ | ||
r0 = r2 | ||
jumpr r31 | ||
} | ||
/* Normal copy loops. Use dst-dst_sav to compute distance */ | ||
/* dst holds best write, no need to unwind any loops */ | ||
/* X - (A - B) == X + B - A */ | ||
.falign | ||
8189: | ||
8199: | ||
4189: | ||
4199: | ||
2189: | ||
2199: | ||
1189: | ||
1199: | ||
{ | ||
r2 += sub(dst_sav,dst) | ||
} | ||
{ | ||
r0 = r2 | ||
jumpr r31 | ||
} | ||
|
||
/* COPY TO USER: only stores can fail */ | ||
.section __ex_table,"a" | ||
.long 1100b,1109b | ||
.long 2100b,2109b | ||
.long 4100b,4109b | ||
.long 8180b,8189b | ||
.long 8190b,8199b | ||
.long 4180b,4189b | ||
.long 4190b,4199b | ||
.long 2180b,2189b | ||
.long 2190b,2199b | ||
.long 1180b,1189b | ||
.long 1190b,1199b | ||
.previous |
Oops, something went wrong.