blob: 8bfaf10d99612e5b1a7920f0ef90e8633287e97c [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>
18
Rusty Russelld3561b72006-12-07 02:14:07 +010019struct thread_struct;
20struct Xgt_desc_struct;
21struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010022struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020023struct desc_struct;
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020024
25/* Lazy mode for batching updates / context switch */
26enum paravirt_lazy_mode {
27 PARAVIRT_LAZY_NONE = 0,
28 PARAVIRT_LAZY_MMU = 1,
29 PARAVIRT_LAZY_CPU = 2,
30};
31
Rusty Russelld3561b72006-12-07 02:14:07 +010032struct paravirt_ops
33{
34 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020035 int shared_kernel_pmd;
Rusty Russelld3561b72006-12-07 02:14:07 +010036 int paravirt_enabled;
37 const char *name;
38
Rusty Russell139ec7c2006-12-07 02:14:08 +010039 /*
40 * Patch may replace one of the defined code sequences with arbitrary
41 * code, subject to the same register constraints. This generally
42 * means the code is not free to clobber any registers other than EAX.
43 * The patch function should return the number of bytes of code
44 * generated, as we nop pad the rest in generic code.
45 */
46 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
47
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020048 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010049 void (*arch_setup)(void);
50 char *(*memory_setup)(void);
51 void (*init_IRQ)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020052 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010053
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020054 /*
55 * Called before/after init_mm pagetable setup. setup_start
56 * may reset %cr3, and may pre-install parts of the pagetable;
57 * pagetable setup is expected to preserve any existing
58 * mapping.
59 */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +020060 void (*pagetable_setup_start)(pgd_t *pgd_base);
61 void (*pagetable_setup_done)(pgd_t *pgd_base);
62
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020063 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010064 void (*banner)(void);
65
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020066 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +010067 unsigned long (*get_wallclock)(void);
68 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010069
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020070 /* cpuid emulation, mostly so that caps bits can be disabled */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010071 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010072 unsigned int *ecx, unsigned int *edx);
73
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020074 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010075 unsigned long (*get_debugreg)(int regno);
76 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010077
Andi Kleen1a1eecd2007-02-13 13:26:25 +010078 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010079
Andi Kleen1a1eecd2007-02-13 13:26:25 +010080 unsigned long (*read_cr0)(void);
81 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010082
Andi Kleen1a1eecd2007-02-13 13:26:25 +010083 unsigned long (*read_cr2)(void);
84 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010085
Andi Kleen1a1eecd2007-02-13 13:26:25 +010086 unsigned long (*read_cr3)(void);
87 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010088
Andi Kleen1a1eecd2007-02-13 13:26:25 +010089 unsigned long (*read_cr4_safe)(void);
90 unsigned long (*read_cr4)(void);
91 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010092
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020093 /*
94 * Get/set interrupt state. save_fl and restore_fl are only
95 * expected to use X86_EFLAGS_IF; all other bits
96 * returned from save_fl are undefined, and may be ignored by
97 * restore_fl.
98 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010099 unsigned long (*save_fl)(void);
100 void (*restore_fl)(unsigned long);
101 void (*irq_disable)(void);
102 void (*irq_enable)(void);
103 void (*safe_halt)(void);
104 void (*halt)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200105
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100106 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100107
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200108 /* MSR, PMC and TSR operations.
109 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100110 u64 (*read_msr)(unsigned int msr, int *err);
111 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +0100112
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100113 u64 (*read_tsc)(void);
114 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800115 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -0800116 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100117
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200118 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100119 void (*load_tr_desc)(void);
120 void (*load_gdt)(const struct Xgt_desc_struct *);
121 void (*load_idt)(const struct Xgt_desc_struct *);
122 void (*store_gdt)(struct Xgt_desc_struct *);
123 void (*store_idt)(struct Xgt_desc_struct *);
124 void (*set_ldt)(const void *desc, unsigned entries);
125 unsigned long (*store_tr)(void);
126 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +0200127 void (*write_ldt_entry)(struct desc_struct *,
128 int entrynum, u32 low, u32 high);
129 void (*write_gdt_entry)(struct desc_struct *,
130 int entrynum, u32 low, u32 high);
131 void (*write_idt_entry)(struct desc_struct *,
132 int entrynum, u32 low, u32 high);
133 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100134
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100135 void (*set_iopl_mask)(unsigned mask);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100136 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100137
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200138 /*
139 * Hooks for intercepting the creation/use/destruction of an
140 * mm_struct.
141 */
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200142 void (*activate_mm)(struct mm_struct *prev,
143 struct mm_struct *next);
144 void (*dup_mmap)(struct mm_struct *oldmm,
145 struct mm_struct *mm);
146 void (*exit_mmap)(struct mm_struct *mm);
147
Rusty Russell13623d72006-12-07 02:14:08 +0100148#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200149 /*
150 * Direct APIC operations, principally for VMI. Ideally
151 * these shouldn't be in this interface.
152 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100153 void (*apic_write)(unsigned long reg, unsigned long v);
154 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
155 unsigned long (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100156 void (*setup_boot_clock)(void);
157 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200158
159 void (*startup_ipi_hook)(int phys_apicid,
160 unsigned long start_eip,
161 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100162#endif
163
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200164 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100165 void (*flush_tlb_user)(void);
166 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200167 void (*flush_tlb_single)(unsigned long addr);
Rusty Russellda181a82006-12-07 02:14:08 +0100168
Al Viro192cd592007-03-14 09:18:09 +0000169 void (*map_pt_hook)(int type, pte_t *va, u32 pfn);
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800170
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200171 /* Hooks for allocating/releasing pagetable pages */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100172 void (*alloc_pt)(u32 pfn);
173 void (*alloc_pd)(u32 pfn);
174 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
175 void (*release_pt)(u32 pfn);
176 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100177
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200178 /* Pagetable manipulation functions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100179 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200180 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
181 pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100182 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200183 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200184 void (*pte_update_defer)(struct mm_struct *mm,
185 unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200186
187 pte_t (*ptep_get_and_clear)(pte_t *ptep);
188
Rusty Russellda181a82006-12-07 02:14:08 +0100189#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100190 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200191 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100192 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200193 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100194 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200195
196 unsigned long long (*pte_val)(pte_t);
197 unsigned long long (*pmd_val)(pmd_t);
198 unsigned long long (*pgd_val)(pgd_t);
199
200 pte_t (*make_pte)(unsigned long long pte);
201 pmd_t (*make_pmd)(unsigned long long pmd);
202 pgd_t (*make_pgd)(unsigned long long pgd);
203#else
204 unsigned long (*pte_val)(pte_t);
205 unsigned long (*pgd_val)(pgd_t);
206
207 pte_t (*make_pte)(unsigned long pte);
208 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100209#endif
210
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200211 /* Set deferred update mode, used for batching operations. */
212 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100213
Rusty Russelld3561b72006-12-07 02:14:07 +0100214 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100215 void (*irq_enable_sysexit)(void);
216 void (*iret)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100217};
218
Rusty Russellc9ccf302006-12-07 02:14:08 +0100219/* Mark a paravirt probe function. */
220#define paravirt_probe(fn) \
221 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
222 __attribute__((__section__(".paravirtprobe"))) = fn
223
Rusty Russelld3561b72006-12-07 02:14:07 +0100224extern struct paravirt_ops paravirt_ops;
225
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200226#define PARAVIRT_PATCH(x) \
227 (offsetof(struct paravirt_ops, x) / sizeof(void *))
228
229#define paravirt_type(type) \
230 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
231#define paravirt_clobber(clobber) \
232 [paravirt_clobber] "i" (clobber)
233
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200234/*
235 * Generate some code, and mark it as patchable by the
236 * apply_paravirt() alternate instruction patcher.
237 */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200238#define _paravirt_alt(insn_string, type, clobber) \
239 "771:\n\t" insn_string "\n" "772:\n" \
240 ".pushsection .parainstructions,\"a\"\n" \
241 " .long 771b\n" \
242 " .byte " type "\n" \
243 " .byte 772b-771b\n" \
244 " .short " clobber "\n" \
245 ".popsection\n"
246
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200247/* Generate patchable code, with the default asm parameters. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200248#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200249 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
250
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200251/*
252 * This generates an indirect call based on the operation type number.
253 * The type number, computed in PARAVIRT_PATCH, is derived from the
254 * offset into the paravirt_ops structure, and can therefore be freely
255 * converted back into a structure offset.
256 */
257#define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
258
259/*
260 * These macros are intended to wrap calls into a paravirt_ops
261 * operation, so that they can be later identified and patched at
262 * runtime.
263 *
264 * Normally, a call to a pv_op function is a simple indirect call:
265 * (paravirt_ops.operations)(args...).
266 *
267 * Unfortunately, this is a relatively slow operation for modern CPUs,
268 * because it cannot necessarily determine what the destination
269 * address is. In this case, the address is a runtime constant, so at
270 * the very least we can patch the call to e a simple direct call, or
271 * ideally, patch an inline implementation into the callsite. (Direct
272 * calls are essentially free, because the call and return addresses
273 * are completely predictable.)
274 *
275 * These macros rely on the standard gcc "regparm(3)" calling
276 * convention, in which the first three arguments are placed in %eax,
277 * %edx, %ecx (in that order), and the remaining arguments are placed
278 * on the stack. All caller-save registers (eax,edx,ecx) are expected
279 * to be modified (either clobbered or used for return values).
280 *
281 * The call instruction itself is marked by placing its start address
282 * and size into the .parainstructions section, so that
283 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
284 * appropriate patching under the control of the backend paravirt_ops
285 * implementation.
286 *
287 * Unfortunately there's no way to get gcc to generate the args setup
288 * for the call, and then allow the call itself to be generated by an
289 * inline asm. Because of this, we must do the complete arg setup and
290 * return value handling from within these macros. This is fairly
291 * cumbersome.
292 *
293 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
294 * It could be extended to more arguments, but there would be little
295 * to be gained from that. For each number of arguments, there are
296 * the two VCALL and CALL variants for void and non-void functions.
297 *
298 * When there is a return value, the invoker of the macro must specify
299 * the return type. The macro then uses sizeof() on that type to
300 * determine whether its a 32 or 64 bit value, and places the return
301 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
302 * 64-bit).
303 *
304 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
305 * in low,high order.
306 *
307 * Small structures are passed and returned in registers. The macro
308 * calling convention can't directly deal with this, so the wrapper
309 * functions must do this.
310 *
311 * These PVOP_* macros are only defined within this header. This
312 * means that all uses must be wrapped in inline functions. This also
313 * makes sure the incoming and outgoing types are always correct.
314 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200315#define PVOP_CALL0(__rettype, __op) \
316 ({ \
317 __rettype __ret; \
318 if (sizeof(__rettype) > sizeof(unsigned long)) { \
319 unsigned long long __tmp; \
320 unsigned long __ecx; \
321 asm volatile(paravirt_alt(PARAVIRT_CALL) \
322 : "=A" (__tmp), "=c" (__ecx) \
323 : paravirt_type(__op), \
324 paravirt_clobber(CLBR_ANY) \
325 : "memory", "cc"); \
326 __ret = (__rettype)__tmp; \
327 } else { \
328 unsigned long __tmp, __edx, __ecx; \
329 asm volatile(paravirt_alt(PARAVIRT_CALL) \
330 : "=a" (__tmp), "=d" (__edx), \
331 "=c" (__ecx) \
332 : paravirt_type(__op), \
333 paravirt_clobber(CLBR_ANY) \
334 : "memory", "cc"); \
335 __ret = (__rettype)__tmp; \
336 } \
337 __ret; \
338 })
339#define PVOP_VCALL0(__op) \
340 ({ \
341 unsigned long __eax, __edx, __ecx; \
342 asm volatile(paravirt_alt(PARAVIRT_CALL) \
343 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
344 : paravirt_type(__op), \
345 paravirt_clobber(CLBR_ANY) \
346 : "memory", "cc"); \
347 })
348
349#define PVOP_CALL1(__rettype, __op, arg1) \
350 ({ \
351 __rettype __ret; \
352 if (sizeof(__rettype) > sizeof(unsigned long)) { \
353 unsigned long long __tmp; \
354 unsigned long __ecx; \
355 asm volatile(paravirt_alt(PARAVIRT_CALL) \
356 : "=A" (__tmp), "=c" (__ecx) \
357 : "a" ((u32)(arg1)), \
358 paravirt_type(__op), \
359 paravirt_clobber(CLBR_ANY) \
360 : "memory", "cc"); \
361 __ret = (__rettype)__tmp; \
362 } else { \
363 unsigned long __tmp, __edx, __ecx; \
364 asm volatile(paravirt_alt(PARAVIRT_CALL) \
365 : "=a" (__tmp), "=d" (__edx), \
366 "=c" (__ecx) \
367 : "0" ((u32)(arg1)), \
368 paravirt_type(__op), \
369 paravirt_clobber(CLBR_ANY) \
370 : "memory", "cc"); \
371 __ret = (__rettype)__tmp; \
372 } \
373 __ret; \
374 })
375#define PVOP_VCALL1(__op, arg1) \
376 ({ \
377 unsigned long __eax, __edx, __ecx; \
378 asm volatile(paravirt_alt(PARAVIRT_CALL) \
379 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
380 : "0" ((u32)(arg1)), \
381 paravirt_type(__op), \
382 paravirt_clobber(CLBR_ANY) \
383 : "memory", "cc"); \
384 })
385
386#define PVOP_CALL2(__rettype, __op, arg1, arg2) \
387 ({ \
388 __rettype __ret; \
389 if (sizeof(__rettype) > sizeof(unsigned long)) { \
390 unsigned long long __tmp; \
391 unsigned long __ecx; \
392 asm volatile(paravirt_alt(PARAVIRT_CALL) \
393 : "=A" (__tmp), "=c" (__ecx) \
394 : "a" ((u32)(arg1)), \
395 "d" ((u32)(arg2)), \
396 paravirt_type(__op), \
397 paravirt_clobber(CLBR_ANY) \
398 : "memory", "cc"); \
399 __ret = (__rettype)__tmp; \
400 } else { \
401 unsigned long __tmp, __edx, __ecx; \
402 asm volatile(paravirt_alt(PARAVIRT_CALL) \
403 : "=a" (__tmp), "=d" (__edx), \
404 "=c" (__ecx) \
405 : "0" ((u32)(arg1)), \
406 "1" ((u32)(arg2)), \
407 paravirt_type(__op), \
408 paravirt_clobber(CLBR_ANY) \
409 : "memory", "cc"); \
410 __ret = (__rettype)__tmp; \
411 } \
412 __ret; \
413 })
414#define PVOP_VCALL2(__op, arg1, arg2) \
415 ({ \
416 unsigned long __eax, __edx, __ecx; \
417 asm volatile(paravirt_alt(PARAVIRT_CALL) \
418 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
419 : "0" ((u32)(arg1)), \
420 "1" ((u32)(arg2)), \
421 paravirt_type(__op), \
422 paravirt_clobber(CLBR_ANY) \
423 : "memory", "cc"); \
424 })
425
426#define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \
427 ({ \
428 __rettype __ret; \
429 if (sizeof(__rettype) > sizeof(unsigned long)) { \
430 unsigned long long __tmp; \
431 unsigned long __ecx; \
432 asm volatile(paravirt_alt(PARAVIRT_CALL) \
433 : "=A" (__tmp), "=c" (__ecx) \
434 : "a" ((u32)(arg1)), \
435 "d" ((u32)(arg2)), \
436 "1" ((u32)(arg3)), \
437 paravirt_type(__op), \
438 paravirt_clobber(CLBR_ANY) \
439 : "memory", "cc"); \
440 __ret = (__rettype)__tmp; \
441 } else { \
442 unsigned long __tmp, __edx, __ecx; \
443 asm volatile(paravirt_alt(PARAVIRT_CALL) \
444 : "=a" (__tmp), "=d" (__edx), \
445 "=c" (__ecx) \
446 : "0" ((u32)(arg1)), \
447 "1" ((u32)(arg2)), \
448 "2" ((u32)(arg3)), \
449 paravirt_type(__op), \
450 paravirt_clobber(CLBR_ANY) \
451 : "memory", "cc"); \
452 __ret = (__rettype)__tmp; \
453 } \
454 __ret; \
455 })
456#define PVOP_VCALL3(__op, arg1, arg2, arg3) \
457 ({ \
458 unsigned long __eax, __edx, __ecx; \
459 asm volatile(paravirt_alt(PARAVIRT_CALL) \
460 : "=a" (__eax), "=d" (__edx), "=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 })
468
469#define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \
470 ({ \
471 __rettype __ret; \
472 if (sizeof(__rettype) > sizeof(unsigned long)) { \
473 unsigned long long __tmp; \
474 unsigned long __ecx; \
475 asm volatile("push %[_arg4]; " \
476 paravirt_alt(PARAVIRT_CALL) \
477 "lea 4(%%esp),%%esp" \
478 : "=A" (__tmp), "=c" (__ecx) \
479 : "a" ((u32)(arg1)), \
480 "d" ((u32)(arg2)), \
481 "1" ((u32)(arg3)), \
482 [_arg4] "mr" ((u32)(arg4)), \
483 paravirt_type(__op), \
484 paravirt_clobber(CLBR_ANY) \
485 : "memory", "cc",); \
486 __ret = (__rettype)__tmp; \
487 } else { \
488 unsigned long __tmp, __edx, __ecx; \
489 asm volatile("push %[_arg4]; " \
490 paravirt_alt(PARAVIRT_CALL) \
491 "lea 4(%%esp),%%esp" \
492 : "=a" (__tmp), "=d" (__edx), "=c" (__ecx) \
493 : "0" ((u32)(arg1)), \
494 "1" ((u32)(arg2)), \
495 "2" ((u32)(arg3)), \
496 [_arg4]"mr" ((u32)(arg4)), \
497 paravirt_type(__op), \
498 paravirt_clobber(CLBR_ANY) \
499 : "memory", "cc"); \
500 __ret = (__rettype)__tmp; \
501 } \
502 __ret; \
503 })
504#define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \
505 ({ \
506 unsigned long __eax, __edx, __ecx; \
507 asm volatile("push %[_arg4]; " \
508 paravirt_alt(PARAVIRT_CALL) \
509 "lea 4(%%esp),%%esp" \
510 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
511 : "0" ((u32)(arg1)), \
512 "1" ((u32)(arg2)), \
513 "2" ((u32)(arg3)), \
514 [_arg4]"mr" ((u32)(arg4)), \
515 paravirt_type(__op), \
516 paravirt_clobber(CLBR_ANY) \
517 : "memory", "cc"); \
518 })
519
520static inline int paravirt_enabled(void)
521{
522 return paravirt_ops.paravirt_enabled;
523}
Rusty Russelld3561b72006-12-07 02:14:07 +0100524
525static inline void load_esp0(struct tss_struct *tss,
526 struct thread_struct *thread)
527{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200528 PVOP_VCALL2(load_esp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100529}
530
531#define ARCH_SETUP paravirt_ops.arch_setup();
532static inline unsigned long get_wallclock(void)
533{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200534 return PVOP_CALL0(unsigned long, get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100535}
536
537static inline int set_wallclock(unsigned long nowtime)
538{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200539 return PVOP_CALL1(int, set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100540}
541
Zachary Amsdene30fab32007-03-05 00:30:39 -0800542static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100543{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800544 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100545}
546
547/* The paravirtualized CPUID instruction. */
548static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
549 unsigned int *ecx, unsigned int *edx)
550{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200551 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100552}
553
554/*
555 * These special macros can be used to get or set a debugging register
556 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200557static inline unsigned long paravirt_get_debugreg(int reg)
558{
559 return PVOP_CALL1(unsigned long, get_debugreg, reg);
560}
561#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
562static inline void set_debugreg(unsigned long val, int reg)
563{
564 PVOP_VCALL2(set_debugreg, reg, val);
565}
Rusty Russelld3561b72006-12-07 02:14:07 +0100566
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200567static inline void clts(void)
568{
569 PVOP_VCALL0(clts);
570}
Rusty Russelld3561b72006-12-07 02:14:07 +0100571
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200572static inline unsigned long read_cr0(void)
573{
574 return PVOP_CALL0(unsigned long, read_cr0);
575}
Rusty Russelld3561b72006-12-07 02:14:07 +0100576
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200577static inline void write_cr0(unsigned long x)
578{
579 PVOP_VCALL1(write_cr0, x);
580}
Rusty Russelld3561b72006-12-07 02:14:07 +0100581
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200582static inline unsigned long read_cr2(void)
583{
584 return PVOP_CALL0(unsigned long, read_cr2);
585}
Rusty Russelld3561b72006-12-07 02:14:07 +0100586
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200587static inline void write_cr2(unsigned long x)
588{
589 PVOP_VCALL1(write_cr2, x);
590}
Rusty Russelld3561b72006-12-07 02:14:07 +0100591
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200592static inline unsigned long read_cr3(void)
593{
594 return PVOP_CALL0(unsigned long, read_cr3);
595}
596
597static inline void write_cr3(unsigned long x)
598{
599 PVOP_VCALL1(write_cr3, x);
600}
601
602static inline unsigned long read_cr4(void)
603{
604 return PVOP_CALL0(unsigned long, read_cr4);
605}
606static inline unsigned long read_cr4_safe(void)
607{
608 return PVOP_CALL0(unsigned long, read_cr4_safe);
609}
610
611static inline void write_cr4(unsigned long x)
612{
613 PVOP_VCALL1(write_cr4, x);
614}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200615
Rusty Russelld3561b72006-12-07 02:14:07 +0100616static inline void raw_safe_halt(void)
617{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200618 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100619}
620
621static inline void halt(void)
622{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200623 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100624}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200625
626static inline void wbinvd(void)
627{
628 PVOP_VCALL0(wbinvd);
629}
Rusty Russelld3561b72006-12-07 02:14:07 +0100630
631#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
632
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200633static inline u64 paravirt_read_msr(unsigned msr, int *err)
634{
635 return PVOP_CALL2(u64, read_msr, msr, err);
636}
637static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
638{
639 return PVOP_CALL3(int, write_msr, msr, low, high);
640}
641
Rusty Russell90a0a062007-05-02 19:27:10 +0200642/* These should all do BUG_ON(_err), but our headers are too tangled. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200643#define rdmsr(msr,val1,val2) do { \
644 int _err; \
645 u64 _l = paravirt_read_msr(msr, &_err); \
646 val1 = (u32)_l; \
647 val2 = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100648} while(0)
649
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200650#define wrmsr(msr,val1,val2) do { \
651 paravirt_write_msr(msr, val1, val2); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100652} while(0)
653
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200654#define rdmsrl(msr,val) do { \
655 int _err; \
656 val = paravirt_read_msr(msr, &_err); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100657} while(0)
658
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200659#define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
660#define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100661
662/* rdmsr with exception handling */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200663#define rdmsr_safe(msr,a,b) ({ \
664 int _err; \
665 u64 _l = paravirt_read_msr(msr, &_err); \
666 (*a) = (u32)_l; \
667 (*b) = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100668 _err; })
669
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200670
671static inline u64 paravirt_read_tsc(void)
672{
673 return PVOP_CALL0(u64, read_tsc);
674}
675#define rdtsc(low,high) do { \
676 u64 _l = paravirt_read_tsc(); \
677 low = (u32)_l; \
678 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100679} while(0)
680
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200681#define rdtscl(low) do { \
682 u64 _l = paravirt_read_tsc(); \
683 low = (int)_l; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100684} while(0)
685
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200686#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100687
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800688#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800689#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800690
Rusty Russelld3561b72006-12-07 02:14:07 +0100691#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
692
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200693static inline unsigned long long paravirt_read_pmc(int counter)
694{
695 return PVOP_CALL1(u64, read_pmc, counter);
696}
697
698#define rdpmc(counter,low,high) do { \
699 u64 _l = paravirt_read_pmc(counter); \
700 low = (u32)_l; \
701 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100702} while(0)
703
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200704static inline void load_TR_desc(void)
705{
706 PVOP_VCALL0(load_tr_desc);
707}
708static inline void load_gdt(const struct Xgt_desc_struct *dtr)
709{
710 PVOP_VCALL1(load_gdt, dtr);
711}
712static inline void load_idt(const struct Xgt_desc_struct *dtr)
713{
714 PVOP_VCALL1(load_idt, dtr);
715}
716static inline void set_ldt(const void *addr, unsigned entries)
717{
718 PVOP_VCALL2(set_ldt, addr, entries);
719}
720static inline void store_gdt(struct Xgt_desc_struct *dtr)
721{
722 PVOP_VCALL1(store_gdt, dtr);
723}
724static inline void store_idt(struct Xgt_desc_struct *dtr)
725{
726 PVOP_VCALL1(store_idt, dtr);
727}
728static inline unsigned long paravirt_store_tr(void)
729{
730 return PVOP_CALL0(unsigned long, store_tr);
731}
732#define store_tr(tr) ((tr) = paravirt_store_tr())
733static inline void load_TLS(struct thread_struct *t, unsigned cpu)
734{
735 PVOP_VCALL2(load_tls, t, cpu);
736}
737static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
738{
739 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
740}
741static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
742{
743 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
744}
745static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
746{
747 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
748}
749static inline void set_iopl_mask(unsigned mask)
750{
751 PVOP_VCALL1(set_iopl_mask, mask);
752}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200753
Rusty Russelld3561b72006-12-07 02:14:07 +0100754/* The paravirtualized I/O functions */
755static inline void slow_down_io(void) {
756 paravirt_ops.io_delay();
757#ifdef REALLY_SLOW_IO
758 paravirt_ops.io_delay();
759 paravirt_ops.io_delay();
760 paravirt_ops.io_delay();
761#endif
762}
763
Rusty Russell13623d72006-12-07 02:14:08 +0100764#ifdef CONFIG_X86_LOCAL_APIC
765/*
766 * Basic functions accessing APICs.
767 */
768static inline void apic_write(unsigned long reg, unsigned long v)
769{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200770 PVOP_VCALL2(apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100771}
772
773static inline void apic_write_atomic(unsigned long reg, unsigned long v)
774{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200775 PVOP_VCALL2(apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100776}
777
778static inline unsigned long apic_read(unsigned long reg)
779{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200780 return PVOP_CALL1(unsigned long, apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100781}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100782
783static inline void setup_boot_clock(void)
784{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200785 PVOP_VCALL0(setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100786}
787
788static inline void setup_secondary_clock(void)
789{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200790 PVOP_VCALL0(setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100791}
Rusty Russell13623d72006-12-07 02:14:08 +0100792#endif
793
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200794static inline void paravirt_pagetable_setup_start(pgd_t *base)
795{
796 if (paravirt_ops.pagetable_setup_start)
797 (*paravirt_ops.pagetable_setup_start)(base);
798}
799
800static inline void paravirt_pagetable_setup_done(pgd_t *base)
801{
802 if (paravirt_ops.pagetable_setup_done)
803 (*paravirt_ops.pagetable_setup_done)(base);
804}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200805
Zachary Amsdenae5da272007-02-13 13:26:21 +0100806#ifdef CONFIG_SMP
807static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
808 unsigned long start_esp)
809{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200810 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100811}
812#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100813
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200814static inline void paravirt_activate_mm(struct mm_struct *prev,
815 struct mm_struct *next)
816{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200817 PVOP_VCALL2(activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200818}
819
820static inline void arch_dup_mmap(struct mm_struct *oldmm,
821 struct mm_struct *mm)
822{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200823 PVOP_VCALL2(dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200824}
825
826static inline void arch_exit_mmap(struct mm_struct *mm)
827{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200828 PVOP_VCALL1(exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200829}
830
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200831static inline void __flush_tlb(void)
832{
833 PVOP_VCALL0(flush_tlb_user);
834}
835static inline void __flush_tlb_global(void)
836{
837 PVOP_VCALL0(flush_tlb_kernel);
838}
839static inline void __flush_tlb_single(unsigned long addr)
840{
841 PVOP_VCALL1(flush_tlb_single, addr);
842}
Rusty Russellda181a82006-12-07 02:14:08 +0100843
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200844static inline void paravirt_map_pt_hook(int type, pte_t *va, u32 pfn)
845{
846 PVOP_VCALL3(map_pt_hook, type, va, pfn);
847}
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800848
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200849static inline void paravirt_alloc_pt(unsigned pfn)
850{
851 PVOP_VCALL1(alloc_pt, pfn);
852}
853static inline void paravirt_release_pt(unsigned pfn)
854{
855 PVOP_VCALL1(release_pt, pfn);
856}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100857
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200858static inline void paravirt_alloc_pd(unsigned pfn)
859{
860 PVOP_VCALL1(alloc_pd, pfn);
861}
862
863static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
864 unsigned start, unsigned count)
865{
866 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
867}
868static inline void paravirt_release_pd(unsigned pfn)
869{
870 PVOP_VCALL1(release_pd, pfn);
871}
872
873static inline void pte_update(struct mm_struct *mm, unsigned long addr,
874 pte_t *ptep)
875{
876 PVOP_VCALL3(pte_update, mm, addr, ptep);
877}
878
879static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
880 pte_t *ptep)
881{
882 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
883}
884
885#ifdef CONFIG_X86_PAE
886static inline pte_t __pte(unsigned long long val)
887{
888 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
889 val, val >> 32);
890 return (pte_t) { ret, ret >> 32 };
891}
892
893static inline pmd_t __pmd(unsigned long long val)
894{
895 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
896}
897
898static inline pgd_t __pgd(unsigned long long val)
899{
900 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
901}
902
903static inline unsigned long long pte_val(pte_t x)
904{
905 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
906}
907
908static inline unsigned long long pmd_val(pmd_t x)
909{
910 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
911}
912
913static inline unsigned long long pgd_val(pgd_t x)
914{
915 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
916}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100917
Rusty Russellda181a82006-12-07 02:14:08 +0100918static inline void set_pte(pte_t *ptep, pte_t pteval)
919{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200920 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
Rusty Russellda181a82006-12-07 02:14:08 +0100921}
922
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200923static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
924 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100925{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200926 /* 5 arg words */
Rusty Russellda181a82006-12-07 02:14:08 +0100927 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
928}
929
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200930static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
931{
932 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
933}
934
935static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
936 pte_t *ptep, pte_t pte)
937{
938 /* 5 arg words */
939 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
940}
941
Rusty Russellda181a82006-12-07 02:14:08 +0100942static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
943{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200944 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100945}
946
947static inline void set_pud(pud_t *pudp, pud_t pudval)
948{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200949 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100950}
951
952static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
953{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200954 PVOP_VCALL3(pte_clear, mm, addr, ptep);
Rusty Russellda181a82006-12-07 02:14:08 +0100955}
956
957static inline void pmd_clear(pmd_t *pmdp)
958{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200959 PVOP_VCALL1(pmd_clear, pmdp);
Rusty Russellda181a82006-12-07 02:14:08 +0100960}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200961
962static inline pte_t raw_ptep_get_and_clear(pte_t *p)
963{
964 unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
965 return (pte_t) { val, val >> 32 };
966}
967#else /* !CONFIG_X86_PAE */
968static inline pte_t __pte(unsigned long val)
969{
970 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
971}
972
973static inline pgd_t __pgd(unsigned long val)
974{
975 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
976}
977
978static inline unsigned long pte_val(pte_t x)
979{
980 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
981}
982
983static inline unsigned long pgd_val(pgd_t x)
984{
985 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
986}
987
988static inline void set_pte(pte_t *ptep, pte_t pteval)
989{
990 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
991}
992
993static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
994 pte_t *ptep, pte_t pteval)
995{
996 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
997}
998
999static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
1000{
1001 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
1002}
1003
1004static inline pte_t raw_ptep_get_and_clear(pte_t *p)
1005{
1006 return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
1007}
1008#endif /* CONFIG_X86_PAE */
Rusty Russellda181a82006-12-07 02:14:08 +01001009
Zachary Amsden9226d122007-02-13 13:26:21 +01001010/* Lazy mode for batching updates / context switch */
1011#define PARAVIRT_LAZY_NONE 0
1012#define PARAVIRT_LAZY_MMU 1
1013#define PARAVIRT_LAZY_CPU 2
Zachary Amsden49f19712007-04-08 16:04:01 -07001014#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +01001015
1016#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001017static inline void arch_enter_lazy_cpu_mode(void)
1018{
1019 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
1020}
1021
1022static inline void arch_leave_lazy_cpu_mode(void)
1023{
1024 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1025}
1026
1027static inline void arch_flush_lazy_cpu_mode(void)
1028{
1029 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1030}
1031
Zachary Amsden9226d122007-02-13 13:26:21 +01001032
1033#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001034static inline void arch_enter_lazy_mmu_mode(void)
1035{
1036 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
1037}
1038
1039static inline void arch_leave_lazy_mmu_mode(void)
1040{
1041 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1042}
1043
1044static inline void arch_flush_lazy_mmu_mode(void)
1045{
1046 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1047}
Zachary Amsden9226d122007-02-13 13:26:21 +01001048
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +02001049void _paravirt_nop(void);
1050#define paravirt_nop ((void *)_paravirt_nop)
1051
Rusty Russell139ec7c2006-12-07 02:14:08 +01001052/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001053struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +01001054 u8 *instr; /* original instructions */
1055 u8 instrtype; /* type of this instruction */
1056 u8 len; /* length of original instruction */
1057 u16 clobbers; /* what registers you may clobber */
1058};
1059
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001060extern struct paravirt_patch_site __parainstructions[],
1061 __parainstructions_end[];
1062
Rusty Russell139ec7c2006-12-07 02:14:08 +01001063static inline unsigned long __raw_local_save_flags(void)
1064{
1065 unsigned long f;
1066
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001067 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1068 PARAVIRT_CALL
1069 "popl %%edx; popl %%ecx")
1070 : "=a"(f)
1071 : paravirt_type(save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001072 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001073 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001074 return f;
1075}
1076
1077static inline void raw_local_irq_restore(unsigned long f)
1078{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001079 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1080 PARAVIRT_CALL
1081 "popl %%edx; popl %%ecx")
1082 : "=a"(f)
1083 : "0"(f),
1084 paravirt_type(restore_fl),
1085 paravirt_clobber(CLBR_EAX)
1086 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001087}
1088
1089static inline void raw_local_irq_disable(void)
1090{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001091 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1092 PARAVIRT_CALL
1093 "popl %%edx; popl %%ecx")
1094 :
1095 : paravirt_type(irq_disable),
1096 paravirt_clobber(CLBR_EAX)
1097 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001098}
1099
1100static inline void raw_local_irq_enable(void)
1101{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001102 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1103 PARAVIRT_CALL
1104 "popl %%edx; popl %%ecx")
1105 :
1106 : paravirt_type(irq_enable),
1107 paravirt_clobber(CLBR_EAX)
1108 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001109}
1110
1111static inline unsigned long __raw_local_irq_save(void)
1112{
1113 unsigned long f;
1114
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001115 f = __raw_local_save_flags();
1116 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001117 return f;
1118}
1119
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001120#define CLI_STRING \
1121 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1122 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1123 "popl %%edx; popl %%ecx", \
1124 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
Rusty Russell139ec7c2006-12-07 02:14:08 +01001125
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001126#define STI_STRING \
1127 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1128 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1129 "popl %%edx; popl %%ecx", \
1130 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1131
Rusty Russell139ec7c2006-12-07 02:14:08 +01001132#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001133#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001134 , \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001135 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1136 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1137 paravirt_clobber(CLBR_EAX)
1138
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001139/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001140#undef PARAVIRT_CALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001141#undef PVOP_VCALL0
1142#undef PVOP_CALL0
1143#undef PVOP_VCALL1
1144#undef PVOP_CALL1
1145#undef PVOP_VCALL2
1146#undef PVOP_CALL2
1147#undef PVOP_VCALL3
1148#undef PVOP_CALL3
1149#undef PVOP_VCALL4
1150#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001151
Rusty Russelld3561b72006-12-07 02:14:07 +01001152#else /* __ASSEMBLY__ */
1153
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001154#define PARA_PATCH(off) ((off) / 4)
1155
1156#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001157771:; \
1158 ops; \
1159772:; \
1160 .pushsection .parainstructions,"a"; \
1161 .long 771b; \
1162 .byte ptype; \
1163 .byte 772b-771b; \
1164 .short clobbers; \
1165 .popsection
1166
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001167#define INTERRUPT_RETURN \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001168 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001169 jmp *%cs:paravirt_ops+PARAVIRT_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001170
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001171#define DISABLE_INTERRUPTS(clobbers) \
1172 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001173 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001174 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001175 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001176
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001177#define ENABLE_INTERRUPTS(clobbers) \
1178 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001179 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001180 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001181 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001182
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001183#define ENABLE_INTERRUPTS_SYSEXIT \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001184 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001185 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001186
1187#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001188 push %ecx; push %edx; \
1189 call *paravirt_ops+PARAVIRT_read_cr0; \
1190 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +01001191
Rusty Russelld3561b72006-12-07 02:14:07 +01001192#endif /* __ASSEMBLY__ */
1193#endif /* CONFIG_PARAVIRT */
1194#endif /* __ASM_PARAVIRT_H */