2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * Copyright (c) 2007 Cisco Systems. All rights reserved.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
40 #include <linux/list.h>
41 #include <linux/scatterlist.h>
42 #include <linux/workqueue.h>
48 struct ib_ucontext *context;
50 unsigned long address;
53 struct work_struct work;
57 struct ib_umem_odp *odp_data;
58 struct sg_table sg_head;
63 /* Returns the offset of the umem start relative to the first page. */
64 static inline int ib_umem_offset(struct ib_umem *umem)
66 return umem->address & ((unsigned long)umem->page_size - 1);
69 /* Returns the first page of an ODP umem. */
70 static inline unsigned long ib_umem_start(struct ib_umem *umem)
72 return umem->address - ib_umem_offset(umem);
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)
78 return PAGE_ALIGN(umem->address + umem->length);
81 static inline size_t ib_umem_num_pages(struct ib_umem *umem)
83 return (ib_umem_end(umem) - ib_umem_start(umem)) >> PAGE_SHIFT;
86 #ifdef CONFIG_INFINIBAND_USER_MEM
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,
95 #else /* CONFIG_INFINIBAND_USER_MEM */
97 #include <linux/err.h>
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);
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,
110 #endif /* CONFIG_INFINIBAND_USER_MEM */
112 #endif /* IB_UMEM_H */