page.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <asm/pgtable.h>
  6. #include <linux/pfn.h>
  7. #include <linux/types.h>
  8. #include <linux/dma-mapping.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) (pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT))
  62. #define gfn_to_virt(m) (__va(gfn_to_pfn(m) << XEN_PAGE_SHIFT))
  63. /* Only used in PV code. But ARM guests are always HVM. */
  64. static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
  65. {
  66. BUG();
  67. }
  68. extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
  69. struct gnttab_map_grant_ref *kmap_ops,
  70. struct page **pages, unsigned int count);
  71. extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
  72. struct gnttab_unmap_grant_ref *kunmap_ops,
  73. struct page **pages, unsigned int count);
  74. bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
  75. bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
  76. unsigned long nr_pages);
  77. static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
  78. {
  79. return __set_phys_to_machine(pfn, mfn);
  80. }
  81. #define xen_remap(cookie, size) ioremap_cache((cookie), (size))
  82. #define xen_unmap(cookie) iounmap((cookie))
  83. bool xen_arch_need_swiotlb(struct device *dev,
  84. phys_addr_t phys,
  85. dma_addr_t dev_addr);
  86. unsigned long xen_get_swiotlb_free_pages(unsigned int order);
  87. #endif /* _ASM_ARM_XEN_PAGE_H */