Skip to contentSkip to conversation

drm/i915: read current freq from Punit on VLV

PATCH Applied Jesse Barnes 4 participants 9 messages May 2, 2013 – May 6, 2013

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

PATCH 1/4 drm/i915: read current freq from Punit on VLV

Instead of returning the cached value, which is just what the kernel requested.

---
 drivers/gpu/drm/i915/i915_sysfs.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_sysfs.c +6 -3
index ca00df2..c0d7875 100644
@@ -212,10 +212,13 @@ static ssize_t gt_cur_freq_mhz_show(struct device *kdev,
 	int ret;
 
 	mutex_lock(&dev_priv->rps.hw_lock);
-	if (IS_VALLEYVIEW(dev_priv->dev))
-		ret = vlv_gpu_freq(dev_priv->mem_freq, dev_priv->rps.cur_delay);
-	else
+	if (IS_VALLEYVIEW(dev_priv->dev)) {
+		u32 freq;
+		valleyview_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS, &freq);
+		ret = vlv_gpu_freq(dev_priv->mem_freq, (freq >> 8) & 0xff);
+	} else {
 		ret = dev_priv->rps.cur_delay * GT_FREQUENCY_MULTIPLIER;
+	}
 	mutex_unlock(&dev_priv->rps.hw_lock);
 
 	return snprintf(buf, PAGE_SIZE, "%d\n", ret);
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/4 drm/i915: go back to switch for VLV mem freq detection v2

Both the docs and the existing code were wrong. So fix both and use a switch statement like we do elsewhere to make things simple & clear.

---
 drivers/gpu/drm/i915/intel_pm.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_pm.c +12 -1
index 0f4b46e..556b989 100644
@@ -2902,7 +2902,18 @@ static void valleyview_enable_rps(struct drm_device *dev)
 		   GEN7_RC_CTL_TO_MODE);
 
 	valleyview_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS, &val);
-	dev_priv->mem_freq = 800 + (266 * (val >> 6) & 3);
+	switch ((val >> 6) & 3) {
+	case 0:
+	case 1:
+		dev_priv->mem_freq = 800;
+		break;
+	case 2:
+		dev_priv->mem_freq = 1066;
+		break;
+	case 3:
+		dev_priv->mem_freq = 1333;
+		break;
+	}
 	DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq);
 
 	DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no");
Signature · 1 line
1.7.10.4
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] drm/i915: go back to switch for VLV mem freq detection v2

Quoted 22 lines · Jesse Barnes

Both the docs and the existing code were wrong. So fix both and use a switch statement like we do elsewhere to make things simple & clear.

---
 drivers/gpu/drm/i915/intel_pm.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_pm.c +5 -1
index 0f4b46e..556b989 100644
@@ -2902,7 +2902,18 @@ static void valleyview_enable_rps(struct drm_device *dev)
 		   GEN7_RC_CTL_TO_MODE);
 
 	valleyview_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS, &val);
-	dev_priv->mem_freq = 800 + (266 * (val >> 6) & 3);
+	switch ((val >> 6) & 3) {
+	case 0:
+	case 1:
+		dev_priv->mem_freq = 800;
+		break;

drivers/gpu/drm/i915/intel_pm.c static void valleyview_enable_rps(struct drm_device *dev) · line 2919

Quoted 10 lines
drivers/gpu/drm/i915/intel_pm.c +7 -0
+	case 2:
+		dev_priv->mem_freq = 1066;
+		break;
+	case 3:
+		dev_priv->mem_freq = 1333;
+		break;
+	}
 	DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq);
 
 	DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no");

The code does what the author wants it to, but I don't have the doc that says this:

Since I've set up a precedent of providing what I think are better options:
freq_lut[] = {800, 800, 1066, 1333};
freq_lut[(val >> 6) & 3];

[really ugly one-liner redacted]

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#3 lore raw

Re: [PATCH 2/4] drm/i915: go back to switch for VLV mem freq detection v2

Quoted 32 lines · Ben Widawsky
Quoted 31 lines · Jesse Barnes

Both the docs and the existing code were wrong. So fix both and use a switch statement like we do elsewhere to make things simple & clear.

---
 drivers/gpu/drm/i915/intel_pm.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_pm.c +12 -1
index 0f4b46e..556b989 100644
@@ -2902,7 +2902,18 @@ static void valleyview_enable_rps(struct drm_device *dev)
 		   GEN7_RC_CTL_TO_MODE);
 
 	valleyview_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS, &val);
-	dev_priv->mem_freq = 800 + (266 * (val >> 6) & 3);
+	switch ((val >> 6) & 3) {
+	case 0:
+	case 1:
+		dev_priv->mem_freq = 800;
+		break;
+	case 2:
+		dev_priv->mem_freq = 1066;
+		break;
+	case 3:
+		dev_priv->mem_freq = 1333;
+		break;
+	}
 	DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq);
 
Quoted 5 lines

drivers/gpu/drm/i915/intel_pm.c static void valleyview_enable_rps(struct drm_device *dev) · line 2919

Quoted 1 line
drivers/gpu/drm/i915/intel_pm.c +0 -0
 	DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no");

The code does what the author wants it to, but I don't have the doc that says this:

First two patches of this series are merged to dinq, thanks. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#4 lore raw

PATCH 3/4 drm/i915: set proper DPIO post divider for VGA on VLV v4

In reply to Jesse Barnes

Supposedly we should use the DAC divider for <300MHz pixel clocks, but as that doesn't actually work as well as the high freq divider here in practice, just use the high freq divider all the time.

v2: remove unconditional write (Jesse)
check for pixel rate properly (Jesse)
v3: give up, the DAC divider apparently doesn't work, and low res modes
work ok (Jesse)
remove debug msg (Jesse)

---
 drivers/gpu/drm/i915/intel_display.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_display.c +7 -4
index 6504337..59c2114 100644
@@ -4425,10 +4425,13 @@ static void vlv_update_pll(struct intel_crtc *crtc)
 	mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
 	mdiv |= ((bestn << DPIO_N_SHIFT));
 	mdiv |= (1 << DPIO_K_SHIFT);
-	if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI) ||
-	    intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
-	    intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
-		mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
+
+	/*
+	 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
+	 * but we don't support that).
+	 * Note: don't use the DAC post divider as it seems unstable.
+	 */
+	mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
 	intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
 
 	mdiv |= DPIO_ENABLE_CALIBRATION;
Signature · 1 line
1.7.10.4
Tested-by on v1 3/4
#5 lore raw

Re: [PATCH 3/4] drm/i915: set proper DPIO post divider for VGA on VLV v4

Quoted 11 lines · Jesse Barnes

Supposedly we should use the DAC divider for <300MHz pixel clocks, but as that doesn't actually work as well as the high freq divider here in practice, just use the high freq divider all the time.

v2: remove unconditional write (Jesse)
check for pixel rate properly (Jesse)
v3: give up, the DAC divider apparently doesn't work, and low res modes
work ok (Jesse)
remove debug msg (Jesse)

VGA is broken with today's drm-intel-next-queued (3a2128bcac1ae). Applying this patch fixes it. Thanks!

Quoted 27 lines
---
  drivers/gpu/drm/i915/intel_display.c |   11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_display.c +7 -4
index 6504337..59c2114 100644
@@ -4425,10 +4425,13 @@ static void vlv_update_pll(struct intel_crtc *crtc)
  	mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  	mdiv |= ((bestn << DPIO_N_SHIFT));
  	mdiv |= (1 << DPIO_K_SHIFT);
-	if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI) ||
-	    intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
-	    intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
-		mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
+
+	/*
+	 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
+	 * but we don't support that).
+	 * Note: don't use the DAC post divider as it seems unstable.
+	 */
+	mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  	intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
 
  	mdiv |= DPIO_ENABLE_CALIBRATION;
#6 lore raw

Re: [PATCH 3/4] drm/i915: set proper DPIO post divider for VGA on VLV v4

Quoted 11 lines · Kenneth Graunke
Quoted 10 lines · Jesse Barnes

Supposedly we should use the DAC divider for <300MHz pixel clocks, but as that doesn't actually work as well as the high freq divider here in practice, just use the high freq divider all the time.

v2: remove unconditional write (Jesse)
check for pixel rate properly (Jesse)
v3: give up, the DAC divider apparently doesn't work, and low res modes
work ok (Jesse)
remove debug msg (Jesse)

Quoted 6 lines
Quoted 1 line

VGA is broken with today's drm-intel-next-queued (3a2128bcac1ae). Applying this patch fixes it. Thanks!

Queued for -next, thanks for the patch.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#7 lore raw

PATCH 4/4 drm/i915: BIOS and power context stolen mem handling for VLV

In reply to Jesse Barnes

But we need to get the right stolen base and make pre-allocated objects for BIOS stuff so we don't clobber it. If the BIOS hasn't allocated a power context, we allocate one here too, from stolen space as required by the docs.

---
 drivers/gpu/drm/i915/i915_drv.h        |    2 +
 drivers/gpu/drm/i915/i915_gem_stolen.c |   78 +++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_reg.h        |    1 +
 3 files changed, 80 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 3ac71db..5e9ea36 100644
@@ -1055,6 +1055,8 @@ typedef struct drm_i915_private {
 
 	struct i915_gpu_error gpu_error;
 
+	struct drm_i915_gem_object *vlv_pctx;
+
 	/* list of fbdev register on this device */
 	struct intel_fbdev *fbdev;
 
drivers/gpu/drm/i915/i915_gem_stolen.c +77 -1

104 lines not on this page · raw message

drivers/gpu/drm/i915/i915_reg.h +1 -0
index b5d87bd..1cc43ce 100644
@@ -700,6 +700,7 @@
 #define VLV_IIR		(VLV_DISPLAY_BASE + 0x20a4)
 #define VLV_IMR		(VLV_DISPLAY_BASE + 0x20a8)
 #define VLV_ISR		(VLV_DISPLAY_BASE + 0x20ac)
+#define VLV_PCBR	(VLV_DISPLAY_BASE + 0x2120)
 #define   I915_PIPE_CONTROL_NOTIFY_INTERRUPT		(1<<18)
 #define   I915_DISPLAY_PORT_INTERRUPT			(1<<17)
 #define   I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT	(1<<15)
Signature · 1 line
1.7.10.4
#8 lore raw

Re: [PATCH 4/4] drm/i915: BIOS and power context stolen mem handling for VLV

Quoted 30 lines · Jesse Barnes

But we need to get the right stolen base and make pre-allocated objects for BIOS stuff so we don't clobber it. If the BIOS hasn't allocated a power context, we allocate one here too, from stolen space as required by the docs.

---
 drivers/gpu/drm/i915/i915_drv.h        |    2 +
 drivers/gpu/drm/i915/i915_gem_stolen.c |   78 +++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_reg.h        |    1 +
 3 files changed, 80 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 3ac71db..5e9ea36 100644
@@ -1055,6 +1055,8 @@ typedef struct drm_i915_private {
 
 	struct i915_gpu_error gpu_error;
 
+	struct drm_i915_gem_object *vlv_pctx;
+
 	/* list of fbdev register on this device */
 	struct intel_fbdev *fbdev;
 
drivers/gpu/drm/i915/i915_gem_stolen.c +0 -0
index 67d3510..c06056a 100644

drivers/gpu/drm/i915/i915_gem_stolen.c static unsigned long i915_stolen_to_physical(struct drm_device *dev) · line 68

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +4 -1
@@ -62,7 +62,10 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
 	 * its value of TOLUD.
 	 */
 	base = 0;
-	if (INTEL_INFO(dev)->gen >= 6) {
+	if (IS_VALLEYVIEW(dev)) {
+		pci_read_config_dword(pdev, 0x5c, &base);
+		base &= ((1<<19) - 1);
+	} if (INTEL_INFO(dev)->gen >= 6) {

else if

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +4 -0
 		/* Read Base Data of Stolen Memory Register (BDSM) directly.
 		 * Note that there is also a MCHBAR miror at 0x1080c0 or
 		 * we could use device 2:0x5c instead.
@@ -172,14 +175,82 @@ void i915_gem_stolen_cleanup_compression(struct drm_device *dev)
 	dev_priv->cfb_size = 0;
 }
 
+static void valleyview_setup_pctx(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_gem_object *pctx;

drivers/gpu/drm/i915/i915_gem_stolen.c void i915_gem_stolen_cleanup_compression(struct drm_device *dev) · line 191

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10 -0
+	unsigned long pctx_paddr;
+	u32 pcbr;
+	int pctx_size = 24*1024;
+
+	pcbr = I915_READ(VLV_PCBR);
+	if (pcbr) {
+		/* BIOS set it up already, grab the pre-alloc'd space */
+		int pcbr_offset;
+
+		pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base;

s/4095/PAGE_MASK?

drivers/gpu/drm/i915/i915_gem_stolen.c void i915_gem_stolen_cleanup_compression(struct drm_device *dev) · line 195

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +4 -0
+		pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev,
+								      pcbr_offset,
+								      pcbr_offset,
+								      pctx_size);

Can you remind me how we can get away with the assumption that gtt offset has a 1:1 mapping with the stolen offset?

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +11 -0
+		/* We don't need to track it since we don't own it */
+		return;
+	}
+
+	/*
+	 * From the Gunit register HAS:
+	 * The Gfx driver is expected to program this register and ensure
+	 * proper allocation within Gfx stolen memory.  For example, this
+	 * register should be programmed such than the PCBR range does not
+	 * overlap with other ranges, such as the frame buffer, protected
+	 * memory, or any other relevant ranges.

drivers/gpu/drm/i915/i915_gem_stolen.c void i915_gem_stolen_cleanup_compression(struct drm_device *dev) · line 216

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10 -0
+	 */
+	pctx = i915_gem_object_create_stolen(dev, pctx_size);
+	if (!pctx) {
+		DRM_DEBUG("not enough stolen space for PCTX, disabling\n");
+		return;
+	}
+
+	dev_priv->vlv_pctx = pctx;
+	pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start;
+	I915_WRITE(VLV_PCBR, pctx_paddr);

Does the powerctx need to be reinitialized after GPU reset?

Quoted 42 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +29 -0
+}
 
+
+static void valleyview_cleanup_pctx(struct drm_device *dev)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	if (!dev_priv->vlv_pctx)
+		return;
+
+	i915_gem_object_release_stolen(dev_priv->vlv_pctx);
+	I915_WRITE(VLV_PCBR, 0);
+}
+
 void i915_gem_cleanup_stolen(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 
 	i915_gem_stolen_cleanup_compression(dev);
+	if (IS_VALLEYVIEW(dev))
+		valleyview_cleanup_pctx(dev);
 	drm_mm_takedown(&dev_priv->mm.stolen);
 }
 
+/* On VLV make sure we create pre-alloc'd objects for BIOS bits */
+static void valleyview_init_bios_stolen(struct drm_i915_private *dev_priv)
+{
+	struct drm_i915_gem_object *bios_stolen;
+	int bios_offset;
+
+	/* Top 1M of stolen space is used by firmware */
+	bios_offset = dev_priv->gtt.stolen_size - 1024*1024;
+	bios_stolen = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev,
+								     bios_offset,
+								     bios_offset,
+								     1024*1024);
+}
+
 int i915_gem_init_stolen(struct drm_device *dev)
 {
drivers/gpu/drm/i915/i915_gem_stolen.c +0 -0
 	struct drm_i915_private *dev_priv = dev->dev_private;

drivers/gpu/drm/i915/i915_gem_stolen.c int i915_gem_init_stolen(struct drm_device *dev) · line 266

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +0 -0
@@ -194,6 +265,11 @@ int i915_gem_init_stolen(struct drm_device *dev)
 	/* Basic memrange allocator for stolen space */
 	drm_mm_init(&dev_priv->mm.stolen, 0, dev_priv->gtt.stolen_size);

I think you should chop off the 1MB here instead of making a stolen object which we don't want to use or touch

drivers/gpu/drm/i915/i915_gem_stolen.c int i915_gem_init_stolen(struct drm_device *dev) · line 270

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +3 -0
+	if (IS_VALLEYVIEW(dev)) {
+		valleyview_init_bios_stolen(dev_priv);
+		valleyview_setup_pctx(dev);
       drm_mm_init(&dev_priv->mm.stolen, 0, dev_priv->gtt.stolen_size - 1K); 
} else {
        drm_mm_init(&dev_priv->mm.stolen, 0, dev_priv->gtt.stolen_size);
}
Quoted 23 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -0
+
 	return 0;
 }
 
drivers/gpu/drm/i915/i915_reg.h +1 -0
index b5d87bd..1cc43ce 100644
@@ -700,6 +700,7 @@
 #define VLV_IIR		(VLV_DISPLAY_BASE + 0x20a4)
 #define VLV_IMR		(VLV_DISPLAY_BASE + 0x20a8)
 #define VLV_ISR		(VLV_DISPLAY_BASE + 0x20ac)
+#define VLV_PCBR	(VLV_DISPLAY_BASE + 0x2120)
 #define   I915_PIPE_CONTROL_NOTIFY_INTERRUPT		(1<<18)
 #define   I915_DISPLAY_PORT_INTERRUPT			(1<<17)
 #define   I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT	(1<<15)
Signature · 6 lines
1.7.10.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center