linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mukesh Ojha <quic_mojha@quicinc.com>
To: <corbet@lwn.net>, <agross@kernel.org>, <andersson@kernel.org>,
	<konrad.dybcio@linaro.org>, <robh+dt@kernel.org>,
	<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
	<keescook@chromium.org>, <tony.luck@intel.com>,
	<gpiccoli@igalia.com>, <mathieu.poirier@linaro.org>,
	<catalin.marinas@arm.com>, <will@kernel.org>,
	<linus.walleij@linaro.org>, <andy.shevchenko@gmail.com>
Cc: <linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-msm@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-hardening@vger.kernel.org>,
	<linux-remoteproc@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-gpio@vger.kernel.org>,
	"Mukesh Ojha" <quic_mojha@quicinc.com>
Subject: [PATCH v4 03/21] soc: qcom: Add qcom_minidump_smem module
Date: Wed, 28 Jun 2023 18:04:30 +0530	[thread overview]
Message-ID: <1687955688-20809-4-git-send-email-quic_mojha@quicinc.com> (raw)
In-Reply-To: <1687955688-20809-1-git-send-email-quic_mojha@quicinc.com>

Add qcom_minidump_smem module in a preparation to remove smem
based minidump specific code from driver/remoteproc/qcom_common.c
and provide needed exported API, this abstract minidump specific
data layout from qualcomm's remoteproc driver.

Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
---
 drivers/soc/qcom/Kconfig              |   8 ++
 drivers/soc/qcom/qcom_minidump_smem.c | 147 ++++++++++++++++++++++++++++++++++
 include/soc/qcom/qcom_minidump.h      |  24 ++++++
 3 files changed, 179 insertions(+)
 create mode 100644 drivers/soc/qcom/qcom_minidump_smem.c
 create mode 100644 include/soc/qcom/qcom_minidump.h

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index a491718f8064..982310b5a1cb 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -279,4 +279,12 @@ config QCOM_INLINE_CRYPTO_ENGINE
 	tristate
 	select QCOM_SCM
 
+config QCOM_MINIDUMP_SMEM
+	tristate "QCOM Minidump SMEM (as backend) Support"
+	depends on ARCH_QCOM
+	depends on QCOM_SMEM
+	help
+	  Enablement of core minidump feature is controlled from boot firmware
+	  side, and this config allow linux to query minidump segments associated
+	  with the remote processor and check its validity.
 endmenu
diff --git a/drivers/soc/qcom/qcom_minidump_smem.c b/drivers/soc/qcom/qcom_minidump_smem.c
new file mode 100644
index 000000000000..b588833ea26e
--- /dev/null
+++ b/drivers/soc/qcom/qcom_minidump_smem.c
@@ -0,0 +1,147 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/soc/qcom/smem.h>
+#include <soc/qcom/qcom_minidump.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];
+};
+
+/**
+ * qcom_ss_md_mapped_base() - For getting subsystem iomapped base segment address
+ * for given minidump index.
+ *
+ * @minidump_id: Subsystem minidump index.
+ * @seg_cnt:	 Segment count for a given minidump index
+ *
+ * Return: On success, it returns iomapped base segment address, otherwise NULL on error.
+ */
+void *qcom_ss_md_mapped_base(unsigned int minidump_id, int *seg_cnt)
+{
+	struct minidump_global_toc *toc;
+	struct minidump_subsystem *subsystem;
+
+	/*
+	 * Get global minidump ToC and check if global table
+	 * pointer exists and init is set.
+	 */
+	toc = qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, NULL);
+	if (IS_ERR(toc) || !toc->status)
+		return NULL;
+
+	/* 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)
+		return NULL;
+
+	*seg_cnt = le32_to_cpu(subsystem->region_count);
+
+	return ioremap((unsigned long)le64_to_cpu(subsystem->regions_baseptr),
+			*seg_cnt * sizeof(struct minidump_region));
+}
+EXPORT_SYMBOL_GPL(qcom_ss_md_mapped_base);
+
+/**
+ * qcom_ss_valid_segment_info() - Checks segment sanity and gets it's details
+ *
+ * @ptr:  Segment IO-mapped base address.
+ * @i:	  Segment index.
+ * @name: Segment name.
+ * @da:	  Segment physical address.
+ * @size: Segment size.
+ *
+ * Return: It returns 0 on success and 1 if the segment is invalid and negative
+ *	   value on error.
+ */
+int qcom_ss_valid_segment_info(void *ptr, int i, char **name, dma_addr_t *da, size_t *size)
+{
+	struct minidump_region __iomem *tmp;
+	struct minidump_region region;
+
+	if (!ptr)
+		return -EINVAL;
+
+	tmp = ptr;
+	memcpy_fromio(&region, tmp + i, sizeof(region));
+
+	/* If it is not valid region, skip it */
+	if (le32_to_cpu(region.valid) != MINIDUMP_REGION_VALID)
+		return 1;
+
+	*name = kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL);
+	if (!*name)
+		return -ENOMEM;
+
+	*da = le64_to_cpu(region.address);
+	*size = le64_to_cpu(region.size);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(qcom_ss_valid_segment_info);
+
+MODULE_DESCRIPTION("Qualcomm Minidump SMEM as backend driver");
+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..d7747c27fd45
--- /dev/null
+++ b/include/soc/qcom/qcom_minidump.h
@@ -0,0 +1,24 @@
+/* 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_
+
+#if IS_ENABLED(CONFIG_QCOM_MINIDUMP_SMEM)
+void *qcom_ss_md_mapped_base(unsigned int minidump_id, int *seg_cnt);
+int qcom_ss_valid_segment_info(void *ptr, int i, char **name,
+			       dma_addr_t *da, size_t *size);
+#else
+static inline void *qcom_ss_md_mapped_base(unsigned int minidump_id, int *seg_cnt)
+{
+	return NULL;
+}
+static inline int qcom_ss_valid_segment_info(void *ptr, int i, char **name,
+					     dma_addr_t *da, size_t *size)
+{
+	return -EINVAL;
+}
+#endif /* CONFIG_QCOM_MINIDUMP_SMEM */
+#endif /* _QCOM_MINIDUMP_H_ */
-- 
2.7.4


  parent reply	other threads:[~2023-06-28 12:38 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28 12:34 [PATCH v4 00/21] Add Qualcomm Minidump kernel driver related support Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 01/21] docs: qcom: Add qualcomm minidump guide Mukesh Ojha
2023-06-28 23:21   ` Rob Herring
2023-06-28 12:34 ` [PATCH v4 02/21] kallsyms: Export kallsyms_lookup_name Mukesh Ojha
2023-06-28 13:24   ` Andy Shevchenko
2023-06-28 15:04     ` Mukesh Ojha
2023-06-28 13:53   ` Pavan Kondeti
2023-06-28 15:22     ` Mukesh Ojha
2023-06-28 15:32       ` Will Deacon
2023-06-28 15:43         ` Greg KH
2023-06-28 12:34 ` Mukesh Ojha [this message]
2023-06-28 13:31   ` [PATCH v4 03/21] soc: qcom: Add qcom_minidump_smem module Andy Shevchenko
2023-06-28 15:47   ` Greg KH
2023-06-28 12:34 ` [PATCH v4 04/21] soc: qcom: Add Qualcomm APSS minidump (frontend) feature support Mukesh Ojha
2023-06-28 13:43   ` Andy Shevchenko
2023-06-29  2:33   ` Pavan Kondeti
2023-06-30  7:15     ` Mukesh Ojha
2023-06-30  8:38       ` Pavan Kondeti
2023-06-28 12:34 ` [PATCH v4 05/21] soc: qcom: Add linux minidump smem backend driver support Mukesh Ojha
2023-06-28 13:51   ` Andy Shevchenko
2023-06-28 12:34 ` [PATCH v4 06/21] soc: qcom: minidump: Add pending region registration support Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 07/21] soc: qcom: minidump: Add update region support Mukesh Ojha
2023-06-29  2:49   ` Pavan Kondeti
2023-06-28 12:34 ` [PATCH v4 08/21] dt-bindings: reserved-memory: Add qcom,ramoops binding Mukesh Ojha
2023-06-28 14:10   ` Pavan Kondeti
2023-06-28 23:17     ` Rob Herring
2023-06-29  1:45       ` Pavan Kondeti
2023-06-28 14:47   ` Rob Herring
2023-06-28 15:01     ` Mukesh Ojha
2023-07-02  8:12       ` Krzysztof Kozlowski
2023-07-03  6:21         ` Mukesh Ojha
2023-07-03  7:20           ` Krzysztof Kozlowski
2023-07-03 15:55             ` Mukesh Ojha
2023-07-04  5:57               ` Krzysztof Kozlowski
2023-07-19 10:29                 ` Luca Stefani
2023-06-28 12:34 ` [PATCH v4 09/21] pstore/ram : Export ramoops_parse_dt() symbol Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 10/21] soc: qcom: Add qcom's pstore minidump driver support Mukesh Ojha
2023-06-28 22:57   ` Rob Herring
2023-06-29  9:16     ` Mukesh Ojha
2023-07-05 23:27       ` Rob Herring
2023-06-28 12:34 ` [PATCH v4 11/21] soc: qcom: Register pstore frontend region with minidump Mukesh Ojha
2023-06-30  4:55   ` Pavan Kondeti
2023-06-30  9:25     ` Andy Shevchenko
2023-06-28 12:34 ` [PATCH v4 12/21] remoteproc: qcom: Expand MD_* as MINIDUMP_* Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 13/21] remoterproc: qcom: refactor to leverage exported minidump symbol Mukesh Ojha
2023-06-28 15:51   ` Pavan Kondeti
2023-06-29  9:20     ` Mukesh Ojha
2023-06-30  3:41       ` Pavan Kondeti
2023-06-28 12:34 ` [PATCH v4 14/21] MAINTAINERS: Add entry for minidump driver related support Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 15/21] arm64: defconfig: Enable Qualcomm Minidump related drivers Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 16/21] arm64: dts: qcom: sm8450: Add Qualcomm ramoops minidump node Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 17/21] firmware: qcom_scm: provide a read-modify-write function Mukesh Ojha
2023-06-30  5:01   ` Pavan Kondeti
2023-06-28 12:34 ` [PATCH v4 18/21] pinctrl: qcom: Use qcom_scm_io_update_field() Mukesh Ojha
2023-06-28 13:44   ` Andy Shevchenko
2023-06-30 14:58     ` Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 19/21] firmware: scm: Modify only the download bits in TCSR register Mukesh Ojha
2023-06-28 15:20   ` Konrad Dybcio
2023-06-30 14:57     ` Mukesh Ojha
2023-06-28 12:34 ` [PATCH v4 20/21] firmware: qcom_scm: Refactor code to support multiple download mode Mukesh Ojha
2023-06-30  5:25   ` Pavan Kondeti
2023-06-30  9:28     ` Andy Shevchenko
2023-06-28 12:34 ` [PATCH v4 21/21] firmware: qcom_scm: Add multiple download mode support Mukesh Ojha
2023-06-28 15:45 ` [PATCH v4 00/21] Add Qualcomm Minidump kernel driver related support Greg KH
2023-06-28 16:20   ` Mukesh Ojha
2023-06-28 16:53     ` Greg KH
2023-06-28 23:12   ` Rob Herring
2023-06-30 16:04     ` Mukesh Ojha
2023-07-02  8:29       ` Krzysztof Kozlowski
2023-07-03 21:05         ` Trilok Soni
2023-07-06 17:20           ` Mathieu Poirier
2023-07-18 15:03             ` Mukesh Ojha
2023-08-07 13:46               ` Mukesh Ojha
2023-07-06 17:40           ` Rob Herring
2023-07-06 18:07             ` Trilok Soni
2023-08-10 16:47             ` Mukesh Ojha
2023-07-04  9:27     ` Linus Walleij
2023-07-05 17:29       ` Trilok Soni
2023-07-14 23:45         ` Trilok Soni
2023-07-18  5:47           ` Mukesh Ojha
2023-07-18 13:35             ` Greg KH
2023-07-18 13:55               ` Mukesh Ojha
2023-07-18 14:41                 ` Greg KH
2023-07-18 16:22                   ` Trilok Soni
2023-07-02  8:08 ` Krzysztof Kozlowski
2023-07-13  4:39 ` Kathiravan T
2023-07-14 15:25   ` Mukesh Ojha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1687955688-20809-4-git-send-email-quic_mojha@quicinc.com \
    --to=quic_mojha@quicinc.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gpiccoli@igalia.com \
    --cc=keescook@chromium.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=robh+dt@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).