Lines Matching refs:umem
48 static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dirty) in __ib_umem_release() argument
50 bool make_dirty = umem->writable && dirty; in __ib_umem_release()
55 ib_dma_unmap_sgtable_attrs(dev, &umem->sgt_append.sgt, in __ib_umem_release()
58 for_each_sgtable_sg(&umem->sgt_append.sgt, sg, i) in __ib_umem_release()
62 sg_free_append_table(&umem->sgt_append); in __ib_umem_release()
79 unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, in ib_umem_find_best_pgsz() argument
88 if (umem->is_odp) { in ib_umem_find_best_pgsz()
89 unsigned int page_size = BIT(to_ib_umem_odp(umem)->page_shift); in ib_umem_find_best_pgsz()
103 umem->iova = va = virt; in ib_umem_find_best_pgsz()
110 bits_per((umem->length - 1 + virt) ^ virt)); in ib_umem_find_best_pgsz()
112 pgoff = umem->address & ~PAGE_MASK; in ib_umem_find_best_pgsz()
114 for_each_sgtable_dma_sg(&umem->sgt_append.sgt, sg, i) { in ib_umem_find_best_pgsz()
124 if (i != (umem->sgt_append.sgt.nents - 1)) in ib_umem_find_best_pgsz()
150 struct ib_umem *umem; in ib_umem_get() local
175 umem = kzalloc(sizeof(*umem), GFP_KERNEL); in ib_umem_get()
176 if (!umem) in ib_umem_get()
178 umem->ibdev = device; in ib_umem_get()
179 umem->length = size; in ib_umem_get()
180 umem->address = addr; in ib_umem_get()
185 umem->iova = addr; in ib_umem_get()
186 umem->writable = ib_access_writable(access); in ib_umem_get()
187 umem->owning_mm = mm = current->mm; in ib_umem_get()
196 npages = ib_umem_num_pages(umem); in ib_umem_get()
213 if (!umem->writable) in ib_umem_get()
231 &umem->sgt_append, page_list, pinned, 0, in ib_umem_get()
243 ret = ib_dma_map_sgtable_attrs(device, &umem->sgt_append.sgt, in ib_umem_get()
250 __ib_umem_release(device, umem, 0); in ib_umem_get()
251 atomic64_sub(ib_umem_num_pages(umem), &mm->pinned_vm); in ib_umem_get()
256 mmdrop(umem->owning_mm); in ib_umem_get()
257 kfree(umem); in ib_umem_get()
259 return ret ? ERR_PTR(ret) : umem; in ib_umem_get()
267 void ib_umem_release(struct ib_umem *umem) in ib_umem_release() argument
269 if (!umem) in ib_umem_release()
271 if (umem->is_dmabuf) in ib_umem_release()
272 return ib_umem_dmabuf_release(to_ib_umem_dmabuf(umem)); in ib_umem_release()
273 if (umem->is_odp) in ib_umem_release()
274 return ib_umem_odp_release(to_ib_umem_odp(umem)); in ib_umem_release()
276 __ib_umem_release(umem->ibdev, umem, 1); in ib_umem_release()
278 atomic64_sub(ib_umem_num_pages(umem), &umem->owning_mm->pinned_vm); in ib_umem_release()
279 mmdrop(umem->owning_mm); in ib_umem_release()
280 kfree(umem); in ib_umem_release()
294 int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset, in ib_umem_copy_from() argument
300 if (offset > umem->length || length > umem->length - offset) { in ib_umem_copy_from()
302 __func__, offset, umem->length, end); in ib_umem_copy_from()
306 ret = sg_pcopy_to_buffer(umem->sgt_append.sgt.sgl, in ib_umem_copy_from()
307 umem->sgt_append.sgt.orig_nents, dst, length, in ib_umem_copy_from()
308 offset + ib_umem_offset(umem)); in ib_umem_copy_from()