Skip to contentSkip to conversation

drm/gma500: 1 fix + further cleanups

PATCH In review Hans de Goede 2 participants 12 messages Sep 9, 2022 – Sep 18, 2022

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

cover drm/gma500: 1 fix + further cleanups

Hi Patrik,

Here is another gma500 patch-series with one more bugfix and a bunch of other cleanups of stuff which I noticed while doing the previous set of bugfixes.

Regards,

Hans

Hans de Goede (6):
drm/gma500: Wait longer for the GPU to power-down drm/gma500: Remove runtime_allowed dead code in psb_unlocked_ioctl() drm/gma500: Remove never set dev_priv->rpm_enabled flag drm/gma500: Remove a couple of not useful function wrappers drm/gma500: Rewrite power management code
drm/gma500: Remove unnecessary suspend/resume wrappers

 drivers/gpu/drm/gma500/cdv_device.c    |   2 +-
 drivers/gpu/drm/gma500/gma_display.c   |  19 +--
 drivers/gpu/drm/gma500/gma_display.h   |   2 -
 drivers/gpu/drm/gma500/oaktrail_lvds.c |   1 -
 drivers/gpu/drm/gma500/power.c         | 156 +++++--------------------
 drivers/gpu/drm/gma500/power.h         |  18 ---
 drivers/gpu/drm/gma500/psb_drv.c       |  35 +-----
 drivers/gpu/drm/gma500/psb_drv.h       |   7 +-
 drivers/gpu/drm/gma500/psb_irq.c       |  15 ++-
 9 files changed, 41 insertions(+), 214 deletions(-)
Signature · 1 line
2.37.2
#1 lore raw

PATCH 1/6 drm/gma500: Wait longer for the GPU to power-down

On a cedartrail during boot the following error was logged each boot:

[   12.168341] gma500 0000:00:02.0: GPU: power management timed out.

Increase the timeout to fix this.

Sometimes the display also failed to come up properly (userspace was running normally, but the LCD was showing all black as contents). Hopefully this also fix this issue.

---
 drivers/gpu/drm/gma500/cdv_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/gma500/cdv_device.c +1 -1
index ce96234f3df2..ff5104fe5692 100644
@@ -230,7 +230,7 @@ static void cdv_init_pm(struct drm_device *dev)
 		u32 pwr_sts = inl(dev_priv->apm_base + PSB_APM_STS);
 		if ((pwr_sts & PSB_PWRGT_GFX_MASK) == 0)
 			return;
-		udelay(10);
+		usleep_range(100, 1000);
 	}
 	dev_err(dev->dev, "GPU: power management timed out.\n");
 }
Signature · 1 line
2.37.2
#2 lore raw

PATCH 2/6 drm/gma500: Remove runtime_allowed dead code in psb_unlocked_ioctl()

In reply to Hans de Goede

runtime_allowed is initialized to 0, so the runtime_allowed == 1 condition is never true making this dead code. Remove it.

---
 drivers/gpu/drm/gma500/psb_drv.c | 11 -----------
 1 file changed, 11 deletions(-)
drivers/gpu/drm/gma500/psb_drv.c +0 -11
index 54e756b48606..7a94e0d8fa6c 100644
@@ -433,18 +433,7 @@ static inline void get_brightness(struct backlight_device *bd)
 static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
-	struct drm_file *file_priv = filp->private_data;
-	struct drm_device *dev = file_priv->minor->dev;
-	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
-	static unsigned int runtime_allowed;
-
-	if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
-		runtime_allowed++;
-		pm_runtime_allow(dev->dev);
-		dev_priv->rpm_enabled = 1;
-	}
 	return drm_ioctl(filp, cmd, arg);
-	/* FIXME: do we need to wrap the other side of this */
 }
 
 static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Signature · 1 line
2.37.2
#3 lore raw

PATCH 3/6 drm/gma500: Remove never set dev_priv->rpm_enabled flag

In reply to Hans de Goede

The rpm_enabled flag is never set, remove it.

---
 drivers/gpu/drm/gma500/gma_display.c | 13 +------------
 drivers/gpu/drm/gma500/psb_drv.h     |  3 ---
 2 files changed, 1 insertion(+), 15 deletions(-)
drivers/gpu/drm/gma500/gma_display.c +1 -12
index 2f52eceda3a1..bdbd2afa8171 100644
@@ -558,18 +558,7 @@ int gma_crtc_page_flip(struct drm_crtc *crtc,
 int gma_crtc_set_config(struct drm_mode_set *set,
 			struct drm_modeset_acquire_ctx *ctx)
 {
-	struct drm_device *dev = set->crtc->dev;
-	struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
-	int ret;
-
-	if (!dev_priv->rpm_enabled)
-		return drm_crtc_helper_set_config(set, ctx);
-
-	pm_runtime_forbid(dev->dev);
-	ret = drm_crtc_helper_set_config(set, ctx);
-	pm_runtime_allow(dev->dev);
-
-	return ret;
+	return drm_crtc_helper_set_config(set, ctx);
 }
 
 const struct drm_crtc_funcs gma_crtc_funcs = {
drivers/gpu/drm/gma500/psb_drv.h +0 -3
index 731cc356c07a..dd6fd49d85f3 100644
@@ -486,9 +486,6 @@ struct drm_psb_private {
 	unsigned int core_freq;
 	uint32_t iLVDS_enable;
 
-	/* Runtime PM state */
-	int rpm_enabled;
-
 	/* MID specific */
 	bool use_msi;
 	bool has_gct;
Signature · 1 line
2.37.2
#4 lore raw

PATCH 4/6 drm/gma500: Remove a couple of not useful function wrappers

In reply to Hans de Goede

The gma_crtc_set_config() and psb_unlocked_ioctl() functions are 1:1 wrappers for drm_helpers. Drop these wrappers.

---
 drivers/gpu/drm/gma500/gma_display.c | 8 +-------
 drivers/gpu/drm/gma500/gma_display.h | 2 --
 drivers/gpu/drm/gma500/psb_drv.c     | 8 +-------
 3 files changed, 2 insertions(+), 16 deletions(-)
drivers/gpu/drm/gma500/gma_display.c +1 -7
index bdbd2afa8171..fe7b8436f87a 100644
@@ -555,17 +555,11 @@ int gma_crtc_page_flip(struct drm_crtc *crtc,
 	return ret;
 }
 
-int gma_crtc_set_config(struct drm_mode_set *set,
-			struct drm_modeset_acquire_ctx *ctx)
-{
-	return drm_crtc_helper_set_config(set, ctx);
-}
-
 const struct drm_crtc_funcs gma_crtc_funcs = {
 	.cursor_set = gma_crtc_cursor_set,
 	.cursor_move = gma_crtc_cursor_move,
 	.gamma_set = gma_crtc_gamma_set,
-	.set_config = gma_crtc_set_config,
+	.set_config = drm_crtc_helper_set_config,
 	.destroy = gma_crtc_destroy,
 	.page_flip = gma_crtc_page_flip,
 	.enable_vblank = gma_crtc_enable_vblank,
drivers/gpu/drm/gma500/gma_display.h +0 -2
index 113cf048105e..c8b611a2f6c6 100644
@@ -69,8 +69,6 @@ extern int gma_crtc_page_flip(struct drm_crtc *crtc,
 			      struct drm_pending_vblank_event *event,
 			      uint32_t page_flip_flags,
 			      struct drm_modeset_acquire_ctx *ctx);
-extern int gma_crtc_set_config(struct drm_mode_set *set,
-			       struct drm_modeset_acquire_ctx *ctx);
 
 extern void gma_crtc_save(struct drm_crtc *crtc);
 extern void gma_crtc_restore(struct drm_crtc *crtc);
drivers/gpu/drm/gma500/psb_drv.c +1 -7
index 7a94e0d8fa6c..8266371aeac1 100644
@@ -430,12 +430,6 @@ static inline void get_brightness(struct backlight_device *bd)
 #endif
 }
 
-static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
-			       unsigned long arg)
-{
-	return drm_ioctl(filp, cmd, arg);
-}
-
 static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct drm_psb_private *dev_priv;
@@ -497,7 +491,7 @@ static const struct file_operations psb_gem_fops = {
 	.owner = THIS_MODULE,
 	.open = drm_open,
 	.release = drm_release,
-	.unlocked_ioctl = psb_unlocked_ioctl,
+	.unlocked_ioctl = drm_ioctl,
 	.compat_ioctl = drm_compat_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
Signature · 1 line
2.37.2
#5 lore raw

PATCH 5/6 drm/gma500: Rewrite power management code

In reply to Hans de Goede

Rewrite the power.c code. For some reason this was doing locking + refcounting + state (suspended or not) bookkeeping all by itself.

But there is no reason for this, this is all taken care of by the runtime-pm core, through pm_runtime_get()/_put().

Besides this not being necessary the DIY code is also quite weird/ buggy in some places. E.g. power_begin() would manually do a resume when not resumed already and force_on=true, followed by a pm_runtime_get(), which will cause a call to gma_power_resume() to get scheduled which would redo the entire resume again. Which can all be replaced by a single pm_runtime_get_sync() call.

Note that this is just a cleanup, this does not actually fix the (disabled through #if 0) runtime-pm support. It does now call pm_runtime_enable(), but only after doing a pm_runtime_get() at probe-time, so the device is never runtime suspended.

Doing this permanent get() + enable() instead of not calling enable() at all is necessary for the pm_runtime_get_if_in_use() call in gma_power_begin() to work properly.

Note this also removes the gma_power_is_on() call a check like this without actually holding a reference is always racy, so it is a bad idea (and therefor has no pm_runtime_foo() equivalent).

The 2 code paths which were using gma_power_is_on() are actually both guaranteed to only run when the device is powered-on so the 2 checks can simply be dropped.

---
 drivers/gpu/drm/gma500/oaktrail_lvds.c |   1 -
 drivers/gpu/drm/gma500/power.c         | 131 ++++++-------------------
 drivers/gpu/drm/gma500/power.h         |   9 --
 drivers/gpu/drm/gma500/psb_drv.c       |   6 --
 drivers/gpu/drm/gma500/psb_drv.h       |   4 +-
 drivers/gpu/drm/gma500/psb_irq.c       |  15 ++-
 6 files changed, 37 insertions(+), 129 deletions(-)
drivers/gpu/drm/gma500/oaktrail_lvds.c +0 -1
index 4d98df189e10..75b4eb1c8884 100644
@@ -61,7 +61,6 @@ static void oaktrail_lvds_set_power(struct drm_device *dev,
 			pp_status = REG_READ(PP_STATUS);
 		} while (pp_status & PP_ON);
 		dev_priv->is_lvds_on = false;
-		pm_request_idle(dev->dev);
 	}
 	gma_power_end(dev);
 }
drivers/gpu/drm/gma500/power.c +29 -102

230 lines not on this page · raw message

drivers/gpu/drm/gma500/power.h +0 -9
index 0c89c4d6ec20..243b9dd00910 100644
@@ -54,19 +54,10 @@ int gma_power_restore(struct device *_dev);
 bool gma_power_begin(struct drm_device *dev, bool force);
 void gma_power_end(struct drm_device *dev);
 
-/*
- * Use this function to do an instantaneous check for if the hw is on.
- * Only use this in cases where you know the mutex is already held such
- * as in irq install/uninstall and you need to
- * prevent a deadlock situation.  Otherwise use gma_power_begin().
- */
-bool gma_power_is_on(struct drm_device *dev);
-
 /*
  * GFX-Runtime PM callbacks
  */
 int psb_runtime_suspend(struct device *dev);
 int psb_runtime_resume(struct device *dev);
-int psb_runtime_idle(struct device *dev);
 
 #endif /*_PSB_POWERMGMT_H_*/
drivers/gpu/drm/gma500/psb_drv.c +0 -6
index 8266371aeac1..aea8876059d8 100644
@@ -407,11 +407,6 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 	if (ret)
 		return ret;
 	psb_intel_opregion_enable_asle(dev);
-#if 0
-	/* Enable runtime pm at last */
-	pm_runtime_enable(dev->dev);
-	pm_runtime_set_active(dev->dev);
-#endif
 
 	return devm_add_action_or_reset(dev->dev, psb_device_release, dev);
 
@@ -484,7 +479,6 @@ static const struct dev_pm_ops psb_pm_ops = {
 	.restore = gma_power_restore,
 	.runtime_suspend = psb_runtime_suspend,
 	.runtime_resume = psb_runtime_resume,
-	.runtime_idle = psb_runtime_idle,
 };
 
 static const struct file_operations psb_gem_fops = {
drivers/gpu/drm/gma500/psb_drv.h +1 -3
index dd6fd49d85f3..049701ce8a5f 100644
@@ -426,9 +426,7 @@ struct drm_psb_private {
 	spinlock_t irqmask_lock;
 
 	/* Power */
-	bool suspended;
-	bool display_power;
-	int display_count;
+	bool pm_initialized;
 
 	/* Modesetting */
 	struct psb_intel_mode_device mode_dev;
drivers/gpu/drm/gma500/psb_irq.c +7 -8
index 038f18ed0a95..d421031462df 100644
@@ -228,7 +228,7 @@ static irqreturn_t gma_irq_handler(int irq, void *arg)
 	vdc_stat &= dev_priv->vdc_irq_mask;
 	spin_unlock(&dev_priv->irqmask_lock);
 
-	if (dsp_int && gma_power_is_on(dev)) {
+	if (dsp_int) {
 		gma_vdc_interrupt(dev, vdc_stat);
 		handled = 1;
 	}
@@ -264,13 +264,12 @@ void gma_irq_preinstall(struct drm_device *dev)
 
 	spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
 
-	if (gma_power_is_on(dev)) {
-		PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
-		PSB_WVDC32(0x00000000, PSB_INT_MASK_R);
-		PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
-		PSB_WSGX32(0x00000000, PSB_CR_EVENT_HOST_ENABLE);
-		PSB_RSGX32(PSB_CR_EVENT_HOST_ENABLE);
-	}
+	PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
+	PSB_WVDC32(0x00000000, PSB_INT_MASK_R);
+	PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
+	PSB_WSGX32(0x00000000, PSB_CR_EVENT_HOST_ENABLE);
+	PSB_RSGX32(PSB_CR_EVENT_HOST_ENABLE);
+
 	if (dev->vblank[0].enabled)
 		dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
 	if (dev->vblank[1].enabled)
Signature · 1 line
2.37.2
#6 lore raw

PATCH 6/6 drm/gma500: Remove unnecessary suspend/resume wrappers

In reply to Hans de Goede

The psb_runtime_suspend/resume/thaw/freeze/restore functions are all just 1:1 wrappers around gma_power_suspend/_resume.

Drop these wrappers and use the DEFINE_RUNTIME_DEV_PM_OPS() macro to define the dev_pm_ops struct.

---
 drivers/gpu/drm/gma500/power.c   | 25 -------------------------
 drivers/gpu/drm/gma500/power.h   |  9 ---------
 drivers/gpu/drm/gma500/psb_drv.c | 10 +---------
 3 files changed, 1 insertion(+), 43 deletions(-)
drivers/gpu/drm/gma500/power.c +0 -25
index 5dd291dad4a4..62d2cc1923f1 100644
@@ -230,28 +230,3 @@ void gma_power_end(struct drm_device *dev)
 {
 	pm_runtime_put(dev->dev);
 }
-
-int psb_runtime_suspend(struct device *dev)
-{
-	return gma_power_suspend(dev);
-}
-
-int psb_runtime_resume(struct device *dev)
-{
-	return gma_power_resume(dev);
-}
-
-int gma_power_thaw(struct device *_dev)
-{
-	return gma_power_resume(_dev);
-}
-
-int gma_power_freeze(struct device *_dev)
-{
-	return gma_power_suspend(_dev);
-}
-
-int gma_power_restore(struct device *_dev)
-{
-	return gma_power_resume(_dev);
-}
drivers/gpu/drm/gma500/power.h +0 -9
index 243b9dd00910..063328d66652 100644
@@ -43,9 +43,6 @@ void gma_power_uninit(struct drm_device *dev);
  */
 int gma_power_suspend(struct device *dev);
 int gma_power_resume(struct device *dev);
-int gma_power_thaw(struct device *dev);
-int gma_power_freeze(struct device *dev);
-int gma_power_restore(struct device *_dev);
 
 /*
  * These are the functions the driver should use to wrap all hw access
@@ -54,10 +51,4 @@ int gma_power_restore(struct device *_dev);
 bool gma_power_begin(struct drm_device *dev, bool force);
 void gma_power_end(struct drm_device *dev);
 
-/*
- * GFX-Runtime PM callbacks
- */
-int psb_runtime_suspend(struct device *dev);
-int psb_runtime_resume(struct device *dev);
-
 #endif /*_PSB_POWERMGMT_H_*/
drivers/gpu/drm/gma500/psb_drv.c +1 -9
index aea8876059d8..9168bc620628 100644
@@ -471,15 +471,7 @@ static void psb_pci_remove(struct pci_dev *pdev)
 	drm_dev_unregister(dev);
 }
 
-static const struct dev_pm_ops psb_pm_ops = {
-	.resume = gma_power_resume,
-	.suspend = gma_power_suspend,
-	.thaw = gma_power_thaw,
-	.freeze = gma_power_freeze,
-	.restore = gma_power_restore,
-	.runtime_suspend = psb_runtime_suspend,
-	.runtime_resume = psb_runtime_resume,
-};
+static DEFINE_RUNTIME_DEV_PM_OPS(psb_pm_ops, gma_power_suspend, gma_power_resume, NULL);
 
 static const struct file_operations psb_gem_fops = {
 	.owner = THIS_MODULE,
Signature · 1 line
2.37.2
maintainer Acked-by on the v1 series
#7 lore raw
In reply to Hans de Goede
Quoted 7 lines · Hans de Goede

Hi Patrik,

Here is another gma500 patch-series with one more bugfix and a bunch of other cleanups of stuff which I noticed while doing the previous set of bugfixes.

Hi Hans, nice cleanups!

I'm rather busy at the moment so you can commit these yourself to drm-misc-next if you like.

"drm/gma500: Wait longer for the GPU to power-down" can go through drm-misc-fixes if you prefer. It fixed the timeout message on two of my CDV machines but I never saw an actual problem from the timeouts.

For the entire series:

Quoted 27 lines

Regards,

Hans

Hans de Goede (6):
drm/gma500: Wait longer for the GPU to power-down drm/gma500: Remove runtime_allowed dead code in psb_unlocked_ioctl() drm/gma500: Remove never set dev_priv->rpm_enabled flag drm/gma500: Remove a couple of not useful function wrappers drm/gma500: Rewrite power management code
drm/gma500: Remove unnecessary suspend/resume wrappers

 drivers/gpu/drm/gma500/cdv_device.c    |   2 +-
 drivers/gpu/drm/gma500/gma_display.c   |  19 +--
 drivers/gpu/drm/gma500/gma_display.h   |   2 -
 drivers/gpu/drm/gma500/oaktrail_lvds.c |   1 -
 drivers/gpu/drm/gma500/power.c         | 156 +++++--------------------
 drivers/gpu/drm/gma500/power.h         |  18 ---
 drivers/gpu/drm/gma500/psb_drv.c       |  35 +-----
 drivers/gpu/drm/gma500/psb_drv.h       |   7 +-
 drivers/gpu/drm/gma500/psb_irq.c       |  15 ++-
 9 files changed, 41 insertions(+), 214 deletions(-)

--
2.37.2

#8 lore raw

Hi,

Quoted 9 lines · Patrik Jakobsson
Quoted 7 lines · Hans de Goede

Hi Patrik,

Here is another gma500 patch-series with one more bugfix and a bunch of other cleanups of stuff which I noticed while doing the previous set of bugfixes.

Quoted 4 lines

Hi Hans, nice cleanups!

I'm rather busy at the moment so you can commit these yourself to drm-misc-next if you like.

Ok, I'm at Linux Plumbers atm, so I will take care of this in a couple of days.

Quoted 6 lines

"drm/gma500: Wait longer for the GPU to power-down" can go through drm-misc-fixes if you prefer. It fixed the timeout message on two of my CDV machines but I never saw an actual problem from the timeouts.

For the entire series:

Thanks.

Regards,

Hans

Quoted 23 lines
Quoted 22 lines

Hans de Goede (6):
drm/gma500: Wait longer for the GPU to power-down drm/gma500: Remove runtime_allowed dead code in psb_unlocked_ioctl() drm/gma500: Remove never set dev_priv->rpm_enabled flag drm/gma500: Remove a couple of not useful function wrappers drm/gma500: Rewrite power management code
drm/gma500: Remove unnecessary suspend/resume wrappers

 drivers/gpu/drm/gma500/cdv_device.c    |   2 +-
 drivers/gpu/drm/gma500/gma_display.c   |  19 +--
 drivers/gpu/drm/gma500/gma_display.h   |   2 -
 drivers/gpu/drm/gma500/oaktrail_lvds.c |   1 -
 drivers/gpu/drm/gma500/power.c         | 156 +++++--------------------
 drivers/gpu/drm/gma500/power.h         |  18 ---
 drivers/gpu/drm/gma500/psb_drv.c       |  35 +-----
 drivers/gpu/drm/gma500/psb_drv.h       |   7 +-
 drivers/gpu/drm/gma500/psb_irq.c       |  15 ++-
 9 files changed, 41 insertions(+), 214 deletions(-)

--
2.37.2

#9 lore raw
In reply to Patrik Jakobsson

Hi Patrik,

Quoted 14 lines · Patrik Jakobsson
Quoted 7 lines · Hans de Goede

Hi Patrik,

Here is another gma500 patch-series with one more bugfix and a bunch of other cleanups of stuff which I noticed while doing the previous set of bugfixes.

Hi Hans, nice cleanups!

I'm rather busy at the moment so you can commit these yourself to drm-misc-next if you like.

Quoted 6 lines

"drm/gma500: Wait longer for the GPU to power-down" can go through drm-misc-fixes if you prefer. It fixed the timeout message on two of my CDV machines but I never saw an actual problem from the timeouts.

For the entire series:

Thanks.

I'm pushing these out to drm-misc-next now, but with some small changes:

1. I have dropped the "drm/gma500: Wait longer for the GPU to power-down" patch I'm still seeing timeouts even if I increase the wait time to a full seconds. I believe that the actual issue is this line:

	dev_priv->apm_base = CDV_MSG_READ32(domain, PSB_PUNIT_PORT, PSB_APMBA);

sometimes failing. When the timeout happens I see apm_base is set to 0 and reading apm_base + cmd / sts offset returns bogus values.

I have yet to have a successful boot where the timeout does not happen since I have been poking at this (it seems success/fail wrt the timeout is random). But I suspect that with a successful boot apm_base will not be 0 and that the problem is there. To be continued...

2. For the "drm/gma500: Rewrite power management code" I noticed the following error during further testing (for the actual backlight changes):

[   12.292509] gma500 0000:00:02.0: Unbalanced pm_runtime_enable!

The problem is that pci_pm_init() which the PCI core runs for each device already does:

        pm_runtime_forbid(&dev->dev);
        pm_runtime_set_active(&dev->dev);
        pm_runtime_enable(&dev->dev);

So the pm_runtime_enable() call in "drm/gma500: Rewrite power management code" was a second enable call and as such was not necessary. So I'm going to squash in the following small fix while pushing this out:

drivers/gpu/drm/gma500/power.c +3 -3
index 62d2cc1923f1..0080b692dc3e 100644
@@ -61,10 +61,11 @@ void gma_power_init(struct drm_device *dev)
 	 * To fix this we need to call pm_runtime_get() once for each active
 	 * pipe at boot and then put() / get() for each pipe disable / enable
 	 * so that the device gets runtime suspended when no pipes are active.
+	 * Once this is in place the pm_runtime_get() below should be replaced
+	 * by a pm_runtime_allow() call to undo the pm_runtime_forbid() from
+	 * pci_pm_init().
 	 */
 	pm_runtime_get(dev->dev);
-	pm_runtime_set_active(dev->dev); /* Must be done before pm_runtime_enable()! */
-	pm_runtime_enable(dev->dev);
 
 	dev_priv->pm_initialized = true;
 }
@@ -83,7 +83,6 @@ void gma_power_uninit(struct drm_device *dev)
 	if (!dev_priv->pm_initialized)
 		return;
 
-	pm_runtime_disable(dev->dev);
 	pm_runtime_put_noidle(dev->dev);
 }
 

As you can see all the removed lines are already taken care of by the PCI core, so this squashed in change really is a no-op (other then that it silences the "Unbalanced pm_runtime_enable!" message).

Regards,

Hans

Quoted 30 lines
Quoted 29 lines

Regards,

Hans

Hans de Goede (6):
drm/gma500: Wait longer for the GPU to power-down drm/gma500: Remove runtime_allowed dead code in psb_unlocked_ioctl() drm/gma500: Remove never set dev_priv->rpm_enabled flag drm/gma500: Remove a couple of not useful function wrappers drm/gma500: Rewrite power management code
drm/gma500: Remove unnecessary suspend/resume wrappers

 drivers/gpu/drm/gma500/cdv_device.c    |   2 +-
 drivers/gpu/drm/gma500/gma_display.c   |  19 +--
 drivers/gpu/drm/gma500/gma_display.h   |   2 -
 drivers/gpu/drm/gma500/oaktrail_lvds.c |   1 -
 drivers/gpu/drm/gma500/power.c         | 156 +++++--------------------
 drivers/gpu/drm/gma500/power.h         |  18 ---
 drivers/gpu/drm/gma500/psb_drv.c       |  35 +-----
 drivers/gpu/drm/gma500/psb_drv.h       |   7 +-
 drivers/gpu/drm/gma500/psb_irq.c       |  15 ++-
 9 files changed, 41 insertions(+), 214 deletions(-)

--
2.37.2

maintainer
#10 lore raw
Quoted 30 lines · Hans de Goede

Hi Patrik,

Quoted 14 lines · Patrik Jakobsson
Quoted 7 lines · Hans de Goede

Hi Patrik,

Here is another gma500 patch-series with one more bugfix and a bunch of other cleanups of stuff which I noticed while doing the previous set of bugfixes.

Hi Hans, nice cleanups!

I'm rather busy at the moment so you can commit these yourself to drm-misc-next if you like.

Quoted 6 lines

"drm/gma500: Wait longer for the GPU to power-down" can go through drm-misc-fixes if you prefer. It fixed the timeout message on two of my CDV machines but I never saw an actual problem from the timeouts.

For the entire series:

Thanks.

I'm pushing these out to drm-misc-next now, but with some small changes:

Quoted 8 lines

1. I have dropped the "drm/gma500: Wait longer for the GPU to power-down" patch I'm still seeing timeouts even if I increase the wait time to a full seconds. I believe that the actual issue is this line:

        dev_priv->apm_base = CDV_MSG_READ32(domain, PSB_PUNIT_PORT, PSB_APMBA);

sometimes failing. When the timeout happens I see apm_base is set to 0 and reading apm_base + cmd / sts offset returns bogus values.

Ugh, that is nasty. Debugging the punit is probably not easy. But the increased delay did remove the error on two of my 64-bit CDV systems. The 32-bit system never had an issue to begin with. I can also take a closer look at this.

Quoted 5 lines

I have yet to have a successful boot where the timeout does not happen since I have been poking at this (it seems success/fail wrt the timeout is random). But I suspect that with a successful boot apm_base will not be 0 and that the problem is there. To be continued...

Do you still get working outputs when this happens? Perhaps we can work around it by simply not touching APM if apm_base is 0.

Quoted 87 lines

2. For the "drm/gma500: Rewrite power management code" I noticed the following error during further testing (for the actual backlight changes):

[   12.292509] gma500 0000:00:02.0: Unbalanced pm_runtime_enable!

The problem is that pci_pm_init() which the PCI core runs for each device already does:

        pm_runtime_forbid(&dev->dev);
        pm_runtime_set_active(&dev->dev);
        pm_runtime_enable(&dev->dev);

So the pm_runtime_enable() call in "drm/gma500: Rewrite power management code" was a second enable call and as such was not necessary. So I'm going to squash in the following small fix while pushing this out:

drivers/gpu/drm/gma500/power.c +3 -3
index 62d2cc1923f1..0080b692dc3e 100644
@@ -61,10 +61,11 @@ void gma_power_init(struct drm_device *dev)
         * To fix this we need to call pm_runtime_get() once for each active
         * pipe at boot and then put() / get() for each pipe disable / enable
         * so that the device gets runtime suspended when no pipes are active.
+        * Once this is in place the pm_runtime_get() below should be replaced
+        * by a pm_runtime_allow() call to undo the pm_runtime_forbid() from
+        * pci_pm_init().
         */
        pm_runtime_get(dev->dev);
-       pm_runtime_set_active(dev->dev); /* Must be done before pm_runtime_enable()! */
-       pm_runtime_enable(dev->dev);
 
        dev_priv->pm_initialized = true;
 }
@@ -83,7 +83,6 @@ void gma_power_uninit(struct drm_device *dev)
        if (!dev_priv->pm_initialized)
                return;
 
-       pm_runtime_disable(dev->dev);
        pm_runtime_put_noidle(dev->dev);
 }
 

As you can see all the removed lines are already taken care of by the PCI core, so this squashed in change really is a no-op (other then that it silences the "Unbalanced pm_runtime_enable!" message).

Regards,

Hans

Quoted 30 lines
Quoted 29 lines

Regards,

Hans

Hans de Goede (6):
drm/gma500: Wait longer for the GPU to power-down drm/gma500: Remove runtime_allowed dead code in psb_unlocked_ioctl() drm/gma500: Remove never set dev_priv->rpm_enabled flag drm/gma500: Remove a couple of not useful function wrappers drm/gma500: Rewrite power management code
drm/gma500: Remove unnecessary suspend/resume wrappers

 drivers/gpu/drm/gma500/cdv_device.c    |   2 +-
 drivers/gpu/drm/gma500/gma_display.c   |  19 +--
 drivers/gpu/drm/gma500/gma_display.h   |   2 -
 drivers/gpu/drm/gma500/oaktrail_lvds.c |   1 -
 drivers/gpu/drm/gma500/power.c         | 156 +++++--------------------
 drivers/gpu/drm/gma500/power.h         |  18 ---
 drivers/gpu/drm/gma500/psb_drv.c       |  35 +-----
 drivers/gpu/drm/gma500/psb_drv.h       |   7 +-
 drivers/gpu/drm/gma500/psb_irq.c       |  15 ++-
 9 files changed, 41 insertions(+), 214 deletions(-)

--
2.37.2

#11 lore raw

Hi Patrik,

Quoted 35 lines · Patrik Jakobsson
Quoted 34 lines · Hans de Goede

Hi Patrik,

Quoted 14 lines · Patrik Jakobsson
Quoted 7 lines · Hans de Goede

Hi Patrik,

Here is another gma500 patch-series with one more bugfix and a bunch of other cleanups of stuff which I noticed while doing the previous set of bugfixes.

Hi Hans, nice cleanups!

I'm rather busy at the moment so you can commit these yourself to drm-misc-next if you like.

Quoted 6 lines

"drm/gma500: Wait longer for the GPU to power-down" can go through drm-misc-fixes if you prefer. It fixed the timeout message on two of my CDV machines but I never saw an actual problem from the timeouts.

For the entire series:

Thanks.

I'm pushing these out to drm-misc-next now, but with some small changes:

1. I have dropped the "drm/gma500: Wait longer for the GPU to power-down" patch I'm still seeing timeouts even if I increase the wait time to a full seconds. I believe that the actual issue is this line:

Quoted 7 lines
Quoted 4 lines
        dev_priv->apm_base = CDV_MSG_READ32(domain, PSB_PUNIT_PORT, PSB_APMBA);

sometimes failing. When the timeout happens I see apm_base is set to 0 and reading apm_base + cmd / sts offset returns bogus values.

Ugh, that is nasty. Debugging the punit is probably not easy. But the increased delay did remove the error on two of my 64-bit CDV systems.

It seemed to fix things on my 64 bit CDV system too, but it is really hit and miss for me. I suspect that if you do a couple of full poweroff
+ boot again cycles it will be back some of the time for you too...

Quoted 2 lines

The 32-bit system never had an issue to begin with. I can also take a closer look at this.

If you feel like verifying my dev_priv->apm_base = 0; theory that would be great. Looking at the less hacky iosf-mbi access code from:
arch/x86/platform/intel/iosf_mbi.c

What might help is adding this:

drivers/gpu/drm/gma500/cdv_device.c +1 -1
index 3065596257e9..70ce06ee3c1c 100644
@@ -145,7 +145,7 @@ static int cdv_backlight_init(struct drm_device *dev)
 
 static inline u32 CDV_MSG_READ32(int domain, uint port, uint offset)
 {
-	int mcr = (0x10<<24) | (port << 16) | (offset << 8);
+	int mcr = (0x10<<24) | (port << 16) | (offset << 8) | 0xF0;
 	uint32_t ret_val = 0;
 	struct pci_dev *pci_root = pci_get_domain_bus_and_slot(domain, 0, 0);
 	pci_write_config_dword(pci_root, 0xD0, mcr);

the gma500 cdv code already does this in the write path, but the:
arch/x86/platform/intel/iosf_mbi.c code does it both the write and read paths.

Also we should probably just add the PCI root-bridge product-id to:
drivers/gpu/drm/gma500/cdv_device.c

and start using the iosf_mbi_read() / iosf_mbi_write() helpers from there.

Quoted 7 lines
Quoted 4 lines

I have yet to have a successful boot where the timeout does not happen since I have been poking at this (it seems success/fail wrt the timeout is random). But I suspect that with a successful boot apm_base will not be 0 and that the problem is there. To be continued...

Do you still get working outputs when this happens? Perhaps we can work around it by simply not touching APM if apm_base is 0.

The non working outputs thing is something weirdly timing related, I have only seen this happen when the gma500_gfx module is not in the initrd (so it gets loaded later). So I need to retry once we have a proper fix for this, atm I am using the default Fedora config of having the module inside the initrd.

Not doing random outl to IO address 0 and 0x04 seems like a good idea regardless though :)

Regards,

Hans

Quoted 89 lines
Quoted 88 lines

2. For the "drm/gma500: Rewrite power management code" I noticed the following error during further testing (for the actual backlight changes):

[   12.292509] gma500 0000:00:02.0: Unbalanced pm_runtime_enable!

The problem is that pci_pm_init() which the PCI core runs for each device already does:

        pm_runtime_forbid(&dev->dev);
        pm_runtime_set_active(&dev->dev);
        pm_runtime_enable(&dev->dev);

So the pm_runtime_enable() call in "drm/gma500: Rewrite power management code" was a second enable call and as such was not necessary. So I'm going to squash in the following small fix while pushing this out:

drivers/gpu/drm/gma500/power.c +3 -3
index 62d2cc1923f1..0080b692dc3e 100644
@@ -61,10 +61,11 @@ void gma_power_init(struct drm_device *dev)
         * To fix this we need to call pm_runtime_get() once for each active
         * pipe at boot and then put() / get() for each pipe disable / enable
         * so that the device gets runtime suspended when no pipes are active.
+        * Once this is in place the pm_runtime_get() below should be replaced
+        * by a pm_runtime_allow() call to undo the pm_runtime_forbid() from
+        * pci_pm_init().
         */
        pm_runtime_get(dev->dev);
-       pm_runtime_set_active(dev->dev); /* Must be done before pm_runtime_enable()! */
-       pm_runtime_enable(dev->dev);
 
        dev_priv->pm_initialized = true;
 }
@@ -83,7 +83,6 @@ void gma_power_uninit(struct drm_device *dev)
        if (!dev_priv->pm_initialized)
                return;
 
-       pm_runtime_disable(dev->dev);
        pm_runtime_put_noidle(dev->dev);
 }
 

As you can see all the removed lines are already taken care of by the PCI core, so this squashed in change really is a no-op (other then that it silences the "Unbalanced pm_runtime_enable!" message).

Regards,

Hans

Quoted 30 lines
Quoted 29 lines

Regards,

Hans

Hans de Goede (6):
drm/gma500: Wait longer for the GPU to power-down drm/gma500: Remove runtime_allowed dead code in psb_unlocked_ioctl() drm/gma500: Remove never set dev_priv->rpm_enabled flag drm/gma500: Remove a couple of not useful function wrappers drm/gma500: Rewrite power management code
drm/gma500: Remove unnecessary suspend/resume wrappers

 drivers/gpu/drm/gma500/cdv_device.c    |   2 +-
 drivers/gpu/drm/gma500/gma_display.c   |  19 +--
 drivers/gpu/drm/gma500/gma_display.h   |   2 -
 drivers/gpu/drm/gma500/oaktrail_lvds.c |   1 -
 drivers/gpu/drm/gma500/power.c         | 156 +++++--------------------
 drivers/gpu/drm/gma500/power.h         |  18 ---
 drivers/gpu/drm/gma500/psb_drv.c       |  35 +-----
 drivers/gpu/drm/gma500/psb_drv.h       |   7 +-
 drivers/gpu/drm/gma500/psb_irq.c       |  15 ++-
 9 files changed, 41 insertions(+), 214 deletions(-)

--
2.37.2