xen-ops.h 7.0 KB

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