Lines Matching refs:bo
52 static void tegra_bo_put(struct host1x_bo *bo) in tegra_bo_put() argument
54 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_put()
59 static struct host1x_bo_mapping *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, in tegra_bo_pin() argument
62 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_pin()
72 map->bo = host1x_bo_get(bo); in tegra_bo_pin()
173 host1x_bo_put(map->bo); in tegra_bo_unpin()
177 static void *tegra_bo_mmap(struct host1x_bo *bo) in tegra_bo_mmap() argument
179 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_mmap()
203 static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) in tegra_bo_munmap() argument
205 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_munmap()
217 static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) in tegra_bo_get() argument
219 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_get()
223 return bo; in tegra_bo_get()
235 static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_map() argument
240 if (bo->mm) in tegra_bo_iommu_map()
243 bo->mm = kzalloc(sizeof(*bo->mm), GFP_KERNEL); in tegra_bo_iommu_map()
244 if (!bo->mm) in tegra_bo_iommu_map()
250 bo->mm, bo->gem.size, PAGE_SIZE, 0, 0); in tegra_bo_iommu_map()
257 bo->iova = bo->mm->start; in tegra_bo_iommu_map()
259 bo->size = iommu_map_sgtable(tegra->domain, bo->iova, bo->sgt, prot); in tegra_bo_iommu_map()
260 if (!bo->size) { in tegra_bo_iommu_map()
271 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_map()
274 kfree(bo->mm); in tegra_bo_iommu_map()
278 static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_unmap() argument
280 if (!bo->mm) in tegra_bo_iommu_unmap()
284 iommu_unmap(tegra->domain, bo->iova, bo->size); in tegra_bo_iommu_unmap()
285 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_unmap()
288 kfree(bo->mm); in tegra_bo_iommu_unmap()
302 struct tegra_bo *bo; in tegra_bo_alloc_object() local
305 bo = kzalloc(sizeof(*bo), GFP_KERNEL); in tegra_bo_alloc_object()
306 if (!bo) in tegra_bo_alloc_object()
309 bo->gem.funcs = &tegra_gem_object_funcs; in tegra_bo_alloc_object()
311 host1x_bo_init(&bo->base, &tegra_bo_ops); in tegra_bo_alloc_object()
314 err = drm_gem_object_init(drm, &bo->gem, size); in tegra_bo_alloc_object()
318 err = drm_gem_create_mmap_offset(&bo->gem); in tegra_bo_alloc_object()
322 return bo; in tegra_bo_alloc_object()
325 drm_gem_object_release(&bo->gem); in tegra_bo_alloc_object()
327 kfree(bo); in tegra_bo_alloc_object()
331 static void tegra_bo_free(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_free() argument
333 if (bo->pages) { in tegra_bo_free()
334 dma_unmap_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_free()
335 drm_gem_put_pages(&bo->gem, bo->pages, true, true); in tegra_bo_free()
336 sg_free_table(bo->sgt); in tegra_bo_free()
337 kfree(bo->sgt); in tegra_bo_free()
338 } else if (bo->vaddr) { in tegra_bo_free()
339 dma_free_wc(drm->dev, bo->gem.size, bo->vaddr, bo->iova); in tegra_bo_free()
343 static int tegra_bo_get_pages(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_get_pages() argument
347 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
348 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
349 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
351 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
353 bo->sgt = drm_prime_pages_to_sg(bo->gem.dev, bo->pages, bo->num_pages); in tegra_bo_get_pages()
354 if (IS_ERR(bo->sgt)) { in tegra_bo_get_pages()
355 err = PTR_ERR(bo->sgt); in tegra_bo_get_pages()
359 err = dma_map_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_get_pages()
366 sg_free_table(bo->sgt); in tegra_bo_get_pages()
367 kfree(bo->sgt); in tegra_bo_get_pages()
369 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
373 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
379 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
383 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
385 tegra_bo_free(drm, bo); in tegra_bo_alloc()
389 size_t size = bo->gem.size; in tegra_bo_alloc()
391 bo->vaddr = dma_alloc_wc(drm->dev, size, &bo->iova, in tegra_bo_alloc()
393 if (!bo->vaddr) { in tegra_bo_alloc()
407 struct tegra_bo *bo; in tegra_bo_create() local
410 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
411 if (IS_ERR(bo)) in tegra_bo_create()
412 return bo; in tegra_bo_create()
414 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
419 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
422 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
424 return bo; in tegra_bo_create()
427 drm_gem_object_release(&bo->gem); in tegra_bo_create()
428 kfree(bo); in tegra_bo_create()
438 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
441 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
442 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
443 return bo; in tegra_bo_create_with_handle()
445 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
447 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
451 drm_gem_object_put(&bo->gem); in tegra_bo_create_with_handle()
453 return bo; in tegra_bo_create_with_handle()
461 struct tegra_bo *bo; in tegra_bo_import() local
464 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
465 if (IS_ERR(bo)) in tegra_bo_import()
466 return bo; in tegra_bo_import()
479 bo->sgt = dma_buf_map_attachment_unlocked(attach, DMA_TO_DEVICE); in tegra_bo_import()
480 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
481 err = PTR_ERR(bo->sgt); in tegra_bo_import()
485 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
489 bo->gem.import_attach = attach; in tegra_bo_import()
493 bo->dma_buf = buf; in tegra_bo_import()
495 return bo; in tegra_bo_import()
498 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
499 dma_buf_unmap_attachment_unlocked(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
504 drm_gem_object_release(&bo->gem); in tegra_bo_import()
505 kfree(bo); in tegra_bo_import()
513 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
516 list_for_each_entry_safe(mapping, tmp, &bo->base.mappings, list) { in tegra_bo_free_object()
525 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
528 dma_buf_unmap_attachment_unlocked(gem->import_attach, bo->sgt, in tegra_bo_free_object()
534 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
536 if (bo->dma_buf) in tegra_bo_free_object()
537 dma_buf_put(bo->dma_buf); in tegra_bo_free_object()
540 kfree(bo); in tegra_bo_free_object()
548 struct tegra_bo *bo; in tegra_bo_dumb_create() local
553 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
555 if (IS_ERR(bo)) in tegra_bo_dumb_create()
556 return PTR_ERR(bo); in tegra_bo_dumb_create()
565 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
569 if (!bo->pages) in tegra_bo_fault()
573 page = bo->pages[offset]; in tegra_bo_fault()
586 struct tegra_bo *bo = to_tegra_bo(gem); in __tegra_gem_mmap() local
588 if (!bo->pages) { in __tegra_gem_mmap()
600 err = dma_mmap_wc(gem->dev->dev, vma, bo->vaddr, bo->iova, in __tegra_gem_mmap()
638 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
645 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
646 if (sg_alloc_table_from_pages(sgt, bo->pages, bo->num_pages, in tegra_gem_prime_map_dma_buf()
650 if (dma_get_sgtable(attach->dev, sgt, bo->vaddr, bo->iova, in tegra_gem_prime_map_dma_buf()
671 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
673 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
689 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_begin_cpu_access() local
692 if (bo->pages) in tegra_gem_prime_begin_cpu_access()
693 dma_sync_sgtable_for_cpu(drm->dev, bo->sgt, DMA_FROM_DEVICE); in tegra_gem_prime_begin_cpu_access()
702 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_end_cpu_access() local
705 if (bo->pages) in tegra_gem_prime_end_cpu_access()
706 dma_sync_sgtable_for_device(drm->dev, bo->sgt, DMA_TO_DEVICE); in tegra_gem_prime_end_cpu_access()
726 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
729 vaddr = tegra_bo_mmap(&bo->base); in tegra_gem_prime_vmap()
741 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vunmap() local
743 tegra_bo_munmap(&bo->base, map->vaddr); in tegra_gem_prime_vunmap()
775 struct tegra_bo *bo; in tegra_gem_prime_import() local
786 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
787 if (IS_ERR(bo)) in tegra_gem_prime_import()
788 return ERR_CAST(bo); in tegra_gem_prime_import()
790 return &bo->gem; in tegra_gem_prime_import()
796 struct tegra_bo *bo; in tegra_gem_lookup() local
802 bo = to_tegra_bo(gem); in tegra_gem_lookup()
803 return &bo->base; in tegra_gem_lookup()