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 dma_resv_lock(bo->base.base.resv, NULL); 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 dma_resv_unlock(bo->base.base.resv); 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 dma_resv_unlock(bo->base.base.resv); in lima_heap_alloc()
65 dma_resv_unlock(bo->base.base.resv); 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()
78 ret = -ENOMEM; in lima_heap_alloc()
87 *bo->base.sgt = sgt; in lima_heap_alloc()
89 if (vm) { in lima_heap_alloc()
90 ret = lima_vm_map_bo(vm, bo, old_size >> PAGE_SHIFT); in lima_heap_alloc()
95 bo->heap_size = new_size; in lima_heap_alloc()
101 kfree(bo->base.sgt); in lima_heap_alloc()
102 bo->base.sgt = NULL; in lima_heap_alloc()
122 obj = &shmem->base; in lima_gem_create_handle()
125 mask = mapping_gfp_mask(obj->filp->f_mapping); in lima_gem_create_handle()
128 mapping_set_gfp_mask(obj->filp->f_mapping, mask); in lima_gem_create_handle()
147 /* drop reference from allocate - handle holds it now */ in lima_gem_create_handle()
157 if (!list_empty(&bo->va)) in lima_gem_free_object()
158 dev_err(obj->dev->dev, "lima gem free bo still has va\n"); in lima_gem_free_object()
160 drm_gem_shmem_free(&bo->base); in lima_gem_free_object()
167 struct lima_vm *vm = priv->vm; in lima_gem_object_open() local
169 return lima_vm_bo_add(vm, bo, true); in lima_gem_object_open()
176 struct lima_vm *vm = priv->vm; in lima_gem_object_close() local
178 lima_vm_bo_del(vm, bo); in lima_gem_object_close()
185 if (bo->heap_size) in lima_gem_pin()
186 return -EINVAL; in lima_gem_pin()
188 return drm_gem_shmem_pin(&bo->base); in lima_gem_pin()
191 static int lima_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map) in lima_gem_vmap() argument
195 if (bo->heap_size) in lima_gem_vmap()
196 return -EINVAL; in lima_gem_vmap()
198 return drm_gem_shmem_vmap(&bo->base, map); in lima_gem_vmap()
205 if (bo->heap_size) in lima_gem_mmap()
206 return -EINVAL; in lima_gem_mmap()
208 return drm_gem_shmem_mmap(&bo->base, vma); in lima_gem_mmap()
231 return ERR_PTR(-ENOMEM); in lima_gem_create_object()
233 mutex_init(&bo->lock); in lima_gem_create_object()
234 INIT_LIST_HEAD(&bo->va); in lima_gem_create_object()
235 bo->base.map_wc = true; in lima_gem_create_object()
236 bo->base.base.funcs = &lima_gem_funcs; in lima_gem_create_object()
238 return &bo->base.base; in lima_gem_create_object()
246 struct lima_vm *vm = priv->vm; in lima_gem_get_info() local
250 return -ENOENT; in lima_gem_get_info()
254 *va = lima_vm_get_va(vm, bo); in lima_gem_get_info()
256 *offset = drm_vma_node_offset_addr(&obj->vma_node); in lima_gem_get_info()
275 return drm_sched_job_add_implicit_dependencies(&task->base, in lima_gem_sync_bo()
276 &bo->base.base, in lima_gem_sync_bo()
284 for (i = 0; i < ARRAY_SIZE(submit->in_sync); i++) { in lima_gem_add_deps()
285 if (!submit->in_sync[i]) in lima_gem_add_deps()
288 err = drm_sched_job_add_syncobj_dependency(&submit->task->base, file, in lima_gem_add_deps()
289 submit->in_sync[i], 0); in lima_gem_add_deps()
302 struct lima_vm *vm = priv->vm; in lima_gem_submit() local
305 struct lima_bo **bos = submit->lbos; in lima_gem_submit()
307 if (submit->out_sync) { in lima_gem_submit()
308 out_sync = drm_syncobj_find(file, submit->out_sync); in lima_gem_submit()
310 return -ENOENT; in lima_gem_submit()
313 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
317 obj = drm_gem_object_lookup(file, submit->bos[i].handle); in lima_gem_submit()
319 err = -ENOENT; in lima_gem_submit()
325 /* increase refcnt of gpu va map to prevent unmapped when executing, in lima_gem_submit()
328 err = lima_vm_bo_add(vm, bo, false); in lima_gem_submit()
338 submit->nr_bos, &ctx); in lima_gem_submit()
343 submit->task, submit->ctx->context + submit->pipe, in lima_gem_submit()
344 bos, submit->nr_bos, vm); in lima_gem_submit()
352 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
354 submit->task, bos[i], in lima_gem_submit()
355 submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE, in lima_gem_submit()
356 submit->flags & LIMA_SUBMIT_FLAG_EXPLICIT_FENCE); in lima_gem_submit()
361 fence = lima_sched_context_queue_task(submit->task); in lima_gem_submit()
363 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
365 submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE ? in lima_gem_submit()
370 submit->nr_bos, &ctx); in lima_gem_submit()
372 for (i = 0; i < submit->nr_bos; i++) in lima_gem_submit()
373 drm_gem_object_put(&bos[i]->base.base); in lima_gem_submit()
385 lima_sched_task_fini(submit->task); in lima_gem_submit()
388 submit->nr_bos, &ctx); in lima_gem_submit()
390 for (i = 0; i < submit->nr_bos; i++) { in lima_gem_submit()
393 lima_vm_bo_del(vm, bos[i]); in lima_gem_submit()
394 drm_gem_object_put(&bos[i]->base.base); in lima_gem_submit()
412 if (ret == -ETIME) in lima_gem_wait()
413 ret = timeout ? -ETIMEDOUT : -EBUSY; in lima_gem_wait()