1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3 *
4 * Copyright (c) 2007 Cisco Systems. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 *
34 * $FreeBSD$
35 */
36
37 #ifndef IB_UMEM_H
38 #define IB_UMEM_H
39
40 #include <linux/list.h>
41 #include <linux/scatterlist.h>
42 #include <linux/workqueue.h>
43
44 struct ib_ucontext;
45 struct ib_umem_odp;
46
47 struct ib_umem {
48 struct ib_ucontext *context;
49 size_t length;
50 unsigned long address;
51 int page_size;
52 int writable;
53 struct work_struct work;
54 pid_t pid;
55 struct mm_struct *mm;
56 unsigned long diff;
57 struct ib_umem_odp *odp_data;
58 struct sg_table sg_head;
59 int nmap;
60 int npages;
61 };
62
63 /* Returns the offset of the umem start relative to the first page. */
64 static inline int ib_umem_offset(struct ib_umem *umem)
65 {
66 return umem->address & ((unsigned long)umem->page_size - 1);
67 }
68
69 /* Returns the first page of an ODP umem. */
70 static inline unsigned long ib_umem_start(struct ib_umem *umem)
71 {
72 return umem->address - ib_umem_offset(umem);
73 }
74
75 /* Returns the address of the page after the last one of an ODP umem. */
76 static inline unsigned long ib_umem_end(struct ib_umem *umem)
77 {
78 return PAGE_ALIGN(umem->address + umem->length);
79 }
80
81 static inline size_t ib_umem_num_pages(struct ib_umem *umem)
82 {
83 return (ib_umem_end(umem) - ib_umem_start(umem)) >> PAGE_SHIFT;
84 }
85
86 #ifdef CONFIG_INFINIBAND_USER_MEM
87
88 struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
89 size_t size, int access, int dmasync);
90 void ib_umem_release(struct ib_umem *umem);
91 int ib_umem_page_count(struct ib_umem *umem);
92 int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
93 size_t length);
94
95 #else /* CONFIG_INFINIBAND_USER_MEM */
96
97 #include <linux/err.h>
98
99 static inline struct ib_umem *ib_umem_get(struct ib_ucontext *context,
100 unsigned long addr, size_t size,
101 int access, int dmasync) {
102 return ERR_PTR(-EINVAL);
103 }
104 static inline void ib_umem_release(struct ib_umem *umem) { }
105 static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; }
106 static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
107 size_t length) {
108 return -EINVAL;
109 }
110 #endif /* CONFIG_INFINIBAND_USER_MEM */
111
112 #endif /* IB_UMEM_H */
Cache object: cb51474c4ad42f5d23f1da0d02f9e9d9
|