1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Contains the definition of registers common to all PowerPC variants.
4  * If a register definition has been changed in a different PowerPC
5  * variant, we will case it in #ifndef XXX ... #endif, and have the
6  * number used in the Programming Environments Manual For 32-Bit
7  * Implementations of the PowerPC Architecture (a.k.a. Green Book) here.
8  */
9 
10 #ifndef _ASM_POWERPC_REG_H
11 #define _ASM_POWERPC_REG_H
12 #ifdef __KERNEL__
13 
14 #include <linux/stringify.h>
15 #include <asm/cputable.h>
16 #include <asm/asm-const.h>
17 #include <asm/feature-fixups.h>
18 
19 /* Pickup Book E specific registers. */
20 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
21 #include <asm/reg_booke.h>
22 #endif /* CONFIG_BOOKE || CONFIG_40x */
23 
24 #ifdef CONFIG_FSL_EMB_PERFMON
25 #include <asm/reg_fsl_emb.h>
26 #endif
27 
28 #ifdef CONFIG_PPC_8xx
29 #include <asm/reg_8xx.h>
30 #endif /* CONFIG_PPC_8xx */
31 
32 #define MSR_SF_LG	63              /* Enable 64 bit mode */
33 #define MSR_ISF_LG	61              /* Interrupt 64b mode valid on 630 */
34 #define MSR_HV_LG 	60              /* Hypervisor state */
35 #define MSR_TS_T_LG	34		/* Trans Mem state: Transactional */
36 #define MSR_TS_S_LG	33		/* Trans Mem state: Suspended */
37 #define MSR_TS_LG	33		/* Trans Mem state (2 bits) */
38 #define MSR_TM_LG	32		/* Trans Mem Available */
39 #define MSR_VEC_LG	25	        /* Enable AltiVec */
40 #define MSR_VSX_LG	23		/* Enable VSX */
41 #define MSR_POW_LG	18		/* Enable Power Management */
42 #define MSR_WE_LG	18		/* Wait State Enable */
43 #define MSR_TGPR_LG	17		/* TLB Update registers in use */
44 #define MSR_CE_LG	17		/* Critical Interrupt Enable */
45 #define MSR_ILE_LG	16		/* Interrupt Little Endian */
46 #define MSR_EE_LG	15		/* External Interrupt Enable */
47 #define MSR_PR_LG	14		/* Problem State / Privilege Level */
48 #define MSR_FP_LG	13		/* Floating Point enable */
49 #define MSR_ME_LG	12		/* Machine Check Enable */
50 #define MSR_FE0_LG	11		/* Floating Exception mode 0 */
51 #define MSR_SE_LG	10		/* Single Step */
52 #define MSR_BE_LG	9		/* Branch Trace */
53 #define MSR_DE_LG	9 		/* Debug Exception Enable */
54 #define MSR_FE1_LG	8		/* Floating Exception mode 1 */
55 #define MSR_IP_LG	6		/* Exception prefix 0x000/0xFFF */
56 #define MSR_IR_LG	5 		/* Instruction Relocate */
57 #define MSR_DR_LG	4 		/* Data Relocate */
58 #define MSR_PE_LG	3		/* Protection Enable */
59 #define MSR_PX_LG	2		/* Protection Exclusive Mode */
60 #define MSR_PMM_LG	2		/* Performance monitor */
61 #define MSR_RI_LG	1		/* Recoverable Exception */
62 #define MSR_LE_LG	0 		/* Little Endian */
63 
64 #ifdef __ASSEMBLY__
65 #define __MASK(X)	(1<<(X))
66 #else
67 #define __MASK(X)	(1UL<<(X))
68 #endif
69 
70 #ifdef CONFIG_PPC64
71 #define MSR_SF		__MASK(MSR_SF_LG)	/* Enable 64 bit mode */
72 #define MSR_ISF		__MASK(MSR_ISF_LG)	/* Interrupt 64b mode valid on 630 */
73 #define MSR_HV 		__MASK(MSR_HV_LG)	/* Hypervisor state */
74 #else
75 /* so tests for these bits fail on 32-bit */
76 #define MSR_SF		0
77 #define MSR_ISF		0
78 #define MSR_HV		0
79 #endif
80 
81 /*
82  * To be used in shared book E/book S, this avoids needing to worry about
83  * book S/book E in shared code
84  */
85 #ifndef MSR_SPE
86 #define MSR_SPE 	0
87 #endif
88 
89 #define MSR_VEC		__MASK(MSR_VEC_LG)	/* Enable AltiVec */
90 #define MSR_VSX		__MASK(MSR_VSX_LG)	/* Enable VSX */
91 #define MSR_POW		__MASK(MSR_POW_LG)	/* Enable Power Management */
92 #define MSR_WE		__MASK(MSR_WE_LG)	/* Wait State Enable */
93 #define MSR_TGPR	__MASK(MSR_TGPR_LG)	/* TLB Update registers in use */
94 #define MSR_CE		__MASK(MSR_CE_LG)	/* Critical Interrupt Enable */
95 #define MSR_ILE		__MASK(MSR_ILE_LG)	/* Interrupt Little Endian */
96 #define MSR_EE		__MASK(MSR_EE_LG)	/* External Interrupt Enable */
97 #define MSR_PR		__MASK(MSR_PR_LG)	/* Problem State / Privilege Level */
98 #define MSR_FP		__MASK(MSR_FP_LG)	/* Floating Point enable */
99 #define MSR_ME		__MASK(MSR_ME_LG)	/* Machine Check Enable */
100 #define MSR_FE0		__MASK(MSR_FE0_LG)	/* Floating Exception mode 0 */
101 #define MSR_SE		__MASK(MSR_SE_LG)	/* Single Step */
102 #define MSR_BE		__MASK(MSR_BE_LG)	/* Branch Trace */
103 #define MSR_DE		__MASK(MSR_DE_LG)	/* Debug Exception Enable */
104 #define MSR_FE1		__MASK(MSR_FE1_LG)	/* Floating Exception mode 1 */
105 #define MSR_IP		__MASK(MSR_IP_LG)	/* Exception prefix 0x000/0xFFF */
106 #define MSR_IR		__MASK(MSR_IR_LG)	/* Instruction Relocate */
107 #define MSR_DR		__MASK(MSR_DR_LG)	/* Data Relocate */
108 #define MSR_PE		__MASK(MSR_PE_LG)	/* Protection Enable */
109 #define MSR_PX		__MASK(MSR_PX_LG)	/* Protection Exclusive Mode */
110 #ifndef MSR_PMM
111 #define MSR_PMM		__MASK(MSR_PMM_LG)	/* Performance monitor */
112 #endif
113 #define MSR_RI		__MASK(MSR_RI_LG)	/* Recoverable Exception */
114 #define MSR_LE		__MASK(MSR_LE_LG)	/* Little Endian */
115 
116 #define MSR_TM		__MASK(MSR_TM_LG)	/* Transactional Mem Available */
117 #define MSR_TS_N	0			/*  Non-transactional */
118 #define MSR_TS_S	__MASK(MSR_TS_S_LG)	/*  Transaction Suspended */
119 #define MSR_TS_T	__MASK(MSR_TS_T_LG)	/*  Transaction Transactional */
120 #define MSR_TS_MASK	(MSR_TS_T | MSR_TS_S)   /* Transaction State bits */
121 #define MSR_TM_ACTIVE(x) (((x) & MSR_TS_MASK) != 0) /* Transaction active? */
122 #define MSR_TM_RESV(x) (((x) & MSR_TS_MASK) == MSR_TS_MASK) /* Reserved */
123 #define MSR_TM_TRANSACTIONAL(x)	(((x) & MSR_TS_MASK) == MSR_TS_T)
124 #define MSR_TM_SUSPENDED(x)	(((x) & MSR_TS_MASK) == MSR_TS_S)
125 
126 #if defined(CONFIG_PPC_BOOK3S_64)
127 #define MSR_64BIT	MSR_SF
128 
129 /* Server variant */
130 #define __MSR		(MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV)
131 #ifdef __BIG_ENDIAN__
132 #define MSR_		__MSR
133 #define MSR_IDLE	(MSR_ME | MSR_SF | MSR_HV)
134 #else
135 #define MSR_		(__MSR | MSR_LE)
136 #define MSR_IDLE	(MSR_ME | MSR_SF | MSR_HV | MSR_LE)
137 #endif
138 #define MSR_KERNEL	(MSR_ | MSR_64BIT)
139 #define MSR_USER32	(MSR_ | MSR_PR | MSR_EE)
140 #define MSR_USER64	(MSR_USER32 | MSR_64BIT)
141 #elif defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx)
142 /* Default MSR for kernel mode. */
143 #define MSR_KERNEL	(MSR_ME|MSR_RI|MSR_IR|MSR_DR)
144 #define MSR_USER	(MSR_KERNEL|MSR_PR|MSR_EE)
145 #endif
146 
147 #ifndef MSR_64BIT
148 #define MSR_64BIT	0
149 #endif
150 
151 /* Condition Register related */
152 #define CR0_SHIFT	28
153 #define CR0_MASK	0xF
154 #define CR0_TBEGIN_FAILURE	(0x2 << 28) /* 0b0010 */
155 
156 
157 /* Power Management - Processor Stop Status and Control Register Fields */
158 #define PSSCR_RL_MASK		0x0000000F /* Requested Level */
159 #define PSSCR_MTL_MASK		0x000000F0 /* Maximum Transition Level */
160 #define PSSCR_TR_MASK		0x00000300 /* Transition State */
161 #define PSSCR_PSLL_MASK		0x000F0000 /* Power-Saving Level Limit */
162 #define PSSCR_EC		0x00100000 /* Exit Criterion */
163 #define PSSCR_ESL		0x00200000 /* Enable State Loss */
164 #define PSSCR_SD		0x00400000 /* Status Disable */
165 #define PSSCR_PLS	0xf000000000000000 /* Power-saving Level Status */
166 #define PSSCR_GUEST_VIS	0xf0000000000003ffUL /* Guest-visible PSSCR fields */
167 #define PSSCR_FAKE_SUSPEND	0x00000400 /* Fake-suspend bit (P9 DD2.2) */
168 #define PSSCR_FAKE_SUSPEND_LG	10	   /* Fake-suspend bit position */
169 
170 /* Floating Point Status and Control Register (FPSCR) Fields */
171 #define FPSCR_FX	0x80000000	/* FPU exception summary */
172 #define FPSCR_FEX	0x40000000	/* FPU enabled exception summary */
173 #define FPSCR_VX	0x20000000	/* Invalid operation summary */
174 #define FPSCR_OX	0x10000000	/* Overflow exception summary */
175 #define FPSCR_UX	0x08000000	/* Underflow exception summary */
176 #define FPSCR_ZX	0x04000000	/* Zero-divide exception summary */
177 #define FPSCR_XX	0x02000000	/* Inexact exception summary */
178 #define FPSCR_VXSNAN	0x01000000	/* Invalid op for SNaN */
179 #define FPSCR_VXISI	0x00800000	/* Invalid op for Inv - Inv */
180 #define FPSCR_VXIDI	0x00400000	/* Invalid op for Inv / Inv */
181 #define FPSCR_VXZDZ	0x00200000	/* Invalid op for Zero / Zero */
182 #define FPSCR_VXIMZ	0x00100000	/* Invalid op for Inv * Zero */
183 #define FPSCR_VXVC	0x00080000	/* Invalid op for Compare */
184 #define FPSCR_FR	0x00040000	/* Fraction rounded */
185 #define FPSCR_FI	0x00020000	/* Fraction inexact */
186 #define FPSCR_FPRF	0x0001f000	/* FPU Result Flags */
187 #define FPSCR_FPCC	0x0000f000	/* FPU Condition Codes */
188 #define FPSCR_VXSOFT	0x00000400	/* Invalid op for software request */
189 #define FPSCR_VXSQRT	0x00000200	/* Invalid op for square root */
190 #define FPSCR_VXCVI	0x00000100	/* Invalid op for integer convert */
191 #define FPSCR_VE	0x00000080	/* Invalid op exception enable */
192 #define FPSCR_OE	0x00000040	/* IEEE overflow exception enable */
193 #define FPSCR_UE	0x00000020	/* IEEE underflow exception enable */
194 #define FPSCR_ZE	0x00000010	/* IEEE zero divide exception enable */
195 #define FPSCR_XE	0x00000008	/* FP inexact exception enable */
196 #define FPSCR_NI	0x00000004	/* FPU non IEEE-Mode */
197 #define FPSCR_RN	0x00000003	/* FPU rounding control */
198 
199 /* Bit definitions for SPEFSCR. */
200 #define SPEFSCR_SOVH	0x80000000	/* Summary integer overflow high */
201 #define SPEFSCR_OVH	0x40000000	/* Integer overflow high */
202 #define SPEFSCR_FGH	0x20000000	/* Embedded FP guard bit high */
203 #define SPEFSCR_FXH	0x10000000	/* Embedded FP sticky bit high */
204 #define SPEFSCR_FINVH	0x08000000	/* Embedded FP invalid operation high */
205 #define SPEFSCR_FDBZH	0x04000000	/* Embedded FP div by zero high */
206 #define SPEFSCR_FUNFH	0x02000000	/* Embedded FP underflow high */
207 #define SPEFSCR_FOVFH	0x01000000	/* Embedded FP overflow high */
208 #define SPEFSCR_FINXS	0x00200000	/* Embedded FP inexact sticky */
209 #define SPEFSCR_FINVS	0x00100000	/* Embedded FP invalid op. sticky */
210 #define SPEFSCR_FDBZS	0x00080000	/* Embedded FP div by zero sticky */
211 #define SPEFSCR_FUNFS	0x00040000	/* Embedded FP underflow sticky */
212 #define SPEFSCR_FOVFS	0x00020000	/* Embedded FP overflow sticky */
213 #define SPEFSCR_MODE	0x00010000	/* Embedded FP mode */
214 #define SPEFSCR_SOV	0x00008000	/* Integer summary overflow */
215 #define SPEFSCR_OV	0x00004000	/* Integer overflow */
216 #define SPEFSCR_FG	0x00002000	/* Embedded FP guard bit */
217 #define SPEFSCR_FX	0x00001000	/* Embedded FP sticky bit */
218 #define SPEFSCR_FINV	0x00000800	/* Embedded FP invalid operation */
219 #define SPEFSCR_FDBZ	0x00000400	/* Embedded FP div by zero */
220 #define SPEFSCR_FUNF	0x00000200	/* Embedded FP underflow */
221 #define SPEFSCR_FOVF	0x00000100	/* Embedded FP overflow */
222 #define SPEFSCR_FINXE	0x00000040	/* Embedded FP inexact enable */
223 #define SPEFSCR_FINVE	0x00000020	/* Embedded FP invalid op. enable */
224 #define SPEFSCR_FDBZE	0x00000010	/* Embedded FP div by zero enable */
225 #define SPEFSCR_FUNFE	0x00000008	/* Embedded FP underflow enable */
226 #define SPEFSCR_FOVFE	0x00000004	/* Embedded FP overflow enable */
227 #define SPEFSCR_FRMC 	0x00000003	/* Embedded FP rounding mode control */
228 
229 /* Special Purpose Registers (SPRNs)*/
230 
231 #ifdef CONFIG_40x
232 #define SPRN_PID	0x3B1	/* Process ID */
233 #else
234 #define SPRN_PID	0x030	/* Process ID */
235 #ifdef CONFIG_BOOKE
236 #define SPRN_PID0	SPRN_PID/* Process ID Register 0 */
237 #endif
238 #endif
239 
240 #define SPRN_CTR	0x009	/* Count Register */
241 #define SPRN_DSCR	0x11
242 #define SPRN_CFAR	0x1c	/* Come From Address Register */
243 #define SPRN_AMR	0x1d	/* Authority Mask Register */
244 #define SPRN_UAMOR	0x9d	/* User Authority Mask Override Register */
245 #define SPRN_AMOR	0x15d	/* Authority Mask Override Register */
246 #define SPRN_ACOP	0x1F	/* Available Coprocessor Register */
247 #define SPRN_TFIAR	0x81	/* Transaction Failure Inst Addr   */
248 #define SPRN_TEXASR	0x82	/* Transaction EXception & Summary */
249 #define SPRN_TEXASRU	0x83	/* ''	   ''	   ''	 Upper 32  */
250 
251 #define TEXASR_FC_LG	(63 - 7)	/* Failure Code */
252 #define TEXASR_AB_LG	(63 - 31)	/* Abort */
253 #define TEXASR_SU_LG	(63 - 32)	/* Suspend */
254 #define TEXASR_HV_LG	(63 - 34)	/* Hypervisor state*/
255 #define TEXASR_PR_LG	(63 - 35)	/* Privilege level */
256 #define TEXASR_FS_LG	(63 - 36)	/* failure summary */
257 #define TEXASR_EX_LG	(63 - 37)	/* TFIAR exact bit */
258 #define TEXASR_ROT_LG	(63 - 38)	/* ROT bit */
259 
260 #define   TEXASR_ABORT	__MASK(TEXASR_AB_LG) /* terminated by tabort or treclaim */
261 #define   TEXASR_SUSP	__MASK(TEXASR_SU_LG) /* tx failed in suspended state */
262 #define   TEXASR_HV	__MASK(TEXASR_HV_LG) /* MSR[HV] when failure occurred */
263 #define   TEXASR_PR	__MASK(TEXASR_PR_LG) /* MSR[PR] when failure occurred */
264 #define   TEXASR_FS	__MASK(TEXASR_FS_LG) /* TEXASR Failure Summary */
265 #define   TEXASR_EXACT	__MASK(TEXASR_EX_LG) /* TFIAR value is exact */
266 #define   TEXASR_ROT	__MASK(TEXASR_ROT_LG)
267 #define   TEXASR_FC	(ASM_CONST(0xFF) << TEXASR_FC_LG)
268 
269 #define SPRN_TFHAR	0x80	/* Transaction Failure Handler Addr */
270 
271 #define SPRN_TIDR	144	/* Thread ID register */
272 #define SPRN_CTRLF	0x088
273 #define SPRN_CTRLT	0x098
274 #define   CTRL_CT	0xc0000000	/* current thread */
275 #define   CTRL_CT0	0x80000000	/* thread 0 */
276 #define   CTRL_CT1	0x40000000	/* thread 1 */
277 #define   CTRL_TE	0x00c00000	/* thread enable */
278 #define   CTRL_RUNLATCH	0x1
279 #define SPRN_DAWR	0xB4
280 #define SPRN_RPR	0xBA	/* Relative Priority Register */
281 #define SPRN_CIABR	0xBB
282 #define   CIABR_PRIV		0x3
283 #define   CIABR_PRIV_USER	1
284 #define   CIABR_PRIV_SUPER	2
285 #define   CIABR_PRIV_HYPER	3
286 #define SPRN_DAWRX	0xBC
287 #define   DAWRX_USER	__MASK(0)
288 #define   DAWRX_KERNEL	__MASK(1)
289 #define   DAWRX_HYP	__MASK(2)
290 #define   DAWRX_WTI	__MASK(3)
291 #define   DAWRX_WT	__MASK(4)
292 #define   DAWRX_DR	__MASK(5)
293 #define   DAWRX_DW	__MASK(6)
294 #define SPRN_DABR	0x3F5	/* Data Address Breakpoint Register */
295 #define SPRN_DABR2	0x13D	/* e300 */
296 #define SPRN_DABRX	0x3F7	/* Data Address Breakpoint Register Extension */
297 #define   DABRX_USER	__MASK(0)
298 #define   DABRX_KERNEL	__MASK(1)
299 #define   DABRX_HYP	__MASK(2)
300 #define   DABRX_BTI	__MASK(3)
301 #define   DABRX_ALL     (DABRX_BTI | DABRX_HYP | DABRX_KERNEL | DABRX_USER)
302 #define SPRN_DAR	0x013	/* Data Address Register */
303 #define SPRN_DBCR	0x136	/* e300 Data Breakpoint Control Reg */
304 #define SPRN_DSISR	0x012	/* Data Storage Interrupt Status Register */
305 #define   DSISR_BAD_DIRECT_ST	0x80000000 /* Obsolete: Direct store error */
306 #define   DSISR_NOHPTE		0x40000000 /* no translation found */
307 #define   DSISR_ATTR_CONFLICT	0x20000000 /* P9: Process vs. Partition attr */
308 #define   DSISR_NOEXEC_OR_G	0x10000000 /* Alias of SRR1 bit, see below */
309 #define   DSISR_PROTFAULT	0x08000000 /* protection fault */
310 #define   DSISR_BADACCESS	0x04000000 /* bad access to CI or G */
311 #define   DSISR_ISSTORE		0x02000000 /* access was a store */
312 #define   DSISR_DABRMATCH	0x00400000 /* hit data breakpoint */
313 #define   DSISR_NOSEGMENT	0x00200000 /* STAB miss (unsupported) */
314 #define   DSISR_KEYFAULT	0x00200000 /* Storage Key fault */
315 #define   DSISR_BAD_EXT_CTRL	0x00100000 /* Obsolete: External ctrl error */
316 #define   DSISR_UNSUPP_MMU	0x00080000 /* P9: Unsupported MMU config */
317 #define   DSISR_SET_RC		0x00040000 /* P9: Failed setting of R/C bits */
318 #define   DSISR_PRTABLE_FAULT   0x00020000 /* P9: Fault on process table */
319 #define   DSISR_ICSWX_NO_CT     0x00004000 /* P7: icswx unavailable cp type */
320 #define   DSISR_BAD_COPYPASTE   0x00000008 /* P9: Copy/Paste on wrong memtype */
321 #define   DSISR_BAD_AMO		0x00000004 /* P9: Incorrect AMO opcode */
322 #define   DSISR_BAD_CI_LDST	0x00000002 /* P8: Bad HV CI load/store */
323 
324 /*
325  * DSISR_NOEXEC_OR_G doesn't actually exist. This bit is always
326  * 0 on DSIs. However, on ISIs, the corresponding bit in SRR1
327  * indicates an attempt at executing from a no-execute PTE
328  * or segment or from a guarded page.
329  *
330  * We add a definition here for completeness as we alias
331  * DSISR and SRR1 in do_page_fault.
332  */
333 
334 /*
335  * DSISR bits that are treated as a fault. Any bit set
336  * here will skip hash_page, and cause do_page_fault to
337  * trigger a SIGBUS or SIGSEGV:
338  */
339 #define   DSISR_BAD_FAULT_32S	(DSISR_BAD_DIRECT_ST	| \
340 				 DSISR_BADACCESS	| \
341 				 DSISR_BAD_EXT_CTRL)
342 #define	  DSISR_BAD_FAULT_64S	(DSISR_BAD_FAULT_32S	| \
343 				 DSISR_ATTR_CONFLICT	| \
344 				 DSISR_UNSUPP_MMU	| \
345 				 DSISR_PRTABLE_FAULT	| \
346 				 DSISR_ICSWX_NO_CT	| \
347 				 DSISR_BAD_COPYPASTE	| \
348 				 DSISR_BAD_AMO		| \
349 				 DSISR_BAD_CI_LDST)
350 /*
351  * These bits are equivalent in SRR1 and DSISR for 0x400
352  * instruction access interrupts on Book3S
353  */
354 #define   DSISR_SRR1_MATCH_32S	(DSISR_NOHPTE		| \
355 				 DSISR_NOEXEC_OR_G	| \
356 				 DSISR_PROTFAULT)
357 #define   DSISR_SRR1_MATCH_64S	(DSISR_SRR1_MATCH_32S	| \
358 				 DSISR_KEYFAULT		| \
359 				 DSISR_UNSUPP_MMU	| \
360 				 DSISR_SET_RC		| \
361 				 DSISR_PRTABLE_FAULT)
362 
363 #define SPRN_TBRL	0x10C	/* Time Base Read Lower Register (user, R/O) */
364 #define SPRN_TBRU	0x10D	/* Time Base Read Upper Register (user, R/O) */
365 #define SPRN_CIR	0x11B	/* Chip Information Register (hyper, R/0) */
366 #define SPRN_TBWL	0x11C	/* Time Base Lower Register (super, R/W) */
367 #define SPRN_TBWU	0x11D	/* Time Base Upper Register (super, R/W) */
368 #define SPRN_TBU40	0x11E	/* Timebase upper 40 bits (hyper, R/W) */
369 #define SPRN_SPURR	0x134	/* Scaled PURR */
370 #define SPRN_HSPRG0	0x130	/* Hypervisor Scratch 0 */
371 #define SPRN_HSPRG1	0x131	/* Hypervisor Scratch 1 */
372 #define SPRN_HDSISR     0x132
373 #define SPRN_HDAR       0x133
374 #define SPRN_HDEC	0x136	/* Hypervisor Decrementer */
375 #define SPRN_HIOR	0x137	/* 970 Hypervisor interrupt offset */
376 #define SPRN_RMOR	0x138	/* Real mode offset register */
377 #define SPRN_HRMOR	0x139	/* Real mode offset register */
378 #define SPRN_HSRR0	0x13A	/* Hypervisor Save/Restore 0 */
379 #define SPRN_HSRR1	0x13B	/* Hypervisor Save/Restore 1 */
380 #define SPRN_ASDR	0x330	/* Access segment descriptor register */
381 #define SPRN_IC		0x350	/* Virtual Instruction Count */
382 #define SPRN_VTB	0x351	/* Virtual Time Base */
383 #define SPRN_LDBAR	0x352	/* LD Base Address Register */
384 #define SPRN_PMICR	0x354   /* Power Management Idle Control Reg */
385 #define SPRN_PMSR	0x355   /* Power Management Status Reg */
386 #define SPRN_PMMAR	0x356	/* Power Management Memory Activity Register */
387 #define SPRN_PSSCR	0x357	/* Processor Stop Status and Control Register (ISA 3.0) */
388 #define SPRN_PSSCR_PR	0x337	/* PSSCR ISA 3.0, privileged mode access */
389 #define SPRN_PMCR	0x374	/* Power Management Control Register */
390 #define SPRN_RWMR	0x375	/* Region-Weighting Mode Register */
391 
392 /* HFSCR and FSCR bit numbers are the same */
393 #define FSCR_SCV_LG	12	/* Enable System Call Vectored */
394 #define FSCR_MSGP_LG	10	/* Enable MSGP */
395 #define FSCR_TAR_LG	8	/* Enable Target Address Register */
396 #define FSCR_EBB_LG	7	/* Enable Event Based Branching */
397 #define FSCR_TM_LG	5	/* Enable Transactional Memory */
398 #define FSCR_BHRB_LG	4	/* Enable Branch History Rolling Buffer*/
399 #define FSCR_PM_LG	3	/* Enable prob/priv access to PMU SPRs */
400 #define FSCR_DSCR_LG	2	/* Enable Data Stream Control Register */
401 #define FSCR_VECVSX_LG	1	/* Enable VMX/VSX  */
402 #define FSCR_FP_LG	0	/* Enable Floating Point */
403 #define SPRN_FSCR	0x099	/* Facility Status & Control Register */
404 #define   FSCR_SCV	__MASK(FSCR_SCV_LG)
405 #define   FSCR_TAR	__MASK(FSCR_TAR_LG)
406 #define   FSCR_EBB	__MASK(FSCR_EBB_LG)
407 #define   FSCR_DSCR	__MASK(FSCR_DSCR_LG)
408 #define SPRN_HFSCR	0xbe	/* HV=1 Facility Status & Control Register */
409 #define   HFSCR_MSGP	__MASK(FSCR_MSGP_LG)
410 #define   HFSCR_TAR	__MASK(FSCR_TAR_LG)
411 #define   HFSCR_EBB	__MASK(FSCR_EBB_LG)
412 #define   HFSCR_TM	__MASK(FSCR_TM_LG)
413 #define   HFSCR_PM	__MASK(FSCR_PM_LG)
414 #define   HFSCR_BHRB	__MASK(FSCR_BHRB_LG)
415 #define   HFSCR_DSCR	__MASK(FSCR_DSCR_LG)
416 #define   HFSCR_VECVSX	__MASK(FSCR_VECVSX_LG)
417 #define   HFSCR_FP	__MASK(FSCR_FP_LG)
418 #define SPRN_TAR	0x32f	/* Target Address Register */
419 #define SPRN_LPCR	0x13E	/* LPAR Control Register */
420 #define   LPCR_VPM0		ASM_CONST(0x8000000000000000)
421 #define   LPCR_VPM1		ASM_CONST(0x4000000000000000)
422 #define   LPCR_ISL		ASM_CONST(0x2000000000000000)
423 #define   LPCR_VC_SH		61
424 #define   LPCR_DPFD_SH		52
425 #define   LPCR_DPFD		(ASM_CONST(7) << LPCR_DPFD_SH)
426 #define   LPCR_VRMASD_SH	47
427 #define   LPCR_VRMASD		(ASM_CONST(0x1f) << LPCR_VRMASD_SH)
428 #define   LPCR_VRMA_L		ASM_CONST(0x0008000000000000)
429 #define   LPCR_VRMA_LP0		ASM_CONST(0x0001000000000000)
430 #define   LPCR_VRMA_LP1		ASM_CONST(0x0000800000000000)
431 #define   LPCR_RMLS		0x1C000000	/* Implementation dependent RMO limit sel */
432 #define   LPCR_RMLS_SH		26
433 #define   LPCR_ILE		ASM_CONST(0x0000000002000000)   /* !HV irqs set MSR:LE */
434 #define   LPCR_AIL		ASM_CONST(0x0000000001800000)	/* Alternate interrupt location */
435 #define   LPCR_AIL_0		ASM_CONST(0x0000000000000000)	/* MMU off exception offset 0x0 */
436 #define   LPCR_AIL_3		ASM_CONST(0x0000000001800000)   /* MMU on exception offset 0xc00...4xxx */
437 #define   LPCR_ONL		ASM_CONST(0x0000000000040000)	/* online - PURR/SPURR count */
438 #define   LPCR_LD		ASM_CONST(0x0000000000020000)	/* large decremeter */
439 #define   LPCR_PECE		ASM_CONST(0x000000000001f000)	/* powersave exit cause enable */
440 #define     LPCR_PECEDP	ASM_CONST(0x0000000000010000)	/* directed priv dbells cause exit */
441 #define     LPCR_PECEDH	ASM_CONST(0x0000000000008000)	/* directed hyp dbells cause exit */
442 #define     LPCR_PECE0		ASM_CONST(0x0000000000004000)	/* ext. exceptions can cause exit */
443 #define     LPCR_PECE1		ASM_CONST(0x0000000000002000)	/* decrementer can cause exit */
444 #define     LPCR_PECE2		ASM_CONST(0x0000000000001000)	/* machine check etc can cause exit */
445 #define     LPCR_PECE_HVEE	ASM_CONST(0x0000400000000000)	/* P9 Wakeup on HV interrupts */
446 #define   LPCR_MER		ASM_CONST(0x0000000000000800)	/* Mediated External Exception */
447 #define   LPCR_MER_SH		11
448 #define	  LPCR_GTSE		ASM_CONST(0x0000000000000400)  	/* Guest Translation Shootdown Enable */
449 #define   LPCR_TC		ASM_CONST(0x0000000000000200)	/* Translation control */
450 #define   LPCR_HEIC		ASM_CONST(0x0000000000000010)   /* Hypervisor External Interrupt Control */
451 #define   LPCR_LPES		0x0000000c
452 #define   LPCR_LPES0		ASM_CONST(0x0000000000000008)      /* LPAR Env selector 0 */
453 #define   LPCR_LPES1		ASM_CONST(0x0000000000000004)      /* LPAR Env selector 1 */
454 #define   LPCR_LPES_SH		2
455 #define   LPCR_RMI		ASM_CONST(0x0000000000000002)      /* real mode is cache inhibit */
456 #define   LPCR_HVICE		ASM_CONST(0x0000000000000002)      /* P9: HV interrupt enable */
457 #define   LPCR_HDICE		ASM_CONST(0x0000000000000001)      /* Hyp Decr enable (HV,PR,EE) */
458 #define   LPCR_UPRT		ASM_CONST(0x0000000000400000)      /* Use Process Table (ISA 3) */
459 #define   LPCR_HR		ASM_CONST(0x0000000000100000)
460 #ifndef SPRN_LPID
461 #define SPRN_LPID	0x13F	/* Logical Partition Identifier */
462 #endif
463 #define   LPID_RSVD	0x3ff		/* Reserved LPID for partn switching */
464 #define	SPRN_HMER	0x150	/* Hypervisor maintenance exception reg */
465 #define   HMER_DEBUG_TRIG	(1ul << (63 - 17)) /* Debug trigger */
466 #define	SPRN_HMEER	0x151	/* Hyp maintenance exception enable reg */
467 #define SPRN_PCR	0x152	/* Processor compatibility register */
468 #define   PCR_VEC_DIS	(1ul << (63-0))	/* Vec. disable (bit NA since POWER8) */
469 #define   PCR_VSX_DIS	(1ul << (63-1))	/* VSX disable (bit NA since POWER8) */
470 #define   PCR_TM_DIS	(1ul << (63-2))	/* Trans. memory disable (POWER8) */
471 /*
472  * These bits are used in the function kvmppc_set_arch_compat() to specify and
473  * determine both the compatibility level which we want to emulate and the
474  * compatibility level which the host is capable of emulating.
475  */
476 #define   PCR_ARCH_207	0x8		/* Architecture 2.07 */
477 #define   PCR_ARCH_206	0x4		/* Architecture 2.06 */
478 #define   PCR_ARCH_205	0x2		/* Architecture 2.05 */
479 #define	SPRN_HEIR	0x153	/* Hypervisor Emulated Instruction Register */
480 #define SPRN_TLBINDEXR	0x154	/* P7 TLB control register */
481 #define SPRN_TLBVPNR	0x155	/* P7 TLB control register */
482 #define SPRN_TLBRPNR	0x156	/* P7 TLB control register */
483 #define SPRN_TLBLPIDR	0x157	/* P7 TLB control register */
484 #define SPRN_DBAT0L	0x219	/* Data BAT 0 Lower Register */
485 #define SPRN_DBAT0U	0x218	/* Data BAT 0 Upper Register */
486 #define SPRN_DBAT1L	0x21B	/* Data BAT 1 Lower Register */
487 #define SPRN_DBAT1U	0x21A	/* Data BAT 1 Upper Register */
488 #define SPRN_DBAT2L	0x21D	/* Data BAT 2 Lower Register */
489 #define SPRN_DBAT2U	0x21C	/* Data BAT 2 Upper Register */
490 #define SPRN_DBAT3L	0x21F	/* Data BAT 3 Lower Register */
491 #define SPRN_DBAT3U	0x21E	/* Data BAT 3 Upper Register */
492 #define SPRN_DBAT4L	0x239	/* Data BAT 4 Lower Register */
493 #define SPRN_DBAT4U	0x238	/* Data BAT 4 Upper Register */
494 #define SPRN_DBAT5L	0x23B	/* Data BAT 5 Lower Register */
495 #define SPRN_DBAT5U	0x23A	/* Data BAT 5 Upper Register */
496 #define SPRN_DBAT6L	0x23D	/* Data BAT 6 Lower Register */
497 #define SPRN_DBAT6U	0x23C	/* Data BAT 6 Upper Register */
498 #define SPRN_DBAT7L	0x23F	/* Data BAT 7 Lower Register */
499 #define SPRN_DBAT7U	0x23E	/* Data BAT 7 Upper Register */
500 #define SPRN_PPR	0x380	/* SMT Thread status Register */
501 #define SPRN_TSCR	0x399	/* Thread Switch Control Register */
502 
503 #define SPRN_DEC	0x016		/* Decrement Register */
504 #define SPRN_DER	0x095		/* Debug Enable Register */
505 #define DER_RSTE	0x40000000	/* Reset Interrupt */
506 #define DER_CHSTPE	0x20000000	/* Check Stop */
507 #define DER_MCIE	0x10000000	/* Machine Check Interrupt */
508 #define DER_EXTIE	0x02000000	/* External Interrupt */
509 #define DER_ALIE	0x01000000	/* Alignment Interrupt */
510 #define DER_PRIE	0x00800000	/* Program Interrupt */
511 #define DER_FPUVIE	0x00400000	/* FP Unavailable Interrupt */
512 #define DER_DECIE	0x00200000	/* Decrementer Interrupt */
513 #define DER_SYSIE	0x00040000	/* System Call Interrupt */
514 #define DER_TRE		0x00020000	/* Trace Interrupt */
515 #define DER_SEIE	0x00004000	/* FP SW Emulation Interrupt */
516 #define DER_ITLBMSE	0x00002000	/* Imp. Spec. Instruction TLB Miss */
517 #define DER_ITLBERE	0x00001000	/* Imp. Spec. Instruction TLB Error */
518 #define DER_DTLBMSE	0x00000800	/* Imp. Spec. Data TLB Miss */
519 #define DER_DTLBERE	0x00000400	/* Imp. Spec. Data TLB Error */
520 #define DER_LBRKE	0x00000008	/* Load/Store Breakpoint Interrupt */
521 #define DER_IBRKE	0x00000004	/* Instruction Breakpoint Interrupt */
522 #define DER_EBRKE	0x00000002	/* External Breakpoint Interrupt */
523 #define DER_DPIE	0x00000001	/* Dev. Port Nonmaskable Request */
524 #define SPRN_DMISS	0x3D0		/* Data TLB Miss Register */
525 #define SPRN_DHDES	0x0B1		/* Directed Hyp. Doorbell Exc. State */
526 #define SPRN_DPDES	0x0B0		/* Directed Priv. Doorbell Exc. State */
527 #define SPRN_EAR	0x11A		/* External Address Register */
528 #define SPRN_HASH1	0x3D2		/* Primary Hash Address Register */
529 #define SPRN_HASH2	0x3D3		/* Secondary Hash Address Register */
530 #define SPRN_HID0	0x3F0		/* Hardware Implementation Register 0 */
531 #define HID0_HDICE_SH	(63 - 23)	/* 970 HDEC interrupt enable */
532 #define HID0_EMCP	(1<<31)		/* Enable Machine Check pin */
533 #define HID0_EBA	(1<<29)		/* Enable Bus Address Parity */
534 #define HID0_EBD	(1<<28)		/* Enable Bus Data Parity */
535 #define HID0_SBCLK	(1<<27)
536 #define HID0_EICE	(1<<26)
537 #define HID0_TBEN	(1<<26)		/* Timebase enable - 745x */
538 #define HID0_ECLK	(1<<25)
539 #define HID0_PAR	(1<<24)
540 #define HID0_STEN	(1<<24)		/* Software table search enable - 745x */
541 #define HID0_HIGH_BAT	(1<<23)		/* Enable high BATs - 7455 */
542 #define HID0_DOZE	(1<<23)
543 #define HID0_NAP	(1<<22)
544 #define HID0_SLEEP	(1<<21)
545 #define HID0_DPM	(1<<20)
546 #define HID0_BHTCLR	(1<<18)		/* Clear branch history table - 7450 */
547 #define HID0_XAEN	(1<<17)		/* Extended addressing enable - 7450 */
548 #define HID0_NHR	(1<<16)		/* Not hard reset (software bit-7450)*/
549 #define HID0_ICE	(1<<15)		/* Instruction Cache Enable */
550 #define HID0_DCE	(1<<14)		/* Data Cache Enable */
551 #define HID0_ILOCK	(1<<13)		/* Instruction Cache Lock */
552 #define HID0_DLOCK	(1<<12)		/* Data Cache Lock */
553 #define HID0_ICFI	(1<<11)		/* Instr. Cache Flash Invalidate */
554 #define HID0_DCI	(1<<10)		/* Data Cache Invalidate */
555 #define HID0_SPD	(1<<9)		/* Speculative disable */
556 #define HID0_DAPUEN	(1<<8)		/* Debug APU enable */
557 #define HID0_SGE	(1<<7)		/* Store Gathering Enable */
558 #define HID0_SIED	(1<<7)		/* Serial Instr. Execution [Disable] */
559 #define HID0_DCFA	(1<<6)		/* Data Cache Flush Assist */
560 #define HID0_LRSTK	(1<<4)		/* Link register stack - 745x */
561 #define HID0_BTIC	(1<<5)		/* Branch Target Instr Cache Enable */
562 #define HID0_ABE	(1<<3)		/* Address Broadcast Enable */
563 #define HID0_FOLD	(1<<3)		/* Branch Folding enable - 745x */
564 #define HID0_BHTE	(1<<2)		/* Branch History Table Enable */
565 #define HID0_BTCD	(1<<1)		/* Branch target cache disable */
566 #define HID0_NOPDST	(1<<1)		/* No-op dst, dstt, etc. instr. */
567 #define HID0_NOPTI	(1<<0)		/* No-op dcbt and dcbst instr. */
568 /* POWER8 HID0 bits */
569 #define HID0_POWER8_4LPARMODE	__MASK(61)
570 #define HID0_POWER8_2LPARMODE	__MASK(57)
571 #define HID0_POWER8_1TO2LPAR	__MASK(52)
572 #define HID0_POWER8_1TO4LPAR	__MASK(51)
573 #define HID0_POWER8_DYNLPARDIS	__MASK(48)
574 
575 /* POWER9 HID0 bits */
576 #define HID0_POWER9_RADIX	__MASK(63 - 8)
577 
578 #define SPRN_HID1	0x3F1		/* Hardware Implementation Register 1 */
579 #ifdef CONFIG_6xx
580 #define HID1_EMCP	(1<<31)		/* 7450 Machine Check Pin Enable */
581 #define HID1_DFS	(1<<22)		/* 7447A Dynamic Frequency Scaling */
582 #define HID1_PC0	(1<<16)		/* 7450 PLL_CFG[0] */
583 #define HID1_PC1	(1<<15)		/* 7450 PLL_CFG[1] */
584 #define HID1_PC2	(1<<14)		/* 7450 PLL_CFG[2] */
585 #define HID1_PC3	(1<<13)		/* 7450 PLL_CFG[3] */
586 #define HID1_SYNCBE	(1<<11)		/* 7450 ABE for sync, eieio */
587 #define HID1_ABE	(1<<10)		/* 7450 Address Broadcast Enable */
588 #define HID1_PS		(1<<16)		/* 750FX PLL selection */
589 #endif
590 #define SPRN_HID2	0x3F8		/* Hardware Implementation Register 2 */
591 #define SPRN_HID2_GEKKO	0x398		/* Gekko HID2 Register */
592 #define SPRN_IABR	0x3F2	/* Instruction Address Breakpoint Register */
593 #define SPRN_IABR2	0x3FA		/* 83xx */
594 #define SPRN_IBCR	0x135		/* 83xx Insn Breakpoint Control Reg */
595 #define SPRN_IAMR	0x03D		/* Instr. Authority Mask Reg */
596 #define SPRN_HID4	0x3F4		/* 970 HID4 */
597 #define  HID4_LPES0	 (1ul << (63-0)) /* LPAR env. sel. bit 0 */
598 #define	 HID4_RMLS2_SH	 (63 - 2)	/* Real mode limit bottom 2 bits */
599 #define	 HID4_LPID5_SH	 (63 - 6)	/* partition ID bottom 4 bits */
600 #define	 HID4_RMOR_SH	 (63 - 22)	/* real mode offset (16 bits) */
601 #define  HID4_RMOR	 (0xFFFFul << HID4_RMOR_SH)
602 #define  HID4_LPES1	 (1 << (63-57))	/* LPAR env. sel. bit 1 */
603 #define  HID4_RMLS0_SH	 (63 - 58)	/* Real mode limit top bit */
604 #define	 HID4_LPID1_SH	 0		/* partition ID top 2 bits */
605 #define SPRN_HID4_GEKKO	0x3F3		/* Gekko HID4 */
606 #define SPRN_HID5	0x3F6		/* 970 HID5 */
607 #define SPRN_HID6	0x3F9	/* BE HID 6 */
608 #define   HID6_LB	(0x0F<<12) /* Concurrent Large Page Modes */
609 #define   HID6_DLP	(1<<20)	/* Disable all large page modes (4K only) */
610 #define SPRN_TSC_CELL	0x399	/* Thread switch control on Cell */
611 #define   TSC_CELL_DEC_ENABLE_0	0x400000 /* Decrementer Interrupt */
612 #define   TSC_CELL_DEC_ENABLE_1	0x200000 /* Decrementer Interrupt */
613 #define   TSC_CELL_EE_ENABLE	0x100000 /* External Interrupt */
614 #define   TSC_CELL_EE_BOOST	0x080000 /* External Interrupt Boost */
615 #define SPRN_TSC 	0x3FD	/* Thread switch control on others */
616 #define SPRN_TST 	0x3FC	/* Thread switch timeout on others */
617 #if !defined(SPRN_IAC1) && !defined(SPRN_IAC2)
618 #define SPRN_IAC1	0x3F4		/* Instruction Address Compare 1 */
619 #define SPRN_IAC2	0x3F5		/* Instruction Address Compare 2 */
620 #endif
621 #define SPRN_IBAT0L	0x211		/* Instruction BAT 0 Lower Register */
622 #define SPRN_IBAT0U	0x210		/* Instruction BAT 0 Upper Register */
623 #define SPRN_IBAT1L	0x213		/* Instruction BAT 1 Lower Register */
624 #define SPRN_IBAT1U	0x212		/* Instruction BAT 1 Upper Register */
625 #define SPRN_IBAT2L	0x215		/* Instruction BAT 2 Lower Register */
626 #define SPRN_IBAT2U	0x214		/* Instruction BAT 2 Upper Register */
627 #define SPRN_IBAT3L	0x217		/* Instruction BAT 3 Lower Register */
628 #define SPRN_IBAT3U	0x216		/* Instruction BAT 3 Upper Register */
629 #define SPRN_IBAT4L	0x231		/* Instruction BAT 4 Lower Register */
630 #define SPRN_IBAT4U	0x230		/* Instruction BAT 4 Upper Register */
631 #define SPRN_IBAT5L	0x233		/* Instruction BAT 5 Lower Register */
632 #define SPRN_IBAT5U	0x232		/* Instruction BAT 5 Upper Register */
633 #define SPRN_IBAT6L	0x235		/* Instruction BAT 6 Lower Register */
634 #define SPRN_IBAT6U	0x234		/* Instruction BAT 6 Upper Register */
635 #define SPRN_IBAT7L	0x237		/* Instruction BAT 7 Lower Register */
636 #define SPRN_IBAT7U	0x236		/* Instruction BAT 7 Upper Register */
637 #define SPRN_ICMP	0x3D5		/* Instruction TLB Compare Register */
638 #define SPRN_ICTC	0x3FB	/* Instruction Cache Throttling Control Reg */
639 #ifndef SPRN_ICTRL
640 #define SPRN_ICTRL	0x3F3	/* 1011 7450 icache and interrupt ctrl */
641 #endif
642 #define ICTRL_EICE	0x08000000	/* enable icache parity errs */
643 #define ICTRL_EDC	0x04000000	/* enable dcache parity errs */
644 #define ICTRL_EICP	0x00000100	/* enable icache par. check */
645 #define SPRN_IMISS	0x3D4		/* Instruction TLB Miss Register */
646 #define SPRN_IMMR	0x27E		/* Internal Memory Map Register */
647 #define SPRN_L2CR	0x3F9		/* Level 2 Cache Control Register */
648 #define SPRN_L2CR2	0x3f8
649 #define L2CR_L2E		0x80000000	/* L2 enable */
650 #define L2CR_L2PE		0x40000000	/* L2 parity enable */
651 #define L2CR_L2SIZ_MASK		0x30000000	/* L2 size mask */
652 #define L2CR_L2SIZ_256KB	0x10000000	/* L2 size 256KB */
653 #define L2CR_L2SIZ_512KB	0x20000000	/* L2 size 512KB */
654 #define L2CR_L2SIZ_1MB		0x30000000	/* L2 size 1MB */
655 #define L2CR_L2CLK_MASK		0x0e000000	/* L2 clock mask */
656 #define L2CR_L2CLK_DISABLED	0x00000000	/* L2 clock disabled */
657 #define L2CR_L2CLK_DIV1		0x02000000	/* L2 clock / 1 */
658 #define L2CR_L2CLK_DIV1_5	0x04000000	/* L2 clock / 1.5 */
659 #define L2CR_L2CLK_DIV2		0x08000000	/* L2 clock / 2 */
660 #define L2CR_L2CLK_DIV2_5	0x0a000000	/* L2 clock / 2.5 */
661 #define L2CR_L2CLK_DIV3		0x0c000000	/* L2 clock / 3 */
662 #define L2CR_L2RAM_MASK		0x01800000	/* L2 RAM type mask */
663 #define L2CR_L2RAM_FLOW		0x00000000	/* L2 RAM flow through */
664 #define L2CR_L2RAM_PIPE		0x01000000	/* L2 RAM pipelined */
665 #define L2CR_L2RAM_PIPE_LW	0x01800000	/* L2 RAM pipelined latewr */
666 #define L2CR_L2DO		0x00400000	/* L2 data only */
667 #define L2CR_L2I		0x00200000	/* L2 global invalidate */
668 #define L2CR_L2CTL		0x00100000	/* L2 RAM control */
669 #define L2CR_L2WT		0x00080000	/* L2 write-through */
670 #define L2CR_L2TS		0x00040000	/* L2 test support */
671 #define L2CR_L2OH_MASK		0x00030000	/* L2 output hold mask */
672 #define L2CR_L2OH_0_5		0x00000000	/* L2 output hold 0.5 ns */
673 #define L2CR_L2OH_1_0		0x00010000	/* L2 output hold 1.0 ns */
674 #define L2CR_L2SL		0x00008000	/* L2 DLL slow */
675 #define L2CR_L2DF		0x00004000	/* L2 differential clock */
676 #define L2CR_L2BYP		0x00002000	/* L2 DLL bypass */
677 #define L2CR_L2IP		0x00000001	/* L2 GI in progress */
678 #define L2CR_L2IO_745x		0x00100000	/* L2 instr. only (745x) */
679 #define L2CR_L2DO_745x		0x00010000	/* L2 data only (745x) */
680 #define L2CR_L2REP_745x		0x00001000	/* L2 repl. algorithm (745x) */
681 #define L2CR_L2HWF_745x		0x00000800	/* L2 hardware flush (745x) */
682 #define SPRN_L3CR		0x3FA	/* Level 3 Cache Control Register */
683 #define L3CR_L3E		0x80000000	/* L3 enable */
684 #define L3CR_L3PE		0x40000000	/* L3 data parity enable */
685 #define L3CR_L3APE		0x20000000	/* L3 addr parity enable */
686 #define L3CR_L3SIZ		0x10000000	/* L3 size */
687 #define L3CR_L3CLKEN		0x08000000	/* L3 clock enable */
688 #define L3CR_L3RES		0x04000000	/* L3 special reserved bit */
689 #define L3CR_L3CLKDIV		0x03800000	/* L3 clock divisor */
690 #define L3CR_L3IO		0x00400000	/* L3 instruction only */
691 #define L3CR_L3SPO		0x00040000	/* L3 sample point override */
692 #define L3CR_L3CKSP		0x00030000	/* L3 clock sample point */
693 #define L3CR_L3PSP		0x0000e000	/* L3 P-clock sample point */
694 #define L3CR_L3REP		0x00001000	/* L3 replacement algorithm */
695 #define L3CR_L3HWF		0x00000800	/* L3 hardware flush */
696 #define L3CR_L3I		0x00000400	/* L3 global invalidate */
697 #define L3CR_L3RT		0x00000300	/* L3 SRAM type */
698 #define L3CR_L3NIRCA		0x00000080	/* L3 non-integer ratio clock adj. */
699 #define L3CR_L3DO		0x00000040	/* L3 data only mode */
700 #define L3CR_PMEN		0x00000004	/* L3 private memory enable */
701 #define L3CR_PMSIZ		0x00000001	/* L3 private memory size */
702 
703 #define SPRN_MSSCR0	0x3f6	/* Memory Subsystem Control Register 0 */
704 #define SPRN_MSSSR0	0x3f7	/* Memory Subsystem Status Register 1 */
705 #define SPRN_LDSTCR	0x3f8	/* Load/Store control register */
706 #define SPRN_LDSTDB	0x3f4	/* */
707 #define SPRN_LR		0x008	/* Link Register */
708 #ifndef SPRN_PIR
709 #define SPRN_PIR	0x3FF	/* Processor Identification Register */
710 #endif
711 #define SPRN_TIR	0x1BE	/* Thread Identification Register */
712 #define SPRN_PTCR	0x1D0	/* Partition table control Register */
713 #define SPRN_PSPB	0x09F	/* Problem State Priority Boost reg */
714 #define SPRN_PTEHI	0x3D5	/* 981 7450 PTE HI word (S/W TLB load) */
715 #define SPRN_PTELO	0x3D6	/* 982 7450 PTE LO word (S/W TLB load) */
716 #define SPRN_PURR	0x135	/* Processor Utilization of Resources Reg */
717 #define SPRN_PVR	0x11F	/* Processor Version Register */
718 #define SPRN_RPA	0x3D6	/* Required Physical Address Register */
719 #define SPRN_SDA	0x3BF	/* Sampled Data Address Register */
720 #define SPRN_SDR1	0x019	/* MMU Hash Base Register */
721 #define SPRN_ASR	0x118   /* Address Space Register */
722 #define SPRN_SIA	0x3BB	/* Sampled Instruction Address Register */
723 #define SPRN_SPRG0	0x110	/* Special Purpose Register General 0 */
724 #define SPRN_SPRG1	0x111	/* Special Purpose Register General 1 */
725 #define SPRN_SPRG2	0x112	/* Special Purpose Register General 2 */
726 #define SPRN_SPRG3	0x113	/* Special Purpose Register General 3 */
727 #define SPRN_USPRG3	0x103	/* SPRG3 userspace read */
728 #define SPRN_SPRG4	0x114	/* Special Purpose Register General 4 */
729 #define SPRN_USPRG4	0x104	/* SPRG4 userspace read */
730 #define SPRN_SPRG5	0x115	/* Special Purpose Register General 5 */
731 #define SPRN_USPRG5	0x105	/* SPRG5 userspace read */
732 #define SPRN_SPRG6	0x116	/* Special Purpose Register General 6 */
733 #define SPRN_USPRG6	0x106	/* SPRG6 userspace read */
734 #define SPRN_SPRG7	0x117	/* Special Purpose Register General 7 */
735 #define SPRN_USPRG7	0x107	/* SPRG7 userspace read */
736 #define SPRN_SRR0	0x01A	/* Save/Restore Register 0 */
737 #define SPRN_SRR1	0x01B	/* Save/Restore Register 1 */
738 #define   SRR1_ISI_NOPT		0x40000000 /* ISI: Not found in hash */
739 #define   SRR1_ISI_N_OR_G	0x10000000 /* ISI: Access is no-exec or G */
740 #define   SRR1_ISI_PROT		0x08000000 /* ISI: Other protection fault */
741 #define   SRR1_WAKEMASK		0x00380000 /* reason for wakeup */
742 #define   SRR1_WAKEMASK_P8	0x003c0000 /* reason for wakeup on POWER8 and 9 */
743 #define   SRR1_WAKEMCE_RESVD	0x003c0000 /* Unused/reserved value used by MCE wakeup to indicate cause to idle wakeup handler */
744 #define   SRR1_WAKESYSERR	0x00300000 /* System error */
745 #define   SRR1_WAKEEE		0x00200000 /* External interrupt */
746 #define   SRR1_WAKEHVI		0x00240000 /* Hypervisor Virtualization Interrupt (P9) */
747 #define   SRR1_WAKEMT		0x00280000 /* mtctrl */
748 #define	  SRR1_WAKEHMI		0x00280000 /* Hypervisor maintenance */
749 #define   SRR1_WAKEDEC		0x00180000 /* Decrementer interrupt */
750 #define   SRR1_WAKEDBELL	0x00140000 /* Privileged doorbell on P8 */
751 #define   SRR1_WAKETHERM	0x00100000 /* Thermal management interrupt */
752 #define	  SRR1_WAKERESET	0x00100000 /* System reset */
753 #define   SRR1_WAKEHDBELL	0x000c0000 /* Hypervisor doorbell on P8 */
754 #define	  SRR1_WAKESTATE	0x00030000 /* Powersave exit mask [46:47] */
755 #define	  SRR1_WS_DEEPEST	0x00030000 /* Some resources not maintained,
756 					  * may not be recoverable */
757 #define	  SRR1_WS_DEEPER	0x00020000 /* Some resources not maintained */
758 #define	  SRR1_WS_DEEP		0x00010000 /* All resources maintained */
759 #define   SRR1_PROGTM		0x00200000 /* TM Bad Thing */
760 #define   SRR1_PROGFPE		0x00100000 /* Floating Point Enabled */
761 #define   SRR1_PROGILL		0x00080000 /* Illegal instruction */
762 #define   SRR1_PROGPRIV		0x00040000 /* Privileged instruction */
763 #define   SRR1_PROGTRAP		0x00020000 /* Trap */
764 #define   SRR1_PROGADDR		0x00010000 /* SRR0 contains subsequent addr */
765 
766 #define SPRN_HSRR0	0x13A	/* Save/Restore Register 0 */
767 #define SPRN_HSRR1	0x13B	/* Save/Restore Register 1 */
768 #define   HSRR1_DENORM		0x00100000 /* Denorm exception */
769 
770 #define SPRN_TBCTL	0x35f	/* PA6T Timebase control register */
771 #define   TBCTL_FREEZE		0x0000000000000000ull /* Freeze all tbs */
772 #define   TBCTL_RESTART		0x0000000100000000ull /* Restart all tbs */
773 #define   TBCTL_UPDATE_UPPER	0x0000000200000000ull /* Set upper 32 bits */
774 #define   TBCTL_UPDATE_LOWER	0x0000000300000000ull /* Set lower 32 bits */
775 
776 #ifndef SPRN_SVR
777 #define SPRN_SVR	0x11E	/* System Version Register */
778 #endif
779 #define SPRN_THRM1	0x3FC		/* Thermal Management Register 1 */
780 /* these bits were defined in inverted endian sense originally, ugh, confusing */
781 #define THRM1_TIN	(1 << 31)
782 #define THRM1_TIV	(1 << 30)
783 #define THRM1_THRES(x)	((x&0x7f)<<23)
784 #define THRM3_SITV(x)	((x&0x3fff)<<1)
785 #define THRM1_TID	(1<<2)
786 #define THRM1_TIE	(1<<1)
787 #define THRM1_V		(1<<0)
788 #define SPRN_THRM2	0x3FD		/* Thermal Management Register 2 */
789 #define SPRN_THRM3	0x3FE		/* Thermal Management Register 3 */
790 #define THRM3_E		(1<<0)
791 #define SPRN_TLBMISS	0x3D4		/* 980 7450 TLB Miss Register */
792 #define SPRN_UMMCR0	0x3A8	/* User Monitor Mode Control Register 0 */
793 #define SPRN_UMMCR1	0x3AC	/* User Monitor Mode Control Register 0 */
794 #define SPRN_UPMC1	0x3A9	/* User Performance Counter Register 1 */
795 #define SPRN_UPMC2	0x3AA	/* User Performance Counter Register 2 */
796 #define SPRN_UPMC3	0x3AD	/* User Performance Counter Register 3 */
797 #define SPRN_UPMC4	0x3AE	/* User Performance Counter Register 4 */
798 #define SPRN_USIA	0x3AB	/* User Sampled Instruction Address Register */
799 #define SPRN_VRSAVE	0x100	/* Vector Register Save Register */
800 #define SPRN_XER	0x001	/* Fixed Point Exception Register */
801 
802 #define SPRN_MMCR0_GEKKO 0x3B8 /* Gekko Monitor Mode Control Register 0 */
803 #define SPRN_MMCR1_GEKKO 0x3BC /* Gekko Monitor Mode Control Register 1 */
804 #define SPRN_PMC1_GEKKO  0x3B9 /* Gekko Performance Monitor Control 1 */
805 #define SPRN_PMC2_GEKKO  0x3BA /* Gekko Performance Monitor Control 2 */
806 #define SPRN_PMC3_GEKKO  0x3BD /* Gekko Performance Monitor Control 3 */
807 #define SPRN_PMC4_GEKKO  0x3BE /* Gekko Performance Monitor Control 4 */
808 #define SPRN_WPAR_GEKKO  0x399 /* Gekko Write Pipe Address Register */
809 
810 #define SPRN_SCOMC	0x114	/* SCOM Access Control */
811 #define SPRN_SCOMD	0x115	/* SCOM Access DATA */
812 
813 /* Performance monitor SPRs */
814 #ifdef CONFIG_PPC64
815 #define SPRN_MMCR0	795
816 #define   MMCR0_FC	0x80000000UL /* freeze counters */
817 #define   MMCR0_FCS	0x40000000UL /* freeze in supervisor state */
818 #define   MMCR0_KERNEL_DISABLE MMCR0_FCS
819 #define   MMCR0_FCP	0x20000000UL /* freeze in problem state */
820 #define   MMCR0_PROBLEM_DISABLE MMCR0_FCP
821 #define   MMCR0_FCM1	0x10000000UL /* freeze counters while MSR mark = 1 */
822 #define   MMCR0_FCM0	0x08000000UL /* freeze counters while MSR mark = 0 */
823 #define   MMCR0_PMXE	ASM_CONST(0x04000000) /* perf mon exception enable */
824 #define   MMCR0_FCECE	ASM_CONST(0x02000000) /* freeze ctrs on enabled cond or event */
825 #define   MMCR0_TBEE	0x00400000UL /* time base exception enable */
826 #define   MMCR0_BHRBA	0x00200000UL /* BHRB Access allowed in userspace */
827 #define   MMCR0_EBE	0x00100000UL /* Event based branch enable */
828 #define   MMCR0_PMCC	0x000c0000UL /* PMC control */
829 #define   MMCR0_PMCC_U6	0x00080000UL /* PMC1-6 are R/W by user (PR) */
830 #define   MMCR0_PMC1CE	0x00008000UL /* PMC1 count enable*/
831 #define   MMCR0_PMCjCE	ASM_CONST(0x00004000) /* PMCj count enable*/
832 #define   MMCR0_TRIGGER	0x00002000UL /* TRIGGER enable */
833 #define   MMCR0_PMAO_SYNC ASM_CONST(0x00000800) /* PMU intr is synchronous */
834 #define   MMCR0_C56RUN	ASM_CONST(0x00000100) /* PMC5/6 count when RUN=0 */
835 /* performance monitor alert has occurred, set to 0 after handling exception */
836 #define   MMCR0_PMAO	ASM_CONST(0x00000080)
837 #define   MMCR0_SHRFC	0x00000040UL /* SHRre freeze conditions between threads */
838 #define   MMCR0_FC56	0x00000010UL /* freeze counters 5 and 6 */
839 #define   MMCR0_FCTI	0x00000008UL /* freeze counters in tags inactive mode */
840 #define   MMCR0_FCTA	0x00000004UL /* freeze counters in tags active mode */
841 #define   MMCR0_FCWAIT	0x00000002UL /* freeze counter in WAIT state */
842 #define   MMCR0_FCHV	0x00000001UL /* freeze conditions in hypervisor mode */
843 #define SPRN_MMCR1	798
844 #define SPRN_MMCR2	785
845 #define SPRN_UMMCR2	769
846 #define SPRN_MMCRA	0x312
847 #define   MMCRA_SDSYNC	0x80000000UL /* SDAR synced with SIAR */
848 #define   MMCRA_SDAR_DCACHE_MISS 0x40000000UL
849 #define   MMCRA_SDAR_ERAT_MISS   0x20000000UL
850 #define   MMCRA_SIHV	0x10000000UL /* state of MSR HV when SIAR set */
851 #define   MMCRA_SIPR	0x08000000UL /* state of MSR PR when SIAR set */
852 #define   MMCRA_SLOT	0x07000000UL /* SLOT bits (37-39) */
853 #define   MMCRA_SLOT_SHIFT	24
854 #define   MMCRA_SAMPLE_ENABLE 0x00000001UL /* enable sampling */
855 #define   POWER6_MMCRA_SDSYNC 0x0000080000000000ULL	/* SDAR/SIAR synced */
856 #define   POWER6_MMCRA_SIHV   0x0000040000000000ULL
857 #define   POWER6_MMCRA_SIPR   0x0000020000000000ULL
858 #define   POWER6_MMCRA_THRM	0x00000020UL
859 #define   POWER6_MMCRA_OTHER	0x0000000EUL
860 
861 #define   POWER7P_MMCRA_SIAR_VALID 0x10000000	/* P7+ SIAR contents valid */
862 #define   POWER7P_MMCRA_SDAR_VALID 0x08000000	/* P7+ SDAR contents valid */
863 
864 #define SPRN_MMCRH	316	/* Hypervisor monitor mode control register */
865 #define SPRN_MMCRS	894	/* Supervisor monitor mode control register */
866 #define SPRN_MMCRC	851	/* Core monitor mode control register */
867 #define SPRN_EBBHR	804	/* Event based branch handler register */
868 #define SPRN_EBBRR	805	/* Event based branch return register */
869 #define SPRN_BESCR	806	/* Branch event status and control register */
870 #define   BESCR_GE	0x8000000000000000ULL /* Global Enable */
871 #define SPRN_WORT	895	/* Workload optimization register - thread */
872 #define SPRN_WORC	863	/* Workload optimization register - core */
873 
874 #define SPRN_PMC1	787
875 #define SPRN_PMC2	788
876 #define SPRN_PMC3	789
877 #define SPRN_PMC4	790
878 #define SPRN_PMC5	791
879 #define SPRN_PMC6	792
880 #define SPRN_PMC7	793
881 #define SPRN_PMC8	794
882 #define SPRN_SIER	784
883 #define   SIER_SIPR		0x2000000	/* Sampled MSR_PR */
884 #define   SIER_SIHV		0x1000000	/* Sampled MSR_HV */
885 #define   SIER_SIAR_VALID	0x0400000	/* SIAR contents valid */
886 #define   SIER_SDAR_VALID	0x0200000	/* SDAR contents valid */
887 #define SPRN_SIAR	796
888 #define SPRN_SDAR	797
889 #define SPRN_TACR	888
890 #define SPRN_TCSCR	889
891 #define SPRN_CSIGR	890
892 #define SPRN_SPMC1	892
893 #define SPRN_SPMC2	893
894 
895 /* When EBB is enabled, some of MMCR0/MMCR2/SIER are user accessible */
896 #define MMCR0_USER_MASK	(MMCR0_FC | MMCR0_PMXE | MMCR0_PMAO)
897 #define MMCR2_USER_MASK	0x4020100804020000UL /* (FC1P|FC2P|FC3P|FC4P|FC5P|FC6P) */
898 #define SIER_USER_MASK	0x7fffffUL
899 
900 #define SPRN_PA6T_MMCR0 795
901 #define   PA6T_MMCR0_EN0	0x0000000000000001UL
902 #define   PA6T_MMCR0_EN1	0x0000000000000002UL
903 #define   PA6T_MMCR0_EN2	0x0000000000000004UL
904 #define   PA6T_MMCR0_EN3	0x0000000000000008UL
905 #define   PA6T_MMCR0_EN4	0x0000000000000010UL
906 #define   PA6T_MMCR0_EN5	0x0000000000000020UL
907 #define   PA6T_MMCR0_SUPEN	0x0000000000000040UL
908 #define   PA6T_MMCR0_PREN	0x0000000000000080UL
909 #define   PA6T_MMCR0_HYPEN	0x0000000000000100UL
910 #define   PA6T_MMCR0_FCM0	0x0000000000000200UL
911 #define   PA6T_MMCR0_FCM1	0x0000000000000400UL
912 #define   PA6T_MMCR0_INTGEN	0x0000000000000800UL
913 #define   PA6T_MMCR0_INTEN0	0x0000000000001000UL
914 #define   PA6T_MMCR0_INTEN1	0x0000000000002000UL
915 #define   PA6T_MMCR0_INTEN2	0x0000000000004000UL
916 #define   PA6T_MMCR0_INTEN3	0x0000000000008000UL
917 #define   PA6T_MMCR0_INTEN4	0x0000000000010000UL
918 #define   PA6T_MMCR0_INTEN5	0x0000000000020000UL
919 #define   PA6T_MMCR0_DISCNT	0x0000000000040000UL
920 #define   PA6T_MMCR0_UOP	0x0000000000080000UL
921 #define   PA6T_MMCR0_TRG	0x0000000000100000UL
922 #define   PA6T_MMCR0_TRGEN	0x0000000000200000UL
923 #define   PA6T_MMCR0_TRGREG	0x0000000001600000UL
924 #define   PA6T_MMCR0_SIARLOG	0x0000000002000000UL
925 #define   PA6T_MMCR0_SDARLOG	0x0000000004000000UL
926 #define   PA6T_MMCR0_PROEN	0x0000000008000000UL
927 #define   PA6T_MMCR0_PROLOG	0x0000000010000000UL
928 #define   PA6T_MMCR0_DAMEN2	0x0000000020000000UL
929 #define   PA6T_MMCR0_DAMEN3	0x0000000040000000UL
930 #define   PA6T_MMCR0_DAMEN4	0x0000000080000000UL
931 #define   PA6T_MMCR0_DAMEN5	0x0000000100000000UL
932 #define   PA6T_MMCR0_DAMSEL2	0x0000000200000000UL
933 #define   PA6T_MMCR0_DAMSEL3	0x0000000400000000UL
934 #define   PA6T_MMCR0_DAMSEL4	0x0000000800000000UL
935 #define   PA6T_MMCR0_DAMSEL5	0x0000001000000000UL
936 #define   PA6T_MMCR0_HANDDIS	0x0000002000000000UL
937 #define   PA6T_MMCR0_PCTEN	0x0000004000000000UL
938 #define   PA6T_MMCR0_SOCEN	0x0000008000000000UL
939 #define   PA6T_MMCR0_SOCMOD	0x0000010000000000UL
940 
941 #define SPRN_PA6T_MMCR1 798
942 #define   PA6T_MMCR1_ES2	0x00000000000000ffUL
943 #define   PA6T_MMCR1_ES3	0x000000000000ff00UL
944 #define   PA6T_MMCR1_ES4	0x0000000000ff0000UL
945 #define   PA6T_MMCR1_ES5	0x00000000ff000000UL
946 
947 #define SPRN_PA6T_UPMC0 771	/* User PerfMon Counter 0 */
948 #define SPRN_PA6T_UPMC1 772	/* ... */
949 #define SPRN_PA6T_UPMC2 773
950 #define SPRN_PA6T_UPMC3 774
951 #define SPRN_PA6T_UPMC4 775
952 #define SPRN_PA6T_UPMC5 776
953 #define SPRN_PA6T_UMMCR0 779	/* User Monitor Mode Control Register 0 */
954 #define SPRN_PA6T_SIAR	780	/* Sampled Instruction Address */
955 #define SPRN_PA6T_UMMCR1 782	/* User Monitor Mode Control Register 1 */
956 #define SPRN_PA6T_SIER	785	/* Sampled Instruction Event Register */
957 #define SPRN_PA6T_PMC0	787
958 #define SPRN_PA6T_PMC1	788
959 #define SPRN_PA6T_PMC2	789
960 #define SPRN_PA6T_PMC3	790
961 #define SPRN_PA6T_PMC4	791
962 #define SPRN_PA6T_PMC5	792
963 #define SPRN_PA6T_TSR0	793	/* Timestamp Register 0 */
964 #define SPRN_PA6T_TSR1	794	/* Timestamp Register 1 */
965 #define SPRN_PA6T_TSR2	799	/* Timestamp Register 2 */
966 #define SPRN_PA6T_TSR3	784	/* Timestamp Register 3 */
967 
968 #define SPRN_PA6T_IER	981	/* Icache Error Register */
969 #define SPRN_PA6T_DER	982	/* Dcache Error Register */
970 #define SPRN_PA6T_BER	862	/* BIU Error Address Register */
971 #define SPRN_PA6T_MER	849	/* MMU Error Register */
972 
973 #define SPRN_PA6T_IMA0	880	/* Instruction Match Array 0 */
974 #define SPRN_PA6T_IMA1	881	/* ... */
975 #define SPRN_PA6T_IMA2	882
976 #define SPRN_PA6T_IMA3	883
977 #define SPRN_PA6T_IMA4	884
978 #define SPRN_PA6T_IMA5	885
979 #define SPRN_PA6T_IMA6	886
980 #define SPRN_PA6T_IMA7	887
981 #define SPRN_PA6T_IMA8	888
982 #define SPRN_PA6T_IMA9	889
983 #define SPRN_PA6T_BTCR	978	/* Breakpoint and Tagging Control Register */
984 #define SPRN_PA6T_IMAAT	979	/* Instruction Match Array Action Table */
985 #define SPRN_PA6T_PCCR	1019	/* Power Counter Control Register */
986 #define SPRN_BKMK	1020	/* Cell Bookmark Register */
987 #define SPRN_PA6T_RPCCR	1021	/* Retire PC Trace Control Register */
988 
989 
990 #else /* 32-bit */
991 #define SPRN_MMCR0	952	/* Monitor Mode Control Register 0 */
992 #define   MMCR0_FC	0x80000000UL /* freeze counters */
993 #define   MMCR0_FCS	0x40000000UL /* freeze in supervisor state */
994 #define   MMCR0_FCP	0x20000000UL /* freeze in problem state */
995 #define   MMCR0_FCM1	0x10000000UL /* freeze counters while MSR mark = 1 */
996 #define   MMCR0_FCM0	0x08000000UL /* freeze counters while MSR mark = 0 */
997 #define   MMCR0_PMXE	0x04000000UL /* performance monitor exception enable */
998 #define   MMCR0_FCECE	0x02000000UL /* freeze ctrs on enabled cond or event */
999 #define   MMCR0_TBEE	0x00400000UL /* time base exception enable */
1000 #define   MMCR0_PMC1CE	0x00008000UL /* PMC1 count enable*/
1001 #define   MMCR0_PMCnCE	0x00004000UL /* count enable for all but PMC 1*/
1002 #define   MMCR0_TRIGGER	0x00002000UL /* TRIGGER enable */
1003 #define   MMCR0_PMC1SEL	0x00001fc0UL /* PMC 1 Event */
1004 #define   MMCR0_PMC2SEL	0x0000003fUL /* PMC 2 Event */
1005 
1006 #define SPRN_MMCR1	956
1007 #define   MMCR1_PMC3SEL	0xf8000000UL /* PMC 3 Event */
1008 #define   MMCR1_PMC4SEL	0x07c00000UL /* PMC 4 Event */
1009 #define   MMCR1_PMC5SEL	0x003e0000UL /* PMC 5 Event */
1010 #define   MMCR1_PMC6SEL 0x0001f800UL /* PMC 6 Event */
1011 #define SPRN_MMCR2	944
1012 #define SPRN_PMC1	953	/* Performance Counter Register 1 */
1013 #define SPRN_PMC2	954	/* Performance Counter Register 2 */
1014 #define SPRN_PMC3	957	/* Performance Counter Register 3 */
1015 #define SPRN_PMC4	958	/* Performance Counter Register 4 */
1016 #define SPRN_PMC5	945	/* Performance Counter Register 5 */
1017 #define SPRN_PMC6	946	/* Performance Counter Register 6 */
1018 
1019 #define SPRN_SIAR	955	/* Sampled Instruction Address Register */
1020 
1021 /* Bit definitions for MMCR0 and PMC1 / PMC2. */
1022 #define MMCR0_PMC1_CYCLES	(1 << 7)
1023 #define MMCR0_PMC1_ICACHEMISS	(5 << 7)
1024 #define MMCR0_PMC1_DTLB		(6 << 7)
1025 #define MMCR0_PMC2_DCACHEMISS	0x6
1026 #define MMCR0_PMC2_CYCLES	0x1
1027 #define MMCR0_PMC2_ITLB		0x7
1028 #define MMCR0_PMC2_LOADMISSTIME	0x5
1029 #endif
1030 
1031 /*
1032  * SPRG usage:
1033  *
1034  * All 64-bit:
1035  *	- SPRG1 stores PACA pointer except 64-bit server in
1036  *        HV mode in which case it is HSPRG0
1037  *
1038  * 64-bit server:
1039  *	- SPRG0 scratch for TM recheckpoint/reclaim (reserved for HV on Power4)
1040  *	- SPRG2 scratch for exception vectors
1041  *	- SPRG3 CPU and NUMA node for VDSO getcpu (user visible)
1042  *      - HSPRG0 stores PACA in HV mode
1043  *      - HSPRG1 scratch for "HV" exceptions
1044  *
1045  * 64-bit embedded
1046  *	- SPRG0 generic exception scratch
1047  *	- SPRG2 TLB exception stack
1048  *	- SPRG3 critical exception scratch (user visible, sorry!)
1049  *	- SPRG4 unused (user visible)
1050  *	- SPRG6 TLB miss scratch (user visible, sorry !)
1051  *	- SPRG7 CPU and NUMA node for VDSO getcpu (user visible)
1052  *	- SPRG8 machine check exception scratch
1053  *	- SPRG9 debug exception scratch
1054  *
1055  * All 32-bit:
1056  *	- SPRG3 current thread_info pointer
1057  *        (virtual on BookE, physical on others)
1058  *
1059  * 32-bit classic:
1060  *	- SPRG0 scratch for exception vectors
1061  *	- SPRG1 scratch for exception vectors
1062  *	- SPRG2 indicator that we are in RTAS
1063  *	- SPRG4 (603 only) pseudo TLB LRU data
1064  *
1065  * 32-bit 40x:
1066  *	- SPRG0 scratch for exception vectors
1067  *	- SPRG1 scratch for exception vectors
1068  *	- SPRG2 scratch for exception vectors
1069  *	- SPRG4 scratch for exception vectors (not 403)
1070  *	- SPRG5 scratch for exception vectors (not 403)
1071  *	- SPRG6 scratch for exception vectors (not 403)
1072  *	- SPRG7 scratch for exception vectors (not 403)
1073  *
1074  * 32-bit 440 and FSL BookE:
1075  *	- SPRG0 scratch for exception vectors
1076  *	- SPRG1 scratch for exception vectors (*)
1077  *	- SPRG2 scratch for crit interrupts handler
1078  *	- SPRG4 scratch for exception vectors
1079  *	- SPRG5 scratch for exception vectors
1080  *	- SPRG6 scratch for machine check handler
1081  *	- SPRG7 scratch for exception vectors
1082  *	- SPRG9 scratch for debug vectors (e500 only)
1083  *
1084  *      Additionally, BookE separates "read" and "write"
1085  *      of those registers. That allows to use the userspace
1086  *      readable variant for reads, which can avoid a fault
1087  *      with KVM type virtualization.
1088  *
1089  * 32-bit 8xx:
1090  *	- SPRG0 scratch for exception vectors
1091  *	- SPRG1 scratch for exception vectors
1092  *	- SPRG2 scratch for exception vectors
1093  *
1094  */
1095 #ifdef CONFIG_PPC64
1096 #define SPRN_SPRG_PACA 		SPRN_SPRG1
1097 #else
1098 #define SPRN_SPRG_THREAD 	SPRN_SPRG3
1099 #endif
1100 
1101 #ifdef CONFIG_PPC_BOOK3S_64
1102 #define SPRN_SPRG_SCRATCH0	SPRN_SPRG2
1103 #define SPRN_SPRG_HPACA		SPRN_HSPRG0
1104 #define SPRN_SPRG_HSCRATCH0	SPRN_HSPRG1
1105 #define SPRN_SPRG_VDSO_READ	SPRN_USPRG3
1106 #define SPRN_SPRG_VDSO_WRITE	SPRN_SPRG3
1107 
1108 #define GET_PACA(rX)					\
1109 	BEGIN_FTR_SECTION_NESTED(66);			\
1110 	mfspr	rX,SPRN_SPRG_PACA;			\
1111 	FTR_SECTION_ELSE_NESTED(66);			\
1112 	mfspr	rX,SPRN_SPRG_HPACA;			\
1113 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_HVMODE, 66)
1114 
1115 #define SET_PACA(rX)					\
1116 	BEGIN_FTR_SECTION_NESTED(66);			\
1117 	mtspr	SPRN_SPRG_PACA,rX;			\
1118 	FTR_SECTION_ELSE_NESTED(66);			\
1119 	mtspr	SPRN_SPRG_HPACA,rX;			\
1120 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_HVMODE, 66)
1121 
1122 #define GET_SCRATCH0(rX)				\
1123 	BEGIN_FTR_SECTION_NESTED(66);			\
1124 	mfspr	rX,SPRN_SPRG_SCRATCH0;			\
1125 	FTR_SECTION_ELSE_NESTED(66);			\
1126 	mfspr	rX,SPRN_SPRG_HSCRATCH0;			\
1127 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_HVMODE, 66)
1128 
1129 #define SET_SCRATCH0(rX)				\
1130 	BEGIN_FTR_SECTION_NESTED(66);			\
1131 	mtspr	SPRN_SPRG_SCRATCH0,rX;			\
1132 	FTR_SECTION_ELSE_NESTED(66);			\
1133 	mtspr	SPRN_SPRG_HSCRATCH0,rX;			\
1134 	ALT_FTR_SECTION_END_NESTED_IFCLR(CPU_FTR_HVMODE, 66)
1135 
1136 #else /* CONFIG_PPC_BOOK3S_64 */
1137 #define GET_SCRATCH0(rX)	mfspr	rX,SPRN_SPRG_SCRATCH0
1138 #define SET_SCRATCH0(rX)	mtspr	SPRN_SPRG_SCRATCH0,rX
1139 
1140 #endif
1141 
1142 #ifdef CONFIG_PPC_BOOK3E_64
1143 #define SPRN_SPRG_MC_SCRATCH	SPRN_SPRG8
1144 #define SPRN_SPRG_CRIT_SCRATCH	SPRN_SPRG3
1145 #define SPRN_SPRG_DBG_SCRATCH	SPRN_SPRG9
1146 #define SPRN_SPRG_TLB_EXFRAME	SPRN_SPRG2
1147 #define SPRN_SPRG_TLB_SCRATCH	SPRN_SPRG6
1148 #define SPRN_SPRG_GEN_SCRATCH	SPRN_SPRG0
1149 #define SPRN_SPRG_GDBELL_SCRATCH SPRN_SPRG_GEN_SCRATCH
1150 #define SPRN_SPRG_VDSO_READ	SPRN_USPRG7
1151 #define SPRN_SPRG_VDSO_WRITE	SPRN_SPRG7
1152 
1153 #define SET_PACA(rX)	mtspr	SPRN_SPRG_PACA,rX
1154 #define GET_PACA(rX)	mfspr	rX,SPRN_SPRG_PACA
1155 
1156 #endif
1157 
1158 #ifdef CONFIG_PPC_BOOK3S_32
1159 #define SPRN_SPRG_SCRATCH0	SPRN_SPRG0
1160 #define SPRN_SPRG_SCRATCH1	SPRN_SPRG1
1161 #define SPRN_SPRG_RTAS		SPRN_SPRG2
1162 #define SPRN_SPRG_603_LRU	SPRN_SPRG4
1163 #endif
1164 
1165 #ifdef CONFIG_40x
1166 #define SPRN_SPRG_SCRATCH0	SPRN_SPRG0
1167 #define SPRN_SPRG_SCRATCH1	SPRN_SPRG1
1168 #define SPRN_SPRG_SCRATCH2	SPRN_SPRG2
1169 #define SPRN_SPRG_SCRATCH3	SPRN_SPRG4
1170 #define SPRN_SPRG_SCRATCH4	SPRN_SPRG5
1171 #define SPRN_SPRG_SCRATCH5	SPRN_SPRG6
1172 #define SPRN_SPRG_SCRATCH6	SPRN_SPRG7
1173 #endif
1174 
1175 #ifdef CONFIG_BOOKE
1176 #define SPRN_SPRG_RSCRATCH0	SPRN_SPRG0
1177 #define SPRN_SPRG_WSCRATCH0	SPRN_SPRG0
1178 #define SPRN_SPRG_RSCRATCH1	SPRN_SPRG1
1179 #define SPRN_SPRG_WSCRATCH1	SPRN_SPRG1
1180 #define SPRN_SPRG_RSCRATCH_CRIT	SPRN_SPRG2
1181 #define SPRN_SPRG_WSCRATCH_CRIT	SPRN_SPRG2
1182 #define SPRN_SPRG_RSCRATCH2	SPRN_SPRG4R
1183 #define SPRN_SPRG_WSCRATCH2	SPRN_SPRG4W
1184 #define SPRN_SPRG_RSCRATCH3	SPRN_SPRG5R
1185 #define SPRN_SPRG_WSCRATCH3	SPRN_SPRG5W
1186 #define SPRN_SPRG_RSCRATCH_MC	SPRN_SPRG1
1187 #define SPRN_SPRG_WSCRATCH_MC	SPRN_SPRG1
1188 #define SPRN_SPRG_RSCRATCH4	SPRN_SPRG7R
1189 #define SPRN_SPRG_WSCRATCH4	SPRN_SPRG7W
1190 #ifdef CONFIG_E200
1191 #define SPRN_SPRG_RSCRATCH_DBG	SPRN_SPRG6R
1192 #define SPRN_SPRG_WSCRATCH_DBG	SPRN_SPRG6W
1193 #else
1194 #define SPRN_SPRG_RSCRATCH_DBG	SPRN_SPRG9
1195 #define SPRN_SPRG_WSCRATCH_DBG	SPRN_SPRG9
1196 #endif
1197 #endif
1198 
1199 #ifdef CONFIG_PPC_8xx
1200 #define SPRN_SPRG_SCRATCH0	SPRN_SPRG0
1201 #define SPRN_SPRG_SCRATCH1	SPRN_SPRG1
1202 #define SPRN_SPRG_SCRATCH2	SPRN_SPRG2
1203 #endif
1204 
1205 
1206 
1207 /*
1208  * An mtfsf instruction with the L bit set. On CPUs that support this a
1209  * full 64bits of FPSCR is restored and on other CPUs the L bit is ignored.
1210  *
1211  * Until binutils gets the new form of mtfsf, hardwire the instruction.
1212  */
1213 #ifdef CONFIG_PPC64
1214 #define MTFSF_L(REG) \
1215 	.long (0xfc00058e | ((0xff) << 17) | ((REG) << 11) | (1 << 25))
1216 #else
1217 #define MTFSF_L(REG)	mtfsf	0xff, (REG)
1218 #endif
1219 
1220 /* Processor Version Register (PVR) field extraction */
1221 
1222 #define PVR_VER(pvr)	(((pvr) >>  16) & 0xFFFF)	/* Version field */
1223 #define PVR_REV(pvr)	(((pvr) >>   0) & 0xFFFF)	/* Revison field */
1224 
1225 #define pvr_version_is(pvr)	(PVR_VER(mfspr(SPRN_PVR)) == (pvr))
1226 
1227 /*
1228  * IBM has further subdivided the standard PowerPC 16-bit version and
1229  * revision subfields of the PVR for the PowerPC 403s into the following:
1230  */
1231 
1232 #define PVR_FAM(pvr)	(((pvr) >> 20) & 0xFFF)	/* Family field */
1233 #define PVR_MEM(pvr)	(((pvr) >> 16) & 0xF)	/* Member field */
1234 #define PVR_CORE(pvr)	(((pvr) >> 12) & 0xF)	/* Core field */
1235 #define PVR_CFG(pvr)	(((pvr) >>  8) & 0xF)	/* Configuration field */
1236 #define PVR_MAJ(pvr)	(((pvr) >>  4) & 0xF)	/* Major revision field */
1237 #define PVR_MIN(pvr)	(((pvr) >>  0) & 0xF)	/* Minor revision field */
1238 
1239 /* Processor Version Numbers */
1240 
1241 #define PVR_403GA	0x00200000
1242 #define PVR_403GB	0x00200100
1243 #define PVR_403GC	0x00200200
1244 #define PVR_403GCX	0x00201400
1245 #define PVR_405GP	0x40110000
1246 #define PVR_476		0x11a52000
1247 #define PVR_476FPE	0x7ff50000
1248 #define PVR_STB03XXX	0x40310000
1249 #define PVR_NP405H	0x41410000
1250 #define PVR_NP405L	0x41610000
1251 #define PVR_601		0x00010000
1252 #define PVR_602		0x00050000
1253 #define PVR_603		0x00030000
1254 #define PVR_603e	0x00060000
1255 #define PVR_603ev	0x00070000
1256 #define PVR_603r	0x00071000
1257 #define PVR_604		0x00040000
1258 #define PVR_604e	0x00090000
1259 #define PVR_604r	0x000A0000
1260 #define PVR_620		0x00140000
1261 #define PVR_740		0x00080000
1262 #define PVR_750		PVR_740
1263 #define PVR_740P	0x10080000
1264 #define PVR_750P	PVR_740P
1265 #define PVR_7400	0x000C0000
1266 #define PVR_7410	0x800C0000
1267 #define PVR_7450	0x80000000
1268 #define PVR_8540	0x80200000
1269 #define PVR_8560	0x80200000
1270 #define PVR_VER_E500V1	0x8020
1271 #define PVR_VER_E500V2	0x8021
1272 #define PVR_VER_E500MC	0x8023
1273 #define PVR_VER_E5500	0x8024
1274 #define PVR_VER_E6500	0x8040
1275 
1276 /*
1277  * For the 8xx processors, all of them report the same PVR family for
1278  * the PowerPC core. The various versions of these processors must be
1279  * differentiated by the version number in the Communication Processor
1280  * Module (CPM).
1281  */
1282 #define PVR_8xx		0x00500000
1283 
1284 #define PVR_8240	0x00810100
1285 #define PVR_8245	0x80811014
1286 #define PVR_8260	PVR_8240
1287 
1288 /* 476 Simulator seems to currently have the PVR of the 602... */
1289 #define PVR_476_ISS	0x00052000
1290 
1291 /* 64-bit processors */
1292 #define PVR_NORTHSTAR	0x0033
1293 #define PVR_PULSAR	0x0034
1294 #define PVR_POWER4	0x0035
1295 #define PVR_ICESTAR	0x0036
1296 #define PVR_SSTAR	0x0037
1297 #define PVR_POWER4p	0x0038
1298 #define PVR_970		0x0039
1299 #define PVR_POWER5	0x003A
1300 #define PVR_POWER5p	0x003B
1301 #define PVR_970FX	0x003C
1302 #define PVR_POWER6	0x003E
1303 #define PVR_POWER7	0x003F
1304 #define PVR_630		0x0040
1305 #define PVR_630p	0x0041
1306 #define PVR_970MP	0x0044
1307 #define PVR_970GX	0x0045
1308 #define PVR_POWER7p	0x004A
1309 #define PVR_POWER8E	0x004B
1310 #define PVR_POWER8NVL	0x004C
1311 #define PVR_POWER8	0x004D
1312 #define PVR_POWER9	0x004E
1313 #define PVR_BE		0x0070
1314 #define PVR_PA6T	0x0090
1315 
1316 /* "Logical" PVR values defined in PAPR, representing architecture levels */
1317 #define PVR_ARCH_204	0x0f000001
1318 #define PVR_ARCH_205	0x0f000002
1319 #define PVR_ARCH_206	0x0f000003
1320 #define PVR_ARCH_206p	0x0f100003
1321 #define PVR_ARCH_207	0x0f000004
1322 #define PVR_ARCH_300	0x0f000005
1323 
1324 /* Macros for setting and retrieving special purpose registers */
1325 #ifndef __ASSEMBLY__
1326 #define mfmsr()		({unsigned long rval; \
1327 			asm volatile("mfmsr %0" : "=r" (rval) : \
1328 						: "memory"); rval;})
1329 #ifdef CONFIG_PPC_BOOK3S_64
1330 #define __mtmsrd(v, l)	asm volatile("mtmsrd %0," __stringify(l) \
1331 				     : : "r" (v) : "memory")
1332 #define mtmsr(v)	__mtmsrd((v), 0)
1333 #define __MTMSR		"mtmsrd"
1334 #else
1335 #define mtmsr(v)	asm volatile("mtmsr %0" : \
1336 				     : "r" ((unsigned long)(v)) \
1337 				     : "memory")
1338 #define __MTMSR		"mtmsr"
1339 #endif
1340 
mtmsr_isync(unsigned long val)1341 static inline void mtmsr_isync(unsigned long val)
1342 {
1343 	asm volatile(__MTMSR " %0; " ASM_FTR_IFCLR("isync", "nop", %1) : :
1344 			"r" (val), "i" (CPU_FTR_ARCH_206) : "memory");
1345 }
1346 
1347 #define mfspr(rn)	({unsigned long rval; \
1348 			asm volatile("mfspr %0," __stringify(rn) \
1349 				: "=r" (rval)); rval;})
1350 #ifndef mtspr
1351 #define mtspr(rn, v)	asm volatile("mtspr " __stringify(rn) ",%0" : \
1352 				     : "r" ((unsigned long)(v)) \
1353 				     : "memory")
1354 #endif
1355 #define wrtspr(rn)	asm volatile("mtspr " __stringify(rn) ",0" : \
1356 				     : : "memory")
1357 
1358 extern unsigned long msr_check_and_set(unsigned long bits);
1359 extern bool strict_msr_control;
1360 extern void __msr_check_and_clear(unsigned long bits);
msr_check_and_clear(unsigned long bits)1361 static inline void msr_check_and_clear(unsigned long bits)
1362 {
1363 	if (strict_msr_control)
1364 		__msr_check_and_clear(bits);
1365 }
1366 
1367 #ifdef __powerpc64__
1368 #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
1369 #define mftb()		({unsigned long rval;				\
1370 			asm volatile(					\
1371 				"90:	mfspr %0, %2;\n"		\
1372 				"97:	cmpwi %0,0;\n"			\
1373 				"	beq- 90b;\n"			\
1374 				"99:\n"					\
1375 				".section __ftr_fixup,\"a\"\n"		\
1376 				".align 3\n"				\
1377 				"98:\n"					\
1378 				"	.8byte %1\n"			\
1379 				"	.8byte %1\n"			\
1380 				"	.8byte 97b-98b\n"		\
1381 				"	.8byte 99b-98b\n"		\
1382 				"	.8byte 0\n"			\
1383 				"	.8byte 0\n"			\
1384 				".previous"				\
1385 			: "=r" (rval) \
1386 			: "i" (CPU_FTR_CELL_TB_BUG), "i" (SPRN_TBRL) : "cr0"); \
1387 			rval;})
1388 #else
1389 #define mftb()		({unsigned long rval;	\
1390 			asm volatile("mfspr %0, %1" : \
1391 				     "=r" (rval) : "i" (SPRN_TBRL)); rval;})
1392 #endif /* !CONFIG_PPC_CELL */
1393 
1394 #else /* __powerpc64__ */
1395 
1396 #if defined(CONFIG_PPC_8xx)
1397 #define mftbl()		({unsigned long rval;	\
1398 			asm volatile("mftbl %0" : "=r" (rval)); rval;})
1399 #define mftbu()		({unsigned long rval;	\
1400 			asm volatile("mftbu %0" : "=r" (rval)); rval;})
1401 #else
1402 #define mftbl()		({unsigned long rval;	\
1403 			asm volatile("mfspr %0, %1" : "=r" (rval) : \
1404 				"i" (SPRN_TBRL)); rval;})
1405 #define mftbu()		({unsigned long rval;	\
1406 			asm volatile("mfspr %0, %1" : "=r" (rval) : \
1407 				"i" (SPRN_TBRU)); rval;})
1408 #endif
1409 #define mftb()		mftbl()
1410 #endif /* !__powerpc64__ */
1411 
1412 #define mttbl(v)	asm volatile("mttbl %0":: "r"(v))
1413 #define mttbu(v)	asm volatile("mttbu %0":: "r"(v))
1414 
1415 #ifdef CONFIG_PPC32
1416 #define mfsrin(v)	({unsigned int rval; \
1417 			asm volatile("mfsrin %0,%1" : "=r" (rval) : "r" (v)); \
1418 					rval;})
1419 #endif
1420 
1421 #define proc_trap()	asm volatile("trap")
1422 
1423 extern unsigned long current_stack_pointer(void);
1424 
1425 extern unsigned long scom970_read(unsigned int address);
1426 extern void scom970_write(unsigned int address, unsigned long value);
1427 
1428 struct pt_regs;
1429 
1430 extern void ppc_save_regs(struct pt_regs *regs);
1431 
update_power8_hid0(unsigned long hid0)1432 static inline void update_power8_hid0(unsigned long hid0)
1433 {
1434 	/*
1435 	 *  The HID0 update on Power8 should at the very least be
1436 	 *  preceded by a a SYNC instruction followed by an ISYNC
1437 	 *  instruction
1438 	 */
1439 	asm volatile("sync; mtspr %0,%1; isync":: "i"(SPRN_HID0), "r"(hid0));
1440 }
1441 #endif /* __ASSEMBLY__ */
1442 #endif /* __KERNEL__ */
1443 #endif /* _ASM_POWERPC_REG_H */
1444