]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * event.c - exporting ACPI events via procfs | |
4 | * | |
5 | * Copyright (C) 2001, 2002 Andy Grover <[email protected]> | |
6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <[email protected]> | |
7 | * | |
8 | */ | |
9 | ||
10 | #include <linux/spinlock.h> | |
214f2c90 | 11 | #include <linux/export.h> |
1da177e4 LT |
12 | #include <linux/proc_fs.h> |
13 | #include <linux/init.h> | |
14 | #include <linux/poll.h> | |
5a0e3ad6 | 15 | #include <linux/gfp.h> |
8b48463f | 16 | #include <linux/acpi.h> |
864bdfb9 ZR |
17 | #include <net/netlink.h> |
18 | #include <net/genetlink.h> | |
1da177e4 | 19 | |
a192a958 LB |
20 | #include "internal.h" |
21 | ||
1da177e4 | 22 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
f52fd66d | 23 | ACPI_MODULE_NAME("event"); |
1da177e4 | 24 | |
9ee85241 | 25 | /* ACPI notifier chain */ |
c8e773fa | 26 | static BLOCKING_NOTIFIER_HEAD(acpi_chain_head); |
9ee85241 ZR |
27 | |
28 | int acpi_notifier_call_chain(struct acpi_device *dev, u32 type, u32 data) | |
29 | { | |
30 | struct acpi_bus_event event; | |
31 | ||
32 | strcpy(event.device_class, dev->pnp.device_class); | |
33 | strcpy(event.bus_id, dev->pnp.bus_id); | |
34 | event.type = type; | |
35 | event.data = data; | |
36 | return (blocking_notifier_call_chain(&acpi_chain_head, 0, (void *)&event) | |
37 | == NOTIFY_BAD) ? -EINVAL : 0; | |
38 | } | |
39 | EXPORT_SYMBOL(acpi_notifier_call_chain); | |
40 | ||
41 | int register_acpi_notifier(struct notifier_block *nb) | |
42 | { | |
43 | return blocking_notifier_chain_register(&acpi_chain_head, nb); | |
44 | } | |
45 | EXPORT_SYMBOL(register_acpi_notifier); | |
46 | ||
47 | int unregister_acpi_notifier(struct notifier_block *nb) | |
48 | { | |
49 | return blocking_notifier_chain_unregister(&acpi_chain_head, nb); | |
50 | } | |
51 | EXPORT_SYMBOL(unregister_acpi_notifier); | |
52 | ||
864bdfb9 | 53 | #ifdef CONFIG_NET |
e13d8747 | 54 | static unsigned int acpi_event_seqnum; |
864bdfb9 ZR |
55 | struct acpi_genl_event { |
56 | acpi_device_class device_class; | |
57 | char bus_id[15]; | |
58 | u32 type; | |
59 | u32 data; | |
60 | }; | |
61 | ||
62 | /* attributes of acpi_genl_family */ | |
63 | enum { | |
64 | ACPI_GENL_ATTR_UNSPEC, | |
65 | ACPI_GENL_ATTR_EVENT, /* ACPI event info needed by user space */ | |
66 | __ACPI_GENL_ATTR_MAX, | |
67 | }; | |
68 | #define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1) | |
69 | ||
70 | /* commands supported by the acpi_genl_family */ | |
71 | enum { | |
72 | ACPI_GENL_CMD_UNSPEC, | |
73 | ACPI_GENL_CMD_EVENT, /* kernel->user notifications for ACPI events */ | |
74 | __ACPI_GENL_CMD_MAX, | |
75 | }; | |
76 | #define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1) | |
77 | ||
9c977a45 ZR |
78 | #define ACPI_GENL_FAMILY_NAME "acpi_event" |
79 | #define ACPI_GENL_VERSION 0x01 | |
80 | #define ACPI_GENL_MCAST_GROUP_NAME "acpi_mc_group" | |
864bdfb9 | 81 | |
2a94fe48 JB |
82 | static const struct genl_multicast_group acpi_event_mcgrps[] = { |
83 | { .name = ACPI_GENL_MCAST_GROUP_NAME, }, | |
84 | }; | |
85 | ||
56989f6d | 86 | static struct genl_family acpi_event_genl_family __ro_after_init = { |
489111e5 | 87 | .module = THIS_MODULE, |
9c977a45 | 88 | .name = ACPI_GENL_FAMILY_NAME, |
864bdfb9 ZR |
89 | .version = ACPI_GENL_VERSION, |
90 | .maxattr = ACPI_GENL_ATTR_MAX, | |
2a94fe48 JB |
91 | .mcgrps = acpi_event_mcgrps, |
92 | .n_mcgrps = ARRAY_SIZE(acpi_event_mcgrps), | |
864bdfb9 ZR |
93 | }; |
94 | ||
962ce8ca ZR |
95 | int acpi_bus_generate_netlink_event(const char *device_class, |
96 | const char *bus_id, | |
864bdfb9 ZR |
97 | u8 type, int data) |
98 | { | |
99 | struct sk_buff *skb; | |
100 | struct nlattr *attr; | |
101 | struct acpi_genl_event *event; | |
102 | void *msg_header; | |
103 | int size; | |
864bdfb9 ZR |
104 | |
105 | /* allocate memory */ | |
106 | size = nla_total_size(sizeof(struct acpi_genl_event)) + | |
107 | nla_total_size(0); | |
108 | ||
109 | skb = genlmsg_new(size, GFP_ATOMIC); | |
110 | if (!skb) | |
111 | return -ENOMEM; | |
112 | ||
113 | /* add the genetlink message header */ | |
114 | msg_header = genlmsg_put(skb, 0, acpi_event_seqnum++, | |
115 | &acpi_event_genl_family, 0, | |
116 | ACPI_GENL_CMD_EVENT); | |
117 | if (!msg_header) { | |
118 | nlmsg_free(skb); | |
119 | return -ENOMEM; | |
120 | } | |
121 | ||
122 | /* fill the data */ | |
123 | attr = | |
124 | nla_reserve(skb, ACPI_GENL_ATTR_EVENT, | |
125 | sizeof(struct acpi_genl_event)); | |
126 | if (!attr) { | |
127 | nlmsg_free(skb); | |
128 | return -EINVAL; | |
129 | } | |
130 | ||
131 | event = nla_data(attr); | |
864bdfb9 ZR |
132 | memset(event, 0, sizeof(struct acpi_genl_event)); |
133 | ||
962ce8ca ZR |
134 | strcpy(event->device_class, device_class); |
135 | strcpy(event->bus_id, bus_id); | |
864bdfb9 ZR |
136 | event->type = type; |
137 | event->data = data; | |
138 | ||
139 | /* send multicast genetlink message */ | |
053c095a | 140 | genlmsg_end(skb, msg_header); |
864bdfb9 | 141 | |
2a94fe48 | 142 | genlmsg_multicast(&acpi_event_genl_family, skb, 0, 0, GFP_ATOMIC); |
864bdfb9 ZR |
143 | return 0; |
144 | } | |
864bdfb9 | 145 | |
962ce8ca ZR |
146 | EXPORT_SYMBOL(acpi_bus_generate_netlink_event); |
147 | ||
56989f6d | 148 | static int __init acpi_event_genetlink_init(void) |
864bdfb9 | 149 | { |
2a94fe48 | 150 | return genl_register_family(&acpi_event_genl_family); |
864bdfb9 ZR |
151 | } |
152 | ||
153 | #else | |
3e069ee0 LB |
154 | int acpi_bus_generate_netlink_event(const char *device_class, |
155 | const char *bus_id, | |
156 | u8 type, int data) | |
864bdfb9 ZR |
157 | { |
158 | return 0; | |
159 | } | |
864bdfb9 | 160 | |
66baf327 | 161 | EXPORT_SYMBOL(acpi_bus_generate_netlink_event); |
962ce8ca | 162 | |
864bdfb9 ZR |
163 | static int acpi_event_genetlink_init(void) |
164 | { | |
165 | return -ENODEV; | |
166 | } | |
167 | #endif | |
168 | ||
1da177e4 LT |
169 | static int __init acpi_event_init(void) |
170 | { | |
1da177e4 LT |
171 | int error = 0; |
172 | ||
1da177e4 | 173 | if (acpi_disabled) |
d550d98d | 174 | return 0; |
1da177e4 | 175 | |
864bdfb9 ZR |
176 | /* create genetlink for acpi event */ |
177 | error = acpi_event_genetlink_init(); | |
178 | if (error) | |
179 | printk(KERN_WARNING PREFIX | |
180 | "Failed to create genetlink family for ACPI event\n"); | |
864bdfb9 | 181 | return 0; |
1da177e4 LT |
182 | } |
183 | ||
864bdfb9 | 184 | fs_initcall(acpi_event_init); |