xen-ops.h 6.4 KB

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