From: Peng Hao <peng.hao2@zte.com.cn>
To: gregkh@linuxfoundation.org, arnd@arndb.de, andy.shevchenko@gmail.com
Cc: linux-kernel@vger.kernel.org, Peng Hao <peng.hao2@zte.com.cn>
Subject: [PATCH V5 2/3] misc/pvpanic : add pci interface for pvpanic
Date: Wed, 19 Dec 2018 16:04:51 +0800 [thread overview]
Message-ID: <1545206692-32183-2-git-send-email-peng.hao2@zte.com.cn> (raw)
In-Reply-To: <1545206692-32183-1-git-send-email-peng.hao2@zte.com.cn>
Support pvpanic as a pci device in guest kernel.
Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
---
drivers/misc/pvpanic.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 70 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
index f84ed30..c30bf62 100644
--- a/drivers/misc/pvpanic.c
+++ b/drivers/misc/pvpanic.c
@@ -13,9 +13,12 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/pci.h>
#include <linux/platform_device.h>
#include <linux/types.h>
+#define PCI_VENDOR_ID_REDHAT 0x1b36
+#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0101
static void __iomem *base;
#define PVPANIC_PANICKED (1 << 0)
@@ -172,12 +175,76 @@ static int pvpanic_mmio_remove(struct platform_device *pdev)
.remove = pvpanic_mmio_remove,
};
+#ifdef CONFIG_PCI
+static const struct pci_device_id pvpanic_pci_id_tbl[] = {
+ { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC),},
+ {}
+};
+
+static int pvpanic_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ int ret;
+
+ ret = pcim_enable_device(pdev);
+ if (ret < 0)
+ return ret;
+
+ ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
+ if (ret)
+ return ret;
+
+ base = pcim_iomap_table(pdev)[0];
+
+ atomic_notifier_chain_register(&panic_notifier_list,
+ &pvpanic_panic_nb);
+ return 0;
+}
+
+static void pvpanic_pci_remove(struct pci_dev *pdev)
+{
+ atomic_notifier_chain_unregister(&panic_notifier_list,
+ &pvpanic_panic_nb);
+}
+
+static struct pci_driver pvpanic_pci_driver = {
+ .name = "pvpanic-pci",
+ .id_table = pvpanic_pci_id_tbl,
+ .probe = pvpanic_pci_probe,
+ .remove = pvpanic_pci_remove,
+};
+
+static int pvpanic_register_pci_driver(void)
+{
+ return pci_register_driver(&pvpanic_pci_driver);
+}
+
+static void pvpanic_unregister_pci_driver(void)
+{
+ pci_unregister_driver(&pvpanic_pci_driver);
+}
+#else
+static int pvpanic_register_pci_driver(void)
+{
+ return 0;
+}
+
+static void pvpanic_unregister_pci_driver(void) {}
+#endif
+
static int __init pvpanic_mmio_init(void)
{
+ int r1, r2;
+
if (acpi_disabled)
- return platform_driver_register(&pvpanic_mmio_driver);
+ r1 = platform_driver_register(&pvpanic_mmio_driver);
+ else
+ r1 = pvpanic_register_acpi_driver();
+ r2 = pvpanic_register_pci_driver();
+ if (r1 && r2) /* all drivers register failed */
+ return 1;
else
- return pvpanic_register_acpi_driver();
+ return 0;
}
static void __exit pvpanic_mmio_exit(void)
@@ -186,6 +253,7 @@ static void __exit pvpanic_mmio_exit(void)
platform_driver_unregister(&pvpanic_mmio_driver);
else
pvpanic_unregister_acpi_driver();
+ pvpanic_unregister_pci_driver();
}
module_init(pvpanic_mmio_init);
--
1.8.3.1
next prev parent reply other threads:[~2018-12-19 7:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-19 8:04 [PATCH V5 1/3] misc/pvpanic: return 0 for empty body register function Peng Hao
2018-12-19 8:04 ` Peng Hao [this message]
2018-12-19 8:04 ` [PATCH V5 3/3] misc/pvpanic : add pci dependency in Kconfig Peng Hao
2018-12-19 8:28 ` [PATCH V5 1/3] misc/pvpanic: return 0 for empty body register function Greg KH
[not found] ` <201812191703216682499@zte.com.cn>
2018-12-19 9:46 ` [PATCH V5 1/3] misc/pvpanic: return 0 for empty body registerfunction Greg KH
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=1545206692-32183-2-git-send-email-peng.hao2@zte.com.cn \
--to=peng.hao2@zte.com.cn \
--cc=andy.shevchenko@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.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).