page.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_pfn(v) (PFN_DOWN(__pa(v)))
  62. #define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
  63. #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
  64. static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
  65. {
  66. /* TODO: assuming it is mapped in the kernel 1:1 */
  67. return virt_to_machine(vaddr);
  68. }
  69. /* TODO: this shouldn't be here but it is because the frontend drivers
  70. * are using it (its rolled in headers) even though we won't hit the code path.
  71. * So for right now just punt with this.
  72. */
  73. static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
  74. {
  75. BUG();
  76. return NULL;
  77. }
  78. static inline int m2p_add_override(unsigned long mfn, struct page *page,
  79. struct gnttab_map_grant_ref *kmap_op)
  80. {
  81. return 0;
  82. }
  83. static inline int m2p_remove_override(struct page *page, bool clear_pte)
  84. {
  85. return 0;
  86. }
  87. bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
  88. bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
  89. unsigned long nr_pages);
  90. static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
  91. {
  92. return __set_phys_to_machine(pfn, mfn);
  93. }
  94. #define xen_remap(cookie, size) ioremap_cached((cookie), (size));
  95. #endif /* _ASM_ARM_XEN_PAGE_H */