blob: 0aacb13bb9295ba95ea2ce831fd739063bcd66e0 [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. */
Rusty Russell139ec7c2006-12-07 02:14:08 +01005#include <linux/stringify.h>
Rusty Russellda181a82006-12-07 02:14:08 +01006#include <asm/page.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01007
8#ifdef CONFIG_PARAVIRT
Rusty Russell139ec7c2006-12-07 02:14:08 +01009/* These are the most performance critical ops, so we want to be able to patch
10 * callers */
11#define PARAVIRT_IRQ_DISABLE 0
12#define PARAVIRT_IRQ_ENABLE 1
13#define PARAVIRT_RESTORE_FLAGS 2
14#define PARAVIRT_SAVE_FLAGS 3
15#define PARAVIRT_SAVE_FLAGS_IRQ_DISABLE 4
16#define PARAVIRT_INTERRUPT_RETURN 5
17#define PARAVIRT_STI_SYSEXIT 6
18
19/* Bitmask of what can be clobbered: usually at least eax. */
20#define CLBR_NONE 0x0
21#define CLBR_EAX 0x1
22#define CLBR_ECX 0x2
23#define CLBR_EDX 0x4
24#define CLBR_ANY 0x7
25
Rusty Russelld3561b72006-12-07 02:14:07 +010026#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020027#include <linux/types.h>
28
Rusty Russelld3561b72006-12-07 02:14:07 +010029struct thread_struct;
30struct Xgt_desc_struct;
31struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010032struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020033struct desc_struct;
Rusty Russelld3561b72006-12-07 02:14:07 +010034struct paravirt_ops
35{
36 unsigned int kernel_rpl;
37 int paravirt_enabled;
38 const char *name;
39
Rusty Russell139ec7c2006-12-07 02:14:08 +010040 /*
41 * Patch may replace one of the defined code sequences with arbitrary
42 * code, subject to the same register constraints. This generally
43 * means the code is not free to clobber any registers other than EAX.
44 * The patch function should return the number of bytes of code
45 * generated, as we nop pad the rest in generic code.
46 */
47 unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len);
48
Rusty Russelld3561b72006-12-07 02:14:07 +010049 void (*arch_setup)(void);
50 char *(*memory_setup)(void);
51 void (*init_IRQ)(void);
52
53 void (*banner)(void);
54
55 unsigned long (*get_wallclock)(void);
56 int (*set_wallclock)(unsigned long);
57 void (*time_init)(void);
58
Andi Kleen1a1eecd2007-02-13 13:26:25 +010059 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
Rusty Russelld3561b72006-12-07 02:14:07 +010060 unsigned int *ecx, unsigned int *edx);
61
Andi Kleen1a1eecd2007-02-13 13:26:25 +010062 unsigned long (*get_debugreg)(int regno);
63 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010064
Andi Kleen1a1eecd2007-02-13 13:26:25 +010065 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010066
Andi Kleen1a1eecd2007-02-13 13:26:25 +010067 unsigned long (*read_cr0)(void);
68 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010069
Andi Kleen1a1eecd2007-02-13 13:26:25 +010070 unsigned long (*read_cr2)(void);
71 void (*write_cr2)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010072
Andi Kleen1a1eecd2007-02-13 13:26:25 +010073 unsigned long (*read_cr3)(void);
74 void (*write_cr3)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010075
Andi Kleen1a1eecd2007-02-13 13:26:25 +010076 unsigned long (*read_cr4_safe)(void);
77 unsigned long (*read_cr4)(void);
78 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010079
Andi Kleen1a1eecd2007-02-13 13:26:25 +010080 unsigned long (*save_fl)(void);
81 void (*restore_fl)(unsigned long);
82 void (*irq_disable)(void);
83 void (*irq_enable)(void);
84 void (*safe_halt)(void);
85 void (*halt)(void);
86 void (*wbinvd)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010087
88 /* err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010089 u64 (*read_msr)(unsigned int msr, int *err);
90 int (*write_msr)(unsigned int msr, u64 val);
Rusty Russelld3561b72006-12-07 02:14:07 +010091
Andi Kleen1a1eecd2007-02-13 13:26:25 +010092 u64 (*read_tsc)(void);
93 u64 (*read_pmc)(void);
Zachary Amsden6cb9a832007-03-05 00:30:35 -080094 u64 (*get_scheduled_cycles)(void);
Zachary Amsden1182d852007-03-05 00:30:36 -080095 unsigned long (*get_cpu_khz)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010096
Andi Kleen1a1eecd2007-02-13 13:26:25 +010097 void (*load_tr_desc)(void);
98 void (*load_gdt)(const struct Xgt_desc_struct *);
99 void (*load_idt)(const struct Xgt_desc_struct *);
100 void (*store_gdt)(struct Xgt_desc_struct *);
101 void (*store_idt)(struct Xgt_desc_struct *);
102 void (*set_ldt)(const void *desc, unsigned entries);
103 unsigned long (*store_tr)(void);
104 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Rusty Russell90a0a062007-05-02 19:27:10 +0200105 void (*write_ldt_entry)(struct desc_struct *,
106 int entrynum, u32 low, u32 high);
107 void (*write_gdt_entry)(struct desc_struct *,
108 int entrynum, u32 low, u32 high);
109 void (*write_idt_entry)(struct desc_struct *,
110 int entrynum, u32 low, u32 high);
111 void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100112
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100113 void (*set_iopl_mask)(unsigned mask);
Rusty Russelld3561b72006-12-07 02:14:07 +0100114
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100115 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100116
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
183#define paravirt_enabled() (paravirt_ops.paravirt_enabled)
184
185static inline void load_esp0(struct tss_struct *tss,
186 struct thread_struct *thread)
187{
188 paravirt_ops.load_esp0(tss, thread);
189}
190
191#define ARCH_SETUP paravirt_ops.arch_setup();
192static inline unsigned long get_wallclock(void)
193{
194 return paravirt_ops.get_wallclock();
195}
196
197static inline int set_wallclock(unsigned long nowtime)
198{
199 return paravirt_ops.set_wallclock(nowtime);
200}
201
Zachary Amsdene30fab32007-03-05 00:30:39 -0800202static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100203{
Zachary Amsdene30fab32007-03-05 00:30:39 -0800204 return paravirt_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100205}
206
207/* The paravirtualized CPUID instruction. */
208static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
209 unsigned int *ecx, unsigned int *edx)
210{
211 paravirt_ops.cpuid(eax, ebx, ecx, edx);
212}
213
214/*
215 * These special macros can be used to get or set a debugging register
216 */
217#define get_debugreg(var, reg) var = paravirt_ops.get_debugreg(reg)
218#define set_debugreg(val, reg) paravirt_ops.set_debugreg(reg, val)
219
220#define clts() paravirt_ops.clts()
221
222#define read_cr0() paravirt_ops.read_cr0()
223#define write_cr0(x) paravirt_ops.write_cr0(x)
224
225#define read_cr2() paravirt_ops.read_cr2()
226#define write_cr2(x) paravirt_ops.write_cr2(x)
227
228#define read_cr3() paravirt_ops.read_cr3()
229#define write_cr3(x) paravirt_ops.write_cr3(x)
230
231#define read_cr4() paravirt_ops.read_cr4()
232#define read_cr4_safe(x) paravirt_ops.read_cr4_safe()
233#define write_cr4(x) paravirt_ops.write_cr4(x)
234
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200235#define raw_ptep_get_and_clear(xp) (paravirt_ops.ptep_get_and_clear(xp))
236
Rusty Russelld3561b72006-12-07 02:14:07 +0100237static inline void raw_safe_halt(void)
238{
239 paravirt_ops.safe_halt();
240}
241
242static inline void halt(void)
243{
244 paravirt_ops.safe_halt();
245}
246#define wbinvd() paravirt_ops.wbinvd()
247
248#define get_kernel_rpl() (paravirt_ops.kernel_rpl)
249
Rusty Russell90a0a062007-05-02 19:27:10 +0200250/* These should all do BUG_ON(_err), but our headers are too tangled. */
Rusty Russelld3561b72006-12-07 02:14:07 +0100251#define rdmsr(msr,val1,val2) do { \
252 int _err; \
253 u64 _l = paravirt_ops.read_msr(msr,&_err); \
254 val1 = (u32)_l; \
255 val2 = _l >> 32; \
256} while(0)
257
258#define wrmsr(msr,val1,val2) do { \
259 u64 _l = ((u64)(val2) << 32) | (val1); \
260 paravirt_ops.write_msr((msr), _l); \
261} while(0)
262
263#define rdmsrl(msr,val) do { \
264 int _err; \
265 val = paravirt_ops.read_msr((msr),&_err); \
266} while(0)
267
268#define wrmsrl(msr,val) (paravirt_ops.write_msr((msr),(val)))
269#define wrmsr_safe(msr,a,b) ({ \
270 u64 _l = ((u64)(b) << 32) | (a); \
271 paravirt_ops.write_msr((msr),_l); \
272})
273
274/* rdmsr with exception handling */
275#define rdmsr_safe(msr,a,b) ({ \
276 int _err; \
277 u64 _l = paravirt_ops.read_msr(msr,&_err); \
278 (*a) = (u32)_l; \
279 (*b) = _l >> 32; \
280 _err; })
281
282#define rdtsc(low,high) do { \
283 u64 _l = paravirt_ops.read_tsc(); \
284 low = (u32)_l; \
285 high = _l >> 32; \
286} while(0)
287
288#define rdtscl(low) do { \
289 u64 _l = paravirt_ops.read_tsc(); \
290 low = (int)_l; \
291} while(0)
292
293#define rdtscll(val) (val = paravirt_ops.read_tsc())
294
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800295#define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles())
Zachary Amsden1182d852007-03-05 00:30:36 -0800296#define calculate_cpu_khz() (paravirt_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800297
Rusty Russelld3561b72006-12-07 02:14:07 +0100298#define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
299
300#define rdpmc(counter,low,high) do { \
301 u64 _l = paravirt_ops.read_pmc(); \
302 low = (u32)_l; \
303 high = _l >> 32; \
304} while(0)
305
306#define load_TR_desc() (paravirt_ops.load_tr_desc())
307#define load_gdt(dtr) (paravirt_ops.load_gdt(dtr))
308#define load_idt(dtr) (paravirt_ops.load_idt(dtr))
309#define set_ldt(addr, entries) (paravirt_ops.set_ldt((addr), (entries)))
310#define store_gdt(dtr) (paravirt_ops.store_gdt(dtr))
311#define store_idt(dtr) (paravirt_ops.store_idt(dtr))
312#define store_tr(tr) ((tr) = paravirt_ops.store_tr())
313#define load_TLS(t,cpu) (paravirt_ops.load_tls((t),(cpu)))
314#define write_ldt_entry(dt, entry, low, high) \
315 (paravirt_ops.write_ldt_entry((dt), (entry), (low), (high)))
316#define write_gdt_entry(dt, entry, low, high) \
317 (paravirt_ops.write_gdt_entry((dt), (entry), (low), (high)))
318#define write_idt_entry(dt, entry, low, high) \
319 (paravirt_ops.write_idt_entry((dt), (entry), (low), (high)))
320#define set_iopl_mask(mask) (paravirt_ops.set_iopl_mask(mask))
321
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200322#define __pte(x) paravirt_ops.make_pte(x)
323#define __pgd(x) paravirt_ops.make_pgd(x)
324
325#define pte_val(x) paravirt_ops.pte_val(x)
326#define pgd_val(x) paravirt_ops.pgd_val(x)
327
328#ifdef CONFIG_X86_PAE
329#define __pmd(x) paravirt_ops.make_pmd(x)
330#define pmd_val(x) paravirt_ops.pmd_val(x)
331#endif
332
Rusty Russelld3561b72006-12-07 02:14:07 +0100333/* The paravirtualized I/O functions */
334static inline void slow_down_io(void) {
335 paravirt_ops.io_delay();
336#ifdef REALLY_SLOW_IO
337 paravirt_ops.io_delay();
338 paravirt_ops.io_delay();
339 paravirt_ops.io_delay();
340#endif
341}
342
Rusty Russell13623d72006-12-07 02:14:08 +0100343#ifdef CONFIG_X86_LOCAL_APIC
344/*
345 * Basic functions accessing APICs.
346 */
347static inline void apic_write(unsigned long reg, unsigned long v)
348{
349 paravirt_ops.apic_write(reg,v);
350}
351
352static inline void apic_write_atomic(unsigned long reg, unsigned long v)
353{
354 paravirt_ops.apic_write_atomic(reg,v);
355}
356
357static inline unsigned long apic_read(unsigned long reg)
358{
359 return paravirt_ops.apic_read(reg);
360}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100361
362static inline void setup_boot_clock(void)
363{
364 paravirt_ops.setup_boot_clock();
365}
366
367static inline void setup_secondary_clock(void)
368{
369 paravirt_ops.setup_secondary_clock();
370}
Rusty Russell13623d72006-12-07 02:14:08 +0100371#endif
372
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200373
Zachary Amsdenae5da272007-02-13 13:26:21 +0100374#ifdef CONFIG_SMP
375static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
376 unsigned long start_esp)
377{
378 return paravirt_ops.startup_ipi_hook(phys_apicid, start_eip, start_esp);
379}
380#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100381
Rusty Russellda181a82006-12-07 02:14:08 +0100382#define __flush_tlb() paravirt_ops.flush_tlb_user()
383#define __flush_tlb_global() paravirt_ops.flush_tlb_kernel()
384#define __flush_tlb_single(addr) paravirt_ops.flush_tlb_single(addr)
385
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800386#define paravirt_map_pt_hook(type, va, pfn) paravirt_ops.map_pt_hook(type, va, pfn)
387
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100388#define paravirt_alloc_pt(pfn) paravirt_ops.alloc_pt(pfn)
389#define paravirt_release_pt(pfn) paravirt_ops.release_pt(pfn)
390
391#define paravirt_alloc_pd(pfn) paravirt_ops.alloc_pd(pfn)
392#define paravirt_alloc_pd_clone(pfn, clonepfn, start, count) \
393 paravirt_ops.alloc_pd_clone(pfn, clonepfn, start, count)
394#define paravirt_release_pd(pfn) paravirt_ops.release_pd(pfn)
395
Rusty Russellda181a82006-12-07 02:14:08 +0100396static inline void set_pte(pte_t *ptep, pte_t pteval)
397{
398 paravirt_ops.set_pte(ptep, pteval);
399}
400
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200401static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
402 pte_t *ptep, pte_t pteval)
Rusty Russellda181a82006-12-07 02:14:08 +0100403{
404 paravirt_ops.set_pte_at(mm, addr, ptep, pteval);
405}
406
407static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval)
408{
409 paravirt_ops.set_pmd(pmdp, pmdval);
410}
411
412static inline void pte_update(struct mm_struct *mm, u32 addr, pte_t *ptep)
413{
414 paravirt_ops.pte_update(mm, addr, ptep);
415}
416
417static inline void pte_update_defer(struct mm_struct *mm, u32 addr, pte_t *ptep)
418{
419 paravirt_ops.pte_update_defer(mm, addr, ptep);
420}
421
422#ifdef CONFIG_X86_PAE
423static inline void set_pte_atomic(pte_t *ptep, pte_t pteval)
424{
425 paravirt_ops.set_pte_atomic(ptep, pteval);
426}
427
428static inline void set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
429{
430 paravirt_ops.set_pte_present(mm, addr, ptep, pte);
431}
432
433static inline void set_pud(pud_t *pudp, pud_t pudval)
434{
435 paravirt_ops.set_pud(pudp, pudval);
436}
437
438static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
439{
440 paravirt_ops.pte_clear(mm, addr, ptep);
441}
442
443static inline void pmd_clear(pmd_t *pmdp)
444{
445 paravirt_ops.pmd_clear(pmdp);
446}
447#endif
448
Zachary Amsden9226d122007-02-13 13:26:21 +0100449/* Lazy mode for batching updates / context switch */
450#define PARAVIRT_LAZY_NONE 0
451#define PARAVIRT_LAZY_MMU 1
452#define PARAVIRT_LAZY_CPU 2
Zachary Amsden49f19712007-04-08 16:04:01 -0700453#define PARAVIRT_LAZY_FLUSH 3
Zachary Amsden9226d122007-02-13 13:26:21 +0100454
455#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
456#define arch_enter_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_CPU)
457#define arch_leave_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700458#define arch_flush_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100459
460#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
461#define arch_enter_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_MMU)
462#define arch_leave_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE)
Zachary Amsden49f19712007-04-08 16:04:01 -0700463#define arch_flush_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH)
Zachary Amsden9226d122007-02-13 13:26:21 +0100464
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200465void _paravirt_nop(void);
466#define paravirt_nop ((void *)_paravirt_nop)
467
Rusty Russell139ec7c2006-12-07 02:14:08 +0100468/* These all sit in the .parainstructions section to tell us what to patch. */
469struct paravirt_patch {
470 u8 *instr; /* original instructions */
471 u8 instrtype; /* type of this instruction */
472 u8 len; /* length of original instruction */
473 u16 clobbers; /* what registers you may clobber */
474};
475
476#define paravirt_alt(insn_string, typenum, clobber) \
477 "771:\n\t" insn_string "\n" "772:\n" \
478 ".pushsection .parainstructions,\"a\"\n" \
479 " .long 771b\n" \
480 " .byte " __stringify(typenum) "\n" \
481 " .byte 772b-771b\n" \
482 " .short " __stringify(clobber) "\n" \
483 ".popsection"
484
485static inline unsigned long __raw_local_save_flags(void)
486{
487 unsigned long f;
488
489 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
490 "call *%1;"
491 "popl %%edx; popl %%ecx",
492 PARAVIRT_SAVE_FLAGS, CLBR_NONE)
493 : "=a"(f): "m"(paravirt_ops.save_fl)
494 : "memory", "cc");
495 return f;
496}
497
498static inline void raw_local_irq_restore(unsigned long f)
499{
500 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
501 "call *%1;"
502 "popl %%edx; popl %%ecx",
503 PARAVIRT_RESTORE_FLAGS, CLBR_EAX)
504 : "=a"(f) : "m" (paravirt_ops.restore_fl), "0"(f)
505 : "memory", "cc");
506}
507
508static inline void raw_local_irq_disable(void)
509{
510 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
511 "call *%0;"
512 "popl %%edx; popl %%ecx",
513 PARAVIRT_IRQ_DISABLE, CLBR_EAX)
514 : : "m" (paravirt_ops.irq_disable)
515 : "memory", "eax", "cc");
516}
517
518static inline void raw_local_irq_enable(void)
519{
520 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
521 "call *%0;"
522 "popl %%edx; popl %%ecx",
523 PARAVIRT_IRQ_ENABLE, CLBR_EAX)
524 : : "m" (paravirt_ops.irq_enable)
525 : "memory", "eax", "cc");
526}
527
528static inline unsigned long __raw_local_irq_save(void)
529{
530 unsigned long f;
531
532 __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;"
533 "call *%1; pushl %%eax;"
534 "call *%2; popl %%eax;"
535 "popl %%edx; popl %%ecx",
536 PARAVIRT_SAVE_FLAGS_IRQ_DISABLE,
537 CLBR_NONE)
538 : "=a"(f)
539 : "m" (paravirt_ops.save_fl),
540 "m" (paravirt_ops.irq_disable)
541 : "memory", "cc");
542 return f;
543}
544
545#define CLI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \
546 "call *paravirt_ops+%c[irq_disable];" \
547 "popl %%edx; popl %%ecx", \
548 PARAVIRT_IRQ_DISABLE, CLBR_EAX)
549
550#define STI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \
551 "call *paravirt_ops+%c[irq_enable];" \
552 "popl %%edx; popl %%ecx", \
553 PARAVIRT_IRQ_ENABLE, CLBR_EAX)
554#define CLI_STI_CLOBBERS , "%eax"
555#define CLI_STI_INPUT_ARGS \
556 , \
557 [irq_disable] "i" (offsetof(struct paravirt_ops, irq_disable)), \
558 [irq_enable] "i" (offsetof(struct paravirt_ops, irq_enable))
559
Rusty Russelld3561b72006-12-07 02:14:07 +0100560#else /* __ASSEMBLY__ */
561
Rusty Russell139ec7c2006-12-07 02:14:08 +0100562#define PARA_PATCH(ptype, clobbers, ops) \
563771:; \
564 ops; \
565772:; \
566 .pushsection .parainstructions,"a"; \
567 .long 771b; \
568 .byte ptype; \
569 .byte 772b-771b; \
570 .short clobbers; \
571 .popsection
572
573#define INTERRUPT_RETURN \
574 PARA_PATCH(PARAVIRT_INTERRUPT_RETURN, CLBR_ANY, \
575 jmp *%cs:paravirt_ops+PARAVIRT_iret)
576
577#define DISABLE_INTERRUPTS(clobbers) \
578 PARA_PATCH(PARAVIRT_IRQ_DISABLE, clobbers, \
579 pushl %ecx; pushl %edx; \
580 call *paravirt_ops+PARAVIRT_irq_disable; \
581 popl %edx; popl %ecx) \
582
583#define ENABLE_INTERRUPTS(clobbers) \
584 PARA_PATCH(PARAVIRT_IRQ_ENABLE, clobbers, \
585 pushl %ecx; pushl %edx; \
586 call *%cs:paravirt_ops+PARAVIRT_irq_enable; \
587 popl %edx; popl %ecx)
588
589#define ENABLE_INTERRUPTS_SYSEXIT \
590 PARA_PATCH(PARAVIRT_STI_SYSEXIT, CLBR_ANY, \
591 jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit)
592
593#define GET_CR0_INTO_EAX \
594 call *paravirt_ops+PARAVIRT_read_cr0
595
Rusty Russelld3561b72006-12-07 02:14:07 +0100596#endif /* __ASSEMBLY__ */
597#endif /* CONFIG_PARAVIRT */
598#endif /* __ASM_PARAVIRT_H */