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>
19 #include <asm/kmap_types.h>
23 struct Xgt_desc_struct;
28 /* Lazy mode for batching updates / context switch */
29 enum paravirt_lazy_mode {
30 PARAVIRT_LAZY_NONE = 0,
31 PARAVIRT_LAZY_MMU = 1,
32 PARAVIRT_LAZY_CPU = 2,
37 unsigned int kernel_rpl;
38 int shared_kernel_pmd;
43 * Patch may replace one of the defined code sequences with arbitrary
44 * code, subject to the same register constraints. This generally
45 * means the code is not free to clobber any registers other than EAX.
46 * The patch function should return the number of bytes of code
47 * generated, as we nop pad the rest in generic code.
49 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
51 /* Basic arch-specific setup */
52 void (*arch_setup)(void);
53 char *(*memory_setup)(void);
54 void (*init_IRQ)(void);
55 void (*time_init)(void);
58 * Called before/after init_mm pagetable setup. setup_start
59 * may reset %cr3, and may pre-install parts of the pagetable;
60 * pagetable setup is expected to preserve any existing
63 void (*pagetable_setup_start)(pgd_t *pgd_base);
64 void (*pagetable_setup_done)(pgd_t *pgd_base);
66 /* Print a banner to identify the environment */
69 /* Set and set time of day */
70 unsigned long (*get_wallclock)(void);
71 int (*set_wallclock)(unsigned long);
73 /* cpuid emulation, mostly so that caps bits can be disabled */
74 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
75 unsigned int *ecx, unsigned int *edx);
77 /* hooks for various privileged instructions */
78 unsigned long (*get_debugreg)(int regno);
79 void (*set_debugreg)(int regno, unsigned long value);
83 unsigned long (*read_cr0)(void);
84 void (*write_cr0)(unsigned long);
86 unsigned long (*read_cr2)(void);
87 void (*write_cr2)(unsigned long);
89 unsigned long (*read_cr3)(void);
90 void (*write_cr3)(unsigned long);
92 unsigned long (*read_cr4_safe)(void);
93 unsigned long (*read_cr4)(void);
94 void (*write_cr4)(unsigned long);
97 * Get/set interrupt state. save_fl and restore_fl are only
98 * expected to use X86_EFLAGS_IF; all other bits
99 * returned from save_fl are undefined, and may be ignored by
102 unsigned long (*save_fl)(void);
103 void (*restore_fl)(unsigned long);
104 void (*irq_disable)(void);
105 void (*irq_enable)(void);
106 void (*safe_halt)(void);
109 void (*wbinvd)(void);
111 /* MSR, PMC and TSR operations.
112 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
113 u64 (*read_msr)(unsigned int msr, int *err);
114 int (*write_msr)(unsigned int msr, u64 val);
116 u64 (*read_tsc)(void);
117 u64 (*read_pmc)(void);
118 u64 (*get_scheduled_cycles)(void);
119 unsigned long (*get_cpu_khz)(void);
121 /* Segment descriptor handling */
122 void (*load_tr_desc)(void);
123 void (*load_gdt)(const struct Xgt_desc_struct *);
124 void (*load_idt)(const struct Xgt_desc_struct *);
125 void (*store_gdt)(struct Xgt_desc_struct *);
126 void (*store_idt)(struct Xgt_desc_struct *);
127 void (*set_ldt)(const void *desc, unsigned entries);
128 unsigned long (*store_tr)(void);
129 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
130 void (*write_ldt_entry)(struct desc_struct *,
131 int entrynum, u32 low, u32 high);
132 void (*write_gdt_entry)(struct desc_struct *,
133 int entrynum, u32 low, u32 high);
134 void (*write_idt_entry)(struct desc_struct *,
135 int entrynum, u32 low, u32 high);
136 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
138 void (*set_iopl_mask)(unsigned mask);
139 void (*io_delay)(void);
142 * Hooks for intercepting the creation/use/destruction of an
145 void (*activate_mm)(struct mm_struct *prev,
146 struct mm_struct *next);
147 void (*dup_mmap)(struct mm_struct *oldmm,
148 struct mm_struct *mm);
149 void (*exit_mmap)(struct mm_struct *mm);
151 #ifdef CONFIG_X86_LOCAL_APIC
153 * Direct APIC operations, principally for VMI. Ideally
154 * these shouldn't be in this interface.
156 void (*apic_write)(unsigned long reg, unsigned long v);
157 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
158 unsigned long (*apic_read)(unsigned long reg);
159 void (*setup_boot_clock)(void);
160 void (*setup_secondary_clock)(void);
162 void (*startup_ipi_hook)(int phys_apicid,
163 unsigned long start_eip,
164 unsigned long start_esp);
168 void (*flush_tlb_user)(void);
169 void (*flush_tlb_kernel)(void);
170 void (*flush_tlb_single)(unsigned long addr);
171 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
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_HIGHPTE
193 void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
196 #ifdef CONFIG_X86_PAE
197 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
198 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
199 void (*set_pud)(pud_t *pudp, pud_t pudval);
200 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
201 void (*pmd_clear)(pmd_t *pmdp);
203 unsigned long long (*pte_val)(pte_t);
204 unsigned long long (*pmd_val)(pmd_t);
205 unsigned long long (*pgd_val)(pgd_t);
207 pte_t (*make_pte)(unsigned long long pte);
208 pmd_t (*make_pmd)(unsigned long long pmd);
209 pgd_t (*make_pgd)(unsigned long long pgd);
211 unsigned long (*pte_val)(pte_t);
212 unsigned long (*pgd_val)(pgd_t);
214 pte_t (*make_pte)(unsigned long pte);
215 pgd_t (*make_pgd)(unsigned long pgd);
218 /* Set deferred update mode, used for batching operations. */
219 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
221 /* These two are jmp to, not actually called. */
222 void (*irq_enable_sysexit)(void);
226 /* Mark a paravirt probe function. */
227 #define paravirt_probe(fn) \
228 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
229 __attribute__((__section__(".paravirtprobe"))) = fn
231 extern struct paravirt_ops paravirt_ops;
233 #define PARAVIRT_PATCH(x) \
234 (offsetof(struct paravirt_ops, x) / sizeof(void *))
236 #define paravirt_type(type) \
237 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
238 #define paravirt_clobber(clobber) \
239 [paravirt_clobber] "i" (clobber)
242 * Generate some code, and mark it as patchable by the
243 * apply_paravirt() alternate instruction patcher.
245 #define _paravirt_alt(insn_string, type, clobber) \
246 "771:\n\t" insn_string "\n" "772:\n" \
247 ".pushsection .parainstructions,\"a\"\n" \
249 " .byte " type "\n" \
250 " .byte 772b-771b\n" \
251 " .short " clobber "\n" \
254 /* Generate patchable code, with the default asm parameters. */
255 #define paravirt_alt(insn_string) \
256 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
258 unsigned paravirt_patch_nop(void);
259 unsigned paravirt_patch_ignore(unsigned len);
260 unsigned paravirt_patch_call(void *target, u16 tgt_clobbers,
261 void *site, u16 site_clobbers,
263 unsigned paravirt_patch_jmp(void *target, void *site, unsigned len);
264 unsigned paravirt_patch_default(u8 type, u16 clobbers, void *site, unsigned len);
266 unsigned paravirt_patch_insns(void *site, unsigned len,
267 const char *start, const char *end);
271 * This generates an indirect call based on the operation type number.
272 * The type number, computed in PARAVIRT_PATCH, is derived from the
273 * offset into the paravirt_ops structure, and can therefore be freely
274 * converted back into a structure offset.
276 #define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
279 * These macros are intended to wrap calls into a paravirt_ops
280 * operation, so that they can be later identified and patched at
283 * Normally, a call to a pv_op function is a simple indirect call:
284 * (paravirt_ops.operations)(args...).
286 * Unfortunately, this is a relatively slow operation for modern CPUs,
287 * because it cannot necessarily determine what the destination
288 * address is. In this case, the address is a runtime constant, so at
289 * the very least we can patch the call to e a simple direct call, or
290 * ideally, patch an inline implementation into the callsite. (Direct
291 * calls are essentially free, because the call and return addresses
292 * are completely predictable.)
294 * These macros rely on the standard gcc "regparm(3)" calling
295 * convention, in which the first three arguments are placed in %eax,
296 * %edx, %ecx (in that order), and the remaining arguments are placed
297 * on the stack. All caller-save registers (eax,edx,ecx) are expected
298 * to be modified (either clobbered or used for return values).
300 * The call instruction itself is marked by placing its start address
301 * and size into the .parainstructions section, so that
302 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
303 * appropriate patching under the control of the backend paravirt_ops
306 * Unfortunately there's no way to get gcc to generate the args setup
307 * for the call, and then allow the call itself to be generated by an
308 * inline asm. Because of this, we must do the complete arg setup and
309 * return value handling from within these macros. This is fairly
312 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
313 * It could be extended to more arguments, but there would be little
314 * to be gained from that. For each number of arguments, there are
315 * the two VCALL and CALL variants for void and non-void functions.
317 * When there is a return value, the invoker of the macro must specify
318 * the return type. The macro then uses sizeof() on that type to
319 * determine whether its a 32 or 64 bit value, and places the return
320 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
323 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
326 * Small structures are passed and returned in registers. The macro
327 * calling convention can't directly deal with this, so the wrapper
328 * functions must do this.
330 * These PVOP_* macros are only defined within this header. This
331 * means that all uses must be wrapped in inline functions. This also
332 * makes sure the incoming and outgoing types are always correct.
334 #define PVOP_CALL0(__rettype, __op) \
337 if (sizeof(__rettype) > sizeof(unsigned long)) { \
338 unsigned long long __tmp; \
339 unsigned long __ecx; \
340 asm volatile(paravirt_alt(PARAVIRT_CALL) \
341 : "=A" (__tmp), "=c" (__ecx) \
342 : paravirt_type(__op), \
343 paravirt_clobber(CLBR_ANY) \
345 __ret = (__rettype)__tmp; \
347 unsigned long __tmp, __edx, __ecx; \
348 asm volatile(paravirt_alt(PARAVIRT_CALL) \
349 : "=a" (__tmp), "=d" (__edx), \
351 : paravirt_type(__op), \
352 paravirt_clobber(CLBR_ANY) \
354 __ret = (__rettype)__tmp; \
358 #define PVOP_VCALL0(__op) \
360 unsigned long __eax, __edx, __ecx; \
361 asm volatile(paravirt_alt(PARAVIRT_CALL) \
362 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
363 : paravirt_type(__op), \
364 paravirt_clobber(CLBR_ANY) \
368 #define PVOP_CALL1(__rettype, __op, arg1) \
371 if (sizeof(__rettype) > sizeof(unsigned long)) { \
372 unsigned long long __tmp; \
373 unsigned long __ecx; \
374 asm volatile(paravirt_alt(PARAVIRT_CALL) \
375 : "=A" (__tmp), "=c" (__ecx) \
376 : "a" ((u32)(arg1)), \
377 paravirt_type(__op), \
378 paravirt_clobber(CLBR_ANY) \
380 __ret = (__rettype)__tmp; \
382 unsigned long __tmp, __edx, __ecx; \
383 asm volatile(paravirt_alt(PARAVIRT_CALL) \
384 : "=a" (__tmp), "=d" (__edx), \
386 : "0" ((u32)(arg1)), \
387 paravirt_type(__op), \
388 paravirt_clobber(CLBR_ANY) \
390 __ret = (__rettype)__tmp; \
394 #define PVOP_VCALL1(__op, arg1) \
396 unsigned long __eax, __edx, __ecx; \
397 asm volatile(paravirt_alt(PARAVIRT_CALL) \
398 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
399 : "0" ((u32)(arg1)), \
400 paravirt_type(__op), \
401 paravirt_clobber(CLBR_ANY) \
405 #define PVOP_CALL2(__rettype, __op, arg1, arg2) \
408 if (sizeof(__rettype) > sizeof(unsigned long)) { \
409 unsigned long long __tmp; \
410 unsigned long __ecx; \
411 asm volatile(paravirt_alt(PARAVIRT_CALL) \
412 : "=A" (__tmp), "=c" (__ecx) \
413 : "a" ((u32)(arg1)), \
415 paravirt_type(__op), \
416 paravirt_clobber(CLBR_ANY) \
418 __ret = (__rettype)__tmp; \
420 unsigned long __tmp, __edx, __ecx; \
421 asm volatile(paravirt_alt(PARAVIRT_CALL) \
422 : "=a" (__tmp), "=d" (__edx), \
424 : "0" ((u32)(arg1)), \
426 paravirt_type(__op), \
427 paravirt_clobber(CLBR_ANY) \
429 __ret = (__rettype)__tmp; \
433 #define PVOP_VCALL2(__op, arg1, arg2) \
435 unsigned long __eax, __edx, __ecx; \
436 asm volatile(paravirt_alt(PARAVIRT_CALL) \
437 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
438 : "0" ((u32)(arg1)), \
440 paravirt_type(__op), \
441 paravirt_clobber(CLBR_ANY) \
445 #define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \
448 if (sizeof(__rettype) > sizeof(unsigned long)) { \
449 unsigned long long __tmp; \
450 unsigned long __ecx; \
451 asm volatile(paravirt_alt(PARAVIRT_CALL) \
452 : "=A" (__tmp), "=c" (__ecx) \
453 : "a" ((u32)(arg1)), \
456 paravirt_type(__op), \
457 paravirt_clobber(CLBR_ANY) \
459 __ret = (__rettype)__tmp; \
461 unsigned long __tmp, __edx, __ecx; \
462 asm volatile(paravirt_alt(PARAVIRT_CALL) \
463 : "=a" (__tmp), "=d" (__edx), \
465 : "0" ((u32)(arg1)), \
468 paravirt_type(__op), \
469 paravirt_clobber(CLBR_ANY) \
471 __ret = (__rettype)__tmp; \
475 #define PVOP_VCALL3(__op, arg1, arg2, arg3) \
477 unsigned long __eax, __edx, __ecx; \
478 asm volatile(paravirt_alt(PARAVIRT_CALL) \
479 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
480 : "0" ((u32)(arg1)), \
483 paravirt_type(__op), \
484 paravirt_clobber(CLBR_ANY) \
488 #define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \
491 if (sizeof(__rettype) > sizeof(unsigned long)) { \
492 unsigned long long __tmp; \
493 unsigned long __ecx; \
494 asm volatile("push %[_arg4]; " \
495 paravirt_alt(PARAVIRT_CALL) \
496 "lea 4(%%esp),%%esp" \
497 : "=A" (__tmp), "=c" (__ecx) \
498 : "a" ((u32)(arg1)), \
501 [_arg4] "mr" ((u32)(arg4)), \
502 paravirt_type(__op), \
503 paravirt_clobber(CLBR_ANY) \
504 : "memory", "cc",); \
505 __ret = (__rettype)__tmp; \
507 unsigned long __tmp, __edx, __ecx; \
508 asm volatile("push %[_arg4]; " \
509 paravirt_alt(PARAVIRT_CALL) \
510 "lea 4(%%esp),%%esp" \
511 : "=a" (__tmp), "=d" (__edx), "=c" (__ecx) \
512 : "0" ((u32)(arg1)), \
515 [_arg4]"mr" ((u32)(arg4)), \
516 paravirt_type(__op), \
517 paravirt_clobber(CLBR_ANY) \
519 __ret = (__rettype)__tmp; \
523 #define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \
525 unsigned long __eax, __edx, __ecx; \
526 asm volatile("push %[_arg4]; " \
527 paravirt_alt(PARAVIRT_CALL) \
528 "lea 4(%%esp),%%esp" \
529 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
530 : "0" ((u32)(arg1)), \
533 [_arg4]"mr" ((u32)(arg4)), \
534 paravirt_type(__op), \
535 paravirt_clobber(CLBR_ANY) \
539 static inline int paravirt_enabled(void)
541 return paravirt_ops.paravirt_enabled;
544 static inline void load_esp0(struct tss_struct *tss,
545 struct thread_struct *thread)
547 PVOP_VCALL2(load_esp0, tss, thread);
550 #define ARCH_SETUP paravirt_ops.arch_setup();
551 static inline unsigned long get_wallclock(void)
553 return PVOP_CALL0(unsigned long, get_wallclock);
556 static inline int set_wallclock(unsigned long nowtime)
558 return PVOP_CALL1(int, set_wallclock, nowtime);
561 static inline void (*choose_time_init(void))(void)
563 return paravirt_ops.time_init;
566 /* The paravirtualized CPUID instruction. */
567 static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
568 unsigned int *ecx, unsigned int *edx)
570 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
574 * These special macros can be used to get or set a debugging register
576 static inline unsigned long paravirt_get_debugreg(int reg)
578 return PVOP_CALL1(unsigned long, get_debugreg, reg);
580 #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
581 static inline void set_debugreg(unsigned long val, int reg)
583 PVOP_VCALL2(set_debugreg, reg, val);
586 static inline void clts(void)
591 static inline unsigned long read_cr0(void)
593 return PVOP_CALL0(unsigned long, read_cr0);
596 static inline void write_cr0(unsigned long x)
598 PVOP_VCALL1(write_cr0, x);
601 static inline unsigned long read_cr2(void)
603 return PVOP_CALL0(unsigned long, read_cr2);
606 static inline void write_cr2(unsigned long x)
608 PVOP_VCALL1(write_cr2, x);
611 static inline unsigned long read_cr3(void)
613 return PVOP_CALL0(unsigned long, read_cr3);
616 static inline void write_cr3(unsigned long x)
618 PVOP_VCALL1(write_cr3, x);
621 static inline unsigned long read_cr4(void)
623 return PVOP_CALL0(unsigned long, read_cr4);
625 static inline unsigned long read_cr4_safe(void)
627 return PVOP_CALL0(unsigned long, read_cr4_safe);
630 static inline void write_cr4(unsigned long x)
632 PVOP_VCALL1(write_cr4, x);
635 static inline void raw_safe_halt(void)
637 PVOP_VCALL0(safe_halt);
640 static inline void halt(void)
642 PVOP_VCALL0(safe_halt);
645 static inline void wbinvd(void)
650 #define get_kernel_rpl() (paravirt_ops.kernel_rpl)
652 static inline u64 paravirt_read_msr(unsigned msr, int *err)
654 return PVOP_CALL2(u64, read_msr, msr, err);
656 static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
658 return PVOP_CALL3(int, write_msr, msr, low, high);
661 /* These should all do BUG_ON(_err), but our headers are too tangled. */
662 #define rdmsr(msr,val1,val2) do { \
664 u64 _l = paravirt_read_msr(msr, &_err); \
669 #define wrmsr(msr,val1,val2) do { \
670 paravirt_write_msr(msr, val1, val2); \
673 #define rdmsrl(msr,val) do { \
675 val = paravirt_read_msr(msr, &_err); \
678 #define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
679 #define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
681 /* rdmsr with exception handling */
682 #define rdmsr_safe(msr,a,b) ({ \
684 u64 _l = paravirt_read_msr(msr, &_err); \
690 static inline u64 paravirt_read_tsc(void)
692 return PVOP_CALL0(u64, read_tsc);
694 #define rdtsc(low,high) do { \
695 u64 _l = paravirt_read_tsc(); \
700 #define rdtscl(low) do { \
701 u64 _l = paravirt_read_tsc(); \
705 #define rdtscll(val) (val = paravirt_read_tsc())
707 #define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
708 #define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
710 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
712 static inline unsigned long long paravirt_read_pmc(int counter)
714 return PVOP_CALL1(u64, read_pmc, counter);
717 #define rdpmc(counter,low,high) do { \
718 u64 _l = paravirt_read_pmc(counter); \
723 static inline void load_TR_desc(void)
725 PVOP_VCALL0(load_tr_desc);
727 static inline void load_gdt(const struct Xgt_desc_struct *dtr)
729 PVOP_VCALL1(load_gdt, dtr);
731 static inline void load_idt(const struct Xgt_desc_struct *dtr)
733 PVOP_VCALL1(load_idt, dtr);
735 static inline void set_ldt(const void *addr, unsigned entries)
737 PVOP_VCALL2(set_ldt, addr, entries);
739 static inline void store_gdt(struct Xgt_desc_struct *dtr)
741 PVOP_VCALL1(store_gdt, dtr);
743 static inline void store_idt(struct Xgt_desc_struct *dtr)
745 PVOP_VCALL1(store_idt, dtr);
747 static inline unsigned long paravirt_store_tr(void)
749 return PVOP_CALL0(unsigned long, store_tr);
751 #define store_tr(tr) ((tr) = paravirt_store_tr())
752 static inline void load_TLS(struct thread_struct *t, unsigned cpu)
754 PVOP_VCALL2(load_tls, t, cpu);
756 static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
758 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
760 static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
762 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
764 static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
766 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
768 static inline void set_iopl_mask(unsigned mask)
770 PVOP_VCALL1(set_iopl_mask, mask);
773 /* The paravirtualized I/O functions */
774 static inline void slow_down_io(void) {
775 paravirt_ops.io_delay();
776 #ifdef REALLY_SLOW_IO
777 paravirt_ops.io_delay();
778 paravirt_ops.io_delay();
779 paravirt_ops.io_delay();
783 #ifdef CONFIG_X86_LOCAL_APIC
785 * Basic functions accessing APICs.
787 static inline void apic_write(unsigned long reg, unsigned long v)
789 PVOP_VCALL2(apic_write, reg, v);
792 static inline void apic_write_atomic(unsigned long reg, unsigned long v)
794 PVOP_VCALL2(apic_write_atomic, reg, v);
797 static inline unsigned long apic_read(unsigned long reg)
799 return PVOP_CALL1(unsigned long, apic_read, reg);
802 static inline void setup_boot_clock(void)
804 PVOP_VCALL0(setup_boot_clock);
807 static inline void setup_secondary_clock(void)
809 PVOP_VCALL0(setup_secondary_clock);
813 static inline void paravirt_pagetable_setup_start(pgd_t *base)
815 if (paravirt_ops.pagetable_setup_start)
816 (*paravirt_ops.pagetable_setup_start)(base);
819 static inline void paravirt_pagetable_setup_done(pgd_t *base)
821 if (paravirt_ops.pagetable_setup_done)
822 (*paravirt_ops.pagetable_setup_done)(base);
826 static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
827 unsigned long start_esp)
829 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
833 static inline void paravirt_activate_mm(struct mm_struct *prev,
834 struct mm_struct *next)
836 PVOP_VCALL2(activate_mm, prev, next);
839 static inline void arch_dup_mmap(struct mm_struct *oldmm,
840 struct mm_struct *mm)
842 PVOP_VCALL2(dup_mmap, oldmm, mm);
845 static inline void arch_exit_mmap(struct mm_struct *mm)
847 PVOP_VCALL1(exit_mmap, mm);
850 static inline void __flush_tlb(void)
852 PVOP_VCALL0(flush_tlb_user);
854 static inline void __flush_tlb_global(void)
856 PVOP_VCALL0(flush_tlb_kernel);
858 static inline void __flush_tlb_single(unsigned long addr)
860 PVOP_VCALL1(flush_tlb_single, addr);
863 static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
866 PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va);
869 static inline void paravirt_alloc_pt(unsigned pfn)
871 PVOP_VCALL1(alloc_pt, pfn);
873 static inline void paravirt_release_pt(unsigned pfn)
875 PVOP_VCALL1(release_pt, pfn);
878 static inline void paravirt_alloc_pd(unsigned pfn)
880 PVOP_VCALL1(alloc_pd, pfn);
883 static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
884 unsigned start, unsigned count)
886 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
888 static inline void paravirt_release_pd(unsigned pfn)
890 PVOP_VCALL1(release_pd, pfn);
893 #ifdef CONFIG_HIGHPTE
894 static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
897 ret = PVOP_CALL2(unsigned long, kmap_atomic_pte, page, type);
902 static inline void pte_update(struct mm_struct *mm, unsigned long addr,
905 PVOP_VCALL3(pte_update, mm, addr, ptep);
908 static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
911 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
914 #ifdef CONFIG_X86_PAE
915 static inline pte_t __pte(unsigned long long val)
917 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
919 return (pte_t) { ret, ret >> 32 };
922 static inline pmd_t __pmd(unsigned long long val)
924 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
927 static inline pgd_t __pgd(unsigned long long val)
929 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
932 static inline unsigned long long pte_val(pte_t x)
934 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
937 static inline unsigned long long pmd_val(pmd_t x)
939 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
942 static inline unsigned long long pgd_val(pgd_t x)
944 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
947 static inline void set_pte(pte_t *ptep, pte_t pteval)
949 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
952 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
953 pte_t *ptep, pte_t pteval)
956 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
959 static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
961 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
964 static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
965 pte_t *ptep, pte_t pte)
968 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
971 static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
973 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
976 static inline void set_pud(pud_t *pudp, pud_t pudval)
978 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
981 static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
983 PVOP_VCALL3(pte_clear, mm, addr, ptep);
986 static inline void pmd_clear(pmd_t *pmdp)
988 PVOP_VCALL1(pmd_clear, pmdp);
991 static inline pte_t raw_ptep_get_and_clear(pte_t *p)
993 unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
994 return (pte_t) { val, val >> 32 };
996 #else /* !CONFIG_X86_PAE */
997 static inline pte_t __pte(unsigned long val)
999 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
1002 static inline pgd_t __pgd(unsigned long val)
1004 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
1007 static inline unsigned long pte_val(pte_t x)
1009 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
1012 static inline unsigned long pgd_val(pgd_t x)
1014 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
1017 static inline void set_pte(pte_t *ptep, pte_t pteval)
1019 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
1022 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1023 pte_t *ptep, pte_t pteval)
1025 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
1028 static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
1030 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
1033 static inline pte_t raw_ptep_get_and_clear(pte_t *p)
1035 return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
1037 #endif /* CONFIG_X86_PAE */
1039 /* Lazy mode for batching updates / context switch */
1040 #define PARAVIRT_LAZY_NONE 0
1041 #define PARAVIRT_LAZY_MMU 1
1042 #define PARAVIRT_LAZY_CPU 2
1043 #define PARAVIRT_LAZY_FLUSH 3
1045 #define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
1046 static inline void arch_enter_lazy_cpu_mode(void)
1048 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
1051 static inline void arch_leave_lazy_cpu_mode(void)
1053 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1056 static inline void arch_flush_lazy_cpu_mode(void)
1058 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1062 #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
1063 static inline void arch_enter_lazy_mmu_mode(void)
1065 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
1068 static inline void arch_leave_lazy_mmu_mode(void)
1070 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1073 static inline void arch_flush_lazy_mmu_mode(void)
1075 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1078 void _paravirt_nop(void);
1079 #define paravirt_nop ((void *)_paravirt_nop)
1081 /* These all sit in the .parainstructions section to tell us what to patch. */
1082 struct paravirt_patch_site {
1083 u8 *instr; /* original instructions */
1084 u8 instrtype; /* type of this instruction */
1085 u8 len; /* length of original instruction */
1086 u16 clobbers; /* what registers you may clobber */
1089 extern struct paravirt_patch_site __parainstructions[],
1090 __parainstructions_end[];
1092 static inline unsigned long __raw_local_save_flags(void)
1096 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1098 "popl %%edx; popl %%ecx")
1100 : paravirt_type(save_fl),
1101 paravirt_clobber(CLBR_EAX)
1106 static inline void raw_local_irq_restore(unsigned long f)
1108 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1110 "popl %%edx; popl %%ecx")
1113 paravirt_type(restore_fl),
1114 paravirt_clobber(CLBR_EAX)
1118 static inline void raw_local_irq_disable(void)
1120 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1122 "popl %%edx; popl %%ecx")
1124 : paravirt_type(irq_disable),
1125 paravirt_clobber(CLBR_EAX)
1126 : "memory", "eax", "cc");
1129 static inline void raw_local_irq_enable(void)
1131 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1133 "popl %%edx; popl %%ecx")
1135 : paravirt_type(irq_enable),
1136 paravirt_clobber(CLBR_EAX)
1137 : "memory", "eax", "cc");
1140 static inline unsigned long __raw_local_irq_save(void)
1144 f = __raw_local_save_flags();
1145 raw_local_irq_disable();
1149 #define CLI_STRING \
1150 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1151 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1152 "popl %%edx; popl %%ecx", \
1153 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
1155 #define STI_STRING \
1156 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1157 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1158 "popl %%edx; popl %%ecx", \
1159 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1161 #define CLI_STI_CLOBBERS , "%eax"
1162 #define CLI_STI_INPUT_ARGS \
1164 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1165 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1166 paravirt_clobber(CLBR_EAX)
1168 /* Make sure as little as possible of this mess escapes. */
1169 #undef PARAVIRT_CALL
1181 #else /* __ASSEMBLY__ */
1183 #define PARA_PATCH(off) ((off) / 4)
1185 #define PARA_SITE(ptype, clobbers, ops) \
1189 .pushsection .parainstructions,"a"; \
1196 #define INTERRUPT_RETURN \
1197 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
1198 jmp *%cs:paravirt_ops+PARAVIRT_iret)
1200 #define DISABLE_INTERRUPTS(clobbers) \
1201 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
1202 pushl %eax; pushl %ecx; pushl %edx; \
1203 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
1204 popl %edx; popl %ecx; popl %eax) \
1206 #define ENABLE_INTERRUPTS(clobbers) \
1207 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
1208 pushl %eax; pushl %ecx; pushl %edx; \
1209 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
1210 popl %edx; popl %ecx; popl %eax)
1212 #define ENABLE_INTERRUPTS_SYSEXIT \
1213 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
1214 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
1216 #define GET_CR0_INTO_EAX \
1217 push %ecx; push %edx; \
1218 call *paravirt_ops+PARAVIRT_read_cr0; \
1221 #endif /* __ASSEMBLY__ */
1222 #endif /* CONFIG_PARAVIRT */
1223 #endif /* __ASM_PARAVIRT_H */