paravirt.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. #ifndef __ASM_PARAVIRT_H
  2. #define __ASM_PARAVIRT_H
  3. /* Various instructions on x86 need to be replaced for
  4. * para-virtualization: those hooks are defined here. */
  5. #ifdef CONFIG_PARAVIRT
  6. #include <asm/page.h>
  7. /* Bitmask of what can be clobbered: usually at least eax. */
  8. #define CLBR_NONE 0x0
  9. #define CLBR_EAX 0x1
  10. #define CLBR_ECX 0x2
  11. #define CLBR_EDX 0x4
  12. #define CLBR_ANY 0x7
  13. #ifndef __ASSEMBLY__
  14. #include <linux/types.h>
  15. #include <linux/cpumask.h>
  16. #include <asm/kmap_types.h>
  17. #include <asm/desc_defs.h>
  18. struct page;
  19. struct thread_struct;
  20. struct desc_ptr;
  21. struct tss_struct;
  22. struct mm_struct;
  23. struct desc_struct;
  24. /* general info */
  25. struct pv_info {
  26. unsigned int kernel_rpl;
  27. int shared_kernel_pmd;
  28. int paravirt_enabled;
  29. const char *name;
  30. };
  31. struct pv_init_ops {
  32. /*
  33. * Patch may replace one of the defined code sequences with
  34. * arbitrary code, subject to the same register constraints.
  35. * This generally means the code is not free to clobber any
  36. * registers other than EAX. The patch function should return
  37. * the number of bytes of code generated, as we nop pad the
  38. * rest in generic code.
  39. */
  40. unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
  41. unsigned long addr, unsigned len);
  42. /* Basic arch-specific setup */
  43. void (*arch_setup)(void);
  44. char *(*memory_setup)(void);
  45. void (*post_allocator_init)(void);
  46. /* Print a banner to identify the environment */
  47. void (*banner)(void);
  48. };
  49. struct pv_lazy_ops {
  50. /* Set deferred update mode, used for batching operations. */
  51. void (*enter)(void);
  52. void (*leave)(void);
  53. };
  54. struct pv_time_ops {
  55. void (*time_init)(void);
  56. /* Set and set time of day */
  57. unsigned long (*get_wallclock)(void);
  58. int (*set_wallclock)(unsigned long);
  59. unsigned long long (*sched_clock)(void);
  60. unsigned long (*get_cpu_khz)(void);
  61. };
  62. struct pv_cpu_ops {
  63. /* hooks for various privileged instructions */
  64. unsigned long (*get_debugreg)(int regno);
  65. void (*set_debugreg)(int regno, unsigned long value);
  66. void (*clts)(void);
  67. unsigned long (*read_cr0)(void);
  68. void (*write_cr0)(unsigned long);
  69. unsigned long (*read_cr4_safe)(void);
  70. unsigned long (*read_cr4)(void);
  71. void (*write_cr4)(unsigned long);
  72. /* Segment descriptor handling */
  73. void (*load_tr_desc)(void);
  74. void (*load_gdt)(const struct desc_ptr *);
  75. void (*load_idt)(const struct desc_ptr *);
  76. void (*store_gdt)(struct desc_ptr *);
  77. void (*store_idt)(struct desc_ptr *);
  78. void (*set_ldt)(const void *desc, unsigned entries);
  79. unsigned long (*store_tr)(void);
  80. void (*load_tls)(struct thread_struct *t, unsigned int cpu);
  81. void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum,
  82. const void *desc);
  83. void (*write_gdt_entry)(struct desc_struct *,
  84. int entrynum, const void *desc, int size);
  85. void (*write_idt_entry)(gate_desc *,
  86. int entrynum, const gate_desc *gate);
  87. void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t);
  88. void (*set_iopl_mask)(unsigned mask);
  89. void (*wbinvd)(void);
  90. void (*io_delay)(void);
  91. /* cpuid emulation, mostly so that caps bits can be disabled */
  92. void (*cpuid)(unsigned int *eax, unsigned int *ebx,
  93. unsigned int *ecx, unsigned int *edx);
  94. /* MSR, PMC and TSR operations.
  95. err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
  96. u64 (*read_msr)(unsigned int msr, int *err);
  97. int (*write_msr)(unsigned int msr, unsigned low, unsigned high);
  98. u64 (*read_tsc)(void);
  99. u64 (*read_pmc)(int counter);
  100. unsigned long long (*read_tscp)(unsigned int *aux);
  101. /* These two are jmp to, not actually called. */
  102. void (*irq_enable_syscall_ret)(void);
  103. void (*iret)(void);
  104. struct pv_lazy_ops lazy_mode;
  105. };
  106. struct pv_irq_ops {
  107. void (*init_IRQ)(void);
  108. /*
  109. * Get/set interrupt state. save_fl and restore_fl are only
  110. * expected to use X86_EFLAGS_IF; all other bits
  111. * returned from save_fl are undefined, and may be ignored by
  112. * restore_fl.
  113. */
  114. unsigned long (*save_fl)(void);
  115. void (*restore_fl)(unsigned long);
  116. void (*irq_disable)(void);
  117. void (*irq_enable)(void);
  118. void (*safe_halt)(void);
  119. void (*halt)(void);
  120. };
  121. struct pv_apic_ops {
  122. #ifdef CONFIG_X86_LOCAL_APIC
  123. /*
  124. * Direct APIC operations, principally for VMI. Ideally
  125. * these shouldn't be in this interface.
  126. */
  127. void (*apic_write)(unsigned long reg, u32 v);
  128. void (*apic_write_atomic)(unsigned long reg, u32 v);
  129. u32 (*apic_read)(unsigned long reg);
  130. void (*setup_boot_clock)(void);
  131. void (*setup_secondary_clock)(void);
  132. void (*startup_ipi_hook)(int phys_apicid,
  133. unsigned long start_eip,
  134. unsigned long start_esp);
  135. #endif
  136. };
  137. struct pv_mmu_ops {
  138. /*
  139. * Called before/after init_mm pagetable setup. setup_start
  140. * may reset %cr3, and may pre-install parts of the pagetable;
  141. * pagetable setup is expected to preserve any existing
  142. * mapping.
  143. */
  144. void (*pagetable_setup_start)(pgd_t *pgd_base);
  145. void (*pagetable_setup_done)(pgd_t *pgd_base);
  146. unsigned long (*read_cr2)(void);
  147. void (*write_cr2)(unsigned long);
  148. unsigned long (*read_cr3)(void);
  149. void (*write_cr3)(unsigned long);
  150. /*
  151. * Hooks for intercepting the creation/use/destruction of an
  152. * mm_struct.
  153. */
  154. void (*activate_mm)(struct mm_struct *prev,
  155. struct mm_struct *next);
  156. void (*dup_mmap)(struct mm_struct *oldmm,
  157. struct mm_struct *mm);
  158. void (*exit_mmap)(struct mm_struct *mm);
  159. /* TLB operations */
  160. void (*flush_tlb_user)(void);
  161. void (*flush_tlb_kernel)(void);
  162. void (*flush_tlb_single)(unsigned long addr);
  163. void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
  164. unsigned long va);
  165. /* Hooks for allocating/releasing pagetable pages */
  166. void (*alloc_pt)(struct mm_struct *mm, u32 pfn);
  167. void (*alloc_pd)(u32 pfn);
  168. void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
  169. void (*release_pt)(u32 pfn);
  170. void (*release_pd)(u32 pfn);
  171. /* Pagetable manipulation functions */
  172. void (*set_pte)(pte_t *ptep, pte_t pteval);
  173. void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
  174. pte_t *ptep, pte_t pteval);
  175. void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
  176. void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
  177. void (*pte_update_defer)(struct mm_struct *mm,
  178. unsigned long addr, pte_t *ptep);
  179. #ifdef CONFIG_X86_PAE
  180. void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
  181. void (*set_pte_present)(struct mm_struct *mm, unsigned long addr,
  182. pte_t *ptep, pte_t pte);
  183. void (*set_pud)(pud_t *pudp, pud_t pudval);
  184. void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
  185. void (*pmd_clear)(pmd_t *pmdp);
  186. unsigned long long (*pte_val)(pte_t);
  187. unsigned long long (*pmd_val)(pmd_t);
  188. unsigned long long (*pgd_val)(pgd_t);
  189. pte_t (*make_pte)(unsigned long long pte);
  190. pmd_t (*make_pmd)(unsigned long long pmd);
  191. pgd_t (*make_pgd)(unsigned long long pgd);
  192. #else
  193. unsigned long (*pte_val)(pte_t);
  194. unsigned long (*pgd_val)(pgd_t);
  195. pte_t (*make_pte)(unsigned long pte);
  196. pgd_t (*make_pgd)(unsigned long pgd);
  197. #endif
  198. #ifdef CONFIG_HIGHPTE
  199. void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
  200. #endif
  201. struct pv_lazy_ops lazy_mode;
  202. };
  203. /* This contains all the paravirt structures: we get a convenient
  204. * number for each function using the offset which we use to indicate
  205. * what to patch. */
  206. struct paravirt_patch_template
  207. {
  208. struct pv_init_ops pv_init_ops;
  209. struct pv_time_ops pv_time_ops;
  210. struct pv_cpu_ops pv_cpu_ops;
  211. struct pv_irq_ops pv_irq_ops;
  212. struct pv_apic_ops pv_apic_ops;
  213. struct pv_mmu_ops pv_mmu_ops;
  214. };
  215. extern struct pv_info pv_info;
  216. extern struct pv_init_ops pv_init_ops;
  217. extern struct pv_time_ops pv_time_ops;
  218. extern struct pv_cpu_ops pv_cpu_ops;
  219. extern struct pv_irq_ops pv_irq_ops;
  220. extern struct pv_apic_ops pv_apic_ops;
  221. extern struct pv_mmu_ops pv_mmu_ops;
  222. #define PARAVIRT_PATCH(x) \
  223. (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
  224. #define paravirt_type(op) \
  225. [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \
  226. [paravirt_opptr] "m" (op)
  227. #define paravirt_clobber(clobber) \
  228. [paravirt_clobber] "i" (clobber)
  229. /*
  230. * Generate some code, and mark it as patchable by the
  231. * apply_paravirt() alternate instruction patcher.
  232. */
  233. #define _paravirt_alt(insn_string, type, clobber) \
  234. "771:\n\t" insn_string "\n" "772:\n" \
  235. ".pushsection .parainstructions,\"a\"\n" \
  236. " .long 771b\n" \
  237. " .byte " type "\n" \
  238. " .byte 772b-771b\n" \
  239. " .short " clobber "\n" \
  240. ".popsection\n"
  241. /* Generate patchable code, with the default asm parameters. */
  242. #define paravirt_alt(insn_string) \
  243. _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
  244. unsigned paravirt_patch_nop(void);
  245. unsigned paravirt_patch_ignore(unsigned len);
  246. unsigned paravirt_patch_call(void *insnbuf,
  247. const void *target, u16 tgt_clobbers,
  248. unsigned long addr, u16 site_clobbers,
  249. unsigned len);
  250. unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
  251. unsigned long addr, unsigned len);
  252. unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
  253. unsigned long addr, unsigned len);
  254. unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
  255. const char *start, const char *end);
  256. int paravirt_disable_iospace(void);
  257. /*
  258. * This generates an indirect call based on the operation type number.
  259. * The type number, computed in PARAVIRT_PATCH, is derived from the
  260. * offset into the paravirt_patch_template structure, and can therefore be
  261. * freely converted back into a structure offset.
  262. */
  263. #define PARAVIRT_CALL "call *%[paravirt_opptr];"
  264. /*
  265. * These macros are intended to wrap calls through one of the paravirt
  266. * ops structs, so that they can be later identified and patched at
  267. * runtime.
  268. *
  269. * Normally, a call to a pv_op function is a simple indirect call:
  270. * (pv_op_struct.operations)(args...).
  271. *
  272. * Unfortunately, this is a relatively slow operation for modern CPUs,
  273. * because it cannot necessarily determine what the destination
  274. * address is. In this case, the address is a runtime constant, so at
  275. * the very least we can patch the call to e a simple direct call, or
  276. * ideally, patch an inline implementation into the callsite. (Direct
  277. * calls are essentially free, because the call and return addresses
  278. * are completely predictable.)
  279. *
  280. * For i386, these macros rely on the standard gcc "regparm(3)" calling
  281. * convention, in which the first three arguments are placed in %eax,
  282. * %edx, %ecx (in that order), and the remaining arguments are placed
  283. * on the stack. All caller-save registers (eax,edx,ecx) are expected
  284. * to be modified (either clobbered or used for return values).
  285. * X86_64, on the other hand, already specifies a register-based calling
  286. * conventions, returning at %rax, with parameteres going on %rdi, %rsi,
  287. * %rdx, and %rcx. Note that for this reason, x86_64 does not need any
  288. * special handling for dealing with 4 arguments, unlike i386.
  289. * However, x86_64 also have to clobber all caller saved registers, which
  290. * unfortunately, are quite a bit (r8 - r11)
  291. *
  292. * The call instruction itself is marked by placing its start address
  293. * and size into the .parainstructions section, so that
  294. * apply_paravirt() in arch/i386/kernel/alternative.c can do the
  295. * appropriate patching under the control of the backend pv_init_ops
  296. * implementation.
  297. *
  298. * Unfortunately there's no way to get gcc to generate the args setup
  299. * for the call, and then allow the call itself to be generated by an
  300. * inline asm. Because of this, we must do the complete arg setup and
  301. * return value handling from within these macros. This is fairly
  302. * cumbersome.
  303. *
  304. * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
  305. * It could be extended to more arguments, but there would be little
  306. * to be gained from that. For each number of arguments, there are
  307. * the two VCALL and CALL variants for void and non-void functions.
  308. *
  309. * When there is a return value, the invoker of the macro must specify
  310. * the return type. The macro then uses sizeof() on that type to
  311. * determine whether its a 32 or 64 bit value, and places the return
  312. * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
  313. * 64-bit). For x86_64 machines, it just returns at %rax regardless of
  314. * the return value size.
  315. *
  316. * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
  317. * i386 also passes 64-bit arguments as a pair of adjacent 32-bit arguments
  318. * in low,high order
  319. *
  320. * Small structures are passed and returned in registers. The macro
  321. * calling convention can't directly deal with this, so the wrapper
  322. * functions must do this.
  323. *
  324. * These PVOP_* macros are only defined within this header. This
  325. * means that all uses must be wrapped in inline functions. This also
  326. * makes sure the incoming and outgoing types are always correct.
  327. */
  328. #ifdef CONFIG_X86_32
  329. #define PVOP_VCALL_ARGS unsigned long __eax, __edx, __ecx
  330. #define PVOP_CALL_ARGS PVOP_VCALL_ARGS
  331. #define PVOP_VCALL_CLOBBERS "=a" (__eax), "=d" (__edx), \
  332. "=c" (__ecx)
  333. #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS
  334. #define EXTRA_CLOBBERS
  335. #define VEXTRA_CLOBBERS
  336. #else
  337. #define PVOP_VCALL_ARGS unsigned long __edi, __esi, __edx, __ecx
  338. #define PVOP_CALL_ARGS PVOP_VCALL_ARGS, __eax
  339. #define PVOP_VCALL_CLOBBERS "=D" (__edi), \
  340. "=S" (__esi), "=d" (__edx), \
  341. "=c" (__ecx)
  342. #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax)
  343. #define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11"
  344. #define VEXTRA_CLOBBERS , "rax", "r8", "r9", "r10", "r11"
  345. #endif
  346. #define __PVOP_CALL(rettype, op, pre, post, ...) \
  347. ({ \
  348. rettype __ret; \
  349. PVOP_CALL_ARGS; \
  350. /* This is 32-bit specific, but is okay in 64-bit */ \
  351. /* since this condition will never hold */ \
  352. if (sizeof(rettype) > sizeof(unsigned long)) { \
  353. asm volatile(pre \
  354. paravirt_alt(PARAVIRT_CALL) \
  355. post \
  356. : PVOP_CALL_CLOBBERS \
  357. : paravirt_type(op), \
  358. paravirt_clobber(CLBR_ANY), \
  359. ##__VA_ARGS__ \
  360. : "memory", "cc" EXTRA_CLOBBERS); \
  361. __ret = (rettype)((((u64)__edx) << 32) | __eax); \
  362. } else { \
  363. asm volatile(pre \
  364. paravirt_alt(PARAVIRT_CALL) \
  365. post \
  366. : PVOP_CALL_CLOBBERS \
  367. : paravirt_type(op), \
  368. paravirt_clobber(CLBR_ANY), \
  369. ##__VA_ARGS__ \
  370. : "memory", "cc" EXTRA_CLOBBERS); \
  371. __ret = (rettype)__eax; \
  372. } \
  373. __ret; \
  374. })
  375. #define __PVOP_VCALL(op, pre, post, ...) \
  376. ({ \
  377. PVOP_VCALL_ARGS; \
  378. asm volatile(pre \
  379. paravirt_alt(PARAVIRT_CALL) \
  380. post \
  381. : PVOP_VCALL_CLOBBERS \
  382. : paravirt_type(op), \
  383. paravirt_clobber(CLBR_ANY), \
  384. ##__VA_ARGS__ \
  385. : "memory", "cc" VEXTRA_CLOBBERS); \
  386. })
  387. #define PVOP_CALL0(rettype, op) \
  388. __PVOP_CALL(rettype, op, "", "")
  389. #define PVOP_VCALL0(op) \
  390. __PVOP_VCALL(op, "", "")
  391. #define PVOP_CALL1(rettype, op, arg1) \
  392. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)))
  393. #define PVOP_VCALL1(op, arg1) \
  394. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)))
  395. #define PVOP_CALL2(rettype, op, arg1, arg2) \
  396. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
  397. "1" ((unsigned long)(arg2)))
  398. #define PVOP_VCALL2(op, arg1, arg2) \
  399. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
  400. "1" ((unsigned long)(arg2)))
  401. #define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \
  402. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
  403. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)))
  404. #define PVOP_VCALL3(op, arg1, arg2, arg3) \
  405. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
  406. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)))
  407. /* This is the only difference in x86_64. We can make it much simpler */
  408. #ifdef CONFIG_X86_32
  409. #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
  410. __PVOP_CALL(rettype, op, \
  411. "push %[_arg4];", "lea 4(%%esp),%%esp;", \
  412. "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
  413. "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
  414. #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
  415. __PVOP_VCALL(op, \
  416. "push %[_arg4];", "lea 4(%%esp),%%esp;", \
  417. "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
  418. "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
  419. #else
  420. #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
  421. __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
  422. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)), \
  423. "3"((unsigned long)(arg4)))
  424. #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
  425. __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
  426. "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)), \
  427. "3"((unsigned long)(arg4)))
  428. #endif
  429. static inline int paravirt_enabled(void)
  430. {
  431. return pv_info.paravirt_enabled;
  432. }
  433. static inline void load_sp0(struct tss_struct *tss,
  434. struct thread_struct *thread)
  435. {
  436. PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
  437. }
  438. #define ARCH_SETUP pv_init_ops.arch_setup();
  439. static inline unsigned long get_wallclock(void)
  440. {
  441. return PVOP_CALL0(unsigned long, pv_time_ops.get_wallclock);
  442. }
  443. static inline int set_wallclock(unsigned long nowtime)
  444. {
  445. return PVOP_CALL1(int, pv_time_ops.set_wallclock, nowtime);
  446. }
  447. static inline void (*choose_time_init(void))(void)
  448. {
  449. return pv_time_ops.time_init;
  450. }
  451. /* The paravirtualized CPUID instruction. */
  452. static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
  453. unsigned int *ecx, unsigned int *edx)
  454. {
  455. PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
  456. }
  457. /*
  458. * These special macros can be used to get or set a debugging register
  459. */
  460. static inline unsigned long paravirt_get_debugreg(int reg)
  461. {
  462. return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
  463. }
  464. #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
  465. static inline void set_debugreg(unsigned long val, int reg)
  466. {
  467. PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
  468. }
  469. static inline void clts(void)
  470. {
  471. PVOP_VCALL0(pv_cpu_ops.clts);
  472. }
  473. static inline unsigned long read_cr0(void)
  474. {
  475. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
  476. }
  477. static inline void write_cr0(unsigned long x)
  478. {
  479. PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
  480. }
  481. static inline unsigned long read_cr2(void)
  482. {
  483. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
  484. }
  485. static inline void write_cr2(unsigned long x)
  486. {
  487. PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
  488. }
  489. static inline unsigned long read_cr3(void)
  490. {
  491. return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
  492. }
  493. static inline void write_cr3(unsigned long x)
  494. {
  495. PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
  496. }
  497. static inline unsigned long read_cr4(void)
  498. {
  499. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
  500. }
  501. static inline unsigned long read_cr4_safe(void)
  502. {
  503. return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
  504. }
  505. static inline void write_cr4(unsigned long x)
  506. {
  507. PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
  508. }
  509. static inline void raw_safe_halt(void)
  510. {
  511. PVOP_VCALL0(pv_irq_ops.safe_halt);
  512. }
  513. static inline void halt(void)
  514. {
  515. PVOP_VCALL0(pv_irq_ops.safe_halt);
  516. }
  517. static inline void wbinvd(void)
  518. {
  519. PVOP_VCALL0(pv_cpu_ops.wbinvd);
  520. }
  521. #define get_kernel_rpl() (pv_info.kernel_rpl)
  522. static inline u64 paravirt_read_msr(unsigned msr, int *err)
  523. {
  524. return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
  525. }
  526. static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
  527. {
  528. return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
  529. }
  530. /* These should all do BUG_ON(_err), but our headers are too tangled. */
  531. #define rdmsr(msr,val1,val2) do { \
  532. int _err; \
  533. u64 _l = paravirt_read_msr(msr, &_err); \
  534. val1 = (u32)_l; \
  535. val2 = _l >> 32; \
  536. } while(0)
  537. #define wrmsr(msr,val1,val2) do { \
  538. paravirt_write_msr(msr, val1, val2); \
  539. } while(0)
  540. #define rdmsrl(msr,val) do { \
  541. int _err; \
  542. val = paravirt_read_msr(msr, &_err); \
  543. } while(0)
  544. #define wrmsrl(msr,val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
  545. #define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
  546. /* rdmsr with exception handling */
  547. #define rdmsr_safe(msr,a,b) ({ \
  548. int _err; \
  549. u64 _l = paravirt_read_msr(msr, &_err); \
  550. (*a) = (u32)_l; \
  551. (*b) = _l >> 32; \
  552. _err; })
  553. static inline u64 paravirt_read_tsc(void)
  554. {
  555. return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
  556. }
  557. #define rdtscl(low) do { \
  558. u64 _l = paravirt_read_tsc(); \
  559. low = (int)_l; \
  560. } while(0)
  561. #define rdtscll(val) (val = paravirt_read_tsc())
  562. static inline unsigned long long paravirt_sched_clock(void)
  563. {
  564. return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
  565. }
  566. #define calculate_cpu_khz() (pv_time_ops.get_cpu_khz())
  567. static inline unsigned long long paravirt_read_pmc(int counter)
  568. {
  569. return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
  570. }
  571. #define rdpmc(counter,low,high) do { \
  572. u64 _l = paravirt_read_pmc(counter); \
  573. low = (u32)_l; \
  574. high = _l >> 32; \
  575. } while(0)
  576. static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
  577. {
  578. return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
  579. }
  580. #define rdtscp(low, high, aux) \
  581. do { \
  582. int __aux; \
  583. unsigned long __val = paravirt_rdtscp(&__aux); \
  584. (low) = (u32)__val; \
  585. (high) = (u32)(__val >> 32); \
  586. (aux) = __aux; \
  587. } while (0)
  588. #define rdtscpll(val, aux) \
  589. do { \
  590. unsigned long __aux; \
  591. val = paravirt_rdtscp(&__aux); \
  592. (aux) = __aux; \
  593. } while (0)
  594. static inline void load_TR_desc(void)
  595. {
  596. PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
  597. }
  598. static inline void load_gdt(const struct desc_ptr *dtr)
  599. {
  600. PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
  601. }
  602. static inline void load_idt(const struct desc_ptr *dtr)
  603. {
  604. PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
  605. }
  606. static inline void set_ldt(const void *addr, unsigned entries)
  607. {
  608. PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
  609. }
  610. static inline void store_gdt(struct desc_ptr *dtr)
  611. {
  612. PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
  613. }
  614. static inline void store_idt(struct desc_ptr *dtr)
  615. {
  616. PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
  617. }
  618. static inline unsigned long paravirt_store_tr(void)
  619. {
  620. return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
  621. }
  622. #define store_tr(tr) ((tr) = paravirt_store_tr())
  623. static inline void load_TLS(struct thread_struct *t, unsigned cpu)
  624. {
  625. PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
  626. }
  627. static inline void write_ldt_entry(struct desc_struct *dt, int entry,
  628. const void *desc)
  629. {
  630. PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
  631. }
  632. static inline void write_gdt_entry(struct desc_struct *dt, int entry,
  633. void *desc, int type)
  634. {
  635. PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
  636. }
  637. static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
  638. {
  639. PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
  640. }
  641. static inline void set_iopl_mask(unsigned mask)
  642. {
  643. PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
  644. }
  645. /* The paravirtualized I/O functions */
  646. static inline void slow_down_io(void) {
  647. pv_cpu_ops.io_delay();
  648. #ifdef REALLY_SLOW_IO
  649. pv_cpu_ops.io_delay();
  650. pv_cpu_ops.io_delay();
  651. pv_cpu_ops.io_delay();
  652. #endif
  653. }
  654. #ifdef CONFIG_X86_LOCAL_APIC
  655. /*
  656. * Basic functions accessing APICs.
  657. */
  658. static inline void apic_write(unsigned long reg, u32 v)
  659. {
  660. PVOP_VCALL2(pv_apic_ops.apic_write, reg, v);
  661. }
  662. static inline void apic_write_atomic(unsigned long reg, u32 v)
  663. {
  664. PVOP_VCALL2(pv_apic_ops.apic_write_atomic, reg, v);
  665. }
  666. static inline u32 apic_read(unsigned long reg)
  667. {
  668. return PVOP_CALL1(unsigned long, pv_apic_ops.apic_read, reg);
  669. }
  670. static inline void setup_boot_clock(void)
  671. {
  672. PVOP_VCALL0(pv_apic_ops.setup_boot_clock);
  673. }
  674. static inline void setup_secondary_clock(void)
  675. {
  676. PVOP_VCALL0(pv_apic_ops.setup_secondary_clock);
  677. }
  678. #endif
  679. static inline void paravirt_post_allocator_init(void)
  680. {
  681. if (pv_init_ops.post_allocator_init)
  682. (*pv_init_ops.post_allocator_init)();
  683. }
  684. static inline void paravirt_pagetable_setup_start(pgd_t *base)
  685. {
  686. (*pv_mmu_ops.pagetable_setup_start)(base);
  687. }
  688. static inline void paravirt_pagetable_setup_done(pgd_t *base)
  689. {
  690. (*pv_mmu_ops.pagetable_setup_done)(base);
  691. }
  692. #ifdef CONFIG_SMP
  693. static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
  694. unsigned long start_esp)
  695. {
  696. PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
  697. phys_apicid, start_eip, start_esp);
  698. }
  699. #endif
  700. static inline void paravirt_activate_mm(struct mm_struct *prev,
  701. struct mm_struct *next)
  702. {
  703. PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
  704. }
  705. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  706. struct mm_struct *mm)
  707. {
  708. PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
  709. }
  710. static inline void arch_exit_mmap(struct mm_struct *mm)
  711. {
  712. PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
  713. }
  714. static inline void __flush_tlb(void)
  715. {
  716. PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
  717. }
  718. static inline void __flush_tlb_global(void)
  719. {
  720. PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
  721. }
  722. static inline void __flush_tlb_single(unsigned long addr)
  723. {
  724. PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
  725. }
  726. static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
  727. unsigned long va)
  728. {
  729. PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, &cpumask, mm, va);
  730. }
  731. static inline void paravirt_alloc_pt(struct mm_struct *mm, unsigned pfn)
  732. {
  733. PVOP_VCALL2(pv_mmu_ops.alloc_pt, mm, pfn);
  734. }
  735. static inline void paravirt_release_pt(unsigned pfn)
  736. {
  737. PVOP_VCALL1(pv_mmu_ops.release_pt, pfn);
  738. }
  739. static inline void paravirt_alloc_pd(unsigned pfn)
  740. {
  741. PVOP_VCALL1(pv_mmu_ops.alloc_pd, pfn);
  742. }
  743. static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
  744. unsigned start, unsigned count)
  745. {
  746. PVOP_VCALL4(pv_mmu_ops.alloc_pd_clone, pfn, clonepfn, start, count);
  747. }
  748. static inline void paravirt_release_pd(unsigned pfn)
  749. {
  750. PVOP_VCALL1(pv_mmu_ops.release_pd, pfn);
  751. }
  752. #ifdef CONFIG_HIGHPTE
  753. static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
  754. {
  755. unsigned long ret;
  756. ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type);
  757. return (void *)ret;
  758. }
  759. #endif
  760. static inline void pte_update(struct mm_struct *mm, unsigned long addr,
  761. pte_t *ptep)
  762. {
  763. PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
  764. }
  765. static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
  766. pte_t *ptep)
  767. {
  768. PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
  769. }
  770. #ifdef CONFIG_X86_PAE
  771. static inline pte_t __pte(unsigned long long val)
  772. {
  773. unsigned long long ret = PVOP_CALL2(unsigned long long,
  774. pv_mmu_ops.make_pte,
  775. val, val >> 32);
  776. return (pte_t) { ret, ret >> 32 };
  777. }
  778. static inline pmd_t __pmd(unsigned long long val)
  779. {
  780. return (pmd_t) { PVOP_CALL2(unsigned long long, pv_mmu_ops.make_pmd,
  781. val, val >> 32) };
  782. }
  783. static inline pgd_t __pgd(unsigned long long val)
  784. {
  785. return (pgd_t) { PVOP_CALL2(unsigned long long, pv_mmu_ops.make_pgd,
  786. val, val >> 32) };
  787. }
  788. static inline unsigned long long pte_val(pte_t x)
  789. {
  790. return PVOP_CALL2(unsigned long long, pv_mmu_ops.pte_val,
  791. x.pte_low, x.pte_high);
  792. }
  793. static inline unsigned long long pmd_val(pmd_t x)
  794. {
  795. return PVOP_CALL2(unsigned long long, pv_mmu_ops.pmd_val,
  796. x.pmd, x.pmd >> 32);
  797. }
  798. static inline unsigned long long pgd_val(pgd_t x)
  799. {
  800. return PVOP_CALL2(unsigned long long, pv_mmu_ops.pgd_val,
  801. x.pgd, x.pgd >> 32);
  802. }
  803. static inline void set_pte(pte_t *ptep, pte_t pteval)
  804. {
  805. PVOP_VCALL3(pv_mmu_ops.set_pte, ptep, pteval.pte_low, pteval.pte_high);
  806. }
  807. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  808. pte_t *ptep, pte_t pteval)
  809. {
  810. /* 5 arg words */
  811. pv_mmu_ops.set_pte_at(mm, addr, ptep, pteval);
  812. }
  813. static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
  814. {
  815. PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
  816. pteval.pte_low, pteval.pte_high);
  817. }
  818. static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
  819. pte_t *ptep, pte_t pte)
  820. {
  821. /* 5 arg words */
  822. pv_mmu_ops.set_pte_present(mm, addr, ptep, pte);
  823. }
  824. static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
  825. {
  826. PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp,
  827. pmdval.pmd, pmdval.pmd >> 32);
  828. }
  829. static inline void set_pud(pud_t *pudp, pud_t pudval)
  830. {
  831. PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
  832. pudval.pgd.pgd, pudval.pgd.pgd >> 32);
  833. }
  834. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  835. {
  836. PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
  837. }
  838. static inline void pmd_clear(pmd_t *pmdp)
  839. {
  840. PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
  841. }
  842. #else /* !CONFIG_X86_PAE */
  843. static inline pte_t __pte(unsigned long val)
  844. {
  845. return (pte_t) { PVOP_CALL1(unsigned long, pv_mmu_ops.make_pte, val) };
  846. }
  847. static inline pgd_t __pgd(unsigned long val)
  848. {
  849. return (pgd_t) { PVOP_CALL1(unsigned long, pv_mmu_ops.make_pgd, val) };
  850. }
  851. static inline unsigned long pte_val(pte_t x)
  852. {
  853. return PVOP_CALL1(unsigned long, pv_mmu_ops.pte_val, x.pte_low);
  854. }
  855. static inline unsigned long pgd_val(pgd_t x)
  856. {
  857. return PVOP_CALL1(unsigned long, pv_mmu_ops.pgd_val, x.pgd);
  858. }
  859. static inline void set_pte(pte_t *ptep, pte_t pteval)
  860. {
  861. PVOP_VCALL2(pv_mmu_ops.set_pte, ptep, pteval.pte_low);
  862. }
  863. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  864. pte_t *ptep, pte_t pteval)
  865. {
  866. PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pteval.pte_low);
  867. }
  868. static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
  869. {
  870. PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, pmdval.pud.pgd.pgd);
  871. }
  872. #endif /* CONFIG_X86_PAE */
  873. /* Lazy mode for batching updates / context switch */
  874. enum paravirt_lazy_mode {
  875. PARAVIRT_LAZY_NONE,
  876. PARAVIRT_LAZY_MMU,
  877. PARAVIRT_LAZY_CPU,
  878. };
  879. enum paravirt_lazy_mode paravirt_get_lazy_mode(void);
  880. void paravirt_enter_lazy_cpu(void);
  881. void paravirt_leave_lazy_cpu(void);
  882. void paravirt_enter_lazy_mmu(void);
  883. void paravirt_leave_lazy_mmu(void);
  884. void paravirt_leave_lazy(enum paravirt_lazy_mode mode);
  885. #define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
  886. static inline void arch_enter_lazy_cpu_mode(void)
  887. {
  888. PVOP_VCALL0(pv_cpu_ops.lazy_mode.enter);
  889. }
  890. static inline void arch_leave_lazy_cpu_mode(void)
  891. {
  892. PVOP_VCALL0(pv_cpu_ops.lazy_mode.leave);
  893. }
  894. static inline void arch_flush_lazy_cpu_mode(void)
  895. {
  896. if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_CPU)) {
  897. arch_leave_lazy_cpu_mode();
  898. arch_enter_lazy_cpu_mode();
  899. }
  900. }
  901. #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
  902. static inline void arch_enter_lazy_mmu_mode(void)
  903. {
  904. PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
  905. }
  906. static inline void arch_leave_lazy_mmu_mode(void)
  907. {
  908. PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
  909. }
  910. static inline void arch_flush_lazy_mmu_mode(void)
  911. {
  912. if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU)) {
  913. arch_leave_lazy_mmu_mode();
  914. arch_enter_lazy_mmu_mode();
  915. }
  916. }
  917. void _paravirt_nop(void);
  918. #define paravirt_nop ((void *)_paravirt_nop)
  919. /* These all sit in the .parainstructions section to tell us what to patch. */
  920. struct paravirt_patch_site {
  921. u8 *instr; /* original instructions */
  922. u8 instrtype; /* type of this instruction */
  923. u8 len; /* length of original instruction */
  924. u16 clobbers; /* what registers you may clobber */
  925. };
  926. extern struct paravirt_patch_site __parainstructions[],
  927. __parainstructions_end[];
  928. static inline unsigned long __raw_local_save_flags(void)
  929. {
  930. unsigned long f;
  931. asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
  932. PARAVIRT_CALL
  933. "popl %%edx; popl %%ecx")
  934. : "=a"(f)
  935. : paravirt_type(pv_irq_ops.save_fl),
  936. paravirt_clobber(CLBR_EAX)
  937. : "memory", "cc");
  938. return f;
  939. }
  940. static inline void raw_local_irq_restore(unsigned long f)
  941. {
  942. asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
  943. PARAVIRT_CALL
  944. "popl %%edx; popl %%ecx")
  945. : "=a"(f)
  946. : "0"(f),
  947. paravirt_type(pv_irq_ops.restore_fl),
  948. paravirt_clobber(CLBR_EAX)
  949. : "memory", "cc");
  950. }
  951. static inline void raw_local_irq_disable(void)
  952. {
  953. asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
  954. PARAVIRT_CALL
  955. "popl %%edx; popl %%ecx")
  956. :
  957. : paravirt_type(pv_irq_ops.irq_disable),
  958. paravirt_clobber(CLBR_EAX)
  959. : "memory", "eax", "cc");
  960. }
  961. static inline void raw_local_irq_enable(void)
  962. {
  963. asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
  964. PARAVIRT_CALL
  965. "popl %%edx; popl %%ecx")
  966. :
  967. : paravirt_type(pv_irq_ops.irq_enable),
  968. paravirt_clobber(CLBR_EAX)
  969. : "memory", "eax", "cc");
  970. }
  971. static inline unsigned long __raw_local_irq_save(void)
  972. {
  973. unsigned long f;
  974. f = __raw_local_save_flags();
  975. raw_local_irq_disable();
  976. return f;
  977. }
  978. /* Make sure as little as possible of this mess escapes. */
  979. #undef PARAVIRT_CALL
  980. #undef __PVOP_CALL
  981. #undef __PVOP_VCALL
  982. #undef PVOP_VCALL0
  983. #undef PVOP_CALL0
  984. #undef PVOP_VCALL1
  985. #undef PVOP_CALL1
  986. #undef PVOP_VCALL2
  987. #undef PVOP_CALL2
  988. #undef PVOP_VCALL3
  989. #undef PVOP_CALL3
  990. #undef PVOP_VCALL4
  991. #undef PVOP_CALL4
  992. #else /* __ASSEMBLY__ */
  993. #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
  994. #define PARA_SITE(ptype, clobbers, ops) \
  995. 771:; \
  996. ops; \
  997. 772:; \
  998. .pushsection .parainstructions,"a"; \
  999. .long 771b; \
  1000. .byte ptype; \
  1001. .byte 772b-771b; \
  1002. .short clobbers; \
  1003. .popsection
  1004. #define INTERRUPT_RETURN \
  1005. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
  1006. jmp *%cs:pv_cpu_ops+PV_CPU_iret)
  1007. #define DISABLE_INTERRUPTS(clobbers) \
  1008. PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
  1009. pushl %eax; pushl %ecx; pushl %edx; \
  1010. call *%cs:pv_irq_ops+PV_IRQ_irq_disable; \
  1011. popl %edx; popl %ecx; popl %eax) \
  1012. #define ENABLE_INTERRUPTS(clobbers) \
  1013. PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
  1014. pushl %eax; pushl %ecx; pushl %edx; \
  1015. call *%cs:pv_irq_ops+PV_IRQ_irq_enable; \
  1016. popl %edx; popl %ecx; popl %eax)
  1017. #define ENABLE_INTERRUPTS_SYSCALL_RET \
  1018. PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_syscall_ret),\
  1019. CLBR_NONE, \
  1020. jmp *%cs:pv_cpu_ops+PV_CPU_irq_enable_syscall_ret)
  1021. #define GET_CR0_INTO_EAX \
  1022. push %ecx; push %edx; \
  1023. call *pv_cpu_ops+PV_CPU_read_cr0; \
  1024. pop %edx; pop %ecx
  1025. #endif /* __ASSEMBLY__ */
  1026. #endif /* CONFIG_PARAVIRT */
  1027. #endif /* __ASM_PARAVIRT_H */