Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_ARM_XEN_PAGE_H
0003 #define _ASM_ARM_XEN_PAGE_H
0004 
0005 #include <asm/page.h>
0006 
0007 #include <linux/pfn.h>
0008 #include <linux/types.h>
0009 #include <linux/dma-mapping.h>
0010 #include <linux/pgtable.h>
0011 
0012 #include <xen/xen.h>
0013 #include <xen/interface/grant_table.h>
0014 
0015 #define phys_to_machine_mapping_valid(pfn) (1)
0016 
0017 /* Xen machine address */
0018 typedef struct xmaddr {
0019     phys_addr_t maddr;
0020 } xmaddr_t;
0021 
0022 /* Xen pseudo-physical address */
0023 typedef struct xpaddr {
0024     phys_addr_t paddr;
0025 } xpaddr_t;
0026 
0027 #define XMADDR(x)   ((xmaddr_t) { .maddr = (x) })
0028 #define XPADDR(x)   ((xpaddr_t) { .paddr = (x) })
0029 
0030 #define INVALID_P2M_ENTRY      (~0UL)
0031 
0032 /*
0033  * The pseudo-physical frame (pfn) used in all the helpers is always based
0034  * on Xen page granularity (i.e 4KB).
0035  *
0036  * A Linux page may be split across multiple non-contiguous Xen page so we
0037  * have to keep track with frame based on 4KB page granularity.
0038  *
0039  * PV drivers should never make a direct usage of those helpers (particularly
0040  * pfn_to_gfn and gfn_to_pfn).
0041  */
0042 
0043 unsigned long __pfn_to_mfn(unsigned long pfn);
0044 extern struct rb_root phys_to_mach;
0045 
0046 /* Pseudo-physical <-> Guest conversion */
0047 static inline unsigned long pfn_to_gfn(unsigned long pfn)
0048 {
0049     return pfn;
0050 }
0051 
0052 static inline unsigned long gfn_to_pfn(unsigned long gfn)
0053 {
0054     return gfn;
0055 }
0056 
0057 /* Pseudo-physical <-> BUS conversion */
0058 static inline unsigned long pfn_to_bfn(unsigned long pfn)
0059 {
0060     unsigned long mfn;
0061 
0062     if (phys_to_mach.rb_node != NULL) {
0063         mfn = __pfn_to_mfn(pfn);
0064         if (mfn != INVALID_P2M_ENTRY)
0065             return mfn;
0066     }
0067 
0068     return pfn;
0069 }
0070 
0071 static inline unsigned long bfn_to_pfn(unsigned long bfn)
0072 {
0073     return bfn;
0074 }
0075 
0076 #define bfn_to_local_pfn(bfn)   bfn_to_pfn(bfn)
0077 
0078 /* VIRT <-> GUEST conversion */
0079 #define virt_to_gfn(v)                                                         \
0080     ({                                                                     \
0081         WARN_ON_ONCE(!virt_addr_valid(v));                              \
0082         pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT);                 \
0083     })
0084 #define gfn_to_virt(m)      (__va(gfn_to_pfn(m) << XEN_PAGE_SHIFT))
0085 
0086 #define percpu_to_gfn(v)    \
0087     (pfn_to_gfn(per_cpu_ptr_to_phys(v) >> XEN_PAGE_SHIFT))
0088 
0089 /* Only used in PV code. But ARM guests are always HVM. */
0090 static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
0091 {
0092     BUG();
0093 }
0094 
0095 extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
0096                    struct gnttab_map_grant_ref *kmap_ops,
0097                    struct page **pages, unsigned int count);
0098 
0099 extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
0100                      struct gnttab_unmap_grant_ref *kunmap_ops,
0101                      struct page **pages, unsigned int count);
0102 
0103 bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
0104 bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
0105         unsigned long nr_pages);
0106 
0107 static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
0108 {
0109     return __set_phys_to_machine(pfn, mfn);
0110 }
0111 
0112 bool xen_arch_need_swiotlb(struct device *dev,
0113                phys_addr_t phys,
0114                dma_addr_t dev_addr);
0115 
0116 #endif /* _ASM_ARM_XEN_PAGE_H */