blob: efc87a5aff7f0f5febf0ff04f87b8f72c4a72c6f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/threads.h>
16#include <asm/msr.h>
17#include <asm/current.h>
18#include <asm/system.h>
19#include <asm/mmsegment.h>
20#include <asm/percpu.h>
21#include <linux/personality.h>
Siddha, Suresh B1e9f28f2006-03-27 01:15:22 -080022#include <linux/cpumask.h>
Andi Kleen5d02d7a2007-05-02 19:27:11 +020023#include <asm/processor-flags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
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) \
Zachary Amsden12aaa082005-08-16 12:05:09 -070036 (!((desc)->a | (desc)->b))
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
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
51struct 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;
Siddha, Suresh B94605ef2005-11-05 17:25:54 +010065 __u8 x86_max_cores; /* cpuid returned max cores value */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 __u32 x86_power;
Andi Kleenebfcaa92005-04-16 15:25:18 -070067 __u32 extended_cpuid_level; /* Max extended CPUID function supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 unsigned long loops_per_jiffy;
Siddha, Suresh B1e9f28f2006-03-27 01:15:22 -080069#ifdef CONFIG_SMP
70 cpumask_t llc_shared_map; /* cpus sharing the last level cache */
71#endif
Siddha, Suresh B94605ef2005-11-05 17:25:54 +010072 __u8 apicid;
Rohit Sethf3fa8eb2006-06-26 13:58:17 +020073#ifdef CONFIG_SMP
Siddha, Suresh B94605ef2005-11-05 17:25:54 +010074 __u8 booted_cores; /* number of cores as seen by OS */
Rohit Sethf3fa8eb2006-06-26 13:58:17 +020075 __u8 phys_proc_id; /* Physical Processor id. */
76 __u8 cpu_core_id; /* Core id. */
77#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070078} ____cacheline_aligned;
79
80#define X86_VENDOR_INTEL 0
81#define X86_VENDOR_CYRIX 1
82#define X86_VENDOR_AMD 2
83#define X86_VENDOR_UMC 3
84#define X86_VENDOR_NEXGEN 4
85#define X86_VENDOR_CENTAUR 5
86#define X86_VENDOR_RISE 6
87#define X86_VENDOR_TRANSMETA 7
88#define X86_VENDOR_NUM 8
89#define X86_VENDOR_UNKNOWN 0xff
90
91#ifdef CONFIG_SMP
92extern struct cpuinfo_x86 cpu_data[];
93#define current_cpu_data cpu_data[smp_processor_id()]
94#else
95#define cpu_data (&boot_cpu_data)
96#define current_cpu_data boot_cpu_data
97#endif
98
99extern char ignore_irq13;
100
101extern void identify_cpu(struct cpuinfo_x86 *);
102extern void print_cpu_info(struct cpuinfo_x86 *);
Venki Pallipadi1d679532007-07-11 12:18:32 -0700103extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
Andi Kleen240cd6a802006-06-26 13:56:13 +0200105extern unsigned short num_cache_leaves;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * Save the cr4 feature set we're using (ie
109 * Pentium 4MB enable and PPro Global page
110 * enable), so that any CPU's that boot up
111 * after us can get the correct flags.
112 */
113extern unsigned long mmu_cr4_features;
114
115static inline void set_in_cr4 (unsigned long mask)
116{
117 mmu_cr4_features |= mask;
118 __asm__("movq %%cr4,%%rax\n\t"
119 "orq %0,%%rax\n\t"
120 "movq %%rax,%%cr4\n"
121 : : "irg" (mask)
122 :"ax");
123}
124
125static inline void clear_in_cr4 (unsigned long mask)
126{
127 mmu_cr4_features &= ~mask;
128 __asm__("movq %%cr4,%%rax\n\t"
129 "andq %0,%%rax\n\t"
130 "movq %%rax,%%cr4\n"
131 : : "irg" (~mask)
132 :"ax");
133}
134
135
136/*
Andi Kleen637716a2005-05-16 21:53:20 -0700137 * User space process size. 47bits minus one guard page.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 */
Suresh Siddha84929802005-06-21 17:14:32 -0700139#define TASK_SIZE64 (0x800000000000UL - 4096)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141/* This decides where the kernel will search for a free chunk of vm
142 * space during mmap's.
143 */
144#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000)
Suresh Siddha84929802005-06-21 17:14:32 -0700145
146#define TASK_SIZE (test_thread_flag(TIF_IA32) ? IA32_PAGE_OFFSET : TASK_SIZE64)
147#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)
148
149#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE/3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151/*
152 * Size of io_bitmap.
153 */
154#define IO_BITMAP_BITS 65536
155#define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
156#define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
157#define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
158#define INVALID_IO_BITMAP_OFFSET 0x8000
159
160struct i387_fxsave_struct {
161 u16 cwd;
162 u16 swd;
163 u16 twd;
164 u16 fop;
165 u64 rip;
166 u64 rdp;
167 u32 mxcsr;
168 u32 mxcsr_mask;
169 u32 st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
Avi Kivitybbf30a12007-05-02 19:27:12 +0200170 u32 xmm_space[64]; /* 16*16 bytes for each XMM-reg = 256 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 u32 padding[24];
172} __attribute__ ((aligned (16)));
173
174union i387_union {
175 struct i387_fxsave_struct fxsave;
176};
177
178struct tss_struct {
179 u32 reserved1;
180 u64 rsp0;
181 u64 rsp1;
182 u64 rsp2;
183 u64 reserved2;
184 u64 ist[7];
185 u32 reserved3;
186 u32 reserved4;
187 u16 reserved5;
188 u16 io_bitmap_base;
189 /*
190 * The extra 1 is there because the CPU will access an
191 * additional byte beyond the end of the IO permission
192 * bitmap. The extra byte must be all 1 bits, and must
193 * be within the limit. Thus we have:
194 *
195 * 128 bytes, the bitmap itself, for ports 0..0x3ff
196 * 8 bytes, for an extra "long" of ~0UL
197 */
198 unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
199} __attribute__((packed)) ____cacheline_aligned;
200
Keith Owens01ebb772006-08-30 19:37:19 +0200201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202extern struct cpuinfo_x86 boot_cpu_data;
203DECLARE_PER_CPU(struct tss_struct,init_tss);
Keith Owens01ebb772006-08-30 19:37:19 +0200204/* Save the original ist values for checking stack pointers during debugging */
205struct orig_ist {
206 unsigned long ist[7];
207};
208DECLARE_PER_CPU(struct orig_ist, orig_ist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Ravikiran G Thirumalai5fd63b32006-01-11 22:46:15 +0100210#ifdef CONFIG_X86_VSMP
211#define ARCH_MIN_TASKALIGN (1 << INTERNODE_CACHE_SHIFT)
212#define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT)
213#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#define ARCH_MIN_TASKALIGN 16
Ravikiran G Thirumalai5fd63b32006-01-11 22:46:15 +0100215#define ARCH_MIN_MMSTRUCT_ALIGN 0
216#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218struct thread_struct {
219 unsigned long rsp0;
220 unsigned long rsp;
221 unsigned long userrsp; /* Copy from PDA */
222 unsigned long fs;
223 unsigned long gs;
224 unsigned short es, ds, fsindex, gsindex;
225/* Hardware debugging registers */
226 unsigned long debugreg0;
227 unsigned long debugreg1;
228 unsigned long debugreg2;
229 unsigned long debugreg3;
230 unsigned long debugreg6;
231 unsigned long debugreg7;
232/* fault info */
233 unsigned long cr2, trap_no, error_code;
234/* floating point info */
235 union i387_union i387 __attribute__((aligned(16)));
236/* IO permissions. the bitmap could be moved into the GDT, that would make
237 switch faster for a limited number of ioperm using tasks. -AK */
238 int ioperm;
239 unsigned long *io_bitmap_ptr;
240 unsigned io_bitmap_max;
241/* cached TLS descriptors. */
242 u64 tls_array[GDT_ENTRY_TLS_ENTRIES];
243} __attribute__((aligned(16)));
244
Andi Kleena0d58c92005-09-12 18:49:24 +0200245#define INIT_THREAD { \
246 .rsp0 = (unsigned long)&init_stack + sizeof(init_stack) \
247}
248
249#define INIT_TSS { \
250 .rsp0 = (unsigned long)&init_stack + sizeof(init_stack) \
251}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253#define INIT_MMAP \
254{ &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define start_thread(regs,new_rip,new_rsp) do { \
257 asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0)); \
258 load_gs_index(0); \
259 (regs)->rip = (new_rip); \
260 (regs)->rsp = (new_rsp); \
261 write_pda(oldrsp, (new_rsp)); \
262 (regs)->cs = __USER_CS; \
263 (regs)->ss = __USER_DS; \
264 (regs)->eflags = 0x200; \
265 set_fs(USER_DS); \
266} while(0)
267
Vincent Hanqueze9129e52005-06-23 00:08:46 -0700268#define get_debugreg(var, register) \
269 __asm__("movq %%db" #register ", %0" \
270 :"=r" (var))
271#define set_debugreg(value, register) \
272 __asm__("movq %0,%%db" #register \
273 : /* no output */ \
274 :"r" (value))
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276struct task_struct;
277struct mm_struct;
278
279/* Free all resources held by a thread. */
280extern void release_thread(struct task_struct *);
281
282/* Prepare to copy thread state - unlazy all lazy status */
283extern void prepare_to_copy(struct task_struct *tsk);
284
285/*
286 * create a kernel thread without removing it from tasklists
287 */
288extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
289
290/*
291 * Return saved PC of a blocked thread.
292 * What is this good for? it will be always the scheduler or ret_from_fork.
293 */
294#define thread_saved_pc(t) (*(unsigned long *)((t)->thread.rsp - 8))
295
296extern unsigned long get_wchan(struct task_struct *p);
Al Virobb049232006-01-12 01:05:38 -0800297#define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.rsp0 - 1)
298#define KSTK_EIP(tsk) (task_pt_regs(tsk)->rip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299#define KSTK_ESP(tsk) -1 /* sorry. doesn't work for syscall. */
300
301
302struct microcode_header {
303 unsigned int hdrver;
304 unsigned int rev;
305 unsigned int date;
306 unsigned int sig;
307 unsigned int cksum;
308 unsigned int ldrver;
309 unsigned int pf;
310 unsigned int datasize;
311 unsigned int totalsize;
312 unsigned int reserved[3];
313};
314
315struct microcode {
316 struct microcode_header hdr;
317 unsigned int bits[0];
318};
319
320typedef struct microcode microcode_t;
321typedef struct microcode_header microcode_header_t;
322
323/* microcode format is extended from prescott processors */
324struct extended_signature {
325 unsigned int sig;
326 unsigned int pf;
327 unsigned int cksum;
328};
329
330struct extended_sigtable {
331 unsigned int count;
332 unsigned int cksum;
333 unsigned int reserved[3];
334 struct extended_signature sigs[0];
335};
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338#define ASM_NOP1 K8_NOP1
339#define ASM_NOP2 K8_NOP2
340#define ASM_NOP3 K8_NOP3
341#define ASM_NOP4 K8_NOP4
342#define ASM_NOP5 K8_NOP5
343#define ASM_NOP6 K8_NOP6
344#define ASM_NOP7 K8_NOP7
345#define ASM_NOP8 K8_NOP8
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#define ASM_NOP_MAX 8
358
359/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
Adrian Bunk9c0aa0f2005-09-12 18:49:24 +0200360static inline void rep_nop(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
362 __asm__ __volatile__("rep;nop": : :"memory");
363}
364
365/* Stop speculative execution */
Adrian Bunk9c0aa0f2005-09-12 18:49:24 +0200366static inline void sync_core(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 int tmp;
369 asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
370}
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372#define ARCH_HAS_PREFETCH
373static inline void prefetch(void *x)
374{
375 asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
376}
377
378#define ARCH_HAS_PREFETCHW 1
379static inline void prefetchw(void *x)
380{
Eric Dumazet19aaabb2005-09-06 15:16:17 -0700381 alternative_input("prefetcht0 (%1)",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 "prefetchw (%1)",
383 X86_FEATURE_3DNOW,
384 "r" (x));
385}
386
387#define ARCH_HAS_SPINLOCK_PREFETCH 1
388
389#define spin_lock_prefetch(x) prefetchw(x)
390
391#define cpu_relax() rep_nop()
392
393/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 * NSC/Cyrix CPU indexed register access macros
395 */
396
397#define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })
398
399#define setCx86(reg, data) do { \
400 outb((reg), 0x22); \
401 outb((data), 0x23); \
402} while (0)
403
Zachary Amsden245067d2005-09-03 15:56:37 -0700404static inline void serialize_cpu(void)
405{
406 __asm__ __volatile__ ("cpuid" : : : "ax", "bx", "cx", "dx");
407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409static inline void __monitor(const void *eax, unsigned long ecx,
410 unsigned long edx)
411{
412 /* "monitor %eax,%ecx,%edx;" */
413 asm volatile(
414 ".byte 0x0f,0x01,0xc8;"
415 : :"a" (eax), "c" (ecx), "d"(edx));
416}
417
418static inline void __mwait(unsigned long eax, unsigned long ecx)
419{
420 /* "mwait %eax,%ecx;" */
421 asm volatile(
422 ".byte 0x0f,0x01,0xc9;"
423 : :"a" (eax), "c" (ecx));
424}
425
Venkatesh Pallipadid331e732006-12-07 02:14:13 +0100426static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
427{
428 /* "mwait %eax,%ecx;" */
429 asm volatile(
430 "sti; .byte 0x0f,0x01,0xc9;"
431 : :"a" (eax), "c" (ecx));
432}
433
Venkatesh Pallipadi991528d2006-09-25 16:28:13 -0700434extern void mwait_idle_with_hints(unsigned long eax, unsigned long ecx);
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define stack_current() \
437({ \
438 struct thread_info *ti; \
439 asm("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
440 ti->task; \
441})
442
443#define cache_line_size() (boot_cpu_data.x86_cache_alignment)
444
445extern unsigned long boot_option_idle_override;
446/* Boot loader type from the setup header */
447extern int bootloader_type;
448
Andi Kleen88172102006-01-17 07:03:38 +0100449#define HAVE_ARCH_PICK_MMAP_LAYOUT 1
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#endif /* __ASM_X86_64_PROCESSOR_H */