Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 1 | #ifndef __ASM_PARAVIRT_H |
| 2 | #define __ASM_PARAVIRT_H |
| 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 |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 7 | #include <linux/stringify.h> |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 8 | #include <asm/page.h> |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 9 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 10 | /* These are the most performance critical ops, so we want to be able to patch |
| 11 | * callers */ |
| 12 | #define PARAVIRT_IRQ_DISABLE 0 |
| 13 | #define PARAVIRT_IRQ_ENABLE 1 |
| 14 | #define PARAVIRT_RESTORE_FLAGS 2 |
| 15 | #define PARAVIRT_SAVE_FLAGS 3 |
| 16 | #define PARAVIRT_SAVE_FLAGS_IRQ_DISABLE 4 |
| 17 | #define PARAVIRT_INTERRUPT_RETURN 5 |
| 18 | #define PARAVIRT_STI_SYSEXIT 6 |
| 19 | |
| 20 | /* Bitmask of what can be clobbered: usually at least eax. */ |
| 21 | #define CLBR_NONE 0x0 |
| 22 | #define CLBR_EAX 0x1 |
| 23 | #define CLBR_ECX 0x2 |
| 24 | #define CLBR_EDX 0x4 |
| 25 | #define CLBR_ANY 0x7 |
| 26 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 27 | #ifndef __ASSEMBLY__ |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 28 | #include <linux/types.h> |
| 29 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 30 | struct thread_struct; |
| 31 | struct Xgt_desc_struct; |
| 32 | struct tss_struct; |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 33 | struct mm_struct; |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 34 | struct desc_struct; |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 35 | struct paravirt_ops |
| 36 | { |
| 37 | unsigned int kernel_rpl; |
| 38 | int paravirt_enabled; |
| 39 | const char *name; |
| 40 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 41 | /* |
| 42 | * Patch may replace one of the defined code sequences with arbitrary |
| 43 | * code, subject to the same register constraints. This generally |
| 44 | * means the code is not free to clobber any registers other than EAX. |
| 45 | * The patch function should return the number of bytes of code |
| 46 | * generated, as we nop pad the rest in generic code. |
| 47 | */ |
| 48 | unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len); |
| 49 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 50 | void (*arch_setup)(void); |
| 51 | char *(*memory_setup)(void); |
| 52 | void (*init_IRQ)(void); |
| 53 | |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame^] | 54 | void (*pagetable_setup_start)(pgd_t *pgd_base); |
| 55 | void (*pagetable_setup_done)(pgd_t *pgd_base); |
| 56 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 57 | void (*banner)(void); |
| 58 | |
| 59 | unsigned long (*get_wallclock)(void); |
| 60 | int (*set_wallclock)(unsigned long); |
| 61 | void (*time_init)(void); |
| 62 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 63 | void (*cpuid)(unsigned int *eax, unsigned int *ebx, |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 64 | unsigned int *ecx, unsigned int *edx); |
| 65 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 66 | unsigned long (*get_debugreg)(int regno); |
| 67 | void (*set_debugreg)(int regno, unsigned long value); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 68 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 69 | void (*clts)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 70 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 71 | unsigned long (*read_cr0)(void); |
| 72 | void (*write_cr0)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 73 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 74 | unsigned long (*read_cr2)(void); |
| 75 | void (*write_cr2)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 76 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 77 | unsigned long (*read_cr3)(void); |
| 78 | void (*write_cr3)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 79 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 80 | unsigned long (*read_cr4_safe)(void); |
| 81 | unsigned long (*read_cr4)(void); |
| 82 | void (*write_cr4)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 83 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 84 | unsigned long (*save_fl)(void); |
| 85 | void (*restore_fl)(unsigned long); |
| 86 | void (*irq_disable)(void); |
| 87 | void (*irq_enable)(void); |
| 88 | void (*safe_halt)(void); |
| 89 | void (*halt)(void); |
| 90 | void (*wbinvd)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 91 | |
| 92 | /* err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 93 | u64 (*read_msr)(unsigned int msr, int *err); |
| 94 | int (*write_msr)(unsigned int msr, u64 val); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 95 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 96 | u64 (*read_tsc)(void); |
| 97 | u64 (*read_pmc)(void); |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 98 | u64 (*get_scheduled_cycles)(void); |
Zachary Amsden | 1182d85 | 2007-03-05 00:30:36 -0800 | [diff] [blame] | 99 | unsigned long (*get_cpu_khz)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 100 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 101 | void (*load_tr_desc)(void); |
| 102 | void (*load_gdt)(const struct Xgt_desc_struct *); |
| 103 | void (*load_idt)(const struct Xgt_desc_struct *); |
| 104 | void (*store_gdt)(struct Xgt_desc_struct *); |
| 105 | void (*store_idt)(struct Xgt_desc_struct *); |
| 106 | void (*set_ldt)(const void *desc, unsigned entries); |
| 107 | unsigned long (*store_tr)(void); |
| 108 | void (*load_tls)(struct thread_struct *t, unsigned int cpu); |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 109 | void (*write_ldt_entry)(struct desc_struct *, |
| 110 | int entrynum, u32 low, u32 high); |
| 111 | void (*write_gdt_entry)(struct desc_struct *, |
| 112 | int entrynum, u32 low, u32 high); |
| 113 | void (*write_idt_entry)(struct desc_struct *, |
| 114 | int entrynum, u32 low, u32 high); |
| 115 | void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 116 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 117 | void (*set_iopl_mask)(unsigned mask); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 118 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 119 | void (*io_delay)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 120 | |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 121 | #ifdef CONFIG_X86_LOCAL_APIC |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 122 | void (*apic_write)(unsigned long reg, unsigned long v); |
| 123 | void (*apic_write_atomic)(unsigned long reg, unsigned long v); |
| 124 | unsigned long (*apic_read)(unsigned long reg); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 125 | void (*setup_boot_clock)(void); |
| 126 | void (*setup_secondary_clock)(void); |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 127 | #endif |
| 128 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 129 | void (*flush_tlb_user)(void); |
| 130 | void (*flush_tlb_kernel)(void); |
| 131 | void (*flush_tlb_single)(u32 addr); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 132 | |
Al Viro | 192cd59 | 2007-03-14 09:18:09 +0000 | [diff] [blame] | 133 | void (*map_pt_hook)(int type, pte_t *va, u32 pfn); |
Zachary Amsden | 9a1c13e | 2007-03-05 00:30:37 -0800 | [diff] [blame] | 134 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 135 | void (*alloc_pt)(u32 pfn); |
| 136 | void (*alloc_pd)(u32 pfn); |
| 137 | void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count); |
| 138 | void (*release_pt)(u32 pfn); |
| 139 | void (*release_pd)(u32 pfn); |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 140 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 141 | void (*set_pte)(pte_t *ptep, pte_t pteval); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 142 | void (*set_pte_at)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval); |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 143 | void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 144 | void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep); |
| 145 | void (*pte_update_defer)(struct mm_struct *mm, unsigned long addr, pte_t *ptep); |
| 146 | |
| 147 | pte_t (*ptep_get_and_clear)(pte_t *ptep); |
| 148 | |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 149 | #ifdef CONFIG_X86_PAE |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 150 | void (*set_pte_atomic)(pte_t *ptep, pte_t pteval); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 151 | void (*set_pte_present)(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 152 | void (*set_pud)(pud_t *pudp, pud_t pudval); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 153 | void (*pte_clear)(struct mm_struct *mm, unsigned long addr, pte_t *ptep); |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 154 | void (*pmd_clear)(pmd_t *pmdp); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 155 | |
| 156 | unsigned long long (*pte_val)(pte_t); |
| 157 | unsigned long long (*pmd_val)(pmd_t); |
| 158 | unsigned long long (*pgd_val)(pgd_t); |
| 159 | |
| 160 | pte_t (*make_pte)(unsigned long long pte); |
| 161 | pmd_t (*make_pmd)(unsigned long long pmd); |
| 162 | pgd_t (*make_pgd)(unsigned long long pgd); |
| 163 | #else |
| 164 | unsigned long (*pte_val)(pte_t); |
| 165 | unsigned long (*pgd_val)(pgd_t); |
| 166 | |
| 167 | pte_t (*make_pte)(unsigned long pte); |
| 168 | pgd_t (*make_pgd)(unsigned long pgd); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 169 | #endif |
| 170 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 171 | void (*set_lazy_mode)(int mode); |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 172 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 173 | /* These two are jmp to, not actually called. */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 174 | void (*irq_enable_sysexit)(void); |
| 175 | void (*iret)(void); |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 176 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 177 | void (*startup_ipi_hook)(int phys_apicid, unsigned long start_eip, unsigned long start_esp); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
Rusty Russell | c9ccf30 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 180 | /* Mark a paravirt probe function. */ |
| 181 | #define paravirt_probe(fn) \ |
| 182 | static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \ |
| 183 | __attribute__((__section__(".paravirtprobe"))) = fn |
| 184 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 185 | extern struct paravirt_ops paravirt_ops; |
| 186 | |
| 187 | #define paravirt_enabled() (paravirt_ops.paravirt_enabled) |
| 188 | |
| 189 | static inline void load_esp0(struct tss_struct *tss, |
| 190 | struct thread_struct *thread) |
| 191 | { |
| 192 | paravirt_ops.load_esp0(tss, thread); |
| 193 | } |
| 194 | |
| 195 | #define ARCH_SETUP paravirt_ops.arch_setup(); |
| 196 | static inline unsigned long get_wallclock(void) |
| 197 | { |
| 198 | return paravirt_ops.get_wallclock(); |
| 199 | } |
| 200 | |
| 201 | static inline int set_wallclock(unsigned long nowtime) |
| 202 | { |
| 203 | return paravirt_ops.set_wallclock(nowtime); |
| 204 | } |
| 205 | |
Zachary Amsden | e30fab3 | 2007-03-05 00:30:39 -0800 | [diff] [blame] | 206 | static inline void (*choose_time_init(void))(void) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 207 | { |
Zachary Amsden | e30fab3 | 2007-03-05 00:30:39 -0800 | [diff] [blame] | 208 | return paravirt_ops.time_init; |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* The paravirtualized CPUID instruction. */ |
| 212 | static inline void __cpuid(unsigned int *eax, unsigned int *ebx, |
| 213 | unsigned int *ecx, unsigned int *edx) |
| 214 | { |
| 215 | paravirt_ops.cpuid(eax, ebx, ecx, edx); |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * These special macros can be used to get or set a debugging register |
| 220 | */ |
| 221 | #define get_debugreg(var, reg) var = paravirt_ops.get_debugreg(reg) |
| 222 | #define set_debugreg(val, reg) paravirt_ops.set_debugreg(reg, val) |
| 223 | |
| 224 | #define clts() paravirt_ops.clts() |
| 225 | |
| 226 | #define read_cr0() paravirt_ops.read_cr0() |
| 227 | #define write_cr0(x) paravirt_ops.write_cr0(x) |
| 228 | |
| 229 | #define read_cr2() paravirt_ops.read_cr2() |
| 230 | #define write_cr2(x) paravirt_ops.write_cr2(x) |
| 231 | |
| 232 | #define read_cr3() paravirt_ops.read_cr3() |
| 233 | #define write_cr3(x) paravirt_ops.write_cr3(x) |
| 234 | |
| 235 | #define read_cr4() paravirt_ops.read_cr4() |
| 236 | #define read_cr4_safe(x) paravirt_ops.read_cr4_safe() |
| 237 | #define write_cr4(x) paravirt_ops.write_cr4(x) |
| 238 | |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 239 | #define raw_ptep_get_and_clear(xp) (paravirt_ops.ptep_get_and_clear(xp)) |
| 240 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 241 | static inline void raw_safe_halt(void) |
| 242 | { |
| 243 | paravirt_ops.safe_halt(); |
| 244 | } |
| 245 | |
| 246 | static inline void halt(void) |
| 247 | { |
| 248 | paravirt_ops.safe_halt(); |
| 249 | } |
| 250 | #define wbinvd() paravirt_ops.wbinvd() |
| 251 | |
| 252 | #define get_kernel_rpl() (paravirt_ops.kernel_rpl) |
| 253 | |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 254 | /* These should all do BUG_ON(_err), but our headers are too tangled. */ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 255 | #define rdmsr(msr,val1,val2) do { \ |
| 256 | int _err; \ |
| 257 | u64 _l = paravirt_ops.read_msr(msr,&_err); \ |
| 258 | val1 = (u32)_l; \ |
| 259 | val2 = _l >> 32; \ |
| 260 | } while(0) |
| 261 | |
| 262 | #define wrmsr(msr,val1,val2) do { \ |
| 263 | u64 _l = ((u64)(val2) << 32) | (val1); \ |
| 264 | paravirt_ops.write_msr((msr), _l); \ |
| 265 | } while(0) |
| 266 | |
| 267 | #define rdmsrl(msr,val) do { \ |
| 268 | int _err; \ |
| 269 | val = paravirt_ops.read_msr((msr),&_err); \ |
| 270 | } while(0) |
| 271 | |
| 272 | #define wrmsrl(msr,val) (paravirt_ops.write_msr((msr),(val))) |
| 273 | #define wrmsr_safe(msr,a,b) ({ \ |
| 274 | u64 _l = ((u64)(b) << 32) | (a); \ |
| 275 | paravirt_ops.write_msr((msr),_l); \ |
| 276 | }) |
| 277 | |
| 278 | /* rdmsr with exception handling */ |
| 279 | #define rdmsr_safe(msr,a,b) ({ \ |
| 280 | int _err; \ |
| 281 | u64 _l = paravirt_ops.read_msr(msr,&_err); \ |
| 282 | (*a) = (u32)_l; \ |
| 283 | (*b) = _l >> 32; \ |
| 284 | _err; }) |
| 285 | |
| 286 | #define rdtsc(low,high) do { \ |
| 287 | u64 _l = paravirt_ops.read_tsc(); \ |
| 288 | low = (u32)_l; \ |
| 289 | high = _l >> 32; \ |
| 290 | } while(0) |
| 291 | |
| 292 | #define rdtscl(low) do { \ |
| 293 | u64 _l = paravirt_ops.read_tsc(); \ |
| 294 | low = (int)_l; \ |
| 295 | } while(0) |
| 296 | |
| 297 | #define rdtscll(val) (val = paravirt_ops.read_tsc()) |
| 298 | |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 299 | #define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles()) |
Zachary Amsden | 1182d85 | 2007-03-05 00:30:36 -0800 | [diff] [blame] | 300 | #define calculate_cpu_khz() (paravirt_ops.get_cpu_khz()) |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 301 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 302 | #define write_tsc(val1,val2) wrmsr(0x10, val1, val2) |
| 303 | |
| 304 | #define rdpmc(counter,low,high) do { \ |
| 305 | u64 _l = paravirt_ops.read_pmc(); \ |
| 306 | low = (u32)_l; \ |
| 307 | high = _l >> 32; \ |
| 308 | } while(0) |
| 309 | |
| 310 | #define load_TR_desc() (paravirt_ops.load_tr_desc()) |
| 311 | #define load_gdt(dtr) (paravirt_ops.load_gdt(dtr)) |
| 312 | #define load_idt(dtr) (paravirt_ops.load_idt(dtr)) |
| 313 | #define set_ldt(addr, entries) (paravirt_ops.set_ldt((addr), (entries))) |
| 314 | #define store_gdt(dtr) (paravirt_ops.store_gdt(dtr)) |
| 315 | #define store_idt(dtr) (paravirt_ops.store_idt(dtr)) |
| 316 | #define store_tr(tr) ((tr) = paravirt_ops.store_tr()) |
| 317 | #define load_TLS(t,cpu) (paravirt_ops.load_tls((t),(cpu))) |
| 318 | #define write_ldt_entry(dt, entry, low, high) \ |
| 319 | (paravirt_ops.write_ldt_entry((dt), (entry), (low), (high))) |
| 320 | #define write_gdt_entry(dt, entry, low, high) \ |
| 321 | (paravirt_ops.write_gdt_entry((dt), (entry), (low), (high))) |
| 322 | #define write_idt_entry(dt, entry, low, high) \ |
| 323 | (paravirt_ops.write_idt_entry((dt), (entry), (low), (high))) |
| 324 | #define set_iopl_mask(mask) (paravirt_ops.set_iopl_mask(mask)) |
| 325 | |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 326 | #define __pte(x) paravirt_ops.make_pte(x) |
| 327 | #define __pgd(x) paravirt_ops.make_pgd(x) |
| 328 | |
| 329 | #define pte_val(x) paravirt_ops.pte_val(x) |
| 330 | #define pgd_val(x) paravirt_ops.pgd_val(x) |
| 331 | |
| 332 | #ifdef CONFIG_X86_PAE |
| 333 | #define __pmd(x) paravirt_ops.make_pmd(x) |
| 334 | #define pmd_val(x) paravirt_ops.pmd_val(x) |
| 335 | #endif |
| 336 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 337 | /* The paravirtualized I/O functions */ |
| 338 | static inline void slow_down_io(void) { |
| 339 | paravirt_ops.io_delay(); |
| 340 | #ifdef REALLY_SLOW_IO |
| 341 | paravirt_ops.io_delay(); |
| 342 | paravirt_ops.io_delay(); |
| 343 | paravirt_ops.io_delay(); |
| 344 | #endif |
| 345 | } |
| 346 | |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 347 | #ifdef CONFIG_X86_LOCAL_APIC |
| 348 | /* |
| 349 | * Basic functions accessing APICs. |
| 350 | */ |
| 351 | static inline void apic_write(unsigned long reg, unsigned long v) |
| 352 | { |
| 353 | paravirt_ops.apic_write(reg,v); |
| 354 | } |
| 355 | |
| 356 | static inline void apic_write_atomic(unsigned long reg, unsigned long v) |
| 357 | { |
| 358 | paravirt_ops.apic_write_atomic(reg,v); |
| 359 | } |
| 360 | |
| 361 | static inline unsigned long apic_read(unsigned long reg) |
| 362 | { |
| 363 | return paravirt_ops.apic_read(reg); |
| 364 | } |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 365 | |
| 366 | static inline void setup_boot_clock(void) |
| 367 | { |
| 368 | paravirt_ops.setup_boot_clock(); |
| 369 | } |
| 370 | |
| 371 | static inline void setup_secondary_clock(void) |
| 372 | { |
| 373 | paravirt_ops.setup_secondary_clock(); |
| 374 | } |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 375 | #endif |
| 376 | |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame^] | 377 | static inline void paravirt_pagetable_setup_start(pgd_t *base) |
| 378 | { |
| 379 | if (paravirt_ops.pagetable_setup_start) |
| 380 | (*paravirt_ops.pagetable_setup_start)(base); |
| 381 | } |
| 382 | |
| 383 | static inline void paravirt_pagetable_setup_done(pgd_t *base) |
| 384 | { |
| 385 | if (paravirt_ops.pagetable_setup_done) |
| 386 | (*paravirt_ops.pagetable_setup_done)(base); |
| 387 | } |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 388 | |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 389 | #ifdef CONFIG_SMP |
| 390 | static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip, |
| 391 | unsigned long start_esp) |
| 392 | { |
| 393 | return paravirt_ops.startup_ipi_hook(phys_apicid, start_eip, start_esp); |
| 394 | } |
| 395 | #endif |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 396 | |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 397 | #define __flush_tlb() paravirt_ops.flush_tlb_user() |
| 398 | #define __flush_tlb_global() paravirt_ops.flush_tlb_kernel() |
| 399 | #define __flush_tlb_single(addr) paravirt_ops.flush_tlb_single(addr) |
| 400 | |
Zachary Amsden | 9a1c13e | 2007-03-05 00:30:37 -0800 | [diff] [blame] | 401 | #define paravirt_map_pt_hook(type, va, pfn) paravirt_ops.map_pt_hook(type, va, pfn) |
| 402 | |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 403 | #define paravirt_alloc_pt(pfn) paravirt_ops.alloc_pt(pfn) |
| 404 | #define paravirt_release_pt(pfn) paravirt_ops.release_pt(pfn) |
| 405 | |
| 406 | #define paravirt_alloc_pd(pfn) paravirt_ops.alloc_pd(pfn) |
| 407 | #define paravirt_alloc_pd_clone(pfn, clonepfn, start, count) \ |
| 408 | paravirt_ops.alloc_pd_clone(pfn, clonepfn, start, count) |
| 409 | #define paravirt_release_pd(pfn) paravirt_ops.release_pd(pfn) |
| 410 | |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 411 | static inline void set_pte(pte_t *ptep, pte_t pteval) |
| 412 | { |
| 413 | paravirt_ops.set_pte(ptep, pteval); |
| 414 | } |
| 415 | |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 416 | static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 417 | pte_t *ptep, pte_t pteval) |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 418 | { |
| 419 | paravirt_ops.set_pte_at(mm, addr, ptep, pteval); |
| 420 | } |
| 421 | |
| 422 | static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval) |
| 423 | { |
| 424 | paravirt_ops.set_pmd(pmdp, pmdval); |
| 425 | } |
| 426 | |
| 427 | static inline void pte_update(struct mm_struct *mm, u32 addr, pte_t *ptep) |
| 428 | { |
| 429 | paravirt_ops.pte_update(mm, addr, ptep); |
| 430 | } |
| 431 | |
| 432 | static inline void pte_update_defer(struct mm_struct *mm, u32 addr, pte_t *ptep) |
| 433 | { |
| 434 | paravirt_ops.pte_update_defer(mm, addr, ptep); |
| 435 | } |
| 436 | |
| 437 | #ifdef CONFIG_X86_PAE |
| 438 | static inline void set_pte_atomic(pte_t *ptep, pte_t pteval) |
| 439 | { |
| 440 | paravirt_ops.set_pte_atomic(ptep, pteval); |
| 441 | } |
| 442 | |
| 443 | static inline void set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) |
| 444 | { |
| 445 | paravirt_ops.set_pte_present(mm, addr, ptep, pte); |
| 446 | } |
| 447 | |
| 448 | static inline void set_pud(pud_t *pudp, pud_t pudval) |
| 449 | { |
| 450 | paravirt_ops.set_pud(pudp, pudval); |
| 451 | } |
| 452 | |
| 453 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 454 | { |
| 455 | paravirt_ops.pte_clear(mm, addr, ptep); |
| 456 | } |
| 457 | |
| 458 | static inline void pmd_clear(pmd_t *pmdp) |
| 459 | { |
| 460 | paravirt_ops.pmd_clear(pmdp); |
| 461 | } |
| 462 | #endif |
| 463 | |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 464 | /* Lazy mode for batching updates / context switch */ |
| 465 | #define PARAVIRT_LAZY_NONE 0 |
| 466 | #define PARAVIRT_LAZY_MMU 1 |
| 467 | #define PARAVIRT_LAZY_CPU 2 |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 468 | #define PARAVIRT_LAZY_FLUSH 3 |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 469 | |
| 470 | #define __HAVE_ARCH_ENTER_LAZY_CPU_MODE |
| 471 | #define arch_enter_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_CPU) |
| 472 | #define arch_leave_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE) |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 473 | #define arch_flush_lazy_cpu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH) |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 474 | |
| 475 | #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE |
| 476 | #define arch_enter_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_MMU) |
| 477 | #define arch_leave_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_NONE) |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 478 | #define arch_flush_lazy_mmu_mode() paravirt_ops.set_lazy_mode(PARAVIRT_LAZY_FLUSH) |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 479 | |
Jeremy Fitzhardinge | 4587623 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 480 | void _paravirt_nop(void); |
| 481 | #define paravirt_nop ((void *)_paravirt_nop) |
| 482 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 483 | /* These all sit in the .parainstructions section to tell us what to patch. */ |
| 484 | struct paravirt_patch { |
| 485 | u8 *instr; /* original instructions */ |
| 486 | u8 instrtype; /* type of this instruction */ |
| 487 | u8 len; /* length of original instruction */ |
| 488 | u16 clobbers; /* what registers you may clobber */ |
| 489 | }; |
| 490 | |
| 491 | #define paravirt_alt(insn_string, typenum, clobber) \ |
| 492 | "771:\n\t" insn_string "\n" "772:\n" \ |
| 493 | ".pushsection .parainstructions,\"a\"\n" \ |
| 494 | " .long 771b\n" \ |
| 495 | " .byte " __stringify(typenum) "\n" \ |
| 496 | " .byte 772b-771b\n" \ |
| 497 | " .short " __stringify(clobber) "\n" \ |
| 498 | ".popsection" |
| 499 | |
| 500 | static inline unsigned long __raw_local_save_flags(void) |
| 501 | { |
| 502 | unsigned long f; |
| 503 | |
| 504 | __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;" |
| 505 | "call *%1;" |
| 506 | "popl %%edx; popl %%ecx", |
| 507 | PARAVIRT_SAVE_FLAGS, CLBR_NONE) |
| 508 | : "=a"(f): "m"(paravirt_ops.save_fl) |
| 509 | : "memory", "cc"); |
| 510 | return f; |
| 511 | } |
| 512 | |
| 513 | static inline void raw_local_irq_restore(unsigned long f) |
| 514 | { |
| 515 | __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;" |
| 516 | "call *%1;" |
| 517 | "popl %%edx; popl %%ecx", |
| 518 | PARAVIRT_RESTORE_FLAGS, CLBR_EAX) |
| 519 | : "=a"(f) : "m" (paravirt_ops.restore_fl), "0"(f) |
| 520 | : "memory", "cc"); |
| 521 | } |
| 522 | |
| 523 | static inline void raw_local_irq_disable(void) |
| 524 | { |
| 525 | __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;" |
| 526 | "call *%0;" |
| 527 | "popl %%edx; popl %%ecx", |
| 528 | PARAVIRT_IRQ_DISABLE, CLBR_EAX) |
| 529 | : : "m" (paravirt_ops.irq_disable) |
| 530 | : "memory", "eax", "cc"); |
| 531 | } |
| 532 | |
| 533 | static inline void raw_local_irq_enable(void) |
| 534 | { |
| 535 | __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;" |
| 536 | "call *%0;" |
| 537 | "popl %%edx; popl %%ecx", |
| 538 | PARAVIRT_IRQ_ENABLE, CLBR_EAX) |
| 539 | : : "m" (paravirt_ops.irq_enable) |
| 540 | : "memory", "eax", "cc"); |
| 541 | } |
| 542 | |
| 543 | static inline unsigned long __raw_local_irq_save(void) |
| 544 | { |
| 545 | unsigned long f; |
| 546 | |
| 547 | __asm__ __volatile__(paravirt_alt( "pushl %%ecx; pushl %%edx;" |
| 548 | "call *%1; pushl %%eax;" |
| 549 | "call *%2; popl %%eax;" |
| 550 | "popl %%edx; popl %%ecx", |
| 551 | PARAVIRT_SAVE_FLAGS_IRQ_DISABLE, |
| 552 | CLBR_NONE) |
| 553 | : "=a"(f) |
| 554 | : "m" (paravirt_ops.save_fl), |
| 555 | "m" (paravirt_ops.irq_disable) |
| 556 | : "memory", "cc"); |
| 557 | return f; |
| 558 | } |
| 559 | |
| 560 | #define CLI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \ |
| 561 | "call *paravirt_ops+%c[irq_disable];" \ |
| 562 | "popl %%edx; popl %%ecx", \ |
| 563 | PARAVIRT_IRQ_DISABLE, CLBR_EAX) |
| 564 | |
| 565 | #define STI_STRING paravirt_alt("pushl %%ecx; pushl %%edx;" \ |
| 566 | "call *paravirt_ops+%c[irq_enable];" \ |
| 567 | "popl %%edx; popl %%ecx", \ |
| 568 | PARAVIRT_IRQ_ENABLE, CLBR_EAX) |
| 569 | #define CLI_STI_CLOBBERS , "%eax" |
| 570 | #define CLI_STI_INPUT_ARGS \ |
| 571 | , \ |
| 572 | [irq_disable] "i" (offsetof(struct paravirt_ops, irq_disable)), \ |
| 573 | [irq_enable] "i" (offsetof(struct paravirt_ops, irq_enable)) |
| 574 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 575 | #else /* __ASSEMBLY__ */ |
| 576 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 577 | #define PARA_PATCH(ptype, clobbers, ops) \ |
| 578 | 771:; \ |
| 579 | ops; \ |
| 580 | 772:; \ |
| 581 | .pushsection .parainstructions,"a"; \ |
| 582 | .long 771b; \ |
| 583 | .byte ptype; \ |
| 584 | .byte 772b-771b; \ |
| 585 | .short clobbers; \ |
| 586 | .popsection |
| 587 | |
| 588 | #define INTERRUPT_RETURN \ |
| 589 | PARA_PATCH(PARAVIRT_INTERRUPT_RETURN, CLBR_ANY, \ |
| 590 | jmp *%cs:paravirt_ops+PARAVIRT_iret) |
| 591 | |
| 592 | #define DISABLE_INTERRUPTS(clobbers) \ |
| 593 | PARA_PATCH(PARAVIRT_IRQ_DISABLE, clobbers, \ |
| 594 | pushl %ecx; pushl %edx; \ |
| 595 | call *paravirt_ops+PARAVIRT_irq_disable; \ |
| 596 | popl %edx; popl %ecx) \ |
| 597 | |
| 598 | #define ENABLE_INTERRUPTS(clobbers) \ |
| 599 | PARA_PATCH(PARAVIRT_IRQ_ENABLE, clobbers, \ |
| 600 | pushl %ecx; pushl %edx; \ |
| 601 | call *%cs:paravirt_ops+PARAVIRT_irq_enable; \ |
| 602 | popl %edx; popl %ecx) |
| 603 | |
| 604 | #define ENABLE_INTERRUPTS_SYSEXIT \ |
| 605 | PARA_PATCH(PARAVIRT_STI_SYSEXIT, CLBR_ANY, \ |
| 606 | jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit) |
| 607 | |
| 608 | #define GET_CR0_INTO_EAX \ |
| 609 | call *paravirt_ops+PARAVIRT_read_cr0 |
| 610 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 611 | #endif /* __ASSEMBLY__ */ |
| 612 | #endif /* CONFIG_PARAVIRT */ |
| 613 | #endif /* __ASM_PARAVIRT_H */ |