Skip to contentSkip to conversation

memory: tegra: Restore MC state on system resume

PATCH Applied Ashish Mhetre 3 participants 8 messages Apr 30 – May 4

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

v3 cover memory: tegra: Restore MC state on system resume

The tegra-mc platform driver does not register any dev_pm_ops, so the SoC-specific ->resume() is never invoked (e.g. tegra186_mc_resume) on system wake. On Tegra186 and later this means MC client Stream-ID override registers are not reprogrammed, and clients behind the ARM SMMU fault on the first DMA after resume.

Patch 1 makes the SoC-level ->resume() callback return void, since the sole implementation never fails. This simplifies the wrapper added in the next patch.

Patch 2 registers a dev_pm_ops on the tegra-mc driver and routes the system resume callback into mc->soc->ops->resume() so the existing SID restore path runs again on wake.

Patch 3 factors the existing intmask programming out of tegra_mc_probe() into a helper and reuses it from the resume path so the MC interrupt mask state, which is also lost across SC7, is restored on wake too.

Changes in V3:
- New patch 1 to change the SoC ->resume() callback return type from int to void, so the wrapper in patch 2 does not need to deal with an err value that is always 0. (Jon Hunter)
- Patches 2 and 3 simplified accordingly, no other functional change.

Changes in V2:
- Split the original single patch into two - register the PM ops and reprogram the MC interrupt masks on resume.

Ashish Mhetre (3):
memory: tegra: Make ->resume() callback return void
memory: tegra: Wire up system sleep PM ops
memory: tegra: Restore MC interrupt masks on resume

 drivers/memory/tegra/mc.c       | 37 ++++++++++++++++++++++++++-------
 drivers/memory/tegra/tegra186.c |  4 +---
 include/soc/tegra/mc.h          |  2 +-
 3 files changed, 32 insertions(+), 11 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v3 1/3 memory: tegra: Make ->resume() callback return void

tegra186_mc_resume() is the only implementation of the SoC ->resume() op in struct tegra_mc_ops, and it can never fail as the SID override loop has no error path. The int return value is therefore not used.

Change the prototype to return void so callers do not need to deal with a value that is always 0. If a future SoC needs to report failure from resume, an int return type can be reintroduced then.

---
 drivers/memory/tegra/tegra186.c | 4 +---
 include/soc/tegra/mc.h          | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/memory/tegra/tegra186.c +1 -3
index 91d56165605f..579d058da220 100644
@@ -154,7 +154,7 @@ static int tegra186_mc_probe_device(struct tegra_mc *mc, struct device *dev)
 	return 0;
 }
 
-static int tegra186_mc_resume(struct tegra_mc *mc)
+static void tegra186_mc_resume(struct tegra_mc *mc)
 {
 #if IS_ENABLED(CONFIG_IOMMU_API)
 	unsigned int i;
@@ -165,8 +165,6 @@ static int tegra186_mc_resume(struct tegra_mc *mc)
 		tegra186_mc_client_sid_override(mc, client, client->sid);
 	}
 #endif
-
-	return 0;
 }
 
 const struct tegra_mc_ops tegra186_mc_ops = {
include/soc/tegra/mc.h +1 -1
index e6da035d1306..25d465d70493 100644
@@ -164,7 +164,7 @@ struct tegra_mc_ops {
 	 */
 	int (*probe)(struct tegra_mc *mc);
 	void (*remove)(struct tegra_mc *mc);
-	int (*resume)(struct tegra_mc *mc);
+	void (*resume)(struct tegra_mc *mc);
 	int (*probe_device)(struct tegra_mc *mc, struct device *dev);
 };
 
Signature · 1 line
2.50.1
#2 lore raw

PATCH v3 2/3 memory: tegra: Wire up system sleep PM ops

In reply to Ashish Mhetre

The tegra-mc platform driver does not register any dev_pm_ops, so the SoC-specific ->resume() is never invoked (e.g. tegra186_mc_resume) on system wake. On Tegra186 and later this means MC client Stream-ID override registers are not reprogrammed, and clients behind the ARM SMMU fault on the first DMA after resume.

Register a dev_pm_ops on the tegra-mc driver and route the system resume callback into mc->soc->ops->resume() so the existing SID restore path runs again on wake.

No suspend callback is needed as the resume path reprograms all MC state from the static SoC tables, so there is nothing to save.

Fixes fe3b082a6eb8 ("memory: tegra: Add SID override programming for MC clients")
---
 drivers/memory/tegra/mc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/memory/tegra/mc.c +14 -0
index d620660da331..64e41338cdf2 100644
@@ -13,6 +13,7 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
+#include <linux/pm.h>
 #include <linux/slab.h>
 #include <linux/sort.h>
 #include <linux/tegra-icc.h>
@@ -1010,10 +1011,23 @@ static void tegra_mc_sync_state(struct device *dev)
 		icc_sync_state(dev);
 }
 
+static int tegra_mc_resume(struct device *dev)
+{
+	struct tegra_mc *mc = dev_get_drvdata(dev);
+
+	if (mc->soc->ops && mc->soc->ops->resume)
+		mc->soc->ops->resume(mc);
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(tegra_mc_pm_ops, NULL, tegra_mc_resume);
+
 static struct platform_driver tegra_mc_driver = {
 	.driver = {
 		.name = "tegra-mc",
 		.of_match_table = tegra_mc_of_match,
+		.pm = pm_sleep_ptr(&tegra_mc_pm_ops),
 		.suppress_bind_attrs = true,
 		.sync_state = tegra_mc_sync_state,
 	},
Signature · 1 line
2.50.1
#3 lore raw

PATCH v3 3/3 memory: tegra: Restore MC interrupt masks on resume

In reply to Ashish Mhetre

The MC interrupt mask registers lose their state across SC7. Without re-applying them on resume, MC interrupts that were enabled at probe remain masked after wake, so any post-resume MC error goes unreported.

Factor the existing intmask programming out of tegra_mc_probe() into tegra_mc_setup_intmask() and reuse it from the system resume callback so the mask state is restored on wake.

---
 drivers/memory/tegra/mc.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/memory/tegra/mc.c +16 -7
index 64e41338cdf2..cfcfc7291106 100644
@@ -911,6 +911,19 @@ static void tegra_mc_num_channel_enabled(struct tegra_mc *mc)
 	}
 }
 
+static void tegra_mc_setup_intmask(struct tegra_mc *mc)
+{
+	unsigned int i;
+
+	for (i = 0; i < mc->soc->num_intmasks; i++) {
+		if (mc->soc->num_channels)
+			mc_ch_writel(mc, MC_BROADCAST_CHANNEL, mc->soc->intmasks[i].mask,
+				     mc->soc->intmasks[i].reg);
+		else
+			mc_writel(mc, mc->soc->intmasks[i].mask, mc->soc->intmasks[i].reg);
+	}
+}
+
 static int tegra_mc_probe(struct platform_device *pdev)
 {
 	struct tegra_mc *mc;
@@ -971,13 +984,7 @@ static int tegra_mc_probe(struct platform_device *pdev)
 			}
 		}
 
-		for (i = 0; i < mc->soc->num_intmasks; i++) {
-			if (mc->soc->num_channels)
-				mc_ch_writel(mc, MC_BROADCAST_CHANNEL, mc->soc->intmasks[i].mask,
-					     mc->soc->intmasks[i].reg);
-			else
-				mc_writel(mc, mc->soc->intmasks[i].mask, mc->soc->intmasks[i].reg);
-		}
+		tegra_mc_setup_intmask(mc);
 	}
 
 	if (mc->soc->reset_ops) {
@@ -1018,6 +1025,8 @@ static int tegra_mc_resume(struct device *dev)
 	if (mc->soc->ops && mc->soc->ops->resume)
 		mc->soc->ops->resume(mc);
 
+	tegra_mc_setup_intmask(mc);
+
 	return 0;
 }
 
Signature · 1 line
2.50.1
maintainer
#4 lore raw

Re: [PATCH V3 3/3] memory: tegra: Restore MC interrupt masks on resume

Quoted 1 line · Ashish Mhetre

The MC interrupt mask registers lose their state across SC7. Without

SC7 may not mean anything to anyone that is not familiar with Tegra. I often refer to this as 'Tegra low power suspend state (aka. SC7)'. Or we can just simply say 'suspend' instead of 'SC7'.

Krzysztof, do you want use to clarify this and update the commit message?

Quoted 52 lines

re-applying them on resume, MC interrupts that were enabled at probe remain masked after wake, so any post-resume MC error goes unreported.

Factor the existing intmask programming out of tegra_mc_probe() into tegra_mc_setup_intmask() and reuse it from the system resume callback so the mask state is restored on wake.

---
  drivers/memory/tegra/mc.c | 23 ++++++++++++++++-------
  1 file changed, 16 insertions(+), 7 deletions(-)
drivers/memory/tegra/mc.c +14 -7
index 64e41338cdf2..cfcfc7291106 100644
@@ -911,6 +911,19 @@ static void tegra_mc_num_channel_enabled(struct tegra_mc *mc)
  	}
  }
 
+static void tegra_mc_setup_intmask(struct tegra_mc *mc)
+{
+	unsigned int i;
+
+	for (i = 0; i < mc->soc->num_intmasks; i++) {
+		if (mc->soc->num_channels)
+			mc_ch_writel(mc, MC_BROADCAST_CHANNEL, mc->soc->intmasks[i].mask,
+				     mc->soc->intmasks[i].reg);
+		else
+			mc_writel(mc, mc->soc->intmasks[i].mask, mc->soc->intmasks[i].reg);
+	}
+}
+
  static int tegra_mc_probe(struct platform_device *pdev)
  {
  	struct tegra_mc *mc;
@@ -971,13 +984,7 @@ static int tegra_mc_probe(struct platform_device *pdev)
  			}
  		}
 
-		for (i = 0; i < mc->soc->num_intmasks; i++) {
-			if (mc->soc->num_channels)
-				mc_ch_writel(mc, MC_BROADCAST_CHANNEL, mc->soc->intmasks[i].mask,
-					     mc->soc->intmasks[i].reg);
-			else
-				mc_writel(mc, mc->soc->intmasks[i].mask, mc->soc->intmasks[i].reg);
-		}
+		tegra_mc_setup_intmask(mc);
  	}
 
  	if (mc->soc->reset_ops) {

drivers/memory/tegra/mc.c static int tegra_mc_resume(struct device *dev) · line 1032

Quoted 8 lines
drivers/memory/tegra/mc.c +2 -0
@@ -1018,6 +1025,8 @@ static int tegra_mc_resume(struct device *dev)
  	if (mc->soc->ops && mc->soc->ops->resume)
  		mc->soc->ops->resume(mc);
 
+	tegra_mc_setup_intmask(mc);
+
  	return 0;
  }
 

Otherwise this looks good to me.

Jon

Signature · 1 line
nvpublic
#5 lore raw

Re: [PATCH V3 3/3] memory: tegra: Restore MC interrupt masks on resume

Quoted 9 lines · Jon Hunter
Quoted 1 line · Ashish Mhetre

The MC interrupt mask registers lose their state across SC7. Without

SC7 may not mean anything to anyone that is not familiar with Tegra. I often refer to this as 'Tegra low power suspend state (aka. SC7)'. Or we can just simply say 'suspend' instead of 'SC7'.

Krzysztof, do you want use to clarify this and update the commit message?

I can adjust it while applying.

Best regards,
Krzysztof

maintainer Reviewed-by on the v3 series
#6 lore raw
In reply to Ashish Mhetre
Quoted 34 lines · Ashish Mhetre

The tegra-mc platform driver does not register any dev_pm_ops, so the SoC-specific ->resume() is never invoked (e.g. tegra186_mc_resume) on system wake. On Tegra186 and later this means MC client Stream-ID override registers are not reprogrammed, and clients behind the ARM SMMU fault on the first DMA after resume.

Patch 1 makes the SoC-level ->resume() callback return void, since the sole implementation never fails. This simplifies the wrapper added in the next patch.

Patch 2 registers a dev_pm_ops on the tegra-mc driver and routes the system resume callback into mc->soc->ops->resume() so the existing SID restore path runs again on wake.

Patch 3 factors the existing intmask programming out of tegra_mc_probe() into a helper and reuses it from the resume path so the MC interrupt mask state, which is also lost across SC7, is restored on wake too.

Changes in V3:
- New patch 1 to change the SoC ->resume() callback return type from int to void, so the wrapper in patch 2 does not need to deal with an err value that is always 0. (Jon Hunter)
- Patches 2 and 3 simplified accordingly, no other functional change.

Changes in V2:
- Split the original single patch into two - register the PM ops and reprogram the MC interrupt masks on resume.

Ashish Mhetre (3):
memory: tegra: Make ->resume() callback return void
memory: tegra: Wire up system sleep PM ops
memory: tegra: Restore MC interrupt masks on resume

Quoted 5 lines
  drivers/memory/tegra/mc.c       | 37 ++++++++++++++++++++++++++-------
  drivers/memory/tegra/tegra186.c |  4 +---
  include/soc/tegra/mc.h          |  2 +-
  3 files changed, 32 insertions(+), 11 deletions(-)

For the series ...

Thanks!
Jon

Signature · 1 line
nvpublic
maintainer Applied
#7 lore raw
In reply to Ashish Mhetre
Quoted 11 lines · Ashish Mhetre

The tegra-mc platform driver does not register any dev_pm_ops, so the SoC-specific ->resume() is never invoked (e.g. tegra186_mc_resume) on system wake. On Tegra186 and later this means MC client Stream-ID override registers are not reprogrammed, and clients behind the ARM SMMU fault on the first DMA after resume.

Patch 1 makes the SoC-level ->resume() callback return void, since the sole implementation never fails. This simplifies the wrapper added in the next patch.

[...]

Applied, thanks!

[1/3] memory: tegra: Make ->resume() callback return void

      https://git.kernel.org/krzk/linux-mem-ctrl/c/4f42beeb9796e24e8009c46d1a2d676803e5ab24
[2/3] memory: tegra: Wire up system sleep PM ops
      https://git.kernel.org/krzk/linux-mem-ctrl/c/2411c8d1e3e09910e94bab0d0a2c071fbc8a9e7b
[3/3] memory: tegra: Restore MC interrupt masks on resume
      https://git.kernel.org/krzk/linux-mem-ctrl/c/35934fd08d17071c5ae0e99b95258f61f0cff763

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>