processor_32.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. * include/asm-i386/processor.h
  3. *
  4. * Copyright (C) 1994 Linus Torvalds
  5. */
  6. #ifndef __ASM_I386_PROCESSOR_H
  7. #define __ASM_I386_PROCESSOR_H
  8. #include <asm/vm86.h>
  9. #include <asm/math_emu.h>
  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>
  15. #include <asm/msr.h>
  16. #include <asm/system.h>
  17. #include <linux/cache.h>
  18. #include <linux/threads.h>
  19. #include <asm/percpu.h>
  20. #include <linux/cpumask.h>
  21. #include <linux/init.h>
  22. #include <asm/processor-flags.h>
  23. /* flag for disabling the tsc */
  24. extern int tsc_disable;
  25. struct desc_struct {
  26. unsigned long a,b;
  27. };
  28. #define desc_empty(desc) \
  29. (!((desc)->a | (desc)->b))
  30. #define desc_equal(desc1, desc2) \
  31. (((desc1)->a == (desc2)->a) && ((desc1)->b == (desc2)->b))
  32. /*
  33. * Default implementation of macro that returns current
  34. * instruction pointer ("program counter").
  35. */
  36. #define current_text_addr() ({ void *pc; __asm__("movl $1f,%0\n1:":"=g" (pc)); pc; })
  37. /*
  38. * CPU type and hardware bug flags. Kept separately for each CPU.
  39. * Members of this structure are referenced in head.S, so think twice
  40. * before touching them. [mj]
  41. */
  42. struct cpuinfo_x86 {
  43. __u8 x86; /* CPU family */
  44. __u8 x86_vendor; /* CPU vendor */
  45. __u8 x86_model;
  46. __u8 x86_mask;
  47. char wp_works_ok; /* It doesn't on 386's */
  48. char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
  49. char hard_math;
  50. char rfu;
  51. int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
  52. unsigned long x86_capability[NCAPINTS];
  53. char x86_vendor_id[16];
  54. char x86_model_id[64];
  55. int x86_cache_size; /* in KB - valid for CPUS which support this
  56. call */
  57. int x86_cache_alignment; /* In bytes */
  58. char fdiv_bug;
  59. char f00f_bug;
  60. char coma_bug;
  61. char pad0;
  62. int x86_power;
  63. unsigned long loops_per_jiffy;
  64. #ifdef CONFIG_SMP
  65. cpumask_t llc_shared_map; /* cpus sharing the last level cache */
  66. #endif
  67. unsigned char x86_max_cores; /* cpuid returned max cores value */
  68. unsigned char apicid;
  69. unsigned short x86_clflush_size;
  70. #ifdef CONFIG_SMP
  71. unsigned char booted_cores; /* number of cores as seen by OS */
  72. __u8 phys_proc_id; /* Physical processor id. */
  73. __u8 cpu_core_id; /* Core id */
  74. #endif
  75. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  76. #define X86_VENDOR_INTEL 0
  77. #define X86_VENDOR_CYRIX 1
  78. #define X86_VENDOR_AMD 2
  79. #define X86_VENDOR_UMC 3
  80. #define X86_VENDOR_NEXGEN 4
  81. #define X86_VENDOR_CENTAUR 5
  82. #define X86_VENDOR_TRANSMETA 7
  83. #define X86_VENDOR_NSC 8
  84. #define X86_VENDOR_NUM 9
  85. #define X86_VENDOR_UNKNOWN 0xff
  86. /*
  87. * capabilities of CPUs
  88. */
  89. extern struct cpuinfo_x86 boot_cpu_data;
  90. extern struct cpuinfo_x86 new_cpu_data;
  91. extern struct tss_struct doublefault_tss;
  92. DECLARE_PER_CPU(struct tss_struct, init_tss);
  93. #ifdef CONFIG_SMP
  94. extern struct cpuinfo_x86 cpu_data[];
  95. #define current_cpu_data cpu_data[smp_processor_id()]
  96. #else
  97. #define cpu_data (&boot_cpu_data)
  98. #define current_cpu_data boot_cpu_data
  99. #endif
  100. extern int cpu_llc_id[NR_CPUS];
  101. extern char ignore_fpu_irq;
  102. void __init cpu_detect(struct cpuinfo_x86 *c);
  103. extern void identify_boot_cpu(void);
  104. extern void identify_secondary_cpu(struct cpuinfo_x86 *);
  105. extern void print_cpu_info(struct cpuinfo_x86 *);
  106. extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
  107. extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
  108. extern unsigned short num_cache_leaves;
  109. #ifdef CONFIG_X86_HT
  110. extern void detect_ht(struct cpuinfo_x86 *c);
  111. #else
  112. static inline void detect_ht(struct cpuinfo_x86 *c) {}
  113. #endif
  114. static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
  115. unsigned int *ecx, unsigned int *edx)
  116. {
  117. /* ecx is often an input as well as an output. */
  118. __asm__("cpuid"
  119. : "=a" (*eax),
  120. "=b" (*ebx),
  121. "=c" (*ecx),
  122. "=d" (*edx)
  123. : "0" (*eax), "2" (*ecx));
  124. }
  125. #define load_cr3(pgdir) write_cr3(__pa(pgdir))
  126. /*
  127. * Save the cr4 feature set we're using (ie
  128. * Pentium 4MB enable and PPro Global page
  129. * enable), so that any CPU's that boot up
  130. * after us can get the correct flags.
  131. */
  132. extern unsigned long mmu_cr4_features;
  133. static inline void set_in_cr4 (unsigned long mask)
  134. {
  135. unsigned cr4;
  136. mmu_cr4_features |= mask;
  137. cr4 = read_cr4();
  138. cr4 |= mask;
  139. write_cr4(cr4);
  140. }
  141. static inline void clear_in_cr4 (unsigned long mask)
  142. {
  143. unsigned cr4;
  144. mmu_cr4_features &= ~mask;
  145. cr4 = read_cr4();
  146. cr4 &= ~mask;
  147. write_cr4(cr4);
  148. }
  149. /* Stop speculative execution */
  150. static inline void sync_core(void)
  151. {
  152. int tmp;
  153. asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
  154. }
  155. static inline void __monitor(const void *eax, unsigned long ecx,
  156. unsigned long edx)
  157. {
  158. /* "monitor %eax,%ecx,%edx;" */
  159. asm volatile(
  160. ".byte 0x0f,0x01,0xc8;"
  161. : :"a" (eax), "c" (ecx), "d"(edx));
  162. }
  163. static inline void __mwait(unsigned long eax, unsigned long ecx)
  164. {
  165. /* "mwait %eax,%ecx;" */
  166. asm volatile(
  167. ".byte 0x0f,0x01,0xc9;"
  168. : :"a" (eax), "c" (ecx));
  169. }
  170. extern void mwait_idle_with_hints(unsigned long eax, unsigned long ecx);
  171. /* from system description table in BIOS. Mostly for MCA use, but
  172. others may find it useful. */
  173. extern unsigned int machine_id;
  174. extern unsigned int machine_submodel_id;
  175. extern unsigned int BIOS_revision;
  176. extern unsigned int mca_pentium_flag;
  177. /* Boot loader type from the setup header */
  178. extern int bootloader_type;
  179. /*
  180. * User space process size: 3GB (default).
  181. */
  182. #define TASK_SIZE (PAGE_OFFSET)
  183. /* This decides where the kernel will search for a free chunk of vm
  184. * space during mmap's.
  185. */
  186. #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
  187. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  188. extern void hard_disable_TSC(void);
  189. extern void disable_TSC(void);
  190. extern void hard_enable_TSC(void);
  191. /*
  192. * Size of io_bitmap.
  193. */
  194. #define IO_BITMAP_BITS 65536
  195. #define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
  196. #define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
  197. #define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
  198. #define INVALID_IO_BITMAP_OFFSET 0x8000
  199. #define INVALID_IO_BITMAP_OFFSET_LAZY 0x9000
  200. struct i387_fsave_struct {
  201. long cwd;
  202. long swd;
  203. long twd;
  204. long fip;
  205. long fcs;
  206. long foo;
  207. long fos;
  208. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  209. long status; /* software status information */
  210. };
  211. struct i387_fxsave_struct {
  212. unsigned short cwd;
  213. unsigned short swd;
  214. unsigned short twd;
  215. unsigned short fop;
  216. long fip;
  217. long fcs;
  218. long foo;
  219. long fos;
  220. long mxcsr;
  221. long mxcsr_mask;
  222. long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
  223. long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
  224. long padding[56];
  225. } __attribute__ ((aligned (16)));
  226. struct i387_soft_struct {
  227. long cwd;
  228. long swd;
  229. long twd;
  230. long fip;
  231. long fcs;
  232. long foo;
  233. long fos;
  234. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  235. unsigned char ftop, changed, lookahead, no_update, rm, alimit;
  236. struct info *info;
  237. unsigned long entry_eip;
  238. };
  239. union i387_union {
  240. struct i387_fsave_struct fsave;
  241. struct i387_fxsave_struct fxsave;
  242. struct i387_soft_struct soft;
  243. };
  244. typedef struct {
  245. unsigned long seg;
  246. } mm_segment_t;
  247. struct thread_struct;
  248. /* This is the TSS defined by the hardware. */
  249. struct i386_hw_tss {
  250. unsigned short back_link,__blh;
  251. unsigned long esp0;
  252. unsigned short ss0,__ss0h;
  253. unsigned long esp1;
  254. unsigned short ss1,__ss1h; /* ss1 is used to cache MSR_IA32_SYSENTER_CS */
  255. unsigned long esp2;
  256. unsigned short ss2,__ss2h;
  257. unsigned long __cr3;
  258. unsigned long eip;
  259. unsigned long eflags;
  260. unsigned long eax,ecx,edx,ebx;
  261. unsigned long esp;
  262. unsigned long ebp;
  263. unsigned long esi;
  264. unsigned long edi;
  265. unsigned short es, __esh;
  266. unsigned short cs, __csh;
  267. unsigned short ss, __ssh;
  268. unsigned short ds, __dsh;
  269. unsigned short fs, __fsh;
  270. unsigned short gs, __gsh;
  271. unsigned short ldt, __ldth;
  272. unsigned short trace, io_bitmap_base;
  273. } __attribute__((packed));
  274. struct tss_struct {
  275. struct i386_hw_tss x86_tss;
  276. /*
  277. * The extra 1 is there because the CPU will access an
  278. * additional byte beyond the end of the IO permission
  279. * bitmap. The extra byte must be all 1 bits, and must
  280. * be within the limit.
  281. */
  282. unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
  283. /*
  284. * Cache the current maximum and the last task that used the bitmap:
  285. */
  286. unsigned long io_bitmap_max;
  287. struct thread_struct *io_bitmap_owner;
  288. /*
  289. * pads the TSS to be cacheline-aligned (size is 0x100)
  290. */
  291. unsigned long __cacheline_filler[35];
  292. /*
  293. * .. and then another 0x100 bytes for emergency kernel stack
  294. */
  295. unsigned long stack[64];
  296. } __attribute__((packed));
  297. #define ARCH_MIN_TASKALIGN 16
  298. struct thread_struct {
  299. /* cached TLS descriptors. */
  300. struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
  301. unsigned long esp0;
  302. unsigned long sysenter_cs;
  303. unsigned long eip;
  304. unsigned long esp;
  305. unsigned long fs;
  306. unsigned long gs;
  307. /* Hardware debugging registers */
  308. unsigned long debugreg[8]; /* %%db0-7 debug registers */
  309. /* fault info */
  310. unsigned long cr2, trap_no, error_code;
  311. /* floating point info */
  312. union i387_union i387;
  313. /* virtual 86 mode info */
  314. struct vm86_struct __user * vm86_info;
  315. unsigned long screen_bitmap;
  316. unsigned long v86flags, v86mask, saved_esp0;
  317. unsigned int saved_fs, saved_gs;
  318. /* IO permissions */
  319. unsigned long *io_bitmap_ptr;
  320. unsigned long iopl;
  321. /* max allowed port in the bitmap, in bytes: */
  322. unsigned long io_bitmap_max;
  323. };
  324. #define INIT_THREAD { \
  325. .esp0 = sizeof(init_stack) + (long)&init_stack, \
  326. .vm86_info = NULL, \
  327. .sysenter_cs = __KERNEL_CS, \
  328. .io_bitmap_ptr = NULL, \
  329. .fs = __KERNEL_PERCPU, \
  330. }
  331. /*
  332. * Note that the .io_bitmap member must be extra-big. This is because
  333. * the CPU will access an additional byte beyond the end of the IO
  334. * permission bitmap. The extra byte must be all 1 bits, and must
  335. * be within the limit.
  336. */
  337. #define INIT_TSS { \
  338. .x86_tss = { \
  339. .esp0 = sizeof(init_stack) + (long)&init_stack, \
  340. .ss0 = __KERNEL_DS, \
  341. .ss1 = __KERNEL_CS, \
  342. .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
  343. }, \
  344. .io_bitmap = { [ 0 ... IO_BITMAP_LONGS] = ~0 }, \
  345. }
  346. #define start_thread(regs, new_eip, new_esp) do { \
  347. __asm__("movl %0,%%gs": :"r" (0)); \
  348. regs->xfs = 0; \
  349. set_fs(USER_DS); \
  350. regs->xds = __USER_DS; \
  351. regs->xes = __USER_DS; \
  352. regs->xss = __USER_DS; \
  353. regs->xcs = __USER_CS; \
  354. regs->eip = new_eip; \
  355. regs->esp = new_esp; \
  356. } while (0)
  357. /* Forward declaration, a strange C thing */
  358. struct task_struct;
  359. struct mm_struct;
  360. /* Free all resources held by a thread. */
  361. extern void release_thread(struct task_struct *);
  362. /* Prepare to copy thread state - unlazy all lazy status */
  363. extern void prepare_to_copy(struct task_struct *tsk);
  364. /*
  365. * create a kernel thread without removing it from tasklists
  366. */
  367. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  368. extern unsigned long thread_saved_pc(struct task_struct *tsk);
  369. void show_trace(struct task_struct *task, struct pt_regs *regs, unsigned long *stack);
  370. unsigned long get_wchan(struct task_struct *p);
  371. #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
  372. #define KSTK_TOP(info) \
  373. ({ \
  374. unsigned long *__ptr = (unsigned long *)(info); \
  375. (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
  376. })
  377. /*
  378. * The below -8 is to reserve 8 bytes on top of the ring0 stack.
  379. * This is necessary to guarantee that the entire "struct pt_regs"
  380. * is accessable even if the CPU haven't stored the SS/ESP registers
  381. * on the stack (interrupt gate does not save these registers
  382. * when switching to the same priv ring).
  383. * Therefore beware: accessing the xss/esp fields of the
  384. * "struct pt_regs" is possible, but they may contain the
  385. * completely wrong values.
  386. */
  387. #define task_pt_regs(task) \
  388. ({ \
  389. struct pt_regs *__regs__; \
  390. __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
  391. __regs__ - 1; \
  392. })
  393. #define KSTK_EIP(task) (task_pt_regs(task)->eip)
  394. #define KSTK_ESP(task) (task_pt_regs(task)->esp)
  395. struct microcode_header {
  396. unsigned int hdrver;
  397. unsigned int rev;
  398. unsigned int date;
  399. unsigned int sig;
  400. unsigned int cksum;
  401. unsigned int ldrver;
  402. unsigned int pf;
  403. unsigned int datasize;
  404. unsigned int totalsize;
  405. unsigned int reserved[3];
  406. };
  407. struct microcode {
  408. struct microcode_header hdr;
  409. unsigned int bits[0];
  410. };
  411. typedef struct microcode microcode_t;
  412. typedef struct microcode_header microcode_header_t;
  413. /* microcode format is extended from prescott processors */
  414. struct extended_signature {
  415. unsigned int sig;
  416. unsigned int pf;
  417. unsigned int cksum;
  418. };
  419. struct extended_sigtable {
  420. unsigned int count;
  421. unsigned int cksum;
  422. unsigned int reserved[3];
  423. struct extended_signature sigs[0];
  424. };
  425. /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
  426. static inline void rep_nop(void)
  427. {
  428. __asm__ __volatile__("rep;nop": : :"memory");
  429. }
  430. #define cpu_relax() rep_nop()
  431. static inline void native_load_esp0(struct tss_struct *tss, struct thread_struct *thread)
  432. {
  433. tss->x86_tss.esp0 = thread->esp0;
  434. /* This can only happen when SEP is enabled, no need to test "SEP"arately */
  435. if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) {
  436. tss->x86_tss.ss1 = thread->sysenter_cs;
  437. wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
  438. }
  439. }
  440. static inline unsigned long native_get_debugreg(int regno)
  441. {
  442. unsigned long val = 0; /* Damn you, gcc! */
  443. switch (regno) {
  444. case 0:
  445. asm("movl %%db0, %0" :"=r" (val)); break;
  446. case 1:
  447. asm("movl %%db1, %0" :"=r" (val)); break;
  448. case 2:
  449. asm("movl %%db2, %0" :"=r" (val)); break;
  450. case 3:
  451. asm("movl %%db3, %0" :"=r" (val)); break;
  452. case 6:
  453. asm("movl %%db6, %0" :"=r" (val)); break;
  454. case 7:
  455. asm("movl %%db7, %0" :"=r" (val)); break;
  456. default:
  457. BUG();
  458. }
  459. return val;
  460. }
  461. static inline void native_set_debugreg(int regno, unsigned long value)
  462. {
  463. switch (regno) {
  464. case 0:
  465. asm("movl %0,%%db0" : /* no output */ :"r" (value));
  466. break;
  467. case 1:
  468. asm("movl %0,%%db1" : /* no output */ :"r" (value));
  469. break;
  470. case 2:
  471. asm("movl %0,%%db2" : /* no output */ :"r" (value));
  472. break;
  473. case 3:
  474. asm("movl %0,%%db3" : /* no output */ :"r" (value));
  475. break;
  476. case 6:
  477. asm("movl %0,%%db6" : /* no output */ :"r" (value));
  478. break;
  479. case 7:
  480. asm("movl %0,%%db7" : /* no output */ :"r" (value));
  481. break;
  482. default:
  483. BUG();
  484. }
  485. }
  486. /*
  487. * Set IOPL bits in EFLAGS from given mask
  488. */
  489. static inline void native_set_iopl_mask(unsigned mask)
  490. {
  491. unsigned int reg;
  492. __asm__ __volatile__ ("pushfl;"
  493. "popl %0;"
  494. "andl %1, %0;"
  495. "orl %2, %0;"
  496. "pushl %0;"
  497. "popfl"
  498. : "=&r" (reg)
  499. : "i" (~X86_EFLAGS_IOPL), "r" (mask));
  500. }
  501. #ifdef CONFIG_PARAVIRT
  502. #include <asm/paravirt.h>
  503. #else
  504. #define paravirt_enabled() 0
  505. #define __cpuid native_cpuid
  506. static inline void load_esp0(struct tss_struct *tss, struct thread_struct *thread)
  507. {
  508. native_load_esp0(tss, thread);
  509. }
  510. /*
  511. * These special macros can be used to get or set a debugging register
  512. */
  513. #define get_debugreg(var, register) \
  514. (var) = native_get_debugreg(register)
  515. #define set_debugreg(value, register) \
  516. native_set_debugreg(register, value)
  517. #define set_iopl_mask native_set_iopl_mask
  518. #endif /* CONFIG_PARAVIRT */
  519. /*
  520. * Generic CPUID function
  521. * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
  522. * resulting in stale register contents being returned.
  523. */
  524. static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
  525. {
  526. *eax = op;
  527. *ecx = 0;
  528. __cpuid(eax, ebx, ecx, edx);
  529. }
  530. /* Some CPUID calls want 'count' to be placed in ecx */
  531. static inline void cpuid_count(int op, int count, int *eax, int *ebx, int *ecx,
  532. int *edx)
  533. {
  534. *eax = op;
  535. *ecx = count;
  536. __cpuid(eax, ebx, ecx, edx);
  537. }
  538. /*
  539. * CPUID functions returning a single datum
  540. */
  541. static inline unsigned int cpuid_eax(unsigned int op)
  542. {
  543. unsigned int eax, ebx, ecx, edx;
  544. cpuid(op, &eax, &ebx, &ecx, &edx);
  545. return eax;
  546. }
  547. static inline unsigned int cpuid_ebx(unsigned int op)
  548. {
  549. unsigned int eax, ebx, ecx, edx;
  550. cpuid(op, &eax, &ebx, &ecx, &edx);
  551. return ebx;
  552. }
  553. static inline unsigned int cpuid_ecx(unsigned int op)
  554. {
  555. unsigned int eax, ebx, ecx, edx;
  556. cpuid(op, &eax, &ebx, &ecx, &edx);
  557. return ecx;
  558. }
  559. static inline unsigned int cpuid_edx(unsigned int op)
  560. {
  561. unsigned int eax, ebx, ecx, edx;
  562. cpuid(op, &eax, &ebx, &ecx, &edx);
  563. return edx;
  564. }
  565. /* generic versions from gas */
  566. #define GENERIC_NOP1 ".byte 0x90\n"
  567. #define GENERIC_NOP2 ".byte 0x89,0xf6\n"
  568. #define GENERIC_NOP3 ".byte 0x8d,0x76,0x00\n"
  569. #define GENERIC_NOP4 ".byte 0x8d,0x74,0x26,0x00\n"
  570. #define GENERIC_NOP5 GENERIC_NOP1 GENERIC_NOP4
  571. #define GENERIC_NOP6 ".byte 0x8d,0xb6,0x00,0x00,0x00,0x00\n"
  572. #define GENERIC_NOP7 ".byte 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00\n"
  573. #define GENERIC_NOP8 GENERIC_NOP1 GENERIC_NOP7
  574. /* Opteron nops */
  575. #define K8_NOP1 GENERIC_NOP1
  576. #define K8_NOP2 ".byte 0x66,0x90\n"
  577. #define K8_NOP3 ".byte 0x66,0x66,0x90\n"
  578. #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n"
  579. #define K8_NOP5 K8_NOP3 K8_NOP2
  580. #define K8_NOP6 K8_NOP3 K8_NOP3
  581. #define K8_NOP7 K8_NOP4 K8_NOP3
  582. #define K8_NOP8 K8_NOP4 K8_NOP4
  583. /* K7 nops */
  584. /* uses eax dependencies (arbitary choice) */
  585. #define K7_NOP1 GENERIC_NOP1
  586. #define K7_NOP2 ".byte 0x8b,0xc0\n"
  587. #define K7_NOP3 ".byte 0x8d,0x04,0x20\n"
  588. #define K7_NOP4 ".byte 0x8d,0x44,0x20,0x00\n"
  589. #define K7_NOP5 K7_NOP4 ASM_NOP1
  590. #define K7_NOP6 ".byte 0x8d,0x80,0,0,0,0\n"
  591. #define K7_NOP7 ".byte 0x8D,0x04,0x05,0,0,0,0\n"
  592. #define K7_NOP8 K7_NOP7 ASM_NOP1
  593. #ifdef CONFIG_MK8
  594. #define ASM_NOP1 K8_NOP1
  595. #define ASM_NOP2 K8_NOP2
  596. #define ASM_NOP3 K8_NOP3
  597. #define ASM_NOP4 K8_NOP4
  598. #define ASM_NOP5 K8_NOP5
  599. #define ASM_NOP6 K8_NOP6
  600. #define ASM_NOP7 K8_NOP7
  601. #define ASM_NOP8 K8_NOP8
  602. #elif defined(CONFIG_MK7)
  603. #define ASM_NOP1 K7_NOP1
  604. #define ASM_NOP2 K7_NOP2
  605. #define ASM_NOP3 K7_NOP3
  606. #define ASM_NOP4 K7_NOP4
  607. #define ASM_NOP5 K7_NOP5
  608. #define ASM_NOP6 K7_NOP6
  609. #define ASM_NOP7 K7_NOP7
  610. #define ASM_NOP8 K7_NOP8
  611. #else
  612. #define ASM_NOP1 GENERIC_NOP1
  613. #define ASM_NOP2 GENERIC_NOP2
  614. #define ASM_NOP3 GENERIC_NOP3
  615. #define ASM_NOP4 GENERIC_NOP4
  616. #define ASM_NOP5 GENERIC_NOP5
  617. #define ASM_NOP6 GENERIC_NOP6
  618. #define ASM_NOP7 GENERIC_NOP7
  619. #define ASM_NOP8 GENERIC_NOP8
  620. #endif
  621. #define ASM_NOP_MAX 8
  622. /* Prefetch instructions for Pentium III and AMD Athlon */
  623. /* It's not worth to care about 3dnow! prefetches for the K6
  624. because they are microcoded there and very slow.
  625. However we don't do prefetches for pre XP Athlons currently
  626. That should be fixed. */
  627. #define ARCH_HAS_PREFETCH
  628. static inline void prefetch(const void *x)
  629. {
  630. alternative_input(ASM_NOP4,
  631. "prefetchnta (%1)",
  632. X86_FEATURE_XMM,
  633. "r" (x));
  634. }
  635. #define ARCH_HAS_PREFETCH
  636. #define ARCH_HAS_PREFETCHW
  637. #define ARCH_HAS_SPINLOCK_PREFETCH
  638. /* 3dnow! prefetch to get an exclusive cache line. Useful for
  639. spinlocks to avoid one state transition in the cache coherency protocol. */
  640. static inline void prefetchw(const void *x)
  641. {
  642. alternative_input(ASM_NOP4,
  643. "prefetchw (%1)",
  644. X86_FEATURE_3DNOW,
  645. "r" (x));
  646. }
  647. #define spin_lock_prefetch(x) prefetchw(x)
  648. extern void select_idle_routine(const struct cpuinfo_x86 *c);
  649. #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
  650. extern unsigned long boot_option_idle_override;
  651. extern void enable_sep_cpu(void);
  652. extern int sysenter_setup(void);
  653. /* Defined in head.S */
  654. extern struct Xgt_desc_struct early_gdt_descr;
  655. extern void cpu_set_gdt(int);
  656. extern void switch_to_new_gdt(void);
  657. extern void cpu_init(void);
  658. extern void init_gdt(int cpu);
  659. extern int force_mwait;
  660. #endif /* __ASM_I386_PROCESSOR_H */