Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / arch / x86 / include / asm / paravirt.h
bloba7d2db9a74fbc835dd7ed41ca2f7b5754b0263fe
1 #ifndef _ASM_X86_PARAVIRT_H
2 #define _ASM_X86_PARAVIRT_H
3 /* Various instructions on x86 need to be replaced for
4 * para-virtualization: those hooks are defined here. */
6 #ifdef CONFIG_PARAVIRT
7 #include <asm/pgtable_types.h>
8 #include <asm/asm.h>
10 #include <asm/paravirt_types.h>
12 #ifndef __ASSEMBLY__
13 #include <linux/types.h>
14 #include <linux/cpumask.h>
16 static inline int paravirt_enabled(void)
18 return pv_info.paravirt_enabled;
21 static inline void load_sp0(struct tss_struct *tss,
22 struct thread_struct *thread)
24 PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
27 /* The paravirtualized CPUID instruction. */
28 static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
29 unsigned int *ecx, unsigned int *edx)
31 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
35 * These special macros can be used to get or set a debugging register
37 static inline unsigned long paravirt_get_debugreg(int reg)
39 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
41 #define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
42 static inline void set_debugreg(unsigned long val, int reg)
44 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
47 static inline void clts(void)
49 PVOP_VCALL0(pv_cpu_ops.clts);
52 static inline unsigned long read_cr0(void)
54 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
57 static inline void write_cr0(unsigned long x)
59 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
62 static inline unsigned long read_cr2(void)
64 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
67 static inline void write_cr2(unsigned long x)
69 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
72 static inline unsigned long read_cr3(void)
74 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
77 static inline void write_cr3(unsigned long x)
79 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
82 static inline unsigned long read_cr4(void)
84 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
86 static inline unsigned long read_cr4_safe(void)
88 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
91 static inline void write_cr4(unsigned long x)
93 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
96 #ifdef CONFIG_X86_64
97 static inline unsigned long read_cr8(void)
99 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
102 static inline void write_cr8(unsigned long x)
104 PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
106 #endif
108 static inline void arch_safe_halt(void)
110 PVOP_VCALL0(pv_irq_ops.safe_halt);
113 static inline void halt(void)
115 PVOP_VCALL0(pv_irq_ops.halt);
118 static inline void wbinvd(void)
120 PVOP_VCALL0(pv_cpu_ops.wbinvd);
123 #define get_kernel_rpl() (pv_info.kernel_rpl)
125 static inline u64 paravirt_read_msr(unsigned msr, int *err)
127 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
130 static inline int paravirt_rdmsr_regs(u32 *regs)
132 return PVOP_CALL1(int, pv_cpu_ops.rdmsr_regs, regs);
135 static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
137 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
140 static inline int paravirt_wrmsr_regs(u32 *regs)
142 return PVOP_CALL1(int, pv_cpu_ops.wrmsr_regs, regs);
145 /* These should all do BUG_ON(_err), but our headers are too tangled. */
146 #define rdmsr(msr, val1, val2) \
147 do { \
148 int _err; \
149 u64 _l = paravirt_read_msr(msr, &_err); \
150 val1 = (u32)_l; \
151 val2 = _l >> 32; \
152 } while (0)
154 #define wrmsr(msr, val1, val2) \
155 do { \
156 paravirt_write_msr(msr, val1, val2); \
157 } while (0)
159 #define rdmsrl(msr, val) \
160 do { \
161 int _err; \
162 val = paravirt_read_msr(msr, &_err); \
163 } while (0)
165 #define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
166 #define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
168 /* rdmsr with exception handling */
169 #define rdmsr_safe(msr, a, b) \
170 ({ \
171 int _err; \
172 u64 _l = paravirt_read_msr(msr, &_err); \
173 (*a) = (u32)_l; \
174 (*b) = _l >> 32; \
175 _err; \
178 #define rdmsr_safe_regs(regs) paravirt_rdmsr_regs(regs)
179 #define wrmsr_safe_regs(regs) paravirt_wrmsr_regs(regs)
181 static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)
183 int err;
185 *p = paravirt_read_msr(msr, &err);
186 return err;
188 static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
190 u32 gprs[8] = { 0 };
191 int err;
193 gprs[1] = msr;
194 gprs[7] = 0x9c5a203a;
196 err = paravirt_rdmsr_regs(gprs);
198 *p = gprs[0] | ((u64)gprs[2] << 32);
200 return err;
203 static inline int wrmsrl_amd_safe(unsigned msr, unsigned long long val)
205 u32 gprs[8] = { 0 };
207 gprs[0] = (u32)val;
208 gprs[1] = msr;
209 gprs[2] = val >> 32;
210 gprs[7] = 0x9c5a203a;
212 return paravirt_wrmsr_regs(gprs);
215 static inline u64 paravirt_read_tsc(void)
217 return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
220 #define rdtscl(low) \
221 do { \
222 u64 _l = paravirt_read_tsc(); \
223 low = (int)_l; \
224 } while (0)
226 #define rdtscll(val) (val = paravirt_read_tsc())
228 static inline unsigned long long paravirt_sched_clock(void)
230 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
233 struct jump_label_key;
234 extern struct jump_label_key paravirt_steal_enabled;
235 extern struct jump_label_key paravirt_steal_rq_enabled;
237 static inline u64 paravirt_steal_clock(int cpu)
239 return PVOP_CALL1(u64, pv_time_ops.steal_clock, cpu);
242 static inline unsigned long long paravirt_read_pmc(int counter)
244 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
247 #define rdpmc(counter, low, high) \
248 do { \
249 u64 _l = paravirt_read_pmc(counter); \
250 low = (u32)_l; \
251 high = _l >> 32; \
252 } while (0)
254 static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
256 return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
259 #define rdtscp(low, high, aux) \
260 do { \
261 int __aux; \
262 unsigned long __val = paravirt_rdtscp(&__aux); \
263 (low) = (u32)__val; \
264 (high) = (u32)(__val >> 32); \
265 (aux) = __aux; \
266 } while (0)
268 #define rdtscpll(val, aux) \
269 do { \
270 unsigned long __aux; \
271 val = paravirt_rdtscp(&__aux); \
272 (aux) = __aux; \
273 } while (0)
275 static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
277 PVOP_VCALL2(pv_cpu_ops.alloc_ldt, ldt, entries);
280 static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
282 PVOP_VCALL2(pv_cpu_ops.free_ldt, ldt, entries);
285 static inline void load_TR_desc(void)
287 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
289 static inline void load_gdt(const struct desc_ptr *dtr)
291 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
293 static inline void load_idt(const struct desc_ptr *dtr)
295 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
297 static inline void set_ldt(const void *addr, unsigned entries)
299 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
301 static inline void store_gdt(struct desc_ptr *dtr)
303 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
305 static inline void store_idt(struct desc_ptr *dtr)
307 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
309 static inline unsigned long paravirt_store_tr(void)
311 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
313 #define store_tr(tr) ((tr) = paravirt_store_tr())
314 static inline void load_TLS(struct thread_struct *t, unsigned cpu)
316 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
319 #ifdef CONFIG_X86_64
320 static inline void load_gs_index(unsigned int gs)
322 PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
324 #endif
326 static inline void write_ldt_entry(struct desc_struct *dt, int entry,
327 const void *desc)
329 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
332 static inline void write_gdt_entry(struct desc_struct *dt, int entry,
333 void *desc, int type)
335 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
338 static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
340 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
342 static inline void set_iopl_mask(unsigned mask)
344 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
347 /* The paravirtualized I/O functions */
348 static inline void slow_down_io(void)
350 pv_cpu_ops.io_delay();
351 #ifdef REALLY_SLOW_IO
352 pv_cpu_ops.io_delay();
353 pv_cpu_ops.io_delay();
354 pv_cpu_ops.io_delay();
355 #endif
358 #ifdef CONFIG_SMP
359 static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
360 unsigned long start_esp)
362 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
363 phys_apicid, start_eip, start_esp);
365 #endif
367 static inline void paravirt_activate_mm(struct mm_struct *prev,
368 struct mm_struct *next)
370 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
373 static inline void arch_dup_mmap(struct mm_struct *oldmm,
374 struct mm_struct *mm)
376 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
379 static inline void arch_exit_mmap(struct mm_struct *mm)
381 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
384 static inline void __flush_tlb(void)
386 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
388 static inline void __flush_tlb_global(void)
390 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
392 static inline void __flush_tlb_single(unsigned long addr)
394 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
397 static inline void flush_tlb_others(const struct cpumask *cpumask,
398 struct mm_struct *mm,
399 unsigned long va)
401 PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, cpumask, mm, va);
404 static inline int paravirt_pgd_alloc(struct mm_struct *mm)
406 return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
409 static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
411 PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
414 static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
416 PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
418 static inline void paravirt_release_pte(unsigned long pfn)
420 PVOP_VCALL1(pv_mmu_ops.release_pte, pfn);
423 static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
425 PVOP_VCALL2(pv_mmu_ops.alloc_pmd, mm, pfn);
428 static inline void paravirt_release_pmd(unsigned long pfn)
430 PVOP_VCALL1(pv_mmu_ops.release_pmd, pfn);
433 static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
435 PVOP_VCALL2(pv_mmu_ops.alloc_pud, mm, pfn);
437 static inline void paravirt_release_pud(unsigned long pfn)
439 PVOP_VCALL1(pv_mmu_ops.release_pud, pfn);
442 static inline void pte_update(struct mm_struct *mm, unsigned long addr,
443 pte_t *ptep)
445 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
447 static inline void pmd_update(struct mm_struct *mm, unsigned long addr,
448 pmd_t *pmdp)
450 PVOP_VCALL3(pv_mmu_ops.pmd_update, mm, addr, pmdp);
453 static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
454 pte_t *ptep)
456 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
459 static inline void pmd_update_defer(struct mm_struct *mm, unsigned long addr,
460 pmd_t *pmdp)
462 PVOP_VCALL3(pv_mmu_ops.pmd_update_defer, mm, addr, pmdp);
465 static inline pte_t __pte(pteval_t val)
467 pteval_t ret;
469 if (sizeof(pteval_t) > sizeof(long))
470 ret = PVOP_CALLEE2(pteval_t,
471 pv_mmu_ops.make_pte,
472 val, (u64)val >> 32);
473 else
474 ret = PVOP_CALLEE1(pteval_t,
475 pv_mmu_ops.make_pte,
476 val);
478 return (pte_t) { .pte = ret };
481 static inline pteval_t pte_val(pte_t pte)
483 pteval_t ret;
485 if (sizeof(pteval_t) > sizeof(long))
486 ret = PVOP_CALLEE2(pteval_t, pv_mmu_ops.pte_val,
487 pte.pte, (u64)pte.pte >> 32);
488 else
489 ret = PVOP_CALLEE1(pteval_t, pv_mmu_ops.pte_val,
490 pte.pte);
492 return ret;
495 static inline pgd_t __pgd(pgdval_t val)
497 pgdval_t ret;
499 if (sizeof(pgdval_t) > sizeof(long))
500 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.make_pgd,
501 val, (u64)val >> 32);
502 else
503 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.make_pgd,
504 val);
506 return (pgd_t) { ret };
509 static inline pgdval_t pgd_val(pgd_t pgd)
511 pgdval_t ret;
513 if (sizeof(pgdval_t) > sizeof(long))
514 ret = PVOP_CALLEE2(pgdval_t, pv_mmu_ops.pgd_val,
515 pgd.pgd, (u64)pgd.pgd >> 32);
516 else
517 ret = PVOP_CALLEE1(pgdval_t, pv_mmu_ops.pgd_val,
518 pgd.pgd);
520 return ret;
523 #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
524 static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
525 pte_t *ptep)
527 pteval_t ret;
529 ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
530 mm, addr, ptep);
532 return (pte_t) { .pte = ret };
535 static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
536 pte_t *ptep, pte_t pte)
538 if (sizeof(pteval_t) > sizeof(long))
539 /* 5 arg words */
540 pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
541 else
542 PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
543 mm, addr, ptep, pte.pte);
546 static inline void set_pte(pte_t *ptep, pte_t pte)
548 if (sizeof(pteval_t) > sizeof(long))
549 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
550 pte.pte, (u64)pte.pte >> 32);
551 else
552 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
553 pte.pte);
556 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
557 pte_t *ptep, pte_t pte)
559 if (sizeof(pteval_t) > sizeof(long))
560 /* 5 arg words */
561 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
562 else
563 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
566 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
567 static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
568 pmd_t *pmdp, pmd_t pmd)
570 if (sizeof(pmdval_t) > sizeof(long))
571 /* 5 arg words */
572 pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd);
573 else
574 PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp,
575 native_pmd_val(pmd));
577 #endif
579 static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
581 pmdval_t val = native_pmd_val(pmd);
583 if (sizeof(pmdval_t) > sizeof(long))
584 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
585 else
586 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
589 #if PAGETABLE_LEVELS >= 3
590 static inline pmd_t __pmd(pmdval_t val)
592 pmdval_t ret;
594 if (sizeof(pmdval_t) > sizeof(long))
595 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.make_pmd,
596 val, (u64)val >> 32);
597 else
598 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.make_pmd,
599 val);
601 return (pmd_t) { ret };
604 static inline pmdval_t pmd_val(pmd_t pmd)
606 pmdval_t ret;
608 if (sizeof(pmdval_t) > sizeof(long))
609 ret = PVOP_CALLEE2(pmdval_t, pv_mmu_ops.pmd_val,
610 pmd.pmd, (u64)pmd.pmd >> 32);
611 else
612 ret = PVOP_CALLEE1(pmdval_t, pv_mmu_ops.pmd_val,
613 pmd.pmd);
615 return ret;
618 static inline void set_pud(pud_t *pudp, pud_t pud)
620 pudval_t val = native_pud_val(pud);
622 if (sizeof(pudval_t) > sizeof(long))
623 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
624 val, (u64)val >> 32);
625 else
626 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
627 val);
629 #if PAGETABLE_LEVELS == 4
630 static inline pud_t __pud(pudval_t val)
632 pudval_t ret;
634 if (sizeof(pudval_t) > sizeof(long))
635 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.make_pud,
636 val, (u64)val >> 32);
637 else
638 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.make_pud,
639 val);
641 return (pud_t) { ret };
644 static inline pudval_t pud_val(pud_t pud)
646 pudval_t ret;
648 if (sizeof(pudval_t) > sizeof(long))
649 ret = PVOP_CALLEE2(pudval_t, pv_mmu_ops.pud_val,
650 pud.pud, (u64)pud.pud >> 32);
651 else
652 ret = PVOP_CALLEE1(pudval_t, pv_mmu_ops.pud_val,
653 pud.pud);
655 return ret;
658 static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
660 pgdval_t val = native_pgd_val(pgd);
662 if (sizeof(pgdval_t) > sizeof(long))
663 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
664 val, (u64)val >> 32);
665 else
666 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
667 val);
670 static inline void pgd_clear(pgd_t *pgdp)
672 set_pgd(pgdp, __pgd(0));
675 static inline void pud_clear(pud_t *pudp)
677 set_pud(pudp, __pud(0));
680 #endif /* PAGETABLE_LEVELS == 4 */
682 #endif /* PAGETABLE_LEVELS >= 3 */
684 #ifdef CONFIG_X86_PAE
685 /* Special-case pte-setting operations for PAE, which can't update a
686 64-bit pte atomically */
687 static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
689 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
690 pte.pte, pte.pte >> 32);
693 static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
694 pte_t *ptep)
696 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
699 static inline void pmd_clear(pmd_t *pmdp)
701 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
703 #else /* !CONFIG_X86_PAE */
704 static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
706 set_pte(ptep, pte);
709 static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
710 pte_t *ptep)
712 set_pte_at(mm, addr, ptep, __pte(0));
715 static inline void pmd_clear(pmd_t *pmdp)
717 set_pmd(pmdp, __pmd(0));
719 #endif /* CONFIG_X86_PAE */
721 #define __HAVE_ARCH_START_CONTEXT_SWITCH
722 static inline void arch_start_context_switch(struct task_struct *prev)
724 PVOP_VCALL1(pv_cpu_ops.start_context_switch, prev);
727 static inline void arch_end_context_switch(struct task_struct *next)
729 PVOP_VCALL1(pv_cpu_ops.end_context_switch, next);
732 #define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
733 static inline void arch_enter_lazy_mmu_mode(void)
735 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
738 static inline void arch_leave_lazy_mmu_mode(void)
740 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
743 void arch_flush_lazy_mmu_mode(void);
745 static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
746 phys_addr_t phys, pgprot_t flags)
748 pv_mmu_ops.set_fixmap(idx, phys, flags);
751 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
753 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
755 return PVOP_CALL1(int, pv_lock_ops.spin_is_locked, lock);
758 static inline int arch_spin_is_contended(struct arch_spinlock *lock)
760 return PVOP_CALL1(int, pv_lock_ops.spin_is_contended, lock);
762 #define arch_spin_is_contended arch_spin_is_contended
764 static __always_inline void arch_spin_lock(struct arch_spinlock *lock)
766 PVOP_VCALL1(pv_lock_ops.spin_lock, lock);
769 static __always_inline void arch_spin_lock_flags(struct arch_spinlock *lock,
770 unsigned long flags)
772 PVOP_VCALL2(pv_lock_ops.spin_lock_flags, lock, flags);
775 static __always_inline int arch_spin_trylock(struct arch_spinlock *lock)
777 return PVOP_CALL1(int, pv_lock_ops.spin_trylock, lock);
780 static __always_inline void arch_spin_unlock(struct arch_spinlock *lock)
782 PVOP_VCALL1(pv_lock_ops.spin_unlock, lock);
785 #endif
787 #ifdef CONFIG_X86_32
788 #define PV_SAVE_REGS "pushl %ecx; pushl %edx;"
789 #define PV_RESTORE_REGS "popl %edx; popl %ecx;"
791 /* save and restore all caller-save registers, except return value */
792 #define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
793 #define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
795 #define PV_FLAGS_ARG "0"
796 #define PV_EXTRA_CLOBBERS
797 #define PV_VEXTRA_CLOBBERS
798 #else
799 /* save and restore all caller-save registers, except return value */
800 #define PV_SAVE_ALL_CALLER_REGS \
801 "push %rcx;" \
802 "push %rdx;" \
803 "push %rsi;" \
804 "push %rdi;" \
805 "push %r8;" \
806 "push %r9;" \
807 "push %r10;" \
808 "push %r11;"
809 #define PV_RESTORE_ALL_CALLER_REGS \
810 "pop %r11;" \
811 "pop %r10;" \
812 "pop %r9;" \
813 "pop %r8;" \
814 "pop %rdi;" \
815 "pop %rsi;" \
816 "pop %rdx;" \
817 "pop %rcx;"
819 /* We save some registers, but all of them, that's too much. We clobber all
820 * caller saved registers but the argument parameter */
821 #define PV_SAVE_REGS "pushq %%rdi;"
822 #define PV_RESTORE_REGS "popq %%rdi;"
823 #define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx", "rsi"
824 #define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx", "rsi"
825 #define PV_FLAGS_ARG "D"
826 #endif
829 * Generate a thunk around a function which saves all caller-save
830 * registers except for the return value. This allows C functions to
831 * be called from assembler code where fewer than normal registers are
832 * available. It may also help code generation around calls from C
833 * code if the common case doesn't use many registers.
835 * When a callee is wrapped in a thunk, the caller can assume that all
836 * arg regs and all scratch registers are preserved across the
837 * call. The return value in rax/eax will not be saved, even for void
838 * functions.
840 #define PV_CALLEE_SAVE_REGS_THUNK(func) \
841 extern typeof(func) __raw_callee_save_##func; \
842 static void *__##func##__ __used = func; \
844 asm(".pushsection .text;" \
845 "__raw_callee_save_" #func ": " \
846 PV_SAVE_ALL_CALLER_REGS \
847 "call " #func ";" \
848 PV_RESTORE_ALL_CALLER_REGS \
849 "ret;" \
850 ".popsection")
852 /* Get a reference to a callee-save function */
853 #define PV_CALLEE_SAVE(func) \
854 ((struct paravirt_callee_save) { __raw_callee_save_##func })
856 /* Promise that "func" already uses the right calling convention */
857 #define __PV_IS_CALLEE_SAVE(func) \
858 ((struct paravirt_callee_save) { func })
860 static inline notrace unsigned long arch_local_save_flags(void)
862 return PVOP_CALLEE0(unsigned long, pv_irq_ops.save_fl);
865 static inline notrace void arch_local_irq_restore(unsigned long f)
867 PVOP_VCALLEE1(pv_irq_ops.restore_fl, f);
870 static inline notrace void arch_local_irq_disable(void)
872 PVOP_VCALLEE0(pv_irq_ops.irq_disable);
875 static inline notrace void arch_local_irq_enable(void)
877 PVOP_VCALLEE0(pv_irq_ops.irq_enable);
880 static inline notrace unsigned long arch_local_irq_save(void)
882 unsigned long f;
884 f = arch_local_save_flags();
885 arch_local_irq_disable();
886 return f;
890 /* Make sure as little as possible of this mess escapes. */
891 #undef PARAVIRT_CALL
892 #undef __PVOP_CALL
893 #undef __PVOP_VCALL
894 #undef PVOP_VCALL0
895 #undef PVOP_CALL0
896 #undef PVOP_VCALL1
897 #undef PVOP_CALL1
898 #undef PVOP_VCALL2
899 #undef PVOP_CALL2
900 #undef PVOP_VCALL3
901 #undef PVOP_CALL3
902 #undef PVOP_VCALL4
903 #undef PVOP_CALL4
905 extern void default_banner(void);
907 #else /* __ASSEMBLY__ */
909 #define _PVSITE(ptype, clobbers, ops, word, algn) \
910 771:; \
911 ops; \
912 772:; \
913 .pushsection .parainstructions,"a"; \
914 .align algn; \
915 word 771b; \
916 .byte ptype; \
917 .byte 772b-771b; \
918 .short clobbers; \
919 .popsection
922 #define COND_PUSH(set, mask, reg) \
923 .if ((~(set)) & mask); push %reg; .endif
924 #define COND_POP(set, mask, reg) \
925 .if ((~(set)) & mask); pop %reg; .endif
927 #ifdef CONFIG_X86_64
929 #define PV_SAVE_REGS(set) \
930 COND_PUSH(set, CLBR_RAX, rax); \
931 COND_PUSH(set, CLBR_RCX, rcx); \
932 COND_PUSH(set, CLBR_RDX, rdx); \
933 COND_PUSH(set, CLBR_RSI, rsi); \
934 COND_PUSH(set, CLBR_RDI, rdi); \
935 COND_PUSH(set, CLBR_R8, r8); \
936 COND_PUSH(set, CLBR_R9, r9); \
937 COND_PUSH(set, CLBR_R10, r10); \
938 COND_PUSH(set, CLBR_R11, r11)
939 #define PV_RESTORE_REGS(set) \
940 COND_POP(set, CLBR_R11, r11); \
941 COND_POP(set, CLBR_R10, r10); \
942 COND_POP(set, CLBR_R9, r9); \
943 COND_POP(set, CLBR_R8, r8); \
944 COND_POP(set, CLBR_RDI, rdi); \
945 COND_POP(set, CLBR_RSI, rsi); \
946 COND_POP(set, CLBR_RDX, rdx); \
947 COND_POP(set, CLBR_RCX, rcx); \
948 COND_POP(set, CLBR_RAX, rax)
950 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
951 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
952 #define PARA_INDIRECT(addr) *addr(%rip)
953 #else
954 #define PV_SAVE_REGS(set) \
955 COND_PUSH(set, CLBR_EAX, eax); \
956 COND_PUSH(set, CLBR_EDI, edi); \
957 COND_PUSH(set, CLBR_ECX, ecx); \
958 COND_PUSH(set, CLBR_EDX, edx)
959 #define PV_RESTORE_REGS(set) \
960 COND_POP(set, CLBR_EDX, edx); \
961 COND_POP(set, CLBR_ECX, ecx); \
962 COND_POP(set, CLBR_EDI, edi); \
963 COND_POP(set, CLBR_EAX, eax)
965 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
966 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
967 #define PARA_INDIRECT(addr) *%cs:addr
968 #endif
970 #define INTERRUPT_RETURN \
971 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
972 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
974 #define DISABLE_INTERRUPTS(clobbers) \
975 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
976 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
977 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
978 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
980 #define ENABLE_INTERRUPTS(clobbers) \
981 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
982 PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
983 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
984 PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
986 #define USERGS_SYSRET32 \
987 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32), \
988 CLBR_NONE, \
989 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
991 #ifdef CONFIG_X86_32
992 #define GET_CR0_INTO_EAX \
993 push %ecx; push %edx; \
994 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
995 pop %edx; pop %ecx
997 #define ENABLE_INTERRUPTS_SYSEXIT \
998 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
999 CLBR_NONE, \
1000 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1003 #else /* !CONFIG_X86_32 */
1006 * If swapgs is used while the userspace stack is still current,
1007 * there's no way to call a pvop. The PV replacement *must* be
1008 * inlined, or the swapgs instruction must be trapped and emulated.
1010 #define SWAPGS_UNSAFE_STACK \
1011 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1012 swapgs)
1015 * Note: swapgs is very special, and in practise is either going to be
1016 * implemented with a single "swapgs" instruction or something very
1017 * special. Either way, we don't need to save any registers for
1018 * it.
1020 #define SWAPGS \
1021 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1022 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
1025 #define GET_CR2_INTO_RCX \
1026 call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \
1027 movq %rax, %rcx; \
1028 xorq %rax, %rax;
1030 #define PARAVIRT_ADJUST_EXCEPTION_FRAME \
1031 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
1032 CLBR_NONE, \
1033 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
1035 #define USERGS_SYSRET64 \
1036 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
1037 CLBR_NONE, \
1038 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
1040 #define ENABLE_INTERRUPTS_SYSEXIT32 \
1041 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
1042 CLBR_NONE, \
1043 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
1044 #endif /* CONFIG_X86_32 */
1046 #endif /* __ASSEMBLY__ */
1047 #else /* CONFIG_PARAVIRT */
1048 # define default_banner x86_init_noop
1049 #endif /* !CONFIG_PARAVIRT */
1050 #endif /* _ASM_X86_PARAVIRT_H */