blob: 7e2c2a6357374ed50bcaafcc43606430411cfc1d [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__
Paul Gortmaker187f1882011-11-23 20:12:59 -050013#include <linux/bug.h>
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020014#include <linux/types.h>
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +020015#include <linux/cpumask.h>
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +020016
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020017static inline int paravirt_enabled(void)
18{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070019 return pv_info.paravirt_enabled;
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020020}
Rusty Russelld3561b72006-12-07 02:14:07 +010021
H. Peter Anvinfaca6222008-01-30 13:31:02 +010022static inline void load_sp0(struct tss_struct *tss,
Rusty Russelld3561b72006-12-07 02:14:07 +010023 struct thread_struct *thread)
24{
H. Peter Anvinfaca6222008-01-30 13:31:02 +010025 PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +010026}
27
Rusty Russelld3561b72006-12-07 02:14:07 +010028/* The paravirtualized CPUID instruction. */
29static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
30 unsigned int *ecx, unsigned int *edx)
31{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070032 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +010033}
34
35/*
36 * These special macros can be used to get or set a debugging register
37 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020038static inline unsigned long paravirt_get_debugreg(int reg)
39{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070040 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020041}
42#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
43static inline void set_debugreg(unsigned long val, int reg)
44{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070045 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020046}
Rusty Russelld3561b72006-12-07 02:14:07 +010047
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020048static inline void clts(void)
49{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070050 PVOP_VCALL0(pv_cpu_ops.clts);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020051}
Rusty Russelld3561b72006-12-07 02:14:07 +010052
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020053static inline unsigned long read_cr0(void)
54{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070055 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020056}
Rusty Russelld3561b72006-12-07 02:14:07 +010057
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020058static inline void write_cr0(unsigned long x)
59{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070060 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020061}
Rusty Russelld3561b72006-12-07 02:14:07 +010062
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020063static inline unsigned long read_cr2(void)
64{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070065 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020066}
Rusty Russelld3561b72006-12-07 02:14:07 +010067
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020068static inline void write_cr2(unsigned long x)
69{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070070 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020071}
Rusty Russelld3561b72006-12-07 02:14:07 +010072
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020073static inline unsigned long read_cr3(void)
74{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070075 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020076}
77
78static inline void write_cr3(unsigned long x)
79{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070080 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020081}
82
83static inline unsigned long read_cr4(void)
84{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070085 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020086}
87static inline unsigned long read_cr4_safe(void)
88{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070089 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020090}
91
92static inline void write_cr4(unsigned long x)
93{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070094 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020095}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020096
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +010097#ifdef CONFIG_X86_64
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +010098static inline unsigned long read_cr8(void)
99{
100 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
101}
102
103static inline void write_cr8(unsigned long x)
104{
105 PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
106}
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100107#endif
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100108
David Howellsdf9ee292010-10-07 14:08:55 +0100109static inline void arch_safe_halt(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100110{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700111 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100112}
113
114static inline void halt(void)
115{
Cliff Wickmanc8217b82010-12-13 10:51:57 -0600116 PVOP_VCALL0(pv_irq_ops.halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100117}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200118
119static inline void wbinvd(void)
120{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700121 PVOP_VCALL0(pv_cpu_ops.wbinvd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200122}
Rusty Russelld3561b72006-12-07 02:14:07 +0100123
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700124#define get_kernel_rpl() (pv_info.kernel_rpl)
Rusty Russelld3561b72006-12-07 02:14:07 +0100125
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200126static inline u64 paravirt_read_msr(unsigned msr, int *err)
127{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700128 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200129}
Borislav Petkov132ec922009-08-31 09:50:09 +0200130
131static inline int paravirt_rdmsr_regs(u32 *regs)
132{
133 return PVOP_CALL1(int, pv_cpu_ops.rdmsr_regs, regs);
134}
135
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200136static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
137{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700138 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200139}
140
Borislav Petkov132ec922009-08-31 09:50:09 +0200141static inline int paravirt_wrmsr_regs(u32 *regs)
142{
143 return PVOP_CALL1(int, pv_cpu_ops.wrmsr_regs, regs);
144}
145
Rusty Russell90a0a062007-05-02 19:27:10 +0200146/* These should all do BUG_ON(_err), but our headers are too tangled. */
Joe Perches49cd7402008-03-23 01:03:00 -0700147#define rdmsr(msr, val1, val2) \
148do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200149 int _err; \
150 u64 _l = paravirt_read_msr(msr, &_err); \
151 val1 = (u32)_l; \
152 val2 = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700153} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100154
Joe Perches49cd7402008-03-23 01:03:00 -0700155#define wrmsr(msr, val1, val2) \
156do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200157 paravirt_write_msr(msr, val1, val2); \
Joe Perches49cd7402008-03-23 01:03:00 -0700158} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100159
Joe Perches49cd7402008-03-23 01:03:00 -0700160#define rdmsrl(msr, val) \
161do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200162 int _err; \
163 val = paravirt_read_msr(msr, &_err); \
Joe Perches49cd7402008-03-23 01:03:00 -0700164} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100165
Joe Perches49cd7402008-03-23 01:03:00 -0700166#define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
167#define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100168
169/* rdmsr with exception handling */
Joe Perches49cd7402008-03-23 01:03:00 -0700170#define rdmsr_safe(msr, a, b) \
171({ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200172 int _err; \
173 u64 _l = paravirt_read_msr(msr, &_err); \
174 (*a) = (u32)_l; \
175 (*b) = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700176 _err; \
177})
Rusty Russelld3561b72006-12-07 02:14:07 +0100178
Borislav Petkov132ec922009-08-31 09:50:09 +0200179#define rdmsr_safe_regs(regs) paravirt_rdmsr_regs(regs)
180#define wrmsr_safe_regs(regs) paravirt_wrmsr_regs(regs)
181
Andi Kleen1de87bd2008-03-22 10:59:28 +0100182static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
183{
184 int err;
185
186 *p = paravirt_read_msr(msr, &err);
187 return err;
188}
Yinghai Lub05f78f2008-08-22 01:32:50 -0700189static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
190{
Borislav Petkov177fed12009-08-31 09:50:10 +0200191 u32 gprs[8] = { 0 };
Yinghai Lub05f78f2008-08-22 01:32:50 -0700192 int err;
193
Borislav Petkov177fed12009-08-31 09:50:10 +0200194 gprs[1] = msr;
195 gprs[7] = 0x9c5a203a;
196
197 err = paravirt_rdmsr_regs(gprs);
198
199 *p = gprs[0] | ((u64)gprs[2] << 32);
200
Yinghai Lub05f78f2008-08-22 01:32:50 -0700201 return err;
202}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200203
Borislav Petkov177fed12009-08-31 09:50:10 +0200204static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val)
205{
206 u32 gprs[8] = { 0 };
207
208 gprs[0] = (u32)val;
209 gprs[1] = msr;
210 gprs[2] = val >> 32;
211 gprs[7] = 0x9c5a203a;
212
213 return paravirt_wrmsr_regs(gprs);
214}
215
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200216static inline u64 paravirt_read_tsc(void)
217{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700218 return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200219}
Rusty Russelld3561b72006-12-07 02:14:07 +0100220
Joe Perches49cd7402008-03-23 01:03:00 -0700221#define rdtscl(low) \
222do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200223 u64 _l = paravirt_read_tsc(); \
224 low = (int)_l; \
Joe Perches49cd7402008-03-23 01:03:00 -0700225} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100226
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200227#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100228
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700229static inline unsigned long long paravirt_sched_clock(void)
230{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700231 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700232}
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800233
Ingo Molnarc5905af2012-02-24 08:31:31 +0100234struct static_key;
235extern struct static_key paravirt_steal_enabled;
236extern struct static_key paravirt_steal_rq_enabled;
Glauber Costa3c404b52011-07-11 15:28:15 -0400237
238static inline u64 paravirt_steal_clock(int cpu)
239{
240 return PVOP_CALL1(u64, pv_time_ops.steal_clock, cpu);
241}
242
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200243static inline unsigned long long paravirt_read_pmc(int counter)
244{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700245 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200246}
247
Joe Perches49cd7402008-03-23 01:03:00 -0700248#define rdpmc(counter, low, high) \
249do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200250 u64 _l = paravirt_read_pmc(counter); \
251 low = (u32)_l; \
252 high = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700253} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100254
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100255static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
256{
257 return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
258}
259
260#define rdtscp(low, high, aux) \
261do { \
262 int __aux; \
263 unsigned long __val = paravirt_rdtscp(&__aux); \
264 (low) = (u32)__val; \
265 (high) = (u32)(__val >> 32); \
266 (aux) = __aux; \
267} while (0)
268
269#define rdtscpll(val, aux) \
270do { \
271 unsigned long __aux; \
272 val = paravirt_rdtscp(&__aux); \
273 (aux) = __aux; \
274} while (0)
275
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700276static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
277{
278 PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
279}
280
281static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
282{
283 PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
284}
285
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200286static inline void load_TR_desc(void)
287{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700288 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200289}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100290static inline void load_gdt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200291{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700292 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200293}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100294static inline void load_idt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200295{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700296 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200297}
298static inline void set_ldt(const void *addr, unsigned entries)
299{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700300 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200301}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100302static inline void store_gdt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200303{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700304 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200305}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100306static inline void store_idt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200307{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700308 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200309}
310static inline unsigned long paravirt_store_tr(void)
311{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700312 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200313}
314#define store_tr(tr) ((tr) = paravirt_store_tr())
315static inline void load_TLS(struct thread_struct *t, unsigned cpu)
316{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700317 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200318}
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100319
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400320#ifdef CONFIG_X86_64
321static inline void load_gs_index(unsigned int gs)
322{
323 PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
324}
325#endif
326
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100327static inline void write_ldt_entry(struct desc_struct *dt, int entry,
328 const void *desc)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200329{
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100330 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200331}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100332
333static inline void write_gdt_entry(struct desc_struct *dt, int entry,
334 void *desc, int type)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200335{
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100336 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200337}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100338
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100339static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200340{
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100341 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200342}
343static inline void set_iopl_mask(unsigned mask)
344{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700345 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200346}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200347
Rusty Russelld3561b72006-12-07 02:14:07 +0100348/* The paravirtualized I/O functions */
Joe Perches49cd7402008-03-23 01:03:00 -0700349static inline void slow_down_io(void)
350{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700351 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100352#ifdef REALLY_SLOW_IO
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700353 pv_cpu_ops.io_delay();
354 pv_cpu_ops.io_delay();
355 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100356#endif
357}
358
Zachary Amsdenae5da272007-02-13 13:26:21 +0100359#ifdef CONFIG_SMP
360static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
361 unsigned long start_esp)
362{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700363 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
364 phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100365}
366#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100367
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200368static inline void paravirt_activate_mm(struct mm_struct *prev,
369 struct mm_struct *next)
370{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700371 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200372}
373
374static inline void arch_dup_mmap(struct mm_struct *oldmm,
375 struct mm_struct *mm)
376{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700377 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200378}
379
380static inline void arch_exit_mmap(struct mm_struct *mm)
381{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700382 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200383}
384
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200385static inline void __flush_tlb(void)
386{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700387 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200388}
389static inline void __flush_tlb_global(void)
390{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700391 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200392}
393static inline void __flush_tlb_single(unsigned long addr)
394{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700395 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200396}
Rusty Russellda181a82006-12-07 02:14:08 +0100397
Rusty Russell4595f962009-01-10 21:58:09 -0800398static inline void flush_tlb_others(const struct cpumask *cpumask,
399 struct mm_struct *mm,
Alex Shie7b52ff2012-06-28 09:02:17 +0800400 unsigned long start,
401 unsigned long end)
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200402{
Alex Shie7b52ff2012-06-28 09:02:17 +0800403 PVOP_VCALL4(pv_mmu_ops.flush_tlb_others, cpumask, mm, start, end);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200404}
405
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -0400406static inline int paravirt_pgd_alloc(struct mm_struct *mm)
407{
408 return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
409}
410
411static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
412{
413 PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
414}
415
Eduardo Habkostf8639932008-07-30 18:32:27 -0300416static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200417{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700418 PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200419}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300420static inline void paravirt_release_pte(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200421{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700422 PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200423}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100424
Eduardo Habkostf8639932008-07-30 18:32:27 -0300425static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200426{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700427 PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200428}
429
Eduardo Habkostf8639932008-07-30 18:32:27 -0300430static inline void paravirt_release_pmd(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200431{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700432 PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200433}
434
Eduardo Habkostf8639932008-07-30 18:32:27 -0300435static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700436{
437 PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
438}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300439static inline void paravirt_release_pud(unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700440{
441 PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
442}
443
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200444static inline void pte_update(struct mm_struct *mm, unsigned long addr,
445 pte_t *ptep)
446{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700447 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200448}
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800449static inline void pmd_update(struct mm_struct *mm, unsigned long addr,
450 pmd_t *pmdp)
451{
452 PVOP_VCALL3(pv_mmu_ops.pmd_update, mm, addr, pmdp);
453}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200454
455static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
456 pte_t *ptep)
457{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700458 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200459}
460
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800461static inline void pmd_update_defer(struct mm_struct *mm, unsigned long addr,
462 pmd_t *pmdp)
463{
464 PVOP_VCALL3(pv_mmu_ops.pmd_update_defer, mm, addr, pmdp);
465}
466
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100467static inline pte_t __pte(pteval_t val)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200468{
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100469 pteval_t ret;
470
471 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800472 ret = PVOP_CALLEE2(pteval_t,
473 pv_mmu_ops.make_pte,
474 val, (u64)val >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100475 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800476 ret = PVOP_CALLEE1(pteval_t,
477 pv_mmu_ops.make_pte,
478 val);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100479
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100480 return (pte_t) { .pte = ret };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200481}
482
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100483static inline pteval_t pte_val(pte_t pte)
484{
485 pteval_t ret;
486
487 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800488 ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
489 pte.pte, (u64)pte.pte >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100490 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800491 ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
492 pte.pte);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100493
494 return ret;
495}
496
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100497static inline pgd_t __pgd(pgdval_t val)
498{
499 pgdval_t ret;
500
501 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800502 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
503 val, (u64)val >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100504 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800505 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
506 val);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100507
508 return (pgd_t) { ret };
509}
510
511static inline pgdval_t pgd_val(pgd_t pgd)
512{
513 pgdval_t ret;
514
515 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800516 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
517 pgd.pgd, (u64)pgd.pgd >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100518 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800519 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
520 pgd.pgd);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100521
522 return ret;
523}
524
Jeremy Fitzhardinge08b882c2008-06-16 04:30:01 -0700525#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
526static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
527 pte_t *ptep)
528{
529 pteval_t ret;
530
531 ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
532 mm, addr, ptep);
533
534 return (pte_t) { .pte = ret };
535}
536
537static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
538 pte_t *ptep, pte_t pte)
539{
540 if (sizeof(pteval_t) > sizeof(long))
541 /* 5 arg words */
542 pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
543 else
544 PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
545 mm, addr, ptep, pte.pte);
546}
547
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100548static inline void set_pte(pte_t *ptep, pte_t pte)
549{
550 if (sizeof(pteval_t) > sizeof(long))
551 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
552 pte.pte, (u64)pte.pte >> 32);
553 else
554 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
555 pte.pte);
556}
557
558static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
559 pte_t *ptep, pte_t pte)
560{
561 if (sizeof(pteval_t) > sizeof(long))
562 /* 5 arg words */
563 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
564 else
565 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
566}
567
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800568#ifdef CONFIG_TRANSPARENT_HUGEPAGE
569static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
570 pmd_t *pmdp, pmd_t pmd)
571{
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800572 if (sizeof(pmdval_t) > sizeof(long))
573 /* 5 arg words */
574 pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd);
575 else
Andrea Arcangelicacf0612011-01-25 15:07:09 -0800576 PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp,
577 native_pmd_val(pmd));
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800578}
579#endif
580
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100581static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
582{
583 pmdval_t val = native_pmd_val(pmd);
584
585 if (sizeof(pmdval_t) > sizeof(long))
586 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
587 else
588 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
589}
590
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100591#if PAGETABLE_LEVELS >= 3
592static inline pmd_t __pmd(pmdval_t val)
593{
594 pmdval_t ret;
595
596 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800597 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
598 val, (u64)val >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100599 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800600 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
601 val);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100602
603 return (pmd_t) { ret };
604}
605
606static inline pmdval_t pmd_val(pmd_t pmd)
607{
608 pmdval_t ret;
609
610 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800611 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
612 pmd.pmd, (u64)pmd.pmd >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100613 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800614 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
615 pmd.pmd);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100616
617 return ret;
618}
619
620static inline void set_pud(pud_t *pudp, pud_t pud)
621{
622 pudval_t val = native_pud_val(pud);
623
624 if (sizeof(pudval_t) > sizeof(long))
625 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
626 val, (u64)val >> 32);
627 else
628 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
629 val);
630}
Eduardo Habkost90422192008-01-30 13:33:20 +0100631#if PAGETABLE_LEVELS == 4
632static inline pud_t __pud(pudval_t val)
633{
634 pudval_t ret;
635
636 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800637 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
638 val, (u64)val >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100639 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800640 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
641 val);
Eduardo Habkost90422192008-01-30 13:33:20 +0100642
643 return (pud_t) { ret };
644}
645
646static inline pudval_t pud_val(pud_t pud)
647{
648 pudval_t ret;
649
650 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800651 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
652 pud.pud, (u64)pud.pud >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100653 else
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800654 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
655 pud.pud);
Eduardo Habkost90422192008-01-30 13:33:20 +0100656
657 return ret;
658}
659
660static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
661{
662 pgdval_t val = native_pgd_val(pgd);
663
664 if (sizeof(pgdval_t) > sizeof(long))
665 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
666 val, (u64)val >> 32);
667 else
668 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
669 val);
670}
671
672static inline void pgd_clear(pgd_t *pgdp)
673{
674 set_pgd(pgdp, __pgd(0));
675}
676
677static inline void pud_clear(pud_t *pudp)
678{
679 set_pud(pudp, __pud(0));
680}
681
682#endif /* PAGETABLE_LEVELS == 4 */
683
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100684#endif /* PAGETABLE_LEVELS >= 3 */
685
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100686#ifdef CONFIG_X86_PAE
687/* Special-case pte-setting operations for PAE, which can't update a
688 64-bit pte atomically */
689static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
690{
691 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
692 pte.pte, pte.pte >> 32);
693}
694
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100695static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
696 pte_t *ptep)
697{
698 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
699}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100700
701static inline void pmd_clear(pmd_t *pmdp)
702{
703 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
704}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100705#else /* !CONFIG_X86_PAE */
706static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
707{
708 set_pte(ptep, pte);
709}
710
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100711static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
712 pte_t *ptep)
713{
714 set_pte_at(mm, addr, ptep, __pte(0));
715}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100716
717static inline void pmd_clear(pmd_t *pmdp)
718{
719 set_pmd(pmdp, __pmd(0));
720}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100721#endif /* CONFIG_X86_PAE */
722
Jeremy Fitzhardinge7fd7d832009-02-17 23:24:03 -0800723#define __HAVE_ARCH_START_CONTEXT_SWITCH
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800724static inline void arch_start_context_switch(struct task_struct *prev)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200725{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800726 PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200727}
728
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800729static inline void arch_end_context_switch(struct task_struct *next)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200730{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800731 PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200732}
733
Zachary Amsden9226d122007-02-13 13:26:21 +0100734#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200735static inline void arch_enter_lazy_mmu_mode(void)
736{
Jeremy Fitzhardinge8965c1c02007-10-16 11:51:29 -0700737 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200738}
739
740static inline void arch_leave_lazy_mmu_mode(void)
741{
Jeremy Fitzhardinge8965c1c02007-10-16 11:51:29 -0700742 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200743}
744
Jeremy Fitzhardinged85cf932009-02-12 10:02:56 -0800745void arch_flush_lazy_mmu_mode(void);
Zachary Amsden9226d122007-02-13 13:26:21 +0100746
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700747static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
Masami Hiramatsu3b3809a2009-04-09 10:55:33 -0700748 phys_addr_t phys, pgprot_t flags)
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700749{
750 pv_mmu_ops.set_fixmap(idx, phys, flags);
751}
752
Jeremy Fitzhardingeb4ecc122009-05-13 17:16:55 -0700753#if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200754
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100755static inline int arch_spin_is_locked(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700756{
757 return PVOP_CALL1(int, pv_lock_ops.spin_is_locked, lock);
758}
759
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100760static inline int arch_spin_is_contended(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700761{
762 return PVOP_CALL1(int, pv_lock_ops.spin_is_contended, lock);
763}
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100764#define arch_spin_is_contended arch_spin_is_contended
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700765
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100766static __always_inline void arch_spin_lock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700767{
Harvey Harrison32172562008-07-17 14:22:34 -0700768 PVOP_VCALL1(pv_lock_ops.spin_lock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700769}
770
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100771static __always_inline void arch_spin_lock_flags(struct arch_spinlock *lock,
Jeremy Fitzhardinge63d3a752008-08-19 13:19:36 -0700772 unsigned long flags)
773{
774 PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags);
775}
776
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100777static __always_inline int arch_spin_trylock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700778{
779 return PVOP_CALL1(int, pv_lock_ops.spin_trylock, lock);
780}
781
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100782static __always_inline void arch_spin_unlock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700783{
Harvey Harrison32172562008-07-17 14:22:34 -0700784 PVOP_VCALL1(pv_lock_ops.spin_unlock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700785}
786
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200787#endif
788
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100789#ifdef CONFIG_X86_32
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800790#define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
791#define PV_RESTORE_REGS "popl %edx; popl %ecx;"
792
793/* save and restore all caller-save registers, except return value */
Jeremy Fitzhardingee584f552009-01-30 23:17:23 -0800794#define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
795#define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800796
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100797#define PV_FLAGS_ARG "0"
798#define PV_EXTRA_CLOBBERS
799#define PV_VEXTRA_CLOBBERS
800#else
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800801/* save and restore all caller-save registers, except return value */
802#define PV_SAVE_ALL_CALLER_REGS \
803 "push %rcx;" \
804 "push %rdx;" \
805 "push %rsi;" \
806 "push %rdi;" \
807 "push %r8;" \
808 "push %r9;" \
809 "push %r10;" \
810 "push %r11;"
811#define PV_RESTORE_ALL_CALLER_REGS \
812 "pop %r11;" \
813 "pop %r10;" \
814 "pop %r9;" \
815 "pop %r8;" \
816 "pop %rdi;" \
817 "pop %rsi;" \
818 "pop %rdx;" \
819 "pop %rcx;"
820
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100821/* We save some registers, but all of them, that's too much. We clobber all
822 * caller saved registers but the argument parameter */
823#define PV_SAVE_REGS "pushq %%rdi;"
824#define PV_RESTORE_REGS "popq %%rdi;"
Jeremy Fitzhardingec24481e2008-07-08 15:07:12 -0700825#define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
826#define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100827#define PV_FLAGS_ARG "D"
828#endif
829
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800830/*
831 * Generate a thunk around a function which saves all caller-save
832 * registers except for the return value. This allows C functions to
833 * be called from assembler code where fewer than normal registers are
834 * available. It may also help code generation around calls from C
835 * code if the common case doesn't use many registers.
836 *
837 * When a callee is wrapped in a thunk, the caller can assume that all
838 * arg regs and all scratch registers are preserved across the
839 * call. The return value in rax/eax will not be saved, even for void
840 * functions.
841 */
842#define PV_CALLEE_SAVE_REGS_THUNK(func) \
843 extern typeof(func) __raw_callee_save_##func; \
844 static void *__##func##__ __used = func; \
845 \
846 asm(".pushsection .text;" \
847 "__raw_callee_save_" #func ": " \
848 PV_SAVE_ALL_CALLER_REGS \
849 "call " #func ";" \
850 PV_RESTORE_ALL_CALLER_REGS \
851 "ret;" \
852 ".popsection")
853
854/* Get a reference to a callee-save function */
855#define PV_CALLEE_SAVE(func) \
856 ((struct paravirt_callee_save) { __raw_callee_save_##func })
857
858/* Promise that "func" already uses the right calling convention */
859#define __PV_IS_CALLEE_SAVE(func) \
860 ((struct paravirt_callee_save) { func })
861
Steven Rostedtb5908542010-11-10 22:29:49 -0500862static inline notrace unsigned long arch_local_save_flags(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100863{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700864 return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100865}
866
Steven Rostedtb5908542010-11-10 22:29:49 -0500867static inline notrace void arch_local_irq_restore(unsigned long f)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100868{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700869 PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100870}
871
Steven Rostedtb5908542010-11-10 22:29:49 -0500872static inline notrace void arch_local_irq_disable(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100873{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700874 PVOP_VCALLEE0(pv_irq_ops.irq_disable);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100875}
876
Steven Rostedtb5908542010-11-10 22:29:49 -0500877static inline notrace void arch_local_irq_enable(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100878{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700879 PVOP_VCALLEE0(pv_irq_ops.irq_enable);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100880}
881
Steven Rostedtb5908542010-11-10 22:29:49 -0500882static inline notrace unsigned long arch_local_irq_save(void)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100883{
884 unsigned long f;
885
David Howellsdf9ee292010-10-07 14:08:55 +0100886 f = arch_local_save_flags();
887 arch_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +0100888 return f;
889}
890
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700891
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200892/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200893#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200894#undef __PVOP_CALL
895#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200896#undef PVOP_VCALL0
897#undef PVOP_CALL0
898#undef PVOP_VCALL1
899#undef PVOP_CALL1
900#undef PVOP_VCALL2
901#undef PVOP_CALL2
902#undef PVOP_VCALL3
903#undef PVOP_CALL3
904#undef PVOP_VCALL4
905#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100906
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +0200907extern void default_banner(void);
908
Rusty Russelld3561b72006-12-07 02:14:07 +0100909#else /* __ASSEMBLY__ */
910
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100911#define _PVSITE(ptype, clobbers, ops, word, algn) \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100912771:; \
913 ops; \
914772:; \
915 .pushsection .parainstructions,"a"; \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100916 .align algn; \
917 word 771b; \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100918 .byte ptype; \
919 .byte 772b-771b; \
920 .short clobbers; \
921 .popsection
922
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100923
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800924#define COND_PUSH(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800925 .if ((~(set)) & mask); push %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800926#define COND_POP(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800927 .if ((~(set)) & mask); pop %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800928
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100929#ifdef CONFIG_X86_64
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800930
931#define PV_SAVE_REGS(set) \
932 COND_PUSH(set, CLBR_RAX, rax); \
933 COND_PUSH(set, CLBR_RCX, rcx); \
934 COND_PUSH(set, CLBR_RDX, rdx); \
935 COND_PUSH(set, CLBR_RSI, rsi); \
936 COND_PUSH(set, CLBR_RDI, rdi); \
937 COND_PUSH(set, CLBR_R8, r8); \
938 COND_PUSH(set, CLBR_R9, r9); \
939 COND_PUSH(set, CLBR_R10, r10); \
940 COND_PUSH(set, CLBR_R11, r11)
941#define PV_RESTORE_REGS(set) \
942 COND_POP(set, CLBR_R11, r11); \
943 COND_POP(set, CLBR_R10, r10); \
944 COND_POP(set, CLBR_R9, r9); \
945 COND_POP(set, CLBR_R8, r8); \
946 COND_POP(set, CLBR_RDI, rdi); \
947 COND_POP(set, CLBR_RSI, rsi); \
948 COND_POP(set, CLBR_RDX, rdx); \
949 COND_POP(set, CLBR_RCX, rcx); \
950 COND_POP(set, CLBR_RAX, rax)
951
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100952#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100953#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400954#define PARA_INDIRECT(addr) *addr(%rip)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100955#else
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800956#define PV_SAVE_REGS(set) \
957 COND_PUSH(set, CLBR_EAX, eax); \
958 COND_PUSH(set, CLBR_EDI, edi); \
959 COND_PUSH(set, CLBR_ECX, ecx); \
960 COND_PUSH(set, CLBR_EDX, edx)
961#define PV_RESTORE_REGS(set) \
962 COND_POP(set, CLBR_EDX, edx); \
963 COND_POP(set, CLBR_ECX, ecx); \
964 COND_POP(set, CLBR_EDI, edi); \
965 COND_POP(set, CLBR_EAX, eax)
966
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100967#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100968#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400969#define PARA_INDIRECT(addr) *%cs:addr
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100970#endif
971
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700972#define INTERRUPT_RETURN \
973 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400974 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
Rusty Russell139ec7c2006-12-07 02:14:08 +0100975
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200976#define DISABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700977 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800978 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400979 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800980 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100981
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200982#define ENABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700983 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800984 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400985 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800986 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100987
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400988#define USERGS_SYSRET32 \
989 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100990 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400991 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100992
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100993#ifdef CONFIG_X86_32
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400994#define GET_CR0_INTO_EAX \
995 push %ecx; push %edx; \
996 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200997 pop %edx; pop %ecx
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400998
999#define ENABLE_INTERRUPTS_SYSEXIT \
1000 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1001 CLBR_NONE, \
1002 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1003
1004
1005#else /* !CONFIG_X86_32 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -04001006
1007/*
1008 * If swapgs is used while the userspace stack is still current,
1009 * there's no way to call a pvop. The PV replacement *must* be
1010 * inlined, or the swapgs instruction must be trapped and emulated.
1011 */
1012#define SWAPGS_UNSAFE_STACK \
1013 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1014 swapgs)
1015
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001016/*
1017 * Note: swapgs is very special, and in practise is either going to be
1018 * implemented with a single "swapgs" instruction or something very
1019 * special. Either way, we don't need to save any registers for
1020 * it.
1021 */
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001022#define SWAPGS \
1023 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001024 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001025 )
1026
H. Peter Anvinffc4bc92012-04-18 17:16:48 -07001027#define GET_CR2_INTO_RAX \
1028 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2)
Glauber de Oliveira Costa4a8c4c42008-01-30 13:32:07 +01001029
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 Fitzhardinged75cd222008-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 */