This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-x86_64 / mach-xen / asm / processor.h
1 /*
2  * include/asm-x86_64/processor.h
3  *
4  * Copyright (C) 1994 Linus Torvalds
5  */
6
7 #ifndef __ASM_X86_64_PROCESSOR_H
8 #define __ASM_X86_64_PROCESSOR_H
9
10 #include <asm/segment.h>
11 #include <asm/page.h>
12 #include <asm/types.h>
13 #include <asm/sigcontext.h>
14 #include <asm/cpufeature.h>
15 #include <linux/config.h>
16 #include <linux/threads.h>
17 #include <asm/msr.h>
18 #include <asm/current.h>
19 #include <asm/system.h>
20 #include <asm/mmsegment.h>
21 #include <asm/percpu.h>
22 #include <linux/personality.h>
23 #include <linux/cpumask.h>
24
25 #define TF_MASK         0x00000100
26 #define IF_MASK         0x00000200
27 #define IOPL_MASK       0x00003000
28 #define NT_MASK         0x00004000
29 #define VM_MASK         0x00020000
30 #define AC_MASK         0x00040000
31 #define VIF_MASK        0x00080000      /* virtual interrupt flag */
32 #define VIP_MASK        0x00100000      /* virtual interrupt pending */
33 #define ID_MASK         0x00200000
34
35 #define desc_empty(desc) \
36                (!((desc)->a | (desc)->b))
37
38 #define desc_equal(desc1, desc2) \
39                (((desc1)->a == (desc2)->a) && ((desc1)->b == (desc2)->b))
40
41 /*
42  * Default implementation of macro that returns current
43  * instruction pointer ("program counter").
44  */
45 #define current_text_addr() ({ void *pc; asm volatile("leaq 1f(%%rip),%0\n1:":"=r"(pc)); pc; })
46
47 /*
48  *  CPU type and hardware bug flags. Kept separately for each CPU.
49  */
50
51 struct cpuinfo_x86 {
52         __u8    x86;            /* CPU family */
53         __u8    x86_vendor;     /* CPU vendor */
54         __u8    x86_model;
55         __u8    x86_mask;
56         int     cpuid_level;    /* Maximum supported CPUID level, -1=no CPUID */
57         __u32   x86_capability[NCAPINTS];
58         char    x86_vendor_id[16];
59         char    x86_model_id[64];
60         int     x86_cache_size;  /* in KB */
61         int     x86_clflush_size;
62         int     x86_cache_alignment;
63         int     x86_tlbsize;    /* number of 4K pages in DTLB/ITLB combined(in pages)*/
64         __u8    x86_virt_bits, x86_phys_bits;
65         __u8    x86_max_cores;  /* cpuid returned max cores value */
66         __u32   x86_power;      
67         __u32   extended_cpuid_level;   /* Max extended CPUID function supported */
68         unsigned long loops_per_jiffy;
69 #ifdef CONFIG_SMP
70         cpumask_t llc_shared_map;       /* cpus sharing the last level cache */
71 #endif
72         __u8    apicid;
73         __u8    booted_cores;   /* number of cores as seen by OS */
74 } ____cacheline_aligned;
75
76 #define X86_VENDOR_INTEL 0
77 #define X86_VENDOR_CYRIX 1
78 #define X86_VENDOR_AMD 2
79 #define X86_VENDOR_UMC 3
80 #define X86_VENDOR_NEXGEN 4
81 #define X86_VENDOR_CENTAUR 5
82 #define X86_VENDOR_RISE 6
83 #define X86_VENDOR_TRANSMETA 7
84 #define X86_VENDOR_NUM 8
85 #define X86_VENDOR_UNKNOWN 0xff
86
87 #ifdef CONFIG_SMP
88 extern struct cpuinfo_x86 cpu_data[];
89 #define current_cpu_data cpu_data[smp_processor_id()]
90 #else
91 #define cpu_data (&boot_cpu_data)
92 #define current_cpu_data boot_cpu_data
93 #endif
94
95 extern char ignore_irq13;
96
97 extern void identify_cpu(struct cpuinfo_x86 *);
98 extern void print_cpu_info(struct cpuinfo_x86 *);
99 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
100
101 /*
102  * EFLAGS bits
103  */
104 #define X86_EFLAGS_CF   0x00000001 /* Carry Flag */
105 #define X86_EFLAGS_PF   0x00000004 /* Parity Flag */
106 #define X86_EFLAGS_AF   0x00000010 /* Auxillary carry Flag */
107 #define X86_EFLAGS_ZF   0x00000040 /* Zero Flag */
108 #define X86_EFLAGS_SF   0x00000080 /* Sign Flag */
109 #define X86_EFLAGS_TF   0x00000100 /* Trap Flag */
110 #define X86_EFLAGS_IF   0x00000200 /* Interrupt Flag */
111 #define X86_EFLAGS_DF   0x00000400 /* Direction Flag */
112 #define X86_EFLAGS_OF   0x00000800 /* Overflow Flag */
113 #define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
114 #define X86_EFLAGS_NT   0x00004000 /* Nested Task */
115 #define X86_EFLAGS_RF   0x00010000 /* Resume Flag */
116 #define X86_EFLAGS_VM   0x00020000 /* Virtual Mode */
117 #define X86_EFLAGS_AC   0x00040000 /* Alignment Check */
118 #define X86_EFLAGS_VIF  0x00080000 /* Virtual Interrupt Flag */
119 #define X86_EFLAGS_VIP  0x00100000 /* Virtual Interrupt Pending */
120 #define X86_EFLAGS_ID   0x00200000 /* CPUID detection flag */
121
122 /*
123  * Intel CPU features in CR4
124  */
125 #define X86_CR4_VME             0x0001  /* enable vm86 extensions */
126 #define X86_CR4_PVI             0x0002  /* virtual interrupts flag enable */
127 #define X86_CR4_TSD             0x0004  /* disable time stamp at ipl 3 */
128 #define X86_CR4_DE              0x0008  /* enable debugging extensions */
129 #define X86_CR4_PSE             0x0010  /* enable page size extensions */
130 #define X86_CR4_PAE             0x0020  /* enable physical address extensions */
131 #define X86_CR4_MCE             0x0040  /* Machine check enable */
132 #define X86_CR4_PGE             0x0080  /* enable global pages */
133 #define X86_CR4_PCE             0x0100  /* enable performance counters at ipl 3 */
134 #define X86_CR4_OSFXSR          0x0200  /* enable fast FPU save and restore */
135 #define X86_CR4_OSXMMEXCPT      0x0400  /* enable unmasked SSE exceptions */
136
137 /*
138  * Save the cr4 feature set we're using (ie
139  * Pentium 4MB enable and PPro Global page
140  * enable), so that any CPU's that boot up
141  * after us can get the correct flags.
142  */
143 extern unsigned long mmu_cr4_features;
144
145 static inline void set_in_cr4 (unsigned long mask)
146 {
147         mmu_cr4_features |= mask;
148         __asm__("movq %%cr4,%%rax\n\t"
149                 "orq %0,%%rax\n\t"
150                 "movq %%rax,%%cr4\n"
151                 : : "irg" (mask)
152                 :"ax");
153 }
154
155 static inline void clear_in_cr4 (unsigned long mask)
156 {
157         mmu_cr4_features &= ~mask;
158         __asm__("movq %%cr4,%%rax\n\t"
159                 "andq %0,%%rax\n\t"
160                 "movq %%rax,%%cr4\n"
161                 : : "irg" (~mask)
162                 :"ax");
163 }
164
165
166 /*
167  * Bus types
168  */
169 #define MCA_bus 0
170 #define MCA_bus__is_a_macro
171
172 /*
173  * User space process size. 47bits minus one guard page.
174  */
175 #define TASK_SIZE64     (0x800000000000UL - 4096)
176
177 #define __HAVE_ARCH_ALIGN_STACK
178
179 /* This decides where the kernel will search for a free chunk of vm
180  * space during mmap's.
181  */
182 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000)
183
184 #define TASK_SIZE               (test_thread_flag(TIF_IA32) ? IA32_PAGE_OFFSET : TASK_SIZE64)
185 #define TASK_SIZE_OF(child)     ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)
186
187 #define TASK_UNMAPPED_BASE      PAGE_ALIGN(TASK_SIZE/3)
188
189 /*
190  * Size of io_bitmap.
191  */
192 #define IO_BITMAP_BITS  65536
193 #define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
194 #define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
195 #ifndef CONFIG_X86_NO_TSS
196 #define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
197 #endif
198 #define INVALID_IO_BITMAP_OFFSET 0x8000
199
200 struct i387_fxsave_struct {
201         u16     cwd;
202         u16     swd;
203         u16     twd;
204         u16     fop;
205         u64     rip;
206         u64     rdp; 
207         u32     mxcsr;
208         u32     mxcsr_mask;
209         u32     st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
210         u32     xmm_space[64];  /* 16*16 bytes for each XMM-reg = 128 bytes */
211         u32     padding[24];
212 } __attribute__ ((aligned (16)));
213
214 union i387_union {
215         struct i387_fxsave_struct       fxsave;
216 };
217
218 #ifndef CONFIG_X86_NO_TSS
219 struct tss_struct {
220         u32 reserved1;
221         u64 rsp0;       
222         u64 rsp1;
223         u64 rsp2;
224         u64 reserved2;
225         u64 ist[7];
226         u32 reserved3;
227         u32 reserved4;
228         u16 reserved5;
229         u16 io_bitmap_base;
230         /*
231          * The extra 1 is there because the CPU will access an
232          * additional byte beyond the end of the IO permission
233          * bitmap. The extra byte must be all 1 bits, and must
234          * be within the limit. Thus we have:
235          *
236          * 128 bytes, the bitmap itself, for ports 0..0x3ff
237          * 8 bytes, for an extra "long" of ~0UL
238          */
239         unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
240 } __attribute__((packed)) ____cacheline_aligned;
241
242 DECLARE_PER_CPU(struct tss_struct,init_tss);
243 #endif
244
245 extern struct cpuinfo_x86 boot_cpu_data;
246
247 #ifdef CONFIG_X86_VSMP
248 #define ARCH_MIN_TASKALIGN      (1 << INTERNODE_CACHE_SHIFT)
249 #define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT)
250 #else
251 #define ARCH_MIN_TASKALIGN      16
252 #define ARCH_MIN_MMSTRUCT_ALIGN 0
253 #endif
254
255 struct thread_struct {
256         unsigned long   rsp0;
257         unsigned long   rsp;
258         unsigned long   userrsp;        /* Copy from PDA */ 
259         unsigned long   fs;
260         unsigned long   gs;
261         unsigned short  es, ds, fsindex, gsindex;       
262 /* Hardware debugging registers */
263         unsigned long   debugreg0;  
264         unsigned long   debugreg1;  
265         unsigned long   debugreg2;  
266         unsigned long   debugreg3;  
267         unsigned long   debugreg6;  
268         unsigned long   debugreg7;  
269 /* fault info */
270         unsigned long   cr2, trap_no, error_code;
271 /* floating point info */
272         union i387_union        i387  __attribute__((aligned(16)));
273 /* IO permissions. the bitmap could be moved into the GDT, that would make
274    switch faster for a limited number of ioperm using tasks. -AK */
275         int             ioperm;
276         unsigned long   *io_bitmap_ptr;
277         unsigned io_bitmap_max;
278 /* cached TLS descriptors. */
279         u64 tls_array[GDT_ENTRY_TLS_ENTRIES];
280         unsigned int    iopl;
281 } __attribute__((aligned(16)));
282
283 #define INIT_THREAD  { \
284         .rsp0 = (unsigned long)&init_stack + sizeof(init_stack) \
285 }
286
287 #ifndef CONFIG_X86_NO_TSS
288 #define INIT_TSS  { \
289         .rsp0 = (unsigned long)&init_stack + sizeof(init_stack) \
290 }
291 #endif
292
293 #define INIT_MMAP \
294 { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
295
296 #define start_thread(regs,new_rip,new_rsp) do { \
297         asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0));      \
298         load_gs_index(0);                                                       \
299         (regs)->rip = (new_rip);                                                 \
300         (regs)->rsp = (new_rsp);                                                 \
301         write_pda(oldrsp, (new_rsp));                                            \
302         (regs)->cs = __USER_CS;                                                  \
303         (regs)->ss = __USER_DS;                                                  \
304         (regs)->eflags = 0x200;                                                  \
305         set_fs(USER_DS);                                                         \
306 } while(0) 
307
308 #define get_debugreg(var, register)                             \
309         var = HYPERVISOR_get_debugreg(register)
310 #define set_debugreg(value, register)                   \
311         HYPERVISOR_set_debugreg(register, value)
312
313 struct task_struct;
314 struct mm_struct;
315
316 /* Free all resources held by a thread. */
317 extern void release_thread(struct task_struct *);
318
319 /* Prepare to copy thread state - unlazy all lazy status */
320 extern void prepare_to_copy(struct task_struct *tsk);
321
322 /*
323  * create a kernel thread without removing it from tasklists
324  */
325 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
326
327 /*
328  * Return saved PC of a blocked thread.
329  * What is this good for? it will be always the scheduler or ret_from_fork.
330  */
331 #define thread_saved_pc(t) (*(unsigned long *)((t)->thread.rsp - 8))
332
333 extern unsigned long get_wchan(struct task_struct *p);
334 #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.rsp0 - 1)
335 #define KSTK_EIP(tsk) (task_pt_regs(tsk)->rip)
336 #define KSTK_ESP(tsk) -1 /* sorry. doesn't work for syscall. */
337
338
339 struct microcode_header {
340         unsigned int hdrver;
341         unsigned int rev;
342         unsigned int date;
343         unsigned int sig;
344         unsigned int cksum;
345         unsigned int ldrver;
346         unsigned int pf;
347         unsigned int datasize;
348         unsigned int totalsize;
349         unsigned int reserved[3];
350 };
351
352 struct microcode {
353         struct microcode_header hdr;
354         unsigned int bits[0];
355 };
356
357 typedef struct microcode microcode_t;
358 typedef struct microcode_header microcode_header_t;
359
360 /* microcode format is extended from prescott processors */
361 struct extended_signature {
362         unsigned int sig;
363         unsigned int pf;
364         unsigned int cksum;
365 };
366
367 struct extended_sigtable {
368         unsigned int count;
369         unsigned int cksum;
370         unsigned int reserved[3];
371         struct extended_signature sigs[0];
372 };
373
374
375 #define ASM_NOP1 K8_NOP1
376 #define ASM_NOP2 K8_NOP2
377 #define ASM_NOP3 K8_NOP3
378 #define ASM_NOP4 K8_NOP4
379 #define ASM_NOP5 K8_NOP5
380 #define ASM_NOP6 K8_NOP6
381 #define ASM_NOP7 K8_NOP7
382 #define ASM_NOP8 K8_NOP8
383
384 /* Opteron nops */
385 #define K8_NOP1 ".byte 0x90\n"
386 #define K8_NOP2 ".byte 0x66,0x90\n" 
387 #define K8_NOP3 ".byte 0x66,0x66,0x90\n" 
388 #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n" 
389 #define K8_NOP5 K8_NOP3 K8_NOP2 
390 #define K8_NOP6 K8_NOP3 K8_NOP3
391 #define K8_NOP7 K8_NOP4 K8_NOP3
392 #define K8_NOP8 K8_NOP4 K8_NOP4
393
394 #define ASM_NOP_MAX 8
395
396 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
397 static inline void rep_nop(void)
398 {
399         __asm__ __volatile__("rep;nop": : :"memory");
400 }
401
402 /* Stop speculative execution */
403 static inline void sync_core(void)
404
405         int tmp;
406         asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
407
408
409 #define cpu_has_fpu 1
410
411 #define ARCH_HAS_PREFETCH
412 static inline void prefetch(void *x) 
413
414         asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
415
416
417 #define ARCH_HAS_PREFETCHW 1
418 static inline void prefetchw(void *x) 
419
420         alternative_input("prefetcht0 (%1)",
421                           "prefetchw (%1)",
422                           X86_FEATURE_3DNOW,
423                           "r" (x));
424
425
426 #define ARCH_HAS_SPINLOCK_PREFETCH 1
427
428 #define spin_lock_prefetch(x)  prefetchw(x)
429
430 #define cpu_relax()   rep_nop()
431
432 /*
433  *      NSC/Cyrix CPU configuration register indexes
434  */
435 #define CX86_CCR0 0xc0
436 #define CX86_CCR1 0xc1
437 #define CX86_CCR2 0xc2
438 #define CX86_CCR3 0xc3
439 #define CX86_CCR4 0xe8
440 #define CX86_CCR5 0xe9
441 #define CX86_CCR6 0xea
442 #define CX86_CCR7 0xeb
443 #define CX86_DIR0 0xfe
444 #define CX86_DIR1 0xff
445 #define CX86_ARR_BASE 0xc4
446 #define CX86_RCR_BASE 0xdc
447
448 /*
449  *      NSC/Cyrix CPU indexed register access macros
450  */
451
452 #define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })
453
454 #define setCx86(reg, data) do { \
455         outb((reg), 0x22); \
456         outb((data), 0x23); \
457 } while (0)
458
459 static inline void serialize_cpu(void)
460 {
461         __asm__ __volatile__ ("cpuid" : : : "ax", "bx", "cx", "dx");
462 }
463
464 static inline void __monitor(const void *eax, unsigned long ecx,
465                 unsigned long edx)
466 {
467         /* "monitor %eax,%ecx,%edx;" */
468         asm volatile(
469                 ".byte 0x0f,0x01,0xc8;"
470                 : :"a" (eax), "c" (ecx), "d"(edx));
471 }
472
473 static inline void __mwait(unsigned long eax, unsigned long ecx)
474 {
475         /* "mwait %eax,%ecx;" */
476         asm volatile(
477                 ".byte 0x0f,0x01,0xc9;"
478                 : :"a" (eax), "c" (ecx));
479 }
480
481 #define stack_current() \
482 ({                                                              \
483         struct thread_info *ti;                                 \
484         asm("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK));  \
485         ti->task;                                       \
486 })
487
488 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
489
490 extern unsigned long boot_option_idle_override;
491 /* Boot loader type from the setup header */
492 extern int bootloader_type;
493
494 #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
495
496 #endif /* __ASM_X86_64_PROCESSOR_H */