Lines Matching refs:bo

51 static void tegra_bo_put(struct host1x_bo *bo)  in tegra_bo_put()  argument
53 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_put()
58 static struct host1x_bo_mapping *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, in tegra_bo_pin() argument
61 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_pin()
71 map->bo = host1x_bo_get(bo); in tegra_bo_pin()
172 host1x_bo_put(map->bo); in tegra_bo_unpin()
176 static void *tegra_bo_mmap(struct host1x_bo *bo) in tegra_bo_mmap() argument
178 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_mmap()
202 static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) in tegra_bo_munmap() argument
204 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_munmap()
216 static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) in tegra_bo_get() argument
218 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_get()
222 return bo; in tegra_bo_get()
234 static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_map() argument
239 if (bo->mm) in tegra_bo_iommu_map()
242 bo->mm = kzalloc(sizeof(*bo->mm), GFP_KERNEL); in tegra_bo_iommu_map()
243 if (!bo->mm) in tegra_bo_iommu_map()
249 bo->mm, bo->gem.size, PAGE_SIZE, 0, 0); in tegra_bo_iommu_map()
256 bo->iova = bo->mm->start; in tegra_bo_iommu_map()
258 bo->size = iommu_map_sgtable(tegra->domain, bo->iova, bo->sgt, prot); in tegra_bo_iommu_map()
259 if (!bo->size) { in tegra_bo_iommu_map()
270 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_map()
273 kfree(bo->mm); in tegra_bo_iommu_map()
277 static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_unmap() argument
279 if (!bo->mm) in tegra_bo_iommu_unmap()
283 iommu_unmap(tegra->domain, bo->iova, bo->size); in tegra_bo_iommu_unmap()
284 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_unmap()
287 kfree(bo->mm); in tegra_bo_iommu_unmap()
301 struct tegra_bo *bo; in tegra_bo_alloc_object() local
304 bo = kzalloc(sizeof(*bo), GFP_KERNEL); in tegra_bo_alloc_object()
305 if (!bo) in tegra_bo_alloc_object()
308 bo->gem.funcs = &tegra_gem_object_funcs; in tegra_bo_alloc_object()
310 host1x_bo_init(&bo->base, &tegra_bo_ops); in tegra_bo_alloc_object()
313 err = drm_gem_object_init(drm, &bo->gem, size); in tegra_bo_alloc_object()
317 err = drm_gem_create_mmap_offset(&bo->gem); in tegra_bo_alloc_object()
321 return bo; in tegra_bo_alloc_object()
324 drm_gem_object_release(&bo->gem); in tegra_bo_alloc_object()
326 kfree(bo); in tegra_bo_alloc_object()
330 static void tegra_bo_free(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_free() argument
332 if (bo->pages) { in tegra_bo_free()
333 dma_unmap_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_free()
334 drm_gem_put_pages(&bo->gem, bo->pages, true, true); in tegra_bo_free()
335 sg_free_table(bo->sgt); in tegra_bo_free()
336 kfree(bo->sgt); in tegra_bo_free()
337 } else if (bo->vaddr) { in tegra_bo_free()
338 dma_free_wc(drm->dev, bo->gem.size, bo->vaddr, bo->iova); in tegra_bo_free()
342 static int tegra_bo_get_pages(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_get_pages() argument
346 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
347 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
348 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
350 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
352 bo->sgt = drm_prime_pages_to_sg(bo->gem.dev, bo->pages, bo->num_pages); in tegra_bo_get_pages()
353 if (IS_ERR(bo->sgt)) { in tegra_bo_get_pages()
354 err = PTR_ERR(bo->sgt); in tegra_bo_get_pages()
358 err = dma_map_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_get_pages()
365 sg_free_table(bo->sgt); in tegra_bo_get_pages()
366 kfree(bo->sgt); in tegra_bo_get_pages()
368 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
372 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
378 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
382 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
384 tegra_bo_free(drm, bo); in tegra_bo_alloc()
388 size_t size = bo->gem.size; in tegra_bo_alloc()
390 bo->vaddr = dma_alloc_wc(drm->dev, size, &bo->iova, in tegra_bo_alloc()
392 if (!bo->vaddr) { in tegra_bo_alloc()
406 struct tegra_bo *bo; in tegra_bo_create() local
409 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
410 if (IS_ERR(bo)) in tegra_bo_create()
411 return bo; in tegra_bo_create()
413 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
418 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
421 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
423 return bo; in tegra_bo_create()
426 drm_gem_object_release(&bo->gem); in tegra_bo_create()
427 kfree(bo); in tegra_bo_create()
437 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
440 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
441 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
442 return bo; in tegra_bo_create_with_handle()
444 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
446 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
450 drm_gem_object_put(&bo->gem); in tegra_bo_create_with_handle()
452 return bo; in tegra_bo_create_with_handle()
460 struct tegra_bo *bo; in tegra_bo_import() local
463 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
464 if (IS_ERR(bo)) in tegra_bo_import()
465 return bo; in tegra_bo_import()
478 bo->sgt = dma_buf_map_attachment_unlocked(attach, DMA_TO_DEVICE); in tegra_bo_import()
479 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
480 err = PTR_ERR(bo->sgt); in tegra_bo_import()
484 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
488 bo->gem.import_attach = attach; in tegra_bo_import()
492 bo->dma_buf = buf; in tegra_bo_import()
494 return bo; in tegra_bo_import()
497 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
498 dma_buf_unmap_attachment_unlocked(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
503 drm_gem_object_release(&bo->gem); in tegra_bo_import()
504 kfree(bo); in tegra_bo_import()
512 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
515 list_for_each_entry_safe(mapping, tmp, &bo->base.mappings, list) { in tegra_bo_free_object()
524 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
527 dma_buf_unmap_attachment_unlocked(gem->import_attach, bo->sgt, in tegra_bo_free_object()
533 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
535 if (bo->dma_buf) in tegra_bo_free_object()
536 dma_buf_put(bo->dma_buf); in tegra_bo_free_object()
539 kfree(bo); in tegra_bo_free_object()
547 struct tegra_bo *bo; in tegra_bo_dumb_create() local
552 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
554 if (IS_ERR(bo)) in tegra_bo_dumb_create()
555 return PTR_ERR(bo); in tegra_bo_dumb_create()
564 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
568 if (!bo->pages) in tegra_bo_fault()
572 page = bo->pages[offset]; in tegra_bo_fault()
585 struct tegra_bo *bo = to_tegra_bo(gem); in __tegra_gem_mmap() local
587 if (!bo->pages) { in __tegra_gem_mmap()
599 err = dma_mmap_wc(gem->dev->dev, vma, bo->vaddr, bo->iova, in __tegra_gem_mmap()
637 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
644 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
645 if (sg_alloc_table_from_pages(sgt, bo->pages, bo->num_pages, in tegra_gem_prime_map_dma_buf()
649 if (dma_get_sgtable(attach->dev, sgt, bo->vaddr, bo->iova, in tegra_gem_prime_map_dma_buf()
670 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
672 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
688 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_begin_cpu_access() local
691 if (bo->pages) in tegra_gem_prime_begin_cpu_access()
692 dma_sync_sgtable_for_cpu(drm->dev, bo->sgt, DMA_FROM_DEVICE); in tegra_gem_prime_begin_cpu_access()
701 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_end_cpu_access() local
704 if (bo->pages) in tegra_gem_prime_end_cpu_access()
705 dma_sync_sgtable_for_device(drm->dev, bo->sgt, DMA_TO_DEVICE); in tegra_gem_prime_end_cpu_access()
725 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
728 vaddr = tegra_bo_mmap(&bo->base); in tegra_gem_prime_vmap()
740 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vunmap() local
742 tegra_bo_munmap(&bo->base, map->vaddr); in tegra_gem_prime_vunmap()
774 struct tegra_bo *bo; in tegra_gem_prime_import() local
785 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
786 if (IS_ERR(bo)) in tegra_gem_prime_import()
787 return ERR_CAST(bo); in tegra_gem_prime_import()
789 return &bo->gem; in tegra_gem_prime_import()
795 struct tegra_bo *bo; in tegra_gem_lookup() local
801 bo = to_tegra_bo(gem); in tegra_gem_lookup()
802 return &bo->base; in tegra_gem_lookup()