processor.h 11 KB

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