blob: f93599dc7756d1b1237ccf35cd31f1339267acf2 [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 Russell139ec7c2006-12-07 02:14:08 +01007#include <linux/stringify.h>
Rusty Russellda181a82006-12-07 02:14:08 +01008#include <asm/page.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01009
Rusty Russell139ec7c2006-12-07 02:14:08 +010010/* These are the most performance critical ops, so we want to be able to patch
11 * callers */
12#define PARAVIRT_IRQ_DISABLE 0
13#define PARAVIRT_IRQ_ENABLE 1
14#define PARAVIRT_RESTORE_FLAGS 2
15#define PARAVIRT_SAVE_FLAGS 3
16#define PARAVIRT_SAVE_FLAGS_IRQ_DISABLE 4
17#define PARAVIRT_INTERRUPT_RETURN 5
18#define PARAVIRT_STI_SYSEXIT 6
19
20/* Bitmask of what can be clobbered: usually at least eax. */
21#define CLBR_NONE 0x0
22#define CLBR_EAX 0x1
23#define CLBR_ECX 0x2
24#define CLBR_EDX 0x4
25#define CLBR_ANY 0x7
26
Rusty Russelld3561b72006-12-07 02:14:07 +010027#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020028#include <linux/types.h>
29
Rusty Russelld3561b72006-12-07 02:14:07 +010030struct thread_struct;
31struct Xgt_desc_struct;
32struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010033struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020034struct desc_struct;
Rusty Russelld3561b72006-12-07 02:14:07 +010035struct paravirt_ops
36{
37 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020038 int shared_kernel_pmd;
Rusty Russelld3561b72006-12-07 02:14:07 +010039 int paravirt_enabled;
40 const char *name;
41
Rusty Russell139ec7c2006-12-07 02:14:08 +010042 /*
43 * Patch may replace one of the defined code sequences with arbitrary
44 * code, subject to the same register constraints. This generally
45 * means the code is not free to clobber any registers other than EAX.
46 * The patch function should return the number of bytes of code
47 * generated, as we nop pad the rest in generic code.
48 */
49 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
50
Rusty Russelld3561b72006-12-07 02:14:07 +010051 void (*arch_setup)(void);
52 char *(*memory_setup)(void);
53 void (*init_IRQ)(void);
54
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +020055 void (*pagetable_setup_start)(pgd_t *pgd_base);
56 void (*pagetable_setup_done)(pgd_t *pgd_base);
57
Rusty Russelld3561b72006-12-07 02:14:07 +010058 void (*banner)(void);
59
60 unsigned long (*get_wallclock)(void);
61 int (*set_wallclock)(unsigned long);
62 void (*time_init)(void);
63
Andi Kleen1a1eecd2007-02-13 13:26:25 +010064 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010065 unsigned int *ecx, unsigned int *edx);
66
Andi Kleen1a1eecd2007-02-13 13:26:25 +010067 unsigned long (*get_debugreg)(int regno);
68 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010069
Andi Kleen1a1eecd2007-02-13 13:26:25 +010070 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010071
Andi Kleen1a1eecd2007-02-13 13:26:25 +010072 unsigned long (*read_cr0)(void);
73 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010074
Andi Kleen1a1eecd2007-02-13 13:26:25 +010075 unsigned long (*read_cr2)(void);
76 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010077
Andi Kleen1a1eecd2007-02-13 13:26:25 +010078 unsigned long (*read_cr3)(void);
79 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010080
Andi Kleen1a1eecd2007-02-13 13:26:25 +010081 unsigned long (*read_cr4_safe)(void);
82 unsigned long (*read_cr4)(void);
83 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010084
Andi Kleen1a1eecd2007-02-13 13:26:25 +010085 unsigned long (*save_fl)(void);
86 void (*restore_fl)(unsigned long);
87 void (*irq_disable)(void);
88 void (*irq_enable)(void);
89 void (*safe_halt)(void);
90 void (*halt)(void);
91 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010092
93 /* err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010094 u64 (*read_msr)(unsigned int msr, int *err);
95 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +010096
Andi Kleen1a1eecd2007-02-13 13:26:25 +010097 u64 (*read_tsc)(void);
98 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -080099 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -0800100 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100101
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100102 void (*load_tr_desc)(void);
103 void (*load_gdt)(const struct Xgt_desc_struct *);
104 void (*load_idt)(const struct Xgt_desc_struct *);
105 void (*store_gdt)(struct Xgt_desc_struct *);
106 void (*store_idt)(struct Xgt_desc_struct *);
107 void (*set_ldt)(const void *desc, unsigned entries);
108 unsigned long (*store_tr)(void);
109 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +0200110 void (*write_ldt_entry)(struct desc_struct *,
111 int entrynum, u32 low, u32 high);
112 void (*write_gdt_entry)(struct desc_struct *,
113 int entrynum, u32 low, u32 high);
114 void (*write_idt_entry)(struct desc_struct *,
115 int entrynum, u32 low, u32 high);
116 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100117
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100118 void (*set_iopl_mask)(unsigned mask);
Rusty Russelld3561b72006-12-07 02:14:07 +0100119
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100120 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100121
Rusty Russell13623d72006-12-07 02:14:08 +0100122#ifdef CONFIG_X86_LOCAL_APIC
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100123 void (*apic_write)(unsigned long reg, unsigned long v);
124 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
125 unsigned long (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100126 void (*setup_boot_clock)(void);
127 void (*setup_secondary_clock)(void);
Rusty Russell13623d72006-12-07 02:14:08 +0100128#endif
129
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100130 void (*flush_tlb_user)(void);
131 void (*flush_tlb_kernel)(void);
132 void (*flush_tlb_single)(u32 addr);
Rusty Russellda181a82006-12-07 02:14:08 +0100133
Al Viro192cd592007-03-14 09:18:09 +0000134 void (*map_pt_hook)(int type, pte_t *va, u32 pfn);
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800135
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100136 void (*alloc_pt)(u32 pfn);
137 void (*alloc_pd)(u32 pfn);
138 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
139 void (*release_pt)(u32 pfn);
140 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100141
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100142 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200143 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100144 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200145 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
146 void (*pte_update_defer)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
147
148 pte_t (*ptep_get_and_clear)(pte_t *ptep);
149
Rusty Russellda181a82006-12-07 02:14:08 +0100150#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100151 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200152 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100153 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200154 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100155 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200156
157 unsigned long long (*pte_val)(pte_t);
158 unsigned long long (*pmd_val)(pmd_t);
159 unsigned long long (*pgd_val)(pgd_t);
160
161 pte_t (*make_pte)(unsigned long long pte);
162 pmd_t (*make_pmd)(unsigned long long pmd);
163 pgd_t (*make_pgd)(unsigned long long pgd);
164#else
165 unsigned long (*pte_val)(pte_t);
166 unsigned long (*pgd_val)(pgd_t);
167
168 pte_t (*make_pte)(unsigned long pte);
169 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100170#endif
171
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100172 void (*set_lazy_mode)(int mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100173
Rusty Russelld3561b72006-12-07 02:14:07 +0100174 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100175 void (*irq_enable_sysexit)(void);
176 void (*iret)(void);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100177
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100178 void (*startup_ipi_hook)(int phys_apicid, unsigned long start_eip, unsigned long start_esp);
Rusty Russelld3561b72006-12-07 02:14:07 +0100179};
180
Rusty Russellc9ccf302006-12-07 02:14:08 +0100181/* Mark a paravirt probe function. */
182#define paravirt_probe(fn) \
183 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
184 __attribute__((__section__(".paravirtprobe"))) = fn
185
Rusty Russelld3561b72006-12-07 02:14:07 +0100186extern struct paravirt_ops paravirt_ops;
187
188#define paravirt_enabled() (paravirt_ops.paravirt_enabled)
189
190static inline void load_esp0(struct tss_struct *tss,
191 struct thread_struct *thread)
192{
193 paravirt_ops.load_esp0(tss, thread);
194}
195
196#define ARCH_SETUP paravirt_ops.arch_setup();
197static inline unsigned long get_wallclock(void)
198{
199 return paravirt_ops.get_wallclock();
200}
201
202static inline int set_wallclock(unsigned long nowtime)
203{
204 return paravirt_ops.set_wallclock(nowtime);
205}
206
Zachary Amsdene30fab32007-03-05 00:30:39 -0800207static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100208{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800209 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100210}
211
212/* The paravirtualized CPUID instruction. */
213static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
214 unsigned int *ecx, unsigned int *edx)
215{
216 paravirt_ops.cpuid(eax, ebx, ecx, edx);
217}
218
219/*
220 * These special macros can be used to get or set a debugging register
221 */
222#define get_debugreg(var, reg) var = paravirt_ops.get_debugreg(reg)
223#define set_debugreg(val, reg) paravirt_ops.set_debugreg(reg, val)
224
225#define clts() paravirt_ops.clts()
226
227#define read_cr0() paravirt_ops.read_cr0()
228#define write_cr0(x) paravirt_ops.write_cr0(x)
229
230#define read_cr2() paravirt_ops.read_cr2()
231#define write_cr2(x) paravirt_ops.write_cr2(x)
232
233#define read_cr3() paravirt_ops.read_cr3()
234#define write_cr3(x) paravirt_ops.write_cr3(x)
235
236#define read_cr4() paravirt_ops.read_cr4()
237#define read_cr4_safe(x) paravirt_ops.read_cr4_safe()
238#define write_cr4(x) paravirt_ops.write_cr4(x)
239
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200240#define raw_ptep_get_and_clear(xp) (paravirt_ops.ptep_get_and_clear(xp))
241
Rusty Russelld3561b72006-12-07 02:14:07 +0100242static inline void raw_safe_halt(void)
243{
244 paravirt_ops.safe_halt();
245}
246
247static inline void halt(void)
248{
249 paravirt_ops.safe_halt();
250}
251#define wbinvd() paravirt_ops.wbinvd()
252
253#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
254
Rusty Russell90a0a062007-05-02 19:27:10 +0200255/* These should all do BUG_ON(_err), but our headers are too tangled. */
Rusty Russelld3561b72006-12-07 02:14:07 +0100256#define rdmsr(msr,val1,val2) do { \
257 int _err; \
258 u64 _l = paravirt_ops.read_msr(msr,&_err); \
259 val1 = (u32)_l; \
260 val2 = _l >> 32; \
261} while(0)
262
263#define wrmsr(msr,val1,val2) do { \
264 u64 _l = ((u64)(val2) << 32) | (val1); \
265 paravirt_ops.write_msr((msr), _l); \
266} while(0)
267
268#define rdmsrl(msr,val) do { \
269 int _err; \
270 val = paravirt_ops.read_msr((msr),&_err); \
271} while(0)
272
273#define wrmsrl(msr,val) (paravirt_ops.write_msr((msr),(val)))
274#define wrmsr_safe(msr,a,b) ({ \
275 u64 _l = ((u64)(b) << 32) | (a); \
276 paravirt_ops.write_msr((msr),_l); \
277})
278
279/* rdmsr with exception handling */
280#define rdmsr_safe(msr,a,b) ({ \
281 int _err; \
282 u64 _l = paravirt_ops.read_msr(msr,&_err); \
283 (*a) = (u32)_l; \
284 (*b) = _l >> 32; \
285 _err; })
286
287#define rdtsc(low,high) do { \
288 u64 _l = paravirt_ops.read_tsc(); \
289 low = (u32)_l; \
290 high = _l >> 32; \
291} while(0)
292
293#define rdtscl(low) do { \
294 u64 _l = paravirt_ops.read_tsc(); \
295 low = (int)_l; \
296} while(0)
297
298#define rdtscll(val) (val = paravirt_ops.read_tsc())
299
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800300#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800301#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800302
Rusty Russelld3561b72006-12-07 02:14:07 +0100303#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
304
305#define rdpmc(counter,low,high) do { \
306 u64 _l = paravirt_ops.read_pmc(); \
307 low = (u32)_l; \
308 high = _l >> 32; \
309} while(0)
310
311#define load_TR_desc() (paravirt_ops.load_tr_desc())
312#define load_gdt(dtr) (paravirt_ops.load_gdt(dtr))
313#define load_idt(dtr) (paravirt_ops.load_idt(dtr))
314#define set_ldt(addr, entries) (paravirt_ops.set_ldt((addr), (entries)))
315#define store_gdt(dtr) (paravirt_ops.store_gdt(dtr))
316#define store_idt(dtr) (paravirt_ops.store_idt(dtr))
317#define store_tr(tr) ((tr) = paravirt_ops.store_tr())
318#define load_TLS(t,cpu) (paravirt_ops.load_tls((t),(cpu)))
319#define write_ldt_entry(dt, entry, low, high) \
320 (paravirt_ops.write_ldt_entry((dt), (entry), (low), (high)))
321#define write_gdt_entry(dt, entry, low, high) \
322 (paravirt_ops.write_gdt_entry((dt), (entry), (low), (high)))
323#define write_idt_entry(dt, entry, low, high) \
324 (paravirt_ops.write_idt_entry((dt), (entry), (low), (high)))
325#define set_iopl_mask(mask) (paravirt_ops.set_iopl_mask(mask))
326
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200327#define __pte(x) paravirt_ops.make_pte(x)
328#define __pgd(x) paravirt_ops.make_pgd(x)
329
330#define pte_val(x) paravirt_ops.pte_val(x)
331#define pgd_val(x) paravirt_ops.pgd_val(x)
332
333#ifdef CONFIG_X86_PAE
334#define __pmd(x) paravirt_ops.make_pmd(x)
335#define pmd_val(x) paravirt_ops.pmd_val(x)
336#endif
337
Rusty Russelld3561b72006-12-07 02:14:07 +0100338/* The paravirtualized I/O functions */
339static inline void slow_down_io(void) {
340 paravirt_ops.io_delay();
341#ifdef REALLY_SLOW_IO
342 paravirt_ops.io_delay();
343 paravirt_ops.io_delay();
344 paravirt_ops.io_delay();
345#endif
346}
347
Rusty Russell13623d72006-12-07 02:14:08 +0100348#ifdef CONFIG_X86_LOCAL_APIC
349/*
350 * Basic functions accessing APICs.
351 */
352static inline void apic_write(unsigned long reg, unsigned long v)
353{
354 paravirt_ops.apic_write(reg,v);
355}
356
357static inline void apic_write_atomic(unsigned long reg, unsigned long v)
358{
359 paravirt_ops.apic_write_atomic(reg,v);
360}
361
362static inline unsigned long apic_read(unsigned long reg)
363{
364 return paravirt_ops.apic_read(reg);
365}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100366
367static inline void setup_boot_clock(void)
368{
369 paravirt_ops.setup_boot_clock();
370}
371
372static inline void setup_secondary_clock(void)
373{
374 paravirt_ops.setup_secondary_clock();
375}
Rusty Russell13623d72006-12-07 02:14:08 +0100376#endif
377
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200378static inline void paravirt_pagetable_setup_start(pgd_t *base)
379{
380 if (paravirt_ops.pagetable_setup_start)
381 (*paravirt_ops.pagetable_setup_start)(base);
382}
383
384static inline void paravirt_pagetable_setup_done(pgd_t *base)
385{
386 if (paravirt_ops.pagetable_setup_done)
387 (*paravirt_ops.pagetable_setup_done)(base);
388}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200389
Zachary Amsdenae5da272007-02-13 13:26:21 +0100390#ifdef CONFIG_SMP
391static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
392 unsigned long start_esp)
393{
394 return paravirt_ops.startup_ipi_hook(phys_apicid, start_eip, start_esp);
395}
396#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100397
Rusty Russellda181a82006-12-07 02:14:08 +0100398#define __flush_tlb() paravirt_ops.flush_tlb_user()
399#define __flush_tlb_global() paravirt_ops.flush_tlb_kernel()
400#define __flush_tlb_single(addr) paravirt_ops.flush_tlb_single(addr)
401
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800402#define paravirt_map_pt_hook(type, va, pfn) paravirt_ops.map_pt_hook(type, va, pfn)
403
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100404#define paravirt_alloc_pt(pfn) paravirt_ops.alloc_pt(pfn)
405#define paravirt_release_pt(pfn) paravirt_ops.release_pt(pfn)
406
407#define paravirt_alloc_pd(pfn) paravirt_ops.alloc_pd(pfn)
408#define paravirt_alloc_pd_clone(pfn, clonepfn, start, count) \
409 paravirt_ops.alloc_pd_clone(pfn, clonepfn, start, count)
410#define paravirt_release_pd(pfn) paravirt_ops.release_pd(pfn)
411
Rusty Russellda181a82006-12-07 02:14:08 +0100412static inline void set_pte(pte_t *ptep, pte_t pteval)
413{
414 paravirt_ops.set_pte(ptep, pteval);
415}
416
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200417static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
418 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100419{
420 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
421}
422
423static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
424{
425 paravirt_ops.set_pmd(pmdp, pmdval);
426}
427
428static inline void pte_update(struct mm_struct *mm, u32 addr, pte_t *ptep)
429{
430 paravirt_ops.pte_update(mm, addr, ptep);
431}
432
433static inline void pte_update_defer(struct mm_struct *mm, u32 addr, pte_t *ptep)
434{
435 paravirt_ops.pte_update_defer(mm, addr, ptep);
436}
437
438#ifdef CONFIG_X86_PAE
439static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
440{
441 paravirt_ops.set_pte_atomic(ptep, pteval);
442}
443
444static inline void set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
445{
446 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
447}
448
449static inline void set_pud(pud_t *pudp, pud_t pudval)
450{
451 paravirt_ops.set_pud(pudp, pudval);
452}
453
454static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
455{
456 paravirt_ops.pte_clear(mm, addr, ptep);
457}
458
459static inline void pmd_clear(pmd_t *pmdp)
460{
461 paravirt_ops.pmd_clear(pmdp);
462}
463#endif
464
Zachary Amsden9226d122007-02-13 13:26:21 +0100465/* Lazy mode for batching updates / context switch */
466#define PARAVIRT_LAZY_NONE 0
467#define PARAVIRT_LAZY_MMU 1
468#define PARAVIRT_LAZY_CPU 2
Zachary Amsden49f19712007-04-08 16:04:01 -0700469#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +0100470
471#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
472#define arch_enter_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_CPU)
473#define arch_leave_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700474#define arch_flush_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100475
476#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
477#define arch_enter_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_MMU)
478#define arch_leave_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700479#define arch_flush_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100480
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200481void _paravirt_nop(void);
482#define paravirt_nop ((void *)_paravirt_nop)
483
Rusty Russell139ec7c2006-12-07 02:14:08 +0100484/* These all sit in the .parainstructions section to tell us what to patch. */
485struct paravirt_patch {
486 u8 *instr; /* original instructions */
487 u8 instrtype; /* type of this instruction */
488 u8 len; /* length of original instruction */
489 u16 clobbers; /* what registers you may clobber */
490};
491
492#define paravirt_alt(insn_string, typenum, clobber) \
493 "771:\n\t" insn_string "\n" "772:\n" \
494 ".pushsection .parainstructions,\"a\"\n" \
495 " .long 771b\n" \
496 " .byte " __stringify(typenum) "\n" \
497 " .byte 772b-771b\n" \
498 " .short " __stringify(clobber) "\n" \
499 ".popsection"
500
501static inline unsigned long __raw_local_save_flags(void)
502{
503 unsigned long f;
504
505 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
506 "call *%1;"
507 "popl %%edx; popl %%ecx",
508 PARAVIRT_SAVE_FLAGS, CLBR_NONE)
509 : "=a"(f): "m"(paravirt_ops.save_fl)
510 : "memory", "cc");
511 return f;
512}
513
514static inline void raw_local_irq_restore(unsigned long f)
515{
516 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
517 "call *%1;"
518 "popl %%edx; popl %%ecx",
519 PARAVIRT_RESTORE_FLAGS, CLBR_EAX)
520 : "=a"(f) : "m" (paravirt_ops.restore_fl), "0"(f)
521 : "memory", "cc");
522}
523
524static inline void raw_local_irq_disable(void)
525{
526 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
527 "call *%0;"
528 "popl %%edx; popl %%ecx",
529 PARAVIRT_IRQ_DISABLE, CLBR_EAX)
530 : : "m" (paravirt_ops.irq_disable)
531 : "memory", "eax", "cc");
532}
533
534static inline void raw_local_irq_enable(void)
535{
536 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
537 "call *%0;"
538 "popl %%edx; popl %%ecx",
539 PARAVIRT_IRQ_ENABLE, CLBR_EAX)
540 : : "m" (paravirt_ops.irq_enable)
541 : "memory", "eax", "cc");
542}
543
544static inline unsigned long __raw_local_irq_save(void)
545{
546 unsigned long f;
547
548 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
549 "call *%1; pushl %%eax;"
550 "call *%2; popl %%eax;"
551 "popl %%edx; popl %%ecx",
552 PARAVIRT_SAVE_FLAGS_IRQ_DISABLE,
553 CLBR_NONE)
554 : "=a"(f)
555 : "m" (paravirt_ops.save_fl),
556 "m" (paravirt_ops.irq_disable)
557 : "memory", "cc");
558 return f;
559}
560
561#define CLI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \
562 "call *paravirt_ops+%c[irq_disable];" \
563 "popl %%edx; popl %%ecx", \
564 PARAVIRT_IRQ_DISABLE, CLBR_EAX)
565
566#define STI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \
567 "call *paravirt_ops+%c[irq_enable];" \
568 "popl %%edx; popl %%ecx", \
569 PARAVIRT_IRQ_ENABLE, CLBR_EAX)
570#define CLI_STI_CLOBBERS , "%eax"
571#define CLI_STI_INPUT_ARGS \
572 , \
573 [irq_disable] "i" (offsetof(struct paravirt_ops, irq_disable)), \
574 [irq_enable] "i" (offsetof(struct paravirt_ops, irq_enable))
575
Rusty Russelld3561b72006-12-07 02:14:07 +0100576#else /* __ASSEMBLY__ */
577
Rusty Russell139ec7c2006-12-07 02:14:08 +0100578#define PARA_PATCH(ptype, clobbers, ops) \
579771:; \
580 ops; \
581772:; \
582 .pushsection .parainstructions,"a"; \
583 .long 771b; \
584 .byte ptype; \
585 .byte 772b-771b; \
586 .short clobbers; \
587 .popsection
588
589#define INTERRUPT_RETURN \
590 PARA_PATCH(PARAVIRT_INTERRUPT_RETURN, CLBR_ANY, \
591 jmp *%cs:paravirt_ops+PARAVIRT_iret)
592
593#define DISABLE_INTERRUPTS(clobbers) \
594 PARA_PATCH(PARAVIRT_IRQ_DISABLE, clobbers, \
595 pushl %ecx; pushl %edx; \
596 call *paravirt_ops+PARAVIRT_irq_disable; \
597 popl %edx; popl %ecx) \
598
599#define ENABLE_INTERRUPTS(clobbers) \
600 PARA_PATCH(PARAVIRT_IRQ_ENABLE, clobbers, \
601 pushl %ecx; pushl %edx; \
602 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
603 popl %edx; popl %ecx)
604
605#define ENABLE_INTERRUPTS_SYSEXIT \
606 PARA_PATCH(PARAVIRT_STI_SYSEXIT, CLBR_ANY, \
607 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
608
609#define GET_CR0_INTO_EAX \
610 call *paravirt_ops+PARAVIRT_read_cr0
611
Rusty Russelld3561b72006-12-07 02:14:07 +0100612#endif /* __ASSEMBLY__ */
613#endif /* CONFIG_PARAVIRT */
614#endif /* __ASM_PARAVIRT_H */