blob: e2e7f98723c57fac6c3f45c797a1a7a1060df45a [file] [log] [blame]
Rusty Russelld3561b72006-12-07 02:14:07 +01001#ifndef __ASM_PARAVIRT_H
2#define __ASM_PARAVIRT_H
3/* Various instructions on x86 need to be replaced for
4 * para-virtualization: those hooks are defined here. */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02005
6#ifdef CONFIG_PARAVIRT
Rusty Russellda181a82006-12-07 02:14:08 +01007#include <asm/page.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01008
Rusty Russell139ec7c2006-12-07 02:14:08 +01009/* Bitmask of what can be clobbered: usually at least eax. */
10#define CLBR_NONE 0x0
11#define CLBR_EAX 0x1
12#define CLBR_ECX 0x2
13#define CLBR_EDX 0x4
14#define CLBR_ANY 0x7
15
Rusty Russelld3561b72006-12-07 02:14:07 +010016#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020017#include <linux/types.h>
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +020018#include <linux/cpumask.h>
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020019#include <asm/kmap_types.h>
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020020
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020021struct page;
Rusty Russelld3561b72006-12-07 02:14:07 +010022struct thread_struct;
23struct Xgt_desc_struct;
24struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010025struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020026struct desc_struct;
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020027
28/* Lazy mode for batching updates / context switch */
29enum paravirt_lazy_mode {
30 PARAVIRT_LAZY_NONE = 0,
31 PARAVIRT_LAZY_MMU = 1,
32 PARAVIRT_LAZY_CPU = 2,
Jeremy Fitzhardinge4e0fa852007-05-02 19:27:15 +020033 PARAVIRT_LAZY_FLUSH = 3,
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020034};
35
Rusty Russelld3561b72006-12-07 02:14:07 +010036struct paravirt_ops
37{
38 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020039 int shared_kernel_pmd;
Rusty Russelld3561b72006-12-07 02:14:07 +010040 int paravirt_enabled;
41 const char *name;
42
Rusty Russell139ec7c2006-12-07 02:14:08 +010043 /*
44 * Patch may replace one of the defined code sequences with arbitrary
45 * code, subject to the same register constraints. This generally
46 * means the code is not free to clobber any registers other than EAX.
47 * The patch function should return the number of bytes of code
48 * generated, as we nop pad the rest in generic code.
49 */
50 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
51
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020052 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010053 void (*arch_setup)(void);
54 char *(*memory_setup)(void);
55 void (*init_IRQ)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020056 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010057
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020058 /*
59 * Called before/after init_mm pagetable setup. setup_start
60 * may reset %cr3, and may pre-install parts of the pagetable;
61 * pagetable setup is expected to preserve any existing
62 * mapping.
63 */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +020064 void (*pagetable_setup_start)(pgd_t *pgd_base);
65 void (*pagetable_setup_done)(pgd_t *pgd_base);
66
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020067 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010068 void (*banner)(void);
69
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020070 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +010071 unsigned long (*get_wallclock)(void);
72 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010073
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020074 /* cpuid emulation, mostly so that caps bits can be disabled */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010075 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010076 unsigned int *ecx, unsigned int *edx);
77
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020078 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010079 unsigned long (*get_debugreg)(int regno);
80 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010081
Andi Kleen1a1eecd2007-02-13 13:26:25 +010082 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010083
Andi Kleen1a1eecd2007-02-13 13:26:25 +010084 unsigned long (*read_cr0)(void);
85 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010086
Andi Kleen1a1eecd2007-02-13 13:26:25 +010087 unsigned long (*read_cr2)(void);
88 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010089
Andi Kleen1a1eecd2007-02-13 13:26:25 +010090 unsigned long (*read_cr3)(void);
91 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010092
Andi Kleen1a1eecd2007-02-13 13:26:25 +010093 unsigned long (*read_cr4_safe)(void);
94 unsigned long (*read_cr4)(void);
95 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010096
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020097 /*
98 * Get/set interrupt state. save_fl and restore_fl are only
99 * expected to use X86_EFLAGS_IF; all other bits
100 * returned from save_fl are undefined, and may be ignored by
101 * restore_fl.
102 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100103 unsigned long (*save_fl)(void);
104 void (*restore_fl)(unsigned long);
105 void (*irq_disable)(void);
106 void (*irq_enable)(void);
107 void (*safe_halt)(void);
108 void (*halt)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200109
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100110 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100111
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200112 /* MSR, PMC and TSR operations.
113 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100114 u64 (*read_msr)(unsigned int msr, int *err);
115 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +0100116
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100117 u64 (*read_tsc)(void);
118 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800119 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -0800120 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100121
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200122 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100123 void (*load_tr_desc)(void);
124 void (*load_gdt)(const struct Xgt_desc_struct *);
125 void (*load_idt)(const struct Xgt_desc_struct *);
126 void (*store_gdt)(struct Xgt_desc_struct *);
127 void (*store_idt)(struct Xgt_desc_struct *);
128 void (*set_ldt)(const void *desc, unsigned entries);
129 unsigned long (*store_tr)(void);
130 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +0200131 void (*write_ldt_entry)(struct desc_struct *,
132 int entrynum, u32 low, u32 high);
133 void (*write_gdt_entry)(struct desc_struct *,
134 int entrynum, u32 low, u32 high);
135 void (*write_idt_entry)(struct desc_struct *,
136 int entrynum, u32 low, u32 high);
137 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100138
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100139 void (*set_iopl_mask)(unsigned mask);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100140 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100141
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200142 /*
143 * Hooks for intercepting the creation/use/destruction of an
144 * mm_struct.
145 */
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200146 void (*activate_mm)(struct mm_struct *prev,
147 struct mm_struct *next);
148 void (*dup_mmap)(struct mm_struct *oldmm,
149 struct mm_struct *mm);
150 void (*exit_mmap)(struct mm_struct *mm);
151
Rusty Russell13623d72006-12-07 02:14:08 +0100152#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200153 /*
154 * Direct APIC operations, principally for VMI. Ideally
155 * these shouldn't be in this interface.
156 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100157 void (*apic_write)(unsigned long reg, unsigned long v);
158 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
159 unsigned long (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100160 void (*setup_boot_clock)(void);
161 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200162
163 void (*startup_ipi_hook)(int phys_apicid,
164 unsigned long start_eip,
165 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100166#endif
167
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200168 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100169 void (*flush_tlb_user)(void);
170 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200171 void (*flush_tlb_single)(unsigned long addr);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200172 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
173 unsigned long va);
Rusty Russellda181a82006-12-07 02:14:08 +0100174
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200175 /* Hooks for allocating/releasing pagetable pages */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100176 void (*alloc_pt)(u32 pfn);
177 void (*alloc_pd)(u32 pfn);
178 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
179 void (*release_pt)(u32 pfn);
180 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100181
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200182 /* Pagetable manipulation functions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100183 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200184 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
185 pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100186 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200187 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200188 void (*pte_update_defer)(struct mm_struct *mm,
189 unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200190
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200191#ifdef CONFIG_HIGHPTE
192 void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
193#endif
194
Rusty Russellda181a82006-12-07 02:14:08 +0100195#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100196 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200197 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100198 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200199 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100200 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200201
202 unsigned long long (*pte_val)(pte_t);
203 unsigned long long (*pmd_val)(pmd_t);
204 unsigned long long (*pgd_val)(pgd_t);
205
206 pte_t (*make_pte)(unsigned long long pte);
207 pmd_t (*make_pmd)(unsigned long long pmd);
208 pgd_t (*make_pgd)(unsigned long long pgd);
209#else
210 unsigned long (*pte_val)(pte_t);
211 unsigned long (*pgd_val)(pgd_t);
212
213 pte_t (*make_pte)(unsigned long pte);
214 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100215#endif
216
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200217 /* Set deferred update mode, used for batching operations. */
218 void (*set_lazy_mode)(enum paravirt_lazy_mode mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100219
Rusty Russelld3561b72006-12-07 02:14:07 +0100220 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100221 void (*irq_enable_sysexit)(void);
222 void (*iret)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100223};
224
Rusty Russellc9ccf302006-12-07 02:14:08 +0100225/* Mark a paravirt probe function. */
226#define paravirt_probe(fn) \
227 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
228 __attribute__((__section__(".paravirtprobe"))) = fn
229
Rusty Russelld3561b72006-12-07 02:14:07 +0100230extern struct paravirt_ops paravirt_ops;
231
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200232#define PARAVIRT_PATCH(x) \
233 (offsetof(struct paravirt_ops, x) / sizeof(void *))
234
235#define paravirt_type(type) \
236 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
237#define paravirt_clobber(clobber) \
238 [paravirt_clobber] "i" (clobber)
239
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200240/*
241 * Generate some code, and mark it as patchable by the
242 * apply_paravirt() alternate instruction patcher.
243 */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200244#define _paravirt_alt(insn_string, type, clobber) \
245 "771:\n\t" insn_string "\n" "772:\n" \
246 ".pushsection .parainstructions,\"a\"\n" \
247 " .long 771b\n" \
248 " .byte " type "\n" \
249 " .byte 772b-771b\n" \
250 " .short " clobber "\n" \
251 ".popsection\n"
252
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200253/* Generate patchable code, with the default asm parameters. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200254#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200255 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
256
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200257unsigned paravirt_patch_nop(void);
258unsigned paravirt_patch_ignore(unsigned len);
259unsigned paravirt_patch_call(void *target, u16 tgt_clobbers,
260 void *site, u16 site_clobbers,
261 unsigned len);
262unsigned paravirt_patch_jmp(void *target, void *site, unsigned len);
263unsigned paravirt_patch_default(u8 type, u16 clobbers, void *site, unsigned len);
264
265unsigned paravirt_patch_insns(void *site, unsigned len,
266 const char *start, const char *end);
267
268
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200269/*
270 * This generates an indirect call based on the operation type number.
271 * The type number, computed in PARAVIRT_PATCH, is derived from the
272 * offset into the paravirt_ops structure, and can therefore be freely
273 * converted back into a structure offset.
274 */
275#define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
276
277/*
278 * These macros are intended to wrap calls into a paravirt_ops
279 * operation, so that they can be later identified and patched at
280 * runtime.
281 *
282 * Normally, a call to a pv_op function is a simple indirect call:
283 * (paravirt_ops.operations)(args...).
284 *
285 * Unfortunately, this is a relatively slow operation for modern CPUs,
286 * because it cannot necessarily determine what the destination
287 * address is. In this case, the address is a runtime constant, so at
288 * the very least we can patch the call to e a simple direct call, or
289 * ideally, patch an inline implementation into the callsite. (Direct
290 * calls are essentially free, because the call and return addresses
291 * are completely predictable.)
292 *
293 * These macros rely on the standard gcc "regparm(3)" calling
294 * convention, in which the first three arguments are placed in %eax,
295 * %edx, %ecx (in that order), and the remaining arguments are placed
296 * on the stack. All caller-save registers (eax,edx,ecx) are expected
297 * to be modified (either clobbered or used for return values).
298 *
299 * The call instruction itself is marked by placing its start address
300 * and size into the .parainstructions section, so that
301 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
302 * appropriate patching under the control of the backend paravirt_ops
303 * implementation.
304 *
305 * Unfortunately there's no way to get gcc to generate the args setup
306 * for the call, and then allow the call itself to be generated by an
307 * inline asm. Because of this, we must do the complete arg setup and
308 * return value handling from within these macros. This is fairly
309 * cumbersome.
310 *
311 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
312 * It could be extended to more arguments, but there would be little
313 * to be gained from that. For each number of arguments, there are
314 * the two VCALL and CALL variants for void and non-void functions.
315 *
316 * When there is a return value, the invoker of the macro must specify
317 * the return type. The macro then uses sizeof() on that type to
318 * determine whether its a 32 or 64 bit value, and places the return
319 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
320 * 64-bit).
321 *
322 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
323 * in low,high order.
324 *
325 * Small structures are passed and returned in registers. The macro
326 * calling convention can't directly deal with this, so the wrapper
327 * functions must do this.
328 *
329 * These PVOP_* macros are only defined within this header. This
330 * means that all uses must be wrapped in inline functions. This also
331 * makes sure the incoming and outgoing types are always correct.
332 */
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200333#define __PVOP_CALL(rettype, op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200334 ({ \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200335 rettype __ret; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200336 unsigned long __eax, __edx, __ecx; \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200337 if (sizeof(rettype) > sizeof(unsigned long)) { \
338 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200339 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200340 post \
341 : "=a" (__eax), "=d" (__edx), \
342 "=c" (__ecx) \
343 : paravirt_type(op), \
344 paravirt_clobber(CLBR_ANY), \
345 ##__VA_ARGS__ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200346 : "memory", "cc"); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200347 __ret = (rettype)((((u64)__edx) << 32) | __eax); \
348 } else { \
349 asm volatile(pre \
350 paravirt_alt(PARAVIRT_CALL) \
351 post \
352 : "=a" (__eax), "=d" (__edx), \
353 "=c" (__ecx) \
354 : paravirt_type(op), \
355 paravirt_clobber(CLBR_ANY), \
356 ##__VA_ARGS__ \
357 : "memory", "cc"); \
358 __ret = (rettype)__eax; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200359 } \
360 __ret; \
361 })
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200362#define __PVOP_VCALL(op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200363 ({ \
364 unsigned long __eax, __edx, __ecx; \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200365 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200366 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200367 post \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200368 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200369 : paravirt_type(op), \
370 paravirt_clobber(CLBR_ANY), \
371 ##__VA_ARGS__ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200372 : "memory", "cc"); \
373 })
374
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200375#define PVOP_CALL0(rettype, op) \
376 __PVOP_CALL(rettype, op, "", "")
377#define PVOP_VCALL0(op) \
378 __PVOP_VCALL(op, "", "")
379
380#define PVOP_CALL1(rettype, op, arg1) \
381 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)))
382#define PVOP_VCALL1(op, arg1) \
383 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)))
384
385#define PVOP_CALL2(rettype, op, arg1, arg2) \
386 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)), "1" ((u32)(arg2)))
387#define PVOP_VCALL2(op, arg1, arg2) \
388 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)), "1" ((u32)(arg2)))
389
390#define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \
391 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)), \
392 "1"((u32)(arg2)), "2"((u32)(arg3)))
393#define PVOP_VCALL3(op, arg1, arg2, arg3) \
394 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)), "1"((u32)(arg2)), \
395 "2"((u32)(arg3)))
396
397#define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
398 __PVOP_CALL(rettype, op, \
399 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
400 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
401 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
402#define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
403 __PVOP_VCALL(op, \
404 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
405 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
406 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
407
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200408static inline int paravirt_enabled(void)
409{
410 return paravirt_ops.paravirt_enabled;
411}
Rusty Russelld3561b72006-12-07 02:14:07 +0100412
413static inline void load_esp0(struct tss_struct *tss,
414 struct thread_struct *thread)
415{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200416 PVOP_VCALL2(load_esp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100417}
418
419#define ARCH_SETUP paravirt_ops.arch_setup();
420static inline unsigned long get_wallclock(void)
421{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200422 return PVOP_CALL0(unsigned long, get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100423}
424
425static inline int set_wallclock(unsigned long nowtime)
426{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200427 return PVOP_CALL1(int, set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100428}
429
Zachary Amsdene30fab32007-03-05 00:30:39 -0800430static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100431{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800432 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100433}
434
435/* The paravirtualized CPUID instruction. */
436static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
437 unsigned int *ecx, unsigned int *edx)
438{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200439 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100440}
441
442/*
443 * These special macros can be used to get or set a debugging register
444 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200445static inline unsigned long paravirt_get_debugreg(int reg)
446{
447 return PVOP_CALL1(unsigned long, get_debugreg, reg);
448}
449#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
450static inline void set_debugreg(unsigned long val, int reg)
451{
452 PVOP_VCALL2(set_debugreg, reg, val);
453}
Rusty Russelld3561b72006-12-07 02:14:07 +0100454
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200455static inline void clts(void)
456{
457 PVOP_VCALL0(clts);
458}
Rusty Russelld3561b72006-12-07 02:14:07 +0100459
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200460static inline unsigned long read_cr0(void)
461{
462 return PVOP_CALL0(unsigned long, read_cr0);
463}
Rusty Russelld3561b72006-12-07 02:14:07 +0100464
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200465static inline void write_cr0(unsigned long x)
466{
467 PVOP_VCALL1(write_cr0, x);
468}
Rusty Russelld3561b72006-12-07 02:14:07 +0100469
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200470static inline unsigned long read_cr2(void)
471{
472 return PVOP_CALL0(unsigned long, read_cr2);
473}
Rusty Russelld3561b72006-12-07 02:14:07 +0100474
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200475static inline void write_cr2(unsigned long x)
476{
477 PVOP_VCALL1(write_cr2, x);
478}
Rusty Russelld3561b72006-12-07 02:14:07 +0100479
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200480static inline unsigned long read_cr3(void)
481{
482 return PVOP_CALL0(unsigned long, read_cr3);
483}
484
485static inline void write_cr3(unsigned long x)
486{
487 PVOP_VCALL1(write_cr3, x);
488}
489
490static inline unsigned long read_cr4(void)
491{
492 return PVOP_CALL0(unsigned long, read_cr4);
493}
494static inline unsigned long read_cr4_safe(void)
495{
496 return PVOP_CALL0(unsigned long, read_cr4_safe);
497}
498
499static inline void write_cr4(unsigned long x)
500{
501 PVOP_VCALL1(write_cr4, x);
502}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200503
Rusty Russelld3561b72006-12-07 02:14:07 +0100504static inline void raw_safe_halt(void)
505{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200506 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100507}
508
509static inline void halt(void)
510{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200511 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100512}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200513
514static inline void wbinvd(void)
515{
516 PVOP_VCALL0(wbinvd);
517}
Rusty Russelld3561b72006-12-07 02:14:07 +0100518
519#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
520
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200521static inline u64 paravirt_read_msr(unsigned msr, int *err)
522{
523 return PVOP_CALL2(u64, read_msr, msr, err);
524}
525static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
526{
527 return PVOP_CALL3(int, write_msr, msr, low, high);
528}
529
Rusty Russell90a0a062007-05-02 19:27:10 +0200530/* These should all do BUG_ON(_err), but our headers are too tangled. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200531#define rdmsr(msr,val1,val2) do { \
532 int _err; \
533 u64 _l = paravirt_read_msr(msr, &_err); \
534 val1 = (u32)_l; \
535 val2 = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100536} while(0)
537
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200538#define wrmsr(msr,val1,val2) do { \
539 paravirt_write_msr(msr, val1, val2); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100540} while(0)
541
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200542#define rdmsrl(msr,val) do { \
543 int _err; \
544 val = paravirt_read_msr(msr, &_err); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100545} while(0)
546
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200547#define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
548#define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100549
550/* rdmsr with exception handling */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200551#define rdmsr_safe(msr,a,b) ({ \
552 int _err; \
553 u64 _l = paravirt_read_msr(msr, &_err); \
554 (*a) = (u32)_l; \
555 (*b) = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100556 _err; })
557
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200558
559static inline u64 paravirt_read_tsc(void)
560{
561 return PVOP_CALL0(u64, read_tsc);
562}
563#define rdtsc(low,high) do { \
564 u64 _l = paravirt_read_tsc(); \
565 low = (u32)_l; \
566 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100567} while(0)
568
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200569#define rdtscl(low) do { \
570 u64 _l = paravirt_read_tsc(); \
571 low = (int)_l; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100572} while(0)
573
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200574#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100575
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800576#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800577#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800578
Rusty Russelld3561b72006-12-07 02:14:07 +0100579#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
580
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200581static inline unsigned long long paravirt_read_pmc(int counter)
582{
583 return PVOP_CALL1(u64, read_pmc, counter);
584}
585
586#define rdpmc(counter,low,high) do { \
587 u64 _l = paravirt_read_pmc(counter); \
588 low = (u32)_l; \
589 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100590} while(0)
591
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200592static inline void load_TR_desc(void)
593{
594 PVOP_VCALL0(load_tr_desc);
595}
596static inline void load_gdt(const struct Xgt_desc_struct *dtr)
597{
598 PVOP_VCALL1(load_gdt, dtr);
599}
600static inline void load_idt(const struct Xgt_desc_struct *dtr)
601{
602 PVOP_VCALL1(load_idt, dtr);
603}
604static inline void set_ldt(const void *addr, unsigned entries)
605{
606 PVOP_VCALL2(set_ldt, addr, entries);
607}
608static inline void store_gdt(struct Xgt_desc_struct *dtr)
609{
610 PVOP_VCALL1(store_gdt, dtr);
611}
612static inline void store_idt(struct Xgt_desc_struct *dtr)
613{
614 PVOP_VCALL1(store_idt, dtr);
615}
616static inline unsigned long paravirt_store_tr(void)
617{
618 return PVOP_CALL0(unsigned long, store_tr);
619}
620#define store_tr(tr) ((tr) = paravirt_store_tr())
621static inline void load_TLS(struct thread_struct *t, unsigned cpu)
622{
623 PVOP_VCALL2(load_tls, t, cpu);
624}
625static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
626{
627 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
628}
629static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
630{
631 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
632}
633static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
634{
635 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
636}
637static inline void set_iopl_mask(unsigned mask)
638{
639 PVOP_VCALL1(set_iopl_mask, mask);
640}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200641
Rusty Russelld3561b72006-12-07 02:14:07 +0100642/* The paravirtualized I/O functions */
643static inline void slow_down_io(void) {
644 paravirt_ops.io_delay();
645#ifdef REALLY_SLOW_IO
646 paravirt_ops.io_delay();
647 paravirt_ops.io_delay();
648 paravirt_ops.io_delay();
649#endif
650}
651
Rusty Russell13623d72006-12-07 02:14:08 +0100652#ifdef CONFIG_X86_LOCAL_APIC
653/*
654 * Basic functions accessing APICs.
655 */
656static inline void apic_write(unsigned long reg, unsigned long v)
657{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200658 PVOP_VCALL2(apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100659}
660
661static inline void apic_write_atomic(unsigned long reg, unsigned long v)
662{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200663 PVOP_VCALL2(apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100664}
665
666static inline unsigned long apic_read(unsigned long reg)
667{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200668 return PVOP_CALL1(unsigned long, apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100669}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100670
671static inline void setup_boot_clock(void)
672{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200673 PVOP_VCALL0(setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100674}
675
676static inline void setup_secondary_clock(void)
677{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200678 PVOP_VCALL0(setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100679}
Rusty Russell13623d72006-12-07 02:14:08 +0100680#endif
681
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200682static inline void paravirt_pagetable_setup_start(pgd_t *base)
683{
684 if (paravirt_ops.pagetable_setup_start)
685 (*paravirt_ops.pagetable_setup_start)(base);
686}
687
688static inline void paravirt_pagetable_setup_done(pgd_t *base)
689{
690 if (paravirt_ops.pagetable_setup_done)
691 (*paravirt_ops.pagetable_setup_done)(base);
692}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200693
Zachary Amsdenae5da272007-02-13 13:26:21 +0100694#ifdef CONFIG_SMP
695static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
696 unsigned long start_esp)
697{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200698 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100699}
700#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100701
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200702static inline void paravirt_activate_mm(struct mm_struct *prev,
703 struct mm_struct *next)
704{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200705 PVOP_VCALL2(activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200706}
707
708static inline void arch_dup_mmap(struct mm_struct *oldmm,
709 struct mm_struct *mm)
710{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200711 PVOP_VCALL2(dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200712}
713
714static inline void arch_exit_mmap(struct mm_struct *mm)
715{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200716 PVOP_VCALL1(exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200717}
718
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200719static inline void __flush_tlb(void)
720{
721 PVOP_VCALL0(flush_tlb_user);
722}
723static inline void __flush_tlb_global(void)
724{
725 PVOP_VCALL0(flush_tlb_kernel);
726}
727static inline void __flush_tlb_single(unsigned long addr)
728{
729 PVOP_VCALL1(flush_tlb_single, addr);
730}
Rusty Russellda181a82006-12-07 02:14:08 +0100731
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200732static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
733 unsigned long va)
734{
735 PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va);
736}
737
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200738static inline void paravirt_alloc_pt(unsigned pfn)
739{
740 PVOP_VCALL1(alloc_pt, pfn);
741}
742static inline void paravirt_release_pt(unsigned pfn)
743{
744 PVOP_VCALL1(release_pt, pfn);
745}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100746
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200747static inline void paravirt_alloc_pd(unsigned pfn)
748{
749 PVOP_VCALL1(alloc_pd, pfn);
750}
751
752static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
753 unsigned start, unsigned count)
754{
755 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
756}
757static inline void paravirt_release_pd(unsigned pfn)
758{
759 PVOP_VCALL1(release_pd, pfn);
760}
761
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200762#ifdef CONFIG_HIGHPTE
763static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
764{
765 unsigned long ret;
766 ret = PVOP_CALL2(unsigned long, kmap_atomic_pte, page, type);
767 return (void *)ret;
768}
769#endif
770
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200771static inline void pte_update(struct mm_struct *mm, unsigned long addr,
772 pte_t *ptep)
773{
774 PVOP_VCALL3(pte_update, mm, addr, ptep);
775}
776
777static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
778 pte_t *ptep)
779{
780 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
781}
782
783#ifdef CONFIG_X86_PAE
784static inline pte_t __pte(unsigned long long val)
785{
786 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
787 val, val >> 32);
788 return (pte_t) { ret, ret >> 32 };
789}
790
791static inline pmd_t __pmd(unsigned long long val)
792{
793 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
794}
795
796static inline pgd_t __pgd(unsigned long long val)
797{
798 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
799}
800
801static inline unsigned long long pte_val(pte_t x)
802{
803 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
804}
805
806static inline unsigned long long pmd_val(pmd_t x)
807{
808 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
809}
810
811static inline unsigned long long pgd_val(pgd_t x)
812{
813 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
814}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100815
Rusty Russellda181a82006-12-07 02:14:08 +0100816static inline void set_pte(pte_t *ptep, pte_t pteval)
817{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200818 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
Rusty Russellda181a82006-12-07 02:14:08 +0100819}
820
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200821static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
822 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100823{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200824 /* 5 arg words */
Rusty Russellda181a82006-12-07 02:14:08 +0100825 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
826}
827
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200828static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
829{
830 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
831}
832
833static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
834 pte_t *ptep, pte_t pte)
835{
836 /* 5 arg words */
837 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
838}
839
Rusty Russellda181a82006-12-07 02:14:08 +0100840static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
841{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200842 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100843}
844
845static inline void set_pud(pud_t *pudp, pud_t pudval)
846{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200847 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100848}
849
850static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
851{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200852 PVOP_VCALL3(pte_clear, mm, addr, ptep);
Rusty Russellda181a82006-12-07 02:14:08 +0100853}
854
855static inline void pmd_clear(pmd_t *pmdp)
856{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200857 PVOP_VCALL1(pmd_clear, pmdp);
Rusty Russellda181a82006-12-07 02:14:08 +0100858}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200859
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200860#else /* !CONFIG_X86_PAE */
Jeremy Fitzhardinge4cdd9c82007-05-02 19:27:15 +0200861
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200862static inline pte_t __pte(unsigned long val)
863{
864 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
865}
866
867static inline pgd_t __pgd(unsigned long val)
868{
869 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
870}
871
872static inline unsigned long pte_val(pte_t x)
873{
874 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
875}
876
877static inline unsigned long pgd_val(pgd_t x)
878{
879 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
880}
881
882static inline void set_pte(pte_t *ptep, pte_t pteval)
883{
884 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
885}
886
887static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
888 pte_t *ptep, pte_t pteval)
889{
890 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
891}
892
893static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
894{
895 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
896}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200897#endif /* CONFIG_X86_PAE */
Rusty Russellda181a82006-12-07 02:14:08 +0100898
Zachary Amsden9226d122007-02-13 13:26:21 +0100899#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200900static inline void arch_enter_lazy_cpu_mode(void)
901{
902 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
903}
904
905static inline void arch_leave_lazy_cpu_mode(void)
906{
907 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
908}
909
910static inline void arch_flush_lazy_cpu_mode(void)
911{
912 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
913}
914
Zachary Amsden9226d122007-02-13 13:26:21 +0100915
916#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200917static inline void arch_enter_lazy_mmu_mode(void)
918{
919 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
920}
921
922static inline void arch_leave_lazy_mmu_mode(void)
923{
924 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
925}
926
927static inline void arch_flush_lazy_mmu_mode(void)
928{
929 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
930}
Zachary Amsden9226d122007-02-13 13:26:21 +0100931
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200932void _paravirt_nop(void);
933#define paravirt_nop ((void *)_paravirt_nop)
934
Rusty Russell139ec7c2006-12-07 02:14:08 +0100935/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200936struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +0100937 u8 *instr; /* original instructions */
938 u8 instrtype; /* type of this instruction */
939 u8 len; /* length of original instruction */
940 u16 clobbers; /* what registers you may clobber */
941};
942
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200943extern struct paravirt_patch_site __parainstructions[],
944 __parainstructions_end[];
945
Rusty Russell139ec7c2006-12-07 02:14:08 +0100946static inline unsigned long __raw_local_save_flags(void)
947{
948 unsigned long f;
949
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200950 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
951 PARAVIRT_CALL
952 "popl %%edx; popl %%ecx")
953 : "=a"(f)
954 : paravirt_type(save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200955 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200956 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100957 return f;
958}
959
960static inline void raw_local_irq_restore(unsigned long f)
961{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200962 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
963 PARAVIRT_CALL
964 "popl %%edx; popl %%ecx")
965 : "=a"(f)
966 : "0"(f),
967 paravirt_type(restore_fl),
968 paravirt_clobber(CLBR_EAX)
969 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100970}
971
972static inline void raw_local_irq_disable(void)
973{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200974 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
975 PARAVIRT_CALL
976 "popl %%edx; popl %%ecx")
977 :
978 : paravirt_type(irq_disable),
979 paravirt_clobber(CLBR_EAX)
980 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100981}
982
983static inline void raw_local_irq_enable(void)
984{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200985 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
986 PARAVIRT_CALL
987 "popl %%edx; popl %%ecx")
988 :
989 : paravirt_type(irq_enable),
990 paravirt_clobber(CLBR_EAX)
991 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100992}
993
994static inline unsigned long __raw_local_irq_save(void)
995{
996 unsigned long f;
997
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200998 f = __raw_local_save_flags();
999 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001000 return f;
1001}
1002
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001003#define CLI_STRING \
1004 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1005 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1006 "popl %%edx; popl %%ecx", \
1007 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
Rusty Russell139ec7c2006-12-07 02:14:08 +01001008
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001009#define STI_STRING \
1010 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1011 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1012 "popl %%edx; popl %%ecx", \
1013 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1014
Rusty Russell139ec7c2006-12-07 02:14:08 +01001015#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001016#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001017 , \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001018 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1019 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1020 paravirt_clobber(CLBR_EAX)
1021
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001022/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001023#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +02001024#undef __PVOP_CALL
1025#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001026#undef PVOP_VCALL0
1027#undef PVOP_CALL0
1028#undef PVOP_VCALL1
1029#undef PVOP_CALL1
1030#undef PVOP_VCALL2
1031#undef PVOP_CALL2
1032#undef PVOP_VCALL3
1033#undef PVOP_CALL3
1034#undef PVOP_VCALL4
1035#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001036
Rusty Russelld3561b72006-12-07 02:14:07 +01001037#else /* __ASSEMBLY__ */
1038
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001039#define PARA_PATCH(off) ((off) / 4)
1040
1041#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001042771:; \
1043 ops; \
1044772:; \
1045 .pushsection .parainstructions,"a"; \
1046 .long 771b; \
1047 .byte ptype; \
1048 .byte 772b-771b; \
1049 .short clobbers; \
1050 .popsection
1051
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001052#define INTERRUPT_RETURN \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001053 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001054 jmp *%cs:paravirt_ops+PARAVIRT_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001055
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001056#define DISABLE_INTERRUPTS(clobbers) \
1057 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001058 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001059 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001060 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001061
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001062#define ENABLE_INTERRUPTS(clobbers) \
1063 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001064 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001065 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001066 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001067
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001068#define ENABLE_INTERRUPTS_SYSEXIT \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001069 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001070 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001071
1072#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001073 push %ecx; push %edx; \
1074 call *paravirt_ops+PARAVIRT_read_cr0; \
1075 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +01001076
Rusty Russelld3561b72006-12-07 02:14:07 +01001077#endif /* __ASSEMBLY__ */
1078#endif /* CONFIG_PARAVIRT */
1079#endif /* __ASM_PARAVIRT_H */