Lines Matching refs:bo

23 static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo)  in host1x_to_tegra_bo()  argument
25 return container_of(bo, struct tegra_bo, base); in host1x_to_tegra_bo()
28 static void tegra_bo_put(struct host1x_bo *bo) in tegra_bo_put() argument
30 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_put()
38 static dma_addr_t tegra_bo_pin(struct host1x_bo *bo, struct sg_table **sgt) in tegra_bo_pin() argument
40 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_pin()
45 static void tegra_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt) in tegra_bo_unpin() argument
49 static void *tegra_bo_mmap(struct host1x_bo *bo) in tegra_bo_mmap() argument
51 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_mmap()
56 static void tegra_bo_munmap(struct host1x_bo *bo, void *addr) in tegra_bo_munmap() argument
60 static void *tegra_bo_kmap(struct host1x_bo *bo, unsigned int page) in tegra_bo_kmap() argument
62 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_kmap()
67 static void tegra_bo_kunmap(struct host1x_bo *bo, unsigned int page, in tegra_bo_kunmap() argument
72 static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) in tegra_bo_get() argument
74 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_get()
81 return bo; in tegra_bo_get()
95 static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_map() argument
100 if (bo->mm) in tegra_bo_iommu_map()
103 bo->mm = kzalloc(sizeof(*bo->mm), GFP_KERNEL); in tegra_bo_iommu_map()
104 if (!bo->mm) in tegra_bo_iommu_map()
107 err = drm_mm_insert_node_generic(&tegra->mm, bo->mm, bo->gem.size, in tegra_bo_iommu_map()
115 bo->paddr = bo->mm->start; in tegra_bo_iommu_map()
117 err = iommu_map_sg(tegra->domain, bo->paddr, bo->sgt->sgl, in tegra_bo_iommu_map()
118 bo->sgt->nents, prot); in tegra_bo_iommu_map()
124 bo->size = err; in tegra_bo_iommu_map()
129 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_map()
131 kfree(bo->mm); in tegra_bo_iommu_map()
135 static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_unmap() argument
137 if (!bo->mm) in tegra_bo_iommu_unmap()
140 iommu_unmap(tegra->domain, bo->paddr, bo->size); in tegra_bo_iommu_unmap()
141 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_unmap()
142 kfree(bo->mm); in tegra_bo_iommu_unmap()
150 struct tegra_bo *bo; in tegra_bo_alloc_object() local
153 bo = kzalloc(sizeof(*bo), GFP_KERNEL); in tegra_bo_alloc_object()
154 if (!bo) in tegra_bo_alloc_object()
157 host1x_bo_init(&bo->base, &tegra_bo_ops); in tegra_bo_alloc_object()
160 err = drm_gem_object_init(drm, &bo->gem, size); in tegra_bo_alloc_object()
164 err = drm_gem_create_mmap_offset(&bo->gem); in tegra_bo_alloc_object()
168 return bo; in tegra_bo_alloc_object()
171 drm_gem_object_release(&bo->gem); in tegra_bo_alloc_object()
173 kfree(bo); in tegra_bo_alloc_object()
177 static void tegra_bo_free(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_free() argument
179 if (bo->pages) { in tegra_bo_free()
180 drm_gem_put_pages(&bo->gem, bo->pages, true, true); in tegra_bo_free()
181 sg_free_table(bo->sgt); in tegra_bo_free()
182 kfree(bo->sgt); in tegra_bo_free()
183 } else if (bo->vaddr) { in tegra_bo_free()
184 dma_free_writecombine(drm->dev, bo->gem.size, bo->vaddr, in tegra_bo_free()
185 bo->paddr); in tegra_bo_free()
189 static int tegra_bo_get_pages(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_get_pages() argument
195 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
196 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
197 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
199 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
201 sgt = drm_prime_pages_to_sg(bo->pages, bo->num_pages); in tegra_bo_get_pages()
220 bo->sgt = sgt; in tegra_bo_get_pages()
229 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
233 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
239 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
243 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
245 tegra_bo_free(drm, bo); in tegra_bo_alloc()
249 size_t size = bo->gem.size; in tegra_bo_alloc()
251 bo->vaddr = dma_alloc_writecombine(drm->dev, size, &bo->paddr, in tegra_bo_alloc()
253 if (!bo->vaddr) { in tegra_bo_alloc()
267 struct tegra_bo *bo; in tegra_bo_create() local
270 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
271 if (IS_ERR(bo)) in tegra_bo_create()
272 return bo; in tegra_bo_create()
274 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
279 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
282 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
284 return bo; in tegra_bo_create()
287 drm_gem_object_release(&bo->gem); in tegra_bo_create()
288 kfree(bo); in tegra_bo_create()
298 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
301 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
302 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
303 return bo; in tegra_bo_create_with_handle()
305 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
307 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
311 drm_gem_object_unreference_unlocked(&bo->gem); in tegra_bo_create_with_handle()
313 return bo; in tegra_bo_create_with_handle()
321 struct tegra_bo *bo; in tegra_bo_import() local
324 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
325 if (IS_ERR(bo)) in tegra_bo_import()
326 return bo; in tegra_bo_import()
336 bo->sgt = dma_buf_map_attachment(attach, DMA_TO_DEVICE); in tegra_bo_import()
337 if (!bo->sgt) { in tegra_bo_import()
342 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
343 err = PTR_ERR(bo->sgt); in tegra_bo_import()
348 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
352 if (bo->sgt->nents > 1) { in tegra_bo_import()
357 bo->paddr = sg_dma_address(bo->sgt->sgl); in tegra_bo_import()
360 bo->gem.import_attach = attach; in tegra_bo_import()
362 return bo; in tegra_bo_import()
365 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
366 dma_buf_unmap_attachment(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
371 drm_gem_object_release(&bo->gem); in tegra_bo_import()
372 kfree(bo); in tegra_bo_import()
379 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
382 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
385 dma_buf_unmap_attachment(gem->import_attach, bo->sgt, in tegra_bo_free_object()
389 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
393 kfree(bo); in tegra_bo_free_object()
401 struct tegra_bo *bo; in tegra_bo_dumb_create() local
406 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
408 if (IS_ERR(bo)) in tegra_bo_dumb_create()
409 return PTR_ERR(bo); in tegra_bo_dumb_create()
418 struct tegra_bo *bo; in tegra_bo_dumb_map_offset() local
429 bo = to_tegra_bo(gem); in tegra_bo_dumb_map_offset()
431 *offset = drm_vma_node_offset_addr(&bo->gem.vma_node); in tegra_bo_dumb_map_offset()
443 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
448 if (!bo->pages) in tegra_bo_fault()
452 page = bo->pages[offset]; in tegra_bo_fault()
479 struct tegra_bo *bo; in tegra_drm_mmap() local
487 bo = to_tegra_bo(gem); in tegra_drm_mmap()
489 if (!bo->pages) { in tegra_drm_mmap()
495 ret = dma_mmap_writecombine(gem->dev->dev, vma, bo->vaddr, in tegra_drm_mmap()
496 bo->paddr, gem->size); in tegra_drm_mmap()
520 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
527 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
531 if (sg_alloc_table(sgt, bo->num_pages, GFP_KERNEL)) in tegra_gem_prime_map_dma_buf()
534 for_each_sg(sgt->sgl, sg, bo->num_pages, i) in tegra_gem_prime_map_dma_buf()
535 sg_set_page(sg, bo->pages[i], PAGE_SIZE, 0); in tegra_gem_prime_map_dma_buf()
543 sg_dma_address(sgt->sgl) = bo->paddr; in tegra_gem_prime_map_dma_buf()
560 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
562 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
604 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
606 return bo->vaddr; in tegra_gem_prime_vmap()
643 struct tegra_bo *bo; in tegra_gem_prime_import() local
654 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
655 if (IS_ERR(bo)) in tegra_gem_prime_import()
656 return ERR_CAST(bo); in tegra_gem_prime_import()
658 return &bo->gem; in tegra_gem_prime_import()