blob: f880b06d6d568b10b8edd2bd33f6cff97620d0cd [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 Fitzhardinge3dc494e2007-05-02 19:27:13 +020019
Rusty Russelld3561b72006-12-07 02:14:07 +010020struct thread_struct;
21struct Xgt_desc_struct;
22struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010023struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020024struct desc_struct;
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020025
26/* Lazy mode for batching updates / context switch */
27enum paravirt_lazy_mode {
28 PARAVIRT_LAZY_NONE = 0,
29 PARAVIRT_LAZY_MMU = 1,
30 PARAVIRT_LAZY_CPU = 2,
31};
32
Rusty Russelld3561b72006-12-07 02:14:07 +010033struct paravirt_ops
34{
35 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020036 int shared_kernel_pmd;
Rusty Russelld3561b72006-12-07 02:14:07 +010037 int paravirt_enabled;
38 const char *name;
39
Rusty Russell139ec7c2006-12-07 02:14:08 +010040 /*
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.
46 */
47 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
48
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020049 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010050 void (*arch_setup)(void);
51 char *(*memory_setup)(void);
52 void (*init_IRQ)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020053 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010054
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020055 /*
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
59 * mapping.
60 */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +020061 void (*pagetable_setup_start)(pgd_t *pgd_base);
62 void (*pagetable_setup_done)(pgd_t *pgd_base);
63
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020064 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010065 void (*banner)(void);
66
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020067 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +010068 unsigned long (*get_wallclock)(void);
69 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010070
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020071 /* cpuid emulation, mostly so that caps bits can be disabled */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010072 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010073 unsigned int *ecx, unsigned int *edx);
74
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020075 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010076 unsigned long (*get_debugreg)(int regno);
77 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010078
Andi Kleen1a1eecd2007-02-13 13:26:25 +010079 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010080
Andi Kleen1a1eecd2007-02-13 13:26:25 +010081 unsigned long (*read_cr0)(void);
82 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010083
Andi Kleen1a1eecd2007-02-13 13:26:25 +010084 unsigned long (*read_cr2)(void);
85 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010086
Andi Kleen1a1eecd2007-02-13 13:26:25 +010087 unsigned long (*read_cr3)(void);
88 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010089
Andi Kleen1a1eecd2007-02-13 13:26:25 +010090 unsigned long (*read_cr4_safe)(void);
91 unsigned long (*read_cr4)(void);
92 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010093
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020094 /*
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
98 * restore_fl.
99 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100100 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);
105 void (*halt)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200106
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100107 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100108
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200109 /* MSR, PMC and TSR operations.
110 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100111 u64 (*read_msr)(unsigned int msr, int *err);
112 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +0100113
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100114 u64 (*read_tsc)(void);
115 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800116 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -0800117 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100118
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200119 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100120 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);
Rusty Russell90a0a062007-05-02 19:27:10 +0200128 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);
Rusty Russelld3561b72006-12-07 02:14:07 +0100135
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100136 void (*set_iopl_mask)(unsigned mask);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100137 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100138
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200139 /*
140 * Hooks for intercepting the creation/use/destruction of an
141 * mm_struct.
142 */
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200143 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);
148
Rusty Russell13623d72006-12-07 02:14:08 +0100149#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200150 /*
151 * Direct APIC operations, principally for VMI. Ideally
152 * these shouldn't be in this interface.
153 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100154 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);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100157 void (*setup_boot_clock)(void);
158 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200159
160 void (*startup_ipi_hook)(int phys_apicid,
161 unsigned long start_eip,
162 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100163#endif
164
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200165 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100166 void (*flush_tlb_user)(void);
167 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200168 void (*flush_tlb_single)(unsigned long addr);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200169 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
170 unsigned long va);
Rusty Russellda181a82006-12-07 02:14:08 +0100171
Al Viro192cd592007-03-14 09:18:09 +0000172 void (*map_pt_hook)(int type, pte_t *va, u32 pfn);
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800173
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200174 /* Hooks for allocating/releasing pagetable pages */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100175 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);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100180
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200181 /* Pagetable manipulation functions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100182 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200183 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
184 pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100185 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200186 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200187 void (*pte_update_defer)(struct mm_struct *mm,
188 unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200189
190 pte_t (*ptep_get_and_clear)(pte_t *ptep);
191
Rusty Russellda181a82006-12-07 02:14:08 +0100192#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100193 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200194 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100195 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200196 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100197 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200198
199 unsigned long long (*pte_val)(pte_t);
200 unsigned long long (*pmd_val)(pmd_t);
201 unsigned long long (*pgd_val)(pgd_t);
202
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);
206#else
207 unsigned long (*pte_val)(pte_t);
208 unsigned long (*pgd_val)(pgd_t);
209
210 pte_t (*make_pte)(unsigned long pte);
211 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100212#endif
213
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200214 /* Set deferred update mode, used for batching operations. */
215 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100216
Rusty Russelld3561b72006-12-07 02:14:07 +0100217 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100218 void (*irq_enable_sysexit)(void);
219 void (*iret)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100220};
221
Rusty Russellc9ccf302006-12-07 02:14:08 +0100222/* Mark a paravirt probe function. */
223#define paravirt_probe(fn) \
224 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
225 __attribute__((__section__(".paravirtprobe"))) = fn
226
Rusty Russelld3561b72006-12-07 02:14:07 +0100227extern 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
265
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200266/*
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.
271 */
272#define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
273
274/*
275 * These macros are intended to wrap calls into a paravirt_ops
276 * operation, so that they can be later identified and patched at
277 * runtime.
278 *
279 * Normally, a call to a pv_op function is a simple indirect call:
280 * (paravirt_ops.operations)(args...).
281 *
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.)
289 *
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).
295 *
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
300 * implementation.
301 *
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
306 * cumbersome.
307 *
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.
312 *
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
317 * 64-bit).
318 *
319 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
320 * in low,high order.
321 *
322 * Small structures are passed and returned in registers. The macro
323 * calling convention can't directly deal with this, so the wrapper
324 * functions must do this.
325 *
326 * These PVOP_* macros are only defined within this header. This
327 * means that all uses must be wrapped in inline functions. This also
328 * makes sure the incoming and outgoing types are always correct.
329 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200330#define PVOP_CALL0(__rettype, __op) \
331 ({ \
332 __rettype __ret; \
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) \
340 : "memory", "cc"); \
341 __ret = (__rettype)__tmp; \
342 } else { \
343 unsigned long __tmp, __edx, __ecx; \
344 asm volatile(paravirt_alt(PARAVIRT_CALL) \
345 : "=a" (__tmp), "=d" (__edx), \
346 "=c" (__ecx) \
347 : paravirt_type(__op), \
348 paravirt_clobber(CLBR_ANY) \
349 : "memory", "cc"); \
350 __ret = (__rettype)__tmp; \
351 } \
352 __ret; \
353 })
354#define PVOP_VCALL0(__op) \
355 ({ \
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) \
361 : "memory", "cc"); \
362 })
363
364#define PVOP_CALL1(__rettype, __op, arg1) \
365 ({ \
366 __rettype __ret; \
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) \
375 : "memory", "cc"); \
376 __ret = (__rettype)__tmp; \
377 } else { \
378 unsigned long __tmp, __edx, __ecx; \
379 asm volatile(paravirt_alt(PARAVIRT_CALL) \
380 : "=a" (__tmp), "=d" (__edx), \
381 "=c" (__ecx) \
382 : "0" ((u32)(arg1)), \
383 paravirt_type(__op), \
384 paravirt_clobber(CLBR_ANY) \
385 : "memory", "cc"); \
386 __ret = (__rettype)__tmp; \
387 } \
388 __ret; \
389 })
390#define PVOP_VCALL1(__op, arg1) \
391 ({ \
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) \
398 : "memory", "cc"); \
399 })
400
401#define PVOP_CALL2(__rettype, __op, arg1, arg2) \
402 ({ \
403 __rettype __ret; \
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)), \
410 "d" ((u32)(arg2)), \
411 paravirt_type(__op), \
412 paravirt_clobber(CLBR_ANY) \
413 : "memory", "cc"); \
414 __ret = (__rettype)__tmp; \
415 } else { \
416 unsigned long __tmp, __edx, __ecx; \
417 asm volatile(paravirt_alt(PARAVIRT_CALL) \
418 : "=a" (__tmp), "=d" (__edx), \
419 "=c" (__ecx) \
420 : "0" ((u32)(arg1)), \
421 "1" ((u32)(arg2)), \
422 paravirt_type(__op), \
423 paravirt_clobber(CLBR_ANY) \
424 : "memory", "cc"); \
425 __ret = (__rettype)__tmp; \
426 } \
427 __ret; \
428 })
429#define PVOP_VCALL2(__op, arg1, arg2) \
430 ({ \
431 unsigned long __eax, __edx, __ecx; \
432 asm volatile(paravirt_alt(PARAVIRT_CALL) \
433 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
434 : "0" ((u32)(arg1)), \
435 "1" ((u32)(arg2)), \
436 paravirt_type(__op), \
437 paravirt_clobber(CLBR_ANY) \
438 : "memory", "cc"); \
439 })
440
441#define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \
442 ({ \
443 __rettype __ret; \
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)), \
450 "d" ((u32)(arg2)), \
451 "1" ((u32)(arg3)), \
452 paravirt_type(__op), \
453 paravirt_clobber(CLBR_ANY) \
454 : "memory", "cc"); \
455 __ret = (__rettype)__tmp; \
456 } else { \
457 unsigned long __tmp, __edx, __ecx; \
458 asm volatile(paravirt_alt(PARAVIRT_CALL) \
459 : "=a" (__tmp), "=d" (__edx), \
460 "=c" (__ecx) \
461 : "0" ((u32)(arg1)), \
462 "1" ((u32)(arg2)), \
463 "2" ((u32)(arg3)), \
464 paravirt_type(__op), \
465 paravirt_clobber(CLBR_ANY) \
466 : "memory", "cc"); \
467 __ret = (__rettype)__tmp; \
468 } \
469 __ret; \
470 })
471#define PVOP_VCALL3(__op, arg1, arg2, arg3) \
472 ({ \
473 unsigned long __eax, __edx, __ecx; \
474 asm volatile(paravirt_alt(PARAVIRT_CALL) \
475 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
476 : "0" ((u32)(arg1)), \
477 "1" ((u32)(arg2)), \
478 "2" ((u32)(arg3)), \
479 paravirt_type(__op), \
480 paravirt_clobber(CLBR_ANY) \
481 : "memory", "cc"); \
482 })
483
484#define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \
485 ({ \
486 __rettype __ret; \
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)), \
495 "d" ((u32)(arg2)), \
496 "1" ((u32)(arg3)), \
497 [_arg4] "mr" ((u32)(arg4)), \
498 paravirt_type(__op), \
499 paravirt_clobber(CLBR_ANY) \
500 : "memory", "cc",); \
501 __ret = (__rettype)__tmp; \
502 } else { \
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)), \
509 "1" ((u32)(arg2)), \
510 "2" ((u32)(arg3)), \
511 [_arg4]"mr" ((u32)(arg4)), \
512 paravirt_type(__op), \
513 paravirt_clobber(CLBR_ANY) \
514 : "memory", "cc"); \
515 __ret = (__rettype)__tmp; \
516 } \
517 __ret; \
518 })
519#define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \
520 ({ \
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)), \
527 "1" ((u32)(arg2)), \
528 "2" ((u32)(arg3)), \
529 [_arg4]"mr" ((u32)(arg4)), \
530 paravirt_type(__op), \
531 paravirt_clobber(CLBR_ANY) \
532 : "memory", "cc"); \
533 })
534
535static inline int paravirt_enabled(void)
536{
537 return paravirt_ops.paravirt_enabled;
538}
Rusty Russelld3561b72006-12-07 02:14:07 +0100539
540static inline void load_esp0(struct tss_struct *tss,
541 struct thread_struct *thread)
542{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200543 PVOP_VCALL2(load_esp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100544}
545
546#define ARCH_SETUP paravirt_ops.arch_setup();
547static inline unsigned long get_wallclock(void)
548{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200549 return PVOP_CALL0(unsigned long, get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100550}
551
552static inline int set_wallclock(unsigned long nowtime)
553{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200554 return PVOP_CALL1(int, set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100555}
556
Zachary Amsdene30fab32007-03-05 00:30:39 -0800557static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100558{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800559 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100560}
561
562/* The paravirtualized CPUID instruction. */
563static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
564 unsigned int *ecx, unsigned int *edx)
565{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200566 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100567}
568
569/*
570 * These special macros can be used to get or set a debugging register
571 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200572static inline unsigned long paravirt_get_debugreg(int reg)
573{
574 return PVOP_CALL1(unsigned long, get_debugreg, reg);
575}
576#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
577static inline void set_debugreg(unsigned long val, int reg)
578{
579 PVOP_VCALL2(set_debugreg, reg, val);
580}
Rusty Russelld3561b72006-12-07 02:14:07 +0100581
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200582static inline void clts(void)
583{
584 PVOP_VCALL0(clts);
585}
Rusty Russelld3561b72006-12-07 02:14:07 +0100586
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200587static inline unsigned long read_cr0(void)
588{
589 return PVOP_CALL0(unsigned long, read_cr0);
590}
Rusty Russelld3561b72006-12-07 02:14:07 +0100591
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200592static inline void write_cr0(unsigned long x)
593{
594 PVOP_VCALL1(write_cr0, x);
595}
Rusty Russelld3561b72006-12-07 02:14:07 +0100596
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200597static inline unsigned long read_cr2(void)
598{
599 return PVOP_CALL0(unsigned long, read_cr2);
600}
Rusty Russelld3561b72006-12-07 02:14:07 +0100601
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200602static inline void write_cr2(unsigned long x)
603{
604 PVOP_VCALL1(write_cr2, x);
605}
Rusty Russelld3561b72006-12-07 02:14:07 +0100606
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200607static inline unsigned long read_cr3(void)
608{
609 return PVOP_CALL0(unsigned long, read_cr3);
610}
611
612static inline void write_cr3(unsigned long x)
613{
614 PVOP_VCALL1(write_cr3, x);
615}
616
617static inline unsigned long read_cr4(void)
618{
619 return PVOP_CALL0(unsigned long, read_cr4);
620}
621static inline unsigned long read_cr4_safe(void)
622{
623 return PVOP_CALL0(unsigned long, read_cr4_safe);
624}
625
626static inline void write_cr4(unsigned long x)
627{
628 PVOP_VCALL1(write_cr4, x);
629}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200630
Rusty Russelld3561b72006-12-07 02:14:07 +0100631static inline void raw_safe_halt(void)
632{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200633 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100634}
635
636static inline void halt(void)
637{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200638 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100639}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200640
641static inline void wbinvd(void)
642{
643 PVOP_VCALL0(wbinvd);
644}
Rusty Russelld3561b72006-12-07 02:14:07 +0100645
646#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
647
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200648static inline u64 paravirt_read_msr(unsigned msr, int *err)
649{
650 return PVOP_CALL2(u64, read_msr, msr, err);
651}
652static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
653{
654 return PVOP_CALL3(int, write_msr, msr, low, high);
655}
656
Rusty Russell90a0a062007-05-02 19:27:10 +0200657/* These should all do BUG_ON(_err), but our headers are too tangled. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200658#define rdmsr(msr,val1,val2) do { \
659 int _err; \
660 u64 _l = paravirt_read_msr(msr, &_err); \
661 val1 = (u32)_l; \
662 val2 = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100663} while(0)
664
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200665#define wrmsr(msr,val1,val2) do { \
666 paravirt_write_msr(msr, val1, val2); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100667} while(0)
668
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200669#define rdmsrl(msr,val) do { \
670 int _err; \
671 val = paravirt_read_msr(msr, &_err); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100672} while(0)
673
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200674#define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
675#define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100676
677/* rdmsr with exception handling */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200678#define rdmsr_safe(msr,a,b) ({ \
679 int _err; \
680 u64 _l = paravirt_read_msr(msr, &_err); \
681 (*a) = (u32)_l; \
682 (*b) = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100683 _err; })
684
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200685
686static inline u64 paravirt_read_tsc(void)
687{
688 return PVOP_CALL0(u64, read_tsc);
689}
690#define rdtsc(low,high) do { \
691 u64 _l = paravirt_read_tsc(); \
692 low = (u32)_l; \
693 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100694} while(0)
695
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200696#define rdtscl(low) do { \
697 u64 _l = paravirt_read_tsc(); \
698 low = (int)_l; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100699} while(0)
700
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200701#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100702
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800703#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800704#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800705
Rusty Russelld3561b72006-12-07 02:14:07 +0100706#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
707
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200708static inline unsigned long long paravirt_read_pmc(int counter)
709{
710 return PVOP_CALL1(u64, read_pmc, counter);
711}
712
713#define rdpmc(counter,low,high) do { \
714 u64 _l = paravirt_read_pmc(counter); \
715 low = (u32)_l; \
716 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100717} while(0)
718
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200719static inline void load_TR_desc(void)
720{
721 PVOP_VCALL0(load_tr_desc);
722}
723static inline void load_gdt(const struct Xgt_desc_struct *dtr)
724{
725 PVOP_VCALL1(load_gdt, dtr);
726}
727static inline void load_idt(const struct Xgt_desc_struct *dtr)
728{
729 PVOP_VCALL1(load_idt, dtr);
730}
731static inline void set_ldt(const void *addr, unsigned entries)
732{
733 PVOP_VCALL2(set_ldt, addr, entries);
734}
735static inline void store_gdt(struct Xgt_desc_struct *dtr)
736{
737 PVOP_VCALL1(store_gdt, dtr);
738}
739static inline void store_idt(struct Xgt_desc_struct *dtr)
740{
741 PVOP_VCALL1(store_idt, dtr);
742}
743static inline unsigned long paravirt_store_tr(void)
744{
745 return PVOP_CALL0(unsigned long, store_tr);
746}
747#define store_tr(tr) ((tr) = paravirt_store_tr())
748static inline void load_TLS(struct thread_struct *t, unsigned cpu)
749{
750 PVOP_VCALL2(load_tls, t, cpu);
751}
752static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
753{
754 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
755}
756static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
757{
758 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
759}
760static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
761{
762 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
763}
764static inline void set_iopl_mask(unsigned mask)
765{
766 PVOP_VCALL1(set_iopl_mask, mask);
767}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200768
Rusty Russelld3561b72006-12-07 02:14:07 +0100769/* The paravirtualized I/O functions */
770static 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();
776#endif
777}
778
Rusty Russell13623d72006-12-07 02:14:08 +0100779#ifdef CONFIG_X86_LOCAL_APIC
780/*
781 * Basic functions accessing APICs.
782 */
783static inline void apic_write(unsigned long reg, unsigned long v)
784{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200785 PVOP_VCALL2(apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100786}
787
788static inline void apic_write_atomic(unsigned long reg, unsigned long v)
789{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200790 PVOP_VCALL2(apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100791}
792
793static inline unsigned long apic_read(unsigned long reg)
794{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200795 return PVOP_CALL1(unsigned long, apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100796}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100797
798static inline void setup_boot_clock(void)
799{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200800 PVOP_VCALL0(setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100801}
802
803static inline void setup_secondary_clock(void)
804{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200805 PVOP_VCALL0(setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100806}
Rusty Russell13623d72006-12-07 02:14:08 +0100807#endif
808
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200809static inline void paravirt_pagetable_setup_start(pgd_t *base)
810{
811 if (paravirt_ops.pagetable_setup_start)
812 (*paravirt_ops.pagetable_setup_start)(base);
813}
814
815static inline void paravirt_pagetable_setup_done(pgd_t *base)
816{
817 if (paravirt_ops.pagetable_setup_done)
818 (*paravirt_ops.pagetable_setup_done)(base);
819}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200820
Zachary Amsdenae5da272007-02-13 13:26:21 +0100821#ifdef CONFIG_SMP
822static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
823 unsigned long start_esp)
824{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200825 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100826}
827#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100828
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200829static inline void paravirt_activate_mm(struct mm_struct *prev,
830 struct mm_struct *next)
831{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200832 PVOP_VCALL2(activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200833}
834
835static inline void arch_dup_mmap(struct mm_struct *oldmm,
836 struct mm_struct *mm)
837{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200838 PVOP_VCALL2(dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200839}
840
841static inline void arch_exit_mmap(struct mm_struct *mm)
842{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200843 PVOP_VCALL1(exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200844}
845
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200846static inline void __flush_tlb(void)
847{
848 PVOP_VCALL0(flush_tlb_user);
849}
850static inline void __flush_tlb_global(void)
851{
852 PVOP_VCALL0(flush_tlb_kernel);
853}
854static inline void __flush_tlb_single(unsigned long addr)
855{
856 PVOP_VCALL1(flush_tlb_single, addr);
857}
Rusty Russellda181a82006-12-07 02:14:08 +0100858
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200859static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
860 unsigned long va)
861{
862 PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va);
863}
864
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200865static inline void paravirt_map_pt_hook(int type, pte_t *va, u32 pfn)
866{
867 PVOP_VCALL3(map_pt_hook, type, va, pfn);
868}
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800869
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200870static inline void paravirt_alloc_pt(unsigned pfn)
871{
872 PVOP_VCALL1(alloc_pt, pfn);
873}
874static inline void paravirt_release_pt(unsigned pfn)
875{
876 PVOP_VCALL1(release_pt, pfn);
877}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100878
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200879static inline void paravirt_alloc_pd(unsigned pfn)
880{
881 PVOP_VCALL1(alloc_pd, pfn);
882}
883
884static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
885 unsigned start, unsigned count)
886{
887 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
888}
889static inline void paravirt_release_pd(unsigned pfn)
890{
891 PVOP_VCALL1(release_pd, pfn);
892}
893
894static inline void pte_update(struct mm_struct *mm, unsigned long addr,
895 pte_t *ptep)
896{
897 PVOP_VCALL3(pte_update, mm, addr, ptep);
898}
899
900static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
901 pte_t *ptep)
902{
903 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
904}
905
906#ifdef CONFIG_X86_PAE
907static inline pte_t __pte(unsigned long long val)
908{
909 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
910 val, val >> 32);
911 return (pte_t) { ret, ret >> 32 };
912}
913
914static inline pmd_t __pmd(unsigned long long val)
915{
916 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
917}
918
919static inline pgd_t __pgd(unsigned long long val)
920{
921 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
922}
923
924static inline unsigned long long pte_val(pte_t x)
925{
926 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
927}
928
929static inline unsigned long long pmd_val(pmd_t x)
930{
931 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
932}
933
934static inline unsigned long long pgd_val(pgd_t x)
935{
936 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
937}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100938
Rusty Russellda181a82006-12-07 02:14:08 +0100939static inline void set_pte(pte_t *ptep, pte_t pteval)
940{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200941 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
Rusty Russellda181a82006-12-07 02:14:08 +0100942}
943
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200944static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
945 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100946{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200947 /* 5 arg words */
Rusty Russellda181a82006-12-07 02:14:08 +0100948 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
949}
950
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200951static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
952{
953 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
954}
955
956static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
957 pte_t *ptep, pte_t pte)
958{
959 /* 5 arg words */
960 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
961}
962
Rusty Russellda181a82006-12-07 02:14:08 +0100963static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
964{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200965 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100966}
967
968static inline void set_pud(pud_t *pudp, pud_t pudval)
969{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200970 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100971}
972
973static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
974{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200975 PVOP_VCALL3(pte_clear, mm, addr, ptep);
Rusty Russellda181a82006-12-07 02:14:08 +0100976}
977
978static inline void pmd_clear(pmd_t *pmdp)
979{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200980 PVOP_VCALL1(pmd_clear, pmdp);
Rusty Russellda181a82006-12-07 02:14:08 +0100981}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200982
983static inline pte_t raw_ptep_get_and_clear(pte_t *p)
984{
985 unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
986 return (pte_t) { val, val >> 32 };
987}
988#else /* !CONFIG_X86_PAE */
989static inline pte_t __pte(unsigned long val)
990{
991 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
992}
993
994static inline pgd_t __pgd(unsigned long val)
995{
996 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
997}
998
999static inline unsigned long pte_val(pte_t x)
1000{
1001 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
1002}
1003
1004static inline unsigned long pgd_val(pgd_t x)
1005{
1006 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
1007}
1008
1009static inline void set_pte(pte_t *ptep, pte_t pteval)
1010{
1011 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
1012}
1013
1014static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1015 pte_t *ptep, pte_t pteval)
1016{
1017 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
1018}
1019
1020static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
1021{
1022 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
1023}
1024
1025static inline pte_t raw_ptep_get_and_clear(pte_t *p)
1026{
1027 return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
1028}
1029#endif /* CONFIG_X86_PAE */
Rusty Russellda181a82006-12-07 02:14:08 +01001030
Zachary Amsden9226d122007-02-13 13:26:21 +01001031/* 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
Zachary Amsden49f19712007-04-08 16:04:01 -07001035#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +01001036
1037#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001038static inline void arch_enter_lazy_cpu_mode(void)
1039{
1040 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
1041}
1042
1043static inline void arch_leave_lazy_cpu_mode(void)
1044{
1045 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1046}
1047
1048static inline void arch_flush_lazy_cpu_mode(void)
1049{
1050 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1051}
1052
Zachary Amsden9226d122007-02-13 13:26:21 +01001053
1054#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001055static inline void arch_enter_lazy_mmu_mode(void)
1056{
1057 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
1058}
1059
1060static inline void arch_leave_lazy_mmu_mode(void)
1061{
1062 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1063}
1064
1065static inline void arch_flush_lazy_mmu_mode(void)
1066{
1067 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1068}
Zachary Amsden9226d122007-02-13 13:26:21 +01001069
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +02001070void _paravirt_nop(void);
1071#define paravirt_nop ((void *)_paravirt_nop)
1072
Rusty Russell139ec7c2006-12-07 02:14:08 +01001073/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001074struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +01001075 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 */
1079};
1080
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001081extern struct paravirt_patch_site __parainstructions[],
1082 __parainstructions_end[];
1083
Rusty Russell139ec7c2006-12-07 02:14:08 +01001084static inline unsigned long __raw_local_save_flags(void)
1085{
1086 unsigned long f;
1087
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001088 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1089 PARAVIRT_CALL
1090 "popl %%edx; popl %%ecx")
1091 : "=a"(f)
1092 : paravirt_type(save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001093 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001094 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001095 return f;
1096}
1097
1098static inline void raw_local_irq_restore(unsigned long f)
1099{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001100 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1101 PARAVIRT_CALL
1102 "popl %%edx; popl %%ecx")
1103 : "=a"(f)
1104 : "0"(f),
1105 paravirt_type(restore_fl),
1106 paravirt_clobber(CLBR_EAX)
1107 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001108}
1109
1110static inline void raw_local_irq_disable(void)
1111{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001112 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1113 PARAVIRT_CALL
1114 "popl %%edx; popl %%ecx")
1115 :
1116 : paravirt_type(irq_disable),
1117 paravirt_clobber(CLBR_EAX)
1118 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001119}
1120
1121static inline void raw_local_irq_enable(void)
1122{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001123 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1124 PARAVIRT_CALL
1125 "popl %%edx; popl %%ecx")
1126 :
1127 : paravirt_type(irq_enable),
1128 paravirt_clobber(CLBR_EAX)
1129 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001130}
1131
1132static inline unsigned long __raw_local_irq_save(void)
1133{
1134 unsigned long f;
1135
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001136 f = __raw_local_save_flags();
1137 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001138 return f;
1139}
1140
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001141#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]")
Rusty Russell139ec7c2006-12-07 02:14:08 +01001146
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001147#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]")
1152
Rusty Russell139ec7c2006-12-07 02:14:08 +01001153#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001154#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001155 , \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001156 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1157 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1158 paravirt_clobber(CLBR_EAX)
1159
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001160/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001161#undef PARAVIRT_CALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001162#undef PVOP_VCALL0
1163#undef PVOP_CALL0
1164#undef PVOP_VCALL1
1165#undef PVOP_CALL1
1166#undef PVOP_VCALL2
1167#undef PVOP_CALL2
1168#undef PVOP_VCALL3
1169#undef PVOP_CALL3
1170#undef PVOP_VCALL4
1171#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001172
Rusty Russelld3561b72006-12-07 02:14:07 +01001173#else /* __ASSEMBLY__ */
1174
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001175#define PARA_PATCH(off) ((off) / 4)
1176
1177#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001178771:; \
1179 ops; \
1180772:; \
1181 .pushsection .parainstructions,"a"; \
1182 .long 771b; \
1183 .byte ptype; \
1184 .byte 772b-771b; \
1185 .short clobbers; \
1186 .popsection
1187
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001188#define INTERRUPT_RETURN \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001189 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001190 jmp *%cs:paravirt_ops+PARAVIRT_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001191
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001192#define DISABLE_INTERRUPTS(clobbers) \
1193 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001194 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001195 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001196 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001197
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001198#define ENABLE_INTERRUPTS(clobbers) \
1199 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001200 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001201 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001202 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001203
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001204#define ENABLE_INTERRUPTS_SYSEXIT \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001205 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001206 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001207
1208#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001209 push %ecx; push %edx; \
1210 call *paravirt_ops+PARAVIRT_read_cr0; \
1211 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +01001212
Rusty Russelld3561b72006-12-07 02:14:07 +01001213#endif /* __ASSEMBLY__ */
1214#endif /* CONFIG_PARAVIRT */
1215#endif /* __ASM_PARAVIRT_H */