paravirt.h 33 KB

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