blob: dd59a85a918fcf6dfe70b1768e19d976ae80ba59 [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
Rusty Russelld3561b72006-12-07 02:14:07 +0100108static inline void raw_safe_halt(void)
109{
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{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700115 PVOP_VCALL0(pv_irq_ops.safe_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
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200233static inline unsigned long long paravirt_read_pmc(int counter)
234{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700235 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200236}
237
Joe Perches49cd7402008-03-23 01:03:00 -0700238#define rdpmc(counter, low, high) \
239do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200240 u64 _l = paravirt_read_pmc(counter); \
241 low = (u32)_l; \
242 high = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700243} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100244
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100245static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
246{
247 return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
248}
249
250#define rdtscp(low, high, aux) \
251do { \
252 int __aux; \
253 unsigned long __val = paravirt_rdtscp(&__aux); \
254 (low) = (u32)__val; \
255 (high) = (u32)(__val >> 32); \
256 (aux) = __aux; \
257} while (0)
258
259#define rdtscpll(val, aux) \
260do { \
261 unsigned long __aux; \
262 val = paravirt_rdtscp(&__aux); \
263 (aux) = __aux; \
264} while (0)
265
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700266static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
267{
268 PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
269}
270
271static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
272{
273 PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
274}
275
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200276static inline void load_TR_desc(void)
277{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700278 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200279}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100280static inline void load_gdt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200281{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700282 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200283}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100284static inline void load_idt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200285{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700286 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200287}
288static inline void set_ldt(const void *addr, unsigned entries)
289{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700290 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200291}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100292static inline void store_gdt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200293{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700294 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200295}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100296static inline void store_idt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200297{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700298 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200299}
300static inline unsigned long paravirt_store_tr(void)
301{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700302 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200303}
304#define store_tr(tr) ((tr) = paravirt_store_tr())
305static inline void load_TLS(struct thread_struct *t, unsigned cpu)
306{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700307 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200308}
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100309
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400310#ifdef CONFIG_X86_64
311static inline void load_gs_index(unsigned int gs)
312{
313 PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
314}
315#endif
316
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100317static inline void write_ldt_entry(struct desc_struct *dt, int entry,
318 const void *desc)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200319{
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100320 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200321}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100322
323static inline void write_gdt_entry(struct desc_struct *dt, int entry,
324 void *desc, int type)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200325{
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100326 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200327}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100328
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100329static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200330{
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100331 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200332}
333static inline void set_iopl_mask(unsigned mask)
334{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700335 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200336}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200337
Rusty Russelld3561b72006-12-07 02:14:07 +0100338/* The paravirtualized I/O functions */
Joe Perches49cd7402008-03-23 01:03:00 -0700339static inline void slow_down_io(void)
340{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700341 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100342#ifdef REALLY_SLOW_IO
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700343 pv_cpu_ops.io_delay();
344 pv_cpu_ops.io_delay();
345 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100346#endif
347}
348
Zachary Amsdenae5da272007-02-13 13:26:21 +0100349#ifdef CONFIG_SMP
350static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
351 unsigned long start_esp)
352{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700353 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
354 phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100355}
356#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100357
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200358static inline void paravirt_activate_mm(struct mm_struct *prev,
359 struct mm_struct *next)
360{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700361 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200362}
363
364static inline void arch_dup_mmap(struct mm_struct *oldmm,
365 struct mm_struct *mm)
366{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700367 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200368}
369
370static inline void arch_exit_mmap(struct mm_struct *mm)
371{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700372 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200373}
374
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200375static inline void __flush_tlb(void)
376{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700377 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200378}
379static inline void __flush_tlb_global(void)
380{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700381 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200382}
383static inline void __flush_tlb_single(unsigned long addr)
384{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700385 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200386}
Rusty Russellda181a82006-12-07 02:14:08 +0100387
Rusty Russell4595f962009-01-10 21:58:09 -0800388static inline void flush_tlb_others(const struct cpumask *cpumask,
389 struct mm_struct *mm,
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200390 unsigned long va)
391{
Rusty Russell4595f962009-01-10 21:58:09 -0800392 PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, cpumask, mm, va);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200393}
394
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -0400395static inline int paravirt_pgd_alloc(struct mm_struct *mm)
396{
397 return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
398}
399
400static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
401{
402 PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
403}
404
Eduardo Habkostf8639932008-07-30 18:32:27 -0300405static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200406{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700407 PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200408}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300409static inline void paravirt_release_pte(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200410{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700411 PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200412}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100413
Eduardo Habkostf8639932008-07-30 18:32:27 -0300414static inline void paravirt_alloc_pmd(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_pmd, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200417}
418
Eduardo Habkostf8639932008-07-30 18:32:27 -0300419static inline void paravirt_alloc_pmd_clone(unsigned long pfn, unsigned long clonepfn,
420 unsigned long start, unsigned long count)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200421{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700422 PVOP_VCALL4(pv_mmu_ops.alloc_pmd_clone, pfn, clonepfn, start, count);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200423}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300424static inline void paravirt_release_pmd(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200425{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700426 PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200427}
428
Eduardo Habkostf8639932008-07-30 18:32:27 -0300429static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700430{
431 PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
432}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300433static inline void paravirt_release_pud(unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700434{
435 PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
436}
437
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200438#ifdef CONFIG_HIGHPTE
439static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
440{
441 unsigned long ret;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700442 ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type);
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200443 return (void *)ret;
444}
445#endif
446
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200447static inline void pte_update(struct mm_struct *mm, unsigned long addr,
448 pte_t *ptep)
449{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700450 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200451}
452
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
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100459static inline pte_t __pte(pteval_t val)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200460{
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100461 pteval_t ret;
462
463 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800464 ret = PVOP_CALLEE2(pteval_t,
465 pv_mmu_ops.make_pte,
466 val, (u64)val >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100467 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800468 ret = PVOP_CALLEE1(pteval_t,
469 pv_mmu_ops.make_pte,
470 val);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100471
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100472 return (pte_t) { .pte = ret };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200473}
474
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100475static inline pteval_t pte_val(pte_t pte)
476{
477 pteval_t ret;
478
479 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800480 ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
481 pte.pte, (u64)pte.pte >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100482 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800483 ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
484 pte.pte);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100485
486 return ret;
487}
488
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100489static inline pgd_t __pgd(pgdval_t val)
490{
491 pgdval_t ret;
492
493 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800494 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
495 val, (u64)val >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100496 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800497 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
498 val);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100499
500 return (pgd_t) { ret };
501}
502
503static inline pgdval_t pgd_val(pgd_t pgd)
504{
505 pgdval_t ret;
506
507 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800508 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
509 pgd.pgd, (u64)pgd.pgd >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100510 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800511 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
512 pgd.pgd);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100513
514 return ret;
515}
516
Jeremy Fitzhardinge08b882c2008-06-16 04:30:01 -0700517#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
518static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
519 pte_t *ptep)
520{
521 pteval_t ret;
522
523 ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
524 mm, addr, ptep);
525
526 return (pte_t) { .pte = ret };
527}
528
529static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
530 pte_t *ptep, pte_t pte)
531{
532 if (sizeof(pteval_t) > sizeof(long))
533 /* 5 arg words */
534 pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
535 else
536 PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
537 mm, addr, ptep, pte.pte);
538}
539
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100540static inline void set_pte(pte_t *ptep, pte_t pte)
541{
542 if (sizeof(pteval_t) > sizeof(long))
543 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
544 pte.pte, (u64)pte.pte >> 32);
545 else
546 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
547 pte.pte);
548}
549
550static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
551 pte_t *ptep, pte_t pte)
552{
553 if (sizeof(pteval_t) > sizeof(long))
554 /* 5 arg words */
555 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
556 else
557 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
558}
559
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100560static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
561{
562 pmdval_t val = native_pmd_val(pmd);
563
564 if (sizeof(pmdval_t) > sizeof(long))
565 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
566 else
567 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
568}
569
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100570#if PAGETABLE_LEVELS >= 3
571static inline pmd_t __pmd(pmdval_t val)
572{
573 pmdval_t ret;
574
575 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800576 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
577 val, (u64)val >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100578 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800579 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
580 val);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100581
582 return (pmd_t) { ret };
583}
584
585static inline pmdval_t pmd_val(pmd_t pmd)
586{
587 pmdval_t ret;
588
589 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800590 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
591 pmd.pmd, (u64)pmd.pmd >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100592 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800593 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
594 pmd.pmd);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100595
596 return ret;
597}
598
599static inline void set_pud(pud_t *pudp, pud_t pud)
600{
601 pudval_t val = native_pud_val(pud);
602
603 if (sizeof(pudval_t) > sizeof(long))
604 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
605 val, (u64)val >> 32);
606 else
607 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
608 val);
609}
Eduardo Habkost90422192008-01-30 13:33:20 +0100610#if PAGETABLE_LEVELS == 4
611static inline pud_t __pud(pudval_t val)
612{
613 pudval_t ret;
614
615 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800616 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
617 val, (u64)val >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100618 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800619 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
620 val);
Eduardo Habkost90422192008-01-30 13:33:20 +0100621
622 return (pud_t) { ret };
623}
624
625static inline pudval_t pud_val(pud_t pud)
626{
627 pudval_t ret;
628
629 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800630 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
631 pud.pud, (u64)pud.pud >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100632 else
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800633 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
634 pud.pud);
Eduardo Habkost90422192008-01-30 13:33:20 +0100635
636 return ret;
637}
638
639static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
640{
641 pgdval_t val = native_pgd_val(pgd);
642
643 if (sizeof(pgdval_t) > sizeof(long))
644 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
645 val, (u64)val >> 32);
646 else
647 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
648 val);
649}
650
651static inline void pgd_clear(pgd_t *pgdp)
652{
653 set_pgd(pgdp, __pgd(0));
654}
655
656static inline void pud_clear(pud_t *pudp)
657{
658 set_pud(pudp, __pud(0));
659}
660
661#endif /* PAGETABLE_LEVELS == 4 */
662
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100663#endif /* PAGETABLE_LEVELS >= 3 */
664
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100665#ifdef CONFIG_X86_PAE
666/* Special-case pte-setting operations for PAE, which can't update a
667 64-bit pte atomically */
668static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
669{
670 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
671 pte.pte, pte.pte >> 32);
672}
673
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100674static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
675 pte_t *ptep)
676{
677 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
678}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100679
680static inline void pmd_clear(pmd_t *pmdp)
681{
682 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
683}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100684#else /* !CONFIG_X86_PAE */
685static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
686{
687 set_pte(ptep, pte);
688}
689
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100690static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
691 pte_t *ptep)
692{
693 set_pte_at(mm, addr, ptep, __pte(0));
694}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100695
696static inline void pmd_clear(pmd_t *pmdp)
697{
698 set_pmd(pmdp, __pmd(0));
699}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100700#endif /* CONFIG_X86_PAE */
701
Jeremy Fitzhardinge7fd7d832009-02-17 23:24:03 -0800702#define __HAVE_ARCH_START_CONTEXT_SWITCH
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800703static inline void arch_start_context_switch(struct task_struct *prev)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200704{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800705 PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200706}
707
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800708static inline void arch_end_context_switch(struct task_struct *next)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200709{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800710 PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200711}
712
Zachary Amsden9226d122007-02-13 13:26:21 +0100713#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200714static inline void arch_enter_lazy_mmu_mode(void)
715{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700716 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200717}
718
719static inline void arch_leave_lazy_mmu_mode(void)
720{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700721 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200722}
723
Jeremy Fitzhardinged85cf932009-02-12 10:02:56 -0800724void arch_flush_lazy_mmu_mode(void);
Zachary Amsden9226d122007-02-13 13:26:21 +0100725
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700726static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
Masami Hiramatsu3b3809a2009-04-09 10:55:33 -0700727 phys_addr_t phys, pgprot_t flags)
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700728{
729 pv_mmu_ops.set_fixmap(idx, phys, flags);
730}
731
Jeremy Fitzhardingeb4ecc122009-05-13 17:16:55 -0700732#if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200733
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100734static inline int arch_spin_is_locked(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700735{
736 return PVOP_CALL1(int, pv_lock_ops.spin_is_locked, lock);
737}
738
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100739static inline int arch_spin_is_contended(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700740{
741 return PVOP_CALL1(int, pv_lock_ops.spin_is_contended, lock);
742}
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100743#define arch_spin_is_contended arch_spin_is_contended
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700744
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100745static __always_inline void arch_spin_lock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700746{
Harvey Harrison32172562008-07-17 14:22:34 -0700747 PVOP_VCALL1(pv_lock_ops.spin_lock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700748}
749
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100750static __always_inline void arch_spin_lock_flags(struct arch_spinlock *lock,
Jeremy Fitzhardinge63d3a752008-08-19 13:19:36 -0700751 unsigned long flags)
752{
753 PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags);
754}
755
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100756static __always_inline int arch_spin_trylock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700757{
758 return PVOP_CALL1(int, pv_lock_ops.spin_trylock, lock);
759}
760
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100761static __always_inline void arch_spin_unlock(struct arch_spinlock *lock)
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700762{
Harvey Harrison32172562008-07-17 14:22:34 -0700763 PVOP_VCALL1(pv_lock_ops.spin_unlock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700764}
765
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200766#endif
767
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100768#ifdef CONFIG_X86_32
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800769#define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
770#define PV_RESTORE_REGS "popl %edx; popl %ecx;"
771
772/* save and restore all caller-save registers, except return value */
Jeremy Fitzhardingee584f552009-01-30 23:17:23 -0800773#define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
774#define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800775
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100776#define PV_FLAGS_ARG "0"
777#define PV_EXTRA_CLOBBERS
778#define PV_VEXTRA_CLOBBERS
779#else
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800780/* save and restore all caller-save registers, except return value */
781#define PV_SAVE_ALL_CALLER_REGS \
782 "push %rcx;" \
783 "push %rdx;" \
784 "push %rsi;" \
785 "push %rdi;" \
786 "push %r8;" \
787 "push %r9;" \
788 "push %r10;" \
789 "push %r11;"
790#define PV_RESTORE_ALL_CALLER_REGS \
791 "pop %r11;" \
792 "pop %r10;" \
793 "pop %r9;" \
794 "pop %r8;" \
795 "pop %rdi;" \
796 "pop %rsi;" \
797 "pop %rdx;" \
798 "pop %rcx;"
799
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100800/* We save some registers, but all of them, that's too much. We clobber all
801 * caller saved registers but the argument parameter */
802#define PV_SAVE_REGS "pushq %%rdi;"
803#define PV_RESTORE_REGS "popq %%rdi;"
Jeremy Fitzhardingec24481e2008-07-08 15:07:12 -0700804#define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
805#define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100806#define PV_FLAGS_ARG "D"
807#endif
808
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800809/*
810 * Generate a thunk around a function which saves all caller-save
811 * registers except for the return value. This allows C functions to
812 * be called from assembler code where fewer than normal registers are
813 * available. It may also help code generation around calls from C
814 * code if the common case doesn't use many registers.
815 *
816 * When a callee is wrapped in a thunk, the caller can assume that all
817 * arg regs and all scratch registers are preserved across the
818 * call. The return value in rax/eax will not be saved, even for void
819 * functions.
820 */
821#define PV_CALLEE_SAVE_REGS_THUNK(func) \
822 extern typeof(func) __raw_callee_save_##func; \
823 static void *__##func##__ __used = func; \
824 \
825 asm(".pushsection .text;" \
826 "__raw_callee_save_" #func ": " \
827 PV_SAVE_ALL_CALLER_REGS \
828 "call " #func ";" \
829 PV_RESTORE_ALL_CALLER_REGS \
830 "ret;" \
831 ".popsection")
832
833/* Get a reference to a callee-save function */
834#define PV_CALLEE_SAVE(func) \
835 ((struct paravirt_callee_save) { __raw_callee_save_##func })
836
837/* Promise that "func" already uses the right calling convention */
838#define __PV_IS_CALLEE_SAVE(func) \
839 ((struct paravirt_callee_save) { func })
840
Rusty Russell139ec7c2006-12-07 02:14:08 +0100841static inline unsigned long __raw_local_save_flags(void)
842{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700843 return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100844}
845
846static inline void raw_local_irq_restore(unsigned long f)
847{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700848 PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100849}
850
851static inline void raw_local_irq_disable(void)
852{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700853 PVOP_VCALLEE0(pv_irq_ops.irq_disable);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100854}
855
856static inline void raw_local_irq_enable(void)
857{
Jeremy Fitzhardinge71999d92009-10-12 16:32:43 -0700858 PVOP_VCALLEE0(pv_irq_ops.irq_enable);
Rusty Russell139ec7c2006-12-07 02:14:08 +0100859}
860
861static inline unsigned long __raw_local_irq_save(void)
862{
863 unsigned long f;
864
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200865 f = __raw_local_save_flags();
866 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +0100867 return f;
868}
869
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700870
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200871/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200872#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200873#undef __PVOP_CALL
874#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200875#undef PVOP_VCALL0
876#undef PVOP_CALL0
877#undef PVOP_VCALL1
878#undef PVOP_CALL1
879#undef PVOP_VCALL2
880#undef PVOP_CALL2
881#undef PVOP_VCALL3
882#undef PVOP_CALL3
883#undef PVOP_VCALL4
884#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100885
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +0200886extern void default_banner(void);
887
Rusty Russelld3561b72006-12-07 02:14:07 +0100888#else /* __ASSEMBLY__ */
889
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100890#define _PVSITE(ptype, clobbers, ops, word, algn) \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100891771:; \
892 ops; \
893772:; \
894 .pushsection .parainstructions,"a"; \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100895 .align algn; \
896 word 771b; \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100897 .byte ptype; \
898 .byte 772b-771b; \
899 .short clobbers; \
900 .popsection
901
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100902
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800903#define COND_PUSH(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800904 .if ((~(set)) & mask); push %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800905#define COND_POP(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800906 .if ((~(set)) & mask); pop %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800907
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100908#ifdef CONFIG_X86_64
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800909
910#define PV_SAVE_REGS(set) \
911 COND_PUSH(set, CLBR_RAX, rax); \
912 COND_PUSH(set, CLBR_RCX, rcx); \
913 COND_PUSH(set, CLBR_RDX, rdx); \
914 COND_PUSH(set, CLBR_RSI, rsi); \
915 COND_PUSH(set, CLBR_RDI, rdi); \
916 COND_PUSH(set, CLBR_R8, r8); \
917 COND_PUSH(set, CLBR_R9, r9); \
918 COND_PUSH(set, CLBR_R10, r10); \
919 COND_PUSH(set, CLBR_R11, r11)
920#define PV_RESTORE_REGS(set) \
921 COND_POP(set, CLBR_R11, r11); \
922 COND_POP(set, CLBR_R10, r10); \
923 COND_POP(set, CLBR_R9, r9); \
924 COND_POP(set, CLBR_R8, r8); \
925 COND_POP(set, CLBR_RDI, rdi); \
926 COND_POP(set, CLBR_RSI, rsi); \
927 COND_POP(set, CLBR_RDX, rdx); \
928 COND_POP(set, CLBR_RCX, rcx); \
929 COND_POP(set, CLBR_RAX, rax)
930
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100931#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100932#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400933#define PARA_INDIRECT(addr) *addr(%rip)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100934#else
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800935#define PV_SAVE_REGS(set) \
936 COND_PUSH(set, CLBR_EAX, eax); \
937 COND_PUSH(set, CLBR_EDI, edi); \
938 COND_PUSH(set, CLBR_ECX, ecx); \
939 COND_PUSH(set, CLBR_EDX, edx)
940#define PV_RESTORE_REGS(set) \
941 COND_POP(set, CLBR_EDX, edx); \
942 COND_POP(set, CLBR_ECX, ecx); \
943 COND_POP(set, CLBR_EDI, edi); \
944 COND_POP(set, CLBR_EAX, eax)
945
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100946#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100947#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400948#define PARA_INDIRECT(addr) *%cs:addr
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100949#endif
950
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700951#define INTERRUPT_RETURN \
952 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400953 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
Rusty Russell139ec7c2006-12-07 02:14:08 +0100954
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200955#define DISABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700956 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800957 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400958 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800959 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100960
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200961#define ENABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700962 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800963 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400964 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800965 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100966
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400967#define USERGS_SYSRET32 \
968 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100969 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400970 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100971
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100972#ifdef CONFIG_X86_32
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400973#define GET_CR0_INTO_EAX \
974 push %ecx; push %edx; \
975 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200976 pop %edx; pop %ecx
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400977
978#define ENABLE_INTERRUPTS_SYSEXIT \
979 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
980 CLBR_NONE, \
981 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
982
983
984#else /* !CONFIG_X86_32 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -0400985
986/*
987 * If swapgs is used while the userspace stack is still current,
988 * there's no way to call a pvop. The PV replacement *must* be
989 * inlined, or the swapgs instruction must be trapped and emulated.
990 */
991#define SWAPGS_UNSAFE_STACK \
992 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
993 swapgs)
994
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800995/*
996 * Note: swapgs is very special, and in practise is either going to be
997 * implemented with a single "swapgs" instruction or something very
998 * special. Either way, we don't need to save any registers for
999 * it.
1000 */
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001001#define SWAPGS \
1002 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001003 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001004 )
1005
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001006#define GET_CR2_INTO_RCX \
1007 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \
1008 movq %rax, %rcx; \
Glauber de Oliveira Costa4a8c4c42008-01-30 13:32:07 +01001009 xorq %rax, %rax;
1010
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -04001011#define PARAVIRT_ADJUST_EXCEPTION_FRAME \
1012 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
1013 CLBR_NONE, \
1014 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
1015
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001016#define USERGS_SYSRET64 \
1017 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -04001018 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001019 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
1020
1021#define ENABLE_INTERRUPTS_SYSEXIT32 \
1022 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1023 CLBR_NONE, \
1024 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1025#endif /* CONFIG_X86_32 */
Rusty Russell139ec7c2006-12-07 02:14:08 +01001026
Rusty Russelld3561b72006-12-07 02:14:07 +01001027#endif /* __ASSEMBLY__ */
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +02001028#else /* CONFIG_PARAVIRT */
1029# define default_banner x86_init_noop
1030#endif /* !CONFIG_PARAVIRT */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001031#endif /* _ASM_X86_PARAVIRT_H */