Skip to contentSkip to conversation

drm: tilcdc: simplify the recovery from sync lost error on rev1

PATCH Superseded Bartosz Golaszewski 2 participants 4 messages Dec 13, 2016 – Dec 19, 2016

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: tilcdc: simplify the recovery from sync lost error on rev1

Revision 2 of LCDC suffers from an issue where a SYNC_LOST error caused by limited memory bandwidth may leave the picture shifted a couple pixels to the right.

This issue has not been observed on revision 1, while the recovery mechanism introduces a different issue, where the END_OF_FRAME interrupt doesn't fire while drm is waiting for vblanks.

On rev1: recover from sync lost errors by simply clearing the RASTER_ENABLE bit in the RASTER_CTRL register and re-enabling it again as is suggested by the datasheet.

---
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +15 -9
index 9942b05..70e57a7 100644
@@ -921,17 +921,23 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc)
 		dev_err_ratelimited(dev->dev, "%s(0x%08x): Sync lost",
 				    __func__, stat);
 		tilcdc_crtc->frame_intact = false;
-		if (tilcdc_crtc->sync_lost_count++ >
-		    SYNC_LOST_COUNT_LIMIT) {
-			dev_err(dev->dev, "%s(0x%08x): Sync lost flood detected, recovering", __func__, stat);
-			queue_work(system_wq, &tilcdc_crtc->recover_work);
-			if (priv->rev == 1)
-				tilcdc_clear(dev, LCDC_RASTER_CTRL_REG,
-					     LCDC_V1_SYNC_LOST_INT_ENA);
-			else
+		if (priv->rev == 1) {
+			tilcdc_clear(dev,
+				     LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);
+			tilcdc_set(dev,
+				   LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);
+		} else {
+			if (tilcdc_crtc->sync_lost_count++ >
+			    SYNC_LOST_COUNT_LIMIT) {
+				dev_err(dev->dev,
+					"%s(0x%08x): Sync lost flood detected, recovering",
+					__func__, stat);
+				queue_work(system_wq,
+					   &tilcdc_crtc->recover_work);
 				tilcdc_write(dev, LCDC_INT_ENABLE_CLR_REG,
 					     LCDC_SYNC_LOST);
-			tilcdc_crtc->sync_lost_count = 0;
+				tilcdc_crtc->sync_lost_count = 0;
+			}
 		}
 	}
 
Signature · 1 line
2.9.3
#1 lore raw

One comment bellow.

Quoted 24 lines · Bartosz Golaszewski

Revision 2 of LCDC suffers from an issue where a SYNC_LOST error caused by limited memory bandwidth may leave the picture shifted a couple pixels to the right.

This issue has not been observed on revision 1, while the recovery mechanism introduces a different issue, where the END_OF_FRAME interrupt doesn't fire while drm is waiting for vblanks.

On rev1: recover from sync lost errors by simply clearing the RASTER_ENABLE bit in the RASTER_CTRL register and re-enabling it again as is suggested by the datasheet.

---
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +0 -0
index 9942b05..70e57a7 100644
@@ -921,17 +921,23 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc)
 		dev_err_ratelimited(dev->dev, "%s(0x%08x): Sync lost",
 				    __func__, stat);

drivers/gpu/drm/tilcdc/tilcdc_crtc.c irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) · line 924

Quoted 10 lines
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +1 -8
 		tilcdc_crtc->frame_intact = false;
-		if (tilcdc_crtc->sync_lost_count++ >
-		    SYNC_LOST_COUNT_LIMIT) {
-			dev_err(dev->dev, "%s(0x%08x): Sync lost flood detected, recovering", __func__, stat);
-			queue_work(system_wq, &tilcdc_crtc->recover_work);
-			if (priv->rev == 1)
-				tilcdc_clear(dev, LCDC_RASTER_CTRL_REG,
-					     LCDC_V1_SYNC_LOST_INT_ENA);
-			else
+		if (priv->rev == 1) {

I would add here:
+ if ((tilcdc_read(dev, LCDC_RASTER_CTRL_REG) &
+ LCDC_RASTER_ENABLE)) {

drivers/gpu/drm/tilcdc/tilcdc_crtc.c irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) · line 928

Quoted 4 lines
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +4 -0
+			tilcdc_clear(dev,
+				     LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);
+			tilcdc_set(dev,
+				   LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);

+ }

Just in case the interrupt is for some reason handled right after the crtc is disabled.

With this addition I could send a pull request for this fix still today, if you agree with the change.

Quoted 17 lines
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +10 -1
+		} else {
+			if (tilcdc_crtc->sync_lost_count++ >
+			    SYNC_LOST_COUNT_LIMIT) {
+				dev_err(dev->dev,
+					"%s(0x%08x): Sync lost flood detected, recovering",
+					__func__, stat);
+				queue_work(system_wq,
+					   &tilcdc_crtc->recover_work);
 				tilcdc_write(dev, LCDC_INT_ENABLE_CLR_REG,
 					     LCDC_SYNC_LOST);
-			tilcdc_crtc->sync_lost_count = 0;
+				tilcdc_crtc->sync_lost_count = 0;
+			}
 		}
 	}
 
#2 lore raw

2016-12-19 14:09 GMT+01:00 Jyri Sarha <[email protected]>:

Quoted 46 lines

One comment bellow.

Quoted 24 lines · Bartosz Golaszewski

Revision 2 of LCDC suffers from an issue where a SYNC_LOST error caused by limited memory bandwidth may leave the picture shifted a couple pixels to the right.

This issue has not been observed on revision 1, while the recovery mechanism introduces a different issue, where the END_OF_FRAME interrupt doesn't fire while drm is waiting for vblanks.

On rev1: recover from sync lost errors by simply clearing the RASTER_ENABLE bit in the RASTER_CTRL register and re-enabling it again as is suggested by the datasheet.

---
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +0 -0
index 9942b05..70e57a7 100644
@@ -921,17 +921,23 @@ irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc)
              dev_err_ratelimited(dev->dev, "%s(0x%08x): Sync lost",
                                  __func__, stat);

drivers/gpu/drm/tilcdc/tilcdc_crtc.c irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) · line 924

Quoted 10 lines
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +1 -8
              tilcdc_crtc->frame_intact = false;
-             if (tilcdc_crtc->sync_lost_count++ >
-                 SYNC_LOST_COUNT_LIMIT) {
-                     dev_err(dev->dev, "%s(0x%08x): Sync lost flood detected, recovering", __func__, stat);
-                     queue_work(system_wq, &tilcdc_crtc->recover_work);
-                     if (priv->rev == 1)
-                             tilcdc_clear(dev, LCDC_RASTER_CTRL_REG,
-                                          LCDC_V1_SYNC_LOST_INT_ENA);
-                     else
+             if (priv->rev == 1) {

I would add here:

(quoted diff) +2 -0
+               if ((tilcdc_read(dev, LCDC_RASTER_CTRL_REG) &
+                               LCDC_RASTER_ENABLE)) {

drivers/gpu/drm/tilcdc/tilcdc_crtc.c irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) · line 928

Quoted 5 lines
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +4 -0
+                     tilcdc_clear(dev,
+                                  LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);
+                     tilcdc_set(dev,
+                                LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);
Quoted 7 lines

+ }

Just in case the interrupt is for some reason handled right after the crtc is disabled.

With this addition I could send a pull request for this fix still today, if you agree with the change.

I'm not sure this can really happen, but it won't hurt either, so I'll send a v2.

Thanks,
Bartosz

#3 lore raw
Quoted 10 lines · Bartosz Golaszewski
Quoted 10 lines

I would add here:

(quoted diff) +2 -0
+               if ((tilcdc_read(dev, LCDC_RASTER_CTRL_REG) &
+                               LCDC_RASTER_ENABLE)) {

drivers/gpu/drm/tilcdc/tilcdc_crtc.c irqreturn_t tilcdc_crtc_irq(struct drm_crtc *crtc) · line 928

Quoted 5 lines
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +4 -0
+                     tilcdc_clear(dev,
+                                  LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);
+                     tilcdc_set(dev,
+                                LCDC_RASTER_CTRL_REG, LCDC_RASTER_ENABLE);

+ }

Quoted 7 lines
Quoted 5 lines

Just in case the interrupt is for some reason handled right after the crtc is disabled.

With this addition I could send a pull request for this fix still today, if you agree with the change.

I'm not sure this can really happen, but it won't hurt either, so I'll send a v2.

Well, in theory it is quite possible. If the driver clears the raster enable at the same time when sync lost interrupt is generated, then the irq routine handles the irq before the interrupts are disabled. Then it happens that rastere remains on but the driver thinks it has already turned it off.

In practice this is of course terribly unlikely, but a race is a race and should be avoided.

Anyway, my vacation has already been started so I won't send a pull request now. I do not like the idea of doing something like that and then vanishing for two weeks. I hope they still take fixes for 4.10 in 4th Jan.

Best regards,
Jyri