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