ib_umem_odp.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2. /*
  3. * Copyright (c) 2014 Mellanox Technologies. All rights reserved.
  4. */
  5. #ifndef IB_UMEM_ODP_H
  6. #define IB_UMEM_ODP_H
  7. #include <rdma/ib_umem.h>
  8. #include <rdma/ib_verbs.h>
  9. #include <linux/hmm-dma.h>
  10. struct ib_umem_odp {
  11. struct ib_umem umem;
  12. struct mmu_interval_notifier notifier;
  13. struct pid *tgid;
  14. struct hmm_dma_map map;
  15. /*
  16. * The umem_mutex protects the page_list field of an ODP
  17. * umem, allowing only a single thread to map/unmap pages. The mutex
  18. * also protects access to the mmu notifier counters.
  19. */
  20. struct mutex umem_mutex;
  21. void *private; /* for the HW driver to use. */
  22. int npages;
  23. /*
  24. * An implicit odp umem cannot be DMA mapped, has 0 length, and serves
  25. * only as an anchor for the driver to hold onto the per_mm. FIXME:
  26. * This should be removed and drivers should work with the per_mm
  27. * directly.
  28. */
  29. bool is_implicit_odp;
  30. unsigned int page_shift;
  31. };
  32. static inline struct ib_umem_odp *to_ib_umem_odp(struct ib_umem *umem)
  33. {
  34. return container_of(umem, struct ib_umem_odp, umem);
  35. }
  36. /* Returns the first page of an ODP umem. */
  37. static inline unsigned long ib_umem_start(struct ib_umem_odp *umem_odp)
  38. {
  39. return umem_odp->notifier.interval_tree.start;
  40. }
  41. /* Returns the address of the page after the last one of an ODP umem. */
  42. static inline unsigned long ib_umem_end(struct ib_umem_odp *umem_odp)
  43. {
  44. return umem_odp->notifier.interval_tree.last + 1;
  45. }
  46. static inline size_t ib_umem_odp_num_pages(struct ib_umem_odp *umem_odp)
  47. {
  48. return (ib_umem_end(umem_odp) - ib_umem_start(umem_odp)) >>
  49. umem_odp->page_shift;
  50. }
  51. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  52. struct ib_umem_odp *
  53. ib_umem_odp_get(struct ib_device *device, unsigned long addr, size_t size,
  54. int access, const struct mmu_interval_notifier_ops *ops);
  55. struct ib_umem_odp *ib_umem_odp_alloc_implicit(struct ib_device *device,
  56. int access);
  57. struct ib_umem_odp *
  58. ib_umem_odp_alloc_child(struct ib_umem_odp *root_umem, unsigned long addr,
  59. size_t size,
  60. const struct mmu_interval_notifier_ops *ops);
  61. void ib_umem_odp_release(struct ib_umem_odp *umem_odp);
  62. int ib_umem_odp_map_dma_and_lock(struct ib_umem_odp *umem_odp, u64 start_offset,
  63. u64 bcnt, u64 access_mask, bool fault);
  64. void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp *umem_odp, u64 start_offset,
  65. u64 bound);
  66. #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  67. static inline struct ib_umem_odp *
  68. ib_umem_odp_get(struct ib_device *device, unsigned long addr, size_t size,
  69. int access, const struct mmu_interval_notifier_ops *ops)
  70. {
  71. return ERR_PTR(-EINVAL);
  72. }
  73. static inline void ib_umem_odp_release(struct ib_umem_odp *umem_odp) {}
  74. #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  75. #endif /* IB_UMEM_ODP_H */