xref: /openbmc/linux/include/xen/xen-ops.h (revision 0b003749)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef INCLUDE_XEN_OPS_H
3 #define INCLUDE_XEN_OPS_H
4 
5 #include <linux/percpu.h>
6 #include <linux/notifier.h>
7 #include <linux/efi.h>
8 #include <xen/features.h>
9 #include <asm/xen/interface.h>
10 #include <xen/interface/vcpu.h>
11 
12 DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
13 
14 DECLARE_PER_CPU(uint32_t, xen_vcpu_id);
15 static inline uint32_t xen_vcpu_nr(int cpu)
16 {
17 	return per_cpu(xen_vcpu_id, cpu);
18 }
19 
20 #define XEN_VCPU_ID_INVALID U32_MAX
21 
22 void xen_arch_pre_suspend(void);
23 void xen_arch_post_suspend(int suspend_cancelled);
24 
25 void xen_timer_resume(void);
26 void xen_arch_resume(void);
27 void xen_arch_suspend(void);
28 
29 void xen_reboot(int reason);
30 
31 void xen_resume_notifier_register(struct notifier_block *nb);
32 void xen_resume_notifier_unregister(struct notifier_block *nb);
33 
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);
40 
41 int xen_setup_shutdown_event(void);
42 
43 extern unsigned long *xen_contiguous_bitmap;
44 
45 #ifdef CONFIG_XEN_PV
46 int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order,
47 				unsigned int address_bits,
48 				dma_addr_t *dma_handle);
49 
50 void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order);
51 
52 int xen_remap_pfn(struct vm_area_struct *vma, unsigned long addr,
53 		  xen_pfn_t *pfn, int nr, int *err_ptr, pgprot_t prot,
54 		  unsigned int domid, bool no_translate, struct page **pages);
55 #else
56 static inline int xen_create_contiguous_region(phys_addr_t pstart,
57 					       unsigned int order,
58 					       unsigned int address_bits,
59 					       dma_addr_t *dma_handle)
60 {
61 	return 0;
62 }
63 
64 static inline void xen_destroy_contiguous_region(phys_addr_t pstart,
65 						 unsigned int order) { }
66 
67 static inline int xen_remap_pfn(struct vm_area_struct *vma, unsigned long addr,
68 				xen_pfn_t *pfn, int nr, int *err_ptr,
69 				pgprot_t prot,  unsigned int domid,
70 				bool no_translate, struct page **pages)
71 {
72 	BUG();
73 	return 0;
74 }
75 #endif
76 
77 struct vm_area_struct;
78 
79 #ifdef CONFIG_XEN_AUTO_XLATE
80 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
81 			      unsigned long addr,
82 			      xen_pfn_t *gfn, int nr,
83 			      int *err_ptr, pgprot_t prot,
84 			      unsigned int domid,
85 			      struct page **pages);
86 int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
87 			      int nr, struct page **pages);
88 #else
89 /*
90  * These two functions are called from arch/x86/xen/mmu.c and so stubs
91  * are needed for a configuration not specifying CONFIG_XEN_AUTO_XLATE.
92  */
93 static inline int xen_xlate_remap_gfn_array(struct vm_area_struct *vma,
94 					    unsigned long addr,
95 					    xen_pfn_t *gfn, int nr,
96 					    int *err_ptr, pgprot_t prot,
97 					    unsigned int domid,
98 					    struct page **pages)
99 {
100 	return -EOPNOTSUPP;
101 }
102 
103 static inline int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
104 					    int nr, struct page **pages)
105 {
106 	return -EOPNOTSUPP;
107 }
108 #endif
109 
110 /*
111  * xen_remap_domain_gfn_array() - map an array of foreign frames by gfn
112  * @vma:     VMA to map the pages into
113  * @addr:    Address at which to map the pages
114  * @gfn:     Array of GFNs to map
115  * @nr:      Number entries in the GFN array
116  * @err_ptr: Returns per-GFN error status.
117  * @prot:    page protection mask
118  * @domid:   Domain owning the pages
119  * @pages:   Array of pages if this domain has an auto-translated physmap
120  *
121  * @gfn and @err_ptr may point to the same buffer, the GFNs will be
122  * overwritten by the error codes after they are mapped.
123  *
124  * Returns the number of successfully mapped frames, or a -ve error
125  * code.
126  */
127 static inline int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
128 					     unsigned long addr,
129 					     xen_pfn_t *gfn, int nr,
130 					     int *err_ptr, pgprot_t prot,
131 					     unsigned int domid,
132 					     struct page **pages)
133 {
134 	if (xen_feature(XENFEAT_auto_translated_physmap))
135 		return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr,
136 						 prot, domid, pages);
137 
138 	/* We BUG_ON because it's a programmer error to pass a NULL err_ptr,
139 	 * and the consequences later is quite hard to detect what the actual
140 	 * cause of "wrong memory was mapped in".
141 	 */
142 	BUG_ON(err_ptr == NULL);
143 	return xen_remap_pfn(vma, addr, gfn, nr, err_ptr, prot, domid,
144 			     false, pages);
145 }
146 
147 /*
148  * xen_remap_domain_mfn_array() - map an array of foreign frames by mfn
149  * @vma:     VMA to map the pages into
150  * @addr:    Address at which to map the pages
151  * @mfn:     Array of MFNs to map
152  * @nr:      Number entries in the MFN array
153  * @err_ptr: Returns per-MFN error status.
154  * @prot:    page protection mask
155  * @domid:   Domain owning the pages
156  * @pages:   Array of pages if this domain has an auto-translated physmap
157  *
158  * @mfn and @err_ptr may point to the same buffer, the MFNs will be
159  * overwritten by the error codes after they are mapped.
160  *
161  * Returns the number of successfully mapped frames, or a -ve error
162  * code.
163  */
164 static inline int xen_remap_domain_mfn_array(struct vm_area_struct *vma,
165 					     unsigned long addr, xen_pfn_t *mfn,
166 					     int nr, int *err_ptr,
167 					     pgprot_t prot, unsigned int domid,
168 					     struct page **pages)
169 {
170 	if (xen_feature(XENFEAT_auto_translated_physmap))
171 		return -EOPNOTSUPP;
172 
173 	return xen_remap_pfn(vma, addr, mfn, nr, err_ptr, prot, domid,
174 			     true, pages);
175 }
176 
177 /* xen_remap_domain_gfn_range() - map a range of foreign frames
178  * @vma:     VMA to map the pages into
179  * @addr:    Address at which to map the pages
180  * @gfn:     First GFN to map.
181  * @nr:      Number frames to map
182  * @prot:    page protection mask
183  * @domid:   Domain owning the pages
184  * @pages:   Array of pages if this domain has an auto-translated physmap
185  *
186  * Returns the number of successfully mapped frames, or a -ve error
187  * code.
188  */
189 static inline int xen_remap_domain_gfn_range(struct vm_area_struct *vma,
190 					     unsigned long addr,
191 					     xen_pfn_t gfn, int nr,
192 					     pgprot_t prot, unsigned int domid,
193 					     struct page **pages)
194 {
195 	if (xen_feature(XENFEAT_auto_translated_physmap))
196 		return -EOPNOTSUPP;
197 
198 	return xen_remap_pfn(vma, addr, &gfn, nr, NULL, prot, domid, false,
199 			     pages);
200 }
201 
202 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
203 			       int numpgs, struct page **pages);
204 
205 int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr,
206 				  unsigned long nr_grant_frames);
207 
208 bool xen_running_on_version_or_later(unsigned int major, unsigned int minor);
209 
210 efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc);
211 efi_status_t xen_efi_set_time(efi_time_t *tm);
212 efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
213 				     efi_time_t *tm);
214 efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm);
215 efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
216 				  u32 *attr, unsigned long *data_size,
217 				  void *data);
218 efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
219 				       efi_char16_t *name, efi_guid_t *vendor);
220 efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
221 				  u32 attr, unsigned long data_size,
222 				  void *data);
223 efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
224 					 u64 *remaining_space,
225 					 u64 *max_variable_size);
226 efi_status_t xen_efi_get_next_high_mono_count(u32 *count);
227 efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
228 				    unsigned long count, unsigned long sg_list);
229 efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
230 					unsigned long count, u64 *max_size,
231 					int *reset_type);
232 void xen_efi_reset_system(int reset_type, efi_status_t status,
233 			  unsigned long data_size, efi_char16_t *data);
234 
235 
236 #ifdef CONFIG_PREEMPT
237 
238 static inline void xen_preemptible_hcall_begin(void)
239 {
240 }
241 
242 static inline void xen_preemptible_hcall_end(void)
243 {
244 }
245 
246 #else
247 
248 DECLARE_PER_CPU(bool, xen_in_preemptible_hcall);
249 
250 static inline void xen_preemptible_hcall_begin(void)
251 {
252 	__this_cpu_write(xen_in_preemptible_hcall, true);
253 }
254 
255 static inline void xen_preemptible_hcall_end(void)
256 {
257 	__this_cpu_write(xen_in_preemptible_hcall, false);
258 }
259 
260 #endif /* CONFIG_PREEMPT */
261 
262 #endif /* INCLUDE_XEN_OPS_H */
263