page.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef _ASM_ARM_XEN_PAGE_H
  2. #define _ASM_ARM_XEN_PAGE_H
  3. #include <asm/page.h>
  4. #include <asm/pgtable.h>
  5. #include <linux/pfn.h>
  6. #include <linux/types.h>
  7. #include <linux/dma-mapping.h>
  8. #include <xen/xen.h>
  9. #include <xen/interface/grant_table.h>
  10. #define phys_to_machine_mapping_valid(pfn) (1)
  11. #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
  12. #define pte_mfn pte_pfn
  13. #define mfn_pte pfn_pte
  14. /* Xen machine address */
  15. typedef struct xmaddr {
  16. phys_addr_t maddr;
  17. } xmaddr_t;
  18. /* Xen pseudo-physical address */
  19. typedef struct xpaddr {
  20. phys_addr_t paddr;
  21. } xpaddr_t;
  22. #define XMADDR(x) ((xmaddr_t) { .maddr = (x) })
  23. #define XPADDR(x) ((xpaddr_t) { .paddr = (x) })
  24. #define INVALID_P2M_ENTRY (~0UL)
  25. unsigned long __pfn_to_mfn(unsigned long pfn);
  26. unsigned long __mfn_to_pfn(unsigned long mfn);
  27. extern struct rb_root phys_to_mach;
  28. static inline unsigned long pfn_to_mfn(unsigned long pfn)
  29. {
  30. unsigned long mfn;
  31. if (phys_to_mach.rb_node != NULL) {
  32. mfn = __pfn_to_mfn(pfn);
  33. if (mfn != INVALID_P2M_ENTRY)
  34. return mfn;
  35. }
  36. return pfn;
  37. }
  38. static inline unsigned long mfn_to_pfn(unsigned long mfn)
  39. {
  40. unsigned long pfn;
  41. if (phys_to_mach.rb_node != NULL) {
  42. pfn = __mfn_to_pfn(mfn);
  43. if (pfn != INVALID_P2M_ENTRY)
  44. return pfn;
  45. }
  46. return mfn;
  47. }
  48. #define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
  49. static inline xmaddr_t phys_to_machine(xpaddr_t phys)
  50. {
  51. unsigned offset = phys.paddr & ~PAGE_MASK;
  52. return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
  53. }
  54. static inline xpaddr_t machine_to_phys(xmaddr_t machine)
  55. {
  56. unsigned offset = machine.maddr & ~PAGE_MASK;
  57. return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
  58. }
  59. /* VIRT <-> MACHINE conversion */
  60. #define virt_to_machine(v) (phys_to_machine(XPADDR(__pa(v))))
  61. #define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
  62. #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
  63. static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
  64. {
  65. /* TODO: assuming it is mapped in the kernel 1:1 */
  66. return virt_to_machine(vaddr);
  67. }
  68. /* TODO: this shouldn't be here but it is because the frontend drivers
  69. * are using it (its rolled in headers) even though we won't hit the code path.
  70. * So for right now just punt with this.
  71. */
  72. static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
  73. {
  74. BUG();
  75. return NULL;
  76. }
  77. extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
  78. struct gnttab_map_grant_ref *kmap_ops,
  79. struct page **pages, unsigned int count);
  80. extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
  81. struct gnttab_map_grant_ref *kmap_ops,
  82. struct page **pages, unsigned int count);
  83. bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
  84. bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
  85. unsigned long nr_pages);
  86. static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
  87. {
  88. return __set_phys_to_machine(pfn, mfn);
  89. }
  90. #define xen_remap(cookie, size) ioremap_cache((cookie), (size))
  91. #define xen_unmap(cookie) iounmap((cookie))
  92. #endif /* _ASM_ARM_XEN_PAGE_H */