page.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. extern struct rb_root phys_to_mach;
  27. static inline unsigned long pfn_to_mfn(unsigned long pfn)
  28. {
  29. unsigned long mfn;
  30. if (phys_to_mach.rb_node != NULL) {
  31. mfn = __pfn_to_mfn(pfn);
  32. if (mfn != INVALID_P2M_ENTRY)
  33. return mfn;
  34. }
  35. return pfn;
  36. }
  37. static inline unsigned long mfn_to_pfn(unsigned long mfn)
  38. {
  39. return mfn;
  40. }
  41. #define mfn_to_local_pfn(mfn) mfn_to_pfn(mfn)
  42. static inline xmaddr_t phys_to_machine(xpaddr_t phys)
  43. {
  44. unsigned offset = phys.paddr & ~PAGE_MASK;
  45. return XMADDR(PFN_PHYS(pfn_to_mfn(PFN_DOWN(phys.paddr))) | offset);
  46. }
  47. static inline xpaddr_t machine_to_phys(xmaddr_t machine)
  48. {
  49. unsigned offset = machine.maddr & ~PAGE_MASK;
  50. return XPADDR(PFN_PHYS(mfn_to_pfn(PFN_DOWN(machine.maddr))) | offset);
  51. }
  52. /* VIRT <-> MACHINE conversion */
  53. #define virt_to_machine(v) (phys_to_machine(XPADDR(__pa(v))))
  54. #define virt_to_mfn(v) (pfn_to_mfn(virt_to_pfn(v)))
  55. #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
  56. static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
  57. {
  58. /* TODO: assuming it is mapped in the kernel 1:1 */
  59. return virt_to_machine(vaddr);
  60. }
  61. /* TODO: this shouldn't be here but it is because the frontend drivers
  62. * are using it (its rolled in headers) even though we won't hit the code path.
  63. * So for right now just punt with this.
  64. */
  65. static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
  66. {
  67. BUG();
  68. return NULL;
  69. }
  70. extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
  71. struct gnttab_map_grant_ref *kmap_ops,
  72. struct page **pages, unsigned int count);
  73. extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
  74. struct gnttab_map_grant_ref *kmap_ops,
  75. struct page **pages, unsigned int count);
  76. bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
  77. bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
  78. unsigned long nr_pages);
  79. static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
  80. {
  81. return __set_phys_to_machine(pfn, mfn);
  82. }
  83. #define xen_remap(cookie, size) ioremap_cache((cookie), (size))
  84. #define xen_unmap(cookie) iounmap((cookie))
  85. #endif /* _ASM_ARM_XEN_PAGE_H */