Эх сурвалжийг харах

qcom: soc: Convert minidump driver into module

Refactor minidump driver to support as loadable
module and handle errors observed during the compilation.

Change-Id: I54b58226e3d6de0b674ac4ca1407138d1c9707e8
Signed-off-by: Prasad Sodagudi <[email protected]>
Prasad Sodagudi 4 жил өмнө
parent
commit
7819b1a145

+ 1 - 1
drivers/soc/qcom/Kconfig

@@ -498,7 +498,7 @@ config QCOM_DCC_V2
 
 config QCOM_MINIDUMP
 	tristate "QCOM Minidump Support"
-	depends on QCOM_SMEM && POWER_RESET_MSM
+	depends on QCOM_SMEM
 	help
 	  This enables minidump feature. It allows various clients to
 	  register to dump their state at system bad state (panic/WDT,etc.,).

+ 2 - 1
drivers/soc/qcom/Makefile

@@ -44,7 +44,8 @@ obj-$(CONFIG_QCOM_RIMPS) += qcom_rimps.o
 obj-$(CONFIG_QCOM_RUN_QUEUE_STATS) += rq_stats.o
 obj-$(CONFIG_QCOM_APR) += apr.o
 obj-$(CONFIG_QCOM_LLCC) += llcc-qcom.o
-obj-$(CONFIG_QCOM_MINIDUMP) += msm_minidump.o minidump_log.o
+obj-$(CONFIG_QCOM_MINIDUMP) += minidump.o
+minidump-y	 += msm_minidump.o minidump_log.o
 obj-$(CONFIG_QCOM_MEM_OFFLINE) += mem-offline.o
 obj-$(CONFIG_QCOM_MEM_BUF) += mem_buf/
 obj-$(CONFIG_QCOM_MEMORY_DUMP_V2) += memory_dump_v2.o

+ 4 - 5
drivers/soc/qcom/minidump_log.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/cache.h>
@@ -142,7 +142,7 @@ static DEFINE_SPINLOCK(md_modules_lock);
 #endif	/* CONFIG_MODULES */
 #endif
 
-static void __init register_log_buf(void)
+static void register_log_buf(void)
 {
 	char *log_bufp;
 	uint32_t log_buf_len;
@@ -185,7 +185,7 @@ static int register_stack_entry(struct md_region *ksp_entry, u64 sp, u64 size)
 	return entry;
 }
 
-static void __init register_kernel_sections(void)
+static void register_kernel_sections(void)
 {
 	struct md_region ksec_entry;
 	char *data_name = "KDATABSS";
@@ -1320,7 +1320,7 @@ static void md_register_module_data(void)
 #endif	/* CONFIG_MODULES */
 #endif	/* CONFIG_QCOM_MINIDUMP_PANIC_DUMP */
 
-static int __init msm_minidump_log_init(void)
+int msm_minidump_log_init(void)
 {
 	register_kernel_sections();
 	is_vmap_stack = IS_ENABLED(CONFIG_VMAP_STACK);
@@ -1346,4 +1346,3 @@ static int __init msm_minidump_log_init(void)
 #endif
 	return 0;
 }
-late_initcall(msm_minidump_log_init);

+ 3 - 1
drivers/soc/qcom/minidump_private.h

@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2019, 2021, The Linux Foundation. All rights reserved.
  */
 
 #ifndef __MINIDUMP_PRIVATE_H
@@ -76,4 +76,6 @@ struct md_global_toc {
 	struct md_ss_toc	md_ss_toc[MAX_NUM_OF_SS];
 };
 
+int msm_minidump_log_init(void);
+
 #endif

+ 39 - 8
drivers/soc/qcom/msm_minidump.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #define pr_fmt(fmt) "Minidump: " fmt
@@ -8,6 +8,9 @@
 #include <linux/init.h>
 #include <linux/export.h>
 #include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
 #include <linux/err.h>
 #include <linux/elf.h>
 #include <linux/errno.h>
@@ -505,7 +508,7 @@ static int msm_minidump_add_header(void)
 
 	/* 4th section is linux banner */
 	banner = (char *)ehdr + strtbl_off + MAX_STRTBL_SIZE;
-	strlcpy(banner, linux_banner, strlen(linux_banner) + 1);
+	strlcpy(banner, linux_banner, MAX_STRTBL_SIZE);
 
 	shdr->sh_type = SHT_PROGBITS;
 	shdr->sh_offset = (elf_addr_t)(strtbl_off + MAX_STRTBL_SIZE);
@@ -530,7 +533,16 @@ static int msm_minidump_add_header(void)
 	return 0;
 }
 
-static int __init msm_minidump_init(void)
+static int msm_minidump_driver_remove(struct platform_device *pdev)
+{
+	/* TO-DO.
+	 *Free the required resources and set the global
+	 * variables as minidump is not initialized.
+	 */
+	return 0;
+}
+
+static int msm_minidump_driver_probe(struct platform_device *pdev)
 {
 	unsigned int i;
 	size_t size;
@@ -543,7 +555,7 @@ static int __init msm_minidump_init(void)
 				      &size);
 	if (IS_ERR_OR_NULL(md_global_toc)) {
 		pr_err("SMEM is not initialized.\n");
-		return -ENODEV;
+		return PTR_ERR(md_global_toc);
 	}
 
 	/*Check global minidump support initialization */
@@ -560,7 +572,7 @@ static int __init msm_minidump_init(void)
 	md_ss_toc->encryption_required = MD_SS_ENCR_REQ;
 
 	minidump_table.md_ss_toc = md_ss_toc;
-	minidump_table.md_regions = kzalloc((MAX_NUM_ENTRIES *
+	minidump_table.md_regions = devm_kzalloc(&pdev->dev, (MAX_NUM_ENTRIES *
 				sizeof(struct md_ss_region)), GFP_KERNEL);
 	if (!minidump_table.md_regions)
 		return -ENOMEM;
@@ -584,11 +596,30 @@ static int __init msm_minidump_init(void)
 	pendings = 0;
 	spin_unlock(&mdt_lock);
 
+	/* All updates above should be visible, before init completes */
+	smp_store_release(&md_init_done, true);
+	msm_minidump_log_init();
 	pr_info("Enabled with max number of regions %d\n",
 		CONFIG_MINIDUMP_MAX_ENTRIES);
 
-	/* All updates above should be visible, before init completes */
-	smp_store_release(&md_init_done, true);
 	return 0;
 }
-subsys_initcall(msm_minidump_init)
+
+static const struct of_device_id msm_minidump_of_match[] = {
+	{ .compatible = "qcom,minidump" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, msm_minidump_of_match);
+
+static struct platform_driver msm_minidump_driver = {
+	.driver = {
+		.name = "qcom-minidump",
+		.of_match_table = msm_minidump_of_match,
+	},
+	.probe = msm_minidump_driver_probe,
+	.remove = msm_minidump_driver_remove,
+};
+module_platform_driver(msm_minidump_driver);
+
+MODULE_DESCRIPTION("MSM Mini Dump Driver");
+MODULE_LICENSE("GPL v2");