blob: 5048b41428fa5524107d8cdf4fa3434ba6f0cb30 [file] [log] [blame]
Rusty Russelld3561b72006-12-07 02:14:07 +01001#ifndef __ASM_PARAVIRT_H
2#define __ASM_PARAVIRT_H
3/* Various instructions on x86 need to be replaced for
4 * para-virtualization: those hooks are defined here. */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02005
6#ifdef CONFIG_PARAVIRT
Rusty Russellda181a82006-12-07 02:14:08 +01007#include <asm/page.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01008
Rusty Russell139ec7c2006-12-07 02:14:08 +01009/* Bitmask of what can be clobbered: usually at least eax. */
10#define CLBR_NONE 0x0
11#define CLBR_EAX 0x1
12#define CLBR_ECX 0x2
13#define CLBR_EDX 0x4
14#define CLBR_ANY 0x7
15
Rusty Russelld3561b72006-12-07 02:14:07 +010016#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020017#include <linux/types.h>
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +020018#include <linux/cpumask.h>
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020019#include <asm/kmap_types.h>
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020020
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020021struct page;
Rusty Russelld3561b72006-12-07 02:14:07 +010022struct thread_struct;
23struct Xgt_desc_struct;
24struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010025struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020026struct desc_struct;
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020027
28/* Lazy mode for batching updates / context switch */
29enum paravirt_lazy_mode {
30 PARAVIRT_LAZY_NONE = 0,
31 PARAVIRT_LAZY_MMU = 1,
32 PARAVIRT_LAZY_CPU = 2,
33};
34
Rusty Russelld3561b72006-12-07 02:14:07 +010035struct paravirt_ops
36{
37 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020038 int shared_kernel_pmd;
Rusty Russelld3561b72006-12-07 02:14:07 +010039 int paravirt_enabled;
40 const char *name;
41
Rusty Russell139ec7c2006-12-07 02:14:08 +010042 /*
43 * Patch may replace one of the defined code sequences with arbitrary
44 * code, subject to the same register constraints. This generally
45 * means the code is not free to clobber any registers other than EAX.
46 * The patch function should return the number of bytes of code
47 * generated, as we nop pad the rest in generic code.
48 */
49 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
50
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020051 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010052 void (*arch_setup)(void);
53 char *(*memory_setup)(void);
54 void (*init_IRQ)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020055 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010056
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020057 /*
58 * Called before/after init_mm pagetable setup. setup_start
59 * may reset %cr3, and may pre-install parts of the pagetable;
60 * pagetable setup is expected to preserve any existing
61 * mapping.
62 */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +020063 void (*pagetable_setup_start)(pgd_t *pgd_base);
64 void (*pagetable_setup_done)(pgd_t *pgd_base);
65
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020066 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010067 void (*banner)(void);
68
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020069 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +010070 unsigned long (*get_wallclock)(void);
71 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010072
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020073 /* cpuid emulation, mostly so that caps bits can be disabled */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010074 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010075 unsigned int *ecx, unsigned int *edx);
76
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020077 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010078 unsigned long (*get_debugreg)(int regno);
79 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010080
Andi Kleen1a1eecd2007-02-13 13:26:25 +010081 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010082
Andi Kleen1a1eecd2007-02-13 13:26:25 +010083 unsigned long (*read_cr0)(void);
84 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010085
Andi Kleen1a1eecd2007-02-13 13:26:25 +010086 unsigned long (*read_cr2)(void);
87 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010088
Andi Kleen1a1eecd2007-02-13 13:26:25 +010089 unsigned long (*read_cr3)(void);
90 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010091
Andi Kleen1a1eecd2007-02-13 13:26:25 +010092 unsigned long (*read_cr4_safe)(void);
93 unsigned long (*read_cr4)(void);
94 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010095
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020096 /*
97 * Get/set interrupt state. save_fl and restore_fl are only
98 * expected to use X86_EFLAGS_IF; all other bits
99 * returned from save_fl are undefined, and may be ignored by
100 * restore_fl.
101 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100102 unsigned long (*save_fl)(void);
103 void (*restore_fl)(unsigned long);
104 void (*irq_disable)(void);
105 void (*irq_enable)(void);
106 void (*safe_halt)(void);
107 void (*halt)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200108
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100109 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100110
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200111 /* MSR, PMC and TSR operations.
112 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100113 u64 (*read_msr)(unsigned int msr, int *err);
114 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +0100115
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100116 u64 (*read_tsc)(void);
117 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800118 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -0800119 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100120
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200121 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100122 void (*load_tr_desc)(void);
123 void (*load_gdt)(const struct Xgt_desc_struct *);
124 void (*load_idt)(const struct Xgt_desc_struct *);
125 void (*store_gdt)(struct Xgt_desc_struct *);
126 void (*store_idt)(struct Xgt_desc_struct *);
127 void (*set_ldt)(const void *desc, unsigned entries);
128 unsigned long (*store_tr)(void);
129 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +0200130 void (*write_ldt_entry)(struct desc_struct *,
131 int entrynum, u32 low, u32 high);
132 void (*write_gdt_entry)(struct desc_struct *,
133 int entrynum, u32 low, u32 high);
134 void (*write_idt_entry)(struct desc_struct *,
135 int entrynum, u32 low, u32 high);
136 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100137
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100138 void (*set_iopl_mask)(unsigned mask);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100139 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100140
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200141 /*
142 * Hooks for intercepting the creation/use/destruction of an
143 * mm_struct.
144 */
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200145 void (*activate_mm)(struct mm_struct *prev,
146 struct mm_struct *next);
147 void (*dup_mmap)(struct mm_struct *oldmm,
148 struct mm_struct *mm);
149 void (*exit_mmap)(struct mm_struct *mm);
150
Rusty Russell13623d72006-12-07 02:14:08 +0100151#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200152 /*
153 * Direct APIC operations, principally for VMI. Ideally
154 * these shouldn't be in this interface.
155 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100156 void (*apic_write)(unsigned long reg, unsigned long v);
157 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
158 unsigned long (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100159 void (*setup_boot_clock)(void);
160 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200161
162 void (*startup_ipi_hook)(int phys_apicid,
163 unsigned long start_eip,
164 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100165#endif
166
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200167 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100168 void (*flush_tlb_user)(void);
169 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200170 void (*flush_tlb_single)(unsigned long addr);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200171 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
172 unsigned long va);
Rusty Russellda181a82006-12-07 02:14:08 +0100173
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
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200192#ifdef CONFIG_HIGHPTE
193 void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
194#endif
195
Rusty Russellda181a82006-12-07 02:14:08 +0100196#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100197 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200198 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100199 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200200 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100201 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200202
203 unsigned long long (*pte_val)(pte_t);
204 unsigned long long (*pmd_val)(pmd_t);
205 unsigned long long (*pgd_val)(pgd_t);
206
207 pte_t (*make_pte)(unsigned long long pte);
208 pmd_t (*make_pmd)(unsigned long long pmd);
209 pgd_t (*make_pgd)(unsigned long long pgd);
210#else
211 unsigned long (*pte_val)(pte_t);
212 unsigned long (*pgd_val)(pgd_t);
213
214 pte_t (*make_pte)(unsigned long pte);
215 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100216#endif
217
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200218 /* Set deferred update mode, used for batching operations. */
219 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100220
Rusty Russelld3561b72006-12-07 02:14:07 +0100221 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100222 void (*irq_enable_sysexit)(void);
223 void (*iret)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100224};
225
Rusty Russellc9ccf302006-12-07 02:14:08 +0100226/* Mark a paravirt probe function. */
227#define paravirt_probe(fn) \
228 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
229 __attribute__((__section__(".paravirtprobe"))) = fn
230
Rusty Russelld3561b72006-12-07 02:14:07 +0100231extern struct paravirt_ops paravirt_ops;
232
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200233#define PARAVIRT_PATCH(x) \
234 (offsetof(struct paravirt_ops, x) / sizeof(void *))
235
236#define paravirt_type(type) \
237 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
238#define paravirt_clobber(clobber) \
239 [paravirt_clobber] "i" (clobber)
240
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200241/*
242 * Generate some code, and mark it as patchable by the
243 * apply_paravirt() alternate instruction patcher.
244 */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200245#define _paravirt_alt(insn_string, type, clobber) \
246 "771:\n\t" insn_string "\n" "772:\n" \
247 ".pushsection .parainstructions,\"a\"\n" \
248 " .long 771b\n" \
249 " .byte " type "\n" \
250 " .byte 772b-771b\n" \
251 " .short " clobber "\n" \
252 ".popsection\n"
253
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200254/* Generate patchable code, with the default asm parameters. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200255#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200256 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
257
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200258unsigned paravirt_patch_nop(void);
259unsigned paravirt_patch_ignore(unsigned len);
260unsigned paravirt_patch_call(void *target, u16 tgt_clobbers,
261 void *site, u16 site_clobbers,
262 unsigned len);
263unsigned paravirt_patch_jmp(void *target, void *site, unsigned len);
264unsigned paravirt_patch_default(u8 type, u16 clobbers, void *site, unsigned len);
265
266unsigned paravirt_patch_insns(void *site, unsigned len,
267 const char *start, const char *end);
268
269
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200270/*
271 * This generates an indirect call based on the operation type number.
272 * The type number, computed in PARAVIRT_PATCH, is derived from the
273 * offset into the paravirt_ops structure, and can therefore be freely
274 * converted back into a structure offset.
275 */
276#define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
277
278/*
279 * These macros are intended to wrap calls into a paravirt_ops
280 * operation, so that they can be later identified and patched at
281 * runtime.
282 *
283 * Normally, a call to a pv_op function is a simple indirect call:
284 * (paravirt_ops.operations)(args...).
285 *
286 * Unfortunately, this is a relatively slow operation for modern CPUs,
287 * because it cannot necessarily determine what the destination
288 * address is. In this case, the address is a runtime constant, so at
289 * the very least we can patch the call to e a simple direct call, or
290 * ideally, patch an inline implementation into the callsite. (Direct
291 * calls are essentially free, because the call and return addresses
292 * are completely predictable.)
293 *
294 * These macros rely on the standard gcc "regparm(3)" calling
295 * convention, in which the first three arguments are placed in %eax,
296 * %edx, %ecx (in that order), and the remaining arguments are placed
297 * on the stack. All caller-save registers (eax,edx,ecx) are expected
298 * to be modified (either clobbered or used for return values).
299 *
300 * The call instruction itself is marked by placing its start address
301 * and size into the .parainstructions section, so that
302 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
303 * appropriate patching under the control of the backend paravirt_ops
304 * implementation.
305 *
306 * Unfortunately there's no way to get gcc to generate the args setup
307 * for the call, and then allow the call itself to be generated by an
308 * inline asm. Because of this, we must do the complete arg setup and
309 * return value handling from within these macros. This is fairly
310 * cumbersome.
311 *
312 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
313 * It could be extended to more arguments, but there would be little
314 * to be gained from that. For each number of arguments, there are
315 * the two VCALL and CALL variants for void and non-void functions.
316 *
317 * When there is a return value, the invoker of the macro must specify
318 * the return type. The macro then uses sizeof() on that type to
319 * determine whether its a 32 or 64 bit value, and places the return
320 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
321 * 64-bit).
322 *
323 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
324 * in low,high order.
325 *
326 * Small structures are passed and returned in registers. The macro
327 * calling convention can't directly deal with this, so the wrapper
328 * functions must do this.
329 *
330 * These PVOP_* macros are only defined within this header. This
331 * means that all uses must be wrapped in inline functions. This also
332 * makes sure the incoming and outgoing types are always correct.
333 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200334#define PVOP_CALL0(__rettype, __op) \
335 ({ \
336 __rettype __ret; \
337 if (sizeof(__rettype) > sizeof(unsigned long)) { \
338 unsigned long long __tmp; \
339 unsigned long __ecx; \
340 asm volatile(paravirt_alt(PARAVIRT_CALL) \
341 : "=A" (__tmp), "=c" (__ecx) \
342 : paravirt_type(__op), \
343 paravirt_clobber(CLBR_ANY) \
344 : "memory", "cc"); \
345 __ret = (__rettype)__tmp; \
346 } else { \
347 unsigned long __tmp, __edx, __ecx; \
348 asm volatile(paravirt_alt(PARAVIRT_CALL) \
349 : "=a" (__tmp), "=d" (__edx), \
350 "=c" (__ecx) \
351 : paravirt_type(__op), \
352 paravirt_clobber(CLBR_ANY) \
353 : "memory", "cc"); \
354 __ret = (__rettype)__tmp; \
355 } \
356 __ret; \
357 })
358#define PVOP_VCALL0(__op) \
359 ({ \
360 unsigned long __eax, __edx, __ecx; \
361 asm volatile(paravirt_alt(PARAVIRT_CALL) \
362 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
363 : paravirt_type(__op), \
364 paravirt_clobber(CLBR_ANY) \
365 : "memory", "cc"); \
366 })
367
368#define PVOP_CALL1(__rettype, __op, arg1) \
369 ({ \
370 __rettype __ret; \
371 if (sizeof(__rettype) > sizeof(unsigned long)) { \
372 unsigned long long __tmp; \
373 unsigned long __ecx; \
374 asm volatile(paravirt_alt(PARAVIRT_CALL) \
375 : "=A" (__tmp), "=c" (__ecx) \
376 : "a" ((u32)(arg1)), \
377 paravirt_type(__op), \
378 paravirt_clobber(CLBR_ANY) \
379 : "memory", "cc"); \
380 __ret = (__rettype)__tmp; \
381 } else { \
382 unsigned long __tmp, __edx, __ecx; \
383 asm volatile(paravirt_alt(PARAVIRT_CALL) \
384 : "=a" (__tmp), "=d" (__edx), \
385 "=c" (__ecx) \
386 : "0" ((u32)(arg1)), \
387 paravirt_type(__op), \
388 paravirt_clobber(CLBR_ANY) \
389 : "memory", "cc"); \
390 __ret = (__rettype)__tmp; \
391 } \
392 __ret; \
393 })
394#define PVOP_VCALL1(__op, arg1) \
395 ({ \
396 unsigned long __eax, __edx, __ecx; \
397 asm volatile(paravirt_alt(PARAVIRT_CALL) \
398 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
399 : "0" ((u32)(arg1)), \
400 paravirt_type(__op), \
401 paravirt_clobber(CLBR_ANY) \
402 : "memory", "cc"); \
403 })
404
405#define PVOP_CALL2(__rettype, __op, arg1, arg2) \
406 ({ \
407 __rettype __ret; \
408 if (sizeof(__rettype) > sizeof(unsigned long)) { \
409 unsigned long long __tmp; \
410 unsigned long __ecx; \
411 asm volatile(paravirt_alt(PARAVIRT_CALL) \
412 : "=A" (__tmp), "=c" (__ecx) \
413 : "a" ((u32)(arg1)), \
414 "d" ((u32)(arg2)), \
415 paravirt_type(__op), \
416 paravirt_clobber(CLBR_ANY) \
417 : "memory", "cc"); \
418 __ret = (__rettype)__tmp; \
419 } else { \
420 unsigned long __tmp, __edx, __ecx; \
421 asm volatile(paravirt_alt(PARAVIRT_CALL) \
422 : "=a" (__tmp), "=d" (__edx), \
423 "=c" (__ecx) \
424 : "0" ((u32)(arg1)), \
425 "1" ((u32)(arg2)), \
426 paravirt_type(__op), \
427 paravirt_clobber(CLBR_ANY) \
428 : "memory", "cc"); \
429 __ret = (__rettype)__tmp; \
430 } \
431 __ret; \
432 })
433#define PVOP_VCALL2(__op, arg1, arg2) \
434 ({ \
435 unsigned long __eax, __edx, __ecx; \
436 asm volatile(paravirt_alt(PARAVIRT_CALL) \
437 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
438 : "0" ((u32)(arg1)), \
439 "1" ((u32)(arg2)), \
440 paravirt_type(__op), \
441 paravirt_clobber(CLBR_ANY) \
442 : "memory", "cc"); \
443 })
444
445#define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \
446 ({ \
447 __rettype __ret; \
448 if (sizeof(__rettype) > sizeof(unsigned long)) { \
449 unsigned long long __tmp; \
450 unsigned long __ecx; \
451 asm volatile(paravirt_alt(PARAVIRT_CALL) \
452 : "=A" (__tmp), "=c" (__ecx) \
453 : "a" ((u32)(arg1)), \
454 "d" ((u32)(arg2)), \
455 "1" ((u32)(arg3)), \
456 paravirt_type(__op), \
457 paravirt_clobber(CLBR_ANY) \
458 : "memory", "cc"); \
459 __ret = (__rettype)__tmp; \
460 } else { \
461 unsigned long __tmp, __edx, __ecx; \
462 asm volatile(paravirt_alt(PARAVIRT_CALL) \
463 : "=a" (__tmp), "=d" (__edx), \
464 "=c" (__ecx) \
465 : "0" ((u32)(arg1)), \
466 "1" ((u32)(arg2)), \
467 "2" ((u32)(arg3)), \
468 paravirt_type(__op), \
469 paravirt_clobber(CLBR_ANY) \
470 : "memory", "cc"); \
471 __ret = (__rettype)__tmp; \
472 } \
473 __ret; \
474 })
475#define PVOP_VCALL3(__op, arg1, arg2, arg3) \
476 ({ \
477 unsigned long __eax, __edx, __ecx; \
478 asm volatile(paravirt_alt(PARAVIRT_CALL) \
479 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
480 : "0" ((u32)(arg1)), \
481 "1" ((u32)(arg2)), \
482 "2" ((u32)(arg3)), \
483 paravirt_type(__op), \
484 paravirt_clobber(CLBR_ANY) \
485 : "memory", "cc"); \
486 })
487
488#define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \
489 ({ \
490 __rettype __ret; \
491 if (sizeof(__rettype) > sizeof(unsigned long)) { \
492 unsigned long long __tmp; \
493 unsigned long __ecx; \
494 asm volatile("push %[_arg4]; " \
495 paravirt_alt(PARAVIRT_CALL) \
496 "lea 4(%%esp),%%esp" \
497 : "=A" (__tmp), "=c" (__ecx) \
498 : "a" ((u32)(arg1)), \
499 "d" ((u32)(arg2)), \
500 "1" ((u32)(arg3)), \
501 [_arg4] "mr" ((u32)(arg4)), \
502 paravirt_type(__op), \
503 paravirt_clobber(CLBR_ANY) \
504 : "memory", "cc",); \
505 __ret = (__rettype)__tmp; \
506 } else { \
507 unsigned long __tmp, __edx, __ecx; \
508 asm volatile("push %[_arg4]; " \
509 paravirt_alt(PARAVIRT_CALL) \
510 "lea 4(%%esp),%%esp" \
511 : "=a" (__tmp), "=d" (__edx), "=c" (__ecx) \
512 : "0" ((u32)(arg1)), \
513 "1" ((u32)(arg2)), \
514 "2" ((u32)(arg3)), \
515 [_arg4]"mr" ((u32)(arg4)), \
516 paravirt_type(__op), \
517 paravirt_clobber(CLBR_ANY) \
518 : "memory", "cc"); \
519 __ret = (__rettype)__tmp; \
520 } \
521 __ret; \
522 })
523#define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \
524 ({ \
525 unsigned long __eax, __edx, __ecx; \
526 asm volatile("push %[_arg4]; " \
527 paravirt_alt(PARAVIRT_CALL) \
528 "lea 4(%%esp),%%esp" \
529 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
530 : "0" ((u32)(arg1)), \
531 "1" ((u32)(arg2)), \
532 "2" ((u32)(arg3)), \
533 [_arg4]"mr" ((u32)(arg4)), \
534 paravirt_type(__op), \
535 paravirt_clobber(CLBR_ANY) \
536 : "memory", "cc"); \
537 })
538
539static inline int paravirt_enabled(void)
540{
541 return paravirt_ops.paravirt_enabled;
542}
Rusty Russelld3561b72006-12-07 02:14:07 +0100543
544static inline void load_esp0(struct tss_struct *tss,
545 struct thread_struct *thread)
546{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200547 PVOP_VCALL2(load_esp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100548}
549
550#define ARCH_SETUP paravirt_ops.arch_setup();
551static inline unsigned long get_wallclock(void)
552{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200553 return PVOP_CALL0(unsigned long, get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100554}
555
556static inline int set_wallclock(unsigned long nowtime)
557{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200558 return PVOP_CALL1(int, set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100559}
560
Zachary Amsdene30fab32007-03-05 00:30:39 -0800561static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100562{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800563 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100564}
565
566/* The paravirtualized CPUID instruction. */
567static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
568 unsigned int *ecx, unsigned int *edx)
569{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200570 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100571}
572
573/*
574 * These special macros can be used to get or set a debugging register
575 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200576static inline unsigned long paravirt_get_debugreg(int reg)
577{
578 return PVOP_CALL1(unsigned long, get_debugreg, reg);
579}
580#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
581static inline void set_debugreg(unsigned long val, int reg)
582{
583 PVOP_VCALL2(set_debugreg, reg, val);
584}
Rusty Russelld3561b72006-12-07 02:14:07 +0100585
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200586static inline void clts(void)
587{
588 PVOP_VCALL0(clts);
589}
Rusty Russelld3561b72006-12-07 02:14:07 +0100590
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200591static inline unsigned long read_cr0(void)
592{
593 return PVOP_CALL0(unsigned long, read_cr0);
594}
Rusty Russelld3561b72006-12-07 02:14:07 +0100595
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200596static inline void write_cr0(unsigned long x)
597{
598 PVOP_VCALL1(write_cr0, x);
599}
Rusty Russelld3561b72006-12-07 02:14:07 +0100600
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200601static inline unsigned long read_cr2(void)
602{
603 return PVOP_CALL0(unsigned long, read_cr2);
604}
Rusty Russelld3561b72006-12-07 02:14:07 +0100605
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200606static inline void write_cr2(unsigned long x)
607{
608 PVOP_VCALL1(write_cr2, x);
609}
Rusty Russelld3561b72006-12-07 02:14:07 +0100610
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200611static inline unsigned long read_cr3(void)
612{
613 return PVOP_CALL0(unsigned long, read_cr3);
614}
615
616static inline void write_cr3(unsigned long x)
617{
618 PVOP_VCALL1(write_cr3, x);
619}
620
621static inline unsigned long read_cr4(void)
622{
623 return PVOP_CALL0(unsigned long, read_cr4);
624}
625static inline unsigned long read_cr4_safe(void)
626{
627 return PVOP_CALL0(unsigned long, read_cr4_safe);
628}
629
630static inline void write_cr4(unsigned long x)
631{
632 PVOP_VCALL1(write_cr4, x);
633}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200634
Rusty Russelld3561b72006-12-07 02:14:07 +0100635static inline void raw_safe_halt(void)
636{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200637 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100638}
639
640static inline void halt(void)
641{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200642 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100643}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200644
645static inline void wbinvd(void)
646{
647 PVOP_VCALL0(wbinvd);
648}
Rusty Russelld3561b72006-12-07 02:14:07 +0100649
650#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
651
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200652static inline u64 paravirt_read_msr(unsigned msr, int *err)
653{
654 return PVOP_CALL2(u64, read_msr, msr, err);
655}
656static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
657{
658 return PVOP_CALL3(int, write_msr, msr, low, high);
659}
660
Rusty Russell90a0a062007-05-02 19:27:10 +0200661/* These should all do BUG_ON(_err), but our headers are too tangled. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200662#define rdmsr(msr,val1,val2) do { \
663 int _err; \
664 u64 _l = paravirt_read_msr(msr, &_err); \
665 val1 = (u32)_l; \
666 val2 = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100667} while(0)
668
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200669#define wrmsr(msr,val1,val2) do { \
670 paravirt_write_msr(msr, val1, val2); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100671} while(0)
672
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200673#define rdmsrl(msr,val) do { \
674 int _err; \
675 val = paravirt_read_msr(msr, &_err); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100676} while(0)
677
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200678#define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
679#define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100680
681/* rdmsr with exception handling */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200682#define rdmsr_safe(msr,a,b) ({ \
683 int _err; \
684 u64 _l = paravirt_read_msr(msr, &_err); \
685 (*a) = (u32)_l; \
686 (*b) = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100687 _err; })
688
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200689
690static inline u64 paravirt_read_tsc(void)
691{
692 return PVOP_CALL0(u64, read_tsc);
693}
694#define rdtsc(low,high) do { \
695 u64 _l = paravirt_read_tsc(); \
696 low = (u32)_l; \
697 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100698} while(0)
699
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200700#define rdtscl(low) do { \
701 u64 _l = paravirt_read_tsc(); \
702 low = (int)_l; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100703} while(0)
704
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200705#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100706
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800707#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800708#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800709
Rusty Russelld3561b72006-12-07 02:14:07 +0100710#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
711
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200712static inline unsigned long long paravirt_read_pmc(int counter)
713{
714 return PVOP_CALL1(u64, read_pmc, counter);
715}
716
717#define rdpmc(counter,low,high) do { \
718 u64 _l = paravirt_read_pmc(counter); \
719 low = (u32)_l; \
720 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100721} while(0)
722
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200723static inline void load_TR_desc(void)
724{
725 PVOP_VCALL0(load_tr_desc);
726}
727static inline void load_gdt(const struct Xgt_desc_struct *dtr)
728{
729 PVOP_VCALL1(load_gdt, dtr);
730}
731static inline void load_idt(const struct Xgt_desc_struct *dtr)
732{
733 PVOP_VCALL1(load_idt, dtr);
734}
735static inline void set_ldt(const void *addr, unsigned entries)
736{
737 PVOP_VCALL2(set_ldt, addr, entries);
738}
739static inline void store_gdt(struct Xgt_desc_struct *dtr)
740{
741 PVOP_VCALL1(store_gdt, dtr);
742}
743static inline void store_idt(struct Xgt_desc_struct *dtr)
744{
745 PVOP_VCALL1(store_idt, dtr);
746}
747static inline unsigned long paravirt_store_tr(void)
748{
749 return PVOP_CALL0(unsigned long, store_tr);
750}
751#define store_tr(tr) ((tr) = paravirt_store_tr())
752static inline void load_TLS(struct thread_struct *t, unsigned cpu)
753{
754 PVOP_VCALL2(load_tls, t, cpu);
755}
756static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
757{
758 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
759}
760static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
761{
762 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
763}
764static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
765{
766 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
767}
768static inline void set_iopl_mask(unsigned mask)
769{
770 PVOP_VCALL1(set_iopl_mask, mask);
771}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200772
Rusty Russelld3561b72006-12-07 02:14:07 +0100773/* The paravirtualized I/O functions */
774static inline void slow_down_io(void) {
775 paravirt_ops.io_delay();
776#ifdef REALLY_SLOW_IO
777 paravirt_ops.io_delay();
778 paravirt_ops.io_delay();
779 paravirt_ops.io_delay();
780#endif
781}
782
Rusty Russell13623d72006-12-07 02:14:08 +0100783#ifdef CONFIG_X86_LOCAL_APIC
784/*
785 * Basic functions accessing APICs.
786 */
787static inline void apic_write(unsigned long reg, unsigned long v)
788{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200789 PVOP_VCALL2(apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100790}
791
792static inline void apic_write_atomic(unsigned long reg, unsigned long v)
793{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200794 PVOP_VCALL2(apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100795}
796
797static inline unsigned long apic_read(unsigned long reg)
798{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200799 return PVOP_CALL1(unsigned long, apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100800}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100801
802static inline void setup_boot_clock(void)
803{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200804 PVOP_VCALL0(setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100805}
806
807static inline void setup_secondary_clock(void)
808{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200809 PVOP_VCALL0(setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100810}
Rusty Russell13623d72006-12-07 02:14:08 +0100811#endif
812
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200813static inline void paravirt_pagetable_setup_start(pgd_t *base)
814{
815 if (paravirt_ops.pagetable_setup_start)
816 (*paravirt_ops.pagetable_setup_start)(base);
817}
818
819static inline void paravirt_pagetable_setup_done(pgd_t *base)
820{
821 if (paravirt_ops.pagetable_setup_done)
822 (*paravirt_ops.pagetable_setup_done)(base);
823}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200824
Zachary Amsdenae5da272007-02-13 13:26:21 +0100825#ifdef CONFIG_SMP
826static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
827 unsigned long start_esp)
828{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200829 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100830}
831#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100832
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200833static inline void paravirt_activate_mm(struct mm_struct *prev,
834 struct mm_struct *next)
835{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200836 PVOP_VCALL2(activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200837}
838
839static inline void arch_dup_mmap(struct mm_struct *oldmm,
840 struct mm_struct *mm)
841{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200842 PVOP_VCALL2(dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200843}
844
845static inline void arch_exit_mmap(struct mm_struct *mm)
846{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200847 PVOP_VCALL1(exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200848}
849
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200850static inline void __flush_tlb(void)
851{
852 PVOP_VCALL0(flush_tlb_user);
853}
854static inline void __flush_tlb_global(void)
855{
856 PVOP_VCALL0(flush_tlb_kernel);
857}
858static inline void __flush_tlb_single(unsigned long addr)
859{
860 PVOP_VCALL1(flush_tlb_single, addr);
861}
Rusty Russellda181a82006-12-07 02:14:08 +0100862
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200863static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
864 unsigned long va)
865{
866 PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va);
867}
868
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200869static inline void paravirt_alloc_pt(unsigned pfn)
870{
871 PVOP_VCALL1(alloc_pt, pfn);
872}
873static inline void paravirt_release_pt(unsigned pfn)
874{
875 PVOP_VCALL1(release_pt, pfn);
876}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100877
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200878static inline void paravirt_alloc_pd(unsigned pfn)
879{
880 PVOP_VCALL1(alloc_pd, pfn);
881}
882
883static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
884 unsigned start, unsigned count)
885{
886 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
887}
888static inline void paravirt_release_pd(unsigned pfn)
889{
890 PVOP_VCALL1(release_pd, pfn);
891}
892
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200893#ifdef CONFIG_HIGHPTE
894static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
895{
896 unsigned long ret;
897 ret = PVOP_CALL2(unsigned long, kmap_atomic_pte, page, type);
898 return (void *)ret;
899}
900#endif
901
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200902static inline void pte_update(struct mm_struct *mm, unsigned long addr,
903 pte_t *ptep)
904{
905 PVOP_VCALL3(pte_update, mm, addr, ptep);
906}
907
908static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
909 pte_t *ptep)
910{
911 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
912}
913
914#ifdef CONFIG_X86_PAE
915static inline pte_t __pte(unsigned long long val)
916{
917 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
918 val, val >> 32);
919 return (pte_t) { ret, ret >> 32 };
920}
921
922static inline pmd_t __pmd(unsigned long long val)
923{
924 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
925}
926
927static inline pgd_t __pgd(unsigned long long val)
928{
929 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
930}
931
932static inline unsigned long long pte_val(pte_t x)
933{
934 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
935}
936
937static inline unsigned long long pmd_val(pmd_t x)
938{
939 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
940}
941
942static inline unsigned long long pgd_val(pgd_t x)
943{
944 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
945}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100946
Rusty Russellda181a82006-12-07 02:14:08 +0100947static inline void set_pte(pte_t *ptep, pte_t pteval)
948{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200949 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
Rusty Russellda181a82006-12-07 02:14:08 +0100950}
951
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200952static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
953 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100954{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200955 /* 5 arg words */
Rusty Russellda181a82006-12-07 02:14:08 +0100956 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
957}
958
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200959static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
960{
961 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
962}
963
964static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
965 pte_t *ptep, pte_t pte)
966{
967 /* 5 arg words */
968 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
969}
970
Rusty Russellda181a82006-12-07 02:14:08 +0100971static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
972{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200973 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100974}
975
976static inline void set_pud(pud_t *pudp, pud_t pudval)
977{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200978 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100979}
980
981static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
982{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200983 PVOP_VCALL3(pte_clear, mm, addr, ptep);
Rusty Russellda181a82006-12-07 02:14:08 +0100984}
985
986static inline void pmd_clear(pmd_t *pmdp)
987{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200988 PVOP_VCALL1(pmd_clear, pmdp);
Rusty Russellda181a82006-12-07 02:14:08 +0100989}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200990
991static inline pte_t raw_ptep_get_and_clear(pte_t *p)
992{
993 unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
994 return (pte_t) { val, val >> 32 };
995}
996#else /* !CONFIG_X86_PAE */
997static inline pte_t __pte(unsigned long val)
998{
999 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
1000}
1001
1002static inline pgd_t __pgd(unsigned long val)
1003{
1004 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
1005}
1006
1007static inline unsigned long pte_val(pte_t x)
1008{
1009 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
1010}
1011
1012static inline unsigned long pgd_val(pgd_t x)
1013{
1014 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
1015}
1016
1017static inline void set_pte(pte_t *ptep, pte_t pteval)
1018{
1019 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
1020}
1021
1022static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1023 pte_t *ptep, pte_t pteval)
1024{
1025 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
1026}
1027
1028static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
1029{
1030 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
1031}
1032
1033static inline pte_t raw_ptep_get_and_clear(pte_t *p)
1034{
1035 return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
1036}
1037#endif /* CONFIG_X86_PAE */
Rusty Russellda181a82006-12-07 02:14:08 +01001038
Zachary Amsden9226d122007-02-13 13:26:21 +01001039/* Lazy mode for batching updates / context switch */
1040#define PARAVIRT_LAZY_NONE 0
1041#define PARAVIRT_LAZY_MMU 1
1042#define PARAVIRT_LAZY_CPU 2
Zachary Amsden49f19712007-04-08 16:04:01 -07001043#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +01001044
1045#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001046static inline void arch_enter_lazy_cpu_mode(void)
1047{
1048 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
1049}
1050
1051static inline void arch_leave_lazy_cpu_mode(void)
1052{
1053 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1054}
1055
1056static inline void arch_flush_lazy_cpu_mode(void)
1057{
1058 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1059}
1060
Zachary Amsden9226d122007-02-13 13:26:21 +01001061
1062#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001063static inline void arch_enter_lazy_mmu_mode(void)
1064{
1065 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
1066}
1067
1068static inline void arch_leave_lazy_mmu_mode(void)
1069{
1070 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
1071}
1072
1073static inline void arch_flush_lazy_mmu_mode(void)
1074{
1075 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
1076}
Zachary Amsden9226d122007-02-13 13:26:21 +01001077
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +02001078void _paravirt_nop(void);
1079#define paravirt_nop ((void *)_paravirt_nop)
1080
Rusty Russell139ec7c2006-12-07 02:14:08 +01001081/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001082struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +01001083 u8 *instr; /* original instructions */
1084 u8 instrtype; /* type of this instruction */
1085 u8 len; /* length of original instruction */
1086 u16 clobbers; /* what registers you may clobber */
1087};
1088
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001089extern struct paravirt_patch_site __parainstructions[],
1090 __parainstructions_end[];
1091
Rusty Russell139ec7c2006-12-07 02:14:08 +01001092static inline unsigned long __raw_local_save_flags(void)
1093{
1094 unsigned long f;
1095
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001096 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1097 PARAVIRT_CALL
1098 "popl %%edx; popl %%ecx")
1099 : "=a"(f)
1100 : paravirt_type(save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001101 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001102 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001103 return f;
1104}
1105
1106static inline void raw_local_irq_restore(unsigned long f)
1107{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001108 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1109 PARAVIRT_CALL
1110 "popl %%edx; popl %%ecx")
1111 : "=a"(f)
1112 : "0"(f),
1113 paravirt_type(restore_fl),
1114 paravirt_clobber(CLBR_EAX)
1115 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001116}
1117
1118static inline void raw_local_irq_disable(void)
1119{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001120 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1121 PARAVIRT_CALL
1122 "popl %%edx; popl %%ecx")
1123 :
1124 : paravirt_type(irq_disable),
1125 paravirt_clobber(CLBR_EAX)
1126 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001127}
1128
1129static inline void raw_local_irq_enable(void)
1130{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001131 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1132 PARAVIRT_CALL
1133 "popl %%edx; popl %%ecx")
1134 :
1135 : paravirt_type(irq_enable),
1136 paravirt_clobber(CLBR_EAX)
1137 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001138}
1139
1140static inline unsigned long __raw_local_irq_save(void)
1141{
1142 unsigned long f;
1143
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001144 f = __raw_local_save_flags();
1145 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001146 return f;
1147}
1148
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001149#define CLI_STRING \
1150 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1151 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1152 "popl %%edx; popl %%ecx", \
1153 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
Rusty Russell139ec7c2006-12-07 02:14:08 +01001154
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001155#define STI_STRING \
1156 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1157 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1158 "popl %%edx; popl %%ecx", \
1159 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1160
Rusty Russell139ec7c2006-12-07 02:14:08 +01001161#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001162#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001163 , \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001164 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1165 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1166 paravirt_clobber(CLBR_EAX)
1167
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001168/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001169#undef PARAVIRT_CALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001170#undef PVOP_VCALL0
1171#undef PVOP_CALL0
1172#undef PVOP_VCALL1
1173#undef PVOP_CALL1
1174#undef PVOP_VCALL2
1175#undef PVOP_CALL2
1176#undef PVOP_VCALL3
1177#undef PVOP_CALL3
1178#undef PVOP_VCALL4
1179#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001180
Rusty Russelld3561b72006-12-07 02:14:07 +01001181#else /* __ASSEMBLY__ */
1182
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001183#define PARA_PATCH(off) ((off) / 4)
1184
1185#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001186771:; \
1187 ops; \
1188772:; \
1189 .pushsection .parainstructions,"a"; \
1190 .long 771b; \
1191 .byte ptype; \
1192 .byte 772b-771b; \
1193 .short clobbers; \
1194 .popsection
1195
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001196#define INTERRUPT_RETURN \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001197 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001198 jmp *%cs:paravirt_ops+PARAVIRT_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001199
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001200#define DISABLE_INTERRUPTS(clobbers) \
1201 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001202 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001203 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001204 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001205
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001206#define ENABLE_INTERRUPTS(clobbers) \
1207 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001208 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001209 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001210 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001211
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001212#define ENABLE_INTERRUPTS_SYSEXIT \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001213 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001214 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001215
1216#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001217 push %ecx; push %edx; \
1218 call *paravirt_ops+PARAVIRT_read_cr0; \
1219 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +01001220
Rusty Russelld3561b72006-12-07 02:14:07 +01001221#endif /* __ASSEMBLY__ */
1222#endif /* CONFIG_PARAVIRT */
1223#endif /* __ASM_PARAVIRT_H */