blob: a7d2db9a74fbc835dd7ed41ca2f7b5754b0263fe [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_PARAVIRT_H
2#define _ASM_X86_PARAVIRT_H
Rusty Russelld3561b72006-12-07 02:14:07 +01003/* 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
Jeremy Fitzhardinge54321d92009-02-11 10:20:05 -08007#include <asm/pgtable_types.h>
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01008#include <asm/asm.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01009
Jeremy Fitzhardingeac5672f2009-04-14 14:29:44 -070010#include <asm/paravirt_types.h>
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -080011
Rusty Russelld3561b72006-12-07 02:14:07 +010012#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020013#include <linux/types.h>
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +020014#include <linux/cpumask.h>
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +020015
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020016static inline int paravirt_enabled(void)
17{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070018 return pv_info.paravirt_enabled;
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020019}
Rusty Russelld3561b72006-12-07 02:14:07 +010020
H. Peter Anvinfaca6222008-01-30 13:31:02 +010021static inline void load_sp0(struct tss_struct *tss,
Rusty Russelld3561b72006-12-07 02:14:07 +010022 struct thread_struct *thread)
23{
H. Peter Anvinfaca6222008-01-30 13:31:02 +010024 PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +010025}
26
Rusty Russelld3561b72006-12-07 02:14:07 +010027/* The paravirtualized CPUID instruction. */
28static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
29 unsigned int *ecx, unsigned int *edx)
30{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070031 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +010032}
33
34/*
35 * These special macros can be used to get or set a debugging register
36 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020037static inline unsigned long paravirt_get_debugreg(int reg)
38{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070039 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020040}
41#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
42static inline void set_debugreg(unsigned long val, int reg)
43{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070044 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020045}
Rusty Russelld3561b72006-12-07 02:14:07 +010046
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020047static inline void clts(void)
48{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070049 PVOP_VCALL0(pv_cpu_ops.clts);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020050}
Rusty Russelld3561b72006-12-07 02:14:07 +010051
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020052static inline unsigned long read_cr0(void)
53{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070054 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020055}
Rusty Russelld3561b72006-12-07 02:14:07 +010056
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020057static inline void write_cr0(unsigned long x)
58{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070059 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020060}
Rusty Russelld3561b72006-12-07 02:14:07 +010061
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020062static inline unsigned long read_cr2(void)
63{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070064 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020065}
Rusty Russelld3561b72006-12-07 02:14:07 +010066
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020067static inline void write_cr2(unsigned long x)
68{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070069 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020070}
Rusty Russelld3561b72006-12-07 02:14:07 +010071
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020072static inline unsigned long read_cr3(void)
73{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070074 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020075}
76
77static inline void write_cr3(unsigned long x)
78{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070079 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020080}
81
82static inline unsigned long read_cr4(void)
83{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070084 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020085}
86static inline unsigned long read_cr4_safe(void)
87{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070088 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020089}
90
91static inline void write_cr4(unsigned long x)
92{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070093 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020094}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020095
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +010096#ifdef CONFIG_X86_64
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +010097static inline unsigned long read_cr8(void)
98{
99 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
100}
101
102static inline void write_cr8(unsigned long x)
103{
104 PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
105}
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100106#endif
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100107
David Howellsdf9ee292010-10-07 14:08:55 +0100108static inline void arch_safe_halt(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100109{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700110 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100111}
112
113static inline void halt(void)
114{
Cliff Wickmanc8217b82010-12-13 10:51:57 -0600115 PVOP_VCALL0(pv_irq_ops.halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100116}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200117
118static inline void wbinvd(void)
119{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700120 PVOP_VCALL0(pv_cpu_ops.wbinvd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200121}
Rusty Russelld3561b72006-12-07 02:14:07 +0100122
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700123#define get_kernel_rpl() (pv_info.kernel_rpl)
Rusty Russelld3561b72006-12-07 02:14:07 +0100124
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200125static inline u64 paravirt_read_msr(unsigned msr, int *err)
126{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700127 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200128}
Borislav Petkov132ec922009-08-31 09:50:09 +0200129
130static inline int paravirt_rdmsr_regs(u32 *regs)
131{
132 return PVOP_CALL1(int, pv_cpu_ops.rdmsr_regs, regs);
133}
134
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200135static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
136{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700137 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200138}
139
Borislav Petkov132ec922009-08-31 09:50:09 +0200140static inline int paravirt_wrmsr_regs(u32 *regs)
141{
142 return PVOP_CALL1(int, pv_cpu_ops.wrmsr_regs, regs);
143}
144
Rusty Russell90a0a062007-05-02 19:27:10 +0200145/* These should all do BUG_ON(_err), but our headers are too tangled. */
Joe Perches49cd7402008-03-23 01:03:00 -0700146#define rdmsr(msr, val1, val2) \
147do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200148 int _err; \
149 u64 _l = paravirt_read_msr(msr, &_err); \
150 val1 = (u32)_l; \
151 val2 = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700152} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100153
Joe Perches49cd7402008-03-23 01:03:00 -0700154#define wrmsr(msr, val1, val2) \
155do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200156 paravirt_write_msr(msr, val1, val2); \
Joe Perches49cd7402008-03-23 01:03:00 -0700157} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100158
Joe Perches49cd7402008-03-23 01:03:00 -0700159#define rdmsrl(msr, val) \
160do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200161 int _err; \
162 val = paravirt_read_msr(msr, &_err); \
Joe Perches49cd7402008-03-23 01:03:00 -0700163} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100164
Joe Perches49cd7402008-03-23 01:03:00 -0700165#define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
166#define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100167
168/* rdmsr with exception handling */
Joe Perches49cd7402008-03-23 01:03:00 -0700169#define rdmsr_safe(msr, a, b) \
170({ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200171 int _err; \
172 u64 _l = paravirt_read_msr(msr, &_err); \
173 (*a) = (u32)_l; \
174 (*b) = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700175 _err; \
176})
Rusty Russelld3561b72006-12-07 02:14:07 +0100177
Borislav Petkov132ec922009-08-31 09:50:09 +0200178#define rdmsr_safe_regs(regs) paravirt_rdmsr_regs(regs)
179#define wrmsr_safe_regs(regs) paravirt_wrmsr_regs(regs)
180
Andi Kleen1de87bd2008-03-22 10:59:28 +0100181static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
182{
183 int err;
184
185 *p = paravirt_read_msr(msr, &err);
186 return err;
187}
Yinghai Lub05f78f2008-08-22 01:32:50 -0700188static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
189{
Borislav Petkov177fed12009-08-31 09:50:10 +0200190 u32 gprs[8] = { 0 };
Yinghai Lub05f78f2008-08-22 01:32:50 -0700191 int err;
192
Borislav Petkov177fed12009-08-31 09:50:10 +0200193 gprs[1] = msr;
194 gprs[7] = 0x9c5a203a;
195
196 err = paravirt_rdmsr_regs(gprs);
197
198 *p = gprs[0] | ((u64)gprs[2] << 32);
199
Yinghai Lub05f78f2008-08-22 01:32:50 -0700200 return err;
201}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200202
Borislav Petkov177fed12009-08-31 09:50:10 +0200203static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val)
204{
205 u32 gprs[8] = { 0 };
206
207 gprs[0] = (u32)val;
208 gprs[1] = msr;
209 gprs[2] = val >> 32;
210 gprs[7] = 0x9c5a203a;
211
212 return paravirt_wrmsr_regs(gprs);
213}
214
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200215static inline u64 paravirt_read_tsc(void)
216{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700217 return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200218}
Rusty Russelld3561b72006-12-07 02:14:07 +0100219
Joe Perches49cd7402008-03-23 01:03:00 -0700220#define rdtscl(low) \
221do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200222 u64 _l = paravirt_read_tsc(); \
223 low = (int)_l; \
Joe Perches49cd7402008-03-23 01:03:00 -0700224} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100225
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200226#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100227
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700228static inline unsigned long long paravirt_sched_clock(void)
229{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700230 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700231}
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800232
Glauber Costa3c404b52011-07-11 15:28:15 -0400233struct jump_label_key;
234extern struct jump_label_key paravirt_steal_enabled;
235extern struct jump_label_key paravirt_steal_rq_enabled;
236
237static inline u64 paravirt_steal_clock(int cpu)
238{
239 return PVOP_CALL1(u64, pv_time_ops.steal_clock, cpu);
240}
241
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200242static inline unsigned long long paravirt_read_pmc(int counter)
243{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700244 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200245}
246
Joe Perches49cd7402008-03-23 01:03:00 -0700247#define rdpmc(counter, low, high) \
248do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200249 u64 _l = paravirt_read_pmc(counter); \
250 low = (u32)_l; \
251 high = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700252} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100253
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100254static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
255{
256 return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
257}
258
259#define rdtscp(low, high, aux) \
260do { \
261 int __aux; \
262 unsigned long __val = paravirt_rdtscp(&__aux); \
263 (low) = (u32)__val; \
264 (high) = (u32)(__val >> 32); \
265 (aux) = __aux; \
266} while (0)
267
268#define rdtscpll(val, aux) \
269do { \
270 unsigned long __aux; \
271 val = paravirt_rdtscp(&__aux); \
272 (aux) = __aux; \
273} while (0)
274
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700275static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
276{
277 PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
278}
279
280static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
281{
282 PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
283}
284
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200285static inline void load_TR_desc(void)
286{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700287 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200288}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100289static inline void load_gdt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200290{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700291 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200292}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100293static inline void load_idt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200294{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700295 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200296}
297static inline void set_ldt(const void *addr, unsigned entries)
298{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700299 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200300}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100301static inline void store_gdt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200302{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700303 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200304}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100305static inline void store_idt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200306{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700307 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200308}
309static inline unsigned long paravirt_store_tr(void)
310{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700311 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200312}
313#define store_tr(tr) ((tr) = paravirt_store_tr())
314static inline void load_TLS(struct thread_struct *t, unsigned cpu)
315{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700316 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200317}
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100318
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400319#ifdef CONFIG_X86_64
320static inline void load_gs_index(unsigned int gs)
321{
322 PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
323}
324#endif
325
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100326static inline void write_ldt_entry(struct desc_struct *dt, int entry,
327 const void *desc)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200328{
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100329 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200330}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100331
332static inline void write_gdt_entry(struct desc_struct *dt, int entry,
333 void *desc, int type)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200334{
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100335 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200336}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100337
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100338static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200339{
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100340 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200341}
342static inline void set_iopl_mask(unsigned mask)
343{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700344 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200345}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200346
Rusty Russelld3561b72006-12-07 02:14:07 +0100347/* The paravirtualized I/O functions */
Joe Perches49cd7402008-03-23 01:03:00 -0700348static inline void slow_down_io(void)
349{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700350 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100351#ifdef REALLY_SLOW_IO
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700352 pv_cpu_ops.io_delay();
353 pv_cpu_ops.io_delay();
354 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100355#endif
356}
357
Zachary Amsdenae5da272007-02-13 13:26:21 +0100358#ifdef CONFIG_SMP
359static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
360 unsigned long start_esp)
361{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700362 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
363 phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100364}
365#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100366
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200367static inline void paravirt_activate_mm(struct mm_struct *prev,
368 struct mm_struct *next)
369{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700370 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200371}
372
373static inline void arch_dup_mmap(struct mm_struct *oldmm,
374 struct mm_struct *mm)
375{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700376 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200377}
378
379static inline void arch_exit_mmap(struct mm_struct *mm)
380{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700381 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200382}
383
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200384static inline void __flush_tlb(void)
385{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700386 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200387}
388static inline void __flush_tlb_global(void)
389{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700390 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200391}
392static inline void __flush_tlb_single(unsigned long addr)
393{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700394 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200395}
Rusty Russellda181a82006-12-07 02:14:08 +0100396
Rusty Russell4595f962009-01-10 21:58:09 -0800397static inline void flush_tlb_others(const struct cpumask *cpumask,
398 struct mm_struct *mm,
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200399 unsigned long va)
400{
Rusty Russell4595f962009-01-10 21:58:09 -0800401 PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, cpumask, mm, va);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200402}
403
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -0400404static inline int paravirt_pgd_alloc(struct mm_struct *mm)
405{
406 return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
407}
408
409static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
410{
411 PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
412}
413
Eduardo Habkostf8639932008-07-30 18:32:27 -0300414static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200415{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700416 PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200417}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300418static inline void paravirt_release_pte(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200419{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700420 PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200421}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100422
Eduardo Habkostf8639932008-07-30 18:32:27 -0300423static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200424{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700425 PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200426}
427
Eduardo Habkostf8639932008-07-30 18:32:27 -0300428static inline void paravirt_release_pmd(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200429{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700430 PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200431}
432
Eduardo Habkostf8639932008-07-30 18:32:27 -0300433static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700434{
435 PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
436}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300437static inline void paravirt_release_pud(unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700438{
439 PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
440}
441
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200442static inline void pte_update(struct mm_struct *mm, unsigned long addr,
443 pte_t *ptep)
444{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700445 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200446}
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800447static inline void pmd_update(struct mm_struct *mm, unsigned long addr,
448 pmd_t *pmdp)
449{
450 PVOP_VCALL3(pv_mmu_ops.pmd_update, mm, addr, pmdp);
451}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200452
453static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
454 pte_t *ptep)
455{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700456 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200457}
458
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800459static inline void pmd_update_defer(struct mm_struct *mm, unsigned long addr,
460 pmd_t *pmdp)
461{
462 PVOP_VCALL3(pv_mmu_ops.pmd_update_defer, mm, addr, pmdp);
463}
464
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100465static inline pte_t __pte(pteval_t val)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200466{
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100467 pteval_t ret;
468
469 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800470 ret = PVOP_CALLEE2(pteval_t,
471 pv_mmu_ops.make_pte,
472 val, (u64)val >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100473 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800474 ret = PVOP_CALLEE1(pteval_t,
475 pv_mmu_ops.make_pte,
476 val);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100477
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100478 return (pte_t) { .pte = ret };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200479}
480
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100481static inline pteval_t pte_val(pte_t pte)
482{
483 pteval_t ret;
484
485 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800486 ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
487 pte.pte, (u64)pte.pte >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100488 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800489 ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
490 pte.pte);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100491
492 return ret;
493}
494
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100495static inline pgd_t __pgd(pgdval_t val)
496{
497 pgdval_t ret;
498
499 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800500 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
501 val, (u64)val >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100502 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800503 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
504 val);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100505
506 return (pgd_t) { ret };
507}
508
509static inline pgdval_t pgd_val(pgd_t pgd)
510{
511 pgdval_t ret;
512
513 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800514 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
515 pgd.pgd, (u64)pgd.pgd >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100516 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800517 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
518 pgd.pgd);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100519
520 return ret;
521}
522
Jeremy Fitzhardinge08b882c2008-06-16 04:30:01 -0700523#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
524static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
525 pte_t *ptep)
526{
527 pteval_t ret;
528
529 ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
530 mm, addr, ptep);
531
532 return (pte_t) { .pte = ret };
533}
534
535static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
536 pte_t *ptep, pte_t pte)
537{
538 if (sizeof(pteval_t) > sizeof(long))
539 /* 5 arg words */
540 pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
541 else
542 PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
543 mm, addr, ptep, pte.pte);
544}
545
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100546static inline void set_pte(pte_t *ptep, pte_t pte)
547{
548 if (sizeof(pteval_t) > sizeof(long))
549 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
550 pte.pte, (u64)pte.pte >> 32);
551 else
552 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
553 pte.pte);
554}
555
556static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
557 pte_t *ptep, pte_t pte)
558{
559 if (sizeof(pteval_t) > sizeof(long))
560 /* 5 arg words */
561 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
562 else
563 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
564}
565
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800566#ifdef CONFIG_TRANSPARENT_HUGEPAGE
567static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
568 pmd_t *pmdp, pmd_t pmd)
569{
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800570 if (sizeof(pmdval_t) > sizeof(long))
571 /* 5 arg words */
572 pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd);
573 else
Andrea Arcangelicacf0612011-01-25 15:07:09 -0800574 PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp,
575 native_pmd_val(pmd));
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800576}
577#endif
578
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100579static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
580{
581 pmdval_t val = native_pmd_val(pmd);
582
583 if (sizeof(pmdval_t) > sizeof(long))
584 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
585 else
586 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
587}
588
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100589#if PAGETABLE_LEVELS >= 3
590static inline pmd_t __pmd(pmdval_t val)
591{
592 pmdval_t ret;
593
594 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800595 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
596 val, (u64)val >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100597 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800598 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
599 val);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100600
601 return (pmd_t) { ret };
602}
603
604static inline pmdval_t pmd_val(pmd_t pmd)
605{
606 pmdval_t ret;
607
608 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800609 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
610 pmd.pmd, (u64)pmd.pmd >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100611 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800612 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
613 pmd.pmd);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100614
615 return ret;
616}
617
618static inline void set_pud(pud_t *pudp, pud_t pud)
619{
620 pudval_t val = native_pud_val(pud);
621
622 if (sizeof(pudval_t) > sizeof(long))
623 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
624 val, (u64)val >> 32);
625 else
626 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
627 val);
628}
Eduardo Habkost90422192008-01-30 13:33:20 +0100629#if PAGETABLE_LEVELS == 4
630static inline pud_t __pud(pudval_t val)
631{
632 pudval_t ret;
633
634 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800635 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
636 val, (u64)val >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100637 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800638 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
639 val);
Eduardo Habkost90422192008-01-30 13:33:20 +0100640
641 return (pud_t) { ret };
642}
643
644static inline pudval_t pud_val(pud_t pud)
645{
646 pudval_t ret;
647
648 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800649 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
650 pud.pud, (u64)pud.pud >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100651 else
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800652 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
653 pud.pud);
Eduardo Habkost90422192008-01-30 13:33:20 +0100654
655 return ret;
656}
657
658static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
659{
660 pgdval_t val = native_pgd_val(pgd);
661
662 if (sizeof(pgdval_t) > sizeof(long))
663 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
664 val, (u64)val >> 32);
665 else
666 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
667 val);
668}
669
670static inline void pgd_clear(pgd_t *pgdp)
671{
672 set_pgd(pgdp, __pgd(0));
673}
674
675static inline void pud_clear(pud_t *pudp)
676{
677 set_pud(pudp, __pud(0));
678}
679
680#endif /* PAGETABLE_LEVELS == 4 */
681
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100682#endif /* PAGETABLE_LEVELS >= 3 */
683
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100684#ifdef CONFIG_X86_PAE
685/* Special-case pte-setting operations for PAE, which can't update a
686 64-bit pte atomically */
687static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
688{
689 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
690 pte.pte, pte.pte >> 32);
691}
692
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100693static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
694 pte_t *ptep)
695{
696 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
697}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100698
699static inline void pmd_clear(pmd_t *pmdp)
700{
701 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
702}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100703#else /* !CONFIG_X86_PAE */
704static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
705{
706 set_pte(ptep, pte);
707}
708
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100709static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
710 pte_t *ptep)
711{
712 set_pte_at(mm, addr, ptep, __pte(0));
713}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100714
715static inline void pmd_clear(pmd_t *pmdp)
716{
717 set_pmd(pmdp, __pmd(0));
718}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100719#endif /* CONFIG_X86_PAE */
720
Jeremy Fitzhardinge7fd7d832009-02-17 23:24:03 -0800721#define __HAVE_ARCH_START_CONTEXT_SWITCH
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800722static inline void arch_start_context_switch(struct task_struct *prev)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200723{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800724 PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200725}
726
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800727static inline void arch_end_context_switch(struct task_struct *next)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200728{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800729 PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200730}
731
Zachary Amsden9226d122007-02-13 13:26:21 +0100732#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200733static inline void arch_enter_lazy_mmu_mode(void)
734{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700735 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200736}
737
738static inline void arch_leave_lazy_mmu_mode(void)
739{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700740 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200741}
742
Jeremy Fitzhardinged85cf932009-02-12 10:02:56 -0800743void arch_flush_lazy_mmu_mode(void);
Zachary Amsden9226d122007-02-13 13:26:21 +0100744
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700745static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
Masami Hiramatsu3b3809a2009-04-09 10:55:33 -0700746 phys_addr_t phys, pgprot_t flags)
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700747{
748 pv_mmu_ops.set_fixmap(idx, phys, flags);
749}
750
Jeremy Fitzhardingeb4ecc122009-05-13 17:16:55 -0700751#if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200752
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100753static inline int arch_spin_is_locked(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700754{
755 return PVOP_CALL1(int, pv_lock_ops.spin_is_locked, lock);
756}
757
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100758static inline int arch_spin_is_contended(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700759{
760 return PVOP_CALL1(int, pv_lock_ops.spin_is_contended, lock);
761}
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100762#define arch_spin_is_contended arch_spin_is_contended
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700763
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100764static __always_inline void arch_spin_lock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700765{
Harvey Harrison32172562008-07-17 14:22:34 -0700766 PVOP_VCALL1(pv_lock_ops.spin_lock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700767}
768
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100769static __always_inline void arch_spin_lock_flags(struct arch_spinlock *lock,
Jeremy Fitzhardinge63d3a752008-08-19 13:19:36 -0700770 unsigned long flags)
771{
772 PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags);
773}
774
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100775static __always_inline int arch_spin_trylock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700776{
777 return PVOP_CALL1(int, pv_lock_ops.spin_trylock, lock);
778}
779
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100780static __always_inline void arch_spin_unlock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700781{
Harvey Harrison32172562008-07-17 14:22:34 -0700782 PVOP_VCALL1(pv_lock_ops.spin_unlock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700783}
784
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200785#endif
786
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100787#ifdef CONFIG_X86_32
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800788#define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
789#define PV_RESTORE_REGS "popl %edx; popl %ecx;"
790
791/* save and restore all caller-save registers, except return value */
Jeremy Fitzhardingee584f552009-01-30 23:17:23 -0800792#define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
793#define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800794
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100795#define PV_FLAGS_ARG "0"
796#define PV_EXTRA_CLOBBERS
797#define PV_VEXTRA_CLOBBERS
798#else
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800799/* save and restore all caller-save registers, except return value */
800#define PV_SAVE_ALL_CALLER_REGS \
801 "push %rcx;" \
802 "push %rdx;" \
803 "push %rsi;" \
804 "push %rdi;" \
805 "push %r8;" \
806 "push %r9;" \
807 "push %r10;" \
808 "push %r11;"
809#define PV_RESTORE_ALL_CALLER_REGS \
810 "pop %r11;" \
811 "pop %r10;" \
812 "pop %r9;" \
813 "pop %r8;" \
814 "pop %rdi;" \
815 "pop %rsi;" \
816 "pop %rdx;" \
817 "pop %rcx;"
818
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100819/* We save some registers, but all of them, that's too much. We clobber all
820 * caller saved registers but the argument parameter */
821#define PV_SAVE_REGS "pushq %%rdi;"
822#define PV_RESTORE_REGS "popq %%rdi;"
Jeremy Fitzhardingec24481e2008-07-08 15:07:12 -0700823#define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
824#define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100825#define PV_FLAGS_ARG "D"
826#endif
827
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800828/*
829 * Generate a thunk around a function which saves all caller-save
830 * registers except for the return value. This allows C functions to
831 * be called from assembler code where fewer than normal registers are
832 * available. It may also help code generation around calls from C
833 * code if the common case doesn't use many registers.
834 *
835 * When a callee is wrapped in a thunk, the caller can assume that all
836 * arg regs and all scratch registers are preserved across the
837 * call. The return value in rax/eax will not be saved, even for void
838 * functions.
839 */
840#define PV_CALLEE_SAVE_REGS_THUNK(func) \
841 extern typeof(func) __raw_callee_save_##func; \
842 static void *__##func##__ __used = func; \
843 \
844 asm(".pushsection .text;" \
845 "__raw_callee_save_" #func ": " \
846 PV_SAVE_ALL_CALLER_REGS \
847 "call " #func ";" \
848 PV_RESTORE_ALL_CALLER_REGS \
849 "ret;" \
850 ".popsection")
851
852/* Get a reference to a callee-save function */
853#define PV_CALLEE_SAVE(func) \
854 ((struct paravirt_callee_save) { __raw_callee_save_##func })
855
856/* Promise that "func" already uses the right calling convention */
857#define __PV_IS_CALLEE_SAVE(func) \
858 ((struct paravirt_callee_save) { func })
859
Steven Rostedtb5908542010-11-10 22:29:49 -0500860static inline notrace unsigned long arch_local_save_flags(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100861{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700862 return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100863}
864
Steven Rostedtb5908542010-11-10 22:29:49 -0500865static inline notrace void arch_local_irq_restore(unsigned long f)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100866{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700867 PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100868}
869
Steven Rostedtb5908542010-11-10 22:29:49 -0500870static inline notrace void arch_local_irq_disable(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100871{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700872 PVOP_VCALLEE0(pv_irq_ops.irq_disable);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100873}
874
Steven Rostedtb5908542010-11-10 22:29:49 -0500875static inline notrace void arch_local_irq_enable(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100876{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700877 PVOP_VCALLEE0(pv_irq_ops.irq_enable);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100878}
879
Steven Rostedtb5908542010-11-10 22:29:49 -0500880static inline notrace unsigned long arch_local_irq_save(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100881{
882 unsigned long f;
883
David Howellsdf9ee292010-10-07 14:08:55 +0100884 f = arch_local_save_flags();
885 arch_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +0100886 return f;
887}
888
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700889
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200890/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200891#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200892#undef __PVOP_CALL
893#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200894#undef PVOP_VCALL0
895#undef PVOP_CALL0
896#undef PVOP_VCALL1
897#undef PVOP_CALL1
898#undef PVOP_VCALL2
899#undef PVOP_CALL2
900#undef PVOP_VCALL3
901#undef PVOP_CALL3
902#undef PVOP_VCALL4
903#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100904
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +0200905extern void default_banner(void);
906
Rusty Russelld3561b72006-12-07 02:14:07 +0100907#else /* __ASSEMBLY__ */
908
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100909#define _PVSITE(ptype, clobbers, ops, word, algn) \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100910771:; \
911 ops; \
912772:; \
913 .pushsection .parainstructions,"a"; \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100914 .align algn; \
915 word 771b; \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100916 .byte ptype; \
917 .byte 772b-771b; \
918 .short clobbers; \
919 .popsection
920
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100921
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800922#define COND_PUSH(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800923 .if ((~(set)) & mask); push %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800924#define COND_POP(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800925 .if ((~(set)) & mask); pop %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800926
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100927#ifdef CONFIG_X86_64
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800928
929#define PV_SAVE_REGS(set) \
930 COND_PUSH(set, CLBR_RAX, rax); \
931 COND_PUSH(set, CLBR_RCX, rcx); \
932 COND_PUSH(set, CLBR_RDX, rdx); \
933 COND_PUSH(set, CLBR_RSI, rsi); \
934 COND_PUSH(set, CLBR_RDI, rdi); \
935 COND_PUSH(set, CLBR_R8, r8); \
936 COND_PUSH(set, CLBR_R9, r9); \
937 COND_PUSH(set, CLBR_R10, r10); \
938 COND_PUSH(set, CLBR_R11, r11)
939#define PV_RESTORE_REGS(set) \
940 COND_POP(set, CLBR_R11, r11); \
941 COND_POP(set, CLBR_R10, r10); \
942 COND_POP(set, CLBR_R9, r9); \
943 COND_POP(set, CLBR_R8, r8); \
944 COND_POP(set, CLBR_RDI, rdi); \
945 COND_POP(set, CLBR_RSI, rsi); \
946 COND_POP(set, CLBR_RDX, rdx); \
947 COND_POP(set, CLBR_RCX, rcx); \
948 COND_POP(set, CLBR_RAX, rax)
949
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100950#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100951#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400952#define PARA_INDIRECT(addr) *addr(%rip)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100953#else
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800954#define PV_SAVE_REGS(set) \
955 COND_PUSH(set, CLBR_EAX, eax); \
956 COND_PUSH(set, CLBR_EDI, edi); \
957 COND_PUSH(set, CLBR_ECX, ecx); \
958 COND_PUSH(set, CLBR_EDX, edx)
959#define PV_RESTORE_REGS(set) \
960 COND_POP(set, CLBR_EDX, edx); \
961 COND_POP(set, CLBR_ECX, ecx); \
962 COND_POP(set, CLBR_EDI, edi); \
963 COND_POP(set, CLBR_EAX, eax)
964
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100965#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100966#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400967#define PARA_INDIRECT(addr) *%cs:addr
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100968#endif
969
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700970#define INTERRUPT_RETURN \
971 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400972 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
Rusty Russell139ec7c2006-12-07 02:14:08 +0100973
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200974#define DISABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700975 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800976 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400977 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800978 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100979
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200980#define ENABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700981 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800982 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400983 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800984 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100985
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400986#define USERGS_SYSRET32 \
987 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100988 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400989 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100990
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100991#ifdef CONFIG_X86_32
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400992#define GET_CR0_INTO_EAX \
993 push %ecx; push %edx; \
994 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200995 pop %edx; pop %ecx
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400996
997#define ENABLE_INTERRUPTS_SYSEXIT \
998 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
999 CLBR_NONE, \
1000 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1001
1002
1003#else /* !CONFIG_X86_32 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -04001004
1005/*
1006 * If swapgs is used while the userspace stack is still current,
1007 * there's no way to call a pvop. The PV replacement *must* be
1008 * inlined, or the swapgs instruction must be trapped and emulated.
1009 */
1010#define SWAPGS_UNSAFE_STACK \
1011 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1012 swapgs)
1013
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001014/*
1015 * Note: swapgs is very special, and in practise is either going to be
1016 * implemented with a single "swapgs" instruction or something very
1017 * special. Either way, we don't need to save any registers for
1018 * it.
1019 */
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001020#define SWAPGS \
1021 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001022 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001023 )
1024
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001025#define GET_CR2_INTO_RCX \
1026 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \
1027 movq %rax, %rcx; \
Glauber de Oliveira Costa4a8c4c42008-01-30 13:32:07 +01001028 xorq %rax, %rax;
1029
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -04001030#define PARAVIRT_ADJUST_EXCEPTION_FRAME \
1031 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
1032 CLBR_NONE, \
1033 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
1034
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001035#define USERGS_SYSRET64 \
1036 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -04001037 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001038 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
1039
1040#define ENABLE_INTERRUPTS_SYSEXIT32 \
1041 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1042 CLBR_NONE, \
1043 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1044#endif /* CONFIG_X86_32 */
Rusty Russell139ec7c2006-12-07 02:14:08 +01001045
Rusty Russelld3561b72006-12-07 02:14:07 +01001046#endif /* __ASSEMBLY__ */
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +02001047#else /* CONFIG_PARAVIRT */
1048# define default_banner x86_init_noop
1049#endif /* !CONFIG_PARAVIRT */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001050#endif /* _ASM_X86_PARAVIRT_H */