Lines Matching refs:bo

23 static void tegra_bo_put(struct host1x_bo *bo)  in tegra_bo_put()  argument
25 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_put()
53 static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, in tegra_bo_pin() argument
56 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_pin()
132 static void *tegra_bo_mmap(struct host1x_bo *bo) in tegra_bo_mmap() argument
134 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_mmap()
149 static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) in tegra_bo_munmap() argument
151 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_munmap()
162 static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) in tegra_bo_get() argument
164 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_get()
168 return bo; in tegra_bo_get()
180 static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_map() argument
185 if (bo->mm) in tegra_bo_iommu_map()
188 bo->mm = kzalloc(sizeof(*bo->mm), GFP_KERNEL); in tegra_bo_iommu_map()
189 if (!bo->mm) in tegra_bo_iommu_map()
195 bo->mm, bo->gem.size, PAGE_SIZE, 0, 0); in tegra_bo_iommu_map()
202 bo->iova = bo->mm->start; in tegra_bo_iommu_map()
204 bo->size = iommu_map_sgtable(tegra->domain, bo->iova, bo->sgt, prot); in tegra_bo_iommu_map()
205 if (!bo->size) { in tegra_bo_iommu_map()
216 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_map()
219 kfree(bo->mm); in tegra_bo_iommu_map()
223 static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_unmap() argument
225 if (!bo->mm) in tegra_bo_iommu_unmap()
229 iommu_unmap(tegra->domain, bo->iova, bo->size); in tegra_bo_iommu_unmap()
230 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_unmap()
233 kfree(bo->mm); in tegra_bo_iommu_unmap()
247 struct tegra_bo *bo; in tegra_bo_alloc_object() local
250 bo = kzalloc(sizeof(*bo), GFP_KERNEL); in tegra_bo_alloc_object()
251 if (!bo) in tegra_bo_alloc_object()
254 bo->gem.funcs = &tegra_gem_object_funcs; in tegra_bo_alloc_object()
256 host1x_bo_init(&bo->base, &tegra_bo_ops); in tegra_bo_alloc_object()
259 err = drm_gem_object_init(drm, &bo->gem, size); in tegra_bo_alloc_object()
263 err = drm_gem_create_mmap_offset(&bo->gem); in tegra_bo_alloc_object()
267 return bo; in tegra_bo_alloc_object()
270 drm_gem_object_release(&bo->gem); in tegra_bo_alloc_object()
272 kfree(bo); in tegra_bo_alloc_object()
276 static void tegra_bo_free(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_free() argument
278 if (bo->pages) { in tegra_bo_free()
279 dma_unmap_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_free()
280 drm_gem_put_pages(&bo->gem, bo->pages, true, true); in tegra_bo_free()
281 sg_free_table(bo->sgt); in tegra_bo_free()
282 kfree(bo->sgt); in tegra_bo_free()
283 } else if (bo->vaddr) { in tegra_bo_free()
284 dma_free_wc(drm->dev, bo->gem.size, bo->vaddr, bo->iova); in tegra_bo_free()
288 static int tegra_bo_get_pages(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_get_pages() argument
292 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
293 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
294 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
296 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
298 bo->sgt = drm_prime_pages_to_sg(bo->gem.dev, bo->pages, bo->num_pages); in tegra_bo_get_pages()
299 if (IS_ERR(bo->sgt)) { in tegra_bo_get_pages()
300 err = PTR_ERR(bo->sgt); in tegra_bo_get_pages()
304 err = dma_map_sgtable(drm->dev, bo->sgt, DMA_FROM_DEVICE, 0); in tegra_bo_get_pages()
311 sg_free_table(bo->sgt); in tegra_bo_get_pages()
312 kfree(bo->sgt); in tegra_bo_get_pages()
314 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
318 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
324 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
328 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
330 tegra_bo_free(drm, bo); in tegra_bo_alloc()
334 size_t size = bo->gem.size; in tegra_bo_alloc()
336 bo->vaddr = dma_alloc_wc(drm->dev, size, &bo->iova, in tegra_bo_alloc()
338 if (!bo->vaddr) { in tegra_bo_alloc()
352 struct tegra_bo *bo; in tegra_bo_create() local
355 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
356 if (IS_ERR(bo)) in tegra_bo_create()
357 return bo; in tegra_bo_create()
359 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
364 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
367 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
369 return bo; in tegra_bo_create()
372 drm_gem_object_release(&bo->gem); in tegra_bo_create()
373 kfree(bo); in tegra_bo_create()
383 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
386 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
387 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
388 return bo; in tegra_bo_create_with_handle()
390 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
392 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
396 drm_gem_object_put(&bo->gem); in tegra_bo_create_with_handle()
398 return bo; in tegra_bo_create_with_handle()
406 struct tegra_bo *bo; in tegra_bo_import() local
409 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
410 if (IS_ERR(bo)) in tegra_bo_import()
411 return bo; in tegra_bo_import()
421 bo->sgt = dma_buf_map_attachment(attach, DMA_TO_DEVICE); in tegra_bo_import()
422 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
423 err = PTR_ERR(bo->sgt); in tegra_bo_import()
428 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
433 bo->gem.import_attach = attach; in tegra_bo_import()
435 return bo; in tegra_bo_import()
438 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
439 dma_buf_unmap_attachment(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
444 drm_gem_object_release(&bo->gem); in tegra_bo_import()
445 kfree(bo); in tegra_bo_import()
452 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
455 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
458 dma_buf_unmap_attachment(gem->import_attach, bo->sgt, in tegra_bo_free_object()
462 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
466 kfree(bo); in tegra_bo_free_object()
474 struct tegra_bo *bo; in tegra_bo_dumb_create() local
479 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
481 if (IS_ERR(bo)) in tegra_bo_dumb_create()
482 return PTR_ERR(bo); in tegra_bo_dumb_create()
491 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
495 if (!bo->pages) in tegra_bo_fault()
499 page = bo->pages[offset]; in tegra_bo_fault()
512 struct tegra_bo *bo = to_tegra_bo(gem); in __tegra_gem_mmap() local
514 if (!bo->pages) { in __tegra_gem_mmap()
526 err = dma_mmap_wc(gem->dev->dev, vma, bo->vaddr, bo->iova, in __tegra_gem_mmap()
565 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
572 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
573 if (sg_alloc_table_from_pages(sgt, bo->pages, bo->num_pages, in tegra_gem_prime_map_dma_buf()
577 if (dma_get_sgtable(attach->dev, sgt, bo->vaddr, bo->iova, in tegra_gem_prime_map_dma_buf()
598 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
600 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
616 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_begin_cpu_access() local
619 if (bo->pages) in tegra_gem_prime_begin_cpu_access()
620 dma_sync_sgtable_for_cpu(drm->dev, bo->sgt, DMA_FROM_DEVICE); in tegra_gem_prime_begin_cpu_access()
629 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_end_cpu_access() local
632 if (bo->pages) in tegra_gem_prime_end_cpu_access()
633 dma_sync_sgtable_for_device(drm->dev, bo->sgt, DMA_TO_DEVICE); in tegra_gem_prime_end_cpu_access()
653 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
655 dma_buf_map_set_vaddr(map, bo->vaddr); in tegra_gem_prime_vmap()
693 struct tegra_bo *bo; in tegra_gem_prime_import() local
704 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
705 if (IS_ERR(bo)) in tegra_gem_prime_import()
706 return ERR_CAST(bo); in tegra_gem_prime_import()
708 return &bo->gem; in tegra_gem_prime_import()
714 struct tegra_bo *bo; in tegra_gem_lookup() local
720 bo = to_tegra_bo(gem); in tegra_gem_lookup()
721 return &bo->base; in tegra_gem_lookup()