Merge branch 'writeback-for-next' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / arch / x86 / include / asm / processor.h
CommitLineData
1965aae3
PA
1#ifndef _ASM_X86_PROCESSOR_H
2#define _ASM_X86_PROCESSOR_H
c758ecf6 3
053de044
GOC
4#include <asm/processor-flags.h>
5
683e0253
GOC
6/* Forward declaration, a strange C thing */
7struct task_struct;
8struct mm_struct;
9
2f66dcc9
GOC
10#include <asm/vm86.h>
11#include <asm/math_emu.h>
12#include <asm/segment.h>
2f66dcc9
GOC
13#include <asm/types.h>
14#include <asm/sigcontext.h>
15#include <asm/current.h>
16#include <asm/cpufeature.h>
2f66dcc9 17#include <asm/page.h>
54321d94 18#include <asm/pgtable_types.h>
5300db88 19#include <asm/percpu.h>
2f66dcc9
GOC
20#include <asm/msr.h>
21#include <asm/desc_defs.h>
bd61643e 22#include <asm/nops.h>
f05e798a 23#include <asm/special_insns.h>
4d46a89e 24
2f66dcc9 25#include <linux/personality.h>
5300db88
GOC
26#include <linux/cpumask.h>
27#include <linux/cache.h>
2f66dcc9 28#include <linux/threads.h>
5cbc19a9 29#include <linux/math64.h>
2f66dcc9 30#include <linux/init.h>
faa4602e 31#include <linux/err.h>
f05e798a
DH
32#include <linux/irqflags.h>
33
34/*
35 * We handle most unaligned accesses in hardware. On the other hand
36 * unaligned DMA can be quite expensive on some Nehalem processors.
37 *
38 * Based on this we disable the IP header alignment in network drivers.
39 */
40#define NET_IP_ALIGN 0
c72dcf83 41
b332828c 42#define HBP_NUM 4
0ccb8acc
GOC
43/*
44 * Default implementation of macro that returns current
45 * instruction pointer ("program counter").
46 */
47static inline void *current_text_addr(void)
48{
49 void *pc;
4d46a89e
IM
50
51 asm volatile("mov $1f, %0; 1:":"=r" (pc));
52
0ccb8acc
GOC
53 return pc;
54}
55
dbcb4660 56#ifdef CONFIG_X86_VSMP
4d46a89e
IM
57# define ARCH_MIN_TASKALIGN (1 << INTERNODE_CACHE_SHIFT)
58# define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT)
dbcb4660 59#else
4d46a89e
IM
60# define ARCH_MIN_TASKALIGN 16
61# define ARCH_MIN_MMSTRUCT_ALIGN 0
dbcb4660
GOC
62#endif
63
e0ba94f1
AS
64enum tlb_infos {
65 ENTRIES,
66 NR_INFO
67};
68
69extern u16 __read_mostly tlb_lli_4k[NR_INFO];
70extern u16 __read_mostly tlb_lli_2m[NR_INFO];
71extern u16 __read_mostly tlb_lli_4m[NR_INFO];
72extern u16 __read_mostly tlb_lld_4k[NR_INFO];
73extern u16 __read_mostly tlb_lld_2m[NR_INFO];
74extern u16 __read_mostly tlb_lld_4m[NR_INFO];
c4211f42
AS
75extern s8 __read_mostly tlb_flushall_shift;
76
5300db88
GOC
77/*
78 * CPU type and hardware bug flags. Kept separately for each CPU.
79 * Members of this structure are referenced in head.S, so think twice
80 * before touching them. [mj]
81 */
82
83struct cpuinfo_x86 {
4d46a89e
IM
84 __u8 x86; /* CPU family */
85 __u8 x86_vendor; /* CPU vendor */
86 __u8 x86_model;
87 __u8 x86_mask;
5300db88 88#ifdef CONFIG_X86_32
4d46a89e
IM
89 char wp_works_ok; /* It doesn't on 386's */
90
91 /* Problems on some 486Dx4's and old 386's: */
92 char hlt_works_ok;
93 char hard_math;
94 char rfu;
95 char fdiv_bug;
96 char f00f_bug;
97 char coma_bug;
98 char pad0;
5300db88 99#else
4d46a89e 100 /* Number of 4K pages in DTLB/ITLB combined(in pages): */
b1882e68 101 int x86_tlbsize;
13c6c532 102#endif
4d46a89e
IM
103 __u8 x86_virt_bits;
104 __u8 x86_phys_bits;
105 /* CPUID returned core id bits: */
106 __u8 x86_coreid_bits;
107 /* Max extended CPUID function supported: */
108 __u32 extended_cpuid_level;
4d46a89e
IM
109 /* Maximum supported CPUID level, -1=no CPUID: */
110 int cpuid_level;
111 __u32 x86_capability[NCAPINTS];
112 char x86_vendor_id[16];
113 char x86_model_id[64];
114 /* in KB - valid for CPUS which support this call: */
115 int x86_cache_size;
116 int x86_cache_alignment; /* In bytes */
117 int x86_power;
118 unsigned long loops_per_jiffy;
4d46a89e
IM
119 /* cpuid returned max cores value: */
120 u16 x86_max_cores;
121 u16 apicid;
01aaea1a 122 u16 initial_apicid;
4d46a89e 123 u16 x86_clflush_size;
4d46a89e
IM
124 /* number of cores as seen by the OS: */
125 u16 booted_cores;
126 /* Physical processor id: */
127 u16 phys_proc_id;
128 /* Core id: */
129 u16 cpu_core_id;
6057b4d3
AH
130 /* Compute unit id */
131 u8 compute_unit_id;
4d46a89e
IM
132 /* Index into per_cpu list: */
133 u16 cpu_index;
506ed6b5 134 u32 microcode;
5300db88
GOC
135} __attribute__((__aligned__(SMP_CACHE_BYTES)));
136
4d46a89e
IM
137#define X86_VENDOR_INTEL 0
138#define X86_VENDOR_CYRIX 1
139#define X86_VENDOR_AMD 2
140#define X86_VENDOR_UMC 3
4d46a89e
IM
141#define X86_VENDOR_CENTAUR 5
142#define X86_VENDOR_TRANSMETA 7
143#define X86_VENDOR_NSC 8
144#define X86_VENDOR_NUM 9
145
146#define X86_VENDOR_UNKNOWN 0xff
5300db88 147
1a53905a
GOC
148/*
149 * capabilities of CPUs
150 */
4d46a89e
IM
151extern struct cpuinfo_x86 boot_cpu_data;
152extern struct cpuinfo_x86 new_cpu_data;
153
154extern struct tss_struct doublefault_tss;
3e0c3737
YL
155extern __u32 cpu_caps_cleared[NCAPINTS];
156extern __u32 cpu_caps_set[NCAPINTS];
5300db88
GOC
157
158#ifdef CONFIG_SMP
9b8de747 159DECLARE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);
5300db88 160#define cpu_data(cpu) per_cpu(cpu_info, cpu)
5300db88 161#else
7b543a53 162#define cpu_info boot_cpu_data
5300db88 163#define cpu_data(cpu) boot_cpu_data
5300db88
GOC
164#endif
165
1c6c727d
JS
166extern const struct seq_operations cpuinfo_op;
167
3d3f487c
GC
168static inline int hlt_works(int cpu)
169{
170#ifdef CONFIG_X86_32
171 return cpu_data(cpu).hlt_works_ok;
172#else
173 return 1;
174#endif
175}
176
4d46a89e
IM
177#define cache_line_size() (boot_cpu_data.x86_cache_alignment)
178
179extern void cpu_detect(struct cpuinfo_x86 *c);
1a53905a 180
8fd329a1
JS
181extern struct pt_regs *idle_regs(struct pt_regs *);
182
f580366f 183extern void early_cpu_init(void);
1a53905a
GOC
184extern void identify_boot_cpu(void);
185extern void identify_secondary_cpu(struct cpuinfo_x86 *);
5300db88 186extern void print_cpu_info(struct cpuinfo_x86 *);
21c3fcf3 187void print_cpu_msr(struct cpuinfo_x86 *);
5300db88
GOC
188extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
189extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
190extern unsigned short num_cache_leaves;
191
bbb65d2d 192extern void detect_extended_topology(struct cpuinfo_x86 *c);
1a53905a 193extern void detect_ht(struct cpuinfo_x86 *c);
1a53905a 194
c758ecf6 195static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
4d46a89e 196 unsigned int *ecx, unsigned int *edx)
c758ecf6
GOC
197{
198 /* ecx is often an input as well as an output. */
45a94d7c 199 asm volatile("cpuid"
cca2e6f8
JP
200 : "=a" (*eax),
201 "=b" (*ebx),
202 "=c" (*ecx),
203 "=d" (*edx)
506ed6b5
AK
204 : "0" (*eax), "2" (*ecx)
205 : "memory");
c758ecf6
GOC
206}
207
c72dcf83
GOC
208static inline void load_cr3(pgd_t *pgdir)
209{
210 write_cr3(__pa(pgdir));
211}
c758ecf6 212
ca241c75
GOC
213#ifdef CONFIG_X86_32
214/* This is the TSS defined by the hardware. */
215struct x86_hw_tss {
4d46a89e
IM
216 unsigned short back_link, __blh;
217 unsigned long sp0;
218 unsigned short ss0, __ss0h;
219 unsigned long sp1;
220 /* ss1 caches MSR_IA32_SYSENTER_CS: */
221 unsigned short ss1, __ss1h;
222 unsigned long sp2;
223 unsigned short ss2, __ss2h;
224 unsigned long __cr3;
225 unsigned long ip;
226 unsigned long flags;
227 unsigned long ax;
228 unsigned long cx;
229 unsigned long dx;
230 unsigned long bx;
231 unsigned long sp;
232 unsigned long bp;
233 unsigned long si;
234 unsigned long di;
235 unsigned short es, __esh;
236 unsigned short cs, __csh;
237 unsigned short ss, __ssh;
238 unsigned short ds, __dsh;
239 unsigned short fs, __fsh;
240 unsigned short gs, __gsh;
241 unsigned short ldt, __ldth;
242 unsigned short trace;
243 unsigned short io_bitmap_base;
244
ca241c75
GOC
245} __attribute__((packed));
246#else
247struct x86_hw_tss {
4d46a89e
IM
248 u32 reserved1;
249 u64 sp0;
250 u64 sp1;
251 u64 sp2;
252 u64 reserved2;
253 u64 ist[7];
254 u32 reserved3;
255 u32 reserved4;
256 u16 reserved5;
257 u16 io_bitmap_base;
258
ca241c75
GOC
259} __attribute__((packed)) ____cacheline_aligned;
260#endif
261
262/*
4d46a89e 263 * IO-bitmap sizes:
ca241c75 264 */
4d46a89e
IM
265#define IO_BITMAP_BITS 65536
266#define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
267#define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
268#define IO_BITMAP_OFFSET offsetof(struct tss_struct, io_bitmap)
269#define INVALID_IO_BITMAP_OFFSET 0x8000
ca241c75
GOC
270
271struct tss_struct {
4d46a89e
IM
272 /*
273 * The hardware state:
274 */
275 struct x86_hw_tss x86_tss;
ca241c75
GOC
276
277 /*
278 * The extra 1 is there because the CPU will access an
279 * additional byte beyond the end of the IO permission
280 * bitmap. The extra byte must be all 1 bits, and must
281 * be within the limit.
282 */
4d46a89e 283 unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
4d46a89e 284
ca241c75 285 /*
4d46a89e 286 * .. and then another 0x100 bytes for the emergency kernel stack:
ca241c75 287 */
4d46a89e
IM
288 unsigned long stack[64];
289
84e65b0a 290} ____cacheline_aligned;
ca241c75 291
9b8de747 292DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
ca241c75 293
4d46a89e
IM
294/*
295 * Save the original ist values for checking stack pointers during debugging
296 */
1a53905a 297struct orig_ist {
4d46a89e 298 unsigned long ist[7];
1a53905a
GOC
299};
300
99f8ecdf 301#define MXCSR_DEFAULT 0x1f80
46265df0 302
99f8ecdf 303struct i387_fsave_struct {
ca9cda2f
IM
304 u32 cwd; /* FPU Control Word */
305 u32 swd; /* FPU Status Word */
306 u32 twd; /* FPU Tag Word */
307 u32 fip; /* FPU IP Offset */
308 u32 fcs; /* FPU IP Selector */
309 u32 foo; /* FPU Operand Pointer Offset */
310 u32 fos; /* FPU Operand Pointer Selector */
311
312 /* 8*10 bytes for each FP-reg = 80 bytes: */
4d46a89e 313 u32 st_space[20];
ca9cda2f
IM
314
315 /* Software status information [not touched by FSAVE ]: */
4d46a89e 316 u32 status;
46265df0
GOC
317};
318
46265df0 319struct i387_fxsave_struct {
ca9cda2f
IM
320 u16 cwd; /* Control Word */
321 u16 swd; /* Status Word */
322 u16 twd; /* Tag Word */
323 u16 fop; /* Last Instruction Opcode */
99f8ecdf
RM
324 union {
325 struct {
ca9cda2f
IM
326 u64 rip; /* Instruction Pointer */
327 u64 rdp; /* Data Pointer */
99f8ecdf
RM
328 };
329 struct {
ca9cda2f
IM
330 u32 fip; /* FPU IP Offset */
331 u32 fcs; /* FPU IP Selector */
332 u32 foo; /* FPU Operand Offset */
333 u32 fos; /* FPU Operand Selector */
99f8ecdf
RM
334 };
335 };
ca9cda2f
IM
336 u32 mxcsr; /* MXCSR Register State */
337 u32 mxcsr_mask; /* MXCSR Mask */
338
339 /* 8*16 bytes for each FP-reg = 128 bytes: */
4d46a89e 340 u32 st_space[32];
ca9cda2f
IM
341
342 /* 16*16 bytes for each XMM-reg = 256 bytes: */
4d46a89e 343 u32 xmm_space[64];
ca9cda2f 344
bdd8caba
SS
345 u32 padding[12];
346
347 union {
348 u32 padding1[12];
349 u32 sw_reserved[12];
350 };
4d46a89e 351
46265df0
GOC
352} __attribute__((aligned(16)));
353
99f8ecdf 354struct i387_soft_struct {
4d46a89e
IM
355 u32 cwd;
356 u32 swd;
357 u32 twd;
358 u32 fip;
359 u32 fcs;
360 u32 foo;
361 u32 fos;
362 /* 8*10 bytes for each FP-reg = 80 bytes: */
363 u32 st_space[20];
364 u8 ftop;
365 u8 changed;
366 u8 lookahead;
367 u8 no_update;
368 u8 rm;
369 u8 alimit;
ae6af41f 370 struct math_emu_info *info;
4d46a89e 371 u32 entry_eip;
99f8ecdf
RM
372};
373
a30469e7
SS
374struct ymmh_struct {
375 /* 16 * 16 bytes for each YMMH-reg = 256 bytes */
376 u32 ymmh_space[64];
377};
378
dc1e35c6
SS
379struct xsave_hdr_struct {
380 u64 xstate_bv;
381 u64 reserved1[2];
382 u64 reserved2[5];
383} __attribute__((packed));
384
385struct xsave_struct {
386 struct i387_fxsave_struct i387;
387 struct xsave_hdr_struct xsave_hdr;
a30469e7 388 struct ymmh_struct ymmh;
dc1e35c6
SS
389 /* new processor state extensions will go here */
390} __attribute__ ((packed, aligned (64)));
391
61c4628b 392union thread_xstate {
99f8ecdf 393 struct i387_fsave_struct fsave;
46265df0 394 struct i387_fxsave_struct fxsave;
4d46a89e 395 struct i387_soft_struct soft;
b359e8a4 396 struct xsave_struct xsave;
46265df0
GOC
397};
398
86603283 399struct fpu {
7e16838d
LT
400 unsigned int last_cpu;
401 unsigned int has_fpu;
86603283
AK
402 union thread_xstate *state;
403};
404
fe676203 405#ifdef CONFIG_X86_64
2f66dcc9 406DECLARE_PER_CPU(struct orig_ist, orig_ist);
26f80bd6 407
947e76cd
BG
408union irq_stack_union {
409 char irq_stack[IRQ_STACK_SIZE];
410 /*
411 * GCC hardcodes the stack canary as %gs:40. Since the
412 * irq_stack is the object at %gs:0, we reserve the bottom
413 * 48 bytes of the irq stack for the canary.
414 */
415 struct {
416 char gs_base[40];
417 unsigned long stack_canary;
418 };
419};
420
9b8de747 421DECLARE_PER_CPU_FIRST(union irq_stack_union, irq_stack_union);
2add8e23
BG
422DECLARE_INIT_PER_CPU(irq_stack_union);
423
26f80bd6 424DECLARE_PER_CPU(char *, irq_stack_ptr);
9766cdbc 425DECLARE_PER_CPU(unsigned int, irq_count);
9766cdbc 426extern asmlinkage void ignore_sysret(void);
60a5317f
TH
427#else /* X86_64 */
428#ifdef CONFIG_CC_STACKPROTECTOR
1ea0d14e
JF
429/*
430 * Make sure stack canary segment base is cached-aligned:
431 * "For Intel Atom processors, avoid non zero segment base address
432 * that is not aligned to cache line boundary at all cost."
433 * (Optim Ref Manual Assembly/Compiler Coding Rule 15.)
434 */
435struct stack_canary {
436 char __pad[20]; /* canary at %gs:20 */
437 unsigned long canary;
438};
53f82452 439DECLARE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);
96a388de 440#endif
60a5317f 441#endif /* X86_64 */
c758ecf6 442
61c4628b 443extern unsigned int xstate_size;
aa283f49
SS
444extern void free_thread_xstate(struct task_struct *);
445extern struct kmem_cache *task_xstate_cachep;
683e0253 446
24f1e32c
FW
447struct perf_event;
448
cb38d377 449struct thread_struct {
4d46a89e
IM
450 /* Cached TLS descriptors: */
451 struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
452 unsigned long sp0;
453 unsigned long sp;
cb38d377 454#ifdef CONFIG_X86_32
4d46a89e 455 unsigned long sysenter_cs;
cb38d377 456#else
4d46a89e
IM
457 unsigned long usersp; /* Copy from PDA */
458 unsigned short es;
459 unsigned short ds;
460 unsigned short fsindex;
461 unsigned short gsindex;
cb38d377 462#endif
0c23590f 463#ifdef CONFIG_X86_32
4d46a89e 464 unsigned long ip;
0c23590f 465#endif
d756f4ad 466#ifdef CONFIG_X86_64
4d46a89e 467 unsigned long fs;
d756f4ad 468#endif
4d46a89e 469 unsigned long gs;
24f1e32c
FW
470 /* Save middle states of ptrace breakpoints */
471 struct perf_event *ptrace_bps[HBP_NUM];
472 /* Debug status used for traps, single steps, etc... */
473 unsigned long debugreg6;
326264a0
FW
474 /* Keep track of the exact dr7 value set by the user */
475 unsigned long ptrace_dr7;
4d46a89e
IM
476 /* Fault info: */
477 unsigned long cr2;
51e7dc70 478 unsigned long trap_nr;
4d46a89e 479 unsigned long error_code;
61c4628b 480 /* floating point and extended processor state */
86603283 481 struct fpu fpu;
cb38d377 482#ifdef CONFIG_X86_32
4d46a89e 483 /* Virtual 86 mode info */
cb38d377
GOC
484 struct vm86_struct __user *vm86_info;
485 unsigned long screen_bitmap;
4d46a89e
IM
486 unsigned long v86flags;
487 unsigned long v86mask;
488 unsigned long saved_sp0;
489 unsigned int saved_fs;
490 unsigned int saved_gs;
cb38d377 491#endif
4d46a89e
IM
492 /* IO permissions: */
493 unsigned long *io_bitmap_ptr;
494 unsigned long iopl;
495 /* Max allowed port in the bitmap, in bytes: */
496 unsigned io_bitmap_max;
cb38d377
GOC
497};
498
62d7d7ed
GOC
499/*
500 * Set IOPL bits in EFLAGS from given mask
501 */
502static inline void native_set_iopl_mask(unsigned mask)
503{
504#ifdef CONFIG_X86_32
505 unsigned int reg;
4d46a89e 506
cca2e6f8
JP
507 asm volatile ("pushfl;"
508 "popl %0;"
509 "andl %1, %0;"
510 "orl %2, %0;"
511 "pushl %0;"
512 "popfl"
513 : "=&r" (reg)
514 : "i" (~X86_EFLAGS_IOPL), "r" (mask));
62d7d7ed
GOC
515#endif
516}
517
4d46a89e
IM
518static inline void
519native_load_sp0(struct tss_struct *tss, struct thread_struct *thread)
7818a1e0
GOC
520{
521 tss->x86_tss.sp0 = thread->sp0;
522#ifdef CONFIG_X86_32
4d46a89e 523 /* Only happens when SEP is enabled, no need to test "SEP"arately: */
7818a1e0
GOC
524 if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) {
525 tss->x86_tss.ss1 = thread->sysenter_cs;
526 wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
527 }
528#endif
529}
1b46cbe0 530
e801f864
GOC
531static inline void native_swapgs(void)
532{
533#ifdef CONFIG_X86_64
534 asm volatile("swapgs" ::: "memory");
535#endif
536}
537
7818a1e0
GOC
538#ifdef CONFIG_PARAVIRT
539#include <asm/paravirt.h>
540#else
4d46a89e
IM
541#define __cpuid native_cpuid
542#define paravirt_enabled() 0
1b46cbe0 543
cca2e6f8
JP
544static inline void load_sp0(struct tss_struct *tss,
545 struct thread_struct *thread)
7818a1e0
GOC
546{
547 native_load_sp0(tss, thread);
548}
549
62d7d7ed 550#define set_iopl_mask native_set_iopl_mask
1b46cbe0
GOC
551#endif /* CONFIG_PARAVIRT */
552
553/*
554 * Save the cr4 feature set we're using (ie
555 * Pentium 4MB enable and PPro Global page
556 * enable), so that any CPU's that boot up
557 * after us can get the correct flags.
558 */
cda846f1
JS
559extern unsigned long mmu_cr4_features;
560extern u32 *trampoline_cr4_features;
1b46cbe0
GOC
561
562static inline void set_in_cr4(unsigned long mask)
563{
2df7a6e9 564 unsigned long cr4;
4d46a89e 565
1b46cbe0 566 mmu_cr4_features |= mask;
cda846f1
JS
567 if (trampoline_cr4_features)
568 *trampoline_cr4_features = mmu_cr4_features;
1b46cbe0
GOC
569 cr4 = read_cr4();
570 cr4 |= mask;
571 write_cr4(cr4);
572}
573
574static inline void clear_in_cr4(unsigned long mask)
575{
2df7a6e9 576 unsigned long cr4;
4d46a89e 577
1b46cbe0 578 mmu_cr4_features &= ~mask;
cda846f1
JS
579 if (trampoline_cr4_features)
580 *trampoline_cr4_features = mmu_cr4_features;
1b46cbe0
GOC
581 cr4 = read_cr4();
582 cr4 &= ~mask;
583 write_cr4(cr4);
584}
585
fc87e906 586typedef struct {
4d46a89e 587 unsigned long seg;
fc87e906
GOC
588} mm_segment_t;
589
590
683e0253
GOC
591/* Free all resources held by a thread. */
592extern void release_thread(struct task_struct *);
593
683e0253 594unsigned long get_wchan(struct task_struct *p);
c758ecf6
GOC
595
596/*
597 * Generic CPUID function
598 * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
599 * resulting in stale register contents being returned.
600 */
601static inline void cpuid(unsigned int op,
602 unsigned int *eax, unsigned int *ebx,
603 unsigned int *ecx, unsigned int *edx)
604{
605 *eax = op;
606 *ecx = 0;
607 __cpuid(eax, ebx, ecx, edx);
608}
609
610/* Some CPUID calls want 'count' to be placed in ecx */
611static inline void cpuid_count(unsigned int op, int count,
612 unsigned int *eax, unsigned int *ebx,
613 unsigned int *ecx, unsigned int *edx)
614{
615 *eax = op;
616 *ecx = count;
617 __cpuid(eax, ebx, ecx, edx);
618}
619
620/*
621 * CPUID functions returning a single datum
622 */
623static inline unsigned int cpuid_eax(unsigned int op)
624{
625 unsigned int eax, ebx, ecx, edx;
626
627 cpuid(op, &eax, &ebx, &ecx, &edx);
4d46a89e 628
c758ecf6
GOC
629 return eax;
630}
4d46a89e 631
c758ecf6
GOC
632static inline unsigned int cpuid_ebx(unsigned int op)
633{
634 unsigned int eax, ebx, ecx, edx;
635
636 cpuid(op, &eax, &ebx, &ecx, &edx);
4d46a89e 637
c758ecf6
GOC
638 return ebx;
639}
4d46a89e 640
c758ecf6
GOC
641static inline unsigned int cpuid_ecx(unsigned int op)
642{
643 unsigned int eax, ebx, ecx, edx;
644
645 cpuid(op, &eax, &ebx, &ecx, &edx);
4d46a89e 646
c758ecf6
GOC
647 return ecx;
648}
4d46a89e 649
c758ecf6
GOC
650static inline unsigned int cpuid_edx(unsigned int op)
651{
652 unsigned int eax, ebx, ecx, edx;
653
654 cpuid(op, &eax, &ebx, &ecx, &edx);
4d46a89e 655
c758ecf6
GOC
656 return edx;
657}
658
683e0253
GOC
659/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
660static inline void rep_nop(void)
661{
cca2e6f8 662 asm volatile("rep; nop" ::: "memory");
683e0253
GOC
663}
664
4d46a89e
IM
665static inline void cpu_relax(void)
666{
667 rep_nop();
668}
669
5367b688 670/* Stop speculative execution and prefetching of modified code. */
683e0253
GOC
671static inline void sync_core(void)
672{
673 int tmp;
4d46a89e 674
5367b688
BH
675#if defined(CONFIG_M386) || defined(CONFIG_M486)
676 if (boot_cpu_data.x86 < 5)
677 /* There is no speculative execution.
678 * jmp is a barrier to prefetching. */
679 asm volatile("jmp 1f\n1:\n" ::: "memory");
680 else
681#endif
682 /* cpuid is a barrier to speculative execution.
683 * Prefetched instructions are automatically
684 * invalidated when modified. */
685 asm volatile("cpuid" : "=a" (tmp) : "0" (1)
686 : "ebx", "ecx", "edx", "memory");
683e0253
GOC
687}
688
cca2e6f8
JP
689static inline void __monitor(const void *eax, unsigned long ecx,
690 unsigned long edx)
683e0253 691{
4d46a89e 692 /* "monitor %eax, %ecx, %edx;" */
cca2e6f8
JP
693 asm volatile(".byte 0x0f, 0x01, 0xc8;"
694 :: "a" (eax), "c" (ecx), "d"(edx));
683e0253
GOC
695}
696
697static inline void __mwait(unsigned long eax, unsigned long ecx)
698{
4d46a89e 699 /* "mwait %eax, %ecx;" */
cca2e6f8
JP
700 asm volatile(".byte 0x0f, 0x01, 0xc9;"
701 :: "a" (eax), "c" (ecx));
683e0253
GOC
702}
703
704static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
705{
7f424a8b 706 trace_hardirqs_on();
4d46a89e 707 /* "mwait %eax, %ecx;" */
cca2e6f8
JP
708 asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
709 :: "a" (eax), "c" (ecx));
683e0253
GOC
710}
711
683e0253 712extern void select_idle_routine(const struct cpuinfo_x86 *c);
02c68a02 713extern void init_amd_e400_c1e_mask(void);
683e0253 714
4d46a89e 715extern unsigned long boot_option_idle_override;
02c68a02 716extern bool amd_e400_c1e_detected;
683e0253 717
d1896049
TR
718enum idle_boot_override {IDLE_NO_OVERRIDE=0, IDLE_HALT, IDLE_NOMWAIT,
719 IDLE_POLL, IDLE_FORCE_MWAIT};
720
1a53905a
GOC
721extern void enable_sep_cpu(void);
722extern int sysenter_setup(void);
723
29c84391
JK
724extern void early_trap_init(void);
725
1a53905a 726/* Defined in head.S */
4d46a89e 727extern struct desc_ptr early_gdt_descr;
1a53905a
GOC
728
729extern void cpu_set_gdt(int);
552be871 730extern void switch_to_new_gdt(int);
11e3a840 731extern void load_percpu_segment(int);
1a53905a 732extern void cpu_init(void);
1a53905a 733
c2724775
MM
734static inline unsigned long get_debugctlmsr(void)
735{
ea8e61b7 736 unsigned long debugctlmsr = 0;
c2724775
MM
737
738#ifndef CONFIG_X86_DEBUGCTLMSR
739 if (boot_cpu_data.x86 < 6)
740 return 0;
741#endif
742 rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
743
ea8e61b7 744 return debugctlmsr;
c2724775
MM
745}
746
5b0e5084
JB
747static inline void update_debugctlmsr(unsigned long debugctlmsr)
748{
749#ifndef CONFIG_X86_DEBUGCTLMSR
750 if (boot_cpu_data.x86 < 6)
751 return;
752#endif
753 wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
754}
755
9bd1190a
ON
756extern void set_task_blockstep(struct task_struct *task, bool on);
757
4d46a89e
IM
758/*
759 * from system description table in BIOS. Mostly for MCA use, but
760 * others may find it useful:
761 */
762extern unsigned int machine_id;
763extern unsigned int machine_submodel_id;
764extern unsigned int BIOS_revision;
1a53905a 765
4d46a89e
IM
766/* Boot loader type from the setup header: */
767extern int bootloader_type;
5031296c 768extern int bootloader_version;
1a53905a 769
4d46a89e 770extern char ignore_fpu_irq;
683e0253
GOC
771
772#define HAVE_ARCH_PICK_MMAP_LAYOUT 1
773#define ARCH_HAS_PREFETCHW
774#define ARCH_HAS_SPINLOCK_PREFETCH
775
ae2e15eb 776#ifdef CONFIG_X86_32
4d46a89e
IM
777# define BASE_PREFETCH ASM_NOP4
778# define ARCH_HAS_PREFETCH
ae2e15eb 779#else
4d46a89e 780# define BASE_PREFETCH "prefetcht0 (%1)"
ae2e15eb
GOC
781#endif
782
4d46a89e
IM
783/*
784 * Prefetch instructions for Pentium III (+) and AMD Athlon (+)
785 *
786 * It's not worth to care about 3dnow prefetches for the K6
787 * because they are microcoded there and very slow.
788 */
ae2e15eb
GOC
789static inline void prefetch(const void *x)
790{
791 alternative_input(BASE_PREFETCH,
792 "prefetchnta (%1)",
793 X86_FEATURE_XMM,
794 "r" (x));
795}
796
4d46a89e
IM
797/*
798 * 3dnow prefetch to get an exclusive cache line.
799 * Useful for spinlocks to avoid one state transition in the
800 * cache coherency protocol:
801 */
ae2e15eb
GOC
802static inline void prefetchw(const void *x)
803{
804 alternative_input(BASE_PREFETCH,
805 "prefetchw (%1)",
806 X86_FEATURE_3DNOW,
807 "r" (x));
808}
809
4d46a89e
IM
810static inline void spin_lock_prefetch(const void *x)
811{
812 prefetchw(x);
813}
814
2f66dcc9
GOC
815#ifdef CONFIG_X86_32
816/*
817 * User space process size: 3GB (default).
818 */
4d46a89e 819#define TASK_SIZE PAGE_OFFSET
d9517346 820#define TASK_SIZE_MAX TASK_SIZE
4d46a89e
IM
821#define STACK_TOP TASK_SIZE
822#define STACK_TOP_MAX STACK_TOP
823
824#define INIT_THREAD { \
825 .sp0 = sizeof(init_stack) + (long)&init_stack, \
826 .vm86_info = NULL, \
827 .sysenter_cs = __KERNEL_CS, \
828 .io_bitmap_ptr = NULL, \
2f66dcc9
GOC
829}
830
831/*
832 * Note that the .io_bitmap member must be extra-big. This is because
833 * the CPU will access an additional byte beyond the end of the IO
834 * permission bitmap. The extra byte must be all 1 bits, and must
835 * be within the limit.
836 */
4d46a89e
IM
837#define INIT_TSS { \
838 .x86_tss = { \
2f66dcc9 839 .sp0 = sizeof(init_stack) + (long)&init_stack, \
4d46a89e
IM
840 .ss0 = __KERNEL_DS, \
841 .ss1 = __KERNEL_CS, \
842 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
843 }, \
844 .io_bitmap = { [0 ... IO_BITMAP_LONGS] = ~0 }, \
2f66dcc9
GOC
845}
846
2f66dcc9
GOC
847extern unsigned long thread_saved_pc(struct task_struct *tsk);
848
849#define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
850#define KSTK_TOP(info) \
851({ \
852 unsigned long *__ptr = (unsigned long *)(info); \
853 (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
854})
855
856/*
857 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
858 * This is necessary to guarantee that the entire "struct pt_regs"
b595076a 859 * is accessible even if the CPU haven't stored the SS/ESP registers
2f66dcc9
GOC
860 * on the stack (interrupt gate does not save these registers
861 * when switching to the same priv ring).
862 * Therefore beware: accessing the ss/esp fields of the
863 * "struct pt_regs" is possible, but they may contain the
864 * completely wrong values.
865 */
866#define task_pt_regs(task) \
867({ \
868 struct pt_regs *__regs__; \
869 __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
870 __regs__ - 1; \
871})
872
4d46a89e 873#define KSTK_ESP(task) (task_pt_regs(task)->sp)
2f66dcc9
GOC
874
875#else
876/*
877 * User space process size. 47bits minus one guard page.
878 */
d9517346 879#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
2f66dcc9
GOC
880
881/* This decides where the kernel will search for a free chunk of vm
882 * space during mmap's.
883 */
4d46a89e
IM
884#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
885 0xc0000000 : 0xFFFFe000)
2f66dcc9 886
6bd33008 887#define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
d9517346 888 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
6bd33008 889#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_ADDR32)) ? \
d9517346 890 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
2f66dcc9 891
922a70d3 892#define STACK_TOP TASK_SIZE
d9517346 893#define STACK_TOP_MAX TASK_SIZE_MAX
922a70d3 894
2f66dcc9
GOC
895#define INIT_THREAD { \
896 .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
897}
898
899#define INIT_TSS { \
900 .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
901}
902
2f66dcc9
GOC
903/*
904 * Return saved PC of a blocked thread.
905 * What is this good for? it will be always the scheduler or ret_from_fork.
906 */
4d46a89e 907#define thread_saved_pc(t) (*(unsigned long *)((t)->thread.sp - 8))
2f66dcc9 908
4d46a89e 909#define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1)
89240ba0 910extern unsigned long KSTK_ESP(struct task_struct *task);
d046ff8b
L
911
912/*
913 * User space RSP while inside the SYSCALL fast path
914 */
915DECLARE_PER_CPU(unsigned long, old_rsp);
916
2f66dcc9
GOC
917#endif /* CONFIG_X86_64 */
918
513ad84b
IM
919extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
920 unsigned long new_sp);
921
4d46a89e
IM
922/*
923 * This decides where the kernel will search for a free chunk of vm
683e0253
GOC
924 * space during mmap's.
925 */
926#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
927
4d46a89e 928#define KSTK_EIP(task) (task_pt_regs(task)->ip)
683e0253 929
529e25f6
EB
930/* Get/set a process' ability to use the timestamp counter instruction */
931#define GET_TSC_CTL(adr) get_tsc_mode((adr))
932#define SET_TSC_CTL(val) set_tsc_mode((val))
933
934extern int get_tsc_mode(unsigned long adr);
935extern int set_tsc_mode(unsigned int val);
936
6a812691
AH
937extern int amd_get_nb_id(int cpu);
938
5cbc19a9
PZ
939struct aperfmperf {
940 u64 aperf, mperf;
941};
942
943static inline void get_aperfmperf(struct aperfmperf *am)
944{
945 WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_APERFMPERF));
946
947 rdmsrl(MSR_IA32_APERF, am->aperf);
948 rdmsrl(MSR_IA32_MPERF, am->mperf);
949}
950
951#define APERFMPERF_SHIFT 10
952
953static inline
954unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
955 struct aperfmperf *new)
956{
957 u64 aperf = new->aperf - old->aperf;
958 u64 mperf = new->mperf - old->mperf;
959 unsigned long ratio = aperf;
960
961 mperf >>= APERFMPERF_SHIFT;
962 if (mperf)
963 ratio = div64_u64(aperf, mperf);
964
965 return ratio;
966}
967
d78d671d
HR
968/*
969 * AMD errata checking
970 */
971#ifdef CONFIG_CPU_SUP_AMD
1be85a6d 972extern const int amd_erratum_383[];
9d8888c2 973extern const int amd_erratum_400[];
d78d671d
HR
974extern bool cpu_has_amd_erratum(const int *);
975
976#define AMD_LEGACY_ERRATUM(...) { -1, __VA_ARGS__, 0 }
977#define AMD_OSVW_ERRATUM(osvw_id, ...) { osvw_id, __VA_ARGS__, 0 }
978#define AMD_MODEL_RANGE(f, m_start, s_start, m_end, s_end) \
979 ((f << 24) | (m_start << 16) | (s_start << 12) | (m_end << 4) | (s_end))
980#define AMD_MODEL_RANGE_FAMILY(range) (((range) >> 24) & 0xff)
981#define AMD_MODEL_RANGE_START(range) (((range) >> 12) & 0xfff)
982#define AMD_MODEL_RANGE_END(range) ((range) & 0xfff)
983
984#else
985#define cpu_has_amd_erratum(x) (false)
986#endif /* CONFIG_CPU_SUP_AMD */
987
f05e798a
DH
988extern unsigned long arch_align_stack(unsigned long sp);
989extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
990
991void default_idle(void);
992bool set_pm_idle_to_default(void);
993
994void stop_this_cpu(void *dummy);
995
1965aae3 996#endif /* _ASM_X86_PROCESSOR_H */
This page took 0.779543 seconds and 5 git commands to generate.