Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +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> |
Stefano Stabellini | 83862cc | 2013-10-10 13:40:44 +0000 | [diff] [blame] | 9 | #include <linux/dma-mapping.h> |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 10 | |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 11 | #include <xen/xen.h> |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 12 | #include <xen/interface/grant_table.h> |
| 13 | |
Ian Campbell | ee7b595 | 2012-10-17 09:39:17 +0100 | [diff] [blame] | 14 | #define phys_to_machine_mapping_valid(pfn) (1) |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 15 | |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 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 | |
Ian Campbell | ee7b595 | 2012-10-17 09:39:17 +0100 | [diff] [blame] | 29 | #define INVALID_P2M_ENTRY (~0UL) |
| 30 | |
Julien Grall | 250c9af | 2015-05-05 16:36:56 +0100 | [diff] [blame] | 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 | |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 42 | unsigned long __pfn_to_mfn(unsigned long pfn); |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 43 | extern struct rb_root phys_to_mach; |
| 44 | |
Julien Grall | 0df4f26 | 2015-08-07 17:34:37 +0100 | [diff] [blame] | 45 | /* Pseudo-physical <-> Guest conversion */ |
| 46 | static inline unsigned long pfn_to_gfn(unsigned long pfn) |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 47 | { |
Stefano Stabellini | 18c51e1 | 2013-11-11 12:50:30 +0000 | [diff] [blame] | 48 | return pfn; |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Julien Grall | 0df4f26 | 2015-08-07 17:34:37 +0100 | [diff] [blame] | 51 | static inline unsigned long gfn_to_pfn(unsigned long gfn) |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 52 | { |
Julien Grall | 0df4f26 | 2015-08-07 17:34:37 +0100 | [diff] [blame] | 53 | return gfn; |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Julien Grall | 32e0987 | 2015-08-07 17:34:35 +0100 | [diff] [blame] | 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) |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 76 | |
Julien Grall | 0df4f26 | 2015-08-07 17:34:37 +0100 | [diff] [blame] | 77 | /* VIRT <-> GUEST conversion */ |
Julien Grall | 250c9af | 2015-05-05 16:36:56 +0100 | [diff] [blame] | 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)) |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 80 | |
Julien Grall | 724afae | 2015-08-07 17:34:34 +0100 | [diff] [blame] | 81 | /* Only used in PV code. But ARM guests are always HVM. */ |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 82 | static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr) |
| 83 | { |
Julien Grall | 724afae | 2015-08-07 17:34:34 +0100 | [diff] [blame] | 84 | BUG(); |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* TODO: this shouldn't be here but it is because the frontend drivers |
| 88 | * are using it (its rolled in headers) even though we won't hit the code path. |
| 89 | * So for right now just punt with this. |
| 90 | */ |
| 91 | static inline pte_t *lookup_address(unsigned long address, unsigned int *level) |
| 92 | { |
| 93 | BUG(); |
| 94 | return NULL; |
| 95 | } |
| 96 | |
Zoltan Kiss | 1429d46 | 2014-02-27 15:55:30 +0000 | [diff] [blame] | 97 | extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops, |
| 98 | struct gnttab_map_grant_ref *kmap_ops, |
| 99 | struct page **pages, unsigned int count); |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 100 | |
Zoltan Kiss | 1429d46 | 2014-02-27 15:55:30 +0000 | [diff] [blame] | 101 | extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops, |
David Vrabel | 853d028 | 2015-01-05 14:13:41 +0000 | [diff] [blame] | 102 | struct gnttab_unmap_grant_ref *kunmap_ops, |
Zoltan Kiss | 1429d46 | 2014-02-27 15:55:30 +0000 | [diff] [blame] | 103 | struct page **pages, unsigned int count); |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 104 | |
Stefano Stabellini | 4a19138 | 2013-10-17 16:22:27 +0000 | [diff] [blame] | 105 | bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn); |
| 106 | bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn, |
| 107 | unsigned long nr_pages); |
Ian Campbell | ee7b595 | 2012-10-17 09:39:17 +0100 | [diff] [blame] | 108 | |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 109 | static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn) |
| 110 | { |
Ian Campbell | ee7b595 | 2012-10-17 09:39:17 +0100 | [diff] [blame] | 111 | return __set_phys_to_machine(pfn, mfn); |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 112 | } |
Stefano Stabellini | 3216dce | 2013-02-19 13:59:19 +0000 | [diff] [blame] | 113 | |
Linus Torvalds | 84621c9 | 2014-01-22 22:00:18 -0800 | [diff] [blame] | 114 | #define xen_remap(cookie, size) ioremap_cache((cookie), (size)) |
Konrad Rzeszutek Wilk | efaf30a | 2014-01-06 10:40:36 -0500 | [diff] [blame] | 115 | #define xen_unmap(cookie) iounmap((cookie)) |
Stefano Stabellini | 3216dce | 2013-02-19 13:59:19 +0000 | [diff] [blame] | 116 | |
Stefano Stabellini | a4dba13 | 2014-11-21 11:07:39 +0000 | [diff] [blame] | 117 | bool xen_arch_need_swiotlb(struct device *dev, |
Julien Grall | 291be10 | 2015-09-09 15:17:33 +0100 | [diff] [blame^] | 118 | phys_addr_t phys, |
| 119 | dma_addr_t dev_addr); |
Stefano Stabellini | 8746515 | 2015-04-24 10:16:40 +0100 | [diff] [blame] | 120 | unsigned long xen_get_swiotlb_free_pages(unsigned int order); |
Stefano Stabellini | a4dba13 | 2014-11-21 11:07:39 +0000 | [diff] [blame] | 121 | |
Stefano Stabellini | 36a67ab | 2012-08-08 16:33:46 +0000 | [diff] [blame] | 122 | #endif /* _ASM_ARM_XEN_PAGE_H */ |