Lines Matching +full:non +full:- +full:contiguous
1 // SPDX-License-Identifier: GPL-2.0-or-later
9 #include <linux/dma-buf.h>
27 struct drm_device *dev = exynos_gem->base.dev; in exynos_drm_alloc_buf()
30 if (exynos_gem->dma_addr) { in exynos_drm_alloc_buf()
36 * if EXYNOS_BO_CONTIG, fully physically contiguous memory in exynos_drm_alloc_buf()
37 * region will be allocated else physically contiguous in exynos_drm_alloc_buf()
40 if (!(exynos_gem->flags & EXYNOS_BO_NONCONTIG)) in exynos_drm_alloc_buf()
47 if (exynos_gem->flags & EXYNOS_BO_WC || in exynos_drm_alloc_buf()
48 !(exynos_gem->flags & EXYNOS_BO_CACHABLE)) in exynos_drm_alloc_buf()
55 exynos_gem->dma_attrs = attr; in exynos_drm_alloc_buf()
56 exynos_gem->cookie = dma_alloc_attrs(to_dma_dev(dev), exynos_gem->size, in exynos_drm_alloc_buf()
57 &exynos_gem->dma_addr, GFP_KERNEL, in exynos_drm_alloc_buf()
58 exynos_gem->dma_attrs); in exynos_drm_alloc_buf()
59 if (!exynos_gem->cookie) { in exynos_drm_alloc_buf()
61 return -ENOMEM; in exynos_drm_alloc_buf()
65 exynos_gem->kvaddr = exynos_gem->cookie; in exynos_drm_alloc_buf()
68 (unsigned long)exynos_gem->dma_addr, exynos_gem->size); in exynos_drm_alloc_buf()
74 struct drm_device *dev = exynos_gem->base.dev; in exynos_drm_free_buf()
76 if (!exynos_gem->dma_addr) { in exynos_drm_free_buf()
77 DRM_DEV_DEBUG_KMS(dev->dev, "dma_addr is invalid.\n"); in exynos_drm_free_buf()
81 DRM_DEV_DEBUG_KMS(dev->dev, "dma_addr(0x%lx), size(0x%lx)\n", in exynos_drm_free_buf()
82 (unsigned long)exynos_gem->dma_addr, exynos_gem->size); in exynos_drm_free_buf()
84 dma_free_attrs(to_dma_dev(dev), exynos_gem->size, exynos_gem->cookie, in exynos_drm_free_buf()
85 (dma_addr_t)exynos_gem->dma_addr, in exynos_drm_free_buf()
86 exynos_gem->dma_attrs); in exynos_drm_free_buf()
103 DRM_DEV_DEBUG_KMS(to_dma_dev(obj->dev), "gem handle = 0x%x\n", *handle); in exynos_drm_gem_handle_create()
105 /* drop reference from allocate - handle holds it now. */ in exynos_drm_gem_handle_create()
113 struct drm_gem_object *obj = &exynos_gem->base; in exynos_drm_gem_destroy()
115 DRM_DEV_DEBUG_KMS(to_dma_dev(obj->dev), "handle count = %d\n", in exynos_drm_gem_destroy()
116 obj->handle_count); in exynos_drm_gem_destroy()
124 if (obj->import_attach) in exynos_drm_gem_destroy()
125 drm_prime_gem_destroy(obj, exynos_gem->sgt); in exynos_drm_gem_destroy()
156 return ERR_PTR(-ENOMEM); in exynos_drm_gem_init()
158 exynos_gem->size = size; in exynos_drm_gem_init()
159 obj = &exynos_gem->base; in exynos_drm_gem_init()
161 obj->funcs = &exynos_drm_gem_object_funcs; in exynos_drm_gem_init()
165 DRM_DEV_ERROR(dev->dev, "failed to initialize gem object\n"); in exynos_drm_gem_init()
177 DRM_DEV_DEBUG_KMS(dev->dev, "created file object = %pK\n", obj->filp); in exynos_drm_gem_init()
191 DRM_DEV_ERROR(dev->dev, in exynos_drm_gem_create()
193 return ERR_PTR(-EINVAL); in exynos_drm_gem_create()
197 DRM_DEV_ERROR(dev->dev, "invalid GEM buffer size: %lu\n", size); in exynos_drm_gem_create()
198 return ERR_PTR(-EINVAL); in exynos_drm_gem_create()
210 * contiguous anyway, so drop EXYNOS_BO_NONCONTIG flag in exynos_drm_gem_create()
213 …DRM_WARN("Non-contiguous allocation is not supported without IOMMU, falling back to contiguous buf… in exynos_drm_gem_create()
217 exynos_gem->flags = flags; in exynos_drm_gem_create()
221 drm_gem_object_release(&exynos_gem->base); in exynos_drm_gem_create()
236 exynos_gem = exynos_drm_gem_create(dev, args->flags, args->size, false); in exynos_drm_gem_create_ioctl()
240 ret = exynos_drm_gem_handle_create(&exynos_gem->base, file_priv, in exynos_drm_gem_create_ioctl()
241 &args->handle); in exynos_drm_gem_create_ioctl()
255 return drm_gem_dumb_map_offset(file_priv, dev, args->handle, in exynos_drm_gem_map_ioctl()
256 &args->offset); in exynos_drm_gem_map_ioctl()
273 struct drm_device *drm_dev = exynos_gem->base.dev; in exynos_drm_gem_mmap_buffer()
278 vma->vm_pgoff = 0; in exynos_drm_gem_mmap_buffer()
280 vm_size = vma->vm_end - vma->vm_start; in exynos_drm_gem_mmap_buffer()
282 /* check if user-requested size is valid. */ in exynos_drm_gem_mmap_buffer()
283 if (vm_size > exynos_gem->size) in exynos_drm_gem_mmap_buffer()
284 return -EINVAL; in exynos_drm_gem_mmap_buffer()
286 ret = dma_mmap_attrs(to_dma_dev(drm_dev), vma, exynos_gem->cookie, in exynos_drm_gem_mmap_buffer()
287 exynos_gem->dma_addr, exynos_gem->size, in exynos_drm_gem_mmap_buffer()
288 exynos_gem->dma_attrs); in exynos_drm_gem_mmap_buffer()
304 obj = drm_gem_object_lookup(file_priv, args->handle); in exynos_drm_gem_get_ioctl()
306 DRM_DEV_ERROR(dev->dev, "failed to lookup gem object.\n"); in exynos_drm_gem_get_ioctl()
307 return -EINVAL; in exynos_drm_gem_get_ioctl()
312 args->flags = exynos_gem->flags; in exynos_drm_gem_get_ioctl()
313 args->size = exynos_gem->size; in exynos_drm_gem_get_ioctl()
335 * - this callback would be called by user application in exynos_drm_gem_dumb_create()
339 args->pitch = args->width * ((args->bpp + 7) / 8); in exynos_drm_gem_dumb_create()
340 args->size = args->pitch * args->height; in exynos_drm_gem_dumb_create()
347 exynos_gem = exynos_drm_gem_create(dev, flags, args->size, false); in exynos_drm_gem_dumb_create()
349 dev_warn(dev->dev, "FB allocation failed.\n"); in exynos_drm_gem_dumb_create()
353 ret = exynos_drm_gem_handle_create(&exynos_gem->base, file_priv, in exynos_drm_gem_dumb_create()
354 &args->handle); in exynos_drm_gem_dumb_create()
368 if (obj->import_attach) in exynos_drm_gem_mmap()
369 return dma_buf_mmap(obj->dma_buf, vma, 0); in exynos_drm_gem_mmap()
373 DRM_DEV_DEBUG_KMS(to_dma_dev(obj->dev), "flags = 0x%x\n", in exynos_drm_gem_mmap()
374 exynos_gem->flags); in exynos_drm_gem_mmap()
376 /* non-cachable as default. */ in exynos_drm_gem_mmap()
377 if (exynos_gem->flags & EXYNOS_BO_CACHABLE) in exynos_drm_gem_mmap()
378 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); in exynos_drm_gem_mmap()
379 else if (exynos_gem->flags & EXYNOS_BO_WC) in exynos_drm_gem_mmap()
380 vma->vm_page_prot = in exynos_drm_gem_mmap()
381 pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); in exynos_drm_gem_mmap()
383 vma->vm_page_prot = in exynos_drm_gem_mmap()
384 pgprot_noncached(vm_get_page_prot(vma->vm_flags)); in exynos_drm_gem_mmap()
398 /* low-level interface prime helpers */
408 struct drm_device *drm_dev = obj->dev; in exynos_drm_gem_prime_get_sg_table()
414 return ERR_PTR(-ENOMEM); in exynos_drm_gem_prime_get_sg_table()
416 ret = dma_get_sgtable_attrs(to_dma_dev(drm_dev), sgt, exynos_gem->cookie, in exynos_drm_gem_prime_get_sg_table()
417 exynos_gem->dma_addr, exynos_gem->size, in exynos_drm_gem_prime_get_sg_table()
418 exynos_gem->dma_attrs); in exynos_drm_gem_prime_get_sg_table()
435 /* check if the entries in the sg_table are contiguous */ in exynos_drm_gem_prime_import_sg_table()
436 if (drm_prime_get_contiguous_size(sgt) < attach->dmabuf->size) { in exynos_drm_gem_prime_import_sg_table()
438 return ERR_PTR(-EINVAL); in exynos_drm_gem_prime_import_sg_table()
441 exynos_gem = exynos_drm_gem_init(dev, attach->dmabuf->size); in exynos_drm_gem_prime_import_sg_table()
446 * Buffer has been mapped as contiguous into DMA address space, in exynos_drm_gem_prime_import_sg_table()
451 exynos_gem->flags |= EXYNOS_BO_NONCONTIG; in exynos_drm_gem_prime_import_sg_table()
453 exynos_gem->flags |= EXYNOS_BO_CONTIG; in exynos_drm_gem_prime_import_sg_table()
455 exynos_gem->dma_addr = sg_dma_address(sgt->sgl); in exynos_drm_gem_prime_import_sg_table()
456 exynos_gem->sgt = sgt; in exynos_drm_gem_prime_import_sg_table()
457 return &exynos_gem->base; in exynos_drm_gem_prime_import_sg_table()