xref: /OK3568_Linux_fs/kernel/arch/xtensa/include/asm/coprocessor.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * include/asm-xtensa/coprocessor.h
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
5*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
6*4882a593Smuzhiyun  * for more details.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright (C) 2003 - 2007 Tensilica Inc.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #ifndef _XTENSA_COPROCESSOR_H
13*4882a593Smuzhiyun #define _XTENSA_COPROCESSOR_H
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <variant/tie.h>
16*4882a593Smuzhiyun #include <asm/core.h>
17*4882a593Smuzhiyun #include <asm/types.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #ifdef __ASSEMBLY__
20*4882a593Smuzhiyun # include <variant/tie-asm.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun .macro	xchal_sa_start  a b
23*4882a593Smuzhiyun 	.set .Lxchal_pofs_, 0
24*4882a593Smuzhiyun 	.set .Lxchal_ofs_, 0
25*4882a593Smuzhiyun .endm
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun .macro	xchal_sa_align  ptr minofs maxofs ofsalign totalign
28*4882a593Smuzhiyun 	.set	.Lxchal_ofs_, .Lxchal_ofs_ + .Lxchal_pofs_ + \totalign - 1
29*4882a593Smuzhiyun 	.set	.Lxchal_ofs_, (.Lxchal_ofs_ & -\totalign) - .Lxchal_pofs_
30*4882a593Smuzhiyun .endm
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #define _SELECT	(  XTHAL_SAS_TIE | XTHAL_SAS_OPT \
33*4882a593Smuzhiyun 		 | XTHAL_SAS_CC \
34*4882a593Smuzhiyun 		 | XTHAL_SAS_CALR | XTHAL_SAS_CALE )
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun .macro save_xtregs_opt ptr clb at1 at2 at3 at4 offset
37*4882a593Smuzhiyun 	.if XTREGS_OPT_SIZE > 0
38*4882a593Smuzhiyun 		addi	\clb, \ptr, \offset
39*4882a593Smuzhiyun 		xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
40*4882a593Smuzhiyun 	.endif
41*4882a593Smuzhiyun .endm
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun .macro load_xtregs_opt ptr clb at1 at2 at3 at4 offset
44*4882a593Smuzhiyun 	.if XTREGS_OPT_SIZE > 0
45*4882a593Smuzhiyun 		addi	\clb, \ptr, \offset
46*4882a593Smuzhiyun 		xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
47*4882a593Smuzhiyun 	.endif
48*4882a593Smuzhiyun .endm
49*4882a593Smuzhiyun #undef _SELECT
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun #define _SELECT	(  XTHAL_SAS_TIE | XTHAL_SAS_OPT \
52*4882a593Smuzhiyun 		 | XTHAL_SAS_NOCC \
53*4882a593Smuzhiyun 		 | XTHAL_SAS_CALR | XTHAL_SAS_CALE | XTHAL_SAS_GLOB )
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun .macro save_xtregs_user ptr clb at1 at2 at3 at4 offset
56*4882a593Smuzhiyun 	.if XTREGS_USER_SIZE > 0
57*4882a593Smuzhiyun 		addi	\clb, \ptr, \offset
58*4882a593Smuzhiyun 		xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
59*4882a593Smuzhiyun 	.endif
60*4882a593Smuzhiyun .endm
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun .macro load_xtregs_user ptr clb at1 at2 at3 at4 offset
63*4882a593Smuzhiyun 	.if XTREGS_USER_SIZE > 0
64*4882a593Smuzhiyun 		addi	\clb, \ptr, \offset
65*4882a593Smuzhiyun 		xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
66*4882a593Smuzhiyun 	.endif
67*4882a593Smuzhiyun .endm
68*4882a593Smuzhiyun #undef _SELECT
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun #endif	/* __ASSEMBLY__ */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun  * XTENSA_HAVE_COPROCESSOR(x) returns 1 if coprocessor x is configured.
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  * XTENSA_HAVE_IO_PORT(x) returns 1 if io-port x is configured.
78*4882a593Smuzhiyun  *
79*4882a593Smuzhiyun  */
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun #define XTENSA_HAVE_COPROCESSOR(x)					\
82*4882a593Smuzhiyun 	((XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK) & (1 << (x)))
83*4882a593Smuzhiyun #define XTENSA_HAVE_COPROCESSORS					\
84*4882a593Smuzhiyun 	(XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK)
85*4882a593Smuzhiyun #define XTENSA_HAVE_IO_PORT(x)						\
86*4882a593Smuzhiyun 	(XCHAL_CP_PORT_MASK & (1 << (x)))
87*4882a593Smuzhiyun #define XTENSA_HAVE_IO_PORTS						\
88*4882a593Smuzhiyun 	XCHAL_CP_PORT_MASK
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun #ifndef __ASSEMBLY__
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /*
93*4882a593Smuzhiyun  * Additional registers.
94*4882a593Smuzhiyun  * We define three types of additional registers:
95*4882a593Smuzhiyun  *  ext: extra registers that are used by the compiler
96*4882a593Smuzhiyun  *  cpn: optional registers that can be used by a user application
97*4882a593Smuzhiyun  *  cpX: coprocessor registers that can only be used if the corresponding
98*4882a593Smuzhiyun  *       CPENABLE bit is set.
99*4882a593Smuzhiyun  */
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun #define XCHAL_SA_REG(list,cc,abi,type,y,name,z,align,size,...)	\
102*4882a593Smuzhiyun 	__REG ## list (cc, abi, type, name, size, align)
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #define __REG0(cc,abi,t,name,s,a)	__REG0_ ## cc (abi,name)
105*4882a593Smuzhiyun #define __REG1(cc,abi,t,name,s,a)	__REG1_ ## cc (name)
106*4882a593Smuzhiyun #define __REG2(cc,abi,type,...)		__REG2_ ## type (__VA_ARGS__)
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun #define __REG0_0(abi,name)
109*4882a593Smuzhiyun #define __REG0_1(abi,name)		__REG0_1 ## abi (name)
110*4882a593Smuzhiyun #define __REG0_10(name)	__u32 name;
111*4882a593Smuzhiyun #define __REG0_11(name)	__u32 name;
112*4882a593Smuzhiyun #define __REG0_12(name)
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #define __REG1_0(name)	__u32 name;
115*4882a593Smuzhiyun #define __REG1_1(name)
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define __REG2_0(n,s,a)	__u32 name;
118*4882a593Smuzhiyun #define __REG2_1(n,s,a)	unsigned char n[s] __attribute__ ((aligned(a)));
119*4882a593Smuzhiyun #define __REG2_2(n,s,a) unsigned char n[s] __attribute__ ((aligned(a)));
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun typedef struct { XCHAL_NCP_SA_LIST(0) } xtregs_opt_t
122*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
123*4882a593Smuzhiyun typedef struct { XCHAL_NCP_SA_LIST(1) } xtregs_user_t
124*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun #if XTENSA_HAVE_COPROCESSORS
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun typedef struct { XCHAL_CP0_SA_LIST(2) } xtregs_cp0_t
129*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP0_SA_ALIGN)));
130*4882a593Smuzhiyun typedef struct { XCHAL_CP1_SA_LIST(2) } xtregs_cp1_t
131*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP1_SA_ALIGN)));
132*4882a593Smuzhiyun typedef struct { XCHAL_CP2_SA_LIST(2) } xtregs_cp2_t
133*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP2_SA_ALIGN)));
134*4882a593Smuzhiyun typedef struct { XCHAL_CP3_SA_LIST(2) } xtregs_cp3_t
135*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP3_SA_ALIGN)));
136*4882a593Smuzhiyun typedef struct { XCHAL_CP4_SA_LIST(2) } xtregs_cp4_t
137*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP4_SA_ALIGN)));
138*4882a593Smuzhiyun typedef struct { XCHAL_CP5_SA_LIST(2) } xtregs_cp5_t
139*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP5_SA_ALIGN)));
140*4882a593Smuzhiyun typedef struct { XCHAL_CP6_SA_LIST(2) } xtregs_cp6_t
141*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP6_SA_ALIGN)));
142*4882a593Smuzhiyun typedef struct { XCHAL_CP7_SA_LIST(2) } xtregs_cp7_t
143*4882a593Smuzhiyun 	__attribute__ ((aligned (XCHAL_CP7_SA_ALIGN)));
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun extern struct thread_info* coprocessor_owner[XCHAL_CP_MAX];
146*4882a593Smuzhiyun extern void coprocessor_flush(struct thread_info*, int);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun extern void coprocessor_release_all(struct thread_info*);
149*4882a593Smuzhiyun extern void coprocessor_flush_all(struct thread_info*);
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun #endif	/* XTENSA_HAVE_COPROCESSORS */
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun #endif	/* !__ASSEMBLY__ */
154*4882a593Smuzhiyun #endif	/* _XTENSA_COPROCESSOR_H */
155