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. */
9 /* Bitmask of what can be clobbered: usually at least eax. */
17 #include <linux/types.h>
18 #include <linux/cpumask.h>
21 struct Xgt_desc_struct;
26 /* Lazy mode for batching updates / context switch */
27 enum paravirt_lazy_mode {
28 PARAVIRT_LAZY_NONE = 0,
29 PARAVIRT_LAZY_MMU = 1,
30 PARAVIRT_LAZY_CPU = 2,
35 unsigned int kernel_rpl;
36 int shared_kernel_pmd;
41 * Patch may replace one of the defined code sequences with arbitrary
42 * code, subject to the same register constraints. This generally
43 * means the code is not free to clobber any registers other than EAX.
44 * The patch function should return the number of bytes of code
45 * generated, as we nop pad the rest in generic code.
47 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
49 /* Basic arch-specific setup */
50 void (*arch_setup)(void);
51 char *(*memory_setup)(void);
52 void (*init_IRQ)(void);
53 void (*time_init)(void);
56 * Called before/after init_mm pagetable setup. setup_start
57 * may reset %cr3, and may pre-install parts of the pagetable;
58 * pagetable setup is expected to preserve any existing
61 void (*pagetable_setup_start)(pgd_t *pgd_base);
62 void (*pagetable_setup_done)(pgd_t *pgd_base);
64 /* Print a banner to identify the environment */
67 /* Set and set time of day */
68 unsigned long (*get_wallclock)(void);
69 int (*set_wallclock)(unsigned long);
71 /* cpuid emulation, mostly so that caps bits can be disabled */
72 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
73 unsigned int *ecx, unsigned int *edx);
75 /* hooks for various privileged instructions */
76 unsigned long (*get_debugreg)(int regno);
77 void (*set_debugreg)(int regno, unsigned long value);
81 unsigned long (*read_cr0)(void);
82 void (*write_cr0)(unsigned long);
84 unsigned long (*read_cr2)(void);
85 void (*write_cr2)(unsigned long);
87 unsigned long (*read_cr3)(void);
88 void (*write_cr3)(unsigned long);
90 unsigned long (*read_cr4_safe)(void);
91 unsigned long (*read_cr4)(void);
92 void (*write_cr4)(unsigned long);
95 * Get/set interrupt state. save_fl and restore_fl are only
96 * expected to use X86_EFLAGS_IF; all other bits
97 * returned from save_fl are undefined, and may be ignored by
100 unsigned long (*save_fl)(void);
101 void (*restore_fl)(unsigned long);
102 void (*irq_disable)(void);
103 void (*irq_enable)(void);
104 void (*safe_halt)(void);
107 void (*wbinvd)(void);
109 /* MSR, PMC and TSR operations.
110 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
111 u64 (*read_msr)(unsigned int msr, int *err);
112 int (*write_msr)(unsigned int msr, u64 val);
114 u64 (*read_tsc)(void);
115 u64 (*read_pmc)(void);
116 u64 (*get_scheduled_cycles)(void);
117 unsigned long (*get_cpu_khz)(void);
119 /* Segment descriptor handling */
120 void (*load_tr_desc)(void);
121 void (*load_gdt)(const struct Xgt_desc_struct *);
122 void (*load_idt)(const struct Xgt_desc_struct *);
123 void (*store_gdt)(struct Xgt_desc_struct *);
124 void (*store_idt)(struct Xgt_desc_struct *);
125 void (*set_ldt)(const void *desc, unsigned entries);
126 unsigned long (*store_tr)(void);
127 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
128 void (*write_ldt_entry)(struct desc_struct *,
129 int entrynum, u32 low, u32 high);
130 void (*write_gdt_entry)(struct desc_struct *,
131 int entrynum, u32 low, u32 high);
132 void (*write_idt_entry)(struct desc_struct *,
133 int entrynum, u32 low, u32 high);
134 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
136 void (*set_iopl_mask)(unsigned mask);
137 void (*io_delay)(void);
140 * Hooks for intercepting the creation/use/destruction of an
143 void (*activate_mm)(struct mm_struct *prev,
144 struct mm_struct *next);
145 void (*dup_mmap)(struct mm_struct *oldmm,
146 struct mm_struct *mm);
147 void (*exit_mmap)(struct mm_struct *mm);
149 #ifdef CONFIG_X86_LOCAL_APIC
151 * Direct APIC operations, principally for VMI. Ideally
152 * these shouldn't be in this interface.
154 void (*apic_write)(unsigned long reg, unsigned long v);
155 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
156 unsigned long (*apic_read)(unsigned long reg);
157 void (*setup_boot_clock)(void);
158 void (*setup_secondary_clock)(void);
160 void (*startup_ipi_hook)(int phys_apicid,
161 unsigned long start_eip,
162 unsigned long start_esp);
166 void (*flush_tlb_user)(void);
167 void (*flush_tlb_kernel)(void);
168 void (*flush_tlb_single)(unsigned long addr);
169 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
172 /* Hooks for allocating/releasing pagetable pages */
173 void (*alloc_pt)(u32 pfn);
174 void (*alloc_pd)(u32 pfn);
175 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
176 void (*release_pt)(u32 pfn);
177 void (*release_pd)(u32 pfn);
179 /* Pagetable manipulation functions */
180 void (*set_pte)(pte_t *ptep, pte_t pteval);
181 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
182 pte_t *ptep, pte_t pteval);
183 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
184 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
185 void (*pte_update_defer)(struct mm_struct *mm,
186 unsigned long addr, pte_t *ptep);
188 pte_t (*ptep_get_and_clear)(pte_t *ptep);
190 #ifdef CONFIG_X86_PAE
191 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
192 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
193 void (*set_pud)(pud_t *pudp, pud_t pudval);
194 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
195 void (*pmd_clear)(pmd_t *pmdp);
197 unsigned long long (*pte_val)(pte_t);
198 unsigned long long (*pmd_val)(pmd_t);
199 unsigned long long (*pgd_val)(pgd_t);
201 pte_t (*make_pte)(unsigned long long pte);
202 pmd_t (*make_pmd)(unsigned long long pmd);
203 pgd_t (*make_pgd)(unsigned long long pgd);
205 unsigned long (*pte_val)(pte_t);
206 unsigned long (*pgd_val)(pgd_t);
208 pte_t (*make_pte)(unsigned long pte);
209 pgd_t (*make_pgd)(unsigned long pgd);
212 /* Set deferred update mode, used for batching operations. */
213 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
215 /* These two are jmp to, not actually called. */
216 void (*irq_enable_sysexit)(void);
220 /* Mark a paravirt probe function. */
221 #define paravirt_probe(fn) \
222 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
223 __attribute__((__section__(".paravirtprobe"))) = fn
225 extern struct paravirt_ops paravirt_ops;
227 #define PARAVIRT_PATCH(x) \
228 (offsetof(struct paravirt_ops, x) / sizeof(void *))
230 #define paravirt_type(type) \
231 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
232 #define paravirt_clobber(clobber) \
233 [paravirt_clobber] "i" (clobber)
236 * Generate some code, and mark it as patchable by the
237 * apply_paravirt() alternate instruction patcher.
239 #define _paravirt_alt(insn_string, type, clobber) \
240 "771:\n\t" insn_string "\n" "772:\n" \
241 ".pushsection .parainstructions,\"a\"\n" \
243 " .byte " type "\n" \
244 " .byte 772b-771b\n" \
245 " .short " clobber "\n" \
248 /* Generate patchable code, with the default asm parameters. */
249 #define paravirt_alt(insn_string) \
250 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
252 unsigned paravirt_patch_nop(void);
253 unsigned paravirt_patch_ignore(unsigned len);
254 unsigned paravirt_patch_call(void *target, u16 tgt_clobbers,
255 void *site, u16 site_clobbers,
257 unsigned paravirt_patch_jmp(void *target, void *site, unsigned len);
258 unsigned paravirt_patch_default(u8 type, u16 clobbers, void *site, unsigned len);
260 unsigned paravirt_patch_insns(void *site, unsigned len,
261 const char *start, const char *end);
265 * This generates an indirect call based on the operation type number.
266 * The type number, computed in PARAVIRT_PATCH, is derived from the
267 * offset into the paravirt_ops structure, and can therefore be freely
268 * converted back into a structure offset.
270 #define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
273 * These macros are intended to wrap calls into a paravirt_ops
274 * operation, so that they can be later identified and patched at
277 * Normally, a call to a pv_op function is a simple indirect call:
278 * (paravirt_ops.operations)(args...).
280 * Unfortunately, this is a relatively slow operation for modern CPUs,
281 * because it cannot necessarily determine what the destination
282 * address is. In this case, the address is a runtime constant, so at
283 * the very least we can patch the call to e a simple direct call, or
284 * ideally, patch an inline implementation into the callsite. (Direct
285 * calls are essentially free, because the call and return addresses
286 * are completely predictable.)
288 * These macros rely on the standard gcc "regparm(3)" calling
289 * convention, in which the first three arguments are placed in %eax,
290 * %edx, %ecx (in that order), and the remaining arguments are placed
291 * on the stack. All caller-save registers (eax,edx,ecx) are expected
292 * to be modified (either clobbered or used for return values).
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 paravirt_ops
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
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.
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
317 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
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.
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.
328 #define PVOP_CALL0(__rettype, __op) \
331 if (sizeof(__rettype) > sizeof(unsigned long)) { \
332 unsigned long long __tmp; \
333 unsigned long __ecx; \
334 asm volatile(paravirt_alt(PARAVIRT_CALL) \
335 : "=A" (__tmp), "=c" (__ecx) \
336 : paravirt_type(__op), \
337 paravirt_clobber(CLBR_ANY) \
339 __ret = (__rettype)__tmp; \
341 unsigned long __tmp, __edx, __ecx; \
342 asm volatile(paravirt_alt(PARAVIRT_CALL) \
343 : "=a" (__tmp), "=d" (__edx), \
345 : paravirt_type(__op), \
346 paravirt_clobber(CLBR_ANY) \
348 __ret = (__rettype)__tmp; \
352 #define PVOP_VCALL0(__op) \
354 unsigned long __eax, __edx, __ecx; \
355 asm volatile(paravirt_alt(PARAVIRT_CALL) \
356 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
357 : paravirt_type(__op), \
358 paravirt_clobber(CLBR_ANY) \
362 #define PVOP_CALL1(__rettype, __op, arg1) \
365 if (sizeof(__rettype) > sizeof(unsigned long)) { \
366 unsigned long long __tmp; \
367 unsigned long __ecx; \
368 asm volatile(paravirt_alt(PARAVIRT_CALL) \
369 : "=A" (__tmp), "=c" (__ecx) \
370 : "a" ((u32)(arg1)), \
371 paravirt_type(__op), \
372 paravirt_clobber(CLBR_ANY) \
374 __ret = (__rettype)__tmp; \
376 unsigned long __tmp, __edx, __ecx; \
377 asm volatile(paravirt_alt(PARAVIRT_CALL) \
378 : "=a" (__tmp), "=d" (__edx), \
380 : "0" ((u32)(arg1)), \
381 paravirt_type(__op), \
382 paravirt_clobber(CLBR_ANY) \
384 __ret = (__rettype)__tmp; \
388 #define PVOP_VCALL1(__op, arg1) \
390 unsigned long __eax, __edx, __ecx; \
391 asm volatile(paravirt_alt(PARAVIRT_CALL) \
392 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
393 : "0" ((u32)(arg1)), \
394 paravirt_type(__op), \
395 paravirt_clobber(CLBR_ANY) \
399 #define PVOP_CALL2(__rettype, __op, arg1, arg2) \
402 if (sizeof(__rettype) > sizeof(unsigned long)) { \
403 unsigned long long __tmp; \
404 unsigned long __ecx; \
405 asm volatile(paravirt_alt(PARAVIRT_CALL) \
406 : "=A" (__tmp), "=c" (__ecx) \
407 : "a" ((u32)(arg1)), \
409 paravirt_type(__op), \
410 paravirt_clobber(CLBR_ANY) \
412 __ret = (__rettype)__tmp; \
414 unsigned long __tmp, __edx, __ecx; \
415 asm volatile(paravirt_alt(PARAVIRT_CALL) \
416 : "=a" (__tmp), "=d" (__edx), \
418 : "0" ((u32)(arg1)), \
420 paravirt_type(__op), \
421 paravirt_clobber(CLBR_ANY) \
423 __ret = (__rettype)__tmp; \
427 #define PVOP_VCALL2(__op, arg1, arg2) \
429 unsigned long __eax, __edx, __ecx; \
430 asm volatile(paravirt_alt(PARAVIRT_CALL) \
431 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
432 : "0" ((u32)(arg1)), \
434 paravirt_type(__op), \
435 paravirt_clobber(CLBR_ANY) \
439 #define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \
442 if (sizeof(__rettype) > sizeof(unsigned long)) { \
443 unsigned long long __tmp; \
444 unsigned long __ecx; \
445 asm volatile(paravirt_alt(PARAVIRT_CALL) \
446 : "=A" (__tmp), "=c" (__ecx) \
447 : "a" ((u32)(arg1)), \
450 paravirt_type(__op), \
451 paravirt_clobber(CLBR_ANY) \
453 __ret = (__rettype)__tmp; \
455 unsigned long __tmp, __edx, __ecx; \
456 asm volatile(paravirt_alt(PARAVIRT_CALL) \
457 : "=a" (__tmp), "=d" (__edx), \
459 : "0" ((u32)(arg1)), \
462 paravirt_type(__op), \
463 paravirt_clobber(CLBR_ANY) \
465 __ret = (__rettype)__tmp; \
469 #define PVOP_VCALL3(__op, arg1, arg2, arg3) \
471 unsigned long __eax, __edx, __ecx; \
472 asm volatile(paravirt_alt(PARAVIRT_CALL) \
473 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
474 : "0" ((u32)(arg1)), \
477 paravirt_type(__op), \
478 paravirt_clobber(CLBR_ANY) \
482 #define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \
485 if (sizeof(__rettype) > sizeof(unsigned long)) { \
486 unsigned long long __tmp; \
487 unsigned long __ecx; \
488 asm volatile("push %[_arg4]; " \
489 paravirt_alt(PARAVIRT_CALL) \
490 "lea 4(%%esp),%%esp" \
491 : "=A" (__tmp), "=c" (__ecx) \
492 : "a" ((u32)(arg1)), \
495 [_arg4] "mr" ((u32)(arg4)), \
496 paravirt_type(__op), \
497 paravirt_clobber(CLBR_ANY) \
498 : "memory", "cc",); \
499 __ret = (__rettype)__tmp; \
501 unsigned long __tmp, __edx, __ecx; \
502 asm volatile("push %[_arg4]; " \
503 paravirt_alt(PARAVIRT_CALL) \
504 "lea 4(%%esp),%%esp" \
505 : "=a" (__tmp), "=d" (__edx), "=c" (__ecx) \
506 : "0" ((u32)(arg1)), \
509 [_arg4]"mr" ((u32)(arg4)), \
510 paravirt_type(__op), \
511 paravirt_clobber(CLBR_ANY) \
513 __ret = (__rettype)__tmp; \
517 #define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \
519 unsigned long __eax, __edx, __ecx; \
520 asm volatile("push %[_arg4]; " \
521 paravirt_alt(PARAVIRT_CALL) \
522 "lea 4(%%esp),%%esp" \
523 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
524 : "0" ((u32)(arg1)), \
527 [_arg4]"mr" ((u32)(arg4)), \
528 paravirt_type(__op), \
529 paravirt_clobber(CLBR_ANY) \
533 static inline int paravirt_enabled(void)
535 return paravirt_ops.paravirt_enabled;
538 static inline void load_esp0(struct tss_struct *tss,
539 struct thread_struct *thread)
541 PVOP_VCALL2(load_esp0, tss, thread);
544 #define ARCH_SETUP paravirt_ops.arch_setup();
545 static inline unsigned long get_wallclock(void)
547 return PVOP_CALL0(unsigned long, get_wallclock);
550 static inline int set_wallclock(unsigned long nowtime)
552 return PVOP_CALL1(int, set_wallclock, nowtime);
555 static inline void (*choose_time_init(void))(void)
557 return paravirt_ops.time_init;
560 /* The paravirtualized CPUID instruction. */
561 static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
562 unsigned int *ecx, unsigned int *edx)
564 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
568 * These special macros can be used to get or set a debugging register
570 static inline unsigned long paravirt_get_debugreg(int reg)
572 return PVOP_CALL1(unsigned long, get_debugreg, reg);
574 #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
575 static inline void set_debugreg(unsigned long val, int reg)
577 PVOP_VCALL2(set_debugreg, reg, val);
580 static inline void clts(void)
585 static inline unsigned long read_cr0(void)
587 return PVOP_CALL0(unsigned long, read_cr0);
590 static inline void write_cr0(unsigned long x)
592 PVOP_VCALL1(write_cr0, x);
595 static inline unsigned long read_cr2(void)
597 return PVOP_CALL0(unsigned long, read_cr2);
600 static inline void write_cr2(unsigned long x)
602 PVOP_VCALL1(write_cr2, x);
605 static inline unsigned long read_cr3(void)
607 return PVOP_CALL0(unsigned long, read_cr3);
610 static inline void write_cr3(unsigned long x)
612 PVOP_VCALL1(write_cr3, x);
615 static inline unsigned long read_cr4(void)
617 return PVOP_CALL0(unsigned long, read_cr4);
619 static inline unsigned long read_cr4_safe(void)
621 return PVOP_CALL0(unsigned long, read_cr4_safe);
624 static inline void write_cr4(unsigned long x)
626 PVOP_VCALL1(write_cr4, x);
629 static inline void raw_safe_halt(void)
631 PVOP_VCALL0(safe_halt);
634 static inline void halt(void)
636 PVOP_VCALL0(safe_halt);
639 static inline void wbinvd(void)
644 #define get_kernel_rpl() (paravirt_ops.kernel_rpl)
646 static inline u64 paravirt_read_msr(unsigned msr, int *err)
648 return PVOP_CALL2(u64, read_msr, msr, err);
650 static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
652 return PVOP_CALL3(int, write_msr, msr, low, high);
655 /* These should all do BUG_ON(_err), but our headers are too tangled. */
656 #define rdmsr(msr,val1,val2) do { \
658 u64 _l = paravirt_read_msr(msr, &_err); \
663 #define wrmsr(msr,val1,val2) do { \
664 paravirt_write_msr(msr, val1, val2); \
667 #define rdmsrl(msr,val) do { \
669 val = paravirt_read_msr(msr, &_err); \
672 #define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
673 #define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
675 /* rdmsr with exception handling */
676 #define rdmsr_safe(msr,a,b) ({ \
678 u64 _l = paravirt_read_msr(msr, &_err); \
684 static inline u64 paravirt_read_tsc(void)
686 return PVOP_CALL0(u64, read_tsc);
688 #define rdtsc(low,high) do { \
689 u64 _l = paravirt_read_tsc(); \
694 #define rdtscl(low) do { \
695 u64 _l = paravirt_read_tsc(); \
699 #define rdtscll(val) (val = paravirt_read_tsc())
701 #define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
702 #define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
704 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
706 static inline unsigned long long paravirt_read_pmc(int counter)
708 return PVOP_CALL1(u64, read_pmc, counter);
711 #define rdpmc(counter,low,high) do { \
712 u64 _l = paravirt_read_pmc(counter); \
717 static inline void load_TR_desc(void)
719 PVOP_VCALL0(load_tr_desc);
721 static inline void load_gdt(const struct Xgt_desc_struct *dtr)
723 PVOP_VCALL1(load_gdt, dtr);
725 static inline void load_idt(const struct Xgt_desc_struct *dtr)
727 PVOP_VCALL1(load_idt, dtr);
729 static inline void set_ldt(const void *addr, unsigned entries)
731 PVOP_VCALL2(set_ldt, addr, entries);
733 static inline void store_gdt(struct Xgt_desc_struct *dtr)
735 PVOP_VCALL1(store_gdt, dtr);
737 static inline void store_idt(struct Xgt_desc_struct *dtr)
739 PVOP_VCALL1(store_idt, dtr);
741 static inline unsigned long paravirt_store_tr(void)
743 return PVOP_CALL0(unsigned long, store_tr);
745 #define store_tr(tr) ((tr) = paravirt_store_tr())
746 static inline void load_TLS(struct thread_struct *t, unsigned cpu)
748 PVOP_VCALL2(load_tls, t, cpu);
750 static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
752 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
754 static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
756 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
758 static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
760 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
762 static inline void set_iopl_mask(unsigned mask)
764 PVOP_VCALL1(set_iopl_mask, mask);
767 /* The paravirtualized I/O functions */
768 static inline void slow_down_io(void) {
769 paravirt_ops.io_delay();
770 #ifdef REALLY_SLOW_IO
771 paravirt_ops.io_delay();
772 paravirt_ops.io_delay();
773 paravirt_ops.io_delay();
777 #ifdef CONFIG_X86_LOCAL_APIC
779 * Basic functions accessing APICs.
781 static inline void apic_write(unsigned long reg, unsigned long v)
783 PVOP_VCALL2(apic_write, reg, v);
786 static inline void apic_write_atomic(unsigned long reg, unsigned long v)
788 PVOP_VCALL2(apic_write_atomic, reg, v);
791 static inline unsigned long apic_read(unsigned long reg)
793 return PVOP_CALL1(unsigned long, apic_read, reg);
796 static inline void setup_boot_clock(void)
798 PVOP_VCALL0(setup_boot_clock);
801 static inline void setup_secondary_clock(void)
803 PVOP_VCALL0(setup_secondary_clock);
807 static inline void paravirt_pagetable_setup_start(pgd_t *base)
809 if (paravirt_ops.pagetable_setup_start)
810 (*paravirt_ops.pagetable_setup_start)(base);
813 static inline void paravirt_pagetable_setup_done(pgd_t *base)
815 if (paravirt_ops.pagetable_setup_done)
816 (*paravirt_ops.pagetable_setup_done)(base);
820 static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
821 unsigned long start_esp)
823 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
827 static inline void paravirt_activate_mm(struct mm_struct *prev,
828 struct mm_struct *next)
830 PVOP_VCALL2(activate_mm, prev, next);
833 static inline void arch_dup_mmap(struct mm_struct *oldmm,
834 struct mm_struct *mm)
836 PVOP_VCALL2(dup_mmap, oldmm, mm);
839 static inline void arch_exit_mmap(struct mm_struct *mm)
841 PVOP_VCALL1(exit_mmap, mm);
844 static inline void __flush_tlb(void)
846 PVOP_VCALL0(flush_tlb_user);
848 static inline void __flush_tlb_global(void)
850 PVOP_VCALL0(flush_tlb_kernel);
852 static inline void __flush_tlb_single(unsigned long addr)
854 PVOP_VCALL1(flush_tlb_single, addr);
857 static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
860 PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va);
863 static inline void paravirt_alloc_pt(unsigned pfn)
865 PVOP_VCALL1(alloc_pt, pfn);
867 static inline void paravirt_release_pt(unsigned pfn)
869 PVOP_VCALL1(release_pt, pfn);
872 static inline void paravirt_alloc_pd(unsigned pfn)
874 PVOP_VCALL1(alloc_pd, pfn);
877 static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
878 unsigned start, unsigned count)
880 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
882 static inline void paravirt_release_pd(unsigned pfn)
884 PVOP_VCALL1(release_pd, pfn);
887 static inline void pte_update(struct mm_struct *mm, unsigned long addr,
890 PVOP_VCALL3(pte_update, mm, addr, ptep);
893 static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
896 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
899 #ifdef CONFIG_X86_PAE
900 static inline pte_t __pte(unsigned long long val)
902 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
904 return (pte_t) { ret, ret >> 32 };
907 static inline pmd_t __pmd(unsigned long long val)
909 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
912 static inline pgd_t __pgd(unsigned long long val)
914 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
917 static inline unsigned long long pte_val(pte_t x)
919 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
922 static inline unsigned long long pmd_val(pmd_t x)
924 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
927 static inline unsigned long long pgd_val(pgd_t x)
929 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
932 static inline void set_pte(pte_t *ptep, pte_t pteval)
934 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
937 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
938 pte_t *ptep, pte_t pteval)
941 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
944 static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
946 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
949 static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
950 pte_t *ptep, pte_t pte)
953 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
956 static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
958 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
961 static inline void set_pud(pud_t *pudp, pud_t pudval)
963 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
966 static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
968 PVOP_VCALL3(pte_clear, mm, addr, ptep);
971 static inline void pmd_clear(pmd_t *pmdp)
973 PVOP_VCALL1(pmd_clear, pmdp);
976 static inline pte_t raw_ptep_get_and_clear(pte_t *p)
978 unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
979 return (pte_t) { val, val >> 32 };
981 #else /* !CONFIG_X86_PAE */
982 static inline pte_t __pte(unsigned long val)
984 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
987 static inline pgd_t __pgd(unsigned long val)
989 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
992 static inline unsigned long pte_val(pte_t x)
994 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
997 static inline unsigned long pgd_val(pgd_t x)
999 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
1002 static inline void set_pte(pte_t *ptep, pte_t pteval)
1004 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
1007 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1008 pte_t *ptep, pte_t pteval)
1010 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
1013 static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
1015 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
1018 static inline pte_t raw_ptep_get_and_clear(pte_t *p)
1020 return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
1022 #endif /* CONFIG_X86_PAE */
1024 /* Lazy mode for batching updates / context switch */
1025 #define PARAVIRT_LAZY_NONE 0
1026 #define PARAVIRT_LAZY_MMU 1
1027 #define PARAVIRT_LAZY_CPU 2
1028 #define PARAVIRT_LAZY_FLUSH 3
1030 #define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
1031 static inline void arch_enter_lazy_cpu_mode(void)
1033 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
1036 static inline void arch_leave_lazy_cpu_mode(void)
1038 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1041 static inline void arch_flush_lazy_cpu_mode(void)
1043 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1047 #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
1048 static inline void arch_enter_lazy_mmu_mode(void)
1050 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
1053 static inline void arch_leave_lazy_mmu_mode(void)
1055 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1058 static inline void arch_flush_lazy_mmu_mode(void)
1060 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1063 void _paravirt_nop(void);
1064 #define paravirt_nop ((void *)_paravirt_nop)
1066 /* These all sit in the .parainstructions section to tell us what to patch. */
1067 struct paravirt_patch_site {
1068 u8 *instr; /* original instructions */
1069 u8 instrtype; /* type of this instruction */
1070 u8 len; /* length of original instruction */
1071 u16 clobbers; /* what registers you may clobber */
1074 extern struct paravirt_patch_site __parainstructions[],
1075 __parainstructions_end[];
1077 static inline unsigned long __raw_local_save_flags(void)
1081 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1083 "popl %%edx; popl %%ecx")
1085 : paravirt_type(save_fl),
1086 paravirt_clobber(CLBR_EAX)
1091 static inline void raw_local_irq_restore(unsigned long f)
1093 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1095 "popl %%edx; popl %%ecx")
1098 paravirt_type(restore_fl),
1099 paravirt_clobber(CLBR_EAX)
1103 static inline void raw_local_irq_disable(void)
1105 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1107 "popl %%edx; popl %%ecx")
1109 : paravirt_type(irq_disable),
1110 paravirt_clobber(CLBR_EAX)
1111 : "memory", "eax", "cc");
1114 static inline void raw_local_irq_enable(void)
1116 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1118 "popl %%edx; popl %%ecx")
1120 : paravirt_type(irq_enable),
1121 paravirt_clobber(CLBR_EAX)
1122 : "memory", "eax", "cc");
1125 static inline unsigned long __raw_local_irq_save(void)
1129 f = __raw_local_save_flags();
1130 raw_local_irq_disable();
1134 #define CLI_STRING \
1135 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1136 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1137 "popl %%edx; popl %%ecx", \
1138 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
1140 #define STI_STRING \
1141 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1142 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1143 "popl %%edx; popl %%ecx", \
1144 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1146 #define CLI_STI_CLOBBERS , "%eax"
1147 #define CLI_STI_INPUT_ARGS \
1149 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1150 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1151 paravirt_clobber(CLBR_EAX)
1153 /* Make sure as little as possible of this mess escapes. */
1154 #undef PARAVIRT_CALL
1166 #else /* __ASSEMBLY__ */
1168 #define PARA_PATCH(off) ((off) / 4)
1170 #define PARA_SITE(ptype, clobbers, ops) \
1174 .pushsection .parainstructions,"a"; \
1181 #define INTERRUPT_RETURN \
1182 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
1183 jmp *%cs:paravirt_ops+PARAVIRT_iret)
1185 #define DISABLE_INTERRUPTS(clobbers) \
1186 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
1187 pushl %eax; pushl %ecx; pushl %edx; \
1188 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
1189 popl %edx; popl %ecx; popl %eax) \
1191 #define ENABLE_INTERRUPTS(clobbers) \
1192 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
1193 pushl %eax; pushl %ecx; pushl %edx; \
1194 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
1195 popl %edx; popl %ecx; popl %eax)
1197 #define ENABLE_INTERRUPTS_SYSEXIT \
1198 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
1199 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
1201 #define GET_CR0_INTO_EAX \
1202 push %ecx; push %edx; \
1203 call *paravirt_ops+PARAVIRT_read_cr0; \
1206 #endif /* __ASSEMBLY__ */
1207 #endif /* CONFIG_PARAVIRT */
1208 #endif /* __ASM_PARAVIRT_H */