]>
Commit | Line | Data |
---|---|---|
8b10acd7 HT |
1 | /* |
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> | |
8b48463f | 27 | #include <linux/acpi.h> |
8b10acd7 HT |
28 | |
29 | MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>"); | |
30 | MODULE_DESCRIPTION("pvpanic device driver"); | |
31 | MODULE_LICENSE("GPL"); | |
32 | ||
33 | static int pvpanic_add(struct acpi_device *device); | |
34 | static int pvpanic_remove(struct acpi_device *device); | |
35 | ||
36 | static const struct acpi_device_id pvpanic_device_ids[] = { | |
37 | { "QEMU0001", 0 }, | |
38 | { "", 0 }, | |
39 | }; | |
40 | MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids); | |
41 | ||
42 | #define PVPANIC_PANICKED (1 << 0) | |
43 | ||
44 | static u16 port; | |
45 | ||
46 | static 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 | ||
57 | static void | |
58 | pvpanic_send_event(unsigned int event) | |
59 | { | |
60 | outb(event, port); | |
61 | } | |
62 | ||
63 | static int | |
64 | pvpanic_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 | ||
71 | static struct notifier_block pvpanic_panic_nb = { | |
72 | .notifier_call = pvpanic_panic_notify, | |
73 | }; | |
74 | ||
75 | ||
76 | static acpi_status | |
77 | pvpanic_walk_resources(struct acpi_resource *res, void *context) | |
78 | { | |
79 | switch (res->type) { | |
80 | case ACPI_RESOURCE_TYPE_END_TAG: | |
81 | return AE_OK; | |
82 | ||
83 | case ACPI_RESOURCE_TYPE_IO: | |
84 | port = res->data.io.minimum; | |
85 | return AE_OK; | |
86 | ||
87 | default: | |
88 | return AE_ERROR; | |
89 | } | |
90 | } | |
91 | ||
92 | static int pvpanic_add(struct acpi_device *device) | |
93 | { | |
94 | acpi_status status; | |
95 | u64 ret; | |
96 | ||
97 | status = acpi_evaluate_integer(device->handle, "_STA", NULL, | |
98 | &ret); | |
99 | ||
100 | if (ACPI_FAILURE(status) || (ret & 0x0B) != 0x0B) | |
101 | return -ENODEV; | |
102 | ||
103 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, | |
104 | pvpanic_walk_resources, NULL); | |
105 | ||
106 | if (!port) | |
107 | return -ENODEV; | |
108 | ||
109 | atomic_notifier_chain_register(&panic_notifier_list, | |
110 | &pvpanic_panic_nb); | |
111 | ||
112 | return 0; | |
113 | } | |
114 | ||
115 | static int pvpanic_remove(struct acpi_device *device) | |
116 | { | |
117 | ||
118 | atomic_notifier_chain_unregister(&panic_notifier_list, | |
119 | &pvpanic_panic_nb); | |
120 | return 0; | |
121 | } | |
122 | ||
123 | module_acpi_driver(pvpanic_driver); |