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