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
40struct ib_ucontext;
41struct ib_umem_odp;
42
43struct ib_umem {
44 struct ib_ucontext *context;
45 size_t length;
46 unsigned long address;
47 int page_shift;
48 int writable;
49 int hugetlb;
50 struct work_struct work;
51 struct mm_struct *mm;
52 unsigned long diff;
53 struct ib_umem_odp *odp_data;
54 struct sg_table sg_head;
55 int nmap;
56 int npages;
57};
58
59
60static inline int ib_umem_offset(struct ib_umem *umem)
61{
62 return umem->address & (BIT(umem->page_shift) - 1);
63}
64
65
66static inline unsigned long ib_umem_start(struct ib_umem *umem)
67{
68 return umem->address - ib_umem_offset(umem);
69}
70
71
72static inline unsigned long ib_umem_end(struct ib_umem *umem)
73{
74 return ALIGN(umem->address + umem->length, BIT(umem->page_shift));
75}
76
77static inline size_t ib_umem_num_pages(struct ib_umem *umem)
78{
79 return (ib_umem_end(umem) - ib_umem_start(umem)) >> umem->page_shift;
80}
81
82#ifdef CONFIG_INFINIBAND_USER_MEM
83
84struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
85 size_t size, int access, int dmasync);
86void ib_umem_release(struct ib_umem *umem);
87int ib_umem_page_count(struct ib_umem *umem);
88int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
89 size_t length);
90
91#else
92
93#include <linux/err.h>
94
95static inline struct ib_umem *ib_umem_get(struct ib_ucontext *context,
96 unsigned long addr, size_t size,
97 int access, int dmasync) {
98 return ERR_PTR(-EINVAL);
99}
100static inline void ib_umem_release(struct ib_umem *umem) { }
101static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; }
102static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
103 size_t length) {
104 return -EINVAL;
105}
106#endif
107
108#endif
109