Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Bjorn Andersson and committed by
Andy Gross
8c1b7dc9 4e659dbe

+109
+2
Documentation/devicetree/bindings/firmware/qcom,scm.txt
··· 18 18 * Core, iface, and bus clocks required for "qcom,scm" 19 19 - clock-names: Must contain "core" for the core clock, "iface" for the interface 20 20 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) 21 23 22 24 Example for MSM8916: 23 25
+11
drivers/firmware/Kconfig
··· 215 215 def_bool y 216 216 depends on QCOM_SCM && ARM64 217 217 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 + 218 229 config TI_SCI_PROTOCOL 219 230 tristate "TI System Control Interface (TISCI) Message Protocol" 220 231 depends on TI_MESSAGE_MANAGER
+6
drivers/firmware/qcom_scm-32.c
··· 561 561 return ret ? : le32_to_cpu(out); 562 562 } 563 563 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 + 564 570 int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id) 565 571 { 566 572 struct {
+13
drivers/firmware/qcom_scm-64.c
··· 440 440 return ret; 441 441 } 442 442 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 + 443 456 int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, 444 457 unsigned int *val) 445 458 {
+75
drivers/firmware/qcom_scm.c
··· 19 19 #include <linux/cpumask.h> 20 20 #include <linux/export.h> 21 21 #include <linux/dma-mapping.h> 22 + #include <linux/module.h> 22 23 #include <linux/types.h> 23 24 #include <linux/qcom_scm.h> 24 25 #include <linux/of.h> 26 + #include <linux/of_address.h> 25 27 #include <linux/of_platform.h> 26 28 #include <linux/clk.h> 27 29 #include <linux/reset-controller.h> 28 30 29 31 #include "qcom_scm.h" 32 + 33 + static bool download_mode = IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT); 34 + module_param(download_mode, bool, 0); 30 35 31 36 #define SCM_HAS_CORE_CLK BIT(0) 32 37 #define SCM_HAS_IFACE_CLK BIT(1) ··· 43 38 struct clk *iface_clk; 44 39 struct clk *bus_clk; 45 40 struct reset_controller_dev reset; 41 + 42 + u64 dload_mode_addr; 46 43 }; 47 44 48 45 static struct qcom_scm *__scm; ··· 352 345 } 353 346 EXPORT_SYMBOL(qcom_scm_io_writel); 354 347 348 + static void qcom_scm_set_download_mode(bool enable) 349 + { 350 + bool avail; 351 + int ret = 0; 352 + 353 + avail = __qcom_scm_is_call_available(__scm->dev, 354 + QCOM_SCM_SVC_BOOT, 355 + QCOM_SCM_SET_DLOAD_MODE); 356 + if (avail) { 357 + ret = __qcom_scm_set_dload_mode(__scm->dev, enable); 358 + } else if (__scm->dload_mode_addr) { 359 + ret = __qcom_scm_io_writel(__scm->dev, __scm->dload_mode_addr, 360 + enable ? QCOM_SCM_SET_DLOAD_MODE : 0); 361 + } else { 362 + dev_err(__scm->dev, 363 + "No available mechanism for setting download mode\n"); 364 + } 365 + 366 + if (ret) 367 + dev_err(__scm->dev, "failed to set download mode: %d\n", ret); 368 + } 369 + 370 + static int qcom_scm_find_dload_address(struct device *dev, u64 *addr) 371 + { 372 + struct device_node *tcsr; 373 + struct device_node *np = dev->of_node; 374 + struct resource res; 375 + u32 offset; 376 + int ret; 377 + 378 + tcsr = of_parse_phandle(np, "qcom,dload-mode", 0); 379 + if (!tcsr) 380 + return 0; 381 + 382 + ret = of_address_to_resource(tcsr, 0, &res); 383 + of_node_put(tcsr); 384 + if (ret) 385 + return ret; 386 + 387 + ret = of_property_read_u32_index(np, "qcom,dload-mode", 1, &offset); 388 + if (ret < 0) 389 + return ret; 390 + 391 + *addr = res.start + offset; 392 + 393 + return 0; 394 + } 395 + 355 396 /** 356 397 * qcom_scm_is_available() - Checks if SCM is available 357 398 */ ··· 424 369 scm = devm_kzalloc(&pdev->dev, sizeof(*scm), GFP_KERNEL); 425 370 if (!scm) 426 371 return -ENOMEM; 372 + 373 + ret = qcom_scm_find_dload_address(&pdev->dev, &scm->dload_mode_addr); 374 + if (ret < 0) 375 + return ret; 427 376 428 377 clks = (unsigned long)of_device_get_match_data(&pdev->dev); 429 378 if (clks & SCM_HAS_CORE_CLK) { ··· 477 418 478 419 __qcom_scm_init(); 479 420 421 + /* 422 + * If requested enable "download mode", from this point on warmboot 423 + * will cause the the boot stages to enter download mode, unless 424 + * disabled below by a clean shutdown/reboot. 425 + */ 426 + if (download_mode) 427 + qcom_scm_set_download_mode(true); 428 + 480 429 return 0; 430 + } 431 + 432 + static void qcom_scm_shutdown(struct platform_device *pdev) 433 + { 434 + /* Clean shutdown, disable download mode to allow normal restart */ 435 + if (download_mode) 436 + qcom_scm_set_download_mode(false); 481 437 } 482 438 483 439 static const struct of_device_id qcom_scm_dt_match[] = { ··· 522 448 .of_match_table = qcom_scm_dt_match, 523 449 }, 524 450 .probe = qcom_scm_probe, 451 + .shutdown = qcom_scm_shutdown, 525 452 }; 526 453 527 454 static int __init qcom_scm_init(void)
+2
drivers/firmware/qcom_scm.h
··· 14 14 15 15 #define QCOM_SCM_SVC_BOOT 0x1 16 16 #define QCOM_SCM_BOOT_ADDR 0x1 17 + #define QCOM_SCM_SET_DLOAD_MODE 0x10 17 18 #define QCOM_SCM_BOOT_ADDR_MC 0x11 18 19 #define QCOM_SCM_SET_REMOTE_STATE 0xa 19 20 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); 20 22 21 23 #define QCOM_SCM_FLAG_HLOS 0x01 22 24 #define QCOM_SCM_FLAG_COLDBOOT_MC 0x02