mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mihai Carabas <mihai.carabas@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: gregkh@linuxfoundation.org, arnd@arndb.de, rdunlap@infradead.org,
	bobo.shaobowang@huawei.com,
	Mihai Carabas <mihai.carabas@oracle.com>
Subject: [PATCH v3 2/3] misc/pvpanic: probe multiple instances
Date: Fri, 12 Feb 2021 21:32:27 +0200	[thread overview]
Message-ID: <1613158348-19976-3-git-send-email-mihai.carabas@oracle.com> (raw)
In-Reply-To: <1613158348-19976-1-git-send-email-mihai.carabas@oracle.com>

Create the mecahism that allows multiple pvpanic instances to call
pvpanic_probe and receive panic events. A global list will retain all the
mapped addresses where to write panic events.

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
---
 drivers/misc/pvpanic/pvpanic-mmio.c |  9 ++---
 drivers/misc/pvpanic/pvpanic.c      | 76 ++++++++++++++++++++++++++++++++-----
 drivers/misc/pvpanic/pvpanic.h      |  5 +--
 3 files changed, 73 insertions(+), 17 deletions(-)

diff --git a/drivers/misc/pvpanic/pvpanic-mmio.c b/drivers/misc/pvpanic/pvpanic-mmio.c
index 7454eeb..5425369 100644
--- a/drivers/misc/pvpanic/pvpanic-mmio.c
+++ b/drivers/misc/pvpanic/pvpanic-mmio.c
@@ -22,11 +22,12 @@
 MODULE_DESCRIPTION("pvpanic device driver");
 MODULE_LICENSE("GPL");
 
+static void __iomem *base;
+
 static int pvpanic_mmio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct resource *res;
-	void __iomem *base;
 
 	res = platform_get_mem_or_io(pdev, 0);
 	if (!res)
@@ -47,15 +48,13 @@ static int pvpanic_mmio_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	pvpanic_probe(base);
-
-	return 0;
+	return pvpanic_probe(base);
 }
 
 static int pvpanic_mmio_remove(struct platform_device *pdev)
 {
 
-	pvpanic_remove();
+	pvpanic_remove(base);
 
 	return 0;
 }
diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c
index 652ae01..43b65a3 100644
--- a/drivers/misc/pvpanic/pvpanic.c
+++ b/drivers/misc/pvpanic/pvpanic.c
@@ -14,15 +14,30 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/types.h>
+#include <linux/cdev.h>
+#include <linux/list.h>
+#include <linux/slab.h>
 
 #include <uapi/misc/pvpanic.h>
 
-static void __iomem *base;
+struct pvpanic_instance {
+	void __iomem *base;
+	struct list_head list;
+};
+
+struct list_head pvpanic_list;
+spinlock_t pvpanic_lock;
 
 static void
 pvpanic_send_event(unsigned int event)
 {
-	iowrite8(event, base);
+	struct pvpanic_instance *pi_cur;
+
+	spin_lock(&pvpanic_lock);
+	list_for_each_entry(pi_cur, &pvpanic_list, list) {
+		iowrite8(event, pi_cur->base);
+	}
+	spin_unlock(&pvpanic_lock);
 }
 
 static int
@@ -44,19 +59,62 @@
 	.priority = 1, /* let this called before broken drm_fb_helper */
 };
 
-void pvpanic_probe(void __iomem *pbase)
+int pvpanic_probe(void __iomem *pbase)
 {
-	base = pbase;
-	atomic_notifier_chain_register(&panic_notifier_list,
-				       &pvpanic_panic_nb);
+	struct pvpanic_instance *pi;
+
+	if(!pbase)
+		return -EINVAL;
+
+	pi = kmalloc(sizeof(*pi), GFP_ATOMIC);
+	if (!pi)
+		return -ENOMEM;
+
+	pi->base = pbase;
+	spin_lock(&pvpanic_lock);
+	list_add(&pi->list, &pvpanic_list);
+	spin_unlock(&pvpanic_lock);
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(pvpanic_probe);
 
-void pvpanic_remove(void)
+void pvpanic_remove(void __iomem *pbase)
+{
+	struct pvpanic_instance *pi_cur, *pi_next;
+
+	if(!pbase)
+		return -EINVAL;
+
+	spin_lock(&pvpanic_lock);
+	list_for_each_entry_safe(pi_cur, pi_next, &pvpanic_list, list) {
+		if (pi_cur->base == pbase) {
+			list_del(&pi_cur->list);
+			kfree(pi_cur);
+			break;
+		}
+	}
+	spin_unlock(&pvpanic_lock);
+}
+EXPORT_SYMBOL_GPL(pvpanic_remove);
+
+static int pvpanic_init(void)
 {
+	INIT_LIST_HEAD(&pvpanic_list);
+	spin_lock_init(&pvpanic_lock);
+
+	atomic_notifier_chain_register(&panic_notifier_list,
+				       &pvpanic_panic_nb);
 
+	return 0;
+}
+
+static void pvpanic_exit(void)
+{
 	atomic_notifier_chain_unregister(&panic_notifier_list,
 					 &pvpanic_panic_nb);
-	base = NULL;
+
 }
-EXPORT_SYMBOL_GPL(pvpanic_remove);
+
+module_init(pvpanic_init);
+module_exit(pvpanic_exit);
diff --git a/drivers/misc/pvpanic/pvpanic.h b/drivers/misc/pvpanic/pvpanic.h
index 7e75dce..02023d7 100644
--- a/drivers/misc/pvpanic/pvpanic.h
+++ b/drivers/misc/pvpanic/pvpanic.h
@@ -8,10 +8,9 @@
 #ifndef PVPANIC_H_
 #define PVPANIC_H_
 
-
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-void pvpanic_probe(void __iomem *base);
-void pvpanic_remove(void);
+int pvpanic_probe(void __iomem *base);
+void pvpanic_remove(void __iomem *base);
 
 #endif /* PVPANIC_H_ */
-- 
1.8.3.1


  parent reply	other threads:[~2021-02-12 20:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 19:32 [PATCH v3] add support for pci in the pvpanic driver Mihai Carabas
2021-02-12 19:32 ` [PATCH v3 1/3] misc/pvpanic: split-up generic and platform dependent code Mihai Carabas
2021-02-12 20:27   ` Arnd Bergmann
2021-02-12 23:01   ` kernel test robot
2021-02-12 19:32 ` Mihai Carabas [this message]
2021-02-13  2:02   ` [PATCH v3 2/3] misc/pvpanic: probe multiple instances kernel test robot
2021-02-12 19:32 ` [PATCH v3 3/3] misc/pvpanic: add PCI driver Mihai Carabas

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=1613158348-19976-3-git-send-email-mihai.carabas@oracle.com \
    --to=mihai.carabas@oracle.com \
    --cc=arnd@arndb.de \
    --cc=bobo.shaobowang@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.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

all inboxes | Powered by JetHome®