From 274433704518d1d42de11bfb1dadbac9812a25ff Mon Sep 17 00:00:00 2001
From: Zhang Zekun <zhangzekun11@huawei.com>
Date: Sat, 4 Mar 2023 11:28:46 +0000
Subject: [PATCH] ACPI: memhotplug: export the state of each hotplug device

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I67QNJ
CVE: NA

---------------------------------------------------------

Export the state of a hotplug memory device, and driviers
can use this information to manipulate the hotplug memory
device.

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 drivers/acpi/acpi_memhotplug.c | 6 ++++++
 include/linux/memory_hotplug.h | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index b02fd51e5589..e9b9e2db32cf 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -56,6 +56,9 @@ struct acpi_memory_device {
 	struct list_head res_list;
 };
 
+struct acpi_device *hotplug_mdev[MAX_NUMNODES];
+EXPORT_SYMBOL_GPL(hotplug_mdev);
+
 static acpi_status
 acpi_memory_get_resource(struct acpi_resource *resource, void *context)
 {
@@ -217,6 +220,8 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
 		 * Add num_enable even if add_memory() returns -EEXIST, so the
 		 * device is bound to this driver.
 		 */
+
+		hotplug_mdev[node] = mem_device->device;
 		num_enabled++;
 	}
 	if (!num_enabled) {
@@ -240,6 +245,7 @@ static void acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
 	struct acpi_memory_info *info, *n;
 	int nid = acpi_get_node(handle);
 
+	hotplug_mdev[nid] = NULL;
 	list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
 		if (!info->enabled)
 			continue;
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index b9aeabcce49a..3debe1f7a6c1 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -316,6 +316,8 @@ extern void set_zone_contiguous(struct zone *zone);
 extern void clear_zone_contiguous(struct zone *zone);
 
 #ifdef CONFIG_MEMORY_HOTPLUG
+extern struct acpi_device *hotplug_mdev[MAX_NUMNODES];
+
 extern void __ref free_area_init_core_hotplug(int nid);
 extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
 extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
-- 
GitLab