Merge tag 'f2fs-for-5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeu...
[linux-2.6-microblaze.git] / drivers / misc / pvpanic.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Pvpanic Device Support
4  *
5  *  Copyright (C) 2013 Fujitsu.
6  *  Copyright (C) 2018 ZTE.
7  */
8
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10
11 #include <linux/io.h>
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>
18
19 #include <uapi/misc/pvpanic.h>
20
21 static void __iomem *base;
22
23 MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
24 MODULE_DESCRIPTION("pvpanic device driver");
25 MODULE_LICENSE("GPL");
26
27 static void
28 pvpanic_send_event(unsigned int event)
29 {
30         iowrite8(event, base);
31 }
32
33 static int
34 pvpanic_panic_notify(struct notifier_block *nb, unsigned long code,
35                      void *unused)
36 {
37         unsigned int event = PVPANIC_PANICKED;
38
39         if (kexec_crash_loaded())
40                 event = PVPANIC_CRASH_LOADED;
41
42         pvpanic_send_event(event);
43
44         return NOTIFY_DONE;
45 }
46
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 */
50 };
51
52 static int pvpanic_mmio_probe(struct platform_device *pdev)
53 {
54         struct device *dev = &pdev->dev;
55         struct resource *res;
56
57         res = platform_get_mem_or_io(pdev, 0);
58         if (res && resource_type(res) == IORESOURCE_IO)
59                 base = devm_ioport_map(dev, res->start, resource_size(res));
60         else
61                 base = devm_ioremap_resource(dev, res);
62         if (IS_ERR(base))
63                 return PTR_ERR(base);
64
65         atomic_notifier_chain_register(&panic_notifier_list,
66                                        &pvpanic_panic_nb);
67
68         return 0;
69 }
70
71 static int pvpanic_mmio_remove(struct platform_device *pdev)
72 {
73
74         atomic_notifier_chain_unregister(&panic_notifier_list,
75                                          &pvpanic_panic_nb);
76
77         return 0;
78 }
79
80 static const struct of_device_id pvpanic_mmio_match[] = {
81         { .compatible = "qemu,pvpanic-mmio", },
82         {}
83 };
84
85 static const struct acpi_device_id pvpanic_device_ids[] = {
86         { "QEMU0001", 0 },
87         { "", 0 }
88 };
89 MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
90
91 static struct platform_driver pvpanic_mmio_driver = {
92         .driver = {
93                 .name = "pvpanic-mmio",
94                 .of_match_table = pvpanic_mmio_match,
95                 .acpi_match_table = pvpanic_device_ids,
96         },
97         .probe = pvpanic_mmio_probe,
98         .remove = pvpanic_mmio_remove,
99 };
100 module_platform_driver(pvpanic_mmio_driver);