1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
3 * Copyright (c) 2014 Mellanox Technologies. All rights reserved.
9 #include <rdma/ib_umem.h>
10 #include <rdma/ib_verbs.h>
14 struct mmu_interval_notifier notifier
;
17 /* An array of the pfns included in the on-demand paging umem. */
18 unsigned long *pfn_list
;
21 * An array with DMA addresses mapped for pfns in pfn_list.
22 * The lower two bits designate access permissions.
23 * See ODP_READ_ALLOWED_BIT and ODP_WRITE_ALLOWED_BIT.
27 * The umem_mutex protects the page_list and dma_list fields of an ODP
28 * umem, allowing only a single thread to map/unmap pages. The mutex
29 * also protects access to the mmu notifier counters.
31 struct mutex umem_mutex
;
32 void *private; /* for the HW driver to use. */
37 * An implicit odp umem cannot be DMA mapped, has 0 length, and serves
38 * only as an anchor for the driver to hold onto the per_mm. FIXME:
39 * This should be removed and drivers should work with the per_mm
44 unsigned int page_shift
;
47 static inline struct ib_umem_odp
*to_ib_umem_odp(struct ib_umem
*umem
)
49 return container_of(umem
, struct ib_umem_odp
, umem
);
52 /* Returns the first page of an ODP umem. */
53 static inline unsigned long ib_umem_start(struct ib_umem_odp
*umem_odp
)
55 return umem_odp
->notifier
.interval_tree
.start
;
58 /* Returns the address of the page after the last one of an ODP umem. */
59 static inline unsigned long ib_umem_end(struct ib_umem_odp
*umem_odp
)
61 return umem_odp
->notifier
.interval_tree
.last
+ 1;
64 static inline size_t ib_umem_odp_num_pages(struct ib_umem_odp
*umem_odp
)
66 return (ib_umem_end(umem_odp
) - ib_umem_start(umem_odp
)) >>
71 * The lower 2 bits of the DMA address signal the R/W permissions for
72 * the entry. To upgrade the permissions, provide the appropriate
73 * bitmask to the map_dma_pages function.
75 * Be aware that upgrading a mapped address might result in change of
76 * the DMA address for the page.
78 #define ODP_READ_ALLOWED_BIT (1<<0ULL)
79 #define ODP_WRITE_ALLOWED_BIT (1<<1ULL)
81 #define ODP_DMA_ADDR_MASK (~(ODP_READ_ALLOWED_BIT | ODP_WRITE_ALLOWED_BIT))
83 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
86 ib_umem_odp_get(struct ib_device
*device
, unsigned long addr
, size_t size
,
87 int access
, const struct mmu_interval_notifier_ops
*ops
);
88 struct ib_umem_odp
*ib_umem_odp_alloc_implicit(struct ib_device
*device
,
91 ib_umem_odp_alloc_child(struct ib_umem_odp
*root_umem
, unsigned long addr
,
93 const struct mmu_interval_notifier_ops
*ops
);
94 void ib_umem_odp_release(struct ib_umem_odp
*umem_odp
);
96 int ib_umem_odp_map_dma_and_lock(struct ib_umem_odp
*umem_odp
, u64 start_offset
,
97 u64 bcnt
, u64 access_mask
, bool fault
);
99 void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp
*umem_odp
, u64 start_offset
,
102 #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
104 static inline struct ib_umem_odp
*
105 ib_umem_odp_get(struct ib_device
*device
, unsigned long addr
, size_t size
,
106 int access
, const struct mmu_interval_notifier_ops
*ops
)
108 return ERR_PTR(-EINVAL
);
111 static inline void ib_umem_odp_release(struct ib_umem_odp
*umem_odp
) {}
113 #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
115 #endif /* IB_UMEM_ODP_H */