1 #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. */
5 #include <linux/linkage.h>
10 struct Xgt_desc_struct;
14 unsigned int kernel_rpl;
18 void (*arch_setup)(void);
19 char *(*memory_setup)(void);
20 void (*init_IRQ)(void);
24 unsigned long (*get_wallclock)(void);
25 int (*set_wallclock)(unsigned long);
26 void (*time_init)(void);
28 /* All the function pointers here are declared as "fastcall"
29 so that we get a specific register-based calling
30 convention. This makes it easier to implement inline
31 assembler replacements. */
33 void (fastcall *cpuid)(unsigned int *eax, unsigned int *ebx,
34 unsigned int *ecx, unsigned int *edx);
36 unsigned long (fastcall *get_debugreg)(int regno);
37 void (fastcall *set_debugreg)(int regno, unsigned long value);
39 void (fastcall *clts)(void);
41 unsigned long (fastcall *read_cr0)(void);
42 void (fastcall *write_cr0)(unsigned long);
44 unsigned long (fastcall *read_cr2)(void);
45 void (fastcall *write_cr2)(unsigned long);
47 unsigned long (fastcall *read_cr3)(void);
48 void (fastcall *write_cr3)(unsigned long);
50 unsigned long (fastcall *read_cr4_safe)(void);
51 unsigned long (fastcall *read_cr4)(void);
52 void (fastcall *write_cr4)(unsigned long);
54 unsigned long (fastcall *save_fl)(void);
55 void (fastcall *restore_fl)(unsigned long);
56 void (fastcall *irq_disable)(void);
57 void (fastcall *irq_enable)(void);
58 void (fastcall *safe_halt)(void);
59 void (fastcall *halt)(void);
60 void (fastcall *wbinvd)(void);
62 /* err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
63 u64 (fastcall *read_msr)(unsigned int msr, int *err);
64 int (fastcall *write_msr)(unsigned int msr, u64 val);
66 u64 (fastcall *read_tsc)(void);
67 u64 (fastcall *read_pmc)(void);
69 void (fastcall *load_tr_desc)(void);
70 void (fastcall *load_gdt)(const struct Xgt_desc_struct *);
71 void (fastcall *load_idt)(const struct Xgt_desc_struct *);
72 void (fastcall *store_gdt)(struct Xgt_desc_struct *);
73 void (fastcall *store_idt)(struct Xgt_desc_struct *);
74 void (fastcall *set_ldt)(const void *desc, unsigned entries);
75 unsigned long (fastcall *store_tr)(void);
76 void (fastcall *load_tls)(struct thread_struct *t, unsigned int cpu);
77 void (fastcall *write_ldt_entry)(void *dt, int entrynum,
79 void (fastcall *write_gdt_entry)(void *dt, int entrynum,
81 void (fastcall *write_idt_entry)(void *dt, int entrynum,
83 void (fastcall *load_esp0)(struct tss_struct *tss,
84 struct thread_struct *thread);
86 void (fastcall *set_iopl_mask)(unsigned mask);
88 void (fastcall *io_delay)(void);
89 void (*const_udelay)(unsigned long loops);
91 /* These two are jmp to, not actually called. */
92 void (fastcall *irq_enable_sysexit)(void);
93 void (fastcall *iret)(void);
96 extern struct paravirt_ops paravirt_ops;
98 #define paravirt_enabled() (paravirt_ops.paravirt_enabled)
100 static inline void load_esp0(struct tss_struct *tss,
101 struct thread_struct *thread)
103 paravirt_ops.load_esp0(tss, thread);
106 #define ARCH_SETUP paravirt_ops.arch_setup();
107 static inline unsigned long get_wallclock(void)
109 return paravirt_ops.get_wallclock();
112 static inline int set_wallclock(unsigned long nowtime)
114 return paravirt_ops.set_wallclock(nowtime);
117 static inline void do_time_init(void)
119 return paravirt_ops.time_init();
122 /* The paravirtualized CPUID instruction. */
123 static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
124 unsigned int *ecx, unsigned int *edx)
126 paravirt_ops.cpuid(eax, ebx, ecx, edx);
130 * These special macros can be used to get or set a debugging register
132 #define get_debugreg(var, reg) var = paravirt_ops.get_debugreg(reg)
133 #define set_debugreg(val, reg) paravirt_ops.set_debugreg(reg, val)
135 #define clts() paravirt_ops.clts()
137 #define read_cr0() paravirt_ops.read_cr0()
138 #define write_cr0(x) paravirt_ops.write_cr0(x)
140 #define read_cr2() paravirt_ops.read_cr2()
141 #define write_cr2(x) paravirt_ops.write_cr2(x)
143 #define read_cr3() paravirt_ops.read_cr3()
144 #define write_cr3(x) paravirt_ops.write_cr3(x)
146 #define read_cr4() paravirt_ops.read_cr4()
147 #define read_cr4_safe(x) paravirt_ops.read_cr4_safe()
148 #define write_cr4(x) paravirt_ops.write_cr4(x)
150 static inline unsigned long __raw_local_save_flags(void)
152 return paravirt_ops.save_fl();
155 static inline void raw_local_irq_restore(unsigned long flags)
157 return paravirt_ops.restore_fl(flags);
160 static inline void raw_local_irq_disable(void)
162 paravirt_ops.irq_disable();
165 static inline void raw_local_irq_enable(void)
167 paravirt_ops.irq_enable();
170 static inline unsigned long __raw_local_irq_save(void)
172 unsigned long flags = paravirt_ops.save_fl();
174 paravirt_ops.irq_disable();
179 static inline void raw_safe_halt(void)
181 paravirt_ops.safe_halt();
184 static inline void halt(void)
186 paravirt_ops.safe_halt();
188 #define wbinvd() paravirt_ops.wbinvd()
190 #define get_kernel_rpl() (paravirt_ops.kernel_rpl)
192 #define rdmsr(msr,val1,val2) do { \
194 u64 _l = paravirt_ops.read_msr(msr,&_err); \
199 #define wrmsr(msr,val1,val2) do { \
200 u64 _l = ((u64)(val2) << 32) | (val1); \
201 paravirt_ops.write_msr((msr), _l); \
204 #define rdmsrl(msr,val) do { \
206 val = paravirt_ops.read_msr((msr),&_err); \
209 #define wrmsrl(msr,val) (paravirt_ops.write_msr((msr),(val)))
210 #define wrmsr_safe(msr,a,b) ({ \
211 u64 _l = ((u64)(b) << 32) | (a); \
212 paravirt_ops.write_msr((msr),_l); \
215 /* rdmsr with exception handling */
216 #define rdmsr_safe(msr,a,b) ({ \
218 u64 _l = paravirt_ops.read_msr(msr,&_err); \
223 #define rdtsc(low,high) do { \
224 u64 _l = paravirt_ops.read_tsc(); \
229 #define rdtscl(low) do { \
230 u64 _l = paravirt_ops.read_tsc(); \
234 #define rdtscll(val) (val = paravirt_ops.read_tsc())
236 #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
238 #define rdpmc(counter,low,high) do { \
239 u64 _l = paravirt_ops.read_pmc(); \
244 #define load_TR_desc() (paravirt_ops.load_tr_desc())
245 #define load_gdt(dtr) (paravirt_ops.load_gdt(dtr))
246 #define load_idt(dtr) (paravirt_ops.load_idt(dtr))
247 #define set_ldt(addr, entries) (paravirt_ops.set_ldt((addr), (entries)))
248 #define store_gdt(dtr) (paravirt_ops.store_gdt(dtr))
249 #define store_idt(dtr) (paravirt_ops.store_idt(dtr))
250 #define store_tr(tr) ((tr) = paravirt_ops.store_tr())
251 #define load_TLS(t,cpu) (paravirt_ops.load_tls((t),(cpu)))
252 #define write_ldt_entry(dt, entry, low, high) \
253 (paravirt_ops.write_ldt_entry((dt), (entry), (low), (high)))
254 #define write_gdt_entry(dt, entry, low, high) \
255 (paravirt_ops.write_gdt_entry((dt), (entry), (low), (high)))
256 #define write_idt_entry(dt, entry, low, high) \
257 (paravirt_ops.write_idt_entry((dt), (entry), (low), (high)))
258 #define set_iopl_mask(mask) (paravirt_ops.set_iopl_mask(mask))
260 /* The paravirtualized I/O functions */
261 static inline void slow_down_io(void) {
262 paravirt_ops.io_delay();
263 #ifdef REALLY_SLOW_IO
264 paravirt_ops.io_delay();
265 paravirt_ops.io_delay();
266 paravirt_ops.io_delay();
270 #define CLI_STRING "pushl %eax; pushl %ecx; pushl %edx; call *paravirt_ops+PARAVIRT_irq_disable; popl %edx; popl %ecx; popl %eax"
271 #define STI_STRING "pushl %eax; pushl %ecx; pushl %edx; call *paravirt_ops+PARAVIRT_irq_enable; popl %edx; popl %ecx; popl %eax"
272 #else /* __ASSEMBLY__ */
274 #define INTERRUPT_RETURN jmp *%cs:paravirt_ops+PARAVIRT_iret
275 #define DISABLE_INTERRUPTS pushl %eax; pushl %ecx; pushl %edx; call *paravirt_ops+PARAVIRT_irq_disable; popl %edx; popl %ecx; popl %eax
276 #define ENABLE_INTERRUPTS pushl %eax; pushl %ecx; pushl %edx; call *%cs:paravirt_ops+PARAVIRT_irq_enable; popl %edx; popl %ecx; popl %eax
277 #define ENABLE_INTERRUPTS_SYSEXIT jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit
278 #define GET_CR0_INTO_EAX call *paravirt_ops+PARAVIRT_read_cr0
279 #endif /* __ASSEMBLY__ */
280 #endif /* CONFIG_PARAVIRT */
281 #endif /* __ASM_PARAVIRT_H */