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()
30 static dma_addr_t tegra_bo_pin(struct host1x_bo *bo, struct sg_table **sgt) in tegra_bo_pin() argument
32 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_pin()
39 static void tegra_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt) in tegra_bo_unpin() argument
43 static void *tegra_bo_mmap(struct host1x_bo *bo) in tegra_bo_mmap() argument
45 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
58 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_munmap()
68 static void *tegra_bo_kmap(struct host1x_bo *bo, unsigned int page) in tegra_bo_kmap() argument
70 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_kmap()
81 static void tegra_bo_kunmap(struct host1x_bo *bo, unsigned int page, in tegra_bo_kunmap() argument
84 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_kunmap()
94 static struct host1x_bo *tegra_bo_get(struct host1x_bo *bo) in tegra_bo_get() argument
96 struct tegra_bo *obj = host1x_to_tegra_bo(bo); in tegra_bo_get()
100 return bo; in tegra_bo_get()
114 static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_map() argument
119 if (bo->mm) in tegra_bo_iommu_map()
122 bo->mm = kzalloc(sizeof(*bo->mm), GFP_KERNEL); in tegra_bo_iommu_map()
123 if (!bo->mm) in tegra_bo_iommu_map()
129 bo->mm, bo->gem.size, PAGE_SIZE, 0, 0); in tegra_bo_iommu_map()
136 bo->paddr = bo->mm->start; in tegra_bo_iommu_map()
138 bo->size = iommu_map_sg(tegra->domain, bo->paddr, bo->sgt->sgl, in tegra_bo_iommu_map()
139 bo->sgt->nents, prot); in tegra_bo_iommu_map()
140 if (!bo->size) { in tegra_bo_iommu_map()
151 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_map()
154 kfree(bo->mm); in tegra_bo_iommu_map()
158 static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, struct tegra_bo *bo) in tegra_bo_iommu_unmap() argument
160 if (!bo->mm) in tegra_bo_iommu_unmap()
164 iommu_unmap(tegra->domain, bo->paddr, bo->size); in tegra_bo_iommu_unmap()
165 drm_mm_remove_node(bo->mm); in tegra_bo_iommu_unmap()
168 kfree(bo->mm); in tegra_bo_iommu_unmap()
176 struct tegra_bo *bo; in tegra_bo_alloc_object() local
179 bo = kzalloc(sizeof(*bo), GFP_KERNEL); in tegra_bo_alloc_object()
180 if (!bo) in tegra_bo_alloc_object()
183 host1x_bo_init(&bo->base, &tegra_bo_ops); in tegra_bo_alloc_object()
186 err = drm_gem_object_init(drm, &bo->gem, size); in tegra_bo_alloc_object()
190 err = drm_gem_create_mmap_offset(&bo->gem); in tegra_bo_alloc_object()
194 return bo; in tegra_bo_alloc_object()
197 drm_gem_object_release(&bo->gem); in tegra_bo_alloc_object()
199 kfree(bo); in tegra_bo_alloc_object()
203 static void tegra_bo_free(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_free() argument
205 if (bo->pages) { in tegra_bo_free()
206 dma_unmap_sg(drm->dev, bo->sgt->sgl, bo->sgt->nents, in tegra_bo_free()
208 drm_gem_put_pages(&bo->gem, bo->pages, true, true); in tegra_bo_free()
209 sg_free_table(bo->sgt); in tegra_bo_free()
210 kfree(bo->sgt); in tegra_bo_free()
211 } else if (bo->vaddr) { in tegra_bo_free()
212 dma_free_wc(drm->dev, bo->gem.size, bo->vaddr, bo->paddr); in tegra_bo_free()
216 static int tegra_bo_get_pages(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_get_pages() argument
220 bo->pages = drm_gem_get_pages(&bo->gem); in tegra_bo_get_pages()
221 if (IS_ERR(bo->pages)) in tegra_bo_get_pages()
222 return PTR_ERR(bo->pages); in tegra_bo_get_pages()
224 bo->num_pages = bo->gem.size >> PAGE_SHIFT; in tegra_bo_get_pages()
226 bo->sgt = drm_prime_pages_to_sg(bo->pages, bo->num_pages); in tegra_bo_get_pages()
227 if (IS_ERR(bo->sgt)) { in tegra_bo_get_pages()
228 err = PTR_ERR(bo->sgt); in tegra_bo_get_pages()
232 err = dma_map_sg(drm->dev, bo->sgt->sgl, bo->sgt->nents, in tegra_bo_get_pages()
242 sg_free_table(bo->sgt); in tegra_bo_get_pages()
243 kfree(bo->sgt); in tegra_bo_get_pages()
245 drm_gem_put_pages(&bo->gem, bo->pages, false, false); in tegra_bo_get_pages()
249 static int tegra_bo_alloc(struct drm_device *drm, struct tegra_bo *bo) in tegra_bo_alloc() argument
255 err = tegra_bo_get_pages(drm, bo); in tegra_bo_alloc()
259 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_alloc()
261 tegra_bo_free(drm, bo); in tegra_bo_alloc()
265 size_t size = bo->gem.size; in tegra_bo_alloc()
267 bo->vaddr = dma_alloc_wc(drm->dev, size, &bo->paddr, in tegra_bo_alloc()
269 if (!bo->vaddr) { in tegra_bo_alloc()
283 struct tegra_bo *bo; in tegra_bo_create() local
286 bo = tegra_bo_alloc_object(drm, size); in tegra_bo_create()
287 if (IS_ERR(bo)) in tegra_bo_create()
288 return bo; in tegra_bo_create()
290 err = tegra_bo_alloc(drm, bo); in tegra_bo_create()
295 bo->tiling.mode = TEGRA_BO_TILING_MODE_TILED; in tegra_bo_create()
298 bo->flags |= TEGRA_BO_BOTTOM_UP; in tegra_bo_create()
300 return bo; in tegra_bo_create()
303 drm_gem_object_release(&bo->gem); in tegra_bo_create()
304 kfree(bo); in tegra_bo_create()
314 struct tegra_bo *bo; in tegra_bo_create_with_handle() local
317 bo = tegra_bo_create(drm, size, flags); in tegra_bo_create_with_handle()
318 if (IS_ERR(bo)) in tegra_bo_create_with_handle()
319 return bo; in tegra_bo_create_with_handle()
321 err = drm_gem_handle_create(file, &bo->gem, handle); in tegra_bo_create_with_handle()
323 tegra_bo_free_object(&bo->gem); in tegra_bo_create_with_handle()
327 drm_gem_object_put_unlocked(&bo->gem); in tegra_bo_create_with_handle()
329 return bo; in tegra_bo_create_with_handle()
337 struct tegra_bo *bo; in tegra_bo_import() local
340 bo = tegra_bo_alloc_object(drm, buf->size); in tegra_bo_import()
341 if (IS_ERR(bo)) in tegra_bo_import()
342 return bo; in tegra_bo_import()
352 bo->sgt = dma_buf_map_attachment(attach, DMA_TO_DEVICE); in tegra_bo_import()
353 if (IS_ERR(bo->sgt)) { in tegra_bo_import()
354 err = PTR_ERR(bo->sgt); in tegra_bo_import()
359 err = tegra_bo_iommu_map(tegra, bo); in tegra_bo_import()
363 if (bo->sgt->nents > 1) { in tegra_bo_import()
368 bo->paddr = sg_dma_address(bo->sgt->sgl); in tegra_bo_import()
371 bo->gem.import_attach = attach; in tegra_bo_import()
373 return bo; in tegra_bo_import()
376 if (!IS_ERR_OR_NULL(bo->sgt)) in tegra_bo_import()
377 dma_buf_unmap_attachment(attach, bo->sgt, DMA_TO_DEVICE); in tegra_bo_import()
382 drm_gem_object_release(&bo->gem); in tegra_bo_import()
383 kfree(bo); in tegra_bo_import()
390 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_free_object() local
393 tegra_bo_iommu_unmap(tegra, bo); in tegra_bo_free_object()
396 dma_buf_unmap_attachment(gem->import_attach, bo->sgt, in tegra_bo_free_object()
400 tegra_bo_free(gem->dev, bo); in tegra_bo_free_object()
404 kfree(bo); in tegra_bo_free_object()
412 struct tegra_bo *bo; in tegra_bo_dumb_create() local
417 bo = tegra_bo_create_with_handle(file, drm, args->size, 0, in tegra_bo_dumb_create()
419 if (IS_ERR(bo)) in tegra_bo_dumb_create()
420 return PTR_ERR(bo); in tegra_bo_dumb_create()
429 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_bo_fault() local
433 if (!bo->pages) in tegra_bo_fault()
437 page = bo->pages[offset]; in tegra_bo_fault()
450 struct tegra_bo *bo = to_tegra_bo(gem); in __tegra_gem_mmap() local
452 if (!bo->pages) { in __tegra_gem_mmap()
464 err = dma_mmap_wc(gem->dev->dev, vma, bo->vaddr, bo->paddr, in __tegra_gem_mmap()
503 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_map_dma_buf() local
510 if (bo->pages) { in tegra_gem_prime_map_dma_buf()
514 if (sg_alloc_table(sgt, bo->num_pages, GFP_KERNEL)) in tegra_gem_prime_map_dma_buf()
517 for_each_sg(sgt->sgl, sg, bo->num_pages, i) in tegra_gem_prime_map_dma_buf()
518 sg_set_page(sg, bo->pages[i], PAGE_SIZE, 0); in tegra_gem_prime_map_dma_buf()
526 sg_dma_address(sgt->sgl) = bo->paddr; in tegra_gem_prime_map_dma_buf()
543 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_unmap_dma_buf() local
545 if (bo->pages) in tegra_gem_prime_unmap_dma_buf()
561 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_begin_cpu_access() local
564 if (bo->pages) in tegra_gem_prime_begin_cpu_access()
565 dma_sync_sg_for_cpu(drm->dev, bo->sgt->sgl, bo->sgt->nents, in tegra_gem_prime_begin_cpu_access()
575 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_end_cpu_access() local
578 if (bo->pages) in tegra_gem_prime_end_cpu_access()
579 dma_sync_sg_for_device(drm->dev, bo->sgt->sgl, bo->sgt->nents, in tegra_gem_prime_end_cpu_access()
610 struct tegra_bo *bo = to_tegra_bo(gem); in tegra_gem_prime_vmap() local
612 return bo->vaddr; in tegra_gem_prime_vmap()
651 struct tegra_bo *bo; in tegra_gem_prime_import() local
662 bo = tegra_bo_import(drm, buf); in tegra_gem_prime_import()
663 if (IS_ERR(bo)) in tegra_gem_prime_import()
664 return ERR_CAST(bo); in tegra_gem_prime_import()
666 return &bo->gem; in tegra_gem_prime_import()