blob: 87fd4317bee988350dc308cab8df9e7dbe3f3180 [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);
127 void (*flush_tlb_single)(u32 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
191#define PARAVIRT_CALL "call *paravirt_ops+%c[paravirt_typenum]*4;"
192
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
202#define paravirt_alt(insn_string) \
203 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
204
Rusty Russelld3561b72006-12-07 02:14:07 +0100205#define paravirt_enabled() (paravirt_ops.paravirt_enabled)
206
207static inline void load_esp0(struct tss_struct *tss,
208 struct thread_struct *thread)
209{
210 paravirt_ops.load_esp0(tss, thread);
211}
212
213#define ARCH_SETUP paravirt_ops.arch_setup();
214static inline unsigned long get_wallclock(void)
215{
216 return paravirt_ops.get_wallclock();
217}
218
219static inline int set_wallclock(unsigned long nowtime)
220{
221 return paravirt_ops.set_wallclock(nowtime);
222}
223
Zachary Amsdene30fab32007-03-05 00:30:39 -0800224static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100225{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800226 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100227}
228
229/* The paravirtualized CPUID instruction. */
230static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
231 unsigned int *ecx, unsigned int *edx)
232{
233 paravirt_ops.cpuid(eax, ebx, ecx, edx);
234}
235
236/*
237 * These special macros can be used to get or set a debugging register
238 */
239#define get_debugreg(var, reg) var = paravirt_ops.get_debugreg(reg)
240#define set_debugreg(val, reg) paravirt_ops.set_debugreg(reg, val)
241
242#define clts() paravirt_ops.clts()
243
244#define read_cr0() paravirt_ops.read_cr0()
245#define write_cr0(x) paravirt_ops.write_cr0(x)
246
247#define read_cr2() paravirt_ops.read_cr2()
248#define write_cr2(x) paravirt_ops.write_cr2(x)
249
250#define read_cr3() paravirt_ops.read_cr3()
251#define write_cr3(x) paravirt_ops.write_cr3(x)
252
253#define read_cr4() paravirt_ops.read_cr4()
254#define read_cr4_safe(x) paravirt_ops.read_cr4_safe()
255#define write_cr4(x) paravirt_ops.write_cr4(x)
256
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200257#define raw_ptep_get_and_clear(xp) (paravirt_ops.ptep_get_and_clear(xp))
258
Rusty Russelld3561b72006-12-07 02:14:07 +0100259static inline void raw_safe_halt(void)
260{
261 paravirt_ops.safe_halt();
262}
263
264static inline void halt(void)
265{
266 paravirt_ops.safe_halt();
267}
268#define wbinvd() paravirt_ops.wbinvd()
269
270#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
271
Rusty Russell90a0a062007-05-02 19:27:10 +0200272/* These should all do BUG_ON(_err), but our headers are too tangled. */
Rusty Russelld3561b72006-12-07 02:14:07 +0100273#define rdmsr(msr,val1,val2) do { \
274 int _err; \
275 u64 _l = paravirt_ops.read_msr(msr,&_err); \
276 val1 = (u32)_l; \
277 val2 = _l >> 32; \
278} while(0)
279
280#define wrmsr(msr,val1,val2) do { \
281 u64 _l = ((u64)(val2) << 32) | (val1); \
282 paravirt_ops.write_msr((msr), _l); \
283} while(0)
284
285#define rdmsrl(msr,val) do { \
286 int _err; \
287 val = paravirt_ops.read_msr((msr),&_err); \
288} while(0)
289
290#define wrmsrl(msr,val) (paravirt_ops.write_msr((msr),(val)))
291#define wrmsr_safe(msr,a,b) ({ \
292 u64 _l = ((u64)(b) << 32) | (a); \
293 paravirt_ops.write_msr((msr),_l); \
294})
295
296/* rdmsr with exception handling */
297#define rdmsr_safe(msr,a,b) ({ \
298 int _err; \
299 u64 _l = paravirt_ops.read_msr(msr,&_err); \
300 (*a) = (u32)_l; \
301 (*b) = _l >> 32; \
302 _err; })
303
304#define rdtsc(low,high) do { \
305 u64 _l = paravirt_ops.read_tsc(); \
306 low = (u32)_l; \
307 high = _l >> 32; \
308} while(0)
309
310#define rdtscl(low) do { \
311 u64 _l = paravirt_ops.read_tsc(); \
312 low = (int)_l; \
313} while(0)
314
315#define rdtscll(val) (val = paravirt_ops.read_tsc())
316
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800317#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800318#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800319
Rusty Russelld3561b72006-12-07 02:14:07 +0100320#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
321
322#define rdpmc(counter,low,high) do { \
323 u64 _l = paravirt_ops.read_pmc(); \
324 low = (u32)_l; \
325 high = _l >> 32; \
326} while(0)
327
328#define load_TR_desc() (paravirt_ops.load_tr_desc())
329#define load_gdt(dtr) (paravirt_ops.load_gdt(dtr))
330#define load_idt(dtr) (paravirt_ops.load_idt(dtr))
331#define set_ldt(addr, entries) (paravirt_ops.set_ldt((addr), (entries)))
332#define store_gdt(dtr) (paravirt_ops.store_gdt(dtr))
333#define store_idt(dtr) (paravirt_ops.store_idt(dtr))
334#define store_tr(tr) ((tr) = paravirt_ops.store_tr())
335#define load_TLS(t,cpu) (paravirt_ops.load_tls((t),(cpu)))
336#define write_ldt_entry(dt, entry, low, high) \
337 (paravirt_ops.write_ldt_entry((dt), (entry), (low), (high)))
338#define write_gdt_entry(dt, entry, low, high) \
339 (paravirt_ops.write_gdt_entry((dt), (entry), (low), (high)))
340#define write_idt_entry(dt, entry, low, high) \
341 (paravirt_ops.write_idt_entry((dt), (entry), (low), (high)))
342#define set_iopl_mask(mask) (paravirt_ops.set_iopl_mask(mask))
343
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200344#define __pte(x) paravirt_ops.make_pte(x)
345#define __pgd(x) paravirt_ops.make_pgd(x)
346
347#define pte_val(x) paravirt_ops.pte_val(x)
348#define pgd_val(x) paravirt_ops.pgd_val(x)
349
350#ifdef CONFIG_X86_PAE
351#define __pmd(x) paravirt_ops.make_pmd(x)
352#define pmd_val(x) paravirt_ops.pmd_val(x)
353#endif
354
Rusty Russelld3561b72006-12-07 02:14:07 +0100355/* The paravirtualized I/O functions */
356static inline void slow_down_io(void) {
357 paravirt_ops.io_delay();
358#ifdef REALLY_SLOW_IO
359 paravirt_ops.io_delay();
360 paravirt_ops.io_delay();
361 paravirt_ops.io_delay();
362#endif
363}
364
Rusty Russell13623d72006-12-07 02:14:08 +0100365#ifdef CONFIG_X86_LOCAL_APIC
366/*
367 * Basic functions accessing APICs.
368 */
369static inline void apic_write(unsigned long reg, unsigned long v)
370{
371 paravirt_ops.apic_write(reg,v);
372}
373
374static inline void apic_write_atomic(unsigned long reg, unsigned long v)
375{
376 paravirt_ops.apic_write_atomic(reg,v);
377}
378
379static inline unsigned long apic_read(unsigned long reg)
380{
381 return paravirt_ops.apic_read(reg);
382}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100383
384static inline void setup_boot_clock(void)
385{
386 paravirt_ops.setup_boot_clock();
387}
388
389static inline void setup_secondary_clock(void)
390{
391 paravirt_ops.setup_secondary_clock();
392}
Rusty Russell13623d72006-12-07 02:14:08 +0100393#endif
394
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200395static inline void paravirt_pagetable_setup_start(pgd_t *base)
396{
397 if (paravirt_ops.pagetable_setup_start)
398 (*paravirt_ops.pagetable_setup_start)(base);
399}
400
401static inline void paravirt_pagetable_setup_done(pgd_t *base)
402{
403 if (paravirt_ops.pagetable_setup_done)
404 (*paravirt_ops.pagetable_setup_done)(base);
405}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200406
Zachary Amsdenae5da272007-02-13 13:26:21 +0100407#ifdef CONFIG_SMP
408static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
409 unsigned long start_esp)
410{
411 return paravirt_ops.startup_ipi_hook(phys_apicid, start_eip, start_esp);
412}
413#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100414
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200415static inline void paravirt_activate_mm(struct mm_struct *prev,
416 struct mm_struct *next)
417{
418 paravirt_ops.activate_mm(prev, next);
419}
420
421static inline void arch_dup_mmap(struct mm_struct *oldmm,
422 struct mm_struct *mm)
423{
424 paravirt_ops.dup_mmap(oldmm, mm);
425}
426
427static inline void arch_exit_mmap(struct mm_struct *mm)
428{
429 paravirt_ops.exit_mmap(mm);
430}
431
Rusty Russellda181a82006-12-07 02:14:08 +0100432#define __flush_tlb() paravirt_ops.flush_tlb_user()
433#define __flush_tlb_global() paravirt_ops.flush_tlb_kernel()
434#define __flush_tlb_single(addr) paravirt_ops.flush_tlb_single(addr)
435
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800436#define paravirt_map_pt_hook(type, va, pfn) paravirt_ops.map_pt_hook(type, va, pfn)
437
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100438#define paravirt_alloc_pt(pfn) paravirt_ops.alloc_pt(pfn)
439#define paravirt_release_pt(pfn) paravirt_ops.release_pt(pfn)
440
441#define paravirt_alloc_pd(pfn) paravirt_ops.alloc_pd(pfn)
442#define paravirt_alloc_pd_clone(pfn, clonepfn, start, count) \
443 paravirt_ops.alloc_pd_clone(pfn, clonepfn, start, count)
444#define paravirt_release_pd(pfn) paravirt_ops.release_pd(pfn)
445
Rusty Russellda181a82006-12-07 02:14:08 +0100446static inline void set_pte(pte_t *ptep, pte_t pteval)
447{
448 paravirt_ops.set_pte(ptep, pteval);
449}
450
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200451static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
452 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100453{
454 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
455}
456
457static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
458{
459 paravirt_ops.set_pmd(pmdp, pmdval);
460}
461
462static inline void pte_update(struct mm_struct *mm, u32 addr, pte_t *ptep)
463{
464 paravirt_ops.pte_update(mm, addr, ptep);
465}
466
467static inline void pte_update_defer(struct mm_struct *mm, u32 addr, pte_t *ptep)
468{
469 paravirt_ops.pte_update_defer(mm, addr, ptep);
470}
471
472#ifdef CONFIG_X86_PAE
473static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
474{
475 paravirt_ops.set_pte_atomic(ptep, pteval);
476}
477
478static inline void set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
479{
480 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
481}
482
483static inline void set_pud(pud_t *pudp, pud_t pudval)
484{
485 paravirt_ops.set_pud(pudp, pudval);
486}
487
488static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
489{
490 paravirt_ops.pte_clear(mm, addr, ptep);
491}
492
493static inline void pmd_clear(pmd_t *pmdp)
494{
495 paravirt_ops.pmd_clear(pmdp);
496}
497#endif
498
Zachary Amsden9226d122007-02-13 13:26:21 +0100499/* Lazy mode for batching updates / context switch */
500#define PARAVIRT_LAZY_NONE 0
501#define PARAVIRT_LAZY_MMU 1
502#define PARAVIRT_LAZY_CPU 2
Zachary Amsden49f19712007-04-08 16:04:01 -0700503#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +0100504
505#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
506#define arch_enter_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_CPU)
507#define arch_leave_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700508#define arch_flush_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100509
510#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
511#define arch_enter_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_MMU)
512#define arch_leave_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700513#define arch_flush_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100514
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200515void _paravirt_nop(void);
516#define paravirt_nop ((void *)_paravirt_nop)
517
Rusty Russell139ec7c2006-12-07 02:14:08 +0100518/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200519struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +0100520 u8 *instr; /* original instructions */
521 u8 instrtype; /* type of this instruction */
522 u8 len; /* length of original instruction */
523 u16 clobbers; /* what registers you may clobber */
524};
525
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200526extern struct paravirt_patch_site __parainstructions[],
527 __parainstructions_end[];
528
Rusty Russell139ec7c2006-12-07 02:14:08 +0100529static inline unsigned long __raw_local_save_flags(void)
530{
531 unsigned long f;
532
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200533 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
534 PARAVIRT_CALL
535 "popl %%edx; popl %%ecx")
536 : "=a"(f)
537 : paravirt_type(save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200538 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200539 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100540 return f;
541}
542
543static inline void raw_local_irq_restore(unsigned long f)
544{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200545 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
546 PARAVIRT_CALL
547 "popl %%edx; popl %%ecx")
548 : "=a"(f)
549 : "0"(f),
550 paravirt_type(restore_fl),
551 paravirt_clobber(CLBR_EAX)
552 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100553}
554
555static inline void raw_local_irq_disable(void)
556{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200557 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
558 PARAVIRT_CALL
559 "popl %%edx; popl %%ecx")
560 :
561 : paravirt_type(irq_disable),
562 paravirt_clobber(CLBR_EAX)
563 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100564}
565
566static inline void raw_local_irq_enable(void)
567{
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200568 asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;"
569 PARAVIRT_CALL
570 "popl %%edx; popl %%ecx")
571 :
572 : paravirt_type(irq_enable),
573 paravirt_clobber(CLBR_EAX)
574 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100575}
576
577static inline unsigned long __raw_local_irq_save(void)
578{
579 unsigned long f;
580
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200581 f = __raw_local_save_flags();
582 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +0100583 return f;
584}
585
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200586#define CLI_STRING \
587 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
588 "call *paravirt_ops+%c[paravirt_cli_type]*4;" \
589 "popl %%edx; popl %%ecx", \
590 "%c[paravirt_cli_type]", "%c[paravirt_clobber]")
Rusty Russell139ec7c2006-12-07 02:14:08 +0100591
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200592#define STI_STRING \
593 _paravirt_alt("pushl %%ecx; pushl %%edx;" \
594 "call *paravirt_ops+%c[paravirt_sti_type]*4;" \
595 "popl %%edx; popl %%ecx", \
596 "%c[paravirt_sti_type]", "%c[paravirt_clobber]")
597
Rusty Russell139ec7c2006-12-07 02:14:08 +0100598#define CLI_STI_CLOBBERS , "%eax"
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200599#define CLI_STI_INPUT_ARGS \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100600 , \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200601 [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \
602 [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \
603 paravirt_clobber(CLBR_EAX)
604
605#undef PARAVIRT_CALL
Rusty Russell139ec7c2006-12-07 02:14:08 +0100606
Rusty Russelld3561b72006-12-07 02:14:07 +0100607#else /* __ASSEMBLY__ */
608
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200609#define PARA_PATCH(off) ((off) / 4)
610
611#define PARA_SITE(ptype, clobbers, ops) \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100612771:; \
613 ops; \
614772:; \
615 .pushsection .parainstructions,"a"; \
616 .long 771b; \
617 .byte ptype; \
618 .byte 772b-771b; \
619 .short clobbers; \
620 .popsection
621
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200622#define INTERRUPT_RETURN \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200623 PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200624 jmp *%cs:paravirt_ops+PARAVIRT_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100625
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200626#define DISABLE_INTERRUPTS(clobbers) \
627 PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200628 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200629 call *%cs:paravirt_ops+PARAVIRT_irq_disable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200630 popl %edx; popl %ecx; popl %eax) \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100631
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200632#define ENABLE_INTERRUPTS(clobbers) \
633 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200634 pushl %eax; pushl %ecx; pushl %edx; \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200635 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200636 popl %edx; popl %ecx; popl %eax)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100637
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200638#define ENABLE_INTERRUPTS_SYSEXIT \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200639 PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200640 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100641
642#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200643 push %ecx; push %edx; \
644 call *paravirt_ops+PARAVIRT_read_cr0; \
645 pop %edx; pop %ecx
Rusty Russell139ec7c2006-12-07 02:14:08 +0100646
Rusty Russelld3561b72006-12-07 02:14:07 +0100647#endif /* __ASSEMBLY__ */
648#endif /* CONFIG_PARAVIRT */
649#endif /* __ASM_PARAVIRT_H */