public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org>
To: Alex Williamson <alex.williamson-VXdhtT5mjnY@public.gmane.org>
Cc: Paul Ionescu <paul-f7LjuT9/YZU@public.gmane.org>,
	acpi
	<acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: [RFC] filling in ACPI files in sysfs
Date: Thu, 8 Apr 2004 18:25:48 +0100	[thread overview]
Message-ID: <20040408172548.GH18329@parcelfarce.linux.theplanet.co.uk> (raw)
In-Reply-To: <1081376023.2748.15.camel-Wmjt7DDUnIVxnVILBQAtiA@public.gmane.org>

On Wed, Apr 07, 2004 at 04:13:43PM -0600, Alex Williamson wrote:
>    Here you go, a second iteration.  I haven't looked at the _Qxx
> methods yet, but we're up to over 30 methods exported now.  I've added
> several writable methods so you can do more than query status.  I've
> been able to undock my omnibook 500 laptop (electromechanical eject) and
> switch between a CRT and LCD using only the sysfs interface.  I thought
> about parsing some of the more complicated data structures, but that
> turned into way too much code too quickly.  So you'll find there are
> several entries that return a binary dump of the data structures.  these
> include _CRS, _PRS, _PRT, and _MAT.  Some of the methods look like they
> should work, but I don't have a box w/ firmware that exports them, so
> let me know if the output is broken.  Thanks,

Ii'm not a big fan of overloading acpi_device_read_file ... how about
splitting it up like this?

diff -u edited/drivers/acpi/scan.c b/drivers/acpi/scan.c
--- edited/drivers/acpi/scan.c	Wed Apr  7 15:55:17 2004
+++ b/drivers/acpi/scan.c	8 Apr 2004 15:49:40 -0000
@@ -146,61 +146,86 @@
 	ssize_t retval = 0;
 	unsigned int flags = 0;
 
-	if (!strcmp(method, METHOD_NAME__CRS)) {
-		status = acpi_get_current_resources(device->handle, &buffer);
-		if (ACPI_FAILURE(status))
-			return -ENODEV;
-
-		memcpy(buf, buffer.pointer, buffer.length);
-		retval = buffer.length;
-		acpi_os_free(buffer.pointer);
-	} else if (!strcmp(method, METHOD_NAME__PRS)) {
-		status = acpi_get_possible_resources(device->handle, &buffer);
-		if (ACPI_FAILURE(status))
-			return -ENODEV;
-
-		memcpy(buf, buffer.pointer, buffer.length);
-		retval = buffer.length;
-		acpi_os_free(buffer.pointer);
-	} else if (!strcmp(method, METHOD_NAME__PRT)) {
-		status = acpi_get_irq_routing_table(device->handle, &buffer);
-		if (ACPI_FAILURE(status))
-			return -ENODEV;
-
-		memcpy(buf, buffer.pointer, buffer.length);
-		retval = buffer.length;
-		acpi_os_free(buffer.pointer);
-	} else if (!strcmp(method, METHOD_NAME__MAT)) {
-		status = acpi_evaluate_object(device->handle, method,
-		                              NULL, &buffer);
-		if (ACPI_FAILURE(status))
-			return -ENODEV;
-
-		memcpy(buf, buffer.pointer, buffer.length);
-		retval = buffer.length;
-		acpi_os_free(buffer.pointer);
-	} else {
-		status = acpi_evaluate_object(device->handle, method,
-		                              NULL, &buffer);
-		if (ACPI_FAILURE(status))
-			return -ENODEV;
-	
-		if (!strcmp(method, METHOD_NAME__HID)
-		    || !strcmp(method, METHOD_NAME__CID)
-		    || !strcmp(method, METHOD_NAME__FIX))
-			flags |= EISA_ID_TYPE;
-
-		if (!strcmp(method, METHOD_NAME__STR))
-			flags |= UNICODE_TYPE;
-
-		element = (union acpi_object *) buffer.pointer;
-		retval = parse_element(buf, element, flags);
-		acpi_os_free(buffer.pointer);
-	}
+	status = acpi_evaluate_object(device->handle, method, NULL, &buffer);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	if (!strcmp(method, METHOD_NAME__HID)
+	    || !strcmp(method, METHOD_NAME__CID)
+	    || !strcmp(method, METHOD_NAME__FIX))
+		flags = EISA_ID_TYPE;
+
+	if (!strcmp(method, METHOD_NAME__STR))
+		flags = UNICODE_TYPE;
+
+	element = (union acpi_object *) buffer.pointer;
+	retval = parse_element(buf, element, flags);
+	acpi_os_free(buffer.pointer);
+
 	return retval;
 }
 
 static ssize_t
+acpi_device_read_raw(struct acpi_device *device, char *method, char *buf)
+{
+	acpi_status status;
+	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+
+	status = acpi_evaluate_object(device->handle, method, NULL, &buffer);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	memcpy(buf, buffer.pointer, buffer.length);
+	acpi_os_free(buffer.pointer);
+	return buffer.length;
+}
+
+static ssize_t
+acpi_device_read_crs(struct acpi_device *device, char *method, char *buf)
+{
+	acpi_status status;
+	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+
+	status = acpi_get_current_resources(device->handle, &buffer);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	memcpy(buf, buffer.pointer, buffer.length);
+	acpi_os_free(buffer.pointer);
+	return buffer.length;
+}
+
+static ssize_t
+acpi_device_read_prs(struct acpi_device *device, char *method, char *buf)
+{
+	acpi_status status;
+	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+
+	status = acpi_get_possible_resources(device->handle, &buffer);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	memcpy(buf, buffer.pointer, buffer.length);
+	acpi_os_free(buffer.pointer);
+	return buffer.length;
+}
+
+static ssize_t
+acpi_device_read_prt(struct acpi_device *device, char *method, char *buf)
+{
+	acpi_status status;
+	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+
+	status = acpi_get_irq_routing_table(device->handle, &buffer);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	memcpy(buf, buffer.pointer, buffer.length);
+	acpi_os_free(buffer.pointer);
+	return buffer.length;
+}
+
+static ssize_t
 acpi_device_write_integer (
 	struct acpi_device	*device,
 	char			*method,
@@ -237,7 +262,7 @@
 acpi_handle_attr(_BCL, acpi_device_read_file, NULL)
 acpi_handle_attr(_BCM, NULL, acpi_device_write_integer)
 acpi_handle_attr(_CID, acpi_device_read_file, NULL)
-acpi_handle_attr(_CRS, acpi_device_read_file, NULL)
+acpi_handle_attr(_CRS, acpi_device_read_crs, NULL)
 acpi_handle_attr(_DCK, NULL, acpi_device_write_integer)
 acpi_handle_attr(_DCS, acpi_device_read_file, NULL)
 acpi_handle_attr(_DGS, acpi_device_read_file, NULL)
@@ -253,9 +278,9 @@
 acpi_handle_attr(_HPP, acpi_device_read_file, NULL)
 acpi_handle_attr(_LCK, NULL, acpi_device_write_integer)
 acpi_handle_attr(_LID, acpi_device_read_file, NULL)
-acpi_handle_attr(_MAT, acpi_device_read_file, NULL)
-acpi_handle_attr(_PRS, acpi_device_read_file, NULL)
-acpi_handle_attr(_PRT, acpi_device_read_file, NULL)
+acpi_handle_attr(_MAT, acpi_device_read_raw, NULL)
+acpi_handle_attr(_PRS, acpi_device_read_prs, NULL)
+acpi_handle_attr(_PRT, acpi_device_read_prt, NULL)
 acpi_handle_attr(_PXM, acpi_device_read_file, NULL)
 acpi_handle_attr(_RMV, acpi_device_read_file, NULL)
 acpi_handle_attr(_SEG, acpi_device_read_file, NULL)

-- 
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click

  parent reply	other threads:[~2004-04-08 17:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-07 21:36 [RFC] filling in ACPI files in sysfs Paul Ionescu
     [not found] ` <1081373781.23176.30.camel-LjAuIDrFwz0@public.gmane.org>
2004-04-07 22:13   ` Alex Williamson
     [not found]     ` <1081376023.2748.15.camel-Wmjt7DDUnIVxnVILBQAtiA@public.gmane.org>
2004-04-08  5:56       ` Paul Ionescu
2004-04-08 15:46       ` Paul Ionescu
     [not found]         ` <1081439217.23176.70.camel-LjAuIDrFwz0@public.gmane.org>
2004-04-08 16:41           ` Alex Williamson
2004-04-08 16:53       ` Paul Ionescu
2004-04-08 17:25       ` Matthew Wilcox [this message]
     [not found]         ` <20040408172548.GH18329-+pPCBgu9SkPzIGdyhVEDUDl5KyyQGfY2kSSpQ9I8OhVaa/9Udqfwiw@public.gmane.org>
2004-04-08 17:33           ` Alex Williamson
     [not found]             ` <1081536801.26073.120.camel@t40>
     [not found]               ` <1081537175.2694.11.camel@patsy.fc.hp.com>
     [not found]                 ` <1081537175.2694.11.camel-Wmjt7DDUnIVxnVILBQAtiA@public.gmane.org>
2004-04-10 10:03                   ` Paul Ionescu
     [not found]             ` <1081536489.23178.113.camel@t40>
     [not found]               ` <1081537087.2694.8.camel@patsy.fc.hp.com>
     [not found]                 ` <1081537087.2694.8.camel-Wmjt7DDUnIVxnVILBQAtiA@public.gmane.org>
2004-04-10 11:36                   ` Paul Ionescu
  -- strict thread matches above, loose matches on Subject: below --
2004-04-08  8:14 Paul Ionescu
     [not found] ` <20040408081455.52935.qmail-BuYeCebq3BaA/QwVtaZbd3CJp6faPEW9@public.gmane.org>
2004-04-08 14:36   ` Alex Williamson
2004-04-06 15:56 Alex Williamson

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=20040408172548.GH18329@parcelfarce.linux.theplanet.co.uk \
    --to=willy-8fiuurrzop0dnm+yrofe0a@public.gmane.org \
    --cc=acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=alex.williamson-VXdhtT5mjnY@public.gmane.org \
    --cc=paul-f7LjuT9/YZU@public.gmane.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