processor_32.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /*
  2. * Copyright (C) 1994 Linus Torvalds
  3. */
  4. #ifndef __ASM_I386_PROCESSOR_H
  5. #define __ASM_I386_PROCESSOR_H
  6. #include <asm/vm86.h>
  7. #include <asm/math_emu.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 <asm/msr.h>
  14. #include <asm/system.h>
  15. #include <linux/cache.h>
  16. #include <linux/threads.h>
  17. #include <asm/percpu.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/init.h>
  20. #include <asm/desc_defs.h>
  21. /*
  22. * CPU type and hardware bug flags. Kept separately for each CPU.
  23. * Members of this structure are referenced in head.S, so think twice
  24. * before touching them. [mj]
  25. */
  26. struct cpuinfo_x86 {
  27. __u8 x86; /* CPU family */
  28. __u8 x86_vendor; /* CPU vendor */
  29. __u8 x86_model;
  30. __u8 x86_mask;
  31. char wp_works_ok; /* It doesn't on 386's */
  32. char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
  33. char hard_math;
  34. char rfu;
  35. int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
  36. unsigned long x86_capability[NCAPINTS];
  37. char x86_vendor_id[16];
  38. char x86_model_id[64];
  39. int x86_cache_size; /* in KB - valid for CPUS which support this
  40. call */
  41. int x86_cache_alignment; /* In bytes */
  42. char fdiv_bug;
  43. char f00f_bug;
  44. char coma_bug;
  45. char pad0;
  46. int x86_power;
  47. unsigned long loops_per_jiffy;
  48. #ifdef CONFIG_SMP
  49. cpumask_t llc_shared_map; /* cpus sharing the last level cache */
  50. #endif
  51. unsigned char x86_max_cores; /* cpuid returned max cores value */
  52. unsigned char apicid;
  53. unsigned short x86_clflush_size;
  54. #ifdef CONFIG_SMP
  55. unsigned char booted_cores; /* number of cores as seen by OS */
  56. __u8 phys_proc_id; /* Physical processor id. */
  57. __u8 cpu_core_id; /* Core id */
  58. __u8 cpu_index; /* index into per_cpu list */
  59. #endif
  60. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  61. #define X86_VENDOR_INTEL 0
  62. #define X86_VENDOR_CYRIX 1
  63. #define X86_VENDOR_AMD 2
  64. #define X86_VENDOR_UMC 3
  65. #define X86_VENDOR_NEXGEN 4
  66. #define X86_VENDOR_CENTAUR 5
  67. #define X86_VENDOR_TRANSMETA 7
  68. #define X86_VENDOR_NSC 8
  69. #define X86_VENDOR_NUM 9
  70. #define X86_VENDOR_UNKNOWN 0xff
  71. /*
  72. * capabilities of CPUs
  73. */
  74. extern struct cpuinfo_x86 boot_cpu_data;
  75. extern struct cpuinfo_x86 new_cpu_data;
  76. extern struct tss_struct doublefault_tss;
  77. #ifdef CONFIG_SMP
  78. DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
  79. #define cpu_data(cpu) per_cpu(cpu_info, cpu)
  80. #define current_cpu_data cpu_data(smp_processor_id())
  81. #else
  82. #define cpu_data(cpu) boot_cpu_data
  83. #define current_cpu_data boot_cpu_data
  84. #endif
  85. /*
  86. * the following now lives in the per cpu area:
  87. * extern int cpu_llc_id[NR_CPUS];
  88. */
  89. DECLARE_PER_CPU(u8, cpu_llc_id);
  90. extern char ignore_fpu_irq;
  91. void __init cpu_detect(struct cpuinfo_x86 *c);
  92. extern void identify_boot_cpu(void);
  93. extern void identify_secondary_cpu(struct cpuinfo_x86 *);
  94. #ifdef CONFIG_X86_HT
  95. extern void detect_ht(struct cpuinfo_x86 *c);
  96. #else
  97. static inline void detect_ht(struct cpuinfo_x86 *c) {}
  98. #endif
  99. /* from system description table in BIOS. Mostly for MCA use, but
  100. others may find it useful. */
  101. extern unsigned int machine_id;
  102. extern unsigned int machine_submodel_id;
  103. extern unsigned int BIOS_revision;
  104. extern unsigned int mca_pentium_flag;
  105. /*
  106. * User space process size: 3GB (default).
  107. */
  108. #define TASK_SIZE (PAGE_OFFSET)
  109. struct i387_fsave_struct {
  110. long cwd;
  111. long swd;
  112. long twd;
  113. long fip;
  114. long fcs;
  115. long foo;
  116. long fos;
  117. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  118. long status; /* software status information */
  119. };
  120. struct i387_fxsave_struct {
  121. unsigned short cwd;
  122. unsigned short swd;
  123. unsigned short twd;
  124. unsigned short fop;
  125. long fip;
  126. long fcs;
  127. long foo;
  128. long fos;
  129. long mxcsr;
  130. long mxcsr_mask;
  131. long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
  132. long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
  133. long padding[56];
  134. } __attribute__ ((aligned (16)));
  135. struct i387_soft_struct {
  136. long cwd;
  137. long swd;
  138. long twd;
  139. long fip;
  140. long fcs;
  141. long foo;
  142. long fos;
  143. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  144. unsigned char ftop, changed, lookahead, no_update, rm, alimit;
  145. struct info *info;
  146. unsigned long entry_eip;
  147. };
  148. union i387_union {
  149. struct i387_fsave_struct fsave;
  150. struct i387_fxsave_struct fxsave;
  151. struct i387_soft_struct soft;
  152. };
  153. typedef struct {
  154. unsigned long seg;
  155. } mm_segment_t;
  156. #define ARCH_MIN_TASKALIGN 16
  157. #define INIT_THREAD { \
  158. .sp0 = sizeof(init_stack) + (long)&init_stack, \
  159. .vm86_info = NULL, \
  160. .sysenter_cs = __KERNEL_CS, \
  161. .io_bitmap_ptr = NULL, \
  162. .fs = __KERNEL_PERCPU, \
  163. }
  164. /*
  165. * Note that the .io_bitmap member must be extra-big. This is because
  166. * the CPU will access an additional byte beyond the end of the IO
  167. * permission bitmap. The extra byte must be all 1 bits, and must
  168. * be within the limit.
  169. */
  170. #define INIT_TSS { \
  171. .x86_tss = { \
  172. .sp0 = sizeof(init_stack) + (long)&init_stack, \
  173. .ss0 = __KERNEL_DS, \
  174. .ss1 = __KERNEL_CS, \
  175. .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
  176. }, \
  177. .io_bitmap = { [ 0 ... IO_BITMAP_LONGS] = ~0 }, \
  178. }
  179. #define start_thread(regs, new_eip, new_esp) do { \
  180. __asm__("movl %0,%%gs": :"r" (0)); \
  181. regs->fs = 0; \
  182. set_fs(USER_DS); \
  183. regs->ds = __USER_DS; \
  184. regs->es = __USER_DS; \
  185. regs->ss = __USER_DS; \
  186. regs->cs = __USER_CS; \
  187. regs->ip = new_eip; \
  188. regs->sp = new_esp; \
  189. } while (0)
  190. extern unsigned long thread_saved_pc(struct task_struct *tsk);
  191. #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
  192. #define KSTK_TOP(info) \
  193. ({ \
  194. unsigned long *__ptr = (unsigned long *)(info); \
  195. (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
  196. })
  197. /*
  198. * The below -8 is to reserve 8 bytes on top of the ring0 stack.
  199. * This is necessary to guarantee that the entire "struct pt_regs"
  200. * is accessable even if the CPU haven't stored the SS/ESP registers
  201. * on the stack (interrupt gate does not save these registers
  202. * when switching to the same priv ring).
  203. * Therefore beware: accessing the ss/esp fields of the
  204. * "struct pt_regs" is possible, but they may contain the
  205. * completely wrong values.
  206. */
  207. #define task_pt_regs(task) \
  208. ({ \
  209. struct pt_regs *__regs__; \
  210. __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
  211. __regs__ - 1; \
  212. })
  213. #define KSTK_ESP(task) (task_pt_regs(task)->sp)
  214. /* generic versions from gas */
  215. #define GENERIC_NOP1 ".byte 0x90\n"
  216. #define GENERIC_NOP2 ".byte 0x89,0xf6\n"
  217. #define GENERIC_NOP3 ".byte 0x8d,0x76,0x00\n"
  218. #define GENERIC_NOP4 ".byte 0x8d,0x74,0x26,0x00\n"
  219. #define GENERIC_NOP5 GENERIC_NOP1 GENERIC_NOP4
  220. #define GENERIC_NOP6 ".byte 0x8d,0xb6,0x00,0x00,0x00,0x00\n"
  221. #define GENERIC_NOP7 ".byte 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00\n"
  222. #define GENERIC_NOP8 GENERIC_NOP1 GENERIC_NOP7
  223. /* Opteron nops */
  224. #define K8_NOP1 GENERIC_NOP1
  225. #define K8_NOP2 ".byte 0x66,0x90\n"
  226. #define K8_NOP3 ".byte 0x66,0x66,0x90\n"
  227. #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n"
  228. #define K8_NOP5 K8_NOP3 K8_NOP2
  229. #define K8_NOP6 K8_NOP3 K8_NOP3
  230. #define K8_NOP7 K8_NOP4 K8_NOP3
  231. #define K8_NOP8 K8_NOP4 K8_NOP4
  232. /* K7 nops */
  233. /* uses eax dependencies (arbitary choice) */
  234. #define K7_NOP1 GENERIC_NOP1
  235. #define K7_NOP2 ".byte 0x8b,0xc0\n"
  236. #define K7_NOP3 ".byte 0x8d,0x04,0x20\n"
  237. #define K7_NOP4 ".byte 0x8d,0x44,0x20,0x00\n"
  238. #define K7_NOP5 K7_NOP4 ASM_NOP1
  239. #define K7_NOP6 ".byte 0x8d,0x80,0,0,0,0\n"
  240. #define K7_NOP7 ".byte 0x8D,0x04,0x05,0,0,0,0\n"
  241. #define K7_NOP8 K7_NOP7 ASM_NOP1
  242. /* P6 nops */
  243. /* uses eax dependencies (Intel-recommended choice) */
  244. #define P6_NOP1 GENERIC_NOP1
  245. #define P6_NOP2 ".byte 0x66,0x90\n"
  246. #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
  247. #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
  248. #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
  249. #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
  250. #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
  251. #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
  252. #ifdef CONFIG_MK8
  253. #define ASM_NOP1 K8_NOP1
  254. #define ASM_NOP2 K8_NOP2
  255. #define ASM_NOP3 K8_NOP3
  256. #define ASM_NOP4 K8_NOP4
  257. #define ASM_NOP5 K8_NOP5
  258. #define ASM_NOP6 K8_NOP6
  259. #define ASM_NOP7 K8_NOP7
  260. #define ASM_NOP8 K8_NOP8
  261. #elif defined(CONFIG_MK7)
  262. #define ASM_NOP1 K7_NOP1
  263. #define ASM_NOP2 K7_NOP2
  264. #define ASM_NOP3 K7_NOP3
  265. #define ASM_NOP4 K7_NOP4
  266. #define ASM_NOP5 K7_NOP5
  267. #define ASM_NOP6 K7_NOP6
  268. #define ASM_NOP7 K7_NOP7
  269. #define ASM_NOP8 K7_NOP8
  270. #elif defined(CONFIG_M686) || defined(CONFIG_MPENTIUMII) || \
  271. defined(CONFIG_MPENTIUMIII) || defined(CONFIG_MPENTIUMM) || \
  272. defined(CONFIG_MCORE2) || defined(CONFIG_PENTIUM4)
  273. #define ASM_NOP1 P6_NOP1
  274. #define ASM_NOP2 P6_NOP2
  275. #define ASM_NOP3 P6_NOP3
  276. #define ASM_NOP4 P6_NOP4
  277. #define ASM_NOP5 P6_NOP5
  278. #define ASM_NOP6 P6_NOP6
  279. #define ASM_NOP7 P6_NOP7
  280. #define ASM_NOP8 P6_NOP8
  281. #else
  282. #define ASM_NOP1 GENERIC_NOP1
  283. #define ASM_NOP2 GENERIC_NOP2
  284. #define ASM_NOP3 GENERIC_NOP3
  285. #define ASM_NOP4 GENERIC_NOP4
  286. #define ASM_NOP5 GENERIC_NOP5
  287. #define ASM_NOP6 GENERIC_NOP6
  288. #define ASM_NOP7 GENERIC_NOP7
  289. #define ASM_NOP8 GENERIC_NOP8
  290. #endif
  291. #define ASM_NOP_MAX 8
  292. /* Prefetch instructions for Pentium III and AMD Athlon */
  293. /* It's not worth to care about 3dnow! prefetches for the K6
  294. because they are microcoded there and very slow.
  295. However we don't do prefetches for pre XP Athlons currently
  296. That should be fixed. */
  297. static inline void prefetch(const void *x)
  298. {
  299. alternative_input(ASM_NOP4,
  300. "prefetchnta (%1)",
  301. X86_FEATURE_XMM,
  302. "r" (x));
  303. }
  304. #define ARCH_HAS_PREFETCH
  305. /* 3dnow! prefetch to get an exclusive cache line. Useful for
  306. spinlocks to avoid one state transition in the cache coherency protocol. */
  307. static inline void prefetchw(const void *x)
  308. {
  309. alternative_input(ASM_NOP4,
  310. "prefetchw (%1)",
  311. X86_FEATURE_3DNOW,
  312. "r" (x));
  313. }
  314. extern void enable_sep_cpu(void);
  315. extern int sysenter_setup(void);
  316. /* Defined in head.S */
  317. extern struct desc_ptr early_gdt_descr;
  318. extern void cpu_set_gdt(int);
  319. extern void switch_to_new_gdt(void);
  320. extern void cpu_init(void);
  321. extern void init_gdt(int cpu);
  322. #endif /* __ASM_I386_PROCESSOR_H */