]> git.karo-electronics.de Git - mv-sheeva.git/blob - include/asm-x86/processor_64.h
acecef80a510b25de9791056dab4dc579b1077f5
[mv-sheeva.git] / include / asm-x86 / processor_64.h
1 /*
2  * Copyright (C) 1994 Linus Torvalds
3  */
4
5 #ifndef __ASM_X86_64_PROCESSOR_H
6 #define __ASM_X86_64_PROCESSOR_H
7
8 #include <asm/segment.h>
9 #include <asm/page.h>
10 #include <asm/types.h>
11 #include <asm/sigcontext.h>
12 #include <asm/cpufeature.h>
13 #include <linux/threads.h>
14 #include <asm/msr.h>
15 #include <asm/current.h>
16 #include <asm/system.h>
17 #include <asm/mmsegment.h>
18 #include <asm/percpu.h>
19 #include <linux/personality.h>
20 #include <linux/cpumask.h>
21 #include <asm/desc_defs.h>
22
23 /*
24  * Default implementation of macro that returns current
25  * instruction pointer ("program counter").
26  */
27 #define current_text_addr() ({ void *pc; asm volatile("leaq 1f(%%rip),%0\n1:":"=r"(pc)); pc; })
28
29 /*
30  *  CPU type and hardware bug flags. Kept separately for each CPU.
31  */
32
33 struct cpuinfo_x86 {
34         __u8    x86;            /* CPU family */
35         __u8    x86_vendor;     /* CPU vendor */
36         __u8    x86_model;
37         __u8    x86_mask;
38         int     cpuid_level;    /* Maximum supported CPUID level, -1=no CPUID */
39         __u32   x86_capability[NCAPINTS];
40         char    x86_vendor_id[16];
41         char    x86_model_id[64];
42         int     x86_cache_size;  /* in KB */
43         int     x86_clflush_size;
44         int     x86_cache_alignment;
45         int     x86_tlbsize;    /* number of 4K pages in DTLB/ITLB combined(in pages)*/
46         __u8    x86_virt_bits, x86_phys_bits;
47         __u8    x86_max_cores;  /* cpuid returned max cores value */
48         __u8    x86_coreid_bits; /* cpuid returned core id bits */
49         __u32   x86_power;      
50         __u32   extended_cpuid_level;   /* Max extended CPUID function supported */
51         unsigned long loops_per_jiffy;
52 #ifdef CONFIG_SMP
53         cpumask_t llc_shared_map;       /* cpus sharing the last level cache */
54 #endif
55         __u8    apicid;
56 #ifdef CONFIG_SMP
57         __u8    booted_cores;   /* number of cores as seen by OS */
58         __u8    phys_proc_id;   /* Physical Processor id. */
59         __u8    cpu_core_id;    /* Core id. */
60         __u8    cpu_index;      /* index into per_cpu list */
61 #endif
62 } ____cacheline_aligned;
63
64 #define X86_VENDOR_INTEL 0
65 #define X86_VENDOR_CYRIX 1
66 #define X86_VENDOR_AMD 2
67 #define X86_VENDOR_UMC 3
68 #define X86_VENDOR_NEXGEN 4
69 #define X86_VENDOR_CENTAUR 5
70 #define X86_VENDOR_TRANSMETA 7
71 #define X86_VENDOR_NUM 8
72 #define X86_VENDOR_UNKNOWN 0xff
73
74 #ifdef CONFIG_SMP
75 DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
76 #define cpu_data(cpu)           per_cpu(cpu_info, cpu)
77 #define current_cpu_data        cpu_data(smp_processor_id())
78 #else
79 #define cpu_data(cpu)           boot_cpu_data
80 #define current_cpu_data        boot_cpu_data
81 #endif
82
83 extern char ignore_irq13;
84
85 extern void identify_cpu(struct cpuinfo_x86 *);
86 extern void print_cpu_info(struct cpuinfo_x86 *);
87 extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
88 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
89 extern unsigned short num_cache_leaves;
90
91 /*
92  * Save the cr4 feature set we're using (ie
93  * Pentium 4MB enable and PPro Global page
94  * enable), so that any CPU's that boot up
95  * after us can get the correct flags.
96  */
97 extern unsigned long mmu_cr4_features;
98
99 static inline void set_in_cr4 (unsigned long mask)
100 {
101         mmu_cr4_features |= mask;
102         __asm__("movq %%cr4,%%rax\n\t"
103                 "orq %0,%%rax\n\t"
104                 "movq %%rax,%%cr4\n"
105                 : : "irg" (mask)
106                 :"ax");
107 }
108
109 static inline void clear_in_cr4 (unsigned long mask)
110 {
111         mmu_cr4_features &= ~mask;
112         __asm__("movq %%cr4,%%rax\n\t"
113                 "andq %0,%%rax\n\t"
114                 "movq %%rax,%%cr4\n"
115                 : : "irg" (~mask)
116                 :"ax");
117 }
118
119
120 /*
121  * User space process size. 47bits minus one guard page.
122  */
123 #define TASK_SIZE64     (0x800000000000UL - 4096)
124
125 /* This decides where the kernel will search for a free chunk of vm
126  * space during mmap's.
127  */
128 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000)
129
130 #define TASK_SIZE               (test_thread_flag(TIF_IA32) ? IA32_PAGE_OFFSET : TASK_SIZE64)
131 #define TASK_SIZE_OF(child)     ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)
132
133 #define TASK_UNMAPPED_BASE      PAGE_ALIGN(TASK_SIZE/3)
134
135 /*
136  * Size of io_bitmap.
137  */
138 #define IO_BITMAP_BITS  65536
139 #define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
140 #define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
141 #define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
142 #define INVALID_IO_BITMAP_OFFSET 0x8000
143
144 struct i387_fxsave_struct {
145         u16     cwd;
146         u16     swd;
147         u16     twd;
148         u16     fop;
149         u64     rip;
150         u64     rdp; 
151         u32     mxcsr;
152         u32     mxcsr_mask;
153         u32     st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
154         u32     xmm_space[64];  /* 16*16 bytes for each XMM-reg = 256 bytes */
155         u32     padding[24];
156 } __attribute__ ((aligned (16)));
157
158 union i387_union {
159         struct i387_fxsave_struct       fxsave;
160 };
161
162 struct tss_struct {
163         u32 reserved1;
164         u64 sp0;
165         u64 sp1;
166         u64 sp2;
167         u64 reserved2;
168         u64 ist[7];
169         u32 reserved3;
170         u32 reserved4;
171         u16 reserved5;
172         u16 io_bitmap_base;
173         /*
174          * The extra 1 is there because the CPU will access an
175          * additional byte beyond the end of the IO permission
176          * bitmap. The extra byte must be all 1 bits, and must
177          * be within the limit. Thus we have:
178          *
179          * 128 bytes, the bitmap itself, for ports 0..0x3ff
180          * 8 bytes, for an extra "long" of ~0UL
181          */
182         unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
183 } __attribute__((packed)) ____cacheline_aligned;
184
185
186 extern struct cpuinfo_x86 boot_cpu_data;
187 DECLARE_PER_CPU(struct tss_struct,init_tss);
188 /* Save the original ist values for checking stack pointers during debugging */
189 struct orig_ist {
190         unsigned long ist[7];
191 };
192 DECLARE_PER_CPU(struct orig_ist, orig_ist);
193
194 #ifdef CONFIG_X86_VSMP
195 #define ARCH_MIN_TASKALIGN      (1 << INTERNODE_CACHE_SHIFT)
196 #define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT)
197 #else
198 #define ARCH_MIN_TASKALIGN      16
199 #define ARCH_MIN_MMSTRUCT_ALIGN 0
200 #endif
201
202 struct thread_struct {
203         unsigned long   sp0;
204         unsigned long   sp;
205         unsigned long   usersp; /* Copy from PDA */
206         unsigned long   fs;
207         unsigned long   gs;
208         unsigned short  es, ds, fsindex, gsindex;       
209 /* Hardware debugging registers */
210         unsigned long   debugreg0;  
211         unsigned long   debugreg1;  
212         unsigned long   debugreg2;  
213         unsigned long   debugreg3;  
214         unsigned long   debugreg6;  
215         unsigned long   debugreg7;  
216 /* fault info */
217         unsigned long   cr2, trap_no, error_code;
218 /* floating point info */
219         union i387_union        i387  __attribute__((aligned(16)));
220 /* IO permissions. the bitmap could be moved into the GDT, that would make
221    switch faster for a limited number of ioperm using tasks. -AK */
222         int             ioperm;
223         unsigned long   *io_bitmap_ptr;
224         unsigned io_bitmap_max;
225 /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set.  */
226         unsigned long   debugctlmsr;
227 /* Debug Store - if not 0 points to a DS Save Area configuration;
228  *               goes into MSR_IA32_DS_AREA */
229         unsigned long   ds_area_msr;
230 /* cached TLS descriptors. */
231         struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
232 } __attribute__((aligned(16)));
233
234 #define INIT_THREAD  { \
235         .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
236 }
237
238 #define INIT_TSS  { \
239         .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
240 }
241
242 #define INIT_MMAP \
243 { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
244
245 #define start_thread(regs,new_rip,new_rsp) do { \
246         asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0));      \
247         load_gs_index(0);                                                       \
248         (regs)->ip = (new_rip);                                          \
249         (regs)->sp = (new_rsp);                                          \
250         write_pda(oldrsp, (new_rsp));                                            \
251         (regs)->cs = __USER_CS;                                                  \
252         (regs)->ss = __USER_DS;                                                  \
253         (regs)->flags = 0x200;                                                   \
254         set_fs(USER_DS);                                                         \
255 } while(0) 
256
257 #define get_debugreg(var, register)                             \
258                 __asm__("movq %%db" #register ", %0"            \
259                         :"=r" (var))
260 #define set_debugreg(value, register)                   \
261                 __asm__("movq %0,%%db" #register                \
262                         : /* no output */                       \
263                         :"r" (value))
264
265 struct task_struct;
266 struct mm_struct;
267
268 /* Free all resources held by a thread. */
269 extern void release_thread(struct task_struct *);
270
271 /* Prepare to copy thread state - unlazy all lazy status */
272 extern void prepare_to_copy(struct task_struct *tsk);
273
274 /*
275  * create a kernel thread without removing it from tasklists
276  */
277 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
278
279 /*
280  * Return saved PC of a blocked thread.
281  * What is this good for? it will be always the scheduler or ret_from_fork.
282  */
283 #define thread_saved_pc(t) (*(unsigned long *)((t)->thread.sp - 8))
284
285 extern unsigned long get_wchan(struct task_struct *p);
286 #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1)
287 #define KSTK_EIP(tsk) (task_pt_regs(tsk)->ip)
288 #define KSTK_ESP(tsk) -1 /* sorry. doesn't work for syscall. */
289
290
291 struct microcode_header {
292         unsigned int hdrver;
293         unsigned int rev;
294         unsigned int date;
295         unsigned int sig;
296         unsigned int cksum;
297         unsigned int ldrver;
298         unsigned int pf;
299         unsigned int datasize;
300         unsigned int totalsize;
301         unsigned int reserved[3];
302 };
303
304 struct microcode {
305         struct microcode_header hdr;
306         unsigned int bits[0];
307 };
308
309 typedef struct microcode microcode_t;
310 typedef struct microcode_header microcode_header_t;
311
312 /* microcode format is extended from prescott processors */
313 struct extended_signature {
314         unsigned int sig;
315         unsigned int pf;
316         unsigned int cksum;
317 };
318
319 struct extended_sigtable {
320         unsigned int count;
321         unsigned int cksum;
322         unsigned int reserved[3];
323         struct extended_signature sigs[0];
324 };
325
326
327 #if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2)
328 #define ASM_NOP1 P6_NOP1
329 #define ASM_NOP2 P6_NOP2
330 #define ASM_NOP3 P6_NOP3
331 #define ASM_NOP4 P6_NOP4
332 #define ASM_NOP5 P6_NOP5
333 #define ASM_NOP6 P6_NOP6
334 #define ASM_NOP7 P6_NOP7
335 #define ASM_NOP8 P6_NOP8
336 #else
337 #define ASM_NOP1 K8_NOP1
338 #define ASM_NOP2 K8_NOP2
339 #define ASM_NOP3 K8_NOP3
340 #define ASM_NOP4 K8_NOP4
341 #define ASM_NOP5 K8_NOP5
342 #define ASM_NOP6 K8_NOP6
343 #define ASM_NOP7 K8_NOP7
344 #define ASM_NOP8 K8_NOP8
345 #endif
346
347 /* Opteron nops */
348 #define K8_NOP1 ".byte 0x90\n"
349 #define K8_NOP2 ".byte 0x66,0x90\n" 
350 #define K8_NOP3 ".byte 0x66,0x66,0x90\n" 
351 #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n" 
352 #define K8_NOP5 K8_NOP3 K8_NOP2 
353 #define K8_NOP6 K8_NOP3 K8_NOP3
354 #define K8_NOP7 K8_NOP4 K8_NOP3
355 #define K8_NOP8 K8_NOP4 K8_NOP4
356
357 /* P6 nops */
358 /* uses eax dependencies (Intel-recommended choice) */
359 #define P6_NOP1 ".byte 0x90\n"
360 #define P6_NOP2 ".byte 0x66,0x90\n"
361 #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
362 #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
363 #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
364 #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
365 #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
366 #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
367
368 #define ASM_NOP_MAX 8
369
370 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
371 static inline void rep_nop(void)
372 {
373         __asm__ __volatile__("rep;nop": : :"memory");
374 }
375
376 /* Stop speculative execution */
377 static inline void sync_core(void)
378
379         int tmp;
380         asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
381
382
383 #define ARCH_HAS_PREFETCHW 1
384 static inline void prefetchw(void *x) 
385
386         alternative_input("prefetcht0 (%1)",
387                           "prefetchw (%1)",
388                           X86_FEATURE_3DNOW,
389                           "r" (x));
390
391
392 #define ARCH_HAS_SPINLOCK_PREFETCH 1
393
394 #define spin_lock_prefetch(x)  prefetchw(x)
395
396 #define cpu_relax()   rep_nop()
397
398 static inline void __monitor(const void *eax, unsigned long ecx,
399                 unsigned long edx)
400 {
401         /* "monitor %eax,%ecx,%edx;" */
402         asm volatile(
403                 ".byte 0x0f,0x01,0xc8;"
404                 : :"a" (eax), "c" (ecx), "d"(edx));
405 }
406
407 static inline void __mwait(unsigned long eax, unsigned long ecx)
408 {
409         /* "mwait %eax,%ecx;" */
410         asm volatile(
411                 ".byte 0x0f,0x01,0xc9;"
412                 : :"a" (eax), "c" (ecx));
413 }
414
415 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
416 {
417         /* "mwait %eax,%ecx;" */
418         asm volatile(
419                 "sti; .byte 0x0f,0x01,0xc9;"
420                 : :"a" (eax), "c" (ecx));
421 }
422
423 extern void mwait_idle_with_hints(unsigned long eax, unsigned long ecx);
424
425 extern int force_mwait;
426
427 extern void select_idle_routine(const struct cpuinfo_x86 *c);
428
429 #define stack_current() \
430 ({                                                              \
431         struct thread_info *ti;                                 \
432         asm("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK));  \
433         ti->task;                                       \
434 })
435
436 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
437
438 extern unsigned long boot_option_idle_override;
439 /* Boot loader type from the setup header */
440 extern int bootloader_type;
441
442 #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
443
444 #endif /* __ASM_X86_64_PROCESSOR_H */