blob: 690ada22437ad420c754e5b94520a2d77c7c25e5 [file] [log] [blame]
Rusty Russelld3561b72006-12-07 02:14:07 +01001#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. */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02005
6#ifdef CONFIG_PARAVIRT
Rusty Russellda181a82006-12-07 02:14:08 +01007#include <asm/page.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01008
Rusty Russell139ec7c2006-12-07 02:14:08 +01009/* Bitmask of what can be clobbered: usually at least eax. */
10#define CLBR_NONE 0x0
11#define CLBR_EAX 0x1
12#define CLBR_ECX 0x2
13#define CLBR_EDX 0x4
14#define CLBR_ANY 0x7
15
Rusty Russelld3561b72006-12-07 02:14:07 +010016#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020017#include <linux/types.h>
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +020018#include <linux/cpumask.h>
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020019#include <asm/kmap_types.h>
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020020
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020021struct page;
Rusty Russelld3561b72006-12-07 02:14:07 +010022struct thread_struct;
23struct Xgt_desc_struct;
24struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010025struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020026struct desc_struct;
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020027
28/* Lazy mode for batching updates / context switch */
29enum paravirt_lazy_mode {
30 PARAVIRT_LAZY_NONE = 0,
31 PARAVIRT_LAZY_MMU = 1,
32 PARAVIRT_LAZY_CPU = 2,
Jeremy Fitzhardinge4e0fa852007-05-02 19:27:15 +020033 PARAVIRT_LAZY_FLUSH = 3,
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020034};
35
Rusty Russelld3561b72006-12-07 02:14:07 +010036struct paravirt_ops
37{
38 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020039 int shared_kernel_pmd;
Rusty Russelld3561b72006-12-07 02:14:07 +010040 int paravirt_enabled;
41 const char *name;
42
Rusty Russell139ec7c2006-12-07 02:14:08 +010043 /*
44 * Patch may replace one of the defined code sequences with arbitrary
45 * code, subject to the same register constraints. This generally
46 * means the code is not free to clobber any registers other than EAX.
47 * The patch function should return the number of bytes of code
48 * generated, as we nop pad the rest in generic code.
49 */
50 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
51
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020052 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010053 void (*arch_setup)(void);
54 char *(*memory_setup)(void);
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -070055 void (*post_allocator_init)(void);
56
Rusty Russelld3561b72006-12-07 02:14:07 +010057 void (*init_IRQ)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020058 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010059
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020060 /*
61 * Called before/after init_mm pagetable setup. setup_start
62 * may reset %cr3, and may pre-install parts of the pagetable;
63 * pagetable setup is expected to preserve any existing
64 * mapping.
65 */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +020066 void (*pagetable_setup_start)(pgd_t *pgd_base);
67 void (*pagetable_setup_done)(pgd_t *pgd_base);
68
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020069 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010070 void (*banner)(void);
71
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020072 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +010073 unsigned long (*get_wallclock)(void);
74 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010075
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020076 /* cpuid emulation, mostly so that caps bits can be disabled */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010077 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010078 unsigned int *ecx, unsigned int *edx);
79
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020080 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010081 unsigned long (*get_debugreg)(int regno);
82 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010083
Andi Kleen1a1eecd2007-02-13 13:26:25 +010084 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010085
Andi Kleen1a1eecd2007-02-13 13:26:25 +010086 unsigned long (*read_cr0)(void);
87 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010088
Andi Kleen1a1eecd2007-02-13 13:26:25 +010089 unsigned long (*read_cr2)(void);
90 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010091
Andi Kleen1a1eecd2007-02-13 13:26:25 +010092 unsigned long (*read_cr3)(void);
93 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010094
Andi Kleen1a1eecd2007-02-13 13:26:25 +010095 unsigned long (*read_cr4_safe)(void);
96 unsigned long (*read_cr4)(void);
97 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010098
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020099 /*
100 * Get/set interrupt state. save_fl and restore_fl are only
101 * expected to use X86_EFLAGS_IF; all other bits
102 * returned from save_fl are undefined, and may be ignored by
103 * restore_fl.
104 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100105 unsigned long (*save_fl)(void);
106 void (*restore_fl)(unsigned long);
107 void (*irq_disable)(void);
108 void (*irq_enable)(void);
109 void (*safe_halt)(void);
110 void (*halt)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200111
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100112 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100113
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200114 /* MSR, PMC and TSR operations.
115 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100116 u64 (*read_msr)(unsigned int msr, int *err);
117 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +0100118
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100119 u64 (*read_tsc)(void);
120 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800121 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -0800122 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100123
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200124 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100125 void (*load_tr_desc)(void);
126 void (*load_gdt)(const struct Xgt_desc_struct *);
127 void (*load_idt)(const struct Xgt_desc_struct *);
128 void (*store_gdt)(struct Xgt_desc_struct *);
129 void (*store_idt)(struct Xgt_desc_struct *);
130 void (*set_ldt)(const void *desc, unsigned entries);
131 unsigned long (*store_tr)(void);
132 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +0200133 void (*write_ldt_entry)(struct desc_struct *,
134 int entrynum, u32 low, u32 high);
135 void (*write_gdt_entry)(struct desc_struct *,
136 int entrynum, u32 low, u32 high);
137 void (*write_idt_entry)(struct desc_struct *,
138 int entrynum, u32 low, u32 high);
139 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100140
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100141 void (*set_iopl_mask)(unsigned mask);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100142 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100143
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200144 /*
145 * Hooks for intercepting the creation/use/destruction of an
146 * mm_struct.
147 */
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200148 void (*activate_mm)(struct mm_struct *prev,
149 struct mm_struct *next);
150 void (*dup_mmap)(struct mm_struct *oldmm,
151 struct mm_struct *mm);
152 void (*exit_mmap)(struct mm_struct *mm);
153
Rusty Russell13623d72006-12-07 02:14:08 +0100154#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200155 /*
156 * Direct APIC operations, principally for VMI. Ideally
157 * these shouldn't be in this interface.
158 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100159 void (*apic_write)(unsigned long reg, unsigned long v);
160 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
161 unsigned long (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100162 void (*setup_boot_clock)(void);
163 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200164
165 void (*startup_ipi_hook)(int phys_apicid,
166 unsigned long start_eip,
167 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100168#endif
169
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200170 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100171 void (*flush_tlb_user)(void);
172 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200173 void (*flush_tlb_single)(unsigned long addr);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200174 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
175 unsigned long va);
Rusty Russellda181a82006-12-07 02:14:08 +0100176
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200177 /* Hooks for allocating/releasing pagetable pages */
Jeremy Fitzhardingefdb4c332007-07-17 18:37:03 -0700178 void (*alloc_pt)(struct mm_struct *mm, u32 pfn);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100179 void (*alloc_pd)(u32 pfn);
180 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
181 void (*release_pt)(u32 pfn);
182 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100183
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200184 /* Pagetable manipulation functions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100185 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200186 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
187 pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100188 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200189 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200190 void (*pte_update_defer)(struct mm_struct *mm,
191 unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200192
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200193#ifdef CONFIG_HIGHPTE
194 void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
195#endif
196
Rusty Russellda181a82006-12-07 02:14:08 +0100197#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100198 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200199 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100200 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200201 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100202 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200203
204 unsigned long long (*pte_val)(pte_t);
205 unsigned long long (*pmd_val)(pmd_t);
206 unsigned long long (*pgd_val)(pgd_t);
207
208 pte_t (*make_pte)(unsigned long long pte);
209 pmd_t (*make_pmd)(unsigned long long pmd);
210 pgd_t (*make_pgd)(unsigned long long pgd);
211#else
212 unsigned long (*pte_val)(pte_t);
213 unsigned long (*pgd_val)(pgd_t);
214
215 pte_t (*make_pte)(unsigned long pte);
216 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100217#endif
218
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200219 /* Set deferred update mode, used for batching operations. */
220 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100221
Rusty Russelld3561b72006-12-07 02:14:07 +0100222 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100223 void (*irq_enable_sysexit)(void);
224 void (*iret)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100225};
226
227extern struct paravirt_ops paravirt_ops;
228
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200229#define PARAVIRT_PATCH(x) \
230 (offsetof(struct paravirt_ops, x) / sizeof(void *))
231
232#define paravirt_type(type) \
233 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
234#define paravirt_clobber(clobber) \
235 [paravirt_clobber] "i" (clobber)
236
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200237/*
238 * Generate some code, and mark it as patchable by the
239 * apply_paravirt() alternate instruction patcher.
240 */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200241#define _paravirt_alt(insn_string, type, clobber) \
242 "771:\n\t" insn_string "\n" "772:\n" \
243 ".pushsection .parainstructions,\"a\"\n" \
244 " .long 771b\n" \
245 " .byte " type "\n" \
246 " .byte 772b-771b\n" \
247 " .short " clobber "\n" \
248 ".popsection\n"
249
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200250/* Generate patchable code, with the default asm parameters. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200251#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200252 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
253
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200254unsigned paravirt_patch_nop(void);
255unsigned paravirt_patch_ignore(unsigned len);
256unsigned paravirt_patch_call(void *target, u16 tgt_clobbers,
257 void *site, u16 site_clobbers,
258 unsigned len);
259unsigned paravirt_patch_jmp(void *target, void *site, unsigned len);
260unsigned paravirt_patch_default(u8 type, u16 clobbers, void *site, unsigned len);
261
262unsigned paravirt_patch_insns(void *site, unsigned len,
263 const char *start, const char *end);
264
Jeremy Fitzhardinged5729292007-07-17 18:37:04 -0700265int paravirt_disable_iospace(void);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200266
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200267/*
268 * This generates an indirect call based on the operation type number.
269 * The type number, computed in PARAVIRT_PATCH, is derived from the
270 * offset into the paravirt_ops structure, and can therefore be freely
271 * converted back into a structure offset.
272 */
273#define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
274
275/*
276 * These macros are intended to wrap calls into a paravirt_ops
277 * operation, so that they can be later identified and patched at
278 * runtime.
279 *
280 * Normally, a call to a pv_op function is a simple indirect call:
281 * (paravirt_ops.operations)(args...).
282 *
283 * Unfortunately, this is a relatively slow operation for modern CPUs,
284 * because it cannot necessarily determine what the destination
285 * address is. In this case, the address is a runtime constant, so at
286 * the very least we can patch the call to e a simple direct call, or
287 * ideally, patch an inline implementation into the callsite. (Direct
288 * calls are essentially free, because the call and return addresses
289 * are completely predictable.)
290 *
291 * These macros rely on the standard gcc "regparm(3)" calling
292 * convention, in which the first three arguments are placed in %eax,
293 * %edx, %ecx (in that order), and the remaining arguments are placed
294 * on the stack. All caller-save registers (eax,edx,ecx) are expected
295 * to be modified (either clobbered or used for return values).
296 *
297 * The call instruction itself is marked by placing its start address
298 * and size into the .parainstructions section, so that
299 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
300 * appropriate patching under the control of the backend paravirt_ops
301 * implementation.
302 *
303 * Unfortunately there's no way to get gcc to generate the args setup
304 * for the call, and then allow the call itself to be generated by an
305 * inline asm. Because of this, we must do the complete arg setup and
306 * return value handling from within these macros. This is fairly
307 * cumbersome.
308 *
309 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
310 * It could be extended to more arguments, but there would be little
311 * to be gained from that. For each number of arguments, there are
312 * the two VCALL and CALL variants for void and non-void functions.
313 *
314 * When there is a return value, the invoker of the macro must specify
315 * the return type. The macro then uses sizeof() on that type to
316 * determine whether its a 32 or 64 bit value, and places the return
317 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
318 * 64-bit).
319 *
320 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
321 * in low,high order.
322 *
323 * Small structures are passed and returned in registers. The macro
324 * calling convention can't directly deal with this, so the wrapper
325 * functions must do this.
326 *
327 * These PVOP_* macros are only defined within this header. This
328 * means that all uses must be wrapped in inline functions. This also
329 * makes sure the incoming and outgoing types are always correct.
330 */
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200331#define __PVOP_CALL(rettype, op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200332 ({ \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200333 rettype __ret; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200334 unsigned long __eax, __edx, __ecx; \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200335 if (sizeof(rettype) > sizeof(unsigned long)) { \
336 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200337 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200338 post \
339 : "=a" (__eax), "=d" (__edx), \
340 "=c" (__ecx) \
341 : paravirt_type(op), \
342 paravirt_clobber(CLBR_ANY), \
343 ##__VA_ARGS__ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200344 : "memory", "cc"); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200345 __ret = (rettype)((((u64)__edx) << 32) | __eax); \
346 } else { \
347 asm volatile(pre \
348 paravirt_alt(PARAVIRT_CALL) \
349 post \
350 : "=a" (__eax), "=d" (__edx), \
351 "=c" (__ecx) \
352 : paravirt_type(op), \
353 paravirt_clobber(CLBR_ANY), \
354 ##__VA_ARGS__ \
355 : "memory", "cc"); \
356 __ret = (rettype)__eax; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200357 } \
358 __ret; \
359 })
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200360#define __PVOP_VCALL(op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200361 ({ \
362 unsigned long __eax, __edx, __ecx; \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200363 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200364 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200365 post \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200366 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200367 : paravirt_type(op), \
368 paravirt_clobber(CLBR_ANY), \
369 ##__VA_ARGS__ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200370 : "memory", "cc"); \
371 })
372
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200373#define PVOP_CALL0(rettype, op) \
374 __PVOP_CALL(rettype, op, "", "")
375#define PVOP_VCALL0(op) \
376 __PVOP_VCALL(op, "", "")
377
378#define PVOP_CALL1(rettype, op, arg1) \
379 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)))
380#define PVOP_VCALL1(op, arg1) \
381 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)))
382
383#define PVOP_CALL2(rettype, op, arg1, arg2) \
384 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)), "1" ((u32)(arg2)))
385#define PVOP_VCALL2(op, arg1, arg2) \
386 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)), "1" ((u32)(arg2)))
387
388#define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \
389 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)), \
390 "1"((u32)(arg2)), "2"((u32)(arg3)))
391#define PVOP_VCALL3(op, arg1, arg2, arg3) \
392 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)), "1"((u32)(arg2)), \
393 "2"((u32)(arg3)))
394
395#define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
396 __PVOP_CALL(rettype, op, \
397 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
398 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
399 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
400#define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
401 __PVOP_VCALL(op, \
402 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
403 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
404 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
405
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200406static inline int paravirt_enabled(void)
407{
408 return paravirt_ops.paravirt_enabled;
409}
Rusty Russelld3561b72006-12-07 02:14:07 +0100410
411static inline void load_esp0(struct tss_struct *tss,
412 struct thread_struct *thread)
413{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200414 PVOP_VCALL2(load_esp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100415}
416
417#define ARCH_SETUP paravirt_ops.arch_setup();
418static inline unsigned long get_wallclock(void)
419{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200420 return PVOP_CALL0(unsigned long, get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100421}
422
423static inline int set_wallclock(unsigned long nowtime)
424{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200425 return PVOP_CALL1(int, set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100426}
427
Zachary Amsdene30fab32007-03-05 00:30:39 -0800428static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100429{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800430 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100431}
432
433/* The paravirtualized CPUID instruction. */
434static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
435 unsigned int *ecx, unsigned int *edx)
436{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200437 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100438}
439
440/*
441 * These special macros can be used to get or set a debugging register
442 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200443static inline unsigned long paravirt_get_debugreg(int reg)
444{
445 return PVOP_CALL1(unsigned long, get_debugreg, reg);
446}
447#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
448static inline void set_debugreg(unsigned long val, int reg)
449{
450 PVOP_VCALL2(set_debugreg, reg, val);
451}
Rusty Russelld3561b72006-12-07 02:14:07 +0100452
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200453static inline void clts(void)
454{
455 PVOP_VCALL0(clts);
456}
Rusty Russelld3561b72006-12-07 02:14:07 +0100457
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200458static inline unsigned long read_cr0(void)
459{
460 return PVOP_CALL0(unsigned long, read_cr0);
461}
Rusty Russelld3561b72006-12-07 02:14:07 +0100462
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200463static inline void write_cr0(unsigned long x)
464{
465 PVOP_VCALL1(write_cr0, x);
466}
Rusty Russelld3561b72006-12-07 02:14:07 +0100467
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200468static inline unsigned long read_cr2(void)
469{
470 return PVOP_CALL0(unsigned long, read_cr2);
471}
Rusty Russelld3561b72006-12-07 02:14:07 +0100472
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200473static inline void write_cr2(unsigned long x)
474{
475 PVOP_VCALL1(write_cr2, x);
476}
Rusty Russelld3561b72006-12-07 02:14:07 +0100477
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200478static inline unsigned long read_cr3(void)
479{
480 return PVOP_CALL0(unsigned long, read_cr3);
481}
482
483static inline void write_cr3(unsigned long x)
484{
485 PVOP_VCALL1(write_cr3, x);
486}
487
488static inline unsigned long read_cr4(void)
489{
490 return PVOP_CALL0(unsigned long, read_cr4);
491}
492static inline unsigned long read_cr4_safe(void)
493{
494 return PVOP_CALL0(unsigned long, read_cr4_safe);
495}
496
497static inline void write_cr4(unsigned long x)
498{
499 PVOP_VCALL1(write_cr4, x);
500}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200501
Rusty Russelld3561b72006-12-07 02:14:07 +0100502static inline void raw_safe_halt(void)
503{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200504 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100505}
506
507static inline void halt(void)
508{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200509 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100510}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200511
512static inline void wbinvd(void)
513{
514 PVOP_VCALL0(wbinvd);
515}
Rusty Russelld3561b72006-12-07 02:14:07 +0100516
517#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
518
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200519static inline u64 paravirt_read_msr(unsigned msr, int *err)
520{
521 return PVOP_CALL2(u64, read_msr, msr, err);
522}
523static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
524{
525 return PVOP_CALL3(int, write_msr, msr, low, high);
526}
527
Rusty Russell90a0a062007-05-02 19:27:10 +0200528/* These should all do BUG_ON(_err), but our headers are too tangled. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200529#define rdmsr(msr,val1,val2) do { \
530 int _err; \
531 u64 _l = paravirt_read_msr(msr, &_err); \
532 val1 = (u32)_l; \
533 val2 = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100534} while(0)
535
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200536#define wrmsr(msr,val1,val2) do { \
537 paravirt_write_msr(msr, val1, val2); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100538} while(0)
539
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200540#define rdmsrl(msr,val) do { \
541 int _err; \
542 val = paravirt_read_msr(msr, &_err); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100543} while(0)
544
Björn Steinbrinkb9e36142007-06-25 23:04:37 +0200545#define wrmsrl(msr,val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200546#define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100547
548/* rdmsr with exception handling */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200549#define rdmsr_safe(msr,a,b) ({ \
550 int _err; \
551 u64 _l = paravirt_read_msr(msr, &_err); \
552 (*a) = (u32)_l; \
553 (*b) = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100554 _err; })
555
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200556
557static inline u64 paravirt_read_tsc(void)
558{
559 return PVOP_CALL0(u64, read_tsc);
560}
Rusty Russelld3561b72006-12-07 02:14:07 +0100561
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200562#define rdtscl(low) do { \
563 u64 _l = paravirt_read_tsc(); \
564 low = (int)_l; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100565} while(0)
566
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200567#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100568
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800569#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800570#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800571
Rusty Russelld3561b72006-12-07 02:14:07 +0100572#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
573
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200574static inline unsigned long long paravirt_read_pmc(int counter)
575{
576 return PVOP_CALL1(u64, read_pmc, counter);
577}
578
579#define rdpmc(counter,low,high) do { \
580 u64 _l = paravirt_read_pmc(counter); \
581 low = (u32)_l; \
582 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100583} while(0)
584
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200585static inline void load_TR_desc(void)
586{
587 PVOP_VCALL0(load_tr_desc);
588}
589static inline void load_gdt(const struct Xgt_desc_struct *dtr)
590{
591 PVOP_VCALL1(load_gdt, dtr);
592}
593static inline void load_idt(const struct Xgt_desc_struct *dtr)
594{
595 PVOP_VCALL1(load_idt, dtr);
596}
597static inline void set_ldt(const void *addr, unsigned entries)
598{
599 PVOP_VCALL2(set_ldt, addr, entries);
600}
601static inline void store_gdt(struct Xgt_desc_struct *dtr)
602{
603 PVOP_VCALL1(store_gdt, dtr);
604}
605static inline void store_idt(struct Xgt_desc_struct *dtr)
606{
607 PVOP_VCALL1(store_idt, dtr);
608}
609static inline unsigned long paravirt_store_tr(void)
610{
611 return PVOP_CALL0(unsigned long, store_tr);
612}
613#define store_tr(tr) ((tr) = paravirt_store_tr())
614static inline void load_TLS(struct thread_struct *t, unsigned cpu)
615{
616 PVOP_VCALL2(load_tls, t, cpu);
617}
618static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
619{
620 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
621}
622static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
623{
624 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
625}
626static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
627{
628 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
629}
630static inline void set_iopl_mask(unsigned mask)
631{
632 PVOP_VCALL1(set_iopl_mask, mask);
633}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200634
Rusty Russelld3561b72006-12-07 02:14:07 +0100635/* The paravirtualized I/O functions */
636static inline void slow_down_io(void) {
637 paravirt_ops.io_delay();
638#ifdef REALLY_SLOW_IO
639 paravirt_ops.io_delay();
640 paravirt_ops.io_delay();
641 paravirt_ops.io_delay();
642#endif
643}
644
Rusty Russell13623d72006-12-07 02:14:08 +0100645#ifdef CONFIG_X86_LOCAL_APIC
646/*
647 * Basic functions accessing APICs.
648 */
649static inline void apic_write(unsigned long reg, unsigned long v)
650{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200651 PVOP_VCALL2(apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100652}
653
654static inline void apic_write_atomic(unsigned long reg, unsigned long v)
655{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200656 PVOP_VCALL2(apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100657}
658
659static inline unsigned long apic_read(unsigned long reg)
660{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200661 return PVOP_CALL1(unsigned long, apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100662}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100663
664static inline void setup_boot_clock(void)
665{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200666 PVOP_VCALL0(setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100667}
668
669static inline void setup_secondary_clock(void)
670{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200671 PVOP_VCALL0(setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100672}
Rusty Russell13623d72006-12-07 02:14:08 +0100673#endif
674
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -0700675static inline void paravirt_post_allocator_init(void)
676{
677 if (paravirt_ops.post_allocator_init)
678 (*paravirt_ops.post_allocator_init)();
679}
680
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200681static inline void paravirt_pagetable_setup_start(pgd_t *base)
682{
683 if (paravirt_ops.pagetable_setup_start)
684 (*paravirt_ops.pagetable_setup_start)(base);
685}
686
687static inline void paravirt_pagetable_setup_done(pgd_t *base)
688{
689 if (paravirt_ops.pagetable_setup_done)
690 (*paravirt_ops.pagetable_setup_done)(base);
691}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200692
Zachary Amsdenae5da272007-02-13 13:26:21 +0100693#ifdef CONFIG_SMP
694static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
695 unsigned long start_esp)
696{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200697 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100698}
699#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100700
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200701static inline void paravirt_activate_mm(struct mm_struct *prev,
702 struct mm_struct *next)
703{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200704 PVOP_VCALL2(activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200705}
706
707static inline void arch_dup_mmap(struct mm_struct *oldmm,
708 struct mm_struct *mm)
709{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200710 PVOP_VCALL2(dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200711}
712
713static inline void arch_exit_mmap(struct mm_struct *mm)
714{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200715 PVOP_VCALL1(exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200716}
717
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200718static inline void __flush_tlb(void)
719{
720 PVOP_VCALL0(flush_tlb_user);
721}
722static inline void __flush_tlb_global(void)
723{
724 PVOP_VCALL0(flush_tlb_kernel);
725}
726static inline void __flush_tlb_single(unsigned long addr)
727{
728 PVOP_VCALL1(flush_tlb_single, addr);
729}
Rusty Russellda181a82006-12-07 02:14:08 +0100730
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200731static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
732 unsigned long va)
733{
734 PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va);
735}
736
Jeremy Fitzhardingefdb4c332007-07-17 18:37:03 -0700737static inline void paravirt_alloc_pt(struct mm_struct *mm, unsigned pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200738{
Jeremy Fitzhardingefdb4c332007-07-17 18:37:03 -0700739 PVOP_VCALL2(alloc_pt, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200740}
741static inline void paravirt_release_pt(unsigned pfn)
742{
743 PVOP_VCALL1(release_pt, pfn);
744}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100745
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200746static inline void paravirt_alloc_pd(unsigned pfn)
747{
748 PVOP_VCALL1(alloc_pd, pfn);
749}
750
751static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
752 unsigned start, unsigned count)
753{
754 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
755}
756static inline void paravirt_release_pd(unsigned pfn)
757{
758 PVOP_VCALL1(release_pd, pfn);
759}
760
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200761#ifdef CONFIG_HIGHPTE
762static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
763{
764 unsigned long ret;
765 ret = PVOP_CALL2(unsigned long, kmap_atomic_pte, page, type);
766 return (void *)ret;
767}
768#endif
769
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200770static inline void pte_update(struct mm_struct *mm, unsigned long addr,
771 pte_t *ptep)
772{
773 PVOP_VCALL3(pte_update, mm, addr, ptep);
774}
775
776static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
777 pte_t *ptep)
778{
779 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
780}
781
782#ifdef CONFIG_X86_PAE
783static inline pte_t __pte(unsigned long long val)
784{
785 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
786 val, val >> 32);
787 return (pte_t) { ret, ret >> 32 };
788}
789
790static inline pmd_t __pmd(unsigned long long val)
791{
792 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
793}
794
795static inline pgd_t __pgd(unsigned long long val)
796{
797 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
798}
799
800static inline unsigned long long pte_val(pte_t x)
801{
802 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
803}
804
805static inline unsigned long long pmd_val(pmd_t x)
806{
807 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
808}
809
810static inline unsigned long long pgd_val(pgd_t x)
811{
812 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
813}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100814
Rusty Russellda181a82006-12-07 02:14:08 +0100815static inline void set_pte(pte_t *ptep, pte_t pteval)
816{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200817 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
Rusty Russellda181a82006-12-07 02:14:08 +0100818}
819
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200820static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
821 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100822{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200823 /* 5 arg words */
Rusty Russellda181a82006-12-07 02:14:08 +0100824 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
825}
826
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200827static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
828{
829 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
830}
831
832static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
833 pte_t *ptep, pte_t pte)
834{
835 /* 5 arg words */
836 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
837}
838
Rusty Russellda181a82006-12-07 02:14:08 +0100839static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
840{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200841 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100842}
843
844static inline void set_pud(pud_t *pudp, pud_t pudval)
845{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200846 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100847}
848
849static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
850{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200851 PVOP_VCALL3(pte_clear, mm, addr, ptep);
Rusty Russellda181a82006-12-07 02:14:08 +0100852}
853
854static inline void pmd_clear(pmd_t *pmdp)
855{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200856 PVOP_VCALL1(pmd_clear, pmdp);
Rusty Russellda181a82006-12-07 02:14:08 +0100857}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200858
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200859#else /* !CONFIG_X86_PAE */
Jeremy Fitzhardinge4cdd9c82007-05-02 19:27:15 +0200860
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200861static inline pte_t __pte(unsigned long val)
862{
863 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
864}
865
866static inline pgd_t __pgd(unsigned long val)
867{
868 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
869}
870
871static inline unsigned long pte_val(pte_t x)
872{
873 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
874}
875
876static inline unsigned long pgd_val(pgd_t x)
877{
878 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
879}
880
881static inline void set_pte(pte_t *ptep, pte_t pteval)
882{
883 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
884}
885
886static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
887 pte_t *ptep, pte_t pteval)
888{
889 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
890}
891
892static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
893{
894 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
895}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200896#endif /* CONFIG_X86_PAE */
Rusty Russellda181a82006-12-07 02:14:08 +0100897
Zachary Amsden9226d122007-02-13 13:26:21 +0100898#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200899static inline void arch_enter_lazy_cpu_mode(void)
900{
901 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
902}
903
904static inline void arch_leave_lazy_cpu_mode(void)
905{
906 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
907}
908
909static inline void arch_flush_lazy_cpu_mode(void)
910{
911 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
912}
913
Zachary Amsden9226d122007-02-13 13:26:21 +0100914
915#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200916static inline void arch_enter_lazy_mmu_mode(void)
917{
918 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
919}
920
921static inline void arch_leave_lazy_mmu_mode(void)
922{
923 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
924}
925
926static inline void arch_flush_lazy_mmu_mode(void)
927{
928 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
929}
Zachary Amsden9226d122007-02-13 13:26:21 +0100930
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200931void _paravirt_nop(void);
932#define paravirt_nop ((void *)_paravirt_nop)
933
Rusty Russell139ec7c2006-12-07 02:14:08 +0100934/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200935struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +0100936 u8 *instr; /* original instructions */
937 u8 instrtype; /* type of this instruction */
938 u8 len; /* length of original instruction */
939 u16 clobbers; /* what registers you may clobber */
940};
941
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200942extern struct paravirt_patch_site __parainstructions[],
943 __parainstructions_end[];
944
Rusty Russell139ec7c2006-12-07 02:14:08 +0100945static inline unsigned long __raw_local_save_flags(void)
946{
947 unsigned long f;
948
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200949 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
950 PARAVIRT_CALL
951 "popl %%edx; popl %%ecx")
952 : "=a"(f)
953 : paravirt_type(save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200954 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200955 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100956 return f;
957}
958
959static inline void raw_local_irq_restore(unsigned long f)
960{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200961 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
962 PARAVIRT_CALL
963 "popl %%edx; popl %%ecx")
964 : "=a"(f)
965 : "0"(f),
966 paravirt_type(restore_fl),
967 paravirt_clobber(CLBR_EAX)
968 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100969}
970
971static inline void raw_local_irq_disable(void)
972{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200973 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
974 PARAVIRT_CALL
975 "popl %%edx; popl %%ecx")
976 :
977 : paravirt_type(irq_disable),
978 paravirt_clobber(CLBR_EAX)
979 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100980}
981
982static inline void raw_local_irq_enable(void)
983{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200984 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
985 PARAVIRT_CALL
986 "popl %%edx; popl %%ecx")
987 :
988 : paravirt_type(irq_enable),
989 paravirt_clobber(CLBR_EAX)
990 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100991}
992
993static inline unsigned long __raw_local_irq_save(void)
994{
995 unsigned long f;
996
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200997 f = __raw_local_save_flags();
998 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +0100999 return f;
1000}
1001
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001002#define CLI_STRING \
1003 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1004 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1005 "popl %%edx; popl %%ecx", \
1006 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
Rusty Russell139ec7c2006-12-07 02:14:08 +01001007
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001008#define STI_STRING \
1009 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1010 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1011 "popl %%edx; popl %%ecx", \
1012 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1013
Rusty Russell139ec7c2006-12-07 02:14:08 +01001014#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001015#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001016 , \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001017 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1018 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1019 paravirt_clobber(CLBR_EAX)
1020
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001021/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001022#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +02001023#undef __PVOP_CALL
1024#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001025#undef PVOP_VCALL0
1026#undef PVOP_CALL0
1027#undef PVOP_VCALL1
1028#undef PVOP_CALL1
1029#undef PVOP_VCALL2
1030#undef PVOP_CALL2
1031#undef PVOP_VCALL3
1032#undef PVOP_CALL3
1033#undef PVOP_VCALL4
1034#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001035
Rusty Russelld3561b72006-12-07 02:14:07 +01001036#else /* __ASSEMBLY__ */
1037
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001038#define PARA_PATCH(off) ((off) / 4)
1039
1040#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001041771:; \
1042 ops; \
1043772:; \
1044 .pushsection .parainstructions,"a"; \
1045 .long 771b; \
1046 .byte ptype; \
1047 .byte 772b-771b; \
1048 .short clobbers; \
1049 .popsection
1050
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001051#define INTERRUPT_RETURN \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001052 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001053 jmp *%cs:paravirt_ops+PARAVIRT_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001054
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001055#define DISABLE_INTERRUPTS(clobbers) \
1056 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001057 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001058 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001059 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001060
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001061#define ENABLE_INTERRUPTS(clobbers) \
1062 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001063 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001064 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001065 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001066
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001067#define ENABLE_INTERRUPTS_SYSEXIT \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001068 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001069 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001070
1071#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001072 push %ecx; push %edx; \
1073 call *paravirt_ops+PARAVIRT_read_cr0; \
1074 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +01001075
Rusty Russelld3561b72006-12-07 02:14:07 +01001076#endif /* __ASSEMBLY__ */
1077#endif /* CONFIG_PARAVIRT */
1078#endif /* __ASM_PARAVIRT_H */