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()
194 static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) in tegra_bo_munmap() argument
196 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_munmap()
207 static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) in tegra_bo_get() argument
209 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_get()
213 return bo; in tegra_bo_get()
225 static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_map() argument
230 if (bo->mm) in tegra_bo_iommu_map()
233 bo->mm = kzalloc(sizeof(*bo->mm), GFP_KERNEL); in tegra_bo_iommu_map()
234 if (!bo->mm) in tegra_bo_iommu_map()
240 bo->mm, bo->gem.size, PAGE_SIZE, 0, 0); in tegra_bo_iommu_map()
247 bo->iova = bo->mm->start; in tegra_bo_iommu_map()
249 bo->size = iommu_map_sgtable(tegra->domain, bo->iova, bo->sgt, prot); in tegra_bo_iommu_map()
250 if (!bo->size) { in tegra_bo_iommu_map()
261 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_map()
264 kfree(bo->mm); in tegra_bo_iommu_map()
268 static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_unmap() argument
270 if (!bo->mm) in tegra_bo_iommu_unmap()
274 iommu_unmap(tegra->domain, bo->iova, bo->size); in tegra_bo_iommu_unmap()
275 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_unmap()
278 kfree(bo->mm); in tegra_bo_iommu_unmap()
292 struct tegra_bo *bo; in tegra_bo_alloc_object() local
295 bo = kzalloc(sizeof(*bo), GFP_KERNEL); in tegra_bo_alloc_object()
296 if (!bo) in tegra_bo_alloc_object()
299 bo->gem.funcs = &tegra_gem_object_funcs; in tegra_bo_alloc_object()
301 host1x_bo_init(&bo->base, &tegra_bo_ops); in tegra_bo_alloc_object()
304 err = drm_gem_object_init(drm, &bo->gem, size); in tegra_bo_alloc_object()
308 err = drm_gem_create_mmap_offset(&bo->gem); in tegra_bo_alloc_object()
312 return bo; in tegra_bo_alloc_object()
315 drm_gem_object_release(&bo->gem); in tegra_bo_alloc_object()
317 kfree(bo); in tegra_bo_alloc_object()
321 static void tegra_bo_free(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_free() argument
323 if (bo->pages) { in tegra_bo_free()
324 dma_unmap_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_free()
325 drm_gem_put_pages(&bo->gem, bo->pages, true, true); in tegra_bo_free()
326 sg_free_table(bo->sgt); in tegra_bo_free()
327 kfree(bo->sgt); in tegra_bo_free()
328 } else if (bo->vaddr) { in tegra_bo_free()
329 dma_free_wc(drm->dev, bo->gem.size, bo->vaddr, bo->iova); in tegra_bo_free()
333 static int tegra_bo_get_pages(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_get_pages() argument
337 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
338 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
339 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
341 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
343 bo->sgt = drm_prime_pages_to_sg(bo->gem.dev, bo->pages, bo->num_pages); in tegra_bo_get_pages()
344 if (IS_ERR(bo->sgt)) { in tegra_bo_get_pages()
345 err = PTR_ERR(bo->sgt); in tegra_bo_get_pages()
349 err = dma_map_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_get_pages()
356 sg_free_table(bo->sgt); in tegra_bo_get_pages()
357 kfree(bo->sgt); in tegra_bo_get_pages()
359 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
363 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
369 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
373 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
375 tegra_bo_free(drm, bo); in tegra_bo_alloc()
379 size_t size = bo->gem.size; in tegra_bo_alloc()
381 bo->vaddr = dma_alloc_wc(drm->dev, size, &bo->iova, in tegra_bo_alloc()
383 if (!bo->vaddr) { in tegra_bo_alloc()
397 struct tegra_bo *bo; in tegra_bo_create() local
400 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
401 if (IS_ERR(bo)) in tegra_bo_create()
402 return bo; in tegra_bo_create()
404 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
409 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
412 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
414 return bo; in tegra_bo_create()
417 drm_gem_object_release(&bo->gem); in tegra_bo_create()
418 kfree(bo); in tegra_bo_create()
428 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
431 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
432 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
433 return bo; in tegra_bo_create_with_handle()
435 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
437 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
441 drm_gem_object_put(&bo->gem); in tegra_bo_create_with_handle()
443 return bo; in tegra_bo_create_with_handle()
451 struct tegra_bo *bo; in tegra_bo_import() local
454 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
455 if (IS_ERR(bo)) in tegra_bo_import()
456 return bo; in tegra_bo_import()
466 bo->sgt = dma_buf_map_attachment_unlocked(attach, DMA_TO_DEVICE); in tegra_bo_import()
467 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
468 err = PTR_ERR(bo->sgt); in tegra_bo_import()
473 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
478 bo->gem.import_attach = attach; in tegra_bo_import()
480 return bo; in tegra_bo_import()
483 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
484 dma_buf_unmap_attachment_unlocked(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
489 drm_gem_object_release(&bo->gem); in tegra_bo_import()
490 kfree(bo); in tegra_bo_import()
498 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
501 list_for_each_entry_safe(mapping, tmp, &bo->base.mappings, list) { in tegra_bo_free_object()
510 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
513 dma_buf_unmap_attachment_unlocked(gem->import_attach, bo->sgt, in tegra_bo_free_object()
517 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
521 kfree(bo); in tegra_bo_free_object()
529 struct tegra_bo *bo; in tegra_bo_dumb_create() local
534 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
536 if (IS_ERR(bo)) in tegra_bo_dumb_create()
537 return PTR_ERR(bo); in tegra_bo_dumb_create()
546 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
550 if (!bo->pages) in tegra_bo_fault()
554 page = bo->pages[offset]; in tegra_bo_fault()
567 struct tegra_bo *bo = to_tegra_bo(gem); in __tegra_gem_mmap() local
569 if (!bo->pages) { in __tegra_gem_mmap()
581 err = dma_mmap_wc(gem->dev->dev, vma, bo->vaddr, bo->iova, in __tegra_gem_mmap()
619 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
626 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
627 if (sg_alloc_table_from_pages(sgt, bo->pages, bo->num_pages, in tegra_gem_prime_map_dma_buf()
631 if (dma_get_sgtable(attach->dev, sgt, bo->vaddr, bo->iova, in tegra_gem_prime_map_dma_buf()
652 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
654 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
670 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_begin_cpu_access() local
673 if (bo->pages) in tegra_gem_prime_begin_cpu_access()
674 dma_sync_sgtable_for_cpu(drm->dev, bo->sgt, DMA_FROM_DEVICE); in tegra_gem_prime_begin_cpu_access()
683 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_end_cpu_access() local
686 if (bo->pages) in tegra_gem_prime_end_cpu_access()
687 dma_sync_sgtable_for_device(drm->dev, bo->sgt, DMA_TO_DEVICE); in tegra_gem_prime_end_cpu_access()
707 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
710 vaddr = tegra_bo_mmap(&bo->base); in tegra_gem_prime_vmap()
722 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vunmap() local
724 tegra_bo_munmap(&bo->base, map->vaddr); in tegra_gem_prime_vunmap()
756 struct tegra_bo *bo; in tegra_gem_prime_import() local
767 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
768 if (IS_ERR(bo)) in tegra_gem_prime_import()
769 return ERR_CAST(bo); in tegra_gem_prime_import()
771 return &bo->gem; in tegra_gem_prime_import()
777 struct tegra_bo *bo; in tegra_gem_lookup() local
783 bo = to_tegra_bo(gem); in tegra_gem_lookup()
784 return &bo->base; in tegra_gem_lookup()