blob: 677501b32dfcfa0b5a8471c73cc118b3d4415855 [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * include/asm-xtensa/coprocessor.h
Chris Zankel9a8fd552005-06-23 22:01:26 -07003 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
Chris Zankelc658eac2008-02-12 13:17:07 -08008 * Copyright (C) 2003 - 2007 Tensilica Inc.
Chris Zankel9a8fd552005-06-23 22:01:26 -07009 */
10
Chris Zankelc658eac2008-02-12 13:17:07 -080011
Chris Zankel9a8fd552005-06-23 22:01:26 -070012#ifndef _XTENSA_COPROCESSOR_H
13#define _XTENSA_COPROCESSOR_H
14
Chris Zankelc658eac2008-02-12 13:17:07 -080015#include <linux/stringify.h>
Chris Zankeld1eca292010-05-03 01:06:43 -070016#include <variant/core.h>
Chris Zankel367b8112008-11-06 06:40:46 -080017#include <variant/tie.h>
Chris Zankelc658eac2008-02-12 13:17:07 -080018#include <asm/types.h>
Chris Zankel173d66812006-12-10 02:18:48 -080019
Chris Zankelc658eac2008-02-12 13:17:07 -080020#ifdef __ASSEMBLY__
Chris Zankel367b8112008-11-06 06:40:46 -080021# include <variant/tie-asm.h>
Chris Zankel173d66812006-12-10 02:18:48 -080022
Chris Zankelc658eac2008-02-12 13:17:07 -080023.macro xchal_sa_start a b
24 .set .Lxchal_pofs_, 0
25 .set .Lxchal_ofs_, 0
26.endm
Chris Zankel173d66812006-12-10 02:18:48 -080027
Chris Zankelc658eac2008-02-12 13:17:07 -080028.macro xchal_sa_align ptr minofs maxofs ofsalign totalign
29 .set .Lxchal_ofs_, .Lxchal_ofs_ + .Lxchal_pofs_ + \totalign - 1
30 .set .Lxchal_ofs_, (.Lxchal_ofs_ & -\totalign) - .Lxchal_pofs_
31.endm
Chris Zankel9a8fd552005-06-23 22:01:26 -070032
Chris Zankelc658eac2008-02-12 13:17:07 -080033#define _SELECT ( XTHAL_SAS_TIE | XTHAL_SAS_OPT \
34 | XTHAL_SAS_CC \
Chris Zankel67926252008-01-15 09:49:18 -080035 | XTHAL_SAS_CALR | XTHAL_SAS_CALE )
Chris Zankel9a8fd552005-06-23 22:01:26 -070036
Chris Zankelc658eac2008-02-12 13:17:07 -080037.macro save_xtregs_opt ptr clb at1 at2 at3 at4 offset
38 .if XTREGS_OPT_SIZE > 0
39 addi \clb, \ptr, \offset
40 xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
41 .endif
42.endm
Chris Zankel9a8fd552005-06-23 22:01:26 -070043
Chris Zankelc658eac2008-02-12 13:17:07 -080044.macro load_xtregs_opt ptr clb at1 at2 at3 at4 offset
45 .if XTREGS_OPT_SIZE > 0
46 addi \clb, \ptr, \offset
47 xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
48 .endif
49.endm
50#undef _SELECT
Chris Zankel9a8fd552005-06-23 22:01:26 -070051
Chris Zankelc658eac2008-02-12 13:17:07 -080052#define _SELECT ( XTHAL_SAS_TIE | XTHAL_SAS_OPT \
53 | XTHAL_SAS_NOCC \
54 | XTHAL_SAS_CALR | XTHAL_SAS_CALE | XTHAL_SAS_GLOB )
55
56.macro save_xtregs_user ptr clb at1 at2 at3 at4 offset
57 .if XTREGS_USER_SIZE > 0
58 addi \clb, \ptr, \offset
59 xchal_ncp_store \clb \at1 \at2 \at3 \at4 select=_SELECT
60 .endif
61.endm
62
63.macro load_xtregs_user ptr clb at1 at2 at3 at4 offset
64 .if XTREGS_USER_SIZE > 0
65 addi \clb, \ptr, \offset
66 xchal_ncp_load \clb \at1 \at2 \at3 \at4 select=_SELECT
67 .endif
68.endm
69#undef _SELECT
70
71
72
73#endif /* __ASSEMBLY__ */
74
Chris Zankel9a8fd552005-06-23 22:01:26 -070075/*
Chris Zankelc658eac2008-02-12 13:17:07 -080076 * XTENSA_HAVE_COPROCESSOR(x) returns 1 if coprocessor x is configured.
77 *
78 * XTENSA_HAVE_IO_PORT(x) returns 1 if io-port x is configured.
79 *
Chris Zankel9a8fd552005-06-23 22:01:26 -070080 */
Chris Zankel9a8fd552005-06-23 22:01:26 -070081
Chris Zankelc658eac2008-02-12 13:17:07 -080082#define XTENSA_HAVE_COPROCESSOR(x) \
83 ((XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK) & (1 << (x)))
84#define XTENSA_HAVE_COPROCESSORS \
85 (XCHAL_CP_MASK ^ XCHAL_CP_PORT_MASK)
86#define XTENSA_HAVE_IO_PORT(x) \
87 (XCHAL_CP_PORT_MASK & (1 << (x)))
88#define XTENSA_HAVE_IO_PORTS \
89 XCHAL_CP_PORT_MASK
Chris Zankel9a8fd552005-06-23 22:01:26 -070090
91#ifndef __ASSEMBLY__
Chris Zankel9a8fd552005-06-23 22:01:26 -070092
Chris Zankelc658eac2008-02-12 13:17:07 -080093
94#if XCHAL_HAVE_CP
95
96#define RSR_CPENABLE(x) do { \
Max Filippovbc5378f2012-10-15 03:55:38 +040097 __asm__ __volatile__("rsr %0, cpenable" : "=a" (x)); \
Chris Zankelc658eac2008-02-12 13:17:07 -080098 } while(0);
99#define WSR_CPENABLE(x) do { \
Max Filippovbc5378f2012-10-15 03:55:38 +0400100 __asm__ __volatile__("wsr %0, cpenable; rsync" :: "a" (x)); \
Chris Zankelc658eac2008-02-12 13:17:07 -0800101 } while(0);
102
103#endif /* XCHAL_HAVE_CP */
104
105
106/*
107 * Additional registers.
108 * We define three types of additional registers:
109 * ext: extra registers that are used by the compiler
110 * cpn: optional registers that can be used by a user application
111 * cpX: coprocessor registers that can only be used if the corresponding
112 * CPENABLE bit is set.
113 */
114
Chris Zankel67926252008-01-15 09:49:18 -0800115#define XCHAL_SA_REG(list,cc,abi,type,y,name,z,align,size,...) \
116 __REG ## list (cc, abi, type, name, size, align)
Chris Zankelc658eac2008-02-12 13:17:07 -0800117
Chris Zankel67926252008-01-15 09:49:18 -0800118#define __REG0(cc,abi,t,name,s,a) __REG0_ ## cc (abi,name)
119#define __REG1(cc,abi,t,name,s,a) __REG1_ ## cc (name)
120#define __REG2(cc,abi,type,...) __REG2_ ## type (__VA_ARGS__)
Chris Zankelc658eac2008-02-12 13:17:07 -0800121
Chris Zankel67926252008-01-15 09:49:18 -0800122#define __REG0_0(abi,name)
123#define __REG0_1(abi,name) __REG0_1 ## abi (name)
124#define __REG0_10(name) __u32 name;
125#define __REG0_11(name) __u32 name;
126#define __REG0_12(name)
127
Chris Zankelc658eac2008-02-12 13:17:07 -0800128#define __REG1_0(name) __u32 name;
129#define __REG1_1(name)
Chris Zankel67926252008-01-15 09:49:18 -0800130
Chris Zankelc658eac2008-02-12 13:17:07 -0800131#define __REG2_0(n,s,a) __u32 name;
132#define __REG2_1(n,s,a) unsigned char n[s] __attribute__ ((aligned(a)));
133#define __REG2_2(n,s,a) unsigned char n[s] __attribute__ ((aligned(a)));
134
135typedef struct { XCHAL_NCP_SA_LIST(0) } xtregs_opt_t
136 __attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
137typedef struct { XCHAL_NCP_SA_LIST(1) } xtregs_user_t
138 __attribute__ ((aligned (XCHAL_NCP_SA_ALIGN)));
139
140#if XTENSA_HAVE_COPROCESSORS
141
142typedef struct { XCHAL_CP0_SA_LIST(2) } xtregs_cp0_t
143 __attribute__ ((aligned (XCHAL_CP0_SA_ALIGN)));
144typedef struct { XCHAL_CP1_SA_LIST(2) } xtregs_cp1_t
145 __attribute__ ((aligned (XCHAL_CP1_SA_ALIGN)));
146typedef struct { XCHAL_CP2_SA_LIST(2) } xtregs_cp2_t
147 __attribute__ ((aligned (XCHAL_CP2_SA_ALIGN)));
148typedef struct { XCHAL_CP3_SA_LIST(2) } xtregs_cp3_t
149 __attribute__ ((aligned (XCHAL_CP3_SA_ALIGN)));
150typedef struct { XCHAL_CP4_SA_LIST(2) } xtregs_cp4_t
151 __attribute__ ((aligned (XCHAL_CP4_SA_ALIGN)));
152typedef struct { XCHAL_CP5_SA_LIST(2) } xtregs_cp5_t
153 __attribute__ ((aligned (XCHAL_CP5_SA_ALIGN)));
154typedef struct { XCHAL_CP6_SA_LIST(2) } xtregs_cp6_t
155 __attribute__ ((aligned (XCHAL_CP6_SA_ALIGN)));
156typedef struct { XCHAL_CP7_SA_LIST(2) } xtregs_cp7_t
157 __attribute__ ((aligned (XCHAL_CP7_SA_ALIGN)));
158
159extern struct thread_info* coprocessor_owner[XCHAL_CP_MAX];
160extern void coprocessor_save(void*, int);
161extern void coprocessor_load(void*, int);
162extern void coprocessor_flush(struct thread_info*, int);
163extern void coprocessor_restore(struct thread_info*, int);
164
165extern void coprocessor_release_all(struct thread_info*);
166extern void coprocessor_flush_all(struct thread_info*);
167
168static inline void coprocessor_clear_cpenable(void)
169{
170 unsigned long i = 0;
171 WSR_CPENABLE(i);
172}
173
174#endif /* XTENSA_HAVE_COPROCESSORS */
Chris Zankel29c4dfd2007-05-31 17:49:32 -0700175
176#endif /* !__ASSEMBLY__ */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700177#endif /* _XTENSA_COPROCESSOR_H */