Skip to content

Commit 8c1b7dc

Browse files
anderssonAndy Gross
authored andcommitted
firmware: qcom: scm: Expose download-mode control
In order to aid post-mortem debugging the Qualcomm platforms provide 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 somewhere 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. Reviewed-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
1 parent 4e659db commit 8c1b7dc

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

Documentation/devicetree/bindings/firmware/qcom,scm.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Required properties:
1818
* Core, iface, and bus clocks required for "qcom,scm"
1919
- clock-names: Must contain "core" for the core clock, "iface" for the interface
2020
clock and "bus" for the bus clock per the requirements of the compatible.
21+
- qcom,dload-mode: phandle to the TCSR hardware block and offset of the
22+
download mode control register (optional)
2123

2224
Example for MSM8916:
2325

drivers/firmware/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ config QCOM_SCM_64
215215
def_bool y
216216
depends on QCOM_SCM && ARM64
217217

218+
config QCOM_SCM_DOWNLOAD_MODE_DEFAULT
219+
bool "Qualcomm download mode enabled by default"
220+
depends on QCOM_SCM
221+
help
222+
A device with "download mode" enabled will upon an unexpected
223+
warm-restart enter a special debug mode that allows the user to
224+
"download" memory content over USB for offline postmortem analysis.
225+
The feature can be enabled/disabled on the kernel command line.
226+
227+
Say Y here to enable "download mode" by default.
228+
218229
config TI_SCI_PROTOCOL
219230
tristate "TI System Control Interface (TISCI) Message Protocol"
220231
depends on TI_MESSAGE_MANAGER

drivers/firmware/qcom_scm-32.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,12 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)
561561
return ret ? : le32_to_cpu(out);
562562
}
563563

564+
int __qcom_scm_set_dload_mode(struct device *dev, bool enable)
565+
{
566+
return qcom_scm_call_atomic2(QCOM_SCM_SVC_BOOT, QCOM_SCM_SET_DLOAD_MODE,
567+
enable ? QCOM_SCM_SET_DLOAD_MODE : 0, 0);
568+
}
569+
564570
int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id)
565571
{
566572
struct {

drivers/firmware/qcom_scm-64.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,19 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,
440440
return ret;
441441
}
442442

443+
int __qcom_scm_set_dload_mode(struct device *dev, bool enable)
444+
{
445+
struct qcom_scm_desc desc = {0};
446+
struct arm_smccc_res res;
447+
448+
desc.args[0] = QCOM_SCM_SET_DLOAD_MODE;
449+
desc.args[1] = enable ? QCOM_SCM_SET_DLOAD_MODE : 0;
450+
desc.arginfo = QCOM_SCM_ARGS(2);
451+
452+
return qcom_scm_call(dev, QCOM_SCM_SVC_BOOT, QCOM_SCM_SET_DLOAD_MODE,
453+
&desc, &res);
454+
}
455+
443456
int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
444457
unsigned int *val)
445458
{

drivers/firmware/qcom_scm.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919
#include <linux/cpumask.h>
2020
#include <linux/export.h>
2121
#include <linux/dma-mapping.h>
22+
#include <linux/module.h>
2223
#include <linux/types.h>
2324
#include <linux/qcom_scm.h>
2425
#include <linux/of.h>
26+
#include <linux/of_address.h>
2527
#include <linux/of_platform.h>
2628
#include <linux/clk.h>
2729
#include <linux/reset-controller.h>
2830

2931
#include "qcom_scm.h"
3032

33+
static bool download_mode = IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT);
34+
module_param(download_mode, bool, 0);
35+
3136
#define SCM_HAS_CORE_CLK BIT(0)
3237
#define SCM_HAS_IFACE_CLK BIT(1)
3338
#define SCM_HAS_BUS_CLK BIT(2)
@@ -38,6 +43,8 @@ struct qcom_scm {
3843
struct clk *iface_clk;
3944
struct clk *bus_clk;
4045
struct reset_controller_dev reset;
46+
47+
u64 dload_mode_addr;
4148
};
4249

4350
static struct qcom_scm *__scm;
@@ -345,6 +352,54 @@ int qcom_scm_io_writel(phys_addr_t addr, unsigned int val)
345352
}
346353
EXPORT_SYMBOL(qcom_scm_io_writel);
347354

355+
static void qcom_scm_set_download_mode(bool enable)
356+
{
357+
bool avail;
358+
int ret = 0;
359+
360+
avail = __qcom_scm_is_call_available(__scm->dev,
361+
QCOM_SCM_SVC_BOOT,
362+
QCOM_SCM_SET_DLOAD_MODE);
363+
if (avail) {
364+
ret = __qcom_scm_set_dload_mode(__scm->dev, enable);
365+
} else if (__scm->dload_mode_addr) {
366+
ret = __qcom_scm_io_writel(__scm->dev, __scm->dload_mode_addr,
367+
enable ? QCOM_SCM_SET_DLOAD_MODE : 0);
368+
} else {
369+
dev_err(__scm->dev,
370+
"No available mechanism for setting download mode\n");
371+
}
372+
373+
if (ret)
374+
dev_err(__scm->dev, "failed to set download mode: %d\n", ret);
375+
}
376+
377+
static int qcom_scm_find_dload_address(struct device *dev, u64 *addr)
378+
{
379+
struct device_node *tcsr;
380+
struct device_node *np = dev->of_node;
381+
struct resource res;
382+
u32 offset;
383+
int ret;
384+
385+
tcsr = of_parse_phandle(np, "qcom,dload-mode", 0);
386+
if (!tcsr)
387+
return 0;
388+
389+
ret = of_address_to_resource(tcsr, 0, &res);
390+
of_node_put(tcsr);
391+
if (ret)
392+
return ret;
393+
394+
ret = of_property_read_u32_index(np, "qcom,dload-mode", 1, &offset);
395+
if (ret < 0)
396+
return ret;
397+
398+
*addr = res.start + offset;
399+
400+
return 0;
401+
}
402+
348403
/**
349404
* qcom_scm_is_available() - Checks if SCM is available
350405
*/
@@ -370,6 +425,10 @@ static int qcom_scm_probe(struct platform_device *pdev)
370425
if (!scm)
371426
return -ENOMEM;
372427

428+
ret = qcom_scm_find_dload_address(&pdev->dev, &scm->dload_mode_addr);
429+
if (ret < 0)
430+
return ret;
431+
373432
clks = (unsigned long)of_device_get_match_data(&pdev->dev);
374433
if (clks & SCM_HAS_CORE_CLK) {
375434
scm->core_clk = devm_clk_get(&pdev->dev, "core");
@@ -418,9 +477,24 @@ static int qcom_scm_probe(struct platform_device *pdev)
418477

419478
__qcom_scm_init();
420479

480+
/*
481+
* If requested enable "download mode", from this point on warmboot
482+
* will cause the the boot stages to enter download mode, unless
483+
* disabled below by a clean shutdown/reboot.
484+
*/
485+
if (download_mode)
486+
qcom_scm_set_download_mode(true);
487+
421488
return 0;
422489
}
423490

491+
static void qcom_scm_shutdown(struct platform_device *pdev)
492+
{
493+
/* Clean shutdown, disable download mode to allow normal restart */
494+
if (download_mode)
495+
qcom_scm_set_download_mode(false);
496+
}
497+
424498
static const struct of_device_id qcom_scm_dt_match[] = {
425499
{ .compatible = "qcom,scm-apq8064",
426500
/* FIXME: This should have .data = (void *) SCM_HAS_CORE_CLK */
@@ -448,6 +522,7 @@ static struct platform_driver qcom_scm_driver = {
448522
.of_match_table = qcom_scm_dt_match,
449523
},
450524
.probe = qcom_scm_probe,
525+
.shutdown = qcom_scm_shutdown,
451526
};
452527

453528
static int __init qcom_scm_init(void)

drivers/firmware/qcom_scm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
#define QCOM_SCM_SVC_BOOT 0x1
1616
#define QCOM_SCM_BOOT_ADDR 0x1
17+
#define QCOM_SCM_SET_DLOAD_MODE 0x10
1718
#define QCOM_SCM_BOOT_ADDR_MC 0x11
1819
#define QCOM_SCM_SET_REMOTE_STATE 0xa
1920
extern int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id);
21+
extern int __qcom_scm_set_dload_mode(struct device *dev, bool enable);
2022

2123
#define QCOM_SCM_FLAG_HLOS 0x01
2224
#define QCOM_SCM_FLAG_COLDBOOT_MC 0x02

0 commit comments

Comments
 (0)