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