netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [-mm] ACPI: export ACPI events via netlink
@ 2007-05-22  9:47 Zhang Rui
  2007-05-22 10:05 ` Samuel Ortiz
  2007-05-22 11:03 ` jamal
  0 siblings, 2 replies; 71+ messages in thread
From: Zhang Rui @ 2007-05-22  9:47 UTC (permalink / raw)
  To: linux-acpi; +Cc: lenb, netdev

From: Zhang Rui <rui.zhang@intel.com>

Export ACPI events via netlink.
A netlink message is broadcasted when an ACPI event is generated.

Note: The behaviour of how ACPI event works nowadays is not changed.
	Netlink is used to export ACPI event instead of /proc/acpi/event someday,
	but not now.
	This patch only adds the function of sending netlink messages
	when an ACPI event is generated.
	Following is an example of how to receive ACPI event messages.

#include <linux/socket.h>
#include <linux/netlink.h>
#include "stdio.h"

#define NETLINK_ACPI_EVENT	20
#define SOCK_RAW		3

struct acpi_event{
	char device_class[20];
	char bus_id[15];
	unsigned int type;
	unsigned int data;
};

struct sockaddr_nl src_addr, dest_addr;
int sock_fd;
struct msghdr msg;
struct iovec iov;


int main (void){
	int i = 10;
	int result;
	struct acpi_event event;

	sock_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ACPI_EVENT);
	if (sock_fd == -1) {
		printf("Socket faied!\n");
		return 0;
	}

	src_addr.nl_family = AF_NETLINK;
	src_addr.nl_pid = getpid();

	src_addr.nl_groups = 1;

	result = bind(sock_fd, (struct sockaddr*)&src_addr, sizeof(src_addr));
	if (result) {
		printf("Bind faied! %d.\n", result);
		return result;
	}

	iov.iov_base = (void *)&event;
	iov.iov_len = sizeof(struct acpi_event);

	msg.msg_name = (void *)&dest_addr;
	msg.msg_namelen = sizeof(dest_addr);
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;

	while(i > 0) {
		printf("Wait...\n");
		result = recvmsg(sock_fd, &msg, 0);
		if (result == -1) {
			printf("Rui: recvmsg failed, error is %d\n", result);
			return result;
		}
		printf("%20s %15s %08x %08x\n",
			event.device_class, event.bus_id, event.type, event.data);
		i--;
	}

	close(sock_fd);
	return 0;
}

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/acpi/bus.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
 drivers/acpi/event.c    |   25 +++++++++++++++++++++++++
 include/acpi/acpi_bus.h |    4 +++-
 include/linux/netlink.h |    1 +
 4 files changed, 71 insertions(+), 1 deletion(-)

Index: linux-2.6.22-rc1/drivers/acpi/bus.c
===================================================================
--- linux-2.6.22-rc1.orig/drivers/acpi/bus.c	2007-05-21 10:18:58.000000000 +0800
+++ linux-2.6.22-rc1/drivers/acpi/bus.c	2007-05-21 15:38:06.000000000 +0800
@@ -37,6 +37,7 @@
 #endif
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
+#include <linux/netlink.h>
 
 #define _COMPONENT		ACPI_BUS_COMPONENT
 ACPI_MODULE_NAME("bus");
@@ -275,6 +276,43 @@
 /* --------------------------------------------------------------------------
                                 Event Management
    -------------------------------------------------------------------------- */
+#ifdef CONFIG_NET
+struct acpi_bus_netlink_event {
+	acpi_device_class device_class;
+	char bus_id[15];
+	u32 type;
+	u32 data;
+};
+
+static int acpi_bus_generate_netlink_event(struct acpi_device *device,
+						u8 type, int data)
+{
+	struct sk_buff *skb = NULL;
+	struct acpi_bus_netlink_event *event = NULL;
+
+	skb = alloc_skb(sizeof(struct acpi_bus_event), GFP_ATOMIC);
+	if (!skb)
+		return -ENOMEM;
+
+	event = (struct acpi_bus_netlink_event *)
+			skb_put(skb, sizeof(struct acpi_bus_netlink_event));
+	strcpy(event->device_class, device->pnp.device_class);
+	strcpy(event->bus_id, device->dev.bus_id);
+	event->type = type;
+	event->data = data;
+
+	NETLINK_CB(skb).dst_group = 1;
+
+	netlink_broadcast(acpi_event_sock, skb, 0, 1, GFP_ATOMIC);
+	return 0;
+}
+#else
+static int acpi_bus_generate_netlink_event(struct acpi_device *device,
+						u8 type, int data)
+{
+	return 0;
+}
+#endif
 
 static DEFINE_SPINLOCK(acpi_bus_event_lock);
 
@@ -292,6 +330,10 @@
 	if (!device)
 		return -EINVAL;
 
+	if (acpi_bus_generate_netlink_event(device, type, data))
+		printk(KERN_WARNING PREFIX
+			"Failed to generate a netlink message for ACPI event!\n");
+
 	/* drop event on the floor if no one's listening */
 	if (!event_is_open)
 		return 0;
Index: linux-2.6.22-rc1/drivers/acpi/event.c
===================================================================
--- linux-2.6.22-rc1.orig/drivers/acpi/event.c	2007-05-16 16:12:46.000000000 +0800
+++ linux-2.6.22-rc1/drivers/acpi/event.c	2007-05-21 15:38:32.000000000 +0800
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/poll.h>
 #include <acpi/acpi_drivers.h>
+#include <linux/netlink.h>
 
 #define _COMPONENT		ACPI_SYSTEM_COMPONENT
 ACPI_MODULE_NAME("event");
@@ -105,6 +106,24 @@
 	.release = acpi_system_close_event,
 	.poll = acpi_system_poll_event,
 };
+#ifdef CONFIG_NET
+struct sock* acpi_event_sock;
+static int acpi_event_netlink_init(void)
+{
+	acpi_event_sock = netlink_kernel_create(NETLINK_ACPI_EVENT, 1, NULL,
+						NULL, THIS_MODULE);
+
+	if (!acpi_event_sock)
+		return -ENODEV;
+
+	return 0;
+}
+#else
+static int acpi_event_netlink_init(void)
+{
+	return -ENODEV;
+}
+#endif
 
 static int __init acpi_event_init(void)
 {
@@ -115,6 +134,12 @@
 	if (acpi_disabled)
 		return 0;
 
+	/* create netlink for acpi event */
+	error = acpi_event_netlink_init();
+	if (error)
+		printk(KERN_WARNING PREFIX
+		       "Failed to create netlink for ACPI event\n");
+
 	/* 'event' [R] */
 	entry = create_proc_entry("event", S_IRUSR, acpi_root_dir);
 	if (entry)
Index: linux-2.6.22-rc1/include/linux/netlink.h
===================================================================
--- linux-2.6.22-rc1.orig/include/linux/netlink.h	2007-05-21 10:19:00.000000000 +0800
+++ linux-2.6.22-rc1/include/linux/netlink.h	2007-05-21 15:26:14.000000000 +0800
@@ -24,6 +24,7 @@
 /* leave room for NETLINK_DM (DM Events) */
 #define NETLINK_SCSITRANSPORT	18	/* SCSI Transports */
 #define NETLINK_ECRYPTFS	19
+#define NETLINK_ACPI_EVENT	20	/* acpi event notifications */
 
 #define MAX_LINKS 32		
 
Index: linux-2.6.22-rc1/include/acpi/acpi_bus.h
===================================================================
--- linux-2.6.22-rc1.orig/include/acpi/acpi_bus.h	2007-05-21 10:19:00.000000000 +0800
+++ linux-2.6.22-rc1/include/acpi/acpi_bus.h	2007-05-21 15:34:36.000000000 +0800
@@ -321,7 +321,9 @@
 };
 
 extern struct kset acpi_subsys;
-
+#ifdef CONFIG_NET
+extern struct sock* acpi_event_sock;
+#endif
 /*
  * External Functions
  */

^ permalink raw reply	[flat|nested] 71+ messages in thread

end of thread, other threads:[~2007-07-03 23:13 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-22  9:47 [PATCH] [-mm] ACPI: export ACPI events via netlink Zhang Rui
2007-05-22 10:05 ` Samuel Ortiz
2007-05-22 10:10   ` Evgeniy Polyakov
2007-05-22 11:03 ` jamal
2007-05-23  1:17   ` Zhang Rui
2007-05-27  9:40   ` Zhang Rui
     [not found]     ` <4466a10705270629h31977813hd2fc8330bcd87f78@mail.gmail.com>
2007-05-27 13:34       ` Fwd: " jamal
2007-06-14  8:59         ` Zhang Rui
2007-06-14 11:28           ` jamal
2007-06-15  1:01             ` Zhang Rui
2007-06-15 10:26               ` jamal
2007-06-18 15:01               ` jamal
2007-06-19  3:32                 ` Zhang Rui
2007-06-25 22:40                   ` Johannes Berg
2007-06-26 13:33                     ` jamal
2007-06-26 13:42                       ` Johannes Berg
2007-06-27 23:24                     ` jamal
2007-06-28  9:45                       ` Johannes Berg
2007-06-29 11:17                         ` jamal
2007-06-29 11:28                           ` Johannes Berg
2007-06-29 11:48                             ` jamal
2007-06-29 11:58                               ` Johannes Berg
2007-06-29 11:51                         ` Patrick McHardy
2007-06-29 11:59                           ` Johannes Berg
2007-06-29 12:04                             ` Patrick McHardy
2007-06-29 12:01                           ` jamal
2007-06-29 12:09                             ` Patrick McHardy
2007-06-29 12:46                           ` Johannes Berg
2007-06-29 12:48                             ` Patrick McHardy
2007-06-29 12:51                               ` Johannes Berg
2007-06-29 13:02                               ` jamal
2007-06-29 13:12                                 ` Patrick McHardy
2007-06-29 13:27                                   ` jamal
2007-06-29 13:32                                     ` Patrick McHardy
2007-06-29 13:13                                 ` Johannes Berg
2007-06-29 12:57                       ` Johannes Berg
2007-06-29 13:11                         ` Patrick McHardy
2007-06-29 13:15                           ` Johannes Berg
2007-06-29 13:23                             ` Patrick McHardy
2007-06-29 13:34                               ` Johannes Berg
2007-06-29 13:44                                 ` Patrick McHardy
2007-06-29 13:49                                   ` Johannes Berg
2007-06-29 13:53                                     ` Patrick McHardy
2007-06-29 14:05                                       ` Johannes Berg
2007-06-29 14:18                                         ` Johannes Berg
2007-06-29 14:56                                           ` Johannes Berg
2007-06-30 15:32                                             ` jamal
2007-07-02  8:43                                               ` Johannes Berg
2007-07-02 12:56                                                 ` Patrick McHardy
2007-07-02 14:34                                                   ` Johannes Berg
2007-07-02 14:38                                                     ` Patrick McHardy
2007-07-02 14:48                                                       ` Johannes Berg
2007-07-02 22:12                                                         ` Johannes Berg
2007-07-03 10:08                                                           ` [PATCH] netlink: allocate group bitmaps dynamically Johannes Berg
2007-07-03 12:05                                                             ` Patrick McHardy
2007-07-03 14:09                                                               ` Johannes Berg
2007-07-03 14:11                                                                 ` Patrick McHardy
2007-07-03 14:32                                                                   ` Johannes Berg
2007-07-03 23:13                                                                   ` Johannes Berg
2007-07-03 10:09                                                           ` [PATCH] netlink: allow removing multicast groups Johannes Berg
2007-07-03 10:10                                                           ` [PATCH] generic netlink: dynamic " Johannes Berg
2007-07-03 11:56                                                           ` Fwd: [PATCH] [-mm] ACPI: export ACPI events via netlink Patrick McHardy
2007-06-29 13:24                             ` jamal
2007-06-29 13:11                         ` jamal
2007-06-19 11:30                 ` Johannes Berg
2007-06-19 16:20                   ` jamal
2007-06-20 11:25                     ` Johannes Berg
2007-06-21 15:47                       ` jamal
2007-06-22 10:09                         ` Johannes Berg
2007-06-25 17:08                           ` jamal
2007-06-26  8:50                             ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).