Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
0002 /*
0003  * Copyright (c) 2014 Mellanox Technologies. All rights reserved.
0004  */
0005 
0006 #ifndef IB_UMEM_ODP_H
0007 #define IB_UMEM_ODP_H
0008 
0009 #include <rdma/ib_umem.h>
0010 #include <rdma/ib_verbs.h>
0011 
0012 struct ib_umem_odp {
0013     struct ib_umem umem;
0014     struct mmu_interval_notifier notifier;
0015     struct pid *tgid;
0016 
0017     /* An array of the pfns included in the on-demand paging umem. */
0018     unsigned long *pfn_list;
0019 
0020     /*
0021      * An array with DMA addresses mapped for pfns in pfn_list.
0022      * The lower two bits designate access permissions.
0023      * See ODP_READ_ALLOWED_BIT and ODP_WRITE_ALLOWED_BIT.
0024      */
0025     dma_addr_t      *dma_list;
0026     /*
0027      * The umem_mutex protects the page_list and dma_list fields of an ODP
0028      * umem, allowing only a single thread to map/unmap pages. The mutex
0029      * also protects access to the mmu notifier counters.
0030      */
0031     struct mutex        umem_mutex;
0032     void            *private; /* for the HW driver to use. */
0033 
0034     int npages;
0035 
0036     /*
0037      * An implicit odp umem cannot be DMA mapped, has 0 length, and serves
0038      * only as an anchor for the driver to hold onto the per_mm. FIXME:
0039      * This should be removed and drivers should work with the per_mm
0040      * directly.
0041      */
0042     bool is_implicit_odp;
0043 
0044     unsigned int        page_shift;
0045 };
0046 
0047 static inline struct ib_umem_odp *to_ib_umem_odp(struct ib_umem *umem)
0048 {
0049     return container_of(umem, struct ib_umem_odp, umem);
0050 }
0051 
0052 /* Returns the first page of an ODP umem. */
0053 static inline unsigned long ib_umem_start(struct ib_umem_odp *umem_odp)
0054 {
0055     return umem_odp->notifier.interval_tree.start;
0056 }
0057 
0058 /* Returns the address of the page after the last one of an ODP umem. */
0059 static inline unsigned long ib_umem_end(struct ib_umem_odp *umem_odp)
0060 {
0061     return umem_odp->notifier.interval_tree.last + 1;
0062 }
0063 
0064 static inline size_t ib_umem_odp_num_pages(struct ib_umem_odp *umem_odp)
0065 {
0066     return (ib_umem_end(umem_odp) - ib_umem_start(umem_odp)) >>
0067            umem_odp->page_shift;
0068 }
0069 
0070 /*
0071  * The lower 2 bits of the DMA address signal the R/W permissions for
0072  * the entry. To upgrade the permissions, provide the appropriate
0073  * bitmask to the map_dma_pages function.
0074  *
0075  * Be aware that upgrading a mapped address might result in change of
0076  * the DMA address for the page.
0077  */
0078 #define ODP_READ_ALLOWED_BIT  (1<<0ULL)
0079 #define ODP_WRITE_ALLOWED_BIT (1<<1ULL)
0080 
0081 #define ODP_DMA_ADDR_MASK (~(ODP_READ_ALLOWED_BIT | ODP_WRITE_ALLOWED_BIT))
0082 
0083 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
0084 
0085 struct ib_umem_odp *
0086 ib_umem_odp_get(struct ib_device *device, unsigned long addr, size_t size,
0087         int access, const struct mmu_interval_notifier_ops *ops);
0088 struct ib_umem_odp *ib_umem_odp_alloc_implicit(struct ib_device *device,
0089                            int access);
0090 struct ib_umem_odp *
0091 ib_umem_odp_alloc_child(struct ib_umem_odp *root_umem, unsigned long addr,
0092             size_t size,
0093             const struct mmu_interval_notifier_ops *ops);
0094 void ib_umem_odp_release(struct ib_umem_odp *umem_odp);
0095 
0096 int ib_umem_odp_map_dma_and_lock(struct ib_umem_odp *umem_odp, u64 start_offset,
0097                  u64 bcnt, u64 access_mask, bool fault);
0098 
0099 void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp *umem_odp, u64 start_offset,
0100                  u64 bound);
0101 
0102 #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
0103 
0104 static inline struct ib_umem_odp *
0105 ib_umem_odp_get(struct ib_device *device, unsigned long addr, size_t size,
0106         int access, const struct mmu_interval_notifier_ops *ops)
0107 {
0108     return ERR_PTR(-EINVAL);
0109 }
0110 
0111 static inline void ib_umem_odp_release(struct ib_umem_odp *umem_odp) {}
0112 
0113 #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
0114 
0115 #endif /* IB_UMEM_ODP_H */