1 // SPDX-License-Identifier: GPL-2.0
3 * event.c - exporting ACPI events via procfs
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
10 #include <linux/spinlock.h>
11 #include <linux/export.h>
12 #include <linux/proc_fs.h>
13 #include <linux/init.h>
14 #include <linux/poll.h>
15 #include <linux/gfp.h>
16 #include <linux/acpi.h>
17 #include <net/netlink.h>
18 #include <net/genetlink.h>
22 /* ACPI notifier chain */
23 static BLOCKING_NOTIFIER_HEAD(acpi_chain_head
);
25 int acpi_notifier_call_chain(struct acpi_device
*dev
, u32 type
, u32 data
)
27 struct acpi_bus_event event
;
29 strcpy(event
.device_class
, dev
->pnp
.device_class
);
30 strcpy(event
.bus_id
, dev
->pnp
.bus_id
);
33 return (blocking_notifier_call_chain(&acpi_chain_head
, 0, (void *)&event
)
34 == NOTIFY_BAD
) ? -EINVAL
: 0;
36 EXPORT_SYMBOL(acpi_notifier_call_chain
);
38 int register_acpi_notifier(struct notifier_block
*nb
)
40 return blocking_notifier_chain_register(&acpi_chain_head
, nb
);
42 EXPORT_SYMBOL(register_acpi_notifier
);
44 int unregister_acpi_notifier(struct notifier_block
*nb
)
46 return blocking_notifier_chain_unregister(&acpi_chain_head
, nb
);
48 EXPORT_SYMBOL(unregister_acpi_notifier
);
51 static unsigned int acpi_event_seqnum
;
52 struct acpi_genl_event
{
53 acpi_device_class device_class
;
59 /* attributes of acpi_genl_family */
61 ACPI_GENL_ATTR_UNSPEC
,
62 ACPI_GENL_ATTR_EVENT
, /* ACPI event info needed by user space */
65 #define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1)
67 /* commands supported by the acpi_genl_family */
70 ACPI_GENL_CMD_EVENT
, /* kernel->user notifications for ACPI events */
73 #define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1)
75 #define ACPI_GENL_FAMILY_NAME "acpi_event"
76 #define ACPI_GENL_VERSION 0x01
77 #define ACPI_GENL_MCAST_GROUP_NAME "acpi_mc_group"
79 static const struct genl_multicast_group acpi_event_mcgrps
[] = {
80 { .name
= ACPI_GENL_MCAST_GROUP_NAME
, },
83 static struct genl_family acpi_event_genl_family __ro_after_init
= {
84 .module
= THIS_MODULE
,
85 .name
= ACPI_GENL_FAMILY_NAME
,
86 .version
= ACPI_GENL_VERSION
,
87 .maxattr
= ACPI_GENL_ATTR_MAX
,
88 .mcgrps
= acpi_event_mcgrps
,
89 .n_mcgrps
= ARRAY_SIZE(acpi_event_mcgrps
),
92 int acpi_bus_generate_netlink_event(const char *device_class
,
98 struct acpi_genl_event
*event
;
102 /* allocate memory */
103 size
= nla_total_size(sizeof(struct acpi_genl_event
)) +
106 skb
= genlmsg_new(size
, GFP_ATOMIC
);
110 /* add the genetlink message header */
111 msg_header
= genlmsg_put(skb
, 0, acpi_event_seqnum
++,
112 &acpi_event_genl_family
, 0,
113 ACPI_GENL_CMD_EVENT
);
121 nla_reserve(skb
, ACPI_GENL_ATTR_EVENT
,
122 sizeof(struct acpi_genl_event
));
128 event
= nla_data(attr
);
129 memset(event
, 0, sizeof(struct acpi_genl_event
));
131 strscpy(event
->device_class
, device_class
, sizeof(event
->device_class
));
132 strscpy(event
->bus_id
, bus_id
, sizeof(event
->bus_id
));
136 /* send multicast genetlink message */
137 genlmsg_end(skb
, msg_header
);
139 genlmsg_multicast(&acpi_event_genl_family
, skb
, 0, 0, GFP_ATOMIC
);
143 EXPORT_SYMBOL(acpi_bus_generate_netlink_event
);
145 static int __init
acpi_event_genetlink_init(void)
147 return genl_register_family(&acpi_event_genl_family
);
151 int acpi_bus_generate_netlink_event(const char *device_class
,
158 EXPORT_SYMBOL(acpi_bus_generate_netlink_event
);
160 static int acpi_event_genetlink_init(void)
166 static int __init
acpi_event_init(void)
173 /* create genetlink for acpi event */
174 error
= acpi_event_genetlink_init();
176 printk(KERN_WARNING PREFIX
177 "Failed to create genetlink family for ACPI event\n");
181 fs_initcall(acpi_event_init
);