From patchwork Sat May 27 06:33:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 100591 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp574204qge; Fri, 26 May 2017 23:33:39 -0700 (PDT) X-Received: by 10.99.112.86 with SMTP id a22mr6854409pgn.52.1495866819351; Fri, 26 May 2017 23:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495866819; cv=none; d=google.com; s=arc-20160816; b=AUCjdcppOrCs29VN6igAUfv/kvkNadqxowYaXroOxs+Xyfz9q85lPdg2Ac6yEXy+sU F9QWeg5ejvfW9aRuPMPXLPLtZsvr7z9DoUQGybWPbnlulGsmbAA9gfmCjYv44np3UM7o QbkR8VcCqSlgXOhigJ5QinfWZpKoUCQv2yJ2u/72Q/t9mGeK2ydc2pDosaTamR53Dhex Lzt1CU28PzIKNYjVWdsyOaMO7oIlGizklK9XIxAOCou9uJ3NhJJMbVBDQbv8Spr1QFfj KkoduF5IW8pLr6ez5PuZH6h4gkDYCUuvng5a7mUzhUkeKGRcGlQx5tD0cWFdL7QZnaAT MgOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=IGyDQQmd/6qLcnyMt3UA/N+OIzPFOW4G6NTMy6yy5nM=; b=ayz/jowh9sySRErkWBfDnYYdsmX9KK0uKgQfK6jBXJM+79uLvPIrvJYYdPOeGQduQR sYMzgTPXsaJPWNbTFE5zlZowd7FPShIFIBP8aRILQc5QEZyVYOuuuWKJ8dsbKa7pJEJ5 9FHQf9VnMl4SkwNA+2Wd5BunWNk3RSYI5r5Voreo8CWhC97X6Vjjso/BGL8ulE82KIlt T+vguELj662b38wIc86SsAZtWIo5uX5DXmpfUF5VqucrABfCg3xocJK9FbD5pTFCb7cE uC2Kuw7bIJJtzm03l8DDhG5RWcSoFCznDs7My3wISDQEEbp5ZWN0N1B548Ub8bpBN7DU Z5og== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a7si33975312plt.90.2017.05.26.23.33.39; Fri, 26 May 2017 23:33:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752919AbdE0Gdg (ORCPT + 7 others); Sat, 27 May 2017 02:33:36 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:36104 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752841AbdE0GdQ (ORCPT ); Sat, 27 May 2017 02:33:16 -0400 Received: by mail-pf0-f174.google.com with SMTP id m17so26263207pfg.3 for ; Fri, 26 May 2017 23:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1qLAzPsjfkDueHSBVeiF1+YGK9F9Z1do3Rg4CGbhVlQ=; b=Y7cDB7RLMgfmJ0cWJjL8NryChb8yEWxS4doCEpT4LnLc6JIU9R4O3jqzkIZbNOUFg5 wYwBP1VQGyxgsNGIfzBfgGYQMatunscM8NLeX35o7YaQJQVWrDvZZnA1MKpWEhXQ+kwi CszToCVFQKk0yyHiYvl9nZuMTS0ZM7aKY4bvE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1qLAzPsjfkDueHSBVeiF1+YGK9F9Z1do3Rg4CGbhVlQ=; b=fu5eBbWh10Q5S/V5xl1hU4QhS3/3vTX72lD+WUEtCPfZWwfxrJ7EWfa0+RhCu+kjH8 lqmGw8I2/Qqt8/T3MqupZbgHV7yD+fy6Yb4HkR0B2eyjlOIvI4u0cOu0iPuaBHumvPnH daoAPqsM51wLxFazq4zvOdpgCggE7K5V9+257oK8DLVFOzVXDgjGn80OsGpYeF+suAMh qhZi9L3pAQBsbNj3ssw+buGdaAhtQpYX+SLixI7N4lKTC8dgkP8l08HKUU9YSYuypTED 31c5qqnxir2PQ9HRb7vdgBgYuNqvl5f2pKTB7MwHliSVxnJNUJVBVjsIMqpIGp8HXdlz 7PKA== X-Gm-Message-State: AODbwcA63YzBWoOPHsQxrv51j3+T1aWhK4c+AaGocU/9ixAiWrA0SUDk HKvAzoRXO+/Yo+ww X-Received: by 10.98.38.193 with SMTP id m184mr6464978pfm.150.1495866795116; Fri, 26 May 2017 23:33:15 -0700 (PDT) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id g27sm5243346pfg.63.2017.05.26.23.33.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 May 2017 23:33:14 -0700 (PDT) From: Bjorn Andersson To: Andy Gross Cc: Stephen Boyd , Rob Herring , Mark Rutland , David Brown , Srinivas Kandagatla , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 2/3] firmware: qcom: scm: Expose download-mode control Date: Fri, 26 May 2017 23:33:07 -0700 Message-Id: <20170527063308.10483-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170527063308.10483-1-bjorn.andersson@linaro.org> References: <20170527063308.10483-1-bjorn.andersson@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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. Signed-off-by: Bjorn Andersson --- 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/qcom_scm-32.c | 6 +++ drivers/firmware/qcom_scm-64.c | 13 +++++++ drivers/firmware/qcom_scm.c | 43 ++++++++++++++++++++++ drivers/firmware/qcom_scm.h | 2 + 5 files changed, 66 insertions(+) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/devicetree/bindings/firmware/qcom,scm.txt b/Documentation/devicetree/bindings/firmware/qcom,scm.txt index 20f26fbce875..388817d1d00e 100644 --- a/Documentation/devicetree/bindings/firmware/qcom,scm.txt +++ b/Documentation/devicetree/bindings/firmware/qcom,scm.txt @@ -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-addr: Specifies the address (2 cells) for the download mode + magic (optional) Example for MSM8916: diff --git a/drivers/firmware/qcom_scm-32.c b/drivers/firmware/qcom_scm-32.c index 11fdb1584823..68b2033bc30e 100644 --- a/drivers/firmware/qcom_scm-32.c +++ b/drivers/firmware/qcom_scm-32.c @@ -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 { diff --git a/drivers/firmware/qcom_scm-64.c b/drivers/firmware/qcom_scm-64.c index bf50fb59852e..3fea6f563ca9 100644 --- a/drivers/firmware/qcom_scm-64.c +++ b/drivers/firmware/qcom_scm-64.c @@ -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) { diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index e18d63935648..98f4747acddb 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,9 @@ #include "qcom_scm.h" +static bool download_mode; +module_param(download_mode, bool, 0700); + #define SCM_HAS_CORE_CLK BIT(0) #define SCM_HAS_IFACE_CLK BIT(1) #define SCM_HAS_BUS_CLK BIT(2) @@ -38,6 +42,8 @@ struct qcom_scm { struct clk *iface_clk; struct clk *bus_clk; struct reset_controller_dev reset; + + phys_addr_t dload_mode_addr; }; static struct qcom_scm *__scm; @@ -345,6 +351,28 @@ int qcom_scm_io_writel(phys_addr_t addr, unsigned int val) } EXPORT_SYMBOL(qcom_scm_io_writel); +static void qcom_scm_set_download_mode(bool enable) +{ + bool avail; + int ret; + + avail = __qcom_scm_is_call_available(__scm->dev, + QCOM_SCM_SVC_BOOT, + QCOM_SCM_SET_DLOAD_MODE); + if (avail) { + ret = __qcom_scm_set_dload_mode(__scm->dev, enable); + if (ret) + dev_err(__scm->dev, "SCM failed to set download mode: %d\n", ret); + } else if (__scm->dload_mode_addr) { + ret = __qcom_scm_io_writel(__scm->dev, __scm->dload_mode_addr, + enable ? QCOM_SCM_SET_DLOAD_MODE : 0); + if (ret) + dev_err(__scm->dev, "SCM failed to set download mode: %d\n", ret); + } else { + dev_err(__scm->dev, "No available mechanism for setting download mode\n"); + } +} + /** * qcom_scm_is_available() - Checks if SCM is available */ @@ -365,6 +393,7 @@ static int qcom_scm_probe(struct platform_device *pdev) struct qcom_scm *scm; unsigned long clks; int ret; + u64 val; scm = devm_kzalloc(&pdev->dev, sizeof(*scm), GFP_KERNEL); if (!scm) @@ -418,9 +447,22 @@ static int qcom_scm_probe(struct platform_device *pdev) __qcom_scm_init(); + ret = of_property_read_u64(pdev->dev.of_node, "qcom,dload-mode-addr", &val); + if (!ret) + scm->dload_mode_addr = val; + + if (download_mode) + qcom_scm_set_download_mode(true); + return 0; } +void qcom_scm_shutdown(struct platform_device *pdev) +{ + if (download_mode) + qcom_scm_set_download_mode(false); +} + static const struct of_device_id qcom_scm_dt_match[] = { { .compatible = "qcom,scm-apq8064", /* FIXME: This should have .data = (void *) SCM_HAS_CORE_CLK */ @@ -448,6 +490,7 @@ static struct platform_driver qcom_scm_driver = { .of_match_table = qcom_scm_dt_match, }, .probe = qcom_scm_probe, + .shutdown = qcom_scm_shutdown, }; static int __init qcom_scm_init(void) diff --git a/drivers/firmware/qcom_scm.h b/drivers/firmware/qcom_scm.h index a60e4b9b1394..83f171c23943 100644 --- a/drivers/firmware/qcom_scm.h +++ b/drivers/firmware/qcom_scm.h @@ -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