blob: 4782be68d0fac3b890ff1067d3f3c78e8c446915 [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
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070028/* general info */
29struct pv_info {
Rusty Russelld3561b72006-12-07 02:14:07 +010030 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020031 int shared_kernel_pmd;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070032 int paravirt_enabled;
Rusty Russelld3561b72006-12-07 02:14:07 +010033 const char *name;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070034};
Rusty Russelld3561b72006-12-07 02:14:07 +010035
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070036struct pv_init_ops {
Rusty Russell139ec7c2006-12-07 02:14:08 +010037 /*
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070038 * Patch may replace one of the defined code sequences with
39 * arbitrary code, subject to the same register constraints.
40 * This generally means the code is not free to clobber any
41 * registers other than EAX. The patch function should return
42 * the number of bytes of code generated, as we nop pad the
43 * rest in generic code.
Rusty Russell139ec7c2006-12-07 02:14:08 +010044 */
Andi Kleenab144f52007-08-10 22:31:03 +020045 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
46 unsigned long addr, unsigned len);
Rusty Russell139ec7c2006-12-07 02:14:08 +010047
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020048 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010049 void (*arch_setup)(void);
50 char *(*memory_setup)(void);
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -070051 void (*post_allocator_init)(void);
52
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020053 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010054 void (*banner)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070055};
56
57
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -070058struct pv_lazy_ops {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070059 /* Set deferred update mode, used for batching operations. */
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -070060 void (*enter)(void);
61 void (*leave)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070062};
63
64struct pv_time_ops {
65 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010066
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020067 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +010068 unsigned long (*get_wallclock)(void);
69 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010070
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070071 unsigned long long (*sched_clock)(void);
72 unsigned long (*get_cpu_khz)(void);
73};
Rusty Russelld3561b72006-12-07 02:14:07 +010074
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070075struct pv_cpu_ops {
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020076 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010077 unsigned long (*get_debugreg)(int regno);
78 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010079
Andi Kleen1a1eecd2007-02-13 13:26:25 +010080 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010081
Andi Kleen1a1eecd2007-02-13 13:26:25 +010082 unsigned long (*read_cr0)(void);
83 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010084
Andi Kleen1a1eecd2007-02-13 13:26:25 +010085 unsigned long (*read_cr4_safe)(void);
86 unsigned long (*read_cr4)(void);
87 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010088
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020089 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010090 void (*load_tr_desc)(void);
91 void (*load_gdt)(const struct Xgt_desc_struct *);
92 void (*load_idt)(const struct Xgt_desc_struct *);
93 void (*store_gdt)(struct Xgt_desc_struct *);
94 void (*store_idt)(struct Xgt_desc_struct *);
95 void (*set_ldt)(const void *desc, unsigned entries);
96 unsigned long (*store_tr)(void);
97 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +020098 void (*write_ldt_entry)(struct desc_struct *,
99 int entrynum, u32 low, u32 high);
100 void (*write_gdt_entry)(struct desc_struct *,
101 int entrynum, u32 low, u32 high);
102 void (*write_idt_entry)(struct desc_struct *,
103 int entrynum, u32 low, u32 high);
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100104 void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100105
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100106 void (*set_iopl_mask)(unsigned mask);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700107
108 void (*wbinvd)(void);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100109 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100110
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700111 /* cpuid emulation, mostly so that caps bits can be disabled */
112 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
113 unsigned int *ecx, unsigned int *edx);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200114
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700115 /* MSR, PMC and TSR operations.
116 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
117 u64 (*read_msr)(unsigned int msr, int *err);
118 int (*write_msr)(unsigned int msr, u64 val);
119
120 u64 (*read_tsc)(void);
Glauber de Oliveira Costab8d1fae2008-01-30 13:31:07 +0100121 u64 (*read_pmc)(int counter);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700122
123 /* These two are jmp to, not actually called. */
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100124 void (*irq_enable_syscall_ret)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700125 void (*iret)(void);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700126
127 struct pv_lazy_ops lazy_mode;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700128};
129
130struct pv_irq_ops {
131 void (*init_IRQ)(void);
132
133 /*
134 * Get/set interrupt state. save_fl and restore_fl are only
135 * expected to use X86_EFLAGS_IF; all other bits
136 * returned from save_fl are undefined, and may be ignored by
137 * restore_fl.
138 */
139 unsigned long (*save_fl)(void);
140 void (*restore_fl)(unsigned long);
141 void (*irq_disable)(void);
142 void (*irq_enable)(void);
143 void (*safe_halt)(void);
144 void (*halt)(void);
145};
146
147struct pv_apic_ops {
Rusty Russell13623d72006-12-07 02:14:08 +0100148#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200149 /*
150 * Direct APIC operations, principally for VMI. Ideally
151 * these shouldn't be in this interface.
152 */
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100153 void (*apic_write)(unsigned long reg, u32 v);
154 void (*apic_write_atomic)(unsigned long reg, u32 v);
155 u32 (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100156 void (*setup_boot_clock)(void);
157 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200158
159 void (*startup_ipi_hook)(int phys_apicid,
160 unsigned long start_eip,
161 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100162#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700163};
164
165struct pv_mmu_ops {
166 /*
167 * Called before/after init_mm pagetable setup. setup_start
168 * may reset %cr3, and may pre-install parts of the pagetable;
169 * pagetable setup is expected to preserve any existing
170 * mapping.
171 */
172 void (*pagetable_setup_start)(pgd_t *pgd_base);
173 void (*pagetable_setup_done)(pgd_t *pgd_base);
174
175 unsigned long (*read_cr2)(void);
176 void (*write_cr2)(unsigned long);
177
178 unsigned long (*read_cr3)(void);
179 void (*write_cr3)(unsigned long);
180
181 /*
182 * Hooks for intercepting the creation/use/destruction of an
183 * mm_struct.
184 */
185 void (*activate_mm)(struct mm_struct *prev,
186 struct mm_struct *next);
187 void (*dup_mmap)(struct mm_struct *oldmm,
188 struct mm_struct *mm);
189 void (*exit_mmap)(struct mm_struct *mm);
190
Rusty Russell13623d72006-12-07 02:14:08 +0100191
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200192 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100193 void (*flush_tlb_user)(void);
194 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200195 void (*flush_tlb_single)(unsigned long addr);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200196 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
197 unsigned long va);
Rusty Russellda181a82006-12-07 02:14:08 +0100198
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200199 /* Hooks for allocating/releasing pagetable pages */
Jeremy Fitzhardingefdb4c332007-07-17 18:37:03 -0700200 void (*alloc_pt)(struct mm_struct *mm, u32 pfn);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100201 void (*alloc_pd)(u32 pfn);
202 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
203 void (*release_pt)(u32 pfn);
204 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100205
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200206 /* Pagetable manipulation functions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100207 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200208 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
209 pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100210 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200211 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200212 void (*pte_update_defer)(struct mm_struct *mm,
213 unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200214
Rusty Russellda181a82006-12-07 02:14:08 +0100215#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100216 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700217 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr,
218 pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100219 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700220 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100221 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200222
223 unsigned long long (*pte_val)(pte_t);
224 unsigned long long (*pmd_val)(pmd_t);
225 unsigned long long (*pgd_val)(pgd_t);
226
227 pte_t (*make_pte)(unsigned long long pte);
228 pmd_t (*make_pmd)(unsigned long long pmd);
229 pgd_t (*make_pgd)(unsigned long long pgd);
230#else
231 unsigned long (*pte_val)(pte_t);
232 unsigned long (*pgd_val)(pgd_t);
233
234 pte_t (*make_pte)(unsigned long pte);
235 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100236#endif
237
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700238#ifdef CONFIG_HIGHPTE
239 void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
240#endif
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700241
242 struct pv_lazy_ops lazy_mode;
Rusty Russelld3561b72006-12-07 02:14:07 +0100243};
244
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700245/* This contains all the paravirt structures: we get a convenient
246 * number for each function using the offset which we use to indicate
247 * what to patch. */
248struct paravirt_patch_template
249{
250 struct pv_init_ops pv_init_ops;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700251 struct pv_time_ops pv_time_ops;
252 struct pv_cpu_ops pv_cpu_ops;
253 struct pv_irq_ops pv_irq_ops;
254 struct pv_apic_ops pv_apic_ops;
255 struct pv_mmu_ops pv_mmu_ops;
256};
257
258extern struct pv_info pv_info;
259extern struct pv_init_ops pv_init_ops;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700260extern struct pv_time_ops pv_time_ops;
261extern struct pv_cpu_ops pv_cpu_ops;
262extern struct pv_irq_ops pv_irq_ops;
263extern struct pv_apic_ops pv_apic_ops;
264extern struct pv_mmu_ops pv_mmu_ops;
Rusty Russelld3561b72006-12-07 02:14:07 +0100265
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200266#define PARAVIRT_PATCH(x) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700267 (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200268
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700269#define paravirt_type(op) \
270 [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \
271 [paravirt_opptr] "m" (op)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200272#define paravirt_clobber(clobber) \
273 [paravirt_clobber] "i" (clobber)
274
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200275/*
276 * Generate some code, and mark it as patchable by the
277 * apply_paravirt() alternate instruction patcher.
278 */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200279#define _paravirt_alt(insn_string, type, clobber) \
280 "771:\n\t" insn_string "\n" "772:\n" \
281 ".pushsection .parainstructions,\"a\"\n" \
282 " .long 771b\n" \
283 " .byte " type "\n" \
284 " .byte 772b-771b\n" \
285 " .short " clobber "\n" \
286 ".popsection\n"
287
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200288/* Generate patchable code, with the default asm parameters. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200289#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200290 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
291
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200292unsigned paravirt_patch_nop(void);
293unsigned paravirt_patch_ignore(unsigned len);
Andi Kleenab144f52007-08-10 22:31:03 +0200294unsigned paravirt_patch_call(void *insnbuf,
295 const void *target, u16 tgt_clobbers,
296 unsigned long addr, u16 site_clobbers,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200297 unsigned len);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700298unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
Andi Kleenab144f52007-08-10 22:31:03 +0200299 unsigned long addr, unsigned len);
300unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
301 unsigned long addr, unsigned len);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200302
Andi Kleenab144f52007-08-10 22:31:03 +0200303unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200304 const char *start, const char *end);
305
Jeremy Fitzhardinged5729292007-07-17 18:37:04 -0700306int paravirt_disable_iospace(void);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200307
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200308/*
309 * This generates an indirect call based on the operation type number.
310 * The type number, computed in PARAVIRT_PATCH, is derived from the
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700311 * offset into the paravirt_patch_template structure, and can therefore be
312 * freely converted back into a structure offset.
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200313 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700314#define PARAVIRT_CALL "call *%[paravirt_opptr];"
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200315
316/*
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700317 * These macros are intended to wrap calls through one of the paravirt
318 * ops structs, so that they can be later identified and patched at
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200319 * runtime.
320 *
321 * Normally, a call to a pv_op function is a simple indirect call:
322 * (paravirt_ops.operations)(args...).
323 *
324 * Unfortunately, this is a relatively slow operation for modern CPUs,
325 * because it cannot necessarily determine what the destination
326 * address is. In this case, the address is a runtime constant, so at
327 * the very least we can patch the call to e a simple direct call, or
328 * ideally, patch an inline implementation into the callsite. (Direct
329 * calls are essentially free, because the call and return addresses
330 * are completely predictable.)
331 *
332 * These macros rely on the standard gcc "regparm(3)" calling
333 * convention, in which the first three arguments are placed in %eax,
334 * %edx, %ecx (in that order), and the remaining arguments are placed
335 * on the stack. All caller-save registers (eax,edx,ecx) are expected
336 * to be modified (either clobbered or used for return values).
337 *
338 * The call instruction itself is marked by placing its start address
339 * and size into the .parainstructions section, so that
340 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700341 * appropriate patching under the control of the backend pv_init_ops
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200342 * implementation.
343 *
344 * Unfortunately there's no way to get gcc to generate the args setup
345 * for the call, and then allow the call itself to be generated by an
346 * inline asm. Because of this, we must do the complete arg setup and
347 * return value handling from within these macros. This is fairly
348 * cumbersome.
349 *
350 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
351 * It could be extended to more arguments, but there would be little
352 * to be gained from that. For each number of arguments, there are
353 * the two VCALL and CALL variants for void and non-void functions.
354 *
355 * When there is a return value, the invoker of the macro must specify
356 * the return type. The macro then uses sizeof() on that type to
357 * determine whether its a 32 or 64 bit value, and places the return
358 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
359 * 64-bit).
360 *
361 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
362 * in low,high order.
363 *
364 * Small structures are passed and returned in registers. The macro
365 * calling convention can't directly deal with this, so the wrapper
366 * functions must do this.
367 *
368 * These PVOP_* macros are only defined within this header. This
369 * means that all uses must be wrapped in inline functions. This also
370 * makes sure the incoming and outgoing types are always correct.
371 */
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200372#define __PVOP_CALL(rettype, op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200373 ({ \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200374 rettype __ret; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200375 unsigned long __eax, __edx, __ecx; \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200376 if (sizeof(rettype) > sizeof(unsigned long)) { \
377 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200378 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200379 post \
380 : "=a" (__eax), "=d" (__edx), \
381 "=c" (__ecx) \
382 : paravirt_type(op), \
383 paravirt_clobber(CLBR_ANY), \
384 ##__VA_ARGS__ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200385 : "memory", "cc"); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200386 __ret = (rettype)((((u64)__edx) << 32) | __eax); \
387 } else { \
388 asm volatile(pre \
389 paravirt_alt(PARAVIRT_CALL) \
390 post \
391 : "=a" (__eax), "=d" (__edx), \
392 "=c" (__ecx) \
393 : paravirt_type(op), \
394 paravirt_clobber(CLBR_ANY), \
395 ##__VA_ARGS__ \
396 : "memory", "cc"); \
397 __ret = (rettype)__eax; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200398 } \
399 __ret; \
400 })
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200401#define __PVOP_VCALL(op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200402 ({ \
403 unsigned long __eax, __edx, __ecx; \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200404 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200405 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200406 post \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200407 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200408 : paravirt_type(op), \
409 paravirt_clobber(CLBR_ANY), \
410 ##__VA_ARGS__ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200411 : "memory", "cc"); \
412 })
413
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200414#define PVOP_CALL0(rettype, op) \
415 __PVOP_CALL(rettype, op, "", "")
416#define PVOP_VCALL0(op) \
417 __PVOP_VCALL(op, "", "")
418
419#define PVOP_CALL1(rettype, op, arg1) \
420 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)))
421#define PVOP_VCALL1(op, arg1) \
422 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)))
423
424#define PVOP_CALL2(rettype, op, arg1, arg2) \
425 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)), "1" ((u32)(arg2)))
426#define PVOP_VCALL2(op, arg1, arg2) \
427 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)), "1" ((u32)(arg2)))
428
429#define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \
430 __PVOP_CALL(rettype, op, "", "", "0" ((u32)(arg1)), \
431 "1"((u32)(arg2)), "2"((u32)(arg3)))
432#define PVOP_VCALL3(op, arg1, arg2, arg3) \
433 __PVOP_VCALL(op, "", "", "0" ((u32)(arg1)), "1"((u32)(arg2)), \
434 "2"((u32)(arg3)))
435
436#define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
437 __PVOP_CALL(rettype, op, \
438 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
439 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
440 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
441#define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
442 __PVOP_VCALL(op, \
443 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
444 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
445 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
446
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200447static inline int paravirt_enabled(void)
448{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700449 return pv_info.paravirt_enabled;
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200450}
Rusty Russelld3561b72006-12-07 02:14:07 +0100451
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100452static inline void load_sp0(struct tss_struct *tss,
Rusty Russelld3561b72006-12-07 02:14:07 +0100453 struct thread_struct *thread)
454{
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100455 PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100456}
457
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700458#define ARCH_SETUP pv_init_ops.arch_setup();
Rusty Russelld3561b72006-12-07 02:14:07 +0100459static inline unsigned long get_wallclock(void)
460{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700461 return PVOP_CALL0(unsigned long, pv_time_ops.get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100462}
463
464static inline int set_wallclock(unsigned long nowtime)
465{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700466 return PVOP_CALL1(int, pv_time_ops.set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100467}
468
Zachary Amsdene30fab32007-03-05 00:30:39 -0800469static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100470{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700471 return pv_time_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100472}
473
474/* The paravirtualized CPUID instruction. */
475static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
476 unsigned int *ecx, unsigned int *edx)
477{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700478 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100479}
480
481/*
482 * These special macros can be used to get or set a debugging register
483 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200484static inline unsigned long paravirt_get_debugreg(int reg)
485{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700486 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200487}
488#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
489static inline void set_debugreg(unsigned long val, int reg)
490{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700491 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200492}
Rusty Russelld3561b72006-12-07 02:14:07 +0100493
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200494static inline void clts(void)
495{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700496 PVOP_VCALL0(pv_cpu_ops.clts);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200497}
Rusty Russelld3561b72006-12-07 02:14:07 +0100498
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200499static inline unsigned long read_cr0(void)
500{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700501 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200502}
Rusty Russelld3561b72006-12-07 02:14:07 +0100503
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200504static inline void write_cr0(unsigned long x)
505{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700506 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200507}
Rusty Russelld3561b72006-12-07 02:14:07 +0100508
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200509static inline unsigned long read_cr2(void)
510{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700511 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200512}
Rusty Russelld3561b72006-12-07 02:14:07 +0100513
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200514static inline void write_cr2(unsigned long x)
515{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700516 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200517}
Rusty Russelld3561b72006-12-07 02:14:07 +0100518
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200519static inline unsigned long read_cr3(void)
520{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700521 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200522}
523
524static inline void write_cr3(unsigned long x)
525{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700526 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200527}
528
529static inline unsigned long read_cr4(void)
530{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700531 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200532}
533static inline unsigned long read_cr4_safe(void)
534{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700535 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200536}
537
538static inline void write_cr4(unsigned long x)
539{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700540 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200541}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200542
Rusty Russelld3561b72006-12-07 02:14:07 +0100543static inline void raw_safe_halt(void)
544{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700545 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100546}
547
548static inline void halt(void)
549{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700550 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100551}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200552
553static inline void wbinvd(void)
554{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700555 PVOP_VCALL0(pv_cpu_ops.wbinvd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200556}
Rusty Russelld3561b72006-12-07 02:14:07 +0100557
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700558#define get_kernel_rpl() (pv_info.kernel_rpl)
Rusty Russelld3561b72006-12-07 02:14:07 +0100559
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200560static inline u64 paravirt_read_msr(unsigned msr, int *err)
561{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700562 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200563}
564static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
565{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700566 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200567}
568
Rusty Russell90a0a062007-05-02 19:27:10 +0200569/* These should all do BUG_ON(_err), but our headers are too tangled. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200570#define rdmsr(msr,val1,val2) do { \
571 int _err; \
572 u64 _l = paravirt_read_msr(msr, &_err); \
573 val1 = (u32)_l; \
574 val2 = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100575} while(0)
576
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200577#define wrmsr(msr,val1,val2) do { \
578 paravirt_write_msr(msr, val1, val2); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100579} while(0)
580
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200581#define rdmsrl(msr,val) do { \
582 int _err; \
583 val = paravirt_read_msr(msr, &_err); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100584} while(0)
585
Björn Steinbrinkb9e36142007-06-25 23:04:37 +0200586#define wrmsrl(msr,val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200587#define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100588
589/* rdmsr with exception handling */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200590#define rdmsr_safe(msr,a,b) ({ \
591 int _err; \
592 u64 _l = paravirt_read_msr(msr, &_err); \
593 (*a) = (u32)_l; \
594 (*b) = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100595 _err; })
596
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200597
598static inline u64 paravirt_read_tsc(void)
599{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700600 return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200601}
Rusty Russelld3561b72006-12-07 02:14:07 +0100602
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200603#define rdtscl(low) do { \
604 u64 _l = paravirt_read_tsc(); \
605 low = (int)_l; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100606} while(0)
607
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200608#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100609
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700610static inline unsigned long long paravirt_sched_clock(void)
611{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700612 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700613}
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700614#define calculate_cpu_khz() (pv_time_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800615
Rusty Russelld3561b72006-12-07 02:14:07 +0100616#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
617
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200618static inline unsigned long long paravirt_read_pmc(int counter)
619{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700620 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200621}
622
623#define rdpmc(counter,low,high) do { \
624 u64 _l = paravirt_read_pmc(counter); \
625 low = (u32)_l; \
626 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100627} while(0)
628
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200629static inline void load_TR_desc(void)
630{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700631 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200632}
633static inline void load_gdt(const struct Xgt_desc_struct *dtr)
634{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700635 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200636}
637static inline void load_idt(const struct Xgt_desc_struct *dtr)
638{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700639 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200640}
641static inline void set_ldt(const void *addr, unsigned entries)
642{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700643 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200644}
645static inline void store_gdt(struct Xgt_desc_struct *dtr)
646{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700647 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200648}
649static inline void store_idt(struct Xgt_desc_struct *dtr)
650{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700651 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200652}
653static inline unsigned long paravirt_store_tr(void)
654{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700655 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200656}
657#define store_tr(tr) ((tr) = paravirt_store_tr())
658static inline void load_TLS(struct thread_struct *t, unsigned cpu)
659{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700660 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200661}
662static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
663{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700664 PVOP_VCALL4(pv_cpu_ops.write_ldt_entry, dt, entry, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200665}
666static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
667{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700668 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200669}
670static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
671{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700672 PVOP_VCALL4(pv_cpu_ops.write_idt_entry, dt, entry, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200673}
674static inline void set_iopl_mask(unsigned mask)
675{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700676 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200677}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200678
Rusty Russelld3561b72006-12-07 02:14:07 +0100679/* The paravirtualized I/O functions */
680static inline void slow_down_io(void) {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700681 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100682#ifdef REALLY_SLOW_IO
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700683 pv_cpu_ops.io_delay();
684 pv_cpu_ops.io_delay();
685 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100686#endif
687}
688
Rusty Russell13623d72006-12-07 02:14:08 +0100689#ifdef CONFIG_X86_LOCAL_APIC
690/*
691 * Basic functions accessing APICs.
692 */
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100693static inline void apic_write(unsigned long reg, u32 v)
Rusty Russell13623d72006-12-07 02:14:08 +0100694{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700695 PVOP_VCALL2(pv_apic_ops.apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100696}
697
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100698static inline void apic_write_atomic(unsigned long reg, u32 v)
Rusty Russell13623d72006-12-07 02:14:08 +0100699{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700700 PVOP_VCALL2(pv_apic_ops.apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100701}
702
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100703static inline u32 apic_read(unsigned long reg)
Rusty Russell13623d72006-12-07 02:14:08 +0100704{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700705 return PVOP_CALL1(unsigned long, pv_apic_ops.apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100706}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100707
708static inline void setup_boot_clock(void)
709{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700710 PVOP_VCALL0(pv_apic_ops.setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100711}
712
713static inline void setup_secondary_clock(void)
714{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700715 PVOP_VCALL0(pv_apic_ops.setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100716}
Rusty Russell13623d72006-12-07 02:14:08 +0100717#endif
718
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -0700719static inline void paravirt_post_allocator_init(void)
720{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700721 if (pv_init_ops.post_allocator_init)
722 (*pv_init_ops.post_allocator_init)();
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -0700723}
724
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200725static inline void paravirt_pagetable_setup_start(pgd_t *base)
726{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700727 (*pv_mmu_ops.pagetable_setup_start)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200728}
729
730static inline void paravirt_pagetable_setup_done(pgd_t *base)
731{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700732 (*pv_mmu_ops.pagetable_setup_done)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200733}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200734
Zachary Amsdenae5da272007-02-13 13:26:21 +0100735#ifdef CONFIG_SMP
736static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
737 unsigned long start_esp)
738{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700739 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
740 phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100741}
742#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100743
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200744static inline void paravirt_activate_mm(struct mm_struct *prev,
745 struct mm_struct *next)
746{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700747 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200748}
749
750static inline void arch_dup_mmap(struct mm_struct *oldmm,
751 struct mm_struct *mm)
752{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700753 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200754}
755
756static inline void arch_exit_mmap(struct mm_struct *mm)
757{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700758 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200759}
760
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200761static inline void __flush_tlb(void)
762{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700763 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200764}
765static inline void __flush_tlb_global(void)
766{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700767 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200768}
769static inline void __flush_tlb_single(unsigned long addr)
770{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700771 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200772}
Rusty Russellda181a82006-12-07 02:14:08 +0100773
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200774static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
775 unsigned long va)
776{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700777 PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, &cpumask, mm, va);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200778}
779
Jeremy Fitzhardingefdb4c332007-07-17 18:37:03 -0700780static inline void paravirt_alloc_pt(struct mm_struct *mm, unsigned pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200781{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700782 PVOP_VCALL2(pv_mmu_ops.alloc_pt, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200783}
784static inline void paravirt_release_pt(unsigned pfn)
785{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700786 PVOP_VCALL1(pv_mmu_ops.release_pt, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200787}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100788
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200789static inline void paravirt_alloc_pd(unsigned pfn)
790{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700791 PVOP_VCALL1(pv_mmu_ops.alloc_pd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200792}
793
794static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
795 unsigned start, unsigned count)
796{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700797 PVOP_VCALL4(pv_mmu_ops.alloc_pd_clone, pfn, clonepfn, start, count);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200798}
799static inline void paravirt_release_pd(unsigned pfn)
800{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700801 PVOP_VCALL1(pv_mmu_ops.release_pd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200802}
803
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200804#ifdef CONFIG_HIGHPTE
805static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
806{
807 unsigned long ret;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700808 ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type);
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200809 return (void *)ret;
810}
811#endif
812
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200813static inline void pte_update(struct mm_struct *mm, unsigned long addr,
814 pte_t *ptep)
815{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700816 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200817}
818
819static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
820 pte_t *ptep)
821{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700822 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200823}
824
825#ifdef CONFIG_X86_PAE
826static inline pte_t __pte(unsigned long long val)
827{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700828 unsigned long long ret = PVOP_CALL2(unsigned long long,
829 pv_mmu_ops.make_pte,
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200830 val, val >> 32);
831 return (pte_t) { ret, ret >> 32 };
832}
833
834static inline pmd_t __pmd(unsigned long long val)
835{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700836 return (pmd_t) { PVOP_CALL2(unsigned long long, pv_mmu_ops.make_pmd,
837 val, val >> 32) };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200838}
839
840static inline pgd_t __pgd(unsigned long long val)
841{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700842 return (pgd_t) { PVOP_CALL2(unsigned long long, pv_mmu_ops.make_pgd,
843 val, val >> 32) };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200844}
845
846static inline unsigned long long pte_val(pte_t x)
847{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700848 return PVOP_CALL2(unsigned long long, pv_mmu_ops.pte_val,
849 x.pte_low, x.pte_high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200850}
851
852static inline unsigned long long pmd_val(pmd_t x)
853{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700854 return PVOP_CALL2(unsigned long long, pv_mmu_ops.pmd_val,
855 x.pmd, x.pmd >> 32);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200856}
857
858static inline unsigned long long pgd_val(pgd_t x)
859{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700860 return PVOP_CALL2(unsigned long long, pv_mmu_ops.pgd_val,
861 x.pgd, x.pgd >> 32);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200862}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100863
Rusty Russellda181a82006-12-07 02:14:08 +0100864static inline void set_pte(pte_t *ptep, pte_t pteval)
865{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700866 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep, pteval.pte_low, pteval.pte_high);
Rusty Russellda181a82006-12-07 02:14:08 +0100867}
868
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200869static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
870 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100871{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200872 /* 5 arg words */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700873 pv_mmu_ops.set_pte_at(mm, addr, ptep, pteval);
Rusty Russellda181a82006-12-07 02:14:08 +0100874}
875
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200876static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
877{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700878 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
879 pteval.pte_low, pteval.pte_high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200880}
881
882static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
883 pte_t *ptep, pte_t pte)
884{
885 /* 5 arg words */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700886 pv_mmu_ops.set_pte_present(mm, addr, ptep, pte);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200887}
888
Rusty Russellda181a82006-12-07 02:14:08 +0100889static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
890{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700891 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp,
892 pmdval.pmd, pmdval.pmd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100893}
894
895static inline void set_pud(pud_t *pudp, pud_t pudval)
896{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700897 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
898 pudval.pgd.pgd, pudval.pgd.pgd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100899}
900
901static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
902{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700903 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
Rusty Russellda181a82006-12-07 02:14:08 +0100904}
905
906static inline void pmd_clear(pmd_t *pmdp)
907{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700908 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
Rusty Russellda181a82006-12-07 02:14:08 +0100909}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200910
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200911#else /* !CONFIG_X86_PAE */
Jeremy Fitzhardinge4cdd9c82007-05-02 19:27:15 +0200912
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200913static inline pte_t __pte(unsigned long val)
914{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700915 return (pte_t) { PVOP_CALL1(unsigned long, pv_mmu_ops.make_pte, val) };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200916}
917
918static inline pgd_t __pgd(unsigned long val)
919{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700920 return (pgd_t) { PVOP_CALL1(unsigned long, pv_mmu_ops.make_pgd, val) };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200921}
922
923static inline unsigned long pte_val(pte_t x)
924{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700925 return PVOP_CALL1(unsigned long, pv_mmu_ops.pte_val, x.pte_low);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200926}
927
928static inline unsigned long pgd_val(pgd_t x)
929{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700930 return PVOP_CALL1(unsigned long, pv_mmu_ops.pgd_val, x.pgd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200931}
932
933static inline void set_pte(pte_t *ptep, pte_t pteval)
934{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700935 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep, pteval.pte_low);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200936}
937
938static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
939 pte_t *ptep, pte_t pteval)
940{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700941 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pteval.pte_low);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200942}
943
944static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
945{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700946 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, pmdval.pud.pgd.pgd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200947}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200948#endif /* CONFIG_X86_PAE */
Rusty Russellda181a82006-12-07 02:14:08 +0100949
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700950/* Lazy mode for batching updates / context switch */
951enum paravirt_lazy_mode {
952 PARAVIRT_LAZY_NONE,
953 PARAVIRT_LAZY_MMU,
954 PARAVIRT_LAZY_CPU,
955};
956
957enum paravirt_lazy_mode paravirt_get_lazy_mode(void);
958void paravirt_enter_lazy_cpu(void);
959void paravirt_leave_lazy_cpu(void);
960void paravirt_enter_lazy_mmu(void);
961void paravirt_leave_lazy_mmu(void);
962void paravirt_leave_lazy(enum paravirt_lazy_mode mode);
963
Zachary Amsden9226d122007-02-13 13:26:21 +0100964#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200965static inline void arch_enter_lazy_cpu_mode(void)
966{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700967 PVOP_VCALL0(pv_cpu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200968}
969
970static inline void arch_leave_lazy_cpu_mode(void)
971{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700972 PVOP_VCALL0(pv_cpu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200973}
974
975static inline void arch_flush_lazy_cpu_mode(void)
976{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700977 if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_CPU)) {
978 arch_leave_lazy_cpu_mode();
979 arch_enter_lazy_cpu_mode();
980 }
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200981}
982
Zachary Amsden9226d122007-02-13 13:26:21 +0100983
984#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200985static inline void arch_enter_lazy_mmu_mode(void)
986{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700987 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200988}
989
990static inline void arch_leave_lazy_mmu_mode(void)
991{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700992 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200993}
994
995static inline void arch_flush_lazy_mmu_mode(void)
996{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700997 if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU)) {
998 arch_leave_lazy_mmu_mode();
999 arch_enter_lazy_mmu_mode();
1000 }
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001001}
Zachary Amsden9226d122007-02-13 13:26:21 +01001002
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +02001003void _paravirt_nop(void);
1004#define paravirt_nop ((void *)_paravirt_nop)
1005
Rusty Russell139ec7c2006-12-07 02:14:08 +01001006/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001007struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +01001008 u8 *instr; /* original instructions */
1009 u8 instrtype; /* type of this instruction */
1010 u8 len; /* length of original instruction */
1011 u16 clobbers; /* what registers you may clobber */
1012};
1013
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001014extern struct paravirt_patch_site __parainstructions[],
1015 __parainstructions_end[];
1016
Rusty Russell139ec7c2006-12-07 02:14:08 +01001017static inline unsigned long __raw_local_save_flags(void)
1018{
1019 unsigned long f;
1020
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001021 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1022 PARAVIRT_CALL
1023 "popl %%edx; popl %%ecx")
1024 : "=a"(f)
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001025 : paravirt_type(pv_irq_ops.save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001026 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001027 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001028 return f;
1029}
1030
1031static inline void raw_local_irq_restore(unsigned long f)
1032{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001033 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1034 PARAVIRT_CALL
1035 "popl %%edx; popl %%ecx")
1036 : "=a"(f)
1037 : "0"(f),
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001038 paravirt_type(pv_irq_ops.restore_fl),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001039 paravirt_clobber(CLBR_EAX)
1040 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001041}
1042
1043static inline void raw_local_irq_disable(void)
1044{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001045 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1046 PARAVIRT_CALL
1047 "popl %%edx; popl %%ecx")
1048 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001049 : paravirt_type(pv_irq_ops.irq_disable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001050 paravirt_clobber(CLBR_EAX)
1051 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001052}
1053
1054static inline void raw_local_irq_enable(void)
1055{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001056 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
1057 PARAVIRT_CALL
1058 "popl %%edx; popl %%ecx")
1059 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001060 : paravirt_type(pv_irq_ops.irq_enable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001061 paravirt_clobber(CLBR_EAX)
1062 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001063}
1064
1065static inline unsigned long __raw_local_irq_save(void)
1066{
1067 unsigned long f;
1068
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001069 f = __raw_local_save_flags();
1070 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001071 return f;
1072}
1073
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001074#define CLI_STRING \
1075 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001076 "call *%[paravirt_cli_opptr];" \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001077 "popl %%edx; popl %%ecx", \
1078 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
Rusty Russell139ec7c2006-12-07 02:14:08 +01001079
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001080#define STI_STRING \
1081 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001082 "call *%[paravirt_sti_opptr];" \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001083 "popl %%edx; popl %%ecx", \
1084 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1085
Rusty Russell139ec7c2006-12-07 02:14:08 +01001086#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001087#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001088 , \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001089 [paravirt_cli_type] "i" (PARAVIRT_PATCH(pv_irq_ops.irq_disable)), \
1090 [paravirt_cli_opptr] "m" (pv_irq_ops.irq_disable), \
1091 [paravirt_sti_type] "i" (PARAVIRT_PATCH(pv_irq_ops.irq_enable)), \
1092 [paravirt_sti_opptr] "m" (pv_irq_ops.irq_enable), \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001093 paravirt_clobber(CLBR_EAX)
1094
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001095/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001096#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +02001097#undef __PVOP_CALL
1098#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001099#undef PVOP_VCALL0
1100#undef PVOP_CALL0
1101#undef PVOP_VCALL1
1102#undef PVOP_CALL1
1103#undef PVOP_VCALL2
1104#undef PVOP_CALL2
1105#undef PVOP_VCALL3
1106#undef PVOP_CALL3
1107#undef PVOP_VCALL4
1108#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001109
Rusty Russelld3561b72006-12-07 02:14:07 +01001110#else /* __ASSEMBLY__ */
1111
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001112#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001113
1114#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001115771:; \
1116 ops; \
1117772:; \
1118 .pushsection .parainstructions,"a"; \
1119 .long 771b; \
1120 .byte ptype; \
1121 .byte 772b-771b; \
1122 .short clobbers; \
1123 .popsection
1124
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001125#define INTERRUPT_RETURN \
1126 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
1127 jmp *%cs:pv_cpu_ops+PV_CPU_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001128
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001129#define DISABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001130 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001131 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001132 call *%cs:pv_irq_ops+PV_IRQ_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001133 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001134
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001135#define ENABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001136 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001137 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001138 call *%cs:pv_irq_ops+PV_IRQ_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001139 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001140
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +01001141#define ENABLE_INTERRUPTS_SYSCALL_RET \
1142 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_syscall_ret),\
1143 CLBR_NONE, \
1144 jmp *%cs:pv_cpu_ops+PV_CPU_irq_enable_syscall_ret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001145
1146#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001147 push %ecx; push %edx; \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001148 call *pv_cpu_ops+PV_CPU_read_cr0; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001149 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +01001150
Rusty Russelld3561b72006-12-07 02:14:07 +01001151#endif /* __ASSEMBLY__ */
1152#endif /* CONFIG_PARAVIRT */
1153#endif /* __ASM_PARAVIRT_H */