blob: d9910a1e754a87b1a847c5c1ad98d64d312192ea [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
7 * Copyright (C) 2000 Silicon Graphics, Inc.
8 * Modified for further R[236]000 support by Paul M. Antoine, 1996.
9 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
Ralf Baechlea3692022007-07-10 17:33:02 +010010 * Copyright (C) 2000, 07 MIPS Technologies, Inc.
Ralf Baechle41943182005-05-05 16:45:59 +000011 * Copyright (C) 2003, 2004 Maciej W. Rozycki
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13#ifndef _ASM_MIPSREGS_H
14#define _ASM_MIPSREGS_H
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/linkage.h>
17#include <asm/hazards.h>
Marc St-Jean9267a302007-06-14 15:55:31 -060018#include <asm/war.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20/*
21 * The following macros are especially useful for __asm__
22 * inline assembler.
23 */
24#ifndef __STR
25#define __STR(x) #x
26#endif
27#ifndef STR
28#define STR(x) __STR(x)
29#endif
30
31/*
32 * Configure language
33 */
34#ifdef __ASSEMBLY__
35#define _ULCAST_
36#else
37#define _ULCAST_ (unsigned long)
38#endif
39
40/*
41 * Coprocessor 0 register names
42 */
43#define CP0_INDEX $0
44#define CP0_RANDOM $1
45#define CP0_ENTRYLO0 $2
46#define CP0_ENTRYLO1 $3
47#define CP0_CONF $3
48#define CP0_CONTEXT $4
49#define CP0_PAGEMASK $5
50#define CP0_WIRED $6
51#define CP0_INFO $7
52#define CP0_BADVADDR $8
53#define CP0_COUNT $9
54#define CP0_ENTRYHI $10
55#define CP0_COMPARE $11
56#define CP0_STATUS $12
57#define CP0_CAUSE $13
58#define CP0_EPC $14
59#define CP0_PRID $15
60#define CP0_CONFIG $16
61#define CP0_LLADDR $17
62#define CP0_WATCHLO $18
63#define CP0_WATCHHI $19
64#define CP0_XCONTEXT $20
65#define CP0_FRAMEMASK $21
66#define CP0_DIAGNOSTIC $22
67#define CP0_DEBUG $23
68#define CP0_DEPC $24
69#define CP0_PERFORMANCE $25
70#define CP0_ECC $26
71#define CP0_CACHEERR $27
72#define CP0_TAGLO $28
73#define CP0_TAGHI $29
74#define CP0_ERROREPC $30
75#define CP0_DESAVE $31
76
77/*
78 * R4640/R4650 cp0 register names. These registers are listed
79 * here only for completeness; without MMU these CPUs are not useable
80 * by Linux. A future ELKS port might take make Linux run on them
81 * though ...
82 */
83#define CP0_IBASE $0
84#define CP0_IBOUND $1
85#define CP0_DBASE $2
86#define CP0_DBOUND $3
87#define CP0_CALG $17
88#define CP0_IWATCH $18
89#define CP0_DWATCH $19
90
91/*
92 * Coprocessor 0 Set 1 register names
93 */
94#define CP0_S1_DERRADDR0 $26
95#define CP0_S1_DERRADDR1 $27
96#define CP0_S1_INTCONTROL $20
97
98/*
Ralf Baechle7a0fc582005-07-13 19:47:28 +000099 * Coprocessor 0 Set 2 register names
100 */
101#define CP0_S2_SRSCTL $12 /* MIPSR2 */
102
103/*
104 * Coprocessor 0 Set 3 register names
105 */
106#define CP0_S3_SRSMAP $12 /* MIPSR2 */
107
108/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 * TX39 Series
110 */
111#define CP0_TX39_CACHE $7
112
113/*
114 * Coprocessor 1 (FPU) register names
115 */
116#define CP1_REVISION $0
117#define CP1_STATUS $31
118
119/*
120 * FPU Status Register Values
121 */
122/*
123 * Status Register Values
124 */
125
Ralf Baechle70342282013-01-22 12:59:30 +0100126#define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
127#define FPU_CSR_COND 0x00800000 /* $fcc0 */
128#define FPU_CSR_COND0 0x00800000 /* $fcc0 */
129#define FPU_CSR_COND1 0x02000000 /* $fcc1 */
130#define FPU_CSR_COND2 0x04000000 /* $fcc2 */
131#define FPU_CSR_COND3 0x08000000 /* $fcc3 */
132#define FPU_CSR_COND4 0x10000000 /* $fcc4 */
133#define FPU_CSR_COND5 0x20000000 /* $fcc5 */
134#define FPU_CSR_COND6 0x40000000 /* $fcc6 */
135#define FPU_CSR_COND7 0x80000000 /* $fcc7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137/*
Shane McDonald95e8f632010-05-06 23:26:57 -0600138 * Bits 18 - 20 of the FPU Status Register will be read as 0,
139 * and should be written as zero.
140 */
141#define FPU_CSR_RSVD 0x001c0000
142
143/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 * X the exception cause indicator
145 * E the exception enable
146 * S the sticky/flag bit
147*/
Ralf Baechle70342282013-01-22 12:59:30 +0100148#define FPU_CSR_ALL_X 0x0003f000
149#define FPU_CSR_UNI_X 0x00020000
150#define FPU_CSR_INV_X 0x00010000
151#define FPU_CSR_DIV_X 0x00008000
152#define FPU_CSR_OVF_X 0x00004000
153#define FPU_CSR_UDF_X 0x00002000
154#define FPU_CSR_INE_X 0x00001000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Ralf Baechle70342282013-01-22 12:59:30 +0100156#define FPU_CSR_ALL_E 0x00000f80
157#define FPU_CSR_INV_E 0x00000800
158#define FPU_CSR_DIV_E 0x00000400
159#define FPU_CSR_OVF_E 0x00000200
160#define FPU_CSR_UDF_E 0x00000100
161#define FPU_CSR_INE_E 0x00000080
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Ralf Baechle70342282013-01-22 12:59:30 +0100163#define FPU_CSR_ALL_S 0x0000007c
164#define FPU_CSR_INV_S 0x00000040
165#define FPU_CSR_DIV_S 0x00000020
166#define FPU_CSR_OVF_S 0x00000010
167#define FPU_CSR_UDF_S 0x00000008
168#define FPU_CSR_INE_S 0x00000004
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Shane McDonald95e8f632010-05-06 23:26:57 -0600170/* Bits 0 and 1 of FPU Status Register specify the rounding mode */
171#define FPU_CSR_RM 0x00000003
Ralf Baechle70342282013-01-22 12:59:30 +0100172#define FPU_CSR_RN 0x0 /* nearest */
173#define FPU_CSR_RZ 0x1 /* towards zero */
174#define FPU_CSR_RU 0x2 /* towards +Infinity */
175#define FPU_CSR_RD 0x3 /* towards -Infinity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177
178/*
179 * Values for PageMask register
180 */
181#ifdef CONFIG_CPU_VR41XX
182
183/* Why doesn't stupidity hurt ... */
184
185#define PM_1K 0x00000000
186#define PM_4K 0x00001800
187#define PM_16K 0x00007800
188#define PM_64K 0x0001f800
189#define PM_256K 0x0007f800
190
191#else
192
193#define PM_4K 0x00000000
Ralf Baechlec52399b2009-04-02 14:07:10 +0200194#define PM_8K 0x00002000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define PM_16K 0x00006000
Ralf Baechlec52399b2009-04-02 14:07:10 +0200196#define PM_32K 0x0000e000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define PM_64K 0x0001e000
Ralf Baechlec52399b2009-04-02 14:07:10 +0200198#define PM_128K 0x0003e000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define PM_256K 0x0007e000
Ralf Baechlec52399b2009-04-02 14:07:10 +0200200#define PM_512K 0x000fe000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define PM_1M 0x001fe000
Ralf Baechlec52399b2009-04-02 14:07:10 +0200202#define PM_2M 0x003fe000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#define PM_4M 0x007fe000
Ralf Baechlec52399b2009-04-02 14:07:10 +0200204#define PM_8M 0x00ffe000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define PM_16M 0x01ffe000
Ralf Baechlec52399b2009-04-02 14:07:10 +0200206#define PM_32M 0x03ffe000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define PM_64M 0x07ffe000
208#define PM_256M 0x1fffe000
Shinya Kuribayashi542c1022008-10-24 01:27:57 +0900209#define PM_1G 0x7fffe000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211#endif
212
213/*
214 * Default page size for a given kernel configuration
215 */
216#ifdef CONFIG_PAGE_SIZE_4KB
Ralf Baechle70342282013-01-22 12:59:30 +0100217#define PM_DEFAULT_MASK PM_4K
Ralf Baechlec52399b2009-04-02 14:07:10 +0200218#elif defined(CONFIG_PAGE_SIZE_8KB)
Ralf Baechle70342282013-01-22 12:59:30 +0100219#define PM_DEFAULT_MASK PM_8K
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#elif defined(CONFIG_PAGE_SIZE_16KB)
Ralf Baechle70342282013-01-22 12:59:30 +0100221#define PM_DEFAULT_MASK PM_16K
Ralf Baechlec52399b2009-04-02 14:07:10 +0200222#elif defined(CONFIG_PAGE_SIZE_32KB)
Ralf Baechle70342282013-01-22 12:59:30 +0100223#define PM_DEFAULT_MASK PM_32K
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#elif defined(CONFIG_PAGE_SIZE_64KB)
Ralf Baechle70342282013-01-22 12:59:30 +0100225#define PM_DEFAULT_MASK PM_64K
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#else
227#error Bad page size configuration!
228#endif
229
David Daneydd794392009-05-27 17:47:43 -0700230/*
231 * Default huge tlb size for a given kernel configuration
232 */
233#ifdef CONFIG_PAGE_SIZE_4KB
234#define PM_HUGE_MASK PM_1M
235#elif defined(CONFIG_PAGE_SIZE_8KB)
236#define PM_HUGE_MASK PM_4M
237#elif defined(CONFIG_PAGE_SIZE_16KB)
238#define PM_HUGE_MASK PM_16M
239#elif defined(CONFIG_PAGE_SIZE_32KB)
240#define PM_HUGE_MASK PM_64M
241#elif defined(CONFIG_PAGE_SIZE_64KB)
242#define PM_HUGE_MASK PM_256M
David Daneyaa1762f2012-10-17 00:48:10 +0200243#elif defined(CONFIG_MIPS_HUGE_TLB_SUPPORT)
David Daneydd794392009-05-27 17:47:43 -0700244#error Bad page size configuration for hugetlbfs!
245#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247/*
248 * Values used for computation of new tlb entries
249 */
250#define PL_4K 12
251#define PL_16K 14
252#define PL_64K 16
253#define PL_256K 18
254#define PL_1M 20
255#define PL_4M 22
256#define PL_16M 24
257#define PL_64M 26
258#define PL_256M 28
259
260/*
David Daney9fe2e9d2010-02-10 15:12:45 -0800261 * PageGrain bits
262 */
Ralf Baechle70342282013-01-22 12:59:30 +0100263#define PG_RIE (_ULCAST_(1) << 31)
264#define PG_XIE (_ULCAST_(1) << 30)
265#define PG_ELPA (_ULCAST_(1) << 29)
266#define PG_ESP (_ULCAST_(1) << 28)
David Daney9fe2e9d2010-02-10 15:12:45 -0800267
268/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 * R4x00 interrupt enable / cause bits
270 */
Ralf Baechle70342282013-01-22 12:59:30 +0100271#define IE_SW0 (_ULCAST_(1) << 8)
272#define IE_SW1 (_ULCAST_(1) << 9)
273#define IE_IRQ0 (_ULCAST_(1) << 10)
274#define IE_IRQ1 (_ULCAST_(1) << 11)
275#define IE_IRQ2 (_ULCAST_(1) << 12)
276#define IE_IRQ3 (_ULCAST_(1) << 13)
277#define IE_IRQ4 (_ULCAST_(1) << 14)
278#define IE_IRQ5 (_ULCAST_(1) << 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280/*
281 * R4x00 interrupt cause bits
282 */
Ralf Baechle70342282013-01-22 12:59:30 +0100283#define C_SW0 (_ULCAST_(1) << 8)
284#define C_SW1 (_ULCAST_(1) << 9)
285#define C_IRQ0 (_ULCAST_(1) << 10)
286#define C_IRQ1 (_ULCAST_(1) << 11)
287#define C_IRQ2 (_ULCAST_(1) << 12)
288#define C_IRQ3 (_ULCAST_(1) << 13)
289#define C_IRQ4 (_ULCAST_(1) << 14)
290#define C_IRQ5 (_ULCAST_(1) << 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292/*
293 * Bitfields in the R4xx0 cp0 status register
294 */
295#define ST0_IE 0x00000001
296#define ST0_EXL 0x00000002
297#define ST0_ERL 0x00000004
298#define ST0_KSU 0x00000018
299# define KSU_USER 0x00000010
300# define KSU_SUPERVISOR 0x00000008
301# define KSU_KERNEL 0x00000000
302#define ST0_UX 0x00000020
303#define ST0_SX 0x00000040
Ralf Baechle70342282013-01-22 12:59:30 +0100304#define ST0_KX 0x00000080
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305#define ST0_DE 0x00010000
306#define ST0_CE 0x00020000
307
308/*
309 * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
310 * cacheops in userspace. This bit exists only on RM7000 and RM9000
311 * processors.
312 */
313#define ST0_CO 0x08000000
314
315/*
316 * Bitfields in the R[23]000 cp0 status register.
317 */
Ralf Baechle70342282013-01-22 12:59:30 +0100318#define ST0_IEC 0x00000001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#define ST0_KUC 0x00000002
320#define ST0_IEP 0x00000004
321#define ST0_KUP 0x00000008
322#define ST0_IEO 0x00000010
323#define ST0_KUO 0x00000020
324/* bits 6 & 7 are reserved on R[23]000 */
325#define ST0_ISC 0x00010000
326#define ST0_SWC 0x00020000
327#define ST0_CM 0x00080000
328
329/*
330 * Bits specific to the R4640/R4650
331 */
Ralf Baechle70342282013-01-22 12:59:30 +0100332#define ST0_UM (_ULCAST_(1) << 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#define ST0_IL (_ULCAST_(1) << 23)
334#define ST0_DL (_ULCAST_(1) << 24)
335
336/*
Thiemo Seufer3301edc2006-05-15 18:24:57 +0100337 * Enable the MIPS MDMX and DSP ASEs
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000338 */
339#define ST0_MX 0x01000000
340
341/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 * Bitfields in the TX39 family CP0 Configuration Register 3
343 */
344#define TX39_CONF_ICS_SHIFT 19
345#define TX39_CONF_ICS_MASK 0x00380000
Ralf Baechle70342282013-01-22 12:59:30 +0100346#define TX39_CONF_ICS_1KB 0x00000000
347#define TX39_CONF_ICS_2KB 0x00080000
348#define TX39_CONF_ICS_4KB 0x00100000
349#define TX39_CONF_ICS_8KB 0x00180000
350#define TX39_CONF_ICS_16KB 0x00200000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352#define TX39_CONF_DCS_SHIFT 16
353#define TX39_CONF_DCS_MASK 0x00070000
Ralf Baechle70342282013-01-22 12:59:30 +0100354#define TX39_CONF_DCS_1KB 0x00000000
355#define TX39_CONF_DCS_2KB 0x00010000
356#define TX39_CONF_DCS_4KB 0x00020000
357#define TX39_CONF_DCS_8KB 0x00030000
358#define TX39_CONF_DCS_16KB 0x00040000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Ralf Baechle70342282013-01-22 12:59:30 +0100360#define TX39_CONF_CWFON 0x00004000
361#define TX39_CONF_WBON 0x00002000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#define TX39_CONF_RF_SHIFT 10
363#define TX39_CONF_RF_MASK 0x00000c00
364#define TX39_CONF_DOZE 0x00000200
365#define TX39_CONF_HALT 0x00000100
366#define TX39_CONF_LOCK 0x00000080
367#define TX39_CONF_ICE 0x00000020
368#define TX39_CONF_DCE 0x00000010
369#define TX39_CONF_IRSIZE_SHIFT 2
370#define TX39_CONF_IRSIZE_MASK 0x0000000c
371#define TX39_CONF_DRSIZE_SHIFT 0
372#define TX39_CONF_DRSIZE_MASK 0x00000003
373
374/*
375 * Status register bits available in all MIPS CPUs.
376 */
377#define ST0_IM 0x0000ff00
Ralf Baechle70342282013-01-22 12:59:30 +0100378#define STATUSB_IP0 8
379#define STATUSF_IP0 (_ULCAST_(1) << 8)
380#define STATUSB_IP1 9
381#define STATUSF_IP1 (_ULCAST_(1) << 9)
382#define STATUSB_IP2 10
383#define STATUSF_IP2 (_ULCAST_(1) << 10)
384#define STATUSB_IP3 11
385#define STATUSF_IP3 (_ULCAST_(1) << 11)
386#define STATUSB_IP4 12
387#define STATUSF_IP4 (_ULCAST_(1) << 12)
388#define STATUSB_IP5 13
389#define STATUSF_IP5 (_ULCAST_(1) << 13)
390#define STATUSB_IP6 14
391#define STATUSF_IP6 (_ULCAST_(1) << 14)
392#define STATUSB_IP7 15
393#define STATUSF_IP7 (_ULCAST_(1) << 15)
394#define STATUSB_IP8 0
395#define STATUSF_IP8 (_ULCAST_(1) << 0)
396#define STATUSB_IP9 1
397#define STATUSF_IP9 (_ULCAST_(1) << 1)
398#define STATUSB_IP10 2
399#define STATUSF_IP10 (_ULCAST_(1) << 2)
400#define STATUSB_IP11 3
401#define STATUSF_IP11 (_ULCAST_(1) << 3)
402#define STATUSB_IP12 4
403#define STATUSF_IP12 (_ULCAST_(1) << 4)
404#define STATUSB_IP13 5
405#define STATUSF_IP13 (_ULCAST_(1) << 5)
406#define STATUSB_IP14 6
407#define STATUSF_IP14 (_ULCAST_(1) << 6)
408#define STATUSB_IP15 7
409#define STATUSF_IP15 (_ULCAST_(1) << 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410#define ST0_CH 0x00040000
David Daney96ffa022010-07-23 18:41:46 -0700411#define ST0_NMI 0x00080000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#define ST0_SR 0x00100000
413#define ST0_TS 0x00200000
414#define ST0_BEV 0x00400000
415#define ST0_RE 0x02000000
416#define ST0_FR 0x04000000
417#define ST0_CU 0xf0000000
418#define ST0_CU0 0x10000000
419#define ST0_CU1 0x20000000
420#define ST0_CU2 0x40000000
421#define ST0_CU3 0x80000000
422#define ST0_XX 0x80000000 /* MIPS IV naming */
423
424/*
David VomLehn010c1082009-12-21 17:49:22 -0800425 * Bitfields and bit numbers in the coprocessor 0 IntCtl register. (MIPSR2)
426 *
427 * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
428 */
429#define INTCTLB_IPPCI 26
430#define INTCTLF_IPPCI (_ULCAST_(7) << INTCTLB_IPPCI)
431#define INTCTLB_IPTI 29
432#define INTCTLF_IPTI (_ULCAST_(7) << INTCTLB_IPTI)
433
434/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 * Bitfields and bit numbers in the coprocessor 0 cause register.
436 *
437 * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
438 */
Ralf Baechle70342282013-01-22 12:59:30 +0100439#define CAUSEB_EXCCODE 2
440#define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
441#define CAUSEB_IP 8
442#define CAUSEF_IP (_ULCAST_(255) << 8)
443#define CAUSEB_IP0 8
444#define CAUSEF_IP0 (_ULCAST_(1) << 8)
445#define CAUSEB_IP1 9
446#define CAUSEF_IP1 (_ULCAST_(1) << 9)
447#define CAUSEB_IP2 10
448#define CAUSEF_IP2 (_ULCAST_(1) << 10)
449#define CAUSEB_IP3 11
450#define CAUSEF_IP3 (_ULCAST_(1) << 11)
451#define CAUSEB_IP4 12
452#define CAUSEF_IP4 (_ULCAST_(1) << 12)
453#define CAUSEB_IP5 13
454#define CAUSEF_IP5 (_ULCAST_(1) << 13)
455#define CAUSEB_IP6 14
456#define CAUSEF_IP6 (_ULCAST_(1) << 14)
457#define CAUSEB_IP7 15
458#define CAUSEF_IP7 (_ULCAST_(1) << 15)
459#define CAUSEB_IV 23
460#define CAUSEF_IV (_ULCAST_(1) << 23)
461#define CAUSEB_PCI 26
462#define CAUSEF_PCI (_ULCAST_(1) << 26)
463#define CAUSEB_CE 28
464#define CAUSEF_CE (_ULCAST_(3) << 28)
465#define CAUSEB_TI 30
466#define CAUSEF_TI (_ULCAST_(1) << 30)
467#define CAUSEB_BD 31
468#define CAUSEF_BD (_ULCAST_(1) << 31)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470/*
471 * Bits in the coprocessor 0 config register.
472 */
473/* Generic bits. */
474#define CONF_CM_CACHABLE_NO_WA 0
475#define CONF_CM_CACHABLE_WA 1
476#define CONF_CM_UNCACHED 2
477#define CONF_CM_CACHABLE_NONCOHERENT 3
478#define CONF_CM_CACHABLE_CE 4
479#define CONF_CM_CACHABLE_COW 5
480#define CONF_CM_CACHABLE_CUW 6
481#define CONF_CM_CACHABLE_ACCELERATED 7
482#define CONF_CM_CMASK 7
483#define CONF_BE (_ULCAST_(1) << 15)
484
485/* Bits common to various processors. */
Ralf Baechle70342282013-01-22 12:59:30 +0100486#define CONF_CU (_ULCAST_(1) << 3)
487#define CONF_DB (_ULCAST_(1) << 4)
488#define CONF_IB (_ULCAST_(1) << 5)
489#define CONF_DC (_ULCAST_(7) << 6)
490#define CONF_IC (_ULCAST_(7) << 9)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define CONF_EB (_ULCAST_(1) << 13)
492#define CONF_EM (_ULCAST_(1) << 14)
493#define CONF_SM (_ULCAST_(1) << 16)
494#define CONF_SC (_ULCAST_(1) << 17)
495#define CONF_EW (_ULCAST_(3) << 18)
496#define CONF_EP (_ULCAST_(15)<< 24)
497#define CONF_EC (_ULCAST_(7) << 28)
498#define CONF_CM (_ULCAST_(1) << 31)
499
Ralf Baechle70342282013-01-22 12:59:30 +0100500/* Bits specific to the R4xx0. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define R4K_CONF_SW (_ULCAST_(1) << 20)
502#define R4K_CONF_SS (_ULCAST_(1) << 21)
Ralf Baechlee20368d2005-06-21 13:52:33 +0000503#define R4K_CONF_SB (_ULCAST_(3) << 22)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Ralf Baechle70342282013-01-22 12:59:30 +0100505/* Bits specific to the R5000. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506#define R5K_CONF_SE (_ULCAST_(1) << 12)
507#define R5K_CONF_SS (_ULCAST_(3) << 20)
508
Ralf Baechle70342282013-01-22 12:59:30 +0100509/* Bits specific to the RM7000. */
510#define RM7K_CONF_SE (_ULCAST_(1) << 3)
Maciej W. Rozyckic6ad7b72005-06-20 13:09:49 +0000511#define RM7K_CONF_TE (_ULCAST_(1) << 12)
512#define RM7K_CONF_CLK (_ULCAST_(1) << 16)
513#define RM7K_CONF_TC (_ULCAST_(1) << 17)
514#define RM7K_CONF_SI (_ULCAST_(3) << 20)
515#define RM7K_CONF_SC (_ULCAST_(1) << 31)
Thiemo Seuferba5187d2005-04-25 16:36:23 +0000516
Ralf Baechle70342282013-01-22 12:59:30 +0100517/* Bits specific to the R10000. */
518#define R10K_CONF_DN (_ULCAST_(3) << 3)
519#define R10K_CONF_CT (_ULCAST_(1) << 5)
520#define R10K_CONF_PE (_ULCAST_(1) << 6)
521#define R10K_CONF_PM (_ULCAST_(3) << 7)
522#define R10K_CONF_EC (_ULCAST_(15)<< 9)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#define R10K_CONF_SB (_ULCAST_(1) << 13)
524#define R10K_CONF_SK (_ULCAST_(1) << 14)
525#define R10K_CONF_SS (_ULCAST_(7) << 16)
526#define R10K_CONF_SC (_ULCAST_(7) << 19)
527#define R10K_CONF_DC (_ULCAST_(7) << 26)
528#define R10K_CONF_IC (_ULCAST_(7) << 29)
529
Ralf Baechle70342282013-01-22 12:59:30 +0100530/* Bits specific to the VR41xx. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#define VR41_CONF_CS (_ULCAST_(1) << 12)
Yoichi Yuasa2874fe52006-07-08 00:42:12 +0900532#define VR41_CONF_P4K (_ULCAST_(1) << 13)
Yoichi Yuasa4e8ab362006-07-04 22:59:41 +0900533#define VR41_CONF_BP (_ULCAST_(1) << 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#define VR41_CONF_M16 (_ULCAST_(1) << 20)
535#define VR41_CONF_AD (_ULCAST_(1) << 23)
536
Ralf Baechle70342282013-01-22 12:59:30 +0100537/* Bits specific to the R30xx. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#define R30XX_CONF_FDM (_ULCAST_(1) << 19)
539#define R30XX_CONF_REV (_ULCAST_(1) << 22)
540#define R30XX_CONF_AC (_ULCAST_(1) << 23)
541#define R30XX_CONF_RF (_ULCAST_(1) << 24)
542#define R30XX_CONF_HALT (_ULCAST_(1) << 25)
543#define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
544#define R30XX_CONF_DBR (_ULCAST_(1) << 29)
545#define R30XX_CONF_SB (_ULCAST_(1) << 30)
546#define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
547
548/* Bits specific to the TX49. */
549#define TX49_CONF_DC (_ULCAST_(1) << 16)
550#define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
551#define TX49_CONF_HALT (_ULCAST_(1) << 18)
552#define TX49_CONF_CWFON (_ULCAST_(1) << 27)
553
Ralf Baechle70342282013-01-22 12:59:30 +0100554/* Bits specific to the MIPS32/64 PRA. */
555#define MIPS_CONF_MT (_ULCAST_(7) << 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#define MIPS_CONF_AR (_ULCAST_(7) << 10)
557#define MIPS_CONF_AT (_ULCAST_(3) << 13)
558#define MIPS_CONF_M (_ULCAST_(1) << 31)
559
560/*
Ralf Baechle41943182005-05-05 16:45:59 +0000561 * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
562 */
Ralf Baechle70342282013-01-22 12:59:30 +0100563#define MIPS_CONF1_FP (_ULCAST_(1) << 0)
564#define MIPS_CONF1_EP (_ULCAST_(1) << 1)
565#define MIPS_CONF1_CA (_ULCAST_(1) << 2)
566#define MIPS_CONF1_WR (_ULCAST_(1) << 3)
567#define MIPS_CONF1_PC (_ULCAST_(1) << 4)
568#define MIPS_CONF1_MD (_ULCAST_(1) << 5)
569#define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
570#define MIPS_CONF1_DA (_ULCAST_(7) << 7)
Ralf Baechle41943182005-05-05 16:45:59 +0000571#define MIPS_CONF1_DL (_ULCAST_(7) << 10)
572#define MIPS_CONF1_DS (_ULCAST_(7) << 13)
573#define MIPS_CONF1_IA (_ULCAST_(7) << 16)
574#define MIPS_CONF1_IL (_ULCAST_(7) << 19)
575#define MIPS_CONF1_IS (_ULCAST_(7) << 22)
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000576#define MIPS_CONF1_TLBS_SHIFT (25)
577#define MIPS_CONF1_TLBS_SIZE (6)
578#define MIPS_CONF1_TLBS (_ULCAST_(63) << MIPS_CONF1_TLBS_SHIFT)
Ralf Baechle41943182005-05-05 16:45:59 +0000579
Ralf Baechle70342282013-01-22 12:59:30 +0100580#define MIPS_CONF2_SA (_ULCAST_(15)<< 0)
581#define MIPS_CONF2_SL (_ULCAST_(15)<< 4)
582#define MIPS_CONF2_SS (_ULCAST_(15)<< 8)
Ralf Baechle41943182005-05-05 16:45:59 +0000583#define MIPS_CONF2_SU (_ULCAST_(15)<< 12)
584#define MIPS_CONF2_TA (_ULCAST_(15)<< 16)
585#define MIPS_CONF2_TL (_ULCAST_(15)<< 20)
586#define MIPS_CONF2_TS (_ULCAST_(15)<< 24)
587#define MIPS_CONF2_TU (_ULCAST_(7) << 28)
588
Ralf Baechle70342282013-01-22 12:59:30 +0100589#define MIPS_CONF3_TL (_ULCAST_(1) << 0)
590#define MIPS_CONF3_SM (_ULCAST_(1) << 1)
591#define MIPS_CONF3_MT (_ULCAST_(1) << 2)
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000592#define MIPS_CONF3_CDMM (_ULCAST_(1) << 3)
Ralf Baechle70342282013-01-22 12:59:30 +0100593#define MIPS_CONF3_SP (_ULCAST_(1) << 4)
594#define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
595#define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
596#define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000597#define MIPS_CONF3_ITL (_ULCAST_(1) << 8)
598#define MIPS_CONF3_CTXTC (_ULCAST_(1) << 9)
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000599#define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
Steven J. Hillee80f7c72012-08-03 10:26:04 -0500600#define MIPS_CONF3_DSP2P (_ULCAST_(1) << 11)
Steven J. Hillb2ab4f02012-09-13 16:47:58 -0500601#define MIPS_CONF3_RXI (_ULCAST_(1) << 12)
Ralf Baechlea3692022007-07-10 17:33:02 +0100602#define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
Steven J. Hillf8fa4812012-12-07 03:51:35 +0000603#define MIPS_CONF3_ISA (_ULCAST_(3) << 14)
Steven J. Hillc6213c62013-06-05 21:25:17 +0000604#define MIPS_CONF3_ISA_OE (_ULCAST_(1) << 16)
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000605#define MIPS_CONF3_MCU (_ULCAST_(1) << 17)
606#define MIPS_CONF3_MMAR (_ULCAST_(7) << 18)
607#define MIPS_CONF3_IPLW (_ULCAST_(3) << 21)
David Daney1e7decd2013-02-16 23:42:43 +0100608#define MIPS_CONF3_VZ (_ULCAST_(1) << 23)
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000609#define MIPS_CONF3_PW (_ULCAST_(1) << 24)
610#define MIPS_CONF3_SC (_ULCAST_(1) << 25)
611#define MIPS_CONF3_BI (_ULCAST_(1) << 26)
612#define MIPS_CONF3_BP (_ULCAST_(1) << 27)
613#define MIPS_CONF3_MSA (_ULCAST_(1) << 28)
614#define MIPS_CONF3_CMGCR (_ULCAST_(1) << 29)
615#define MIPS_CONF3_BPG (_ULCAST_(1) << 30)
Ralf Baechle41943182005-05-05 16:45:59 +0000616
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000617#define MIPS_CONF4_MMUSIZEEXT_SHIFT (0)
David Daney1b362e32010-01-22 14:41:15 -0800618#define MIPS_CONF4_MMUSIZEEXT (_ULCAST_(255) << 0)
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000619#define MIPS_CONF4_FTLBSETS_SHIFT (0)
620#define MIPS_CONF4_FTLBSETS_SHIFT (0)
621#define MIPS_CONF4_FTLBSETS (_ULCAST_(15) << MIPS_CONF4_FTLBSETS_SHIFT)
622#define MIPS_CONF4_FTLBWAYS_SHIFT (4)
623#define MIPS_CONF4_FTLBWAYS (_ULCAST_(15) << MIPS_CONF4_FTLBWAYS_SHIFT)
624#define MIPS_CONF4_FTLBPAGESIZE_SHIFT (8)
625/* bits 10:8 in FTLB-only configurations */
626#define MIPS_CONF4_FTLBPAGESIZE (_ULCAST_(7) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
627/* bits 12:8 in VTLB-FTLB only configurations */
628#define MIPS_CONF4_VFTLBPAGESIZE (_ULCAST_(31) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
David Daney1b362e32010-01-22 14:41:15 -0800629#define MIPS_CONF4_MMUEXTDEF (_ULCAST_(3) << 14)
630#define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000631#define MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT (_ULCAST_(2) << 14)
632#define MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT (_ULCAST_(3) << 14)
633#define MIPS_CONF4_KSCREXIST (_ULCAST_(255) << 16)
634#define MIPS_CONF4_VTLBSIZEEXT_SHIFT (24)
635#define MIPS_CONF4_VTLBSIZEEXT (_ULCAST_(15) << MIPS_CONF4_VTLBSIZEEXT_SHIFT)
636#define MIPS_CONF4_AE (_ULCAST_(1) << 28)
637#define MIPS_CONF4_IE (_ULCAST_(3) << 29)
638#define MIPS_CONF4_TLBINV (_ULCAST_(2) << 29)
David Daney1b362e32010-01-22 14:41:15 -0800639
Ralf Baechle2f9ee822013-09-19 11:09:48 +0200640#define MIPS_CONF5_NF (_ULCAST_(1) << 0)
641#define MIPS_CONF5_UFR (_ULCAST_(1) << 2)
642#define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)
643#define MIPS_CONF5_EVA (_ULCAST_(1) << 28)
644#define MIPS_CONF5_CV (_ULCAST_(1) << 29)
645#define MIPS_CONF5_K (_ULCAST_(1) << 30)
646
Steven J. Hill006a8512012-06-26 04:11:03 +0000647#define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
648
Ralf Baechle4b3e9752007-06-21 00:22:34 +0100649#define MIPS_CONF7_WII (_ULCAST_(1) << 31)
650
Marc St-Jean9267a302007-06-14 15:55:31 -0600651#define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
652
Leonid Yegoshin691038b2013-11-14 16:12:21 +0000653/* EntryHI bit definition */
654#define MIPS_ENTRYHI_EHINV (_ULCAST_(1) << 10)
Marc St-Jean9267a302007-06-14 15:55:31 -0600655
Ralf Baechle41943182005-05-05 16:45:59 +0000656/*
657 * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
658 */
659#define MIPS_FPIR_S (_ULCAST_(1) << 16)
660#define MIPS_FPIR_D (_ULCAST_(1) << 17)
661#define MIPS_FPIR_PS (_ULCAST_(1) << 18)
662#define MIPS_FPIR_3D (_ULCAST_(1) << 19)
663#define MIPS_FPIR_W (_ULCAST_(1) << 20)
664#define MIPS_FPIR_L (_ULCAST_(1) << 21)
665#define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
666
Steven J. Hill4a0156f2013-11-14 16:12:24 +0000667/*
668 * Bits in the MIPS32 Memory Segmentation registers.
669 */
670#define MIPS_SEGCFG_PA_SHIFT 9
671#define MIPS_SEGCFG_PA (_ULCAST_(127) << MIPS_SEGCFG_PA_SHIFT)
672#define MIPS_SEGCFG_AM_SHIFT 4
673#define MIPS_SEGCFG_AM (_ULCAST_(7) << MIPS_SEGCFG_AM_SHIFT)
674#define MIPS_SEGCFG_EU_SHIFT 3
675#define MIPS_SEGCFG_EU (_ULCAST_(1) << MIPS_SEGCFG_EU_SHIFT)
676#define MIPS_SEGCFG_C_SHIFT 0
677#define MIPS_SEGCFG_C (_ULCAST_(7) << MIPS_SEGCFG_C_SHIFT)
678
679#define MIPS_SEGCFG_UUSK _ULCAST_(7)
680#define MIPS_SEGCFG_USK _ULCAST_(5)
681#define MIPS_SEGCFG_MUSUK _ULCAST_(4)
682#define MIPS_SEGCFG_MUSK _ULCAST_(3)
683#define MIPS_SEGCFG_MSK _ULCAST_(2)
684#define MIPS_SEGCFG_MK _ULCAST_(1)
685#define MIPS_SEGCFG_UK _ULCAST_(0)
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#ifndef __ASSEMBLY__
688
689/*
Steven J. Hillbfd08ba2013-02-05 16:52:03 -0600690 * Macros for handling the ISA mode bit for microMIPS.
691 */
692#define get_isa16_mode(x) ((x) & 0x1)
693#define msk_isa16_mode(x) ((x) & ~0x1)
694#define set_isa16_mode(x) do { (x) |= 0x1; } while(0)
695
696/*
697 * microMIPS instructions can be 16-bit or 32-bit in length. This
698 * returns a 1 if the instruction is 16-bit and a 0 if 32-bit.
699 */
700static inline int mm_insn_16bit(u16 insn)
701{
702 u16 opcode = (insn >> 10) & 0x7;
703
704 return (opcode >= 1 && opcode <= 3) ? 1 : 0;
705}
706
707/*
Leonid Yegoshin198bb4c2013-11-14 16:12:29 +0000708 * TLB Invalidate Flush
709 */
710static inline void tlbinvf(void)
711{
712 __asm__ __volatile__(
713 ".set push\n\t"
714 ".set noreorder\n\t"
715 ".word 0x42000004\n\t" /* tlbinvf */
716 ".set pop");
717}
718
719
720/*
Ralf Baechle70342282013-01-22 12:59:30 +0100721 * Functions to access the R10000 performance counters. These are basically
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
723 * performance counter number encoded into bits 1 ... 5 of the instruction.
724 * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
725 * disassembler these will look like an access to sel 0 or 1.
726 */
727#define read_r10k_perf_cntr(counter) \
728({ \
729 unsigned int __res; \
730 __asm__ __volatile__( \
731 "mfpc\t%0, %1" \
Ralf Baechle70342282013-01-22 12:59:30 +0100732 : "=r" (__res) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 : "i" (counter)); \
734 \
Ralf Baechle70342282013-01-22 12:59:30 +0100735 __res; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736})
737
Ralf Baechle70342282013-01-22 12:59:30 +0100738#define write_r10k_perf_cntr(counter,val) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739do { \
740 __asm__ __volatile__( \
741 "mtpc\t%0, %1" \
742 : \
743 : "r" (val), "i" (counter)); \
744} while (0)
745
746#define read_r10k_perf_event(counter) \
747({ \
748 unsigned int __res; \
749 __asm__ __volatile__( \
750 "mfps\t%0, %1" \
Ralf Baechle70342282013-01-22 12:59:30 +0100751 : "=r" (__res) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 : "i" (counter)); \
753 \
Ralf Baechle70342282013-01-22 12:59:30 +0100754 __res; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755})
756
Ralf Baechle70342282013-01-22 12:59:30 +0100757#define write_r10k_perf_cntl(counter,val) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758do { \
759 __asm__ __volatile__( \
760 "mtps\t%0, %1" \
761 : \
762 : "r" (val), "i" (counter)); \
763} while (0)
764
765
766/*
767 * Macros to access the system control coprocessor
768 */
769
770#define __read_32bit_c0_register(source, sel) \
771({ int __res; \
772 if (sel == 0) \
773 __asm__ __volatile__( \
774 "mfc0\t%0, " #source "\n\t" \
775 : "=r" (__res)); \
776 else \
777 __asm__ __volatile__( \
778 ".set\tmips32\n\t" \
779 "mfc0\t%0, " #source ", " #sel "\n\t" \
780 ".set\tmips0\n\t" \
781 : "=r" (__res)); \
782 __res; \
783})
784
785#define __read_64bit_c0_register(source, sel) \
786({ unsigned long long __res; \
787 if (sizeof(unsigned long) == 4) \
788 __res = __read_64bit_c0_split(source, sel); \
789 else if (sel == 0) \
790 __asm__ __volatile__( \
791 ".set\tmips3\n\t" \
792 "dmfc0\t%0, " #source "\n\t" \
793 ".set\tmips0" \
794 : "=r" (__res)); \
795 else \
796 __asm__ __volatile__( \
797 ".set\tmips64\n\t" \
798 "dmfc0\t%0, " #source ", " #sel "\n\t" \
799 ".set\tmips0" \
800 : "=r" (__res)); \
801 __res; \
802})
803
804#define __write_32bit_c0_register(register, sel, value) \
805do { \
806 if (sel == 0) \
807 __asm__ __volatile__( \
808 "mtc0\t%z0, " #register "\n\t" \
Ralf Baechle0952e292005-08-17 10:03:03 +0000809 : : "Jr" ((unsigned int)(value))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 else \
811 __asm__ __volatile__( \
812 ".set\tmips32\n\t" \
813 "mtc0\t%z0, " #register ", " #sel "\n\t" \
814 ".set\tmips0" \
Ralf Baechle0952e292005-08-17 10:03:03 +0000815 : : "Jr" ((unsigned int)(value))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816} while (0)
817
818#define __write_64bit_c0_register(register, sel, value) \
819do { \
820 if (sizeof(unsigned long) == 4) \
821 __write_64bit_c0_split(register, sel, value); \
822 else if (sel == 0) \
823 __asm__ __volatile__( \
824 ".set\tmips3\n\t" \
825 "dmtc0\t%z0, " #register "\n\t" \
826 ".set\tmips0" \
827 : : "Jr" (value)); \
828 else \
829 __asm__ __volatile__( \
830 ".set\tmips64\n\t" \
831 "dmtc0\t%z0, " #register ", " #sel "\n\t" \
832 ".set\tmips0" \
833 : : "Jr" (value)); \
834} while (0)
835
836#define __read_ulong_c0_register(reg, sel) \
837 ((sizeof(unsigned long) == 4) ? \
838 (unsigned long) __read_32bit_c0_register(reg, sel) : \
839 (unsigned long) __read_64bit_c0_register(reg, sel))
840
841#define __write_ulong_c0_register(reg, sel, val) \
842do { \
843 if (sizeof(unsigned long) == 4) \
844 __write_32bit_c0_register(reg, sel, val); \
845 else \
846 __write_64bit_c0_register(reg, sel, val); \
847} while (0)
848
849/*
850 * On RM7000/RM9000 these are uses to access cop0 set 1 registers
851 */
852#define __read_32bit_c0_ctrl_register(source) \
853({ int __res; \
854 __asm__ __volatile__( \
855 "cfc0\t%0, " #source "\n\t" \
856 : "=r" (__res)); \
857 __res; \
858})
859
860#define __write_32bit_c0_ctrl_register(register, value) \
861do { \
862 __asm__ __volatile__( \
863 "ctc0\t%z0, " #register "\n\t" \
Ralf Baechle0952e292005-08-17 10:03:03 +0000864 : : "Jr" ((unsigned int)(value))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865} while (0)
866
867/*
868 * These versions are only needed for systems with more than 38 bits of
869 * physical address space running the 32-bit kernel. That's none atm :-)
870 */
871#define __read_64bit_c0_split(source, sel) \
872({ \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900873 unsigned long long __val; \
874 unsigned long __flags; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900876 local_irq_save(__flags); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 if (sel == 0) \
878 __asm__ __volatile__( \
879 ".set\tmips64\n\t" \
880 "dmfc0\t%M0, " #source "\n\t" \
881 "dsll\t%L0, %M0, 32\n\t" \
Ralf Baechle0b543522009-04-30 02:16:19 +0200882 "dsra\t%M0, %M0, 32\n\t" \
883 "dsra\t%L0, %L0, 32\n\t" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 ".set\tmips0" \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900885 : "=r" (__val)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 else \
887 __asm__ __volatile__( \
888 ".set\tmips64\n\t" \
889 "dmfc0\t%M0, " #source ", " #sel "\n\t" \
890 "dsll\t%L0, %M0, 32\n\t" \
Ralf Baechle0b543522009-04-30 02:16:19 +0200891 "dsra\t%M0, %M0, 32\n\t" \
892 "dsra\t%L0, %L0, 32\n\t" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 ".set\tmips0" \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900894 : "=r" (__val)); \
895 local_irq_restore(__flags); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900897 __val; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898})
899
900#define __write_64bit_c0_split(source, sel, val) \
901do { \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900902 unsigned long __flags; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900904 local_irq_save(__flags); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (sel == 0) \
906 __asm__ __volatile__( \
907 ".set\tmips64\n\t" \
908 "dsll\t%L0, %L0, 32\n\t" \
909 "dsrl\t%L0, %L0, 32\n\t" \
910 "dsll\t%M0, %M0, 32\n\t" \
911 "or\t%L0, %L0, %M0\n\t" \
912 "dmtc0\t%L0, " #source "\n\t" \
913 ".set\tmips0" \
914 : : "r" (val)); \
915 else \
916 __asm__ __volatile__( \
917 ".set\tmips64\n\t" \
918 "dsll\t%L0, %L0, 32\n\t" \
919 "dsrl\t%L0, %L0, 32\n\t" \
920 "dsll\t%M0, %M0, 32\n\t" \
921 "or\t%L0, %L0, %M0\n\t" \
922 "dmtc0\t%L0, " #source ", " #sel "\n\t" \
923 ".set\tmips0" \
924 : : "r" (val)); \
Atsushi Nemoto87d43dd2007-07-11 23:30:40 +0900925 local_irq_restore(__flags); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926} while (0)
927
928#define read_c0_index() __read_32bit_c0_register($0, 0)
929#define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
930
Ralf Baechle272bace2008-05-26 09:35:47 +0100931#define read_c0_random() __read_32bit_c0_register($1, 0)
932#define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934#define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
935#define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
936
937#define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
938#define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
939
940#define read_c0_conf() __read_32bit_c0_register($3, 0)
941#define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
942
943#define read_c0_context() __read_ulong_c0_register($4, 0)
944#define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
945
Ralf Baechlea3692022007-07-10 17:33:02 +0100946#define read_c0_userlocal() __read_ulong_c0_register($4, 2)
Ralf Baechle70342282013-01-22 12:59:30 +0100947#define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
Ralf Baechlea3692022007-07-10 17:33:02 +0100948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949#define read_c0_pagemask() __read_32bit_c0_register($5, 0)
950#define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
951
David Daney9fe2e9d2010-02-10 15:12:45 -0800952#define read_c0_pagegrain() __read_32bit_c0_register($5, 1)
Ralf Baechle70342282013-01-22 12:59:30 +0100953#define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
David Daney9fe2e9d2010-02-10 15:12:45 -0800954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955#define read_c0_wired() __read_32bit_c0_register($6, 0)
956#define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
957
958#define read_c0_info() __read_32bit_c0_register($7, 0)
959
Ralf Baechle70342282013-01-22 12:59:30 +0100960#define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961#define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
962
Ralf Baechle15c4f672006-03-29 18:51:06 +0100963#define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
964#define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966#define read_c0_count() __read_32bit_c0_register($9, 0)
967#define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
968
Pete Popovbdf21b12005-07-14 17:47:57 +0000969#define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
970#define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
971
972#define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
973#define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975#define read_c0_entryhi() __read_ulong_c0_register($10, 0)
976#define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
977
978#define read_c0_compare() __read_32bit_c0_register($11, 0)
979#define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
980
Pete Popovbdf21b12005-07-14 17:47:57 +0000981#define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
982#define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
983
984#define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
985#define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987#define read_c0_status() __read_32bit_c0_register($12, 0)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100988#ifdef CONFIG_MIPS_MT_SMTC
989#define write_c0_status(val) \
990do { \
991 __write_32bit_c0_register($12, 0, val); \
992 __ehb(); \
993} while (0)
994#else
995/*
996 * Legacy non-SMTC code, which may be hazardous
997 * but which might not support EHB
998 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999#define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
Ralf Baechle41c594a2006-04-05 09:45:45 +01001000#endif /* CONFIG_MIPS_MT_SMTC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002#define read_c0_cause() __read_32bit_c0_register($13, 0)
1003#define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
1004
1005#define read_c0_epc() __read_ulong_c0_register($14, 0)
1006#define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
1007
1008#define read_c0_prid() __read_32bit_c0_register($15, 0)
1009
1010#define read_c0_config() __read_32bit_c0_register($16, 0)
1011#define read_c0_config1() __read_32bit_c0_register($16, 1)
1012#define read_c0_config2() __read_32bit_c0_register($16, 2)
1013#define read_c0_config3() __read_32bit_c0_register($16, 3)
Ralf Baechle0efe2762005-02-06 21:24:55 +00001014#define read_c0_config4() __read_32bit_c0_register($16, 4)
1015#define read_c0_config5() __read_32bit_c0_register($16, 5)
1016#define read_c0_config6() __read_32bit_c0_register($16, 6)
1017#define read_c0_config7() __read_32bit_c0_register($16, 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018#define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
1019#define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
1020#define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
1021#define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
Ralf Baechle0efe2762005-02-06 21:24:55 +00001022#define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
1023#define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
1024#define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
1025#define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
1027/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001028 * The WatchLo register. There may be up to 8 of them.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 */
1030#define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
1031#define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
1032#define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
1033#define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
1034#define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
1035#define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
1036#define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
1037#define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
1038#define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
1039#define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
1040#define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
1041#define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
1042#define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
1043#define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
1044#define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
1045#define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
1046
1047/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001048 * The WatchHi register. There may be up to 8 of them.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 */
1050#define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
1051#define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
1052#define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
1053#define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
1054#define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
1055#define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
1056#define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
1057#define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
1058
1059#define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
1060#define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
1061#define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
1062#define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
1063#define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
1064#define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
1065#define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
1066#define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
1067
1068#define read_c0_xcontext() __read_ulong_c0_register($20, 0)
1069#define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
1070
1071#define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
1072#define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
1073
1074#define read_c0_framemask() __read_32bit_c0_register($21, 0)
Ralf Baechle70342282013-01-22 12:59:30 +01001075#define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077#define read_c0_diag() __read_32bit_c0_register($22, 0)
1078#define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
1079
1080#define read_c0_diag1() __read_32bit_c0_register($22, 1)
1081#define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
1082
1083#define read_c0_diag2() __read_32bit_c0_register($22, 2)
1084#define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
1085
1086#define read_c0_diag3() __read_32bit_c0_register($22, 3)
1087#define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
1088
1089#define read_c0_diag4() __read_32bit_c0_register($22, 4)
1090#define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
1091
1092#define read_c0_diag5() __read_32bit_c0_register($22, 5)
1093#define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
1094
1095#define read_c0_debug() __read_32bit_c0_register($23, 0)
1096#define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
1097
1098#define read_c0_depc() __read_ulong_c0_register($24, 0)
1099#define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
1100
1101/*
1102 * MIPS32 / MIPS64 performance counters
1103 */
1104#define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
Ralf Baechle70342282013-01-22 12:59:30 +01001105#define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106#define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
Ralf Baechle70342282013-01-22 12:59:30 +01001107#define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
David Daney4d36f592011-09-24 02:29:55 +02001108#define read_c0_perfcntr0_64() __read_64bit_c0_register($25, 1)
1109#define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110#define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
Ralf Baechle70342282013-01-22 12:59:30 +01001111#define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112#define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
Ralf Baechle70342282013-01-22 12:59:30 +01001113#define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
David Daney4d36f592011-09-24 02:29:55 +02001114#define read_c0_perfcntr1_64() __read_64bit_c0_register($25, 3)
1115#define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116#define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
Ralf Baechle70342282013-01-22 12:59:30 +01001117#define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118#define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
Ralf Baechle70342282013-01-22 12:59:30 +01001119#define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
David Daney4d36f592011-09-24 02:29:55 +02001120#define read_c0_perfcntr2_64() __read_64bit_c0_register($25, 5)
1121#define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122#define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
Ralf Baechle70342282013-01-22 12:59:30 +01001123#define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124#define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
Ralf Baechle70342282013-01-22 12:59:30 +01001125#define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
David Daney4d36f592011-09-24 02:29:55 +02001126#define read_c0_perfcntr3_64() __read_64bit_c0_register($25, 7)
1127#define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129#define read_c0_ecc() __read_32bit_c0_register($26, 0)
1130#define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
1131
1132#define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
Ralf Baechle70342282013-01-22 12:59:30 +01001133#define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
1135#define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
1136
1137#define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
Ralf Baechle70342282013-01-22 12:59:30 +01001138#define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140#define read_c0_taglo() __read_32bit_c0_register($28, 0)
1141#define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
1142
Ralf Baechle41c594a2006-04-05 09:45:45 +01001143#define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
1144#define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
1145
Kevin Cernekeeaf231172010-10-16 14:22:32 -07001146#define read_c0_ddatalo() __read_32bit_c0_register($28, 3)
1147#define write_c0_ddatalo(val) __write_32bit_c0_register($28, 3, val)
1148
1149#define read_c0_staglo() __read_32bit_c0_register($28, 4)
1150#define write_c0_staglo(val) __write_32bit_c0_register($28, 4, val)
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152#define read_c0_taghi() __read_32bit_c0_register($29, 0)
1153#define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
1154
1155#define read_c0_errorepc() __read_ulong_c0_register($30, 0)
1156#define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
1157
Ralf Baechle7a0fc582005-07-13 19:47:28 +00001158/* MIPSR2 */
Ralf Baechle21a151d2007-10-11 23:46:15 +01001159#define read_c0_hwrena() __read_32bit_c0_register($7, 0)
Ralf Baechle7a0fc582005-07-13 19:47:28 +00001160#define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
1161
1162#define read_c0_intctl() __read_32bit_c0_register($12, 1)
1163#define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
1164
1165#define read_c0_srsctl() __read_32bit_c0_register($12, 2)
1166#define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
1167
1168#define read_c0_srsmap() __read_32bit_c0_register($12, 3)
1169#define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
1170
Ralf Baechle21a151d2007-10-11 23:46:15 +01001171#define read_c0_ebase() __read_32bit_c0_register($15, 1)
Ralf Baechle7a0fc582005-07-13 19:47:28 +00001172#define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
1173
Steven J. Hill4a0156f2013-11-14 16:12:24 +00001174/* MIPSR3 */
1175#define read_c0_segctl0() __read_32bit_c0_register($5, 2)
1176#define write_c0_segctl0(val) __write_32bit_c0_register($5, 2, val)
1177
1178#define read_c0_segctl1() __read_32bit_c0_register($5, 3)
1179#define write_c0_segctl1(val) __write_32bit_c0_register($5, 3, val)
1180
1181#define read_c0_segctl2() __read_32bit_c0_register($5, 4)
1182#define write_c0_segctl2(val) __write_32bit_c0_register($5, 4, val)
David Daneyed918c22008-12-11 15:33:24 -08001183
1184/* Cavium OCTEON (cnMIPS) */
1185#define read_c0_cvmcount() __read_ulong_c0_register($9, 6)
1186#define write_c0_cvmcount(val) __write_ulong_c0_register($9, 6, val)
1187
1188#define read_c0_cvmctl() __read_64bit_c0_register($9, 7)
1189#define write_c0_cvmctl(val) __write_64bit_c0_register($9, 7, val)
1190
1191#define read_c0_cvmmemctl() __read_64bit_c0_register($11, 7)
Ralf Baechle70342282013-01-22 12:59:30 +01001192#define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
David Daneyed918c22008-12-11 15:33:24 -08001193/*
Ralf Baechle70342282013-01-22 12:59:30 +01001194 * The cacheerr registers are not standardized. On OCTEON, they are
David Daneyed918c22008-12-11 15:33:24 -08001195 * 64 bits wide.
1196 */
1197#define read_octeon_c0_icacheerr() __read_64bit_c0_register($27, 0)
1198#define write_octeon_c0_icacheerr(val) __write_64bit_c0_register($27, 0, val)
1199
1200#define read_octeon_c0_dcacheerr() __read_64bit_c0_register($27, 1)
1201#define write_octeon_c0_dcacheerr(val) __write_64bit_c0_register($27, 1, val)
1202
Kevin Cernekeeaf231172010-10-16 14:22:32 -07001203/* BMIPS3300 */
1204#define read_c0_brcm_config_0() __read_32bit_c0_register($22, 0)
1205#define write_c0_brcm_config_0(val) __write_32bit_c0_register($22, 0, val)
1206
1207#define read_c0_brcm_bus_pll() __read_32bit_c0_register($22, 4)
1208#define write_c0_brcm_bus_pll(val) __write_32bit_c0_register($22, 4, val)
1209
1210#define read_c0_brcm_reset() __read_32bit_c0_register($22, 5)
1211#define write_c0_brcm_reset(val) __write_32bit_c0_register($22, 5, val)
1212
Kevin Cernekee020232f2011-11-16 01:25:44 +00001213/* BMIPS43xx */
Kevin Cernekeeaf231172010-10-16 14:22:32 -07001214#define read_c0_brcm_cmt_intr() __read_32bit_c0_register($22, 1)
1215#define write_c0_brcm_cmt_intr(val) __write_32bit_c0_register($22, 1, val)
1216
1217#define read_c0_brcm_cmt_ctrl() __read_32bit_c0_register($22, 2)
1218#define write_c0_brcm_cmt_ctrl(val) __write_32bit_c0_register($22, 2, val)
1219
1220#define read_c0_brcm_cmt_local() __read_32bit_c0_register($22, 3)
1221#define write_c0_brcm_cmt_local(val) __write_32bit_c0_register($22, 3, val)
1222
1223#define read_c0_brcm_config_1() __read_32bit_c0_register($22, 5)
1224#define write_c0_brcm_config_1(val) __write_32bit_c0_register($22, 5, val)
1225
1226#define read_c0_brcm_cbr() __read_32bit_c0_register($22, 6)
1227#define write_c0_brcm_cbr(val) __write_32bit_c0_register($22, 6, val)
1228
1229/* BMIPS5000 */
1230#define read_c0_brcm_config() __read_32bit_c0_register($22, 0)
1231#define write_c0_brcm_config(val) __write_32bit_c0_register($22, 0, val)
1232
1233#define read_c0_brcm_mode() __read_32bit_c0_register($22, 1)
1234#define write_c0_brcm_mode(val) __write_32bit_c0_register($22, 1, val)
1235
1236#define read_c0_brcm_action() __read_32bit_c0_register($22, 2)
1237#define write_c0_brcm_action(val) __write_32bit_c0_register($22, 2, val)
1238
1239#define read_c0_brcm_edsp() __read_32bit_c0_register($22, 3)
1240#define write_c0_brcm_edsp(val) __write_32bit_c0_register($22, 3, val)
1241
1242#define read_c0_brcm_bootvec() __read_32bit_c0_register($22, 4)
1243#define write_c0_brcm_bootvec(val) __write_32bit_c0_register($22, 4, val)
1244
1245#define read_c0_brcm_sleepcount() __read_32bit_c0_register($22, 7)
1246#define write_c0_brcm_sleepcount(val) __write_32bit_c0_register($22, 7, val)
1247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248/*
1249 * Macros to access the floating point coprocessor control registers
1250 */
Steven J. Hillb9688312013-01-12 23:29:27 +00001251#define read_32bit_cp1_register(source) \
1252({ \
1253 int __res; \
1254 \
1255 __asm__ __volatile__( \
1256 " .set push \n" \
1257 " .set reorder \n" \
1258 " # gas fails to assemble cfc1 for some archs, \n" \
1259 " # like Octeon. \n" \
1260 " .set mips1 \n" \
1261 " cfc1 %0,"STR(source)" \n" \
1262 " .set pop \n" \
1263 : "=r" (__res)); \
1264 __res; \
1265})
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001267#ifdef HAVE_AS_DSP
1268#define rddsp(mask) \
1269({ \
1270 unsigned int __dspctl; \
1271 \
1272 __asm__ __volatile__( \
Florian Fainelli63c2b682013-03-18 15:56:10 +00001273 " .set push \n" \
1274 " .set dsp \n" \
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001275 " rddsp %0, %x1 \n" \
Florian Fainelli63c2b682013-03-18 15:56:10 +00001276 " .set pop \n" \
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001277 : "=r" (__dspctl) \
1278 : "i" (mask)); \
1279 __dspctl; \
1280})
1281
1282#define wrdsp(val, mask) \
1283do { \
1284 __asm__ __volatile__( \
Florian Fainelli63c2b682013-03-18 15:56:10 +00001285 " .set push \n" \
1286 " .set dsp \n" \
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001287 " wrdsp %0, %x1 \n" \
Florian Fainelli63c2b682013-03-18 15:56:10 +00001288 " .set pop \n" \
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001289 : \
1290 : "r" (val), "i" (mask)); \
1291} while (0)
1292
Florian Fainelli63c2b682013-03-18 15:56:10 +00001293#define mflo0() \
1294({ \
1295 long mflo0; \
1296 __asm__( \
1297 " .set push \n" \
1298 " .set dsp \n" \
1299 " mflo %0, $ac0 \n" \
1300 " .set pop \n" \
1301 : "=r" (mflo0)); \
1302 mflo0; \
1303})
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001304
Florian Fainelli63c2b682013-03-18 15:56:10 +00001305#define mflo1() \
1306({ \
1307 long mflo1; \
1308 __asm__( \
1309 " .set push \n" \
1310 " .set dsp \n" \
1311 " mflo %0, $ac1 \n" \
1312 " .set pop \n" \
1313 : "=r" (mflo1)); \
1314 mflo1; \
1315})
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001316
Florian Fainelli63c2b682013-03-18 15:56:10 +00001317#define mflo2() \
1318({ \
1319 long mflo2; \
1320 __asm__( \
1321 " .set push \n" \
1322 " .set dsp \n" \
1323 " mflo %0, $ac2 \n" \
1324 " .set pop \n" \
1325 : "=r" (mflo2)); \
1326 mflo2; \
1327})
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001328
Florian Fainelli63c2b682013-03-18 15:56:10 +00001329#define mflo3() \
1330({ \
1331 long mflo3; \
1332 __asm__( \
1333 " .set push \n" \
1334 " .set dsp \n" \
1335 " mflo %0, $ac3 \n" \
1336 " .set pop \n" \
1337 : "=r" (mflo3)); \
1338 mflo3; \
1339})
1340
1341#define mfhi0() \
1342({ \
1343 long mfhi0; \
1344 __asm__( \
1345 " .set push \n" \
1346 " .set dsp \n" \
1347 " mfhi %0, $ac0 \n" \
1348 " .set pop \n" \
1349 : "=r" (mfhi0)); \
1350 mfhi0; \
1351})
1352
1353#define mfhi1() \
1354({ \
1355 long mfhi1; \
1356 __asm__( \
1357 " .set push \n" \
1358 " .set dsp \n" \
1359 " mfhi %0, $ac1 \n" \
1360 " .set pop \n" \
1361 : "=r" (mfhi1)); \
1362 mfhi1; \
1363})
1364
1365#define mfhi2() \
1366({ \
1367 long mfhi2; \
1368 __asm__( \
1369 " .set push \n" \
1370 " .set dsp \n" \
1371 " mfhi %0, $ac2 \n" \
1372 " .set pop \n" \
1373 : "=r" (mfhi2)); \
1374 mfhi2; \
1375})
1376
1377#define mfhi3() \
1378({ \
1379 long mfhi3; \
1380 __asm__( \
1381 " .set push \n" \
1382 " .set dsp \n" \
1383 " mfhi %0, $ac3 \n" \
1384 " .set pop \n" \
1385 : "=r" (mfhi3)); \
1386 mfhi3; \
1387})
1388
1389
1390#define mtlo0(x) \
1391({ \
1392 __asm__( \
1393 " .set push \n" \
1394 " .set dsp \n" \
1395 " mtlo %0, $ac0 \n" \
1396 " .set pop \n" \
1397 : \
1398 : "r" (x)); \
1399})
1400
1401#define mtlo1(x) \
1402({ \
1403 __asm__( \
1404 " .set push \n" \
1405 " .set dsp \n" \
1406 " mtlo %0, $ac1 \n" \
1407 " .set pop \n" \
1408 : \
1409 : "r" (x)); \
1410})
1411
1412#define mtlo2(x) \
1413({ \
1414 __asm__( \
1415 " .set push \n" \
1416 " .set dsp \n" \
1417 " mtlo %0, $ac2 \n" \
1418 " .set pop \n" \
1419 : \
1420 : "r" (x)); \
1421})
1422
1423#define mtlo3(x) \
1424({ \
1425 __asm__( \
1426 " .set push \n" \
1427 " .set dsp \n" \
1428 " mtlo %0, $ac3 \n" \
1429 " .set pop \n" \
1430 : \
1431 : "r" (x)); \
1432})
1433
1434#define mthi0(x) \
1435({ \
1436 __asm__( \
1437 " .set push \n" \
1438 " .set dsp \n" \
1439 " mthi %0, $ac0 \n" \
1440 " .set pop \n" \
1441 : \
1442 : "r" (x)); \
1443})
1444
1445#define mthi1(x) \
1446({ \
1447 __asm__( \
1448 " .set push \n" \
1449 " .set dsp \n" \
1450 " mthi %0, $ac1 \n" \
1451 " .set pop \n" \
1452 : \
1453 : "r" (x)); \
1454})
1455
1456#define mthi2(x) \
1457({ \
1458 __asm__( \
1459 " .set push \n" \
1460 " .set dsp \n" \
1461 " mthi %0, $ac2 \n" \
1462 " .set pop \n" \
1463 : \
1464 : "r" (x)); \
1465})
1466
1467#define mthi3(x) \
1468({ \
1469 __asm__( \
1470 " .set push \n" \
1471 " .set dsp \n" \
1472 " mthi %0, $ac3 \n" \
1473 " .set pop \n" \
1474 : \
1475 : "r" (x)); \
1476})
Steven J. Hill32a7ede2013-01-03 19:01:52 +00001477
1478#else
1479
Steven J. Hilld0c1b472012-12-07 03:53:29 +00001480#ifdef CONFIG_CPU_MICROMIPS
1481#define rddsp(mask) \
1482({ \
1483 unsigned int __res; \
1484 \
1485 __asm__ __volatile__( \
1486 " .set push \n" \
1487 " .set noat \n" \
1488 " # rddsp $1, %x1 \n" \
1489 " .hword ((0x0020067c | (%x1 << 14)) >> 16) \n" \
1490 " .hword ((0x0020067c | (%x1 << 14)) & 0xffff) \n" \
1491 " move %0, $1 \n" \
1492 " .set pop \n" \
1493 : "=r" (__res) \
1494 : "i" (mask)); \
1495 __res; \
1496})
1497
1498#define wrdsp(val, mask) \
1499do { \
1500 __asm__ __volatile__( \
1501 " .set push \n" \
1502 " .set noat \n" \
1503 " move $1, %0 \n" \
1504 " # wrdsp $1, %x1 \n" \
1505 " .hword ((0x0020167c | (%x1 << 14)) >> 16) \n" \
1506 " .hword ((0x0020167c | (%x1 << 14)) & 0xffff) \n" \
1507 " .set pop \n" \
1508 : \
1509 : "r" (val), "i" (mask)); \
1510} while (0)
1511
1512#define _umips_dsp_mfxxx(ins) \
1513({ \
1514 unsigned long __treg; \
1515 \
1516 __asm__ __volatile__( \
1517 " .set push \n" \
1518 " .set noat \n" \
1519 " .hword 0x0001 \n" \
1520 " .hword %x1 \n" \
1521 " move %0, $1 \n" \
1522 " .set pop \n" \
1523 : "=r" (__treg) \
1524 : "i" (ins)); \
1525 __treg; \
1526})
1527
1528#define _umips_dsp_mtxxx(val, ins) \
1529do { \
1530 __asm__ __volatile__( \
1531 " .set push \n" \
1532 " .set noat \n" \
1533 " move $1, %0 \n" \
1534 " .hword 0x0001 \n" \
1535 " .hword %x1 \n" \
1536 " .set pop \n" \
1537 : \
1538 : "r" (val), "i" (ins)); \
1539} while (0)
1540
1541#define _umips_dsp_mflo(reg) _umips_dsp_mfxxx((reg << 14) | 0x107c)
1542#define _umips_dsp_mfhi(reg) _umips_dsp_mfxxx((reg << 14) | 0x007c)
1543
1544#define _umips_dsp_mtlo(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x307c))
1545#define _umips_dsp_mthi(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x207c))
1546
1547#define mflo0() _umips_dsp_mflo(0)
1548#define mflo1() _umips_dsp_mflo(1)
1549#define mflo2() _umips_dsp_mflo(2)
1550#define mflo3() _umips_dsp_mflo(3)
1551
1552#define mfhi0() _umips_dsp_mfhi(0)
1553#define mfhi1() _umips_dsp_mfhi(1)
1554#define mfhi2() _umips_dsp_mfhi(2)
1555#define mfhi3() _umips_dsp_mfhi(3)
1556
1557#define mtlo0(x) _umips_dsp_mtlo(x, 0)
1558#define mtlo1(x) _umips_dsp_mtlo(x, 1)
1559#define mtlo2(x) _umips_dsp_mtlo(x, 2)
1560#define mtlo3(x) _umips_dsp_mtlo(x, 3)
1561
1562#define mthi0(x) _umips_dsp_mthi(x, 0)
1563#define mthi1(x) _umips_dsp_mthi(x, 1)
1564#define mthi2(x) _umips_dsp_mthi(x, 2)
1565#define mthi3(x) _umips_dsp_mthi(x, 3)
1566
1567#else /* !CONFIG_CPU_MICROMIPS */
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001568#define rddsp(mask) \
1569({ \
1570 unsigned int __res; \
1571 \
1572 __asm__ __volatile__( \
1573 " .set push \n" \
1574 " .set noat \n" \
1575 " # rddsp $1, %x1 \n" \
1576 " .word 0x7c000cb8 | (%x1 << 16) \n" \
1577 " move %0, $1 \n" \
1578 " .set pop \n" \
1579 : "=r" (__res) \
1580 : "i" (mask)); \
1581 __res; \
1582})
1583
1584#define wrdsp(val, mask) \
1585do { \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001586 __asm__ __volatile__( \
1587 " .set push \n" \
1588 " .set noat \n" \
1589 " move $1, %0 \n" \
1590 " # wrdsp $1, %x1 \n" \
Ralf Baechle26487952005-12-07 17:52:40 +00001591 " .word 0x7c2004f8 | (%x1 << 11) \n" \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001592 " .set pop \n" \
1593 : \
1594 : "r" (val), "i" (mask)); \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001595} while (0)
1596
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001597#define _dsp_mfxxx(ins) \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001598({ \
1599 unsigned long __treg; \
1600 \
1601 __asm__ __volatile__( \
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001602 " .set push \n" \
1603 " .set noat \n" \
1604 " .word (0x00000810 | %1) \n" \
1605 " move %0, $1 \n" \
1606 " .set pop \n" \
1607 : "=r" (__treg) \
1608 : "i" (ins)); \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001609 __treg; \
1610})
1611
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001612#define _dsp_mtxxx(val, ins) \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001613do { \
1614 __asm__ __volatile__( \
1615 " .set push \n" \
1616 " .set noat \n" \
1617 " move $1, %0 \n" \
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001618 " .word (0x00200011 | %1) \n" \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001619 " .set pop \n" \
1620 : \
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001621 : "r" (val), "i" (ins)); \
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001622} while (0)
1623
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001624#define _dsp_mflo(reg) _dsp_mfxxx((reg << 21) | 0x0002)
1625#define _dsp_mfhi(reg) _dsp_mfxxx((reg << 21) | 0x0000)
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001626
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001627#define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0002))
1628#define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0000))
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001629
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001630#define mflo0() _dsp_mflo(0)
1631#define mflo1() _dsp_mflo(1)
1632#define mflo2() _dsp_mflo(2)
1633#define mflo3() _dsp_mflo(3)
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001634
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001635#define mfhi0() _dsp_mfhi(0)
1636#define mfhi1() _dsp_mfhi(1)
1637#define mfhi2() _dsp_mfhi(2)
1638#define mfhi3() _dsp_mfhi(3)
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001639
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001640#define mtlo0(x) _dsp_mtlo(x, 0)
1641#define mtlo1(x) _dsp_mtlo(x, 1)
1642#define mtlo2(x) _dsp_mtlo(x, 2)
1643#define mtlo3(x) _dsp_mtlo(x, 3)
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001644
Steven J. Hill4cb764b2012-12-07 03:53:52 +00001645#define mthi0(x) _dsp_mthi(x, 0)
1646#define mthi1(x) _dsp_mthi(x, 1)
1647#define mthi2(x) _dsp_mthi(x, 2)
1648#define mthi3(x) _dsp_mthi(x, 3)
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001649
Steven J. Hilld0c1b472012-12-07 03:53:29 +00001650#endif /* CONFIG_CPU_MICROMIPS */
Ralf Baechlee50c0a82005-05-31 11:49:19 +00001651#endif
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653/*
1654 * TLB operations.
1655 *
1656 * It is responsibility of the caller to take care of any TLB hazards.
1657 */
1658static inline void tlb_probe(void)
1659{
1660 __asm__ __volatile__(
1661 ".set noreorder\n\t"
1662 "tlbp\n\t"
1663 ".set reorder");
1664}
1665
1666static inline void tlb_read(void)
1667{
Marc St-Jean9267a302007-06-14 15:55:31 -06001668#if MIPS34K_MISSED_ITLB_WAR
1669 int res = 0;
1670
1671 __asm__ __volatile__(
1672 " .set push \n"
1673 " .set noreorder \n"
1674 " .set noat \n"
1675 " .set mips32r2 \n"
1676 " .word 0x41610001 # dvpe $1 \n"
1677 " move %0, $1 \n"
1678 " ehb \n"
1679 " .set pop \n"
1680 : "=r" (res));
1681
1682 instruction_hazard();
1683#endif
1684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 __asm__ __volatile__(
1686 ".set noreorder\n\t"
1687 "tlbr\n\t"
1688 ".set reorder");
Marc St-Jean9267a302007-06-14 15:55:31 -06001689
1690#if MIPS34K_MISSED_ITLB_WAR
1691 if ((res & _ULCAST_(1)))
1692 __asm__ __volatile__(
1693 " .set push \n"
1694 " .set noreorder \n"
1695 " .set noat \n"
1696 " .set mips32r2 \n"
1697 " .word 0x41600021 # evpe \n"
1698 " ehb \n"
1699 " .set pop \n");
1700#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
1703static inline void tlb_write_indexed(void)
1704{
1705 __asm__ __volatile__(
1706 ".set noreorder\n\t"
1707 "tlbwi\n\t"
1708 ".set reorder");
1709}
1710
1711static inline void tlb_write_random(void)
1712{
1713 __asm__ __volatile__(
1714 ".set noreorder\n\t"
1715 "tlbwr\n\t"
1716 ".set reorder");
1717}
1718
1719/*
1720 * Manipulate bits in a c0 register.
1721 */
Ralf Baechle41c594a2006-04-05 09:45:45 +01001722#ifndef CONFIG_MIPS_MT_SMTC
1723/*
1724 * SMTC Linux requires shutting-down microthread scheduling
1725 * during CP0 register read-modify-write sequences.
1726 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727#define __BUILD_SET_C0(name) \
1728static inline unsigned int \
1729set_c0_##name(unsigned int set) \
1730{ \
Ralf Baechle89e18eb2009-03-23 22:14:55 +01001731 unsigned int res, new; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 \
1733 res = read_c0_##name(); \
Ralf Baechle89e18eb2009-03-23 22:14:55 +01001734 new = res | set; \
1735 write_c0_##name(new); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 \
1737 return res; \
1738} \
1739 \
1740static inline unsigned int \
1741clear_c0_##name(unsigned int clear) \
1742{ \
Ralf Baechle89e18eb2009-03-23 22:14:55 +01001743 unsigned int res, new; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 \
1745 res = read_c0_##name(); \
Ralf Baechle89e18eb2009-03-23 22:14:55 +01001746 new = res & ~clear; \
1747 write_c0_##name(new); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 \
1749 return res; \
1750} \
1751 \
1752static inline unsigned int \
Ralf Baechle89e18eb2009-03-23 22:14:55 +01001753change_c0_##name(unsigned int change, unsigned int val) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{ \
Ralf Baechle89e18eb2009-03-23 22:14:55 +01001755 unsigned int res, new; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 \
1757 res = read_c0_##name(); \
Ralf Baechle89e18eb2009-03-23 22:14:55 +01001758 new = res & ~change; \
1759 new |= (val & change); \
1760 write_c0_##name(new); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 \
1762 return res; \
1763}
1764
Ralf Baechle41c594a2006-04-05 09:45:45 +01001765#else /* SMTC versions that manage MT scheduling */
1766
Ralf Baechle192ef362006-07-07 14:07:18 +01001767#include <linux/irqflags.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +01001768
1769/*
1770 * This is a duplicate of dmt() in mipsmtregs.h to avoid problems with
1771 * header file recursion.
1772 */
1773static inline unsigned int __dmt(void)
1774{
1775 int res;
1776
1777 __asm__ __volatile__(
1778 " .set push \n"
1779 " .set mips32r2 \n"
1780 " .set noat \n"
1781 " .word 0x41610BC1 # dmt $1 \n"
1782 " ehb \n"
1783 " move %0, $1 \n"
1784 " .set pop \n"
1785 : "=r" (res));
1786
1787 instruction_hazard();
1788
1789 return res;
1790}
1791
1792#define __VPECONTROL_TE_SHIFT 15
1793#define __VPECONTROL_TE (1UL << __VPECONTROL_TE_SHIFT)
1794
1795#define __EMT_ENABLE __VPECONTROL_TE
1796
1797static inline void __emt(unsigned int previous)
1798{
1799 if ((previous & __EMT_ENABLE))
1800 __asm__ __volatile__(
Ralf Baechle41c594a2006-04-05 09:45:45 +01001801 " .set mips32r2 \n"
1802 " .word 0x41600be1 # emt \n"
1803 " ehb \n"
Ralf Baechle1bd5e162006-06-03 21:59:51 +01001804 " .set mips0 \n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001805}
1806
1807static inline void __ehb(void)
1808{
1809 __asm__ __volatile__(
Ralf Baechle4277ff52006-06-03 22:40:15 +01001810 " .set mips32r2 \n"
1811 " ehb \n" " .set mips0 \n");
Ralf Baechle41c594a2006-04-05 09:45:45 +01001812}
1813
1814/*
1815 * Note that local_irq_save/restore affect TC-specific IXMT state,
1816 * not Status.IE as in non-SMTC kernel.
1817 */
1818
1819#define __BUILD_SET_C0(name) \
1820static inline unsigned int \
1821set_c0_##name(unsigned int set) \
1822{ \
1823 unsigned int res; \
Kevin D. Kissellc34e6e82009-03-31 12:59:24 +02001824 unsigned int new; \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001825 unsigned int omt; \
Ralf Baechleb7e42262008-10-01 21:52:41 +01001826 unsigned long flags; \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001827 \
1828 local_irq_save(flags); \
1829 omt = __dmt(); \
1830 res = read_c0_##name(); \
Kevin D. Kissellc34e6e82009-03-31 12:59:24 +02001831 new = res | set; \
1832 write_c0_##name(new); \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001833 __emt(omt); \
1834 local_irq_restore(flags); \
1835 \
1836 return res; \
1837} \
1838 \
1839static inline unsigned int \
1840clear_c0_##name(unsigned int clear) \
1841{ \
1842 unsigned int res; \
Kevin D. Kissellc34e6e82009-03-31 12:59:24 +02001843 unsigned int new; \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001844 unsigned int omt; \
Ralf Baechleb7e42262008-10-01 21:52:41 +01001845 unsigned long flags; \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001846 \
1847 local_irq_save(flags); \
1848 omt = __dmt(); \
1849 res = read_c0_##name(); \
Kevin D. Kissellc34e6e82009-03-31 12:59:24 +02001850 new = res & ~clear; \
1851 write_c0_##name(new); \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001852 __emt(omt); \
1853 local_irq_restore(flags); \
1854 \
1855 return res; \
1856} \
1857 \
1858static inline unsigned int \
Kevin D. Kissellc34e6e82009-03-31 12:59:24 +02001859change_c0_##name(unsigned int change, unsigned int newbits) \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001860{ \
1861 unsigned int res; \
Kevin D. Kissellc34e6e82009-03-31 12:59:24 +02001862 unsigned int new; \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001863 unsigned int omt; \
Ralf Baechleb7e42262008-10-01 21:52:41 +01001864 unsigned long flags; \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001865 \
1866 local_irq_save(flags); \
1867 \
1868 omt = __dmt(); \
1869 res = read_c0_##name(); \
Kevin D. Kissellc34e6e82009-03-31 12:59:24 +02001870 new = res & ~change; \
1871 new |= (newbits & change); \
1872 write_c0_##name(new); \
Ralf Baechle41c594a2006-04-05 09:45:45 +01001873 __emt(omt); \
1874 local_irq_restore(flags); \
1875 \
1876 return res; \
1877}
1878#endif
1879
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880__BUILD_SET_C0(status)
1881__BUILD_SET_C0(cause)
1882__BUILD_SET_C0(config)
1883__BUILD_SET_C0(intcontrol)
Ralf Baechle7a0fc582005-07-13 19:47:28 +00001884__BUILD_SET_C0(intctl)
1885__BUILD_SET_C0(srsmap)
Kevin Cernekee020232f2011-11-16 01:25:44 +00001886__BUILD_SET_C0(brcm_config_0)
1887__BUILD_SET_C0(brcm_bus_pll)
1888__BUILD_SET_C0(brcm_reset)
1889__BUILD_SET_C0(brcm_cmt_intr)
1890__BUILD_SET_C0(brcm_cmt_ctrl)
1891__BUILD_SET_C0(brcm_config)
1892__BUILD_SET_C0(brcm_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894#endif /* !__ASSEMBLY__ */
1895
1896#endif /* _ASM_MIPSREGS_H */