blob: cf4f3e867395ef0261b16a4d721d8cff740c1de2 [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>
Stefano Stabellini83862cc2013-10-10 13:40:44 +00009#include <linux/dma-mapping.h>
Stefano Stabellini36a67ab2012-08-08 16:33:46 +000010
Stefano Stabellini4a191382013-10-17 16:22:27 +000011#include <xen/xen.h>
Stefano Stabellini36a67ab2012-08-08 16:33:46 +000012#include <xen/interface/grant_table.h>
13
Ian Campbellee7b5952012-10-17 09:39:17 +010014#define phys_to_machine_mapping_valid(pfn) (1)
Stefano Stabellini36a67ab2012-08-08 16:33:46 +000015#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
16
17#define pte_mfn pte_pfn
18#define mfn_pte pfn_pte
19
20/* Xen machine address */
21typedef struct xmaddr {
22 phys_addr_t maddr;
23} xmaddr_t;
24
25/* Xen pseudo-physical address */
26typedef struct xpaddr {
27 phys_addr_t paddr;
28} xpaddr_t;
29
30#define XMADDR(x) ((xmaddr_t) { .maddr = (x) })
31#define XPADDR(x) ((xpaddr_t) { .paddr = (x) })
32
Ian Campbellee7b5952012-10-17 09:39:17 +010033#define INVALID_P2M_ENTRY (~0UL)
34
Stefano Stabellini4a191382013-10-17 16:22:27 +000035unsigned long __pfn_to_mfn(unsigned long pfn);
36unsigned long __mfn_to_pfn(unsigned long mfn);
37extern struct rb_root phys_to_mach;
38
39static inline unsigned long pfn_to_mfn(unsigned long pfn)
40{
41 unsigned long mfn;
Konrad Rzeszutek Wilke1d8f622013-11-08 15:36:09 -050042
Stefano Stabellini4a191382013-10-17 16:22:27 +000043 if (phys_to_mach.rb_node != NULL) {
44 mfn = __pfn_to_mfn(pfn);
45 if (mfn != INVALID_P2M_ENTRY)
46 return mfn;
47 }
48
Stefano Stabellini18c51e12013-11-11 12:50:30 +000049 return pfn;
Stefano Stabellini4a191382013-10-17 16:22:27 +000050}
51
52static inline unsigned long mfn_to_pfn(unsigned long mfn)
53{
54 unsigned long pfn;
55
56 if (phys_to_mach.rb_node != NULL) {
57 pfn = __mfn_to_pfn(mfn);
58 if (pfn != INVALID_P2M_ENTRY)
59 return pfn;
60 }
61
Stefano Stabellini18c51e12013-11-11 12:50:30 +000062 return mfn;
Stefano Stabellini4a191382013-10-17 16:22:27 +000063}
64
65#define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
66
Stefano Stabellini36a67ab2012-08-08 16:33:46 +000067static inline xmaddr_t phys_to_machine(xpaddr_t phys)
68{
69 unsigned offset = phys.paddr & ~PAGE_MASK;
70 return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
71}
72
73static inline xpaddr_t machine_to_phys(xmaddr_t machine)
74{
75 unsigned offset = machine.maddr & ~PAGE_MASK;
76 return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
77}
78/* VIRT <-> MACHINE conversion */
79#define virt_to_machine(v) (phys_to_machine(XPADDR(__pa(v))))
80#define virt_to_pfn(v) (PFN_DOWN(__pa(v)))
81#define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
82#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
83
84static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
85{
86 /* TODO: assuming it is mapped in the kernel 1:1 */
87 return virt_to_machine(vaddr);
88}
89
90/* TODO: this shouldn't be here but it is because the frontend drivers
91 * are using it (its rolled in headers) even though we won't hit the code path.
92 * So for right now just punt with this.
93 */
94static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
95{
96 BUG();
97 return NULL;
98}
99
Zoltan Kiss1429d462014-02-27 15:55:30 +0000100extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
101 struct gnttab_map_grant_ref *kmap_ops,
102 struct page **pages, unsigned int count);
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000103
Zoltan Kiss1429d462014-02-27 15:55:30 +0000104extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
105 struct gnttab_map_grant_ref *kmap_ops,
106 struct page **pages, unsigned int count);
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000107
Stefano Stabellini4a191382013-10-17 16:22:27 +0000108bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
109bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
110 unsigned long nr_pages);
Ian Campbellee7b5952012-10-17 09:39:17 +0100111
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000112static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
113{
Ian Campbellee7b5952012-10-17 09:39:17 +0100114 return __set_phys_to_machine(pfn, mfn);
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000115}
Stefano Stabellini3216dce2013-02-19 13:59:19 +0000116
Linus Torvalds84621c92014-01-22 22:00:18 -0800117#define xen_remap(cookie, size) ioremap_cache((cookie), (size))
Konrad Rzeszutek Wilkefaf30a2014-01-06 10:40:36 -0500118#define xen_unmap(cookie) iounmap((cookie))
Stefano Stabellini3216dce2013-02-19 13:59:19 +0000119
Stefano Stabellini36a67ab2012-08-08 16:33:46 +0000120#endif /* _ASM_ARM_XEN_PAGE_H */