blob: 3de6435a106ac8e2b0620ec64f08c5b338113b9b [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 +010027static inline unsigned long get_wallclock(void)
28{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070029 return PVOP_CALL0(unsigned long, pv_time_ops.get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +010030}
31
32static inline int set_wallclock(unsigned long nowtime)
33{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070034 return PVOP_CALL1(int, pv_time_ops.set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +010035}
36
Zachary Amsdene30fab32007-03-05 00:30:39 -080037static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +010038{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070039 return pv_time_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +010040}
41
42/* The paravirtualized CPUID instruction. */
43static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
44 unsigned int *ecx, unsigned int *edx)
45{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070046 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +010047}
48
49/*
50 * These special macros can be used to get or set a debugging register
51 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020052static inline unsigned long paravirt_get_debugreg(int reg)
53{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070054 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020055}
56#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
57static inline void set_debugreg(unsigned long val, int reg)
58{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070059 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
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 void clts(void)
63{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070064 PVOP_VCALL0(pv_cpu_ops.clts);
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 unsigned long read_cr0(void)
68{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070069 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
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 void write_cr0(unsigned long x)
73{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070074 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020075}
Rusty Russelld3561b72006-12-07 02:14:07 +010076
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020077static inline unsigned long read_cr2(void)
78{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070079 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020080}
Rusty Russelld3561b72006-12-07 02:14:07 +010081
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020082static inline void write_cr2(unsigned long x)
83{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070084 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020085}
Rusty Russelld3561b72006-12-07 02:14:07 +010086
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020087static inline unsigned long read_cr3(void)
88{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070089 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020090}
91
92static inline void write_cr3(unsigned long x)
93{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070094 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +020095}
96
97static inline unsigned long read_cr4(void)
98{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070099 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200100}
101static inline unsigned long read_cr4_safe(void)
102{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700103 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200104}
105
106static inline void write_cr4(unsigned long x)
107{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700108 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200109}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200110
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100111#ifdef CONFIG_X86_64
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100112static inline unsigned long read_cr8(void)
113{
114 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
115}
116
117static inline void write_cr8(unsigned long x)
118{
119 PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
120}
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100121#endif
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100122
Rusty Russelld3561b72006-12-07 02:14:07 +0100123static inline void raw_safe_halt(void)
124{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700125 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100126}
127
128static inline void halt(void)
129{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700130 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100131}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200132
133static inline void wbinvd(void)
134{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700135 PVOP_VCALL0(pv_cpu_ops.wbinvd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200136}
Rusty Russelld3561b72006-12-07 02:14:07 +0100137
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700138#define get_kernel_rpl() (pv_info.kernel_rpl)
Rusty Russelld3561b72006-12-07 02:14:07 +0100139
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200140static inline u64 paravirt_read_msr(unsigned msr, int *err)
141{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700142 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200143}
Yinghai Lub05f78f2008-08-22 01:32:50 -0700144static inline u64 paravirt_read_msr_amd(unsigned msr, int *err)
145{
146 return PVOP_CALL2(u64, pv_cpu_ops.read_msr_amd, msr, err);
147}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200148static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
149{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700150 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200151}
152
Rusty Russell90a0a062007-05-02 19:27:10 +0200153/* These should all do BUG_ON(_err), but our headers are too tangled. */
Joe Perches49cd7402008-03-23 01:03:00 -0700154#define rdmsr(msr, val1, val2) \
155do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200156 int _err; \
157 u64 _l = paravirt_read_msr(msr, &_err); \
158 val1 = (u32)_l; \
159 val2 = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700160} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100161
Joe Perches49cd7402008-03-23 01:03:00 -0700162#define wrmsr(msr, val1, val2) \
163do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200164 paravirt_write_msr(msr, val1, val2); \
Joe Perches49cd7402008-03-23 01:03:00 -0700165} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100166
Joe Perches49cd7402008-03-23 01:03:00 -0700167#define rdmsrl(msr, val) \
168do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200169 int _err; \
170 val = paravirt_read_msr(msr, &_err); \
Joe Perches49cd7402008-03-23 01:03:00 -0700171} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100172
Joe Perches49cd7402008-03-23 01:03:00 -0700173#define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
174#define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100175
176/* rdmsr with exception handling */
Joe Perches49cd7402008-03-23 01:03:00 -0700177#define rdmsr_safe(msr, a, b) \
178({ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200179 int _err; \
180 u64 _l = paravirt_read_msr(msr, &_err); \
181 (*a) = (u32)_l; \
182 (*b) = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700183 _err; \
184})
Rusty Russelld3561b72006-12-07 02:14:07 +0100185
Andi Kleen1de87bd2008-03-22 10:59:28 +0100186static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
187{
188 int err;
189
190 *p = paravirt_read_msr(msr, &err);
191 return err;
192}
Yinghai Lub05f78f2008-08-22 01:32:50 -0700193static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
194{
195 int err;
196
197 *p = paravirt_read_msr_amd(msr, &err);
198 return err;
199}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200200
201static inline u64 paravirt_read_tsc(void)
202{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700203 return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200204}
Rusty Russelld3561b72006-12-07 02:14:07 +0100205
Joe Perches49cd7402008-03-23 01:03:00 -0700206#define rdtscl(low) \
207do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200208 u64 _l = paravirt_read_tsc(); \
209 low = (int)_l; \
Joe Perches49cd7402008-03-23 01:03:00 -0700210} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100211
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200212#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100213
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700214static inline unsigned long long paravirt_sched_clock(void)
215{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700216 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700217}
Alok Katariae93ef942008-07-01 11:43:36 -0700218#define calibrate_tsc() (pv_time_ops.get_tsc_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800219
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200220static inline unsigned long long paravirt_read_pmc(int counter)
221{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700222 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200223}
224
Joe Perches49cd7402008-03-23 01:03:00 -0700225#define rdpmc(counter, low, high) \
226do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200227 u64 _l = paravirt_read_pmc(counter); \
228 low = (u32)_l; \
229 high = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700230} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100231
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100232static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
233{
234 return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
235}
236
237#define rdtscp(low, high, aux) \
238do { \
239 int __aux; \
240 unsigned long __val = paravirt_rdtscp(&__aux); \
241 (low) = (u32)__val; \
242 (high) = (u32)(__val >> 32); \
243 (aux) = __aux; \
244} while (0)
245
246#define rdtscpll(val, aux) \
247do { \
248 unsigned long __aux; \
249 val = paravirt_rdtscp(&__aux); \
250 (aux) = __aux; \
251} while (0)
252
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700253static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
254{
255 PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
256}
257
258static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
259{
260 PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
261}
262
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200263static inline void load_TR_desc(void)
264{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700265 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200266}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100267static inline void load_gdt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200268{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700269 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200270}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100271static inline void load_idt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200272{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700273 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200274}
275static inline void set_ldt(const void *addr, unsigned entries)
276{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700277 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200278}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100279static inline void store_gdt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200280{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700281 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200282}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100283static inline void store_idt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200284{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700285 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200286}
287static inline unsigned long paravirt_store_tr(void)
288{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700289 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200290}
291#define store_tr(tr) ((tr) = paravirt_store_tr())
292static inline void load_TLS(struct thread_struct *t, unsigned cpu)
293{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700294 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200295}
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100296
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400297#ifdef CONFIG_X86_64
298static inline void load_gs_index(unsigned int gs)
299{
300 PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
301}
302#endif
303
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100304static inline void write_ldt_entry(struct desc_struct *dt, int entry,
305 const void *desc)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200306{
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100307 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200308}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100309
310static inline void write_gdt_entry(struct desc_struct *dt, int entry,
311 void *desc, int type)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200312{
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100313 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200314}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100315
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100316static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200317{
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100318 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200319}
320static inline void set_iopl_mask(unsigned mask)
321{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700322 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200323}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200324
Rusty Russelld3561b72006-12-07 02:14:07 +0100325/* The paravirtualized I/O functions */
Joe Perches49cd7402008-03-23 01:03:00 -0700326static inline void slow_down_io(void)
327{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700328 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100329#ifdef REALLY_SLOW_IO
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700330 pv_cpu_ops.io_delay();
331 pv_cpu_ops.io_delay();
332 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100333#endif
334}
335
Rusty Russell13623d72006-12-07 02:14:08 +0100336#ifdef CONFIG_X86_LOCAL_APIC
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100337static inline void setup_boot_clock(void)
338{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700339 PVOP_VCALL0(pv_apic_ops.setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100340}
341
342static inline void setup_secondary_clock(void)
343{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700344 PVOP_VCALL0(pv_apic_ops.setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100345}
Rusty Russell13623d72006-12-07 02:14:08 +0100346#endif
347
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -0700348static inline void paravirt_post_allocator_init(void)
349{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700350 if (pv_init_ops.post_allocator_init)
351 (*pv_init_ops.post_allocator_init)();
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -0700352}
353
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200354static inline void paravirt_pagetable_setup_start(pgd_t *base)
355{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700356 (*pv_mmu_ops.pagetable_setup_start)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200357}
358
359static inline void paravirt_pagetable_setup_done(pgd_t *base)
360{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700361 (*pv_mmu_ops.pagetable_setup_done)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200362}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200363
Zachary Amsdenae5da272007-02-13 13:26:21 +0100364#ifdef CONFIG_SMP
365static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
366 unsigned long start_esp)
367{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700368 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
369 phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100370}
371#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100372
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200373static inline void paravirt_activate_mm(struct mm_struct *prev,
374 struct mm_struct *next)
375{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700376 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200377}
378
379static inline void arch_dup_mmap(struct mm_struct *oldmm,
380 struct mm_struct *mm)
381{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700382 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200383}
384
385static inline void arch_exit_mmap(struct mm_struct *mm)
386{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700387 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200388}
389
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200390static inline void __flush_tlb(void)
391{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700392 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200393}
394static inline void __flush_tlb_global(void)
395{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700396 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200397}
398static inline void __flush_tlb_single(unsigned long addr)
399{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700400 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200401}
Rusty Russellda181a82006-12-07 02:14:08 +0100402
Rusty Russell4595f962009-01-10 21:58:09 -0800403static inline void flush_tlb_others(const struct cpumask *cpumask,
404 struct mm_struct *mm,
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200405 unsigned long va)
406{
Rusty Russell4595f962009-01-10 21:58:09 -0800407 PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, cpumask, mm, va);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200408}
409
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -0400410static inline int paravirt_pgd_alloc(struct mm_struct *mm)
411{
412 return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
413}
414
415static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
416{
417 PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
418}
419
Eduardo Habkostf8639932008-07-30 18:32:27 -0300420static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200421{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700422 PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200423}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300424static inline void paravirt_release_pte(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_pte, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200427}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100428
Eduardo Habkostf8639932008-07-30 18:32:27 -0300429static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200430{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700431 PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200432}
433
Eduardo Habkostf8639932008-07-30 18:32:27 -0300434static inline void paravirt_alloc_pmd_clone(unsigned long pfn, unsigned long clonepfn,
435 unsigned long start, unsigned long count)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200436{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700437 PVOP_VCALL4(pv_mmu_ops.alloc_pmd_clone, pfn, clonepfn, start, count);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200438}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300439static inline void paravirt_release_pmd(unsigned long pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200440{
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700441 PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200442}
443
Eduardo Habkostf8639932008-07-30 18:32:27 -0300444static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700445{
446 PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
447}
Eduardo Habkostf8639932008-07-30 18:32:27 -0300448static inline void paravirt_release_pud(unsigned long pfn)
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700449{
450 PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
451}
452
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200453#ifdef CONFIG_HIGHPTE
454static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
455{
456 unsigned long ret;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700457 ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type);
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200458 return (void *)ret;
459}
460#endif
461
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200462static inline void pte_update(struct mm_struct *mm, unsigned long addr,
463 pte_t *ptep)
464{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700465 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200466}
467
468static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
469 pte_t *ptep)
470{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700471 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200472}
473
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100474static inline pte_t __pte(pteval_t val)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200475{
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100476 pteval_t ret;
477
478 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800479 ret = PVOP_CALLEE2(pteval_t,
480 pv_mmu_ops.make_pte,
481 val, (u64)val >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100482 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800483 ret = PVOP_CALLEE1(pteval_t,
484 pv_mmu_ops.make_pte,
485 val);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100486
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100487 return (pte_t) { .pte = ret };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200488}
489
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100490static inline pteval_t pte_val(pte_t pte)
491{
492 pteval_t ret;
493
494 if (sizeof(pteval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800495 ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
496 pte.pte, (u64)pte.pte >> 32);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100497 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800498 ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
499 pte.pte);
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100500
501 return ret;
502}
503
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100504static inline pgd_t __pgd(pgdval_t val)
505{
506 pgdval_t ret;
507
508 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800509 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
510 val, (u64)val >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100511 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800512 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
513 val);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100514
515 return (pgd_t) { ret };
516}
517
518static inline pgdval_t pgd_val(pgd_t pgd)
519{
520 pgdval_t ret;
521
522 if (sizeof(pgdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800523 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
524 pgd.pgd, (u64)pgd.pgd >> 32);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100525 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800526 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
527 pgd.pgd);
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100528
529 return ret;
530}
531
Jeremy Fitzhardinge08b882c2008-06-16 04:30:01 -0700532#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
533static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
534 pte_t *ptep)
535{
536 pteval_t ret;
537
538 ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
539 mm, addr, ptep);
540
541 return (pte_t) { .pte = ret };
542}
543
544static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
545 pte_t *ptep, pte_t pte)
546{
547 if (sizeof(pteval_t) > sizeof(long))
548 /* 5 arg words */
549 pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
550 else
551 PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
552 mm, addr, ptep, pte.pte);
553}
554
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100555static inline void set_pte(pte_t *ptep, pte_t pte)
556{
557 if (sizeof(pteval_t) > sizeof(long))
558 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
559 pte.pte, (u64)pte.pte >> 32);
560 else
561 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
562 pte.pte);
563}
564
565static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
566 pte_t *ptep, pte_t pte)
567{
568 if (sizeof(pteval_t) > sizeof(long))
569 /* 5 arg words */
570 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
571 else
572 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
573}
574
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100575static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
576{
577 pmdval_t val = native_pmd_val(pmd);
578
579 if (sizeof(pmdval_t) > sizeof(long))
580 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
581 else
582 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
583}
584
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100585#if PAGETABLE_LEVELS >= 3
586static inline pmd_t __pmd(pmdval_t val)
587{
588 pmdval_t ret;
589
590 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800591 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
592 val, (u64)val >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100593 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800594 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
595 val);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100596
597 return (pmd_t) { ret };
598}
599
600static inline pmdval_t pmd_val(pmd_t pmd)
601{
602 pmdval_t ret;
603
604 if (sizeof(pmdval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800605 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
606 pmd.pmd, (u64)pmd.pmd >> 32);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100607 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800608 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
609 pmd.pmd);
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100610
611 return ret;
612}
613
614static inline void set_pud(pud_t *pudp, pud_t pud)
615{
616 pudval_t val = native_pud_val(pud);
617
618 if (sizeof(pudval_t) > sizeof(long))
619 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
620 val, (u64)val >> 32);
621 else
622 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
623 val);
624}
Eduardo Habkost90422192008-01-30 13:33:20 +0100625#if PAGETABLE_LEVELS == 4
626static inline pud_t __pud(pudval_t val)
627{
628 pudval_t ret;
629
630 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800631 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
632 val, (u64)val >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100633 else
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800634 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
635 val);
Eduardo Habkost90422192008-01-30 13:33:20 +0100636
637 return (pud_t) { ret };
638}
639
640static inline pudval_t pud_val(pud_t pud)
641{
642 pudval_t ret;
643
644 if (sizeof(pudval_t) > sizeof(long))
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800645 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
646 pud.pud, (u64)pud.pud >> 32);
Eduardo Habkost90422192008-01-30 13:33:20 +0100647 else
Jeremy Fitzhardinge4767afb2009-01-29 01:51:34 -0800648 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
649 pud.pud);
Eduardo Habkost90422192008-01-30 13:33:20 +0100650
651 return ret;
652}
653
654static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
655{
656 pgdval_t val = native_pgd_val(pgd);
657
658 if (sizeof(pgdval_t) > sizeof(long))
659 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
660 val, (u64)val >> 32);
661 else
662 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
663 val);
664}
665
666static inline void pgd_clear(pgd_t *pgdp)
667{
668 set_pgd(pgdp, __pgd(0));
669}
670
671static inline void pud_clear(pud_t *pudp)
672{
673 set_pud(pudp, __pud(0));
674}
675
676#endif /* PAGETABLE_LEVELS == 4 */
677
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +0100678#endif /* PAGETABLE_LEVELS >= 3 */
679
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100680#ifdef CONFIG_X86_PAE
681/* Special-case pte-setting operations for PAE, which can't update a
682 64-bit pte atomically */
683static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
684{
685 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
686 pte.pte, pte.pte >> 32);
687}
688
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100689static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
690 pte_t *ptep)
691{
692 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
693}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100694
695static inline void pmd_clear(pmd_t *pmdp)
696{
697 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
698}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100699#else /* !CONFIG_X86_PAE */
700static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
701{
702 set_pte(ptep, pte);
703}
704
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100705static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
706 pte_t *ptep)
707{
708 set_pte_at(mm, addr, ptep, __pte(0));
709}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +0100710
711static inline void pmd_clear(pmd_t *pmdp)
712{
713 set_pmd(pmdp, __pmd(0));
714}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +0100715#endif /* CONFIG_X86_PAE */
716
Jeremy Fitzhardinge7fd7d832009-02-17 23:24:03 -0800717#define __HAVE_ARCH_START_CONTEXT_SWITCH
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800718static inline void arch_start_context_switch(struct task_struct *prev)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200719{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800720 PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200721}
722
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800723static inline void arch_end_context_switch(struct task_struct *next)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200724{
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800725 PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200726}
727
Zachary Amsden9226d122007-02-13 13:26:21 +0100728#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200729static inline void arch_enter_lazy_mmu_mode(void)
730{
Jeremy Fitzhardinge8965c1c02007-10-16 11:51:29 -0700731 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200732}
733
734static inline void arch_leave_lazy_mmu_mode(void)
735{
Jeremy Fitzhardinge8965c1c02007-10-16 11:51:29 -0700736 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200737}
738
Jeremy Fitzhardinged85cf932009-02-12 10:02:56 -0800739void arch_flush_lazy_mmu_mode(void);
Zachary Amsden9226d122007-02-13 13:26:21 +0100740
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700741static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
Masami Hiramatsu3b3809a2009-04-09 10:55:33 -0700742 phys_addr_t phys, pgprot_t flags)
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700743{
744 pv_mmu_ops.set_fixmap(idx, phys, flags);
745}
746
Jeremy Fitzhardingeb4ecc122009-05-13 17:16:55 -0700747#if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200748
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700749static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
750{
751 return PVOP_CALL1(int, pv_lock_ops.spin_is_locked, lock);
752}
753
754static inline int __raw_spin_is_contended(struct raw_spinlock *lock)
755{
756 return PVOP_CALL1(int, pv_lock_ops.spin_is_contended, lock);
757}
Kyle McMartina5ef7ca2009-02-08 17:39:58 -0500758#define __raw_spin_is_contended __raw_spin_is_contended
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700759
760static __always_inline void __raw_spin_lock(struct raw_spinlock *lock)
761{
Harvey Harrison32172562008-07-17 14:22:34 -0700762 PVOP_VCALL1(pv_lock_ops.spin_lock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700763}
764
Jeremy Fitzhardinge63d3a752008-08-19 13:19:36 -0700765static __always_inline void __raw_spin_lock_flags(struct raw_spinlock *lock,
766 unsigned long flags)
767{
768 PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags);
769}
770
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700771static __always_inline int __raw_spin_trylock(struct raw_spinlock *lock)
772{
773 return PVOP_CALL1(int, pv_lock_ops.spin_trylock, lock);
774}
775
776static __always_inline void __raw_spin_unlock(struct raw_spinlock *lock)
777{
Harvey Harrison32172562008-07-17 14:22:34 -0700778 PVOP_VCALL1(pv_lock_ops.spin_unlock, lock);
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700779}
780
Ingo Molnar4bb689e2008-07-09 14:33:33 +0200781#endif
782
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100783#ifdef CONFIG_X86_32
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800784#define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
785#define PV_RESTORE_REGS "popl %edx; popl %ecx;"
786
787/* save and restore all caller-save registers, except return value */
Jeremy Fitzhardingee584f552009-01-30 23:17:23 -0800788#define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
789#define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800790
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100791#define PV_FLAGS_ARG "0"
792#define PV_EXTRA_CLOBBERS
793#define PV_VEXTRA_CLOBBERS
794#else
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800795/* save and restore all caller-save registers, except return value */
796#define PV_SAVE_ALL_CALLER_REGS \
797 "push %rcx;" \
798 "push %rdx;" \
799 "push %rsi;" \
800 "push %rdi;" \
801 "push %r8;" \
802 "push %r9;" \
803 "push %r10;" \
804 "push %r11;"
805#define PV_RESTORE_ALL_CALLER_REGS \
806 "pop %r11;" \
807 "pop %r10;" \
808 "pop %r9;" \
809 "pop %r8;" \
810 "pop %rdi;" \
811 "pop %rsi;" \
812 "pop %rdx;" \
813 "pop %rcx;"
814
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100815/* We save some registers, but all of them, that's too much. We clobber all
816 * caller saved registers but the argument parameter */
817#define PV_SAVE_REGS "pushq %%rdi;"
818#define PV_RESTORE_REGS "popq %%rdi;"
Jeremy Fitzhardingec24481e2008-07-08 15:07:12 -0700819#define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
820#define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100821#define PV_FLAGS_ARG "D"
822#endif
823
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800824/*
825 * Generate a thunk around a function which saves all caller-save
826 * registers except for the return value. This allows C functions to
827 * be called from assembler code where fewer than normal registers are
828 * available. It may also help code generation around calls from C
829 * code if the common case doesn't use many registers.
830 *
831 * When a callee is wrapped in a thunk, the caller can assume that all
832 * arg regs and all scratch registers are preserved across the
833 * call. The return value in rax/eax will not be saved, even for void
834 * functions.
835 */
836#define PV_CALLEE_SAVE_REGS_THUNK(func) \
837 extern typeof(func) __raw_callee_save_##func; \
838 static void *__##func##__ __used = func; \
839 \
840 asm(".pushsection .text;" \
841 "__raw_callee_save_" #func ": " \
842 PV_SAVE_ALL_CALLER_REGS \
843 "call " #func ";" \
844 PV_RESTORE_ALL_CALLER_REGS \
845 "ret;" \
846 ".popsection")
847
848/* Get a reference to a callee-save function */
849#define PV_CALLEE_SAVE(func) \
850 ((struct paravirt_callee_save) { __raw_callee_save_##func })
851
852/* Promise that "func" already uses the right calling convention */
853#define __PV_IS_CALLEE_SAVE(func) \
854 ((struct paravirt_callee_save) { func })
855
Rusty Russell139ec7c2006-12-07 02:14:08 +0100856static inline unsigned long __raw_local_save_flags(void)
857{
858 unsigned long f;
859
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800860 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200861 : "=a"(f)
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700862 : paravirt_type(pv_irq_ops.save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200863 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800864 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100865 return f;
866}
867
868static inline void raw_local_irq_restore(unsigned long f)
869{
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800870 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200871 : "=a"(f)
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +0100872 : PV_FLAGS_ARG(f),
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700873 paravirt_type(pv_irq_ops.restore_fl),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200874 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800875 : "memory", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100876}
877
878static inline void raw_local_irq_disable(void)
879{
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800880 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200881 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700882 : paravirt_type(pv_irq_ops.irq_disable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200883 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800884 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100885}
886
887static inline void raw_local_irq_enable(void)
888{
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800889 asm volatile(paravirt_alt(PARAVIRT_CALL)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200890 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700891 : paravirt_type(pv_irq_ops.irq_enable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200892 paravirt_clobber(CLBR_EAX)
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800893 : "memory", "eax", "cc");
Rusty Russell139ec7c2006-12-07 02:14:08 +0100894}
895
896static inline unsigned long __raw_local_irq_save(void)
897{
898 unsigned long f;
899
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200900 f = __raw_local_save_flags();
901 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +0100902 return f;
903}
904
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700905
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200906/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200907#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200908#undef __PVOP_CALL
909#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200910#undef PVOP_VCALL0
911#undef PVOP_CALL0
912#undef PVOP_VCALL1
913#undef PVOP_CALL1
914#undef PVOP_VCALL2
915#undef PVOP_CALL2
916#undef PVOP_VCALL3
917#undef PVOP_CALL3
918#undef PVOP_VCALL4
919#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100920
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +0200921extern void default_banner(void);
922
Rusty Russelld3561b72006-12-07 02:14:07 +0100923#else /* __ASSEMBLY__ */
924
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100925#define _PVSITE(ptype, clobbers, ops, word, algn) \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100926771:; \
927 ops; \
928772:; \
929 .pushsection .parainstructions,"a"; \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100930 .align algn; \
931 word 771b; \
Rusty Russell139ec7c2006-12-07 02:14:08 +0100932 .byte ptype; \
933 .byte 772b-771b; \
934 .short clobbers; \
935 .popsection
936
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100937
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800938#define COND_PUSH(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800939 .if ((~(set)) & mask); push %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800940#define COND_POP(set, mask, reg) \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800941 .if ((~(set)) & mask); pop %reg; .endif
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800942
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100943#ifdef CONFIG_X86_64
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800944
945#define PV_SAVE_REGS(set) \
946 COND_PUSH(set, CLBR_RAX, rax); \
947 COND_PUSH(set, CLBR_RCX, rcx); \
948 COND_PUSH(set, CLBR_RDX, rdx); \
949 COND_PUSH(set, CLBR_RSI, rsi); \
950 COND_PUSH(set, CLBR_RDI, rdi); \
951 COND_PUSH(set, CLBR_R8, r8); \
952 COND_PUSH(set, CLBR_R9, r9); \
953 COND_PUSH(set, CLBR_R10, r10); \
954 COND_PUSH(set, CLBR_R11, r11)
955#define PV_RESTORE_REGS(set) \
956 COND_POP(set, CLBR_R11, r11); \
957 COND_POP(set, CLBR_R10, r10); \
958 COND_POP(set, CLBR_R9, r9); \
959 COND_POP(set, CLBR_R8, r8); \
960 COND_POP(set, CLBR_RDI, rdi); \
961 COND_POP(set, CLBR_RSI, rsi); \
962 COND_POP(set, CLBR_RDX, rdx); \
963 COND_POP(set, CLBR_RCX, rcx); \
964 COND_POP(set, CLBR_RAX, rax)
965
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100966#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100967#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400968#define PARA_INDIRECT(addr) *addr(%rip)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100969#else
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -0800970#define PV_SAVE_REGS(set) \
971 COND_PUSH(set, CLBR_EAX, eax); \
972 COND_PUSH(set, CLBR_EDI, edi); \
973 COND_PUSH(set, CLBR_ECX, ecx); \
974 COND_PUSH(set, CLBR_EDX, edx)
975#define PV_RESTORE_REGS(set) \
976 COND_POP(set, CLBR_EDX, edx); \
977 COND_POP(set, CLBR_ECX, ecx); \
978 COND_POP(set, CLBR_EDI, edi); \
979 COND_POP(set, CLBR_EAX, eax)
980
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +0100981#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100982#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400983#define PARA_INDIRECT(addr) *%cs:addr
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100984#endif
985
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700986#define INTERRUPT_RETURN \
987 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400988 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
Rusty Russell139ec7c2006-12-07 02:14:08 +0100989
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200990#define DISABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700991 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800992 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400993 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800994 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100995
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200996#define ENABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700997 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800998 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -0400999 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -08001000 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001001
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001002#define USERGS_SYSRET32 \
1003 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +01001004 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001005 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001006
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001007#ifdef CONFIG_X86_32
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001008#define GET_CR0_INTO_EAX \
1009 push %ecx; push %edx; \
1010 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001011 pop %edx; pop %ecx
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001012
1013#define ENABLE_INTERRUPTS_SYSEXIT \
1014 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1015 CLBR_NONE, \
1016 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1017
1018
1019#else /* !CONFIG_X86_32 */
Jeremy Fitzhardingea00394f2008-06-25 00:19:30 -04001020
1021/*
1022 * If swapgs is used while the userspace stack is still current,
1023 * there's no way to call a pvop. The PV replacement *must* be
1024 * inlined, or the swapgs instruction must be trapped and emulated.
1025 */
1026#define SWAPGS_UNSAFE_STACK \
1027 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1028 swapgs)
1029
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001030/*
1031 * Note: swapgs is very special, and in practise is either going to be
1032 * implemented with a single "swapgs" instruction or something very
1033 * special. Either way, we don't need to save any registers for
1034 * it.
1035 */
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001036#define SWAPGS \
1037 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
Jeremy Fitzhardinge9104a182009-01-28 14:35:04 -08001038 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001039 )
1040
Jeremy Fitzhardinge491eccb2008-06-25 00:19:15 -04001041#define GET_CR2_INTO_RCX \
1042 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \
1043 movq %rax, %rcx; \
Glauber de Oliveira Costa4a8c4c42008-01-30 13:32:07 +01001044 xorq %rax, %rax;
1045
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -04001046#define PARAVIRT_ADJUST_EXCEPTION_FRAME \
1047 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
1048 CLBR_NONE, \
1049 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
1050
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001051#define USERGS_SYSRET64 \
1052 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -04001053 CLBR_NONE, \
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -04001054 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
1055
1056#define ENABLE_INTERRUPTS_SYSEXIT32 \
1057 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1058 CLBR_NONE, \
1059 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1060#endif /* CONFIG_X86_32 */
Rusty Russell139ec7c2006-12-07 02:14:08 +01001061
Rusty Russelld3561b72006-12-07 02:14:07 +01001062#endif /* __ASSEMBLY__ */
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +02001063#else /* CONFIG_PARAVIRT */
1064# define default_banner x86_init_noop
1065#endif /* !CONFIG_PARAVIRT */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001066#endif /* _ASM_X86_PARAVIRT_H */