1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef INCLUDE_XEN_OPS_H
3 #define INCLUDE_XEN_OPS_H
5 #include <linux/percpu.h>
6 #include <linux/notifier.h>
8 #include <xen/features.h>
9 #include <asm/xen/interface.h>
10 #include <xen/interface/vcpu.h>
12 DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
14 DECLARE_PER_CPU(uint32_t, xen_vcpu_id);
15 static inline uint32_t xen_vcpu_nr(int cpu)
17 return per_cpu(xen_vcpu_id, cpu);
20 #define XEN_VCPU_ID_INVALID U32_MAX
22 void xen_arch_pre_suspend(void);
23 void xen_arch_post_suspend(int suspend_cancelled);
25 void xen_timer_resume(void);
26 void xen_arch_resume(void);
27 void xen_arch_suspend(void);
29 void xen_reboot(int reason);
31 void xen_resume_notifier_register(struct notifier_block *nb);
32 void xen_resume_notifier_unregister(struct notifier_block *nb);
34 bool xen_vcpu_stolen(int vcpu);
35 void xen_setup_runstate_info(int cpu);
36 void xen_time_setup_guest(void);
37 void xen_manage_runstate_time(int action);
38 void xen_get_runstate_snapshot(struct vcpu_runstate_info *res);
39 u64 xen_steal_clock(int cpu);
41 int xen_setup_shutdown_event(void);
43 extern unsigned long *xen_contiguous_bitmap;
45 #if defined(CONFIG_XEN_PV)
46 int xen_remap_pfn(struct vm_area_struct *vma, unsigned long addr,
47 xen_pfn_t *pfn, int nr, int *err_ptr, pgprot_t prot,
48 unsigned int domid, bool no_translate);
50 static inline int xen_remap_pfn(struct vm_area_struct *vma, unsigned long addr,
51 xen_pfn_t *pfn, int nr, int *err_ptr,
52 pgprot_t prot, unsigned int domid,
60 struct vm_area_struct;
62 #ifdef CONFIG_XEN_AUTO_XLATE
63 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
65 xen_pfn_t *gfn, int nr,
66 int *err_ptr, pgprot_t prot,
69 int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
70 int nr, struct page **pages);
73 * These two functions are called from arch/x86/xen/mmu.c and so stubs
74 * are needed for a configuration not specifying CONFIG_XEN_AUTO_XLATE.
76 static inline int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
78 xen_pfn_t *gfn, int nr,
79 int *err_ptr, pgprot_t prot,
86 static inline int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
87 int nr, struct page **pages)
93 int xen_remap_vma_range(struct vm_area_struct *vma, unsigned long addr,
97 * xen_remap_domain_gfn_array() - map an array of foreign frames by gfn
98 * @vma: VMA to map the pages into
99 * @addr: Address at which to map the pages
100 * @gfn: Array of GFNs to map
101 * @nr: Number entries in the GFN array
102 * @err_ptr: Returns per-GFN error status.
103 * @prot: page protection mask
104 * @domid: Domain owning the pages
105 * @pages: Array of pages if this domain has an auto-translated physmap
107 * @gfn and @err_ptr may point to the same buffer, the GFNs will be
108 * overwritten by the error codes after they are mapped.
110 * Returns the number of successfully mapped frames, or a -ve error
113 static inline int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
115 xen_pfn_t *gfn, int nr,
116 int *err_ptr, pgprot_t prot,
120 if (xen_feature(XENFEAT_auto_translated_physmap))
121 return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
124 /* We BUG_ON because it's a programmer error to pass a NULL err_ptr,
125 * and the consequences later is quite hard to detect what the actual
126 * cause of "wrong memory was mapped in".
128 BUG_ON(err_ptr == NULL);
129 return xen_remap_pfn(vma, addr, gfn, nr, err_ptr, prot, domid,
134 * xen_remap_domain_mfn_array() - map an array of foreign frames by mfn
135 * @vma: VMA to map the pages into
136 * @addr: Address at which to map the pages
137 * @mfn: Array of MFNs to map
138 * @nr: Number entries in the MFN array
139 * @err_ptr: Returns per-MFN error status.
140 * @prot: page protection mask
141 * @domid: Domain owning the pages
143 * @mfn and @err_ptr may point to the same buffer, the MFNs will be
144 * overwritten by the error codes after they are mapped.
146 * Returns the number of successfully mapped frames, or a -ve error
149 static inline int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
150 unsigned long addr, xen_pfn_t *mfn,
151 int nr, int *err_ptr,
152 pgprot_t prot, unsigned int domid)
154 if (xen_feature(XENFEAT_auto_translated_physmap))
157 return xen_remap_pfn(vma, addr, mfn, nr, err_ptr, prot, domid,
161 /* xen_remap_domain_gfn_range() - map a range of foreign frames
162 * @vma: VMA to map the pages into
163 * @addr: Address at which to map the pages
164 * @gfn: First GFN to map.
165 * @nr: Number frames to map
166 * @prot: page protection mask
167 * @domid: Domain owning the pages
168 * @pages: Array of pages if this domain has an auto-translated physmap
170 * Returns the number of successfully mapped frames, or a -ve error
173 static inline int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
175 xen_pfn_t gfn, int nr,
176 pgprot_t prot, unsigned int domid,
179 if (xen_feature(XENFEAT_auto_translated_physmap))
182 return xen_remap_pfn(vma, addr, &gfn, nr, NULL, prot, domid, false);
185 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
186 int numpgs, struct page **pages);
188 int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr,
189 unsigned long nr_grant_frames);
191 bool xen_running_on_version_or_later(unsigned int major, unsigned int minor);
193 void xen_efi_runtime_setup(void);
196 #if defined(CONFIG_XEN_PV) && !defined(CONFIG_PREEMPTION)
198 DECLARE_PER_CPU(bool, xen_in_preemptible_hcall);
200 static inline void xen_preemptible_hcall_begin(void)
202 __this_cpu_write(xen_in_preemptible_hcall, true);
205 static inline void xen_preemptible_hcall_end(void)
207 __this_cpu_write(xen_in_preemptible_hcall, false);
212 static inline void xen_preemptible_hcall_begin(void) { }
213 static inline void xen_preemptible_hcall_end(void) { }
215 #endif /* CONFIG_XEN_PV && !CONFIG_PREEMPTION */
217 #endif /* INCLUDE_XEN_OPS_H */