From nobody Fri Dec 26 07:39:22 2025 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA8733C464; Tue, 9 Jan 2024 15:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="h3Wxd6/s" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 409EBBbX025695; Tue, 9 Jan 2024 15:49:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=pvWii2rG+ndwgTJlbNXZ3/D8TNknZYK59hpEwt0qOHE=; b=h3 Wxd6/sEqKe89E3v4VuATpLRVS1FbKZvv8nqutR7iJfDK+VJnnK2xmkoQ6fzzfIQk T/U+bmoSf4HuiM+LI3rAU56jAI93In7bXUcLHFhMmX1YJqhX0TfPLLWIbSBE/FYs 2MjXlQRcYrZ15mQ3UiRGpZb9eHm4BV5dJWoUD5P1fLEVoPKSQ3YTVu1msERnUhC7 KXpVaH6CBWbV2imDpqx/LbHiAPOXoFXJJ9hnu/wrkjhz3Z+uxaMqDWd0tnAmbrqu 3XTUyhRwJQ9lqCAYiRZT+j4bDl929Ew78AuQqn11gLaymSYGECyXFDNhJhNFSUu5 HiB7O7HUIWuO9Wl6JrDw== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vgq2yt34v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Jan 2024 15:49:39 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 409FncqF026862 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 Jan 2024 15:49:38 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 9 Jan 2024 07:49:33 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , CC: , , Mukesh Ojha Subject: [PATCH v7 11/12] firmware: qcom_scm: Refactor code to support multiple dload mode Date: Tue, 9 Jan 2024 21:01:59 +0530 Message-ID: <20240109153200.12848-12-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.43.0.254.ga26002b62827 In-Reply-To: <20240109153200.12848-1-quic_mojha@quicinc.com> References: <20240109153200.12848-1-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: WsjlKhOlPT_EQ5fqYc_rUEJ7XFv-j9Mn X-Proofpoint-ORIG-GUID: WsjlKhOlPT_EQ5fqYc_rUEJ7XFv-j9Mn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401090128 Content-Type: text/plain; charset="utf-8" Currently on Qualcomm SoC, download_mode is enabled if CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT is selected. Refactor the code such that it supports multiple download modes and drop CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT config instead, give interface to set the download mode from module parameter. Signed-off-by: Mukesh Ojha --- drivers/firmware/qcom/Kconfig | 11 ------ drivers/firmware/qcom/qcom_scm.c | 58 +++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index 3f05d9854ddf..3bbbaef145ad 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -9,17 +9,6 @@ menu "Qualcomm firmware drivers" config QCOM_SCM tristate =20 -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 QCOM_QSEECOM bool "Qualcomm QSEECOM interface driver" depends on QCOM_SCM=3Dy diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_= scm.c index 037e69285b67..1f819f6e14b3 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -26,8 +27,7 @@ =20 #include "qcom_scm.h" =20 -static bool download_mode =3D IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEF= AULT); -module_param(download_mode, bool, 0); +static u32 download_mode; =20 struct qcom_scm { struct device *dev; @@ -129,6 +129,11 @@ static const char * const qcom_scm_convention_names[] = =3D { [SMC_CONVENTION_LEGACY] =3D "smc legacy", }; =20 +static const char * const download_mode_name[] =3D { + [QCOM_DLOAD_NODUMP] =3D "off", + [QCOM_DLOAD_FULLDUMP] =3D "full", +}; + static struct qcom_scm *__scm; =20 static int qcom_scm_clk_enable(void) @@ -528,19 +533,18 @@ static int __qcom_scm_set_dload_mode(struct device *d= ev, bool enable) return qcom_scm_call_atomic(__scm->dev, &desc, NULL); } =20 -static void qcom_scm_set_download_mode(bool enable) +static void qcom_scm_set_download_mode(u32 download_mode) { - u32 val =3D enable ? QCOM_DLOAD_FULLDUMP : QCOM_DLOAD_NODUMP; int ret =3D 0; =20 if (__scm->dload_mode_addr) { ret =3D qcom_scm_io_rmw(__scm->dload_mode_addr, QCOM_DLOAD_MASK, - FIELD_PREP(QCOM_DLOAD_MASK, val)); + FIELD_PREP(QCOM_DLOAD_MASK, download_mode)); } else if (__qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_BOOT, QCOM_SCM_BOOT_SET_DLOAD_MODE)) { - ret =3D __qcom_scm_set_dload_mode(__scm->dev, enable); + ret =3D __qcom_scm_set_dload_mode(__scm->dev, !!download_mode); } else { dev_err(__scm->dev, "No available mechanism for setting download mode\n"); @@ -1842,6 +1846,42 @@ static irqreturn_t qcom_scm_irq_handler(int irq, voi= d *data) return IRQ_HANDLED; } =20 +static int get_download_mode(char *buffer, const struct kernel_param *kp) +{ + if (download_mode >=3D ARRAY_SIZE(download_mode_name)) + return sysfs_emit(buffer, "unknown mode\n"); + + return sysfs_emit(buffer, "%s\n", download_mode_name[download_mode]); +} + +static int set_download_mode(const char *val, const struct kernel_param *k= p) +{ + u32 old =3D download_mode; + int ret; + + ret =3D sysfs_match_string(download_mode_name, val); + if (ret < 0) { + download_mode =3D old; + pr_err("qcom_scm: unknown download mode: %s\n", val); + return -EINVAL; + } + + download_mode =3D ret; + if (__scm) + qcom_scm_set_download_mode(download_mode); + + return 0; +} + +static const struct kernel_param_ops download_mode_param_ops =3D { + .get =3D get_download_mode, + .set =3D set_download_mode, +}; + +module_param_cb(download_mode, &download_mode_param_ops, NULL, 0644); +MODULE_PARM_DESC(download_mode, + "download mode: off/full are acceptable values"); + static int qcom_scm_probe(struct platform_device *pdev) { struct qcom_scm *scm; @@ -1906,12 +1946,12 @@ static int qcom_scm_probe(struct platform_device *p= dev) __get_convention(); =20 /* - * If requested enable "download mode", from this point on warmboot + * If "download mode" is requested, from this point on warmboot * will cause the boot stages to enter download mode, unless * disabled below by a clean shutdown/reboot. */ if (download_mode) - qcom_scm_set_download_mode(true); + qcom_scm_set_download_mode(download_mode); =20 =20 /* @@ -1939,7 +1979,7 @@ static int qcom_scm_probe(struct platform_device *pde= v) static void qcom_scm_shutdown(struct platform_device *pdev) { /* Clean shutdown, disable download mode to allow normal restart */ - qcom_scm_set_download_mode(false); + qcom_scm_set_download_mode(QCOM_DLOAD_NODUMP); } =20 static const struct of_device_id qcom_scm_dt_match[] =3D { --=20 2.43.0.254.ga26002b62827