Skip to contentSkip to conversation

drm/i915: Enable scanline read for gen9 dsi

PATCH In review Vidya Srinivas 9 participants 31 messages Sep 8, 2017 – Sep 15, 2017

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

PATCH 1/1 drm/i915: Enable scanline read for gen9 dsi

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
 drivers/gpu/drm/i915/i915_reg.h  |  3 +++
 drivers/gpu/drm/i915/intel_dsi.c | 46 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index d07d110..4213b54 100644
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
 			     enum dpio_phy *phy, enum dpio_channel *ch);
drivers/gpu/drm/i915/i915_irq.c +5 -0
index 5d391e6..31aa7f0 100644
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
 	else
drivers/gpu/drm/i915/i915_reg.h +3 -0
index 9a73ea0..54582de 100644
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +46 -0

52 lines not on this page · raw message

Signature · 6 lines
1.9.1

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

✗ Fi.CI.BAT: failure for drm/i915: Enable scanline read for gen9 dsi

== Series Details ==

== Series Details ==

Series: drm/i915: Enable scanline read for gen9 dsi
URL : https://patchwork.freedesktop.org/series/30032/
State : failure

== Summary ==

Series 30032v1 drm/i915: Enable scanline read for gen9 dsi
https://patchwork.freedesktop.org/api/1.0/series/30032/revisions/1/mbox/

Test gem_exec_nop:

        Subgroup basic-parallel:
                pass       -> INCOMPLETE (fi-skl-x1585l)
fi-bdw-5557u     total:289  pass:268  dwarn:0   dfail:0   fail:0   skip:21  time:458s
fi-bdw-gvtdvm    total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:444s
fi-blb-e6850     total:289  pass:224  dwarn:1   dfail:0   fail:0   skip:64  time:357s
fi-bsw-n3050     total:289  pass:243  dwarn:0   dfail:0   fail:0   skip:46  time:568s
fi-bwr-2160      total:289  pass:184  dwarn:0   dfail:0   fail:0   skip:105 time:254s
fi-bxt-j4205     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:525s
fi-byt-j1900     total:289  pass:254  dwarn:1   dfail:0   fail:0   skip:34  time:531s
fi-byt-n2820     total:289  pass:250  dwarn:1   dfail:0   fail:0   skip:38  time:521s
fi-cfl-s         total:289  pass:250  dwarn:4   dfail:0   fail:0   skip:35  time:461s
fi-elk-e7500     total:289  pass:230  dwarn:0   dfail:0   fail:0   skip:59  time:431s
fi-glk-2a        total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:612s
fi-hsw-4770      total:289  pass:263  dwarn:0   dfail:0   fail:0   skip:26  time:451s
fi-hsw-4770r     total:289  pass:263  dwarn:0   dfail:0   fail:0   skip:26  time:424s
fi-ilk-650       total:289  pass:229  dwarn:0   dfail:0   fail:0   skip:60  time:423s
fi-ivb-3520m     total:289  pass:261  dwarn:0   dfail:0   fail:0   skip:28  time:519s
fi-ivb-3770      total:289  pass:261  dwarn:0   dfail:0   fail:0   skip:28  time:483s
fi-kbl-7500u     total:289  pass:264  dwarn:1   dfail:0   fail:0   skip:24  time:514s
fi-kbl-7560u     total:289  pass:270  dwarn:0   dfail:0   fail:0   skip:19  time:603s
fi-kbl-r         total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:600s
fi-pnv-d510      total:289  pass:223  dwarn:1   dfail:0   fail:0   skip:65  time:524s
fi-skl-6260u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:474s
fi-skl-6700k     total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:539s
fi-skl-6770hq    total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:519s
fi-skl-gvtdvm    total:289  pass:266  dwarn:0   dfail:0   fail:0   skip:23  time:447s
fi-skl-x1585l    total:76   pass:65   dwarn:0   dfail:0   fail:0   skip:10 
fi-snb-2520m     total:289  pass:251  dwarn:0   dfail:0   fail:0   skip:38  time:569s
fi-snb-2600      total:289  pass:250  dwarn:0   dfail:0   fail:0   skip:39  time:412s

16fef66706a3fcdd1d87009beab7e09de1f32807 drm-tip: 2017y-09m-08d-08h-41m-49s UTC integration manifest dcea2d7c6068 drm/i915: Enable scanline read for gen9 dsi

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_5620/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw
In reply to Vidya Srinivas
Quoted 48 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
 drivers/gpu/drm/i915/i915_reg.h  |  3 +++
 drivers/gpu/drm/i915/intel_dsi.c | 46 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index d07d110..4213b54 100644
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
 			     enum dpio_phy *phy, enum dpio_channel *ch);
drivers/gpu/drm/i915/i915_irq.c +1 -0
index 5d391e6..31aa7f0 100644
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
 	else
drivers/gpu/drm/i915/i915_reg.h +0 -0
index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 5 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Quoted 15 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +3 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct drm_connector *connector)
 	return 1;
 }
 
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1636

Quoted 10 lines
drivers/gpu/drm/i915/intel_dsi.c +10 -0
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc)
+{
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +11 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1657

Quoted 10 lines
drivers/gpu/drm/i915/intel_dsi.c +10 -0
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1664

Quoted 7 lines
drivers/gpu/drm/i915/intel_dsi.c +7 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime - ulPrevTime),
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1665

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should make this at least suitable for vblank timestamps. And for the atomic evade, I guess if we clamp our the scanline before the +vblank_start such that it never reaches vtotal, we can't be sure that our vblank evade never indicates that we already reached the start of vblank prematurely.

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);
return (scanline + vblank_start) % vtotal;

At least that's my thinking atm. Feel free to rip my reasoning to shreds if you think I'm totally wrong here.

Quoted 9 lines
drivers/gpu/drm/i915/intel_dsi.c +4 -0
+
+	return ulScanlineNo2;
+}
+
 static void intel_dsi_connector_destroy(struct drm_connector *connector)
 {
 	struct intel_connector *intel_connector = to_intel_connector(connector);
Signature · 1 line
1.9.1
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
Quoted 71 lines · Ville Syrjälä
Quoted 48 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
 drivers/gpu/drm/i915/i915_reg.h  |  3 +++
 drivers/gpu/drm/i915/intel_dsi.c | 46 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index d07d110..4213b54 100644
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
 			     enum dpio_phy *phy, enum dpio_channel *ch);
drivers/gpu/drm/i915/i915_irq.c +1 -0
index 5d391e6..31aa7f0 100644
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Quoted 14 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
 	else
drivers/gpu/drm/i915/i915_reg.h +0 -0
index 9a73ea0..54582de 100644
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
Quoted 4 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 2 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Oh, and these shouldn't be called BXT_something. I don't recall when they got added to the hardware, but I'm pretty sure it was way before BXT came out.

Another thought that just occurred to me: Maybe we could use these timestamps as a workaround for the DDI "scanline reads as 0 at the wrong time" problem. What we could do is check of the scanline counter reads as 0, and if it does we could switch over to checking the timestamps instead. Not sure if we should just do the full timestamp based scanline read like you do here, or we could just check that if the timestamps look like they're close to vblank_start we just return vblank_start-1. This could then remove the obnoxious retry loop from the scanline counter read.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

HI,

Quoted 10 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Ville Syrjälä
Sent: perjantai 8. syyskuuta 2017 17.55
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 9 lines

Another thought that just occurred to me: Maybe we could use these timestamps as a workaround for the DDI "scanline reads as 0 at the wrong time" problem. What we could do is check of the scanline counter reads as 0, and if it does we could switch over to checking the timestamps instead. Not sure if we should just do the full timestamp based scanline read like you do here, or we could just check that if the timestamps look like they're close to vblank_start we just return vblank_start-1. This could then remove the obnoxious retry loop from the scanline counter read.

Also please use trybot also as dsi system not in pw runs due to known issue.

Quoted 3 lines

--
Ville Syrjälä
Intel OTC

Jani Saarinen
Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw
In reply to Ville Syrjälä
Quoted 72 lines · Ville Syrjälä
Quoted 71 lines · Ville Syrjälä
Quoted 48 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
 drivers/gpu/drm/i915/i915_reg.h  |  3 +++
 drivers/gpu/drm/i915/intel_dsi.c | 46 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index d07d110..4213b54 100644
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
 			     enum dpio_phy *phy, enum dpio_channel *ch);
drivers/gpu/drm/i915/i915_irq.c +1 -0
index 5d391e6..31aa7f0 100644
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Quoted 14 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
 	else
drivers/gpu/drm/i915/i915_reg.h +0 -0
index 9a73ea0..54582de 100644
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
Quoted 8 lines
Quoted 4 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 2 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Oh, and these shouldn't be called BXT_something. I don't recall when they got added to the hardware, but I'm pretty sure it was way before BXT came out.

gen5 or maybe gen4.5 iirc.

Quoted 9 lines

Another thought that just occurred to me: Maybe we could use these timestamps as a workaround for the DDI "scanline reads as 0 at the wrong time" problem. What we could do is check of the scanline counter reads as 0, and if it does we could switch over to checking the timestamps instead. Not sure if we should just do the full timestamp based scanline read like you do here, or we could just check that if the timestamps look like they're close to vblank_start we just return vblank_start-1. This could then remove the obnoxious retry loop from the scanline counter read.

Another concern I have on this is timeframe jitter. If the vblank timestamp stuff isnt' perfectly accurately spaced, or we have a mismatch in clocks, then we might think there's still plenty of time before vblank while we're already racing.

Just a bit of testing won't catch that all that easily unfortunately, and I'm not sure we have any good igts to stress-test this stuff. I'd advocate we're playing it defensive and increase the vblank evasion window for this trick quite a bit to stay on the safe side (maybe 1 full ms or so). Or much, much better testing.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

Quoting Daniel Vetter (2017-09-08 20:45:11)

Quoted 11 lines · Ville Syrjälä
Quoted 9 lines

Another thought that just occurred to me: Maybe we could use these timestamps as a workaround for the DDI "scanline reads as 0 at the wrong time" problem. What we could do is check of the scanline counter reads as 0, and if it does we could switch over to checking the timestamps instead. Not sure if we should just do the full timestamp based scanline read like you do here, or we could just check that if the timestamps look like they're close to vblank_start we just return vblank_start-1. This could then remove the obnoxious retry loop from the scanline counter read.

Quoted 4 lines

Another concern I have on this is timeframe jitter. If the vblank timestamp stuff isnt' perfectly accurately spaced, or we have a mismatch in clocks, then we might think there's still plenty of time before vblank while we're already racing.

You are sort of getting to the point where you just use the ART cpu clock, using an ewma seeded with the vrefresh and fed with the vblank intervals as an estimator for how long you have left to the next vblank. -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

Op 08-09-17 om 21:55 schreef Chris Wilson:

Quoted 11 lines

Quoting Daniel Vetter (2017-09-08 20:45:11)

Quoted 10 lines · Ville Syrjälä
Quoted 9 lines

Another thought that just occurred to me: Maybe we could use these timestamps as a workaround for the DDI "scanline reads as 0 at the wrong time" problem. What we could do is check of the scanline counter reads as 0, and if it does we could switch over to checking the timestamps instead. Not sure if we should just do the full timestamp based scanline read like you do here, or we could just check that if the timestamps look like they're close to vblank_start we just return vblank_start-1. This could then remove the obnoxious retry loop from the scanline counter read.

Quoted 7 lines
Quoted 4 lines

Another concern I have on this is timeframe jitter. If the vblank timestamp stuff isnt' perfectly accurately spaced, or we have a mismatch in clocks, then we might think there's still plenty of time before vblank while we're already racing.

You are sort of getting to the point where you just use the ART cpu clock, using an ewma seeded with the vrefresh and fed with the vblank intervals as an estimator for how long you have left to the next vblank.

Agreed, this seems to be the case.. In which case can't we use that for all of DDI to get a better than scanline resolution for last vblank time by replacing the get_vblank_timestamp hook?
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw
Quoted 16 lines · Maarten Lankhorst

Op 08-09-17 om 21:55 schreef Chris Wilson:

Quoted 15 lines

Quoting Daniel Vetter (2017-09-08 20:45:11)

Quoted 14 lines · Ville Syrjälä
Quoted 9 lines

Another thought that just occurred to me: Maybe we could use these timestamps as a workaround for the DDI "scanline reads as 0 at the wrong time" problem. What we could do is check of the scanline counter reads as 0, and if it does we could switch over to checking the timestamps instead. Not sure if we should just do the full timestamp based scanline read like you do here, or we could just check that if the timestamps look like they're close to vblank_start we just return vblank_start-1. This could then remove the obnoxious retry loop from the scanline counter read.

Another concern I have on this is timeframe jitter. If the vblank timestamp stuff isnt' perfectly accurately spaced, or we have a mismatch in clocks, then we might think there's still plenty of time before vblank while we're already racing.

Quoted 5 lines
Quoted 3 lines

You are sort of getting to the point where you just use the ART cpu clock, using an ewma seeded with the vrefresh and fed with the vblank intervals as an estimator for how long you have left to the next vblank.

Agreed, this seems to be the case.. In which case can't we use that for all of DDI to get a better than scanline resolution for last vblank time by replacing the get_vblank_timestamp hook?

Like I said that should be doable with just a simple timestamp check to fix up the bogus 0.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw
In reply to Daniel Vetter
Quoted 96 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Saturday, September 9, 2017 1:15 AM
To: Ville Syrjälä <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 35 lines · Ville Syrjälä
Quoted 34 lines · Ville Syrjälä
Quoted 33 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg,
 u32 val);
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */

void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum

port port,

Quoted 1 line
Quoted 1 line
Quoted 1 line

enum dpio_phy *phy, enum dpio_channel *ch); diff --

git

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc

Quoted 5 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct

intel_crtc *crtc)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 14 lines
Quoted 13 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Quoted 6 lines
Quoted 3 lines

Oh, and these shouldn't be called BXT_something. I don't recall when they got added to the hardware, but I'm pretty sure it was way before BXT came out.

gen5 or maybe gen4.5 iirc.

As per spec, it says BDW+. Will rename them using BDW as prefix.

Quoted 10 lines
Quoted 9 lines

Another thought that just occurred to me: Maybe we could use these timestamps as a workaround for the DDI "scanline reads as 0 at the wrong time" problem. What we could do is check of the scanline counter reads as 0, and if it does we could switch over to checking the timestamps instead. Not sure if we should just do the full timestamp based scanline read like you do here, or we could just check that if the timestamps look like they're close to vblank_start we just return vblank_start-1. This could then remove the obnoxious retry loop from the scanline counter read.

Quoted 8 lines

Another concern I have on this is timeframe jitter. If the vblank timestamp stuff isnt' perfectly accurately spaced, or we have a mismatch in clocks, then we might think there's still plenty of time before vblank while we're already racing.

Just a bit of testing won't catch that all that easily unfortunately, and I'm not sure we have any good igts to stress-test this stuff. I'd advocate we're playing it defensive and increase the vblank evasion window for this trick quite a bit to stay on the safe side (maybe 1 full ms or so). Or much, much better testing.

We tried to use kms_plane_multiple test from IGT to validate this. Atomic update failure can easily be reproduced using this. With the above approach, we are not seeing those failures. Also to try to check for traditional method of detecting scanline (using Pipe scanline) which works for DDI interfaces. We tried to compare the results from both ways, readback from this register and the calculated one from timestamps on HDMI. The results were pretty similar with a delta of
1. We will try to do more experiments and stress test to get more confidence on the timestamp method. But till now, it looks pretty promising.

If we increase evade time, it may have an adverse impact on fps. So if scanline reported gives promising data (similar to what pipe scanline register returns), I think we should stick to that approach.

Regards,
Uma Shankar

Quoted 9 lines

-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#10 lore raw
Quoted 96 lines · Uma
Quoted 96 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Saturday, September 9, 2017 1:15 AM
To: Ville Syrjälä <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 35 lines · Ville Syrjälä
Quoted 34 lines · Ville Syrjälä
Quoted 33 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg,
 u32 val);
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */

void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum

port port,

Quoted 1 line
Quoted 1 line
Quoted 1 line

enum dpio_phy *phy, enum dpio_channel *ch); diff --

git

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc

Quoted 5 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct

intel_crtc *crtc)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 14 lines
Quoted 13 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Oh, and these shouldn't be called BXT_something. I don't recall when they got added to the hardware, but I'm pretty sure it was way before BXT came out.

gen5 or maybe gen4.5 iirc.

As per spec, it says BDW+. Will rename them using BDW as prefix.

You're not looking at the right spec then. Looks like ctg/elk is the right answer indeed. The gen4 spec is a bit confused in that it doesn't correctly state whether some of the regs apply to gen4 or ctg/elk. But testing on actual gen4 hardware gives me 0s from all the pipe timestamp registers, whereas elk gives sane looking value. The TIMESTAMP register did exist on gen4 already.

There have been some changes in the TIMESTAMP register(s) throughout the years though. I'll try to summarize below:

bw/cl: TIMESTAMP/0x2358. 64bit register that increments every 16 hclks ctg/elk: TIMESTAMP/0x2358. 64bit register where the upper 32 bits increment
every 1.024us, the lower part has more 12 bits which means the whole value increments every 1/4 ns
ilk/snb: TIMESTAMP/0x2358 "64bit" register where the upprt 32 bits increment
every 1 us. Lower part is documented as MBZ. The upprt part is aliased as TIMESTAMP_HI high at offset 0x70070
ivb+: TIMESTAMP_HI got renamed to TIMESTAMP_CTR and moved to 0x44070

The pipe flip/frame timestamp registers seem to have remained unchanged ever since ctg/elk.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw
Quoted 142 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Monday, September 11, 2017 11:51 PM
To: Shankar, Uma <[email protected]>
Cc: Daniel Vetter <[email protected]>; [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 49 lines · Uma
Quoted 49 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Saturday, September 9, 2017 1:15 AM
To: Ville Syrjälä <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 36 lines · Ville Syrjälä
Quoted 35 lines · Ville Syrjälä
Quoted 34 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct
 drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32
 reg); void vlv_flisdsi_write(struct drm_i915_private *dev_priv,
 u32 reg,
 u32 val);
 
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+

/* intel_dpio_phy.c */
void bxt_port_to_phy_channel(struct drm_i915_private
*dev_priv, enum

port port,

Quoted 1 line
Quoted 1 line
Quoted 1 line

enum dpio_phy *phy, enum dpio_channel

*ch); diff --

Quoted 32 lines
Quoted 32 lines

git

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int

__intel_get_crtc_scanline(struct

intel_crtc *crtc)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8802

Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2
	_MMIO(0x160008)
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 4 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Oh, and these shouldn't be called BXT_something. I don't recall when they got added to the hardware, but I'm pretty sure it was way before BXT came out.

gen5 or maybe gen4.5 iirc.

As per spec, it says BDW+. Will rename them using BDW as prefix.

You're not looking at the right spec then. Looks like ctg/elk is the right answer indeed. The gen4 spec is a bit confused in that it doesn't correctly state whether some of the regs apply to gen4 or ctg/elk. But testing on actual gen4 hardware gives me 0s from all the pipe timestamp registers, whereas elk gives sane looking value. The TIMESTAMP register did exist on gen4 already.

There have been some changes in the TIMESTAMP register(s) throughout the years though. I'll try to summarize below:

bw/cl: TIMESTAMP/0x2358. 64bit register that increments every 16 hclks ctg/elk: TIMESTAMP/0x2358. 64bit register where the upper 32 bits increment
every 1.024us, the lower part has more 12 bits which means the whole value increments every 1/4 ns
ilk/snb: TIMESTAMP/0x2358 "64bit" register where the upprt 32 bits increment
every 1 us. Lower part is documented as MBZ. The upprt part is aliased as TIMESTAMP_HI high at offset 0x70070
ivb+: TIMESTAMP_HI got renamed to TIMESTAMP_CTR and moved to 0x44070

Quoted 3 lines

The pipe flip/frame timestamp registers seem to have remained unchanged ever since ctg/elk.

Thanks Ville for this info. Will update the Current Timestamp register for Gen4 and Gen7 (declare as separate macros). Also will define Frame Timestamp generically.

Quoted 3 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#12 lore raw
In reply to Ville Syrjälä
Quoted 67 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 33 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);

void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);

drivers/gpu/drm/i915/i915_drv.h void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,

Quoted 4 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel *ch); diff --

git

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc

Quoted 5 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc

*crtc)

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
Quoted 5 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 2 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1636

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/i915/intel_dsi.c +15 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
Quoted 9 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1657

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Yes, will get it from hwmode and drop this change.

Quoted 10 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1664

Quoted 7 lines
drivers/gpu/drm/i915/intel_dsi.c +7 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime - ulPrevTime),
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

Quoted 7 lines
		   1000 * crtc_htotal);

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1665

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 6 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should make this at least suitable for vblank timestamps.

I also feel the same, this situation should never occur.

Quoted 9 lines

And for
the atomic evade, I guess if we clamp our the scanline before the +vblank_start such that it never reaches vtotal, we can't be sure that our vblank evade never indicates that we already reached the start of vblank prematurely.

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -1. But we can have a check just to be safe. Not sure if I fully got your point here.

Quoted 5 lines

return (scanline + vblank_start) % vtotal;

At least that's my thinking atm. Feel free to rip my reasoning to shreds if you think I'm totally wrong here.

One more thing we missed is, that the current timestamp is just a 32 bit register value. It can overflow and wrap around. So a situation can come, where current timestamp will be less than prev timestamp (read from frame time stamp reg). We need to handle that situation as well. Will fix that in the next version and resend.

Thanks Ville for your valuable review comments.

Regards,
Uma Shankar

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +4 -0
+
+	return ulScanlineNo2;
+}
+
 static void intel_dsi_connector_destroy(struct drm_connector
 *connector)  {
 	struct intel_connector *intel_connector =

to_intel_connector(connector);
--
1.9.1

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#13 lore raw
Quoted 195 lines · Uma
Quoted 67 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 33 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);

void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);

drivers/gpu/drm/i915/i915_drv.h void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,

Quoted 4 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel *ch); diff --

git

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc

Quoted 5 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc

*crtc)

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
Quoted 5 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 2 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1636

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/i915/intel_dsi.c +15 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
Quoted 9 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1657

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Yes, will get it from hwmode and drop this change.

Quoted 10 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1664

Quoted 7 lines
drivers/gpu/drm/i915/intel_dsi.c +7 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime - ulPrevTime),
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

Quoted 7 lines
		   1000 * crtc_htotal);

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1665

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 6 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should make this at least suitable for vblank timestamps.

I also feel the same, this situation should never occur.

Quoted 6 lines

And for
the atomic evade, I guess if we clamp our the scanline before the +vblank_start such that it never reaches vtotal, we can't be sure that our vblank evade never indicates that we already reached the start of vblank prematurely.

Quoted 6 lines
Quoted 3 lines

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -1. But we can have a check just to be safe. Not sure if I fully got your point here.

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality we're not.

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Oh and there's maybe another race lurking here. We might cross into the next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR reads. If that happens we get an answer that's definitely too big for one frame. I guess we could avoid that particular problem by making sure we really read PIPE_FRMTMSTMP and TIMESTAMP_CTR during the same frame. Eg. something like:

do {
prev = PIPE_FRMTMSTMP;
curr = TIMESTAMP_CTR
post = PIPE_FRMTMSTMP
} while (prev != post);

Quoted 11 lines
Quoted 6 lines

return (scanline + vblank_start) % vtotal;

At least that's my thinking atm. Feel free to rip my reasoning to shreds if you think I'm totally wrong here.

One more thing we missed is, that the current timestamp is just a 32 bit register value. It can overflow and wrap around. So a situation can come, where current timestamp will be less than prev timestamp (read from frame time stamp reg). We need to handle that situation as well. Will fix that in the next version and resend.

Modulo 2^32 math will handle that just fine.

Quoted 21 lines

Thanks Ville for your valuable review comments.

Regards,
Uma Shankar

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +4 -0
+
+	return ulScanlineNo2;
+}
+
 static void intel_dsi_connector_destroy(struct drm_connector
 *connector)  {
 	struct intel_connector *intel_connector =

to_intel_connector(connector);
--
1.9.1

--
Ville Syrjälä
Intel OTC

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw
Quoted 238 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Monday, September 11, 2017 11:20 PM
To: Shankar, Uma <[email protected]>
Cc: Srinivas, Vidya <[email protected]>; [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 176 lines · Uma
Quoted 71 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 36 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg,
 u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
Quoted 2 lines

void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv,
enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel *ch); diff --

git

Quoted 6 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
Quoted 5 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 2 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1636

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/i915/intel_dsi.c +15 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
Quoted 9 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1657

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Yes, will get it from hwmode and drop this change.

Quoted 12 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1664

Quoted 7 lines
drivers/gpu/drm/i915/intel_dsi.c +7 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime - ulPrevTime),
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 14 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1665

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 6 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 10 lines

I also feel the same, this situation should never occur.

Quoted 7 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't be sure
+that

our vblank evade never indicates that we already reached the start of vblank prematurely.

Quoted 5 lines
Quoted 3 lines

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

1.

Quoted 1 line

But we can have a check just to be safe. Not sure if I fully got your point here.

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality we're not.

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Oh and there's maybe another race lurking here. We might cross into the next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR reads. If that happens we get an answer that's definitely too big for one frame. I guess we could avoid that particular problem by making sure we really read PIPE_FRMTMSTMP and TIMESTAMP_CTR during the same frame. Eg. something like:

Quoted 6 lines

do {
prev = PIPE_FRMTMSTMP;
curr = TIMESTAMP_CTR
post = PIPE_FRMTMSTMP
} while (prev != post);

Got it. Will add this condition to handle the race situation. Thanks for the explanation.

Regards,
Uma Shankar

Quoted 39 lines
Quoted 9 lines
Quoted 7 lines

return (scanline + vblank_start) % vtotal;

At least that's my thinking atm. Feel free to rip my reasoning to shreds if you think I'm totally wrong here.

One more thing we missed is, that the current timestamp is just a 32 bit register

value.

Quoted 3 lines

It can overflow and wrap around. So a situation can come, where current timestamp will be less than prev timestamp (read from frame time stamp reg). We need to handle that situation as well. Will fix that in the

next version and resend.

Modulo 2^32 math will handle that just fine.

Quoted 21 lines

Thanks Ville for your valuable review comments.

Regards,
Uma Shankar

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +4 -0
+
+	return ulScanlineNo2;
+}
+
 static void intel_dsi_connector_destroy(struct drm_connector
 *connector)  {
 	struct intel_connector *intel_connector =

to_intel_connector(connector);
--
1.9.1

--
Ville Syrjälä
Intel OTC

Quoted 3 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#15 lore raw
Quoted 232 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Shankar, Uma
Sent: Tuesday, September 12, 2017 3:20 PM
To: Ville Syrjälä <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 220 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Monday, September 11, 2017 11:20 PM
To: Shankar, Uma <[email protected]>
Cc: Srinivas, Vidya <[email protected]>; [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 176 lines · Uma
Quoted 71 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 36 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg,
 u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
Quoted 2 lines

void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv,
enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel *ch); diff --

git

Quoted 6 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
Quoted 5 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 2 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1636

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/i915/intel_dsi.c +15 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
Quoted 9 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1657

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Yes, will get it from hwmode and drop this change.

Quoted 12 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1664

Quoted 7 lines
drivers/gpu/drm/i915/intel_dsi.c +7 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime - ulPrevTime),
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 15 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1665

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 7 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 10 lines

I also feel the same, this situation should never occur.

Quoted 7 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't be sure
+that

our vblank evade never indicates that we already reached the start of vblank prematurely.

Quoted 6 lines
Quoted 3 lines

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

1.

Quoted 13 lines
Quoted 7 lines
Quoted 1 line

But we can have a check just to be safe. Not sure if I fully got your point here.

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality

we're not.

Quoted 5 lines

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Hi Ville,
We tried to test with this condition and are calculating wrong scanlines. For ex:

[   79.418943] [drm:bxt_dsi_get_scanline] *ERROR* scanline = 22534, crtc_vtotal-1 = 1211, min of two = 1211

This causes calculated value to be different from PIPE SCANLINE value read from register.

But if we keep scanline and take the modulo with vtotal after adding the vblank_start (not taking min with vtotal -1),
we are getting scanline equal to (delta of 1 all the time ) what the PIPE SCANLINE register returns for HDMI. We can
use HDMI as a reference to validate if timestamp based calculation aligns to h/w values returned by Pipe scanline register. So if we do like below:

scanline = div_u64(...);
return (scanline + vblank_start) % vtotal;

It works perfectly fine. Tested it with "kms_plane_multiple" and almost getting the same result all the time with no atomic update failures. I am not sure on other platforms, but BXT/APL its working fine. Without these changes, issue can easily be reproduced using this IGT test.

Will send the updated patch, please have a look once.

Thanks & Regards,
Uma Shankar

Quoted 61 lines
Quoted 7 lines

Oh and there's maybe another race lurking here. We might cross into the next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR reads. If that happens we get an answer that's definitely too big for one frame. I guess we could avoid that particular problem by making sure we really read PIPE_FRMTMSTMP and TIMESTAMP_CTR during the same frame. Eg. something like:

Quoted 6 lines

do {
prev = PIPE_FRMTMSTMP;
curr = TIMESTAMP_CTR
post = PIPE_FRMTMSTMP
} while (prev != post);

Got it. Will add this condition to handle the race situation. Thanks for the explanation.

Regards,
Uma Shankar

Quoted 41 lines
Quoted 10 lines
Quoted 7 lines

return (scanline + vblank_start) % vtotal;

At least that's my thinking atm. Feel free to rip my reasoning to shreds if you think I'm totally wrong here.

One more thing we missed is, that the current timestamp is just a 32 bit register

value.

Quoted 4 lines

It can overflow and wrap around. So a situation can come, where current timestamp will be less than prev timestamp (read from frame time stamp reg). We need to handle that situation as well. Will fix that in the

next version and resend.

Modulo 2^32 math will handle that just fine.

Quoted 21 lines

Thanks Ville for your valuable review comments.

Regards,
Uma Shankar

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +4 -0
+
+	return ulScanlineNo2;
+}
+
 static void intel_dsi_connector_destroy(struct drm_connector
 *connector)  {
 	struct intel_connector *intel_connector =

to_intel_connector(connector);
--
1.9.1

--
Ville Syrjälä
Intel OTC

Quoted 7 lines
Quoted 3 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw
Quoted 246 lines · Uma
Quoted 232 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Shankar, Uma
Sent: Tuesday, September 12, 2017 3:20 PM
To: Ville Syrjälä <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 220 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Monday, September 11, 2017 11:20 PM
To: Shankar, Uma <[email protected]>
Cc: Srinivas, Vidya <[email protected]>; [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 176 lines · Uma
Quoted 71 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 36 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg,
 u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
Quoted 2 lines

void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv,
enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel *ch); diff --

git

Quoted 6 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc) · line 796

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc *crtc)

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
Quoted 5 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 2 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1636

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/i915/intel_dsi.c +15 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
Quoted 9 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1657

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Yes, will get it from hwmode and drop this change.

Quoted 12 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1664

Quoted 7 lines
drivers/gpu/drm/i915/intel_dsi.c +7 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime - ulPrevTime),
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 15 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct drm_connector *connector) · line 1665

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 7 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 10 lines

I also feel the same, this situation should never occur.

Quoted 7 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't be sure
+that

our vblank evade never indicates that we already reached the start of vblank prematurely.

Quoted 6 lines
Quoted 3 lines

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

1.

Quoted 13 lines
Quoted 7 lines
Quoted 1 line

But we can have a check just to be safe. Not sure if I fully got your point here.

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality

we're not.

Quoted 5 lines

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Quoted 4 lines

Hi Ville,
We tried to test with this condition and are calculating wrong scanlines. For ex:

[   79.418943] [drm:bxt_dsi_get_scanline] *ERROR* scanline = 22534, crtc_vtotal-1 = 1211, min of two = 1211

Well, that scanline number looks totally bogus. How did you calculate it exactly?

Quoted 87 lines

This causes calculated value to be different from PIPE SCANLINE value read from register.

But if we keep scanline and take the modulo with vtotal after adding the vblank_start (not taking min with vtotal -1),
we are getting scanline equal to (delta of 1 all the time ) what the PIPE SCANLINE register returns for HDMI. We can
use HDMI as a reference to validate if timestamp based calculation aligns to h/w values returned by Pipe scanline register. So if we do like below:

scanline = div_u64(...);
return (scanline + vblank_start) % vtotal;

It works perfectly fine. Tested it with "kms_plane_multiple" and almost getting the same result all the time with no atomic update failures. I am not sure on other platforms, but BXT/APL its working fine. Without these changes, issue can easily be reproduced using this IGT test.

Will send the updated patch, please have a look once.

Thanks & Regards,
Uma Shankar

Quoted 68 lines
Quoted 7 lines

Oh and there's maybe another race lurking here. We might cross into the next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR reads. If that happens we get an answer that's definitely too big for one frame. I guess we could avoid that particular problem by making sure we really read PIPE_FRMTMSTMP and TIMESTAMP_CTR during the same frame. Eg. something like:

Quoted 6 lines

do {
prev = PIPE_FRMTMSTMP;
curr = TIMESTAMP_CTR
post = PIPE_FRMTMSTMP
} while (prev != post);

Got it. Will add this condition to handle the race situation. Thanks for the explanation.

Regards,
Uma Shankar

Quoted 41 lines
Quoted 10 lines
Quoted 7 lines

return (scanline + vblank_start) % vtotal;

At least that's my thinking atm. Feel free to rip my reasoning to shreds if you think I'm totally wrong here.

One more thing we missed is, that the current timestamp is just a 32 bit register

value.

Quoted 4 lines

It can overflow and wrap around. So a situation can come, where current timestamp will be less than prev timestamp (read from frame time stamp reg). We need to handle that situation as well. Will fix that in the

next version and resend.

Modulo 2^32 math will handle that just fine.

Quoted 21 lines

Thanks Ville for your valuable review comments.

Regards,
Uma Shankar

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +4 -0
+
+	return ulScanlineNo2;
+}
+
 static void intel_dsi_connector_destroy(struct drm_connector
 *connector)  {
 	struct intel_connector *intel_connector =

to_intel_connector(connector);
--
1.9.1

--
Ville Syrjälä
Intel OTC

Quoted 3 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw
Quoted 265 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:04 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 37 lines · Uma
Quoted 37 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Shankar, Uma
Sent: Tuesday, September 12, 2017 3:20 PM
To: Ville Syrjälä <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 23 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Monday, September 11, 2017 11:20 PM
To: Shankar, Uma <[email protected]>
Cc: Srinivas, Vidya <[email protected]>; [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 12 lines · Uma
Quoted 12 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Vidya Srinivas
Quoted 5 lines

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be

functional.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct
 drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32
 reg); void vlv_flisdsi_write(struct drm_i915_private *dev_priv,
 u32 reg,
 u32 val);
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+

/* intel_dpio_phy.c */
void bxt_port_to_phy_channel(struct drm_i915_private
*dev_priv, enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel

*ch); diff --

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 18 lines

git

Quoted 6 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8802

Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2
	_MMIO(0x160008)
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 4 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1635

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 24 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +11 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1656

Quoted 10 lines
drivers/gpu/drm/i915/intel_dsi.c +10 -0
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Yes, will get it from hwmode and drop this change.

Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1662

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime -

ulPrevTime),

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1663

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 15 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1664

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 7 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 10 lines

I also feel the same, this situation should never occur.

Quoted 7 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't be sure
+that

our vblank evade never indicates that we already reached the start of vblank prematurely.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

1.

Quoted 1 line

But we can have a check just to be safe. Not sure if I fully got your point

here.

Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality

we're not.

Quoted 5 lines

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Quoted 8 lines
Quoted 4 lines

Hi Ville,
We tried to test with this condition and are calculating wrong scanlines. For ex:

[   79.418943] [drm:bxt_dsi_get_scanline] *ERROR* scanline = 22534,

crtc_vtotal-1 = 1211, min of two = 1211

Well, that scanline number looks totally bogus. How did you calculate it exactly?

If we have multiple scans on the same frame (no new flip being issued). Prev timestamp value which is read from Frametime Stamp will remain same, but current time stamp will keep on incrementing. So assume if 10 times the same frame has been scanned and we are in 11 iteration and at that time a new flip is issued (where we are doing these checks). At that moment the delta of curr - prev will still have a huge value and will surely give results, adding the lines scanned in earlier iterations of the same frame. Thus by doing the modulo operation using vtotal we can really check for the scanline in the current iteration of the scan. Thus getting a high value of scanline is expected.

Regards,
Uma Shankar

Quoted 89 lines
Quoted 1 line

This causes calculated value to be different from PIPE SCANLINE value read

from register.

Quoted 5 lines

But if we keep scanline and take the modulo with vtotal after adding the vblank_start (not taking min with vtotal -1), we are getting scanline equal to (delta of 1 all the time ) what the PIPE SCANLINE register returns for HDMI. We can use HDMI as a reference to validate if

timestamp based calculation aligns to h/w values returned by Pipe scanline register. So if we do like below:

Quoted 7 lines

scanline = div_u64(...);
return (scanline + vblank_start) % vtotal;

It works perfectly fine. Tested it with "kms_plane_multiple" and almost getting the same result all the time with no atomic update failures. I am not sure on other platforms, but BXT/APL its working fine.

Without these changes, issue can easily be reproduced using this IGT test.

Quoted 9 lines

Will send the updated patch, please have a look once.

Thanks & Regards,
Uma Shankar

Quoted 3 lines
Quoted 3 lines

Oh and there's maybe another race lurking here. We might cross into the next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR reads. If that happens we get an answer that's definitely too big for one

frame.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I guess we could avoid that particular problem by making sure we really read PIPE_FRMTMSTMP and TIMESTAMP_CTR during the same frame.

Eg.

Quoted 59 lines
Quoted 59 lines
Quoted 8 lines

something like:

do {
prev = PIPE_FRMTMSTMP;
curr = TIMESTAMP_CTR
post = PIPE_FRMTMSTMP
} while (prev != post);

Got it. Will add this condition to handle the race situation. Thanks for the explanation.

Regards,
Uma Shankar

Quoted 44 lines
Quoted 10 lines
Quoted 7 lines

return (scanline + vblank_start) % vtotal;

At least that's my thinking atm. Feel free to rip my reasoning to shreds if you think I'm totally wrong here.

One more thing we missed is, that the current timestamp is just a 32 bit register

value.

Quoted 4 lines

It can overflow and wrap around. So a situation can come, where current timestamp will be less than prev timestamp (read from frame time stamp reg). We need to handle that situation as well. Will fix that in the

next version and resend.

Modulo 2^32 math will handle that just fine.

Quoted 21 lines

Thanks Ville for your valuable review comments.

Regards,
Uma Shankar

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +4 -0
+
+	return ulScanlineNo2;
+}
+
 static void intel_dsi_connector_destroy(struct drm_connector
 *connector)  {
 	struct intel_connector *intel_connector =

to_intel_connector(connector);
--
1.9.1

--
Ville Syrjälä
Intel OTC

--
Ville Syrjälä
Intel OTC

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#18 lore raw

PATCH 1/1 drm/i915: Enable scanline read for gen9 dsi

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

v2: Addressed Ville and Daniel's review comments. Updated the register MACROs, handled race condition for register reads, extracted timings from the hwmode. Removed the dependency on crtc->config to get the encoder type.

Credits-to: Ville Syrjälä <[email protected]>

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
 drivers/gpu/drm/i915/i915_irq.c  |  7 +++++
 drivers/gpu/drm/i915/i915_reg.h  | 11 ++++++++
 drivers/gpu/drm/i915/intel_dsi.c | 59 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 1cc31a5..fc84136 100644
@@ -4085,6 +4085,8 @@ void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
 			     enum dpio_phy *phy, enum dpio_channel *ch);
drivers/gpu/drm/i915/i915_irq.c +7 -0
index 5d391e6..40fa2cb 100644
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	struct intel_encoder *encoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,12 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	if (IS_BROXTON(dev_priv) || IS_GEMINILAKE(dev_priv)) {
+		for_each_encoder_on_crtc(crtc->base.dev, &crtc->base, encoder)
+			if (encoder->type == INTEL_OUTPUT_DSI)
+				return bxt_dsi_get_scanline(crtc);
+	}
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
 	else
drivers/gpu/drm/i915/i915_reg.h +11 -0
index 0b03260..864924c86 100644
@@ -8802,6 +8802,17 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+/* Gen4+ Timestamp and Pipe Frame time stamp registers */
+#define GEN4_TIMESTAMP_CTR	_MMIO(MCHBAR_MIRROR_BASE + 0x2358)
+#define GEN7_TIMESTAMP_CTR	_MMIO(0x44070)
+
+#define _PIPE_FRMTMSTMP_A		0x70048
+#define _PIPE_FRMTMSTMP_B		0x71048
+#define _IVB_PIPE_FRMTMSTMP_C	0x72048
+#define PIPE_FRMTMSTMP(pipe)		\
+			_MMIO_PIPE3((pipe), _PIPE_FRMTMSTMP_A, \
+				_PIPE_FRMTMSTMP_A, _IVB_PIPE_FRMTMSTMP_C)
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +59 -0

65 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#19 lore raw
In reply to Shankar, Uma
Quoted 269 lines · Uma
Quoted 269 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:04 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 37 lines · Uma
Quoted 37 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Shankar, Uma
Sent: Tuesday, September 12, 2017 3:20 PM
To: Ville Syrjälä <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 23 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Monday, September 11, 2017 11:20 PM
To: Shankar, Uma <[email protected]>
Cc: Srinivas, Vidya <[email protected]>; [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 12 lines · Uma
Quoted 12 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Vidya Srinivas
Quoted 5 lines

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be

functional.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct
 drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32
 reg); void vlv_flisdsi_write(struct drm_i915_private *dev_priv,
 u32 reg,
 u32 val);
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+

/* intel_dpio_phy.c */
void bxt_port_to_phy_channel(struct drm_i915_private
*dev_priv, enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel

*ch); diff --

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 18 lines

git

Quoted 6 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct

intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8802

Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2
	_MMIO(0x160008)
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8806

Quoted 4 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1635

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 24 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +11 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1656

Quoted 10 lines
drivers/gpu/drm/i915/intel_dsi.c +10 -0
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Yes, will get it from hwmode and drop this change.

Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1662

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime -

ulPrevTime),

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1663

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 15 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1664

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 7 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 10 lines

I also feel the same, this situation should never occur.

Quoted 7 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't be sure
+that

our vblank evade never indicates that we already reached the start of vblank prematurely.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

1.

Quoted 1 line

But we can have a check just to be safe. Not sure if I fully got your point

here.

Quoted 18 lines
Quoted 13 lines
Quoted 7 lines

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality

we're not.

Quoted 5 lines

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Hi Ville,
We tried to test with this condition and are calculating wrong scanlines. For ex:

[   79.418943] [drm:bxt_dsi_get_scanline] *ERROR* scanline = 22534,
Quoted 8 lines
Quoted 4 lines

crtc_vtotal-1 = 1211, min of two = 1211

Well, that scanline number looks totally bogus. How did you calculate it exactly?

If we have multiple scans on the same frame (no new flip being issued). Prev timestamp value which is read from Frametime Stamp will remain same, but current time stamp will keep on incrementing.

The frame timestamp should get sampled on every vblank, whereas the flip timestamp only when a flip occurs. Are you using the correct timestamp register?

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#20 lore raw
Quoted 269 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:43 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 30 lines · Uma
Quoted 30 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:04 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 6 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be

Quoted 6 lines
Quoted 6 lines

functional.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the

scanline.

Quoted 212 lines
Quoted 212 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct
 drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32

reg); void vlv_flisdsi_write(struct drm_i915_private *dev_priv,
u32 reg,
u32 val);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private

*dev_priv, enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel

*ch); diff --

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 19 lines

git

Quoted 7 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {  #define

MIPIO_TXESC_CLK_DIV2

	_MMIO(0x160008)
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h

Quoted 4 lines

#define GLK_TX_ESC_CLK_DIV2_MASK 0x3FF

drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1635

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 24 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +11 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1656

Quoted 10 lines
drivers/gpu/drm/i915/intel_dsi.c +10 -0
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Yes, will get it from hwmode and drop this change.

Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1662

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime -

ulPrevTime),

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1663

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 15 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1664

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 7 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 17 lines

I also feel the same, this situation should never occur.

Quoted 11 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't be
+sure that

our vblank evade never indicates that we already reached the start of vblank prematurely.

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

1.

Quoted 2 lines

But we can have a check just to be safe. Not sure if I fully got your point

here.

Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality

we're not.

Quoted 5 lines

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Hi Ville,
We tried to test with this condition and are calculating wrong scanlines. For ex:

[   79.418943] [drm:bxt_dsi_get_scanline] *ERROR* scanline = 22534,

crtc_vtotal-1 = 1211, min of two = 1211

Well, that scanline number looks totally bogus. How did you calculate it

exactly?

Quoted 2 lines
Quoted 1 line
Quoted 7 lines
Quoted 3 lines

If we have multiple scans on the same frame (no new flip being issued). Prev timestamp value which is read from Frametime Stamp will remain same, but current time stamp will keep on incrementing.

The frame timestamp should get sampled on every vblank, whereas the flip timestamp only when a flip occurs. Are you using the correct timestamp register?

Yes, we are using what is there in the patch.
Name Pipe A Frame Time Stamp
Symbol PIPE_FRMTMSTMP_A
Start 0x70048
End 0x7004B

Its behaving as FLIP Timestamp though (not being updated on every vblank_start). Atleast with the readback what we get on APL.

Quoted 3 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#21 lore raw
Quoted 277 lines · Uma
Quoted 269 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:43 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 30 lines · Uma
Quoted 30 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:04 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 6 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be

Quoted 6 lines
Quoted 6 lines

functional.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the

scanline.

Quoted 212 lines
Quoted 212 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

It helps resolve atomic update failure for gen9 dsi platforms.

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct
 drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32

reg); void vlv_flisdsi_write(struct drm_i915_private *dev_priv,
u32 reg,
u32 val);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private

*dev_priv, enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel

*ch); diff --

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 19 lines

git

Quoted 7 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more crtc->config uses. We're pretty much trying to get rid of that guy.

Will try to find an alternate way to do this.

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+	if (IS_BROXTON(dev_priv) && transcoder_is_dsi(cpu_transcoder))
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {  #define

MIPIO_TXESC_CLK_DIV2

	_MMIO(0x160008)
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h

Quoted 4 lines

#define GLK_TX_ESC_CLK_DIV2_MASK 0x3FF

drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 14 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return 1;
 }
 
Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1635

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 24 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_dsi.c +11 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime = I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);
+
+	/*
+	 * The TIMESTAMP_CTR register has the current

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1656

Quoted 10 lines
drivers/gpu/drm/i915/intel_dsi.c +10 -0
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Yes, will get it from hwmode and drop this change.

Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1662

Quoted 6 lines
drivers/gpu/drm/i915/intel_dsi.c +6 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal * vrefresh);
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime -

ulPrevTime),

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1663

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+						ulScanlineTime);

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 15 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c static int intel_dsi_get_modes(struct · line 1664

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 7 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 17 lines

I also feel the same, this situation should never occur.

Quoted 11 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't be
+sure that

our vblank evade never indicates that we already reached the start of vblank prematurely.

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

1.

Quoted 2 lines

But we can have a check just to be safe. Not sure if I fully got your point

here.

Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality

we're not.

Quoted 5 lines

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Hi Ville,
We tried to test with this condition and are calculating wrong scanlines. For ex:

[   79.418943] [drm:bxt_dsi_get_scanline] *ERROR* scanline = 22534,

crtc_vtotal-1 = 1211, min of two = 1211

Well, that scanline number looks totally bogus. How did you calculate it

exactly?

Quoted 2 lines
Quoted 1 line
Quoted 7 lines
Quoted 3 lines

If we have multiple scans on the same frame (no new flip being issued). Prev timestamp value which is read from Frametime Stamp will remain same, but current time stamp will keep on incrementing.

The frame timestamp should get sampled on every vblank, whereas the flip timestamp only when a flip occurs. Are you using the correct timestamp register?

Quoted 8 lines

Yes, we are using what is there in the patch.
Name Pipe A Frame Time Stamp
Symbol PIPE_FRMTMSTMP_A
Start 0x70048
End 0x7004B

Its behaving as FLIP Timestamp though (not being updated on every vblank_start). Atleast with the readback what we get on APL.

Then it's broken and probably can't be used without having a decent idea of how long the frame actually is. Which probably means we'd need something like what Chris suggested.

Hmm. It's not a command mode display is it?

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#22 lore raw
Quoted 306 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 8:36 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 113 lines · Uma
Quoted 113 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:43 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 30 lines · Uma
Quoted 30 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:04 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 8, 2017 8:18 PM
To: Srinivas, Vidya <[email protected]>
Cc: [email protected]; Kahola, Mika <[email protected]>; Kamath, Sunil <[email protected]>; Shankar, Uma <[email protected]>; Konduru, Chandra <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 6 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be

Quoted 7 lines
Quoted 7 lines

functional.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the

scanline.

Quoted 64 lines
Quoted 64 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines

It helps resolve atomic update failure for gen9 dsi platforms.

Signed-off-by Chandra Konduru

<[email protected]>

---
 drivers/gpu/drm/i915/i915_drv.h  |  2 ++
drivers/gpu/drm/i915/i915_irq.c  |  5 +++++
drivers/gpu/drm/i915/i915_reg.h  |  3 +++
drivers/gpu/drm/i915/intel_dsi.c | 46
++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index d07d110..4213b54 100644

drivers/gpu/drm/i915/i915_drv.h +0 -0
@@ -4077,6 +4077,8 @@ void intel_sbi_write(struct
 drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv,

u32 reg); void vlv_flisdsi_write(struct drm_i915_private *dev_priv,
u32 reg,
u32 val);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +2 -0
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private

*dev_priv, enum port

port,

Quoted 1 line

enum dpio_phy *phy, enum dpio_channel

*ch); diff --

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines

git

Quoted 7 lines

a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..31aa7f0 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -781,6 +781,7 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	enum transcoder cpu_transcoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,10 @@ static int

__intel_get_crtc_scanline(struct intel_crtc

*crtc)

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	cpu_transcoder = crtc->config->cpu_transcoder;

Humm. Would be nice to be able to do this without adding more
crtc->config uses. We're pretty much trying to get rid of that guy.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Will try to find an alternate way to do this.

Quoted 1 line

drivers/gpu/drm/i915/i915_irq.c

Quoted 1 line
drivers/gpu/drm/i915/i915_irq.c +1 -0
+	if (IS_BROXTON(dev_priv) &&

transcoder_is_dsi(cpu_transcoder))

Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
+		return bxt_dsi_get_scanline(crtc);
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) &

DSL_LINEMASK_GEN2;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 9a73ea0..54582de 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,9 @@ enum skl_power_gate {  #define

MIPIO_TXESC_CLK_DIV2

	_MMIO(0x160008)
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_reg.h

Quoted 4 lines

#define GLK_TX_ESC_CLK_DIV2_MASK 0x3FF

drivers/gpu/drm/i915/i915_reg.h +2 -0
+#define BXT_TIMESTAMP_CTR	_MMIO(0x44070)
+#define BXT_PIPE_FRMTMSTMP_A	_MMIO(0x70048)

Please add proper parametrized define that works for all pipes.

Will add that.

Quoted 15 lines
Quoted 11 lines
drivers/gpu/drm/i915/i915_reg.h +1 -0
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
drivers/gpu/drm/i915/intel_dsi.c +0 -0
index 2a0f5d3..d145ba4 100644
@@ -1621,6 +1621,52 @@ static int

intel_dsi_get_modes(struct

drm_connector *connector)

Quoted 3 lines

return 1;
}

Quoted 15 lines

drivers/gpu/drm/i915/intel_dsi.c

Quoted 12 lines
drivers/gpu/drm/i915/intel_dsi.c +12 -0
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 bxt_dsi_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 vrefresh = crtc->base.mode.vrefresh;
+	u32 ulPrevTime, ulCurrTime, vtotal, ulScanlineNo2 = 0;

Please get rid of the hungarian notation.

Yes, will fix this.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/intel_dsi.c

Quoted 8 lines
drivers/gpu/drm/i915/intel_dsi.c +8 -0
+	uint_fixed_16_16_t ulScanlineTime;
+
+	/*
+	 * This field provides read back of the display
+	 * pipe frame time stamp. The time stamp value
+	 * is sampled at every start of vertical blank.
+	 */
+	ulPrevTime =

I915_READ_FW(BXT_PIPE_FRMTMSTMP_A);

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

drivers/gpu/drm/i915/intel_dsi.c

Quoted 13 lines
drivers/gpu/drm/i915/intel_dsi.c +13 -0
+
+	/*
+	 * The TIMESTAMP_CTR register has the current
+	 * time stamp value.
+	 */
+	ulCurrTime = I915_READ_FW(BXT_TIMESTAMP_CTR);
+
+	/* The PORT for DSI will always be 0 since
+	 * isolated PORTC cannot be enabled for Gen9
+	 * DSI. Hence using PORT_A i.e 0 to extract
+	 * the VTOTAL value.
+	 */
+	vtotal = I915_READ_FW(BXT_MIPI_TRANS_VTOTAL(0));

This value can be dug out from the hwmode.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Yes, will get it from hwmode and drop this change.

Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c

Quoted 5 lines
drivers/gpu/drm/i915/intel_dsi.c +5 -0
+	WARN_ON(!vtotal);
+	if (!vtotal)
+		return ulScanlineNo2;
+
+	ulScanlineTime = div_fixed16(1000000, vtotal *

vrefresh);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/intel_dsi.c

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = div_round_up_u32_fixed16((ulCurrTime

-

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

ulPrevTime),

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

	ulScanlineTime);
Quoted 68 lines
Quoted 68 lines
Quoted 57 lines
Quoted 57 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 5 lines
Quoted 5 lines

Something like:
scanline = div_u64(mul_u32_u32(curr - prev, crtc_clock),

		   1000 * crtc_htotal);
Quoted 15 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_dsi.c

Quoted 1 line
drivers/gpu/drm/i915/intel_dsi.c +1 -0
+	ulScanlineNo2 = (ulScanlineNo2 + vtotal) % vtotal;

I think that would have to be something like:
return (scanline + vblank_start) % vtotal;

Yes you are right. It should be vblank_start. Will fix this.

Quoted 7 lines

All in all this looks like a pretty decent approach to the DSI problem.

One concern here is rounding issues and inaccuracies in our crtc_clock. But since the frame timestamp is sampled at vblank start I guess we can't accidentally get an answer that's earlier than vblank_start as long as we really passed vblank start already. That should

make this at least suitable for vblank timestamps.

Quoted 17 lines

I also feel the same, this situation should never occur.

Quoted 11 lines

And for
the atomic evade, I guess if we clamp our the scanline before the

(quoted diff) +2 -0
+vblank_start such that it never reaches vtotal, we can't
+be sure that

our vblank evade never indicates that we already reached the start of vblank prematurely.

So maybe something like:
scaline = div_u64(...);
scanline = min(scanline, vtotal - 1);

I am not sure if the value of scanline returned can ever be greater than vtotal -

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

1.

Quoted 2 lines

But we can have a check just to be safe. Not sure if I fully got your point

here.

Quoted 15 lines
Quoted 14 lines
Quoted 8 lines

The point is that the timestamp counter might tick at a slightly faster rate than we might think. Thus we might end up with more ticks in one frame than what we calculated as the maximum fom crtc_clock etc. But if we clamp the value like I suggested then at least we should never get an answer that tells us we're already past the start of vblank when in reality

we're not.

Quoted 5 lines

Of course as Daniel pointed out we might also get into trouble if the counter ticks slower than expected. That could lead us to think that we don't need to do the vblank evade when in fact we do.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Hi Ville,
We tried to test with this condition and are calculating wrong scanlines. For ex:

[   79.418943] [drm:bxt_dsi_get_scanline] *ERROR* scanline = 22534,

crtc_vtotal-1 = 1211, min of two = 1211

Well, that scanline number looks totally bogus. How did you calculate it

exactly?

Quoted 2 lines
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

If we have multiple scans on the same frame (no new flip being issued). Prev timestamp value which is read from Frametime Stamp will remain same, but current time stamp will keep on incrementing.

The frame timestamp should get sampled on every vblank, whereas the flip timestamp only when a flip occurs. Are you using the correct timestamp

register?

Quoted 8 lines
Quoted 1 line

Yes, we are using what is there in the patch.
Name Pipe A Frame Time Stamp
Symbol PIPE_FRMTMSTMP_A
Start 0x70048
End 0x7004B

Quoted 8 lines
Quoted 1 line

Its behaving as FLIP Timestamp though (not being updated on every

vblank_start).

Quoted 1 line

Atleast with the readback what we get on APL.

Then it's broken and probably can't be used without having a decent idea of how long the frame actually is. Which probably means we'd need something like what Chris suggested.

Hi Ville,
On further experiments we figured out that, frame time stamp is not updated if the vblank interrupt gets disabled (which is currently controlled through vblank get and put). We tried to forcefully enable vblank interrupt by doing an extra vblank get during crtc_enable. By doing this, we see that frame timestamp is updating at every vblank.

So not sure what should be the best approach to deal with this. I don't think, keeping vblank interrupt enabled always is a good idea. Ideally frame time stamp should get updated even if no physical vblank interrupt is coming, or is the behavior expected ?

Quoted 2 lines

Hmm. It's not a command mode display is it?

No, it's a single link video mode panel. Command Mode is not even enabled in upstream as of now.

Regards,
Uma Shankar

Quoted 3 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#23 lore raw
Quoted 45 lines · Uma
Quoted 36 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 8:36 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 10 lines · Uma
Quoted 10 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:43 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 7 lines
Quoted 7 lines · Uma
Quoted 3 lines

If we have multiple scans on the same frame (no new flip being issued). Prev timestamp value which is read from Frametime Stamp will remain same, but current time stamp will keep on incrementing.

The frame timestamp should get sampled on every vblank, whereas the flip timestamp only when a flip occurs. Are you using the correct timestamp

register?

Quoted 8 lines
Quoted 1 line

Yes, we are using what is there in the patch.
Name Pipe A Frame Time Stamp
Symbol PIPE_FRMTMSTMP_A
Start 0x70048
End 0x7004B

Quoted 8 lines
Quoted 1 line

Its behaving as FLIP Timestamp though (not being updated on every

vblank_start).

Quoted 1 line

Atleast with the readback what we get on APL.

Then it's broken and probably can't be used without having a decent idea of how long the frame actually is. Which probably means we'd need something like what Chris suggested.

Quoted 5 lines

Hi Ville,
On further experiments we figured out that, frame time stamp is not updated if the vblank interrupt gets disabled (which is currently controlled through vblank get and put). We tried to forcefully enable vblank interrupt by doing an extra vblank get during crtc_enable. By doing this, we see that frame timestamp is updating at every vblank.

Well, that's rather unfortuante. I guess we'd have to keep the vblank interrupt unmasked all the time. Hopefully we could still disable it in IER.

So we'd unmask the interrupt permanently, and just toggle the IER bit as needed. That should be doable but somewhat annoying because it's exactly the opposite of what we do normally.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#24 lore raw
Quoted 63 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Wednesday, September 13, 2017 11:07 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 42 lines · Uma
Quoted 42 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 8:36 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 10 lines · Uma
Quoted 10 lines

-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Tuesday, September 12, 2017 7:43 PM
To: Shankar, Uma <[email protected]>
Cc: [email protected]; Srinivas, Vidya <[email protected]>
Subject: Re: [PATCH] drm/i915: Enable scanline read for gen9 dsi

Quoted 8 lines
Quoted 8 lines · Uma
Quoted 3 lines

If we have multiple scans on the same frame (no new flip being issued). Prev timestamp value which is read from Frametime Stamp will remain same, but current time stamp will keep on incrementing.

The frame timestamp should get sampled on every vblank, whereas the flip timestamp only when a flip occurs. Are you using the correct timestamp

register?

Quoted 9 lines
Quoted 1 line

Yes, we are using what is there in the patch.
Name Pipe A Frame Time Stamp
Symbol PIPE_FRMTMSTMP_A
Start 0x70048
End 0x7004B

Its behaving as FLIP Timestamp though (not being updated on every

vblank_start).

Quoted 1 line

Atleast with the readback what we get on APL.

Quoted 8 lines
Quoted 4 lines

Then it's broken and probably can't be used without having a decent idea of how long the frame actually is. Which probably means we'd need something like what Chris suggested.

Hi Ville,
On further experiments we figured out that, frame time stamp is not updated if the vblank interrupt gets disabled (which is currently controlled

through vblank get and put).

Quoted 1 line

We tried to forcefully enable vblank interrupt by doing an extra vblank get

during crtc_enable.

Quoted 9 lines
Quoted 1 line

By doing this, we see that frame timestamp is updating at every vblank.

Well, that's rather unfortuante. I guess we'd have to keep the vblank interrupt unmasked all the time. Hopefully we could still disable it in IER.

So we'd unmask the interrupt permanently, and just toggle the IER bit as needed. That should be doable but somewhat annoying because it's exactly the opposite of what we do normally.

We tried controlling Vblank through IER, keeping IMR always unmasked as you suggested. This is causing frame time stamp properly getting updated at every vblank. We will send the patch for the same for review. Thanks Ville for your suggestion.

Regards,
Uma Shankar

Quoted 3 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#25 lore raw

PATCH 1/2 drm/i915: Enable scanline read for gen9 dsi

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional. This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

v2: Addressed Ville and Daniel's review comments. Updated the register MACROs, handled race condition for register reads, extracted timings from the hwmode. Removed the dependency on crtc->config to get the encoder type.

v3: Made get scanline function generic

Credits-to: Ville Syrjälä <[email protected]>

---
 drivers/gpu/drm/i915/i915_drv.h      |  2 ++
 drivers/gpu/drm/i915/i915_irq.c      |  7 +++++
 drivers/gpu/drm/i915/i915_reg.h      | 11 +++++++
 drivers/gpu/drm/i915/intel_display.c | 60 ++++++++++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 1cc31a5..d9efe83 100644
@@ -4085,6 +4085,8 @@ void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 
+u32 gen9_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
 			     enum dpio_phy *phy, enum dpio_channel *ch);
drivers/gpu/drm/i915/i915_irq.c +7 -0
index 5d391e6..47668dd 100644
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	struct intel_encoder *encoder;
 
 	if (!crtc->active)
 		return -1;
@@ -792,6 +793,12 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	if (IS_BROXTON(dev_priv) || IS_GEMINILAKE(dev_priv)) {
+		for_each_encoder_on_crtc(crtc->base.dev, &crtc->base, encoder)
+			if (encoder->type == INTEL_OUTPUT_DSI)
+				return gen9_get_scanline(crtc);
+	}
+
 	if (IS_GEN2(dev_priv))
 		position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
 	else
drivers/gpu/drm/i915/i915_reg.h +11 -0
index 0b03260..85168ee 100644
@@ -8802,6 +8802,17 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+/* Gen4+ Timestamp and Pipe Frame time stamp registers */
+#define GEN4_TIMESTAMP_CTR	_MMIO(MCHBAR_MIRROR_BASE + 0x2358)
+#define GEN7_TIMESTAMP_CTR	_MMIO(0x44070)
+
+#define _PIPE_FRMTMSTMP_A		0x70048
+#define _PIPE_FRMTMSTMP_B		0x71048
+#define _IVB_PIPE_FRMTMSTMP_C	0x72048
+#define PIPE_FRMTMSTMP(pipe)		\
+			_MMIO_PIPE3((pipe), _PIPE_FRMTMSTMP_A, \
+				_PIPE_FRMTMSTMP_B, _IVB_PIPE_FRMTMSTMP_C)
+
 /* BXT MIPI clock controls */
 #define BXT_MAX_VAR_OUTPUT_KHZ			39500
 
drivers/gpu/drm/i915/intel_display.c +60 -0

66 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#26 lore raw

PATCH 2/2 drm/i915: Control Vblank through IER instead of IMR

From: Uma Shankar <[email protected]>

Frame timestamp register is not updated if the vblank inteerupts are not unmasked. This is needed to calculate scanlines for DSI encoders. This patch changes the vblank enable/disable logic by controlling it through Pipe IER register instead of IMR. Pipe IMR will be unmasked permanently and IER will be toggled based on need.

Credits-to: Ville Syrjälä <[email protected]>

---
 drivers/gpu/drm/i915/i915_irq.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/i915_irq.c +10 -10
index 47668dd..a417cea 100644
@@ -498,15 +498,14 @@ void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
 	if (WARN_ON(!intel_irqs_enabled(dev_priv)))
 		return;
 
-	new_val = dev_priv->de_irq_mask[pipe];
-	new_val &= ~interrupt_mask;
-	new_val |= (~enabled_irq_mask & interrupt_mask);
+	new_val = I915_READ(GEN8_DE_PIPE_IER(pipe));
+	if (enabled_irq_mask)
+		new_val |= enabled_irq_mask;
+	else
+		new_val &= ~interrupt_mask;
 
-	if (new_val != dev_priv->de_irq_mask[pipe]) {
-		dev_priv->de_irq_mask[pipe] = new_val;
-		I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
-		POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
-	}
+	I915_WRITE(GEN8_DE_PIPE_IER(pipe), new_val);
+	POSTING_READ(GEN8_DE_PIPE_IER(pipe));
 }
 
 /**
@@ -3450,8 +3449,9 @@ static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
 				  GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
 	}
 
-	de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
-					   GEN8_PIPE_FIFO_UNDERRUN;
+	de_pipe_enables = de_pipe_masked | GEN8_PIPE_FIFO_UNDERRUN;
+
+	de_pipe_masked |= GEN8_PIPE_VBLANK;
 
 	de_port_enables = de_port_masked;
 	if (IS_GEN9_LP(dev_priv))
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#27 lore raw

Re: [PATCH 2/2] drm/i915: Control Vblank through IER instead of IMR

Quoted 4 lines · Vidya Srinivas

From: Uma Shankar <[email protected]>

Frame timestamp register is not updated if the vblank inteerupts are not unmasked.

Art,

Do you know if there's some other way we could coax the hardware to update the frame timestamp? I see that on non-DSI the timestamp seems to update even with vblank irq masked in IMR, but DSI seems to be special.

Or even better if we could get the scanline counter to tick on DSI, but I presume that simply can't be done.

And if we just have to do the IMR unmasking trick, any idea what the cost of keeping vblank irqs always unmasked would be? I assume it has some very slight power cost, but not sure if it's small enough to be meaningless.

Quoted 54 lines

This is needed to calculate
scanlines for DSI encoders. This patch changes the vblank enable/disable logic by controlling it through Pipe IER register instead of IMR. Pipe IMR will be unmasked permanently and IER will be toggled based on need.

Credits-to: Ville Syrjälä <[email protected]>

---
 drivers/gpu/drm/i915/i915_irq.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/i915_irq.c +10 -10
index 47668dd..a417cea 100644
@@ -498,15 +498,14 @@ void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
 	if (WARN_ON(!intel_irqs_enabled(dev_priv)))
 		return;
 
-	new_val = dev_priv->de_irq_mask[pipe];
-	new_val &= ~interrupt_mask;
-	new_val |= (~enabled_irq_mask & interrupt_mask);
+	new_val = I915_READ(GEN8_DE_PIPE_IER(pipe));
+	if (enabled_irq_mask)
+		new_val |= enabled_irq_mask;
+	else
+		new_val &= ~interrupt_mask;
 
-	if (new_val != dev_priv->de_irq_mask[pipe]) {
-		dev_priv->de_irq_mask[pipe] = new_val;
-		I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
-		POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
-	}
+	I915_WRITE(GEN8_DE_PIPE_IER(pipe), new_val);
+	POSTING_READ(GEN8_DE_PIPE_IER(pipe));
 }
 
 /**
@@ -3450,8 +3449,9 @@ static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
 				  GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
 	}
 
-	de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
-					   GEN8_PIPE_FIFO_UNDERRUN;
+	de_pipe_enables = de_pipe_masked | GEN8_PIPE_FIFO_UNDERRUN;
+
+	de_pipe_masked |= GEN8_PIPE_VBLANK;
 
 	de_port_enables = de_port_masked;
 	if (IS_GEN9_LP(dev_priv))
Signature · 1 line
1.9.1
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#28 lore raw
In reply to Vidya Srinivas
Quoted 68 lines

-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Vidya Srinivas
Sent: Thursday, September 14, 2017 5:42 PM
To: [email protected]
Cc: Srinivas, Vidya <[email protected]>
Subject: [Intel-gfx] [PATCH 1/2] drm/i915: Enable scanline read for gen9 dsi

From: Uma Shankar <[email protected]>

For gen9 platforms, dsi timings are driven from port instead of pipe (unlike ddi). Thus, we can't rely on pipe registers to get the timing information. Even scanline register read will not be functional.
This is causing vblank evasion logic to fail since it relies on scanline, causing atomic update failure warnings.

This patch uses pipe framestamp and current timestamp registers to calculate scanline. This is an indirect way to get the scanline. It helps resolve atomic update failure for gen9 dsi platforms.

v2: Addressed Ville and Daniel's review comments. Updated the register MACROs, handled race condition for register reads, extracted timings from the hwmode. Removed the dependency on
crtc->config to get the encoder type.

v3: Made get scanline function generic

Credits-to: Ville Syrjälä <[email protected]>

---
 drivers/gpu/drm/i915/i915_drv.h      |  2 ++
 drivers/gpu/drm/i915/i915_irq.c      |  7 +++++
 drivers/gpu/drm/i915/i915_reg.h      | 11 +++++++
 drivers/gpu/drm/i915/intel_display.c | 60
++++++++++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index 1cc31a5..d9efe83 100644

drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -4085,6 +4085,8 @@ void intel_sbi_write(struct drm_i915_private
 *dev_priv, u16 reg, u32 value,
 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);  void
 vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 
+u32 gen9_get_scanline(struct intel_crtc *crtc);
+
 /* intel_dpio_phy.c */
 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum

port port,

drivers/gpu/drm/i915/i915_drv.h +0 -0
 			     enum dpio_phy *phy, enum dpio_channel *ch);
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_irq.c index 5d391e6..47668dd 100644

drivers/gpu/drm/i915/i915_irq.c +1 -0
@@ -781,6 +781,7 @@ static int __intel_get_crtc_scanline(struct intel_crtc
 *crtc)
 	struct drm_vblank_crtc *vblank;
 	enum pipe pipe = crtc->pipe;
 	int position, vtotal;
+	struct intel_encoder *encoder;
 
 	if (!crtc->active)
drivers/gpu/drm/i915/i915_irq.c +0 -0
 		return -1;

drivers/gpu/drm/i915/i915_irq.c static int __intel_get_crtc_scanline(struct intel_crtc · line 797

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
@@ -792,6 +793,12 @@ static int __intel_get_crtc_scanline(struct intel_crtc
 *crtc)
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
 		vtotal /= 2;
 
+	if (IS_BROXTON(dev_priv) || IS_GEMINILAKE(dev_priv)) {

Can we use IS_GEN9_LP macro, as this macro is valid only for GLK and BXT??

Quoted 16 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+		for_each_encoder_on_crtc(crtc->base.dev, &crtc->base,
 encoder)
+			if (encoder->type == INTEL_OUTPUT_DSI)
+				return gen9_get_scanline(crtc);
+	}
+
 	if (IS_GEN2(dev_priv))

position = I915_READ_FW(PIPEDSL(pipe)) &
DSL_LINEMASK_GEN2;

drivers/gpu/drm/i915/i915_irq.c +0 -0
 	else
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 0b03260..85168ee 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -8802,6 +8802,17 @@ enum skl_power_gate {
 #define MIPIO_TXESC_CLK_DIV2			_MMIO(0x160008)

drivers/gpu/drm/i915/i915_reg.h enum skl_power_gate { · line 8812

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +7 -0
 #define  GLK_TX_ESC_CLK_DIV2_MASK			0x3FF
 
+/* Gen4+ Timestamp and Pipe Frame time stamp registers */
+#define GEN4_TIMESTAMP_CTR	_MMIO(MCHBAR_MIRROR_BASE +
 0x2358)
+#define GEN7_TIMESTAMP_CTR	_MMIO(0x44070)
+
+#define _PIPE_FRMTMSTMP_A		0x70048
+#define _PIPE_FRMTMSTMP_B		0x71048
+#define _IVB_PIPE_FRMTMSTMP_C	0x72048

Alignment seems incorrect.

Quoted 28 lines
drivers/gpu/drm/i915/i915_reg.h +4 -0
+#define PIPE_FRMTMSTMP(pipe)		\
+			_MMIO_PIPE3((pipe), _PIPE_FRMTMSTMP_A, \
+				_PIPE_FRMTMSTMP_B,
 _IVB_PIPE_FRMTMSTMP_C)
+
 /* BXT MIPI clock controls */

#define BXT_MAX_VAR_OUTPUT_KHZ 39500

drivers/gpu/drm/i915/intel_display.c +11 -0
index 0871807..601032f 100644
@@ -10352,6 +10352,66 @@ static bool needs_scaling(const struct
 intel_plane_state *state)
 	return (src_w != dst_w || src_h != dst_h);  }
 
+/*
+ * For Gen9 DSI, pipe scanline register will not
+ * work to get the scanline since the timings
+ * are driven from the PORT (unlike DDI encoders).
+ * This function will use Framestamp and current
+ * timestamp registers to calculate the scanline.
+ */
+u32 gen9_get_scanline(struct intel_crtc *crtc) {
+	struct drm_device *dev = crtc->base.dev;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	u32 crtc_vblank_start = crtc->base.mode.crtc_vblank_start;

drivers/gpu/drm/i915/intel_display.c static bool needs_scaling(const struct · line 10375

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10 -0
+	u32 crtc_vtotal = crtc->base.mode.crtc_vtotal;
+	u32 crtc_htotal = crtc->base.mode.crtc_htotal;
+	u32 crtc_clock = crtc->base.mode.crtc_clock;
+	u64 scanline = 0, scan_prev_time, scan_curr_time, scan_post_time;
+
+	WARN_ON(!crtc_vtotal);
+	if (!crtc_vtotal)
+		return scanline;
+
+	/* To avoid the race condition where we might cross into the

Please use multiline comment style.

Regards,
Madhav

Quoted 51 lines
drivers/gpu/drm/i915/intel_display.c +1 -0
+	 * next vblank just between the PIPE_FRMTMSTMP and

TIMESTAMP_CTR

drivers/gpu/drm/i915/intel_display.c +1 -0
+	 * reads. We make sure we read PIPE_FRMTMSTMP and

TIMESTAMP_CTR

drivers/gpu/drm/i915/intel_display.c +9 -0
+	 * during the same frame.
+	 */
+	do {
+		/*
+		 * This field provides read back of the display
+		 * pipe frame time stamp. The time stamp value
+		 * is sampled at every start of vertical blank.
+		 */
+		scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc-
Quoted 1 line

pipe));

drivers/gpu/drm/i915/intel_display.c +8 -0
+
+		/*
+		 * The TIMESTAMP_CTR register has the current
+		 * time stamp value.
+		 */
+		scan_curr_time = I915_READ_FW(GEN7_TIMESTAMP_CTR);
+
+		scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc-
Quoted 1 line

pipe));

drivers/gpu/drm/i915/intel_display.c +12 -0
+	} while (scan_post_time != scan_prev_time);
+
+	/*
+	 * Since the register is 32 bit and the values
+	 * can overflow and wrap around, making sure
+	 * current time accounts for the register
+	 * wrap
+	 */
+	if (scan_curr_time < scan_prev_time)
+		scan_curr_time += 0x100000000;
+
+	scanline = div_u64(mul_u64_u32_shr((scan_curr_time -

scan_prev_time),

drivers/gpu/drm/i915/intel_display.c +7 -0
+					crtc_clock, 0), 1000 * crtc_htotal);
+	scanline = min(scanline, (u64)(crtc_vtotal - 1));
+	scanline = (scanline + crtc_vblank_start) % crtc_vtotal;
+
+	return scanline;
+}
+
 int intel_plane_atomic_calc_changes(const struct intel_crtc_state

*old_crtc_state,

drivers/gpu/drm/i915/intel_display.c +0 -0
 				    struct drm_crtc_state *crtc_state,
 				    const struct intel_plane_state

*old_plane_state,
--
1.9.1

Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#29 lore raw

✓ Fi.CI.BAT: success for drm/i915: Enable scanline read for gen9 dsi (rev2)

In reply to Vidya Srinivas
== Series Details ==

== Series Details ==

Series: drm/i915: Enable scanline read for gen9 dsi (rev2)
URL : https://patchwork.freedesktop.org/series/30032/
State : success

== Summary ==

Series 30032v2 drm/i915: Enable scanline read for gen9 dsi
https://patchwork.freedesktop.org/api/1.0/series/30032/revisions/2/mbox/

Test chamelium:

        Subgroup dp-crc-fast:
                fail       -> PASS       (fi-kbl-7500u) fdo#102514
Test kms_cursor_legacy:
        Subgroup basic-busy-flip-before-cursor-legacy:
                pass       -> FAIL       (fi-snb-2600) fdo#100215

fdo#102514 https://bugs.freedesktop.org/show_bug.cgi?id=102514
fdo#100215 https://bugs.freedesktop.org/show_bug.cgi?id=100215

fi-bdw-5557u     total:289  pass:268  dwarn:0   dfail:0   fail:0   skip:21  time:450s
fi-bdw-gvtdvm    total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:452s
fi-blb-e6850     total:289  pass:224  dwarn:1   dfail:0   fail:0   skip:64  time:377s
fi-bsw-n3050     total:289  pass:243  dwarn:0   dfail:0   fail:0   skip:46  time:534s
fi-bwr-2160      total:289  pass:184  dwarn:0   dfail:0   fail:0   skip:105 time:268s
fi-bxt-j4205     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:505s
fi-byt-j1900     total:289  pass:254  dwarn:1   dfail:0   fail:0   skip:34  time:496s
fi-byt-n2820     total:289  pass:250  dwarn:1   dfail:0   fail:0   skip:38  time:497s
fi-cfl-s         total:289  pass:250  dwarn:4   dfail:0   fail:0   skip:35  time:452s
fi-elk-e7500     total:289  pass:230  dwarn:0   dfail:0   fail:0   skip:59  time:445s
fi-glk-2a        total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:592s
fi-hsw-4770      total:289  pass:263  dwarn:0   dfail:0   fail:0   skip:26  time:427s
fi-hsw-4770r     total:289  pass:263  dwarn:0   dfail:0   fail:0   skip:26  time:414s
fi-ilk-650       total:289  pass:229  dwarn:0   dfail:0   fail:0   skip:60  time:433s
fi-ivb-3520m     total:289  pass:261  dwarn:0   dfail:0   fail:0   skip:28  time:489s
fi-ivb-3770      total:289  pass:261  dwarn:0   dfail:0   fail:0   skip:28  time:460s
fi-kbl-7500u     total:289  pass:264  dwarn:1   dfail:0   fail:0   skip:24  time:492s
fi-kbl-7560u     total:289  pass:270  dwarn:0   dfail:0   fail:0   skip:19  time:583s
fi-kbl-r         total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:582s
fi-pnv-d510      total:289  pass:223  dwarn:1   dfail:0   fail:0   skip:65  time:555s
fi-skl-6260u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:476s
fi-skl-6700k     total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:521s
fi-skl-6770hq    total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:500s
fi-skl-gvtdvm    total:289  pass:266  dwarn:0   dfail:0   fail:0   skip:23  time:463s
fi-skl-x1585l    total:289  pass:268  dwarn:0   dfail:0   fail:0   skip:21  time:480s
fi-snb-2520m     total:289  pass:251  dwarn:0   dfail:0   fail:0   skip:38  time:568s
fi-snb-2600      total:289  pass:249  dwarn:0   dfail:0   fail:1   skip:39  time:428s

694f07d3df18c02da3f526ae0e1238eb12534e1e drm-tip: 2017y-09m-12d-09h-59m-00s UTC integration manifest fe9d6f3fa9fd drm/i915: Enable scanline read for gen9 dsi

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_5660/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#30 lore raw

✗ Fi.CI.IGT: warning for drm/i915: Enable scanline read for gen9 dsi (rev2)

In reply to Vidya Srinivas
== Series Details ==

== Series Details ==

Series: drm/i915: Enable scanline read for gen9 dsi (rev2)
URL : https://patchwork.freedesktop.org/series/30032/
State : warning

== Summary ==

Test kms_setmode:

        Subgroup basic:
                pass       -> FAIL       (shard-hsw) fdo#99912
Test perf:
        Subgroup blocking:
                pass       -> FAIL       (shard-hsw) fdo#102252
Test kms_frontbuffer_tracking:
        Subgroup fbc-1p-primscrn-pri-indfb-draw-mmap-cpu:
                pass       -> SKIP       (shard-hsw)
        Subgroup fbc-1p-primscrn-pri-indfb-draw-render:
                pass       -> SKIP       (shard-hsw)
Test kms_flip_event_leak:
                pass       -> SKIP       (shard-hsw)

fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912
fdo#102252 https://bugs.freedesktop.org/show_bug.cgi?id=102252

shard-hsw total:2301 pass:1233 dwarn:0 dfail:0 fail:13 skip:1055 time:9428s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_5660/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx