176580237SAl Viro /*
276580237SAl Viro  * include/asm-xtensa/uaccess.h
376580237SAl Viro  *
476580237SAl Viro  * User space memory access functions
576580237SAl Viro  *
676580237SAl Viro  * These routines provide basic accessing functions to the user memory
776580237SAl Viro  * space for the kernel. This header file provides functions such as:
876580237SAl Viro  *
976580237SAl Viro  * This file is subject to the terms and conditions of the GNU General Public
1076580237SAl Viro  * License.  See the file "COPYING" in the main directory of this archive
1176580237SAl Viro  * for more details.
1276580237SAl Viro  *
1376580237SAl Viro  * Copyright (C) 2001 - 2005 Tensilica Inc.
1476580237SAl Viro  */
1576580237SAl Viro 
1676580237SAl Viro #ifndef _XTENSA_ASM_UACCESS_H
1776580237SAl Viro #define _XTENSA_ASM_UACCESS_H
1876580237SAl Viro 
1976580237SAl Viro #include <linux/errno.h>
2076580237SAl Viro #include <asm/types.h>
2176580237SAl Viro 
2276580237SAl Viro #include <asm/current.h>
2376580237SAl Viro #include <asm/asm-offsets.h>
2476580237SAl Viro #include <asm/processor.h>
2576580237SAl Viro 
2676580237SAl Viro /*
2776580237SAl Viro  * user_ok determines whether the access to user-space memory is allowed.
2876580237SAl Viro  * See the equivalent C-macro version below for clarity.
2976580237SAl Viro  *
3076580237SAl Viro  * On error, user_ok branches to a label indicated by parameter
3176580237SAl Viro  * <error>.  This implies that the macro falls through to the next
3276580237SAl Viro  * instruction on success.
3376580237SAl Viro  *
3476580237SAl Viro  * Note that while this macro can be used independently, we designed
3576580237SAl Viro  * in for optimal use in the access_ok macro below (i.e., we fall
3676580237SAl Viro  * through on success).
3776580237SAl Viro  *
3876580237SAl Viro  * On Entry:
3976580237SAl Viro  * 	<aa>	register containing memory address
4076580237SAl Viro  * 	<as>	register containing memory size
4176580237SAl Viro  * 	<at>	temp register
4276580237SAl Viro  * 	<error>	label to branch to on error; implies fall-through
4376580237SAl Viro  * 		macro on success
4476580237SAl Viro  * On Exit:
4576580237SAl Viro  * 	<aa>	preserved
4676580237SAl Viro  * 	<as>	preserved
4776580237SAl Viro  * 	<at>	destroyed (actually, (TASK_SIZE + 1 - size))
4876580237SAl Viro  */
4976580237SAl Viro 	.macro	user_ok	aa, as, at, error
5076580237SAl Viro 	movi	\at, __XTENSA_UL_CONST(TASK_SIZE)
5176580237SAl Viro 	bgeu	\as, \at, \error
5276580237SAl Viro 	sub	\at, \at, \as
5376580237SAl Viro 	bgeu	\aa, \at, \error
5476580237SAl Viro 	.endm
5576580237SAl Viro 
5676580237SAl Viro /*
5776580237SAl Viro  * access_ok determines whether a memory access is allowed.  See the
5876580237SAl Viro  * equivalent C-macro version below for clarity.
5976580237SAl Viro  *
6076580237SAl Viro  * On error, access_ok branches to a label indicated by parameter
6176580237SAl Viro  * <error>.  This implies that the macro falls through to the next
6276580237SAl Viro  * instruction on success.
6376580237SAl Viro  *
6476580237SAl Viro  * Note that we assume success is the common case, and we optimize the
6576580237SAl Viro  * branch fall-through case on success.
6676580237SAl Viro  *
6776580237SAl Viro  * On Entry:
6876580237SAl Viro  * 	<aa>	register containing memory address
6976580237SAl Viro  * 	<as>	register containing memory size
7076580237SAl Viro  * 	<at>	temp register
7176580237SAl Viro  * 	<sp>
7276580237SAl Viro  * 	<error>	label to branch to on error; implies fall-through
7376580237SAl Viro  * 		macro on success
7476580237SAl Viro  * On Exit:
7576580237SAl Viro  * 	<aa>	preserved
7676580237SAl Viro  * 	<as>	preserved
7776580237SAl Viro  * 	<at>	destroyed
7876580237SAl Viro  */
7976580237SAl Viro 	.macro	access_ok  aa, as, at, sp, error
8076580237SAl Viro 	user_ok    \aa, \as, \at, \error
8176580237SAl Viro .Laccess_ok_\@:
8276580237SAl Viro 	.endm
8376580237SAl Viro 
8476580237SAl Viro #endif	/* _XTENSA_ASM_UACCESS_H */
85