linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous
@ 2019-07-29  5:33 Alexandre Courbot
  2019-07-29  5:33 ` [PATCH v2 1/2] drm/mediatek: use correct device to import PRIME buffers Alexandre Courbot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexandre Courbot @ 2019-07-29  5:33 UTC (permalink / raw)
  To: CK Hu, Philipp Zabel, David Airlie, Daniel Vetter,
	Matthias Brugger, Tomasz Figa
  Cc: dri-devel, linux-arm-kernel, linux-mediatek, linux-kernel,
	Alexandre Courbot

The default DMA segment size was used when importing PRIME buffers,
which resulted in a chance of them not being contiguous in the virtual
IO space of the device and mtk_gem_prime_import_sg_table() complaining
that the SG table was not contiguous as it expects.

This series fixes this issue by

1) Using the correct DMA device when importing PRIME buffers,
2) Setting a more suitable DMA segment size on the DMA device than the
default 64KB.

Changes since v1:
- Split into two patches,
- Fixed an error path that would have returned 0.

Alexandre Courbot (2):
  drm/mediatek: use correct device to import PRIME buffers
  drm/mediatek: set DMA max segment size

 drivers/gpu/drm/mediatek/mtk_drm_drv.c | 49 ++++++++++++++++++++++++--
 drivers/gpu/drm/mediatek/mtk_drm_drv.h |  2 ++
 2 files changed, 48 insertions(+), 3 deletions(-)

-- 
2.22.0.709.g102302147b-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] drm/mediatek: use correct device to import PRIME buffers
  2019-07-29  5:33 [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous Alexandre Courbot
@ 2019-07-29  5:33 ` Alexandre Courbot
  2019-07-29  5:33 ` [PATCH v2 2/2] drm/mediatek: set DMA max segment size Alexandre Courbot
  2019-08-15  1:40 ` [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous CK Hu
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2019-07-29  5:33 UTC (permalink / raw)
  To: CK Hu, Philipp Zabel, David Airlie, Daniel Vetter,
	Matthias Brugger, Tomasz Figa
  Cc: dri-devel, linux-arm-kernel, linux-mediatek, linux-kernel,
	Alexandre Courbot

PRIME buffers should be imported using the DMA device. To this end, use
a custom import function that mimics drm_gem_prime_import_dev(), but
passes the correct device.

Fixes: 119f5173628aa ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 95fdbd0fbcac..8b18a00a58c7 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -320,6 +320,18 @@ static const struct file_operations mtk_drm_fops = {
 	.compat_ioctl = drm_compat_ioctl,
 };
 
+/*
+ * We need to override this because the device used to import the memory is
+ * not dev->dev, as drm_gem_prime_import() expects.
+ */
+struct drm_gem_object *mtk_drm_gem_prime_import(struct drm_device *dev,
+						struct dma_buf *dma_buf)
+{
+	struct mtk_drm_private *private = dev->dev_private;
+
+	return drm_gem_prime_import_dev(dev, dma_buf, private->dma_dev);
+}
+
 static struct drm_driver mtk_drm_driver = {
 	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
 			   DRIVER_ATOMIC,
@@ -331,7 +343,7 @@ static struct drm_driver mtk_drm_driver = {
 	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
 	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
 	.gem_prime_export = drm_gem_prime_export,
-	.gem_prime_import = drm_gem_prime_import,
+	.gem_prime_import = mtk_drm_gem_prime_import,
 	.gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
 	.gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
 	.gem_prime_mmap = mtk_drm_gem_mmap_buf,
-- 
2.22.0.709.g102302147b-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] drm/mediatek: set DMA max segment size
  2019-07-29  5:33 [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous Alexandre Courbot
  2019-07-29  5:33 ` [PATCH v2 1/2] drm/mediatek: use correct device to import PRIME buffers Alexandre Courbot
@ 2019-07-29  5:33 ` Alexandre Courbot
  2019-08-15  1:40 ` [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous CK Hu
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2019-07-29  5:33 UTC (permalink / raw)
  To: CK Hu, Philipp Zabel, David Airlie, Daniel Vetter,
	Matthias Brugger, Tomasz Figa
  Cc: dri-devel, linux-arm-kernel, linux-mediatek, linux-kernel,
	Alexandre Courbot

This driver requires imported PRIME buffers to appear contiguously in
its IO address space. Make sure this is the case by setting the maximum
DMA segment size to a more suitable value than the default 64KB.

Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c | 35 ++++++++++++++++++++++++--
 drivers/gpu/drm/mediatek/mtk_drm_drv.h |  2 ++
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 8b18a00a58c7..c021d4c8324f 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -213,6 +213,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
 	struct mtk_drm_private *private = drm->dev_private;
 	struct platform_device *pdev;
 	struct device_node *np;
+	struct device *dma_dev;
 	int ret;
 
 	if (!iommu_present(&platform_bus_type))
@@ -275,7 +276,29 @@ static int mtk_drm_kms_init(struct drm_device *drm)
 		goto err_component_unbind;
 	}
 
-	private->dma_dev = &pdev->dev;
+	dma_dev = &pdev->dev;
+	private->dma_dev = dma_dev;
+
+	/*
+	 * Configure the DMA segment size to make sure we get contiguous IOVA
+	 * when importing PRIME buffers.
+	 */
+	if (!dma_dev->dma_parms) {
+		private->dma_parms_allocated = true;
+		dma_dev->dma_parms =
+			devm_kzalloc(drm->dev, sizeof(*dma_dev->dma_parms),
+				     GFP_KERNEL);
+	}
+	if (!dma_dev->dma_parms) {
+		ret = -ENOMEM;
+		goto err_component_unbind;
+	}
+
+	ret = dma_set_max_seg_size(dma_dev, (unsigned int)DMA_BIT_MASK(32));
+	if (ret) {
+		dev_err(dma_dev, "Failed to set DMA segment size\n");
+		goto err_unset_dma_parms;
+	}
 
 	/*
 	 * We don't use the drm_irq_install() helpers provided by the DRM
@@ -285,13 +308,16 @@ static int mtk_drm_kms_init(struct drm_device *drm)
 	drm->irq_enabled = true;
 	ret = drm_vblank_init(drm, MAX_CRTC);
 	if (ret < 0)
-		goto err_component_unbind;
+		goto err_unset_dma_parms;
 
 	drm_kms_helper_poll_init(drm);
 	drm_mode_config_reset(drm);
 
 	return 0;
 
+err_unset_dma_parms:
+	if (private->dma_parms_allocated)
+		dma_dev->dma_parms = NULL;
 err_component_unbind:
 	component_unbind_all(drm->dev, drm);
 err_config_cleanup:
@@ -302,9 +328,14 @@ static int mtk_drm_kms_init(struct drm_device *drm)
 
 static void mtk_drm_kms_deinit(struct drm_device *drm)
 {
+	struct mtk_drm_private *private = drm->dev_private;
+
 	drm_kms_helper_poll_fini(drm);
 	drm_atomic_helper_shutdown(drm);
 
+	if (private->dma_parms_allocated)
+		private->dma_dev->dma_parms = NULL;
+
 	component_unbind_all(drm->dev, drm);
 	drm_mode_config_cleanup(drm);
 }
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.h b/drivers/gpu/drm/mediatek/mtk_drm_drv.h
index 598ff3e70446..e03fea12ff59 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.h
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.h
@@ -51,6 +51,8 @@ struct mtk_drm_private {
 	} commit;
 
 	struct drm_atomic_state *suspend_state;
+
+	bool dma_parms_allocated;
 };
 
 extern struct platform_driver mtk_ddp_driver;
-- 
2.22.0.709.g102302147b-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous
  2019-07-29  5:33 [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous Alexandre Courbot
  2019-07-29  5:33 ` [PATCH v2 1/2] drm/mediatek: use correct device to import PRIME buffers Alexandre Courbot
  2019-07-29  5:33 ` [PATCH v2 2/2] drm/mediatek: set DMA max segment size Alexandre Courbot
@ 2019-08-15  1:40 ` CK Hu
  2 siblings, 0 replies; 4+ messages in thread
From: CK Hu @ 2019-08-15  1:40 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger,
	Tomasz Figa, dri-devel, linux-arm-kernel, linux-mediatek,
	linux-kernel

Hi, Alexandre:

On Mon, 2019-07-29 at 14:33 +0900, Alexandre Courbot wrote:
> The default DMA segment size was used when importing PRIME buffers,
> which resulted in a chance of them not being contiguous in the virtual
> IO space of the device and mtk_gem_prime_import_sg_table() complaining
> that the SG table was not contiguous as it expects.
> 
> This series fixes this issue by
> 
> 1) Using the correct DMA device when importing PRIME buffers,
> 2) Setting a more suitable DMA segment size on the DMA device than the
> default 64KB.

For the series, applied to mediatek-drm-fixes-5.3 [1], thanks.

[1]
https://github.com/ckhu-mediatek/linux.git-tags/commits/mediatek-drm-fixes-5.3

> 
> Changes since v1:
> - Split into two patches,
> - Fixed an error path that would have returned 0.
> 
> Alexandre Courbot (2):
>   drm/mediatek: use correct device to import PRIME buffers
>   drm/mediatek: set DMA max segment size
> 
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c | 49 ++++++++++++++++++++++++--
>  drivers/gpu/drm/mediatek/mtk_drm_drv.h |  2 ++
>  2 files changed, 48 insertions(+), 3 deletions(-)
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-15  1:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29  5:33 [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous Alexandre Courbot
2019-07-29  5:33 ` [PATCH v2 1/2] drm/mediatek: use correct device to import PRIME buffers Alexandre Courbot
2019-07-29  5:33 ` [PATCH v2 2/2] drm/mediatek: set DMA max segment size Alexandre Courbot
2019-08-15  1:40 ` [PATCH v2 0/2] drm/mediatek: make imported PRIME buffers contiguous CK Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).