1 // SPDX-License-Identifier: GPL-2.0+
3 * Pvpanic Device Support
5 * Copyright (C) 2013 Fujitsu.
6 * Copyright (C) 2018 ZTE.
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/kernel.h>
13 #include <linux/kexec.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/types.h>
19 #include <uapi/misc/pvpanic.h>
21 static void __iomem *base;
23 MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
24 MODULE_DESCRIPTION("pvpanic device driver");
25 MODULE_LICENSE("GPL");
28 pvpanic_send_event(unsigned int event)
30 iowrite8(event, base);
34 pvpanic_panic_notify(struct notifier_block *nb, unsigned long code,
37 unsigned int event = PVPANIC_PANICKED;
39 if (kexec_crash_loaded())
40 event = PVPANIC_CRASH_LOADED;
42 pvpanic_send_event(event);
47 static struct notifier_block pvpanic_panic_nb = {
48 .notifier_call = pvpanic_panic_notify,
49 .priority = 1, /* let this called before broken drm_fb_helper */
52 static int pvpanic_mmio_probe(struct platform_device *pdev)
54 struct device *dev = &pdev->dev;
57 res = platform_get_mem_or_io(pdev, 0);
61 switch (resource_type(res)) {
63 base = devm_ioport_map(dev, res->start, resource_size(res));
68 base = devm_ioremap_resource(dev, res);
76 atomic_notifier_chain_register(&panic_notifier_list,
82 static int pvpanic_mmio_remove(struct platform_device *pdev)
85 atomic_notifier_chain_unregister(&panic_notifier_list,
91 static const struct of_device_id pvpanic_mmio_match[] = {
92 { .compatible = "qemu,pvpanic-mmio", },
96 static const struct acpi_device_id pvpanic_device_ids[] = {
100 MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
102 static struct platform_driver pvpanic_mmio_driver = {
104 .name = "pvpanic-mmio",
105 .of_match_table = pvpanic_mmio_match,
106 .acpi_match_table = pvpanic_device_ids,
108 .probe = pvpanic_mmio_probe,
109 .remove = pvpanic_mmio_remove,
111 module_platform_driver(pvpanic_mmio_driver);