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