2 * event.c - exporting ACPI events via procfs
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
9 #include <linux/spinlock.h>
10 #include <linux/export.h>
11 #include <linux/proc_fs.h>
12 #include <linux/init.h>
13 #include <linux/poll.h>
14 #include <linux/gfp.h>
15 #include <linux/acpi.h>
16 #include <net/netlink.h>
17 #include <net/genetlink.h>
21 #define _COMPONENT ACPI_SYSTEM_COMPONENT
22 ACPI_MODULE_NAME("event");
24 /* ACPI notifier chain */
25 static BLOCKING_NOTIFIER_HEAD(acpi_chain_head
);
27 int acpi_notifier_call_chain(struct acpi_device
*dev
, u32 type
, u32 data
)
29 struct acpi_bus_event event
;
31 strcpy(event
.device_class
, dev
->pnp
.device_class
);
32 strcpy(event
.bus_id
, dev
->pnp
.bus_id
);
35 return (blocking_notifier_call_chain(&acpi_chain_head
, 0, (void *)&event
)
36 == NOTIFY_BAD
) ? -EINVAL
: 0;
38 EXPORT_SYMBOL(acpi_notifier_call_chain
);
40 int register_acpi_notifier(struct notifier_block
*nb
)
42 return blocking_notifier_chain_register(&acpi_chain_head
, nb
);
44 EXPORT_SYMBOL(register_acpi_notifier
);
46 int unregister_acpi_notifier(struct notifier_block
*nb
)
48 return blocking_notifier_chain_unregister(&acpi_chain_head
, nb
);
50 EXPORT_SYMBOL(unregister_acpi_notifier
);
53 static unsigned int acpi_event_seqnum
;
54 struct acpi_genl_event
{
55 acpi_device_class device_class
;
61 /* attributes of acpi_genl_family */
63 ACPI_GENL_ATTR_UNSPEC
,
64 ACPI_GENL_ATTR_EVENT
, /* ACPI event info needed by user space */
67 #define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1)
69 /* commands supported by the acpi_genl_family */
72 ACPI_GENL_CMD_EVENT
, /* kernel->user notifications for ACPI events */
75 #define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1)
77 #define ACPI_GENL_FAMILY_NAME "acpi_event"
78 #define ACPI_GENL_VERSION 0x01
79 #define ACPI_GENL_MCAST_GROUP_NAME "acpi_mc_group"
81 static const struct genl_multicast_group acpi_event_mcgrps
[] = {
82 { .name
= ACPI_GENL_MCAST_GROUP_NAME
, },
85 static struct genl_family acpi_event_genl_family
= {
86 .id
= GENL_ID_GENERATE
,
87 .name
= ACPI_GENL_FAMILY_NAME
,
88 .version
= ACPI_GENL_VERSION
,
89 .maxattr
= ACPI_GENL_ATTR_MAX
,
90 .mcgrps
= acpi_event_mcgrps
,
91 .n_mcgrps
= ARRAY_SIZE(acpi_event_mcgrps
),
94 int acpi_bus_generate_netlink_event(const char *device_class
,
100 struct acpi_genl_event
*event
;
105 /* allocate memory */
106 size
= nla_total_size(sizeof(struct acpi_genl_event
)) +
109 skb
= genlmsg_new(size
, GFP_ATOMIC
);
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
);
124 nla_reserve(skb
, ACPI_GENL_ATTR_EVENT
,
125 sizeof(struct acpi_genl_event
));
131 event
= nla_data(attr
);
132 memset(event
, 0, sizeof(struct acpi_genl_event
));
134 strcpy(event
->device_class
, device_class
);
135 strcpy(event
->bus_id
, bus_id
);
139 /* send multicast genetlink message */
140 result
= genlmsg_end(skb
, msg_header
);
146 genlmsg_multicast(&acpi_event_genl_family
, skb
, 0, 0, GFP_ATOMIC
);
150 EXPORT_SYMBOL(acpi_bus_generate_netlink_event
);
152 static int acpi_event_genetlink_init(void)
154 return genl_register_family(&acpi_event_genl_family
);
158 int acpi_bus_generate_netlink_event(const char *device_class
,
165 EXPORT_SYMBOL(acpi_bus_generate_netlink_event
);
167 static int acpi_event_genetlink_init(void)
173 static int __init
acpi_event_init(void)
180 /* create genetlink for acpi event */
181 error
= acpi_event_genetlink_init();
183 printk(KERN_WARNING PREFIX
184 "Failed to create genetlink family for ACPI event\n");
188 fs_initcall(acpi_event_init
);