blob: d1b5dd56647227305de7f1f9c6c3875b812a6693 [file] [log] [blame]
Stefano Stabellini36a67ab2012-08-08 16:33:46 +00001#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
Stefano Stabellini4a191382013-10-17 16:22:27 +000010#include <xen/xen.h>
Stefano Stabellini36a67ab2012-08-08 16:33:46 +000011#include <xen/interface/grant_table.h>
12
Ian Campbellee7b5952012-10-17 09:39:17 +010013#define phys_to_machine_mapping_valid(pfn) (1)
Stefano Stabellini36a67ab2012-08-08 16:33:46 +000014#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
15
16#define pte_mfn pte_pfn
17#define mfn_pte pfn_pte
18
19/* Xen machine address */
20typedef struct xmaddr {
21 phys_addr_t maddr;
22} xmaddr_t;
23
24/* Xen pseudo-physical address */
25typedef 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
Ian Campbellee7b5952012-10-17 09:39:17 +010032#define INVALID_P2M_ENTRY (~0UL)
33
Stefano Stabellini4a191382013-10-17 16:22:27 +000034unsigned long __pfn_to_mfn(unsigned long pfn);
35unsigned long __mfn_to_pfn(unsigned long mfn);
36extern struct rb_root phys_to_mach;
37
38static inline unsigned long pfn_to_mfn(unsigned long pfn)
39{
40 unsigned long mfn;
41
42 if (phys_to_mach.rb_node != NULL) {
43 mfn = __pfn_to_mfn(pfn);
44 if (mfn != INVALID_P2M_ENTRY)
45 return mfn;
46 }
47
48 if (xen_initial_domain())
49 return pfn;
50 else
51 return INVALID_P2M_ENTRY;
52}
53
54static inline unsigned long mfn_to_pfn(unsigned long mfn)
55{
56 unsigned long pfn;
57
58 if (phys_to_mach.rb_node != NULL) {
59 pfn = __mfn_to_pfn(mfn);
60 if (pfn != INVALID_P2M_ENTRY)
61 return pfn;
62 }
63
64 if (xen_initial_domain())
65 return mfn;
66 else
67 return INVALID_P2M_ENTRY;
68}
69
70#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
71
Stefano Stabellini36a67ab2012-08-08 16:33:46 +000072static inline xmaddr_t phys_to_machine(xpaddr_t phys)
73{
74 unsigned offset = phys.paddr & ~PAGE_MASK;
75 return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
76}
77
78static inline xpaddr_t machine_to_phys(xmaddr_t machine)
79{
80 unsigned offset = machine.maddr & ~PAGE_MASK;
81 return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
82}
83/* VIRT <-> MACHINE conversion */
84#define virt_to_machine(v) (phys_to_machine(XPADDR(__pa(v))))
85#define virt_to_pfn(v) (PFN_DOWN(__pa(v)))
86#define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
87#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
88
89static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
90{
91 /* TODO: assuming it is mapped in the kernel 1:1 */
92 return virt_to_machine(vaddr);
93}
94
95/* TODO: this shouldn't be here but it is because the frontend drivers
96 * are using it (its rolled in headers) even though we won't hit the code path.
97 * So for right now just punt with this.
98 */
99static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
100{
101 BUG();
102 return NULL;
103}
104
105static inline int m2p_add_override(unsigned long mfn, struct page *page,
106 struct gnttab_map_grant_ref *kmap_op)
107{
108 return 0;
109}
110
111static inline int m2p_remove_override(struct page *page, bool clear_pte)
112{
113 return 0;
114}
115
Stefano Stabellini4a191382013-10-17 16:22:27 +0000116bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
117bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
118 unsigned long nr_pages);
Ian Campbellee7b5952012-10-17 09:39:17 +0100119
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000120static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
121{
Ian Campbellee7b5952012-10-17 09:39:17 +0100122 return __set_phys_to_machine(pfn, mfn);
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000123}
Stefano Stabellini3216dce2013-02-19 13:59:19 +0000124
Stefano Stabellinif0a8d592013-06-04 16:32:15 +0000125#define xen_remap(cookie, size) ioremap_cached((cookie), (size));
Stefano Stabellini3216dce2013-02-19 13:59:19 +0000126
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000127#endif /* _ASM_ARM_XEN_PAGE_H */