Skip to contentSkip to conversation

ARM: tegra114: bring up secondary CPU for SMP

PATCH New Joseph Lo 4 participants 24 messages Feb 22, 2013 – Feb 26, 2013

Subsystems (3)
lore
Share & tools
lore

Joseph Lo

author
#0 lore raw

cover ARM: tegra114: bring up secondary CPU for SMP

This series bring up secondary CPU for Tegra114. Because we are going to support generic power domain later, the conventional powergate driver will be removed. So we add the CPU power on/off function in PMC driver first.

This series was dependent on the patches below.
"ARM: tegra: Fix unchecked return value"
"ARM: tegra30: fix the logical detection of power on sequence of warm boot CPUs" "ARM: tegra: refactor tegra{20,30}_boot_secondary"

Joseph Lo (4):
ARM: tegra: pmc: convert PMC driver to support DT only
ARM: tegra: pmc: add power on function for secondary CPUs
ARM: tegra30: platsmp: replace the CPU power on function in PMC driver
ARM: tegra114: bring up secondary CPU for SMP

 arch/arm/mach-tegra/platsmp.c |  27 +++----
 arch/arm/mach-tegra/pmc.c     | 159 ++++++++++++++++++++++++++++++++++--------
 arch/arm/mach-tegra/pmc.h     |   4 ++
 3 files changed, 149 insertions(+), 41 deletions(-)
Signature · 1 line
1.8.1.1
author
#1 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

---
 arch/arm/mach-tegra/pmc.c | 56 +++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 28 deletions(-)
arch/arm/mach-tegra/pmc.c +28 -28
index d4fdb5f..2315e25 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
+ * Copyright (C) 2012,2013 NVIDIA CORPORATION. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -16,59 +16,59 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/err.h>
 #include <linux/io.h>
 #include <linux/of.h>
-
-#include "iomap.h"
+#include <linux/of_address.h>
 
 #define PMC_CTRL		0x0
 #define PMC_CTRL_INTR_LOW	(1 << 17)
 
+static void __iomem *tegra_pmc_base;
+static bool tegra_pmc_invert_interrupt;
+
 static inline u32 tegra_pmc_readl(u32 reg)
 {
-	return readl(IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	return readl_relaxed(tegra_pmc_base + reg);
 }
 
 static inline void tegra_pmc_writel(u32 val, u32 reg)
 {
-	writel(val, IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	writel_relaxed(val, (tegra_pmc_base + reg));
 }
 
-#ifdef CONFIG_OF
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra20-pmc" },
 	{ }
 };
-#endif
+
+static void tegra_pmc_parse_dt(void)
+{
+	struct device_node *np;
+
+	np = of_find_matching_node(NULL, matches);
+	if (np) {
+		tegra_pmc_base = of_iomap(np, 0);
+
+		tegra_pmc_invert_interrupt = of_property_read_bool(np,
+					     "nvidia,invert-interrupt");
+	} else {
+		/* Should not be here, the PMC DT node should always exist. */
+		BUG();
+	}
+}
 
 void __init tegra_pmc_init(void)
 {
-	/*
-	 * For now, Harmony is the only board that uses the PMC, and it wants
-	 * the signal inverted. Seaboard would too if it used the PMC.
-	 * Hopefully by the time other boards want to use the PMC, everything
-	 * will be device-tree, or they also want it inverted.
-	 */
-	bool invert_interrupt = true;
 	u32 val;
 
-#ifdef CONFIG_OF
-	if (of_have_populated_dt()) {
-		struct device_node *np;
+	if (!of_have_populated_dt())
+		return;
 
-		invert_interrupt = false;
-
-		np = of_find_matching_node(NULL, matches);
-		if (np) {
-			if (of_find_property(np, "nvidia,invert-interrupt",
-						NULL))
-				invert_interrupt = true;
-		}
-	}
-#endif
+	tegra_pmc_parse_dt();
 
 	val = tegra_pmc_readl(PMC_CTRL);
-	if (invert_interrupt)
+	if (tegra_pmc_invert_interrupt)
 		val |= PMC_CTRL_INTR_LOW;
 	else
 		val &= ~PMC_CTRL_INTR_LOW;
Signature · 1 line
1.8.1.1
#2 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

Quoted 45 lines · Joseph Lo

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

---
 arch/arm/mach-tegra/pmc.c | 56 +++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 28 deletions(-)
arch/arm/mach-tegra/pmc.c +7 -4
index d4fdb5f..2315e25 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
+ * Copyright (C) 2012,2013 NVIDIA CORPORATION. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -16,59 +16,59 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/err.h>
 #include <linux/io.h>
 #include <linux/of.h>
-
-#include "iomap.h"
+#include <linux/of_address.h>
 
 #define PMC_CTRL		0x0
 #define PMC_CTRL_INTR_LOW	(1 << 17)
 
+static void __iomem *tegra_pmc_base;
+static bool tegra_pmc_invert_interrupt;
+
 static inline u32 tegra_pmc_readl(u32 reg)
 {
-	return readl(IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	return readl_relaxed(tegra_pmc_base + reg);
 }
 

arch/arm/mach-tegra/pmc.c line 42

Quoted 10 lines
arch/arm/mach-tegra/pmc.c +1 -2
 static inline void tegra_pmc_writel(u32 val, u32 reg)
 {
-	writel(val, IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	writel_relaxed(val, (tegra_pmc_base + reg));
 }
 
-#ifdef CONFIG_OF
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra20-pmc" },
 	{ }

At least an extra entry for tegra114-pmc is necessary here. tegra114.dtsi only has:

pmc {
	compatible = "nvidia,tegra114-pmc", "nvidia,tegra30-pmc";
	reg = <0x7000e400 0x400>;
};

otherwise the system will crash early during boot.

Cheers,

Peter.

author
#3 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

Quoted 12 lines · Peter De Schrijver

arch/arm/mach-tegra/pmc.c line 42

Quoted 10 lines · Joseph Lo

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

arch/arm/mach-tegra/pmc.c +0 -1
-#ifdef CONFIG_OF
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra20-pmc" },
 	{ }
Quoted 8 lines

At least an extra entry for tegra114-pmc is necessary here. tegra114.dtsi only has:

pmc {
	compatible = "nvidia,tegra114-pmc", "nvidia,tegra30-pmc";
	reg = <0x7000e400 0x400>;
};

I think it should be something like below, isn't it?

compatible = "nvidia,tegra114-pmc", "nvidia,tegra30-pmc",

		"nvidia,tegra20-pmc";

or should we add tegra114 and tegra30 in the DT match table?

Thanks,
Joseph

#4 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

Quoted 21 lines · Joseph Lo
Quoted 12 lines · Peter De Schrijver

arch/arm/mach-tegra/pmc.c line 42

Quoted 10 lines · Joseph Lo

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

arch/arm/mach-tegra/pmc.c +0 -1
-#ifdef CONFIG_OF
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra20-pmc" },
 	{ }
Quoted 8 lines

At least an extra entry for tegra114-pmc is necessary here. tegra114.dtsi only has:

pmc {
	compatible = "nvidia,tegra114-pmc", "nvidia,tegra30-pmc";
	reg = <0x7000e400 0x400>;
};
Quoted 6 lines

I think it should be something like below, isn't it?

compatible = "nvidia,tegra114-pmc", "nvidia,tegra30-pmc",

		"nvidia,tegra20-pmc";

or should we add tegra114 and tegra30 in the DT match table?

The Tegra114 PMC HW is probably not 100% backwards-compatible with previous SoCs' PMC, so the DT file should probably only list the specific SoC, and the driver should probably include all the compatible values it supports.

Peter, can you confirm exactly which HW versions, if any, are 100% backwards-compatible?

#5 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

Quoted 29 lines · Stephen Warren
Quoted 21 lines · Joseph Lo
Quoted 12 lines · Peter De Schrijver

arch/arm/mach-tegra/pmc.c line 42

Quoted 10 lines · Joseph Lo

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

arch/arm/mach-tegra/pmc.c +0 -1
-#ifdef CONFIG_OF
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra20-pmc" },
 	{ }
Quoted 8 lines

At least an extra entry for tegra114-pmc is necessary here. tegra114.dtsi only has:

pmc {
	compatible = "nvidia,tegra114-pmc", "nvidia,tegra30-pmc";
	reg = <0x7000e400 0x400>;
};
Quoted 6 lines

I think it should be something like below, isn't it?

compatible = "nvidia,tegra114-pmc", "nvidia,tegra30-pmc",

		"nvidia,tegra20-pmc";

or should we add tegra114 and tegra30 in the DT match table?

Quoted 8 lines

The Tegra114 PMC HW is probably not 100% backwards-compatible with previous SoCs' PMC, so the DT file should probably only list the specific SoC, and the driver should probably include all the compatible values it supports.

Peter, can you confirm exactly which HW versions, if any, are 100% backwards-compatible?

The major difference between the PMCs are the powerdomain IDs. The Tegra30 IDs are a strict superset of the Tegra20 IDs, but the Tegra114 IDs are not. There are differences in the CPU domains and 3D. The CPU domains aren't a problem I think because we won't powergate those domains directly using the PMC. We always program the flowcontroller to do the powergating on WFI. 3D is a different story however. We do powergate 3D under software control and the sequencing is different between Tegra30 and Tegra114. Also Tegra30 has 2 domains for 3D while Tegra114 has only 1. Then ofcourse Tegra114 lacks the SATA and PCIe domains because those features are missing compared to Tegra30. But the IDs haven't been reused. All in all I think it's best to explicitly require the driver to support the various SoCs.

Cheers,

Peter.

#6 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

Quoted 1 line · Peter De Schrijver

On Sat, Feb 23, 2013 at 05:31:17AM +0100, Stephen Warren wrote:

...

Quoted 4 lines
Quoted 3 lines

Peter, can you confirm exactly which [PMC] HW versions, if any, are 100% backwards-compatible?

Quoted 11 lines

The major difference between the PMCs are the powerdomain IDs. The Tegra30 IDs are a strict superset of the Tegra20 IDs, but the Tegra114 IDs are not. There are differences in the CPU domains and 3D. The CPU domains aren't a problem I think because we won't powergate those domains directly using the PMC. We always program the flowcontroller to do the powergating on WFI. 3D is a different story however. We do powergate 3D under software control and the sequencing is different between Tegra30 and Tegra114. Also Tegra30 has 2 domains for 3D while Tegra114 has only 1. Then of course Tegra114 lacks the SATA and PCIe domains because those features are missing compared to Tegra30. But the IDs haven't been reused. All in all I think it's best to explicitly require the driver to support the various SoCs.

That does sound like a good idea; a separate compatible value for each SoC.

author
#7 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

Quoted 19 lines · Stephen Warren
Quoted 1 line · Peter De Schrijver

On Sat, Feb 23, 2013 at 05:31:17AM +0100, Stephen Warren wrote:

...

Quoted 4 lines
Quoted 3 lines

Peter, can you confirm exactly which [PMC] HW versions, if any, are 100% backwards-compatible?

Quoted 11 lines

The major difference between the PMCs are the powerdomain IDs. The Tegra30 IDs are a strict superset of the Tegra20 IDs, but the Tegra114 IDs are not. There are differences in the CPU domains and 3D. The CPU domains aren't a problem I think because we won't powergate those domains directly using the PMC. We always program the flowcontroller to do the powergating on WFI. 3D is a different story however. We do powergate 3D under software control and the sequencing is different between Tegra30 and Tegra114. Also Tegra30 has 2 domains for 3D while Tegra114 has only 1. Then of course Tegra114 lacks the SATA and PCIe domains because those features are missing compared to Tegra30. But the IDs haven't been reused. All in all I think it's best to explicitly require the driver to support the various SoCs.

Quoted 1 line

That does sound like a good idea; a separate compatible value for each SoC.

OK. Will add another patch to fix the PMC compatibility in Tegra30 and Tegra114 dts file. And also in the DT match table of PMC driver.

Thanks,
Joseph

#8 lore raw

PATCH 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

In reply to Joseph Lo

arch/arm/mach-tegra/pmc.c line 32

Quoted 12 lines · Joseph Lo

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

arch/arm/mach-tegra/pmc.c +1 -1
 
 static inline u32 tegra_pmc_readl(u32 reg)
 {
-	return readl(IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	return readl_relaxed(tegra_pmc_base + reg);

The change from readl to readl_relaxed is definitely unrelated to cleaning up DT support. It needs to be a separate patch, and needs to be mentioned in the commit description.

arch/arm/mach-tegra/pmc.c line 50

Quoted 6 lines
arch/arm/mach-tegra/pmc.c +6 -0
+static void tegra_pmc_parse_dt(void)
+{
+	struct device_node *np;
+
+	np = of_find_matching_node(NULL, matches);
+	if (np) {

Here, if (!np) BUG(); would be simpler, and allow the rest of the function not to be indented.

Quoted 2 lines

void __init tegra_pmc_init(void)
{

...

arch/arm/mach-tegra/pmc.c line 66

Quoted 2 lines
arch/arm/mach-tegra/pmc.c +2 -0
+	if (!of_have_populated_dt())
+		return;

That won't ever be true.

author
#9 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

In reply to Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

---
 arch/arm/mach-tegra/pmc.c | 105 +++++++++++++++++++++++++++++++++++++++++++++-
 arch/arm/mach-tegra/pmc.h |   4 ++
 2 files changed, 107 insertions(+), 2 deletions(-)
arch/arm/mach-tegra/pmc.c +103 -2
index 2315e25..a2446c2 100644
@@ -21,8 +21,26 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 
-#define PMC_CTRL		0x0
-#define PMC_CTRL_INTR_LOW	(1 << 17)
+#define PMC_CTRL			0x0
+#define PMC_CTRL_INTR_LOW		(1 << 17)
+#define PMC_PWRGATE_TOGGLE		0x30
+#define PMC_PWRGATE_TOGGLE_START	(1 << 8)
+#define PMC_REMOVE_CLAMPING		0x34
+#define PMC_PWRGATE_STATUS		0x38
+
+#define TEGRA_POWERGATE_PCIE	3
+#define TEGRA_POWERGATE_VDEC	4
+#define TEGRA_POWERGATE_CPU1	9
+#define TEGRA_POWERGATE_CPU2	10
+#define TEGRA_POWERGATE_CPU3	11
+
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */
+	TEGRA_POWERGATE_CPU1,
+	TEGRA_POWERGATE_CPU2,
+	TEGRA_POWERGATE_CPU3,
+};
+static DEFINE_SPINLOCK(tegra_powergate_lock);
 
 static void __iomem *tegra_pmc_base;
 static bool tegra_pmc_invert_interrupt;
@@ -37,6 +55,89 @@ static inline void tegra_pmc_writel(u32 val, u32 reg)
 	writel_relaxed(val, (tegra_pmc_base + reg));
 }
 
+static int tegra_pmc_get_cpu_powerdomain_id(int cpuid)
+{
+	if (cpuid <= 0 || cpuid > num_possible_cpus())
+		return -EINVAL;
+	return tegra_cpu_domains[cpuid];
+}
+
+static int tegra_pmc_powergate_set(int id, bool new_state)
+{
+	bool status;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tegra_powergate_lock, flags);
+
+	status = tegra_pmc_readl(PMC_PWRGATE_STATUS) & (1 << id);
+
+	WARN_ON(status == new_state);
+
+	tegra_pmc_writel(PMC_PWRGATE_TOGGLE_START | id, PMC_PWRGATE_TOGGLE);
+
+	spin_unlock_irqrestore(&tegra_powergate_lock, flags);
+
+	return 0;
+}
+
+static bool tegra_pmc_powergate_is_powered(int id)
+{
+	u32 status;
+
+	status = tegra_pmc_readl(PMC_PWRGATE_STATUS) & (1 << id);
+	return !!status;
+}
+
+static int tegra_pmc_powergate_remove_clamping(int id)
+{
+	u32 mask;
+
+	/*
+	 * Tegra has a bug where PCIE and VDE clamping masks are
+	 * swapped relatively to the partition ids.
+	 */
+	if (id ==  TEGRA_POWERGATE_VDEC)
+		mask = (1 << TEGRA_POWERGATE_PCIE);
+	else if	(id == TEGRA_POWERGATE_PCIE)
+		mask = (1 << TEGRA_POWERGATE_VDEC);
+	else
+		mask = (1 << id);
+
+	tegra_pmc_writel(mask, PMC_REMOVE_CLAMPING);
+
+	return 0;
+}
+
+bool tegra_pmc_cpu_is_powered(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (IS_ERR_VALUE(id))
+		return false;
+	return tegra_pmc_powergate_is_powered(id);
+}
+
+int tegra_pmc_cpu_power_on(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (IS_ERR_VALUE(id))
+		return id;
+	return tegra_pmc_powergate_set(id, true);
+}
+
+int tegra_pmc_cpu_remove_clamping(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (IS_ERR_VALUE(id))
+		return id;
+	return tegra_pmc_powergate_remove_clamping(id);
+}
+
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra20-pmc" },
 	{ }
arch/arm/mach-tegra/pmc.h +4 -0
index 8995ee4..7d44710 100644
@@ -18,6 +18,10 @@
 #ifndef __MACH_TEGRA_PMC_H
 #define __MACH_TEGRA_PMC_H
 
+bool tegra_pmc_cpu_is_powered(int cpuid);
+int tegra_pmc_cpu_power_on(int cpuid);
+int tegra_pmc_cpu_remove_clamping(int cpuid);
+
 void tegra_pmc_init(void);
 
 #endif
Signature · 1 line
1.8.1.1
#10 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 25 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

---
 arch/arm/mach-tegra/pmc.c | 105 +++++++++++++++++++++++++++++++++++++++++++++-
 arch/arm/mach-tegra/pmc.h |   4 ++
 2 files changed, 107 insertions(+), 2 deletions(-)
arch/arm/mach-tegra/pmc.c +5 -2
index 2315e25..a2446c2 100644
@@ -21,8 +21,26 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 
-#define PMC_CTRL		0x0
-#define PMC_CTRL_INTR_LOW	(1 << 17)
+#define PMC_CTRL			0x0
+#define PMC_CTRL_INTR_LOW		(1 << 17)
+#define PMC_PWRGATE_TOGGLE		0x30
+#define PMC_PWRGATE_TOGGLE_START	(1 << 8)
+#define PMC_REMOVE_CLAMPING		0x34

arch/arm/mach-tegra/pmc.c line 38

Quoted 10 lines
arch/arm/mach-tegra/pmc.c +10 -0
+#define PMC_PWRGATE_STATUS		0x38
+
+#define TEGRA_POWERGATE_PCIE	3
+#define TEGRA_POWERGATE_VDEC	4
+#define TEGRA_POWERGATE_CPU1	9
+#define TEGRA_POWERGATE_CPU2	10
+#define TEGRA_POWERGATE_CPU3	11
+
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */

On Tegra114 we can also powergate CPU0, so this needs to be defined then.

Cheers,

Peter.

author
#11 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 30 lines · Peter De Schrijver
Quoted 29 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

---
 arch/arm/mach-tegra/pmc.c | 105 +++++++++++++++++++++++++++++++++++++++++++++-
 arch/arm/mach-tegra/pmc.h |   4 ++
 2 files changed, 107 insertions(+), 2 deletions(-)
arch/arm/mach-tegra/pmc.c +9 -2
index 2315e25..a2446c2 100644
@@ -21,8 +21,26 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 
-#define PMC_CTRL		0x0
-#define PMC_CTRL_INTR_LOW	(1 << 17)
+#define PMC_CTRL			0x0
+#define PMC_CTRL_INTR_LOW		(1 << 17)
+#define PMC_PWRGATE_TOGGLE		0x30
+#define PMC_PWRGATE_TOGGLE_START	(1 << 8)
+#define PMC_REMOVE_CLAMPING		0x34
+#define PMC_PWRGATE_STATUS		0x38
+
+#define TEGRA_POWERGATE_PCIE	3
+#define TEGRA_POWERGATE_VDEC	4
Quoted 9 lines

arch/arm/mach-tegra/pmc.c line 38

Quoted 6 lines
arch/arm/mach-tegra/pmc.c +6 -0
+#define TEGRA_POWERGATE_CPU1	9
+#define TEGRA_POWERGATE_CPU2	10
+#define TEGRA_POWERGATE_CPU3	11
+
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */

On Tegra114 we can also powergate CPU0, so this needs to be defined then.

No, DON'T DO THAT!!
We don't allow any code to power gate CPU0 manually here or elsewhere.

The function here only for SMP and hotplug bring up for secondary CPU.

Thanks,
Joseph

#12 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 13 lines · Joseph Lo
Quoted 5 lines · Peter De Schrijver
Quoted 3 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

Quoted 7 lines

arch/arm/mach-tegra/pmc.c line 38

Quoted 4 lines
arch/arm/mach-tegra/pmc.c +2 -0
 
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */

On Tegra114 we can also powergate CPU0, so this needs to be defined then.

Quoted 4 lines

No, DON'T DO THAT!!
We don't allow any code to power gate CPU0 manually here or elsewhere.

The function here only for SMP and hotplug bring up for secondary CPU.

Doesn't Tegra114 have improved HW that does actually allow power-gating/hot-unplugging/... CPU 0, even though older HW didn't?

author
#13 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 14 lines · Stephen Warren
Quoted 13 lines · Joseph Lo
Quoted 12 lines · Peter De Schrijver

arch/arm/mach-tegra/pmc.c line 38

Quoted 8 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

arch/arm/mach-tegra/pmc.c +2 -0
 
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */

On Tegra114 we can also powergate CPU0, so this needs to be defined then.

Quoted 7 lines
Quoted 4 lines

No, DON'T DO THAT!!
We don't allow any code to power gate CPU0 manually here or elsewhere.

The function here only for SMP and hotplug bring up for secondary CPU.

Doesn't Tegra114 have improved HW that does actually allow power-gating/hot-unplugging/... CPU 0, even though older HW didn't?

Indeed. It support CPU0 be power gated. But the power up sequence does not through here by toggling PMC directly. Just like the CPU idle "powered-down" mode. The CPU0's power gating/un-gating sequence should set up some event flags in flow-controller and controlled by flow-controller.

Thanks,
Joseph

#14 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 20 lines · Joseph Lo
Quoted 19 lines · Stephen Warren
Quoted 17 lines · Joseph Lo
Quoted 5 lines · Peter De Schrijver
Quoted 3 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

Quoted 7 lines

arch/arm/mach-tegra/pmc.c line 38

Quoted 4 lines
arch/arm/mach-tegra/pmc.c +2 -0
 
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */

On Tegra114 we can also powergate CPU0, so this needs to be defined then.

No, DON'T DO THAT!!
We don't allow any code to power gate CPU0 manually here or elsewhere.

The function here only for SMP and hotplug bring up for secondary CPU.

Quoted 8 lines
Quoted 2 lines

Doesn't Tegra114 have improved HW that does actually allow power-gating/hot-unplugging/... CPU 0, even though older HW didn't?

Indeed. It support CPU0 be power gated. But the power up sequence does not through here by toggling PMC directly. Just like the CPU idle "powered-down" mode. The CPU0's power gating/un-gating sequence should set up some event flags in flow-controller and controlled by flow-controller.

Yes, obviously. We don't use this for powergating cores normally... Sorry for the confusion.

Cheers,

Peter.

#15 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

In reply to Joseph Lo

arch/arm/mach-tegra/pmc.c line 42

Quoted 12 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

arch/arm/mach-tegra/pmc.c +6 -0
 
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */
+	TEGRA_POWERGATE_CPU1,
+	TEGRA_POWERGATE_CPU2,
+	TEGRA_POWERGATE_CPU3,
+};

Per Peter's comment, you probably need SoC-specific arrays here, to support CPU0 having a valid value or not.

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 60

Quoted 3 lines
arch/arm/mach-tegra/pmc.c +3 -0
+static int tegra_pmc_get_cpu_powerdomain_id(int cpuid)
+{
+	if (cpuid <= 0 || cpuid > num_possible_cpus())

cpuid >= num_possible_cpus()?

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 72

Quoted 8 lines
arch/arm/mach-tegra/pmc.c +8 -0
+static int tegra_pmc_powergate_set(int id, bool new_state)
+{
+	bool status;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tegra_powergate_lock, flags);
+
+	status = tegra_pmc_readl(PMC_PWRGATE_STATUS) & (1 << id);

I would perform the read and the logical operations separately. Same for the write below.

Don't you want to and with ~BIT(id) not BIT(id)?

Quoted 4 lines
arch/arm/mach-tegra/pmc.c +4 -0
+static int tegra_pmc_powergate_remove_clamping(int id)
+{
+	u32 mask;
+

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 104

Quoted 10 lines
arch/arm/mach-tegra/pmc.c +10 -0
+	/*
+	 * Tegra has a bug where PCIE and VDE clamping masks are
+	 * swapped relatively to the partition ids.
+	 */
+	if (id ==  TEGRA_POWERGATE_VDEC)
+		mask = (1 << TEGRA_POWERGATE_PCIE);
+	else if	(id == TEGRA_POWERGATE_PCIE)
+		mask = (1 << TEGRA_POWERGATE_VDEC);
+	else
+		mask = (1 << id);

Is this just true for this one register, but not others? If it's true everywhere, why not just fix the TEGRA_POWERGATE_* definitions?

I asked this downstream, but you didn't answer.

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 117

Quoted 7 lines
arch/arm/mach-tegra/pmc.c +7 -0
+bool tegra_pmc_cpu_is_powered(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (IS_ERR_VALUE(id))
+		return false;

As I pointed out downstream, that should be if (id < 0); IS_ERR_VALUE is intended for use on error-pointers, not on integer error codes.

author
#16 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 5 lines · Stephen Warren
Quoted 3 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

Quoted 7 lines

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 60

Quoted 4 lines
arch/arm/mach-tegra/pmc.c +3 -0
+static int tegra_pmc_get_cpu_powerdomain_id(int cpuid)
+{
+	if (cpuid <= 0 || cpuid > num_possible_cpus())

cpuid >= num_possible_cpus()?

Yes.

Quoted 12 lines

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 72

Quoted 8 lines
arch/arm/mach-tegra/pmc.c +8 -0
+static int tegra_pmc_powergate_set(int id, bool new_state)
+{
+	bool status;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tegra_powergate_lock, flags);
+
+	status = tegra_pmc_readl(PMC_PWRGATE_STATUS) & (1 << id);

I would perform the read and the logical operations separately. Same for the write below.

Quoted 2 lines

Don't you want to and with ~BIT(id) not BIT(id)?

This is what I want.
WARN_ON(!(!!(status & BIT(id)) ^ new_state));

Quoted 18 lines
Quoted 4 lines
arch/arm/mach-tegra/pmc.c +4 -0
+static int tegra_pmc_powergate_remove_clamping(int id)
+{
+	u32 mask;
+

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 104

Quoted 10 lines
arch/arm/mach-tegra/pmc.c +10 -0
+	/*
+	 * Tegra has a bug where PCIE and VDE clamping masks are
+	 * swapped relatively to the partition ids.
+	 */
+	if (id ==  TEGRA_POWERGATE_VDEC)
+		mask = (1 << TEGRA_POWERGATE_PCIE);
+	else if	(id == TEGRA_POWERGATE_PCIE)
+		mask = (1 << TEGRA_POWERGATE_VDEC);
+	else
+		mask = (1 << id);

Is this just true for this one register, but not others? If it's true everywhere, why not just fix the TEGRA_POWERGATE_* definitions?

Quoted 2 lines

I asked this downstream, but you didn't answer.

This is because the bit of the powergate id was swapped in PMC_REMOVING_CLAMPING with others. So we only need a fix here.

Quoted 10 lines

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 117

Quoted 7 lines
arch/arm/mach-tegra/pmc.c +7 -0
+bool tegra_pmc_cpu_is_powered(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (IS_ERR_VALUE(id))
+		return false;

As I pointed out downstream, that should be if (id < 0); IS_ERR_VALUE is intended for use on error-pointers, not on integer error codes.

IS_ERR is for error pointers, IS_ERR_VALUE is for error return code, isn't it?

Thanks,
Joseph

#17 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 11 lines · Joseph Lo
Quoted 7 lines · Stephen Warren

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 117

Quoted 3 lines · Joseph Lo
arch/arm/mach-tegra/pmc.c +3 -0
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (IS_ERR_VALUE(id))
+		return false;

As I pointed out downstream, that should be if (id < 0); IS_ERR_VALUE is intended for use on error-pointers, not on integer error codes.

IS_ERR is for error pointers, IS_ERR_VALUE is for error return code, isn't it?

No. Just because there's a macro somewhere doesn't mean it should be used.

The err.h stuff is only there to deal with functions which can return kernel pointer values and error values, and resolve the conflict between negative integers and pointers which also appear to be negative integers.

If you don't have that conflict, then making use of err.h is pointless and is pure obfuscation.

So, just use the plain:

	if (id < 0)
		return false;

here.

#18 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

In reply to Joseph Lo
Quoted 27 lines · Joseph Lo
Quoted 5 lines · Stephen Warren
Quoted 3 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

Quoted 7 lines

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 60

Quoted 4 lines
arch/arm/mach-tegra/pmc.c +3 -0
+static int tegra_pmc_get_cpu_powerdomain_id(int cpuid)
+{
+	if (cpuid <= 0 || cpuid > num_possible_cpus())

cpuid >= num_possible_cpus()?

Yes.

Quoted 12 lines

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 72

Quoted 8 lines
arch/arm/mach-tegra/pmc.c +8 -0
+static int tegra_pmc_powergate_set(int id, bool new_state)
+{
+	bool status;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tegra_powergate_lock, flags);
+
+	status = tegra_pmc_readl(PMC_PWRGATE_STATUS) & (1 << id);

I would perform the read and the logical operations separately. Same for the write below.

Quoted 4 lines
Quoted 2 lines

Don't you want to and with ~BIT(id) not BIT(id)?

This is what I want.
WARN_ON(!(!!(status & BIT(id)) ^ new_state));

Oh sorry, I guess this isn't a standard read-modify-write cycle, but something else.

So yes, the & in the register read is probably fine as you have it, but yes there is an issue in the current WARN_ON comparison, as you say.

The WARN_ON you gave above is rather complex. Simplest might be:

u32 reg = tegra_pmc_readl(PMC_PWRGATE_STATUS);
bool old_state = (reg >> id) & 1;
WARN_ON(new_state == old_state);

#19 lore raw

PATCH 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

In reply to Stephen Warren
Quoted 7 lines · Stephen Warren
Quoted 5 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

arch/arm/mach-tegra/pmc.c +0 -0
Quoted 9 lines

arch/arm/mach-tegra/pmc.c line 42

Quoted 6 lines
arch/arm/mach-tegra/pmc.c +6 -0
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */
+	TEGRA_POWERGATE_CPU1,
+	TEGRA_POWERGATE_CPU2,
+	TEGRA_POWERGATE_CPU3,
+};

Per Peter's comment, you probably need SoC-specific arrays here, to support CPU0 having a valid value or not.

That was a mistake, we never use these functions on CPU0. Powergating uses a different path. So this is ok.

Cheers,

Peter.

author
#20 lore raw

PATCH 3/4 ARM: tegra30: platsmp: replace the CPU power on function in PMC driver

In reply to Joseph Lo

Using the CPU power on function in PMC driver to bring up secondary CPUs, because we are going to re-factor powergate driver to support generic power domain. It will be removed later and added the generic power domain support in PMC driver.

---
 arch/arm/mach-tegra/platsmp.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
arch/arm/mach-tegra/platsmp.c +7 -12
index 41971ac..601bd0c 100644
@@ -26,11 +26,10 @@
 #include <asm/smp_scu.h>
 #include <asm/smp_plat.h>
 
-#include <mach/powergate.h>
-
 #include "fuse.h"
 #include "flowctrl.h"
 #include "reset.h"
+#include "pmc.h"
 
 #include "common.h"
 #include "iomap.h"
@@ -80,14 +79,10 @@ static int tegra20_boot_secondary(unsigned int cpu, struct task_struct *idle)
 
 static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
 {
-	int ret, pwrgateid;
+	int ret;
 	unsigned long timeout;
 
 	cpu = cpu_logical_map(cpu);
-	pwrgateid = tegra_cpu_powergate_id(cpu);
-	if (pwrgateid < 0)
-		return pwrgateid;
-
 	tegra_put_cpu_in_reset(cpu);
 	flowctrl_write_cpu_halt(cpu, 0);
 
@@ -108,7 +103,7 @@ static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
 	if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
 		timeout = jiffies + msecs_to_jiffies(50);
 		do {
-			if (tegra_powergate_is_powered(pwrgateid))
+			if (tegra_pmc_cpu_is_powered(cpu))
 				goto remove_clamps;
 			udelay(10);
 		} while (time_before(jiffies, timeout));
@@ -120,14 +115,14 @@ static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
 	 * be un-gated by un-toggling the power gate register
 	 * manually.
 	 */
-	if (!tegra_powergate_is_powered(pwrgateid)) {
-		ret = tegra_powergate_power_on(pwrgateid);
+	if (!tegra_pmc_cpu_is_powered(cpu)) {
+		ret = tegra_pmc_cpu_power_on(cpu);
 		if (ret)
 			return ret;
 
 		/* Wait for the power to come up. */
 		timeout = jiffies + msecs_to_jiffies(100);
-		while (tegra_powergate_is_powered(pwrgateid)) {
+		while (tegra_pmc_cpu_is_powered(cpu)) {
 			if (time_after(jiffies, timeout))
 				return -ETIMEDOUT;
 			udelay(10);
@@ -140,7 +135,7 @@ remove_clamps:
 	udelay(10);
 
 	/* Remove I/O clamps. */
-	ret = tegra_powergate_remove_clamping(pwrgateid);
+	ret = tegra_pmc_cpu_remove_clamping(cpu);
 	if (ret)
 		return ret;
 
Signature · 1 line
1.8.1.1
author
#21 lore raw

PATCH 4/4 ARM: tegra114: bring up secondary CPU for SMP

In reply to Joseph Lo

The secondary CPU can be brought up by toggling the power in PMC. Then the flow controller will release CPU to go by clearing the reset and clamp signal automatically.

Based on the work by:
Bo Yan <[email protected]>

---
 arch/arm/mach-tegra/platsmp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm/mach-tegra/platsmp.c +8 -0
index 601bd0c..516aab2 100644
@@ -146,6 +146,12 @@ remove_clamps:
 	return 0;
 }
 
+static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle)
+{
+	cpu = cpu_logical_map(cpu);
+	return tegra_pmc_cpu_power_on(cpu);
+}
+
 static int __cpuinit tegra_boot_secondary(unsigned int cpu,
 					  struct task_struct *idle)
 {
@@ -153,6 +159,8 @@ static int __cpuinit tegra_boot_secondary(unsigned int cpu,
 		return tegra20_boot_secondary(cpu, idle);
 	if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_chip_id == TEGRA30)
 		return tegra30_boot_secondary(cpu, idle);
+	if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_chip_id == TEGRA114)
+		return tegra114_boot_secondary(cpu, idle);
 
 	return -EINVAL;
 }
Signature · 1 line
1.8.1.1
#22 lore raw

cover ARM: tegra114: bring up secondary CPU for SMP

In reply to Joseph Lo
Quoted 9 lines · Joseph Lo

This series bring up secondary CPU for Tegra114. Because we are going to support generic power domain later, the conventional powergate driver will be removed. So we add the CPU power on/off function in PMC driver first.

This series was dependent on the patches below.
"ARM: tegra: Fix unchecked return value"
"ARM: tegra30: fix the logical detection of power on sequence of warm boot CPUs" "ARM: tegra: refactor tegra{20,30}_boot_secondary"

It also depends on 'ARM: tegra: don't unlock MMIO access to DBGLAR for working' secondary core boot on Tegra114. Otherwise the secondary cores will hang at bootup.

Cheers,

Peter.

author
#23 lore raw

cover ARM: tegra114: bring up secondary CPU for SMP

Quoted 11 lines · Peter De Schrijver
Quoted 9 lines · Joseph Lo

This series bring up secondary CPU for Tegra114. Because we are going to support generic power domain later, the conventional powergate driver will be removed. So we add the CPU power on/off function in PMC driver first.

This series was dependent on the patches below.
"ARM: tegra: Fix unchecked return value"
"ARM: tegra30: fix the logical detection of power on sequence of warm boot CPUs" "ARM: tegra: refactor tegra{20,30}_boot_secondary"

Quoted 4 lines

It also depends on 'ARM: tegra: don't unlock MMIO access to DBGLAR for working' secondary core boot on Tegra114. Otherwise the secondary cores will hang at bootup.

Thanks for reminder. This is definitely needed.

Joseph