public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@suse.cz>
To: andrew.grover@intel.com, kernel list <linux-kernel@vger.kernel.org>
Subject: FYI: ACPI devices put into proc
Date: Thu, 5 Apr 2001 22:52:53 +0200	[thread overview]
Message-ID: <20010405225253.A553@bug.ucw.cz> (raw)

Hi!

Here it how it looks just now. This is work in progress, but feel free
to apply. [You may want to restructure it somehow, move it into
different place maybe, and call its init from convient place].

Oh, and "ACPI_OK" should be killed. It is too easy to write it instead
of AE_OK.

								Pavel

--- clean/drivers/acpi/namespace/nsxfobj.c	Sun Apr  1 00:23:00 2001
+++ linux/drivers/acpi/namespace/nsxfobj.c	Thu Apr  5 22:49:18 2001
@@ -30,6 +30,9 @@
 #include "acnamesp.h"
 #include "acdispat.h"
 
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/proc_fs.h>
 
 #define _COMPONENT          NAMESPACE
 	 MODULE_NAME         ("nsxfobj")
@@ -694,3 +697,137 @@
 
 	return (status);
 }
+
+static int
+proc_read_device_info(char *page, char **start, off_t off,
+			int count, int *eof, void *data)
+{
+	ACPI_HANDLE             obj_handle = (u32) data;
+	ACPI_NAMESPACE_NODE     *node;
+	ACPI_STATUS		status;
+	char *p = page;
+	int len;
+	u32 flags;
+	DEVICE_ID               device_id;
+
+	/* don't get info more than once for a single proc read */
+	if (off != 0)
+		goto end;
+
+	acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
+
+	printk("acpi_read_device_info: %lx\n", obj_handle);
+	node = acpi_ns_convert_handle_to_entry (obj_handle);
+
+	acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
+
+	status = acpi_cm_execute_STA (node, &flags);
+	if (ACPI_FAILURE (status))
+		p += sprintf(p, "Present:	No (%lx)\n", status);
+	else	p += sprintf(p, "Present:	Yes (flags %lx)\n", flags);
+
+	status = acpi_cm_execute_HID (node, &device_id);
+	if (!ACPI_FAILURE (status))
+		p += sprintf(p, "HID ident:	%s\n", &device_id.buffer );
+
+	status = acpi_cm_execute_UID (node, &device_id);
+	if (!ACPI_FAILURE (status))
+		p += sprintf(p, "UID ident:	%s\n", &device_id.buffer );
+
+	p += sprintf(p, "This is some random information\n");
+end:
+	len = (p - page);
+	if (len <= off+count) *eof = 1;
+	*start = page + off;
+	len -= off;
+	if (len>count) len = count;
+	if (len<0) len = 0;
+	return len;
+}
+
+static ACPI_STATUS
+acpi_ns_add_proc_callback (
+	ACPI_HANDLE             obj_handle,
+	u32                     nesting_level,
+	void                    *context,
+	void                    **return_value)
+{
+	ACPI_STATUS             status;
+	ACPI_NAMESPACE_NODE     *node;
+	u32                     flags;
+	DEVICE_ID               device_id;
+	ACPI_GET_DEVICES_INFO   *info;
+
+
+	info = context;
+
+	acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
+
+	printk("acpi_add_proc_callback: %lx\n", obj_handle);
+	node = acpi_ns_convert_handle_to_entry (obj_handle);
+
+	acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
+
+	if (!node) {
+		return (AE_BAD_PARAMETER);
+	}
+
+	/*
+	 * Run _STA to determine if device is present
+	 */
+
+	status = acpi_cm_execute_STA (node, &flags);
+	if (ACPI_FAILURE (status)) {
+		return (AE_OK);
+	}
+
+	if (!(flags & 0x01)) {
+		/* don't return at the device or children of the device if not there */
+
+		return (AE_CTRL_DEPTH);
+	}
+
+	{
+		char proc_name[120];
+
+		status = acpi_cm_execute_HID (node, &device_id);
+
+		if (status == AE_NOT_FOUND) {
+			return (AE_OK);
+		}
+
+		else if (ACPI_FAILURE (status)) {
+			return (status);
+		}
+
+		sprintf(proc_name, "power/device_%s_%lx", device_id.buffer, obj_handle );
+		printk("ACPI: creating %s\n", proc_name);
+		create_proc_read_entry(proc_name, 0, NULL,
+			proc_read_device_info, (void *) obj_handle);
+	}
+
+	return (AE_OK);
+}
+
+
+void
+acpi_namespace_init(
+	void)
+{
+	ACPI_STATUS             status;
+	void ** return_value;
+
+	printk("ACPI: initializing namespace\n");
+
+	acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
+	status = acpi_ns_walk_namespace (ACPI_TYPE_DEVICE,
+			   ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
+			   NS_WALK_UNLOCK,
+			   acpi_ns_add_proc_callback, NULL,
+			   return_value);
+
+	acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
+
+	return (status);
+}
+

-- 
I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at discuss@linmodems.org

                 reply	other threads:[~2001-04-07 18:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010405225253.A553@bug.ucw.cz \
    --to=pavel@suse.cz \
    --cc=andrew.grover@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox