162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * include/asm-xtensa/uaccess.h
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * User space memory access functions
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * These routines provide basic accessing functions to the user memory
762306a36Sopenharmony_ci * space for the kernel. This header file provides functions such as:
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
1062306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
1162306a36Sopenharmony_ci * for more details.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * Copyright (C) 2001 - 2005 Tensilica Inc.
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#ifndef _XTENSA_ASM_UACCESS_H
1762306a36Sopenharmony_ci#define _XTENSA_ASM_UACCESS_H
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#include <linux/errno.h>
2062306a36Sopenharmony_ci#include <asm/types.h>
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#include <asm/current.h>
2362306a36Sopenharmony_ci#include <asm/asm-offsets.h>
2462306a36Sopenharmony_ci#include <asm/processor.h>
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/*
2762306a36Sopenharmony_ci * user_ok determines whether the access to user-space memory is allowed.
2862306a36Sopenharmony_ci * See the equivalent C-macro version below for clarity.
2962306a36Sopenharmony_ci *
3062306a36Sopenharmony_ci * On error, user_ok branches to a label indicated by parameter
3162306a36Sopenharmony_ci * <error>.  This implies that the macro falls through to the next
3262306a36Sopenharmony_ci * instruction on success.
3362306a36Sopenharmony_ci *
3462306a36Sopenharmony_ci * Note that while this macro can be used independently, we designed
3562306a36Sopenharmony_ci * in for optimal use in the access_ok macro below (i.e., we fall
3662306a36Sopenharmony_ci * through on success).
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci * On Entry:
3962306a36Sopenharmony_ci * 	<aa>	register containing memory address
4062306a36Sopenharmony_ci * 	<as>	register containing memory size
4162306a36Sopenharmony_ci * 	<at>	temp register
4262306a36Sopenharmony_ci * 	<error>	label to branch to on error; implies fall-through
4362306a36Sopenharmony_ci * 		macro on success
4462306a36Sopenharmony_ci * On Exit:
4562306a36Sopenharmony_ci * 	<aa>	preserved
4662306a36Sopenharmony_ci * 	<as>	preserved
4762306a36Sopenharmony_ci * 	<at>	destroyed (actually, (TASK_SIZE + 1 - size))
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_ci	.macro	user_ok	aa, as, at, error
5062306a36Sopenharmony_ci	movi	\at, __XTENSA_UL_CONST(TASK_SIZE)
5162306a36Sopenharmony_ci	bgeu	\as, \at, \error
5262306a36Sopenharmony_ci	sub	\at, \at, \as
5362306a36Sopenharmony_ci	bgeu	\aa, \at, \error
5462306a36Sopenharmony_ci	.endm
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/*
5762306a36Sopenharmony_ci * access_ok determines whether a memory access is allowed.  See the
5862306a36Sopenharmony_ci * equivalent C-macro version below for clarity.
5962306a36Sopenharmony_ci *
6062306a36Sopenharmony_ci * On error, access_ok branches to a label indicated by parameter
6162306a36Sopenharmony_ci * <error>.  This implies that the macro falls through to the next
6262306a36Sopenharmony_ci * instruction on success.
6362306a36Sopenharmony_ci *
6462306a36Sopenharmony_ci * Note that we assume success is the common case, and we optimize the
6562306a36Sopenharmony_ci * branch fall-through case on success.
6662306a36Sopenharmony_ci *
6762306a36Sopenharmony_ci * On Entry:
6862306a36Sopenharmony_ci * 	<aa>	register containing memory address
6962306a36Sopenharmony_ci * 	<as>	register containing memory size
7062306a36Sopenharmony_ci * 	<at>	temp register
7162306a36Sopenharmony_ci * 	<sp>
7262306a36Sopenharmony_ci * 	<error>	label to branch to on error; implies fall-through
7362306a36Sopenharmony_ci * 		macro on success
7462306a36Sopenharmony_ci * On Exit:
7562306a36Sopenharmony_ci * 	<aa>	preserved
7662306a36Sopenharmony_ci * 	<as>	preserved
7762306a36Sopenharmony_ci * 	<at>	destroyed
7862306a36Sopenharmony_ci */
7962306a36Sopenharmony_ci	.macro	access_ok  aa, as, at, sp, error
8062306a36Sopenharmony_ci	user_ok    \aa, \as, \at, \error
8162306a36Sopenharmony_ci.Laccess_ok_\@:
8262306a36Sopenharmony_ci	.endm
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#endif	/* _XTENSA_ASM_UACCESS_H */
85