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
194 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
195 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
196 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
198 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
200 bo->sgt = drm_prime_pages_to_sg(bo->pages, bo->num_pages); in tegra_bo_get_pages()
201 if (IS_ERR(bo->sgt)) in tegra_bo_get_pages()
211 for_each_sg(bo->sgt->sgl, s, bo->sgt->nents, i) in tegra_bo_get_pages()
214 dma_sync_sg_for_device(drm->dev, bo->sgt->sgl, bo->sgt->nents, in tegra_bo_get_pages()
220 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
221 return PTR_ERR(bo->sgt); in tegra_bo_get_pages()
224 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
230 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
234 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
236 tegra_bo_free(drm, bo); in tegra_bo_alloc()
240 size_t size = bo->gem.size; in tegra_bo_alloc()
242 bo->vaddr = dma_alloc_writecombine(drm->dev, size, &bo->paddr, in tegra_bo_alloc()
244 if (!bo->vaddr) { in tegra_bo_alloc()
258 struct tegra_bo *bo; in tegra_bo_create() local
261 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
262 if (IS_ERR(bo)) in tegra_bo_create()
263 return bo; in tegra_bo_create()
265 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
270 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
273 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
275 return bo; in tegra_bo_create()
278 drm_gem_object_release(&bo->gem); in tegra_bo_create()
279 kfree(bo); in tegra_bo_create()
289 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
292 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
293 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
294 return bo; in tegra_bo_create_with_handle()
296 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
298 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
302 drm_gem_object_unreference_unlocked(&bo->gem); in tegra_bo_create_with_handle()
304 return bo; in tegra_bo_create_with_handle()
312 struct tegra_bo *bo; in tegra_bo_import() local
315 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
316 if (IS_ERR(bo)) in tegra_bo_import()
317 return bo; in tegra_bo_import()
327 bo->sgt = dma_buf_map_attachment(attach, DMA_TO_DEVICE); in tegra_bo_import()
328 if (!bo->sgt) { in tegra_bo_import()
333 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
334 err = PTR_ERR(bo->sgt); in tegra_bo_import()
339 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
343 if (bo->sgt->nents > 1) { in tegra_bo_import()
348 bo->paddr = sg_dma_address(bo->sgt->sgl); in tegra_bo_import()
351 bo->gem.import_attach = attach; in tegra_bo_import()
353 return bo; in tegra_bo_import()
356 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
357 dma_buf_unmap_attachment(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
362 drm_gem_object_release(&bo->gem); in tegra_bo_import()
363 kfree(bo); in tegra_bo_import()
370 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
373 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
376 dma_buf_unmap_attachment(gem->import_attach, bo->sgt, in tegra_bo_free_object()
380 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
384 kfree(bo); in tegra_bo_free_object()
392 struct tegra_bo *bo; in tegra_bo_dumb_create() local
397 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
399 if (IS_ERR(bo)) in tegra_bo_dumb_create()
400 return PTR_ERR(bo); in tegra_bo_dumb_create()
409 struct tegra_bo *bo; in tegra_bo_dumb_map_offset() local
420 bo = to_tegra_bo(gem); in tegra_bo_dumb_map_offset()
422 *offset = drm_vma_node_offset_addr(&bo->gem.vma_node); in tegra_bo_dumb_map_offset()
434 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
439 if (!bo->pages) in tegra_bo_fault()
443 page = bo->pages[offset]; in tegra_bo_fault()
470 struct tegra_bo *bo; in tegra_drm_mmap() local
478 bo = to_tegra_bo(gem); in tegra_drm_mmap()
480 if (!bo->pages) { in tegra_drm_mmap()
486 ret = dma_mmap_writecombine(gem->dev->dev, vma, bo->vaddr, in tegra_drm_mmap()
487 bo->paddr, gem->size); in tegra_drm_mmap()
511 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
518 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
522 if (sg_alloc_table(sgt, bo->num_pages, GFP_KERNEL)) in tegra_gem_prime_map_dma_buf()
525 for_each_sg(sgt->sgl, sg, bo->num_pages, i) in tegra_gem_prime_map_dma_buf()
526 sg_set_page(sg, bo->pages[i], PAGE_SIZE, 0); in tegra_gem_prime_map_dma_buf()
534 sg_dma_address(sgt->sgl) = bo->paddr; in tegra_gem_prime_map_dma_buf()
551 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
553 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
595 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
597 return bo->vaddr; in tegra_gem_prime_vmap()
634 struct tegra_bo *bo; in tegra_gem_prime_import() local
645 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
646 if (IS_ERR(bo)) in tegra_gem_prime_import()
647 return ERR_CAST(bo); in tegra_gem_prime_import()
649 return &bo->gem; in tegra_gem_prime_import()