blob: dfdee0ca57d3a3328c6ac4dfe1dde729df5fde6b [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_PARAVIRT_H
2#define _ASM_X86_PARAVIRT_H
Rusty Russelld3561b72006-12-07 02:14:07 +01003/* 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
Jeremy Fitzhardinge54321d92009-02-11 10:20:05 -08007#include <asm/pgtable_types.h>
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01008#include <asm/asm.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01009
Rusty Russell139ec7c2006-12-07 02:14:08 +010010/* Bitmask of what can be clobbered: usually at least eax. */
Glauber de Oliveira Costa21438f72008-01-30 13:32:09 +010011#define CLBR_NONE 0
12#define CLBR_EAX (1 << 0)
13#define CLBR_ECX (1 << 1)
14#define CLBR_EDX (1 << 2)
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -080015#define CLBR_EDI (1 << 3)
Glauber de Oliveira Costa21438f72008-01-30 13:32:09 +010016
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -080017#ifdef CONFIG_X86_32
18/* CLBR_ANY should match all regs platform has. For i386, that's just it */
19#define CLBR_ANY ((1 << 4) - 1)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -080020
21#define CLBR_ARG_REGS (CLBR_EAX | CLBR_EDX | CLBR_ECX)
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -080022#define CLBR_RET_REG (CLBR_EAX | CLBR_EDX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -080023#define CLBR_SCRATCH (0)
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -080024#else
25#define CLBR_RAX CLBR_EAX
26#define CLBR_RCX CLBR_ECX
27#define CLBR_RDX CLBR_EDX
28#define CLBR_RDI CLBR_EDI
29#define CLBR_RSI (1 << 4)
Glauber de Oliveira Costa21438f72008-01-30 13:32:09 +010030#define CLBR_R8 (1 << 5)
31#define CLBR_R9 (1 << 6)
32#define CLBR_R10 (1 << 7)
33#define CLBR_R11 (1 << 8)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -080034
Glauber de Oliveira Costa21438f72008-01-30 13:32:09 +010035#define CLBR_ANY ((1 << 9) - 1)
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -080036
37#define CLBR_ARG_REGS (CLBR_RDI | CLBR_RSI | CLBR_RDX | \
38 CLBR_RCX | CLBR_R8 | CLBR_R9)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -080039#define CLBR_RET_REG (CLBR_RAX)
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -080040#define CLBR_SCRATCH (CLBR_R10 | CLBR_R11)
41
Glauber de Oliveira Costa21438f72008-01-30 13:32:09 +010042#include <asm/desc_defs.h>
Glauber de Oliveira Costa21438f72008-01-30 13:32:09 +010043#endif /* X86_64 */
Rusty Russell139ec7c2006-12-07 02:14:08 +010044
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -080045#define CLBR_CALLEE_SAVE ((CLBR_ARG_REGS | CLBR_SCRATCH) & ~CLBR_RET_REG)
46
Rusty Russelld3561b72006-12-07 02:14:07 +010047#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020048#include <linux/types.h>
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +020049#include <linux/cpumask.h>
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020050#include <asm/kmap_types.h>
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +010051#include <asm/desc_defs.h>
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020052
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020053struct page;
Rusty Russelld3561b72006-12-07 02:14:07 +010054struct thread_struct;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010055struct desc_ptr;
Rusty Russelld3561b72006-12-07 02:14:07 +010056struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010057struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020058struct desc_struct;
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -080059struct task_struct;
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020060
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -080061/*
62 * Wrapper type for pointers to code which uses the non-standard
63 * calling convention. See PV_CALL_SAVE_REGS_THUNK below.
64 */
65struct paravirt_callee_save {
66 void *func;
67};
68
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070069/* general info */
70struct pv_info {
Rusty Russelld3561b72006-12-07 02:14:07 +010071 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020072 int shared_kernel_pmd;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070073 int paravirt_enabled;
Rusty Russelld3561b72006-12-07 02:14:07 +010074 const char *name;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070075};
Rusty Russelld3561b72006-12-07 02:14:07 +010076
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070077struct pv_init_ops {
Rusty Russell139ec7c2006-12-07 02:14:08 +010078 /*
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070079 * Patch may replace one of the defined code sequences with
80 * arbitrary code, subject to the same register constraints.
81 * This generally means the code is not free to clobber any
82 * registers other than EAX. The patch function should return
83 * the number of bytes of code generated, as we nop pad the
84 * rest in generic code.
Rusty Russell139ec7c2006-12-07 02:14:08 +010085 */
Andi Kleenab144f52007-08-10 22:31:03 +020086 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
87 unsigned long addr, unsigned len);
Rusty Russell139ec7c2006-12-07 02:14:08 +010088
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020089 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010090 void (*arch_setup)(void);
91 char *(*memory_setup)(void);
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -070092 void (*post_allocator_init)(void);
93
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020094 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010095 void (*banner)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070096};
97
98
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -070099struct pv_lazy_ops {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700100 /* Set deferred update mode, used for batching operations. */
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700101 void (*enter)(void);
102 void (*leave)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700103};
104
105struct pv_time_ops {
106 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100107
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200108 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +0100109 unsigned long (*get_wallclock)(void);
110 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +0100111
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700112 unsigned long long (*sched_clock)(void);
Alok Katariae93ef942008-07-01 11:43:36 -0700113 unsigned long (*get_tsc_khz)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700114};
Rusty Russelld3561b72006-12-07 02:14:07 +0100115
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700116struct pv_cpu_ops {
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200117 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100118 unsigned long (*get_debugreg)(int regno);
119 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +0100120
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100121 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100122
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100123 unsigned long (*read_cr0)(void);
124 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +0100125
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100126 unsigned long (*read_cr4_safe)(void);
127 unsigned long (*read_cr4)(void);
128 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +0100129
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100130#ifdef CONFIG_X86_64
131 unsigned long (*read_cr8)(void);
132 void (*write_cr8)(unsigned long);
133#endif
134
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200135 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100136 void (*load_tr_desc)(void);
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100137 void (*load_gdt)(const struct desc_ptr *);
138 void (*load_idt)(const struct desc_ptr *);
139 void (*store_gdt)(struct desc_ptr *);
140 void (*store_idt)(struct desc_ptr *);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100141 void (*set_ldt)(const void *desc, unsigned entries);
142 unsigned long (*store_tr)(void);
143 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400144#ifdef CONFIG_X86_64
145 void (*load_gs_index)(unsigned int idx);
146#endif
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100147 void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum,
148 const void *desc);
Rusty Russell90a0a062007-05-02 19:27:10 +0200149 void (*write_gdt_entry)(struct desc_struct *,
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100150 int entrynum, const void *desc, int size);
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100151 void (*write_idt_entry)(gate_desc *,
152 int entrynum, const gate_desc *gate);
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700153 void (*alloc_ldt)(struct desc_struct *ldt, unsigned entries);
154 void (*free_ldt)(struct desc_struct *ldt, unsigned entries);
155
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100156 void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100157
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100158 void (*set_iopl_mask)(unsigned mask);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700159
160 void (*wbinvd)(void);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100161 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100162
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700163 /* cpuid emulation, mostly so that caps bits can be disabled */
164 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
165 unsigned int *ecx, unsigned int *edx);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200166
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700167 /* MSR, PMC and TSR operations.
168 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Yinghai Lub05f78f2008-08-22 01:32:50 -0700169 u64 (*read_msr_amd)(unsigned int msr, int *err);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700170 u64 (*read_msr)(unsigned int msr, int *err);
Glauber de Oliveira Costac9dcda52008-01-30 13:31:07 +0100171 int (*write_msr)(unsigned int msr, unsigned low, unsigned high);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700172
173 u64 (*read_tsc)(void);
Glauber de Oliveira Costab8d1fae2008-01-30 13:31:07 +0100174 u64 (*read_pmc)(int counter);
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100175 unsigned long long (*read_tscp)(unsigned int *aux);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700176
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400177 /*
178 * Atomically enable interrupts and return to userspace. This
179 * is only ever used to return to 32-bit processes; in a
180 * 64-bit kernel, it's used for 32-on-64 compat processes, but
181 * never native 64-bit processes. (Jump, not call.)
182 */
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400183 void (*irq_enable_sysexit)(void);
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400184
185 /*
186 * Switch to usermode gs and return to 64-bit usermode using
187 * sysret. Only used in 64-bit kernels to return to 64-bit
188 * processes. Usermode register state, including %rsp, must
189 * already be restored.
190 */
191 void (*usergs_sysret64)(void);
192
193 /*
194 * Switch to usermode gs and return to 32-bit usermode using
195 * sysret. Used to return to 32-on-64 compat processes.
196 * Other usermode register state, including %esp, must already
197 * be restored.
198 */
199 void (*usergs_sysret32)(void);
200
201 /* Normal iret. Jump to this with the standard iret stack
202 frame set up. */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700203 void (*iret)(void);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700204
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +0100205 void (*swapgs)(void);
206
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800207 void (*start_context_switch)(struct task_struct *prev);
208 void (*end_context_switch)(struct task_struct *next);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700209};
210
211struct pv_irq_ops {
212 void (*init_IRQ)(void);
213
214 /*
215 * Get/set interrupt state. save_fl and restore_fl are only
216 * expected to use X86_EFLAGS_IF; all other bits
217 * returned from save_fl are undefined, and may be ignored by
218 * restore_fl.
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800219 *
220 * NOTE: These functions callers expect the callee to preserve
221 * more registers than the standard C calling convention.
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700222 */
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800223 struct paravirt_callee_save save_fl;
224 struct paravirt_callee_save restore_fl;
225 struct paravirt_callee_save irq_disable;
226 struct paravirt_callee_save irq_enable;
227
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700228 void (*safe_halt)(void);
229 void (*halt)(void);
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -0400230
231#ifdef CONFIG_X86_64
232 void (*adjust_exception_frame)(void);
233#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700234};
235
236struct pv_apic_ops {
Rusty Russell13623d72006-12-07 02:14:08 +0100237#ifdef CONFIG_X86_LOCAL_APIC
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100238 void (*setup_boot_clock)(void);
239 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200240
241 void (*startup_ipi_hook)(int phys_apicid,
242 unsigned long start_eip,
243 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100244#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700245};
246
247struct pv_mmu_ops {
248 /*
249 * Called before/after init_mm pagetable setup. setup_start
250 * may reset %cr3, and may pre-install parts of the pagetable;
251 * pagetable setup is expected to preserve any existing
252 * mapping.
253 */
254 void (*pagetable_setup_start)(pgd_t *pgd_base);
255 void (*pagetable_setup_done)(pgd_t *pgd_base);
256
257 unsigned long (*read_cr2)(void);
258 void (*write_cr2)(unsigned long);
259
260 unsigned long (*read_cr3)(void);
261 void (*write_cr3)(unsigned long);
262
263 /*
264 * Hooks for intercepting the creation/use/destruction of an
265 * mm_struct.
266 */
267 void (*activate_mm)(struct mm_struct *prev,
268 struct mm_struct *next);
269 void (*dup_mmap)(struct mm_struct *oldmm,
270 struct mm_struct *mm);
271 void (*exit_mmap)(struct mm_struct *mm);
272
Rusty Russell13623d72006-12-07 02:14:08 +0100273
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200274 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100275 void (*flush_tlb_user)(void);
276 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200277 void (*flush_tlb_single)(unsigned long addr);
Rusty Russell4595f962009-01-10 21:58:09 -0800278 void (*flush_tlb_others)(const struct cpumask *cpus,
279 struct mm_struct *mm,
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200280 unsigned long va);
Rusty Russellda181a82006-12-07 02:14:08 +0100281
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -0400282 /* Hooks for allocating and freeing a pagetable top-level */
283 int (*pgd_alloc)(struct mm_struct *mm);
284 void (*pgd_free)(struct mm_struct *mm, pgd_t *pgd);
285
286 /*
287 * Hooks for allocating/releasing pagetable pages when they're
288 * attached to a pagetable
289 */
Eduardo Habkostf8639932008-07-30 18:32:27 -0300290 void (*alloc_pte)(struct mm_struct *mm, unsigned long pfn);
291 void (*alloc_pmd)(struct mm_struct *mm, unsigned long pfn);
292 void (*alloc_pmd_clone)(unsigned long pfn, unsigned long clonepfn, unsigned long start, unsigned long count);
293 void (*alloc_pud)(struct mm_struct *mm, unsigned long pfn);
294 void (*release_pte)(unsigned long pfn);
295 void (*release_pmd)(unsigned long pfn);
296 void (*release_pud)(unsigned long pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100297
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200298 /* Pagetable manipulation functions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100299 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200300 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
301 pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100302 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Joe Perches49cd7402008-03-23 01:03:00 -0700303 void (*pte_update)(struct mm_struct *mm, unsigned long addr,
304 pte_t *ptep);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200305 void (*pte_update_defer)(struct mm_struct *mm,
306 unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200307
Jeremy Fitzhardinge08b882c2008-06-16 04:30:01 -0700308 pte_t (*ptep_modify_prot_start)(struct mm_struct *mm, unsigned long addr,
309 pte_t *ptep);
310 void (*ptep_modify_prot_commit)(struct mm_struct *mm, unsigned long addr,
311 pte_t *ptep, pte_t pte);
312
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800313 struct paravirt_callee_save pte_val;
314 struct paravirt_callee_save make_pte;
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100315
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800316 struct paravirt_callee_save pgd_val;
317 struct paravirt_callee_save make_pgd;
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100318
319#if PAGETABLE_LEVELS >= 3
Rusty Russellda181a82006-12-07 02:14:08 +0100320#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100321 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700322 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr,
323 pte_t *ptep, pte_t pte);
Joe Perches49cd7402008-03-23 01:03:00 -0700324 void (*pte_clear)(struct mm_struct *mm, unsigned long addr,
325 pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100326 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200327
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100328#endif /* CONFIG_X86_PAE */
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200329
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100330 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200331
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800332 struct paravirt_callee_save pmd_val;
333 struct paravirt_callee_save make_pmd;
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100334
335#if PAGETABLE_LEVELS == 4
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800336 struct paravirt_callee_save pud_val;
337 struct paravirt_callee_save make_pud;
Eduardo Habkost90422192008-01-30 13:33:20 +0100338
339 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100340#endif /* PAGETABLE_LEVELS == 4 */
341#endif /* PAGETABLE_LEVELS >= 3 */
Rusty Russellda181a82006-12-07 02:14:08 +0100342
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700343#ifdef CONFIG_HIGHPTE
344 void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
345#endif
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700346
347 struct pv_lazy_ops lazy_mode;
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700348
349 /* dom0 ops */
350
351 /* Sometimes the physical address is a pfn, and sometimes its
352 an mfn. We can tell which is which from the index. */
353 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
354 unsigned long phys, pgprot_t flags);
Rusty Russelld3561b72006-12-07 02:14:07 +0100355};
356
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700357struct raw_spinlock;
358struct pv_lock_ops {
359 int (*spin_is_locked)(struct raw_spinlock *lock);
360 int (*spin_is_contended)(struct raw_spinlock *lock);
361 void (*spin_lock)(struct raw_spinlock *lock);
Jeremy Fitzhardinge63d3a752008-08-19 13:19:36 -0700362 void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700363 int (*spin_trylock)(struct raw_spinlock *lock);
364 void (*spin_unlock)(struct raw_spinlock *lock);
365};
366
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700367/* This contains all the paravirt structures: we get a convenient
368 * number for each function using the offset which we use to indicate
369 * what to patch. */
Joe Perches49cd7402008-03-23 01:03:00 -0700370struct paravirt_patch_template {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700371 struct pv_init_ops pv_init_ops;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700372 struct pv_time_ops pv_time_ops;
373 struct pv_cpu_ops pv_cpu_ops;
374 struct pv_irq_ops pv_irq_ops;
375 struct pv_apic_ops pv_apic_ops;
376 struct pv_mmu_ops pv_mmu_ops;
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700377 struct pv_lock_ops pv_lock_ops;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700378};
379
380extern struct pv_info pv_info;
381extern struct pv_init_ops pv_init_ops;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700382extern struct pv_time_ops pv_time_ops;
383extern struct pv_cpu_ops pv_cpu_ops;
384extern struct pv_irq_ops pv_irq_ops;
385extern struct pv_apic_ops pv_apic_ops;
386extern struct pv_mmu_ops pv_mmu_ops;
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700387extern struct pv_lock_ops pv_lock_ops;
Rusty Russelld3561b72006-12-07 02:14:07 +0100388
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200389#define PARAVIRT_PATCH(x) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700390 (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200391
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700392#define paravirt_type(op) \
393 [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \
394 [paravirt_opptr] "m" (op)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200395#define paravirt_clobber(clobber) \
396 [paravirt_clobber] "i" (clobber)
397
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200398/*
399 * Generate some code, and mark it as patchable by the
400 * apply_paravirt() alternate instruction patcher.
401 */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200402#define _paravirt_alt(insn_string, type, clobber) \
403 "771:\n\t" insn_string "\n" "772:\n" \
404 ".pushsection .parainstructions,\"a\"\n" \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100405 _ASM_ALIGN "\n" \
406 _ASM_PTR " 771b\n" \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200407 " .byte " type "\n" \
408 " .byte 772b-771b\n" \
409 " .short " clobber "\n" \
410 ".popsection\n"
411
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200412/* Generate patchable code, with the default asm parameters. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200413#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200414 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
415
Glauber de Oliveira Costa2f485ef2008-01-30 13:32:10 +0100416/* Simple instruction patching code. */
417#define DEF_NATIVE(ops, name, code) \
418 extern const char start_##ops##_##name[], end_##ops##_##name[]; \
419 asm("start_" #ops "_" #name ": " code "; end_" #ops "_" #name ":")
420
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200421unsigned paravirt_patch_nop(void);
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -0800422unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len);
423unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200424unsigned paravirt_patch_ignore(unsigned len);
Andi Kleenab144f52007-08-10 22:31:03 +0200425unsigned paravirt_patch_call(void *insnbuf,
426 const void *target, u16 tgt_clobbers,
427 unsigned long addr, u16 site_clobbers,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200428 unsigned len);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700429unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
Andi Kleenab144f52007-08-10 22:31:03 +0200430 unsigned long addr, unsigned len);
431unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
432 unsigned long addr, unsigned len);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200433
Andi Kleenab144f52007-08-10 22:31:03 +0200434unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200435 const char *start, const char *end);
436
Glauber de Oliveira Costa2f485ef2008-01-30 13:32:10 +0100437unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
438 unsigned long addr, unsigned len);
439
Jeremy Fitzhardinged5729292007-07-17 18:37:04 -0700440int paravirt_disable_iospace(void);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200441
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200442/*
443 * This generates an indirect call based on the operation type number.
444 * The type number, computed in PARAVIRT_PATCH, is derived from the
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700445 * offset into the paravirt_patch_template structure, and can therefore be
446 * freely converted back into a structure offset.
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200447 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700448#define PARAVIRT_CALL "call *%[paravirt_opptr];"
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200449
450/*
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700451 * These macros are intended to wrap calls through one of the paravirt
452 * ops structs, so that they can be later identified and patched at
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200453 * runtime.
454 *
455 * Normally, a call to a pv_op function is a simple indirect call:
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100456 * (pv_op_struct.operations)(args...).
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200457 *
458 * Unfortunately, this is a relatively slow operation for modern CPUs,
459 * because it cannot necessarily determine what the destination
460 * address is. In this case, the address is a runtime constant, so at
461 * the very least we can patch the call to e a simple direct call, or
462 * ideally, patch an inline implementation into the callsite. (Direct
463 * calls are essentially free, because the call and return addresses
464 * are completely predictable.)
465 *
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100466 * For i386, these macros rely on the standard gcc "regparm(3)" calling
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200467 * convention, in which the first three arguments are placed in %eax,
468 * %edx, %ecx (in that order), and the remaining arguments are placed
469 * on the stack. All caller-save registers (eax,edx,ecx) are expected
470 * to be modified (either clobbered or used for return values).
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100471 * X86_64, on the other hand, already specifies a register-based calling
472 * conventions, returning at %rax, with parameteres going on %rdi, %rsi,
473 * %rdx, and %rcx. Note that for this reason, x86_64 does not need any
474 * special handling for dealing with 4 arguments, unlike i386.
475 * However, x86_64 also have to clobber all caller saved registers, which
476 * unfortunately, are quite a bit (r8 - r11)
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200477 *
478 * The call instruction itself is marked by placing its start address
479 * and size into the .parainstructions section, so that
480 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700481 * appropriate patching under the control of the backend pv_init_ops
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200482 * implementation.
483 *
484 * Unfortunately there's no way to get gcc to generate the args setup
485 * for the call, and then allow the call itself to be generated by an
486 * inline asm. Because of this, we must do the complete arg setup and
487 * return value handling from within these macros. This is fairly
488 * cumbersome.
489 *
490 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
491 * It could be extended to more arguments, but there would be little
492 * to be gained from that. For each number of arguments, there are
493 * the two VCALL and CALL variants for void and non-void functions.
494 *
495 * When there is a return value, the invoker of the macro must specify
496 * the return type. The macro then uses sizeof() on that type to
497 * determine whether its a 32 or 64 bit value, and places the return
498 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100499 * 64-bit). For x86_64 machines, it just returns at %rax regardless of
500 * the return value size.
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200501 *
502 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100503 * i386 also passes 64-bit arguments as a pair of adjacent 32-bit arguments
504 * in low,high order
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200505 *
506 * Small structures are passed and returned in registers. The macro
507 * calling convention can't directly deal with this, so the wrapper
508 * functions must do this.
509 *
510 * These PVOP_* macros are only defined within this header. This
511 * means that all uses must be wrapped in inline functions. This also
512 * makes sure the incoming and outgoing types are always correct.
513 */
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100514#ifdef CONFIG_X86_32
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800515#define PVOP_VCALL_ARGS \
516 unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100517#define PVOP_CALL_ARGS PVOP_VCALL_ARGS
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800518
519#define PVOP_CALL_ARG1(x) "a" ((unsigned long)(x))
520#define PVOP_CALL_ARG2(x) "d" ((unsigned long)(x))
521#define PVOP_CALL_ARG3(x) "c" ((unsigned long)(x))
522
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100523#define PVOP_VCALL_CLOBBERS "=a" (__eax), "=d" (__edx), \
524 "=c" (__ecx)
525#define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800526
Jeremy Fitzhardinge0eb592d2009-02-03 16:00:38 -0800527#define PVOP_VCALLEE_CLOBBERS "=a" (__eax), "=d" (__edx)
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800528#define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS
529
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100530#define EXTRA_CLOBBERS
531#define VEXTRA_CLOBBERS
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800532#else /* CONFIG_X86_64 */
533#define PVOP_VCALL_ARGS \
534 unsigned long __edi = __edi, __esi = __esi, \
535 __edx = __edx, __ecx = __ecx
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100536#define PVOP_CALL_ARGS PVOP_VCALL_ARGS, __eax
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800537
538#define PVOP_CALL_ARG1(x) "D" ((unsigned long)(x))
539#define PVOP_CALL_ARG2(x) "S" ((unsigned long)(x))
540#define PVOP_CALL_ARG3(x) "d" ((unsigned long)(x))
541#define PVOP_CALL_ARG4(x) "c" ((unsigned long)(x))
542
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100543#define PVOP_VCALL_CLOBBERS "=D" (__edi), \
544 "=S" (__esi), "=d" (__edx), \
545 "=c" (__ecx)
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100546#define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax)
547
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800548#define PVOP_VCALLEE_CLOBBERS "=a" (__eax)
549#define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS
550
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100551#define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11"
552#define VEXTRA_CLOBBERS , "rax", "r8", "r9", "r10", "r11"
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800553#endif /* CONFIG_X86_32 */
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100554
Jeremy Fitzhardinge97349132008-06-25 00:19:14 -0400555#ifdef CONFIG_PARAVIRT_DEBUG
556#define PVOP_TEST_NULL(op) BUG_ON(op == NULL)
557#else
558#define PVOP_TEST_NULL(op) ((void)op)
559#endif
560
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800561#define ____PVOP_CALL(rettype, op, clbr, call_clbr, extra_clbr, \
562 pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200563 ({ \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200564 rettype __ret; \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800565 PVOP_CALL_ARGS; \
Jeremy Fitzhardinge97349132008-06-25 00:19:14 -0400566 PVOP_TEST_NULL(op); \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100567 /* This is 32-bit specific, but is okay in 64-bit */ \
568 /* since this condition will never hold */ \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200569 if (sizeof(rettype) > sizeof(unsigned long)) { \
570 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200571 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200572 post \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800573 : call_clbr \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200574 : paravirt_type(op), \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800575 paravirt_clobber(clbr), \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200576 ##__VA_ARGS__ \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800577 : "memory", "cc" extra_clbr); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200578 __ret = (rettype)((((u64)__edx) << 32) | __eax); \
579 } else { \
580 asm volatile(pre \
581 paravirt_alt(PARAVIRT_CALL) \
582 post \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800583 : call_clbr \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200584 : paravirt_type(op), \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800585 paravirt_clobber(clbr), \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200586 ##__VA_ARGS__ \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800587 : "memory", "cc" extra_clbr); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200588 __ret = (rettype)__eax; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200589 } \
590 __ret; \
591 })
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800592
593#define __PVOP_CALL(rettype, op, pre, post, ...) \
594 ____PVOP_CALL(rettype, op, CLBR_ANY, PVOP_CALL_CLOBBERS, \
595 EXTRA_CLOBBERS, pre, post, ##__VA_ARGS__)
596
597#define __PVOP_CALLEESAVE(rettype, op, pre, post, ...) \
598 ____PVOP_CALL(rettype, op.func, CLBR_RET_REG, \
599 PVOP_CALLEE_CLOBBERS, , \
600 pre, post, ##__VA_ARGS__)
601
602
603#define ____PVOP_VCALL(op, clbr, call_clbr, extra_clbr, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200604 ({ \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100605 PVOP_VCALL_ARGS; \
Jeremy Fitzhardinge97349132008-06-25 00:19:14 -0400606 PVOP_TEST_NULL(op); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200607 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200608 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200609 post \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800610 : call_clbr \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200611 : paravirt_type(op), \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800612 paravirt_clobber(clbr), \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200613 ##__VA_ARGS__ \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800614 : "memory", "cc" extra_clbr); \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200615 })
616
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800617#define __PVOP_VCALL(op, pre, post, ...) \
618 ____PVOP_VCALL(op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \
619 VEXTRA_CLOBBERS, \
620 pre, post, ##__VA_ARGS__)
621
622#define __PVOP_VCALLEESAVE(rettype, op, pre, post, ...) \
623 ____PVOP_CALL(rettype, op.func, CLBR_RET_REG, \
624 PVOP_VCALLEE_CLOBBERS, , \
625 pre, post, ##__VA_ARGS__)
626
627
628
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200629#define PVOP_CALL0(rettype, op) \
630 __PVOP_CALL(rettype, op, "", "")
631#define PVOP_VCALL0(op) \
632 __PVOP_VCALL(op, "", "")
633
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800634#define PVOP_CALLEE0(rettype, op) \
635 __PVOP_CALLEESAVE(rettype, op, "", "")
636#define PVOP_VCALLEE0(op) \
637 __PVOP_VCALLEESAVE(op, "", "")
638
639
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200640#define PVOP_CALL1(rettype, op, arg1) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800641 __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200642#define PVOP_VCALL1(op, arg1) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800643 __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1))
644
645#define PVOP_CALLEE1(rettype, op, arg1) \
646 __PVOP_CALLEESAVE(rettype, op, "", "", PVOP_CALL_ARG1(arg1))
647#define PVOP_VCALLEE1(op, arg1) \
648 __PVOP_VCALLEESAVE(op, "", "", PVOP_CALL_ARG1(arg1))
649
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200650
651#define PVOP_CALL2(rettype, op, arg1, arg2) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800652 __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \
653 PVOP_CALL_ARG2(arg2))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200654#define PVOP_VCALL2(op, arg1, arg2) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800655 __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1), \
656 PVOP_CALL_ARG2(arg2))
657
658#define PVOP_CALLEE2(rettype, op, arg1, arg2) \
659 __PVOP_CALLEESAVE(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \
660 PVOP_CALL_ARG2(arg2))
661#define PVOP_VCALLEE2(op, arg1, arg2) \
662 __PVOP_VCALLEESAVE(op, "", "", PVOP_CALL_ARG1(arg1), \
663 PVOP_CALL_ARG2(arg2))
664
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200665
666#define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800667 __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \
668 PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200669#define PVOP_VCALL3(op, arg1, arg2, arg3) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800670 __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1), \
671 PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200672
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100673/* This is the only difference in x86_64. We can make it much simpler */
674#ifdef CONFIG_X86_32
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200675#define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
676 __PVOP_CALL(rettype, op, \
677 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800678 PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \
679 PVOP_CALL_ARG3(arg3), [_arg4] "mr" ((u32)(arg4)))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200680#define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
681 __PVOP_VCALL(op, \
682 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
683 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
684 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100685#else
686#define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800687 __PVOP_CALL(rettype, op, "", "", \
688 PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \
689 PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4))
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100690#define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
Jeremy Fitzhardinge791bad92009-01-28 14:35:06 -0800691 __PVOP_VCALL(op, "", "", \
692 PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \
693 PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4))
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100694#endif
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200695
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200696static inline int paravirt_enabled(void)
697{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700698 return pv_info.paravirt_enabled;
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200699}
Rusty Russelld3561b72006-12-07 02:14:07 +0100700
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100701static inline void load_sp0(struct tss_struct *tss,
Rusty Russelld3561b72006-12-07 02:14:07 +0100702 struct thread_struct *thread)
703{
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100704 PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100705}
706
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700707#define ARCH_SETUP pv_init_ops.arch_setup();
Rusty Russelld3561b72006-12-07 02:14:07 +0100708static inline unsigned long get_wallclock(void)
709{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700710 return PVOP_CALL0(unsigned long, pv_time_ops.get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100711}
712
713static inline int set_wallclock(unsigned long nowtime)
714{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700715 return PVOP_CALL1(int, pv_time_ops.set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100716}
717
Zachary Amsdene30fab32007-03-05 00:30:39 -0800718static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100719{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700720 return pv_time_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100721}
722
723/* The paravirtualized CPUID instruction. */
724static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
725 unsigned int *ecx, unsigned int *edx)
726{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700727 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100728}
729
730/*
731 * These special macros can be used to get or set a debugging register
732 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200733static inline unsigned long paravirt_get_debugreg(int reg)
734{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700735 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200736}
737#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
738static inline void set_debugreg(unsigned long val, int reg)
739{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700740 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200741}
Rusty Russelld3561b72006-12-07 02:14:07 +0100742
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200743static inline void clts(void)
744{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700745 PVOP_VCALL0(pv_cpu_ops.clts);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200746}
Rusty Russelld3561b72006-12-07 02:14:07 +0100747
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200748static inline unsigned long read_cr0(void)
749{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700750 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200751}
Rusty Russelld3561b72006-12-07 02:14:07 +0100752
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200753static inline void write_cr0(unsigned long x)
754{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700755 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200756}
Rusty Russelld3561b72006-12-07 02:14:07 +0100757
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200758static inline unsigned long read_cr2(void)
759{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700760 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200761}
Rusty Russelld3561b72006-12-07 02:14:07 +0100762
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200763static inline void write_cr2(unsigned long x)
764{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700765 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200766}
Rusty Russelld3561b72006-12-07 02:14:07 +0100767
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200768static inline unsigned long read_cr3(void)
769{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700770 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200771}
772
773static inline void write_cr3(unsigned long x)
774{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700775 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200776}
777
778static inline unsigned long read_cr4(void)
779{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700780 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200781}
782static inline unsigned long read_cr4_safe(void)
783{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700784 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200785}
786
787static inline void write_cr4(unsigned long x)
788{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700789 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200790}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200791
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100792#ifdef CONFIG_X86_64
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100793static inline unsigned long read_cr8(void)
794{
795 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
796}
797
798static inline void write_cr8(unsigned long x)
799{
800 PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
801}
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100802#endif
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100803
Rusty Russelld3561b72006-12-07 02:14:07 +0100804static inline void raw_safe_halt(void)
805{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700806 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100807}
808
809static inline void halt(void)
810{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700811 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100812}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200813
814static inline void wbinvd(void)
815{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700816 PVOP_VCALL0(pv_cpu_ops.wbinvd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200817}
Rusty Russelld3561b72006-12-07 02:14:07 +0100818
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700819#define get_kernel_rpl() (pv_info.kernel_rpl)
Rusty Russelld3561b72006-12-07 02:14:07 +0100820
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200821static inline u64 paravirt_read_msr(unsigned msr, int *err)
822{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700823 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200824}
Yinghai Lub05f78f2008-08-22 01:32:50 -0700825static inline u64 paravirt_read_msr_amd(unsigned msr, int *err)
826{
827 return PVOP_CALL2(u64, pv_cpu_ops.read_msr_amd, msr, err);
828}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200829static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
830{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700831 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200832}
833
Rusty Russell90a0a062007-05-02 19:27:10 +0200834/* These should all do BUG_ON(_err), but our headers are too tangled. */
Joe Perches49cd7402008-03-23 01:03:00 -0700835#define rdmsr(msr, val1, val2) \
836do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200837 int _err; \
838 u64 _l = paravirt_read_msr(msr, &_err); \
839 val1 = (u32)_l; \
840 val2 = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700841} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100842
Joe Perches49cd7402008-03-23 01:03:00 -0700843#define wrmsr(msr, val1, val2) \
844do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200845 paravirt_write_msr(msr, val1, val2); \
Joe Perches49cd7402008-03-23 01:03:00 -0700846} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100847
Joe Perches49cd7402008-03-23 01:03:00 -0700848#define rdmsrl(msr, val) \
849do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200850 int _err; \
851 val = paravirt_read_msr(msr, &_err); \
Joe Perches49cd7402008-03-23 01:03:00 -0700852} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100853
Joe Perches49cd7402008-03-23 01:03:00 -0700854#define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
855#define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100856
857/* rdmsr with exception handling */
Joe Perches49cd7402008-03-23 01:03:00 -0700858#define rdmsr_safe(msr, a, b) \
859({ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200860 int _err; \
861 u64 _l = paravirt_read_msr(msr, &_err); \
862 (*a) = (u32)_l; \
863 (*b) = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700864 _err; \
865})
Rusty Russelld3561b72006-12-07 02:14:07 +0100866
Andi Kleen1de87bd2008-03-22 10:59:28 +0100867static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
868{
869 int err;
870
871 *p = paravirt_read_msr(msr, &err);
872 return err;
873}
Yinghai Lub05f78f2008-08-22 01:32:50 -0700874static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
875{
876 int err;
877
878 *p = paravirt_read_msr_amd(msr, &err);
879 return err;
880}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200881
882static inline u64 paravirt_read_tsc(void)
883{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700884 return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200885}
Rusty Russelld3561b72006-12-07 02:14:07 +0100886
Joe Perches49cd7402008-03-23 01:03:00 -0700887#define rdtscl(low) \
888do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200889 u64 _l = paravirt_read_tsc(); \
890 low = (int)_l; \
Joe Perches49cd7402008-03-23 01:03:00 -0700891} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100892
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200893#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100894
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700895static inline unsigned long long paravirt_sched_clock(void)
896{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700897 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700898}
Alok Katariae93ef942008-07-01 11:43:36 -0700899#define calibrate_tsc() (pv_time_ops.get_tsc_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800900
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200901static inline unsigned long long paravirt_read_pmc(int counter)
902{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700903 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200904}
905
Joe Perches49cd7402008-03-23 01:03:00 -0700906#define rdpmc(counter, low, high) \
907do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200908 u64 _l = paravirt_read_pmc(counter); \
909 low = (u32)_l; \
910 high = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700911} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100912
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100913static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
914{
915 return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
916}
917
918#define rdtscp(low, high, aux) \
919do { \
920 int __aux; \
921 unsigned long __val = paravirt_rdtscp(&__aux); \
922 (low) = (u32)__val; \
923 (high) = (u32)(__val >> 32); \
924 (aux) = __aux; \
925} while (0)
926
927#define rdtscpll(val, aux) \
928do { \
929 unsigned long __aux; \
930 val = paravirt_rdtscp(&__aux); \
931 (aux) = __aux; \
932} while (0)
933
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700934static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
935{
936 PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
937}
938
939static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
940{
941 PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
942}
943
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200944static inline void load_TR_desc(void)
945{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700946 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200947}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100948static inline void load_gdt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200949{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700950 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200951}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100952static inline void load_idt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200953{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700954 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200955}
956static inline void set_ldt(const void *addr, unsigned entries)
957{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700958 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200959}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100960static inline void store_gdt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200961{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700962 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200963}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100964static inline void store_idt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200965{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700966 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200967}
968static inline unsigned long paravirt_store_tr(void)
969{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700970 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200971}
972#define store_tr(tr) ((tr) = paravirt_store_tr())
973static inline void load_TLS(struct thread_struct *t, unsigned cpu)
974{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700975 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200976}
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100977
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400978#ifdef CONFIG_X86_64
979static inline void load_gs_index(unsigned int gs)
980{
981 PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
982}
983#endif
984
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100985static inline void write_ldt_entry(struct desc_struct *dt, int entry,
986 const void *desc)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200987{
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100988 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200989}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100990
991static inline void write_gdt_entry(struct desc_struct *dt, int entry,
992 void *desc, int type)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200993{
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100994 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200995}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100996
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100997static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200998{
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100999 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001000}
1001static inline void set_iopl_mask(unsigned mask)
1002{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001003 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001004}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +02001005
Rusty Russelld3561b72006-12-07 02:14:07 +01001006/* The paravirtualized I/O functions */
Joe Perches49cd7402008-03-23 01:03:00 -07001007static inline void slow_down_io(void)
1008{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001009 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +01001010#ifdef REALLY_SLOW_IO
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001011 pv_cpu_ops.io_delay();
1012 pv_cpu_ops.io_delay();
1013 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +01001014#endif
1015}
1016
Rusty Russell13623d72006-12-07 02:14:08 +01001017#ifdef CONFIG_X86_LOCAL_APIC
Zachary Amsdenbbab4f32007-02-13 13:26:21 +01001018static inline void setup_boot_clock(void)
1019{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001020 PVOP_VCALL0(pv_apic_ops.setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +01001021}
1022
1023static inline void setup_secondary_clock(void)
1024{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001025 PVOP_VCALL0(pv_apic_ops.setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +01001026}
Rusty Russell13623d72006-12-07 02:14:08 +01001027#endif
1028
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -07001029static inline void paravirt_post_allocator_init(void)
1030{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001031 if (pv_init_ops.post_allocator_init)
1032 (*pv_init_ops.post_allocator_init)();
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -07001033}
1034
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02001035static inline void paravirt_pagetable_setup_start(pgd_t *base)
1036{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001037 (*pv_mmu_ops.pagetable_setup_start)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02001038}
1039
1040static inline void paravirt_pagetable_setup_done(pgd_t *base)
1041{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001042 (*pv_mmu_ops.pagetable_setup_done)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02001043}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +02001044
Zachary Amsdenae5da272007-02-13 13:26:21 +01001045#ifdef CONFIG_SMP
1046static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
1047 unsigned long start_esp)
1048{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001049 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
1050 phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +01001051}
1052#endif
Rusty Russell13623d72006-12-07 02:14:08 +01001053
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +02001054static inline void paravirt_activate_mm(struct mm_struct *prev,
1055 struct mm_struct *next)
1056{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001057 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +02001058}
1059
1060static inline void arch_dup_mmap(struct mm_struct *oldmm,
1061 struct mm_struct *mm)
1062{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001063 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +02001064}
1065
1066static inline void arch_exit_mmap(struct mm_struct *mm)
1067{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001068 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +02001069}
1070
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001071static inline void __flush_tlb(void)
1072{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001073 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001074}
1075static inline void __flush_tlb_global(void)
1076{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001077 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001078}
1079static inline void __flush_tlb_single(unsigned long addr)
1080{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001081 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001082}
Rusty Russellda181a82006-12-07 02:14:08 +01001083
Rusty Russell4595f962009-01-10 21:58:09 -08001084static inline void flush_tlb_others(const struct cpumask *cpumask,
1085 struct mm_struct *mm,
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +02001086 unsigned long va)
1087{
Rusty Russell4595f962009-01-10 21:58:09 -08001088 PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, cpumask, mm, va);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +02001089}
1090
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -04001091static inline int paravirt_pgd_alloc(struct mm_struct *mm)
1092{
1093 return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
1094}
1095
1096static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
1097{
1098 PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
1099}
1100
Eduardo Habkostf8639932008-07-30 18:32:27 -03001101static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001102{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -07001103 PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001104}
Eduardo Habkostf8639932008-07-30 18:32:27 -03001105static inline void paravirt_release_pte(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001106{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -07001107 PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001108}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +01001109
Eduardo Habkostf8639932008-07-30 18:32:27 -03001110static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001111{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -07001112 PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001113}
1114
Eduardo Habkostf8639932008-07-30 18:32:27 -03001115static inline void paravirt_alloc_pmd_clone(unsigned long pfn, unsigned long clonepfn,
1116 unsigned long start, unsigned long count)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001117{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -07001118 PVOP_VCALL4(pv_mmu_ops.alloc_pmd_clone, pfn, clonepfn, start, count);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001119}
Eduardo Habkostf8639932008-07-30 18:32:27 -03001120static inline void paravirt_release_pmd(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001121{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -07001122 PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001123}
1124
Eduardo Habkostf8639932008-07-30 18:32:27 -03001125static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -07001126{
1127 PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
1128}
Eduardo Habkostf8639932008-07-30 18:32:27 -03001129static inline void paravirt_release_pud(unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -07001130{
1131 PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
1132}
1133
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +02001134#ifdef CONFIG_HIGHPTE
1135static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
1136{
1137 unsigned long ret;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001138 ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type);
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +02001139 return (void *)ret;
1140}
1141#endif
1142
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001143static inline void pte_update(struct mm_struct *mm, unsigned long addr,
1144 pte_t *ptep)
1145{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001146 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001147}
1148
1149static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
1150 pte_t *ptep)
1151{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001152 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001153}
1154
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +01001155static inline pte_t __pte(pteval_t val)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001156{
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +01001157 pteval_t ret;
1158
1159 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001160 ret = PVOP_CALLEE2(pteval_t,
1161 pv_mmu_ops.make_pte,
1162 val, (u64)val >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +01001163 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001164 ret = PVOP_CALLEE1(pteval_t,
1165 pv_mmu_ops.make_pte,
1166 val);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +01001167
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +01001168 return (pte_t) { .pte = ret };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001169}
1170
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +01001171static inline pteval_t pte_val(pte_t pte)
1172{
1173 pteval_t ret;
1174
1175 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001176 ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
1177 pte.pte, (u64)pte.pte >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +01001178 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001179 ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
1180 pte.pte);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +01001181
1182 return ret;
1183}
1184
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +01001185static inline pgd_t __pgd(pgdval_t val)
1186{
1187 pgdval_t ret;
1188
1189 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001190 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
1191 val, (u64)val >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +01001192 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001193 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
1194 val);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +01001195
1196 return (pgd_t) { ret };
1197}
1198
1199static inline pgdval_t pgd_val(pgd_t pgd)
1200{
1201 pgdval_t ret;
1202
1203 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001204 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
1205 pgd.pgd, (u64)pgd.pgd >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +01001206 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001207 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
1208 pgd.pgd);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +01001209
1210 return ret;
1211}
1212
Jeremy Fitzhardinge08b882c2008-06-16 04:30:01 -07001213#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
1214static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
1215 pte_t *ptep)
1216{
1217 pteval_t ret;
1218
1219 ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
1220 mm, addr, ptep);
1221
1222 return (pte_t) { .pte = ret };
1223}
1224
1225static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
1226 pte_t *ptep, pte_t pte)
1227{
1228 if (sizeof(pteval_t) > sizeof(long))
1229 /* 5 arg words */
1230 pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
1231 else
1232 PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
1233 mm, addr, ptep, pte.pte);
1234}
1235
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001236static inline void set_pte(pte_t *ptep, pte_t pte)
1237{
1238 if (sizeof(pteval_t) > sizeof(long))
1239 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
1240 pte.pte, (u64)pte.pte >> 32);
1241 else
1242 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
1243 pte.pte);
1244}
1245
1246static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1247 pte_t *ptep, pte_t pte)
1248{
1249 if (sizeof(pteval_t) > sizeof(long))
1250 /* 5 arg words */
1251 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
1252 else
1253 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
1254}
1255
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +01001256static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
1257{
1258 pmdval_t val = native_pmd_val(pmd);
1259
1260 if (sizeof(pmdval_t) > sizeof(long))
1261 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
1262 else
1263 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
1264}
1265
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001266#if PAGETABLE_LEVELS >= 3
1267static inline pmd_t __pmd(pmdval_t val)
1268{
1269 pmdval_t ret;
1270
1271 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001272 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
1273 val, (u64)val >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001274 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001275 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
1276 val);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001277
1278 return (pmd_t) { ret };
1279}
1280
1281static inline pmdval_t pmd_val(pmd_t pmd)
1282{
1283 pmdval_t ret;
1284
1285 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001286 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
1287 pmd.pmd, (u64)pmd.pmd >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001288 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001289 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
1290 pmd.pmd);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001291
1292 return ret;
1293}
1294
1295static inline void set_pud(pud_t *pudp, pud_t pud)
1296{
1297 pudval_t val = native_pud_val(pud);
1298
1299 if (sizeof(pudval_t) > sizeof(long))
1300 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
1301 val, (u64)val >> 32);
1302 else
1303 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
1304 val);
1305}
Eduardo Habkost90422192008-01-30 13:33:20 +01001306#if PAGETABLE_LEVELS == 4
1307static inline pud_t __pud(pudval_t val)
1308{
1309 pudval_t ret;
1310
1311 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001312 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
1313 val, (u64)val >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +01001314 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -08001315 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
1316 val);
Eduardo Habkost90422192008-01-30 13:33:20 +01001317
1318 return (pud_t) { ret };
1319}
1320
1321static inline pudval_t pud_val(pud_t pud)
1322{
1323 pudval_t ret;
1324
1325 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -08001326 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
1327 pud.pud, (u64)pud.pud >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +01001328 else
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -08001329 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
1330 pud.pud);
Eduardo Habkost90422192008-01-30 13:33:20 +01001331
1332 return ret;
1333}
1334
1335static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
1336{
1337 pgdval_t val = native_pgd_val(pgd);
1338
1339 if (sizeof(pgdval_t) > sizeof(long))
1340 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
1341 val, (u64)val >> 32);
1342 else
1343 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
1344 val);
1345}
1346
1347static inline void pgd_clear(pgd_t *pgdp)
1348{
1349 set_pgd(pgdp, __pgd(0));
1350}
1351
1352static inline void pud_clear(pud_t *pudp)
1353{
1354 set_pud(pudp, __pud(0));
1355}
1356
1357#endif /* PAGETABLE_LEVELS == 4 */
1358
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001359#endif /* PAGETABLE_LEVELS >= 3 */
1360
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001361#ifdef CONFIG_X86_PAE
1362/* Special-case pte-setting operations for PAE, which can't update a
1363 64-bit pte atomically */
1364static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
1365{
1366 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
1367 pte.pte, pte.pte >> 32);
1368}
1369
1370static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
1371 pte_t *ptep, pte_t pte)
1372{
1373 /* 5 arg words */
1374 pv_mmu_ops.set_pte_present(mm, addr, ptep, pte);
1375}
1376
1377static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
1378 pte_t *ptep)
1379{
1380 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
1381}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +01001382
1383static inline void pmd_clear(pmd_t *pmdp)
1384{
1385 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
1386}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001387#else /* !CONFIG_X86_PAE */
1388static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
1389{
1390 set_pte(ptep, pte);
1391}
1392
1393static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
1394 pte_t *ptep, pte_t pte)
1395{
1396 set_pte(ptep, pte);
1397}
1398
1399static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
1400 pte_t *ptep)
1401{
1402 set_pte_at(mm, addr, ptep, __pte(0));
1403}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +01001404
1405static inline void pmd_clear(pmd_t *pmdp)
1406{
1407 set_pmd(pmdp, __pmd(0));
1408}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001409#endif /* CONFIG_X86_PAE */
1410
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001411/* Lazy mode for batching updates / context switch */
1412enum paravirt_lazy_mode {
1413 PARAVIRT_LAZY_NONE,
1414 PARAVIRT_LAZY_MMU,
1415 PARAVIRT_LAZY_CPU,
1416};
1417
1418enum paravirt_lazy_mode paravirt_get_lazy_mode(void);
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -08001419void paravirt_start_context_switch(struct task_struct *prev);
1420void paravirt_end_context_switch(struct task_struct *next);
1421
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001422void paravirt_enter_lazy_mmu(void);
1423void paravirt_leave_lazy_mmu(void);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001424
Jeremy Fitzhardinge7fd7d832009-02-17 23:24:03 -08001425#define __HAVE_ARCH_START_CONTEXT_SWITCH
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -08001426static inline void arch_start_context_switch(struct task_struct *prev)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001427{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -08001428 PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001429}
1430
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -08001431static inline void arch_end_context_switch(struct task_struct *next)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001432{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -08001433 PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001434}
1435
Zachary Amsden9226d122007-02-13 13:26:21 +01001436#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001437static inline void arch_enter_lazy_mmu_mode(void)
1438{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001439 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001440}
1441
1442static inline void arch_leave_lazy_mmu_mode(void)
1443{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001444 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001445}
1446
Jeremy Fitzhardinged85cf932009-02-12 10:02:56 -08001447void arch_flush_lazy_mmu_mode(void);
Zachary Amsden9226d122007-02-13 13:26:21 +01001448
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -07001449static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
1450 unsigned long phys, pgprot_t flags)
1451{
1452 pv_mmu_ops.set_fixmap(idx, phys, flags);
1453}
1454
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +02001455void _paravirt_nop(void);
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -08001456u32 _paravirt_ident_32(u32);
1457u64 _paravirt_ident_64(u64);
1458
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +02001459#define paravirt_nop ((void *)_paravirt_nop)
1460
Ingo Molnar4bb689e2008-07-09 14:33:33 +02001461#ifdef CONFIG_SMP
1462
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -07001463static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
1464{
1465 return PVOP_CALL1(int, pv_lock_ops.spin_is_locked, lock);
1466}
1467
1468static inline int __raw_spin_is_contended(struct raw_spinlock *lock)
1469{
1470 return PVOP_CALL1(int, pv_lock_ops.spin_is_contended, lock);
1471}
Kyle McMartina5ef7ca2009-02-08 17:39:58 -05001472#define __raw_spin_is_contended __raw_spin_is_contended
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -07001473
1474static __always_inline void __raw_spin_lock(struct raw_spinlock *lock)
1475{
Harvey Harrison32172562008-07-17 14:22:34 -07001476 PVOP_VCALL1(pv_lock_ops.spin_lock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -07001477}
1478
Jeremy Fitzhardinge63d3a752008-08-19 13:19:36 -07001479static __always_inline void __raw_spin_lock_flags(struct raw_spinlock *lock,
1480 unsigned long flags)
1481{
1482 PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags);
1483}
1484
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -07001485static __always_inline int __raw_spin_trylock(struct raw_spinlock *lock)
1486{
1487 return PVOP_CALL1(int, pv_lock_ops.spin_trylock, lock);
1488}
1489
1490static __always_inline void __raw_spin_unlock(struct raw_spinlock *lock)
1491{
Harvey Harrison32172562008-07-17 14:22:34 -07001492 PVOP_VCALL1(pv_lock_ops.spin_unlock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -07001493}
1494
Ingo Molnar4bb689e2008-07-09 14:33:33 +02001495#endif
1496
Rusty Russell139ec7c2006-12-07 02:14:08 +01001497/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001498struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +01001499 u8 *instr; /* original instructions */
1500 u8 instrtype; /* type of this instruction */
1501 u8 len; /* length of original instruction */
1502 u16 clobbers; /* what registers you may clobber */
1503};
1504
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001505extern struct paravirt_patch_site __parainstructions[],
1506 __parainstructions_end[];
1507
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001508#ifdef CONFIG_X86_32
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001509#define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
1510#define PV_RESTORE_REGS "popl %edx; popl %ecx;"
1511
1512/* save and restore all caller-save registers, except return value */
Jeremy Fitzhardingee584f552009-01-30 23:17:23 -08001513#define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
1514#define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001515
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001516#define PV_FLAGS_ARG "0"
1517#define PV_EXTRA_CLOBBERS
1518#define PV_VEXTRA_CLOBBERS
1519#else
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001520/* save and restore all caller-save registers, except return value */
1521#define PV_SAVE_ALL_CALLER_REGS \
1522 "push %rcx;" \
1523 "push %rdx;" \
1524 "push %rsi;" \
1525 "push %rdi;" \
1526 "push %r8;" \
1527 "push %r9;" \
1528 "push %r10;" \
1529 "push %r11;"
1530#define PV_RESTORE_ALL_CALLER_REGS \
1531 "pop %r11;" \
1532 "pop %r10;" \
1533 "pop %r9;" \
1534 "pop %r8;" \
1535 "pop %rdi;" \
1536 "pop %rsi;" \
1537 "pop %rdx;" \
1538 "pop %rcx;"
1539
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001540/* We save some registers, but all of them, that's too much. We clobber all
1541 * caller saved registers but the argument parameter */
1542#define PV_SAVE_REGS "pushq %%rdi;"
1543#define PV_RESTORE_REGS "popq %%rdi;"
Jeremy Fitzhardingec24481e2008-07-08 15:07:12 -07001544#define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
1545#define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001546#define PV_FLAGS_ARG "D"
1547#endif
1548
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001549/*
1550 * Generate a thunk around a function which saves all caller-save
1551 * registers except for the return value. This allows C functions to
1552 * be called from assembler code where fewer than normal registers are
1553 * available. It may also help code generation around calls from C
1554 * code if the common case doesn't use many registers.
1555 *
1556 * When a callee is wrapped in a thunk, the caller can assume that all
1557 * arg regs and all scratch registers are preserved across the
1558 * call. The return value in rax/eax will not be saved, even for void
1559 * functions.
1560 */
1561#define PV_CALLEE_SAVE_REGS_THUNK(func) \
1562 extern typeof(func) __raw_callee_save_##func; \
1563 static void *__##func##__ __used = func; \
1564 \
1565 asm(".pushsection .text;" \
1566 "__raw_callee_save_" #func ": " \
1567 PV_SAVE_ALL_CALLER_REGS \
1568 "call " #func ";" \
1569 PV_RESTORE_ALL_CALLER_REGS \
1570 "ret;" \
1571 ".popsection")
1572
1573/* Get a reference to a callee-save function */
1574#define PV_CALLEE_SAVE(func) \
1575 ((struct paravirt_callee_save) { __raw_callee_save_##func })
1576
1577/* Promise that "func" already uses the right calling convention */
1578#define __PV_IS_CALLEE_SAVE(func) \
1579 ((struct paravirt_callee_save) { func })
1580
Rusty Russell139ec7c2006-12-07 02:14:08 +01001581static inline unsigned long __raw_local_save_flags(void)
1582{
1583 unsigned long f;
1584
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001585 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001586 : "=a"(f)
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001587 : paravirt_type(pv_irq_ops.save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001588 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001589 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001590 return f;
1591}
1592
1593static inline void raw_local_irq_restore(unsigned long f)
1594{
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001595 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001596 : "=a"(f)
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001597 : PV_FLAGS_ARG(f),
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001598 paravirt_type(pv_irq_ops.restore_fl),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001599 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001600 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001601}
1602
1603static inline void raw_local_irq_disable(void)
1604{
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001605 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001606 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001607 : paravirt_type(pv_irq_ops.irq_disable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001608 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001609 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001610}
1611
1612static inline void raw_local_irq_enable(void)
1613{
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001614 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001615 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001616 : paravirt_type(pv_irq_ops.irq_enable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001617 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001618 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +01001619}
1620
1621static inline unsigned long __raw_local_irq_save(void)
1622{
1623 unsigned long f;
1624
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001625 f = __raw_local_save_flags();
1626 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001627 return f;
1628}
1629
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -07001630
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001631/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001632#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +02001633#undef __PVOP_CALL
1634#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001635#undef PVOP_VCALL0
1636#undef PVOP_CALL0
1637#undef PVOP_VCALL1
1638#undef PVOP_CALL1
1639#undef PVOP_VCALL2
1640#undef PVOP_CALL2
1641#undef PVOP_VCALL3
1642#undef PVOP_CALL3
1643#undef PVOP_VCALL4
1644#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001645
Rusty Russelld3561b72006-12-07 02:14:07 +01001646#else /* __ASSEMBLY__ */
1647
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001648#define _PVSITE(ptype, clobbers, ops, word, algn) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001649771:; \
1650 ops; \
1651772:; \
1652 .pushsection .parainstructions,"a"; \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001653 .align algn; \
1654 word 771b; \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001655 .byte ptype; \
1656 .byte 772b-771b; \
1657 .short clobbers; \
1658 .popsection
1659
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001660
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001661#define COND_PUSH(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001662 .if ((~(set)) & mask); push %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001663#define COND_POP(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001664 .if ((~(set)) & mask); pop %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001665
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001666#ifdef CONFIG_X86_64
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001667
1668#define PV_SAVE_REGS(set) \
1669 COND_PUSH(set, CLBR_RAX, rax); \
1670 COND_PUSH(set, CLBR_RCX, rcx); \
1671 COND_PUSH(set, CLBR_RDX, rdx); \
1672 COND_PUSH(set, CLBR_RSI, rsi); \
1673 COND_PUSH(set, CLBR_RDI, rdi); \
1674 COND_PUSH(set, CLBR_R8, r8); \
1675 COND_PUSH(set, CLBR_R9, r9); \
1676 COND_PUSH(set, CLBR_R10, r10); \
1677 COND_PUSH(set, CLBR_R11, r11)
1678#define PV_RESTORE_REGS(set) \
1679 COND_POP(set, CLBR_R11, r11); \
1680 COND_POP(set, CLBR_R10, r10); \
1681 COND_POP(set, CLBR_R9, r9); \
1682 COND_POP(set, CLBR_R8, r8); \
1683 COND_POP(set, CLBR_RDI, rdi); \
1684 COND_POP(set, CLBR_RSI, rsi); \
1685 COND_POP(set, CLBR_RDX, rdx); \
1686 COND_POP(set, CLBR_RCX, rcx); \
1687 COND_POP(set, CLBR_RAX, rax)
1688
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001689#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001690#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001691#define PARA_INDIRECT(addr) *addr(%rip)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001692#else
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001693#define PV_SAVE_REGS(set) \
1694 COND_PUSH(set, CLBR_EAX, eax); \
1695 COND_PUSH(set, CLBR_EDI, edi); \
1696 COND_PUSH(set, CLBR_ECX, ecx); \
1697 COND_PUSH(set, CLBR_EDX, edx)
1698#define PV_RESTORE_REGS(set) \
1699 COND_POP(set, CLBR_EDX, edx); \
1700 COND_POP(set, CLBR_ECX, ecx); \
1701 COND_POP(set, CLBR_EDI, edi); \
1702 COND_POP(set, CLBR_EAX, eax)
1703
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001704#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001705#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001706#define PARA_INDIRECT(addr) *%cs:addr
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001707#endif
1708
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001709#define INTERRUPT_RETURN \
1710 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001711 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
Rusty Russell139ec7c2006-12-07 02:14:08 +01001712
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001713#define DISABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001714 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001715 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001716 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001717 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001718
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001719#define ENABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001720 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001721 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001722 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001723 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001724
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001725#define USERGS_SYSRET32 \
1726 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +01001727 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001728 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001729
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001730#ifdef CONFIG_X86_32
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001731#define GET_CR0_INTO_EAX \
1732 push %ecx; push %edx; \
1733 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001734 pop %edx; pop %ecx
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001735
1736#define ENABLE_INTERRUPTS_SYSEXIT \
1737 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1738 CLBR_NONE, \
1739 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1740
1741
1742#else /* !CONFIG_X86_32 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -04001743
1744/*
1745 * If swapgs is used while the userspace stack is still current,
1746 * there's no way to call a pvop. The PV replacement *must* be
1747 * inlined, or the swapgs instruction must be trapped and emulated.
1748 */
1749#define SWAPGS_UNSAFE_STACK \
1750 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1751 swapgs)
1752
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001753/*
1754 * Note: swapgs is very special, and in practise is either going to be
1755 * implemented with a single "swapgs" instruction or something very
1756 * special. Either way, we don't need to save any registers for
1757 * it.
1758 */
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001759#define SWAPGS \
1760 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001761 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001762 )
1763
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001764#define GET_CR2_INTO_RCX \
1765 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \
1766 movq %rax, %rcx; \
Glauber de Oliveira Costa4a8c4c42008-01-30 13:32:07 +01001767 xorq %rax, %rax;
1768
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -04001769#define PARAVIRT_ADJUST_EXCEPTION_FRAME \
1770 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
1771 CLBR_NONE, \
1772 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
1773
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001774#define USERGS_SYSRET64 \
1775 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -04001776 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001777 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
1778
1779#define ENABLE_INTERRUPTS_SYSEXIT32 \
1780 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1781 CLBR_NONE, \
1782 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1783#endif /* CONFIG_X86_32 */
Rusty Russell139ec7c2006-12-07 02:14:08 +01001784
Rusty Russelld3561b72006-12-07 02:14:07 +01001785#endif /* __ASSEMBLY__ */
1786#endif /* CONFIG_PARAVIRT */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001787#endif /* _ASM_X86_PARAVIRT_H */