Lines Matching refs:bo

26 static void tegra_bo_put(struct host1x_bo *bo)  in tegra_bo_put()  argument
28 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_put()
56 static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, in tegra_bo_pin() argument
59 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_pin()
135 static void *tegra_bo_mmap(struct host1x_bo *bo) in tegra_bo_mmap() argument
137 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_mmap()
152 static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) in tegra_bo_munmap() argument
154 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_munmap()
165 static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) in tegra_bo_get() argument
167 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_get()
171 return bo; in tegra_bo_get()
183 static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_map() argument
188 if (bo->mm) in tegra_bo_iommu_map()
191 bo->mm = kzalloc(sizeof(*bo->mm), GFP_KERNEL); in tegra_bo_iommu_map()
192 if (!bo->mm) in tegra_bo_iommu_map()
198 bo->mm, bo->gem.size, PAGE_SIZE, 0, 0); in tegra_bo_iommu_map()
205 bo->iova = bo->mm->start; in tegra_bo_iommu_map()
207 bo->size = iommu_map_sgtable(tegra->domain, bo->iova, bo->sgt, prot); in tegra_bo_iommu_map()
208 if (!bo->size) { in tegra_bo_iommu_map()
219 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_map()
222 kfree(bo->mm); in tegra_bo_iommu_map()
226 static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_unmap() argument
228 if (!bo->mm) in tegra_bo_iommu_unmap()
232 iommu_unmap(tegra->domain, bo->iova, bo->size); in tegra_bo_iommu_unmap()
233 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_unmap()
236 kfree(bo->mm); in tegra_bo_iommu_unmap()
250 struct tegra_bo *bo; in tegra_bo_alloc_object() local
253 bo = kzalloc(sizeof(*bo), GFP_KERNEL); in tegra_bo_alloc_object()
254 if (!bo) in tegra_bo_alloc_object()
257 bo->gem.funcs = &tegra_gem_object_funcs; in tegra_bo_alloc_object()
259 host1x_bo_init(&bo->base, &tegra_bo_ops); in tegra_bo_alloc_object()
262 err = drm_gem_object_init(drm, &bo->gem, size); in tegra_bo_alloc_object()
266 err = drm_gem_create_mmap_offset(&bo->gem); in tegra_bo_alloc_object()
270 return bo; in tegra_bo_alloc_object()
273 drm_gem_object_release(&bo->gem); in tegra_bo_alloc_object()
275 kfree(bo); in tegra_bo_alloc_object()
279 static void tegra_bo_free(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_free() argument
281 if (bo->pages) { in tegra_bo_free()
282 dma_unmap_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_free()
283 drm_gem_put_pages(&bo->gem, bo->pages, true, true); in tegra_bo_free()
284 sg_free_table(bo->sgt); in tegra_bo_free()
285 kfree(bo->sgt); in tegra_bo_free()
286 } else if (bo->vaddr) { in tegra_bo_free()
287 dma_free_wc(drm->dev, bo->gem.size, bo->vaddr, bo->iova); in tegra_bo_free()
291 static int tegra_bo_get_pages(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_get_pages() argument
295 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
296 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
297 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
299 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
301 bo->sgt = drm_prime_pages_to_sg(bo->gem.dev, bo->pages, bo->num_pages); in tegra_bo_get_pages()
302 if (IS_ERR(bo->sgt)) { in tegra_bo_get_pages()
303 err = PTR_ERR(bo->sgt); in tegra_bo_get_pages()
307 err = dma_map_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_get_pages()
314 sg_free_table(bo->sgt); in tegra_bo_get_pages()
315 kfree(bo->sgt); in tegra_bo_get_pages()
317 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
321 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
327 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
331 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
333 tegra_bo_free(drm, bo); in tegra_bo_alloc()
337 size_t size = bo->gem.size; in tegra_bo_alloc()
339 bo->vaddr = dma_alloc_wc(drm->dev, size, &bo->iova, in tegra_bo_alloc()
341 if (!bo->vaddr) { in tegra_bo_alloc()
355 struct tegra_bo *bo; in tegra_bo_create() local
358 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
359 if (IS_ERR(bo)) in tegra_bo_create()
360 return bo; in tegra_bo_create()
362 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
367 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
370 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
372 return bo; in tegra_bo_create()
375 drm_gem_object_release(&bo->gem); in tegra_bo_create()
376 kfree(bo); in tegra_bo_create()
386 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
389 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
390 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
391 return bo; in tegra_bo_create_with_handle()
393 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
395 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
399 drm_gem_object_put(&bo->gem); in tegra_bo_create_with_handle()
401 return bo; in tegra_bo_create_with_handle()
409 struct tegra_bo *bo; in tegra_bo_import() local
412 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
413 if (IS_ERR(bo)) in tegra_bo_import()
414 return bo; in tegra_bo_import()
424 bo->sgt = dma_buf_map_attachment(attach, DMA_TO_DEVICE); in tegra_bo_import()
425 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
426 err = PTR_ERR(bo->sgt); in tegra_bo_import()
431 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
436 bo->gem.import_attach = attach; in tegra_bo_import()
438 return bo; in tegra_bo_import()
441 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
442 dma_buf_unmap_attachment(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
447 drm_gem_object_release(&bo->gem); in tegra_bo_import()
448 kfree(bo); in tegra_bo_import()
455 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
458 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
461 dma_buf_unmap_attachment(gem->import_attach, bo->sgt, in tegra_bo_free_object()
465 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
469 kfree(bo); in tegra_bo_free_object()
477 struct tegra_bo *bo; in tegra_bo_dumb_create() local
482 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
484 if (IS_ERR(bo)) in tegra_bo_dumb_create()
485 return PTR_ERR(bo); in tegra_bo_dumb_create()
494 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
498 if (!bo->pages) in tegra_bo_fault()
502 page = bo->pages[offset]; in tegra_bo_fault()
515 struct tegra_bo *bo = to_tegra_bo(gem); in __tegra_gem_mmap() local
517 if (!bo->pages) { in __tegra_gem_mmap()
529 err = dma_mmap_wc(gem->dev->dev, vma, bo->vaddr, bo->iova, in __tegra_gem_mmap()
568 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
575 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
576 if (sg_alloc_table_from_pages(sgt, bo->pages, bo->num_pages, in tegra_gem_prime_map_dma_buf()
580 if (dma_get_sgtable(attach->dev, sgt, bo->vaddr, bo->iova, in tegra_gem_prime_map_dma_buf()
601 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
603 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
619 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_begin_cpu_access() local
622 if (bo->pages) in tegra_gem_prime_begin_cpu_access()
623 dma_sync_sgtable_for_cpu(drm->dev, bo->sgt, DMA_FROM_DEVICE); in tegra_gem_prime_begin_cpu_access()
632 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_end_cpu_access() local
635 if (bo->pages) in tegra_gem_prime_end_cpu_access()
636 dma_sync_sgtable_for_device(drm->dev, bo->sgt, DMA_TO_DEVICE); in tegra_gem_prime_end_cpu_access()
656 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
658 dma_buf_map_set_vaddr(map, bo->vaddr); in tegra_gem_prime_vmap()
696 struct tegra_bo *bo; in tegra_gem_prime_import() local
707 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
708 if (IS_ERR(bo)) in tegra_gem_prime_import()
709 return ERR_CAST(bo); in tegra_gem_prime_import()
711 return &bo->gem; in tegra_gem_prime_import()
717 struct tegra_bo *bo; in tegra_gem_lookup() local
723 bo = to_tegra_bo(gem); in tegra_gem_lookup()
724 return &bo->base; in tegra_gem_lookup()