Merge branch 'x86/xsave' into x86/core
[linux-2.6] / include / asm-x86 / processor.h
1 #ifndef ASM_X86__PROCESSOR_H
2 #define ASM_X86__PROCESSOR_H
3
4 #include <asm/processor-flags.h>
5
6 /* Forward declaration, a strange C thing */
7 struct task_struct;
8 struct mm_struct;
9
10 #include <asm/vm86.h>
11 #include <asm/math_emu.h>
12 #include <asm/segment.h>
13 #include <asm/types.h>
14 #include <asm/sigcontext.h>
15 #include <asm/current.h>
16 #include <asm/cpufeature.h>
17 #include <asm/system.h>
18 #include <asm/page.h>
19 #include <asm/percpu.h>
20 #include <asm/msr.h>
21 #include <asm/desc_defs.h>
22 #include <asm/nops.h>
23
24 #include <linux/personality.h>
25 #include <linux/cpumask.h>
26 #include <linux/cache.h>
27 #include <linux/threads.h>
28 #include <linux/init.h>
29
30 /*
31  * Default implementation of macro that returns current
32  * instruction pointer ("program counter").
33  */
34 static inline void *current_text_addr(void)
35 {
36         void *pc;
37
38         asm volatile("mov $1f, %0; 1:":"=r" (pc));
39
40         return pc;
41 }
42
43 #ifdef CONFIG_X86_VSMP
44 # define ARCH_MIN_TASKALIGN             (1 << INTERNODE_CACHE_SHIFT)
45 # define ARCH_MIN_MMSTRUCT_ALIGN        (1 << INTERNODE_CACHE_SHIFT)
46 #else
47 # define ARCH_MIN_TASKALIGN             16
48 # define ARCH_MIN_MMSTRUCT_ALIGN        0
49 #endif
50
51 /*
52  *  CPU type and hardware bug flags. Kept separately for each CPU.
53  *  Members of this structure are referenced in head.S, so think twice
54  *  before touching them. [mj]
55  */
56
57 struct cpuinfo_x86 {
58         __u8                    x86;            /* CPU family */
59         __u8                    x86_vendor;     /* CPU vendor */
60         __u8                    x86_model;
61         __u8                    x86_mask;
62 #ifdef CONFIG_X86_32
63         char                    wp_works_ok;    /* It doesn't on 386's */
64
65         /* Problems on some 486Dx4's and old 386's: */
66         char                    hlt_works_ok;
67         char                    hard_math;
68         char                    rfu;
69         char                    fdiv_bug;
70         char                    f00f_bug;
71         char                    coma_bug;
72         char                    pad0;
73 #else
74         /* Number of 4K pages in DTLB/ITLB combined(in pages): */
75         int                      x86_tlbsize;
76         __u8                    x86_virt_bits;
77         __u8                    x86_phys_bits;
78         /* CPUID returned core id bits: */
79         __u8                    x86_coreid_bits;
80         /* Max extended CPUID function supported: */
81         __u32                   extended_cpuid_level;
82 #endif
83         /* Maximum supported CPUID level, -1=no CPUID: */
84         int                     cpuid_level;
85         __u32                   x86_capability[NCAPINTS];
86         char                    x86_vendor_id[16];
87         char                    x86_model_id[64];
88         /* in KB - valid for CPUS which support this call: */
89         int                     x86_cache_size;
90         int                     x86_cache_alignment;    /* In bytes */
91         int                     x86_power;
92         unsigned long           loops_per_jiffy;
93 #ifdef CONFIG_SMP
94         /* cpus sharing the last level cache: */
95         cpumask_t               llc_shared_map;
96 #endif
97         /* cpuid returned max cores value: */
98         u16                      x86_max_cores;
99         u16                     apicid;
100         u16                     initial_apicid;
101         u16                     x86_clflush_size;
102 #ifdef CONFIG_SMP
103         /* number of cores as seen by the OS: */
104         u16                     booted_cores;
105         /* Physical processor id: */
106         u16                     phys_proc_id;
107         /* Core id: */
108         u16                     cpu_core_id;
109         /* Index into per_cpu list: */
110         u16                     cpu_index;
111 #endif
112 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
113
114 #define X86_VENDOR_INTEL        0
115 #define X86_VENDOR_CYRIX        1
116 #define X86_VENDOR_AMD          2
117 #define X86_VENDOR_UMC          3
118 #define X86_VENDOR_CENTAUR      5
119 #define X86_VENDOR_TRANSMETA    7
120 #define X86_VENDOR_NSC          8
121 #define X86_VENDOR_NUM          9
122
123 #define X86_VENDOR_UNKNOWN      0xff
124
125 /*
126  * capabilities of CPUs
127  */
128 extern struct cpuinfo_x86       boot_cpu_data;
129 extern struct cpuinfo_x86       new_cpu_data;
130
131 extern struct tss_struct        doublefault_tss;
132 extern __u32                    cleared_cpu_caps[NCAPINTS];
133
134 #ifdef CONFIG_SMP
135 DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
136 #define cpu_data(cpu)           per_cpu(cpu_info, cpu)
137 #define current_cpu_data        __get_cpu_var(cpu_info)
138 #else
139 #define cpu_data(cpu)           boot_cpu_data
140 #define current_cpu_data        boot_cpu_data
141 #endif
142
143 extern const struct seq_operations cpuinfo_op;
144
145 static inline int hlt_works(int cpu)
146 {
147 #ifdef CONFIG_X86_32
148         return cpu_data(cpu).hlt_works_ok;
149 #else
150         return 1;
151 #endif
152 }
153
154 #define cache_line_size()       (boot_cpu_data.x86_cache_alignment)
155
156 extern void cpu_detect(struct cpuinfo_x86 *c);
157
158 extern struct pt_regs *idle_regs(struct pt_regs *);
159
160 extern void early_cpu_init(void);
161 extern void identify_boot_cpu(void);
162 extern void identify_secondary_cpu(struct cpuinfo_x86 *);
163 extern void print_cpu_info(struct cpuinfo_x86 *);
164 extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
165 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
166 extern unsigned short num_cache_leaves;
167
168 #if defined(CONFIG_X86_HT) || defined(CONFIG_X86_64)
169 extern void detect_ht(struct cpuinfo_x86 *c);
170 #else
171 static inline void detect_ht(struct cpuinfo_x86 *c) {}
172 #endif
173
174 static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
175                                 unsigned int *ecx, unsigned int *edx)
176 {
177         /* ecx is often an input as well as an output. */
178         asm("cpuid"
179             : "=a" (*eax),
180               "=b" (*ebx),
181               "=c" (*ecx),
182               "=d" (*edx)
183             : "0" (*eax), "2" (*ecx));
184 }
185
186 static inline void load_cr3(pgd_t *pgdir)
187 {
188         write_cr3(__pa(pgdir));
189 }
190
191 #ifdef CONFIG_X86_32
192 /* This is the TSS defined by the hardware. */
193 struct x86_hw_tss {
194         unsigned short          back_link, __blh;
195         unsigned long           sp0;
196         unsigned short          ss0, __ss0h;
197         unsigned long           sp1;
198         /* ss1 caches MSR_IA32_SYSENTER_CS: */
199         unsigned short          ss1, __ss1h;
200         unsigned long           sp2;
201         unsigned short          ss2, __ss2h;
202         unsigned long           __cr3;
203         unsigned long           ip;
204         unsigned long           flags;
205         unsigned long           ax;
206         unsigned long           cx;
207         unsigned long           dx;
208         unsigned long           bx;
209         unsigned long           sp;
210         unsigned long           bp;
211         unsigned long           si;
212         unsigned long           di;
213         unsigned short          es, __esh;
214         unsigned short          cs, __csh;
215         unsigned short          ss, __ssh;
216         unsigned short          ds, __dsh;
217         unsigned short          fs, __fsh;
218         unsigned short          gs, __gsh;
219         unsigned short          ldt, __ldth;
220         unsigned short          trace;
221         unsigned short          io_bitmap_base;
222
223 } __attribute__((packed));
224 #else
225 struct x86_hw_tss {
226         u32                     reserved1;
227         u64                     sp0;
228         u64                     sp1;
229         u64                     sp2;
230         u64                     reserved2;
231         u64                     ist[7];
232         u32                     reserved3;
233         u32                     reserved4;
234         u16                     reserved5;
235         u16                     io_bitmap_base;
236
237 } __attribute__((packed)) ____cacheline_aligned;
238 #endif
239
240 /*
241  * IO-bitmap sizes:
242  */
243 #define IO_BITMAP_BITS                  65536
244 #define IO_BITMAP_BYTES                 (IO_BITMAP_BITS/8)
245 #define IO_BITMAP_LONGS                 (IO_BITMAP_BYTES/sizeof(long))
246 #define IO_BITMAP_OFFSET                offsetof(struct tss_struct, io_bitmap)
247 #define INVALID_IO_BITMAP_OFFSET        0x8000
248 #define INVALID_IO_BITMAP_OFFSET_LAZY   0x9000
249
250 struct tss_struct {
251         /*
252          * The hardware state:
253          */
254         struct x86_hw_tss       x86_tss;
255
256         /*
257          * The extra 1 is there because the CPU will access an
258          * additional byte beyond the end of the IO permission
259          * bitmap. The extra byte must be all 1 bits, and must
260          * be within the limit.
261          */
262         unsigned long           io_bitmap[IO_BITMAP_LONGS + 1];
263         /*
264          * Cache the current maximum and the last task that used the bitmap:
265          */
266         unsigned long           io_bitmap_max;
267         struct thread_struct    *io_bitmap_owner;
268
269         /*
270          * .. and then another 0x100 bytes for the emergency kernel stack:
271          */
272         unsigned long           stack[64];
273
274 } ____cacheline_aligned;
275
276 DECLARE_PER_CPU(struct tss_struct, init_tss);
277
278 /*
279  * Save the original ist values for checking stack pointers during debugging
280  */
281 struct orig_ist {
282         unsigned long           ist[7];
283 };
284
285 #define MXCSR_DEFAULT           0x1f80
286
287 struct i387_fsave_struct {
288         u32                     cwd;    /* FPU Control Word             */
289         u32                     swd;    /* FPU Status Word              */
290         u32                     twd;    /* FPU Tag Word                 */
291         u32                     fip;    /* FPU IP Offset                */
292         u32                     fcs;    /* FPU IP Selector              */
293         u32                     foo;    /* FPU Operand Pointer Offset   */
294         u32                     fos;    /* FPU Operand Pointer Selector */
295
296         /* 8*10 bytes for each FP-reg = 80 bytes:                       */
297         u32                     st_space[20];
298
299         /* Software status information [not touched by FSAVE ]:         */
300         u32                     status;
301 };
302
303 struct i387_fxsave_struct {
304         u16                     cwd; /* Control Word                    */
305         u16                     swd; /* Status Word                     */
306         u16                     twd; /* Tag Word                        */
307         u16                     fop; /* Last Instruction Opcode         */
308         union {
309                 struct {
310                         u64     rip; /* Instruction Pointer             */
311                         u64     rdp; /* Data Pointer                    */
312                 };
313                 struct {
314                         u32     fip; /* FPU IP Offset                   */
315                         u32     fcs; /* FPU IP Selector                 */
316                         u32     foo; /* FPU Operand Offset              */
317                         u32     fos; /* FPU Operand Selector            */
318                 };
319         };
320         u32                     mxcsr;          /* MXCSR Register State */
321         u32                     mxcsr_mask;     /* MXCSR Mask           */
322
323         /* 8*16 bytes for each FP-reg = 128 bytes:                      */
324         u32                     st_space[32];
325
326         /* 16*16 bytes for each XMM-reg = 256 bytes:                    */
327         u32                     xmm_space[64];
328
329         u32                     padding[12];
330
331         union {
332                 u32             padding1[12];
333                 u32             sw_reserved[12];
334         };
335
336 } __attribute__((aligned(16)));
337
338 struct i387_soft_struct {
339         u32                     cwd;
340         u32                     swd;
341         u32                     twd;
342         u32                     fip;
343         u32                     fcs;
344         u32                     foo;
345         u32                     fos;
346         /* 8*10 bytes for each FP-reg = 80 bytes: */
347         u32                     st_space[20];
348         u8                      ftop;
349         u8                      changed;
350         u8                      lookahead;
351         u8                      no_update;
352         u8                      rm;
353         u8                      alimit;
354         struct info             *info;
355         u32                     entry_eip;
356 };
357
358 struct xsave_hdr_struct {
359         u64 xstate_bv;
360         u64 reserved1[2];
361         u64 reserved2[5];
362 } __attribute__((packed));
363
364 struct xsave_struct {
365         struct i387_fxsave_struct i387;
366         struct xsave_hdr_struct xsave_hdr;
367         /* new processor state extensions will go here */
368 } __attribute__ ((packed, aligned (64)));
369
370 union thread_xstate {
371         struct i387_fsave_struct        fsave;
372         struct i387_fxsave_struct       fxsave;
373         struct i387_soft_struct         soft;
374         struct xsave_struct             xsave;
375 };
376
377 #ifdef CONFIG_X86_64
378 DECLARE_PER_CPU(struct orig_ist, orig_ist);
379 #endif
380
381 extern void print_cpu_info(struct cpuinfo_x86 *);
382 extern unsigned int xstate_size;
383 extern void free_thread_xstate(struct task_struct *);
384 extern struct kmem_cache *task_xstate_cachep;
385 extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
386 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
387 extern unsigned short num_cache_leaves;
388
389 struct thread_struct {
390         /* Cached TLS descriptors: */
391         struct desc_struct      tls_array[GDT_ENTRY_TLS_ENTRIES];
392         unsigned long           sp0;
393         unsigned long           sp;
394 #ifdef CONFIG_X86_32
395         unsigned long           sysenter_cs;
396 #else
397         unsigned long           usersp; /* Copy from PDA */
398         unsigned short          es;
399         unsigned short          ds;
400         unsigned short          fsindex;
401         unsigned short          gsindex;
402 #endif
403         unsigned long           ip;
404         unsigned long           fs;
405         unsigned long           gs;
406         /* Hardware debugging registers: */
407         unsigned long           debugreg0;
408         unsigned long           debugreg1;
409         unsigned long           debugreg2;
410         unsigned long           debugreg3;
411         unsigned long           debugreg6;
412         unsigned long           debugreg7;
413         /* Fault info: */
414         unsigned long           cr2;
415         unsigned long           trap_no;
416         unsigned long           error_code;
417         /* floating point and extended processor state */
418         union thread_xstate     *xstate;
419 #ifdef CONFIG_X86_32
420         /* Virtual 86 mode info */
421         struct vm86_struct __user *vm86_info;
422         unsigned long           screen_bitmap;
423         unsigned long           v86flags;
424         unsigned long           v86mask;
425         unsigned long           saved_sp0;
426         unsigned int            saved_fs;
427         unsigned int            saved_gs;
428 #endif
429         /* IO permissions: */
430         unsigned long           *io_bitmap_ptr;
431         unsigned long           iopl;
432         /* Max allowed port in the bitmap, in bytes: */
433         unsigned                io_bitmap_max;
434 /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set.  */
435         unsigned long   debugctlmsr;
436 /* Debug Store - if not 0 points to a DS Save Area configuration;
437  *               goes into MSR_IA32_DS_AREA */
438         unsigned long   ds_area_msr;
439 };
440
441 static inline unsigned long native_get_debugreg(int regno)
442 {
443         unsigned long val = 0;  /* Damn you, gcc! */
444
445         switch (regno) {
446         case 0:
447                 asm("mov %%db0, %0" :"=r" (val));
448                 break;
449         case 1:
450                 asm("mov %%db1, %0" :"=r" (val));
451                 break;
452         case 2:
453                 asm("mov %%db2, %0" :"=r" (val));
454                 break;
455         case 3:
456                 asm("mov %%db3, %0" :"=r" (val));
457                 break;
458         case 6:
459                 asm("mov %%db6, %0" :"=r" (val));
460                 break;
461         case 7:
462                 asm("mov %%db7, %0" :"=r" (val));
463                 break;
464         default:
465                 BUG();
466         }
467         return val;
468 }
469
470 static inline void native_set_debugreg(int regno, unsigned long value)
471 {
472         switch (regno) {
473         case 0:
474                 asm("mov %0, %%db0"     ::"r" (value));
475                 break;
476         case 1:
477                 asm("mov %0, %%db1"     ::"r" (value));
478                 break;
479         case 2:
480                 asm("mov %0, %%db2"     ::"r" (value));
481                 break;
482         case 3:
483                 asm("mov %0, %%db3"     ::"r" (value));
484                 break;
485         case 6:
486                 asm("mov %0, %%db6"     ::"r" (value));
487                 break;
488         case 7:
489                 asm("mov %0, %%db7"     ::"r" (value));
490                 break;
491         default:
492                 BUG();
493         }
494 }
495
496 /*
497  * Set IOPL bits in EFLAGS from given mask
498  */
499 static inline void native_set_iopl_mask(unsigned mask)
500 {
501 #ifdef CONFIG_X86_32
502         unsigned int reg;
503
504         asm volatile ("pushfl;"
505                       "popl %0;"
506                       "andl %1, %0;"
507                       "orl %2, %0;"
508                       "pushl %0;"
509                       "popfl"
510                       : "=&r" (reg)
511                       : "i" (~X86_EFLAGS_IOPL), "r" (mask));
512 #endif
513 }
514
515 static inline void
516 native_load_sp0(struct tss_struct *tss, struct thread_struct *thread)
517 {
518         tss->x86_tss.sp0 = thread->sp0;
519 #ifdef CONFIG_X86_32
520         /* Only happens when SEP is enabled, no need to test "SEP"arately: */
521         if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) {
522                 tss->x86_tss.ss1 = thread->sysenter_cs;
523                 wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
524         }
525 #endif
526 }
527
528 static inline void native_swapgs(void)
529 {
530 #ifdef CONFIG_X86_64
531         asm volatile("swapgs" ::: "memory");
532 #endif
533 }
534
535 #ifdef CONFIG_PARAVIRT
536 #include <asm/paravirt.h>
537 #else
538 #define __cpuid                 native_cpuid
539 #define paravirt_enabled()      0
540
541 /*
542  * These special macros can be used to get or set a debugging register
543  */
544 #define get_debugreg(var, register)                             \
545         (var) = native_get_debugreg(register)
546 #define set_debugreg(value, register)                           \
547         native_set_debugreg(register, value)
548
549 static inline void load_sp0(struct tss_struct *tss,
550                             struct thread_struct *thread)
551 {
552         native_load_sp0(tss, thread);
553 }
554
555 #define set_iopl_mask native_set_iopl_mask
556 #endif /* CONFIG_PARAVIRT */
557
558 /*
559  * Save the cr4 feature set we're using (ie
560  * Pentium 4MB enable and PPro Global page
561  * enable), so that any CPU's that boot up
562  * after us can get the correct flags.
563  */
564 extern unsigned long            mmu_cr4_features;
565
566 static inline void set_in_cr4(unsigned long mask)
567 {
568         unsigned cr4;
569
570         mmu_cr4_features |= mask;
571         cr4 = read_cr4();
572         cr4 |= mask;
573         write_cr4(cr4);
574 }
575
576 static inline void clear_in_cr4(unsigned long mask)
577 {
578         unsigned cr4;
579
580         mmu_cr4_features &= ~mask;
581         cr4 = read_cr4();
582         cr4 &= ~mask;
583         write_cr4(cr4);
584 }
585
586 struct microcode_header {
587         unsigned int            hdrver;
588         unsigned int            rev;
589         unsigned int            date;
590         unsigned int            sig;
591         unsigned int            cksum;
592         unsigned int            ldrver;
593         unsigned int            pf;
594         unsigned int            datasize;
595         unsigned int            totalsize;
596         unsigned int            reserved[3];
597 };
598
599 struct microcode {
600         struct microcode_header hdr;
601         unsigned int            bits[0];
602 };
603
604 typedef struct microcode        microcode_t;
605 typedef struct microcode_header microcode_header_t;
606
607 /* microcode format is extended from prescott processors */
608 struct extended_signature {
609         unsigned int            sig;
610         unsigned int            pf;
611         unsigned int            cksum;
612 };
613
614 struct extended_sigtable {
615         unsigned int            count;
616         unsigned int            cksum;
617         unsigned int            reserved[3];
618         struct extended_signature sigs[0];
619 };
620
621 typedef struct {
622         unsigned long           seg;
623 } mm_segment_t;
624
625
626 /*
627  * create a kernel thread without removing it from tasklists
628  */
629 extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
630
631 /* Free all resources held by a thread. */
632 extern void release_thread(struct task_struct *);
633
634 /* Prepare to copy thread state - unlazy all lazy state */
635 extern void prepare_to_copy(struct task_struct *tsk);
636
637 unsigned long get_wchan(struct task_struct *p);
638
639 /*
640  * Generic CPUID function
641  * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
642  * resulting in stale register contents being returned.
643  */
644 static inline void cpuid(unsigned int op,
645                          unsigned int *eax, unsigned int *ebx,
646                          unsigned int *ecx, unsigned int *edx)
647 {
648         *eax = op;
649         *ecx = 0;
650         __cpuid(eax, ebx, ecx, edx);
651 }
652
653 /* Some CPUID calls want 'count' to be placed in ecx */
654 static inline void cpuid_count(unsigned int op, int count,
655                                unsigned int *eax, unsigned int *ebx,
656                                unsigned int *ecx, unsigned int *edx)
657 {
658         *eax = op;
659         *ecx = count;
660         __cpuid(eax, ebx, ecx, edx);
661 }
662
663 /*
664  * CPUID functions returning a single datum
665  */
666 static inline unsigned int cpuid_eax(unsigned int op)
667 {
668         unsigned int eax, ebx, ecx, edx;
669
670         cpuid(op, &eax, &ebx, &ecx, &edx);
671
672         return eax;
673 }
674
675 static inline unsigned int cpuid_ebx(unsigned int op)
676 {
677         unsigned int eax, ebx, ecx, edx;
678
679         cpuid(op, &eax, &ebx, &ecx, &edx);
680
681         return ebx;
682 }
683
684 static inline unsigned int cpuid_ecx(unsigned int op)
685 {
686         unsigned int eax, ebx, ecx, edx;
687
688         cpuid(op, &eax, &ebx, &ecx, &edx);
689
690         return ecx;
691 }
692
693 static inline unsigned int cpuid_edx(unsigned int op)
694 {
695         unsigned int eax, ebx, ecx, edx;
696
697         cpuid(op, &eax, &ebx, &ecx, &edx);
698
699         return edx;
700 }
701
702 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
703 static inline void rep_nop(void)
704 {
705         asm volatile("rep; nop" ::: "memory");
706 }
707
708 static inline void cpu_relax(void)
709 {
710         rep_nop();
711 }
712
713 /* Stop speculative execution: */
714 static inline void sync_core(void)
715 {
716         int tmp;
717
718         asm volatile("cpuid" : "=a" (tmp) : "0" (1)
719                      : "ebx", "ecx", "edx", "memory");
720 }
721
722 static inline void __monitor(const void *eax, unsigned long ecx,
723                              unsigned long edx)
724 {
725         /* "monitor %eax, %ecx, %edx;" */
726         asm volatile(".byte 0x0f, 0x01, 0xc8;"
727                      :: "a" (eax), "c" (ecx), "d"(edx));
728 }
729
730 static inline void __mwait(unsigned long eax, unsigned long ecx)
731 {
732         /* "mwait %eax, %ecx;" */
733         asm volatile(".byte 0x0f, 0x01, 0xc9;"
734                      :: "a" (eax), "c" (ecx));
735 }
736
737 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
738 {
739         trace_hardirqs_on();
740         /* "mwait %eax, %ecx;" */
741         asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
742                      :: "a" (eax), "c" (ecx));
743 }
744
745 extern void mwait_idle_with_hints(unsigned long eax, unsigned long ecx);
746
747 extern void select_idle_routine(const struct cpuinfo_x86 *c);
748
749 extern unsigned long            boot_option_idle_override;
750 extern unsigned long            idle_halt;
751 extern unsigned long            idle_nomwait;
752
753 /*
754  * on systems with caches, caches must be flashed as the absolute
755  * last instruction before going into a suspended halt.  Otherwise,
756  * dirty data can linger in the cache and become stale on resume,
757  * leading to strange errors.
758  *
759  * perform a variety of operations to guarantee that the compiler
760  * will not reorder instructions.  wbinvd itself is serializing
761  * so the processor will not reorder.
762  *
763  * Systems without cache can just go into halt.
764  */
765 static inline void wbinvd_halt(void)
766 {
767         mb();
768         /* check for clflush to determine if wbinvd is legal */
769         if (cpu_has_clflush)
770                 asm volatile("cli; wbinvd; 1: hlt; jmp 1b" : : : "memory");
771         else
772                 while (1)
773                         halt();
774 }
775
776 extern void enable_sep_cpu(void);
777 extern int sysenter_setup(void);
778
779 /* Defined in head.S */
780 extern struct desc_ptr          early_gdt_descr;
781
782 extern void cpu_set_gdt(int);
783 extern void switch_to_new_gdt(void);
784 extern void cpu_init(void);
785 extern void init_gdt(int cpu);
786
787 static inline void update_debugctlmsr(unsigned long debugctlmsr)
788 {
789 #ifndef CONFIG_X86_DEBUGCTLMSR
790         if (boot_cpu_data.x86 < 6)
791                 return;
792 #endif
793         wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
794 }
795
796 /*
797  * from system description table in BIOS. Mostly for MCA use, but
798  * others may find it useful:
799  */
800 extern unsigned int             machine_id;
801 extern unsigned int             machine_submodel_id;
802 extern unsigned int             BIOS_revision;
803
804 /* Boot loader type from the setup header: */
805 extern int                      bootloader_type;
806
807 extern char                     ignore_fpu_irq;
808
809 #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
810 #define ARCH_HAS_PREFETCHW
811 #define ARCH_HAS_SPINLOCK_PREFETCH
812
813 #ifdef CONFIG_X86_32
814 # define BASE_PREFETCH          ASM_NOP4
815 # define ARCH_HAS_PREFETCH
816 #else
817 # define BASE_PREFETCH          "prefetcht0 (%1)"
818 #endif
819
820 /*
821  * Prefetch instructions for Pentium III (+) and AMD Athlon (+)
822  *
823  * It's not worth to care about 3dnow prefetches for the K6
824  * because they are microcoded there and very slow.
825  */
826 static inline void prefetch(const void *x)
827 {
828         alternative_input(BASE_PREFETCH,
829                           "prefetchnta (%1)",
830                           X86_FEATURE_XMM,
831                           "r" (x));
832 }
833
834 /*
835  * 3dnow prefetch to get an exclusive cache line.
836  * Useful for spinlocks to avoid one state transition in the
837  * cache coherency protocol:
838  */
839 static inline void prefetchw(const void *x)
840 {
841         alternative_input(BASE_PREFETCH,
842                           "prefetchw (%1)",
843                           X86_FEATURE_3DNOW,
844                           "r" (x));
845 }
846
847 static inline void spin_lock_prefetch(const void *x)
848 {
849         prefetchw(x);
850 }
851
852 #ifdef CONFIG_X86_32
853 /*
854  * User space process size: 3GB (default).
855  */
856 #define TASK_SIZE               PAGE_OFFSET
857 #define STACK_TOP               TASK_SIZE
858 #define STACK_TOP_MAX           STACK_TOP
859
860 #define INIT_THREAD  {                                                    \
861         .sp0                    = sizeof(init_stack) + (long)&init_stack, \
862         .vm86_info              = NULL,                                   \
863         .sysenter_cs            = __KERNEL_CS,                            \
864         .io_bitmap_ptr          = NULL,                                   \
865         .fs                     = __KERNEL_PERCPU,                        \
866 }
867
868 /*
869  * Note that the .io_bitmap member must be extra-big. This is because
870  * the CPU will access an additional byte beyond the end of the IO
871  * permission bitmap. The extra byte must be all 1 bits, and must
872  * be within the limit.
873  */
874 #define INIT_TSS  {                                                       \
875         .x86_tss = {                                                      \
876                 .sp0            = sizeof(init_stack) + (long)&init_stack, \
877                 .ss0            = __KERNEL_DS,                            \
878                 .ss1            = __KERNEL_CS,                            \
879                 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,               \
880          },                                                               \
881         .io_bitmap              = { [0 ... IO_BITMAP_LONGS] = ~0 },       \
882 }
883
884 extern unsigned long thread_saved_pc(struct task_struct *tsk);
885
886 #define THREAD_SIZE_LONGS      (THREAD_SIZE/sizeof(unsigned long))
887 #define KSTK_TOP(info)                                                 \
888 ({                                                                     \
889        unsigned long *__ptr = (unsigned long *)(info);                 \
890        (unsigned long)(&__ptr[THREAD_SIZE_LONGS]);                     \
891 })
892
893 /*
894  * The below -8 is to reserve 8 bytes on top of the ring0 stack.
895  * This is necessary to guarantee that the entire "struct pt_regs"
896  * is accessable even if the CPU haven't stored the SS/ESP registers
897  * on the stack (interrupt gate does not save these registers
898  * when switching to the same priv ring).
899  * Therefore beware: accessing the ss/esp fields of the
900  * "struct pt_regs" is possible, but they may contain the
901  * completely wrong values.
902  */
903 #define task_pt_regs(task)                                             \
904 ({                                                                     \
905        struct pt_regs *__regs__;                                       \
906        __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
907        __regs__ - 1;                                                   \
908 })
909
910 #define KSTK_ESP(task)          (task_pt_regs(task)->sp)
911
912 #else
913 /*
914  * User space process size. 47bits minus one guard page.
915  */
916 #define TASK_SIZE64     ((1UL << 47) - PAGE_SIZE)
917
918 /* This decides where the kernel will search for a free chunk of vm
919  * space during mmap's.
920  */
921 #define IA32_PAGE_OFFSET        ((current->personality & ADDR_LIMIT_3GB) ? \
922                                         0xc0000000 : 0xFFFFe000)
923
924 #define TASK_SIZE               (test_thread_flag(TIF_IA32) ? \
925                                         IA32_PAGE_OFFSET : TASK_SIZE64)
926 #define TASK_SIZE_OF(child)     ((test_tsk_thread_flag(child, TIF_IA32)) ? \
927                                         IA32_PAGE_OFFSET : TASK_SIZE64)
928
929 #define STACK_TOP               TASK_SIZE
930 #define STACK_TOP_MAX           TASK_SIZE64
931
932 #define INIT_THREAD  { \
933         .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
934 }
935
936 #define INIT_TSS  { \
937         .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
938 }
939
940 /*
941  * Return saved PC of a blocked thread.
942  * What is this good for? it will be always the scheduler or ret_from_fork.
943  */
944 #define thread_saved_pc(t)      (*(unsigned long *)((t)->thread.sp - 8))
945
946 #define task_pt_regs(tsk)       ((struct pt_regs *)(tsk)->thread.sp0 - 1)
947 #define KSTK_ESP(tsk)           -1 /* sorry. doesn't work for syscall. */
948 #endif /* CONFIG_X86_64 */
949
950 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
951                                                unsigned long new_sp);
952
953 /*
954  * This decides where the kernel will search for a free chunk of vm
955  * space during mmap's.
956  */
957 #define TASK_UNMAPPED_BASE      (PAGE_ALIGN(TASK_SIZE / 3))
958
959 #define KSTK_EIP(task)          (task_pt_regs(task)->ip)
960
961 /* Get/set a process' ability to use the timestamp counter instruction */
962 #define GET_TSC_CTL(adr)        get_tsc_mode((adr))
963 #define SET_TSC_CTL(val)        set_tsc_mode((val))
964
965 extern int get_tsc_mode(unsigned long adr);
966 extern int set_tsc_mode(unsigned int val);
967
968 #endif /* ASM_X86__PROCESSOR_H */