H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_PARAVIRT_H |
| 2 | #define _ASM_X86_PARAVIRT_H |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 3 | /* Various instructions on x86 need to be replaced for |
| 4 | * para-virtualization: those hooks are defined here. */ |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 5 | |
| 6 | #ifdef CONFIG_PARAVIRT |
Jeremy Fitzhardinge | 54321d9 | 2009-02-11 10:20:05 -0800 | [diff] [blame] | 7 | #include <asm/pgtable_types.h> |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 8 | #include <asm/asm.h> |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 9 | |
Jeremy Fitzhardinge | ac5672f | 2009-04-14 14:29:44 -0700 | [diff] [blame] | 10 | #include <asm/paravirt_types.h> |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 11 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 12 | #ifndef __ASSEMBLY__ |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 13 | #include <linux/types.h> |
Jeremy Fitzhardinge | d4c1047 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 14 | #include <linux/cpumask.h> |
Jeremy Fitzhardinge | 1a45b7a | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 15 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 16 | static inline int paravirt_enabled(void) |
| 17 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 18 | return pv_info.paravirt_enabled; |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 19 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 20 | |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 21 | static inline void load_sp0(struct tss_struct *tss, |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 22 | struct thread_struct *thread) |
| 23 | { |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 24 | PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 25 | } |
| 26 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 27 | #define ARCH_SETUP pv_init_ops.arch_setup(); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 28 | static inline unsigned long get_wallclock(void) |
| 29 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 30 | return PVOP_CALL0(unsigned long, pv_time_ops.get_wallclock); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static inline int set_wallclock(unsigned long nowtime) |
| 34 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 35 | return PVOP_CALL1(int, pv_time_ops.set_wallclock, nowtime); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Zachary Amsden | e30fab3 | 2007-03-05 00:30:39 -0800 | [diff] [blame] | 38 | static inline void (*choose_time_init(void))(void) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 39 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 40 | return pv_time_ops.time_init; |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /* The paravirtualized CPUID instruction. */ |
| 44 | static inline void __cpuid(unsigned int *eax, unsigned int *ebx, |
| 45 | unsigned int *ecx, unsigned int *edx) |
| 46 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 47 | PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* |
| 51 | * These special macros can be used to get or set a debugging register |
| 52 | */ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 53 | static inline unsigned long paravirt_get_debugreg(int reg) |
| 54 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 55 | return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 56 | } |
| 57 | #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg) |
| 58 | static inline void set_debugreg(unsigned long val, int reg) |
| 59 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 60 | PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 61 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 62 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 63 | static inline void clts(void) |
| 64 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 65 | PVOP_VCALL0(pv_cpu_ops.clts); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 66 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 67 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 68 | static inline unsigned long read_cr0(void) |
| 69 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 70 | return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 71 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 72 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 73 | static inline void write_cr0(unsigned long x) |
| 74 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 75 | PVOP_VCALL1(pv_cpu_ops.write_cr0, x); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 76 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 77 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 78 | static inline unsigned long read_cr2(void) |
| 79 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 80 | return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 81 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 82 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 83 | static inline void write_cr2(unsigned long x) |
| 84 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 85 | PVOP_VCALL1(pv_mmu_ops.write_cr2, x); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 86 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 87 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 88 | static inline unsigned long read_cr3(void) |
| 89 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 90 | return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static inline void write_cr3(unsigned long x) |
| 94 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 95 | PVOP_VCALL1(pv_mmu_ops.write_cr3, x); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static inline unsigned long read_cr4(void) |
| 99 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 100 | return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 101 | } |
| 102 | static inline unsigned long read_cr4_safe(void) |
| 103 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 104 | return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static inline void write_cr4(unsigned long x) |
| 108 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 109 | PVOP_VCALL1(pv_cpu_ops.write_cr4, x); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 110 | } |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 111 | |
Glauber de Oliveira Costa | 94ea03c | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 112 | #ifdef CONFIG_X86_64 |
Glauber de Oliveira Costa | 4c9890c | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 113 | static inline unsigned long read_cr8(void) |
| 114 | { |
| 115 | return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8); |
| 116 | } |
| 117 | |
| 118 | static inline void write_cr8(unsigned long x) |
| 119 | { |
| 120 | PVOP_VCALL1(pv_cpu_ops.write_cr8, x); |
| 121 | } |
Glauber de Oliveira Costa | 94ea03c | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 122 | #endif |
Glauber de Oliveira Costa | 4c9890c | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 123 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 124 | static inline void raw_safe_halt(void) |
| 125 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 126 | PVOP_VCALL0(pv_irq_ops.safe_halt); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static inline void halt(void) |
| 130 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 131 | PVOP_VCALL0(pv_irq_ops.safe_halt); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 132 | } |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 133 | |
| 134 | static inline void wbinvd(void) |
| 135 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 136 | PVOP_VCALL0(pv_cpu_ops.wbinvd); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 137 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 138 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 139 | #define get_kernel_rpl() (pv_info.kernel_rpl) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 140 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 141 | static inline u64 paravirt_read_msr(unsigned msr, int *err) |
| 142 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 143 | return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 144 | } |
Borislav Petkov | 132ec92 | 2009-08-31 09:50:09 +0200 | [diff] [blame] | 145 | |
| 146 | static inline int paravirt_rdmsr_regs(u32 *regs) |
| 147 | { |
| 148 | return PVOP_CALL1(int, pv_cpu_ops.rdmsr_regs, regs); |
| 149 | } |
| 150 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 151 | static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high) |
| 152 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 153 | return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Borislav Petkov | 132ec92 | 2009-08-31 09:50:09 +0200 | [diff] [blame] | 156 | static inline int paravirt_wrmsr_regs(u32 *regs) |
| 157 | { |
| 158 | return PVOP_CALL1(int, pv_cpu_ops.wrmsr_regs, regs); |
| 159 | } |
| 160 | |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 161 | /* These should all do BUG_ON(_err), but our headers are too tangled. */ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 162 | #define rdmsr(msr, val1, val2) \ |
| 163 | do { \ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 164 | int _err; \ |
| 165 | u64 _l = paravirt_read_msr(msr, &_err); \ |
| 166 | val1 = (u32)_l; \ |
| 167 | val2 = _l >> 32; \ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 168 | } while (0) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 169 | |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 170 | #define wrmsr(msr, val1, val2) \ |
| 171 | do { \ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 172 | paravirt_write_msr(msr, val1, val2); \ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 173 | } while (0) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 174 | |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 175 | #define rdmsrl(msr, val) \ |
| 176 | do { \ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 177 | int _err; \ |
| 178 | val = paravirt_read_msr(msr, &_err); \ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 179 | } while (0) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 180 | |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 181 | #define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32) |
| 182 | #define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 183 | |
| 184 | /* rdmsr with exception handling */ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 185 | #define rdmsr_safe(msr, a, b) \ |
| 186 | ({ \ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 187 | int _err; \ |
| 188 | u64 _l = paravirt_read_msr(msr, &_err); \ |
| 189 | (*a) = (u32)_l; \ |
| 190 | (*b) = _l >> 32; \ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 191 | _err; \ |
| 192 | }) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 193 | |
Borislav Petkov | 132ec92 | 2009-08-31 09:50:09 +0200 | [diff] [blame] | 194 | #define rdmsr_safe_regs(regs) paravirt_rdmsr_regs(regs) |
| 195 | #define wrmsr_safe_regs(regs) paravirt_wrmsr_regs(regs) |
| 196 | |
Andi Kleen | 1de87bd | 2008-03-22 10:59:28 +0100 | [diff] [blame] | 197 | static inline int rdmsrl_safe(unsigned msr, unsigned long long *p) |
| 198 | { |
| 199 | int err; |
| 200 | |
| 201 | *p = paravirt_read_msr(msr, &err); |
| 202 | return err; |
| 203 | } |
Yinghai Lu | b05f78f | 2008-08-22 01:32:50 -0700 | [diff] [blame] | 204 | static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p) |
| 205 | { |
Borislav Petkov | 177fed1 | 2009-08-31 09:50:10 +0200 | [diff] [blame] | 206 | u32 gprs[8] = { 0 }; |
Yinghai Lu | b05f78f | 2008-08-22 01:32:50 -0700 | [diff] [blame] | 207 | int err; |
| 208 | |
Borislav Petkov | 177fed1 | 2009-08-31 09:50:10 +0200 | [diff] [blame] | 209 | gprs[1] = msr; |
| 210 | gprs[7] = 0x9c5a203a; |
| 211 | |
| 212 | err = paravirt_rdmsr_regs(gprs); |
| 213 | |
| 214 | *p = gprs[0] | ((u64)gprs[2] << 32); |
| 215 | |
Yinghai Lu | b05f78f | 2008-08-22 01:32:50 -0700 | [diff] [blame] | 216 | return err; |
| 217 | } |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 218 | |
Borislav Petkov | 177fed1 | 2009-08-31 09:50:10 +0200 | [diff] [blame] | 219 | static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val) |
| 220 | { |
| 221 | u32 gprs[8] = { 0 }; |
| 222 | |
| 223 | gprs[0] = (u32)val; |
| 224 | gprs[1] = msr; |
| 225 | gprs[2] = val >> 32; |
| 226 | gprs[7] = 0x9c5a203a; |
| 227 | |
| 228 | return paravirt_wrmsr_regs(gprs); |
| 229 | } |
| 230 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 231 | static inline u64 paravirt_read_tsc(void) |
| 232 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 233 | return PVOP_CALL0(u64, pv_cpu_ops.read_tsc); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 234 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 235 | |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 236 | #define rdtscl(low) \ |
| 237 | do { \ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 238 | u64 _l = paravirt_read_tsc(); \ |
| 239 | low = (int)_l; \ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 240 | } while (0) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 241 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 242 | #define rdtscll(val) (val = paravirt_read_tsc()) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 243 | |
Jeremy Fitzhardinge | 688340e | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 244 | static inline unsigned long long paravirt_sched_clock(void) |
| 245 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 246 | return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock); |
Jeremy Fitzhardinge | 688340e | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 247 | } |
Alok Kataria | e93ef94 | 2008-07-01 11:43:36 -0700 | [diff] [blame] | 248 | #define calibrate_tsc() (pv_time_ops.get_tsc_khz()) |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 249 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 250 | static inline unsigned long long paravirt_read_pmc(int counter) |
| 251 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 252 | return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 255 | #define rdpmc(counter, low, high) \ |
| 256 | do { \ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 257 | u64 _l = paravirt_read_pmc(counter); \ |
| 258 | low = (u32)_l; \ |
| 259 | high = _l >> 32; \ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 260 | } while (0) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 261 | |
Glauber de Oliveira Costa | e5aaac4 | 2008-01-30 13:32:05 +0100 | [diff] [blame] | 262 | static inline unsigned long long paravirt_rdtscp(unsigned int *aux) |
| 263 | { |
| 264 | return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux); |
| 265 | } |
| 266 | |
| 267 | #define rdtscp(low, high, aux) \ |
| 268 | do { \ |
| 269 | int __aux; \ |
| 270 | unsigned long __val = paravirt_rdtscp(&__aux); \ |
| 271 | (low) = (u32)__val; \ |
| 272 | (high) = (u32)(__val >> 32); \ |
| 273 | (aux) = __aux; \ |
| 274 | } while (0) |
| 275 | |
| 276 | #define rdtscpll(val, aux) \ |
| 277 | do { \ |
| 278 | unsigned long __aux; \ |
| 279 | val = paravirt_rdtscp(&__aux); \ |
| 280 | (aux) = __aux; \ |
| 281 | } while (0) |
| 282 | |
Jeremy Fitzhardinge | 38ffbe6 | 2008-07-23 14:21:18 -0700 | [diff] [blame] | 283 | static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries) |
| 284 | { |
| 285 | PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries); |
| 286 | } |
| 287 | |
| 288 | static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries) |
| 289 | { |
| 290 | PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries); |
| 291 | } |
| 292 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 293 | static inline void load_TR_desc(void) |
| 294 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 295 | PVOP_VCALL0(pv_cpu_ops.load_tr_desc); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 296 | } |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 297 | static inline void load_gdt(const struct desc_ptr *dtr) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 298 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 299 | PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 300 | } |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 301 | static inline void load_idt(const struct desc_ptr *dtr) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 302 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 303 | PVOP_VCALL1(pv_cpu_ops.load_idt, dtr); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 304 | } |
| 305 | static inline void set_ldt(const void *addr, unsigned entries) |
| 306 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 307 | PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 308 | } |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 309 | static inline void store_gdt(struct desc_ptr *dtr) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 310 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 311 | PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 312 | } |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 313 | static inline void store_idt(struct desc_ptr *dtr) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 314 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 315 | PVOP_VCALL1(pv_cpu_ops.store_idt, dtr); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 316 | } |
| 317 | static inline unsigned long paravirt_store_tr(void) |
| 318 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 319 | return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 320 | } |
| 321 | #define store_tr(tr) ((tr) = paravirt_store_tr()) |
| 322 | static inline void load_TLS(struct thread_struct *t, unsigned cpu) |
| 323 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 324 | PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 325 | } |
Glauber de Oliveira Costa | 75b8bb3 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 326 | |
Jeremy Fitzhardinge | 9f9d489 | 2008-06-25 00:19:32 -0400 | [diff] [blame] | 327 | #ifdef CONFIG_X86_64 |
| 328 | static inline void load_gs_index(unsigned int gs) |
| 329 | { |
| 330 | PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs); |
| 331 | } |
| 332 | #endif |
| 333 | |
Glauber de Oliveira Costa | 75b8bb3 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 334 | static inline void write_ldt_entry(struct desc_struct *dt, int entry, |
| 335 | const void *desc) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 336 | { |
Glauber de Oliveira Costa | 75b8bb3 | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 337 | PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 338 | } |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 339 | |
| 340 | static inline void write_gdt_entry(struct desc_struct *dt, int entry, |
| 341 | void *desc, int type) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 342 | { |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 343 | PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 344 | } |
Glauber de Oliveira Costa | 014b15b | 2008-01-30 13:31:13 +0100 | [diff] [blame] | 345 | |
Glauber de Oliveira Costa | 8d94734 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 346 | static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 347 | { |
Glauber de Oliveira Costa | 8d94734 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 348 | PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 349 | } |
| 350 | static inline void set_iopl_mask(unsigned mask) |
| 351 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 352 | PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 353 | } |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 354 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 355 | /* The paravirtualized I/O functions */ |
Joe Perches | 49cd740 | 2008-03-23 01:03:00 -0700 | [diff] [blame] | 356 | static inline void slow_down_io(void) |
| 357 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 358 | pv_cpu_ops.io_delay(); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 359 | #ifdef REALLY_SLOW_IO |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 360 | pv_cpu_ops.io_delay(); |
| 361 | pv_cpu_ops.io_delay(); |
| 362 | pv_cpu_ops.io_delay(); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 363 | #endif |
| 364 | } |
| 365 | |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 366 | #ifdef CONFIG_X86_LOCAL_APIC |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 367 | static inline void setup_boot_clock(void) |
| 368 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 369 | PVOP_VCALL0(pv_apic_ops.setup_boot_clock); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static inline void setup_secondary_clock(void) |
| 373 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 374 | PVOP_VCALL0(pv_apic_ops.setup_secondary_clock); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 375 | } |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 376 | #endif |
| 377 | |
Jeremy Fitzhardinge | 6996d3b | 2007-07-17 18:37:03 -0700 | [diff] [blame] | 378 | static inline void paravirt_post_allocator_init(void) |
| 379 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 380 | if (pv_init_ops.post_allocator_init) |
| 381 | (*pv_init_ops.post_allocator_init)(); |
Jeremy Fitzhardinge | 6996d3b | 2007-07-17 18:37:03 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 384 | static inline void paravirt_pagetable_setup_start(pgd_t *base) |
| 385 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 386 | (*pv_mmu_ops.pagetable_setup_start)(base); |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static inline void paravirt_pagetable_setup_done(pgd_t *base) |
| 390 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 391 | (*pv_mmu_ops.pagetable_setup_done)(base); |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 392 | } |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 393 | |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 394 | #ifdef CONFIG_SMP |
| 395 | static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip, |
| 396 | unsigned long start_esp) |
| 397 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 398 | PVOP_VCALL3(pv_apic_ops.startup_ipi_hook, |
| 399 | phys_apicid, start_eip, start_esp); |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 400 | } |
| 401 | #endif |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 402 | |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 403 | static inline void paravirt_activate_mm(struct mm_struct *prev, |
| 404 | struct mm_struct *next) |
| 405 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 406 | PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next); |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static inline void arch_dup_mmap(struct mm_struct *oldmm, |
| 410 | struct mm_struct *mm) |
| 411 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 412 | PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm); |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static inline void arch_exit_mmap(struct mm_struct *mm) |
| 416 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 417 | PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm); |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 420 | static inline void __flush_tlb(void) |
| 421 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 422 | PVOP_VCALL0(pv_mmu_ops.flush_tlb_user); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 423 | } |
| 424 | static inline void __flush_tlb_global(void) |
| 425 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 426 | PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 427 | } |
| 428 | static inline void __flush_tlb_single(unsigned long addr) |
| 429 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 430 | PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 431 | } |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 432 | |
Rusty Russell | 4595f96 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 433 | static inline void flush_tlb_others(const struct cpumask *cpumask, |
| 434 | struct mm_struct *mm, |
Jeremy Fitzhardinge | d4c1047 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 435 | unsigned long va) |
| 436 | { |
Rusty Russell | 4595f96 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 437 | PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, cpumask, mm, va); |
Jeremy Fitzhardinge | d4c1047 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 438 | } |
| 439 | |
Jeremy Fitzhardinge | eba0045 | 2008-06-25 00:19:12 -0400 | [diff] [blame] | 440 | static inline int paravirt_pgd_alloc(struct mm_struct *mm) |
| 441 | { |
| 442 | return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm); |
| 443 | } |
| 444 | |
| 445 | static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd) |
| 446 | { |
| 447 | PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd); |
| 448 | } |
| 449 | |
Eduardo Habkost | f863993 | 2008-07-30 18:32:27 -0300 | [diff] [blame] | 450 | static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 451 | { |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 452 | PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 453 | } |
Eduardo Habkost | f863993 | 2008-07-30 18:32:27 -0300 | [diff] [blame] | 454 | static inline void paravirt_release_pte(unsigned long pfn) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 455 | { |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 456 | PVOP_VCALL1(pv_mmu_ops.release_pte, pfn); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 457 | } |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 458 | |
Eduardo Habkost | f863993 | 2008-07-30 18:32:27 -0300 | [diff] [blame] | 459 | static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 460 | { |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 461 | PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 462 | } |
| 463 | |
Eduardo Habkost | f863993 | 2008-07-30 18:32:27 -0300 | [diff] [blame] | 464 | static inline void paravirt_alloc_pmd_clone(unsigned long pfn, unsigned long clonepfn, |
| 465 | unsigned long start, unsigned long count) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 466 | { |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 467 | PVOP_VCALL4(pv_mmu_ops.alloc_pmd_clone, pfn, clonepfn, start, count); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 468 | } |
Eduardo Habkost | f863993 | 2008-07-30 18:32:27 -0300 | [diff] [blame] | 469 | static inline void paravirt_release_pmd(unsigned long pfn) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 470 | { |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 471 | PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 472 | } |
| 473 | |
Eduardo Habkost | f863993 | 2008-07-30 18:32:27 -0300 | [diff] [blame] | 474 | static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn) |
Jeremy Fitzhardinge | 2761fa0 | 2008-03-17 16:37:02 -0700 | [diff] [blame] | 475 | { |
| 476 | PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn); |
| 477 | } |
Eduardo Habkost | f863993 | 2008-07-30 18:32:27 -0300 | [diff] [blame] | 478 | static inline void paravirt_release_pud(unsigned long pfn) |
Jeremy Fitzhardinge | 2761fa0 | 2008-03-17 16:37:02 -0700 | [diff] [blame] | 479 | { |
| 480 | PVOP_VCALL1(pv_mmu_ops.release_pud, pfn); |
| 481 | } |
| 482 | |
Jeremy Fitzhardinge | ce6234b | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 483 | #ifdef CONFIG_HIGHPTE |
| 484 | static inline void *kmap_atomic_pte(struct page *page, enum km_type type) |
| 485 | { |
| 486 | unsigned long ret; |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 487 | ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type); |
Jeremy Fitzhardinge | ce6234b | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 488 | return (void *)ret; |
| 489 | } |
| 490 | #endif |
| 491 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 492 | static inline void pte_update(struct mm_struct *mm, unsigned long addr, |
| 493 | pte_t *ptep) |
| 494 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 495 | PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr, |
| 499 | pte_t *ptep) |
| 500 | { |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 501 | PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 502 | } |
| 503 | |
Jeremy Fitzhardinge | 773221f | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 504 | static inline pte_t __pte(pteval_t val) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 505 | { |
Jeremy Fitzhardinge | 773221f | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 506 | pteval_t ret; |
| 507 | |
| 508 | if (sizeof(pteval_t) > sizeof(long)) |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 509 | ret = PVOP_CALLEE2(pteval_t, |
| 510 | pv_mmu_ops.make_pte, |
| 511 | val, (u64)val >> 32); |
Jeremy Fitzhardinge | 773221f | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 512 | else |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 513 | ret = PVOP_CALLEE1(pteval_t, |
| 514 | pv_mmu_ops.make_pte, |
| 515 | val); |
Jeremy Fitzhardinge | 773221f | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 516 | |
Jeremy Fitzhardinge | c8e5393 | 2008-01-30 13:32:57 +0100 | [diff] [blame] | 517 | return (pte_t) { .pte = ret }; |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Jeremy Fitzhardinge | 773221f | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 520 | static inline pteval_t pte_val(pte_t pte) |
| 521 | { |
| 522 | pteval_t ret; |
| 523 | |
| 524 | if (sizeof(pteval_t) > sizeof(long)) |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 525 | ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val, |
| 526 | pte.pte, (u64)pte.pte >> 32); |
Jeremy Fitzhardinge | 773221f | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 527 | else |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 528 | ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val, |
| 529 | pte.pte); |
Jeremy Fitzhardinge | 773221f | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 530 | |
| 531 | return ret; |
| 532 | } |
| 533 | |
Jeremy Fitzhardinge | ef38503 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 534 | static inline pgd_t __pgd(pgdval_t val) |
| 535 | { |
| 536 | pgdval_t ret; |
| 537 | |
| 538 | if (sizeof(pgdval_t) > sizeof(long)) |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 539 | ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd, |
| 540 | val, (u64)val >> 32); |
Jeremy Fitzhardinge | ef38503 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 541 | else |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 542 | ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd, |
| 543 | val); |
Jeremy Fitzhardinge | ef38503 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 544 | |
| 545 | return (pgd_t) { ret }; |
| 546 | } |
| 547 | |
| 548 | static inline pgdval_t pgd_val(pgd_t pgd) |
| 549 | { |
| 550 | pgdval_t ret; |
| 551 | |
| 552 | if (sizeof(pgdval_t) > sizeof(long)) |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 553 | ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val, |
| 554 | pgd.pgd, (u64)pgd.pgd >> 32); |
Jeremy Fitzhardinge | ef38503 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 555 | else |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 556 | ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val, |
| 557 | pgd.pgd); |
Jeremy Fitzhardinge | ef38503 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 558 | |
| 559 | return ret; |
| 560 | } |
| 561 | |
Jeremy Fitzhardinge | 08b882c | 2008-06-16 04:30:01 -0700 | [diff] [blame] | 562 | #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION |
| 563 | static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr, |
| 564 | pte_t *ptep) |
| 565 | { |
| 566 | pteval_t ret; |
| 567 | |
| 568 | ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start, |
| 569 | mm, addr, ptep); |
| 570 | |
| 571 | return (pte_t) { .pte = ret }; |
| 572 | } |
| 573 | |
| 574 | static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr, |
| 575 | pte_t *ptep, pte_t pte) |
| 576 | { |
| 577 | if (sizeof(pteval_t) > sizeof(long)) |
| 578 | /* 5 arg words */ |
| 579 | pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte); |
| 580 | else |
| 581 | PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit, |
| 582 | mm, addr, ptep, pte.pte); |
| 583 | } |
| 584 | |
Jeremy Fitzhardinge | 4eed80c | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 585 | static inline void set_pte(pte_t *ptep, pte_t pte) |
| 586 | { |
| 587 | if (sizeof(pteval_t) > sizeof(long)) |
| 588 | PVOP_VCALL3(pv_mmu_ops.set_pte, ptep, |
| 589 | pte.pte, (u64)pte.pte >> 32); |
| 590 | else |
| 591 | PVOP_VCALL2(pv_mmu_ops.set_pte, ptep, |
| 592 | pte.pte); |
| 593 | } |
| 594 | |
| 595 | static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 596 | pte_t *ptep, pte_t pte) |
| 597 | { |
| 598 | if (sizeof(pteval_t) > sizeof(long)) |
| 599 | /* 5 arg words */ |
| 600 | pv_mmu_ops.set_pte_at(mm, addr, ptep, pte); |
| 601 | else |
| 602 | PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte); |
| 603 | } |
| 604 | |
Jeremy Fitzhardinge | 60b3f62 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 605 | static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) |
| 606 | { |
| 607 | pmdval_t val = native_pmd_val(pmd); |
| 608 | |
| 609 | if (sizeof(pmdval_t) > sizeof(long)) |
| 610 | PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32); |
| 611 | else |
| 612 | PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val); |
| 613 | } |
| 614 | |
Glauber de Oliveira Costa | 1fe9151 | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 615 | #if PAGETABLE_LEVELS >= 3 |
| 616 | static inline pmd_t __pmd(pmdval_t val) |
| 617 | { |
| 618 | pmdval_t ret; |
| 619 | |
| 620 | if (sizeof(pmdval_t) > sizeof(long)) |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 621 | ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd, |
| 622 | val, (u64)val >> 32); |
Glauber de Oliveira Costa | 1fe9151 | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 623 | else |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 624 | ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd, |
| 625 | val); |
Glauber de Oliveira Costa | 1fe9151 | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 626 | |
| 627 | return (pmd_t) { ret }; |
| 628 | } |
| 629 | |
| 630 | static inline pmdval_t pmd_val(pmd_t pmd) |
| 631 | { |
| 632 | pmdval_t ret; |
| 633 | |
| 634 | if (sizeof(pmdval_t) > sizeof(long)) |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 635 | ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val, |
| 636 | pmd.pmd, (u64)pmd.pmd >> 32); |
Glauber de Oliveira Costa | 1fe9151 | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 637 | else |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 638 | ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val, |
| 639 | pmd.pmd); |
Glauber de Oliveira Costa | 1fe9151 | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 640 | |
| 641 | return ret; |
| 642 | } |
| 643 | |
| 644 | static inline void set_pud(pud_t *pudp, pud_t pud) |
| 645 | { |
| 646 | pudval_t val = native_pud_val(pud); |
| 647 | |
| 648 | if (sizeof(pudval_t) > sizeof(long)) |
| 649 | PVOP_VCALL3(pv_mmu_ops.set_pud, pudp, |
| 650 | val, (u64)val >> 32); |
| 651 | else |
| 652 | PVOP_VCALL2(pv_mmu_ops.set_pud, pudp, |
| 653 | val); |
| 654 | } |
Eduardo Habkost | 9042219 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 655 | #if PAGETABLE_LEVELS == 4 |
| 656 | static inline pud_t __pud(pudval_t val) |
| 657 | { |
| 658 | pudval_t ret; |
| 659 | |
| 660 | if (sizeof(pudval_t) > sizeof(long)) |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 661 | ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud, |
| 662 | val, (u64)val >> 32); |
Eduardo Habkost | 9042219 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 663 | else |
Jeremy Fitzhardinge | da5de7c | 2009-01-28 14:35:07 -0800 | [diff] [blame] | 664 | ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud, |
| 665 | val); |
Eduardo Habkost | 9042219 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 666 | |
| 667 | return (pud_t) { ret }; |
| 668 | } |
| 669 | |
| 670 | static inline pudval_t pud_val(pud_t pud) |
| 671 | { |
| 672 | pudval_t ret; |
| 673 | |
| 674 | if (sizeof(pudval_t) > sizeof(long)) |
Jeremy Fitzhardinge | 4767afb | 2009-01-29 01:51:34 -0800 | [diff] [blame] | 675 | ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val, |
| 676 | pud.pud, (u64)pud.pud >> 32); |
Eduardo Habkost | 9042219 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 677 | else |
Jeremy Fitzhardinge | 4767afb | 2009-01-29 01:51:34 -0800 | [diff] [blame] | 678 | ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val, |
| 679 | pud.pud); |
Eduardo Habkost | 9042219 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 680 | |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | static inline void set_pgd(pgd_t *pgdp, pgd_t pgd) |
| 685 | { |
| 686 | pgdval_t val = native_pgd_val(pgd); |
| 687 | |
| 688 | if (sizeof(pgdval_t) > sizeof(long)) |
| 689 | PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp, |
| 690 | val, (u64)val >> 32); |
| 691 | else |
| 692 | PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp, |
| 693 | val); |
| 694 | } |
| 695 | |
| 696 | static inline void pgd_clear(pgd_t *pgdp) |
| 697 | { |
| 698 | set_pgd(pgdp, __pgd(0)); |
| 699 | } |
| 700 | |
| 701 | static inline void pud_clear(pud_t *pudp) |
| 702 | { |
| 703 | set_pud(pudp, __pud(0)); |
| 704 | } |
| 705 | |
| 706 | #endif /* PAGETABLE_LEVELS == 4 */ |
| 707 | |
Glauber de Oliveira Costa | 1fe9151 | 2008-01-30 13:33:19 +0100 | [diff] [blame] | 708 | #endif /* PAGETABLE_LEVELS >= 3 */ |
| 709 | |
Jeremy Fitzhardinge | 4eed80c | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 710 | #ifdef CONFIG_X86_PAE |
| 711 | /* Special-case pte-setting operations for PAE, which can't update a |
| 712 | 64-bit pte atomically */ |
| 713 | static inline void set_pte_atomic(pte_t *ptep, pte_t pte) |
| 714 | { |
| 715 | PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep, |
| 716 | pte.pte, pte.pte >> 32); |
| 717 | } |
| 718 | |
Jeremy Fitzhardinge | 4eed80c | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 719 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, |
| 720 | pte_t *ptep) |
| 721 | { |
| 722 | PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep); |
| 723 | } |
Jeremy Fitzhardinge | 60b3f62 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 724 | |
| 725 | static inline void pmd_clear(pmd_t *pmdp) |
| 726 | { |
| 727 | PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp); |
| 728 | } |
Jeremy Fitzhardinge | 4eed80c | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 729 | #else /* !CONFIG_X86_PAE */ |
| 730 | static inline void set_pte_atomic(pte_t *ptep, pte_t pte) |
| 731 | { |
| 732 | set_pte(ptep, pte); |
| 733 | } |
| 734 | |
Jeremy Fitzhardinge | 4eed80c | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 735 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, |
| 736 | pte_t *ptep) |
| 737 | { |
| 738 | set_pte_at(mm, addr, ptep, __pte(0)); |
| 739 | } |
Jeremy Fitzhardinge | 60b3f62 | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 740 | |
| 741 | static inline void pmd_clear(pmd_t *pmdp) |
| 742 | { |
| 743 | set_pmd(pmdp, __pmd(0)); |
| 744 | } |
Jeremy Fitzhardinge | 4eed80c | 2008-01-30 13:33:15 +0100 | [diff] [blame] | 745 | #endif /* CONFIG_X86_PAE */ |
| 746 | |
Jeremy Fitzhardinge | 7fd7d83 | 2009-02-17 23:24:03 -0800 | [diff] [blame] | 747 | #define __HAVE_ARCH_START_CONTEXT_SWITCH |
Jeremy Fitzhardinge | 224101e | 2009-02-18 11:18:57 -0800 | [diff] [blame] | 748 | static inline void arch_start_context_switch(struct task_struct *prev) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 749 | { |
Jeremy Fitzhardinge | 224101e | 2009-02-18 11:18:57 -0800 | [diff] [blame] | 750 | PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 751 | } |
| 752 | |
Jeremy Fitzhardinge | 224101e | 2009-02-18 11:18:57 -0800 | [diff] [blame] | 753 | static inline void arch_end_context_switch(struct task_struct *next) |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 754 | { |
Jeremy Fitzhardinge | 224101e | 2009-02-18 11:18:57 -0800 | [diff] [blame] | 755 | PVOP_VCALL1(pv_cpu_ops.end_context_switch, next); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 758 | #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 759 | static inline void arch_enter_lazy_mmu_mode(void) |
| 760 | { |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 761 | PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | static inline void arch_leave_lazy_mmu_mode(void) |
| 765 | { |
Jeremy Fitzhardinge | 8965c1c | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 766 | PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 767 | } |
| 768 | |
Jeremy Fitzhardinge | d85cf93 | 2009-02-12 10:02:56 -0800 | [diff] [blame] | 769 | void arch_flush_lazy_mmu_mode(void); |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 770 | |
Jeremy Fitzhardinge | aeaaa59 | 2008-06-17 11:42:01 -0700 | [diff] [blame] | 771 | static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, |
Masami Hiramatsu | 3b3809a | 2009-04-09 10:55:33 -0700 | [diff] [blame] | 772 | phys_addr_t phys, pgprot_t flags) |
Jeremy Fitzhardinge | aeaaa59 | 2008-06-17 11:42:01 -0700 | [diff] [blame] | 773 | { |
| 774 | pv_mmu_ops.set_fixmap(idx, phys, flags); |
| 775 | } |
| 776 | |
Jeremy Fitzhardinge | b4ecc12 | 2009-05-13 17:16:55 -0700 | [diff] [blame] | 777 | #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS) |
Ingo Molnar | 4bb689e | 2008-07-09 14:33:33 +0200 | [diff] [blame] | 778 | |
Jeremy Fitzhardinge | 74d4aff | 2008-07-07 12:07:50 -0700 | [diff] [blame] | 779 | static inline int __raw_spin_is_locked(struct raw_spinlock *lock) |
| 780 | { |
| 781 | return PVOP_CALL1(int, pv_lock_ops.spin_is_locked, lock); |
| 782 | } |
| 783 | |
| 784 | static inline int __raw_spin_is_contended(struct raw_spinlock *lock) |
| 785 | { |
| 786 | return PVOP_CALL1(int, pv_lock_ops.spin_is_contended, lock); |
| 787 | } |
Kyle McMartin | a5ef7ca | 2009-02-08 17:39:58 -0500 | [diff] [blame] | 788 | #define __raw_spin_is_contended __raw_spin_is_contended |
Jeremy Fitzhardinge | 74d4aff | 2008-07-07 12:07:50 -0700 | [diff] [blame] | 789 | |
| 790 | static __always_inline void __raw_spin_lock(struct raw_spinlock *lock) |
| 791 | { |
Harvey Harrison | 3217256 | 2008-07-17 14:22:34 -0700 | [diff] [blame] | 792 | PVOP_VCALL1(pv_lock_ops.spin_lock, lock); |
Jeremy Fitzhardinge | 74d4aff | 2008-07-07 12:07:50 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Jeremy Fitzhardinge | 63d3a75 | 2008-08-19 13:19:36 -0700 | [diff] [blame] | 795 | static __always_inline void __raw_spin_lock_flags(struct raw_spinlock *lock, |
| 796 | unsigned long flags) |
| 797 | { |
| 798 | PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags); |
| 799 | } |
| 800 | |
Jeremy Fitzhardinge | 74d4aff | 2008-07-07 12:07:50 -0700 | [diff] [blame] | 801 | static __always_inline int __raw_spin_trylock(struct raw_spinlock *lock) |
| 802 | { |
| 803 | return PVOP_CALL1(int, pv_lock_ops.spin_trylock, lock); |
| 804 | } |
| 805 | |
| 806 | static __always_inline void __raw_spin_unlock(struct raw_spinlock *lock) |
| 807 | { |
Harvey Harrison | 3217256 | 2008-07-17 14:22:34 -0700 | [diff] [blame] | 808 | PVOP_VCALL1(pv_lock_ops.spin_unlock, lock); |
Jeremy Fitzhardinge | 74d4aff | 2008-07-07 12:07:50 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Ingo Molnar | 4bb689e | 2008-07-09 14:33:33 +0200 | [diff] [blame] | 811 | #endif |
| 812 | |
Glauber de Oliveira Costa | 2e47d3e | 2008-01-30 13:32:07 +0100 | [diff] [blame] | 813 | #ifdef CONFIG_X86_32 |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 814 | #define PV_SAVE_REGS "pushl %ecx; pushl %edx;" |
| 815 | #define PV_RESTORE_REGS "popl %edx; popl %ecx;" |
| 816 | |
| 817 | /* save and restore all caller-save registers, except return value */ |
Jeremy Fitzhardinge | e584f55 | 2009-01-30 23:17:23 -0800 | [diff] [blame] | 818 | #define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;" |
| 819 | #define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;" |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 820 | |
Glauber de Oliveira Costa | 2e47d3e | 2008-01-30 13:32:07 +0100 | [diff] [blame] | 821 | #define PV_FLAGS_ARG "0" |
| 822 | #define PV_EXTRA_CLOBBERS |
| 823 | #define PV_VEXTRA_CLOBBERS |
| 824 | #else |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 825 | /* save and restore all caller-save registers, except return value */ |
| 826 | #define PV_SAVE_ALL_CALLER_REGS \ |
| 827 | "push %rcx;" \ |
| 828 | "push %rdx;" \ |
| 829 | "push %rsi;" \ |
| 830 | "push %rdi;" \ |
| 831 | "push %r8;" \ |
| 832 | "push %r9;" \ |
| 833 | "push %r10;" \ |
| 834 | "push %r11;" |
| 835 | #define PV_RESTORE_ALL_CALLER_REGS \ |
| 836 | "pop %r11;" \ |
| 837 | "pop %r10;" \ |
| 838 | "pop %r9;" \ |
| 839 | "pop %r8;" \ |
| 840 | "pop %rdi;" \ |
| 841 | "pop %rsi;" \ |
| 842 | "pop %rdx;" \ |
| 843 | "pop %rcx;" |
| 844 | |
Glauber de Oliveira Costa | 2e47d3e | 2008-01-30 13:32:07 +0100 | [diff] [blame] | 845 | /* We save some registers, but all of them, that's too much. We clobber all |
| 846 | * caller saved registers but the argument parameter */ |
| 847 | #define PV_SAVE_REGS "pushq %%rdi;" |
| 848 | #define PV_RESTORE_REGS "popq %%rdi;" |
Jeremy Fitzhardinge | c24481e | 2008-07-08 15:07:12 -0700 | [diff] [blame] | 849 | #define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi" |
| 850 | #define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi" |
Glauber de Oliveira Costa | 2e47d3e | 2008-01-30 13:32:07 +0100 | [diff] [blame] | 851 | #define PV_FLAGS_ARG "D" |
| 852 | #endif |
| 853 | |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 854 | /* |
| 855 | * Generate a thunk around a function which saves all caller-save |
| 856 | * registers except for the return value. This allows C functions to |
| 857 | * be called from assembler code where fewer than normal registers are |
| 858 | * available. It may also help code generation around calls from C |
| 859 | * code if the common case doesn't use many registers. |
| 860 | * |
| 861 | * When a callee is wrapped in a thunk, the caller can assume that all |
| 862 | * arg regs and all scratch registers are preserved across the |
| 863 | * call. The return value in rax/eax will not be saved, even for void |
| 864 | * functions. |
| 865 | */ |
| 866 | #define PV_CALLEE_SAVE_REGS_THUNK(func) \ |
| 867 | extern typeof(func) __raw_callee_save_##func; \ |
| 868 | static void *__##func##__ __used = func; \ |
| 869 | \ |
| 870 | asm(".pushsection .text;" \ |
| 871 | "__raw_callee_save_" #func ": " \ |
| 872 | PV_SAVE_ALL_CALLER_REGS \ |
| 873 | "call " #func ";" \ |
| 874 | PV_RESTORE_ALL_CALLER_REGS \ |
| 875 | "ret;" \ |
| 876 | ".popsection") |
| 877 | |
| 878 | /* Get a reference to a callee-save function */ |
| 879 | #define PV_CALLEE_SAVE(func) \ |
| 880 | ((struct paravirt_callee_save) { __raw_callee_save_##func }) |
| 881 | |
| 882 | /* Promise that "func" already uses the right calling convention */ |
| 883 | #define __PV_IS_CALLEE_SAVE(func) \ |
| 884 | ((struct paravirt_callee_save) { func }) |
| 885 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 886 | static inline unsigned long __raw_local_save_flags(void) |
| 887 | { |
| 888 | unsigned long f; |
| 889 | |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 890 | asm volatile(paravirt_alt(PARAVIRT_CALL) |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 891 | : "=a"(f) |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 892 | : paravirt_type(pv_irq_ops.save_fl), |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 893 | paravirt_clobber(CLBR_EAX) |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 894 | : "memory", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 895 | return f; |
| 896 | } |
| 897 | |
| 898 | static inline void raw_local_irq_restore(unsigned long f) |
| 899 | { |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 900 | asm volatile(paravirt_alt(PARAVIRT_CALL) |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 901 | : "=a"(f) |
Glauber de Oliveira Costa | 2e47d3e | 2008-01-30 13:32:07 +0100 | [diff] [blame] | 902 | : PV_FLAGS_ARG(f), |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 903 | paravirt_type(pv_irq_ops.restore_fl), |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 904 | paravirt_clobber(CLBR_EAX) |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 905 | : "memory", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | static inline void raw_local_irq_disable(void) |
| 909 | { |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 910 | asm volatile(paravirt_alt(PARAVIRT_CALL) |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 911 | : |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 912 | : paravirt_type(pv_irq_ops.irq_disable), |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 913 | paravirt_clobber(CLBR_EAX) |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 914 | : "memory", "eax", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | static inline void raw_local_irq_enable(void) |
| 918 | { |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 919 | asm volatile(paravirt_alt(PARAVIRT_CALL) |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 920 | : |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 921 | : paravirt_type(pv_irq_ops.irq_enable), |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 922 | paravirt_clobber(CLBR_EAX) |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 923 | : "memory", "eax", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | static inline unsigned long __raw_local_irq_save(void) |
| 927 | { |
| 928 | unsigned long f; |
| 929 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 930 | f = __raw_local_save_flags(); |
| 931 | raw_local_irq_disable(); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 932 | return f; |
| 933 | } |
| 934 | |
Jeremy Fitzhardinge | 74d4aff | 2008-07-07 12:07:50 -0700 | [diff] [blame] | 935 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 936 | /* Make sure as little as possible of this mess escapes. */ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 937 | #undef PARAVIRT_CALL |
Jeremy Fitzhardinge | 1a45b7a | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 938 | #undef __PVOP_CALL |
| 939 | #undef __PVOP_VCALL |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 940 | #undef PVOP_VCALL0 |
| 941 | #undef PVOP_CALL0 |
| 942 | #undef PVOP_VCALL1 |
| 943 | #undef PVOP_CALL1 |
| 944 | #undef PVOP_VCALL2 |
| 945 | #undef PVOP_CALL2 |
| 946 | #undef PVOP_VCALL3 |
| 947 | #undef PVOP_CALL3 |
| 948 | #undef PVOP_VCALL4 |
| 949 | #undef PVOP_CALL4 |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 950 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 951 | #else /* __ASSEMBLY__ */ |
| 952 | |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 953 | #define _PVSITE(ptype, clobbers, ops, word, algn) \ |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 954 | 771:; \ |
| 955 | ops; \ |
| 956 | 772:; \ |
| 957 | .pushsection .parainstructions,"a"; \ |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 958 | .align algn; \ |
| 959 | word 771b; \ |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 960 | .byte ptype; \ |
| 961 | .byte 772b-771b; \ |
| 962 | .short clobbers; \ |
| 963 | .popsection |
| 964 | |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 965 | |
Jeremy Fitzhardinge | 9104a18 | 2009-01-28 14:35:04 -0800 | [diff] [blame] | 966 | #define COND_PUSH(set, mask, reg) \ |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 967 | .if ((~(set)) & mask); push %reg; .endif |
Jeremy Fitzhardinge | 9104a18 | 2009-01-28 14:35:04 -0800 | [diff] [blame] | 968 | #define COND_POP(set, mask, reg) \ |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 969 | .if ((~(set)) & mask); pop %reg; .endif |
Jeremy Fitzhardinge | 9104a18 | 2009-01-28 14:35:04 -0800 | [diff] [blame] | 970 | |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 971 | #ifdef CONFIG_X86_64 |
Jeremy Fitzhardinge | 9104a18 | 2009-01-28 14:35:04 -0800 | [diff] [blame] | 972 | |
| 973 | #define PV_SAVE_REGS(set) \ |
| 974 | COND_PUSH(set, CLBR_RAX, rax); \ |
| 975 | COND_PUSH(set, CLBR_RCX, rcx); \ |
| 976 | COND_PUSH(set, CLBR_RDX, rdx); \ |
| 977 | COND_PUSH(set, CLBR_RSI, rsi); \ |
| 978 | COND_PUSH(set, CLBR_RDI, rdi); \ |
| 979 | COND_PUSH(set, CLBR_R8, r8); \ |
| 980 | COND_PUSH(set, CLBR_R9, r9); \ |
| 981 | COND_PUSH(set, CLBR_R10, r10); \ |
| 982 | COND_PUSH(set, CLBR_R11, r11) |
| 983 | #define PV_RESTORE_REGS(set) \ |
| 984 | COND_POP(set, CLBR_R11, r11); \ |
| 985 | COND_POP(set, CLBR_R10, r10); \ |
| 986 | COND_POP(set, CLBR_R9, r9); \ |
| 987 | COND_POP(set, CLBR_R8, r8); \ |
| 988 | COND_POP(set, CLBR_RDI, rdi); \ |
| 989 | COND_POP(set, CLBR_RSI, rsi); \ |
| 990 | COND_POP(set, CLBR_RDX, rdx); \ |
| 991 | COND_POP(set, CLBR_RCX, rcx); \ |
| 992 | COND_POP(set, CLBR_RAX, rax) |
| 993 | |
Glauber de Oliveira Costa | 6057fc8 | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 994 | #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8) |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 995 | #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8) |
Jeremy Fitzhardinge | 491eccb | 2008-06-25 00:19:15 -0400 | [diff] [blame] | 996 | #define PARA_INDIRECT(addr) *addr(%rip) |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 997 | #else |
Jeremy Fitzhardinge | 9104a18 | 2009-01-28 14:35:04 -0800 | [diff] [blame] | 998 | #define PV_SAVE_REGS(set) \ |
| 999 | COND_PUSH(set, CLBR_EAX, eax); \ |
| 1000 | COND_PUSH(set, CLBR_EDI, edi); \ |
| 1001 | COND_PUSH(set, CLBR_ECX, ecx); \ |
| 1002 | COND_PUSH(set, CLBR_EDX, edx) |
| 1003 | #define PV_RESTORE_REGS(set) \ |
| 1004 | COND_POP(set, CLBR_EDX, edx); \ |
| 1005 | COND_POP(set, CLBR_ECX, ecx); \ |
| 1006 | COND_POP(set, CLBR_EDI, edi); \ |
| 1007 | COND_POP(set, CLBR_EAX, eax) |
| 1008 | |
Glauber de Oliveira Costa | 6057fc8 | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 1009 | #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4) |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 1010 | #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4) |
Jeremy Fitzhardinge | 491eccb | 2008-06-25 00:19:15 -0400 | [diff] [blame] | 1011 | #define PARA_INDIRECT(addr) *%cs:addr |
Glauber de Oliveira Costa | 658be9d | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 1012 | #endif |
| 1013 | |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 1014 | #define INTERRUPT_RETURN \ |
| 1015 | PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \ |
Jeremy Fitzhardinge | 491eccb | 2008-06-25 00:19:15 -0400 | [diff] [blame] | 1016 | jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret)) |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1017 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1018 | #define DISABLE_INTERRUPTS(clobbers) \ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 1019 | PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \ |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 1020 | PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ |
Jeremy Fitzhardinge | 491eccb | 2008-06-25 00:19:15 -0400 | [diff] [blame] | 1021 | call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \ |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 1022 | PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1023 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1024 | #define ENABLE_INTERRUPTS(clobbers) \ |
Jeremy Fitzhardinge | 93b1eab | 2007-10-16 11:51:29 -0700 | [diff] [blame] | 1025 | PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \ |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 1026 | PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ |
Jeremy Fitzhardinge | 491eccb | 2008-06-25 00:19:15 -0400 | [diff] [blame] | 1027 | call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \ |
Jeremy Fitzhardinge | ecb93d1 | 2009-01-28 14:35:05 -0800 | [diff] [blame] | 1028 | PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1029 | |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 1030 | #define USERGS_SYSRET32 \ |
| 1031 | PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \ |
Glauber de Oliveira Costa | 6abcd98 | 2008-01-30 13:30:33 +0100 | [diff] [blame] | 1032 | CLBR_NONE, \ |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 1033 | jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32)) |
Glauber de Oliveira Costa | 2e47d3e | 2008-01-30 13:32:07 +0100 | [diff] [blame] | 1034 | |
Glauber de Oliveira Costa | 6057fc8 | 2008-01-30 13:32:06 +0100 | [diff] [blame] | 1035 | #ifdef CONFIG_X86_32 |
Jeremy Fitzhardinge | 491eccb | 2008-06-25 00:19:15 -0400 | [diff] [blame] | 1036 | #define GET_CR0_INTO_EAX \ |
| 1037 | push %ecx; push %edx; \ |
| 1038 | call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1039 | pop %edx; pop %ecx |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 1040 | |
| 1041 | #define ENABLE_INTERRUPTS_SYSEXIT \ |
| 1042 | PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \ |
| 1043 | CLBR_NONE, \ |
| 1044 | jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit)) |
| 1045 | |
| 1046 | |
| 1047 | #else /* !CONFIG_X86_32 */ |
Jeremy Fitzhardinge | a00394f | 2008-06-25 00:19:30 -0400 | [diff] [blame] | 1048 | |
| 1049 | /* |
| 1050 | * If swapgs is used while the userspace stack is still current, |
| 1051 | * there's no way to call a pvop. The PV replacement *must* be |
| 1052 | * inlined, or the swapgs instruction must be trapped and emulated. |
| 1053 | */ |
| 1054 | #define SWAPGS_UNSAFE_STACK \ |
| 1055 | PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \ |
| 1056 | swapgs) |
| 1057 | |
Jeremy Fitzhardinge | 9104a18 | 2009-01-28 14:35:04 -0800 | [diff] [blame] | 1058 | /* |
| 1059 | * Note: swapgs is very special, and in practise is either going to be |
| 1060 | * implemented with a single "swapgs" instruction or something very |
| 1061 | * special. Either way, we don't need to save any registers for |
| 1062 | * it. |
| 1063 | */ |
Glauber de Oliveira Costa | e801f86 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1064 | #define SWAPGS \ |
| 1065 | PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \ |
Jeremy Fitzhardinge | 9104a18 | 2009-01-28 14:35:04 -0800 | [diff] [blame] | 1066 | call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \ |
Glauber de Oliveira Costa | e801f86 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1067 | ) |
| 1068 | |
Jeremy Fitzhardinge | 491eccb | 2008-06-25 00:19:15 -0400 | [diff] [blame] | 1069 | #define GET_CR2_INTO_RCX \ |
| 1070 | call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \ |
| 1071 | movq %rax, %rcx; \ |
Glauber de Oliveira Costa | 4a8c4c4 | 2008-01-30 13:32:07 +0100 | [diff] [blame] | 1072 | xorq %rax, %rax; |
| 1073 | |
Jeremy Fitzhardinge | fab5842 | 2008-06-25 00:19:31 -0400 | [diff] [blame] | 1074 | #define PARAVIRT_ADJUST_EXCEPTION_FRAME \ |
| 1075 | PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \ |
| 1076 | CLBR_NONE, \ |
| 1077 | call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame)) |
| 1078 | |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 1079 | #define USERGS_SYSRET64 \ |
| 1080 | PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \ |
Jeremy Fitzhardinge | d75cd22 | 2008-06-25 00:19:26 -0400 | [diff] [blame] | 1081 | CLBR_NONE, \ |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 1082 | jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64)) |
| 1083 | |
| 1084 | #define ENABLE_INTERRUPTS_SYSEXIT32 \ |
| 1085 | PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \ |
| 1086 | CLBR_NONE, \ |
| 1087 | jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit)) |
| 1088 | #endif /* CONFIG_X86_32 */ |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1089 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 1090 | #endif /* __ASSEMBLY__ */ |
| 1091 | #endif /* CONFIG_PARAVIRT */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1092 | #endif /* _ASM_X86_PARAVIRT_H */ |