blob: b4cc2fc4031e259e67fece256da357289e83e653 [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
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200122 void (*activate_mm)(struct mm_struct *prev,
123 struct mm_struct *next);
124 void (*dup_mmap)(struct mm_struct *oldmm,
125 struct mm_struct *mm);
126 void (*exit_mmap)(struct mm_struct *mm);
127
Rusty Russell13623d72006-12-07 02:14:08 +0100128#ifdef CONFIG_X86_LOCAL_APIC
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100129 void (*apic_write)(unsigned long reg, unsigned long v);
130 void (*apic_write_atomic)(unsigned long reg, unsigned long v);
131 unsigned long (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100132 void (*setup_boot_clock)(void);
133 void (*setup_secondary_clock)(void);
Rusty Russell13623d72006-12-07 02:14:08 +0100134#endif
135
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100136 void (*flush_tlb_user)(void);
137 void (*flush_tlb_kernel)(void);
138 void (*flush_tlb_single)(u32 addr);
Rusty Russellda181a82006-12-07 02:14:08 +0100139
Al Viro192cd592007-03-14 09:18:09 +0000140 void (*map_pt_hook)(int type, pte_t *va, u32 pfn);
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800141
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100142 void (*alloc_pt)(u32 pfn);
143 void (*alloc_pd)(u32 pfn);
144 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
145 void (*release_pt)(u32 pfn);
146 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100147
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100148 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200149 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100150 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200151 void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
152 void (*pte_update_defer)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
153
154 pte_t (*ptep_get_and_clear)(pte_t *ptep);
155
Rusty Russellda181a82006-12-07 02:14:08 +0100156#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100157 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200158 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100159 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200160 void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100161 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200162
163 unsigned long long (*pte_val)(pte_t);
164 unsigned long long (*pmd_val)(pmd_t);
165 unsigned long long (*pgd_val)(pgd_t);
166
167 pte_t (*make_pte)(unsigned long long pte);
168 pmd_t (*make_pmd)(unsigned long long pmd);
169 pgd_t (*make_pgd)(unsigned long long pgd);
170#else
171 unsigned long (*pte_val)(pte_t);
172 unsigned long (*pgd_val)(pgd_t);
173
174 pte_t (*make_pte)(unsigned long pte);
175 pgd_t (*make_pgd)(unsigned long pgd);
Rusty Russellda181a82006-12-07 02:14:08 +0100176#endif
177
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100178 void (*set_lazy_mode)(int mode);
Zachary Amsden9226d122007-02-13 13:26:21 +0100179
Rusty Russelld3561b72006-12-07 02:14:07 +0100180 /* These two are jmp to, not actually called. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100181 void (*irq_enable_sysexit)(void);
182 void (*iret)(void);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100183
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100184 void (*startup_ipi_hook)(int phys_apicid, unsigned long start_eip, unsigned long start_esp);
Rusty Russelld3561b72006-12-07 02:14:07 +0100185};
186
Rusty Russellc9ccf302006-12-07 02:14:08 +0100187/* Mark a paravirt probe function. */
188#define paravirt_probe(fn) \
189 static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \
190 __attribute__((__section__(".paravirtprobe"))) = fn
191
Rusty Russelld3561b72006-12-07 02:14:07 +0100192extern struct paravirt_ops paravirt_ops;
193
194#define paravirt_enabled() (paravirt_ops.paravirt_enabled)
195
196static inline void load_esp0(struct tss_struct *tss,
197 struct thread_struct *thread)
198{
199 paravirt_ops.load_esp0(tss, thread);
200}
201
202#define ARCH_SETUP paravirt_ops.arch_setup();
203static inline unsigned long get_wallclock(void)
204{
205 return paravirt_ops.get_wallclock();
206}
207
208static inline int set_wallclock(unsigned long nowtime)
209{
210 return paravirt_ops.set_wallclock(nowtime);
211}
212
Zachary Amsdene30fab32007-03-05 00:30:39 -0800213static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100214{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800215 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100216}
217
218/* The paravirtualized CPUID instruction. */
219static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
220 unsigned int *ecx, unsigned int *edx)
221{
222 paravirt_ops.cpuid(eax, ebx, ecx, edx);
223}
224
225/*
226 * These special macros can be used to get or set a debugging register
227 */
228#define get_debugreg(var, reg) var = paravirt_ops.get_debugreg(reg)
229#define set_debugreg(val, reg) paravirt_ops.set_debugreg(reg, val)
230
231#define clts() paravirt_ops.clts()
232
233#define read_cr0() paravirt_ops.read_cr0()
234#define write_cr0(x) paravirt_ops.write_cr0(x)
235
236#define read_cr2() paravirt_ops.read_cr2()
237#define write_cr2(x) paravirt_ops.write_cr2(x)
238
239#define read_cr3() paravirt_ops.read_cr3()
240#define write_cr3(x) paravirt_ops.write_cr3(x)
241
242#define read_cr4() paravirt_ops.read_cr4()
243#define read_cr4_safe(x) paravirt_ops.read_cr4_safe()
244#define write_cr4(x) paravirt_ops.write_cr4(x)
245
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200246#define raw_ptep_get_and_clear(xp) (paravirt_ops.ptep_get_and_clear(xp))
247
Rusty Russelld3561b72006-12-07 02:14:07 +0100248static inline void raw_safe_halt(void)
249{
250 paravirt_ops.safe_halt();
251}
252
253static inline void halt(void)
254{
255 paravirt_ops.safe_halt();
256}
257#define wbinvd() paravirt_ops.wbinvd()
258
259#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
260
Rusty Russell90a0a062007-05-02 19:27:10 +0200261/* These should all do BUG_ON(_err), but our headers are too tangled. */
Rusty Russelld3561b72006-12-07 02:14:07 +0100262#define rdmsr(msr,val1,val2) do { \
263 int _err; \
264 u64 _l = paravirt_ops.read_msr(msr,&_err); \
265 val1 = (u32)_l; \
266 val2 = _l >> 32; \
267} while(0)
268
269#define wrmsr(msr,val1,val2) do { \
270 u64 _l = ((u64)(val2) << 32) | (val1); \
271 paravirt_ops.write_msr((msr), _l); \
272} while(0)
273
274#define rdmsrl(msr,val) do { \
275 int _err; \
276 val = paravirt_ops.read_msr((msr),&_err); \
277} while(0)
278
279#define wrmsrl(msr,val) (paravirt_ops.write_msr((msr),(val)))
280#define wrmsr_safe(msr,a,b) ({ \
281 u64 _l = ((u64)(b) << 32) | (a); \
282 paravirt_ops.write_msr((msr),_l); \
283})
284
285/* rdmsr with exception handling */
286#define rdmsr_safe(msr,a,b) ({ \
287 int _err; \
288 u64 _l = paravirt_ops.read_msr(msr,&_err); \
289 (*a) = (u32)_l; \
290 (*b) = _l >> 32; \
291 _err; })
292
293#define rdtsc(low,high) do { \
294 u64 _l = paravirt_ops.read_tsc(); \
295 low = (u32)_l; \
296 high = _l >> 32; \
297} while(0)
298
299#define rdtscl(low) do { \
300 u64 _l = paravirt_ops.read_tsc(); \
301 low = (int)_l; \
302} while(0)
303
304#define rdtscll(val) (val = paravirt_ops.read_tsc())
305
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800306#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800307#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800308
Rusty Russelld3561b72006-12-07 02:14:07 +0100309#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
310
311#define rdpmc(counter,low,high) do { \
312 u64 _l = paravirt_ops.read_pmc(); \
313 low = (u32)_l; \
314 high = _l >> 32; \
315} while(0)
316
317#define load_TR_desc() (paravirt_ops.load_tr_desc())
318#define load_gdt(dtr) (paravirt_ops.load_gdt(dtr))
319#define load_idt(dtr) (paravirt_ops.load_idt(dtr))
320#define set_ldt(addr, entries) (paravirt_ops.set_ldt((addr), (entries)))
321#define store_gdt(dtr) (paravirt_ops.store_gdt(dtr))
322#define store_idt(dtr) (paravirt_ops.store_idt(dtr))
323#define store_tr(tr) ((tr) = paravirt_ops.store_tr())
324#define load_TLS(t,cpu) (paravirt_ops.load_tls((t),(cpu)))
325#define write_ldt_entry(dt, entry, low, high) \
326 (paravirt_ops.write_ldt_entry((dt), (entry), (low), (high)))
327#define write_gdt_entry(dt, entry, low, high) \
328 (paravirt_ops.write_gdt_entry((dt), (entry), (low), (high)))
329#define write_idt_entry(dt, entry, low, high) \
330 (paravirt_ops.write_idt_entry((dt), (entry), (low), (high)))
331#define set_iopl_mask(mask) (paravirt_ops.set_iopl_mask(mask))
332
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200333#define __pte(x) paravirt_ops.make_pte(x)
334#define __pgd(x) paravirt_ops.make_pgd(x)
335
336#define pte_val(x) paravirt_ops.pte_val(x)
337#define pgd_val(x) paravirt_ops.pgd_val(x)
338
339#ifdef CONFIG_X86_PAE
340#define __pmd(x) paravirt_ops.make_pmd(x)
341#define pmd_val(x) paravirt_ops.pmd_val(x)
342#endif
343
Rusty Russelld3561b72006-12-07 02:14:07 +0100344/* The paravirtualized I/O functions */
345static inline void slow_down_io(void) {
346 paravirt_ops.io_delay();
347#ifdef REALLY_SLOW_IO
348 paravirt_ops.io_delay();
349 paravirt_ops.io_delay();
350 paravirt_ops.io_delay();
351#endif
352}
353
Rusty Russell13623d72006-12-07 02:14:08 +0100354#ifdef CONFIG_X86_LOCAL_APIC
355/*
356 * Basic functions accessing APICs.
357 */
358static inline void apic_write(unsigned long reg, unsigned long v)
359{
360 paravirt_ops.apic_write(reg,v);
361}
362
363static inline void apic_write_atomic(unsigned long reg, unsigned long v)
364{
365 paravirt_ops.apic_write_atomic(reg,v);
366}
367
368static inline unsigned long apic_read(unsigned long reg)
369{
370 return paravirt_ops.apic_read(reg);
371}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100372
373static inline void setup_boot_clock(void)
374{
375 paravirt_ops.setup_boot_clock();
376}
377
378static inline void setup_secondary_clock(void)
379{
380 paravirt_ops.setup_secondary_clock();
381}
Rusty Russell13623d72006-12-07 02:14:08 +0100382#endif
383
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200384static inline void paravirt_pagetable_setup_start(pgd_t *base)
385{
386 if (paravirt_ops.pagetable_setup_start)
387 (*paravirt_ops.pagetable_setup_start)(base);
388}
389
390static inline void paravirt_pagetable_setup_done(pgd_t *base)
391{
392 if (paravirt_ops.pagetable_setup_done)
393 (*paravirt_ops.pagetable_setup_done)(base);
394}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200395
Zachary Amsdenae5da272007-02-13 13:26:21 +0100396#ifdef CONFIG_SMP
397static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
398 unsigned long start_esp)
399{
400 return paravirt_ops.startup_ipi_hook(phys_apicid, start_eip, start_esp);
401}
402#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100403
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200404static inline void paravirt_activate_mm(struct mm_struct *prev,
405 struct mm_struct *next)
406{
407 paravirt_ops.activate_mm(prev, next);
408}
409
410static inline void arch_dup_mmap(struct mm_struct *oldmm,
411 struct mm_struct *mm)
412{
413 paravirt_ops.dup_mmap(oldmm, mm);
414}
415
416static inline void arch_exit_mmap(struct mm_struct *mm)
417{
418 paravirt_ops.exit_mmap(mm);
419}
420
Rusty Russellda181a82006-12-07 02:14:08 +0100421#define __flush_tlb() paravirt_ops.flush_tlb_user()
422#define __flush_tlb_global() paravirt_ops.flush_tlb_kernel()
423#define __flush_tlb_single(addr) paravirt_ops.flush_tlb_single(addr)
424
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800425#define paravirt_map_pt_hook(type, va, pfn) paravirt_ops.map_pt_hook(type, va, pfn)
426
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100427#define paravirt_alloc_pt(pfn) paravirt_ops.alloc_pt(pfn)
428#define paravirt_release_pt(pfn) paravirt_ops.release_pt(pfn)
429
430#define paravirt_alloc_pd(pfn) paravirt_ops.alloc_pd(pfn)
431#define paravirt_alloc_pd_clone(pfn, clonepfn, start, count) \
432 paravirt_ops.alloc_pd_clone(pfn, clonepfn, start, count)
433#define paravirt_release_pd(pfn) paravirt_ops.release_pd(pfn)
434
Rusty Russellda181a82006-12-07 02:14:08 +0100435static inline void set_pte(pte_t *ptep, pte_t pteval)
436{
437 paravirt_ops.set_pte(ptep, pteval);
438}
439
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200440static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
441 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100442{
443 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
444}
445
446static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
447{
448 paravirt_ops.set_pmd(pmdp, pmdval);
449}
450
451static inline void pte_update(struct mm_struct *mm, u32 addr, pte_t *ptep)
452{
453 paravirt_ops.pte_update(mm, addr, ptep);
454}
455
456static inline void pte_update_defer(struct mm_struct *mm, u32 addr, pte_t *ptep)
457{
458 paravirt_ops.pte_update_defer(mm, addr, ptep);
459}
460
461#ifdef CONFIG_X86_PAE
462static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
463{
464 paravirt_ops.set_pte_atomic(ptep, pteval);
465}
466
467static inline void set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
468{
469 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
470}
471
472static inline void set_pud(pud_t *pudp, pud_t pudval)
473{
474 paravirt_ops.set_pud(pudp, pudval);
475}
476
477static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
478{
479 paravirt_ops.pte_clear(mm, addr, ptep);
480}
481
482static inline void pmd_clear(pmd_t *pmdp)
483{
484 paravirt_ops.pmd_clear(pmdp);
485}
486#endif
487
Zachary Amsden9226d122007-02-13 13:26:21 +0100488/* Lazy mode for batching updates / context switch */
489#define PARAVIRT_LAZY_NONE 0
490#define PARAVIRT_LAZY_MMU 1
491#define PARAVIRT_LAZY_CPU 2
Zachary Amsden49f19712007-04-08 16:04:01 -0700492#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +0100493
494#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
495#define arch_enter_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_CPU)
496#define arch_leave_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700497#define arch_flush_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100498
499#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
500#define arch_enter_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_MMU)
501#define arch_leave_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700502#define arch_flush_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100503
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200504void _paravirt_nop(void);
505#define paravirt_nop ((void *)_paravirt_nop)
506
Rusty Russell139ec7c2006-12-07 02:14:08 +0100507/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200508struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +0100509 u8 *instr; /* original instructions */
510 u8 instrtype; /* type of this instruction */
511 u8 len; /* length of original instruction */
512 u16 clobbers; /* what registers you may clobber */
513};
514
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +0200515extern struct paravirt_patch_site __parainstructions[],
516 __parainstructions_end[];
517
Rusty Russell139ec7c2006-12-07 02:14:08 +0100518#define paravirt_alt(insn_string, typenum, clobber) \
519 "771:\n\t" insn_string "\n" "772:\n" \
520 ".pushsection .parainstructions,\"a\"\n" \
521 " .long 771b\n" \
522 " .byte " __stringify(typenum) "\n" \
523 " .byte 772b-771b\n" \
524 " .short " __stringify(clobber) "\n" \
525 ".popsection"
526
527static inline unsigned long __raw_local_save_flags(void)
528{
529 unsigned long f;
530
531 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
532 "call *%1;"
533 "popl %%edx; popl %%ecx",
534 PARAVIRT_SAVE_FLAGS, CLBR_NONE)
535 : "=a"(f): "m"(paravirt_ops.save_fl)
536 : "memory", "cc");
537 return f;
538}
539
540static inline void raw_local_irq_restore(unsigned long f)
541{
542 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
543 "call *%1;"
544 "popl %%edx; popl %%ecx",
545 PARAVIRT_RESTORE_FLAGS, CLBR_EAX)
546 : "=a"(f) : "m" (paravirt_ops.restore_fl), "0"(f)
547 : "memory", "cc");
548}
549
550static inline void raw_local_irq_disable(void)
551{
552 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
553 "call *%0;"
554 "popl %%edx; popl %%ecx",
555 PARAVIRT_IRQ_DISABLE, CLBR_EAX)
556 : : "m" (paravirt_ops.irq_disable)
557 : "memory", "eax", "cc");
558}
559
560static inline void raw_local_irq_enable(void)
561{
562 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
563 "call *%0;"
564 "popl %%edx; popl %%ecx",
565 PARAVIRT_IRQ_ENABLE, CLBR_EAX)
566 : : "m" (paravirt_ops.irq_enable)
567 : "memory", "eax", "cc");
568}
569
570static inline unsigned long __raw_local_irq_save(void)
571{
572 unsigned long f;
573
574 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
575 "call *%1; pushl %%eax;"
576 "call *%2; popl %%eax;"
577 "popl %%edx; popl %%ecx",
578 PARAVIRT_SAVE_FLAGS_IRQ_DISABLE,
579 CLBR_NONE)
580 : "=a"(f)
581 : "m" (paravirt_ops.save_fl),
582 "m" (paravirt_ops.irq_disable)
583 : "memory", "cc");
584 return f;
585}
586
587#define CLI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \
588 "call *paravirt_ops+%c[irq_disable];" \
589 "popl %%edx; popl %%ecx", \
590 PARAVIRT_IRQ_DISABLE, CLBR_EAX)
591
592#define STI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \
593 "call *paravirt_ops+%c[irq_enable];" \
594 "popl %%edx; popl %%ecx", \
595 PARAVIRT_IRQ_ENABLE, CLBR_EAX)
596#define CLI_STI_CLOBBERS , "%eax"
597#define CLI_STI_INPUT_ARGS \
598 , \
599 [irq_disable] "i" (offsetof(struct paravirt_ops, irq_disable)), \
600 [irq_enable] "i" (offsetof(struct paravirt_ops, irq_enable))
601
Rusty Russelld3561b72006-12-07 02:14:07 +0100602#else /* __ASSEMBLY__ */
603
Rusty Russell139ec7c2006-12-07 02:14:08 +0100604#define PARA_PATCH(ptype, clobbers, ops) \
605771:; \
606 ops; \
607772:; \
608 .pushsection .parainstructions,"a"; \
609 .long 771b; \
610 .byte ptype; \
611 .byte 772b-771b; \
612 .short clobbers; \
613 .popsection
614
615#define INTERRUPT_RETURN \
616 PARA_PATCH(PARAVIRT_INTERRUPT_RETURN, CLBR_ANY, \
617 jmp *%cs:paravirt_ops+PARAVIRT_iret)
618
619#define DISABLE_INTERRUPTS(clobbers) \
620 PARA_PATCH(PARAVIRT_IRQ_DISABLE, clobbers, \
621 pushl %ecx; pushl %edx; \
622 call *paravirt_ops+PARAVIRT_irq_disable; \
623 popl %edx; popl %ecx) \
624
625#define ENABLE_INTERRUPTS(clobbers) \
626 PARA_PATCH(PARAVIRT_IRQ_ENABLE, clobbers, \
627 pushl %ecx; pushl %edx; \
628 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
629 popl %edx; popl %ecx)
630
631#define ENABLE_INTERRUPTS_SYSEXIT \
632 PARA_PATCH(PARAVIRT_STI_SYSEXIT, CLBR_ANY, \
633 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
634
635#define GET_CR0_INTO_EAX \
636 call *paravirt_ops+PARAVIRT_read_cr0
637
Rusty Russelld3561b72006-12-07 02:14:07 +0100638#endif /* __ASSEMBLY__ */
639#endif /* CONFIG_PARAVIRT */
640#endif /* __ASM_PARAVIRT_H */