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 | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 7 | #include <asm/page.h> |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 8 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 9 | /* Bitmask of what can be clobbered: usually at least eax. */ |
| 10 | #define CLBR_NONE 0x0 |
| 11 | #define CLBR_EAX 0x1 |
| 12 | #define CLBR_ECX 0x2 |
| 13 | #define CLBR_EDX 0x4 |
| 14 | #define CLBR_ANY 0x7 |
| 15 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 16 | #ifndef __ASSEMBLY__ |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 17 | #include <linux/types.h> |
Jeremy Fitzhardinge | d4c1047 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 18 | #include <linux/cpumask.h> |
Jeremy Fitzhardinge | ce6234b | 2007-05-02 19:27:15 +0200 | [diff] [blame^] | 19 | #include <asm/kmap_types.h> |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 20 | |
Jeremy Fitzhardinge | ce6234b | 2007-05-02 19:27:15 +0200 | [diff] [blame^] | 21 | struct page; |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 22 | struct thread_struct; |
| 23 | struct Xgt_desc_struct; |
| 24 | struct tss_struct; |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 25 | struct mm_struct; |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 26 | struct desc_struct; |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 27 | |
| 28 | /* Lazy mode for batching updates / context switch */ |
| 29 | enum paravirt_lazy_mode { |
| 30 | PARAVIRT_LAZY_NONE = 0, |
| 31 | PARAVIRT_LAZY_MMU = 1, |
| 32 | PARAVIRT_LAZY_CPU = 2, |
| 33 | }; |
| 34 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 35 | struct paravirt_ops |
| 36 | { |
| 37 | unsigned int kernel_rpl; |
Jeremy Fitzhardinge | 5311ab6 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 38 | int shared_kernel_pmd; |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 39 | int paravirt_enabled; |
| 40 | const char *name; |
| 41 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 42 | /* |
| 43 | * Patch may replace one of the defined code sequences with arbitrary |
| 44 | * code, subject to the same register constraints. This generally |
| 45 | * means the code is not free to clobber any registers other than EAX. |
| 46 | * The patch function should return the number of bytes of code |
| 47 | * generated, as we nop pad the rest in generic code. |
| 48 | */ |
| 49 | unsigned (*patch)(u8 type, u16 clobber, void *firstinsn, unsigned len); |
| 50 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 51 | /* Basic arch-specific setup */ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 52 | void (*arch_setup)(void); |
| 53 | char *(*memory_setup)(void); |
| 54 | void (*init_IRQ)(void); |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 55 | void (*time_init)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 56 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 57 | /* |
| 58 | * Called before/after init_mm pagetable setup. setup_start |
| 59 | * may reset %cr3, and may pre-install parts of the pagetable; |
| 60 | * pagetable setup is expected to preserve any existing |
| 61 | * mapping. |
| 62 | */ |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 63 | void (*pagetable_setup_start)(pgd_t *pgd_base); |
| 64 | void (*pagetable_setup_done)(pgd_t *pgd_base); |
| 65 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 66 | /* Print a banner to identify the environment */ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 67 | void (*banner)(void); |
| 68 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 69 | /* Set and set time of day */ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 70 | unsigned long (*get_wallclock)(void); |
| 71 | int (*set_wallclock)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 72 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 73 | /* cpuid emulation, mostly so that caps bits can be disabled */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 74 | void (*cpuid)(unsigned int *eax, unsigned int *ebx, |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 75 | unsigned int *ecx, unsigned int *edx); |
| 76 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 77 | /* hooks for various privileged instructions */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 78 | unsigned long (*get_debugreg)(int regno); |
| 79 | void (*set_debugreg)(int regno, unsigned long value); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 80 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 81 | void (*clts)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 82 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 83 | unsigned long (*read_cr0)(void); |
| 84 | void (*write_cr0)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 85 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 86 | unsigned long (*read_cr2)(void); |
| 87 | void (*write_cr2)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 88 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 89 | unsigned long (*read_cr3)(void); |
| 90 | void (*write_cr3)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 91 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 92 | unsigned long (*read_cr4_safe)(void); |
| 93 | unsigned long (*read_cr4)(void); |
| 94 | void (*write_cr4)(unsigned long); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 95 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 96 | /* |
| 97 | * Get/set interrupt state. save_fl and restore_fl are only |
| 98 | * expected to use X86_EFLAGS_IF; all other bits |
| 99 | * returned from save_fl are undefined, and may be ignored by |
| 100 | * restore_fl. |
| 101 | */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 102 | unsigned long (*save_fl)(void); |
| 103 | void (*restore_fl)(unsigned long); |
| 104 | void (*irq_disable)(void); |
| 105 | void (*irq_enable)(void); |
| 106 | void (*safe_halt)(void); |
| 107 | void (*halt)(void); |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 108 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 109 | void (*wbinvd)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 110 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 111 | /* MSR, PMC and TSR operations. |
| 112 | err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 113 | u64 (*read_msr)(unsigned int msr, int *err); |
| 114 | int (*write_msr)(unsigned int msr, u64 val); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 115 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 116 | u64 (*read_tsc)(void); |
| 117 | u64 (*read_pmc)(void); |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 118 | u64 (*get_scheduled_cycles)(void); |
Zachary Amsden | 1182d85 | 2007-03-05 00:30:36 -0800 | [diff] [blame] | 119 | unsigned long (*get_cpu_khz)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 120 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 121 | /* Segment descriptor handling */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 122 | void (*load_tr_desc)(void); |
| 123 | void (*load_gdt)(const struct Xgt_desc_struct *); |
| 124 | void (*load_idt)(const struct Xgt_desc_struct *); |
| 125 | void (*store_gdt)(struct Xgt_desc_struct *); |
| 126 | void (*store_idt)(struct Xgt_desc_struct *); |
| 127 | void (*set_ldt)(const void *desc, unsigned entries); |
| 128 | unsigned long (*store_tr)(void); |
| 129 | void (*load_tls)(struct thread_struct *t, unsigned int cpu); |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 130 | void (*write_ldt_entry)(struct desc_struct *, |
| 131 | int entrynum, u32 low, u32 high); |
| 132 | void (*write_gdt_entry)(struct desc_struct *, |
| 133 | int entrynum, u32 low, u32 high); |
| 134 | void (*write_idt_entry)(struct desc_struct *, |
| 135 | int entrynum, u32 low, u32 high); |
| 136 | void (*load_esp0)(struct tss_struct *tss, struct thread_struct *t); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 137 | |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 138 | void (*set_iopl_mask)(unsigned mask); |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 139 | void (*io_delay)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 140 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 141 | /* |
| 142 | * Hooks for intercepting the creation/use/destruction of an |
| 143 | * mm_struct. |
| 144 | */ |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 145 | void (*activate_mm)(struct mm_struct *prev, |
| 146 | struct mm_struct *next); |
| 147 | void (*dup_mmap)(struct mm_struct *oldmm, |
| 148 | struct mm_struct *mm); |
| 149 | void (*exit_mmap)(struct mm_struct *mm); |
| 150 | |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 151 | #ifdef CONFIG_X86_LOCAL_APIC |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 152 | /* |
| 153 | * Direct APIC operations, principally for VMI. Ideally |
| 154 | * these shouldn't be in this interface. |
| 155 | */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 156 | void (*apic_write)(unsigned long reg, unsigned long v); |
| 157 | void (*apic_write_atomic)(unsigned long reg, unsigned long v); |
| 158 | unsigned long (*apic_read)(unsigned long reg); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 159 | void (*setup_boot_clock)(void); |
| 160 | void (*setup_secondary_clock)(void); |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 161 | |
| 162 | void (*startup_ipi_hook)(int phys_apicid, |
| 163 | unsigned long start_eip, |
| 164 | unsigned long start_esp); |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 165 | #endif |
| 166 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 167 | /* TLB operations */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 168 | void (*flush_tlb_user)(void); |
| 169 | void (*flush_tlb_kernel)(void); |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 170 | void (*flush_tlb_single)(unsigned long addr); |
Jeremy Fitzhardinge | d4c1047 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 171 | void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm, |
| 172 | unsigned long va); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 173 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 174 | /* Hooks for allocating/releasing pagetable pages */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 175 | void (*alloc_pt)(u32 pfn); |
| 176 | void (*alloc_pd)(u32 pfn); |
| 177 | void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count); |
| 178 | void (*release_pt)(u32 pfn); |
| 179 | void (*release_pd)(u32 pfn); |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 180 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 181 | /* Pagetable manipulation functions */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 182 | void (*set_pte)(pte_t *ptep, pte_t pteval); |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 183 | void (*set_pte_at)(struct mm_struct *mm, unsigned long addr, |
| 184 | pte_t *ptep, pte_t pteval); |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 185 | void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 186 | void (*pte_update)(struct mm_struct *mm, unsigned long addr, pte_t *ptep); |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 187 | void (*pte_update_defer)(struct mm_struct *mm, |
| 188 | unsigned long addr, pte_t *ptep); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 189 | |
| 190 | pte_t (*ptep_get_and_clear)(pte_t *ptep); |
| 191 | |
Jeremy Fitzhardinge | ce6234b | 2007-05-02 19:27:15 +0200 | [diff] [blame^] | 192 | #ifdef CONFIG_HIGHPTE |
| 193 | void *(*kmap_atomic_pte)(struct page *page, enum km_type type); |
| 194 | #endif |
| 195 | |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 196 | #ifdef CONFIG_X86_PAE |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 197 | void (*set_pte_atomic)(pte_t *ptep, pte_t pteval); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 198 | 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] | 199 | void (*set_pud)(pud_t *pudp, pud_t pudval); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 200 | 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] | 201 | void (*pmd_clear)(pmd_t *pmdp); |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 202 | |
| 203 | unsigned long long (*pte_val)(pte_t); |
| 204 | unsigned long long (*pmd_val)(pmd_t); |
| 205 | unsigned long long (*pgd_val)(pgd_t); |
| 206 | |
| 207 | pte_t (*make_pte)(unsigned long long pte); |
| 208 | pmd_t (*make_pmd)(unsigned long long pmd); |
| 209 | pgd_t (*make_pgd)(unsigned long long pgd); |
| 210 | #else |
| 211 | unsigned long (*pte_val)(pte_t); |
| 212 | unsigned long (*pgd_val)(pgd_t); |
| 213 | |
| 214 | pte_t (*make_pte)(unsigned long pte); |
| 215 | pgd_t (*make_pgd)(unsigned long pgd); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 216 | #endif |
| 217 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 218 | /* Set deferred update mode, used for batching operations. */ |
| 219 | void (*set_lazy_mode)(enum paravirt_lazy_mode mode); |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 220 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 221 | /* These two are jmp to, not actually called. */ |
Andi Kleen | 1a1eecd | 2007-02-13 13:26:25 +0100 | [diff] [blame] | 222 | void (*irq_enable_sysexit)(void); |
| 223 | void (*iret)(void); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 224 | }; |
| 225 | |
Rusty Russell | c9ccf30 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 226 | /* Mark a paravirt probe function. */ |
| 227 | #define paravirt_probe(fn) \ |
| 228 | static asmlinkage void (*__paravirtprobe_##fn)(void) __attribute_used__ \ |
| 229 | __attribute__((__section__(".paravirtprobe"))) = fn |
| 230 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 231 | extern struct paravirt_ops paravirt_ops; |
| 232 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 233 | #define PARAVIRT_PATCH(x) \ |
| 234 | (offsetof(struct paravirt_ops, x) / sizeof(void *)) |
| 235 | |
| 236 | #define paravirt_type(type) \ |
| 237 | [paravirt_typenum] "i" (PARAVIRT_PATCH(type)) |
| 238 | #define paravirt_clobber(clobber) \ |
| 239 | [paravirt_clobber] "i" (clobber) |
| 240 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 241 | /* |
| 242 | * Generate some code, and mark it as patchable by the |
| 243 | * apply_paravirt() alternate instruction patcher. |
| 244 | */ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 245 | #define _paravirt_alt(insn_string, type, clobber) \ |
| 246 | "771:\n\t" insn_string "\n" "772:\n" \ |
| 247 | ".pushsection .parainstructions,\"a\"\n" \ |
| 248 | " .long 771b\n" \ |
| 249 | " .byte " type "\n" \ |
| 250 | " .byte 772b-771b\n" \ |
| 251 | " .short " clobber "\n" \ |
| 252 | ".popsection\n" |
| 253 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 254 | /* Generate patchable code, with the default asm parameters. */ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 255 | #define paravirt_alt(insn_string) \ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 256 | _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]") |
| 257 | |
Jeremy Fitzhardinge | 63f7027 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 258 | unsigned paravirt_patch_nop(void); |
| 259 | unsigned paravirt_patch_ignore(unsigned len); |
| 260 | unsigned paravirt_patch_call(void *target, u16 tgt_clobbers, |
| 261 | void *site, u16 site_clobbers, |
| 262 | unsigned len); |
| 263 | unsigned paravirt_patch_jmp(void *target, void *site, unsigned len); |
| 264 | unsigned paravirt_patch_default(u8 type, u16 clobbers, void *site, unsigned len); |
| 265 | |
| 266 | unsigned paravirt_patch_insns(void *site, unsigned len, |
| 267 | const char *start, const char *end); |
| 268 | |
| 269 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 270 | /* |
| 271 | * This generates an indirect call based on the operation type number. |
| 272 | * The type number, computed in PARAVIRT_PATCH, is derived from the |
| 273 | * offset into the paravirt_ops structure, and can therefore be freely |
| 274 | * converted back into a structure offset. |
| 275 | */ |
| 276 | #define PARAVIRT_CALL "call *(paravirt_ops+%c[paravirt_typenum]*4);" |
| 277 | |
| 278 | /* |
| 279 | * These macros are intended to wrap calls into a paravirt_ops |
| 280 | * operation, so that they can be later identified and patched at |
| 281 | * runtime. |
| 282 | * |
| 283 | * Normally, a call to a pv_op function is a simple indirect call: |
| 284 | * (paravirt_ops.operations)(args...). |
| 285 | * |
| 286 | * Unfortunately, this is a relatively slow operation for modern CPUs, |
| 287 | * because it cannot necessarily determine what the destination |
| 288 | * address is. In this case, the address is a runtime constant, so at |
| 289 | * the very least we can patch the call to e a simple direct call, or |
| 290 | * ideally, patch an inline implementation into the callsite. (Direct |
| 291 | * calls are essentially free, because the call and return addresses |
| 292 | * are completely predictable.) |
| 293 | * |
| 294 | * These macros rely on the standard gcc "regparm(3)" calling |
| 295 | * convention, in which the first three arguments are placed in %eax, |
| 296 | * %edx, %ecx (in that order), and the remaining arguments are placed |
| 297 | * on the stack. All caller-save registers (eax,edx,ecx) are expected |
| 298 | * to be modified (either clobbered or used for return values). |
| 299 | * |
| 300 | * The call instruction itself is marked by placing its start address |
| 301 | * and size into the .parainstructions section, so that |
| 302 | * apply_paravirt() in arch/i386/kernel/alternative.c can do the |
| 303 | * appropriate patching under the control of the backend paravirt_ops |
| 304 | * implementation. |
| 305 | * |
| 306 | * Unfortunately there's no way to get gcc to generate the args setup |
| 307 | * for the call, and then allow the call itself to be generated by an |
| 308 | * inline asm. Because of this, we must do the complete arg setup and |
| 309 | * return value handling from within these macros. This is fairly |
| 310 | * cumbersome. |
| 311 | * |
| 312 | * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments. |
| 313 | * It could be extended to more arguments, but there would be little |
| 314 | * to be gained from that. For each number of arguments, there are |
| 315 | * the two VCALL and CALL variants for void and non-void functions. |
| 316 | * |
| 317 | * When there is a return value, the invoker of the macro must specify |
| 318 | * the return type. The macro then uses sizeof() on that type to |
| 319 | * determine whether its a 32 or 64 bit value, and places the return |
| 320 | * in the right register(s) (just %eax for 32-bit, and %edx:%eax for |
| 321 | * 64-bit). |
| 322 | * |
| 323 | * 64-bit arguments are passed as a pair of adjacent 32-bit arguments |
| 324 | * in low,high order. |
| 325 | * |
| 326 | * Small structures are passed and returned in registers. The macro |
| 327 | * calling convention can't directly deal with this, so the wrapper |
| 328 | * functions must do this. |
| 329 | * |
| 330 | * These PVOP_* macros are only defined within this header. This |
| 331 | * means that all uses must be wrapped in inline functions. This also |
| 332 | * makes sure the incoming and outgoing types are always correct. |
| 333 | */ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 334 | #define PVOP_CALL0(__rettype, __op) \ |
| 335 | ({ \ |
| 336 | __rettype __ret; \ |
| 337 | if (sizeof(__rettype) > sizeof(unsigned long)) { \ |
| 338 | unsigned long long __tmp; \ |
| 339 | unsigned long __ecx; \ |
| 340 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 341 | : "=A" (__tmp), "=c" (__ecx) \ |
| 342 | : paravirt_type(__op), \ |
| 343 | paravirt_clobber(CLBR_ANY) \ |
| 344 | : "memory", "cc"); \ |
| 345 | __ret = (__rettype)__tmp; \ |
| 346 | } else { \ |
| 347 | unsigned long __tmp, __edx, __ecx; \ |
| 348 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 349 | : "=a" (__tmp), "=d" (__edx), \ |
| 350 | "=c" (__ecx) \ |
| 351 | : paravirt_type(__op), \ |
| 352 | paravirt_clobber(CLBR_ANY) \ |
| 353 | : "memory", "cc"); \ |
| 354 | __ret = (__rettype)__tmp; \ |
| 355 | } \ |
| 356 | __ret; \ |
| 357 | }) |
| 358 | #define PVOP_VCALL0(__op) \ |
| 359 | ({ \ |
| 360 | unsigned long __eax, __edx, __ecx; \ |
| 361 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 362 | : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \ |
| 363 | : paravirt_type(__op), \ |
| 364 | paravirt_clobber(CLBR_ANY) \ |
| 365 | : "memory", "cc"); \ |
| 366 | }) |
| 367 | |
| 368 | #define PVOP_CALL1(__rettype, __op, arg1) \ |
| 369 | ({ \ |
| 370 | __rettype __ret; \ |
| 371 | if (sizeof(__rettype) > sizeof(unsigned long)) { \ |
| 372 | unsigned long long __tmp; \ |
| 373 | unsigned long __ecx; \ |
| 374 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 375 | : "=A" (__tmp), "=c" (__ecx) \ |
| 376 | : "a" ((u32)(arg1)), \ |
| 377 | paravirt_type(__op), \ |
| 378 | paravirt_clobber(CLBR_ANY) \ |
| 379 | : "memory", "cc"); \ |
| 380 | __ret = (__rettype)__tmp; \ |
| 381 | } else { \ |
| 382 | unsigned long __tmp, __edx, __ecx; \ |
| 383 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 384 | : "=a" (__tmp), "=d" (__edx), \ |
| 385 | "=c" (__ecx) \ |
| 386 | : "0" ((u32)(arg1)), \ |
| 387 | paravirt_type(__op), \ |
| 388 | paravirt_clobber(CLBR_ANY) \ |
| 389 | : "memory", "cc"); \ |
| 390 | __ret = (__rettype)__tmp; \ |
| 391 | } \ |
| 392 | __ret; \ |
| 393 | }) |
| 394 | #define PVOP_VCALL1(__op, arg1) \ |
| 395 | ({ \ |
| 396 | unsigned long __eax, __edx, __ecx; \ |
| 397 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 398 | : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \ |
| 399 | : "0" ((u32)(arg1)), \ |
| 400 | paravirt_type(__op), \ |
| 401 | paravirt_clobber(CLBR_ANY) \ |
| 402 | : "memory", "cc"); \ |
| 403 | }) |
| 404 | |
| 405 | #define PVOP_CALL2(__rettype, __op, arg1, arg2) \ |
| 406 | ({ \ |
| 407 | __rettype __ret; \ |
| 408 | if (sizeof(__rettype) > sizeof(unsigned long)) { \ |
| 409 | unsigned long long __tmp; \ |
| 410 | unsigned long __ecx; \ |
| 411 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 412 | : "=A" (__tmp), "=c" (__ecx) \ |
| 413 | : "a" ((u32)(arg1)), \ |
| 414 | "d" ((u32)(arg2)), \ |
| 415 | paravirt_type(__op), \ |
| 416 | paravirt_clobber(CLBR_ANY) \ |
| 417 | : "memory", "cc"); \ |
| 418 | __ret = (__rettype)__tmp; \ |
| 419 | } else { \ |
| 420 | unsigned long __tmp, __edx, __ecx; \ |
| 421 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 422 | : "=a" (__tmp), "=d" (__edx), \ |
| 423 | "=c" (__ecx) \ |
| 424 | : "0" ((u32)(arg1)), \ |
| 425 | "1" ((u32)(arg2)), \ |
| 426 | paravirt_type(__op), \ |
| 427 | paravirt_clobber(CLBR_ANY) \ |
| 428 | : "memory", "cc"); \ |
| 429 | __ret = (__rettype)__tmp; \ |
| 430 | } \ |
| 431 | __ret; \ |
| 432 | }) |
| 433 | #define PVOP_VCALL2(__op, arg1, arg2) \ |
| 434 | ({ \ |
| 435 | unsigned long __eax, __edx, __ecx; \ |
| 436 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 437 | : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \ |
| 438 | : "0" ((u32)(arg1)), \ |
| 439 | "1" ((u32)(arg2)), \ |
| 440 | paravirt_type(__op), \ |
| 441 | paravirt_clobber(CLBR_ANY) \ |
| 442 | : "memory", "cc"); \ |
| 443 | }) |
| 444 | |
| 445 | #define PVOP_CALL3(__rettype, __op, arg1, arg2, arg3) \ |
| 446 | ({ \ |
| 447 | __rettype __ret; \ |
| 448 | if (sizeof(__rettype) > sizeof(unsigned long)) { \ |
| 449 | unsigned long long __tmp; \ |
| 450 | unsigned long __ecx; \ |
| 451 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 452 | : "=A" (__tmp), "=c" (__ecx) \ |
| 453 | : "a" ((u32)(arg1)), \ |
| 454 | "d" ((u32)(arg2)), \ |
| 455 | "1" ((u32)(arg3)), \ |
| 456 | paravirt_type(__op), \ |
| 457 | paravirt_clobber(CLBR_ANY) \ |
| 458 | : "memory", "cc"); \ |
| 459 | __ret = (__rettype)__tmp; \ |
| 460 | } else { \ |
| 461 | unsigned long __tmp, __edx, __ecx; \ |
| 462 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 463 | : "=a" (__tmp), "=d" (__edx), \ |
| 464 | "=c" (__ecx) \ |
| 465 | : "0" ((u32)(arg1)), \ |
| 466 | "1" ((u32)(arg2)), \ |
| 467 | "2" ((u32)(arg3)), \ |
| 468 | paravirt_type(__op), \ |
| 469 | paravirt_clobber(CLBR_ANY) \ |
| 470 | : "memory", "cc"); \ |
| 471 | __ret = (__rettype)__tmp; \ |
| 472 | } \ |
| 473 | __ret; \ |
| 474 | }) |
| 475 | #define PVOP_VCALL3(__op, arg1, arg2, arg3) \ |
| 476 | ({ \ |
| 477 | unsigned long __eax, __edx, __ecx; \ |
| 478 | asm volatile(paravirt_alt(PARAVIRT_CALL) \ |
| 479 | : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \ |
| 480 | : "0" ((u32)(arg1)), \ |
| 481 | "1" ((u32)(arg2)), \ |
| 482 | "2" ((u32)(arg3)), \ |
| 483 | paravirt_type(__op), \ |
| 484 | paravirt_clobber(CLBR_ANY) \ |
| 485 | : "memory", "cc"); \ |
| 486 | }) |
| 487 | |
| 488 | #define PVOP_CALL4(__rettype, __op, arg1, arg2, arg3, arg4) \ |
| 489 | ({ \ |
| 490 | __rettype __ret; \ |
| 491 | if (sizeof(__rettype) > sizeof(unsigned long)) { \ |
| 492 | unsigned long long __tmp; \ |
| 493 | unsigned long __ecx; \ |
| 494 | asm volatile("push %[_arg4]; " \ |
| 495 | paravirt_alt(PARAVIRT_CALL) \ |
| 496 | "lea 4(%%esp),%%esp" \ |
| 497 | : "=A" (__tmp), "=c" (__ecx) \ |
| 498 | : "a" ((u32)(arg1)), \ |
| 499 | "d" ((u32)(arg2)), \ |
| 500 | "1" ((u32)(arg3)), \ |
| 501 | [_arg4] "mr" ((u32)(arg4)), \ |
| 502 | paravirt_type(__op), \ |
| 503 | paravirt_clobber(CLBR_ANY) \ |
| 504 | : "memory", "cc",); \ |
| 505 | __ret = (__rettype)__tmp; \ |
| 506 | } else { \ |
| 507 | unsigned long __tmp, __edx, __ecx; \ |
| 508 | asm volatile("push %[_arg4]; " \ |
| 509 | paravirt_alt(PARAVIRT_CALL) \ |
| 510 | "lea 4(%%esp),%%esp" \ |
| 511 | : "=a" (__tmp), "=d" (__edx), "=c" (__ecx) \ |
| 512 | : "0" ((u32)(arg1)), \ |
| 513 | "1" ((u32)(arg2)), \ |
| 514 | "2" ((u32)(arg3)), \ |
| 515 | [_arg4]"mr" ((u32)(arg4)), \ |
| 516 | paravirt_type(__op), \ |
| 517 | paravirt_clobber(CLBR_ANY) \ |
| 518 | : "memory", "cc"); \ |
| 519 | __ret = (__rettype)__tmp; \ |
| 520 | } \ |
| 521 | __ret; \ |
| 522 | }) |
| 523 | #define PVOP_VCALL4(__op, arg1, arg2, arg3, arg4) \ |
| 524 | ({ \ |
| 525 | unsigned long __eax, __edx, __ecx; \ |
| 526 | asm volatile("push %[_arg4]; " \ |
| 527 | paravirt_alt(PARAVIRT_CALL) \ |
| 528 | "lea 4(%%esp),%%esp" \ |
| 529 | : "=a" (__eax), "=d" (__edx), "=c" (__ecx) \ |
| 530 | : "0" ((u32)(arg1)), \ |
| 531 | "1" ((u32)(arg2)), \ |
| 532 | "2" ((u32)(arg3)), \ |
| 533 | [_arg4]"mr" ((u32)(arg4)), \ |
| 534 | paravirt_type(__op), \ |
| 535 | paravirt_clobber(CLBR_ANY) \ |
| 536 | : "memory", "cc"); \ |
| 537 | }) |
| 538 | |
| 539 | static inline int paravirt_enabled(void) |
| 540 | { |
| 541 | return paravirt_ops.paravirt_enabled; |
| 542 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 543 | |
| 544 | static inline void load_esp0(struct tss_struct *tss, |
| 545 | struct thread_struct *thread) |
| 546 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 547 | PVOP_VCALL2(load_esp0, tss, thread); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | #define ARCH_SETUP paravirt_ops.arch_setup(); |
| 551 | static inline unsigned long get_wallclock(void) |
| 552 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 553 | return PVOP_CALL0(unsigned long, get_wallclock); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static inline int set_wallclock(unsigned long nowtime) |
| 557 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 558 | return PVOP_CALL1(int, set_wallclock, nowtime); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Zachary Amsden | e30fab3 | 2007-03-05 00:30:39 -0800 | [diff] [blame] | 561 | static inline void (*choose_time_init(void))(void) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 562 | { |
Zachary Amsden | e30fab3 | 2007-03-05 00:30:39 -0800 | [diff] [blame] | 563 | return paravirt_ops.time_init; |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* The paravirtualized CPUID instruction. */ |
| 567 | static inline void __cpuid(unsigned int *eax, unsigned int *ebx, |
| 568 | unsigned int *ecx, unsigned int *edx) |
| 569 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 570 | PVOP_VCALL4(cpuid, eax, ebx, ecx, edx); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /* |
| 574 | * These special macros can be used to get or set a debugging register |
| 575 | */ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 576 | static inline unsigned long paravirt_get_debugreg(int reg) |
| 577 | { |
| 578 | return PVOP_CALL1(unsigned long, get_debugreg, reg); |
| 579 | } |
| 580 | #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg) |
| 581 | static inline void set_debugreg(unsigned long val, int reg) |
| 582 | { |
| 583 | PVOP_VCALL2(set_debugreg, reg, val); |
| 584 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 585 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 586 | static inline void clts(void) |
| 587 | { |
| 588 | PVOP_VCALL0(clts); |
| 589 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 590 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 591 | static inline unsigned long read_cr0(void) |
| 592 | { |
| 593 | return PVOP_CALL0(unsigned long, read_cr0); |
| 594 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 595 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 596 | static inline void write_cr0(unsigned long x) |
| 597 | { |
| 598 | PVOP_VCALL1(write_cr0, x); |
| 599 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 600 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 601 | static inline unsigned long read_cr2(void) |
| 602 | { |
| 603 | return PVOP_CALL0(unsigned long, read_cr2); |
| 604 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 605 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 606 | static inline void write_cr2(unsigned long x) |
| 607 | { |
| 608 | PVOP_VCALL1(write_cr2, x); |
| 609 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 610 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 611 | static inline unsigned long read_cr3(void) |
| 612 | { |
| 613 | return PVOP_CALL0(unsigned long, read_cr3); |
| 614 | } |
| 615 | |
| 616 | static inline void write_cr3(unsigned long x) |
| 617 | { |
| 618 | PVOP_VCALL1(write_cr3, x); |
| 619 | } |
| 620 | |
| 621 | static inline unsigned long read_cr4(void) |
| 622 | { |
| 623 | return PVOP_CALL0(unsigned long, read_cr4); |
| 624 | } |
| 625 | static inline unsigned long read_cr4_safe(void) |
| 626 | { |
| 627 | return PVOP_CALL0(unsigned long, read_cr4_safe); |
| 628 | } |
| 629 | |
| 630 | static inline void write_cr4(unsigned long x) |
| 631 | { |
| 632 | PVOP_VCALL1(write_cr4, x); |
| 633 | } |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 634 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 635 | static inline void raw_safe_halt(void) |
| 636 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 637 | PVOP_VCALL0(safe_halt); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static inline void halt(void) |
| 641 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 642 | PVOP_VCALL0(safe_halt); |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 643 | } |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 644 | |
| 645 | static inline void wbinvd(void) |
| 646 | { |
| 647 | PVOP_VCALL0(wbinvd); |
| 648 | } |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 649 | |
| 650 | #define get_kernel_rpl() (paravirt_ops.kernel_rpl) |
| 651 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 652 | static inline u64 paravirt_read_msr(unsigned msr, int *err) |
| 653 | { |
| 654 | return PVOP_CALL2(u64, read_msr, msr, err); |
| 655 | } |
| 656 | static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high) |
| 657 | { |
| 658 | return PVOP_CALL3(int, write_msr, msr, low, high); |
| 659 | } |
| 660 | |
Rusty Russell | 90a0a06 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 661 | /* These should all do BUG_ON(_err), but our headers are too tangled. */ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 662 | #define rdmsr(msr,val1,val2) do { \ |
| 663 | int _err; \ |
| 664 | u64 _l = paravirt_read_msr(msr, &_err); \ |
| 665 | val1 = (u32)_l; \ |
| 666 | val2 = _l >> 32; \ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 667 | } while(0) |
| 668 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 669 | #define wrmsr(msr,val1,val2) do { \ |
| 670 | paravirt_write_msr(msr, val1, val2); \ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 671 | } while(0) |
| 672 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 673 | #define rdmsrl(msr,val) do { \ |
| 674 | int _err; \ |
| 675 | val = paravirt_read_msr(msr, &_err); \ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 676 | } while(0) |
| 677 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 678 | #define wrmsrl(msr,val) ((void)paravirt_write_msr(msr, val, 0)) |
| 679 | #define wrmsr_safe(msr,a,b) paravirt_write_msr(msr, a, b) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 680 | |
| 681 | /* rdmsr with exception handling */ |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 682 | #define rdmsr_safe(msr,a,b) ({ \ |
| 683 | int _err; \ |
| 684 | u64 _l = paravirt_read_msr(msr, &_err); \ |
| 685 | (*a) = (u32)_l; \ |
| 686 | (*b) = _l >> 32; \ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 687 | _err; }) |
| 688 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 689 | |
| 690 | static inline u64 paravirt_read_tsc(void) |
| 691 | { |
| 692 | return PVOP_CALL0(u64, read_tsc); |
| 693 | } |
| 694 | #define rdtsc(low,high) do { \ |
| 695 | u64 _l = paravirt_read_tsc(); \ |
| 696 | low = (u32)_l; \ |
| 697 | high = _l >> 32; \ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 698 | } while(0) |
| 699 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 700 | #define rdtscl(low) do { \ |
| 701 | u64 _l = paravirt_read_tsc(); \ |
| 702 | low = (int)_l; \ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 703 | } while(0) |
| 704 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 705 | #define rdtscll(val) (val = paravirt_read_tsc()) |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 706 | |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 707 | #define get_scheduled_cycles(val) (val = paravirt_ops.get_scheduled_cycles()) |
Zachary Amsden | 1182d85 | 2007-03-05 00:30:36 -0800 | [diff] [blame] | 708 | #define calculate_cpu_khz() (paravirt_ops.get_cpu_khz()) |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 709 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 710 | #define write_tsc(val1,val2) wrmsr(0x10, val1, val2) |
| 711 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 712 | static inline unsigned long long paravirt_read_pmc(int counter) |
| 713 | { |
| 714 | return PVOP_CALL1(u64, read_pmc, counter); |
| 715 | } |
| 716 | |
| 717 | #define rdpmc(counter,low,high) do { \ |
| 718 | u64 _l = paravirt_read_pmc(counter); \ |
| 719 | low = (u32)_l; \ |
| 720 | high = _l >> 32; \ |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 721 | } while(0) |
| 722 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 723 | static inline void load_TR_desc(void) |
| 724 | { |
| 725 | PVOP_VCALL0(load_tr_desc); |
| 726 | } |
| 727 | static inline void load_gdt(const struct Xgt_desc_struct *dtr) |
| 728 | { |
| 729 | PVOP_VCALL1(load_gdt, dtr); |
| 730 | } |
| 731 | static inline void load_idt(const struct Xgt_desc_struct *dtr) |
| 732 | { |
| 733 | PVOP_VCALL1(load_idt, dtr); |
| 734 | } |
| 735 | static inline void set_ldt(const void *addr, unsigned entries) |
| 736 | { |
| 737 | PVOP_VCALL2(set_ldt, addr, entries); |
| 738 | } |
| 739 | static inline void store_gdt(struct Xgt_desc_struct *dtr) |
| 740 | { |
| 741 | PVOP_VCALL1(store_gdt, dtr); |
| 742 | } |
| 743 | static inline void store_idt(struct Xgt_desc_struct *dtr) |
| 744 | { |
| 745 | PVOP_VCALL1(store_idt, dtr); |
| 746 | } |
| 747 | static inline unsigned long paravirt_store_tr(void) |
| 748 | { |
| 749 | return PVOP_CALL0(unsigned long, store_tr); |
| 750 | } |
| 751 | #define store_tr(tr) ((tr) = paravirt_store_tr()) |
| 752 | static inline void load_TLS(struct thread_struct *t, unsigned cpu) |
| 753 | { |
| 754 | PVOP_VCALL2(load_tls, t, cpu); |
| 755 | } |
| 756 | static inline void write_ldt_entry(void *dt, int entry, u32 low, u32 high) |
| 757 | { |
| 758 | PVOP_VCALL4(write_ldt_entry, dt, entry, low, high); |
| 759 | } |
| 760 | static inline void write_gdt_entry(void *dt, int entry, u32 low, u32 high) |
| 761 | { |
| 762 | PVOP_VCALL4(write_gdt_entry, dt, entry, low, high); |
| 763 | } |
| 764 | static inline void write_idt_entry(void *dt, int entry, u32 low, u32 high) |
| 765 | { |
| 766 | PVOP_VCALL4(write_idt_entry, dt, entry, low, high); |
| 767 | } |
| 768 | static inline void set_iopl_mask(unsigned mask) |
| 769 | { |
| 770 | PVOP_VCALL1(set_iopl_mask, mask); |
| 771 | } |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 772 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 773 | /* The paravirtualized I/O functions */ |
| 774 | static inline void slow_down_io(void) { |
| 775 | paravirt_ops.io_delay(); |
| 776 | #ifdef REALLY_SLOW_IO |
| 777 | paravirt_ops.io_delay(); |
| 778 | paravirt_ops.io_delay(); |
| 779 | paravirt_ops.io_delay(); |
| 780 | #endif |
| 781 | } |
| 782 | |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 783 | #ifdef CONFIG_X86_LOCAL_APIC |
| 784 | /* |
| 785 | * Basic functions accessing APICs. |
| 786 | */ |
| 787 | static inline void apic_write(unsigned long reg, unsigned long v) |
| 788 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 789 | PVOP_VCALL2(apic_write, reg, v); |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static inline void apic_write_atomic(unsigned long reg, unsigned long v) |
| 793 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 794 | PVOP_VCALL2(apic_write_atomic, reg, v); |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static inline unsigned long apic_read(unsigned long reg) |
| 798 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 799 | return PVOP_CALL1(unsigned long, apic_read, reg); |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 800 | } |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 801 | |
| 802 | static inline void setup_boot_clock(void) |
| 803 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 804 | PVOP_VCALL0(setup_boot_clock); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | static inline void setup_secondary_clock(void) |
| 808 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 809 | PVOP_VCALL0(setup_secondary_clock); |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 810 | } |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 811 | #endif |
| 812 | |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 813 | static inline void paravirt_pagetable_setup_start(pgd_t *base) |
| 814 | { |
| 815 | if (paravirt_ops.pagetable_setup_start) |
| 816 | (*paravirt_ops.pagetable_setup_start)(base); |
| 817 | } |
| 818 | |
| 819 | static inline void paravirt_pagetable_setup_done(pgd_t *base) |
| 820 | { |
| 821 | if (paravirt_ops.pagetable_setup_done) |
| 822 | (*paravirt_ops.pagetable_setup_done)(base); |
| 823 | } |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 824 | |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 825 | #ifdef CONFIG_SMP |
| 826 | static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip, |
| 827 | unsigned long start_esp) |
| 828 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 829 | PVOP_VCALL3(startup_ipi_hook, phys_apicid, start_eip, start_esp); |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 830 | } |
| 831 | #endif |
Rusty Russell | 13623d7 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 832 | |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 833 | static inline void paravirt_activate_mm(struct mm_struct *prev, |
| 834 | struct mm_struct *next) |
| 835 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 836 | PVOP_VCALL2(activate_mm, prev, next); |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | static inline void arch_dup_mmap(struct mm_struct *oldmm, |
| 840 | struct mm_struct *mm) |
| 841 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 842 | PVOP_VCALL2(dup_mmap, oldmm, mm); |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | static inline void arch_exit_mmap(struct mm_struct *mm) |
| 846 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 847 | PVOP_VCALL1(exit_mmap, mm); |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 848 | } |
| 849 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 850 | static inline void __flush_tlb(void) |
| 851 | { |
| 852 | PVOP_VCALL0(flush_tlb_user); |
| 853 | } |
| 854 | static inline void __flush_tlb_global(void) |
| 855 | { |
| 856 | PVOP_VCALL0(flush_tlb_kernel); |
| 857 | } |
| 858 | static inline void __flush_tlb_single(unsigned long addr) |
| 859 | { |
| 860 | PVOP_VCALL1(flush_tlb_single, addr); |
| 861 | } |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 862 | |
Jeremy Fitzhardinge | d4c1047 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 863 | static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm, |
| 864 | unsigned long va) |
| 865 | { |
| 866 | PVOP_VCALL3(flush_tlb_others, &cpumask, mm, va); |
| 867 | } |
| 868 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 869 | static inline void paravirt_alloc_pt(unsigned pfn) |
| 870 | { |
| 871 | PVOP_VCALL1(alloc_pt, pfn); |
| 872 | } |
| 873 | static inline void paravirt_release_pt(unsigned pfn) |
| 874 | { |
| 875 | PVOP_VCALL1(release_pt, pfn); |
| 876 | } |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 877 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 878 | static inline void paravirt_alloc_pd(unsigned pfn) |
| 879 | { |
| 880 | PVOP_VCALL1(alloc_pd, pfn); |
| 881 | } |
| 882 | |
| 883 | static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn, |
| 884 | unsigned start, unsigned count) |
| 885 | { |
| 886 | PVOP_VCALL4(alloc_pd_clone, pfn, clonepfn, start, count); |
| 887 | } |
| 888 | static inline void paravirt_release_pd(unsigned pfn) |
| 889 | { |
| 890 | PVOP_VCALL1(release_pd, pfn); |
| 891 | } |
| 892 | |
Jeremy Fitzhardinge | ce6234b | 2007-05-02 19:27:15 +0200 | [diff] [blame^] | 893 | #ifdef CONFIG_HIGHPTE |
| 894 | static inline void *kmap_atomic_pte(struct page *page, enum km_type type) |
| 895 | { |
| 896 | unsigned long ret; |
| 897 | ret = PVOP_CALL2(unsigned long, kmap_atomic_pte, page, type); |
| 898 | return (void *)ret; |
| 899 | } |
| 900 | #endif |
| 901 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 902 | static inline void pte_update(struct mm_struct *mm, unsigned long addr, |
| 903 | pte_t *ptep) |
| 904 | { |
| 905 | PVOP_VCALL3(pte_update, mm, addr, ptep); |
| 906 | } |
| 907 | |
| 908 | static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr, |
| 909 | pte_t *ptep) |
| 910 | { |
| 911 | PVOP_VCALL3(pte_update_defer, mm, addr, ptep); |
| 912 | } |
| 913 | |
| 914 | #ifdef CONFIG_X86_PAE |
| 915 | static inline pte_t __pte(unsigned long long val) |
| 916 | { |
| 917 | unsigned long long ret = PVOP_CALL2(unsigned long long, make_pte, |
| 918 | val, val >> 32); |
| 919 | return (pte_t) { ret, ret >> 32 }; |
| 920 | } |
| 921 | |
| 922 | static inline pmd_t __pmd(unsigned long long val) |
| 923 | { |
| 924 | return (pmd_t) { PVOP_CALL2(unsigned long long, make_pmd, val, val >> 32) }; |
| 925 | } |
| 926 | |
| 927 | static inline pgd_t __pgd(unsigned long long val) |
| 928 | { |
| 929 | return (pgd_t) { PVOP_CALL2(unsigned long long, make_pgd, val, val >> 32) }; |
| 930 | } |
| 931 | |
| 932 | static inline unsigned long long pte_val(pte_t x) |
| 933 | { |
| 934 | return PVOP_CALL2(unsigned long long, pte_val, x.pte_low, x.pte_high); |
| 935 | } |
| 936 | |
| 937 | static inline unsigned long long pmd_val(pmd_t x) |
| 938 | { |
| 939 | return PVOP_CALL2(unsigned long long, pmd_val, x.pmd, x.pmd >> 32); |
| 940 | } |
| 941 | |
| 942 | static inline unsigned long long pgd_val(pgd_t x) |
| 943 | { |
| 944 | return PVOP_CALL2(unsigned long long, pgd_val, x.pgd, x.pgd >> 32); |
| 945 | } |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 946 | |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 947 | static inline void set_pte(pte_t *ptep, pte_t pteval) |
| 948 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 949 | PVOP_VCALL3(set_pte, ptep, pteval.pte_low, pteval.pte_high); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 950 | } |
| 951 | |
Jeremy Fitzhardinge | 3dc494e | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 952 | static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 953 | pte_t *ptep, pte_t pteval) |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 954 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 955 | /* 5 arg words */ |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 956 | paravirt_ops.set_pte_at(mm, addr, ptep, pteval); |
| 957 | } |
| 958 | |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 959 | static inline void set_pte_atomic(pte_t *ptep, pte_t pteval) |
| 960 | { |
| 961 | PVOP_VCALL3(set_pte_atomic, ptep, pteval.pte_low, pteval.pte_high); |
| 962 | } |
| 963 | |
| 964 | static inline void set_pte_present(struct mm_struct *mm, unsigned long addr, |
| 965 | pte_t *ptep, pte_t pte) |
| 966 | { |
| 967 | /* 5 arg words */ |
| 968 | paravirt_ops.set_pte_present(mm, addr, ptep, pte); |
| 969 | } |
| 970 | |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 971 | static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval) |
| 972 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 973 | PVOP_VCALL3(set_pmd, pmdp, pmdval.pmd, pmdval.pmd >> 32); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static inline void set_pud(pud_t *pudp, pud_t pudval) |
| 977 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 978 | PVOP_VCALL3(set_pud, pudp, pudval.pgd.pgd, pudval.pgd.pgd >> 32); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) |
| 982 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 983 | PVOP_VCALL3(pte_clear, mm, addr, ptep); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | static inline void pmd_clear(pmd_t *pmdp) |
| 987 | { |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 988 | PVOP_VCALL1(pmd_clear, pmdp); |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 989 | } |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 990 | |
| 991 | static inline pte_t raw_ptep_get_and_clear(pte_t *p) |
| 992 | { |
| 993 | unsigned long long val = PVOP_CALL1(unsigned long long, ptep_get_and_clear, p); |
| 994 | return (pte_t) { val, val >> 32 }; |
| 995 | } |
| 996 | #else /* !CONFIG_X86_PAE */ |
| 997 | static inline pte_t __pte(unsigned long val) |
| 998 | { |
| 999 | return (pte_t) { PVOP_CALL1(unsigned long, make_pte, val) }; |
| 1000 | } |
| 1001 | |
| 1002 | static inline pgd_t __pgd(unsigned long val) |
| 1003 | { |
| 1004 | return (pgd_t) { PVOP_CALL1(unsigned long, make_pgd, val) }; |
| 1005 | } |
| 1006 | |
| 1007 | static inline unsigned long pte_val(pte_t x) |
| 1008 | { |
| 1009 | return PVOP_CALL1(unsigned long, pte_val, x.pte_low); |
| 1010 | } |
| 1011 | |
| 1012 | static inline unsigned long pgd_val(pgd_t x) |
| 1013 | { |
| 1014 | return PVOP_CALL1(unsigned long, pgd_val, x.pgd); |
| 1015 | } |
| 1016 | |
| 1017 | static inline void set_pte(pte_t *ptep, pte_t pteval) |
| 1018 | { |
| 1019 | PVOP_VCALL2(set_pte, ptep, pteval.pte_low); |
| 1020 | } |
| 1021 | |
| 1022 | static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, |
| 1023 | pte_t *ptep, pte_t pteval) |
| 1024 | { |
| 1025 | PVOP_VCALL4(set_pte_at, mm, addr, ptep, pteval.pte_low); |
| 1026 | } |
| 1027 | |
| 1028 | static inline void set_pmd(pmd_t *pmdp, pmd_t pmdval) |
| 1029 | { |
| 1030 | PVOP_VCALL2(set_pmd, pmdp, pmdval.pud.pgd.pgd); |
| 1031 | } |
| 1032 | |
| 1033 | static inline pte_t raw_ptep_get_and_clear(pte_t *p) |
| 1034 | { |
| 1035 | return (pte_t) { PVOP_CALL1(unsigned long, ptep_get_and_clear, p) }; |
| 1036 | } |
| 1037 | #endif /* CONFIG_X86_PAE */ |
Rusty Russell | da181a8 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1038 | |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1039 | /* Lazy mode for batching updates / context switch */ |
| 1040 | #define PARAVIRT_LAZY_NONE 0 |
| 1041 | #define PARAVIRT_LAZY_MMU 1 |
| 1042 | #define PARAVIRT_LAZY_CPU 2 |
Zachary Amsden | 49f1971 | 2007-04-08 16:04:01 -0700 | [diff] [blame] | 1043 | #define PARAVIRT_LAZY_FLUSH 3 |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1044 | |
| 1045 | #define __HAVE_ARCH_ENTER_LAZY_CPU_MODE |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1046 | static inline void arch_enter_lazy_cpu_mode(void) |
| 1047 | { |
| 1048 | PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_CPU); |
| 1049 | } |
| 1050 | |
| 1051 | static inline void arch_leave_lazy_cpu_mode(void) |
| 1052 | { |
| 1053 | PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE); |
| 1054 | } |
| 1055 | |
| 1056 | static inline void arch_flush_lazy_cpu_mode(void) |
| 1057 | { |
| 1058 | PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH); |
| 1059 | } |
| 1060 | |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1061 | |
| 1062 | #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1063 | static inline void arch_enter_lazy_mmu_mode(void) |
| 1064 | { |
| 1065 | PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_MMU); |
| 1066 | } |
| 1067 | |
| 1068 | static inline void arch_leave_lazy_mmu_mode(void) |
| 1069 | { |
| 1070 | PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_NONE); |
| 1071 | } |
| 1072 | |
| 1073 | static inline void arch_flush_lazy_mmu_mode(void) |
| 1074 | { |
| 1075 | PVOP_VCALL1(set_lazy_mode, PARAVIRT_LAZY_FLUSH); |
| 1076 | } |
Zachary Amsden | 9226d12 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1077 | |
Jeremy Fitzhardinge | 4587623 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 1078 | void _paravirt_nop(void); |
| 1079 | #define paravirt_nop ((void *)_paravirt_nop) |
| 1080 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1081 | /* These all sit in the .parainstructions section to tell us what to patch. */ |
Jeremy Fitzhardinge | 98de032 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1082 | struct paravirt_patch_site { |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1083 | u8 *instr; /* original instructions */ |
| 1084 | u8 instrtype; /* type of this instruction */ |
| 1085 | u8 len; /* length of original instruction */ |
| 1086 | u16 clobbers; /* what registers you may clobber */ |
| 1087 | }; |
| 1088 | |
Jeremy Fitzhardinge | 98de032 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1089 | extern struct paravirt_patch_site __parainstructions[], |
| 1090 | __parainstructions_end[]; |
| 1091 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1092 | static inline unsigned long __raw_local_save_flags(void) |
| 1093 | { |
| 1094 | unsigned long f; |
| 1095 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1096 | asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;" |
| 1097 | PARAVIRT_CALL |
| 1098 | "popl %%edx; popl %%ecx") |
| 1099 | : "=a"(f) |
| 1100 | : paravirt_type(save_fl), |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1101 | paravirt_clobber(CLBR_EAX) |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1102 | : "memory", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1103 | return f; |
| 1104 | } |
| 1105 | |
| 1106 | static inline void raw_local_irq_restore(unsigned long f) |
| 1107 | { |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1108 | asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;" |
| 1109 | PARAVIRT_CALL |
| 1110 | "popl %%edx; popl %%ecx") |
| 1111 | : "=a"(f) |
| 1112 | : "0"(f), |
| 1113 | paravirt_type(restore_fl), |
| 1114 | paravirt_clobber(CLBR_EAX) |
| 1115 | : "memory", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static inline void raw_local_irq_disable(void) |
| 1119 | { |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1120 | asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;" |
| 1121 | PARAVIRT_CALL |
| 1122 | "popl %%edx; popl %%ecx") |
| 1123 | : |
| 1124 | : paravirt_type(irq_disable), |
| 1125 | paravirt_clobber(CLBR_EAX) |
| 1126 | : "memory", "eax", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static inline void raw_local_irq_enable(void) |
| 1130 | { |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1131 | asm volatile(paravirt_alt("pushl %%ecx; pushl %%edx;" |
| 1132 | PARAVIRT_CALL |
| 1133 | "popl %%edx; popl %%ecx") |
| 1134 | : |
| 1135 | : paravirt_type(irq_enable), |
| 1136 | paravirt_clobber(CLBR_EAX) |
| 1137 | : "memory", "eax", "cc"); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static inline unsigned long __raw_local_irq_save(void) |
| 1141 | { |
| 1142 | unsigned long f; |
| 1143 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1144 | f = __raw_local_save_flags(); |
| 1145 | raw_local_irq_disable(); |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1146 | return f; |
| 1147 | } |
| 1148 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1149 | #define CLI_STRING \ |
| 1150 | _paravirt_alt("pushl %%ecx; pushl %%edx;" \ |
| 1151 | "call *paravirt_ops+%c[paravirt_cli_type]*4;" \ |
| 1152 | "popl %%edx; popl %%ecx", \ |
| 1153 | "%c[paravirt_cli_type]", "%c[paravirt_clobber]") |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1154 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1155 | #define STI_STRING \ |
| 1156 | _paravirt_alt("pushl %%ecx; pushl %%edx;" \ |
| 1157 | "call *paravirt_ops+%c[paravirt_sti_type]*4;" \ |
| 1158 | "popl %%edx; popl %%ecx", \ |
| 1159 | "%c[paravirt_sti_type]", "%c[paravirt_clobber]") |
| 1160 | |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1161 | #define CLI_STI_CLOBBERS , "%eax" |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1162 | #define CLI_STI_INPUT_ARGS \ |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1163 | , \ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1164 | [paravirt_cli_type] "i" (PARAVIRT_PATCH(irq_disable)), \ |
| 1165 | [paravirt_sti_type] "i" (PARAVIRT_PATCH(irq_enable)), \ |
| 1166 | paravirt_clobber(CLBR_EAX) |
| 1167 | |
Jeremy Fitzhardinge | 294688c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1168 | /* Make sure as little as possible of this mess escapes. */ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1169 | #undef PARAVIRT_CALL |
Jeremy Fitzhardinge | f8822f4 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1170 | #undef PVOP_VCALL0 |
| 1171 | #undef PVOP_CALL0 |
| 1172 | #undef PVOP_VCALL1 |
| 1173 | #undef PVOP_CALL1 |
| 1174 | #undef PVOP_VCALL2 |
| 1175 | #undef PVOP_CALL2 |
| 1176 | #undef PVOP_VCALL3 |
| 1177 | #undef PVOP_CALL3 |
| 1178 | #undef PVOP_VCALL4 |
| 1179 | #undef PVOP_CALL4 |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1180 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 1181 | #else /* __ASSEMBLY__ */ |
| 1182 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1183 | #define PARA_PATCH(off) ((off) / 4) |
| 1184 | |
| 1185 | #define PARA_SITE(ptype, clobbers, ops) \ |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1186 | 771:; \ |
| 1187 | ops; \ |
| 1188 | 772:; \ |
| 1189 | .pushsection .parainstructions,"a"; \ |
| 1190 | .long 771b; \ |
| 1191 | .byte ptype; \ |
| 1192 | .byte 772b-771b; \ |
| 1193 | .short clobbers; \ |
| 1194 | .popsection |
| 1195 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1196 | #define INTERRUPT_RETURN \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1197 | PARA_SITE(PARA_PATCH(PARAVIRT_iret), CLBR_NONE, \ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1198 | jmp *%cs:paravirt_ops+PARAVIRT_iret) |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1199 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1200 | #define DISABLE_INTERRUPTS(clobbers) \ |
| 1201 | PARA_SITE(PARA_PATCH(PARAVIRT_irq_disable), clobbers, \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1202 | pushl %eax; pushl %ecx; pushl %edx; \ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1203 | call *%cs:paravirt_ops+PARAVIRT_irq_disable; \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1204 | popl %edx; popl %ecx; popl %eax) \ |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1205 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1206 | #define ENABLE_INTERRUPTS(clobbers) \ |
| 1207 | PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable), clobbers, \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1208 | pushl %eax; pushl %ecx; pushl %edx; \ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1209 | call *%cs:paravirt_ops+PARAVIRT_irq_enable; \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1210 | popl %edx; popl %ecx; popl %eax) |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1211 | |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1212 | #define ENABLE_INTERRUPTS_SYSEXIT \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1213 | PARA_SITE(PARA_PATCH(PARAVIRT_irq_enable_sysexit), CLBR_NONE, \ |
Jeremy Fitzhardinge | d582203 | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1214 | jmp *%cs:paravirt_ops+PARAVIRT_irq_enable_sysexit) |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1215 | |
| 1216 | #define GET_CR0_INTO_EAX \ |
Jeremy Fitzhardinge | 42c24fa | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 1217 | push %ecx; push %edx; \ |
| 1218 | call *paravirt_ops+PARAVIRT_read_cr0; \ |
| 1219 | pop %edx; pop %ecx |
Rusty Russell | 139ec7c | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 1220 | |
Rusty Russell | d3561b7 | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 1221 | #endif /* __ASSEMBLY__ */ |
| 1222 | #endif /* CONFIG_PARAVIRT */ |
| 1223 | #endif /* __ASM_PARAVIRT_H */ |