xen/events: avoid handling the same event on two cpus at the same time
[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)
59                 return -EINVAL;
60
61         switch (resource_type(res)) {
62         case IORESOURCE_IO:
63                 base = devm_ioport_map(dev, res->start, resource_size(res));
64                 if (!base)
65                         return -ENOMEM;
66                 break;
67         case IORESOURCE_MEM:
68                 base = devm_ioremap_resource(dev, res);
69                 if (IS_ERR(base))
70                         return PTR_ERR(base);
71                 break;
72         default:
73                 return -EINVAL;
74         }
75
76         atomic_notifier_chain_register(&panic_notifier_list,
77                                        &pvpanic_panic_nb);
78
79         return 0;
80 }
81
82 static int pvpanic_mmio_remove(struct platform_device *pdev)
83 {
84
85         atomic_notifier_chain_unregister(&panic_notifier_list,
86                                          &pvpanic_panic_nb);
87
88         return 0;
89 }
90
91 static const struct of_device_id pvpanic_mmio_match[] = {
92         { .compatible = "qemu,pvpanic-mmio", },
93         {}
94 };
95
96 static const struct acpi_device_id pvpanic_device_ids[] = {
97         { "QEMU0001", 0 },
98         { "", 0 }
99 };
100 MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
101
102 static struct platform_driver pvpanic_mmio_driver = {
103         .driver = {
104                 .name = "pvpanic-mmio",
105                 .of_match_table = pvpanic_mmio_match,
106                 .acpi_match_table = pvpanic_device_ids,
107         },
108         .probe = pvpanic_mmio_probe,
109         .remove = pvpanic_mmio_remove,
110 };
111 module_platform_driver(pvpanic_mmio_driver);