Skip to contentSkip to conversation

drm/omap: dmm_tiler: fixes and workaround for errata i878

PATCH In review Peter Ujfalusi 2 participants 6 messages Sep 26, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover drm/omap: dmm_tiler: fixes and workaround for errata i878

Hi,

Hi,

Changes since v3:
- Included two fixes for dmm_tiler:
- fix for memory barrier bug from Tomi
- correct the ordering of the interrupt request
- dropped the new compatible as the i878 is affecting only dra7 family of SoCs, the DMM itself is the same.

Changes since v2:
- Use threaded irq when the i878 workaround is used to avoid unlikely system
freeze: dma_sync_wait() have 5 second timeout
- Use mutex instead of spinlock as wa_lock
- use the dmaengine_prep_dma_memcpy() wrapper
- do not explicitly call dma_async_issue_pending() as it is done as part of dma_sync_wait()
- Use define for the DMM register size (4 bytes)
- Cleanup patch for the remove path: no need to check if the irq is valid. The driver would not probe w/o valid interrupt.

Changes since v1:
- rebased on drm-next
- comments for the v1 (https://patchwork.kernel.org/patch/8358741/) addressed
- u32 -> dma_addr_t when applicable
- additional wmb()/rmb() added to make sure we have correct behavior

Errata i878 says that MPU should not be used to access RAM and DMM at the same time. As it's not possible to prevent MPU accessing RAM, we need to access DMM via a proxy.

Regards,
Peter
---
Peter Ujfalusi (2):
drm/omap: dmm_tiler: No need to check if irq is valid in
omap_dmm_remove
drm/omap: dmm_tiler: Fix interrupt request/free sequence during
probe/remove

Tomi Valkeinen (2):
drm/omap: fix memory barrier bug in DMM driver drm/omap: partial workaround for DRA7xx DMM errata i878

 drivers/gpu/drm/omapdrm/omap_dmm_priv.h  |   7 +
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 201 ++++++++++++++++++++---
 2 files changed, 186 insertions(+), 22 deletions(-)
Signature · 9 lines
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v4 1/4 drm/omap: fix memory barrier bug in DMM driver

From: Tomi Valkeinen <[email protected]>

A DMM timeout "timed out waiting for done" has been observed on DRA7 devices. The timeout happens rarely, and only when the system is under heavy load.

Debugging showed that the timeout can be made to happen much more frequently by optimizing the DMM driver, so that there's almost no code between writing the last DMM descriptors to RAM, and writing to DMM register which starts the DMM transaction.

The current theory is that a wmb() does not properly ensure that the data written to RAM is observable by all the components in the system.

This DMM timeout has caused interesting (and rare) bugs as the error handling was not functioning properly (the error handling has been fixed in previous commits):

* If a DMM timeout happened when a GEM buffer was being pinned for display on the screen, a timeout error would be shown, but the driver would continue programming DSS HW with broken buffer, leading to SYNCLOST floods and possible crashes.

* If a DMM timeout happened when other user (say, video decoder) was pinning a GEM buffer, a timeout would be shown but if the user handled the error properly, no other issues followed.

* If a DMM timeout happened when a GEM buffer was being released, the driver does not even notice the error, leading to crashes or hang later.

This patch adds wmb() and readl() calls after the last bit is written to RAM, which should ensure that the execution proceeds only after the data is actually in RAM, and thus observable by DMM.

The read-back should not be needed. Further study is required to understand if DMM is somehow special case and read-back is ok, or if DRA7's memory barriers do not work correctly.

---
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +11 -0
index f9fa1c90b35c..e84871e74615 100644
@@ -285,6 +285,17 @@ static int dmm_txn_commit(struct dmm_txn *txn, bool wait)
 	}
 
 	txn->last_pat->next_pa = 0;
+	/* ensure that the written descriptors are visible to DMM */
+	wmb();
+
+	/*
+	 * NOTE: the wmb() above should be enough, but there seems to be a bug
+	 * in OMAP's memory barrier implementation, which in some rare cases may
+	 * cause the writes not to be observable after wmb().
+	 */
+
+	/* read back to ensure the data is in RAM */
+	readl(&txn->last_pat->next_pa);
 
 	/* write to PAT_DESCR to clear out any pending transaction */
 	dmm_write(dmm, 0x0, reg[PAT_DESCR][engine->id]);
Signature · 9 lines
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH v4 2/4 drm/omap: dmm_tiler: No need to check if irq is valid in omap_dmm_remove

In reply to Peter Ujfalusi

The driver probe would fail if the irq is not available.

---
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +1 -2
index e84871e74615..8671d06c0eb4 100644
@@ -632,8 +632,7 @@ static int omap_dmm_remove(struct platform_device *dev)
 		if (omap_dmm->dummy_page)
 			__free_page(omap_dmm->dummy_page);
 
-		if (omap_dmm->irq > 0)
-			free_irq(omap_dmm->irq, omap_dmm);
+		free_irq(omap_dmm->irq, omap_dmm);
 
 		iounmap(omap_dmm->base);
 		kfree(omap_dmm);
Signature · 9 lines
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH v4 3/4 drm/omap: dmm_tiler: Fix interrupt request/free sequence during probe/remove

In reply to Peter Ujfalusi

The interrupts should be enabled after the driver initialization to avoid early interrupts while the driver is not yet ready to handle them.

On removal the interrupts must be disabled before other resources are released, freed up.

---
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 42 +++++++++++++-----------
 1 file changed, 22 insertions(+), 20 deletions(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +22 -20
index 8671d06c0eb4..ef9a88c772ed 100644
@@ -610,6 +610,10 @@ static int omap_dmm_remove(struct platform_device *dev)
 	unsigned long flags;
 
 	if (omap_dmm) {
+		/* Disable all enabled interrupts */
+		dmm_write(omap_dmm, 0x7e7e7e7e, DMM_PAT_IRQENABLE_CLR);
+		free_irq(omap_dmm->irq, omap_dmm);
+
 		/* free all area regions */
 		spin_lock_irqsave(&list_lock, flags);
 		list_for_each_entry_safe(block, _block, &omap_dmm->alloc_head,
@@ -632,8 +636,6 @@ static int omap_dmm_remove(struct platform_device *dev)
 		if (omap_dmm->dummy_page)
 			__free_page(omap_dmm->dummy_page);
 
-		free_irq(omap_dmm->irq, omap_dmm);
-
 		iounmap(omap_dmm->base);
 		kfree(omap_dmm);
 		omap_dmm = NULL;
@@ -720,24 +722,6 @@ static int omap_dmm_probe(struct platform_device *dev)
 	dmm_write(omap_dmm, 0x88888888, DMM_TILER_OR__0);
 	dmm_write(omap_dmm, 0x88888888, DMM_TILER_OR__1);
 
-	ret = request_irq(omap_dmm->irq, omap_dmm_irq_handler, IRQF_SHARED,
-				"omap_dmm_irq_handler", omap_dmm);
-
-	if (ret) {
-		dev_err(&dev->dev, "couldn't register IRQ %d, error %d\n",
-			omap_dmm->irq, ret);
-		omap_dmm->irq = -1;
-		goto fail;
-	}
-
-	/* Enable all interrupts for each refill engine except
-	 * ERR_LUT_MISS<n> (which is just advisory, and we don't care
-	 * about because we want to be able to refill live scanout
-	 * buffers for accelerated pan/scroll) and FILL_DSC<n> which
-	 * we just generally don't care about.
-	 */
-	dmm_write(omap_dmm, 0x7e7e7e7e, DMM_PAT_IRQENABLE_SET);
-
 	omap_dmm->dummy_page = alloc_page(GFP_KERNEL | __GFP_DMA32);
 	if (!omap_dmm->dummy_page) {
 		dev_err(&dev->dev, "could not allocate dummy page\n");
@@ -829,6 +813,24 @@ static int omap_dmm_probe(struct platform_device *dev)
 		.p1.y = omap_dmm->container_height - 1,
 	};
 
+	ret = request_irq(omap_dmm->irq, omap_dmm_irq_handler, IRQF_SHARED,
+				"omap_dmm_irq_handler", omap_dmm);
+
+	if (ret) {
+		dev_err(&dev->dev, "couldn't register IRQ %d, error %d\n",
+			omap_dmm->irq, ret);
+		omap_dmm->irq = -1;
+		goto fail;
+	}
+
+	/* Enable all interrupts for each refill engine except
+	 * ERR_LUT_MISS<n> (which is just advisory, and we don't care
+	 * about because we want to be able to refill live scanout
+	 * buffers for accelerated pan/scroll) and FILL_DSC<n> which
+	 * we just generally don't care about.
+	 */
+	dmm_write(omap_dmm, 0x7e7e7e7e, DMM_PAT_IRQENABLE_SET);
+
 	/* initialize all LUTs to dummy page entries */
 	for (i = 0; i < omap_dmm->num_lut; i++) {
 		area.tcm = omap_dmm->tcm[i];
Signature · 9 lines
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

PATCH v4 4/4 drm/omap: partial workaround for DRA7xx DMM errata i878

In reply to Peter Ujfalusi

From: Tomi Valkeinen <[email protected]>

Errata i878 says that MPU should not be used to access RAM and DMM at the same time. As it's not possible to prevent MPU accessing RAM, we need to access DMM via a proxy.

This patch changes DMM driver to access DMM registers via sDMA. Instead of doing a normal readl/writel call to read/write a register, we use sDMA to copy 4 bytes from/to the DMM registers.

This patch provides only a partial workaround for i878, as not only DMM register reads/writes are affected, but also accesses to the DMM mapped buffers (framebuffers, usually).

---
 drivers/gpu/drm/omapdrm/omap_dmm_priv.h  |   7 ++
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 149 ++++++++++++++++++++++-
 2 files changed, 154 insertions(+), 2 deletions(-)
drivers/gpu/drm/omapdrm/omap_dmm_priv.h +7 -0
index c2785cc98dc9..60bb3f9297bc 100644
@@ -159,6 +159,7 @@ struct dmm_platform_data {
 
 struct dmm {
 	struct device *dev;
+	dma_addr_t phys_base;
 	void __iomem *base;
 	int irq;
 
@@ -189,6 +190,12 @@ struct dmm {
 	struct list_head alloc_head;
 
 	const struct dmm_platform_data *plat_data;
+
+	bool dmm_workaround;
+	spinlock_t wa_lock;
+	u32 *wa_dma_data;
+	dma_addr_t wa_dma_handle;
+	struct dma_chan *wa_dma_chan;
 };
 
 #endif
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +147 -2

185 lines not on this page · raw message

Signature · 9 lines
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
In reply to Peter Ujfalusi
Quoted 41 lines · Peter Ujfalusi

Hi,

Hi,

Changes since v3:
- Included two fixes for dmm_tiler:
- fix for memory barrier bug from Tomi
- correct the ordering of the interrupt request
- dropped the new compatible as the i878 is affecting only dra7 family of SoCs, the DMM itself is the same.

Changes since v2:
- Use threaded irq when the i878 workaround is used to avoid unlikely system
freeze: dma_sync_wait() have 5 second timeout
- Use mutex instead of spinlock as wa_lock
- use the dmaengine_prep_dma_memcpy() wrapper
- do not explicitly call dma_async_issue_pending() as it is done as part of dma_sync_wait()
- Use define for the DMM register size (4 bytes)
- Cleanup patch for the remove path: no need to check if the irq is valid. The driver would not probe w/o valid interrupt.

Changes since v1:
- rebased on drm-next
- comments for the v1 (https://patchwork.kernel.org/patch/8358741/) addressed
- u32 -> dma_addr_t when applicable
- additional wmb()/rmb() added to make sure we have correct behavior

Errata i878 says that MPU should not be used to access RAM and DMM at the same time. As it's not possible to prevent MPU accessing RAM, we need to access DMM via a proxy.

Regards,
Peter
---
Peter Ujfalusi (2):
drm/omap: dmm_tiler: No need to check if irq is valid in
omap_dmm_remove
drm/omap: dmm_tiler: Fix interrupt request/free sequence during
probe/remove

Quoted 8 lines

Tomi Valkeinen (2):
drm/omap: fix memory barrier bug in DMM driver drm/omap: partial workaround for DRA7xx DMM errata i878

 drivers/gpu/drm/omapdrm/omap_dmm_priv.h  |   7 +
 drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 201 ++++++++++++++++++++---
 2 files changed, 186 insertions(+), 22 deletions(-)

Thanks, looks good to me. Applied.

Tomi

Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel