page.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_ARM_XEN_PAGE_H
  3. #define _ASM_ARM_XEN_PAGE_H
  4. #include <asm/page.h>
  5. #include <linux/pfn.h>
  6. #include <linux/types.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/pgtable.h>
  9. #include <xen/xen.h>
  10. #include <xen/interface/grant_table.h>
  11. #define phys_to_machine_mapping_valid(pfn) (1)
  12. /* Xen machine address */
  13. typedef struct xmaddr {
  14. phys_addr_t maddr;
  15. } xmaddr_t;
  16. /* Xen pseudo-physical address */
  17. typedef struct xpaddr {
  18. phys_addr_t paddr;
  19. } xpaddr_t;
  20. #define XMADDR(x) ((xmaddr_t) { .maddr = (x) })
  21. #define XPADDR(x) ((xpaddr_t) { .paddr = (x) })
  22. #define INVALID_P2M_ENTRY (~0UL)
  23. /*
  24. * The pseudo-physical frame (pfn) used in all the helpers is always based
  25. * on Xen page granularity (i.e 4KB).
  26. *
  27. * A Linux page may be split across multiple non-contiguous Xen page so we
  28. * have to keep track with frame based on 4KB page granularity.
  29. *
  30. * PV drivers should never make a direct usage of those helpers (particularly
  31. * pfn_to_gfn and gfn_to_pfn).
  32. */
  33. unsigned long __pfn_to_mfn(unsigned long pfn);
  34. extern struct rb_root phys_to_mach;
  35. /* Pseudo-physical <-> Guest conversion */
  36. static inline unsigned long pfn_to_gfn(unsigned long pfn)
  37. {
  38. return pfn;
  39. }
  40. static inline unsigned long gfn_to_pfn(unsigned long gfn)
  41. {
  42. return gfn;
  43. }
  44. /* Pseudo-physical <-> BUS conversion */
  45. static inline unsigned long pfn_to_bfn(unsigned long pfn)
  46. {
  47. unsigned long mfn;
  48. if (phys_to_mach.rb_node != NULL) {
  49. mfn = __pfn_to_mfn(pfn);
  50. if (mfn != INVALID_P2M_ENTRY)
  51. return mfn;
  52. }
  53. return pfn;
  54. }
  55. static inline unsigned long bfn_to_pfn(unsigned long bfn)
  56. {
  57. return bfn;
  58. }
  59. #define bfn_to_local_pfn(bfn) bfn_to_pfn(bfn)
  60. /* VIRT <-> GUEST conversion */
  61. #define virt_to_gfn(v) \
  62. ({ \
  63. WARN_ON_ONCE(!virt_addr_valid(v)); \
  64. pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT); \
  65. })
  66. #define gfn_to_virt(m) (__va(gfn_to_pfn(m) << XEN_PAGE_SHIFT))
  67. #define percpu_to_gfn(v) \
  68. (pfn_to_gfn(per_cpu_ptr_to_phys(v) >> XEN_PAGE_SHIFT))
  69. /* Only used in PV code. But ARM guests are always HVM. */
  70. static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
  71. {
  72. BUG();
  73. }
  74. extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
  75. struct gnttab_map_grant_ref *kmap_ops,
  76. struct page **pages, unsigned int count);
  77. extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
  78. struct gnttab_unmap_grant_ref *kunmap_ops,
  79. struct page **pages, unsigned int count);
  80. bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
  81. bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
  82. unsigned long nr_pages);
  83. static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
  84. {
  85. return __set_phys_to_machine(pfn, mfn);
  86. }
  87. bool xen_arch_need_swiotlb(struct device *dev,
  88. phys_addr_t phys,
  89. dma_addr_t dev_addr);
  90. #endif /* _ASM_ARM_XEN_PAGE_H */