Merge tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
[linux-2.6-block.git] / arch / x86 / include / asm / paravirt.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1965aae3
PA
2#ifndef _ASM_X86_PARAVIRT_H
3#define _ASM_X86_PARAVIRT_H
d3561b7f
RR
4/* Various instructions on x86 need to be replaced for
5 * para-virtualization: those hooks are defined here. */
b239fb25 6
239f2e24
TG
7#include <asm/paravirt_types.h>
8
24a295e4 9#ifndef __ASSEMBLER__
a5a0abfd
KO
10struct mm_struct;
11#endif
12
b239fb25 13#ifdef CONFIG_PARAVIRT
54321d94 14#include <asm/pgtable_types.h>
658be9d3 15#include <asm/asm.h>
3010a066 16#include <asm/nospec-branch.h>
d3561b7f 17
24a295e4 18#ifndef __ASSEMBLER__
187f1882 19#include <linux/bug.h>
3dc494e8 20#include <linux/types.h>
d4c10477 21#include <linux/cpumask.h>
a0e2bf7c 22#include <linux/static_call_types.h>
87b240cb 23#include <asm/frame.h>
1a45b7aa 24
a0e2bf7c
JG
25u64 dummy_steal_clock(int cpu);
26u64 dummy_sched_clock(void);
27
28DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
29DECLARE_STATIC_CALL(pv_sched_clock, dummy_sched_clock);
30
31void paravirt_set_sched_clock(u64 (*func)(void));
32
8739c681 33static __always_inline u64 paravirt_sched_clock(void)
fdc0269e 34{
a0e2bf7c 35 return static_call(pv_sched_clock)();
fdc0269e
JG
36}
37
38struct static_key;
39extern struct static_key paravirt_steal_enabled;
40extern struct static_key paravirt_steal_rq_enabled;
41
89f579ce
YW
42__visible void __native_queued_spin_unlock(struct qspinlock *lock);
43bool pv_is_native_spin_unlock(void);
44__visible bool __native_vcpu_is_preempted(long cpu);
45bool pv_is_native_vcpu_is_preempted(void);
46
fdc0269e
JG
47static inline u64 paravirt_steal_clock(int cpu)
48{
a0e2bf7c 49 return static_call(pv_steal_clock)(cpu);
fdc0269e
JG
50}
51
4e629211
JG
52#ifdef CONFIG_PARAVIRT_SPINLOCKS
53void __init paravirt_set_cap(void);
54#endif
55
fdc0269e
JG
56/* The paravirtualized I/O functions */
57static inline void slow_down_io(void)
58{
eac46b32 59 PVOP_VCALL0(cpu.io_delay);
fdc0269e 60#ifdef REALLY_SLOW_IO
eac46b32
PZ
61 PVOP_VCALL0(cpu.io_delay);
62 PVOP_VCALL0(cpu.io_delay);
63 PVOP_VCALL0(cpu.io_delay);
fdc0269e
JG
64#endif
65}
66
2faf153b 67void native_flush_tlb_local(void);
cd30d26c 68void native_flush_tlb_global(void);
127ac915 69void native_flush_tlb_one_user(unsigned long addr);
4ce94eab 70void native_flush_tlb_multi(const struct cpumask *cpumask,
29def599 71 const struct flush_tlb_info *info);
2faf153b
TG
72
73static inline void __flush_tlb_local(void)
fdc0269e
JG
74{
75 PVOP_VCALL0(mmu.flush_tlb_user);
76}
77
78static inline void __flush_tlb_global(void)
79{
80 PVOP_VCALL0(mmu.flush_tlb_kernel);
81}
82
83static inline void __flush_tlb_one_user(unsigned long addr)
84{
85 PVOP_VCALL1(mmu.flush_tlb_one_user, addr);
86}
87
4ce94eab 88static inline void __flush_tlb_multi(const struct cpumask *cpumask,
29def599 89 const struct flush_tlb_info *info)
fdc0269e 90{
4ce94eab 91 PVOP_VCALL2(mmu.flush_tlb_multi, cpumask, info);
fdc0269e
JG
92}
93
fdc0269e
JG
94static inline void paravirt_arch_exit_mmap(struct mm_struct *mm)
95{
96 PVOP_VCALL1(mmu.exit_mmap, mm);
97}
98
064ce6c5
BS
99static inline void notify_page_enc_status_changed(unsigned long pfn,
100 int npages, bool enc)
101{
102 PVOP_VCALL3(mmu.notify_page_enc_status_changed, pfn, npages, enc);
fdc0269e
JG
103}
104
22cc5ca5
KS
105static __always_inline void arch_safe_halt(void)
106{
107 PVOP_VCALL0(irq.safe_halt);
108}
109
110static inline void halt(void)
111{
112 PVOP_VCALL0(irq.halt);
113}
114
9bad5658 115#ifdef CONFIG_PARAVIRT_XXL
da51da18 116static inline void load_sp0(unsigned long sp0)
d3561b7f 117{
5c83511b 118 PVOP_VCALL1(cpu.load_sp0, sp0);
d3561b7f
RR
119}
120
d3561b7f
RR
121/* The paravirtualized CPUID instruction. */
122static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
123 unsigned int *ecx, unsigned int *edx)
124{
5c83511b 125 PVOP_VCALL4(cpu.cpuid, eax, ebx, ecx, edx);
d3561b7f
RR
126}
127
128/*
129 * These special macros can be used to get or set a debugging register
130 */
f4afb713 131static __always_inline unsigned long paravirt_get_debugreg(int reg)
f8822f42 132{
5c83511b 133 return PVOP_CALL1(unsigned long, cpu.get_debugreg, reg);
f8822f42
JF
134}
135#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
7361fac0 136static __always_inline void set_debugreg(unsigned long val, int reg)
f8822f42 137{
5c83511b 138 PVOP_VCALL2(cpu.set_debugreg, reg, val);
f8822f42 139}
d3561b7f 140
f8822f42
JF
141static inline unsigned long read_cr0(void)
142{
5c83511b 143 return PVOP_CALL0(unsigned long, cpu.read_cr0);
f8822f42 144}
d3561b7f 145
f8822f42
JF
146static inline void write_cr0(unsigned long x)
147{
5c83511b 148 PVOP_VCALL1(cpu.write_cr0, x);
f8822f42
JF
149}
150
0a53c9ac 151static __always_inline unsigned long read_cr2(void)
f8822f42 152{
fafe5e74 153 return PVOP_ALT_CALLEE0(unsigned long, mmu.read_cr2,
772ca413 154 "mov %%cr2, %%rax;", ALT_NOT_XEN);
f8822f42
JF
155}
156
209cfd0c 157static __always_inline void write_cr2(unsigned long x)
f8822f42 158{
5c83511b 159 PVOP_VCALL1(mmu.write_cr2, x);
f8822f42
JF
160}
161
6c690ee1 162static inline unsigned long __read_cr3(void)
f8822f42 163{
fafe5e74 164 return PVOP_ALT_CALL0(unsigned long, mmu.read_cr3,
772ca413 165 "mov %%cr3, %%rax;", ALT_NOT_XEN);
f8822f42 166}
d3561b7f 167
f8822f42
JF
168static inline void write_cr3(unsigned long x)
169{
772ca413 170 PVOP_ALT_VCALL1(mmu.write_cr3, x, "mov %%rdi, %%cr3", ALT_NOT_XEN);
f8822f42 171}
d3561b7f 172
1e02ce4c 173static inline void __write_cr4(unsigned long x)
f8822f42 174{
5c83511b 175 PVOP_VCALL1(cpu.write_cr4, x);
f8822f42 176}
3dc494e8 177
502ad6e5 178static inline u64 paravirt_read_msr(u32 msr)
dd2f4a00 179{
5c83511b 180 return PVOP_CALL1(u64, cpu.read_msr, msr);
dd2f4a00
AL
181}
182
0c2678ef 183static inline void paravirt_write_msr(u32 msr, u64 val)
dd2f4a00 184{
0c2678ef 185 PVOP_VCALL2(cpu.write_msr, msr, val);
dd2f4a00
AL
186}
187
502ad6e5 188static inline int paravirt_read_msr_safe(u32 msr, u64 *val)
f8822f42 189{
502ad6e5 190 return PVOP_CALL2(int, cpu.read_msr_safe, msr, val);
f8822f42 191}
132ec92f 192
0c2678ef 193static inline int paravirt_write_msr_safe(u32 msr, u64 val)
f8822f42 194{
0c2678ef 195 return PVOP_CALL2(int, cpu.write_msr_safe, msr, val);
f8822f42
JF
196}
197
49cd740b
JP
198#define rdmsr(msr, val1, val2) \
199do { \
4985ce15 200 u64 _l = paravirt_read_msr(msr); \
f8822f42
JF
201 val1 = (u32)_l; \
202 val2 = _l >> 32; \
49cd740b 203} while (0)
d3561b7f 204
0c2678ef
XLI
205static __always_inline void wrmsr(u32 msr, u32 low, u32 high)
206{
207 paravirt_write_msr(msr, (u64)high << 32 | low);
208}
d3561b7f 209
c435e608 210#define rdmsrq(msr, val) \
49cd740b 211do { \
4985ce15 212 val = paravirt_read_msr(msr); \
49cd740b 213} while (0)
d3561b7f 214
0c2678ef 215static inline void wrmsrq(u32 msr, u64 val)
47edb651 216{
0c2678ef 217 paravirt_write_msr(msr, val);
47edb651
AL
218}
219
0c2678ef
XLI
220static inline int wrmsrq_safe(u32 msr, u64 val)
221{
222 return paravirt_write_msr_safe(msr, val);
223}
d3561b7f
RR
224
225/* rdmsr with exception handling */
c2ee03b2
AL
226#define rdmsr_safe(msr, a, b) \
227({ \
502ad6e5
XLI
228 u64 _l; \
229 int _err = paravirt_read_msr_safe((msr), &_l); \
c2ee03b2 230 (*a) = (u32)_l; \
502ad6e5 231 (*b) = (u32)(_l >> 32); \
c2ee03b2 232 _err; \
49cd740b 233})
d3561b7f 234
502ad6e5 235static __always_inline int rdmsrq_safe(u32 msr, u64 *p)
1de87bd4 236{
502ad6e5 237 return paravirt_read_msr_safe(msr, p);
1de87bd4 238}
177fed1e 239
795ada52 240static __always_inline u64 rdpmc(int counter)
f8822f42 241{
5c83511b 242 return PVOP_CALL1(u64, cpu.read_pmc, counter);
f8822f42 243}
d3561b7f 244
38ffbe66
JF
245static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
246{
5c83511b 247 PVOP_VCALL2(cpu.alloc_ldt, ldt, entries);
38ffbe66
JF
248}
249
250static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
251{
5c83511b 252 PVOP_VCALL2(cpu.free_ldt, ldt, entries);
38ffbe66
JF
253}
254
f8822f42
JF
255static inline void load_TR_desc(void)
256{
5c83511b 257 PVOP_VCALL0(cpu.load_tr_desc);
f8822f42 258}
6b68f01b 259static inline void load_gdt(const struct desc_ptr *dtr)
f8822f42 260{
5c83511b 261 PVOP_VCALL1(cpu.load_gdt, dtr);
f8822f42 262}
6b68f01b 263static inline void load_idt(const struct desc_ptr *dtr)
f8822f42 264{
5c83511b 265 PVOP_VCALL1(cpu.load_idt, dtr);
f8822f42
JF
266}
267static inline void set_ldt(const void *addr, unsigned entries)
268{
5c83511b 269 PVOP_VCALL2(cpu.set_ldt, addr, entries);
f8822f42 270}
f8822f42
JF
271static inline unsigned long paravirt_store_tr(void)
272{
5c83511b 273 return PVOP_CALL0(unsigned long, cpu.store_tr);
f8822f42 274}
9bad5658 275
f8822f42
JF
276#define store_tr(tr) ((tr) = paravirt_store_tr())
277static inline void load_TLS(struct thread_struct *t, unsigned cpu)
278{
5c83511b 279 PVOP_VCALL2(cpu.load_tls, t, cpu);
f8822f42 280}
75b8bb3e 281
9f9d489a
JF
282static inline void load_gs_index(unsigned int gs)
283{
5c83511b 284 PVOP_VCALL1(cpu.load_gs_index, gs);
9f9d489a 285}
9f9d489a 286
75b8bb3e
GOC
287static inline void write_ldt_entry(struct desc_struct *dt, int entry,
288 const void *desc)
f8822f42 289{
5c83511b 290 PVOP_VCALL3(cpu.write_ldt_entry, dt, entry, desc);
f8822f42 291}
014b15be
GOC
292
293static inline void write_gdt_entry(struct desc_struct *dt, int entry,
294 void *desc, int type)
f8822f42 295{
5c83511b 296 PVOP_VCALL4(cpu.write_gdt_entry, dt, entry, desc, type);
f8822f42 297}
014b15be 298
8d947344 299static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
f8822f42 300{
5c83511b 301 PVOP_VCALL3(cpu.write_idt_entry, dt, entry, g);
f8822f42 302}
d3561b7f 303
99bcd4a6 304#ifdef CONFIG_X86_IOPL_IOPERM
cadfad87
AL
305static inline void tss_invalidate_io_bitmap(void)
306{
307 PVOP_VCALL0(cpu.invalidate_io_bitmap);
308}
309
99bcd4a6
JG
310static inline void tss_update_io_bitmap(void)
311{
312 PVOP_VCALL0(cpu.update_io_bitmap);
313}
314#endif
315
c9ae1b10 316static inline void paravirt_enter_mmap(struct mm_struct *next)
d6dd61c8 317{
c9ae1b10 318 PVOP_VCALL1(mmu.enter_mmap, next);
d6dd61c8
JF
319}
320
eba0045f
JF
321static inline int paravirt_pgd_alloc(struct mm_struct *mm)
322{
5c83511b 323 return PVOP_CALL1(int, mmu.pgd_alloc, mm);
eba0045f
JF
324}
325
326static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
327{
5c83511b 328 PVOP_VCALL2(mmu.pgd_free, mm, pgd);
eba0045f
JF
329}
330
f8639939 331static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn)
f8822f42 332{
5c83511b 333 PVOP_VCALL2(mmu.alloc_pte, mm, pfn);
f8822f42 334}
f8639939 335static inline void paravirt_release_pte(unsigned long pfn)
f8822f42 336{
5c83511b 337 PVOP_VCALL1(mmu.release_pte, pfn);
f8822f42 338}
c119ecce 339
f8639939 340static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn)
f8822f42 341{
5c83511b 342 PVOP_VCALL2(mmu.alloc_pmd, mm, pfn);
f8822f42 343}
c119ecce 344
f8639939 345static inline void paravirt_release_pmd(unsigned long pfn)
da181a8b 346{
5c83511b 347 PVOP_VCALL1(mmu.release_pmd, pfn);
da181a8b
RR
348}
349
f8639939 350static inline void paravirt_alloc_pud(struct mm_struct *mm, unsigned long pfn)
2761fa09 351{
5c83511b 352 PVOP_VCALL2(mmu.alloc_pud, mm, pfn);
2761fa09 353}
f8639939 354static inline void paravirt_release_pud(unsigned long pfn)
2761fa09 355{
5c83511b 356 PVOP_VCALL1(mmu.release_pud, pfn);
2761fa09
JF
357}
358
335437fb
KS
359static inline void paravirt_alloc_p4d(struct mm_struct *mm, unsigned long pfn)
360{
5c83511b 361 PVOP_VCALL2(mmu.alloc_p4d, mm, pfn);
335437fb
KS
362}
363
364static inline void paravirt_release_p4d(unsigned long pfn)
365{
5c83511b 366 PVOP_VCALL1(mmu.release_p4d, pfn);
335437fb
KS
367}
368
773221f4 369static inline pte_t __pte(pteval_t val)
da181a8b 370{
fafe5e74 371 return (pte_t) { PVOP_ALT_CALLEE1(pteval_t, mmu.make_pte, val,
772ca413 372 "mov %%rdi, %%rax", ALT_NOT_XEN) };
da181a8b
RR
373}
374
773221f4
JF
375static inline pteval_t pte_val(pte_t pte)
376{
fafe5e74 377 return PVOP_ALT_CALLEE1(pteval_t, mmu.pte_val, pte.pte,
772ca413 378 "mov %%rdi, %%rax", ALT_NOT_XEN);
773221f4
JF
379}
380
ef38503e 381static inline pgd_t __pgd(pgdval_t val)
da181a8b 382{
fafe5e74 383 return (pgd_t) { PVOP_ALT_CALLEE1(pgdval_t, mmu.make_pgd, val,
772ca413 384 "mov %%rdi, %%rax", ALT_NOT_XEN) };
ef38503e
JF
385}
386
387static inline pgdval_t pgd_val(pgd_t pgd)
388{
fafe5e74 389 return PVOP_ALT_CALLEE1(pgdval_t, mmu.pgd_val, pgd.pgd,
772ca413 390 "mov %%rdi, %%rax", ALT_NOT_XEN);
f8822f42
JF
391}
392
08b882c6 393#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
0cbe3e26 394static inline pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr,
08b882c6
JF
395 pte_t *ptep)
396{
397 pteval_t ret;
398
0cbe3e26 399 ret = PVOP_CALL3(pteval_t, mmu.ptep_modify_prot_start, vma, addr, ptep);
08b882c6
JF
400
401 return (pte_t) { .pte = ret };
402}
403
0cbe3e26 404static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr,
04a86453 405 pte_t *ptep, pte_t old_pte, pte_t pte)
08b882c6 406{
0cbe3e26 407
0cabf991 408 PVOP_VCALL4(mmu.ptep_modify_prot_commit, vma, addr, ptep, pte.pte);
08b882c6
JF
409}
410
4eed80cd
JF
411static inline void set_pte(pte_t *ptep, pte_t pte)
412{
0cabf991 413 PVOP_VCALL2(mmu.set_pte, ptep, pte.pte);
4eed80cd
JF
414}
415
60b3f626
JF
416static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
417{
0cabf991 418 PVOP_VCALL2(mmu.set_pmd, pmdp, native_pmd_val(pmd));
60b3f626
JF
419}
420
1fe91514
GOC
421static inline pmd_t __pmd(pmdval_t val)
422{
fafe5e74 423 return (pmd_t) { PVOP_ALT_CALLEE1(pmdval_t, mmu.make_pmd, val,
772ca413 424 "mov %%rdi, %%rax", ALT_NOT_XEN) };
1fe91514
GOC
425}
426
427static inline pmdval_t pmd_val(pmd_t pmd)
428{
fafe5e74 429 return PVOP_ALT_CALLEE1(pmdval_t, mmu.pmd_val, pmd.pmd,
772ca413 430 "mov %%rdi, %%rax", ALT_NOT_XEN);
1fe91514
GOC
431}
432
433static inline void set_pud(pud_t *pudp, pud_t pud)
434{
0cabf991 435 PVOP_VCALL2(mmu.set_pud, pudp, native_pud_val(pud));
1fe91514 436}
0cabf991 437
9042219c
EH
438static inline pud_t __pud(pudval_t val)
439{
440 pudval_t ret;
441
fafe5e74 442 ret = PVOP_ALT_CALLEE1(pudval_t, mmu.make_pud, val,
772ca413 443 "mov %%rdi, %%rax", ALT_NOT_XEN);
9042219c
EH
444
445 return (pud_t) { ret };
446}
447
448static inline pudval_t pud_val(pud_t pud)
449{
fafe5e74 450 return PVOP_ALT_CALLEE1(pudval_t, mmu.pud_val, pud.pud,
772ca413 451 "mov %%rdi, %%rax", ALT_NOT_XEN);
9042219c
EH
452}
453
f2a6a705
KS
454static inline void pud_clear(pud_t *pudp)
455{
7c9f80cb 456 set_pud(pudp, native_make_pud(0));
f2a6a705
KS
457}
458
459static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)
460{
461 p4dval_t val = native_p4d_val(p4d);
462
495310e4 463 PVOP_VCALL2(mmu.set_p4d, p4dp, val);
f2a6a705
KS
464}
465
335437fb 466static inline p4d_t __p4d(p4dval_t val)
f2a6a705 467{
fafe5e74 468 p4dval_t ret = PVOP_ALT_CALLEE1(p4dval_t, mmu.make_p4d, val,
772ca413 469 "mov %%rdi, %%rax", ALT_NOT_XEN);
f2a6a705 470
335437fb
KS
471 return (p4d_t) { ret };
472}
f2a6a705 473
335437fb
KS
474static inline p4dval_t p4d_val(p4d_t p4d)
475{
fafe5e74 476 return PVOP_ALT_CALLEE1(p4dval_t, mmu.p4d_val, p4d.p4d,
772ca413 477 "mov %%rdi, %%rax", ALT_NOT_XEN);
335437fb 478}
f2a6a705 479
92e1c5b3 480static inline void __set_pgd(pgd_t *pgdp, pgd_t pgd)
9042219c 481{
5c83511b 482 PVOP_VCALL2(mmu.set_pgd, pgdp, native_pgd_val(pgd));
9042219c
EH
483}
484
92e1c5b3 485#define set_pgd(pgdp, pgdval) do { \
ed7588d5 486 if (pgtable_l5_enabled()) \
92e1c5b3
KS
487 __set_pgd(pgdp, pgdval); \
488 else \
489 set_p4d((p4d_t *)(pgdp), (p4d_t) { (pgdval).pgd }); \
490} while (0)
491
492#define pgd_clear(pgdp) do { \
7c9f80cb
JG
493 if (pgtable_l5_enabled()) \
494 set_pgd(pgdp, native_make_pgd(0)); \
92e1c5b3 495} while (0)
9042219c 496
335437fb
KS
497static inline void p4d_clear(p4d_t *p4dp)
498{
7c9f80cb 499 set_p4d(p4dp, native_make_p4d(0));
335437fb
KS
500}
501
4eed80cd
JF
502static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
503{
504 set_pte(ptep, pte);
505}
506
4eed80cd
JF
507static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
508 pte_t *ptep)
509{
7c9f80cb 510 set_pte(ptep, native_make_pte(0));
4eed80cd 511}
60b3f626
JF
512
513static inline void pmd_clear(pmd_t *pmdp)
514{
7c9f80cb 515 set_pmd(pmdp, native_make_pmd(0));
60b3f626 516}
4eed80cd 517
7fd7d83d 518#define __HAVE_ARCH_START_CONTEXT_SWITCH
224101ed 519static inline void arch_start_context_switch(struct task_struct *prev)
f8822f42 520{
5c83511b 521 PVOP_VCALL1(cpu.start_context_switch, prev);
f8822f42
JF
522}
523
224101ed 524static inline void arch_end_context_switch(struct task_struct *next)
f8822f42 525{
5c83511b 526 PVOP_VCALL1(cpu.end_context_switch, next);
f8822f42
JF
527}
528
9226d125 529#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
f8822f42
JF
530static inline void arch_enter_lazy_mmu_mode(void)
531{
5c83511b 532 PVOP_VCALL0(mmu.lazy_mode.enter);
f8822f42
JF
533}
534
535static inline void arch_leave_lazy_mmu_mode(void)
536{
5c83511b 537 PVOP_VCALL0(mmu.lazy_mode.leave);
f8822f42
JF
538}
539
511ba86e
BO
540static inline void arch_flush_lazy_mmu_mode(void)
541{
5c83511b 542 PVOP_VCALL0(mmu.lazy_mode.flush);
511ba86e 543}
9226d125 544
aeaaa59c 545static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
3b3809ac 546 phys_addr_t phys, pgprot_t flags)
aeaaa59c 547{
5c83511b 548 pv_ops.mmu.set_fixmap(idx, phys, flags);
aeaaa59c 549}
fdc0269e 550#endif
aeaaa59c 551
b4ecc126 552#if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
4bb689ee 553
f233f7f1
PZI
554static __always_inline void pv_queued_spin_lock_slowpath(struct qspinlock *lock,
555 u32 val)
556{
5c83511b 557 PVOP_VCALL2(lock.queued_spin_lock_slowpath, lock, val);
f233f7f1
PZI
558}
559
560static __always_inline void pv_queued_spin_unlock(struct qspinlock *lock)
561{
fafe5e74
JG
562 PVOP_ALT_VCALLEE1(lock.queued_spin_unlock, lock,
563 "movb $0, (%%" _ASM_ARG1 ");",
564 ALT_NOT(X86_FEATURE_PVUNLOCK));
f233f7f1
PZI
565}
566
567static __always_inline void pv_wait(u8 *ptr, u8 val)
568{
5c83511b 569 PVOP_VCALL2(lock.wait, ptr, val);
f233f7f1
PZI
570}
571
572static __always_inline void pv_kick(int cpu)
573{
5c83511b 574 PVOP_VCALL1(lock.kick, cpu);
f233f7f1
PZI
575}
576
6c62985d 577static __always_inline bool pv_vcpu_is_preempted(long cpu)
3cded417 578{
fafe5e74
JG
579 return PVOP_ALT_CALLEE1(bool, lock.vcpu_is_preempted, cpu,
580 "xor %%" _ASM_AX ", %%" _ASM_AX ";",
581 ALT_NOT(X86_FEATURE_VCPUPREEMPT));
3cded417
PZ
582}
583
5c83511b
JG
584void __raw_callee_save___native_queued_spin_unlock(struct qspinlock *lock);
585bool __raw_callee_save___native_vcpu_is_preempted(long cpu);
586
f233f7f1 587#endif /* SMP && PARAVIRT_SPINLOCKS */
4bb689ee 588
2e47d3e6 589#ifdef CONFIG_X86_32
ecb93d1c 590/* save and restore all caller-save registers, except return value */
e584f559
JF
591#define PV_SAVE_ALL_CALLER_REGS "pushl %ecx;"
592#define PV_RESTORE_ALL_CALLER_REGS "popl %ecx;"
2e47d3e6 593#else
ecb93d1c
JF
594/* save and restore all caller-save registers, except return value */
595#define PV_SAVE_ALL_CALLER_REGS \
596 "push %rcx;" \
597 "push %rdx;" \
598 "push %rsi;" \
599 "push %rdi;" \
600 "push %r8;" \
601 "push %r9;" \
602 "push %r10;" \
603 "push %r11;"
604#define PV_RESTORE_ALL_CALLER_REGS \
605 "pop %r11;" \
606 "pop %r10;" \
607 "pop %r9;" \
608 "pop %r8;" \
609 "pop %rdi;" \
610 "pop %rsi;" \
611 "pop %rdx;" \
612 "pop %rcx;"
2e47d3e6
GOC
613#endif
614
ecb93d1c
JF
615/*
616 * Generate a thunk around a function which saves all caller-save
617 * registers except for the return value. This allows C functions to
618 * be called from assembler code where fewer than normal registers are
619 * available. It may also help code generation around calls from C
620 * code if the common case doesn't use many registers.
621 *
622 * When a callee is wrapped in a thunk, the caller can assume that all
623 * arg regs and all scratch registers are preserved across the
624 * call. The return value in rax/eax will not be saved, even for void
625 * functions.
626 */
87b240cb 627#define PV_THUNK_NAME(func) "__raw_callee_save_" #func
20125c87 628#define __PV_CALLEE_SAVE_REGS_THUNK(func, section) \
ecb93d1c 629 extern typeof(func) __raw_callee_save_##func; \
ecb93d1c 630 \
20125c87 631 asm(".pushsection " section ", \"ax\";" \
87b240cb
JP
632 ".globl " PV_THUNK_NAME(func) ";" \
633 ".type " PV_THUNK_NAME(func) ", @function;" \
1d293758 634 ASM_FUNC_ALIGN \
87b240cb 635 PV_THUNK_NAME(func) ":" \
c3b03791 636 ASM_ENDBR \
87b240cb 637 FRAME_BEGIN \
ecb93d1c
JF
638 PV_SAVE_ALL_CALLER_REGS \
639 "call " #func ";" \
640 PV_RESTORE_ALL_CALLER_REGS \
87b240cb 641 FRAME_END \
b17c2baa 642 ASM_RET \
083db676 643 ".size " PV_THUNK_NAME(func) ", .-" PV_THUNK_NAME(func) ";" \
ecb93d1c
JF
644 ".popsection")
645
20125c87
PZ
646#define PV_CALLEE_SAVE_REGS_THUNK(func) \
647 __PV_CALLEE_SAVE_REGS_THUNK(func, ".text")
648
ecb93d1c
JF
649/* Get a reference to a callee-save function */
650#define PV_CALLEE_SAVE(func) \
651 ((struct paravirt_callee_save) { __raw_callee_save_##func })
652
653/* Promise that "func" already uses the right calling convention */
654#define __PV_IS_CALLEE_SAVE(func) \
655 ((struct paravirt_callee_save) { func })
656
6da63eb2 657#ifdef CONFIG_PARAVIRT_XXL
e9382440 658static __always_inline unsigned long arch_local_save_flags(void)
139ec7c4 659{
fafe5e74 660 return PVOP_ALT_CALLEE0(unsigned long, irq.save_fl, "pushf; pop %%rax;",
772ca413 661 ALT_NOT_XEN);
139ec7c4
RR
662}
663
e9382440 664static __always_inline void arch_local_irq_disable(void)
139ec7c4 665{
772ca413 666 PVOP_ALT_VCALLEE0(irq.irq_disable, "cli;", ALT_NOT_XEN);
139ec7c4
RR
667}
668
e9382440 669static __always_inline void arch_local_irq_enable(void)
139ec7c4 670{
772ca413 671 PVOP_ALT_VCALLEE0(irq.irq_enable, "sti;", ALT_NOT_XEN);
139ec7c4
RR
672}
673
e9382440 674static __always_inline unsigned long arch_local_irq_save(void)
139ec7c4
RR
675{
676 unsigned long f;
677
df9ee292
DH
678 f = arch_local_save_flags();
679 arch_local_irq_disable();
139ec7c4
RR
680 return f;
681}
6da63eb2 682#endif
139ec7c4 683
74d4affd 684
294688c0 685/* Make sure as little as possible of this mess escapes. */
d5822035 686#undef PARAVIRT_CALL
1a45b7aa
JF
687#undef __PVOP_CALL
688#undef __PVOP_VCALL
f8822f42
JF
689#undef PVOP_VCALL0
690#undef PVOP_CALL0
691#undef PVOP_VCALL1
692#undef PVOP_CALL1
693#undef PVOP_VCALL2
694#undef PVOP_CALL2
695#undef PVOP_VCALL3
696#undef PVOP_CALL3
697#undef PVOP_VCALL4
698#undef PVOP_CALL4
139ec7c4 699
6f30c1ac 700extern void default_banner(void);
ce0a1b60 701void native_pv_lock_init(void) __init;
6f30c1ac 702
24a295e4 703#else /* __ASSEMBLER__ */
d3561b7f 704
658be9d3 705#ifdef CONFIG_X86_64
33634e42 706#ifdef CONFIG_PARAVIRT_XXL
60bc276b 707#ifdef CONFIG_DEBUG_ENTRY
9104a18d 708
491eccb7 709#define PARA_INDIRECT(addr) *addr(%rip)
658be9d3 710
fafe5e74 711.macro PARA_IRQ_save_fl
60bc276b
JG
712 ANNOTATE_RETPOLINE_SAFE;
713 call PARA_INDIRECT(pv_ops+PV_IRQ_save_fl);
fafe5e74
JG
714.endm
715
60bc276b
JG
716#define SAVE_FLAGS ALTERNATIVE_2 "PARA_IRQ_save_fl;", \
717 "ALT_CALL_INSTR;", ALT_CALL_ALWAYS, \
718 "pushf; pop %rax;", ALT_NOT_XEN
e17f8234 719#endif
55aedddb
PZ
720#endif /* CONFIG_PARAVIRT_XXL */
721#endif /* CONFIG_X86_64 */
722
24a295e4 723#endif /* __ASSEMBLER__ */
6f30c1ac
TG
724#else /* CONFIG_PARAVIRT */
725# define default_banner x86_init_noop
ce0a1b60 726
24a295e4 727#ifndef __ASSEMBLER__
ce0a1b60
AB
728static inline void native_pv_lock_init(void)
729{
730}
731#endif
fdc0269e
JG
732#endif /* !CONFIG_PARAVIRT */
733
24a295e4 734#ifndef __ASSEMBLER__
fdc0269e 735#ifndef CONFIG_PARAVIRT_XXL
c9ae1b10 736static inline void paravirt_enter_mmap(struct mm_struct *mm)
a1ea1c03
DH
737{
738}
fdc0269e 739#endif
a1ea1c03 740
fdc0269e 741#ifndef CONFIG_PARAVIRT
a1ea1c03
DH
742static inline void paravirt_arch_exit_mmap(struct mm_struct *mm)
743{
744}
fdc0269e 745#endif
4e629211
JG
746
747#ifndef CONFIG_PARAVIRT_SPINLOCKS
748static inline void paravirt_set_cap(void)
749{
750}
751#endif
24a295e4 752#endif /* __ASSEMBLER__ */
1965aae3 753#endif /* _ASM_X86_PARAVIRT_H */