Skip to contentSkip to conversation

QCOM SCM Download mode support

PATCH Superseded Bjorn Andersson 2 participants 7 messages Aug 9, 2017 – Aug 14, 2017

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover QCOM SCM Download mode support

This enables kernel developers to enable "download mode", a mechanism for entering a debug state to "download" memory content following a unexpected warm-restart; e.g. security violation by accessing a protected register.

Bjorn Andersson (3):
firmware: qcom: scm: Expose secure IO service
firmware: qcom: scm: Expose download-mode control
arm64: dts: qcom: Specify dload address for msm8916 and msm8996

 .../devicetree/bindings/firmware/qcom,scm.txt      |  2 +
 arch/arm64/boot/dts/qcom/msm8916.dtsi              |  2 +
 arch/arm64/boot/dts/qcom/msm8996.dtsi              |  7 ++
 drivers/firmware/Kconfig                           | 11 +++
 drivers/firmware/qcom_scm-32.c                     | 24 +++++++
 drivers/firmware/qcom_scm-64.c                     | 44 ++++++++++++
 drivers/firmware/qcom_scm.c                        | 81 ++++++++++++++++++++++
 drivers/firmware/qcom_scm.h                        |  8 +++
 include/linux/qcom_scm.h                           |  4 ++
 9 files changed, 183 insertions(+)
Signature · 1 line
2.12.0
#1 lore raw

PATCH v3 1/3 firmware: qcom: scm: Expose secure IO service

The secure IO service provides operations for reading and writing secure memory from non-secure mode, expose this API through SCM.

---

Changes since v2:
- Picked up Stephen's r-b

Changes since v1:
- Correct scm-call return value handling
- Make scm_io_readl() return data by reference

 drivers/firmware/qcom_scm-32.c | 18 ++++++++++++++++++
 drivers/firmware/qcom_scm-64.c | 31 +++++++++++++++++++++++++++++++
 drivers/firmware/qcom_scm.c    | 12 ++++++++++++
 drivers/firmware/qcom_scm.h    |  6 ++++++
 include/linux/qcom_scm.h       |  4 ++++
 5 files changed, 71 insertions(+)
drivers/firmware/qcom_scm-32.c +18 -0
index 93e3b96b6dfa..11fdb1584823 100644
@@ -596,3 +596,21 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,
 {
 	return -ENODEV;
 }
+
+int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
+			unsigned int *val)
+{
+	int ret;
+
+	ret = qcom_scm_call_atomic1(QCOM_SCM_SVC_IO, QCOM_SCM_IO_READ, addr);
+	if (ret >= 0)
+		*val = ret;
+
+	return ret < 0 ? ret : 0;
+}
+
+int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val)
+{
+	return qcom_scm_call_atomic2(QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE,
+				     addr, val);
+}
drivers/firmware/qcom_scm-64.c +31 -0
index 6e6d561708e2..bf50fb59852e 100644
@@ -439,3 +439,34 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,
 
 	return ret;
 }
+
+int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
+			unsigned int *val)
+{
+	struct qcom_scm_desc desc = {0};
+	struct arm_smccc_res res;
+	int ret;
+
+	desc.args[0] = addr;
+	desc.arginfo = QCOM_SCM_ARGS(1);
+
+	ret = qcom_scm_call(dev, QCOM_SCM_SVC_IO, QCOM_SCM_IO_READ,
+			    &desc, &res);
+	if (ret >= 0)
+		*val = res.a1;
+
+	return ret < 0 ? ret : 0;
+}
+
+int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val)
+{
+	struct qcom_scm_desc desc = {0};
+	struct arm_smccc_res res;
+
+	desc.args[0] = addr;
+	desc.args[1] = val;
+	desc.arginfo = QCOM_SCM_ARGS(2);
+
+	return qcom_scm_call(dev, QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE,
+			     &desc, &res);
+}
drivers/firmware/qcom_scm.c +12 -0
index bb16510d75ba..e18d63935648 100644
@@ -333,6 +333,18 @@ int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare)
 }
 EXPORT_SYMBOL(qcom_scm_iommu_secure_ptbl_init);
 
+int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val)
+{
+	return __qcom_scm_io_readl(__scm->dev, addr, val);
+}
+EXPORT_SYMBOL(qcom_scm_io_readl);
+
+int qcom_scm_io_writel(phys_addr_t addr, unsigned int val)
+{
+	return __qcom_scm_io_writel(__scm->dev, addr, val);
+}
+EXPORT_SYMBOL(qcom_scm_io_writel);
+
 /**
  * qcom_scm_is_available() - Checks if SCM is available
  */
drivers/firmware/qcom_scm.h +6 -0
index 9bea691f30fb..a60e4b9b1394 100644
@@ -30,6 +30,12 @@ extern int __qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus);
 #define QCOM_SCM_CMD_CORE_HOTPLUGGED	0x10
 extern void __qcom_scm_cpu_power_down(u32 flags);
 
+#define QCOM_SCM_SVC_IO			0x5
+#define QCOM_SCM_IO_READ		0x1
+#define QCOM_SCM_IO_WRITE		0x2
+extern int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, unsigned int *val);
+extern int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val);
+
 #define QCOM_SCM_SVC_INFO		0x6
 #define QCOM_IS_CALL_AVAIL_CMD		0x1
 extern int __qcom_scm_is_call_available(struct device *dev, u32 svc_id,
include/linux/qcom_scm.h +4 -0
index e5380471c2cd..e8357f570695 100644
@@ -43,6 +43,8 @@ extern int qcom_scm_set_remote_state(u32 state, u32 id);
 extern int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare);
 extern int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size);
 extern int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare);
+extern int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val);
+extern int qcom_scm_io_writel(phys_addr_t addr, unsigned int val);
 #else
 static inline
 int qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus)
@@ -73,5 +75,7 @@ qcom_scm_set_remote_state(u32 state,u32 id) { return -ENODEV; }
 static inline int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare) { return -ENODEV; }
 static inline int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size) { return -ENODEV; }
 static inline int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) { return -ENODEV; }
+static inline int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val) { return -ENODEV; }
+static inline int qcom_scm_io_writel(phys_addr_t addr, unsigned int val) { return -ENODEV; }
 #endif
 #endif
Signature · 1 line
2.12.0
#2 lore raw

PATCH v3 2/3 firmware: qcom: scm: Expose download-mode control

In reply to Bjorn Andersson

In order to aid post-mortem debugging the Qualcomm platforms provides a "memory download mode", where the boot loader will provide an interface for custom tools to "download" the content of RAM to a host machine.

The mode is triggered by writing a magic value somehwere in RAM, that is read in the boot code path after a warm-restart. Two mechanism for setting this magic value are supported in modern platforms; a direct SCM call to enable the mode or through a secure io write of a magic value.

In order for a normal reboot not to trigger "download mode" the magic must be cleared during a clean reboot.

Download mode has to be enabled by including qcom_scm.download_mode=1 on the command line.

---

Changes since v2:
- Define memory address by reference to TCSR
- Provide Kconfig option for defaulting to enabled
- Provided some comment in the code

Changes since v1:
- Specify DT propert being two-cell
- Correct handling of scm-call return code

 .../devicetree/bindings/firmware/qcom,scm.txt      |  2 +
 drivers/firmware/Kconfig                           | 11 ++++
 drivers/firmware/qcom_scm-32.c                     |  6 ++
 drivers/firmware/qcom_scm-64.c                     | 13 ++++
 drivers/firmware/qcom_scm.c                        | 69 ++++++++++++++++++++++
 drivers/firmware/qcom_scm.h                        |  2 +
 6 files changed, 103 insertions(+)
Documentation/devicetree/bindings/firmware/qcom,scm.txt +2 -0
index 20f26fbce875..838dba841797 100644
@@ -18,6 +18,8 @@ Required properties:
  * Core, iface, and bus clocks required for "qcom,scm"
 - clock-names: Must contain "core" for the core clock, "iface" for the interface
   clock and "bus" for the bus clock per the requirements of the compatible.
+- qcom,dload-mode: phandle reference to the TCSR hardware block containing the
+		   download mode control register (optional)
 
 Example for MSM8916:
 
drivers/firmware/Kconfig +11 -0
index 6e4ed5a9c6fd..ed23c77d6361 100644
@@ -215,6 +215,17 @@ config QCOM_SCM_64
 	def_bool y
 	depends on QCOM_SCM && ARM64
 
+config QCOM_SCM_DOWNLOAD_MODE_DEFAULT
+	bool "Qualcomm Download mode enabled by default"
+	depends on QCOM_SCM
+	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 TI_SCI_PROTOCOL
 	tristate "TI System Control Interface (TISCI) Message Protocol"
 	depends on TI_MESSAGE_MANAGER
drivers/firmware/qcom_scm-32.c +6 -0
index 11fdb1584823..68b2033bc30e 100644
@@ -561,6 +561,12 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)
 	return ret ? : le32_to_cpu(out);
 }
 
+int __qcom_scm_set_dload_mode(struct device *dev, bool enable)
+{
+	return qcom_scm_call_atomic2(QCOM_SCM_SVC_BOOT, QCOM_SCM_SET_DLOAD_MODE,
+				     enable ? QCOM_SCM_SET_DLOAD_MODE : 0, 0);
+}
+
 int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id)
 {
 	struct {
drivers/firmware/qcom_scm-64.c +13 -0
index bf50fb59852e..3fea6f563ca9 100644
@@ -440,6 +440,19 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,
 	return ret;
 }
 
+int __qcom_scm_set_dload_mode(struct device *dev, bool enable)
+{
+	struct qcom_scm_desc desc = {0};
+	struct arm_smccc_res res;
+
+	desc.args[0] = QCOM_SCM_SET_DLOAD_MODE;
+	desc.args[1] = enable ? QCOM_SCM_SET_DLOAD_MODE : 0;
+	desc.arginfo = QCOM_SCM_ARGS(2);
+
+	return qcom_scm_call(dev, QCOM_SCM_SVC_BOOT, QCOM_SCM_SET_DLOAD_MODE,
+			     &desc, &res);
+}
+
 int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
 			unsigned int *val)
 {
drivers/firmware/qcom_scm.c +69 -0

117 lines not on this page · raw message

drivers/firmware/qcom_scm.h +2 -0
index a60e4b9b1394..83f171c23943 100644
@@ -14,9 +14,11 @@
 
 #define QCOM_SCM_SVC_BOOT		0x1
 #define QCOM_SCM_BOOT_ADDR		0x1
+#define QCOM_SCM_SET_DLOAD_MODE		0x10
 #define QCOM_SCM_BOOT_ADDR_MC		0x11
 #define QCOM_SCM_SET_REMOTE_STATE	0xa
 extern int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id);
+extern int __qcom_scm_set_dload_mode(struct device *dev, bool enable);
 
 #define QCOM_SCM_FLAG_HLOS		0x01
 #define QCOM_SCM_FLAG_COLDBOOT_MC	0x02
Signature · 1 line
2.12.0
Reviewed-by on v3 2/3
#3 lore raw

Re: [PATCH v3 2/3] firmware: qcom: scm: Expose download-mode control

Quoted 1 line · Bjorn Andersson

In order to aid post-mortem debugging the Qualcomm platforms provides a

s/provides/provide/

Quoted 4 lines

"memory download mode", where the boot loader will provide an interface for custom tools to "download" the content of RAM to a host machine.

The mode is triggered by writing a magic value somehwere in RAM, that is

s/somehwere/somewhere/

Quoted 48 lines

read in the boot code path after a warm-restart. Two mechanism for setting this magic value are supported in modern platforms; a direct SCM call to enable the mode or through a secure io write of a magic value.

In order for a normal reboot not to trigger "download mode" the magic must be cleared during a clean reboot.

Download mode has to be enabled by including qcom_scm.download_mode=1 on the command line.

---

Changes since v2:
- Define memory address by reference to TCSR
- Provide Kconfig option for defaulting to enabled
- Provided some comment in the code

Changes since v1:
- Specify DT propert being two-cell
- Correct handling of scm-call return code

 .../devicetree/bindings/firmware/qcom,scm.txt      |  2 +
 drivers/firmware/Kconfig                           | 11 ++++
 drivers/firmware/qcom_scm-32.c                     |  6 ++
 drivers/firmware/qcom_scm-64.c                     | 13 ++++
 drivers/firmware/qcom_scm.c                        | 69 ++++++++++++++++++++++
 drivers/firmware/qcom_scm.h                        |  2 +
 6 files changed, 103 insertions(+)
Documentation/devicetree/bindings/firmware/qcom,scm.txt +2 -0
index 20f26fbce875..838dba841797 100644
@@ -18,6 +18,8 @@ Required properties:
  * Core, iface, and bus clocks required for "qcom,scm"
 - clock-names: Must contain "core" for the core clock, "iface" for the interface
   clock and "bus" for the bus clock per the requirements of the compatible.
+- qcom,dload-mode: phandle reference to the TCSR hardware block containing the
+		   download mode control register (optional)
 
 Example for MSM8916:
 
drivers/firmware/Kconfig +0 -0
index 6e4ed5a9c6fd..ed23c77d6361 100644

drivers/firmware/Kconfig config QCOM_SCM_64 · line 219

Quoted 5 lines
drivers/firmware/Kconfig +2 -0
@@ -215,6 +215,17 @@ config QCOM_SCM_64
 	def_bool y
 	depends on QCOM_SCM && ARM64
 
+config QCOM_SCM_DOWNLOAD_MODE_DEFAULT
+	bool "Qualcomm Download mode enabled by default"

Decapitalize download?

drivers/firmware/Kconfig config QCOM_SCM_64 · line 228

Quoted 9 lines
drivers/firmware/Kconfig +9 -0
+	depends on QCOM_SCM
+	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.
+

otherwise

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

PATCH v3 3/3 arm64: dts: qcom: Specify dload address for msm8916 and msm8996

In reply to Bjorn Andersson

On msm8916 and msm8996 boards a secure io-write is used to write the magic for selecting "download mode", specify this address in the DeviceTree.

Note that qcom_scm.download_mode=1 must be specified on the kernel command line for the kernel to attempt selecting download mode.

---
 arch/arm64/boot/dts/qcom/msm8916.dtsi | 2 ++
 arch/arm64/boot/dts/qcom/msm8996.dtsi | 7 +++++++
 2 files changed, 9 insertions(+)
arch/arm64/boot/dts/qcom/msm8916.dtsi +2 -0
index 039991f80831..b7197f2e7209 100644
@@ -241,6 +241,8 @@
 			clocks = <&gcc GCC_CRYPTO_CLK>, <&gcc GCC_CRYPTO_AXI_CLK>, <&gcc GCC_CRYPTO_AHB_CLK>;
 			clock-names = "core", "bus", "iface";
 			#reset-cells = <1>;
+
+			qcom,dload-mode = <&tcsr>;
 		};
 	};
 
arch/arm64/boot/dts/qcom/msm8996.dtsi +7 -0
index 8f085716e258..2eee6a33f22b 100644
@@ -261,6 +261,8 @@
 	firmware {
 		scm {
 			compatible = "qcom,scm-msm8996";
+
+			qcom,dload-mode = <&tcsr>;
 		};
 	};
 
@@ -287,6 +289,11 @@
 			reg = <0x740000 0x20000>;
 		};
 
+		tcsr: syscon@1937000 {
+			compatible = "qcom,tcsr-msm8996", "syscon";
+			reg = <0x7a0000 0x18000>;
+		};
+
 		intc: interrupt-controller@9bc0000 {
 			compatible = "arm,gic-v3";
 			#interrupt-cells = <3>;
Signature · 1 line
2.12.0
#5 lore raw

Re: [PATCH v3 3/3] arm64: dts: qcom: Specify dload address for msm8916 and msm8996

Quoted 31 lines · Bjorn Andersson

On msm8916 and msm8996 boards a secure io-write is used to write the magic for selecting "download mode", specify this address in the DeviceTree.

Note that qcom_scm.download_mode=1 must be specified on the kernel command line for the kernel to attempt selecting download mode.

---
 arch/arm64/boot/dts/qcom/msm8916.dtsi | 2 ++
 arch/arm64/boot/dts/qcom/msm8996.dtsi | 7 +++++++
 2 files changed, 9 insertions(+)
arch/arm64/boot/dts/qcom/msm8916.dtsi +2 -0
index 039991f80831..b7197f2e7209 100644
@@ -241,6 +241,8 @@
 			clocks = <&gcc GCC_CRYPTO_CLK>, <&gcc GCC_CRYPTO_AXI_CLK>, <&gcc GCC_CRYPTO_AHB_CLK>;
 			clock-names = "core", "bus", "iface";
 			#reset-cells = <1>;
+
+			qcom,dload-mode = <&tcsr>;
 		};
 	};
 
arch/arm64/boot/dts/qcom/msm8996.dtsi +0 -0
index 8f085716e258..2eee6a33f22b 100644

arch/arm64/boot/dts/qcom/msm8996.dtsi line 265

Quoted 5 lines
arch/arm64/boot/dts/qcom/msm8996.dtsi +2 -0
@@ -261,6 +261,8 @@
 	firmware {
 		scm {
 			compatible = "qcom,scm-msm8996";
+
+			qcom,dload-mode = <&tcsr>;

We don't need an offset into tcsr?

arch/arm64/boot/dts/qcom/msm8996.dtsi line 292

Quoted 8 lines
arch/arm64/boot/dts/qcom/msm8996.dtsi +1 -0
 		};
 	};
 
@@ -287,6 +289,11 @@
 			reg = <0x740000 0x20000>;
 		};
 
+		tcsr: syscon@1937000 {

This doesn't match reg property.

Quoted 7 lines
arch/arm64/boot/dts/qcom/msm8996.dtsi +4 -0
+			compatible = "qcom,tcsr-msm8996", "syscon";
+			reg = <0x7a0000 0x18000>;
+		};
+
 		intc: interrupt-controller@9bc0000 {
 			compatible = "arm,gic-v3";
 			#interrupt-cells = <3>;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#6 lore raw

Re: [PATCH v3 3/3] arm64: dts: qcom: Specify dload address for msm8916 and msm8996

Quoted 27 lines · Stephen Boyd
Quoted 26 lines · Bjorn Andersson

On msm8916 and msm8996 boards a secure io-write is used to write the magic for selecting "download mode", specify this address in the DeviceTree.

Note that qcom_scm.download_mode=1 must be specified on the kernel command line for the kernel to attempt selecting download mode.

---
 arch/arm64/boot/dts/qcom/msm8916.dtsi | 2 ++
 arch/arm64/boot/dts/qcom/msm8996.dtsi | 7 +++++++
 2 files changed, 9 insertions(+)
arch/arm64/boot/dts/qcom/msm8916.dtsi +2 -0
index 039991f80831..b7197f2e7209 100644
@@ -241,6 +241,8 @@
 			clocks = <&gcc GCC_CRYPTO_CLK>, <&gcc GCC_CRYPTO_AXI_CLK>, <&gcc GCC_CRYPTO_AHB_CLK>;
 			clock-names = "core", "bus", "iface";
 			#reset-cells = <1>;
+
+			qcom,dload-mode = <&tcsr>;
 		};
 	};
 
Quoted 13 lines

arch/arm64/boot/dts/qcom/msm8996.dtsi line 265

Quoted 10 lines
arch/arm64/boot/dts/qcom/msm8996.dtsi +2 -0
index 8f085716e258..2eee6a33f22b 100644
@@ -261,6 +261,8 @@
 	firmware {
 		scm {
 			compatible = "qcom,scm-msm8996";
+
+			qcom,dload-mode = <&tcsr>;

We don't need an offset into tcsr?

Of course we do, this only worked with my previous (and incorrect) tcsr definition - not the one I ended up including in the patch.

Thanks,
Bjorn