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