xen-ops.h 8.1 KB

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