xref: /linux-6.15/arch/x86/include/asm/processor.h (revision 14b9675a)
11965aae3SH. Peter Anvin #ifndef _ASM_X86_PROCESSOR_H
21965aae3SH. Peter Anvin #define _ASM_X86_PROCESSOR_H
3bb898558SAl Viro 
4bb898558SAl Viro #include <asm/processor-flags.h>
5bb898558SAl Viro 
6bb898558SAl Viro /* Forward declaration, a strange C thing */
7bb898558SAl Viro struct task_struct;
8bb898558SAl Viro struct mm_struct;
9bb898558SAl Viro 
10bb898558SAl Viro #include <asm/vm86.h>
11bb898558SAl Viro #include <asm/math_emu.h>
12bb898558SAl Viro #include <asm/segment.h>
13bb898558SAl Viro #include <asm/types.h>
14bb898558SAl Viro #include <asm/sigcontext.h>
15bb898558SAl Viro #include <asm/current.h>
16bb898558SAl Viro #include <asm/cpufeature.h>
17bb898558SAl Viro #include <asm/page.h>
1854321d94SJeremy Fitzhardinge #include <asm/pgtable_types.h>
19bb898558SAl Viro #include <asm/percpu.h>
20bb898558SAl Viro #include <asm/msr.h>
21bb898558SAl Viro #include <asm/desc_defs.h>
22bb898558SAl Viro #include <asm/nops.h>
23f05e798aSDavid Howells #include <asm/special_insns.h>
24*14b9675aSIngo Molnar #include <asm/fpu/types.h>
25bb898558SAl Viro 
26bb898558SAl Viro #include <linux/personality.h>
27bb898558SAl Viro #include <linux/cpumask.h>
28bb898558SAl Viro #include <linux/cache.h>
29bb898558SAl Viro #include <linux/threads.h>
305cbc19a9SPeter Zijlstra #include <linux/math64.h>
31faa4602eSPeter Zijlstra #include <linux/err.h>
32f05e798aSDavid Howells #include <linux/irqflags.h>
33f05e798aSDavid Howells 
34f05e798aSDavid Howells /*
35f05e798aSDavid Howells  * We handle most unaligned accesses in hardware.  On the other hand
36f05e798aSDavid Howells  * unaligned DMA can be quite expensive on some Nehalem processors.
37f05e798aSDavid Howells  *
38f05e798aSDavid Howells  * Based on this we disable the IP header alignment in network drivers.
39f05e798aSDavid Howells  */
40f05e798aSDavid Howells #define NET_IP_ALIGN	0
41bb898558SAl Viro 
42b332828cSK.Prasad #define HBP_NUM 4
43bb898558SAl Viro /*
44bb898558SAl Viro  * Default implementation of macro that returns current
45bb898558SAl Viro  * instruction pointer ("program counter").
46bb898558SAl Viro  */
47bb898558SAl Viro static inline void *current_text_addr(void)
48bb898558SAl Viro {
49bb898558SAl Viro 	void *pc;
50bb898558SAl Viro 
51bb898558SAl Viro 	asm volatile("mov $1f, %0; 1:":"=r" (pc));
52bb898558SAl Viro 
53bb898558SAl Viro 	return pc;
54bb898558SAl Viro }
55bb898558SAl Viro 
56bb898558SAl Viro #ifdef CONFIG_X86_VSMP
57bb898558SAl Viro # define ARCH_MIN_TASKALIGN		(1 << INTERNODE_CACHE_SHIFT)
58bb898558SAl Viro # define ARCH_MIN_MMSTRUCT_ALIGN	(1 << INTERNODE_CACHE_SHIFT)
59bb898558SAl Viro #else
60bb898558SAl Viro # define ARCH_MIN_TASKALIGN		16
61bb898558SAl Viro # define ARCH_MIN_MMSTRUCT_ALIGN	0
62bb898558SAl Viro #endif
63bb898558SAl Viro 
64e0ba94f1SAlex Shi enum tlb_infos {
65e0ba94f1SAlex Shi 	ENTRIES,
66e0ba94f1SAlex Shi 	NR_INFO
67e0ba94f1SAlex Shi };
68e0ba94f1SAlex Shi 
69e0ba94f1SAlex Shi extern u16 __read_mostly tlb_lli_4k[NR_INFO];
70e0ba94f1SAlex Shi extern u16 __read_mostly tlb_lli_2m[NR_INFO];
71e0ba94f1SAlex Shi extern u16 __read_mostly tlb_lli_4m[NR_INFO];
72e0ba94f1SAlex Shi extern u16 __read_mostly tlb_lld_4k[NR_INFO];
73e0ba94f1SAlex Shi extern u16 __read_mostly tlb_lld_2m[NR_INFO];
74e0ba94f1SAlex Shi extern u16 __read_mostly tlb_lld_4m[NR_INFO];
75dd360393SKirill A. Shutemov extern u16 __read_mostly tlb_lld_1g[NR_INFO];
76c4211f42SAlex Shi 
77bb898558SAl Viro /*
78bb898558SAl Viro  *  CPU type and hardware bug flags. Kept separately for each CPU.
79bb898558SAl Viro  *  Members of this structure are referenced in head.S, so think twice
80bb898558SAl Viro  *  before touching them. [mj]
81bb898558SAl Viro  */
82bb898558SAl Viro 
83bb898558SAl Viro struct cpuinfo_x86 {
84bb898558SAl Viro 	__u8			x86;		/* CPU family */
85bb898558SAl Viro 	__u8			x86_vendor;	/* CPU vendor */
86bb898558SAl Viro 	__u8			x86_model;
87bb898558SAl Viro 	__u8			x86_mask;
88bb898558SAl Viro #ifdef CONFIG_X86_32
89bb898558SAl Viro 	char			wp_works_ok;	/* It doesn't on 386's */
90bb898558SAl Viro 
91bb898558SAl Viro 	/* Problems on some 486Dx4's and old 386's: */
92bb898558SAl Viro 	char			rfu;
93bb898558SAl Viro 	char			pad0;
9460e019ebSH. Peter Anvin 	char			pad1;
95bb898558SAl Viro #else
96bb898558SAl Viro 	/* Number of 4K pages in DTLB/ITLB combined(in pages): */
97bb898558SAl Viro 	int			x86_tlbsize;
9813c6c532SJan Beulich #endif
99bb898558SAl Viro 	__u8			x86_virt_bits;
100bb898558SAl Viro 	__u8			x86_phys_bits;
101bb898558SAl Viro 	/* CPUID returned core id bits: */
102bb898558SAl Viro 	__u8			x86_coreid_bits;
103bb898558SAl Viro 	/* Max extended CPUID function supported: */
104bb898558SAl Viro 	__u32			extended_cpuid_level;
105bb898558SAl Viro 	/* Maximum supported CPUID level, -1=no CPUID: */
106bb898558SAl Viro 	int			cpuid_level;
10765fc985bSBorislav Petkov 	__u32			x86_capability[NCAPINTS + NBUGINTS];
108bb898558SAl Viro 	char			x86_vendor_id[16];
109bb898558SAl Viro 	char			x86_model_id[64];
110bb898558SAl Viro 	/* in KB - valid for CPUS which support this call: */
111bb898558SAl Viro 	int			x86_cache_size;
112bb898558SAl Viro 	int			x86_cache_alignment;	/* In bytes */
113cbc82b17SPeter P Waskiewicz Jr 	/* Cache QoS architectural values: */
114cbc82b17SPeter P Waskiewicz Jr 	int			x86_cache_max_rmid;	/* max index */
115cbc82b17SPeter P Waskiewicz Jr 	int			x86_cache_occ_scale;	/* scale to bytes */
116bb898558SAl Viro 	int			x86_power;
117bb898558SAl Viro 	unsigned long		loops_per_jiffy;
118bb898558SAl Viro 	/* cpuid returned max cores value: */
119bb898558SAl Viro 	u16			 x86_max_cores;
120bb898558SAl Viro 	u16			apicid;
121bb898558SAl Viro 	u16			initial_apicid;
122bb898558SAl Viro 	u16			x86_clflush_size;
123bb898558SAl Viro 	/* number of cores as seen by the OS: */
124bb898558SAl Viro 	u16			booted_cores;
125bb898558SAl Viro 	/* Physical processor id: */
126bb898558SAl Viro 	u16			phys_proc_id;
127bb898558SAl Viro 	/* Core id: */
128bb898558SAl Viro 	u16			cpu_core_id;
1296057b4d3SAndreas Herrmann 	/* Compute unit id */
1306057b4d3SAndreas Herrmann 	u8			compute_unit_id;
131bb898558SAl Viro 	/* Index into per_cpu list: */
132bb898558SAl Viro 	u16			cpu_index;
133506ed6b5SAndi Kleen 	u32			microcode;
1342c773dd3SJan Beulich };
135bb898558SAl Viro 
136bb898558SAl Viro #define X86_VENDOR_INTEL	0
137bb898558SAl Viro #define X86_VENDOR_CYRIX	1
138bb898558SAl Viro #define X86_VENDOR_AMD		2
139bb898558SAl Viro #define X86_VENDOR_UMC		3
140bb898558SAl Viro #define X86_VENDOR_CENTAUR	5
141bb898558SAl Viro #define X86_VENDOR_TRANSMETA	7
142bb898558SAl Viro #define X86_VENDOR_NSC		8
143bb898558SAl Viro #define X86_VENDOR_NUM		9
144bb898558SAl Viro 
145bb898558SAl Viro #define X86_VENDOR_UNKNOWN	0xff
146bb898558SAl Viro 
147bb898558SAl Viro /*
148bb898558SAl Viro  * capabilities of CPUs
149bb898558SAl Viro  */
150bb898558SAl Viro extern struct cpuinfo_x86	boot_cpu_data;
151bb898558SAl Viro extern struct cpuinfo_x86	new_cpu_data;
152bb898558SAl Viro 
153bb898558SAl Viro extern struct tss_struct	doublefault_tss;
1543e0c3737SYinghai Lu extern __u32			cpu_caps_cleared[NCAPINTS];
1553e0c3737SYinghai Lu extern __u32			cpu_caps_set[NCAPINTS];
156bb898558SAl Viro 
157bb898558SAl Viro #ifdef CONFIG_SMP
1582c773dd3SJan Beulich DECLARE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
159bb898558SAl Viro #define cpu_data(cpu)		per_cpu(cpu_info, cpu)
160bb898558SAl Viro #else
1617b543a53STejun Heo #define cpu_info		boot_cpu_data
162bb898558SAl Viro #define cpu_data(cpu)		boot_cpu_data
163bb898558SAl Viro #endif
164bb898558SAl Viro 
165bb898558SAl Viro extern const struct seq_operations cpuinfo_op;
166bb898558SAl Viro 
167bb898558SAl Viro #define cache_line_size()	(boot_cpu_data.x86_cache_alignment)
168bb898558SAl Viro 
169bb898558SAl Viro extern void cpu_detect(struct cpuinfo_x86 *c);
1701a7dc0dbSIngo Molnar extern void fpu__detect(struct cpuinfo_x86 *c);
171bb898558SAl Viro 
172bb898558SAl Viro extern void early_cpu_init(void);
173bb898558SAl Viro extern void identify_boot_cpu(void);
174bb898558SAl Viro extern void identify_secondary_cpu(struct cpuinfo_x86 *);
175bb898558SAl Viro extern void print_cpu_info(struct cpuinfo_x86 *);
17621c3fcf3SYinghai Lu void print_cpu_msr(struct cpuinfo_x86 *);
177bb898558SAl Viro extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
178bb898558SAl Viro extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
17904a15418SAndreas Herrmann extern void init_amd_cacheinfo(struct cpuinfo_x86 *c);
180bb898558SAl Viro 
181bb898558SAl Viro extern void detect_extended_topology(struct cpuinfo_x86 *c);
182bb898558SAl Viro extern void detect_ht(struct cpuinfo_x86 *c);
183bb898558SAl Viro 
184d288e1cfSFenghua Yu #ifdef CONFIG_X86_32
185d288e1cfSFenghua Yu extern int have_cpuid_p(void);
186d288e1cfSFenghua Yu #else
187d288e1cfSFenghua Yu static inline int have_cpuid_p(void)
188d288e1cfSFenghua Yu {
189d288e1cfSFenghua Yu 	return 1;
190d288e1cfSFenghua Yu }
191d288e1cfSFenghua Yu #endif
192bb898558SAl Viro static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
193bb898558SAl Viro 				unsigned int *ecx, unsigned int *edx)
194bb898558SAl Viro {
195bb898558SAl Viro 	/* ecx is often an input as well as an output. */
19645a94d7cSSuresh Siddha 	asm volatile("cpuid"
197bb898558SAl Viro 	    : "=a" (*eax),
198bb898558SAl Viro 	      "=b" (*ebx),
199bb898558SAl Viro 	      "=c" (*ecx),
200bb898558SAl Viro 	      "=d" (*edx)
201506ed6b5SAndi Kleen 	    : "0" (*eax), "2" (*ecx)
202506ed6b5SAndi Kleen 	    : "memory");
203bb898558SAl Viro }
204bb898558SAl Viro 
205bb898558SAl Viro static inline void load_cr3(pgd_t *pgdir)
206bb898558SAl Viro {
207bb898558SAl Viro 	write_cr3(__pa(pgdir));
208bb898558SAl Viro }
209bb898558SAl Viro 
210bb898558SAl Viro #ifdef CONFIG_X86_32
211bb898558SAl Viro /* This is the TSS defined by the hardware. */
212bb898558SAl Viro struct x86_hw_tss {
213bb898558SAl Viro 	unsigned short		back_link, __blh;
214bb898558SAl Viro 	unsigned long		sp0;
215bb898558SAl Viro 	unsigned short		ss0, __ss0h;
216cf9328ccSAndy Lutomirski 	unsigned long		sp1;
21776e4c490SAndy Lutomirski 
21876e4c490SAndy Lutomirski 	/*
219cf9328ccSAndy Lutomirski 	 * We don't use ring 1, so ss1 is a convenient scratch space in
220cf9328ccSAndy Lutomirski 	 * the same cacheline as sp0.  We use ss1 to cache the value in
221cf9328ccSAndy Lutomirski 	 * MSR_IA32_SYSENTER_CS.  When we context switch
222cf9328ccSAndy Lutomirski 	 * MSR_IA32_SYSENTER_CS, we first check if the new value being
223cf9328ccSAndy Lutomirski 	 * written matches ss1, and, if it's not, then we wrmsr the new
224cf9328ccSAndy Lutomirski 	 * value and update ss1.
22576e4c490SAndy Lutomirski 	 *
226cf9328ccSAndy Lutomirski 	 * The only reason we context switch MSR_IA32_SYSENTER_CS is
227cf9328ccSAndy Lutomirski 	 * that we set it to zero in vm86 tasks to avoid corrupting the
228cf9328ccSAndy Lutomirski 	 * stack if we were to go through the sysenter path from vm86
229cf9328ccSAndy Lutomirski 	 * mode.
23076e4c490SAndy Lutomirski 	 */
23176e4c490SAndy Lutomirski 	unsigned short		ss1;	/* MSR_IA32_SYSENTER_CS */
23276e4c490SAndy Lutomirski 
23376e4c490SAndy Lutomirski 	unsigned short		__ss1h;
234bb898558SAl Viro 	unsigned long		sp2;
235bb898558SAl Viro 	unsigned short		ss2, __ss2h;
236bb898558SAl Viro 	unsigned long		__cr3;
237bb898558SAl Viro 	unsigned long		ip;
238bb898558SAl Viro 	unsigned long		flags;
239bb898558SAl Viro 	unsigned long		ax;
240bb898558SAl Viro 	unsigned long		cx;
241bb898558SAl Viro 	unsigned long		dx;
242bb898558SAl Viro 	unsigned long		bx;
243bb898558SAl Viro 	unsigned long		sp;
244bb898558SAl Viro 	unsigned long		bp;
245bb898558SAl Viro 	unsigned long		si;
246bb898558SAl Viro 	unsigned long		di;
247bb898558SAl Viro 	unsigned short		es, __esh;
248bb898558SAl Viro 	unsigned short		cs, __csh;
249bb898558SAl Viro 	unsigned short		ss, __ssh;
250bb898558SAl Viro 	unsigned short		ds, __dsh;
251bb898558SAl Viro 	unsigned short		fs, __fsh;
252bb898558SAl Viro 	unsigned short		gs, __gsh;
253bb898558SAl Viro 	unsigned short		ldt, __ldth;
254bb898558SAl Viro 	unsigned short		trace;
255bb898558SAl Viro 	unsigned short		io_bitmap_base;
256bb898558SAl Viro 
257bb898558SAl Viro } __attribute__((packed));
258bb898558SAl Viro #else
259bb898558SAl Viro struct x86_hw_tss {
260bb898558SAl Viro 	u32			reserved1;
261bb898558SAl Viro 	u64			sp0;
262bb898558SAl Viro 	u64			sp1;
263bb898558SAl Viro 	u64			sp2;
264bb898558SAl Viro 	u64			reserved2;
265bb898558SAl Viro 	u64			ist[7];
266bb898558SAl Viro 	u32			reserved3;
267bb898558SAl Viro 	u32			reserved4;
268bb898558SAl Viro 	u16			reserved5;
269bb898558SAl Viro 	u16			io_bitmap_base;
270bb898558SAl Viro 
271bb898558SAl Viro } __attribute__((packed)) ____cacheline_aligned;
272bb898558SAl Viro #endif
273bb898558SAl Viro 
274bb898558SAl Viro /*
275bb898558SAl Viro  * IO-bitmap sizes:
276bb898558SAl Viro  */
277bb898558SAl Viro #define IO_BITMAP_BITS			65536
278bb898558SAl Viro #define IO_BITMAP_BYTES			(IO_BITMAP_BITS/8)
279bb898558SAl Viro #define IO_BITMAP_LONGS			(IO_BITMAP_BYTES/sizeof(long))
280bb898558SAl Viro #define IO_BITMAP_OFFSET		offsetof(struct tss_struct, io_bitmap)
281bb898558SAl Viro #define INVALID_IO_BITMAP_OFFSET	0x8000
282bb898558SAl Viro 
283bb898558SAl Viro struct tss_struct {
284bb898558SAl Viro 	/*
285bb898558SAl Viro 	 * The hardware state:
286bb898558SAl Viro 	 */
287bb898558SAl Viro 	struct x86_hw_tss	x86_tss;
288bb898558SAl Viro 
289bb898558SAl Viro 	/*
290bb898558SAl Viro 	 * The extra 1 is there because the CPU will access an
291bb898558SAl Viro 	 * additional byte beyond the end of the IO permission
292bb898558SAl Viro 	 * bitmap. The extra byte must be all 1 bits, and must
293bb898558SAl Viro 	 * be within the limit.
294bb898558SAl Viro 	 */
295bb898558SAl Viro 	unsigned long		io_bitmap[IO_BITMAP_LONGS + 1];
296bb898558SAl Viro 
297bb898558SAl Viro 	/*
298d828c71fSDenys Vlasenko 	 * Space for the temporary SYSENTER stack:
299bb898558SAl Viro 	 */
300d828c71fSDenys Vlasenko 	unsigned long		SYSENTER_stack[64];
301bb898558SAl Viro 
302bb898558SAl Viro } ____cacheline_aligned;
303bb898558SAl Viro 
30424933b82SAndy Lutomirski DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss);
305bb898558SAl Viro 
306a7fcf28dSAndy Lutomirski #ifdef CONFIG_X86_32
307a7fcf28dSAndy Lutomirski DECLARE_PER_CPU(unsigned long, cpu_current_top_of_stack);
308a7fcf28dSAndy Lutomirski #endif
309a7fcf28dSAndy Lutomirski 
310bb898558SAl Viro /*
311bb898558SAl Viro  * Save the original ist values for checking stack pointers during debugging
312bb898558SAl Viro  */
313bb898558SAl Viro struct orig_ist {
314bb898558SAl Viro 	unsigned long		ist[7];
315bb898558SAl Viro };
316bb898558SAl Viro 
317bb898558SAl Viro #ifdef CONFIG_X86_64
318bb898558SAl Viro DECLARE_PER_CPU(struct orig_ist, orig_ist);
31926f80bd6SBrian Gerst 
320947e76cdSBrian Gerst union irq_stack_union {
321947e76cdSBrian Gerst 	char irq_stack[IRQ_STACK_SIZE];
322947e76cdSBrian Gerst 	/*
323947e76cdSBrian Gerst 	 * GCC hardcodes the stack canary as %gs:40.  Since the
324947e76cdSBrian Gerst 	 * irq_stack is the object at %gs:0, we reserve the bottom
325947e76cdSBrian Gerst 	 * 48 bytes of the irq stack for the canary.
326947e76cdSBrian Gerst 	 */
327947e76cdSBrian Gerst 	struct {
328947e76cdSBrian Gerst 		char gs_base[40];
329947e76cdSBrian Gerst 		unsigned long stack_canary;
330947e76cdSBrian Gerst 	};
331947e76cdSBrian Gerst };
332947e76cdSBrian Gerst 
333277d5b40SAndi Kleen DECLARE_PER_CPU_FIRST(union irq_stack_union, irq_stack_union) __visible;
3342add8e23SBrian Gerst DECLARE_INIT_PER_CPU(irq_stack_union);
3352add8e23SBrian Gerst 
33626f80bd6SBrian Gerst DECLARE_PER_CPU(char *, irq_stack_ptr);
3379766cdbcSJaswinder Singh Rajput DECLARE_PER_CPU(unsigned int, irq_count);
3389766cdbcSJaswinder Singh Rajput extern asmlinkage void ignore_sysret(void);
33960a5317fSTejun Heo #else	/* X86_64 */
34060a5317fSTejun Heo #ifdef CONFIG_CC_STACKPROTECTOR
3411ea0d14eSJeremy Fitzhardinge /*
3421ea0d14eSJeremy Fitzhardinge  * Make sure stack canary segment base is cached-aligned:
3431ea0d14eSJeremy Fitzhardinge  *   "For Intel Atom processors, avoid non zero segment base address
3441ea0d14eSJeremy Fitzhardinge  *    that is not aligned to cache line boundary at all cost."
3451ea0d14eSJeremy Fitzhardinge  * (Optim Ref Manual Assembly/Compiler Coding Rule 15.)
3461ea0d14eSJeremy Fitzhardinge  */
3471ea0d14eSJeremy Fitzhardinge struct stack_canary {
3481ea0d14eSJeremy Fitzhardinge 	char __pad[20];		/* canary at %gs:20 */
3491ea0d14eSJeremy Fitzhardinge 	unsigned long canary;
3501ea0d14eSJeremy Fitzhardinge };
35153f82452SJeremy Fitzhardinge DECLARE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);
352bb898558SAl Viro #endif
353198d208dSSteven Rostedt /*
354198d208dSSteven Rostedt  * per-CPU IRQ handling stacks
355198d208dSSteven Rostedt  */
356198d208dSSteven Rostedt struct irq_stack {
357198d208dSSteven Rostedt 	u32                     stack[THREAD_SIZE/sizeof(u32)];
358198d208dSSteven Rostedt } __aligned(THREAD_SIZE);
359198d208dSSteven Rostedt 
360198d208dSSteven Rostedt DECLARE_PER_CPU(struct irq_stack *, hardirq_stack);
361198d208dSSteven Rostedt DECLARE_PER_CPU(struct irq_stack *, softirq_stack);
36260a5317fSTejun Heo #endif	/* X86_64 */
363bb898558SAl Viro 
364bb898558SAl Viro extern unsigned int xstate_size;
365bb898558SAl Viro extern void free_thread_xstate(struct task_struct *);
366bb898558SAl Viro extern struct kmem_cache *task_xstate_cachep;
367bb898558SAl Viro 
36824f1e32cSFrederic Weisbecker struct perf_event;
36924f1e32cSFrederic Weisbecker 
370bb898558SAl Viro struct thread_struct {
371bb898558SAl Viro 	/* Cached TLS descriptors: */
372bb898558SAl Viro 	struct desc_struct	tls_array[GDT_ENTRY_TLS_ENTRIES];
373bb898558SAl Viro 	unsigned long		sp0;
374bb898558SAl Viro 	unsigned long		sp;
375bb898558SAl Viro #ifdef CONFIG_X86_32
376bb898558SAl Viro 	unsigned long		sysenter_cs;
377bb898558SAl Viro #else
378bb898558SAl Viro 	unsigned short		es;
379bb898558SAl Viro 	unsigned short		ds;
380bb898558SAl Viro 	unsigned short		fsindex;
381bb898558SAl Viro 	unsigned short		gsindex;
382bb898558SAl Viro #endif
3830c23590fSAlexey Dobriyan #ifdef CONFIG_X86_32
384bb898558SAl Viro 	unsigned long		ip;
3850c23590fSAlexey Dobriyan #endif
386d756f4adSAlexey Dobriyan #ifdef CONFIG_X86_64
387bb898558SAl Viro 	unsigned long		fs;
388d756f4adSAlexey Dobriyan #endif
389bb898558SAl Viro 	unsigned long		gs;
39024f1e32cSFrederic Weisbecker 	/* Save middle states of ptrace breakpoints */
39124f1e32cSFrederic Weisbecker 	struct perf_event	*ptrace_bps[HBP_NUM];
39224f1e32cSFrederic Weisbecker 	/* Debug status used for traps, single steps, etc... */
393bb898558SAl Viro 	unsigned long           debugreg6;
394326264a0SFrederic Weisbecker 	/* Keep track of the exact dr7 value set by the user */
395326264a0SFrederic Weisbecker 	unsigned long           ptrace_dr7;
396bb898558SAl Viro 	/* Fault info: */
397bb898558SAl Viro 	unsigned long		cr2;
39851e7dc70SSrikar Dronamraju 	unsigned long		trap_nr;
399bb898558SAl Viro 	unsigned long		error_code;
400bb898558SAl Viro 	/* floating point and extended processor state */
40186603283SAvi Kivity 	struct fpu		fpu;
402bb898558SAl Viro #ifdef CONFIG_X86_32
403bb898558SAl Viro 	/* Virtual 86 mode info */
404bb898558SAl Viro 	struct vm86_struct __user *vm86_info;
405bb898558SAl Viro 	unsigned long		screen_bitmap;
406bb898558SAl Viro 	unsigned long		v86flags;
407bb898558SAl Viro 	unsigned long		v86mask;
408bb898558SAl Viro 	unsigned long		saved_sp0;
409bb898558SAl Viro 	unsigned int		saved_fs;
410bb898558SAl Viro 	unsigned int		saved_gs;
411bb898558SAl Viro #endif
412bb898558SAl Viro 	/* IO permissions: */
413bb898558SAl Viro 	unsigned long		*io_bitmap_ptr;
414bb898558SAl Viro 	unsigned long		iopl;
415bb898558SAl Viro 	/* Max allowed port in the bitmap, in bytes: */
416bb898558SAl Viro 	unsigned		io_bitmap_max;
417bb898558SAl Viro };
418bb898558SAl Viro 
419bb898558SAl Viro /*
420bb898558SAl Viro  * Set IOPL bits in EFLAGS from given mask
421bb898558SAl Viro  */
422bb898558SAl Viro static inline void native_set_iopl_mask(unsigned mask)
423bb898558SAl Viro {
424bb898558SAl Viro #ifdef CONFIG_X86_32
425bb898558SAl Viro 	unsigned int reg;
426bb898558SAl Viro 
427bb898558SAl Viro 	asm volatile ("pushfl;"
428bb898558SAl Viro 		      "popl %0;"
429bb898558SAl Viro 		      "andl %1, %0;"
430bb898558SAl Viro 		      "orl %2, %0;"
431bb898558SAl Viro 		      "pushl %0;"
432bb898558SAl Viro 		      "popfl"
433bb898558SAl Viro 		      : "=&r" (reg)
434bb898558SAl Viro 		      : "i" (~X86_EFLAGS_IOPL), "r" (mask));
435bb898558SAl Viro #endif
436bb898558SAl Viro }
437bb898558SAl Viro 
438bb898558SAl Viro static inline void
439bb898558SAl Viro native_load_sp0(struct tss_struct *tss, struct thread_struct *thread)
440bb898558SAl Viro {
441bb898558SAl Viro 	tss->x86_tss.sp0 = thread->sp0;
442bb898558SAl Viro #ifdef CONFIG_X86_32
443bb898558SAl Viro 	/* Only happens when SEP is enabled, no need to test "SEP"arately: */
444bb898558SAl Viro 	if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) {
445bb898558SAl Viro 		tss->x86_tss.ss1 = thread->sysenter_cs;
446bb898558SAl Viro 		wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
447bb898558SAl Viro 	}
448bb898558SAl Viro #endif
449bb898558SAl Viro }
450bb898558SAl Viro 
451bb898558SAl Viro static inline void native_swapgs(void)
452bb898558SAl Viro {
453bb898558SAl Viro #ifdef CONFIG_X86_64
454bb898558SAl Viro 	asm volatile("swapgs" ::: "memory");
455bb898558SAl Viro #endif
456bb898558SAl Viro }
457bb898558SAl Viro 
458a7fcf28dSAndy Lutomirski static inline unsigned long current_top_of_stack(void)
4598ef46a67SAndy Lutomirski {
460a7fcf28dSAndy Lutomirski #ifdef CONFIG_X86_64
46124933b82SAndy Lutomirski 	return this_cpu_read_stable(cpu_tss.x86_tss.sp0);
462a7fcf28dSAndy Lutomirski #else
463a7fcf28dSAndy Lutomirski 	/* sp0 on x86_32 is special in and around vm86 mode. */
464a7fcf28dSAndy Lutomirski 	return this_cpu_read_stable(cpu_current_top_of_stack);
465a7fcf28dSAndy Lutomirski #endif
4668ef46a67SAndy Lutomirski }
4678ef46a67SAndy Lutomirski 
468bb898558SAl Viro #ifdef CONFIG_PARAVIRT
469bb898558SAl Viro #include <asm/paravirt.h>
470bb898558SAl Viro #else
471bb898558SAl Viro #define __cpuid			native_cpuid
472bb898558SAl Viro #define paravirt_enabled()	0
473bb898558SAl Viro 
474bb898558SAl Viro static inline void load_sp0(struct tss_struct *tss,
475bb898558SAl Viro 			    struct thread_struct *thread)
476bb898558SAl Viro {
477bb898558SAl Viro 	native_load_sp0(tss, thread);
478bb898558SAl Viro }
479bb898558SAl Viro 
480bb898558SAl Viro #define set_iopl_mask native_set_iopl_mask
481bb898558SAl Viro #endif /* CONFIG_PARAVIRT */
482bb898558SAl Viro 
483bb898558SAl Viro typedef struct {
484bb898558SAl Viro 	unsigned long		seg;
485bb898558SAl Viro } mm_segment_t;
486bb898558SAl Viro 
487bb898558SAl Viro 
488bb898558SAl Viro /* Free all resources held by a thread. */
489bb898558SAl Viro extern void release_thread(struct task_struct *);
490bb898558SAl Viro 
491bb898558SAl Viro unsigned long get_wchan(struct task_struct *p);
492bb898558SAl Viro 
493bb898558SAl Viro /*
494bb898558SAl Viro  * Generic CPUID function
495bb898558SAl Viro  * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
496bb898558SAl Viro  * resulting in stale register contents being returned.
497bb898558SAl Viro  */
498bb898558SAl Viro static inline void cpuid(unsigned int op,
499bb898558SAl Viro 			 unsigned int *eax, unsigned int *ebx,
500bb898558SAl Viro 			 unsigned int *ecx, unsigned int *edx)
501bb898558SAl Viro {
502bb898558SAl Viro 	*eax = op;
503bb898558SAl Viro 	*ecx = 0;
504bb898558SAl Viro 	__cpuid(eax, ebx, ecx, edx);
505bb898558SAl Viro }
506bb898558SAl Viro 
507bb898558SAl Viro /* Some CPUID calls want 'count' to be placed in ecx */
508bb898558SAl Viro static inline void cpuid_count(unsigned int op, int count,
509bb898558SAl Viro 			       unsigned int *eax, unsigned int *ebx,
510bb898558SAl Viro 			       unsigned int *ecx, unsigned int *edx)
511bb898558SAl Viro {
512bb898558SAl Viro 	*eax = op;
513bb898558SAl Viro 	*ecx = count;
514bb898558SAl Viro 	__cpuid(eax, ebx, ecx, edx);
515bb898558SAl Viro }
516bb898558SAl Viro 
517bb898558SAl Viro /*
518bb898558SAl Viro  * CPUID functions returning a single datum
519bb898558SAl Viro  */
520bb898558SAl Viro static inline unsigned int cpuid_eax(unsigned int op)
521bb898558SAl Viro {
522bb898558SAl Viro 	unsigned int eax, ebx, ecx, edx;
523bb898558SAl Viro 
524bb898558SAl Viro 	cpuid(op, &eax, &ebx, &ecx, &edx);
525bb898558SAl Viro 
526bb898558SAl Viro 	return eax;
527bb898558SAl Viro }
528bb898558SAl Viro 
529bb898558SAl Viro static inline unsigned int cpuid_ebx(unsigned int op)
530bb898558SAl Viro {
531bb898558SAl Viro 	unsigned int eax, ebx, ecx, edx;
532bb898558SAl Viro 
533bb898558SAl Viro 	cpuid(op, &eax, &ebx, &ecx, &edx);
534bb898558SAl Viro 
535bb898558SAl Viro 	return ebx;
536bb898558SAl Viro }
537bb898558SAl Viro 
538bb898558SAl Viro static inline unsigned int cpuid_ecx(unsigned int op)
539bb898558SAl Viro {
540bb898558SAl Viro 	unsigned int eax, ebx, ecx, edx;
541bb898558SAl Viro 
542bb898558SAl Viro 	cpuid(op, &eax, &ebx, &ecx, &edx);
543bb898558SAl Viro 
544bb898558SAl Viro 	return ecx;
545bb898558SAl Viro }
546bb898558SAl Viro 
547bb898558SAl Viro static inline unsigned int cpuid_edx(unsigned int op)
548bb898558SAl Viro {
549bb898558SAl Viro 	unsigned int eax, ebx, ecx, edx;
550bb898558SAl Viro 
551bb898558SAl Viro 	cpuid(op, &eax, &ebx, &ecx, &edx);
552bb898558SAl Viro 
553bb898558SAl Viro 	return edx;
554bb898558SAl Viro }
555bb898558SAl Viro 
556bb898558SAl Viro /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
557bb898558SAl Viro static inline void rep_nop(void)
558bb898558SAl Viro {
559bb898558SAl Viro 	asm volatile("rep; nop" ::: "memory");
560bb898558SAl Viro }
561bb898558SAl Viro 
562bb898558SAl Viro static inline void cpu_relax(void)
563bb898558SAl Viro {
564bb898558SAl Viro 	rep_nop();
565bb898558SAl Viro }
566bb898558SAl Viro 
5673a6bfbc9SDavidlohr Bueso #define cpu_relax_lowlatency() cpu_relax()
5683a6bfbc9SDavidlohr Bueso 
5695367b688SBen Hutchings /* Stop speculative execution and prefetching of modified code. */
570bb898558SAl Viro static inline void sync_core(void)
571bb898558SAl Viro {
572bb898558SAl Viro 	int tmp;
573bb898558SAl Viro 
574eb068e78SH. Peter Anvin #ifdef CONFIG_M486
57545c39fb0SH. Peter Anvin 	/*
57645c39fb0SH. Peter Anvin 	 * Do a CPUID if available, otherwise do a jump.  The jump
57745c39fb0SH. Peter Anvin 	 * can conveniently enough be the jump around CPUID.
57845c39fb0SH. Peter Anvin 	 */
57945c39fb0SH. Peter Anvin 	asm volatile("cmpl %2,%1\n\t"
58045c39fb0SH. Peter Anvin 		     "jl 1f\n\t"
58145c39fb0SH. Peter Anvin 		     "cpuid\n"
58245c39fb0SH. Peter Anvin 		     "1:"
58345c39fb0SH. Peter Anvin 		     : "=a" (tmp)
58445c39fb0SH. Peter Anvin 		     : "rm" (boot_cpu_data.cpuid_level), "ri" (0), "0" (1)
585bb898558SAl Viro 		     : "ebx", "ecx", "edx", "memory");
58645c39fb0SH. Peter Anvin #else
58745c39fb0SH. Peter Anvin 	/*
58845c39fb0SH. Peter Anvin 	 * CPUID is a barrier to speculative execution.
58945c39fb0SH. Peter Anvin 	 * Prefetched instructions are automatically
59045c39fb0SH. Peter Anvin 	 * invalidated when modified.
59145c39fb0SH. Peter Anvin 	 */
59245c39fb0SH. Peter Anvin 	asm volatile("cpuid"
59345c39fb0SH. Peter Anvin 		     : "=a" (tmp)
59445c39fb0SH. Peter Anvin 		     : "0" (1)
59545c39fb0SH. Peter Anvin 		     : "ebx", "ecx", "edx", "memory");
59645c39fb0SH. Peter Anvin #endif
597bb898558SAl Viro }
598bb898558SAl Viro 
599bb898558SAl Viro extern void select_idle_routine(const struct cpuinfo_x86 *c);
60002c68a02SLen Brown extern void init_amd_e400_c1e_mask(void);
601bb898558SAl Viro 
602bb898558SAl Viro extern unsigned long		boot_option_idle_override;
60302c68a02SLen Brown extern bool			amd_e400_c1e_detected;
604bb898558SAl Viro 
605d1896049SThomas Renninger enum idle_boot_override {IDLE_NO_OVERRIDE=0, IDLE_HALT, IDLE_NOMWAIT,
60669fb3676SLen Brown 			 IDLE_POLL};
607d1896049SThomas Renninger 
608bb898558SAl Viro extern void enable_sep_cpu(void);
609bb898558SAl Viro extern int sysenter_setup(void);
610bb898558SAl Viro 
61129c84391SJan Kiszka extern void early_trap_init(void);
6128170e6beSH. Peter Anvin void early_trap_pf_init(void);
61329c84391SJan Kiszka 
614bb898558SAl Viro /* Defined in head.S */
615bb898558SAl Viro extern struct desc_ptr		early_gdt_descr;
616bb898558SAl Viro 
617bb898558SAl Viro extern void cpu_set_gdt(int);
618552be871SBrian Gerst extern void switch_to_new_gdt(int);
61911e3a840SJeremy Fitzhardinge extern void load_percpu_segment(int);
620bb898558SAl Viro extern void cpu_init(void);
621bb898558SAl Viro 
622c2724775SMarkus Metzger static inline unsigned long get_debugctlmsr(void)
623c2724775SMarkus Metzger {
624c2724775SMarkus Metzger 	unsigned long debugctlmsr = 0;
625c2724775SMarkus Metzger 
626c2724775SMarkus Metzger #ifndef CONFIG_X86_DEBUGCTLMSR
627c2724775SMarkus Metzger 	if (boot_cpu_data.x86 < 6)
628c2724775SMarkus Metzger 		return 0;
629c2724775SMarkus Metzger #endif
630c2724775SMarkus Metzger 	rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
631c2724775SMarkus Metzger 
632c2724775SMarkus Metzger 	return debugctlmsr;
633c2724775SMarkus Metzger }
634c2724775SMarkus Metzger 
635bb898558SAl Viro static inline void update_debugctlmsr(unsigned long debugctlmsr)
636bb898558SAl Viro {
637bb898558SAl Viro #ifndef CONFIG_X86_DEBUGCTLMSR
638bb898558SAl Viro 	if (boot_cpu_data.x86 < 6)
639bb898558SAl Viro 		return;
640bb898558SAl Viro #endif
641bb898558SAl Viro 	wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
642bb898558SAl Viro }
643bb898558SAl Viro 
6449bd1190aSOleg Nesterov extern void set_task_blockstep(struct task_struct *task, bool on);
6459bd1190aSOleg Nesterov 
646bb898558SAl Viro /*
647bb898558SAl Viro  * from system description table in BIOS. Mostly for MCA use, but
648bb898558SAl Viro  * others may find it useful:
649bb898558SAl Viro  */
650bb898558SAl Viro extern unsigned int		machine_id;
651bb898558SAl Viro extern unsigned int		machine_submodel_id;
652bb898558SAl Viro extern unsigned int		BIOS_revision;
653bb898558SAl Viro 
654bb898558SAl Viro /* Boot loader type from the setup header: */
655bb898558SAl Viro extern int			bootloader_type;
6565031296cSH. Peter Anvin extern int			bootloader_version;
657bb898558SAl Viro 
658bb898558SAl Viro extern char			ignore_fpu_irq;
659bb898558SAl Viro 
660bb898558SAl Viro #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
661bb898558SAl Viro #define ARCH_HAS_PREFETCHW
662bb898558SAl Viro #define ARCH_HAS_SPINLOCK_PREFETCH
663bb898558SAl Viro 
664bb898558SAl Viro #ifdef CONFIG_X86_32
665a930dc45SBorislav Petkov # define BASE_PREFETCH		""
666bb898558SAl Viro # define ARCH_HAS_PREFETCH
667bb898558SAl Viro #else
668a930dc45SBorislav Petkov # define BASE_PREFETCH		"prefetcht0 %P1"
669bb898558SAl Viro #endif
670bb898558SAl Viro 
671bb898558SAl Viro /*
672bb898558SAl Viro  * Prefetch instructions for Pentium III (+) and AMD Athlon (+)
673bb898558SAl Viro  *
674bb898558SAl Viro  * It's not worth to care about 3dnow prefetches for the K6
675bb898558SAl Viro  * because they are microcoded there and very slow.
676bb898558SAl Viro  */
677bb898558SAl Viro static inline void prefetch(const void *x)
678bb898558SAl Viro {
679a930dc45SBorislav Petkov 	alternative_input(BASE_PREFETCH, "prefetchnta %P1",
680bb898558SAl Viro 			  X86_FEATURE_XMM,
681a930dc45SBorislav Petkov 			  "m" (*(const char *)x));
682bb898558SAl Viro }
683bb898558SAl Viro 
684bb898558SAl Viro /*
685bb898558SAl Viro  * 3dnow prefetch to get an exclusive cache line.
686bb898558SAl Viro  * Useful for spinlocks to avoid one state transition in the
687bb898558SAl Viro  * cache coherency protocol:
688bb898558SAl Viro  */
689bb898558SAl Viro static inline void prefetchw(const void *x)
690bb898558SAl Viro {
691a930dc45SBorislav Petkov 	alternative_input(BASE_PREFETCH, "prefetchw %P1",
692a930dc45SBorislav Petkov 			  X86_FEATURE_3DNOWPREFETCH,
693a930dc45SBorislav Petkov 			  "m" (*(const char *)x));
694bb898558SAl Viro }
695bb898558SAl Viro 
696bb898558SAl Viro static inline void spin_lock_prefetch(const void *x)
697bb898558SAl Viro {
698bb898558SAl Viro 	prefetchw(x);
699bb898558SAl Viro }
700bb898558SAl Viro 
701d9e05cc5SAndy Lutomirski #define TOP_OF_INIT_STACK ((unsigned long)&init_stack + sizeof(init_stack) - \
702d9e05cc5SAndy Lutomirski 			   TOP_OF_KERNEL_STACK_PADDING)
703d9e05cc5SAndy Lutomirski 
704bb898558SAl Viro #ifdef CONFIG_X86_32
705bb898558SAl Viro /*
706bb898558SAl Viro  * User space process size: 3GB (default).
707bb898558SAl Viro  */
708bb898558SAl Viro #define TASK_SIZE		PAGE_OFFSET
709d9517346SIngo Molnar #define TASK_SIZE_MAX		TASK_SIZE
710bb898558SAl Viro #define STACK_TOP		TASK_SIZE
711bb898558SAl Viro #define STACK_TOP_MAX		STACK_TOP
712bb898558SAl Viro 
713bb898558SAl Viro #define INIT_THREAD  {							  \
714d9e05cc5SAndy Lutomirski 	.sp0			= TOP_OF_INIT_STACK,			  \
715bb898558SAl Viro 	.vm86_info		= NULL,					  \
716bb898558SAl Viro 	.sysenter_cs		= __KERNEL_CS,				  \
717bb898558SAl Viro 	.io_bitmap_ptr		= NULL,					  \
718bb898558SAl Viro }
719bb898558SAl Viro 
720bb898558SAl Viro extern unsigned long thread_saved_pc(struct task_struct *tsk);
721bb898558SAl Viro 
722bb898558SAl Viro /*
7235c39403eSDenys Vlasenko  * TOP_OF_KERNEL_STACK_PADDING reserves 8 bytes on top of the ring0 stack.
724bb898558SAl Viro  * This is necessary to guarantee that the entire "struct pt_regs"
725b595076aSUwe Kleine-König  * is accessible even if the CPU haven't stored the SS/ESP registers
726bb898558SAl Viro  * on the stack (interrupt gate does not save these registers
727bb898558SAl Viro  * when switching to the same priv ring).
728bb898558SAl Viro  * Therefore beware: accessing the ss/esp fields of the
729bb898558SAl Viro  * "struct pt_regs" is possible, but they may contain the
730bb898558SAl Viro  * completely wrong values.
731bb898558SAl Viro  */
732bb898558SAl Viro #define task_pt_regs(task) \
733bb898558SAl Viro ({									\
7345c39403eSDenys Vlasenko 	unsigned long __ptr = (unsigned long)task_stack_page(task);	\
7355c39403eSDenys Vlasenko 	__ptr += THREAD_SIZE - TOP_OF_KERNEL_STACK_PADDING;		\
7365c39403eSDenys Vlasenko 	((struct pt_regs *)__ptr) - 1;					\
737bb898558SAl Viro })
738bb898558SAl Viro 
739bb898558SAl Viro #define KSTK_ESP(task)		(task_pt_regs(task)->sp)
740bb898558SAl Viro 
741bb898558SAl Viro #else
742bb898558SAl Viro /*
74307114f0fSAndy Lutomirski  * User space process size. 47bits minus one guard page.  The guard
74407114f0fSAndy Lutomirski  * page is necessary on Intel CPUs: if a SYSCALL instruction is at
74507114f0fSAndy Lutomirski  * the highest possible canonical userspace address, then that
74607114f0fSAndy Lutomirski  * syscall will enter the kernel with a non-canonical return
74707114f0fSAndy Lutomirski  * address, and SYSRET will explode dangerously.  We avoid this
74807114f0fSAndy Lutomirski  * particular problem by preventing anything from being mapped
74907114f0fSAndy Lutomirski  * at the maximum canonical address.
750bb898558SAl Viro  */
751d9517346SIngo Molnar #define TASK_SIZE_MAX	((1UL << 47) - PAGE_SIZE)
752bb898558SAl Viro 
753bb898558SAl Viro /* This decides where the kernel will search for a free chunk of vm
754bb898558SAl Viro  * space during mmap's.
755bb898558SAl Viro  */
756bb898558SAl Viro #define IA32_PAGE_OFFSET	((current->personality & ADDR_LIMIT_3GB) ? \
757bb898558SAl Viro 					0xc0000000 : 0xFFFFe000)
758bb898558SAl Viro 
7596bd33008SH. Peter Anvin #define TASK_SIZE		(test_thread_flag(TIF_ADDR32) ? \
760d9517346SIngo Molnar 					IA32_PAGE_OFFSET : TASK_SIZE_MAX)
7616bd33008SH. Peter Anvin #define TASK_SIZE_OF(child)	((test_tsk_thread_flag(child, TIF_ADDR32)) ? \
762d9517346SIngo Molnar 					IA32_PAGE_OFFSET : TASK_SIZE_MAX)
763bb898558SAl Viro 
764bb898558SAl Viro #define STACK_TOP		TASK_SIZE
765d9517346SIngo Molnar #define STACK_TOP_MAX		TASK_SIZE_MAX
766bb898558SAl Viro 
767bb898558SAl Viro #define INIT_THREAD  { \
768d9e05cc5SAndy Lutomirski 	.sp0 = TOP_OF_INIT_STACK \
769bb898558SAl Viro }
770bb898558SAl Viro 
771bb898558SAl Viro /*
772bb898558SAl Viro  * Return saved PC of a blocked thread.
773bb898558SAl Viro  * What is this good for? it will be always the scheduler or ret_from_fork.
774bb898558SAl Viro  */
775bb898558SAl Viro #define thread_saved_pc(t)	(*(unsigned long *)((t)->thread.sp - 8))
776bb898558SAl Viro 
777bb898558SAl Viro #define task_pt_regs(tsk)	((struct pt_regs *)(tsk)->thread.sp0 - 1)
77889240ba0SStefani Seibold extern unsigned long KSTK_ESP(struct task_struct *task);
779d046ff8bSH. J. Lu 
780bb898558SAl Viro #endif /* CONFIG_X86_64 */
781bb898558SAl Viro 
782bb898558SAl Viro extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
783bb898558SAl Viro 					       unsigned long new_sp);
784bb898558SAl Viro 
785bb898558SAl Viro /*
786bb898558SAl Viro  * This decides where the kernel will search for a free chunk of vm
787bb898558SAl Viro  * space during mmap's.
788bb898558SAl Viro  */
789bb898558SAl Viro #define TASK_UNMAPPED_BASE	(PAGE_ALIGN(TASK_SIZE / 3))
790bb898558SAl Viro 
791bb898558SAl Viro #define KSTK_EIP(task)		(task_pt_regs(task)->ip)
792bb898558SAl Viro 
793bb898558SAl Viro /* Get/set a process' ability to use the timestamp counter instruction */
794bb898558SAl Viro #define GET_TSC_CTL(adr)	get_tsc_mode((adr))
795bb898558SAl Viro #define SET_TSC_CTL(val)	set_tsc_mode((val))
796bb898558SAl Viro 
797bb898558SAl Viro extern int get_tsc_mode(unsigned long adr);
798bb898558SAl Viro extern int set_tsc_mode(unsigned int val);
799bb898558SAl Viro 
800fe3d197fSDave Hansen /* Register/unregister a process' MPX related resource */
801fe3d197fSDave Hansen #define MPX_ENABLE_MANAGEMENT(tsk)	mpx_enable_management((tsk))
802fe3d197fSDave Hansen #define MPX_DISABLE_MANAGEMENT(tsk)	mpx_disable_management((tsk))
803fe3d197fSDave Hansen 
804fe3d197fSDave Hansen #ifdef CONFIG_X86_INTEL_MPX
805fe3d197fSDave Hansen extern int mpx_enable_management(struct task_struct *tsk);
806fe3d197fSDave Hansen extern int mpx_disable_management(struct task_struct *tsk);
807fe3d197fSDave Hansen #else
808fe3d197fSDave Hansen static inline int mpx_enable_management(struct task_struct *tsk)
809fe3d197fSDave Hansen {
810fe3d197fSDave Hansen 	return -EINVAL;
811fe3d197fSDave Hansen }
812fe3d197fSDave Hansen static inline int mpx_disable_management(struct task_struct *tsk)
813fe3d197fSDave Hansen {
814fe3d197fSDave Hansen 	return -EINVAL;
815fe3d197fSDave Hansen }
816fe3d197fSDave Hansen #endif /* CONFIG_X86_INTEL_MPX */
817fe3d197fSDave Hansen 
8188b84c8dfSDaniel J Blueman extern u16 amd_get_nb_id(int cpu);
8196a812691SAndreas Herrmann 
82096e39ac0SJason Wang static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
82196e39ac0SJason Wang {
82296e39ac0SJason Wang 	uint32_t base, eax, signature[3];
82396e39ac0SJason Wang 
82496e39ac0SJason Wang 	for (base = 0x40000000; base < 0x40010000; base += 0x100) {
82596e39ac0SJason Wang 		cpuid(base, &eax, &signature[0], &signature[1], &signature[2]);
82696e39ac0SJason Wang 
82796e39ac0SJason Wang 		if (!memcmp(sig, signature, 12) &&
82896e39ac0SJason Wang 		    (leaves == 0 || ((eax - base) >= leaves)))
82996e39ac0SJason Wang 			return base;
83096e39ac0SJason Wang 	}
83196e39ac0SJason Wang 
83296e39ac0SJason Wang 	return 0;
83396e39ac0SJason Wang }
83496e39ac0SJason Wang 
835f05e798aSDavid Howells extern unsigned long arch_align_stack(unsigned long sp);
836f05e798aSDavid Howells extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
837f05e798aSDavid Howells 
838f05e798aSDavid Howells void default_idle(void);
8396a377ddcSLen Brown #ifdef	CONFIG_XEN
8406a377ddcSLen Brown bool xen_set_default_idle(void);
8416a377ddcSLen Brown #else
8426a377ddcSLen Brown #define xen_set_default_idle 0
8436a377ddcSLen Brown #endif
844f05e798aSDavid Howells 
845f05e798aSDavid Howells void stop_this_cpu(void *dummy);
8464d067d8eSBorislav Petkov void df_debug(struct pt_regs *regs, long error_code);
8471965aae3SH. Peter Anvin #endif /* _ASM_X86_PROCESSOR_H */
848