blob: 49c59e1d299db5cc7b0c8cbf6305805f7573ef5d [file] [log] [blame]
Hu Tao8b10acd2013-05-08 11:15:32 +08001/*
2 * pvpanic.c - pvpanic Device Support
3 *
4 * Copyright (C) 2013 Fujitsu.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/types.h>
Lv Zheng8b484632013-12-03 08:49:16 +080027#include <linux/acpi.h>
Hu Tao8b10acd2013-05-08 11:15:32 +080028
29MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
30MODULE_DESCRIPTION("pvpanic device driver");
31MODULE_LICENSE("GPL");
32
33static int pvpanic_add(struct acpi_device *device);
34static int pvpanic_remove(struct acpi_device *device);
35
36static const struct acpi_device_id pvpanic_device_ids[] = {
37 { "QEMU0001", 0 },
38 { "", 0 },
39};
40MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
41
42#define PVPANIC_PANICKED (1 << 0)
43
44static u16 port;
45
46static struct acpi_driver pvpanic_driver = {
47 .name = "pvpanic",
48 .class = "QEMU",
49 .ids = pvpanic_device_ids,
50 .ops = {
51 .add = pvpanic_add,
52 .remove = pvpanic_remove,
53 },
54 .owner = THIS_MODULE,
55};
56
57static void
58pvpanic_send_event(unsigned int event)
59{
60 outb(event, port);
61}
62
63static int
64pvpanic_panic_notify(struct notifier_block *nb, unsigned long code,
65 void *unused)
66{
67 pvpanic_send_event(PVPANIC_PANICKED);
68 return NOTIFY_DONE;
69}
70
71static struct notifier_block pvpanic_panic_nb = {
72 .notifier_call = pvpanic_panic_notify,
Takashi Iwai79398312014-05-06 17:52:26 +020073 .priority = 1, /* let this called before broken drm_fb_helper */
Hu Tao8b10acd2013-05-08 11:15:32 +080074};
75
76
77static acpi_status
78pvpanic_walk_resources(struct acpi_resource *res, void *context)
79{
Peng Haod2ae1712018-11-06 22:57:13 +080080 struct resource r;
Hu Tao8b10acd2013-05-08 11:15:32 +080081
Peng Haod2ae1712018-11-06 22:57:13 +080082 if (acpi_dev_resource_io(res, &r)) {
83 port = r.start;
Hu Tao8b10acd2013-05-08 11:15:32 +080084 return AE_OK;
Hu Tao8b10acd2013-05-08 11:15:32 +080085 }
Peng Haod2ae1712018-11-06 22:57:13 +080086
87 return AE_ERROR;
Hu Tao8b10acd2013-05-08 11:15:32 +080088}
89
90static int pvpanic_add(struct acpi_device *device)
91{
Radim Krčmář55cd3f02015-05-29 22:18:52 +020092 int ret;
Hu Tao8b10acd2013-05-08 11:15:32 +080093
Radim Krčmář55cd3f02015-05-29 22:18:52 +020094 ret = acpi_bus_get_status(device);
95 if (ret < 0)
96 return ret;
Hu Tao8b10acd2013-05-08 11:15:32 +080097
Radim Krčmář55cd3f02015-05-29 22:18:52 +020098 if (!device->status.enabled || !device->status.functional)
Hu Tao8b10acd2013-05-08 11:15:32 +080099 return -ENODEV;
100
101 acpi_walk_resources(device->handle, METHOD_NAME__CRS,
102 pvpanic_walk_resources, NULL);
103
104 if (!port)
105 return -ENODEV;
106
107 atomic_notifier_chain_register(&panic_notifier_list,
108 &pvpanic_panic_nb);
109
110 return 0;
111}
112
113static int pvpanic_remove(struct acpi_device *device)
114{
115
116 atomic_notifier_chain_unregister(&panic_notifier_list,
117 &pvpanic_panic_nb);
118 return 0;
119}
120
121module_acpi_driver(pvpanic_driver);