*** Disclaimer: I know extremely little about Qualcomm's undocumented
SMC API. ***

I'm trying to get upstream support for an IPQ4019 device I have, and by
default, warm boot does not work properly -- it appears to trap into
TrustZone. I find that the downstream/vendor kernel makes this call at
boot, with notes about the watchdog and SDI configuration. It appears
some of this is leftover from when they had download-mode enabled, as
well as some other debug features, and they didn't get completely turned
off in the production bootloader. But I reall can't tell that well; I'm
just going off the minimal source code and git logs.

Because this is so undocumented, I can't tell what the right thing to do
is -- should this go behind a DT property? Should I apply it only for
ipq4019? Is there a better way to describe and document the bits used in
this command?

If it helps, I can try to shop around for some testing on other systems.

Signed-off-by: Brian Norris <[email protected]>
---
 drivers/firmware/qcom_scm.c | 20 ++++++++++++++++++++
 drivers/firmware/qcom_scm.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c
index 0e7233a20f34..70c46f1668d1 100644
--- a/drivers/firmware/qcom_scm.c
+++ b/drivers/firmware/qcom_scm.c
@@ -394,6 +394,20 @@ static int __qcom_scm_set_dload_mode(struct device *dev, 
bool enable)
        return qcom_scm_call(__scm->dev, &desc, NULL);
 }
 
+static int __qcom_scm_disable_sdi(struct device *dev)
+{
+       struct qcom_scm_desc desc = {
+               .svc = QCOM_SCM_SVC_BOOT,
+               .cmd = QCOM_SCM_BOOT_CONFIG_SDI,
+               .arginfo = QCOM_SCM_ARGS(2),
+               .args[0] = 1  /* 1: disable watchdog debug */,
+               .args[1] = 0  /* 0: disable SDI */,
+               .owner = ARM_SMCCC_OWNER_SIP,
+       };
+
+       return qcom_scm_call(__scm->dev, &desc, NULL);
+}
+
 static void qcom_scm_set_download_mode(bool enable)
 {
        bool avail;
@@ -1122,6 +1136,12 @@ static int qcom_scm_probe(struct platform_device *pdev)
        if (download_mode)
                qcom_scm_set_download_mode(true);
 
+       /*
+        * Some bootloaders leave this enabled by default, which prevents
+        * normal warm reboot.
+        */
+       __qcom_scm_disable_sdi(__scm->dev);
+
        return 0;
 }
 
diff --git a/drivers/firmware/qcom_scm.h b/drivers/firmware/qcom_scm.h
index d9ed670da222..39c3dc0dfc50 100644
--- a/drivers/firmware/qcom_scm.h
+++ b/drivers/firmware/qcom_scm.h
@@ -74,6 +74,7 @@ extern int scm_legacy_call(struct device *dev, const struct 
qcom_scm_desc *desc,
 #define QCOM_SCM_SVC_BOOT              0x01
 #define QCOM_SCM_BOOT_SET_ADDR         0x01
 #define QCOM_SCM_BOOT_TERMINATE_PC     0x02
+#define QCOM_SCM_BOOT_CONFIG_SDI       0x09
 #define QCOM_SCM_BOOT_SET_DLOAD_MODE   0x10
 #define QCOM_SCM_BOOT_SET_REMOTE_STATE 0x0a
 #define QCOM_SCM_FLUSH_FLAG_MASK       0x3
-- 
2.27.0

Reply via email to