Skip to contentSkip to conversation

power: reset: msm: Add support for download-mode control

PATCH In review Rajendra Nayak 4 participants 8 messages Jul 19, 2018 – Dec 17, 2018

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

PATCH 1/1 power: reset: msm: Add support for download-mode control

commit '8c1b7dc9b: firmware: qcom: scm: Expose download-mode control' added support for download-mode control using the scm firmware driver for platforms which require a secure call to write the magic cookie into the tcsr location.

For platforms which *do not* need an scm call and where the kernel can write the cookie by a direct read/write, add similar support in the msm-poweroff driver.
Similar to the scm driver, the msm-poweroff driver clears the cookie during a clean reboot.

Download mode using msm-poweroff driver can be enabled by including msm-poweroff.download_mode=1 on the command line.

---
 .../bindings/power/reset/msm-poweroff.txt          |  3 ++
 drivers/power/reset/Kconfig                        | 11 +++++++
 drivers/power/reset/msm-poweroff.c                 | 38 ++++++++++++++++++++++
 3 files changed, 52 insertions(+)
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
 Required Properties:
 -compatible: "qcom,pshold"
 -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+		 download mode control register
 
 Example:
 
drivers/power/reset/Kconfig +11 -0
index df58fc8..0c97e34 100644
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
 	help
 	  Power off and restart support for Qualcomm boards.
 
+config POWER_RESET_MSM_DOWNLOAD_MODE
+	bool "Qualcomm download mode enabled by default"
+	depends on POWER_RESET_MSM
+	help
+	  A device with "download mode" enabled will upon an unexpected
+	  warm-restart enter a special debug mode that allows the user to
+	  "download" memory content over USB for offline postmortem analysis.
+	  The feature can be enabled/disabled on the kernel command line.
+
+	  Say Y here to enable "download mode" by default.
+
 config POWER_RESET_OCELOT_RESET
 	bool "Microsemi Ocelot reset driver"
 	depends on MSCC_OCELOT || COMPILE_TEST
drivers/power/reset/msm-poweroff.c +38 -0
index 01b8c71..c33eac5 100644
@@ -18,11 +18,20 @@
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/reboot.h>
+#include <linux/regmap.h>
 #include <linux/pm.h>
 
+static bool download_mode = IS_ENABLED(CONFIG_POWER_RESET_MSM_DOWNLOAD_MODE);
+module_param(download_mode, bool, 0);
+
+#define QCOM_SET_DLOAD_MODE 0x10
 static void __iomem *msm_ps_hold;
+static struct regmap *tcsr_regmap;
+static unsigned int dload_mode_offset;
+
 static int deassert_pshold(struct notifier_block *nb, unsigned long action,
 			   void *data)
 {
@@ -44,9 +53,30 @@ static void do_msm_poweroff(void)
 
 static int msm_restart_probe(struct platform_device *pdev)
 {
+	int ret;
+	struct of_phandle_args args;
 	struct device *dev = &pdev->dev;
 	struct resource *mem;
 
+	if (download_mode) {
+		ret = of_parse_phandle_with_fixed_args(dev->of_node,
+						       "qcom,dload-mode", 1, 0,
+						       &args);
+		if (ret < 0)
+			return ret;
+
+		tcsr_regmap = syscon_node_to_regmap(args.np);
+		of_node_put(args.np);
+		if (IS_ERR(tcsr_regmap))
+			return PTR_ERR(tcsr_regmap);
+
+		dload_mode_offset = args.args[0];
+
+		/* Enable download mode by writing the cookie */
+		regmap_write(tcsr_regmap, dload_mode_offset,
+			     QCOM_SET_DLOAD_MODE);
+	}
+
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	msm_ps_hold = devm_ioremap_resource(dev, mem);
 	if (IS_ERR(msm_ps_hold))
@@ -59,6 +89,13 @@ static int msm_restart_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static void msm_restart_shutdown(struct platform_device *pdev)
+{
+	/* Clean shutdown, disable download mode to allow normal restart */
+	if (download_mode)
+		regmap_write(tcsr_regmap, dload_mode_offset, 0x0);
+}
+
 static const struct of_device_id of_msm_restart_match[] = {
 	{ .compatible = "qcom,pshold", },
 	{},
@@ -71,6 +108,7 @@ static int msm_restart_probe(struct platform_device *pdev)
 		.name = "msm-restart",
 		.of_match_table = of_match_ptr(of_msm_restart_match),
 	},
+	.shutdown = msm_restart_shutdown,
 };
 
 static int __init msm_restart_init(void)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw
Quoted 5 lines · Rajendra Nayak

commit '8c1b7dc9b: firmware: qcom: scm: Expose download-mode control' added support for download-mode control using the scm firmware driver for platforms which require a secure call to write the magic cookie into the tcsr location.

Quoted 9 lines

For platforms which *do not* need an scm call and where the kernel can write the cookie by a direct read/write, add similar support in the msm-poweroff driver.
Similar to the scm driver, the msm-poweroff driver clears the cookie during a clean reboot.

Download mode using msm-poweroff driver can be enabled by including msm-poweroff.download_mode=1 on the command line.

Should have thought about this when I wrote the scm code...

I would prefer if we could find a way to consolidate the two implementations behind the same Kconfig and command line parameters.

Quoted 26 lines
---
 .../bindings/power/reset/msm-poweroff.txt          |  3 ++
 drivers/power/reset/Kconfig                        | 11 +++++++
 drivers/power/reset/msm-poweroff.c                 | 38 ++++++++++++++++++++++
 3 files changed, 52 insertions(+)
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
 Required Properties:
 -compatible: "qcom,pshold"
 -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+		 download mode control register
 
 Example:
 
drivers/power/reset/Kconfig +0 -0
index df58fc8..0c97e34 100644

drivers/power/reset/Kconfig config POWER_RESET_MSM · line 107

Quoted 4 lines
drivers/power/reset/Kconfig +1 -0
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
 	help
 	  Power off and restart support for Qualcomm boards.
 
+config POWER_RESET_MSM_DOWNLOAD_MODE

How about moving QCOM_SCM_DOWNLOAD_MODE_DEFAULT to drivers/soc/qcom/Kconfig (and removing "SCM") and referencing this in both drivers?

Quoted 19 lines
drivers/power/reset/Kconfig +10 -0
+	bool "Qualcomm download mode enabled by default"
+	depends on POWER_RESET_MSM
+	help
+	  A device with "download mode" enabled will upon an unexpected
+	  warm-restart enter a special debug mode that allows the user to
+	  "download" memory content over USB for offline postmortem analysis.
+	  The feature can be enabled/disabled on the kernel command line.
+
+	  Say Y here to enable "download mode" by default.
+
 config POWER_RESET_OCELOT_RESET
 	bool "Microsemi Ocelot reset driver"
 	depends on MSCC_OCELOT || COMPILE_TEST
drivers/power/reset/msm-poweroff.c +0 -0
index 01b8c71..c33eac5 100644
@@ -18,11 +18,20 @@
 #include <linux/io.h>

drivers/power/reset/msm-poweroff.c line 28

Quoted 10 lines
drivers/power/reset/msm-poweroff.c +4 -0
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/reboot.h>
+#include <linux/regmap.h>
 #include <linux/pm.h>
 
+static bool download_mode = IS_ENABLED(CONFIG_POWER_RESET_MSM_DOWNLOAD_MODE);
+module_param(download_mode, bool, 0);

Iirc it's possible to have multiple implementations of __setup() for the same string. I'm uncertain if this would be considered okay though.

Quoted 55 lines
drivers/power/reset/msm-poweroff.c +33 -0
+
+#define QCOM_SET_DLOAD_MODE 0x10
 static void __iomem *msm_ps_hold;
+static struct regmap *tcsr_regmap;
+static unsigned int dload_mode_offset;
+
 static int deassert_pshold(struct notifier_block *nb, unsigned long action,
 			   void *data)
 {
@@ -44,9 +53,30 @@ static void do_msm_poweroff(void)
 
 static int msm_restart_probe(struct platform_device *pdev)
 {
+	int ret;
+	struct of_phandle_args args;
 	struct device *dev = &pdev->dev;
 	struct resource *mem;
 
+	if (download_mode) {
+		ret = of_parse_phandle_with_fixed_args(dev->of_node,
+						       "qcom,dload-mode", 1, 0,
+						       &args);
+		if (ret < 0)
+			return ret;
+
+		tcsr_regmap = syscon_node_to_regmap(args.np);
+		of_node_put(args.np);
+		if (IS_ERR(tcsr_regmap))
+			return PTR_ERR(tcsr_regmap);
+
+		dload_mode_offset = args.args[0];
+
+		/* Enable download mode by writing the cookie */
+		regmap_write(tcsr_regmap, dload_mode_offset,
+			     QCOM_SET_DLOAD_MODE);
+	}
+
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	msm_ps_hold = devm_ioremap_resource(dev, mem);
 	if (IS_ERR(msm_ps_hold))
@@ -59,6 +89,13 @@ static int msm_restart_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static void msm_restart_shutdown(struct platform_device *pdev)
+{
+	/* Clean shutdown, disable download mode to allow normal restart */
+	if (download_mode)
+		regmap_write(tcsr_regmap, dload_mode_offset, 0x0);
+}
+
 static const struct of_device_id of_msm_restart_match[] = {
 	{ .compatible = "qcom,pshold", },
 	{},

drivers/power/reset/msm-poweroff.c static int msm_restart_probe(struct platform_device *pdev) · line 112

Quoted 5 lines
drivers/power/reset/msm-poweroff.c +1 -0
@@ -71,6 +108,7 @@ static int msm_restart_probe(struct platform_device *pdev)
 		.name = "msm-restart",
 		.of_match_table = of_match_ptr(of_msm_restart_match),
 	},
+	.shutdown = msm_restart_shutdown,
 };

Implementation looks good.

Regards,
Bjorn

#2 lore raw
Quoted 13 lines · Bjorn Andersson
Quoted 11 lines · Rajendra Nayak

commit '8c1b7dc9b: firmware: qcom: scm: Expose download-mode control' added support for download-mode control using the scm firmware driver for platforms which require a secure call to write the magic cookie into the tcsr location.

For platforms which *do not* need an scm call and where the kernel can write the cookie by a direct read/write, add similar support in the msm-poweroff driver.
Similar to the scm driver, the msm-poweroff driver clears the cookie during a clean reboot.

Quoted 8 lines
Quoted 3 lines

Download mode using msm-poweroff driver can be enabled by including msm-poweroff.download_mode=1 on the command line.

Should have thought about this when I wrote the scm code...

I would prefer if we could find a way to consolidate the two implementations behind the same Kconfig and command line parameters.

The only problem I saw with this was that *both* drivers would think its enabled and try their own ways to enable it, and one of it would always fail. We could fail silently, which would mean we will miss cases when its a genuine failure but that should be fine?

Quoted 29 lines
Quoted 29 lines
---
  .../bindings/power/reset/msm-poweroff.txt          |  3 ++
  drivers/power/reset/Kconfig                        | 11 +++++++
  drivers/power/reset/msm-poweroff.c                 | 38 ++++++++++++++++++++++
  3 files changed, 52 insertions(+)
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
  Required Properties:
  -compatible: "qcom,pshold"
  -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+		 download mode control register
 
  Example:
 
drivers/power/reset/Kconfig +0 -0
index df58fc8..0c97e34 100644
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
  	help
  	  Power off and restart support for Qualcomm boards.
 
Quoted 5 lines

drivers/power/reset/Kconfig config POWER_RESET_MSM · line 107

Quoted 1 line
drivers/power/reset/Kconfig +1 -0
+config POWER_RESET_MSM_DOWNLOAD_MODE

How about moving QCOM_SCM_DOWNLOAD_MODE_DEFAULT to drivers/soc/qcom/Kconfig (and removing "SCM") and referencing this in both drivers?

yes, thats possible, but I am not sure how to make the command line option common for both. One other option I thought was if we could handle it within the scm driver itself with an additional
binding to specify the non-secure download mode address. something like qcom,dload-mode-ns?

regards,
Rajendra

Quoted 100 lines
Quoted 20 lines
drivers/power/reset/Kconfig +10 -0
+	bool "Qualcomm download mode enabled by default"
+	depends on POWER_RESET_MSM
+	help
+	  A device with "download mode" enabled will upon an unexpected
+	  warm-restart enter a special debug mode that allows the user to
+	  "download" memory content over USB for offline postmortem analysis.
+	  The feature can be enabled/disabled on the kernel command line.
+
+	  Say Y here to enable "download mode" by default.
+
  config POWER_RESET_OCELOT_RESET
  	bool "Microsemi Ocelot reset driver"
  	depends on MSCC_OCELOT || COMPILE_TEST
drivers/power/reset/msm-poweroff.c +0 -0
index 01b8c71..c33eac5 100644
@@ -18,11 +18,20 @@
  #include <linux/io.h>

drivers/power/reset/msm-poweroff.c line 28

Quoted 10 lines
drivers/power/reset/msm-poweroff.c +4 -0
  #include <linux/of.h>
  #include <linux/platform_device.h>
+#include <linux/mfd/syscon.h>
  #include <linux/module.h>
  #include <linux/reboot.h>
+#include <linux/regmap.h>
  #include <linux/pm.h>
 
+static bool download_mode = IS_ENABLED(CONFIG_POWER_RESET_MSM_DOWNLOAD_MODE);
+module_param(download_mode, bool, 0);

Iirc it's possible to have multiple implementations of __setup() for the same string. I'm uncertain if this would be considered okay though.

Quoted 55 lines
drivers/power/reset/msm-poweroff.c +33 -0
+
+#define QCOM_SET_DLOAD_MODE 0x10
  static void __iomem *msm_ps_hold;
+static struct regmap *tcsr_regmap;
+static unsigned int dload_mode_offset;
+
  static int deassert_pshold(struct notifier_block *nb, unsigned long action,
  			   void *data)
  {
@@ -44,9 +53,30 @@ static void do_msm_poweroff(void)
 
  static int msm_restart_probe(struct platform_device *pdev)
  {
+	int ret;
+	struct of_phandle_args args;
  	struct device *dev = &pdev->dev;
  	struct resource *mem;
 
+	if (download_mode) {
+		ret = of_parse_phandle_with_fixed_args(dev->of_node,
+						       "qcom,dload-mode", 1, 0,
+						       &args);
+		if (ret < 0)
+			return ret;
+
+		tcsr_regmap = syscon_node_to_regmap(args.np);
+		of_node_put(args.np);
+		if (IS_ERR(tcsr_regmap))
+			return PTR_ERR(tcsr_regmap);
+
+		dload_mode_offset = args.args[0];
+
+		/* Enable download mode by writing the cookie */
+		regmap_write(tcsr_regmap, dload_mode_offset,
+			     QCOM_SET_DLOAD_MODE);
+	}
+
  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	msm_ps_hold = devm_ioremap_resource(dev, mem);
  	if (IS_ERR(msm_ps_hold))
@@ -59,6 +89,13 @@ static int msm_restart_probe(struct platform_device *pdev)
  	return 0;
  }
 
+static void msm_restart_shutdown(struct platform_device *pdev)
+{
+	/* Clean shutdown, disable download mode to allow normal restart */
+	if (download_mode)
+		regmap_write(tcsr_regmap, dload_mode_offset, 0x0);
+}
+
  static const struct of_device_id of_msm_restart_match[] = {
  	{ .compatible = "qcom,pshold", },
  	{},

drivers/power/reset/msm-poweroff.c static int msm_restart_probe(struct platform_device *pdev) · line 112

Quoted 5 lines
drivers/power/reset/msm-poweroff.c +1 -0
@@ -71,6 +108,7 @@ static int msm_restart_probe(struct platform_device *pdev)
  		.name = "msm-restart",
  		.of_match_table = of_match_ptr(of_msm_restart_match),
  	},
+	.shutdown = msm_restart_shutdown,
  };

Implementation looks good.

Regards,
Bjorn

#3 lore raw

Quoting Rajendra Nayak (2018-07-18 23:59:20)

Quoted 22 lines · Bjorn Andersson
Quoted 19 lines · Rajendra Nayak
Quoted 6 lines

commit '8c1b7dc9b: firmware: qcom: scm: Expose download-mode control' added support for download-mode control using the scm firmware driver for platforms which require a secure call to write the magic cookie into the tcsr location.

Quoted 9 lines

For platforms which *do not* need an scm call and where the kernel can write the cookie by a direct read/write, add similar support in the msm-poweroff driver.
Similar to the scm driver, the msm-poweroff driver clears the cookie during a clean reboot.

Download mode using msm-poweroff driver can be enabled by including msm-poweroff.download_mode=1 on the command line.

Should have thought about this when I wrote the scm code...

Quoted 7 lines
Quoted 2 lines

I would prefer if we could find a way to consolidate the two implementations behind the same Kconfig and command line parameters.

The only problem I saw with this was that *both* drivers would think its enabled and try their own ways to enable it, and one of it would always fail. We could fail silently, which would mean we will miss cases when its a genuine failure but that should be fine?

Should be fine if SCM fails silently. If TCSR is specified it better work because that doesn't really rely on anything besides writing into a memory location.

Quoted 36 lines
Quoted 30 lines
Quoted 30 lines
---
  .../bindings/power/reset/msm-poweroff.txt          |  3 ++
  drivers/power/reset/Kconfig                        | 11 +++++++
  drivers/power/reset/msm-poweroff.c                 | 38 ++++++++++++++++++++++
  3 files changed, 52 insertions(+)
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
  Required Properties:
  -compatible: "qcom,pshold"
  -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+             download mode control register
 
  Example:
 
drivers/power/reset/Kconfig +0 -0
index df58fc8..0c97e34 100644
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
     help
       Power off and restart support for Qualcomm boards.
 
Quoted 5 lines

drivers/power/reset/Kconfig config POWER_RESET_MSM · line 107

Quoted 1 line
drivers/power/reset/Kconfig +1 -0
+config POWER_RESET_MSM_DOWNLOAD_MODE

How about moving QCOM_SCM_DOWNLOAD_MODE_DEFAULT to drivers/soc/qcom/Kconfig (and removing "SCM") and referencing this in both drivers?

Quoted 5 lines

yes, thats possible, but I am not sure how to make the command line option common for both. One other option I thought was if we could handle it within the scm driver itself with an additional
binding to specify the non-secure download mode address. something like qcom,dload-mode-ns?

Is the SCM device and driver always going to be present though? It may be better to make a TCSR platform device driver on designs that would configure the cookie with direct read/writes from Linux to break the relationship with scm entirely. Then the different configurations could flow from the DTS file either describing scm that has scm call, a special scm_writel address for TCSR, or a specific TCSR node with the address of the download mode cookie that triggers a TCSR driver to probe and register a reboot handler.

#4 lore raw

Hi,

What's the status of this patch? It looks good to me, should it be merged, did I miss a newer version?

-- Sebastian

Quoted 87 lines · Stephen Boyd

Quoting Rajendra Nayak (2018-07-18 23:59:20)

Quoted 22 lines · Bjorn Andersson
Quoted 19 lines · Rajendra Nayak
Quoted 6 lines

commit '8c1b7dc9b: firmware: qcom: scm: Expose download-mode control' added support for download-mode control using the scm firmware driver for platforms which require a secure call to write the magic cookie into the tcsr location.

Quoted 9 lines

For platforms which *do not* need an scm call and where the kernel can write the cookie by a direct read/write, add similar support in the msm-poweroff driver.
Similar to the scm driver, the msm-poweroff driver clears the cookie during a clean reboot.

Download mode using msm-poweroff driver can be enabled by including msm-poweroff.download_mode=1 on the command line.

Should have thought about this when I wrote the scm code...

Quoted 7 lines
Quoted 2 lines

I would prefer if we could find a way to consolidate the two implementations behind the same Kconfig and command line parameters.

The only problem I saw with this was that *both* drivers would think its enabled and try their own ways to enable it, and one of it would always fail. We could fail silently, which would mean we will miss cases when its a genuine failure but that should be fine?

Should be fine if SCM fails silently. If TCSR is specified it better work because that doesn't really rely on anything besides writing into a memory location.

Quoted 36 lines
Quoted 30 lines
Quoted 30 lines
---
  .../bindings/power/reset/msm-poweroff.txt          |  3 ++
  drivers/power/reset/Kconfig                        | 11 +++++++
  drivers/power/reset/msm-poweroff.c                 | 38 ++++++++++++++++++++++
  3 files changed, 52 insertions(+)
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
  Required Properties:
  -compatible: "qcom,pshold"
  -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+             download mode control register
 
  Example:
 
drivers/power/reset/Kconfig +0 -0
index df58fc8..0c97e34 100644
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
     help
       Power off and restart support for Qualcomm boards.
 
Quoted 5 lines

drivers/power/reset/Kconfig config POWER_RESET_MSM · line 107

Quoted 1 line
drivers/power/reset/Kconfig +1 -0
+config POWER_RESET_MSM_DOWNLOAD_MODE

How about moving QCOM_SCM_DOWNLOAD_MODE_DEFAULT to drivers/soc/qcom/Kconfig (and removing "SCM") and referencing this in both drivers?

Quoted 5 lines

yes, thats possible, but I am not sure how to make the command line option common for both. One other option I thought was if we could handle it within the scm driver itself with an additional
binding to specify the non-secure download mode address. something like qcom,dload-mode-ns?

Is the SCM device and driver always going to be present though? It may be better to make a TCSR platform device driver on designs that would configure the cookie with direct read/writes from Linux to break the relationship with scm entirely. Then the different configurations could flow from the DTS file either describing scm that has scm call, a special scm_writel address for TCSR, or a specific TCSR node with the address of the download mode cookie that triggers a TCSR driver to probe and register a reboot handler.

#5 lore raw
In reply to Stephen Boyd

Quoting Stephen Boyd (2018-07-20 10:44:53)

Quoted 37 lines

Quoting Rajendra Nayak (2018-07-18 23:59:20)

Quoted 30 lines · Bjorn Andersson
Quoted 23 lines · Rajendra Nayak
Quoted 22 lines
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
  Required Properties:
  -compatible: "qcom,pshold"
  -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+             download mode control register
 
  Example:
 
drivers/power/reset/Kconfig +0 -0
index df58fc8..0c97e34 100644
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
     help
       Power off and restart support for Qualcomm boards.
 
Quoted 5 lines

drivers/power/reset/Kconfig config POWER_RESET_MSM · line 107

Quoted 1 line
drivers/power/reset/Kconfig +1 -0
+config POWER_RESET_MSM_DOWNLOAD_MODE

How about moving QCOM_SCM_DOWNLOAD_MODE_DEFAULT to drivers/soc/qcom/Kconfig (and removing "SCM") and referencing this in both drivers?

Quoted 5 lines

yes, thats possible, but I am not sure how to make the command line option common for both. One other option I thought was if we could handle it within the scm driver itself with an additional
binding to specify the non-secure download mode address. something like qcom,dload-mode-ns?

Quoted 9 lines

Is the SCM device and driver always going to be present though? It may be better to make a TCSR platform device driver on designs that would configure the cookie with direct read/writes from Linux to break the relationship with scm entirely. Then the different configurations could flow from the DTS file either describing scm that has scm call, a special scm_writel address for TCSR, or a specific TCSR node with the address of the download mode cookie that triggers a TCSR driver to probe and register a reboot handler.

Does my proposal work? I haven't seen anything new on the list since this email.

#6 lore raw
Quoted 48 lines · Stephen Boyd

Quoting Stephen Boyd (2018-07-20 10:44:53)

Quoted 37 lines

Quoting Rajendra Nayak (2018-07-18 23:59:20)

Quoted 30 lines · Bjorn Andersson
Quoted 23 lines · Rajendra Nayak
Quoted 22 lines
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
  Required Properties:
  -compatible: "qcom,pshold"
  -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+             download mode control register
 
  Example:
 
drivers/power/reset/Kconfig +0 -0
index df58fc8..0c97e34 100644
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
     help
       Power off and restart support for Qualcomm boards.
 
Quoted 5 lines

drivers/power/reset/Kconfig config POWER_RESET_MSM · line 107

Quoted 1 line
drivers/power/reset/Kconfig +1 -0
+config POWER_RESET_MSM_DOWNLOAD_MODE

How about moving QCOM_SCM_DOWNLOAD_MODE_DEFAULT to drivers/soc/qcom/Kconfig (and removing "SCM") and referencing this in both drivers?

Quoted 5 lines

yes, thats possible, but I am not sure how to make the command line option common for both. One other option I thought was if we could handle it within the scm driver itself with an additional
binding to specify the non-secure download mode address. something like qcom,dload-mode-ns?

Quoted 9 lines

Is the SCM device and driver always going to be present though? It may be better to make a TCSR platform device driver on designs that would configure the cookie with direct read/writes from Linux to break the relationship with scm entirely. Then the different configurations could flow from the DTS file either describing scm that has scm call, a special scm_writel address for TCSR, or a specific TCSR node with the address of the download mode cookie that triggers a TCSR driver to probe and register a reboot handler.

Quoted 3 lines

Does my proposal work? I haven't seen anything new on the list since this email.

Afaiu the SCM device is still there, even though we don't use all the usual functionality.

I tested on qcs404 and sdm845-mtp (LA boot chain), and they both return positive on:

__qcom_scm_is_call_available(dev, QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE)

So how about we change qcom_scm_set_download_mode() to do:

  if (scm_call_avail(QCOM_SCM_SVC_BOOT, QCOM_SCM_SET_DLOAD_MODE))
  	__qcom_scm_set_dload_mode()
  else if (scm_call_avail(QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE) && dload_mode_addr)
  	__qcom_scm_io_writel();
  else if (dload_mode_addr)
  	writel()

This would also mean that we can put the dload addr in the sdm845.dtsi and share that between LA and ATF.

Regards,
Bjorn

#7 lore raw

Quoting Bjorn Andersson (2018-12-13 21:30:35)

Quoted 50 lines · Stephen Boyd
Quoted 49 lines

Quoting Stephen Boyd (2018-07-20 10:44:53)

Quoted 46 lines

Quoting Rajendra Nayak (2018-07-18 23:59:20)

Quoted 30 lines · Bjorn Andersson
Quoted 23 lines · Rajendra Nayak
Quoted 22 lines
Documentation/devicetree/bindings/power/reset/msm-poweroff.txt +3 -0
index ce44ad3..9dd489f 100644
@@ -8,6 +8,9 @@ settings.
  Required Properties:
  -compatible: "qcom,pshold"
  -reg: Specifies the physical address of the ps-hold register
+Optional Properties:
+-qcom,dload-mode: phandle to the TCSR hardware block and offset of the
+             download mode control register
 
  Example:
 
drivers/power/reset/Kconfig +0 -0
index df58fc8..0c97e34 100644
@@ -104,6 +104,17 @@ config POWER_RESET_MSM
     help
       Power off and restart support for Qualcomm boards.
 
Quoted 5 lines

drivers/power/reset/Kconfig config POWER_RESET_MSM · line 107

Quoted 1 line
drivers/power/reset/Kconfig +1 -0
+config POWER_RESET_MSM_DOWNLOAD_MODE

How about moving QCOM_SCM_DOWNLOAD_MODE_DEFAULT to drivers/soc/qcom/Kconfig (and removing "SCM") and referencing this in both drivers?

Quoted 5 lines

yes, thats possible, but I am not sure how to make the command line option common for both. One other option I thought was if we could handle it within the scm driver itself with an additional
binding to specify the non-secure download mode address. something like qcom,dload-mode-ns?

Is the SCM device and driver always going to be present though? It may be better to make a TCSR platform device driver on designs that would configure the cookie with direct read/writes from Linux to break the relationship with scm entirely. Then the different configurations could flow from the DTS file either describing scm that has scm call, a special scm_writel address for TCSR, or a specific TCSR node with the address of the download mode cookie that triggers a TCSR driver to probe and register a reboot handler.

Quoted 6 lines
Quoted 3 lines

Does my proposal work? I haven't seen anything new on the list since this email.

Afaiu the SCM device is still there, even though we don't use all the usual functionality.

You mean the SCM device is always there even when TCSR is used to lay down the download mode cookie?

Quoted 15 lines

I tested on qcs404 and sdm845-mtp (LA boot chain), and they both return positive on:

__qcom_scm_is_call_available(dev, QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE)

So how about we change qcom_scm_set_download_mode() to do:

  if (scm_call_avail(QCOM_SCM_SVC_BOOT, QCOM_SCM_SET_DLOAD_MODE))
        __qcom_scm_set_dload_mode()
  else if (scm_call_avail(QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE) && dload_mode_addr)
        __qcom_scm_io_writel();
  else if (dload_mode_addr)
        writel()
Quoted 3 lines

This would also mean that we can put the dload addr in the sdm845.dtsi and share that between LA and ATF.

I'd prefer that any ATF firmware put qcom's download mode behind a vendor specific SYSTEM_RESET2 PSCI call so that ATF can do the magic to clear the cookie on normal reboots and shutdowns. Abnormal resets where we want to enter download mode from some panic or crash handler can be handled by calling the vendor specific PSCI call. Then the only decision that needs to be made is this one we're talking about now, where someone wants a way to express that download mode should be entered when a hardware event causes a reset (i.e. watchdog bite, thermal restart).

Even that decision could be made statically though, in which case I don't see why SCM is a dependency. The bootloader or firmware can decide to always put down the cookie early and clear it when the system is normally rebooted so that bootloader bugs can be detected. I'll admit that we lose the ability to disable download mode unless we implement something to clear the cookie, so on firmwares without SCM I imagine the cookie could be cleared with the direct writel() code. Long story short, we need a more generic method than qcom_scm_set_download_mode() to do that because it doesn't make sense to say there's SCM firmware there when there isn't any.

So can there be some generic kernel piece of code that looks for the scm firmware node and a tcsr node and then decides to set or clear the cookie based on a commandline parameter? It can also look for a PSCI node and if there's a compatible firmware with the vendor specific reset call it can use that to know that it shouldn't do anything besides allow the commandline parameter to clear or set the cookie. All of this wouldn't actually require to be bound to any sort of device or device node. It's just looking in DT/firmware tables for various pieces of information and changing how reset, shutdown and the commandline parameter is handled for the architecture.

Furthermore, the PSCI style reset handling would need to be plumbed into the ARM/ARM64 reset hooks, so we would already need to add some panic crash handler calls into the PSCI layer to handle the vendor specific cases. Coming up with a more generic commandline parameter like 'panic_mode=<vendor>,type' would be good to express that we want to use qcom download mode when the system panics and then one place for all the different reboot logic can be contained to focus other SoC manufacturers on implementing a PSCI call or flow in a similar way.