1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_POWERPC_PROCESSOR_H
3 #define _ASM_POWERPC_PROCESSOR_H
6 * Copyright (C) 2001 PPC 64 Team, IBM Corp
15 #define TS_FPROFFSET 0
16 #define TS_VSRLOWOFFSET 1
18 #define TS_FPROFFSET 1
19 #define TS_VSRLOWOFFSET 0
24 #define TS_FPROFFSET 0
28 /* Default SMT priority is set to 3. Use 11- 13bits to save priority. */
29 #define PPR_PRIORITY 3
31 #define DEFAULT_PPR (PPR_PRIORITY << 50)
33 #define DEFAULT_PPR ((u64)PPR_PRIORITY << 50)
34 #endif /* __ASSEMBLY__ */
35 #endif /* CONFIG_PPC64 */
38 #include <linux/types.h>
39 #include <linux/thread_info.h>
40 #include <asm/ptrace.h>
41 #include <asm/hw_breakpoint.h>
43 /* We do _not_ want to define new machine types at all, those must die
44 * in favor of using the device-tree
48 /* PREP sub-platform types. Unused */
49 #define _PREP_Motorola 0x01 /* motorola prep */
50 #define _PREP_Firm 0x02 /* firmworks prep */
51 #define _PREP_IBM 0x00 /* ibm prep */
52 #define _PREP_Bull 0x03 /* bull prep */
54 /* CHRP sub-platform types. These are arbitrary */
55 #define _CHRP_Motorola 0x04 /* motorola chrp, the cobra */
56 #define _CHRP_IBM 0x05 /* IBM chrp, the longtrail and longtrail 2 */
57 #define _CHRP_Pegasos 0x06 /* Genesi/bplan's Pegasos and Pegasos2 */
58 #define _CHRP_briq 0x07 /* TotalImpact's briQ */
60 #if defined(__KERNEL__) && defined(CONFIG_PPC32)
62 extern int _chrp_type;
64 #endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */
66 /* Macros for adjusting thread priority (hardware multi-threading) */
67 #define HMT_very_low() asm volatile("or 31,31,31 # very low priority")
68 #define HMT_low() asm volatile("or 1,1,1 # low priority")
69 #define HMT_medium_low() asm volatile("or 6,6,6 # medium low priority")
70 #define HMT_medium() asm volatile("or 2,2,2 # medium priority")
71 #define HMT_medium_high() asm volatile("or 5,5,5 # medium high priority")
72 #define HMT_high() asm volatile("or 3,3,3 # high priority")
77 #include <asm/task_size_64.h>
79 #include <asm/task_size_32.h>
83 void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
84 void release_thread(struct task_struct *);
86 #define TS_FPR(i) fp_state.fpr[i][TS_FPROFFSET]
87 #define TS_CKFPR(i) ckfp_state.fpr[i][TS_FPROFFSET]
89 /* FP and VSX 0-31 register set */
90 struct thread_fp_state {
91 u64 fpr[32][TS_FPRWIDTH] __attribute__((aligned(16)));
92 u64 fpscr; /* Floating point status */
95 /* Complete AltiVec register set including VSCR */
96 struct thread_vr_state {
97 vector128 vr[32] __attribute__((aligned(16)));
98 vector128 vscr __attribute__((aligned(16)));
102 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
104 * The following help to manage the use of Debug Control Registers
105 * om the BookE platforms.
113 * The stored value of the DBSR register will be the value at the
114 * last debug interrupt. This register can only be read from the
115 * user (will never be written to) and has value while helping to
116 * describe the reason for the last debug trap. Torez
120 * The following will contain addresses used by debug applications
121 * to help trace and trap on particular address locations.
122 * The bits in the Debug Control Registers above help define which
123 * of the following registers will contain valid data and/or addresses.
127 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
133 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
140 struct thread_struct {
141 unsigned long ksp; /* Kernel stack pointer */
144 unsigned long ksp_vsid;
146 struct pt_regs *regs; /* Pointer to saved register state */
148 /* BookE base exception scratch space; align on cacheline */
149 unsigned long normsave[8] ____cacheline_aligned;
152 void *pgdir; /* root of page-table tree */
153 unsigned long ksp_limit; /* if ksp <= ksp_limit stack overflow */
154 #ifdef CONFIG_PPC_RTAS
155 unsigned long rtas_sp; /* stack pointer for when in RTAS */
158 #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
159 unsigned long kuap; /* opened segments for user access */
161 #ifdef CONFIG_VMAP_STACK
166 #ifdef CONFIG_PPC_BOOK3S_32
167 unsigned long r0, r3, r4, r5, r6, r8, r9, r11;
168 unsigned long lr, ctr;
171 /* Debug Registers */
172 struct debug_reg debug;
173 struct thread_fp_state fp_state;
174 struct thread_fp_state *fp_save_area;
175 int fpexc_mode; /* floating-point exception mode */
176 unsigned int align_ctl; /* alignment handling control */
177 #ifdef CONFIG_HAVE_HW_BREAKPOINT
178 struct perf_event *ptrace_bps[HBP_NUM_MAX];
180 * Helps identify source of single-step exception and subsequent
181 * hw-breakpoint enablement
183 struct perf_event *last_hit_ubp[HBP_NUM_MAX];
184 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
185 struct arch_hw_breakpoint hw_brk[HBP_NUM_MAX]; /* hardware breakpoint info */
186 unsigned long trap_nr; /* last trap # on this thread */
187 u8 load_slb; /* Ages out SLB preload cache entries */
189 #ifdef CONFIG_ALTIVEC
191 struct thread_vr_state vr_state;
192 struct thread_vr_state *vr_save_area;
193 unsigned long vrsave;
194 int used_vr; /* set if process has used altivec */
195 #endif /* CONFIG_ALTIVEC */
198 int used_vsr; /* set if process has used VSX */
199 #endif /* CONFIG_VSX */
201 unsigned long evr[32]; /* upper 32-bits of SPE regs */
202 u64 acc; /* Accumulator */
203 unsigned long spefscr; /* SPE & eFP status */
204 unsigned long spefscr_last; /* SPEFSCR value on last prctl
205 call or trap return */
206 int used_spe; /* set if process has used spe */
207 #endif /* CONFIG_SPE */
208 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
210 u64 tm_tfhar; /* Transaction fail handler addr */
211 u64 tm_texasr; /* Transaction exception & summary */
212 u64 tm_tfiar; /* Transaction fail instr address reg */
213 struct pt_regs ckpt_regs; /* Checkpointed registers */
215 unsigned long tm_tar;
216 unsigned long tm_ppr;
217 unsigned long tm_dscr;
218 unsigned long tm_amr;
221 * Checkpointed FP and VSX 0-31 register set.
223 * When a transaction is active/signalled/scheduled etc., *regs is the
224 * most recent set of/speculated GPRs with ckpt_regs being the older
225 * checkpointed regs to which we roll back if transaction aborts.
227 * These are analogous to how ckpt_regs and pt_regs work
229 struct thread_fp_state ckfp_state; /* Checkpointed FP state */
230 struct thread_vr_state ckvr_state; /* Checkpointed VR state */
231 unsigned long ckvrsave; /* Checkpointed VRSAVE */
232 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
233 #ifdef CONFIG_PPC_MEM_KEYS
237 #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
238 void* kvm_shadow_vcpu; /* KVM internal data */
239 #endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
240 #if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
241 struct kvm_vcpu *kvm_vcpu;
247 * This member element dscr_inherit indicates that the process
248 * has explicitly attempted and changed the DSCR register value
249 * for itself. Hence kernel wont use the default CPU DSCR value
250 * contained in the PACA structure anymore during process context
251 * switch. Once this variable is set, this behaviour will also be
252 * inherited to all the children of this process from that point
258 #ifdef CONFIG_PPC_BOOK3S_64
277 #define ARCH_MIN_TASKALIGN 16
279 #define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)
280 #define INIT_SP_LIMIT ((unsigned long)&init_stack)
283 #define SPEFSCR_INIT \
284 .spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE, \
285 .spefscr_last = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
291 #define INIT_THREAD { \
293 .ksp_limit = INIT_SP_LIMIT, \
294 .pgdir = swapper_pg_dir, \
295 .fpexc_mode = MSR_FE0 | MSR_FE1, \
299 #define INIT_THREAD { \
305 #define task_pt_regs(tsk) ((tsk)->thread.regs)
307 unsigned long get_wchan(struct task_struct *p);
309 #define KSTK_EIP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
310 #define KSTK_ESP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
312 /* Get/set floating-point exception mode */
313 #define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
314 #define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
316 extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
317 extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
319 #define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
320 #define SET_ENDIAN(tsk, val) set_endian((tsk), (val))
322 extern int get_endian(struct task_struct *tsk, unsigned long adr);
323 extern int set_endian(struct task_struct *tsk, unsigned int val);
325 #define GET_UNALIGN_CTL(tsk, adr) get_unalign_ctl((tsk), (adr))
326 #define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
328 extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
329 extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
331 extern void load_fp_state(struct thread_fp_state *fp);
332 extern void store_fp_state(struct thread_fp_state *fp);
333 extern void load_vr_state(struct thread_vr_state *vr);
334 extern void store_vr_state(struct thread_vr_state *vr);
336 static inline unsigned int __unpack_fe01(unsigned long msr_bits)
338 return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
341 static inline unsigned long __pack_fe01(unsigned int fpmode)
343 return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
347 #define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
349 #define spin_begin() HMT_low()
351 #define spin_cpu_relax() barrier()
353 #define spin_end() HMT_medium()
355 #define spin_until_cond(cond) \
357 if (unlikely(!(cond))) { \
367 #define cpu_relax() barrier()
370 /* Check that a certain kernel stack pointer is valid in task_struct p */
371 int validate_sp(unsigned long sp, struct task_struct *p,
372 unsigned long nbytes);
377 #define ARCH_HAS_PREFETCH
378 #define ARCH_HAS_PREFETCHW
379 #define ARCH_HAS_SPINLOCK_PREFETCH
381 static inline void prefetch(const void *x)
386 __asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
389 static inline void prefetchw(const void *x)
394 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
397 #define spin_lock_prefetch(x) prefetchw(x)
399 #define HAVE_ARCH_PICK_MMAP_LAYOUT
402 static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
405 return sp & 0x0ffffffffUL;
409 static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
416 extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
417 extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
418 extern unsigned long isa206_idle_insn_mayloss(unsigned long type);
419 #ifdef CONFIG_PPC_970_NAP
420 extern void power4_idle_nap(void);
423 extern unsigned long cpuidle_disable;
424 enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
426 extern int powersave_nap; /* set if nap mode can be used in idle loop */
428 extern void power7_idle_type(unsigned long type);
429 extern void arch300_idle_type(unsigned long stop_psscr_val,
430 unsigned long stop_psscr_mask);
432 extern int fix_alignment(struct pt_regs *);
436 * We handle most unaligned accesses in hardware. On the other hand
437 * unaligned DMA can be very expensive on some ppc64 IO chips (it does
438 * powers of 2 writes until it reaches sufficient alignment).
440 * Based on this we disable the IP header alignment in network drivers.
442 #define NET_IP_ALIGN 0
445 #endif /* __KERNEL__ */
446 #endif /* __ASSEMBLY__ */
447 #endif /* _ASM_POWERPC_PROCESSOR_H */