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