blob: 837457b42dbe5a639c806fc531a2cb96d0ab5459 [file] [log] [blame]
Rusty Russelld3561b72006-12-07 02:14:07 +01001#ifndef __ASM_PARAVIRT_H
2#define __ASM_PARAVIRT_H
3/* Various instructions on x86 need to be replaced for
4 * para-virtualization: those hooks are defined here. */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02005
6#ifdef CONFIG_PARAVIRT
Rusty Russellda181a82006-12-07 02:14:08 +01007#include <asm/page.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01008
Rusty Russell139ec7c2006-12-07 02:14:08 +01009/* Bitmask of what can be clobbered: usually at least eax. */
10#define CLBR_NONE 0x0
11#define CLBR_EAX 0x1
12#define CLBR_ECX 0x2
13#define CLBR_EDX 0x4
14#define CLBR_ANY 0x7
15
Rusty Russelld3561b72006-12-07 02:14:07 +010016#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020017#include <linux/types.h>
18
Rusty Russelld3561b72006-12-07 02:14:07 +010019struct thread_struct;
20struct Xgt_desc_struct;
21struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010022struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020023struct desc_struct;
Rusty Russelld3561b72006-12-07 02:14:07 +010024struct paravirt_ops
25{
26 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020027 int shared_kernel_pmd;
Rusty Russelld3561b72006-12-07 02:14:07 +010028 int paravirt_enabled;
29 const char *name;
30
Rusty Russell139ec7c2006-12-07 02:14:08 +010031 /*
32 * Patch may replace one of the defined code sequences with arbitrary
33 * code, subject to the same register constraints. This generally
34 * means the code is not free to clobber any registers other than EAX.
35 * The patch function should return the number of bytes of code
36 * generated, as we nop pad the rest in generic code.
37 */
38 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
39
Rusty Russelld3561b72006-12-07 02:14:07 +010040 void (*arch_setup)(void);
41 char *(*memory_setup)(void);
42 void (*init_IRQ)(void);
43
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +020044 void (*pagetable_setup_start)(pgd_t *pgd_base);
45 void (*pagetable_setup_done)(pgd_t *pgd_base);
46
Rusty Russelld3561b72006-12-07 02:14:07 +010047 void (*banner)(void);
48
49 unsigned long (*get_wallclock)(void);
50 int (*set_wallclock)(unsigned long);
51 void (*time_init)(void);
52
Andi Kleen1a1eecd2007-02-13 13:26:25 +010053 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010054 unsigned int *ecx, unsigned int *edx);
55
Andi Kleen1a1eecd2007-02-13 13:26:25 +010056 unsigned long (*get_debugreg)(int regno);
57 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010058
Andi Kleen1a1eecd2007-02-13 13:26:25 +010059 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010060
Andi Kleen1a1eecd2007-02-13 13:26:25 +010061 unsigned long (*read_cr0)(void);
62 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010063
Andi Kleen1a1eecd2007-02-13 13:26:25 +010064 unsigned long (*read_cr2)(void);
65 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010066
Andi Kleen1a1eecd2007-02-13 13:26:25 +010067 unsigned long (*read_cr3)(void);
68 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010069
Andi Kleen1a1eecd2007-02-13 13:26:25 +010070 unsigned long (*read_cr4_safe)(void);
71 unsigned long (*read_cr4)(void);
72 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010073
Andi Kleen1a1eecd2007-02-13 13:26:25 +010074 unsigned long (*save_fl)(void);
75 void (*restore_fl)(unsigned long);
76 void (*irq_disable)(void);
77 void (*irq_enable)(void);
78 void (*safe_halt)(void);
79 void (*halt)(void);
80 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010081
82 /* err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010083 u64 (*read_msr)(unsigned int msr, int *err);
84 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +010085
Andi Kleen1a1eecd2007-02-13 13:26:25 +010086 u64 (*read_tsc)(void);
87 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -080088 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -080089 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010090
Andi Kleen1a1eecd2007-02-13 13:26:25 +010091 void (*load_tr_desc)(void);
92 void (*load_gdt)(const struct Xgt_desc_struct *);
93 void (*load_idt)(const struct Xgt_desc_struct *);
94 void (*store_gdt)(struct Xgt_desc_struct *);
95 void (*store_idt)(struct Xgt_desc_struct *);
96 void (*set_ldt)(const void *desc, unsigned entries);
97 unsigned long (*store_tr)(void);
98 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +020099 void (*write_ldt_entry)(struct desc_struct *,
100 int entrynum, u32 low, u32 high);
101 void (*write_gdt_entry)(struct desc_struct *,
102 int entrynum, u32 low, u32 high);
103 void (*write_idt_entry)(struct desc_struct *,
104 int entrynum, u32 low, u32 high);
105 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100106
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100107 void (*set_iopl_mask)(unsigned mask);
Rusty Russelld3561b72006-12-07 02:14:07 +0100108
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100109 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100110
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200111 void (*activate_mm)(struct mm_struct *prev,
112 struct mm_struct *next);
113 void (*dup_mmap)(struct mm_struct *oldmm,
114 struct mm_struct *mm);
115 void (*exit_mmap)(struct mm_struct *mm);
116
Rusty Russell13623d72006-12-07 02:14:08 +0100117#ifdef CONFIG_X86_LOCAL_APIC
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100118 void (*apic_write)(unsigned long reg, unsigned long v);
119 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
120 unsigned long (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100121 void (*setup_boot_clock)(void);
122 void (*setup_secondary_clock)(void);
Rusty Russell13623d72006-12-07 02:14:08 +0100123#endif
124
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100125 void (*flush_tlb_user)(void);
126 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200127 void (*flush_tlb_single)(unsigned long addr);
Rusty Russellda181a82006-12-07 02:14:08 +0100128
Al Viro192cd592007-03-14 09:18:09 +0000129 void (*map_pt_hook)(int type, pte_t *va, u32 pfn);
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800130
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100131 void (*alloc_pt)(u32 pfn);
132 void (*alloc_pd)(u32 pfn);
133 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
134 void (*release_pt)(u32 pfn);
135 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100136
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100137 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200138 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100139 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200140 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
141 void (*pte_update_defer)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
142
143 pte_t (*ptep_get_and_clear)(pte_t *ptep);
144
Rusty Russellda181a82006-12-07 02:14:08 +0100145#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100146 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200147 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100148 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200149 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100150 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200151
152 unsigned long long (*pte_val)(pte_t);
153 unsigned long long (*pmd_val)(pmd_t);
154 unsigned long long (*pgd_val)(pgd_t);
155
156 pte_t (*make_pte)(unsigned long long pte);
157 pmd_t (*make_pmd)(unsigned long long pmd);
158 pgd_t (*make_pgd)(unsigned long long pgd);
159#else
160 unsigned long (*pte_val)(pte_t);
161 unsigned long (*pgd_val)(pgd_t);
162
163 pte_t (*make_pte)(unsigned long pte);
164 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100165#endif
166
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100167 void (*set_lazy_mode)(int mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100168
Rusty Russelld3561b72006-12-07 02:14:07 +0100169 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100170 void (*irq_enable_sysexit)(void);
171 void (*iret)(void);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100172
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100173 void (*startup_ipi_hook)(int phys_apicid, unsigned long start_eip, unsigned long start_esp);
Rusty Russelld3561b72006-12-07 02:14:07 +0100174};
175
Rusty Russellc9ccf302006-12-07 02:14:08 +0100176/* Mark a paravirt probe function. */
177#define paravirt_probe(fn) \
178 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
179 __attribute__((__section__(".paravirtprobe"))) = fn
180
Rusty Russelld3561b72006-12-07 02:14:07 +0100181extern struct paravirt_ops paravirt_ops;
182
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200183#define PARAVIRT_PATCH(x) \
184 (offsetof(struct paravirt_ops, x) / sizeof(void *))
185
186#define paravirt_type(type) \
187 [paravirt_typenum] "i" (PARAVIRT_PATCH(type))
188#define paravirt_clobber(clobber) \
189 [paravirt_clobber] "i" (clobber)
190
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200191#define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200192
193#define _paravirt_alt(insn_string, type, clobber) \
194 "771:\n\t" insn_string "\n" "772:\n" \
195 ".pushsection .parainstructions,\"a\"\n" \
196 " .long 771b\n" \
197 " .byte " type "\n" \
198 " .byte 772b-771b\n" \
199 " .short " clobber "\n" \
200 ".popsection\n"
201
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200202#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200203 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
204
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200205#define PVOP_CALL0(__rettype, __op) \
206 ({ \
207 __rettype __ret; \
208 if (sizeof(__rettype) > sizeof(unsigned long)) { \
209 unsigned long long __tmp; \
210 unsigned long __ecx; \
211 asm volatile(paravirt_alt(PARAVIRT_CALL) \
212 : "=A" (__tmp), "=c" (__ecx) \
213 : paravirt_type(__op), \
214 paravirt_clobber(CLBR_ANY) \
215 : "memory", "cc"); \
216 __ret = (__rettype)__tmp; \
217 } else { \
218 unsigned long __tmp, __edx, __ecx; \
219 asm volatile(paravirt_alt(PARAVIRT_CALL) \
220 : "=a" (__tmp), "=d" (__edx), \
221 "=c" (__ecx) \
222 : paravirt_type(__op), \
223 paravirt_clobber(CLBR_ANY) \
224 : "memory", "cc"); \
225 __ret = (__rettype)__tmp; \
226 } \
227 __ret; \
228 })
229#define PVOP_VCALL0(__op) \
230 ({ \
231 unsigned long __eax, __edx, __ecx; \
232 asm volatile(paravirt_alt(PARAVIRT_CALL) \
233 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
234 : paravirt_type(__op), \
235 paravirt_clobber(CLBR_ANY) \
236 : "memory", "cc"); \
237 })
238
239#define PVOP_CALL1(__rettype, __op, arg1) \
240 ({ \
241 __rettype __ret; \
242 if (sizeof(__rettype) > sizeof(unsigned long)) { \
243 unsigned long long __tmp; \
244 unsigned long __ecx; \
245 asm volatile(paravirt_alt(PARAVIRT_CALL) \
246 : "=A" (__tmp), "=c" (__ecx) \
247 : "a" ((u32)(arg1)), \
248 paravirt_type(__op), \
249 paravirt_clobber(CLBR_ANY) \
250 : "memory", "cc"); \
251 __ret = (__rettype)__tmp; \
252 } else { \
253 unsigned long __tmp, __edx, __ecx; \
254 asm volatile(paravirt_alt(PARAVIRT_CALL) \
255 : "=a" (__tmp), "=d" (__edx), \
256 "=c" (__ecx) \
257 : "0" ((u32)(arg1)), \
258 paravirt_type(__op), \
259 paravirt_clobber(CLBR_ANY) \
260 : "memory", "cc"); \
261 __ret = (__rettype)__tmp; \
262 } \
263 __ret; \
264 })
265#define PVOP_VCALL1(__op, arg1) \
266 ({ \
267 unsigned long __eax, __edx, __ecx; \
268 asm volatile(paravirt_alt(PARAVIRT_CALL) \
269 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
270 : "0" ((u32)(arg1)), \
271 paravirt_type(__op), \
272 paravirt_clobber(CLBR_ANY) \
273 : "memory", "cc"); \
274 })
275
276#define PVOP_CALL2(__rettype, __op, arg1, arg2) \
277 ({ \
278 __rettype __ret; \
279 if (sizeof(__rettype) > sizeof(unsigned long)) { \
280 unsigned long long __tmp; \
281 unsigned long __ecx; \
282 asm volatile(paravirt_alt(PARAVIRT_CALL) \
283 : "=A" (__tmp), "=c" (__ecx) \
284 : "a" ((u32)(arg1)), \
285 "d" ((u32)(arg2)), \
286 paravirt_type(__op), \
287 paravirt_clobber(CLBR_ANY) \
288 : "memory", "cc"); \
289 __ret = (__rettype)__tmp; \
290 } else { \
291 unsigned long __tmp, __edx, __ecx; \
292 asm volatile(paravirt_alt(PARAVIRT_CALL) \
293 : "=a" (__tmp), "=d" (__edx), \
294 "=c" (__ecx) \
295 : "0" ((u32)(arg1)), \
296 "1" ((u32)(arg2)), \
297 paravirt_type(__op), \
298 paravirt_clobber(CLBR_ANY) \
299 : "memory", "cc"); \
300 __ret = (__rettype)__tmp; \
301 } \
302 __ret; \
303 })
304#define PVOP_VCALL2(__op, arg1, arg2) \
305 ({ \
306 unsigned long __eax, __edx, __ecx; \
307 asm volatile(paravirt_alt(PARAVIRT_CALL) \
308 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
309 : "0" ((u32)(arg1)), \
310 "1" ((u32)(arg2)), \
311 paravirt_type(__op), \
312 paravirt_clobber(CLBR_ANY) \
313 : "memory", "cc"); \
314 })
315
316#define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \
317 ({ \
318 __rettype __ret; \
319 if (sizeof(__rettype) > sizeof(unsigned long)) { \
320 unsigned long long __tmp; \
321 unsigned long __ecx; \
322 asm volatile(paravirt_alt(PARAVIRT_CALL) \
323 : "=A" (__tmp), "=c" (__ecx) \
324 : "a" ((u32)(arg1)), \
325 "d" ((u32)(arg2)), \
326 "1" ((u32)(arg3)), \
327 paravirt_type(__op), \
328 paravirt_clobber(CLBR_ANY) \
329 : "memory", "cc"); \
330 __ret = (__rettype)__tmp; \
331 } else { \
332 unsigned long __tmp, __edx, __ecx; \
333 asm volatile(paravirt_alt(PARAVIRT_CALL) \
334 : "=a" (__tmp), "=d" (__edx), \
335 "=c" (__ecx) \
336 : "0" ((u32)(arg1)), \
337 "1" ((u32)(arg2)), \
338 "2" ((u32)(arg3)), \
339 paravirt_type(__op), \
340 paravirt_clobber(CLBR_ANY) \
341 : "memory", "cc"); \
342 __ret = (__rettype)__tmp; \
343 } \
344 __ret; \
345 })
346#define PVOP_VCALL3(__op, arg1, arg2, arg3) \
347 ({ \
348 unsigned long __eax, __edx, __ecx; \
349 asm volatile(paravirt_alt(PARAVIRT_CALL) \
350 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
351 : "0" ((u32)(arg1)), \
352 "1" ((u32)(arg2)), \
353 "2" ((u32)(arg3)), \
354 paravirt_type(__op), \
355 paravirt_clobber(CLBR_ANY) \
356 : "memory", "cc"); \
357 })
358
359#define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \
360 ({ \
361 __rettype __ret; \
362 if (sizeof(__rettype) > sizeof(unsigned long)) { \
363 unsigned long long __tmp; \
364 unsigned long __ecx; \
365 asm volatile("push %[_arg4]; " \
366 paravirt_alt(PARAVIRT_CALL) \
367 "lea 4(%%esp),%%esp" \
368 : "=A" (__tmp), "=c" (__ecx) \
369 : "a" ((u32)(arg1)), \
370 "d" ((u32)(arg2)), \
371 "1" ((u32)(arg3)), \
372 [_arg4] "mr" ((u32)(arg4)), \
373 paravirt_type(__op), \
374 paravirt_clobber(CLBR_ANY) \
375 : "memory", "cc",); \
376 __ret = (__rettype)__tmp; \
377 } else { \
378 unsigned long __tmp, __edx, __ecx; \
379 asm volatile("push %[_arg4]; " \
380 paravirt_alt(PARAVIRT_CALL) \
381 "lea 4(%%esp),%%esp" \
382 : "=a" (__tmp), "=d" (__edx), "=c" (__ecx) \
383 : "0" ((u32)(arg1)), \
384 "1" ((u32)(arg2)), \
385 "2" ((u32)(arg3)), \
386 [_arg4]"mr" ((u32)(arg4)), \
387 paravirt_type(__op), \
388 paravirt_clobber(CLBR_ANY) \
389 : "memory", "cc"); \
390 __ret = (__rettype)__tmp; \
391 } \
392 __ret; \
393 })
394#define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \
395 ({ \
396 unsigned long __eax, __edx, __ecx; \
397 asm volatile("push %[_arg4]; " \
398 paravirt_alt(PARAVIRT_CALL) \
399 "lea 4(%%esp),%%esp" \
400 : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \
401 : "0" ((u32)(arg1)), \
402 "1" ((u32)(arg2)), \
403 "2" ((u32)(arg3)), \
404 [_arg4]"mr" ((u32)(arg4)), \
405 paravirt_type(__op), \
406 paravirt_clobber(CLBR_ANY) \
407 : "memory", "cc"); \
408 })
409
410static inline int paravirt_enabled(void)
411{
412 return paravirt_ops.paravirt_enabled;
413}
Rusty Russelld3561b72006-12-07 02:14:07 +0100414
415static inline void load_esp0(struct tss_struct *tss,
416 struct thread_struct *thread)
417{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200418 PVOP_VCALL2(load_esp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100419}
420
421#define ARCH_SETUP paravirt_ops.arch_setup();
422static inline unsigned long get_wallclock(void)
423{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200424 return PVOP_CALL0(unsigned long, get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100425}
426
427static inline int set_wallclock(unsigned long nowtime)
428{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200429 return PVOP_CALL1(int, set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100430}
431
Zachary Amsdene30fab32007-03-05 00:30:39 -0800432static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100433{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800434 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100435}
436
437/* The paravirtualized CPUID instruction. */
438static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
439 unsigned int *ecx, unsigned int *edx)
440{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200441 PVOP_VCALL4(cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100442}
443
444/*
445 * These special macros can be used to get or set a debugging register
446 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200447static inline unsigned long paravirt_get_debugreg(int reg)
448{
449 return PVOP_CALL1(unsigned long, get_debugreg, reg);
450}
451#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
452static inline void set_debugreg(unsigned long val, int reg)
453{
454 PVOP_VCALL2(set_debugreg, reg, val);
455}
Rusty Russelld3561b72006-12-07 02:14:07 +0100456
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200457static inline void clts(void)
458{
459 PVOP_VCALL0(clts);
460}
Rusty Russelld3561b72006-12-07 02:14:07 +0100461
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200462static inline unsigned long read_cr0(void)
463{
464 return PVOP_CALL0(unsigned long, read_cr0);
465}
Rusty Russelld3561b72006-12-07 02:14:07 +0100466
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200467static inline void write_cr0(unsigned long x)
468{
469 PVOP_VCALL1(write_cr0, x);
470}
Rusty Russelld3561b72006-12-07 02:14:07 +0100471
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200472static inline unsigned long read_cr2(void)
473{
474 return PVOP_CALL0(unsigned long, read_cr2);
475}
Rusty Russelld3561b72006-12-07 02:14:07 +0100476
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200477static inline void write_cr2(unsigned long x)
478{
479 PVOP_VCALL1(write_cr2, x);
480}
Rusty Russelld3561b72006-12-07 02:14:07 +0100481
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200482static inline unsigned long read_cr3(void)
483{
484 return PVOP_CALL0(unsigned long, read_cr3);
485}
486
487static inline void write_cr3(unsigned long x)
488{
489 PVOP_VCALL1(write_cr3, x);
490}
491
492static inline unsigned long read_cr4(void)
493{
494 return PVOP_CALL0(unsigned long, read_cr4);
495}
496static inline unsigned long read_cr4_safe(void)
497{
498 return PVOP_CALL0(unsigned long, read_cr4_safe);
499}
500
501static inline void write_cr4(unsigned long x)
502{
503 PVOP_VCALL1(write_cr4, x);
504}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200505
Rusty Russelld3561b72006-12-07 02:14:07 +0100506static inline void raw_safe_halt(void)
507{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200508 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100509}
510
511static inline void halt(void)
512{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200513 PVOP_VCALL0(safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100514}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200515
516static inline void wbinvd(void)
517{
518 PVOP_VCALL0(wbinvd);
519}
Rusty Russelld3561b72006-12-07 02:14:07 +0100520
521#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
522
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200523static inline u64 paravirt_read_msr(unsigned msr, int *err)
524{
525 return PVOP_CALL2(u64, read_msr, msr, err);
526}
527static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
528{
529 return PVOP_CALL3(int, write_msr, msr, low, high);
530}
531
Rusty Russell90a0a062007-05-02 19:27:10 +0200532/* These should all do BUG_ON(_err), but our headers are too tangled. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200533#define rdmsr(msr,val1,val2) do { \
534 int _err; \
535 u64 _l = paravirt_read_msr(msr, &_err); \
536 val1 = (u32)_l; \
537 val2 = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100538} while(0)
539
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200540#define wrmsr(msr,val1,val2) do { \
541 paravirt_write_msr(msr, val1, val2); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100542} while(0)
543
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200544#define rdmsrl(msr,val) do { \
545 int _err; \
546 val = paravirt_read_msr(msr, &_err); \
Rusty Russelld3561b72006-12-07 02:14:07 +0100547} while(0)
548
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200549#define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0))
550#define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100551
552/* rdmsr with exception handling */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200553#define rdmsr_safe(msr,a,b) ({ \
554 int _err; \
555 u64 _l = paravirt_read_msr(msr, &_err); \
556 (*a) = (u32)_l; \
557 (*b) = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100558 _err; })
559
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200560
561static inline u64 paravirt_read_tsc(void)
562{
563 return PVOP_CALL0(u64, read_tsc);
564}
565#define rdtsc(low,high) do { \
566 u64 _l = paravirt_read_tsc(); \
567 low = (u32)_l; \
568 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100569} while(0)
570
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200571#define rdtscl(low) do { \
572 u64 _l = paravirt_read_tsc(); \
573 low = (int)_l; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100574} while(0)
575
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200576#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100577
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800578#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800579#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800580
Rusty Russelld3561b72006-12-07 02:14:07 +0100581#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
582
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200583static inline unsigned long long paravirt_read_pmc(int counter)
584{
585 return PVOP_CALL1(u64, read_pmc, counter);
586}
587
588#define rdpmc(counter,low,high) do { \
589 u64 _l = paravirt_read_pmc(counter); \
590 low = (u32)_l; \
591 high = _l >> 32; \
Rusty Russelld3561b72006-12-07 02:14:07 +0100592} while(0)
593
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200594static inline void load_TR_desc(void)
595{
596 PVOP_VCALL0(load_tr_desc);
597}
598static inline void load_gdt(const struct Xgt_desc_struct *dtr)
599{
600 PVOP_VCALL1(load_gdt, dtr);
601}
602static inline void load_idt(const struct Xgt_desc_struct *dtr)
603{
604 PVOP_VCALL1(load_idt, dtr);
605}
606static inline void set_ldt(const void *addr, unsigned entries)
607{
608 PVOP_VCALL2(set_ldt, addr, entries);
609}
610static inline void store_gdt(struct Xgt_desc_struct *dtr)
611{
612 PVOP_VCALL1(store_gdt, dtr);
613}
614static inline void store_idt(struct Xgt_desc_struct *dtr)
615{
616 PVOP_VCALL1(store_idt, dtr);
617}
618static inline unsigned long paravirt_store_tr(void)
619{
620 return PVOP_CALL0(unsigned long, store_tr);
621}
622#define store_tr(tr) ((tr) = paravirt_store_tr())
623static inline void load_TLS(struct thread_struct *t, unsigned cpu)
624{
625 PVOP_VCALL2(load_tls, t, cpu);
626}
627static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high)
628{
629 PVOP_VCALL4(write_ldt_entry, dt, entry, low, high);
630}
631static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high)
632{
633 PVOP_VCALL4(write_gdt_entry, dt, entry, low, high);
634}
635static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high)
636{
637 PVOP_VCALL4(write_idt_entry, dt, entry, low, high);
638}
639static inline void set_iopl_mask(unsigned mask)
640{
641 PVOP_VCALL1(set_iopl_mask, mask);
642}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200643
Rusty Russelld3561b72006-12-07 02:14:07 +0100644/* The paravirtualized I/O functions */
645static inline void slow_down_io(void) {
646 paravirt_ops.io_delay();
647#ifdef REALLY_SLOW_IO
648 paravirt_ops.io_delay();
649 paravirt_ops.io_delay();
650 paravirt_ops.io_delay();
651#endif
652}
653
Rusty Russell13623d72006-12-07 02:14:08 +0100654#ifdef CONFIG_X86_LOCAL_APIC
655/*
656 * Basic functions accessing APICs.
657 */
658static inline void apic_write(unsigned long reg, unsigned long v)
659{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200660 PVOP_VCALL2(apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100661}
662
663static inline void apic_write_atomic(unsigned long reg, unsigned long v)
664{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200665 PVOP_VCALL2(apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100666}
667
668static inline unsigned long apic_read(unsigned long reg)
669{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200670 return PVOP_CALL1(unsigned long, apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100671}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100672
673static inline void setup_boot_clock(void)
674{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200675 PVOP_VCALL0(setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100676}
677
678static inline void setup_secondary_clock(void)
679{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200680 PVOP_VCALL0(setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100681}
Rusty Russell13623d72006-12-07 02:14:08 +0100682#endif
683
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200684static inline void paravirt_pagetable_setup_start(pgd_t *base)
685{
686 if (paravirt_ops.pagetable_setup_start)
687 (*paravirt_ops.pagetable_setup_start)(base);
688}
689
690static inline void paravirt_pagetable_setup_done(pgd_t *base)
691{
692 if (paravirt_ops.pagetable_setup_done)
693 (*paravirt_ops.pagetable_setup_done)(base);
694}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200695
Zachary Amsdenae5da272007-02-13 13:26:21 +0100696#ifdef CONFIG_SMP
697static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
698 unsigned long start_esp)
699{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200700 PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100701}
702#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100703
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200704static inline void paravirt_activate_mm(struct mm_struct *prev,
705 struct mm_struct *next)
706{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200707 PVOP_VCALL2(activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200708}
709
710static inline void arch_dup_mmap(struct mm_struct *oldmm,
711 struct mm_struct *mm)
712{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200713 PVOP_VCALL2(dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200714}
715
716static inline void arch_exit_mmap(struct mm_struct *mm)
717{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200718 PVOP_VCALL1(exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200719}
720
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200721static inline void __flush_tlb(void)
722{
723 PVOP_VCALL0(flush_tlb_user);
724}
725static inline void __flush_tlb_global(void)
726{
727 PVOP_VCALL0(flush_tlb_kernel);
728}
729static inline void __flush_tlb_single(unsigned long addr)
730{
731 PVOP_VCALL1(flush_tlb_single, addr);
732}
Rusty Russellda181a82006-12-07 02:14:08 +0100733
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200734static inline void paravirt_map_pt_hook(int type, pte_t *va, u32 pfn)
735{
736 PVOP_VCALL3(map_pt_hook, type, va, pfn);
737}
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800738
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200739static inline void paravirt_alloc_pt(unsigned pfn)
740{
741 PVOP_VCALL1(alloc_pt, pfn);
742}
743static inline void paravirt_release_pt(unsigned pfn)
744{
745 PVOP_VCALL1(release_pt, pfn);
746}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100747
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200748static inline void paravirt_alloc_pd(unsigned pfn)
749{
750 PVOP_VCALL1(alloc_pd, pfn);
751}
752
753static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
754 unsigned start, unsigned count)
755{
756 PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count);
757}
758static inline void paravirt_release_pd(unsigned pfn)
759{
760 PVOP_VCALL1(release_pd, pfn);
761}
762
763static inline void pte_update(struct mm_struct *mm, unsigned long addr,
764 pte_t *ptep)
765{
766 PVOP_VCALL3(pte_update, mm, addr, ptep);
767}
768
769static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
770 pte_t *ptep)
771{
772 PVOP_VCALL3(pte_update_defer, mm, addr, ptep);
773}
774
775#ifdef CONFIG_X86_PAE
776static inline pte_t __pte(unsigned long long val)
777{
778 unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte,
779 val, val >> 32);
780 return (pte_t) { ret, ret >> 32 };
781}
782
783static inline pmd_t __pmd(unsigned long long val)
784{
785 return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) };
786}
787
788static inline pgd_t __pgd(unsigned long long val)
789{
790 return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) };
791}
792
793static inline unsigned long long pte_val(pte_t x)
794{
795 return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high);
796}
797
798static inline unsigned long long pmd_val(pmd_t x)
799{
800 return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32);
801}
802
803static inline unsigned long long pgd_val(pgd_t x)
804{
805 return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32);
806}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100807
Rusty Russellda181a82006-12-07 02:14:08 +0100808static inline void set_pte(pte_t *ptep, pte_t pteval)
809{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200810 PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high);
Rusty Russellda181a82006-12-07 02:14:08 +0100811}
812
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200813static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
814 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100815{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200816 /* 5 arg words */
Rusty Russellda181a82006-12-07 02:14:08 +0100817 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
818}
819
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200820static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
821{
822 PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high);
823}
824
825static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
826 pte_t *ptep, pte_t pte)
827{
828 /* 5 arg words */
829 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
830}
831
Rusty Russellda181a82006-12-07 02:14:08 +0100832static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
833{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200834 PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100835}
836
837static inline void set_pud(pud_t *pudp, pud_t pudval)
838{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200839 PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32);
Rusty Russellda181a82006-12-07 02:14:08 +0100840}
841
842static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
843{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200844 PVOP_VCALL3(pte_clear, mm, addr, ptep);
Rusty Russellda181a82006-12-07 02:14:08 +0100845}
846
847static inline void pmd_clear(pmd_t *pmdp)
848{
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200849 PVOP_VCALL1(pmd_clear, pmdp);
Rusty Russellda181a82006-12-07 02:14:08 +0100850}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200851
852static inline pte_t raw_ptep_get_and_clear(pte_t *p)
853{
854 unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p);
855 return (pte_t) { val, val >> 32 };
856}
857#else /* !CONFIG_X86_PAE */
858static inline pte_t __pte(unsigned long val)
859{
860 return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) };
861}
862
863static inline pgd_t __pgd(unsigned long val)
864{
865 return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) };
866}
867
868static inline unsigned long pte_val(pte_t x)
869{
870 return PVOP_CALL1(unsigned long, pte_val, x.pte_low);
871}
872
873static inline unsigned long pgd_val(pgd_t x)
874{
875 return PVOP_CALL1(unsigned long, pgd_val, x.pgd);
876}
877
878static inline void set_pte(pte_t *ptep, pte_t pteval)
879{
880 PVOP_VCALL2(set_pte, ptep, pteval.pte_low);
881}
882
883static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
884 pte_t *ptep, pte_t pteval)
885{
886 PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low);
887}
888
889static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
890{
891 PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd);
892}
893
894static inline pte_t raw_ptep_get_and_clear(pte_t *p)
895{
896 return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) };
897}
898#endif /* CONFIG_X86_PAE */
Rusty Russellda181a82006-12-07 02:14:08 +0100899
Zachary Amsden9226d122007-02-13 13:26:21 +0100900/* Lazy mode for batching updates / context switch */
901#define PARAVIRT_LAZY_NONE 0
902#define PARAVIRT_LAZY_MMU 1
903#define PARAVIRT_LAZY_CPU 2
Zachary Amsden49f19712007-04-08 16:04:01 -0700904#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +0100905
906#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200907static inline void arch_enter_lazy_cpu_mode(void)
908{
909 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU);
910}
911
912static inline void arch_leave_lazy_cpu_mode(void)
913{
914 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
915}
916
917static inline void arch_flush_lazy_cpu_mode(void)
918{
919 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
920}
921
Zachary Amsden9226d122007-02-13 13:26:21 +0100922
923#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200924static inline void arch_enter_lazy_mmu_mode(void)
925{
926 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU);
927}
928
929static inline void arch_leave_lazy_mmu_mode(void)
930{
931 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE);
932}
933
934static inline void arch_flush_lazy_mmu_mode(void)
935{
936 PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH);
937}
Zachary Amsden9226d122007-02-13 13:26:21 +0100938
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200939void _paravirt_nop(void);
940#define paravirt_nop ((void *)_paravirt_nop)
941
Rusty Russell139ec7c2006-12-07 02:14:08 +0100942/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200943struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +0100944 u8 *instr; /* original instructions */
945 u8 instrtype; /* type of this instruction */
946 u8 len; /* length of original instruction */
947 u16 clobbers; /* what registers you may clobber */
948};
949
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200950extern struct paravirt_patch_site __parainstructions[],
951 __parainstructions_end[];
952
Rusty Russell139ec7c2006-12-07 02:14:08 +0100953static inline unsigned long __raw_local_save_flags(void)
954{
955 unsigned long f;
956
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200957 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
958 PARAVIRT_CALL
959 "popl %%edx; popl %%ecx")
960 : "=a"(f)
961 : paravirt_type(save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200962 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200963 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100964 return f;
965}
966
967static inline void raw_local_irq_restore(unsigned long f)
968{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200969 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
970 PARAVIRT_CALL
971 "popl %%edx; popl %%ecx")
972 : "=a"(f)
973 : "0"(f),
974 paravirt_type(restore_fl),
975 paravirt_clobber(CLBR_EAX)
976 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100977}
978
979static inline void raw_local_irq_disable(void)
980{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200981 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
982 PARAVIRT_CALL
983 "popl %%edx; popl %%ecx")
984 :
985 : paravirt_type(irq_disable),
986 paravirt_clobber(CLBR_EAX)
987 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100988}
989
990static inline void raw_local_irq_enable(void)
991{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200992 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
993 PARAVIRT_CALL
994 "popl %%edx; popl %%ecx")
995 :
996 : paravirt_type(irq_enable),
997 paravirt_clobber(CLBR_EAX)
998 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100999}
1000
1001static inline unsigned long __raw_local_irq_save(void)
1002{
1003 unsigned long f;
1004
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001005 f = __raw_local_save_flags();
1006 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001007 return f;
1008}
1009
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001010#define CLI_STRING \
1011 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1012 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
1013 "popl %%edx; popl %%ecx", \
1014 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
Rusty Russell139ec7c2006-12-07 02:14:08 +01001015
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001016#define STI_STRING \
1017 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
1018 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
1019 "popl %%edx; popl %%ecx", \
1020 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
1021
Rusty Russell139ec7c2006-12-07 02:14:08 +01001022#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001023#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001024 , \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001025 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
1026 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
1027 paravirt_clobber(CLBR_EAX)
1028
1029#undef PARAVIRT_CALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001030#undef PVOP_VCALL0
1031#undef PVOP_CALL0
1032#undef PVOP_VCALL1
1033#undef PVOP_CALL1
1034#undef PVOP_VCALL2
1035#undef PVOP_CALL2
1036#undef PVOP_VCALL3
1037#undef PVOP_CALL3
1038#undef PVOP_VCALL4
1039#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001040
Rusty Russelld3561b72006-12-07 02:14:07 +01001041#else /* __ASSEMBLY__ */
1042
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001043#define PARA_PATCH(off) ((off) / 4)
1044
1045#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001046771:; \
1047 ops; \
1048772:; \
1049 .pushsection .parainstructions,"a"; \
1050 .long 771b; \
1051 .byte ptype; \
1052 .byte 772b-771b; \
1053 .short clobbers; \
1054 .popsection
1055
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001056#define INTERRUPT_RETURN \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001057 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001058 jmp *%cs:paravirt_ops+PARAVIRT_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001059
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001060#define DISABLE_INTERRUPTS(clobbers) \
1061 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001062 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001063 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001064 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001065
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001066#define ENABLE_INTERRUPTS(clobbers) \
1067 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001068 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001069 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001070 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001071
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001072#define ENABLE_INTERRUPTS_SYSEXIT \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001073 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001074 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001075
1076#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001077 push %ecx; push %edx; \
1078 call *paravirt_ops+PARAVIRT_read_cr0; \
1079 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +01001080
Rusty Russelld3561b72006-12-07 02:14:07 +01001081#endif /* __ASSEMBLY__ */
1082#endif /* CONFIG_PARAVIRT */
1083#endif /* __ASM_PARAVIRT_H */