Lines Matching +full:vm +full:- +full:map
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /* Copyright 2017-2019 Qiang Yu <yuq825@gmail.com> */
5 #include <linux/iosys-map.h>
9 #include <linux/dma-mapping.h>
21 int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm) in lima_heap_alloc() argument
24 struct address_space *mapping = bo->base.base.filp->f_mapping; in lima_heap_alloc()
25 struct device *dev = bo->base.base.dev->dev; in lima_heap_alloc()
26 size_t old_size = bo->heap_size; in lima_heap_alloc()
27 size_t new_size = bo->heap_size ? bo->heap_size * 2 : in lima_heap_alloc()
32 if (bo->heap_size >= bo->base.base.size) in lima_heap_alloc()
33 return -ENOSPC; in lima_heap_alloc()
35 new_size = min(new_size, bo->base.base.size); in lima_heap_alloc()
37 mutex_lock(&bo->base.pages_lock); in lima_heap_alloc()
39 if (bo->base.pages) { in lima_heap_alloc()
40 pages = bo->base.pages; in lima_heap_alloc()
42 pages = kvmalloc_array(bo->base.base.size >> PAGE_SHIFT, in lima_heap_alloc()
45 mutex_unlock(&bo->base.pages_lock); in lima_heap_alloc()
46 return -ENOMEM; in lima_heap_alloc()
49 bo->base.pages = pages; in lima_heap_alloc()
50 bo->base.pages_use_count = 1; in lima_heap_alloc()
59 mutex_unlock(&bo->base.pages_lock); in lima_heap_alloc()
65 mutex_unlock(&bo->base.pages_lock); in lima_heap_alloc()
72 if (bo->base.sgt) { in lima_heap_alloc()
73 dma_unmap_sgtable(dev, bo->base.sgt, DMA_BIDIRECTIONAL, 0); in lima_heap_alloc()
74 sg_free_table(bo->base.sgt); in lima_heap_alloc()
76 bo->base.sgt = kmalloc(sizeof(*bo->base.sgt), GFP_KERNEL); in lima_heap_alloc()
77 if (!bo->base.sgt) { in lima_heap_alloc()
79 return -ENOMEM; in lima_heap_alloc()
86 kfree(bo->base.sgt); in lima_heap_alloc()
87 bo->base.sgt = NULL; in lima_heap_alloc()
91 *bo->base.sgt = sgt; in lima_heap_alloc()
93 if (vm) { in lima_heap_alloc()
94 ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT); in lima_heap_alloc()
99 bo->heap_size = new_size; in lima_heap_alloc()
117 obj = &shmem->base; in lima_gem_create_handle()
120 mask = mapping_gfp_mask(obj->filp->f_mapping); in lima_gem_create_handle()
123 mapping_set_gfp_mask(obj->filp->f_mapping, mask); in lima_gem_create_handle()
142 /* drop reference from allocate - handle holds it now */ in lima_gem_create_handle()
152 if (!list_empty(&bo->va)) in lima_gem_free_object()
153 dev_err(obj->dev->dev, "lima gem free bo still has va\n"); in lima_gem_free_object()
155 drm_gem_shmem_free(&bo->base); in lima_gem_free_object()
162 struct lima_vm *vm = priv->vm; in lima_gem_object_open() local
164 return lima_vm_bo_add(vm, bo, true); in lima_gem_object_open()
171 struct lima_vm *vm = priv->vm; in lima_gem_object_close() local
173 lima_vm_bo_del(vm, bo); in lima_gem_object_close()
180 if (bo->heap_size) in lima_gem_pin()
181 return -EINVAL; in lima_gem_pin()
183 return drm_gem_shmem_pin(&bo->base); in lima_gem_pin()
186 static int lima_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map) in lima_gem_vmap() argument
190 if (bo->heap_size) in lima_gem_vmap()
191 return -EINVAL; in lima_gem_vmap()
193 return drm_gem_shmem_vmap(&bo->base, map); in lima_gem_vmap()
200 if (bo->heap_size) in lima_gem_mmap()
201 return -EINVAL; in lima_gem_mmap()
203 return drm_gem_shmem_mmap(&bo->base, vma); in lima_gem_mmap()
226 return ERR_PTR(-ENOMEM); in lima_gem_create_object()
228 mutex_init(&bo->lock); in lima_gem_create_object()
229 INIT_LIST_HEAD(&bo->va); in lima_gem_create_object()
230 bo->base.map_wc = true; in lima_gem_create_object()
231 bo->base.base.funcs = &lima_gem_funcs; in lima_gem_create_object()
233 return &bo->base.base; in lima_gem_create_object()
241 struct lima_vm *vm = priv->vm; in lima_gem_get_info() local
245 return -ENOENT; in lima_gem_get_info()
249 *va = lima_vm_get_va(vm, bo); in lima_gem_get_info()
251 *offset = drm_vma_node_offset_addr(&obj->vma_node); in lima_gem_get_info()
270 return drm_sched_job_add_implicit_dependencies(&task->base, in lima_gem_sync_bo()
271 &bo->base.base, in lima_gem_sync_bo()
279 for (i = 0; i < ARRAY_SIZE(submit->in_sync); i++) { in lima_gem_add_deps()
282 if (!submit->in_sync[i]) in lima_gem_add_deps()
285 err = drm_syncobj_find_fence(file, submit->in_sync[i], in lima_gem_add_deps()
290 err = drm_sched_job_add_dependency(&submit->task->base, fence); in lima_gem_add_deps()
305 struct lima_vm *vm = priv->vm; in lima_gem_submit() local
308 struct lima_bo **bos = submit->lbos; in lima_gem_submit()
310 if (submit->out_sync) { in lima_gem_submit()
311 out_sync = drm_syncobj_find(file, submit->out_sync); in lima_gem_submit()
313 return -ENOENT; in lima_gem_submit()
316 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
320 obj = drm_gem_object_lookup(file, submit->bos[i].handle); in lima_gem_submit()
322 err = -ENOENT; in lima_gem_submit()
328 /* increase refcnt of gpu va map to prevent unmapped when executing, in lima_gem_submit()
331 err = lima_vm_bo_add(vm, bo, false); in lima_gem_submit()
341 submit->nr_bos, &ctx); in lima_gem_submit()
346 submit->task, submit->ctx->context + submit->pipe, in lima_gem_submit()
347 bos, submit->nr_bos, vm); in lima_gem_submit()
355 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
357 submit->task, bos[i], in lima_gem_submit()
358 submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE, in lima_gem_submit()
359 submit->flags & LIMA_SUBMIT_FLAG_EXPLICIT_FENCE); in lima_gem_submit()
364 fence = lima_sched_context_queue_task(submit->task); in lima_gem_submit()
366 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
368 submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE ? in lima_gem_submit()
373 submit->nr_bos, &ctx); in lima_gem_submit()
375 for (i = 0; i < submit->nr_bos; i++) in lima_gem_submit()
376 drm_gem_object_put(&bos[i]->base.base); in lima_gem_submit()
388 lima_sched_task_fini(submit->task); in lima_gem_submit()
391 submit->nr_bos, &ctx); in lima_gem_submit()
393 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
396 lima_vm_bo_del(vm, bos[i]); in lima_gem_submit()
397 drm_gem_object_put(&bos[i]->base.base); in lima_gem_submit()
415 if (ret == -ETIME) in lima_gem_wait()
416 ret = timeout ? -ETIMEDOUT : -EBUSY; in lima_gem_wait()