1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef IB_UMEM_H
34#define IB_UMEM_H
35
36#include <linux/list.h>
37#include <linux/scatterlist.h>
38#include <linux/workqueue.h>
39#include <rdma/ib_verbs.h>
40
41struct ib_ucontext;
42struct ib_umem_odp;
43
44struct ib_umem {
45 struct ib_ucontext *context;
46 struct mm_struct *owning_mm;
47 size_t length;
48 unsigned long address;
49 int page_shift;
50 u32 writable : 1;
51 u32 is_odp : 1;
52 struct work_struct work;
53 struct sg_table sg_head;
54 int nmap;
55 unsigned int sg_nents;
56};
57
58
59static inline int ib_umem_offset(struct ib_umem *umem)
60{
61 return umem->address & (BIT(umem->page_shift) - 1);
62}
63
64
65static inline unsigned long ib_umem_start(struct ib_umem *umem)
66{
67 return umem->address - ib_umem_offset(umem);
68}
69
70
71static inline unsigned long ib_umem_end(struct ib_umem *umem)
72{
73 return ALIGN(umem->address + umem->length, BIT(umem->page_shift));
74}
75
76static inline size_t ib_umem_num_pages(struct ib_umem *umem)
77{
78 return (ib_umem_end(umem) - ib_umem_start(umem)) >> umem->page_shift;
79}
80
81#ifdef CONFIG_INFINIBAND_USER_MEM
82
83struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr,
84 size_t size, int access, int dmasync);
85void ib_umem_release(struct ib_umem *umem);
86int ib_umem_page_count(struct ib_umem *umem);
87int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
88 size_t length);
89unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
90 unsigned long pgsz_bitmap,
91 unsigned long virt);
92
93#else
94
95#include <linux/err.h>
96
97static inline struct ib_umem *ib_umem_get(struct ib_udata *udata,
98 unsigned long addr, size_t size,
99 int access, int dmasync)
100{
101 return ERR_PTR(-EINVAL);
102}
103static inline void ib_umem_release(struct ib_umem *umem) { }
104static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; }
105static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
106 size_t length) {
107 return -EINVAL;
108}
109static inline int ib_umem_find_best_pgsz(struct ib_umem *umem,
110 unsigned long pgsz_bitmap,
111 unsigned long virt) {
112 return -EINVAL;
113}
114
115#endif
116
117#endif
118