From patchwork Fri Nov 24 22:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468180 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="kwwrGA9D" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E84E810F4; Fri, 24 Nov 2023 14:21:18 -0800 (PST) Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOM3lUr002248; Fri, 24 Nov 2023 22:20:52 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-type; s=qcppdkim1; bh=HPKadZG1DvLbRRtA37U95Imcvsned4UOnigF1RUkjoQ=; b=kwwrGA9DewX5E+5veMkV7aCnZkbzRQ5H2Of6UHa3BMG5Ic+GMYLP6UQFulO/Bz5rfWpL mYJaJD/mh+BLoJKafAHQKxBnZdo9kfwZp7Wq9ZAlUSC/CAZBofDApI+4Uf6ZZ6gTvDBD kUSAxp9r1kSIbL9PE+55so+S1nQIPyrQ4ONhfTbhbONTrdQVOGmLZumSSTAOIV5MxVVf qDz0Et/laGgJ2DuwtxATWDFKjqD5O9WmFPFUh6Zu2KmUDDCEJy7wciIm/SKNHgmKH1aK 2CljKAoT8UVFA/5vfSb+n/QHpC53OZ5wSD/R793BpDQqep8+oTI7FjzDJeB7QYdaGKla 6Q== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujyatghf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:20:52 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMKYAa017556 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:20:34 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; Fri, 24 Nov 2023 14:20:24 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 01/12] firmware: qcom_scm: Refactor code to support multiple dload mode Date: Sat, 25 Nov 2023 03:49:44 +0530 Message-ID: <1700864395-1479-2-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: wc0Gr8K0RC2Bw-bbwhMle23Qbuv5BA8B X-Proofpoint-ORIG-GUID: wc0Gr8K0RC2Bw-bbwhMle23Qbuv5BA8B X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 phishscore=0 suspectscore=0 adultscore=0 clxscore=1015 mlxlogscore=999 mlxscore=0 malwarescore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 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 -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=y diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 87bcd5c02f2b..c5878c38f378 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 @@ -27,8 +28,7 @@ #include "qcom_scm.h" -static bool download_mode = IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT); -module_param(download_mode, bool, 0); +static u32 download_mode; struct qcom_scm { struct device *dev; @@ -132,6 +132,11 @@ static const char * const qcom_scm_convention_names[] = { [SMC_CONVENTION_LEGACY] = "smc legacy", }; +static const char * const download_mode_name[] = { + [QCOM_DLOAD_NODUMP] = "off", + [QCOM_DLOAD_FULLDUMP] = "full", +}; + static struct qcom_scm *__scm; static int qcom_scm_clk_enable(void) @@ -529,19 +534,18 @@ static int __qcom_scm_set_dload_mode(struct device *dev, bool enable) return qcom_scm_call_atomic(__scm->dev, &desc, NULL); } -static void qcom_scm_set_download_mode(bool enable) +static void qcom_scm_set_download_mode(u32 download_mode) { - u32 val = enable ? QCOM_DLOAD_FULLDUMP : QCOM_DLOAD_NODUMP; int ret = 0; if (__scm->dload_mode_addr) { ret = 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 = __qcom_scm_set_dload_mode(__scm->dev, enable); + ret = __qcom_scm_set_dload_mode(__scm->dev, !!download_mode); } else { dev_err(__scm->dev, "No available mechanism for setting download mode\n"); @@ -1843,6 +1847,42 @@ static irqreturn_t qcom_scm_irq_handler(int irq, void *data) return IRQ_HANDLED; } +static int get_download_mode(char *buffer, const struct kernel_param *kp) +{ + if (download_mode >= 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 *kp) +{ + u32 old = download_mode; + int ret; + + ret = sysfs_match_string(download_mode_name, val); + if (ret < 0) { + download_mode = old; + pr_err("qcom_scm: unknown download mode: %s\n", val); + return -EINVAL; + } + + download_mode = ret; + if (__scm) + qcom_scm_set_download_mode(download_mode); + + return 0; +} + +static const struct kernel_param_ops download_mode_param_ops = { + .get = get_download_mode, + .set = 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; @@ -1907,12 +1947,12 @@ static int qcom_scm_probe(struct platform_device *pdev) __get_convention(); /* - * 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); /* @@ -1940,7 +1980,7 @@ static int qcom_scm_probe(struct platform_device *pdev) 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); } static const struct of_device_id qcom_scm_dt_match[] = { From patchwork Fri Nov 24 22:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468183 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="NlZsgL6Q" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 854AB198D; Fri, 24 Nov 2023 14:21:25 -0800 (PST) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOLkw7H012282; Fri, 24 Nov 2023 22:21:04 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-type; s=qcppdkim1; bh=6mwvu7xKz6N9G240sW8qG833kZvQJY4H+Sm3Z0bePUs=; b=NlZsgL6QYKbKWXjTsdUl2Oe7JUrw0shRmfN4Y6PdyTQI0tKRN3sC2FuacBbaHAW2f9j7 a7f8HZfSfIvixqb0E4IdgCQWkjtyNR6dh3ES519Sq6850XiDT+dGG95F0vKx82ywjr81 STPGTADz03RwZBgy+JKlVWAGaIza+5dqSaBJlPX6K/ecpcBYJYZ97frx+pSqO/ZkoOk4 JQ9Fn2sHZ7soHTlKdRbJazIWrWa+xSdACqo1Y+dszKG3r7lia/wIFWlHXEzf0RMQgMdU +A2QvitpjIZ54KrCw80hoH/EY202/1ATaAXI0DEYpahNYnMFK9DUlKeD4foCp9ev+QRN kQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uj4hwm10e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:04 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMKfch015479 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:20:41 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; Fri, 24 Nov 2023 14:20:31 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 02/12] firmware/qcom: qcom_scm: Add multiple download mode support Date: Sat, 25 Nov 2023 03:49:45 +0530 Message-ID: <1700864395-1479-3-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: PhexFHj7k_YiyTvntEHtlLIbg_Sf52Hi X-Proofpoint-ORIG-GUID: PhexFHj7k_YiyTvntEHtlLIbg_Sf52Hi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Currently, scm driver only supports full dump when download mode is selected. Add support to enable minidump as well as enable it along with fulldump. Signed-off-by: Mukesh Ojha --- drivers/firmware/qcom/qcom_scm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index c5878c38f378..70bb59992fb9 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -123,6 +123,8 @@ static const u8 qcom_scm_cpu_warm_bits[QCOM_SCM_BOOT_MAX_CPUS] = { enum qcom_dload_mode { QCOM_DLOAD_NODUMP = 0, QCOM_DLOAD_FULLDUMP = 1, + QCOM_DLOAD_MINIDUMP = 2, + QCOM_DLOAD_BOTHDUMP = 3, }; static const char * const qcom_scm_convention_names[] = { @@ -135,6 +137,8 @@ static const char * const qcom_scm_convention_names[] = { static const char * const download_mode_name[] = { [QCOM_DLOAD_NODUMP] = "off", [QCOM_DLOAD_FULLDUMP] = "full", + [QCOM_DLOAD_MINIDUMP] = "mini", + [QCOM_DLOAD_BOTHDUMP] = "full,mini", }; static struct qcom_scm *__scm; @@ -1881,7 +1885,7 @@ static const struct kernel_param_ops download_mode_param_ops = { module_param_cb(download_mode, &download_mode_param_ops, NULL, 0644); MODULE_PARM_DESC(download_mode, - "download mode: off/full are acceptable values"); + "download mode: off/full/mini/full,mini are acceptable values"); static int qcom_scm_probe(struct platform_device *pdev) { From patchwork Fri Nov 24 22:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468184 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="WjnWMJYi" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03D7019A2; Fri, 24 Nov 2023 14:21:25 -0800 (PST) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOM0YCh003775; Fri, 24 Nov 2023 22:21:04 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-type; s=qcppdkim1; bh=OPFI7ax/YiheewXyZu3n4yb6vCIp6C7uRRT3BM+et/4=; b=WjnWMJYip3il96yHEDQygTeODznIvYBZuL6u7v1ASV4rJOVuhqCG7BeSd4NUHvgeYrU6 JNr+bkyFLbp2Phw0/l+g4sH+VrreXy7eF6sVxxKna4K2zTzKhO41vo13U15Aaa5DfO5o XnE5vxMNzd1hrdJpinR9zHENxtmOCZ7+IMbRDW2QOYN+eKL6qTHZd+EJzLJq5oeSTzyj /hADRfqrMjQ9wV5JLDcN6oKMbdaRX5tGGOyDkwyZY6NFTJ9qBAZyLyxBA/YCpLUzuKp0 F2WHG5yQZNJU6RFlhq48a7/9uSbkTxPrViXoJxrmkV7K2T+gehZMIq13bzA5CbnXwKIx PQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujwg50tpv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:03 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMKmEn017679 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:20:48 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; Fri, 24 Nov 2023 14:20:39 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 03/12] docs: qcom: Add qualcomm minidump guide Date: Sat, 25 Nov 2023 03:49:46 +0530 Message-ID: <1700864395-1479-4-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: HaCa0gJSpVeQQ-3wR3bJWVwXlPk5LgtY X-Proofpoint-ORIG-GUID: HaCa0gJSpVeQQ-3wR3bJWVwXlPk5LgtY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 phishscore=0 mlxscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 clxscore=1015 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Add the qualcomm minidump guide for the users which tries to cover the dependency, API use and the way to test and collect minidump on Qualcomm supported SoCs. Signed-off-by: Mukesh Ojha Reviewed-by: Bagas Sanjaya --- Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/qcom_minidump.rst | 272 ++++++++++++++++++++++++++++ 2 files changed, 273 insertions(+) create mode 100644 Documentation/admin-guide/qcom_minidump.rst diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guide/index.rst index 43ea35613dfc..251d070486c2 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -120,6 +120,7 @@ configure specific aspects of kernel behavior to your liking. perf-security pm/index pnp + qcom_minidump rapidio ras rtc diff --git a/Documentation/admin-guide/qcom_minidump.rst b/Documentation/admin-guide/qcom_minidump.rst new file mode 100644 index 000000000000..b492f2b79639 --- /dev/null +++ b/Documentation/admin-guide/qcom_minidump.rst @@ -0,0 +1,272 @@ +Qualcomm minidump feature +========================= + +Introduction +------------ + +Minidump is a best effort mechanism to collect useful and predefined +data for first level of debugging on end user devices running on +Qualcomm SoCs. It is built on the premise that System on Chip (SoC) +or subsystem part of SoC crashes, due to a range of hardware and +software bugs. Hence, the ability to collect accurate data is only +a best-effort. The data collected could be invalid or corrupted, data +collection itself could fail, and so on. + +Qualcomm devices in engineering mode provides a mechanism for generating +full system RAM dumps for post-mortem debugging. But in some cases it's +however not feasible to capture the entire content of RAM. The minidump +mechanism provides the means for selected region should be included in +the ramdump. + + +:: + + +-----------------------------------------------+ + | DDR +-------------+ | + | | SS0-ToC| | + | +----------------+ +----------------+ | | + | |Shared memory | | SS1-ToC| | | + | |(SMEM) | | | | | + | | | +-->|--------+ | | | + | |G-ToC | | | SS-ToC \ | | | + | |+-------------+ | | | +-----------+ | | | + | ||-------------| | | | |-----------| | | | + | || SS0-ToC | | | +-|<|SS1 region1| | | | + | ||-------------| | | | | |-----------| | | | + | || SS1-ToC |-|>+ | | |SS1 region2| | | | + | ||-------------| | | | |-----------| | | | + | || SS2-ToC | | | | | ... | | | | + | ||-------------| | | | |-----------| | | | + | || ... | | |-|<|SS1 regionN| | | | + | ||-------------| | | | |-----------| | | | + | || SSn-ToC | | | | +-----------+ | | | + | |+-------------+ | | | | | | + | | | | |----------------| | | + | | | +>| regionN | | | + | | | | |----------------| | | + | +----------------+ | | | | | + | | |----------------| | | + | +>| region1 | | | + | |----------------| | | + | | | | | + | |----------------|-+ | + | | region5 | | + | |----------------| | + | | | | + | Region information +----------------+ | + | +---------------+ | + | |region name | | + | |---------------| | + | |region address | | + | |---------------| | + | |region size | | + | +---------------+ | + +-----------------------------------------------+ + G-ToC: Global table of contents + SS-ToC: Subsystem table of contents + SS0-SSn: Subsystem numbered from 0 to n + +It depends on SoC where the underlying firmware is keeping the +minidump global table taking care of subsystem ToC part for +minidump like for above diagram, it is for shared memory sitting +in DDR and it is shared among various master however it is possible +that this could be implemented via memory mapped regions but the +general idea should remain same. Here, various subsystem could be +DSP's like ADSP/CDSP/MODEM etc, along with Application processor +(APSS) where Linux runs. DSP minidump gets collected when DSP's goes +for recovery followed by a crash. The minidump part of code for +that resides in ``qcom_rproc_minidump.c``. + + +SMEM as backend +---------------- + +In this document, SMEM will be used as the backend implementation +of minidump. + +The core of minidump feature is part of Qualcomm's boot firmware code. +It initializes shared memory (SMEM), which is a part of DDR and +allocates a small section of it to minidump table, i.e. also called +global table of contents (G-ToC). Each subsystem (APSS, ADSP, ...) has +its own table of segments to be included in the minidump, all +references from a descriptor in SMEM (G-ToC). Each segment/region has +some details like name, physical address and its size etc. and it +could be anywhere scattered in the DDR. + +Qualcomm APSS Minidump kernel driver concept +-------------------------------------------- + +Qualcomm APSS minidump kernel driver adds the capability to add Linux +region to be dumped as part of RAM dump collection. At the moment, +shared memory driver creates platform device for minidump driver and +give a means to APSS minidump to initialize itself on probe. + +This driver provides ``qcom_minidump_region_register`` and +``qcom_minidump_region_unregister`` API's to register and unregister +APSS minidump region. It also supports registration for the clients +who came before minidump driver was initialized. It maintains pending +list of clients who came before minidump and once minidump is initialized +it registers them in one go. + +To simplify post-mortem debugging, driver creates and maintain an ELF +header as first region that gets updated each time a new region gets +registered. + +The solution supports extracting the RAM dump/minidump produced either +over USB or stored to an attached storage device. + +Dependency of minidump kernel driver +------------------------------------ + +It is to note that whole of minidump depends on Qualcomm boot firmware +whether it supports minidump or not. So, if the minidump SMEM ID is +present in shared memory, it indicates that minidump is supported from +boot firmware and it is possible to dump Linux (APSS) region as part +of minidump collection. + +How a kernel client driver can register region with minidump +------------------------------------------------------------ + +Client driver can use ``qcom_minidump_region_register`` API's to register +and ``qcom_minidump_region_unregister`` to unregister their region from +minidump driver. + +Client needs to fill their region by filling ``qcom_minidump_region`` +structure object which consists of the region name, region's virtual +and physical address and its size. + +Below, is one sample client driver snippet which tries to allocate a +region from kernel heap of certain size and it writes a certain known +pattern (that can help in verification after collection that we got +the exact pattern, what we wrote) and registers it with minidump. + + .. code-block:: c + + #include + [...] + + + [... inside a function ...] + struct qcom_minidump_region region; + + [...] + + client_mem_region = kzalloc(region_size, GFP_KERNEL); + if (!client_mem_region) + return -ENOMEM; + + [... Just write a pattern ...] + memset(client_mem_region, 0xAB, region_size); + + [... Fill up the region object ...] + strlcpy(region.name, "REGION_A", sizeof(region.name)); + region.virt_addr = client_mem_region; + region.phys_addr = virt_to_phys(client_mem_region); + region.size = region_size; + + ret = qcom_minidump_region_register(®ion); + if (ret < 0) { + pr_err("failed to add region in minidump: err: %d\n", ret); + return ret; + } + + [...] + + +Test +---- + +Existing Qualcomm devices already supports entire RAM dump (also called +full dump) by writing appropriate value to Qualcomm's top control and +status register (tcsr) in ``driver/firmware/qcom_scm.c`` . + +SCM device Tree bindings required to support download mode +For example (sm8450) :: + + / { + + [...] + + firmware { + scm: scm { + compatible = "qcom,scm-sm8450", "qcom,scm"; + [... tcsr register ... ] + qcom,dload-mode = <&tcsr 0x13000>; + + [...] + }; + }; + + [...] + + soc: soc@0 { + + [...] + + tcsr: syscon@1fc0000 { + compatible = "qcom,sm8450-tcsr", "syscon"; + reg = <0x0 0x1fc0000 0x0 0x30000>; + }; + + [...] + }; + [...] + + }; + +User of minidump can pass ``qcom_scm.download_mode="mini"`` to kernel +commandline to set the current download mode to minidump. +Similarly, ``"full"`` is passed to set the download mode to full dump +where entire RAM dump will be collected while setting it ``"full,mini"`` +will collect minidump along with fulldump. + +Writing to sysfs node can also be used to set the mode to minidump:: + + echo "mini" > /sys/module/qcom_scm/parameter/download_mode + +Once the download mode is set, any kind of crash will make the device collect +respective dump as per set download mode. + +Dump collection +--------------- +:: + + +-----------+ + | | + | | +------+ + | | | | + | | +--+---+ Product(Qualcomm SoC) + +-----------+ | + |+++++++++++|<------------+ + |+++++++++++| usb cable + +-----------+ + x86_64 PC + +The solution supports a product running with Qualcomm SoC (where minidump) +is supported from the firmware) connected to x86_64 host PC running PCAT +tool. It supports downloading the minidump produced from product to the +host PC over USB or to save the minidump to the product attached storage +device(UFS/eMMC/SD Card) into minidump dedicated partition. + +By default, dumps are downloaded via USB to the attached x86_64 PC running +PCAT (Qualcomm tool) software. Upon download, we will see a set of binary +blobs starting with name ``md_*`` in PCAT configured directory in x86_64 +machine, so for above example from the client it will be ``md_REGION_A.BIN``. +This binary blob depends on region content to determine whether it needs +external parser support to get the content of the region, so for simple +plain ASCII text we don't need any parsing and the content can be seen +just opening the binary file. + +To collect the dump to attached storage type, one needs to write appropriate +value to IMEM register, in that case dumps are collected in rawdump +partition on the product device itself. + +One needs to read the entire rawdump partition and pull out content to +save it onto the attached x86_64 machine over USB. Later, this rawdump +can be passed to another tool (``dexter.exe`` [Qualcomm tool]) which +converts this into the similar binary blobs which we have got it when +download type was set to USB, i.e. a set of registered regions as blobs +and their name starts with ``md_*``. + +Replacing the ``dexter.exe`` with some open source tool can be added as future +scope of this document. From patchwork Fri Nov 24 22:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468182 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="GKgH/LS+" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5771701; Fri, 24 Nov 2023 14:21:24 -0800 (PST) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOKuX6L023751; Fri, 24 Nov 2023 22:21:02 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-type; s=qcppdkim1; bh=t2WwXfOWOi9RrET/0BpjLpGMo+ohDBXMjZaVwTzeEO0=; b=GKgH/LS+CjVtSgeNJuebv/ZfSph6KNuGDYmBZpOxXhWfvWdnxnSkVK6EqQsOoIjT0GP7 AZu7++8B7jM98f4cFcc1vF2d3LU4x+omEW0Bb+GwNhCJ/8D+/S4aAV6wV69W9DbPUKU+ 14obHEOn6ylLVFeXsm2XQe8Q73eNapjg5oM/4UsEALTxcurm4pxNnr6mcj8vsQV/PlM0 oXwYjb4S5/GYSvYCxgLmYaXg95HV/vUfus3np8zlihZWuxuhhU4liQHewPXFOzxPyior 2axMWm4EnXj+VQOb/mMk9BxYgZsZ2XNFTUZXUYwZA9Ow/x5H9S1WM5+q+nSYqpdkfvlO bA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujgqdtmr6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:01 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMKuK7010366 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:20:56 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; Fri, 24 Nov 2023 14:20:46 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 04/12] soc: qcom: Add qcom_rproc_minidump module Date: Sat, 25 Nov 2023 03:49:47 +0530 Message-ID: <1700864395-1479-5-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: J7lMzfPeK2Gys1CWc6VWpp1xOHFcZZWM X-Proofpoint-ORIG-GUID: J7lMzfPeK2Gys1CWc6VWpp1xOHFcZZWM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 suspectscore=0 malwarescore=0 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Add qcom_rproc_minidump module in a preparation to remove minidump specific code from driver/remoteproc/qcom_common.c and provide needed exported API, this as well helps to abstract minidump specific data layout from qualcomm's remoteproc driver. It is just a copying of qcom_minidump() functionality from driver/remoteproc/qcom_common.c into a separate file under qcom_rproc_minidump(). Signed-off-by: Mukesh Ojha --- drivers/soc/qcom/Kconfig | 10 +++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/qcom_minidump_internal.h | 64 +++++++++++++++++ drivers/soc/qcom/qcom_rproc_minidump.c | 111 ++++++++++++++++++++++++++++++ include/soc/qcom/qcom_minidump.h | 23 +++++++ 5 files changed, 209 insertions(+) create mode 100644 drivers/soc/qcom/qcom_minidump_internal.h create mode 100644 drivers/soc/qcom/qcom_rproc_minidump.c create mode 100644 include/soc/qcom/qcom_minidump.h diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index b3634e10f6f5..e507a317c74f 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -254,4 +254,14 @@ config QCOM_INLINE_CRYPTO_ENGINE tristate select QCOM_SCM +config QCOM_RPROC_MINIDUMP + tristate "QCOM Remoteproc Minidump Support" + depends on ARCH_QCOM || COMPILE_TEST + depends on QCOM_SMEM + help + Enablement of core minidump feature is controlled from boot firmware + side, so if it is enabled from firmware, this config allow linux to + query predefined minidump segments associated with the remote processor + and check its validity and end up collecting the dump on remote processor + crash during its recovery. endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index bbca2e1e55bb..838528e7e30a 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -32,3 +32,4 @@ obj-$(CONFIG_QCOM_KRYO_L2_ACCESSORS) += kryo-l2-accessors.o obj-$(CONFIG_QCOM_ICC_BWMON) += icc-bwmon.o qcom_ice-objs += ice.o obj-$(CONFIG_QCOM_INLINE_CRYPTO_ENGINE) += qcom_ice.o +obj-$(CONFIG_QCOM_RPROC_MINIDUMP) += qcom_rproc_minidump.o diff --git a/drivers/soc/qcom/qcom_minidump_internal.h b/drivers/soc/qcom/qcom_minidump_internal.h new file mode 100644 index 000000000000..71709235b196 --- /dev/null +++ b/drivers/soc/qcom/qcom_minidump_internal.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _QCOM_MINIDUMP_INTERNAL_H_ +#define _QCOM_MINIDUMP_INTERNAL_H_ + +#define MAX_NUM_OF_SS 10 +#define MAX_REGION_NAME_LENGTH 16 +#define SBL_MINIDUMP_SMEM_ID 602 +#define MINIDUMP_REGION_VALID ('V' << 24 | 'A' << 16 | 'L' << 8 | 'I' << 0) +#define MINIDUMP_SS_ENCR_DONE ('D' << 24 | 'O' << 16 | 'N' << 8 | 'E' << 0) +#define MINIDUMP_SS_ENABLED ('E' << 24 | 'N' << 16 | 'B' << 8 | 'L' << 0) + +/** + * struct minidump_region - Minidump region + * @name : Name of the region to be dumped + * @seq_num: : Use to differentiate regions with same name. + * @valid : This entry to be dumped (if set to 1) + * @address : Physical address of region to be dumped + * @size : Size of the region + */ +struct minidump_region { + char name[MAX_REGION_NAME_LENGTH]; + __le32 seq_num; + __le32 valid; + __le64 address; + __le64 size; +}; + +/** + * struct minidump_subsystem - Subsystem's SMEM Table of content + * @status : Subsystem toc init status + * @enabled : if set to 1, this region would be copied during coredump + * @encryption_status: Encryption status for this subsystem + * @encryption_required : Decides to encrypt the subsystem regions or not + * @region_count : Number of regions added in this subsystem toc + * @regions_baseptr : regions base pointer of the subsystem + */ +struct minidump_subsystem { + __le32 status; + __le32 enabled; + __le32 encryption_status; + __le32 encryption_required; + __le32 region_count; + __le64 regions_baseptr; +}; + +/** + * struct minidump_global_toc - Global Table of Content + * @status : Global Minidump init status + * @md_revision : Minidump revision + * @enabled : Minidump enable status + * @subsystems : Array of subsystems toc + */ +struct minidump_global_toc { + __le32 status; + __le32 md_revision; + __le32 enabled; + struct minidump_subsystem subsystems[MAX_NUM_OF_SS]; +}; + +#endif /* _QCOM_MINIDUMP_INTERNAL_H_ */ diff --git a/drivers/soc/qcom/qcom_rproc_minidump.c b/drivers/soc/qcom/qcom_rproc_minidump.c new file mode 100644 index 000000000000..9bc84cc2536f --- /dev/null +++ b/drivers/soc/qcom/qcom_rproc_minidump.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "qcom_minidump_internal.h" + +static void qcom_minidump_cleanup(struct rproc *rproc) +{ + struct rproc_dump_segment *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &rproc->dump_segments, node) { + list_del(&entry->node); + kfree(entry->priv); + kfree(entry); + } +} + +static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump_subsystem *subsystem, + void (*rproc_dumpfn_t)(struct rproc *rproc, struct rproc_dump_segment *segment, + void *dest, size_t offset, size_t size)) +{ + struct minidump_region __iomem *ptr; + struct minidump_region region; + int seg_cnt, i; + dma_addr_t da; + size_t size; + char *name; + + if (WARN_ON(!list_empty(&rproc->dump_segments))) { + dev_err(&rproc->dev, "dump segment list already populated\n"); + return -EUCLEAN; + } + + seg_cnt = le32_to_cpu(subsystem->region_count); + ptr = ioremap((unsigned long)le64_to_cpu(subsystem->regions_baseptr), + seg_cnt * sizeof(struct minidump_region)); + if (!ptr) + return -EFAULT; + + for (i = 0; i < seg_cnt; i++) { + memcpy_fromio(®ion, ptr + i, sizeof(region)); + if (le32_to_cpu(region.valid) == MINIDUMP_REGION_VALID) { + name = kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL); + if (!name) { + iounmap(ptr); + return -ENOMEM; + } + da = le64_to_cpu(region.address); + size = le64_to_cpu(region.size); + rproc_coredump_add_custom_segment(rproc, da, size, rproc_dumpfn_t, name); + } + } + + iounmap(ptr); + return 0; +} + +void qcom_rproc_minidump(struct rproc *rproc, unsigned int minidump_id, + void (*rproc_dumpfn_t)(struct rproc *rproc, + struct rproc_dump_segment *segment, void *dest, size_t offset, + size_t size)) +{ + int ret; + struct minidump_subsystem *subsystem; + struct minidump_global_toc *toc; + + /* Get Global minidump ToC*/ + toc = qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, NULL); + + /* check if global table pointer exists and init is set */ + if (IS_ERR(toc) || !toc->status) { + dev_err(&rproc->dev, "Minidump TOC not found in SMEM\n"); + return; + } + + /* Get subsystem table of contents using the minidump id */ + subsystem = &toc->subsystems[minidump_id]; + + /** + * Collect minidump if SS ToC is valid and segment table + * is initialized in memory and encryption status is set. + */ + if (subsystem->regions_baseptr == 0 || + le32_to_cpu(subsystem->status) != 1 || + le32_to_cpu(subsystem->enabled) != MINIDUMP_SS_ENABLED || + le32_to_cpu(subsystem->encryption_status) != MINIDUMP_SS_ENCR_DONE) { + dev_err(&rproc->dev, "Minidump not ready, skipping\n"); + return; + } + + ret = qcom_add_minidump_segments(rproc, subsystem, rproc_dumpfn_t); + if (ret) { + dev_err(&rproc->dev, "Failed with error: %d while adding minidump entries\n", ret); + goto clean_minidump; + } + rproc_coredump_using_sections(rproc); +clean_minidump: + qcom_minidump_cleanup(rproc); +} +EXPORT_SYMBOL_GPL(qcom_rproc_minidump); + +MODULE_DESCRIPTION("Qualcomm remoteproc minidump(smem) helper module"); +MODULE_LICENSE("GPL"); diff --git a/include/soc/qcom/qcom_minidump.h b/include/soc/qcom/qcom_minidump.h new file mode 100644 index 000000000000..cd87caef919d --- /dev/null +++ b/include/soc/qcom/qcom_minidump.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _QCOM_MINIDUMP_H_ +#define _QCOM_MINIDUMP_H_ + +struct rproc; +struct rproc_dump_segment; + +#if IS_ENABLED(CONFIG_QCOM_RPROC_MINIDUMP) +void qcom_rproc_minidump(struct rproc *rproc, unsigned int minidump_id, + void (*rproc_dumpfn_t)(struct rproc *rproc, + struct rproc_dump_segment *segment, void *dest, size_t offset, + size_t size)); +#else +static inline void qcom_rproc_minidump(struct rproc *rproc, unsigned int minidump_id, + void (*rproc_dumpfn_t)(struct rproc *rproc, + struct rproc_dump_segment *segment, void *dest, size_t offset, + size_t size)) { } +#endif /* CONFIG_QCOM_RPROC_MINIDUMP */ +#endif /* _QCOM_MINIDUMP_H_ */ From patchwork Fri Nov 24 22:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468185 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Db+OXBw/" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03145198D; Fri, 24 Nov 2023 14:21:30 -0800 (PST) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOLHrl9014972; Fri, 24 Nov 2023 22:21:06 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-type; s=qcppdkim1; bh=618pEiTrNfBVqKTnWpLsCzc77uSsX+fq1jAKbYWC2JM=; b=Db+OXBw/IwAa5+O9bUdjguCJ628mkF+Hp0bl1ew5xLyHRvPqlKFnp1noi6vOUbwrVryA eP/MrjbwhP5N2Vw7Kd5HR5QlKvMP94t99xVQ6eotRcLlmar3YESx40K/fptPb5MJV6Ev lvhanQ/7kTS0lANiN+OByki1zfscJN49TAiSaIFi9RkVD4wQYCrOBOEH7pJpZBI2ROyJ y/FalSjmMbDyvoTNYAFTF/PWBa0I2vEY9IXYipn4rjLpvCQUM383t6sotJP7uSnrJ/O6 ZtHL3uwnH1L/FtEdLPYbm7g8SwugTMQexCeDrjS2QQ5wULfHyN2/d8J85VbyShmObnWs Jg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uj6emuseq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:06 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOML5SC017917 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:05 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; Fri, 24 Nov 2023 14:20:53 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 05/12] remoteproc: qcom_q6v5_pas: Use qcom_rproc_minidump() Date: Sat, 25 Nov 2023 03:49:48 +0530 Message-ID: <1700864395-1479-6-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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-ORIG-GUID: YPRs0icNZHe-KK-5-JSfE-tGZTVJvqOL X-Proofpoint-GUID: YPRs0icNZHe-KK-5-JSfE-tGZTVJvqOL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Now, as all the minidump specific data structure is moved to minidump specific files and implementation wise qcom_rproc_minidump() and qcom_minidump() exactly same and the name qcom_rproc_minidump make more sense as it happen to collect the minidump for the remoteproc processors. So, let's use qcom_rproc_minidump() and we will be removing qcom_minidump() and minidump related stuff from driver/remoteproc/qcom_common.c . Signed-off-by: Mukesh Ojha --- drivers/remoteproc/Kconfig | 1 + drivers/remoteproc/qcom_q6v5_pas.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index 48845dc8fa85..cea960749e2c 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -166,6 +166,7 @@ config QCOM_PIL_INFO config QCOM_RPROC_COMMON tristate + select QCOM_RPROC_MINIDUMP config QCOM_Q6V5_COMMON tristate diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c index 913a5d2068e8..a39fa75a7162 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "qcom_common.h" #include "qcom_pil_info.h" @@ -131,7 +132,7 @@ static void adsp_minidump(struct rproc *rproc) if (rproc->dump_conf == RPROC_COREDUMP_DISABLED) return; - qcom_minidump(rproc, adsp->minidump_id, adsp_segment_dump); + qcom_rproc_minidump(rproc, adsp->minidump_id, adsp_segment_dump); } static int adsp_pds_enable(struct qcom_adsp *adsp, struct device **pds, From patchwork Fri Nov 24 22:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468187 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="OzadvKig" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C93F2107; Fri, 24 Nov 2023 14:21:47 -0800 (PST) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOLp9AP010915; Fri, 24 Nov 2023 22:21:12 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-type; s=qcppdkim1; bh=t03UP7q891F/c5g/2wfXb+TlibZKK7FwWRcbw5U5eKA=; b=OzadvKigJiWiSWlpBs+Zkiid2SpZ4d7HlG0hI25ZCxk96uPXh8+GGUQyifjeLugBxDjS 8UJcZZ8N/B1XnrhWNsqRcOf11lawkr3bAAwV9S0ZgAqtkqDXxg6yoSRBvZxz5Q76Oxet U/F1hAFYq0OAq8fI6MCGNT2UFOd1U44Oq3zDOfMdLwZTW5wwagRgZ6YYvf0NzhppE1zc xU/Ra+o4UPGJjWPTvs1sqDl3lH+jvbKU3HmQpmxzELgUAI4Or9q3PgNI2FCrKZVmTobz WXso1KeMK+8pmM+QLQWkJ6i7YxxY5SK+WW6bN1uWJ/wfjDqxvVnKY44e/eXErciAGYeT qg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujp8x26a6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:11 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMLATp018389 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:10 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; Fri, 24 Nov 2023 14:21:01 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 06/12] remoteproc: qcom: Remove minidump related data from qcom_common.c Date: Sat, 25 Nov 2023 03:49:49 +0530 Message-ID: <1700864395-1479-7-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: TVMGgRRF0lh8OLHdHvgqlX0Zu3GzhCGh X-Proofpoint-ORIG-GUID: TVMGgRRF0lh8OLHdHvgqlX0Zu3GzhCGh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 mlxlogscore=999 clxscore=1015 spamscore=0 lowpriorityscore=0 impostorscore=0 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 As minidump specific data structure and functions move under config QCOM_RPROC_MINIDUMP, so remove minidump specific data from driver/remoteproc/qcom_common.c . Signed-off-by: Mukesh Ojha --- drivers/remoteproc/qcom_common.c | 160 --------------------------------------- 1 file changed, 160 deletions(-) diff --git a/drivers/remoteproc/qcom_common.c b/drivers/remoteproc/qcom_common.c index 03e5f5d533eb..085fd73fa23a 100644 --- a/drivers/remoteproc/qcom_common.c +++ b/drivers/remoteproc/qcom_common.c @@ -17,7 +17,6 @@ #include #include #include -#include #include "remoteproc_internal.h" #include "qcom_common.h" @@ -26,61 +25,6 @@ #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev) #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev) -#define MAX_NUM_OF_SS 10 -#define MAX_REGION_NAME_LENGTH 16 -#define SBL_MINIDUMP_SMEM_ID 602 -#define MINIDUMP_REGION_VALID ('V' << 24 | 'A' << 16 | 'L' << 8 | 'I' << 0) -#define MINIDUMP_SS_ENCR_DONE ('D' << 24 | 'O' << 16 | 'N' << 8 | 'E' << 0) -#define MINIDUMP_SS_ENABLED ('E' << 24 | 'N' << 16 | 'B' << 8 | 'L' << 0) - -/** - * struct minidump_region - Minidump region - * @name : Name of the region to be dumped - * @seq_num: : Use to differentiate regions with same name. - * @valid : This entry to be dumped (if set to 1) - * @address : Physical address of region to be dumped - * @size : Size of the region - */ -struct minidump_region { - char name[MAX_REGION_NAME_LENGTH]; - __le32 seq_num; - __le32 valid; - __le64 address; - __le64 size; -}; - -/** - * struct minidump_subsystem - Subsystem's SMEM Table of content - * @status : Subsystem toc init status - * @enabled : if set to 1, this region would be copied during coredump - * @encryption_status: Encryption status for this subsystem - * @encryption_required : Decides to encrypt the subsystem regions or not - * @region_count : Number of regions added in this subsystem toc - * @regions_baseptr : regions base pointer of the subsystem - */ -struct minidump_subsystem { - __le32 status; - __le32 enabled; - __le32 encryption_status; - __le32 encryption_required; - __le32 region_count; - __le64 regions_baseptr; -}; - -/** - * struct minidump_global_toc - Global Table of Content - * @status : Global Minidump init status - * @md_revision : Minidump revision - * @enabled : Minidump enable status - * @subsystems : Array of subsystems toc - */ -struct minidump_global_toc { - __le32 status; - __le32 md_revision; - __le32 enabled; - struct minidump_subsystem subsystems[MAX_NUM_OF_SS]; -}; - struct qcom_ssr_subsystem { const char *name; struct srcu_notifier_head notifier_list; @@ -90,110 +34,6 @@ struct qcom_ssr_subsystem { static LIST_HEAD(qcom_ssr_subsystem_list); static DEFINE_MUTEX(qcom_ssr_subsys_lock); -static void qcom_minidump_cleanup(struct rproc *rproc) -{ - struct rproc_dump_segment *entry, *tmp; - - list_for_each_entry_safe(entry, tmp, &rproc->dump_segments, node) { - list_del(&entry->node); - kfree(entry->priv); - kfree(entry); - } -} - -static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump_subsystem *subsystem, - void (*rproc_dumpfn_t)(struct rproc *rproc, struct rproc_dump_segment *segment, - void *dest, size_t offset, size_t size)) -{ - struct minidump_region __iomem *ptr; - struct minidump_region region; - int seg_cnt, i; - dma_addr_t da; - size_t size; - char *name; - - if (WARN_ON(!list_empty(&rproc->dump_segments))) { - dev_err(&rproc->dev, "dump segment list already populated\n"); - return -EUCLEAN; - } - - seg_cnt = le32_to_cpu(subsystem->region_count); - ptr = ioremap((unsigned long)le64_to_cpu(subsystem->regions_baseptr), - seg_cnt * sizeof(struct minidump_region)); - if (!ptr) - return -EFAULT; - - for (i = 0; i < seg_cnt; i++) { - memcpy_fromio(®ion, ptr + i, sizeof(region)); - if (le32_to_cpu(region.valid) == MINIDUMP_REGION_VALID) { - name = kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL); - if (!name) { - iounmap(ptr); - return -ENOMEM; - } - da = le64_to_cpu(region.address); - size = le64_to_cpu(region.size); - rproc_coredump_add_custom_segment(rproc, da, size, rproc_dumpfn_t, name); - } - } - - iounmap(ptr); - return 0; -} - -void qcom_minidump(struct rproc *rproc, unsigned int minidump_id, - void (*rproc_dumpfn_t)(struct rproc *rproc, - struct rproc_dump_segment *segment, void *dest, size_t offset, - size_t size)) -{ - int ret; - struct minidump_subsystem *subsystem; - struct minidump_global_toc *toc; - - /* Get Global minidump ToC*/ - toc = qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, NULL); - - /* check if global table pointer exists and init is set */ - if (IS_ERR(toc) || !toc->status) { - dev_err(&rproc->dev, "Minidump TOC not found in SMEM\n"); - return; - } - - /* Get subsystem table of contents using the minidump id */ - subsystem = &toc->subsystems[minidump_id]; - - /** - * Collect minidump if SS ToC is valid and segment table - * is initialized in memory and encryption status is set. - */ - if (subsystem->regions_baseptr == 0 || - le32_to_cpu(subsystem->status) != 1 || - le32_to_cpu(subsystem->enabled) != MINIDUMP_SS_ENABLED) { - return rproc_coredump(rproc); - } - - if (le32_to_cpu(subsystem->encryption_status) != MINIDUMP_SS_ENCR_DONE) { - dev_err(&rproc->dev, "Minidump not ready, skipping\n"); - return; - } - - /** - * Clear out the dump segments populated by parse_fw before - * re-populating them with minidump segments. - */ - rproc_coredump_cleanup(rproc); - - ret = qcom_add_minidump_segments(rproc, subsystem, rproc_dumpfn_t); - if (ret) { - dev_err(&rproc->dev, "Failed with error: %d while adding minidump entries\n", ret); - goto clean_minidump; - } - rproc_coredump_using_sections(rproc); -clean_minidump: - qcom_minidump_cleanup(rproc); -} -EXPORT_SYMBOL_GPL(qcom_minidump); - static int glink_subdev_start(struct rproc_subdev *subdev) { struct qcom_rproc_glink *glink = to_glink_subdev(subdev); From patchwork Fri Nov 24 22:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468186 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="AL8DMv0B" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 493A81FF7; Fri, 24 Nov 2023 14:21:46 -0800 (PST) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOMLIQt003380; Fri, 24 Nov 2023 22:21:18 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-type; s=qcppdkim1; bh=K2A4dtZlUtyZnmNAqQaXcmpJGNAhsKiXHCEqZlAWciU=; b=AL8DMv0BxGjWvN0etm9NtA7uzgBmTN9FJnUm/ywRxhVBQMnD9XGOzppTVBxyWEFAzwc3 5bUZ9LnVfMSmrl9I4Jfj7F3bMja4quX4mh8/C2tiZ2Zn5Hk/bpAxkdHaiPs/r42KzfZx 3O72mlbZvLzi11vKH49G8wOIMrmbHRtG6i8hKp8zys03hk3cP11n5xAMwn8Kocq/lDb/ gwFjKpvXUkqfm+Wna7aOYna6Sv+abNUekQewkJwB3eXAXG3mBnSs/sH8mQfn2th9ZzGi c8034ECKj5qKgryek+/aJ8NGnCFaxqNAPmSFCvitUn5Eliut2jCOcS7h/i3awZ96g1F9 fw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujp8x26a9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:18 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMLH4a016251 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:17 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; Fri, 24 Nov 2023 14:21:08 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 07/12] init: export linux_banner data variable Date: Sat, 25 Nov 2023 03:49:50 +0530 Message-ID: <1700864395-1479-8-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: ULQRcOi6Lxq-hgJwtJiWVaEoqEBtblCH X-Proofpoint-ORIG-GUID: ULQRcOi6Lxq-hgJwtJiWVaEoqEBtblCH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 mlxlogscore=999 clxscore=1015 spamscore=0 lowpriorityscore=0 impostorscore=0 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Some debug loadable module like minidump is interested in knowing the kernel version against which it is being build. Let's export linux_banner. Signed-off-by: Mukesh Ojha --- include/linux/init.h | 3 +++ init/version-timestamp.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/linux/init.h b/include/linux/init.h index 01b52c9c7526..01a28b367841 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -145,6 +145,9 @@ extern char *saved_command_line; extern unsigned int saved_command_line_len; extern unsigned int reset_devices; +/* Defined in init/version-timestamp.c */ +extern const char linux_banner[]; + /* used by init/main.c */ void setup_arch(char **); void prepare_namespace(void); diff --git a/init/version-timestamp.c b/init/version-timestamp.c index 043cbf80a766..a48f2c19e5d7 100644 --- a/init/version-timestamp.c +++ b/init/version-timestamp.c @@ -6,6 +6,7 @@ #include #include #include +#include struct uts_namespace init_uts_ns = { .ns.count = REFCOUNT_INIT(2), @@ -28,3 +29,5 @@ struct uts_namespace init_uts_ns = { const char linux_banner[] = "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n"; + +EXPORT_SYMBOL_GPL(linux_banner); From patchwork Fri Nov 24 22:19:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468213 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="G+3r5MeD" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63EC31BD8; Fri, 24 Nov 2023 14:21:51 -0800 (PST) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOM0bs5026925; Fri, 24 Nov 2023 22:21:26 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-type; s=qcppdkim1; bh=Ni8mPx/bBIsnmkKB9Zvh8ADCg/wTob8Ml3va5e8yT34=; b=G+3r5MeDS/52iSkEcQjS2ihIj0T7uwWLTe3FF0y/T3x4moMJAM4r1Qd3QQBo1Oduggw/ JdGj6FK0DeFRnCjGh82sYaEUZ73oZHJx8jFBMDLWZ9Q8B+PD6XJJYVSPYl0PGWsM8NkZ KCtDxDEhM9/+cfz7FwbDM8kK2oNTL1Iya5yUS9YjBAf+P9VJcqWAdJqwdlWXbBZJT7Kp ybtEin5506NZycJqhzPuN4X/BK3vP0N0op0XBY8asyBAw/TOWpxVTyL1Fj9Rw5EXjYKD 6UioEUlQBYmrmPNpoD0XE35TKBX2llhvLmKKPb6dMsdTbWeLnp0LmiWq/OyC3XqTMDJl Qg== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujp8x26ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:25 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMLPrw004071 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:25 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; Fri, 24 Nov 2023 14:21:15 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 08/12] soc: qcom: Add Qualcomm APSS minidump kernel driver Date: Sat, 25 Nov 2023 03:49:51 +0530 Message-ID: <1700864395-1479-9-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: y5gupyU-c15rHZ7pluY2FcXODXG50dMK X-Proofpoint-ORIG-GUID: y5gupyU-c15rHZ7pluY2FcXODXG50dMK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 mlxlogscore=999 clxscore=1015 spamscore=0 lowpriorityscore=0 impostorscore=0 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Minidump is a best effort mechanism to collect useful and predefined data for first level of debugging on end user devices running on Qualcomm SoCs. It is built on the premise that System on Chip (SoC) or subsystem part of SoC crashes, due to a range of hardware and software bugs. Hence, the ability to collect accurate data is only a best-effort. The data collected could be invalid or corrupted, data collection itself could fail, and so on. Qualcomm devices in engineering mode provides a mechanism for generating full system ramdumps for post mortem debugging. But in some cases it's however not feasible to capture the entire content of RAM. The minidump mechanism provides the means for selecting region should be included in the ramdump. The solution supports extracting the ramdump/minidump produced either over USB or stored to an attached storage device. The core of minidump feature is part of Qualcomm's boot firmware code. It initializes shared memory (SMEM), which is a part of DDR and allocates a small section of it to minidump table i.e also called global table of content (G-ToC). Each subsystem (APSS, ADSP, ...) has their own table of segments to be included in the minidump, all references from a descriptor in SMEM (G-ToC). Each segment/region has some details like name, physical address and it's size etc. and it could be anywhere scattered in the DDR. qcom_minidump(core or frontend) driver adds the capability to add inux region to be dumped as part of ram dump collection. It provides appropriate symbol to register/unregister client regions. To simplify post mortem debugging, it creates and maintain an ELF header as first region that gets updated upon registration of a new region. Signed-off-by: Mukesh Ojha --- drivers/soc/qcom/Kconfig | 13 + drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/qcom_minidump.c | 606 ++++++++++++++++++++++++++++++ drivers/soc/qcom/qcom_minidump_internal.h | 10 + drivers/soc/qcom/smem.c | 20 + include/linux/soc/qcom/smem.h | 2 + include/soc/qcom/qcom_minidump.h | 18 + 7 files changed, 670 insertions(+) create mode 100644 drivers/soc/qcom/qcom_minidump.c diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index e507a317c74f..984623c0c1a0 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -264,4 +264,17 @@ config QCOM_RPROC_MINIDUMP query predefined minidump segments associated with the remote processor and check its validity and end up collecting the dump on remote processor crash during its recovery. + +config QCOM_MINIDUMP + tristate "QCOM APSS Minidump driver" + depends on ARCH_QCOM || COMPILE_TEST + depends on QCOM_SMEM + help + This config enables linux core infrastructure for Application + processor subsystem (APSS) minidump collection i.e, it enables + Linux clients drivers to register their internal data structures + and debug messages as part of the apss minidump table and when + the SoC is crashed, these selective regions will be dumped + instead of the entire DDR dump. This saves significant amount + of time and/or storage space. endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 838528e7e30a..4b5f72f78d3c 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -33,3 +33,4 @@ obj-$(CONFIG_QCOM_ICC_BWMON) += icc-bwmon.o qcom_ice-objs += ice.o obj-$(CONFIG_QCOM_INLINE_CRYPTO_ENGINE) += qcom_ice.o obj-$(CONFIG_QCOM_RPROC_MINIDUMP) += qcom_rproc_minidump.o +obj-$(CONFIG_QCOM_MINIDUMP) += qcom_minidump.o diff --git a/drivers/soc/qcom/qcom_minidump.c b/drivers/soc/qcom/qcom_minidump.c new file mode 100644 index 000000000000..c0f76a51d0e8 --- /dev/null +++ b/drivers/soc/qcom/qcom_minidump.c @@ -0,0 +1,606 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qcom_minidump_internal.h" + +/** + * struct minidump_ss_data - Minidump subsystem private data + * @md_ss_toc: Application Subsystem TOC pointer + * @md_regions: Application Subsystem region base pointer + */ +struct minidump_ss_data { + struct minidump_subsystem *md_ss_toc; + struct minidump_region *md_regions; +}; + +/** + * struct minidump_elfhdr - Minidump table elf header + * @ehdr: elf main header + * @shdr: Section header + * @phdr: Program header + * @elf_offset: Section offset in elf + * @strtable_idx: String table current index position + */ +struct minidump_elfhdr { + struct elfhdr *ehdr; + struct elf_shdr *shdr; + struct elf_phdr *phdr; + size_t elf_offset; + size_t strtable_idx; +}; + +/** + * struct minidump - Minidump driver data information + * @elf: Minidump elf header + * @dev: Minidump backend device + * @apss_data: APSS driver data + * @md_lock: Lock to protect access to APSS minidump table + */ +struct minidump { + struct minidump_elfhdr elf; + struct device *dev; + struct minidump_ss_data *apss_data; + struct mutex md_lock; +}; + +/* + * In some of the Old Qualcomm devices, boot firmware statically allocates 300 + * as total number of supported region (including all co-processors) in + * minidump table out of which linux was using 201. In future, this limitation + * from boot firmware might get removed by allocating the region dynamically. + * So, keep it compatible with older devices, we can keep the current limit for + * Linux to 201. + */ +#define MAX_NUM_ENTRIES 201 +#define MAX_STRTBL_SIZE (MAX_NUM_ENTRIES * MAX_REGION_NAME_LENGTH) + +static struct elf_shdr *elf_shdr_entry_addr(struct elfhdr *ehdr, int idx) +{ + struct elf_shdr *eshdr = (struct elf_shdr *)((size_t)ehdr + ehdr->e_shoff); + + return &eshdr[idx]; +} + +static struct elf_phdr *elf_phdr_entry_addr(struct elfhdr *ehdr, int idx) +{ + struct elf_phdr *ephdr = (struct elf_phdr *)((size_t)ehdr + ehdr->e_phoff); + + return &ephdr[idx]; +} + +static char *elf_str_table_start(struct elfhdr *ehdr) +{ + struct elf_shdr *eshdr; + + if (ehdr->e_shstrndx == SHN_UNDEF) + return NULL; + + eshdr = elf_shdr_entry_addr(ehdr, ehdr->e_shstrndx); + + return (char *)ehdr + eshdr->sh_offset; +} + +static char *elf_lookup_string(struct minidump *md, struct elfhdr *ehdr, int offset) +{ + char *strtab = elf_str_table_start(ehdr); + + if (!strtab || (md->elf.strtable_idx < offset)) + return NULL; + + return strtab + offset; +} + +static unsigned int append_str_to_strtable(struct minidump *md, const char *name) +{ + char *strtab = elf_str_table_start(md->elf.ehdr); + unsigned int old_idx = md->elf.strtable_idx; + unsigned int ret; + + if (!strtab || !name) + return 0; + + ret = old_idx; + old_idx += strscpy((strtab + old_idx), name, MAX_REGION_NAME_LENGTH); + md->elf.strtable_idx = old_idx + 1; + + return ret; +} + +static int qcom_md_clear_elfheader(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct elfhdr *ehdr = md->elf.ehdr; + struct elf_shdr *shdr; + struct elf_shdr *tmp_shdr; + struct elf_phdr *phdr; + struct elf_phdr *tmp_phdr; + unsigned int phidx; + unsigned int shidx; + unsigned int len; + unsigned int i; + char *shname; + + for (i = 0; i < ehdr->e_phnum; i++) { + phdr = elf_phdr_entry_addr(ehdr, i); + if (phdr->p_paddr == region->phys_addr && + phdr->p_memsz == region->size) + break; + } + + if (i == ehdr->e_phnum) { + dev_err(md->dev, "Cannot find program header entry in elf\n"); + return -EINVAL; + } + + phidx = i; + for (i = 0; i < ehdr->e_shnum; i++) { + shdr = elf_shdr_entry_addr(ehdr, i); + shname = elf_lookup_string(md, ehdr, shdr->sh_name); + if (shname && !strcmp(shname, region->name) && + shdr->sh_addr == (elf_addr_t)region->virt_addr && + shdr->sh_size == region->size) + break; + } + + if (i == ehdr->e_shnum) { + dev_err(md->dev, "Cannot find section header entry in elf\n"); + return -EINVAL; + } + + shidx = i; + if (shdr->sh_offset != phdr->p_offset) { + dev_err(md->dev, "Invalid entry details for region: %s\n", region->name); + return -EINVAL; + } + + /* Clear name in string table */ + len = strlen(shname) + 1; + memmove(shname, shname + len, md->elf.strtable_idx - shdr->sh_name - len); + md->elf.strtable_idx -= len; + + /* Clear program header */ + tmp_phdr = elf_phdr_entry_addr(ehdr, phidx); + for (i = phidx; i < ehdr->e_phnum - 1; i++) { + tmp_phdr = elf_phdr_entry_addr(ehdr, i + 1); + phdr = elf_phdr_entry_addr(ehdr, i); + memcpy(phdr, tmp_phdr, sizeof(*phdr)); + phdr->p_offset = phdr->p_offset - region->size; + } + memset(tmp_phdr, 0, sizeof(*tmp_phdr)); + ehdr->e_phnum--; + + /* Clear section header */ + tmp_shdr = elf_shdr_entry_addr(ehdr, shidx); + for (i = shidx; i < ehdr->e_shnum - 1; i++) { + tmp_shdr = elf_shdr_entry_addr(ehdr, i + 1); + shdr = elf_shdr_entry_addr(ehdr, i); + memcpy(shdr, tmp_shdr, sizeof(*shdr)); + shdr->sh_offset -= region->size; + shdr->sh_name -= len; + } + + memset(tmp_shdr, 0, sizeof(*tmp_shdr)); + ehdr->e_shnum--; + md->elf.elf_offset -= region->size; + + return 0; +} + +static void qcom_md_update_elfheader(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct elfhdr *ehdr = md->elf.ehdr; + struct elf_shdr *shdr; + struct elf_phdr *phdr; + + shdr = elf_shdr_entry_addr(ehdr, ehdr->e_shnum++); + phdr = elf_phdr_entry_addr(ehdr, ehdr->e_phnum++); + + shdr->sh_type = SHT_PROGBITS; + shdr->sh_name = append_str_to_strtable(md, region->name); + shdr->sh_addr = (elf_addr_t)region->virt_addr; + shdr->sh_size = region->size; + shdr->sh_flags = SHF_WRITE; + shdr->sh_offset = md->elf.elf_offset; + shdr->sh_entsize = 0; + + phdr->p_type = PT_LOAD; + phdr->p_offset = md->elf.elf_offset; + phdr->p_vaddr = (elf_addr_t)region->virt_addr; + phdr->p_paddr = region->phys_addr; + phdr->p_filesz = phdr->p_memsz = region->size; + phdr->p_flags = PF_R | PF_W; + md->elf.elf_offset += shdr->sh_size; +} + +static void qcom_md_add_region(struct minidump_ss_data *mdss_data, + const struct qcom_minidump_region *region) +{ + struct minidump_subsystem *mdss_toc = mdss_data->md_ss_toc; + struct minidump_region *mdr; + unsigned int region_cnt; + + region_cnt = le32_to_cpu(mdss_toc->region_count); + mdr = &mdss_data->md_regions[region_cnt]; + strscpy(mdr->name, region->name, sizeof(mdr->name)); + mdr->address = cpu_to_le64(region->phys_addr); + mdr->size = cpu_to_le64(region->size); + mdr->valid = cpu_to_le32(MINIDUMP_REGION_VALID); + region_cnt++; + mdss_toc->region_count = cpu_to_le32(region_cnt); +} + +static int qcom_md_get_region_index(struct minidump_ss_data *mdss_data, + const struct qcom_minidump_region *region) +{ + struct minidump_subsystem *mdss_toc = mdss_data->md_ss_toc; + struct minidump_region *mdr; + unsigned int i; + unsigned int count; + + count = le32_to_cpu(mdss_toc->region_count); + for (i = 0; i < count; i++) { + mdr = &mdss_data->md_regions[i]; + if (!strcmp(mdr->name, region->name)) + return i; + } + + return -ENOENT; +} + +static int qcom_md_region_unregister(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct minidump_ss_data *mdss_data = md->apss_data; + struct minidump_subsystem *mdss_toc = mdss_data->md_ss_toc; + struct minidump_region *mdr; + unsigned int region_cnt; + unsigned int idx; + int ret; + + ret = qcom_md_get_region_index(mdss_data, region); + if (ret < 0) { + dev_err(md->dev, "%s region is not present\n", region->name); + return ret; + } + + idx = ret; + mdr = &mdss_data->md_regions[0]; + region_cnt = le32_to_cpu(mdss_toc->region_count); + /* + * Left shift all the regions exist after this removed region + * index by 1 to fill the gap and zero out the last region + * present at the end. + */ + memmove(&mdr[idx], &mdr[idx + 1], (region_cnt - idx - 1) * sizeof(*mdr)); + memset(&mdr[region_cnt - 1], 0, sizeof(*mdr)); + region_cnt--; + mdss_toc->region_count = cpu_to_le32(region_cnt); + + return 0; +} + +static int qcom_md_region_register(struct minidump *md, + const struct qcom_minidump_region *region) +{ + struct minidump_ss_data *mdss_data = md->apss_data; + struct minidump_subsystem *mdss_toc = mdss_data->md_ss_toc; + unsigned int num_region; + int ret; + + ret = qcom_md_get_region_index(mdss_data, region); + if (ret >= 0) { + dev_info(md->dev, "%s region is already registered\n", region->name); + return -EEXIST; + } + + /* Check if there is a room for a new entry */ + num_region = le32_to_cpu(mdss_toc->region_count); + if (num_region >= MAX_NUM_ENTRIES) { + dev_err(md->dev, "maximum region limit %u reached\n", num_region); + return -ENOSPC; + } + + qcom_md_add_region(mdss_data, region); + + return 0; +} + +static bool qcom_minidump_valid_region(const struct qcom_minidump_region *region) +{ + return region && + strnlen(region->name, MAX_NAME_LENGTH) < MAX_NAME_LENGTH && + region->virt_addr && + region->size && + IS_ALIGNED(region->size, 4); +} + +/** + * qcom_minidump_region_register() - Register region in APSS Minidump table. + * @region: minidump region. + * + * Return: On success, it returns 0 and negative error value on failure. + */ +static int qcom_minidump_region_register(const struct qcom_minidump_region *region) +{ + struct minidump *md; + int ret; + + md = qcom_smem_minidump_ready(); + if (!md) + return -EPROBE_DEFER; + + if (!qcom_minidump_valid_region(region)) + return -EINVAL; + + mutex_lock(&md->md_lock); + ret = qcom_md_region_register(md, region); + if (ret) + goto unlock; + + qcom_md_update_elfheader(md, region); +unlock: + mutex_unlock(&md->md_lock); + return ret; +} + +/** + * qcom_minidump_region_unregister() - Unregister region from APSS Minidump table. + * @region: minidump region. + * + * Return: On success, it returns 0 and negative error value on failure. + */ +static int qcom_minidump_region_unregister(const struct qcom_minidump_region *region) +{ + struct minidump *md; + int ret; + + md = qcom_smem_minidump_ready(); + if (!md) + return -EPROBE_DEFER; + + if (!qcom_minidump_valid_region(region)) + return -EINVAL; + + mutex_lock(&md->md_lock); + ret = qcom_md_region_unregister(md, region); + if (ret) + goto unlock; + + ret = qcom_md_clear_elfheader(md, region); +unlock: + mutex_unlock(&md->md_lock); + return ret; +} + +static int qcom_md_add_elfheader(struct minidump *md) +{ + struct qcom_minidump_region elfregion; + struct elfhdr *ehdr; + struct elf_shdr *shdr; + struct elf_phdr *phdr; + unsigned int elfh_size; + unsigned int strtbl_off; + unsigned int phdr_off; + unsigned int banner_len; + char *banner; + + banner_len = strlen(linux_banner); + /* + * Header buffer contains: + * ELF header, (MAX_NUM_ENTRIES + 4) of Section and Program ELF headers, + * where, 4 additional entries, one for empty header, one for string table + * one for minidump table and one for linux banner. + * + * Linux banner is stored in minidump to aid post mortem tools to determine + * the kernel version. + */ + elfh_size = sizeof(*ehdr); + elfh_size += MAX_STRTBL_SIZE; + elfh_size += banner_len + 1; + elfh_size += ((sizeof(*shdr) + sizeof(*phdr)) * (MAX_NUM_ENTRIES + 4)); + elfh_size = ALIGN(elfh_size, 4); + + md->elf.ehdr = devm_kzalloc(md->dev, elfh_size, GFP_KERNEL); + if (!md->elf.ehdr) + return -ENOMEM; + + ehdr = md->elf.ehdr; + /* Assign Section/Program headers offset */ + md->elf.shdr = shdr = (struct elf_shdr *)(ehdr + 1); + md->elf.phdr = phdr = (struct elf_phdr *)(shdr + MAX_NUM_ENTRIES); + phdr_off = sizeof(*ehdr) + (sizeof(*shdr) * MAX_NUM_ENTRIES); + + memcpy(ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] = ELF_CLASS; + ehdr->e_ident[EI_DATA] = ELF_DATA; + ehdr->e_ident[EI_VERSION] = EV_CURRENT; + ehdr->e_ident[EI_OSABI] = ELF_OSABI; + ehdr->e_type = ET_CORE; + ehdr->e_machine = ELF_ARCH; + ehdr->e_version = EV_CURRENT; + ehdr->e_ehsize = sizeof(*ehdr); + ehdr->e_phoff = phdr_off; + ehdr->e_phentsize = sizeof(*phdr); + ehdr->e_shoff = sizeof(*ehdr); + ehdr->e_shentsize = sizeof(*shdr); + ehdr->e_shstrndx = 1; + + md->elf.elf_offset = elfh_size; + /* + * The zeroth index of the section header is reserved and is rarely used. + * Set the section header as null (SHN_UNDEF) and move to the next one. + * 2nd Section is String table. + */ + md->elf.strtable_idx = 1; + strtbl_off = sizeof(*ehdr) + ((sizeof(*phdr) + sizeof(*shdr)) * MAX_NUM_ENTRIES); + shdr++; + shdr->sh_type = SHT_STRTAB; + shdr->sh_offset = (elf_addr_t)strtbl_off; + shdr->sh_size = MAX_STRTBL_SIZE; + shdr->sh_entsize = 0; + shdr->sh_flags = 0; + shdr->sh_name = append_str_to_strtable(md, "STR_TBL"); + shdr++; + + /* 3rd Section is Linux banner */ + banner = (char *)ehdr + strtbl_off + MAX_STRTBL_SIZE; + memcpy(banner, linux_banner, banner_len); + + shdr->sh_type = SHT_PROGBITS; + shdr->sh_offset = (elf_addr_t)(strtbl_off + MAX_STRTBL_SIZE); + shdr->sh_size = banner_len + 1; + shdr->sh_addr = (elf_addr_t)linux_banner; + shdr->sh_entsize = 0; + shdr->sh_flags = SHF_WRITE; + shdr->sh_name = append_str_to_strtable(md, "linux_banner"); + + phdr->p_type = PT_LOAD; + phdr->p_offset = (elf_addr_t)(strtbl_off + MAX_STRTBL_SIZE); + phdr->p_vaddr = (elf_addr_t)linux_banner; + phdr->p_paddr = virt_to_phys(linux_banner); + phdr->p_filesz = phdr->p_memsz = banner_len + 1; + phdr->p_flags = PF_R | PF_W; + + /* + * Above are some prdefined sections/program header used + * for debug, update their count here. + */ + ehdr->e_phnum = 1; + ehdr->e_shnum = 3; + + /* Register ELF header as first region */ + strscpy(elfregion.name, "KELF_HEADER", sizeof(elfregion.name)); + elfregion.virt_addr = md->elf.ehdr; + elfregion.phys_addr = virt_to_phys(md->elf.ehdr); + elfregion.size = elfh_size; + + return qcom_md_region_register(md, &elfregion); +} + +static int qcom_apss_md_table_init(struct minidump *md, + struct minidump_subsystem *mdss_toc) +{ + struct minidump_ss_data *mdss_data; + + mdss_data = devm_kzalloc(md->dev, sizeof(*mdss_data), GFP_KERNEL); + if (!mdss_data) + return -ENOMEM; + + mdss_data->md_ss_toc = mdss_toc; + mdss_data->md_regions = devm_kcalloc(md->dev, MAX_NUM_ENTRIES, + sizeof(*mdss_data->md_regions), + GFP_KERNEL); + if (!mdss_data->md_regions) + return -ENOMEM; + + mdss_toc = mdss_data->md_ss_toc; + mdss_toc->regions_baseptr = cpu_to_le64(virt_to_phys(mdss_data->md_regions)); + mdss_toc->enabled = cpu_to_le32(MINIDUMP_SS_ENABLED); + mdss_toc->status = cpu_to_le32(1); + mdss_toc->region_count = cpu_to_le32(0); + + /* Tell bootloader not to encrypt the regions of this subsystem */ + mdss_toc->encryption_status = cpu_to_le32(MINIDUMP_SS_ENCR_DONE); + mdss_toc->encryption_required = cpu_to_le32(MINIDUMP_SS_ENCR_NOTREQ); + + md->apss_data = mdss_data; + + return 0; +} + +static void qcom_apss_md_table_exit(struct minidump_ss_data *mdss_data) +{ + memset(mdss_data->md_ss_toc, cpu_to_le32(0), sizeof(*mdss_data->md_ss_toc)); +} + +static int qcom_apss_minidump_probe(struct platform_device *pdev) +{ + struct minidump_global_toc *mdgtoc; + struct minidump *md; + size_t size; + int ret; + + md = devm_kzalloc(&pdev->dev, sizeof(*md), GFP_KERNEL); + if (!md) + return -ENOMEM; + + md->dev = &pdev->dev; + mdgtoc = qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, &size); + if (IS_ERR(mdgtoc)) { + ret = PTR_ERR(mdgtoc); + return dev_err_probe(md->dev, ret, + "Couldn't find minidump smem item\n"); + } + + if (size < sizeof(*mdgtoc) || !mdgtoc->status) { + ret = -EINVAL; + return dev_err_probe(md->dev, ret, + "minidump table is not initialized\n"); + } + + mutex_init(&md->md_lock); + ret = qcom_apss_md_table_init(md, &mdgtoc->subsystems[MINIDUMP_APSS_DESC]); + if (ret) + return dev_err_probe(md->dev, ret, + "apss minidump initialization failed\n"); + + /* First entry would be ELF header */ + ret = qcom_md_add_elfheader(md); + if (ret) { + qcom_apss_md_table_exit(md->apss_data); + return dev_err_probe(md->dev, ret, "Failed to add elf header\n"); + } + + platform_set_drvdata(pdev, md); + + return ret; +} + +static void qcom_apss_minidump_remove(struct platform_device *pdev) +{ + struct minidump *md = platform_get_drvdata(pdev); + + qcom_apss_md_table_exit(md->apss_data); +} + +static const struct platform_device_id qcom_minidump_id_table[] = { + { .name = "qcom_minidump_smem" }, + {} +}; +MODULE_DEVICE_TABLE(platform, qcom_minidump_id_table); + +static struct platform_driver qcom_minidump_driver = { + .probe = qcom_apss_minidump_probe, + .remove_new = qcom_apss_minidump_remove, + .driver = { + .name = "qcom_minidump_smem", + }, + .id_table = qcom_minidump_id_table, +}; + +module_platform_driver(qcom_minidump_driver); + +MODULE_DESCRIPTION("Qualcomm APSS minidump driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/soc/qcom/qcom_minidump_internal.h b/drivers/soc/qcom/qcom_minidump_internal.h index 71709235b196..a2aebe5b690a 100644 --- a/drivers/soc/qcom/qcom_minidump_internal.h +++ b/drivers/soc/qcom/qcom_minidump_internal.h @@ -9,10 +9,20 @@ #define MAX_NUM_OF_SS 10 #define MAX_REGION_NAME_LENGTH 16 #define SBL_MINIDUMP_SMEM_ID 602 + #define MINIDUMP_REGION_VALID ('V' << 24 | 'A' << 16 | 'L' << 8 | 'I' << 0) +#define MINIDUMP_REGION_INVALID ('I' << 24 | 'N' << 16 | 'V' << 8 | 'A' << 0) +#define MINIDUMP_REGION_INIT ('I' << 24 | 'N' << 16 | 'I' << 8 | 'T' << 0) +#define MINIDUMP_REGION_NOINIT 0 + +#define MINIDUMP_SS_ENCR_REQ (0 << 24 | 'Y' << 16 | 'E' << 8 | 'S' << 0) +#define MINIDUMP_SS_ENCR_NOTREQ (0 << 24 | 0 << 16 | 'N' << 8 | 'R' << 0) +#define MINIDUMP_SS_ENCR_START ('S' << 24 | 'T' << 16 | 'R' << 8 | 'T' << 0) #define MINIDUMP_SS_ENCR_DONE ('D' << 24 | 'O' << 16 | 'N' << 8 | 'E' << 0) #define MINIDUMP_SS_ENABLED ('E' << 24 | 'N' << 16 | 'B' << 8 | 'L' << 0) +#define MINIDUMP_APSS_DESC 0 + /** * struct minidump_region - Minidump region * @name : Name of the region to be dumped diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 690afc9a12f4..d6d5f4ade471 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -270,6 +270,7 @@ struct smem_region { * @partitions: list of partitions of current processor/host * @item_count: max accepted item number * @socinfo: platform device pointer + * @minidump: minidump platform device pointer * @num_regions: number of @regions * @regions: list of the memory regions defining the shared memory */ @@ -280,6 +281,7 @@ struct qcom_smem { u32 item_count; struct platform_device *socinfo; + struct platform_device *minidump; struct smem_ptable *ptable; struct smem_partition global_partition; struct smem_partition partitions[SMEM_HOST_COUNT]; @@ -806,6 +808,15 @@ int qcom_smem_get_soc_id(u32 *id) } EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id); +void *qcom_smem_minidump_ready(void) +{ + if (__smem && __smem->minidump) + return platform_get_drvdata(__smem->minidump); + else + return NULL; +} +EXPORT_SYMBOL_GPL(qcom_smem_minidump_ready); + static int qcom_smem_get_sbl_version(struct qcom_smem *smem) { struct smem_header *header; @@ -1184,11 +1195,20 @@ static int qcom_smem_probe(struct platform_device *pdev) if (IS_ERR(smem->socinfo)) dev_dbg(&pdev->dev, "failed to register socinfo device\n"); + smem->minidump = platform_device_register_data(&pdev->dev, "qcom_minidump_smem", + PLATFORM_DEVID_NONE, NULL, + 0); + if (IS_ERR(smem->minidump)) { + dev_dbg(&pdev->dev, "failed to register minidump device\n"); + smem->minidump = NULL; + } + return 0; } static void qcom_smem_remove(struct platform_device *pdev) { + platform_device_unregister(__smem->minidump); platform_device_unregister(__smem->socinfo); hwspin_lock_free(__smem->hwlock); diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h index a36a3b9d4929..08288360a55e 100644 --- a/include/linux/soc/qcom/smem.h +++ b/include/linux/soc/qcom/smem.h @@ -14,4 +14,6 @@ phys_addr_t qcom_smem_virt_to_phys(void *p); int qcom_smem_get_soc_id(u32 *id); +void *qcom_smem_minidump_ready(void); + #endif diff --git a/include/soc/qcom/qcom_minidump.h b/include/soc/qcom/qcom_minidump.h index cd87caef919d..9fdf9e9d0af3 100644 --- a/include/soc/qcom/qcom_minidump.h +++ b/include/soc/qcom/qcom_minidump.h @@ -6,6 +6,24 @@ #ifndef _QCOM_MINIDUMP_H_ #define _QCOM_MINIDUMP_H_ +#define MAX_NAME_LENGTH 12 + +/** + * struct qcom_minidump_region - APSS Minidump region information + * + * @name: Entry name, Minidump will dump binary with this name. + * @virt_addr: Virtual address of the entry. + * @phys_addr: Physical address of the entry to dump. + * @size: Number of byte to dump from @address location, + * and it should be 4 byte aligned. + */ +struct qcom_minidump_region { + char name[MAX_NAME_LENGTH]; + void *virt_addr; + phys_addr_t phys_addr; + size_t size; +}; + struct rproc; struct rproc_dump_segment; From patchwork Fri Nov 24 22:19:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468210 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QhiuhTM9" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87FEA1BDB; Fri, 24 Nov 2023 14:21:55 -0800 (PST) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOMLGuB009598; Fri, 24 Nov 2023 22:21:33 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-type; s=qcppdkim1; bh=rpTZzRk9lbzJt5DlEhpEEDB6mNMCUb9SEGfi12cp6PE=; b=QhiuhTM9huHVT806ocrGEevX9R9muzsbjoh35N90J5YY76O7b0tJU2lXay+TLj230Luc u9+bG0hwLbz3V/NzxKKDS+xOOjnAYOH+qVCi5i8u/jBmtFWci75cA+NrPpLjp9jmUn3I Nba9qbniQr8xo8ZRB+ekE7n89ETJfJlmDPB3qVbP33oxrCzT0GjvaA8XoctKWc6PlTqq sX/F9BuzsjLo54WdeKdV3SrbJqU5nGZV/I6Lurl6jy4fPLtuPgauLTsXQV+Tr9FqDToK OrX23i6H1FceG4Ow9gyvWVIAngFfD/QkMZ/JR1jX55C7ZM7Vt4HgLVJQqi7v2SMvkS8D xg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujwhcrtga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:33 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMLWjJ018548 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:32 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; Fri, 24 Nov 2023 14:21:23 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 09/12] MAINTAINERS: Add entry for minidump related files Date: Sat, 25 Nov 2023 03:49:52 +0530 Message-ID: <1700864395-1479-10-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: QSdMNITYzidO7g2hnyH8W17yvK4K4eYc X-Proofpoint-ORIG-GUID: QSdMNITYzidO7g2hnyH8W17yvK4K4eYc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxlogscore=895 bulkscore=0 impostorscore=0 spamscore=0 priorityscore=1501 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Add the entries into maintainer file for all the minidump related modules. Signed-off-by: Mukesh Ojha --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index f2b2cd60eb20..53b9f22816c2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18016,6 +18016,16 @@ S: Maintained F: Documentation/devicetree/bindings/regulator/vqmmc-ipq4019-regulator.yaml F: drivers/regulator/vqmmc-ipq4019-regulator.c +QUALCOMM MINIDUMP DRIVER +M: Mukesh Ojha +L: linux-arm-msm@vger.kernel.org +S: Maintained +F: Documentation/admin-guide/qcom_minidump.rst +F: drivers/soc/qcom/qcom_rproc_minidump.c +F: drivers/soc/qcom/qcom_minidump.c +F: drivers/soc/qcom/qcom_ramoops_minidump.c + + QUALCOMM NAND CONTROLLER DRIVER M: Manivannan Sadhasivam L: linux-mtd@lists.infradead.org From patchwork Fri Nov 24 22:19:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468209 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="dVNS6Jyg" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F8C91BC7; Fri, 24 Nov 2023 14:22:00 -0800 (PST) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOLVLxI017056; Fri, 24 Nov 2023 22:21:41 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-type; s=qcppdkim1; bh=dzhYh7LrMvBp4kXy7q9UTgYwttlEksL+Qn973TCYLxA=; b=dVNS6Jyg3rH/RfJP2BDZnTTiCmcn6gBFHW0eCb3RMm7kMiDQJHtQtQ2rRA/ja9KS5A0m 8jpN2sVvj/J/X8CT2U1baYv12wIVqrhEZtGafQrRRRe+2XdZrjKSoQOplrK36thlieiG 6v7tMjHHXTPnKaaVMaDW1iyvf52EDdVIMvXWbGNW2EQOtzGoBoT7rjFaaQg/I9/og2/D 68nGddAWL/OB2++snRzfSSHLR9SW0whg6W5YxhH2/iiIQBM3ojjp3xwdw3kuslXk8OG0 D9QgUbWzIveN+vXMaCW1MpXMJJgyDYyXwf3ZVI8QKLtMEcw89qfEuAIsEoceqDAEUWSm Gg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujhh4tjd4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:40 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMLdts018614 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:39 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; Fri, 24 Nov 2023 14:21:30 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 10/12] pstore/ram: Add dynamic ramoops region support through commandline Date: Sat, 25 Nov 2023 03:49:53 +0530 Message-ID: <1700864395-1479-11-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: YnvGFjnTQMFwQ9tSAtnR_3ymn6TUt3_b X-Proofpoint-ORIG-GUID: YnvGFjnTQMFwQ9tSAtnR_3ymn6TUt3_b X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 clxscore=1015 phishscore=0 bulkscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 The reserved memory region for ramoops is assumed to be at a fixed and known location when read from the devicetree. This may not be required for something like Qualcomm's minidump which is interested in knowing addresses of ramoops region but it does not put hard requirement of address being fixed as most of it's SoC does not support warm reset and does not use pstorefs at all instead it has firmware way of collecting ramoops region if it gets to know the address and register it with apss minidump table which is sitting in shared memory region in DDR and firmware will have access to these table during reset and collects it on crash of SoC. So, add the support of reserving ramoops region to be dynamically allocated early during boot if it is request through command line via 'dyn_ramoops_size=' and fill up reserved resource structure and export the structure, so that it can be read by ramoops driver. Signed-off-by: Mukesh Ojha --- Documentation/admin-guide/ramoops.rst | 7 ++++ fs/pstore/Kconfig | 15 +++++++++ fs/pstore/ram.c | 62 ++++++++++++++++++++++++++++++++--- include/linux/pstore_ram.h | 5 +++ init/main.c | 2 ++ 5 files changed, 87 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/ramoops.rst b/Documentation/admin-guide/ramoops.rst index e9f85142182d..af737adbf079 100644 --- a/Documentation/admin-guide/ramoops.rst +++ b/Documentation/admin-guide/ramoops.rst @@ -33,6 +33,13 @@ memory are implementation defined, and won't work on many ARMs such as omaps. Setting ``mem_type=2`` attempts to treat the memory region as normal memory, which enables full cache on it. This can improve the performance. +Ramoops memory region can also be allocated dynamically for a special case where +there is no requirement to access the logs from pstorefs on next boot instead there +is separate backend mechanism like minidump present which has awareness about the +dynamic ramoops region and can recover the logs. This is enabled via command line +parameter ``dyn_ramoops_size=`` and should not be used in absence of +separate backend which knows how to recover this dynamic region. + The memory area is divided into ``record_size`` chunks (also rounded down to power of two) and each kmesg dump writes a ``record_size`` chunk of information. diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index 3acc38600cd1..e13e53d7a225 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig @@ -81,6 +81,21 @@ config PSTORE_RAM For more information, see Documentation/admin-guide/ramoops.rst. +config PSTORE_DYNAMIC_RAMOOPS_REGION_RESERVATION + bool "Reserve ramoops region dynamically" + select PSTORE_RAM + help + This enables the dynamic reservation of ramoops region for a special case + where there is no requirement to access the logs from pstorefs on next boot + instead there is separate backend mechanism like minidump present which has + awareness about the dynamic ramoops region and can recover the logs. This is + enabled via command line parameter dyn_ramoops_size= and should not be + used in absence of separate backend which knows how to recover this dynamic + region. + + Note whenever this config is selected ramoops driver will be build statically + into kernel. + config PSTORE_ZONE tristate depends on PSTORE diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 88b34fdbf759..a6c0da8cfdd4 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "internal.h" @@ -103,6 +104,55 @@ struct ramoops_context { }; static struct platform_device *dummy; +static int dyn_ramoops_size; +/* Location of the reserved area for the dynamic ramoops */ +static struct resource dyn_ramoops_res = { + .name = "ramoops", + .start = 0, + .end = 0, + .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, + .desc = IORES_DESC_NONE, +}; + +static int __init parse_dyn_ramoops_size(char *p) +{ + char *tmp; + + dyn_ramoops_size = memparse(p, &tmp); + if (p == tmp) { + pr_err("ramoops: memory size expected\n"); + return -EINVAL; + } + + return 0; +} +early_param("dyn_ramoops_size", parse_dyn_ramoops_size); + +#ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS_REGION_RESERVATION +/* + * setup_dynamic_ramoops() - reserves memory for dynamic ramoops + * + * This enable dynamic reserve memory support for ramoops through + * command line. + */ +void __init setup_dynamic_ramoops(void) +{ + unsigned long long ramoops_base; + unsigned long long ramoops_size; + + ramoops_base = memblock_phys_alloc_range(dyn_ramoops_size, SMP_CACHE_BYTES, + 0, MEMBLOCK_ALLOC_NOLEAKTRACE); + if (!ramoops_base) { + pr_err("cannot allocate ramoops dynamic memory (size:0x%llx).\n", + ramoops_size); + return; + } + + dyn_ramoops_res.start = ramoops_base; + dyn_ramoops_res.end = ramoops_base + dyn_ramoops_size - 1; + insert_resource(&iomem_resource, &dyn_ramoops_res); +} +#endif static int ramoops_pstore_open(struct pstore_info *psi) { @@ -915,14 +965,18 @@ static void __init ramoops_register_dummy(void) /* * Prepare a dummy platform data structure to carry the module - * parameters. If mem_size isn't set, then there are no module - * parameters, and we can skip this. + * parameters. If mem_size isn't set, check for dynamic ramoops + * size and use if it is set. */ - if (!mem_size) + if (!mem_size && !dyn_ramoops_size) return; - pr_info("using module parameters\n"); + if (dyn_ramoops_size) { + mem_size = dyn_ramoops_size; + mem_address = dyn_ramoops_res.start; + } + pr_info("using module parameters\n"); memset(&pdata, 0, sizeof(pdata)); pdata.mem_size = mem_size; pdata.mem_address = mem_address; diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index 9d65ff94e216..b3537336c4e1 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -39,4 +39,9 @@ struct ramoops_platform_data { struct persistent_ram_ecc_info ecc_info; }; +#ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS_REGION_RESERVATION +void __init setup_dynamic_ramoops(void); +#else +static inline void __init setup_dynamic_ramoops(void) {} +#endif #endif diff --git a/init/main.c b/init/main.c index e24b0780fdff..32c7d94558ec 100644 --- a/init/main.c +++ b/init/main.c @@ -99,6 +99,7 @@ #include #include #include +#include #include #include @@ -895,6 +896,7 @@ void start_kernel(void) pr_notice("%s", linux_banner); early_security_init(); setup_arch(&command_line); + setup_dynamic_ramoops(); setup_boot_config(); setup_command_line(command_line); setup_nr_cpu_ids(); From patchwork Fri Nov 24 22:19:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468211 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="a8s4b0Sp" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA2FA1FD7; Fri, 24 Nov 2023 14:22:07 -0800 (PST) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOMD7Vp010830; Fri, 24 Nov 2023 22:21:48 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-type; s=qcppdkim1; bh=4990baIAlfmVS/cuHV5ll4dJd4q948H/yj67VkxMl0o=; b=a8s4b0SpiRAl5E8ln5Cb26pe+rXlFHCURefuDuMQ3SIiNW5Ac8h2m5cu6XoJX9WQZSPP wLKJDNucJscGH3O9BIgf111O8m2VuWcOADzhTZxDkfx812U8+GMGKSQyX/RSOkiSI/jA ss4w3DTJyYJj/eRperxj4Xj2+Ps7VLD0SQzxBc0hzY2OsY1NynFcvt2jXSpJ0cRgMFAG 6OKsMd2tPgaq885i5S5/CSV2eqaLICIMkZDFNYj+5SG6co/geXjpwlu9eun8LSiIwoP9 eBjhLgPFFfFnWIyToc+U8SNWzjauUeiGQFtRjXiWFSjAPSRCuONed7YgqDFbYXQ3d2Cy FQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ujtd8hc5n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:47 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMLlQa018649 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:47 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; Fri, 24 Nov 2023 14:21:37 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 11/12] pstore/ram: Add ramoops ready notifier support Date: Sat, 25 Nov 2023 03:49:54 +0530 Message-ID: <1700864395-1479-12-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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-ORIG-GUID: lqkUmmB8IS1KaL6dqzOsIkviN8gd4TWl X-Proofpoint-GUID: lqkUmmB8IS1KaL6dqzOsIkviN8gd4TWl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Client like minidump, is only interested in ramoops region addresses/size so that it could register them with its table and also it is only deals with ram backend and does not use pstorefs to read the records. Let's introduce a client notifier in ramoops which gets called when ramoops driver probes successfully and it passes the ramoops region information to the passed callback by the client and If the call for ramoops ready register comes after ramoops probe than call the callback directly. Signed-off-by: Mukesh Ojha --- fs/pstore/ram.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pstore_ram.h | 6 ++++ 2 files changed, 83 insertions(+) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index a6c0da8cfdd4..72341fd21aec 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "internal.h" #include "ram_internal.h" @@ -101,6 +102,14 @@ struct ramoops_context { unsigned int ftrace_read_cnt; unsigned int pmsg_read_cnt; struct pstore_info pstore; + /* + * Lock to serialize calls to register_ramoops_ready_notifier, + * ramoops_ready_notifier and read/modification of 'ramoops_ready'. + */ + struct mutex lock; + bool ramoops_ready; + int (*callback)(const char *name, int id, void *vaddr, + phys_addr_t paddr, size_t size); }; static struct platform_device *dummy; @@ -488,6 +497,7 @@ static int ramoops_pstore_erase(struct pstore_record *record) } static struct ramoops_context oops_cxt = { + .lock = __MUTEX_INITIALIZER(oops_cxt.lock), .pstore = { .owner = THIS_MODULE, .name = "ramoops", @@ -662,6 +672,68 @@ static int ramoops_init_prz(const char *name, return 0; } +void ramoops_ready_notifier(struct ramoops_context *cxt) +{ + struct persistent_ram_zone *prz; + int i; + + if (!cxt->callback) + return; + + for (i = 0; i < cxt->max_dump_cnt; i++) { + prz = cxt->dprzs[i]; + cxt->callback("dmesg", i, prz->vaddr, prz->paddr, prz->size); + } + + if (cxt->console_size) { + prz = cxt->cprz; + cxt->callback("console", 0, prz->vaddr, prz->paddr, prz->size); + } + + for (i = 0; i < cxt->max_ftrace_cnt; i++) { + prz = cxt->fprzs[i]; + cxt->callback("ftrace", i, prz->vaddr, prz->paddr, prz->size); + } + + if (cxt->pmsg_size) { + prz = cxt->mprz; + cxt->callback("pmsg", 0, prz->vaddr, prz->paddr, prz->size); + } +} + +int register_ramoops_ready_notifier(int (*fn)(const char *, int, + void *, phys_addr_t, size_t)) +{ + struct ramoops_context *cxt = &oops_cxt; + + mutex_lock(&cxt->lock); + if (cxt->callback) { + mutex_unlock(&cxt->lock); + return -EEXIST; + } + + cxt->callback = fn; + if (cxt->ramoops_ready) + ramoops_ready_notifier(cxt); + + mutex_unlock(&cxt->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(register_ramoops_ready_notifier); + +void unregister_ramoops_ready_notifier(int (*fn)(const char *, int, + void *, phys_addr_t, size_t)) +{ + struct ramoops_context *cxt = &oops_cxt; + + mutex_lock(&cxt->lock); + WARN_ON_ONCE(cxt->callback != fn); + cxt->callback = NULL; + mutex_unlock(&cxt->lock); +} +EXPORT_SYMBOL_GPL(unregister_ramoops_ready_notifier); + /* Read a u32 from a dt property and make sure it's safe for an int. */ static int ramoops_parse_dt_u32(struct platform_device *pdev, const char *propname, @@ -911,6 +983,11 @@ static int ramoops_probe(struct platform_device *pdev) ramoops_pmsg_size = pdata->pmsg_size; ramoops_ftrace_size = pdata->ftrace_size; + mutex_lock(&cxt->lock); + ramoops_ready_notifier(cxt); + cxt->ramoops_ready = true; + mutex_unlock(&cxt->lock); + pr_info("using 0x%lx@0x%llx, ecc: %d\n", cxt->size, (unsigned long long)cxt->phys_addr, cxt->ecc_info.ecc_size); diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h index b3537336c4e1..9745d48ba59e 100644 --- a/include/linux/pstore_ram.h +++ b/include/linux/pstore_ram.h @@ -39,6 +39,12 @@ struct ramoops_platform_data { struct persistent_ram_ecc_info ecc_info; }; +int register_ramoops_ready_notifier(int (*fn)(const char *name, int id, + void *vaddr, phys_addr_t paddr, + size_t size)); +void unregister_ramoops_ready_notifier(int (*fn)(const char *name, int id, + void *vaddr, phys_addr_t paddr, + size_t size)); #ifdef CONFIG_PSTORE_DYNAMIC_RAMOOPS_REGION_RESERVATION void __init setup_dynamic_ramoops(void); #else From patchwork Fri Nov 24 22:19:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Ojha X-Patchwork-Id: 13468212 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="mxK/2Edj" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C75AF1FF6; Fri, 24 Nov 2023 14:22:13 -0800 (PST) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AOMJOVA032368; Fri, 24 Nov 2023 22:21:55 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-type; s=qcppdkim1; bh=b5eTBZeeW3B0oIKYsibzqp9oXL4xrHRnjIPMFNhgnF0=; b=mxK/2EdjjVnrmjFpyttUkIAzFH6685VIp//oIOpM3MTuQV/vi4ldmtkBhd19UMXOOF8Q 6g5ORooFeJCNSKZa0PbA2h7XWG8pT2JRMWfLWP9Qr4nssAIOrSyliKcoIgO2NzUNpuu1 86cK5qj+YepaN+nyGspdarozNzE+Tn8Bh0lIsyBy0qMu/+VU5xROmBdXn9bKnbzRuvRR BHwr8hc2LJPAB9BoaSVWLnUvAGsY7Ei1rssFeW0v7SK8cbO5TN0EA3nkcyYdR06mBQ0d MHI736zOdlAfumZxsLpeyzL3SgWhmw1KpTrumHvtGlqt4IlDIjnRYQes05j3MIqzqJ9w dg== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uj6emusg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:55 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AOMLsMQ016882 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 Nov 2023 22:21:54 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; Fri, 24 Nov 2023 14:21:45 -0800 From: Mukesh Ojha To: , , , , , , , , , , , , , , , , CC: , , , , , , , , , Mukesh Ojha Subject: [Patch v6 12/12] soc: qcom: register ramoops region with APSS minidump Date: Sat, 25 Nov 2023 03:49:55 +0530 Message-ID: <1700864395-1479-13-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> References: <1700864395-1479-1-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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-ORIG-GUID: XhP7UB1QriAxNqtp8DRhI6TdM9sUSISM X-Proofpoint-GUID: XhP7UB1QriAxNqtp8DRhI6TdM9sUSISM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-24_09,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311240174 Register ramoops region with APSS minidump so that these region gets captured on system crash. Signed-off-by: Mukesh Ojha --- drivers/soc/qcom/qcom_minidump.c | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/soc/qcom/qcom_minidump.c b/drivers/soc/qcom/qcom_minidump.c index c0f76a51d0e8..9a39b68903fb 100644 --- a/drivers/soc/qcom/qcom_minidump.c +++ b/drivers/soc/qcom/qcom_minidump.c @@ -18,8 +18,10 @@ #include #include #include +#include #include #include +#include #include #include "qcom_minidump_internal.h" @@ -56,12 +58,20 @@ struct minidump_elfhdr { * @dev: Minidump backend device * @apss_data: APSS driver data * @md_lock: Lock to protect access to APSS minidump table + * @work: Minidump work for any required execution in process context. */ struct minidump { struct minidump_elfhdr elf; struct device *dev; struct minidump_ss_data *apss_data; struct mutex md_lock; + struct work_struct work; +}; + +static LIST_HEAD(apss_md_rlist); +struct md_region_list { + struct qcom_minidump_region md_region; + struct list_head list; }; /* @@ -530,6 +540,52 @@ static int qcom_apss_md_table_init(struct minidump *md, return 0; } +static int ramoops_region_md_register(const char *name, int id, void *vaddr, + phys_addr_t paddr, size_t size) +{ + struct qcom_minidump_region *md_region; + struct md_region_list *mdr_list; + int ret; + + mdr_list = kzalloc(sizeof(*mdr_list), GFP_KERNEL); + if (!mdr_list) + return -ENOMEM; + + md_region = &mdr_list->md_region; + scnprintf(md_region->name, sizeof(md_region->name), "K%s%d", name, id); + md_region->virt_addr = vaddr; + md_region->phys_addr = paddr; + md_region->size = size; + ret = qcom_minidump_region_register(md_region); + if (ret < 0) { + pr_err("failed to register region in minidump: err: %d\n", ret); + return ret; + } + + list_add(&mdr_list->list, &apss_md_rlist); + + return 0; +} + +static void ramoops_register_md_callback(struct work_struct *work) +{ + register_ramoops_ready_notifier(ramoops_region_md_register); +} + +static void qcom_ramoops_minidump_unregister(void) +{ + struct md_region_list *mdr_list; + struct md_region_list *tmp; + + list_for_each_entry_safe(mdr_list, tmp, &apss_md_rlist, list) { + struct qcom_minidump_region *region; + + region = &mdr_list->md_region; + qcom_minidump_region_unregister(region); + list_del(&mdr_list->list); + } +} + static void qcom_apss_md_table_exit(struct minidump_ss_data *mdss_data) { memset(mdss_data->md_ss_toc, cpu_to_le32(0), sizeof(*mdss_data->md_ss_toc)); @@ -575,6 +631,9 @@ static int qcom_apss_minidump_probe(struct platform_device *pdev) platform_set_drvdata(pdev, md); + INIT_WORK(&md->work, ramoops_register_md_callback); + schedule_work(&md->work); + return ret; } @@ -582,6 +641,9 @@ static void qcom_apss_minidump_remove(struct platform_device *pdev) { struct minidump *md = platform_get_drvdata(pdev); + flush_work(&md->work); + qcom_ramoops_minidump_unregister(); + unregister_ramoops_ready_notifier(ramoops_region_md_register); qcom_apss_md_table_exit(md->apss_data); }