18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * include/asm-xtensa/coprocessor.h
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
58c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
68c2ecf20Sopenharmony_ci * for more details.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (C) 2003 - 2007 Tensilica Inc.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef _XTENSA_COPROCESSOR_H
138c2ecf20Sopenharmony_ci#define _XTENSA_COPROCESSOR_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <variant/tie.h>
168c2ecf20Sopenharmony_ci#include <asm/core.h>
178c2ecf20Sopenharmony_ci#include <asm/types.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifdef __ASSEMBLY__
208c2ecf20Sopenharmony_ci# include <variant/tie-asm.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci.macro	xchal_sa_start  a b
238c2ecf20Sopenharmony_ci	.set .Lxchal_pofs_, 0
248c2ecf20Sopenharmony_ci	.set .Lxchal_ofs_, 0
258c2ecf20Sopenharmony_ci.endm
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci.macro	xchal_sa_align  ptr minofs maxofs ofsalign totalign
288c2ecf20Sopenharmony_ci	.set	.Lxchal_ofs_, .Lxchal_ofs_ + .Lxchal_pofs_ + \totalign - 1
298c2ecf20Sopenharmony_ci	.set	.Lxchal_ofs_, (.Lxchal_ofs_ & -\totalign) - .Lxchal_pofs_
308c2ecf20Sopenharmony_ci.endm
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define _SELECT	(  XTHAL_SAS_TIE | XTHAL_SAS_OPT \
338c2ecf20Sopenharmony_ci		 | XTHAL_SAS_CC \
348c2ecf20Sopenharmony_ci		 | XTHAL_SAS_CALR | XTHAL_SAS_CALE )
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci.macro save_xtregs_opt ptr clb at1 at2 at3 at4 offset
378c2ecf20Sopenharmony_ci	.if XTREGS_OPT_SIZE > 0
388c2ecf20Sopenharmony_ci		addi	\clb, \ptr, \offset
398c2ecf20Sopenharmony_ci		xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
408c2ecf20Sopenharmony_ci	.endif
418c2ecf20Sopenharmony_ci.endm
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci.macro load_xtregs_opt ptr clb at1 at2 at3 at4 offset
448c2ecf20Sopenharmony_ci	.if XTREGS_OPT_SIZE > 0
458c2ecf20Sopenharmony_ci		addi	\clb, \ptr, \offset
468c2ecf20Sopenharmony_ci		xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
478c2ecf20Sopenharmony_ci	.endif
488c2ecf20Sopenharmony_ci.endm
498c2ecf20Sopenharmony_ci#undef _SELECT
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define _SELECT	(  XTHAL_SAS_TIE | XTHAL_SAS_OPT \
528c2ecf20Sopenharmony_ci		 | XTHAL_SAS_NOCC \
538c2ecf20Sopenharmony_ci		 | XTHAL_SAS_CALR | XTHAL_SAS_CALE | XTHAL_SAS_GLOB )
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci.macro save_xtregs_user ptr clb at1 at2 at3 at4 offset
568c2ecf20Sopenharmony_ci	.if XTREGS_USER_SIZE > 0
578c2ecf20Sopenharmony_ci		addi	\clb, \ptr, \offset
588c2ecf20Sopenharmony_ci		xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
598c2ecf20Sopenharmony_ci	.endif
608c2ecf20Sopenharmony_ci.endm
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci.macro load_xtregs_user ptr clb at1 at2 at3 at4 offset
638c2ecf20Sopenharmony_ci	.if XTREGS_USER_SIZE > 0
648c2ecf20Sopenharmony_ci		addi	\clb, \ptr, \offset
658c2ecf20Sopenharmony_ci		xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
668c2ecf20Sopenharmony_ci	.endif
678c2ecf20Sopenharmony_ci.endm
688c2ecf20Sopenharmony_ci#undef _SELECT
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#endif	/* __ASSEMBLY__ */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/*
758c2ecf20Sopenharmony_ci * XTENSA_HAVE_COPROCESSOR(x) returns 1 if coprocessor x is configured.
768c2ecf20Sopenharmony_ci *
778c2ecf20Sopenharmony_ci * XTENSA_HAVE_IO_PORT(x) returns 1 if io-port x is configured.
788c2ecf20Sopenharmony_ci *
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define XTENSA_HAVE_COPROCESSOR(x)					\
828c2ecf20Sopenharmony_ci	((XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK) & (1 << (x)))
838c2ecf20Sopenharmony_ci#define XTENSA_HAVE_COPROCESSORS					\
848c2ecf20Sopenharmony_ci	(XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK)
858c2ecf20Sopenharmony_ci#define XTENSA_HAVE_IO_PORT(x)						\
868c2ecf20Sopenharmony_ci	(XCHAL_CP_PORT_MASK & (1 << (x)))
878c2ecf20Sopenharmony_ci#define XTENSA_HAVE_IO_PORTS						\
888c2ecf20Sopenharmony_ci	XCHAL_CP_PORT_MASK
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/*
938c2ecf20Sopenharmony_ci * Additional registers.
948c2ecf20Sopenharmony_ci * We define three types of additional registers:
958c2ecf20Sopenharmony_ci *  ext: extra registers that are used by the compiler
968c2ecf20Sopenharmony_ci *  cpn: optional registers that can be used by a user application
978c2ecf20Sopenharmony_ci *  cpX: coprocessor registers that can only be used if the corresponding
988c2ecf20Sopenharmony_ci *       CPENABLE bit is set.
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define XCHAL_SA_REG(list,cc,abi,type,y,name,z,align,size,...)	\
1028c2ecf20Sopenharmony_ci	__REG ## list (cc, abi, type, name, size, align)
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define __REG0(cc,abi,t,name,s,a)	__REG0_ ## cc (abi,name)
1058c2ecf20Sopenharmony_ci#define __REG1(cc,abi,t,name,s,a)	__REG1_ ## cc (name)
1068c2ecf20Sopenharmony_ci#define __REG2(cc,abi,type,...)		__REG2_ ## type (__VA_ARGS__)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define __REG0_0(abi,name)
1098c2ecf20Sopenharmony_ci#define __REG0_1(abi,name)		__REG0_1 ## abi (name)
1108c2ecf20Sopenharmony_ci#define __REG0_10(name)	__u32 name;
1118c2ecf20Sopenharmony_ci#define __REG0_11(name)	__u32 name;
1128c2ecf20Sopenharmony_ci#define __REG0_12(name)
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define __REG1_0(name)	__u32 name;
1158c2ecf20Sopenharmony_ci#define __REG1_1(name)
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define __REG2_0(n,s,a)	__u32 name;
1188c2ecf20Sopenharmony_ci#define __REG2_1(n,s,a)	unsigned char n[s] __attribute__ ((aligned(a)));
1198c2ecf20Sopenharmony_ci#define __REG2_2(n,s,a) unsigned char n[s] __attribute__ ((aligned(a)));
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_citypedef struct { XCHAL_NCP_SA_LIST(0) } xtregs_opt_t
1228c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
1238c2ecf20Sopenharmony_citypedef struct { XCHAL_NCP_SA_LIST(1) } xtregs_user_t
1248c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#if XTENSA_HAVE_COPROCESSORS
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_citypedef struct { XCHAL_CP0_SA_LIST(2) } xtregs_cp0_t
1298c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP0_SA_ALIGN)));
1308c2ecf20Sopenharmony_citypedef struct { XCHAL_CP1_SA_LIST(2) } xtregs_cp1_t
1318c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP1_SA_ALIGN)));
1328c2ecf20Sopenharmony_citypedef struct { XCHAL_CP2_SA_LIST(2) } xtregs_cp2_t
1338c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP2_SA_ALIGN)));
1348c2ecf20Sopenharmony_citypedef struct { XCHAL_CP3_SA_LIST(2) } xtregs_cp3_t
1358c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP3_SA_ALIGN)));
1368c2ecf20Sopenharmony_citypedef struct { XCHAL_CP4_SA_LIST(2) } xtregs_cp4_t
1378c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP4_SA_ALIGN)));
1388c2ecf20Sopenharmony_citypedef struct { XCHAL_CP5_SA_LIST(2) } xtregs_cp5_t
1398c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP5_SA_ALIGN)));
1408c2ecf20Sopenharmony_citypedef struct { XCHAL_CP6_SA_LIST(2) } xtregs_cp6_t
1418c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP6_SA_ALIGN)));
1428c2ecf20Sopenharmony_citypedef struct { XCHAL_CP7_SA_LIST(2) } xtregs_cp7_t
1438c2ecf20Sopenharmony_ci	__attribute__ ((aligned (XCHAL_CP7_SA_ALIGN)));
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ciextern struct thread_info* coprocessor_owner[XCHAL_CP_MAX];
1468c2ecf20Sopenharmony_ciextern void coprocessor_flush(struct thread_info*, int);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ciextern void coprocessor_release_all(struct thread_info*);
1498c2ecf20Sopenharmony_ciextern void coprocessor_flush_all(struct thread_info*);
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#endif	/* XTENSA_HAVE_COPROCESSORS */
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#endif	/* !__ASSEMBLY__ */
1548c2ecf20Sopenharmony_ci#endif	/* _XTENSA_COPROCESSOR_H */
155