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 void (*map_pt_hook)(int type, pte_t *va, u32 pfn);
174 /* Hooks for allocating/releasing pagetable pages */
175 void (*alloc_pt)(u32 pfn);
176 void (*alloc_pd)(u32 pfn);
177 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
178 void (*release_pt)(u32 pfn);
179 void (*release_pd)(u32 pfn);
181 /* Pagetable manipulation functions */
182 void (*set_pte)(pte_t *ptep, pte_t pteval);
183 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
184 pte_t *ptep, pte_t pteval);
185 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
186 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
187 void (*pte_update_defer)(struct mm_struct *mm,
188 unsigned long addr, pte_t *ptep);
190 pte_t (*ptep_get_and_clear)(pte_t *ptep);
192 #ifdef CONFIG_X86_PAE
193 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
194 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
195 void (*set_pud)(pud_t *pudp, pud_t pudval);
196 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
197 void (*pmd_clear)(pmd_t *pmdp);
199 unsigned long long (*pte_val)(pte_t);
200 unsigned long long (*pmd_val)(pmd_t);
201 unsigned long long (*pgd_val)(pgd_t);
203 pte_t (*make_pte)(unsigned long long pte);
204 pmd_t (*make_pmd)(unsigned long long pmd);
205 pgd_t (*make_pgd)(unsigned long long pgd);
207 unsigned long (*pte_val)(pte_t);
208 unsigned long (*pgd_val)(pgd_t);
210 pte_t (*make_pte)(unsigned long pte);
211 pgd_t (*make_pgd)(unsigned long pgd);
214 /* Set deferred update mode, used for batching operations. */
215 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
217 /* These two are jmp to, not actually called. */
218 void (*irq_enable_sysexit)(void);
222 /* Mark a paravirt probe function. */
223 #define paravirt_probe(fn) \
224 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
225 __attribute__((__section__(".paravirtprobe"))) = fn
227 extern struct paravirt_ops paravirt_ops;
229 #define PARAVIRT_PATCH(x) \
230 (offsetof(struct paravirt_ops, x) / sizeof(void *))
232 #define paravirt_type(type) \
233 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
234 #define paravirt_clobber(clobber) \
235 [paravirt_clobber] "i" (clobber)
238 * Generate some code, and mark it as patchable by the
239 * apply_paravirt() alternate instruction patcher.
241 #define _paravirt_alt(insn_string, type, clobber) \
242 "771:\n\t" insn_string "\n" "772:\n" \
243 ".pushsection .parainstructions,\"a\"\n" \
245 " .byte " type "\n" \
246 " .byte 772b-771b\n" \
247 " .short " clobber "\n" \
250 /* Generate patchable code, with the default asm parameters. */
251 #define paravirt_alt(insn_string) \
252 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
254 unsigned paravirt_patch_nop(void);
255 unsigned paravirt_patch_ignore(unsigned len);
256 unsigned paravirt_patch_call(void *target, u16 tgt_clobbers,
257 void *site, u16 site_clobbers,
259 unsigned paravirt_patch_jmp(void *target, void *site, unsigned len);
260 unsigned paravirt_patch_default(u8 type, u16 clobbers, void *site, unsigned len);
262 unsigned paravirt_patch_insns(void *site, unsigned len,
263 const char *start, const char *end);
267 * This generates an indirect call based on the operation type number.
268 * The type number, computed in PARAVIRT_PATCH, is derived from the
269 * offset into the paravirt_ops structure, and can therefore be freely
270 * converted back into a structure offset.
272 #define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
275 * These macros are intended to wrap calls into a paravirt_ops
276 * operation, so that they can be later identified and patched at
279 * Normally, a call to a pv_op function is a simple indirect call:
280 * (paravirt_ops.operations)(args...).
282 * Unfortunately, this is a relatively slow operation for modern CPUs,
283 * because it cannot necessarily determine what the destination
284 * address is. In this case, the address is a runtime constant, so at
285 * the very least we can patch the call to e a simple direct call, or
286 * ideally, patch an inline implementation into the callsite. (Direct
287 * calls are essentially free, because the call and return addresses
288 * are completely predictable.)
290 * These macros rely on the standard gcc "regparm(3)" calling
291 * convention, in which the first three arguments are placed in %eax,
292 * %edx, %ecx (in that order), and the remaining arguments are placed
293 * on the stack. All caller-save registers (eax,edx,ecx) are expected
294 * to be modified (either clobbered or used for return values).
296 * The call instruction itself is marked by placing its start address
297 * and size into the .parainstructions section, so that
298 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
299 * appropriate patching under the control of the backend paravirt_ops
302 * Unfortunately there's no way to get gcc to generate the args setup
303 * for the call, and then allow the call itself to be generated by an
304 * inline asm. Because of this, we must do the complete arg setup and
305 * return value handling from within these macros. This is fairly
308 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
309 * It could be extended to more arguments, but there would be little
310 * to be gained from that. For each number of arguments, there are
311 * the two VCALL and CALL variants for void and non-void functions.
313 * When there is a return value, the invoker of the macro must specify
314 * the return type. The macro then uses sizeof() on that type to
315 * determine whether its a 32 or 64 bit value, and places the return
316 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
319 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
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.
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.
330 #define PVOP_CALL0(__rettype, __op) \
333 if (sizeof(__rettype) > sizeof(unsigned long)) { \
334 unsigned long long __tmp; \
335 unsigned long __ecx; \
336 asm volatile(paravirt_alt(PARAVIRT_CALL) \
337 : "=A" (__tmp), "=c" (__ecx) \
338 : paravirt_type(__op), \
339 paravirt_clobber(CLBR_ANY) \
341 __ret = (__rettype)__tmp; \
343 unsigned long __tmp, __edx, __ecx; \
344 asm volatile(paravirt_alt(PARAVIRT_CALL) \
345 : "=a" (__tmp), "=d" (__edx), \
347 : paravirt_type(__op), \
348 paravirt_clobber(CLBR_ANY) \
350 __ret = (__rettype)__tmp; \
354 #define PVOP_VCALL0(__op) \
356 unsigned long __eax, __edx, __ecx; \
357 asm volatile(paravirt_alt(PARAVIRT_CALL) \
358 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
359 : paravirt_type(__op), \
360 paravirt_clobber(CLBR_ANY) \
364 #define PVOP_CALL1(__rettype, __op, arg1) \
367 if (sizeof(__rettype) > sizeof(unsigned long)) { \
368 unsigned long long __tmp; \
369 unsigned long __ecx; \
370 asm volatile(paravirt_alt(PARAVIRT_CALL) \
371 : "=A" (__tmp), "=c" (__ecx) \
372 : "a" ((u32)(arg1)), \
373 paravirt_type(__op), \
374 paravirt_clobber(CLBR_ANY) \
376 __ret = (__rettype)__tmp; \
378 unsigned long __tmp, __edx, __ecx; \
379 asm volatile(paravirt_alt(PARAVIRT_CALL) \
380 : "=a" (__tmp), "=d" (__edx), \
382 : "0" ((u32)(arg1)), \
383 paravirt_type(__op), \
384 paravirt_clobber(CLBR_ANY) \
386 __ret = (__rettype)__tmp; \
390 #define PVOP_VCALL1(__op, arg1) \
392 unsigned long __eax, __edx, __ecx; \
393 asm volatile(paravirt_alt(PARAVIRT_CALL) \
394 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
395 : "0" ((u32)(arg1)), \
396 paravirt_type(__op), \
397 paravirt_clobber(CLBR_ANY) \
401 #define PVOP_CALL2(__rettype, __op, arg1, arg2) \
404 if (sizeof(__rettype) > sizeof(unsigned long)) { \
405 unsigned long long __tmp; \
406 unsigned long __ecx; \
407 asm volatile(paravirt_alt(PARAVIRT_CALL) \
408 : "=A" (__tmp), "=c" (__ecx) \
409 : "a" ((u32)(arg1)), \
411 paravirt_type(__op), \
412 paravirt_clobber(CLBR_ANY) \
414 __ret = (__rettype)__tmp; \
416 unsigned long __tmp, __edx, __ecx; \
417 asm volatile(paravirt_alt(PARAVIRT_CALL) \
418 : "=a" (__tmp), "=d" (__edx), \
420 : "0" ((u32)(arg1)), \
422 paravirt_type(__op), \
423 paravirt_clobber(CLBR_ANY) \
425 __ret = (__rettype)__tmp; \
429 #define PVOP_VCALL2(__op, arg1, arg2) \
431 unsigned long __eax, __edx, __ecx; \
432 asm volatile(paravirt_alt(PARAVIRT_CALL) \
433 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
434 : "0" ((u32)(arg1)), \
436 paravirt_type(__op), \
437 paravirt_clobber(CLBR_ANY) \
441 #define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \
444 if (sizeof(__rettype) > sizeof(unsigned long)) { \
445 unsigned long long __tmp; \
446 unsigned long __ecx; \
447 asm volatile(paravirt_alt(PARAVIRT_CALL) \
448 : "=A" (__tmp), "=c" (__ecx) \
449 : "a" ((u32)(arg1)), \
452 paravirt_type(__op), \
453 paravirt_clobber(CLBR_ANY) \
455 __ret = (__rettype)__tmp; \
457 unsigned long __tmp, __edx, __ecx; \
458 asm volatile(paravirt_alt(PARAVIRT_CALL) \
459 : "=a" (__tmp), "=d" (__edx), \
461 : "0" ((u32)(arg1)), \
464 paravirt_type(__op), \
465 paravirt_clobber(CLBR_ANY) \
467 __ret = (__rettype)__tmp; \
471 #define PVOP_VCALL3(__op, arg1, arg2, arg3) \
473 unsigned long __eax, __edx, __ecx; \
474 asm volatile(paravirt_alt(PARAVIRT_CALL) \
475 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
476 : "0" ((u32)(arg1)), \
479 paravirt_type(__op), \
480 paravirt_clobber(CLBR_ANY) \
484 #define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \
487 if (sizeof(__rettype) > sizeof(unsigned long)) { \
488 unsigned long long __tmp; \
489 unsigned long __ecx; \
490 asm volatile("push %[_arg4]; " \
491 paravirt_alt(PARAVIRT_CALL) \
492 "lea 4(%%esp),%%esp" \
493 : "=A" (__tmp), "=c" (__ecx) \
494 : "a" ((u32)(arg1)), \
497 [_arg4] "mr" ((u32)(arg4)), \
498 paravirt_type(__op), \
499 paravirt_clobber(CLBR_ANY) \
500 : "memory", "cc",); \
501 __ret = (__rettype)__tmp; \
503 unsigned long __tmp, __edx, __ecx; \
504 asm volatile("push %[_arg4]; " \
505 paravirt_alt(PARAVIRT_CALL) \
506 "lea 4(%%esp),%%esp" \
507 : "=a" (__tmp), "=d" (__edx), "=c" (__ecx) \
508 : "0" ((u32)(arg1)), \
511 [_arg4]"mr" ((u32)(arg4)), \
512 paravirt_type(__op), \
513 paravirt_clobber(CLBR_ANY) \
515 __ret = (__rettype)__tmp; \
519 #define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \
521 unsigned long __eax, __edx, __ecx; \
522 asm volatile("push %[_arg4]; " \
523 paravirt_alt(PARAVIRT_CALL) \
524 "lea 4(%%esp),%%esp" \
525 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
526 : "0" ((u32)(arg1)), \
529 [_arg4]"mr" ((u32)(arg4)), \
530 paravirt_type(__op), \
531 paravirt_clobber(CLBR_ANY) \
535 static inline int paravirt_enabled(void)
537 return paravirt_ops.paravirt_enabled;
540 static inline void load_esp0(struct tss_struct *tss,
541 struct thread_struct *thread)
543 PVOP_VCALL2(load_esp0, tss, thread);
546 #define ARCH_SETUP paravirt_ops.arch_setup();
547 static inline unsigned long get_wallclock(void)
549 return PVOP_CALL0(unsigned long, get_wallclock);
552 static inline int set_wallclock(unsigned long nowtime)
554 return PVOP_CALL1(int, set_wallclock, nowtime);
557 static inline void (*choose_time_init(void))(void)
559 return paravirt_ops.time_init;
562 /* The paravirtualized CPUID instruction. */
563 static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
564 unsigned int *ecx, unsigned int *edx)
566 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
570 * These special macros can be used to get or set a debugging register
572 static inline unsigned long paravirt_get_debugreg(int reg)
574 return PVOP_CALL1(unsigned long, get_debugreg, reg);
576 #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
577 static inline void set_debugreg(unsigned long val, int reg)
579 PVOP_VCALL2(set_debugreg, reg, val);
582 static inline void clts(void)
587 static inline unsigned long read_cr0(void)
589 return PVOP_CALL0(unsigned long, read_cr0);
592 static inline void write_cr0(unsigned long x)
594 PVOP_VCALL1(write_cr0, x);
597 static inline unsigned long read_cr2(void)
599 return PVOP_CALL0(unsigned long, read_cr2);
602 static inline void write_cr2(unsigned long x)
604 PVOP_VCALL1(write_cr2, x);
607 static inline unsigned long read_cr3(void)
609 return PVOP_CALL0(unsigned long, read_cr3);
612 static inline void write_cr3(unsigned long x)
614 PVOP_VCALL1(write_cr3, x);
617 static inline unsigned long read_cr4(void)
619 return PVOP_CALL0(unsigned long, read_cr4);
621 static inline unsigned long read_cr4_safe(void)
623 return PVOP_CALL0(unsigned long, read_cr4_safe);
626 static inline void write_cr4(unsigned long x)
628 PVOP_VCALL1(write_cr4, x);
631 static inline void raw_safe_halt(void)
633 PVOP_VCALL0(safe_halt);
636 static inline void halt(void)
638 PVOP_VCALL0(safe_halt);
641 static inline void wbinvd(void)
646 #define get_kernel_rpl() (paravirt_ops.kernel_rpl)
648 static inline u64 paravirt_read_msr(unsigned msr, int *err)
650 return PVOP_CALL2(u64, read_msr, msr, err);
652 static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
654 return PVOP_CALL3(int, write_msr, msr, low, high);
657 /* These should all do BUG_ON(_err), but our headers are too tangled. */
658 #define rdmsr(msr,val1,val2) do { \
660 u64 _l = paravirt_read_msr(msr, &_err); \
665 #define wrmsr(msr,val1,val2) do { \
666 paravirt_write_msr(msr, val1, val2); \
669 #define rdmsrl(msr,val) do { \
671 val = paravirt_read_msr(msr, &_err); \
674 #define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
675 #define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
677 /* rdmsr with exception handling */
678 #define rdmsr_safe(msr,a,b) ({ \
680 u64 _l = paravirt_read_msr(msr, &_err); \
686 static inline u64 paravirt_read_tsc(void)
688 return PVOP_CALL0(u64, read_tsc);
690 #define rdtsc(low,high) do { \
691 u64 _l = paravirt_read_tsc(); \
696 #define rdtscl(low) do { \
697 u64 _l = paravirt_read_tsc(); \
701 #define rdtscll(val) (val = paravirt_read_tsc())
703 #define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
704 #define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
706 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
708 static inline unsigned long long paravirt_read_pmc(int counter)
710 return PVOP_CALL1(u64, read_pmc, counter);
713 #define rdpmc(counter,low,high) do { \
714 u64 _l = paravirt_read_pmc(counter); \
719 static inline void load_TR_desc(void)
721 PVOP_VCALL0(load_tr_desc);
723 static inline void load_gdt(const struct Xgt_desc_struct *dtr)
725 PVOP_VCALL1(load_gdt, dtr);
727 static inline void load_idt(const struct Xgt_desc_struct *dtr)
729 PVOP_VCALL1(load_idt, dtr);
731 static inline void set_ldt(const void *addr, unsigned entries)
733 PVOP_VCALL2(set_ldt, addr, entries);
735 static inline void store_gdt(struct Xgt_desc_struct *dtr)
737 PVOP_VCALL1(store_gdt, dtr);
739 static inline void store_idt(struct Xgt_desc_struct *dtr)
741 PVOP_VCALL1(store_idt, dtr);
743 static inline unsigned long paravirt_store_tr(void)
745 return PVOP_CALL0(unsigned long, store_tr);
747 #define store_tr(tr) ((tr) = paravirt_store_tr())
748 static inline void load_TLS(struct thread_struct *t, unsigned cpu)
750 PVOP_VCALL2(load_tls, t, cpu);
752 static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
754 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
756 static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
758 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
760 static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
762 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
764 static inline void set_iopl_mask(unsigned mask)
766 PVOP_VCALL1(set_iopl_mask, mask);
769 /* The paravirtualized I/O functions */
770 static inline void slow_down_io(void) {
771 paravirt_ops.io_delay();
772 #ifdef REALLY_SLOW_IO
773 paravirt_ops.io_delay();
774 paravirt_ops.io_delay();
775 paravirt_ops.io_delay();
779 #ifdef CONFIG_X86_LOCAL_APIC
781 * Basic functions accessing APICs.
783 static inline void apic_write(unsigned long reg, unsigned long v)
785 PVOP_VCALL2(apic_write, reg, v);
788 static inline void apic_write_atomic(unsigned long reg, unsigned long v)
790 PVOP_VCALL2(apic_write_atomic, reg, v);
793 static inline unsigned long apic_read(unsigned long reg)
795 return PVOP_CALL1(unsigned long, apic_read, reg);
798 static inline void setup_boot_clock(void)
800 PVOP_VCALL0(setup_boot_clock);
803 static inline void setup_secondary_clock(void)
805 PVOP_VCALL0(setup_secondary_clock);
809 static inline void paravirt_pagetable_setup_start(pgd_t *base)
811 if (paravirt_ops.pagetable_setup_start)
812 (*paravirt_ops.pagetable_setup_start)(base);
815 static inline void paravirt_pagetable_setup_done(pgd_t *base)
817 if (paravirt_ops.pagetable_setup_done)
818 (*paravirt_ops.pagetable_setup_done)(base);
822 static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
823 unsigned long start_esp)
825 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
829 static inline void paravirt_activate_mm(struct mm_struct *prev,
830 struct mm_struct *next)
832 PVOP_VCALL2(activate_mm, prev, next);
835 static inline void arch_dup_mmap(struct mm_struct *oldmm,
836 struct mm_struct *mm)
838 PVOP_VCALL2(dup_mmap, oldmm, mm);
841 static inline void arch_exit_mmap(struct mm_struct *mm)
843 PVOP_VCALL1(exit_mmap, mm);
846 static inline void __flush_tlb(void)
848 PVOP_VCALL0(flush_tlb_user);
850 static inline void __flush_tlb_global(void)
852 PVOP_VCALL0(flush_tlb_kernel);
854 static inline void __flush_tlb_single(unsigned long addr)
856 PVOP_VCALL1(flush_tlb_single, addr);
859 static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
862 PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va);
865 static inline void paravirt_map_pt_hook(int type, pte_t *va, u32 pfn)
867 PVOP_VCALL3(map_pt_hook, type, va, pfn);
870 static inline void paravirt_alloc_pt(unsigned pfn)
872 PVOP_VCALL1(alloc_pt, pfn);
874 static inline void paravirt_release_pt(unsigned pfn)
876 PVOP_VCALL1(release_pt, pfn);
879 static inline void paravirt_alloc_pd(unsigned pfn)
881 PVOP_VCALL1(alloc_pd, pfn);
884 static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
885 unsigned start, unsigned count)
887 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
889 static inline void paravirt_release_pd(unsigned pfn)
891 PVOP_VCALL1(release_pd, pfn);
894 static inline void pte_update(struct mm_struct *mm, unsigned long addr,
897 PVOP_VCALL3(pte_update, mm, addr, ptep);
900 static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
903 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
906 #ifdef CONFIG_X86_PAE
907 static inline pte_t __pte(unsigned long long val)
909 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
911 return (pte_t) { ret, ret >> 32 };
914 static inline pmd_t __pmd(unsigned long long val)
916 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
919 static inline pgd_t __pgd(unsigned long long val)
921 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
924 static inline unsigned long long pte_val(pte_t x)
926 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
929 static inline unsigned long long pmd_val(pmd_t x)
931 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
934 static inline unsigned long long pgd_val(pgd_t x)
936 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
939 static inline void set_pte(pte_t *ptep, pte_t pteval)
941 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
944 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
945 pte_t *ptep, pte_t pteval)
948 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
951 static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
953 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
956 static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
957 pte_t *ptep, pte_t pte)
960 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
963 static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
965 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
968 static inline void set_pud(pud_t *pudp, pud_t pudval)
970 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
973 static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
975 PVOP_VCALL3(pte_clear, mm, addr, ptep);
978 static inline void pmd_clear(pmd_t *pmdp)
980 PVOP_VCALL1(pmd_clear, pmdp);
983 static inline pte_t raw_ptep_get_and_clear(pte_t *p)
985 unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
986 return (pte_t) { val, val >> 32 };
988 #else /* !CONFIG_X86_PAE */
989 static inline pte_t __pte(unsigned long val)
991 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
994 static inline pgd_t __pgd(unsigned long val)
996 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
999 static inline unsigned long pte_val(pte_t x)
1001 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
1004 static inline unsigned long pgd_val(pgd_t x)
1006 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
1009 static inline void set_pte(pte_t *ptep, pte_t pteval)
1011 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
1014 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1015 pte_t *ptep, pte_t pteval)
1017 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
1020 static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
1022 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
1025 static inline pte_t raw_ptep_get_and_clear(pte_t *p)
1027 return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
1029 #endif /* CONFIG_X86_PAE */
1031 /* Lazy mode for batching updates / context switch */
1032 #define PARAVIRT_LAZY_NONE 0
1033 #define PARAVIRT_LAZY_MMU 1
1034 #define PARAVIRT_LAZY_CPU 2
1035 #define PARAVIRT_LAZY_FLUSH 3
1037 #define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
1038 static inline void arch_enter_lazy_cpu_mode(void)
1040 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
1043 static inline void arch_leave_lazy_cpu_mode(void)
1045 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1048 static inline void arch_flush_lazy_cpu_mode(void)
1050 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1054 #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
1055 static inline void arch_enter_lazy_mmu_mode(void)
1057 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
1060 static inline void arch_leave_lazy_mmu_mode(void)
1062 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1065 static inline void arch_flush_lazy_mmu_mode(void)
1067 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1070 void _paravirt_nop(void);
1071 #define paravirt_nop ((void *)_paravirt_nop)
1073 /* These all sit in the .parainstructions section to tell us what to patch. */
1074 struct paravirt_patch_site {
1075 u8 *instr; /* original instructions */
1076 u8 instrtype; /* type of this instruction */
1077 u8 len; /* length of original instruction */
1078 u16 clobbers; /* what registers you may clobber */
1081 extern struct paravirt_patch_site __parainstructions[],
1082 __parainstructions_end[];
1084 static inline unsigned long __raw_local_save_flags(void)
1088 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1090 "popl %%edx; popl %%ecx")
1092 : paravirt_type(save_fl),
1093 paravirt_clobber(CLBR_EAX)
1098 static inline void raw_local_irq_restore(unsigned long f)
1100 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1102 "popl %%edx; popl %%ecx")
1105 paravirt_type(restore_fl),
1106 paravirt_clobber(CLBR_EAX)
1110 static inline void raw_local_irq_disable(void)
1112 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1114 "popl %%edx; popl %%ecx")
1116 : paravirt_type(irq_disable),
1117 paravirt_clobber(CLBR_EAX)
1118 : "memory", "eax", "cc");
1121 static inline void raw_local_irq_enable(void)
1123 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1125 "popl %%edx; popl %%ecx")
1127 : paravirt_type(irq_enable),
1128 paravirt_clobber(CLBR_EAX)
1129 : "memory", "eax", "cc");
1132 static inline unsigned long __raw_local_irq_save(void)
1136 f = __raw_local_save_flags();
1137 raw_local_irq_disable();
1141 #define CLI_STRING \
1142 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1143 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1144 "popl %%edx; popl %%ecx", \
1145 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
1147 #define STI_STRING \
1148 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1149 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1150 "popl %%edx; popl %%ecx", \
1151 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1153 #define CLI_STI_CLOBBERS , "%eax"
1154 #define CLI_STI_INPUT_ARGS \
1156 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1157 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1158 paravirt_clobber(CLBR_EAX)
1160 /* Make sure as little as possible of this mess escapes. */
1161 #undef PARAVIRT_CALL
1173 #else /* __ASSEMBLY__ */
1175 #define PARA_PATCH(off) ((off) / 4)
1177 #define PARA_SITE(ptype, clobbers, ops) \
1181 .pushsection .parainstructions,"a"; \
1188 #define INTERRUPT_RETURN \
1189 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
1190 jmp *%cs:paravirt_ops+PARAVIRT_iret)
1192 #define DISABLE_INTERRUPTS(clobbers) \
1193 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
1194 pushl %eax; pushl %ecx; pushl %edx; \
1195 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
1196 popl %edx; popl %ecx; popl %eax) \
1198 #define ENABLE_INTERRUPTS(clobbers) \
1199 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
1200 pushl %eax; pushl %ecx; pushl %edx; \
1201 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
1202 popl %edx; popl %ecx; popl %eax)
1204 #define ENABLE_INTERRUPTS_SYSEXIT \
1205 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
1206 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
1208 #define GET_CR0_INTO_EAX \
1209 push %ecx; push %edx; \
1210 call *paravirt_ops+PARAVIRT_read_cr0; \
1213 #endif /* __ASSEMBLY__ */
1214 #endif /* CONFIG_PARAVIRT */
1215 #endif /* __ASM_PARAVIRT_H */