page.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. if (xen_initial_domain())
  37. return pfn;
  38. else
  39. return INVALID_P2M_ENTRY;
  40. }
  41. static inline unsigned long mfn_to_pfn(unsigned long mfn)
  42. {
  43. unsigned long pfn;
  44. if (phys_to_mach.rb_node != NULL) {
  45. pfn = __mfn_to_pfn(mfn);
  46. if (pfn != INVALID_P2M_ENTRY)
  47. return pfn;
  48. }
  49. if (xen_initial_domain())
  50. return mfn;
  51. else
  52. return INVALID_P2M_ENTRY;
  53. }
  54. #define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
  55. static inline xmaddr_t phys_to_machine(xpaddr_t phys)
  56. {
  57. unsigned offset = phys.paddr & ~PAGE_MASK;
  58. return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
  59. }
  60. static inline xpaddr_t machine_to_phys(xmaddr_t machine)
  61. {
  62. unsigned offset = machine.maddr & ~PAGE_MASK;
  63. return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
  64. }
  65. /* VIRT <-> MACHINE conversion */
  66. #define virt_to_machine(v) (phys_to_machine(XPADDR(__pa(v))))
  67. #define virt_to_pfn(v) (PFN_DOWN(__pa(v)))
  68. #define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
  69. #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
  70. static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
  71. {
  72. /* TODO: assuming it is mapped in the kernel 1:1 */
  73. return virt_to_machine(vaddr);
  74. }
  75. /* TODO: this shouldn't be here but it is because the frontend drivers
  76. * are using it (its rolled in headers) even though we won't hit the code path.
  77. * So for right now just punt with this.
  78. */
  79. static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
  80. {
  81. BUG();
  82. return NULL;
  83. }
  84. static inline int m2p_add_override(unsigned long mfn, struct page *page,
  85. struct gnttab_map_grant_ref *kmap_op)
  86. {
  87. return 0;
  88. }
  89. static inline int m2p_remove_override(struct page *page, bool clear_pte)
  90. {
  91. return 0;
  92. }
  93. bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
  94. bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
  95. unsigned long nr_pages);
  96. static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
  97. {
  98. return __set_phys_to_machine(pfn, mfn);
  99. }
  100. #define xen_remap(cookie, size) ioremap_cached((cookie), (size));
  101. #endif /* _ASM_ARM_XEN_PAGE_H */