Commit 24f6fe79 authored by Marek Szyprowski's avatar Marek Szyprowski Committed by Inki Dae

drm/exynos: gem: rework scatter-list contiguity check on prime import

Explicitly check if the imported buffer has been mapped as contiguous in
the DMA address space, what is required by all Exynos DRM CRTC drivers.
While touching this, set buffer flags depending on the availability of
the IOMMU.
Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: default avatarInki Dae <inki.dae@samsung.com>
parent 3a2fe566
...@@ -458,6 +458,29 @@ exynos_drm_gem_prime_import_sg_table(struct drm_device *dev, ...@@ -458,6 +458,29 @@ exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
int npages; int npages;
int ret; int ret;
if (sgt->nents < 1)
return ERR_PTR(-EINVAL);
/*
* Check if the provided buffer has been mapped as contiguous
* into DMA address space.
*/
if (sgt->nents > 1) {
dma_addr_t next_addr = sg_dma_address(sgt->sgl);
struct scatterlist *s;
unsigned int i;
for_each_sg(sgt->sgl, s, sgt->nents, i) {
if (!sg_dma_len(s))
break;
if (sg_dma_address(s) != next_addr) {
DRM_ERROR("buffer chunks must be mapped contiguously");
return ERR_PTR(-EINVAL);
}
next_addr = sg_dma_address(s) + sg_dma_len(s);
}
}
exynos_gem = exynos_drm_gem_init(dev, attach->dmabuf->size); exynos_gem = exynos_drm_gem_init(dev, attach->dmabuf->size);
if (IS_ERR(exynos_gem)) { if (IS_ERR(exynos_gem)) {
ret = PTR_ERR(exynos_gem); ret = PTR_ERR(exynos_gem);
...@@ -480,18 +503,15 @@ exynos_drm_gem_prime_import_sg_table(struct drm_device *dev, ...@@ -480,18 +503,15 @@ exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
exynos_gem->sgt = sgt; exynos_gem->sgt = sgt;
if (sgt->nents == 1) { /*
/* always physically continuous memory if sgt->nents is 1. */ * Buffer has been mapped as contiguous into DMA address space,
exynos_gem->flags |= EXYNOS_BO_CONTIG; * but if there is IOMMU, it can be either CONTIG or NONCONTIG.
} else { * We assume a simplified logic below:
/* */
* this case could be CONTIG or NONCONTIG type but for now if (is_drm_iommu_supported(dev))
* sets NONCONTIG.
* TODO. we have to find a way that exporter can notify
* the type of its own buffer to importer.
*/
exynos_gem->flags |= EXYNOS_BO_NONCONTIG; exynos_gem->flags |= EXYNOS_BO_NONCONTIG;
} else
exynos_gem->flags |= EXYNOS_BO_CONTIG;
return &exynos_gem->base; return &exynos_gem->base;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment