5f76a9e7ef1b7aca462c46b4451a2ab78ba06c50
[firefly-linux-kernel-4.4.55.git] / arch / arm / include / asm / xen / page.h
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 #define pte_mfn     pte_pfn
17 #define mfn_pte     pfn_pte
18
19 /* Xen machine address */
20 typedef struct xmaddr {
21         phys_addr_t maddr;
22 } xmaddr_t;
23
24 /* Xen pseudo-physical address */
25 typedef struct xpaddr {
26         phys_addr_t paddr;
27 } xpaddr_t;
28
29 #define XMADDR(x)       ((xmaddr_t) { .maddr = (x) })
30 #define XPADDR(x)       ((xpaddr_t) { .paddr = (x) })
31
32 #define INVALID_P2M_ENTRY      (~0UL)
33
34 unsigned long __pfn_to_mfn(unsigned long pfn);
35 extern struct rb_root phys_to_mach;
36
37 static inline unsigned long pfn_to_mfn(unsigned long pfn)
38 {
39         unsigned long mfn;
40
41         if (phys_to_mach.rb_node != NULL) {
42                 mfn = __pfn_to_mfn(pfn);
43                 if (mfn != INVALID_P2M_ENTRY)
44                         return mfn;
45         }
46
47         return pfn;
48 }
49
50 static inline unsigned long mfn_to_pfn(unsigned long mfn)
51 {
52         return mfn;
53 }
54
55 /* Pseudo-physical <-> BUS conversion */
56 static inline unsigned long pfn_to_bfn(unsigned long pfn)
57 {
58         unsigned long mfn;
59
60         if (phys_to_mach.rb_node != NULL) {
61                 mfn = __pfn_to_mfn(pfn);
62                 if (mfn != INVALID_P2M_ENTRY)
63                         return mfn;
64         }
65
66         return pfn;
67 }
68
69 static inline unsigned long bfn_to_pfn(unsigned long bfn)
70 {
71         return bfn;
72 }
73
74 #define bfn_to_local_pfn(bfn)   bfn_to_pfn(bfn)
75
76 /* VIRT <-> MACHINE conversion */
77 #define virt_to_mfn(v)          (pfn_to_mfn(virt_to_pfn(v)))
78 #define mfn_to_virt(m)          (__va(mfn_to_pfn(m) << PAGE_SHIFT))
79
80 /* Only used in PV code. But ARM guests are always HVM. */
81 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
82 {
83         BUG();
84 }
85
86 /* TODO: this shouldn't be here but it is because the frontend drivers
87  * are using it (its rolled in headers) even though we won't hit the code path.
88  * So for right now just punt with this.
89  */
90 static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
91 {
92         BUG();
93         return NULL;
94 }
95
96 extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
97                                    struct gnttab_map_grant_ref *kmap_ops,
98                                    struct page **pages, unsigned int count);
99
100 extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
101                                      struct gnttab_unmap_grant_ref *kunmap_ops,
102                                      struct page **pages, unsigned int count);
103
104 bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
105 bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
106                 unsigned long nr_pages);
107
108 static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
109 {
110         return __set_phys_to_machine(pfn, mfn);
111 }
112
113 #define xen_remap(cookie, size) ioremap_cache((cookie), (size))
114 #define xen_unmap(cookie) iounmap((cookie))
115
116 bool xen_arch_need_swiotlb(struct device *dev,
117                            unsigned long pfn,
118                            unsigned long bfn);
119 unsigned long xen_get_swiotlb_free_pages(unsigned int order);
120
121 #endif /* _ASM_ARM_XEN_PAGE_H */