1ac5672f8SJeremy Fitzhardinge #ifndef _ASM_X86_PARAVIRT_TYPES_H 2ac5672f8SJeremy Fitzhardinge #define _ASM_X86_PARAVIRT_TYPES_H 3ac5672f8SJeremy Fitzhardinge 4ac5672f8SJeremy Fitzhardinge /* Bitmask of what can be clobbered: usually at least eax. */ 5ac5672f8SJeremy Fitzhardinge #define CLBR_NONE 0 6ac5672f8SJeremy Fitzhardinge #define CLBR_EAX (1 << 0) 7ac5672f8SJeremy Fitzhardinge #define CLBR_ECX (1 << 1) 8ac5672f8SJeremy Fitzhardinge #define CLBR_EDX (1 << 2) 9ac5672f8SJeremy Fitzhardinge #define CLBR_EDI (1 << 3) 10ac5672f8SJeremy Fitzhardinge 11ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_32 12ac5672f8SJeremy Fitzhardinge /* CLBR_ANY should match all regs platform has. For i386, that's just it */ 13ac5672f8SJeremy Fitzhardinge #define CLBR_ANY ((1 << 4) - 1) 14ac5672f8SJeremy Fitzhardinge 15ac5672f8SJeremy Fitzhardinge #define CLBR_ARG_REGS (CLBR_EAX | CLBR_EDX | CLBR_ECX) 16ac5672f8SJeremy Fitzhardinge #define CLBR_RET_REG (CLBR_EAX | CLBR_EDX) 17ac5672f8SJeremy Fitzhardinge #define CLBR_SCRATCH (0) 18ac5672f8SJeremy Fitzhardinge #else 19ac5672f8SJeremy Fitzhardinge #define CLBR_RAX CLBR_EAX 20ac5672f8SJeremy Fitzhardinge #define CLBR_RCX CLBR_ECX 21ac5672f8SJeremy Fitzhardinge #define CLBR_RDX CLBR_EDX 22ac5672f8SJeremy Fitzhardinge #define CLBR_RDI CLBR_EDI 23ac5672f8SJeremy Fitzhardinge #define CLBR_RSI (1 << 4) 24ac5672f8SJeremy Fitzhardinge #define CLBR_R8 (1 << 5) 25ac5672f8SJeremy Fitzhardinge #define CLBR_R9 (1 << 6) 26ac5672f8SJeremy Fitzhardinge #define CLBR_R10 (1 << 7) 27ac5672f8SJeremy Fitzhardinge #define CLBR_R11 (1 << 8) 28ac5672f8SJeremy Fitzhardinge 29ac5672f8SJeremy Fitzhardinge #define CLBR_ANY ((1 << 9) - 1) 30ac5672f8SJeremy Fitzhardinge 31ac5672f8SJeremy Fitzhardinge #define CLBR_ARG_REGS (CLBR_RDI | CLBR_RSI | CLBR_RDX | \ 32ac5672f8SJeremy Fitzhardinge CLBR_RCX | CLBR_R8 | CLBR_R9) 33ac5672f8SJeremy Fitzhardinge #define CLBR_RET_REG (CLBR_RAX) 34ac5672f8SJeremy Fitzhardinge #define CLBR_SCRATCH (CLBR_R10 | CLBR_R11) 35ac5672f8SJeremy Fitzhardinge 36ac5672f8SJeremy Fitzhardinge #endif /* X86_64 */ 37ac5672f8SJeremy Fitzhardinge 38ac5672f8SJeremy Fitzhardinge #define CLBR_CALLEE_SAVE ((CLBR_ARG_REGS | CLBR_SCRATCH) & ~CLBR_RET_REG) 39ac5672f8SJeremy Fitzhardinge 40ac5672f8SJeremy Fitzhardinge #ifndef __ASSEMBLY__ 41ac5672f8SJeremy Fitzhardinge 42ac5672f8SJeremy Fitzhardinge #include <asm/desc_defs.h> 43ac5672f8SJeremy Fitzhardinge #include <asm/kmap_types.h> 44318f5a2aSAndy Lutomirski #include <asm/pgtable_types.h> 45ac5672f8SJeremy Fitzhardinge 46ac5672f8SJeremy Fitzhardinge struct page; 47ac5672f8SJeremy Fitzhardinge struct thread_struct; 48ac5672f8SJeremy Fitzhardinge struct desc_ptr; 49ac5672f8SJeremy Fitzhardinge struct tss_struct; 50ac5672f8SJeremy Fitzhardinge struct mm_struct; 51ac5672f8SJeremy Fitzhardinge struct desc_struct; 52ac5672f8SJeremy Fitzhardinge struct task_struct; 53ac5672f8SJeremy Fitzhardinge struct cpumask; 54ac5672f8SJeremy Fitzhardinge 55ac5672f8SJeremy Fitzhardinge /* 56ac5672f8SJeremy Fitzhardinge * Wrapper type for pointers to code which uses the non-standard 57ac5672f8SJeremy Fitzhardinge * calling convention. See PV_CALL_SAVE_REGS_THUNK below. 58ac5672f8SJeremy Fitzhardinge */ 59ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save { 60ac5672f8SJeremy Fitzhardinge void *func; 61ac5672f8SJeremy Fitzhardinge }; 62ac5672f8SJeremy Fitzhardinge 63ac5672f8SJeremy Fitzhardinge /* general info */ 64ac5672f8SJeremy Fitzhardinge struct pv_info { 65ac5672f8SJeremy Fitzhardinge unsigned int kernel_rpl; 66ac5672f8SJeremy Fitzhardinge int shared_kernel_pmd; 67318f5a2aSAndy Lutomirski 68318f5a2aSAndy Lutomirski #ifdef CONFIG_X86_64 69318f5a2aSAndy Lutomirski u16 extra_user_64bit_cs; /* __USER_CS if none */ 70318f5a2aSAndy Lutomirski #endif 71318f5a2aSAndy Lutomirski 72ac5672f8SJeremy Fitzhardinge const char *name; 73ac5672f8SJeremy Fitzhardinge }; 74ac5672f8SJeremy Fitzhardinge 75ac5672f8SJeremy Fitzhardinge struct pv_init_ops { 76ac5672f8SJeremy Fitzhardinge /* 77ac5672f8SJeremy Fitzhardinge * Patch may replace one of the defined code sequences with 78ac5672f8SJeremy Fitzhardinge * arbitrary code, subject to the same register constraints. 79ac5672f8SJeremy Fitzhardinge * This generally means the code is not free to clobber any 80ac5672f8SJeremy Fitzhardinge * registers other than EAX. The patch function should return 81ac5672f8SJeremy Fitzhardinge * the number of bytes of code generated, as we nop pad the 82ac5672f8SJeremy Fitzhardinge * rest in generic code. 83ac5672f8SJeremy Fitzhardinge */ 84ac5672f8SJeremy Fitzhardinge unsigned (*patch)(u8 type, u16 clobber, void *insnbuf, 85ac5672f8SJeremy Fitzhardinge unsigned long addr, unsigned len); 86ac5672f8SJeremy Fitzhardinge }; 87ac5672f8SJeremy Fitzhardinge 88ac5672f8SJeremy Fitzhardinge 89ac5672f8SJeremy Fitzhardinge struct pv_lazy_ops { 90ac5672f8SJeremy Fitzhardinge /* Set deferred update mode, used for batching operations. */ 91ac5672f8SJeremy Fitzhardinge void (*enter)(void); 92ac5672f8SJeremy Fitzhardinge void (*leave)(void); 93511ba86eSBoris Ostrovsky void (*flush)(void); 94ac5672f8SJeremy Fitzhardinge }; 95ac5672f8SJeremy Fitzhardinge 96ac5672f8SJeremy Fitzhardinge struct pv_time_ops { 97ac5672f8SJeremy Fitzhardinge unsigned long long (*sched_clock)(void); 983c404b57SGlauber Costa unsigned long long (*steal_clock)(int cpu); 99ac5672f8SJeremy Fitzhardinge }; 100ac5672f8SJeremy Fitzhardinge 101ac5672f8SJeremy Fitzhardinge struct pv_cpu_ops { 102ac5672f8SJeremy Fitzhardinge /* hooks for various privileged instructions */ 103ac5672f8SJeremy Fitzhardinge unsigned long (*get_debugreg)(int regno); 104ac5672f8SJeremy Fitzhardinge void (*set_debugreg)(int regno, unsigned long value); 105ac5672f8SJeremy Fitzhardinge 106ac5672f8SJeremy Fitzhardinge void (*clts)(void); 107ac5672f8SJeremy Fitzhardinge 108ac5672f8SJeremy Fitzhardinge unsigned long (*read_cr0)(void); 109ac5672f8SJeremy Fitzhardinge void (*write_cr0)(unsigned long); 110ac5672f8SJeremy Fitzhardinge 111ac5672f8SJeremy Fitzhardinge unsigned long (*read_cr4)(void); 112ac5672f8SJeremy Fitzhardinge void (*write_cr4)(unsigned long); 113ac5672f8SJeremy Fitzhardinge 114ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_64 115ac5672f8SJeremy Fitzhardinge unsigned long (*read_cr8)(void); 116ac5672f8SJeremy Fitzhardinge void (*write_cr8)(unsigned long); 117ac5672f8SJeremy Fitzhardinge #endif 118ac5672f8SJeremy Fitzhardinge 119ac5672f8SJeremy Fitzhardinge /* Segment descriptor handling */ 120ac5672f8SJeremy Fitzhardinge void (*load_tr_desc)(void); 121ac5672f8SJeremy Fitzhardinge void (*load_gdt)(const struct desc_ptr *); 122ac5672f8SJeremy Fitzhardinge void (*load_idt)(const struct desc_ptr *); 123357d1226SKonrad Rzeszutek Wilk /* store_gdt has been removed. */ 124ac5672f8SJeremy Fitzhardinge void (*store_idt)(struct desc_ptr *); 125ac5672f8SJeremy Fitzhardinge void (*set_ldt)(const void *desc, unsigned entries); 126ac5672f8SJeremy Fitzhardinge unsigned long (*store_tr)(void); 127ac5672f8SJeremy Fitzhardinge void (*load_tls)(struct thread_struct *t, unsigned int cpu); 128ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_64 129ac5672f8SJeremy Fitzhardinge void (*load_gs_index)(unsigned int idx); 130ac5672f8SJeremy Fitzhardinge #endif 131ac5672f8SJeremy Fitzhardinge void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum, 132ac5672f8SJeremy Fitzhardinge const void *desc); 133ac5672f8SJeremy Fitzhardinge void (*write_gdt_entry)(struct desc_struct *, 134ac5672f8SJeremy Fitzhardinge int entrynum, const void *desc, int size); 135ac5672f8SJeremy Fitzhardinge void (*write_idt_entry)(gate_desc *, 136ac5672f8SJeremy Fitzhardinge int entrynum, const gate_desc *gate); 137ac5672f8SJeremy Fitzhardinge void (*alloc_ldt)(struct desc_struct *ldt, unsigned entries); 138ac5672f8SJeremy Fitzhardinge void (*free_ldt)(struct desc_struct *ldt, unsigned entries); 139ac5672f8SJeremy Fitzhardinge 140ac5672f8SJeremy Fitzhardinge void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t); 141ac5672f8SJeremy Fitzhardinge 142ac5672f8SJeremy Fitzhardinge void (*set_iopl_mask)(unsigned mask); 143ac5672f8SJeremy Fitzhardinge 144ac5672f8SJeremy Fitzhardinge void (*wbinvd)(void); 145ac5672f8SJeremy Fitzhardinge void (*io_delay)(void); 146ac5672f8SJeremy Fitzhardinge 147ac5672f8SJeremy Fitzhardinge /* cpuid emulation, mostly so that caps bits can be disabled */ 148ac5672f8SJeremy Fitzhardinge void (*cpuid)(unsigned int *eax, unsigned int *ebx, 149ac5672f8SJeremy Fitzhardinge unsigned int *ecx, unsigned int *edx); 150ac5672f8SJeremy Fitzhardinge 151dd2f4a00SAndy Lutomirski /* Unsafe MSR operations. These will warn or panic on failure. */ 152dd2f4a00SAndy Lutomirski u64 (*read_msr)(unsigned int msr); 153dd2f4a00SAndy Lutomirski void (*write_msr)(unsigned int msr, unsigned low, unsigned high); 154dd2f4a00SAndy Lutomirski 155dd2f4a00SAndy Lutomirski /* 156dd2f4a00SAndy Lutomirski * Safe MSR operations. 157dd2f4a00SAndy Lutomirski * read sets err to 0 or -EIO. write returns 0 or -EIO. 158dd2f4a00SAndy Lutomirski */ 159c2ee03b2SAndy Lutomirski u64 (*read_msr_safe)(unsigned int msr, int *err); 160c2ee03b2SAndy Lutomirski int (*write_msr_safe)(unsigned int msr, unsigned low, unsigned high); 161ac5672f8SJeremy Fitzhardinge 162ac5672f8SJeremy Fitzhardinge u64 (*read_pmc)(int counter); 163ac5672f8SJeremy Fitzhardinge 164ac5672f8SJeremy Fitzhardinge /* 165ac5672f8SJeremy Fitzhardinge * Switch to usermode gs and return to 64-bit usermode using 166ac5672f8SJeremy Fitzhardinge * sysret. Only used in 64-bit kernels to return to 64-bit 167ac5672f8SJeremy Fitzhardinge * processes. Usermode register state, including %rsp, must 168ac5672f8SJeremy Fitzhardinge * already be restored. 169ac5672f8SJeremy Fitzhardinge */ 170ac5672f8SJeremy Fitzhardinge void (*usergs_sysret64)(void); 171ac5672f8SJeremy Fitzhardinge 172ac5672f8SJeremy Fitzhardinge /* Normal iret. Jump to this with the standard iret stack 173ac5672f8SJeremy Fitzhardinge frame set up. */ 174ac5672f8SJeremy Fitzhardinge void (*iret)(void); 175ac5672f8SJeremy Fitzhardinge 176ac5672f8SJeremy Fitzhardinge void (*swapgs)(void); 177ac5672f8SJeremy Fitzhardinge 178ac5672f8SJeremy Fitzhardinge void (*start_context_switch)(struct task_struct *prev); 179ac5672f8SJeremy Fitzhardinge void (*end_context_switch)(struct task_struct *next); 180ac5672f8SJeremy Fitzhardinge }; 181ac5672f8SJeremy Fitzhardinge 182ac5672f8SJeremy Fitzhardinge struct pv_irq_ops { 183ac5672f8SJeremy Fitzhardinge /* 184ac5672f8SJeremy Fitzhardinge * Get/set interrupt state. save_fl and restore_fl are only 185ac5672f8SJeremy Fitzhardinge * expected to use X86_EFLAGS_IF; all other bits 186ac5672f8SJeremy Fitzhardinge * returned from save_fl are undefined, and may be ignored by 187ac5672f8SJeremy Fitzhardinge * restore_fl. 188ac5672f8SJeremy Fitzhardinge * 189ac5672f8SJeremy Fitzhardinge * NOTE: These functions callers expect the callee to preserve 190ac5672f8SJeremy Fitzhardinge * more registers than the standard C calling convention. 191ac5672f8SJeremy Fitzhardinge */ 192ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save save_fl; 193ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save restore_fl; 194ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save irq_disable; 195ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save irq_enable; 196ac5672f8SJeremy Fitzhardinge 197ac5672f8SJeremy Fitzhardinge void (*safe_halt)(void); 198ac5672f8SJeremy Fitzhardinge void (*halt)(void); 199ac5672f8SJeremy Fitzhardinge 200ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_64 201ac5672f8SJeremy Fitzhardinge void (*adjust_exception_frame)(void); 202ac5672f8SJeremy Fitzhardinge #endif 203ac5672f8SJeremy Fitzhardinge }; 204ac5672f8SJeremy Fitzhardinge 205ac5672f8SJeremy Fitzhardinge struct pv_mmu_ops { 206ac5672f8SJeremy Fitzhardinge unsigned long (*read_cr2)(void); 207ac5672f8SJeremy Fitzhardinge void (*write_cr2)(unsigned long); 208ac5672f8SJeremy Fitzhardinge 209ac5672f8SJeremy Fitzhardinge unsigned long (*read_cr3)(void); 210ac5672f8SJeremy Fitzhardinge void (*write_cr3)(unsigned long); 211ac5672f8SJeremy Fitzhardinge 212ac5672f8SJeremy Fitzhardinge /* 213ac5672f8SJeremy Fitzhardinge * Hooks for intercepting the creation/use/destruction of an 214ac5672f8SJeremy Fitzhardinge * mm_struct. 215ac5672f8SJeremy Fitzhardinge */ 216ac5672f8SJeremy Fitzhardinge void (*activate_mm)(struct mm_struct *prev, 217ac5672f8SJeremy Fitzhardinge struct mm_struct *next); 218ac5672f8SJeremy Fitzhardinge void (*dup_mmap)(struct mm_struct *oldmm, 219ac5672f8SJeremy Fitzhardinge struct mm_struct *mm); 220ac5672f8SJeremy Fitzhardinge void (*exit_mmap)(struct mm_struct *mm); 221ac5672f8SJeremy Fitzhardinge 222ac5672f8SJeremy Fitzhardinge 223ac5672f8SJeremy Fitzhardinge /* TLB operations */ 224ac5672f8SJeremy Fitzhardinge void (*flush_tlb_user)(void); 225ac5672f8SJeremy Fitzhardinge void (*flush_tlb_kernel)(void); 226ac5672f8SJeremy Fitzhardinge void (*flush_tlb_single)(unsigned long addr); 227ac5672f8SJeremy Fitzhardinge void (*flush_tlb_others)(const struct cpumask *cpus, 228ac5672f8SJeremy Fitzhardinge struct mm_struct *mm, 229e7b52ffdSAlex Shi unsigned long start, 230e7b52ffdSAlex Shi unsigned long end); 231ac5672f8SJeremy Fitzhardinge 232ac5672f8SJeremy Fitzhardinge /* Hooks for allocating and freeing a pagetable top-level */ 233ac5672f8SJeremy Fitzhardinge int (*pgd_alloc)(struct mm_struct *mm); 234ac5672f8SJeremy Fitzhardinge void (*pgd_free)(struct mm_struct *mm, pgd_t *pgd); 235ac5672f8SJeremy Fitzhardinge 236ac5672f8SJeremy Fitzhardinge /* 237ac5672f8SJeremy Fitzhardinge * Hooks for allocating/releasing pagetable pages when they're 238ac5672f8SJeremy Fitzhardinge * attached to a pagetable 239ac5672f8SJeremy Fitzhardinge */ 240ac5672f8SJeremy Fitzhardinge void (*alloc_pte)(struct mm_struct *mm, unsigned long pfn); 241ac5672f8SJeremy Fitzhardinge void (*alloc_pmd)(struct mm_struct *mm, unsigned long pfn); 242ac5672f8SJeremy Fitzhardinge void (*alloc_pud)(struct mm_struct *mm, unsigned long pfn); 243ac5672f8SJeremy Fitzhardinge void (*release_pte)(unsigned long pfn); 244ac5672f8SJeremy Fitzhardinge void (*release_pmd)(unsigned long pfn); 245ac5672f8SJeremy Fitzhardinge void (*release_pud)(unsigned long pfn); 246ac5672f8SJeremy Fitzhardinge 247ac5672f8SJeremy Fitzhardinge /* Pagetable manipulation functions */ 248ac5672f8SJeremy Fitzhardinge void (*set_pte)(pte_t *ptep, pte_t pteval); 249ac5672f8SJeremy Fitzhardinge void (*set_pte_at)(struct mm_struct *mm, unsigned long addr, 250ac5672f8SJeremy Fitzhardinge pte_t *ptep, pte_t pteval); 251ac5672f8SJeremy Fitzhardinge void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval); 252331127f7SAndrea Arcangeli void (*set_pmd_at)(struct mm_struct *mm, unsigned long addr, 253331127f7SAndrea Arcangeli pmd_t *pmdp, pmd_t pmdval); 254ac5672f8SJeremy Fitzhardinge void (*pte_update)(struct mm_struct *mm, unsigned long addr, 255ac5672f8SJeremy Fitzhardinge pte_t *ptep); 256ac5672f8SJeremy Fitzhardinge 257ac5672f8SJeremy Fitzhardinge pte_t (*ptep_modify_prot_start)(struct mm_struct *mm, unsigned long addr, 258ac5672f8SJeremy Fitzhardinge pte_t *ptep); 259ac5672f8SJeremy Fitzhardinge void (*ptep_modify_prot_commit)(struct mm_struct *mm, unsigned long addr, 260ac5672f8SJeremy Fitzhardinge pte_t *ptep, pte_t pte); 261ac5672f8SJeremy Fitzhardinge 262ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pte_val; 263ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pte; 264ac5672f8SJeremy Fitzhardinge 265ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pgd_val; 266ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pgd; 267ac5672f8SJeremy Fitzhardinge 26898233368SKirill A. Shutemov #if CONFIG_PGTABLE_LEVELS >= 3 269ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_PAE 270ac5672f8SJeremy Fitzhardinge void (*set_pte_atomic)(pte_t *ptep, pte_t pteval); 271ac5672f8SJeremy Fitzhardinge void (*pte_clear)(struct mm_struct *mm, unsigned long addr, 272ac5672f8SJeremy Fitzhardinge pte_t *ptep); 273ac5672f8SJeremy Fitzhardinge void (*pmd_clear)(pmd_t *pmdp); 274ac5672f8SJeremy Fitzhardinge 275ac5672f8SJeremy Fitzhardinge #endif /* CONFIG_X86_PAE */ 276ac5672f8SJeremy Fitzhardinge 277ac5672f8SJeremy Fitzhardinge void (*set_pud)(pud_t *pudp, pud_t pudval); 278ac5672f8SJeremy Fitzhardinge 279ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pmd_val; 280ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pmd; 281ac5672f8SJeremy Fitzhardinge 28298233368SKirill A. Shutemov #if CONFIG_PGTABLE_LEVELS == 4 283ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save pud_val; 284ac5672f8SJeremy Fitzhardinge struct paravirt_callee_save make_pud; 285ac5672f8SJeremy Fitzhardinge 286ac5672f8SJeremy Fitzhardinge void (*set_pgd)(pgd_t *pudp, pgd_t pgdval); 28798233368SKirill A. Shutemov #endif /* CONFIG_PGTABLE_LEVELS == 4 */ 28898233368SKirill A. Shutemov #endif /* CONFIG_PGTABLE_LEVELS >= 3 */ 289ac5672f8SJeremy Fitzhardinge 290ac5672f8SJeremy Fitzhardinge struct pv_lazy_ops lazy_mode; 291ac5672f8SJeremy Fitzhardinge 292ac5672f8SJeremy Fitzhardinge /* dom0 ops */ 293ac5672f8SJeremy Fitzhardinge 294ac5672f8SJeremy Fitzhardinge /* Sometimes the physical address is a pfn, and sometimes its 295ac5672f8SJeremy Fitzhardinge an mfn. We can tell which is which from the index. */ 296ac5672f8SJeremy Fitzhardinge void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx, 297ac5672f8SJeremy Fitzhardinge phys_addr_t phys, pgprot_t flags); 298ac5672f8SJeremy Fitzhardinge }; 299ac5672f8SJeremy Fitzhardinge 300445c8951SThomas Gleixner struct arch_spinlock; 301545ac138SJeremy Fitzhardinge #ifdef CONFIG_SMP 302545ac138SJeremy Fitzhardinge #include <asm/spinlock_types.h> 303545ac138SJeremy Fitzhardinge #endif 304545ac138SJeremy Fitzhardinge 305f233f7f1SPeter Zijlstra (Intel) struct qspinlock; 306f233f7f1SPeter Zijlstra (Intel) 307ac5672f8SJeremy Fitzhardinge struct pv_lock_ops { 308f233f7f1SPeter Zijlstra (Intel) void (*queued_spin_lock_slowpath)(struct qspinlock *lock, u32 val); 309f233f7f1SPeter Zijlstra (Intel) struct paravirt_callee_save queued_spin_unlock; 310f233f7f1SPeter Zijlstra (Intel) 311f233f7f1SPeter Zijlstra (Intel) void (*wait)(u8 *ptr, u8 val); 312f233f7f1SPeter Zijlstra (Intel) void (*kick)(int cpu); 313446f3dc8SPan Xinhui 3143cded417SPeter Zijlstra struct paravirt_callee_save vcpu_is_preempted; 315ac5672f8SJeremy Fitzhardinge }; 316ac5672f8SJeremy Fitzhardinge 317ac5672f8SJeremy Fitzhardinge /* This contains all the paravirt structures: we get a convenient 318ac5672f8SJeremy Fitzhardinge * number for each function using the offset which we use to indicate 319ac5672f8SJeremy Fitzhardinge * what to patch. */ 320ac5672f8SJeremy Fitzhardinge struct paravirt_patch_template { 321ac5672f8SJeremy Fitzhardinge struct pv_init_ops pv_init_ops; 322ac5672f8SJeremy Fitzhardinge struct pv_time_ops pv_time_ops; 323ac5672f8SJeremy Fitzhardinge struct pv_cpu_ops pv_cpu_ops; 324ac5672f8SJeremy Fitzhardinge struct pv_irq_ops pv_irq_ops; 325ac5672f8SJeremy Fitzhardinge struct pv_mmu_ops pv_mmu_ops; 326ac5672f8SJeremy Fitzhardinge struct pv_lock_ops pv_lock_ops; 327ac5672f8SJeremy Fitzhardinge }; 328ac5672f8SJeremy Fitzhardinge 329ac5672f8SJeremy Fitzhardinge extern struct pv_info pv_info; 330ac5672f8SJeremy Fitzhardinge extern struct pv_init_ops pv_init_ops; 331ac5672f8SJeremy Fitzhardinge extern struct pv_time_ops pv_time_ops; 332ac5672f8SJeremy Fitzhardinge extern struct pv_cpu_ops pv_cpu_ops; 333ac5672f8SJeremy Fitzhardinge extern struct pv_irq_ops pv_irq_ops; 334ac5672f8SJeremy Fitzhardinge extern struct pv_mmu_ops pv_mmu_ops; 335ac5672f8SJeremy Fitzhardinge extern struct pv_lock_ops pv_lock_ops; 336ac5672f8SJeremy Fitzhardinge 337ac5672f8SJeremy Fitzhardinge #define PARAVIRT_PATCH(x) \ 338ac5672f8SJeremy Fitzhardinge (offsetof(struct paravirt_patch_template, x) / sizeof(void *)) 339ac5672f8SJeremy Fitzhardinge 340ac5672f8SJeremy Fitzhardinge #define paravirt_type(op) \ 341ac5672f8SJeremy Fitzhardinge [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \ 342ac5672f8SJeremy Fitzhardinge [paravirt_opptr] "i" (&(op)) 343ac5672f8SJeremy Fitzhardinge #define paravirt_clobber(clobber) \ 344ac5672f8SJeremy Fitzhardinge [paravirt_clobber] "i" (clobber) 345ac5672f8SJeremy Fitzhardinge 346ac5672f8SJeremy Fitzhardinge /* 347ac5672f8SJeremy Fitzhardinge * Generate some code, and mark it as patchable by the 348ac5672f8SJeremy Fitzhardinge * apply_paravirt() alternate instruction patcher. 349ac5672f8SJeremy Fitzhardinge */ 350ac5672f8SJeremy Fitzhardinge #define _paravirt_alt(insn_string, type, clobber) \ 351ac5672f8SJeremy Fitzhardinge "771:\n\t" insn_string "\n" "772:\n" \ 352ac5672f8SJeremy Fitzhardinge ".pushsection .parainstructions,\"a\"\n" \ 353ac5672f8SJeremy Fitzhardinge _ASM_ALIGN "\n" \ 354ac5672f8SJeremy Fitzhardinge _ASM_PTR " 771b\n" \ 355ac5672f8SJeremy Fitzhardinge " .byte " type "\n" \ 356ac5672f8SJeremy Fitzhardinge " .byte 772b-771b\n" \ 357ac5672f8SJeremy Fitzhardinge " .short " clobber "\n" \ 358ac5672f8SJeremy Fitzhardinge ".popsection\n" 359ac5672f8SJeremy Fitzhardinge 360ac5672f8SJeremy Fitzhardinge /* Generate patchable code, with the default asm parameters. */ 361ac5672f8SJeremy Fitzhardinge #define paravirt_alt(insn_string) \ 362ac5672f8SJeremy Fitzhardinge _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]") 363ac5672f8SJeremy Fitzhardinge 364ac5672f8SJeremy Fitzhardinge /* Simple instruction patching code. */ 365824a2870SAndi Kleen #define NATIVE_LABEL(a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t" 366824a2870SAndi Kleen 367ac5672f8SJeremy Fitzhardinge #define DEF_NATIVE(ops, name, code) \ 368824a2870SAndi Kleen __visible extern const char start_##ops##_##name[], end_##ops##_##name[]; \ 369824a2870SAndi Kleen asm(NATIVE_LABEL("start_", ops, name) code NATIVE_LABEL("end_", ops, name)) 370ac5672f8SJeremy Fitzhardinge 371ac5672f8SJeremy Fitzhardinge unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len); 372ac5672f8SJeremy Fitzhardinge unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len); 373ac5672f8SJeremy Fitzhardinge unsigned paravirt_patch_call(void *insnbuf, 374ac5672f8SJeremy Fitzhardinge const void *target, u16 tgt_clobbers, 375ac5672f8SJeremy Fitzhardinge unsigned long addr, u16 site_clobbers, 376ac5672f8SJeremy Fitzhardinge unsigned len); 377ac5672f8SJeremy Fitzhardinge unsigned paravirt_patch_jmp(void *insnbuf, const void *target, 378ac5672f8SJeremy Fitzhardinge unsigned long addr, unsigned len); 379ac5672f8SJeremy Fitzhardinge unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf, 380ac5672f8SJeremy Fitzhardinge unsigned long addr, unsigned len); 381ac5672f8SJeremy Fitzhardinge 382ac5672f8SJeremy Fitzhardinge unsigned paravirt_patch_insns(void *insnbuf, unsigned len, 383ac5672f8SJeremy Fitzhardinge const char *start, const char *end); 384ac5672f8SJeremy Fitzhardinge 385ac5672f8SJeremy Fitzhardinge unsigned native_patch(u8 type, u16 clobbers, void *ibuf, 386ac5672f8SJeremy Fitzhardinge unsigned long addr, unsigned len); 387ac5672f8SJeremy Fitzhardinge 388ac5672f8SJeremy Fitzhardinge int paravirt_disable_iospace(void); 389ac5672f8SJeremy Fitzhardinge 390ac5672f8SJeremy Fitzhardinge /* 391ac5672f8SJeremy Fitzhardinge * This generates an indirect call based on the operation type number. 392ac5672f8SJeremy Fitzhardinge * The type number, computed in PARAVIRT_PATCH, is derived from the 393ac5672f8SJeremy Fitzhardinge * offset into the paravirt_patch_template structure, and can therefore be 394ac5672f8SJeremy Fitzhardinge * freely converted back into a structure offset. 395ac5672f8SJeremy Fitzhardinge */ 396ac5672f8SJeremy Fitzhardinge #define PARAVIRT_CALL "call *%c[paravirt_opptr];" 397ac5672f8SJeremy Fitzhardinge 398ac5672f8SJeremy Fitzhardinge /* 399ac5672f8SJeremy Fitzhardinge * These macros are intended to wrap calls through one of the paravirt 400ac5672f8SJeremy Fitzhardinge * ops structs, so that they can be later identified and patched at 401ac5672f8SJeremy Fitzhardinge * runtime. 402ac5672f8SJeremy Fitzhardinge * 403ac5672f8SJeremy Fitzhardinge * Normally, a call to a pv_op function is a simple indirect call: 404ac5672f8SJeremy Fitzhardinge * (pv_op_struct.operations)(args...). 405ac5672f8SJeremy Fitzhardinge * 406ac5672f8SJeremy Fitzhardinge * Unfortunately, this is a relatively slow operation for modern CPUs, 407ac5672f8SJeremy Fitzhardinge * because it cannot necessarily determine what the destination 408ac5672f8SJeremy Fitzhardinge * address is. In this case, the address is a runtime constant, so at 409ac5672f8SJeremy Fitzhardinge * the very least we can patch the call to e a simple direct call, or 410ac5672f8SJeremy Fitzhardinge * ideally, patch an inline implementation into the callsite. (Direct 411ac5672f8SJeremy Fitzhardinge * calls are essentially free, because the call and return addresses 412ac5672f8SJeremy Fitzhardinge * are completely predictable.) 413ac5672f8SJeremy Fitzhardinge * 414ac5672f8SJeremy Fitzhardinge * For i386, these macros rely on the standard gcc "regparm(3)" calling 415ac5672f8SJeremy Fitzhardinge * convention, in which the first three arguments are placed in %eax, 416ac5672f8SJeremy Fitzhardinge * %edx, %ecx (in that order), and the remaining arguments are placed 417ac5672f8SJeremy Fitzhardinge * on the stack. All caller-save registers (eax,edx,ecx) are expected 418ac5672f8SJeremy Fitzhardinge * to be modified (either clobbered or used for return values). 419ac5672f8SJeremy Fitzhardinge * X86_64, on the other hand, already specifies a register-based calling 420ac5672f8SJeremy Fitzhardinge * conventions, returning at %rax, with parameteres going on %rdi, %rsi, 421ac5672f8SJeremy Fitzhardinge * %rdx, and %rcx. Note that for this reason, x86_64 does not need any 422ac5672f8SJeremy Fitzhardinge * special handling for dealing with 4 arguments, unlike i386. 423ac5672f8SJeremy Fitzhardinge * However, x86_64 also have to clobber all caller saved registers, which 424ac5672f8SJeremy Fitzhardinge * unfortunately, are quite a bit (r8 - r11) 425ac5672f8SJeremy Fitzhardinge * 426ac5672f8SJeremy Fitzhardinge * The call instruction itself is marked by placing its start address 427ac5672f8SJeremy Fitzhardinge * and size into the .parainstructions section, so that 428ac5672f8SJeremy Fitzhardinge * apply_paravirt() in arch/i386/kernel/alternative.c can do the 429ac5672f8SJeremy Fitzhardinge * appropriate patching under the control of the backend pv_init_ops 430ac5672f8SJeremy Fitzhardinge * implementation. 431ac5672f8SJeremy Fitzhardinge * 432ac5672f8SJeremy Fitzhardinge * Unfortunately there's no way to get gcc to generate the args setup 433ac5672f8SJeremy Fitzhardinge * for the call, and then allow the call itself to be generated by an 434ac5672f8SJeremy Fitzhardinge * inline asm. Because of this, we must do the complete arg setup and 435ac5672f8SJeremy Fitzhardinge * return value handling from within these macros. This is fairly 436ac5672f8SJeremy Fitzhardinge * cumbersome. 437ac5672f8SJeremy Fitzhardinge * 438ac5672f8SJeremy Fitzhardinge * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments. 439ac5672f8SJeremy Fitzhardinge * It could be extended to more arguments, but there would be little 440ac5672f8SJeremy Fitzhardinge * to be gained from that. For each number of arguments, there are 441ac5672f8SJeremy Fitzhardinge * the two VCALL and CALL variants for void and non-void functions. 442ac5672f8SJeremy Fitzhardinge * 443ac5672f8SJeremy Fitzhardinge * When there is a return value, the invoker of the macro must specify 444ac5672f8SJeremy Fitzhardinge * the return type. The macro then uses sizeof() on that type to 445ac5672f8SJeremy Fitzhardinge * determine whether its a 32 or 64 bit value, and places the return 446ac5672f8SJeremy Fitzhardinge * in the right register(s) (just %eax for 32-bit, and %edx:%eax for 447ac5672f8SJeremy Fitzhardinge * 64-bit). For x86_64 machines, it just returns at %rax regardless of 448ac5672f8SJeremy Fitzhardinge * the return value size. 449ac5672f8SJeremy Fitzhardinge * 450ac5672f8SJeremy Fitzhardinge * 64-bit arguments are passed as a pair of adjacent 32-bit arguments 451ac5672f8SJeremy Fitzhardinge * i386 also passes 64-bit arguments as a pair of adjacent 32-bit arguments 452ac5672f8SJeremy Fitzhardinge * in low,high order 453ac5672f8SJeremy Fitzhardinge * 454ac5672f8SJeremy Fitzhardinge * Small structures are passed and returned in registers. The macro 455ac5672f8SJeremy Fitzhardinge * calling convention can't directly deal with this, so the wrapper 456ac5672f8SJeremy Fitzhardinge * functions must do this. 457ac5672f8SJeremy Fitzhardinge * 458ac5672f8SJeremy Fitzhardinge * These PVOP_* macros are only defined within this header. This 459ac5672f8SJeremy Fitzhardinge * means that all uses must be wrapped in inline functions. This also 460ac5672f8SJeremy Fitzhardinge * makes sure the incoming and outgoing types are always correct. 461ac5672f8SJeremy Fitzhardinge */ 462ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_32 463ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_ARGS \ 464bb93eb4cSJosh Poimboeuf unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx; \ 465bb93eb4cSJosh Poimboeuf register void *__sp asm("esp") 466ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARGS PVOP_VCALL_ARGS 467ac5672f8SJeremy Fitzhardinge 468ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG1(x) "a" ((unsigned long)(x)) 469ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG2(x) "d" ((unsigned long)(x)) 470ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG3(x) "c" ((unsigned long)(x)) 471ac5672f8SJeremy Fitzhardinge 472ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_CLOBBERS "=a" (__eax), "=d" (__edx), \ 473ac5672f8SJeremy Fitzhardinge "=c" (__ecx) 474ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS 475ac5672f8SJeremy Fitzhardinge 476ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE_CLOBBERS "=a" (__eax), "=d" (__edx) 477ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS 478ac5672f8SJeremy Fitzhardinge 479ac5672f8SJeremy Fitzhardinge #define EXTRA_CLOBBERS 480ac5672f8SJeremy Fitzhardinge #define VEXTRA_CLOBBERS 481ac5672f8SJeremy Fitzhardinge #else /* CONFIG_X86_64 */ 48271999d98SJeremy Fitzhardinge /* [re]ax isn't an arg, but the return val */ 483ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_ARGS \ 484ac5672f8SJeremy Fitzhardinge unsigned long __edi = __edi, __esi = __esi, \ 485bb93eb4cSJosh Poimboeuf __edx = __edx, __ecx = __ecx, __eax = __eax; \ 486bb93eb4cSJosh Poimboeuf register void *__sp asm("rsp") 48771999d98SJeremy Fitzhardinge #define PVOP_CALL_ARGS PVOP_VCALL_ARGS 488ac5672f8SJeremy Fitzhardinge 489ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG1(x) "D" ((unsigned long)(x)) 490ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG2(x) "S" ((unsigned long)(x)) 491ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG3(x) "d" ((unsigned long)(x)) 492ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_ARG4(x) "c" ((unsigned long)(x)) 493ac5672f8SJeremy Fitzhardinge 494ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL_CLOBBERS "=D" (__edi), \ 495ac5672f8SJeremy Fitzhardinge "=S" (__esi), "=d" (__edx), \ 496ac5672f8SJeremy Fitzhardinge "=c" (__ecx) 497ac5672f8SJeremy Fitzhardinge #define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax) 498ac5672f8SJeremy Fitzhardinge 49971999d98SJeremy Fitzhardinge /* void functions are still allowed [re]ax for scratch */ 500ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE_CLOBBERS "=a" (__eax) 501ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE_CLOBBERS PVOP_VCALLEE_CLOBBERS 502ac5672f8SJeremy Fitzhardinge 503ac5672f8SJeremy Fitzhardinge #define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11" 504ac5672f8SJeremy Fitzhardinge #define VEXTRA_CLOBBERS , "rax", "r8", "r9", "r10", "r11" 505ac5672f8SJeremy Fitzhardinge #endif /* CONFIG_X86_32 */ 506ac5672f8SJeremy Fitzhardinge 507ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_PARAVIRT_DEBUG 508ac5672f8SJeremy Fitzhardinge #define PVOP_TEST_NULL(op) BUG_ON(op == NULL) 509ac5672f8SJeremy Fitzhardinge #else 510ac5672f8SJeremy Fitzhardinge #define PVOP_TEST_NULL(op) ((void)op) 511ac5672f8SJeremy Fitzhardinge #endif 512ac5672f8SJeremy Fitzhardinge 513ac5672f8SJeremy Fitzhardinge #define ____PVOP_CALL(rettype, op, clbr, call_clbr, extra_clbr, \ 514ac5672f8SJeremy Fitzhardinge pre, post, ...) \ 515ac5672f8SJeremy Fitzhardinge ({ \ 516ac5672f8SJeremy Fitzhardinge rettype __ret; \ 517ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARGS; \ 518ac5672f8SJeremy Fitzhardinge PVOP_TEST_NULL(op); \ 519ac5672f8SJeremy Fitzhardinge /* This is 32-bit specific, but is okay in 64-bit */ \ 520ac5672f8SJeremy Fitzhardinge /* since this condition will never hold */ \ 521ac5672f8SJeremy Fitzhardinge if (sizeof(rettype) > sizeof(unsigned long)) { \ 522ac5672f8SJeremy Fitzhardinge asm volatile(pre \ 523ac5672f8SJeremy Fitzhardinge paravirt_alt(PARAVIRT_CALL) \ 524ac5672f8SJeremy Fitzhardinge post \ 525bb93eb4cSJosh Poimboeuf : call_clbr, "+r" (__sp) \ 526ac5672f8SJeremy Fitzhardinge : paravirt_type(op), \ 527ac5672f8SJeremy Fitzhardinge paravirt_clobber(clbr), \ 528ac5672f8SJeremy Fitzhardinge ##__VA_ARGS__ \ 529ac5672f8SJeremy Fitzhardinge : "memory", "cc" extra_clbr); \ 530ac5672f8SJeremy Fitzhardinge __ret = (rettype)((((u64)__edx) << 32) | __eax); \ 531ac5672f8SJeremy Fitzhardinge } else { \ 532ac5672f8SJeremy Fitzhardinge asm volatile(pre \ 533ac5672f8SJeremy Fitzhardinge paravirt_alt(PARAVIRT_CALL) \ 534ac5672f8SJeremy Fitzhardinge post \ 535bb93eb4cSJosh Poimboeuf : call_clbr, "+r" (__sp) \ 536ac5672f8SJeremy Fitzhardinge : paravirt_type(op), \ 537ac5672f8SJeremy Fitzhardinge paravirt_clobber(clbr), \ 538ac5672f8SJeremy Fitzhardinge ##__VA_ARGS__ \ 539ac5672f8SJeremy Fitzhardinge : "memory", "cc" extra_clbr); \ 540ac5672f8SJeremy Fitzhardinge __ret = (rettype)__eax; \ 541ac5672f8SJeremy Fitzhardinge } \ 542ac5672f8SJeremy Fitzhardinge __ret; \ 543ac5672f8SJeremy Fitzhardinge }) 544ac5672f8SJeremy Fitzhardinge 545ac5672f8SJeremy Fitzhardinge #define __PVOP_CALL(rettype, op, pre, post, ...) \ 546ac5672f8SJeremy Fitzhardinge ____PVOP_CALL(rettype, op, CLBR_ANY, PVOP_CALL_CLOBBERS, \ 547ac5672f8SJeremy Fitzhardinge EXTRA_CLOBBERS, pre, post, ##__VA_ARGS__) 548ac5672f8SJeremy Fitzhardinge 549ac5672f8SJeremy Fitzhardinge #define __PVOP_CALLEESAVE(rettype, op, pre, post, ...) \ 550ac5672f8SJeremy Fitzhardinge ____PVOP_CALL(rettype, op.func, CLBR_RET_REG, \ 551ac5672f8SJeremy Fitzhardinge PVOP_CALLEE_CLOBBERS, , \ 552ac5672f8SJeremy Fitzhardinge pre, post, ##__VA_ARGS__) 553ac5672f8SJeremy Fitzhardinge 554ac5672f8SJeremy Fitzhardinge 555ac5672f8SJeremy Fitzhardinge #define ____PVOP_VCALL(op, clbr, call_clbr, extra_clbr, pre, post, ...) \ 556ac5672f8SJeremy Fitzhardinge ({ \ 557ac5672f8SJeremy Fitzhardinge PVOP_VCALL_ARGS; \ 558ac5672f8SJeremy Fitzhardinge PVOP_TEST_NULL(op); \ 559ac5672f8SJeremy Fitzhardinge asm volatile(pre \ 560ac5672f8SJeremy Fitzhardinge paravirt_alt(PARAVIRT_CALL) \ 561ac5672f8SJeremy Fitzhardinge post \ 562bb93eb4cSJosh Poimboeuf : call_clbr, "+r" (__sp) \ 563ac5672f8SJeremy Fitzhardinge : paravirt_type(op), \ 564ac5672f8SJeremy Fitzhardinge paravirt_clobber(clbr), \ 565ac5672f8SJeremy Fitzhardinge ##__VA_ARGS__ \ 566ac5672f8SJeremy Fitzhardinge : "memory", "cc" extra_clbr); \ 567ac5672f8SJeremy Fitzhardinge }) 568ac5672f8SJeremy Fitzhardinge 569ac5672f8SJeremy Fitzhardinge #define __PVOP_VCALL(op, pre, post, ...) \ 570ac5672f8SJeremy Fitzhardinge ____PVOP_VCALL(op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ 571ac5672f8SJeremy Fitzhardinge VEXTRA_CLOBBERS, \ 572ac5672f8SJeremy Fitzhardinge pre, post, ##__VA_ARGS__) 573ac5672f8SJeremy Fitzhardinge 57471999d98SJeremy Fitzhardinge #define __PVOP_VCALLEESAVE(op, pre, post, ...) \ 57571999d98SJeremy Fitzhardinge ____PVOP_VCALL(op.func, CLBR_RET_REG, \ 576ac5672f8SJeremy Fitzhardinge PVOP_VCALLEE_CLOBBERS, , \ 577ac5672f8SJeremy Fitzhardinge pre, post, ##__VA_ARGS__) 578ac5672f8SJeremy Fitzhardinge 579ac5672f8SJeremy Fitzhardinge 580ac5672f8SJeremy Fitzhardinge 581ac5672f8SJeremy Fitzhardinge #define PVOP_CALL0(rettype, op) \ 582ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "") 583ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL0(op) \ 584ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "") 585ac5672f8SJeremy Fitzhardinge 586ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE0(rettype, op) \ 587ac5672f8SJeremy Fitzhardinge __PVOP_CALLEESAVE(rettype, op, "", "") 588ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE0(op) \ 589ac5672f8SJeremy Fitzhardinge __PVOP_VCALLEESAVE(op, "", "") 590ac5672f8SJeremy Fitzhardinge 591ac5672f8SJeremy Fitzhardinge 592ac5672f8SJeremy Fitzhardinge #define PVOP_CALL1(rettype, op, arg1) \ 593ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1)) 594ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL1(op, arg1) \ 595ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1)) 596ac5672f8SJeremy Fitzhardinge 597ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE1(rettype, op, arg1) \ 598ac5672f8SJeremy Fitzhardinge __PVOP_CALLEESAVE(rettype, op, "", "", PVOP_CALL_ARG1(arg1)) 599ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE1(op, arg1) \ 600ac5672f8SJeremy Fitzhardinge __PVOP_VCALLEESAVE(op, "", "", PVOP_CALL_ARG1(arg1)) 601ac5672f8SJeremy Fitzhardinge 602ac5672f8SJeremy Fitzhardinge 603ac5672f8SJeremy Fitzhardinge #define PVOP_CALL2(rettype, op, arg1, arg2) \ 604ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \ 605ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 606ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL2(op, arg1, arg2) \ 607ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1), \ 608ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 609ac5672f8SJeremy Fitzhardinge 610ac5672f8SJeremy Fitzhardinge #define PVOP_CALLEE2(rettype, op, arg1, arg2) \ 611ac5672f8SJeremy Fitzhardinge __PVOP_CALLEESAVE(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \ 612ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 613ac5672f8SJeremy Fitzhardinge #define PVOP_VCALLEE2(op, arg1, arg2) \ 614ac5672f8SJeremy Fitzhardinge __PVOP_VCALLEESAVE(op, "", "", PVOP_CALL_ARG1(arg1), \ 615ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2)) 616ac5672f8SJeremy Fitzhardinge 617ac5672f8SJeremy Fitzhardinge 618ac5672f8SJeremy Fitzhardinge #define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \ 619ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", PVOP_CALL_ARG1(arg1), \ 620ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3)) 621ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL3(op, arg1, arg2, arg3) \ 622ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", PVOP_CALL_ARG1(arg1), \ 623ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG2(arg2), PVOP_CALL_ARG3(arg3)) 624ac5672f8SJeremy Fitzhardinge 625ac5672f8SJeremy Fitzhardinge /* This is the only difference in x86_64. We can make it much simpler */ 626ac5672f8SJeremy Fitzhardinge #ifdef CONFIG_X86_32 627ac5672f8SJeremy Fitzhardinge #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \ 628ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, \ 629ac5672f8SJeremy Fitzhardinge "push %[_arg4];", "lea 4(%%esp),%%esp;", \ 630ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \ 631ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG3(arg3), [_arg4] "mr" ((u32)(arg4))) 632ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \ 633ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, \ 634ac5672f8SJeremy Fitzhardinge "push %[_arg4];", "lea 4(%%esp),%%esp;", \ 635ac5672f8SJeremy Fitzhardinge "0" ((u32)(arg1)), "1" ((u32)(arg2)), \ 636ac5672f8SJeremy Fitzhardinge "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4))) 637ac5672f8SJeremy Fitzhardinge #else 638ac5672f8SJeremy Fitzhardinge #define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \ 639ac5672f8SJeremy Fitzhardinge __PVOP_CALL(rettype, op, "", "", \ 640ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \ 641ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4)) 642ac5672f8SJeremy Fitzhardinge #define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \ 643ac5672f8SJeremy Fitzhardinge __PVOP_VCALL(op, "", "", \ 644ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \ 645ac5672f8SJeremy Fitzhardinge PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4)) 646ac5672f8SJeremy Fitzhardinge #endif 647ac5672f8SJeremy Fitzhardinge 648ac5672f8SJeremy Fitzhardinge /* Lazy mode for batching updates / context switch */ 649ac5672f8SJeremy Fitzhardinge enum paravirt_lazy_mode { 650ac5672f8SJeremy Fitzhardinge PARAVIRT_LAZY_NONE, 651ac5672f8SJeremy Fitzhardinge PARAVIRT_LAZY_MMU, 652ac5672f8SJeremy Fitzhardinge PARAVIRT_LAZY_CPU, 653ac5672f8SJeremy Fitzhardinge }; 654ac5672f8SJeremy Fitzhardinge 655ac5672f8SJeremy Fitzhardinge enum paravirt_lazy_mode paravirt_get_lazy_mode(void); 656ac5672f8SJeremy Fitzhardinge void paravirt_start_context_switch(struct task_struct *prev); 657ac5672f8SJeremy Fitzhardinge void paravirt_end_context_switch(struct task_struct *next); 658ac5672f8SJeremy Fitzhardinge 659ac5672f8SJeremy Fitzhardinge void paravirt_enter_lazy_mmu(void); 660ac5672f8SJeremy Fitzhardinge void paravirt_leave_lazy_mmu(void); 661511ba86eSBoris Ostrovsky void paravirt_flush_lazy_mmu(void); 662ac5672f8SJeremy Fitzhardinge 663ac5672f8SJeremy Fitzhardinge void _paravirt_nop(void); 664ac5672f8SJeremy Fitzhardinge u32 _paravirt_ident_32(u32); 665ac5672f8SJeremy Fitzhardinge u64 _paravirt_ident_64(u64); 666ac5672f8SJeremy Fitzhardinge 667ac5672f8SJeremy Fitzhardinge #define paravirt_nop ((void *)_paravirt_nop) 668ac5672f8SJeremy Fitzhardinge 669ac5672f8SJeremy Fitzhardinge /* These all sit in the .parainstructions section to tell us what to patch. */ 670ac5672f8SJeremy Fitzhardinge struct paravirt_patch_site { 671ac5672f8SJeremy Fitzhardinge u8 *instr; /* original instructions */ 672ac5672f8SJeremy Fitzhardinge u8 instrtype; /* type of this instruction */ 673ac5672f8SJeremy Fitzhardinge u8 len; /* length of original instruction */ 674ac5672f8SJeremy Fitzhardinge u16 clobbers; /* what registers you may clobber */ 675ac5672f8SJeremy Fitzhardinge }; 676ac5672f8SJeremy Fitzhardinge 677ac5672f8SJeremy Fitzhardinge extern struct paravirt_patch_site __parainstructions[], 678ac5672f8SJeremy Fitzhardinge __parainstructions_end[]; 679ac5672f8SJeremy Fitzhardinge 680ac5672f8SJeremy Fitzhardinge #endif /* __ASSEMBLY__ */ 681ac5672f8SJeremy Fitzhardinge 682ac5672f8SJeremy Fitzhardinge #endif /* _ASM_X86_PARAVIRT_TYPES_H */ 683