1 #ifndef __ASM_X86_PROCESSOR_H
2 #define __ASM_X86_PROCESSOR_H
4 #include <asm/processor-flags.h>
6 /* Forward declaration, a strange C thing */
11 #include <asm/percpu.h>
12 #include <asm/system.h>
13 #include <asm/percpu.h>
14 #include <linux/cpumask.h>
15 #include <linux/cache.h>
18 * Default implementation of macro that returns current
19 * instruction pointer ("program counter").
21 static inline void *current_text_addr(void)
24 asm volatile("mov $1f,%0\n1:":"=r" (pc));
28 #ifdef CONFIG_X86_VSMP
29 #define ARCH_MIN_TASKALIGN (1 << INTERNODE_CACHE_SHIFT)
30 #define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT)
32 #define ARCH_MIN_TASKALIGN 16
33 #define ARCH_MIN_MMSTRUCT_ALIGN 0
37 * CPU type and hardware bug flags. Kept separately for each CPU.
38 * Members of this structure are referenced in head.S, so think twice
39 * before touching them. [mj]
43 __u8 x86; /* CPU family */
44 __u8 x86_vendor; /* CPU vendor */
48 char wp_works_ok; /* It doesn't on 386's */
49 char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
57 /* number of 4K pages in DTLB/ITLB combined(in pages)*/
59 __u8 x86_virt_bits, x86_phys_bits;
60 /* cpuid returned core id bits */
62 /* Max extended CPUID function supported */
63 __u32 extended_cpuid_level;
65 int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
66 __u32 x86_capability[NCAPINTS];
67 char x86_vendor_id[16];
68 char x86_model_id[64];
69 int x86_cache_size; /* in KB - valid for CPUS which support this
71 int x86_cache_alignment; /* In bytes */
73 unsigned long loops_per_jiffy;
75 cpumask_t llc_shared_map; /* cpus sharing the last level cache */
77 unsigned char x86_max_cores; /* cpuid returned max cores value */
79 unsigned short x86_clflush_size;
81 unsigned char booted_cores; /* number of cores as seen by OS */
82 __u8 phys_proc_id; /* Physical processor id. */
83 __u8 cpu_core_id; /* Core id */
84 __u8 cpu_index; /* index into per_cpu list */
86 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
88 #define X86_VENDOR_INTEL 0
89 #define X86_VENDOR_CYRIX 1
90 #define X86_VENDOR_AMD 2
91 #define X86_VENDOR_UMC 3
92 #define X86_VENDOR_NEXGEN 4
93 #define X86_VENDOR_CENTAUR 5
94 #define X86_VENDOR_TRANSMETA 7
95 #define X86_VENDOR_NSC 8
96 #define X86_VENDOR_NUM 9
97 #define X86_VENDOR_UNKNOWN 0xff
99 extern struct cpuinfo_x86 boot_cpu_data;
102 DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
103 #define cpu_data(cpu) per_cpu(cpu_info, cpu)
104 #define current_cpu_data cpu_data(smp_processor_id())
106 #define cpu_data(cpu) boot_cpu_data
107 #define current_cpu_data boot_cpu_data
110 extern void print_cpu_info(struct cpuinfo_x86 *);
111 extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
112 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
113 extern unsigned short num_cache_leaves;
115 static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
116 unsigned int *ecx, unsigned int *edx)
118 /* ecx is often an input as well as an output. */
124 : "0" (*eax), "2" (*ecx));
127 static inline void load_cr3(pgd_t *pgdir)
129 write_cr3(__pa(pgdir));
133 /* This is the TSS defined by the hardware. */
135 unsigned short back_link, __blh;
137 unsigned short ss0, __ss0h;
139 unsigned short ss1, __ss1h; /* ss1 caches MSR_IA32_SYSENTER_CS */
141 unsigned short ss2, __ss2h;
145 unsigned long ax, cx, dx, bx;
146 unsigned long sp, bp, si, di;
147 unsigned short es, __esh;
148 unsigned short cs, __csh;
149 unsigned short ss, __ssh;
150 unsigned short ds, __dsh;
151 unsigned short fs, __fsh;
152 unsigned short gs, __gsh;
153 unsigned short ldt, __ldth;
154 unsigned short trace, io_bitmap_base;
155 } __attribute__((packed));
168 } __attribute__((packed)) ____cacheline_aligned;
174 #define IO_BITMAP_BITS 65536
175 #define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
176 #define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
177 #define IO_BITMAP_OFFSET offsetof(struct tss_struct, io_bitmap)
178 #define INVALID_IO_BITMAP_OFFSET 0x8000
179 #define INVALID_IO_BITMAP_OFFSET_LAZY 0x9000
182 struct x86_hw_tss x86_tss;
185 * The extra 1 is there because the CPU will access an
186 * additional byte beyond the end of the IO permission
187 * bitmap. The extra byte must be all 1 bits, and must
188 * be within the limit.
190 unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
192 * Cache the current maximum and the last task that used the bitmap:
194 unsigned long io_bitmap_max;
195 struct thread_struct *io_bitmap_owner;
197 * pads the TSS to be cacheline-aligned (size is 0x100)
199 unsigned long __cacheline_filler[35];
201 * .. and then another 0x100 bytes for emergency kernel stack
203 unsigned long stack[64];
204 } __attribute__((packed));
206 DECLARE_PER_CPU(struct tss_struct, init_tss);
209 # include "processor_32.h"
211 # include "processor_64.h"
214 extern void print_cpu_info(struct cpuinfo_x86 *);
215 extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
216 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
217 extern unsigned short num_cache_leaves;
219 struct thread_struct {
220 /* cached TLS descriptors. */
221 struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
225 unsigned long sysenter_cs;
227 unsigned long usersp; /* Copy from PDA */
228 unsigned short es, ds, fsindex, gsindex;
233 /* Hardware debugging registers */
234 unsigned long debugreg0;
235 unsigned long debugreg1;
236 unsigned long debugreg2;
237 unsigned long debugreg3;
238 unsigned long debugreg6;
239 unsigned long debugreg7;
241 unsigned long cr2, trap_no, error_code;
242 /* floating point info */
243 union i387_union i387 __attribute__((aligned(16)));;
245 /* virtual 86 mode info */
246 struct vm86_struct __user *vm86_info;
247 unsigned long screen_bitmap;
248 unsigned long v86flags, v86mask, saved_sp0;
249 unsigned int saved_fs, saved_gs;
252 unsigned long *io_bitmap_ptr;
254 /* max allowed port in the bitmap, in bytes: */
255 unsigned io_bitmap_max;
256 /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set. */
257 unsigned long debugctlmsr;
258 /* Debug Store - if not 0 points to a DS Save Area configuration;
259 * goes into MSR_IA32_DS_AREA */
260 unsigned long ds_area_msr;
263 static inline unsigned long native_get_debugreg(int regno)
265 unsigned long val = 0; /* Damn you, gcc! */
269 asm("mov %%db0, %0" :"=r" (val)); break;
271 asm("mov %%db1, %0" :"=r" (val)); break;
273 asm("mov %%db2, %0" :"=r" (val)); break;
275 asm("mov %%db3, %0" :"=r" (val)); break;
277 asm("mov %%db6, %0" :"=r" (val)); break;
279 asm("mov %%db7, %0" :"=r" (val)); break;
286 static inline void native_set_debugreg(int regno, unsigned long value)
290 asm("mov %0,%%db0" : /* no output */ :"r" (value));
293 asm("mov %0,%%db1" : /* no output */ :"r" (value));
296 asm("mov %0,%%db2" : /* no output */ :"r" (value));
299 asm("mov %0,%%db3" : /* no output */ :"r" (value));
302 asm("mov %0,%%db6" : /* no output */ :"r" (value));
305 asm("mov %0,%%db7" : /* no output */ :"r" (value));
313 * Set IOPL bits in EFLAGS from given mask
315 static inline void native_set_iopl_mask(unsigned mask)
319 __asm__ __volatile__ ("pushfl;"
326 : "i" (~X86_EFLAGS_IOPL), "r" (mask));
330 static inline void native_load_sp0(struct tss_struct *tss,
331 struct thread_struct *thread)
333 tss->x86_tss.sp0 = thread->sp0;
335 /* Only happens when SEP is enabled, no need to test "SEP"arately */
336 if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) {
337 tss->x86_tss.ss1 = thread->sysenter_cs;
338 wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
343 #ifdef CONFIG_PARAVIRT
344 #include <asm/paravirt.h>
346 #define __cpuid native_cpuid
347 #define paravirt_enabled() 0
350 * These special macros can be used to get or set a debugging register
352 #define get_debugreg(var, register) \
353 (var) = native_get_debugreg(register)
354 #define set_debugreg(value, register) \
355 native_set_debugreg(register, value)
357 static inline void load_sp0(struct tss_struct *tss,
358 struct thread_struct *thread)
360 native_load_sp0(tss, thread);
363 #define set_iopl_mask native_set_iopl_mask
364 #endif /* CONFIG_PARAVIRT */
367 * Save the cr4 feature set we're using (ie
368 * Pentium 4MB enable and PPro Global page
369 * enable), so that any CPU's that boot up
370 * after us can get the correct flags.
372 extern unsigned long mmu_cr4_features;
374 static inline void set_in_cr4(unsigned long mask)
377 mmu_cr4_features |= mask;
383 static inline void clear_in_cr4(unsigned long mask)
386 mmu_cr4_features &= ~mask;
392 struct microcode_header {
400 unsigned int datasize;
401 unsigned int totalsize;
402 unsigned int reserved[3];
406 struct microcode_header hdr;
407 unsigned int bits[0];
410 typedef struct microcode microcode_t;
411 typedef struct microcode_header microcode_header_t;
413 /* microcode format is extended from prescott processors */
414 struct extended_signature {
420 struct extended_sigtable {
423 unsigned int reserved[3];
424 struct extended_signature sigs[0];
433 * create a kernel thread without removing it from tasklists
435 extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
437 /* Free all resources held by a thread. */
438 extern void release_thread(struct task_struct *);
440 /* Prepare to copy thread state - unlazy all lazy status */
441 extern void prepare_to_copy(struct task_struct *tsk);
443 unsigned long get_wchan(struct task_struct *p);
446 * Generic CPUID function
447 * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
448 * resulting in stale register contents being returned.
450 static inline void cpuid(unsigned int op,
451 unsigned int *eax, unsigned int *ebx,
452 unsigned int *ecx, unsigned int *edx)
456 __cpuid(eax, ebx, ecx, edx);
459 /* Some CPUID calls want 'count' to be placed in ecx */
460 static inline void cpuid_count(unsigned int op, int count,
461 unsigned int *eax, unsigned int *ebx,
462 unsigned int *ecx, unsigned int *edx)
466 __cpuid(eax, ebx, ecx, edx);
470 * CPUID functions returning a single datum
472 static inline unsigned int cpuid_eax(unsigned int op)
474 unsigned int eax, ebx, ecx, edx;
476 cpuid(op, &eax, &ebx, &ecx, &edx);
479 static inline unsigned int cpuid_ebx(unsigned int op)
481 unsigned int eax, ebx, ecx, edx;
483 cpuid(op, &eax, &ebx, &ecx, &edx);
486 static inline unsigned int cpuid_ecx(unsigned int op)
488 unsigned int eax, ebx, ecx, edx;
490 cpuid(op, &eax, &ebx, &ecx, &edx);
493 static inline unsigned int cpuid_edx(unsigned int op)
495 unsigned int eax, ebx, ecx, edx;
497 cpuid(op, &eax, &ebx, &ecx, &edx);
501 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
502 static inline void rep_nop(void)
504 __asm__ __volatile__("rep;nop": : :"memory");
507 /* Stop speculative execution */
508 static inline void sync_core(void)
511 asm volatile("cpuid" : "=a" (tmp) : "0" (1)
512 : "ebx", "ecx", "edx", "memory");
515 #define cpu_relax() rep_nop()
517 static inline void __monitor(const void *eax, unsigned long ecx,
520 /* "monitor %eax,%ecx,%edx;" */
522 ".byte 0x0f,0x01,0xc8;"
523 : :"a" (eax), "c" (ecx), "d"(edx));
526 static inline void __mwait(unsigned long eax, unsigned long ecx)
528 /* "mwait %eax,%ecx;" */
530 ".byte 0x0f,0x01,0xc9;"
531 : :"a" (eax), "c" (ecx));
534 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
536 /* "mwait %eax,%ecx;" */
538 "sti; .byte 0x0f,0x01,0xc9;"
539 : :"a" (eax), "c" (ecx));
542 extern void mwait_idle_with_hints(unsigned long eax, unsigned long ecx);
544 extern int force_mwait;
546 extern void select_idle_routine(const struct cpuinfo_x86 *c);
548 extern unsigned long boot_option_idle_override;
550 /* Boot loader type from the setup header */
551 extern int bootloader_type;
552 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
554 #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
555 #define ARCH_HAS_PREFETCHW
556 #define ARCH_HAS_SPINLOCK_PREFETCH
558 #define spin_lock_prefetch(x) prefetchw(x)
559 /* This decides where the kernel will search for a free chunk of vm
560 * space during mmap's.
562 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
564 #define KSTK_EIP(task) (task_pt_regs(task)->ip)