patch-2.4.22 linux-2.4.22/drivers/acpi/executer/exutils.c

Next file: linux-2.4.22/drivers/acpi/fan.c
Previous file: linux-2.4.22/drivers/acpi/executer/exsystem.c
Back to the patch index
Back to the overall index

diff -urN linux-2.4.21/drivers/acpi/executer/exutils.c linux-2.4.22/drivers/acpi/executer/exutils.c
@@ -2,26 +2,44 @@
 /******************************************************************************
  *
  * Module Name: exutils - interpreter/scanner utilities
- *              $Revision: 85 $
  *
  *****************************************************************************/
 
 /*
- *  Copyright (C) 2000, 2001 R. Byron Moore
+ * Copyright (C) 2000 - 2003, R. Byron Moore
+ * All rights reserved.
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
  */
 
 
@@ -41,45 +59,48 @@
 
 #define DEFINE_AML_GLOBALS
 
-#include "acpi.h"
-#include "acparser.h"
-#include "acinterp.h"
-#include "amlcode.h"
-#include "acnamesp.h"
-#include "acevents.h"
-#include "acparser.h"
+#include <acpi/acpi.h>
+#include <acpi/acinterp.h>
+#include <acpi/amlcode.h>
+#include <acpi/acevents.h>
 
 #define _COMPONENT          ACPI_EXECUTER
-	 MODULE_NAME         ("exutils")
+	 ACPI_MODULE_NAME    ("exutils")
 
 
+#ifndef ACPI_NO_METHOD_EXECUTION
+
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_enter_interpreter
+ * FUNCTION:    acpi_ex_enter_interpreter
  *
  * PARAMETERS:  None
  *
- * DESCRIPTION: Enter the interpreter execution region
- *              TBD: should be a macro
+ * DESCRIPTION: Enter the interpreter execution region.  Failure to enter
+ *              the interpreter region is a fatal system error
  *
  ******************************************************************************/
 
 acpi_status
 acpi_ex_enter_interpreter (void)
 {
-	acpi_status             status;
+	acpi_status                     status;
 
-	FUNCTION_TRACE ("Ex_enter_interpreter");
+	ACPI_FUNCTION_TRACE ("ex_enter_interpreter");
 
 
 	status = acpi_ut_acquire_mutex (ACPI_MTX_EXECUTE);
+	if (ACPI_FAILURE (status)) {
+		ACPI_REPORT_ERROR (("Could not acquire interpreter mutex\n"));
+	}
+
 	return_ACPI_STATUS (status);
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_exit_interpreter
+ * FUNCTION:    acpi_ex_exit_interpreter
  *
  * PARAMETERS:  None
  *
@@ -95,56 +116,31 @@
  *          already executing
  *      7) About to invoke a user-installed opregion handler
  *
- *              TBD: should be a macro
- *
  ******************************************************************************/
 
 void
 acpi_ex_exit_interpreter (void)
 {
-	FUNCTION_TRACE ("Ex_exit_interpreter");
-
-
-	acpi_ut_release_mutex (ACPI_MTX_EXECUTE);
-
-	return_VOID;
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    Acpi_ex_validate_object_type
- *
- * PARAMETERS:  Type            Object type to validate
- *
- * DESCRIPTION: Determine if a type is a valid ACPI object type
- *
- ******************************************************************************/
+	acpi_status                     status;
 
-u8
-acpi_ex_validate_object_type (
-	acpi_object_type        type)
-{
 
-	FUNCTION_ENTRY ();
+	ACPI_FUNCTION_TRACE ("ex_exit_interpreter");
 
 
-	if ((type > ACPI_TYPE_MAX && type < INTERNAL_TYPE_BEGIN) ||
-		(type > INTERNAL_TYPE_MAX)) {
-		return (FALSE);
+	status = acpi_ut_release_mutex (ACPI_MTX_EXECUTE);
+	if (ACPI_FAILURE (status)) {
+		ACPI_REPORT_ERROR (("Could not release interpreter mutex\n"));
 	}
 
-	return (TRUE);
+	return_VOID;
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_truncate_for32bit_table
+ * FUNCTION:    acpi_ex_truncate_for32bit_table
  *
- * PARAMETERS:  Obj_desc        - Object to be truncated
- *              Walk_state      - Current walk state
- *                                (A method must be executing)
+ * PARAMETERS:  obj_desc        - Object to be truncated
  *
  * RETURN:      none
  *
@@ -155,11 +151,10 @@
 
 void
 acpi_ex_truncate_for32bit_table (
-	acpi_operand_object     *obj_desc,
-	acpi_walk_state         *walk_state)
+	union acpi_operand_object       *obj_desc)
 {
 
-	FUNCTION_ENTRY ();
+	ACPI_FUNCTION_ENTRY ();
 
 
 	/*
@@ -167,12 +162,11 @@
 	 * a control method
 	 */
 	if ((!obj_desc) ||
-		(obj_desc->common.type != ACPI_TYPE_INTEGER) ||
-		(!walk_state->method_node)) {
+		(ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_INTEGER)) {
 		return;
 	}
 
-	if (walk_state->method_node->flags & ANOBJ_DATA_WIDTH_32) {
+	if (acpi_gbl_integer_byte_width == 4) {
 		/*
 		 * We are running a method that exists in a 32-bit ACPI table.
 		 * Truncate the value to 32 bits by zeroing out the upper 32-bit field
@@ -184,9 +178,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_acquire_global_lock
+ * FUNCTION:    acpi_ex_acquire_global_lock
  *
- * PARAMETERS:  Rule            - Lock rule: Always_lock, Never_lock
+ * PARAMETERS:  field_flags           - Flags with Lock rule:
+ *                                      always_lock or never_lock
  *
  * RETURN:      TRUE/FALSE indicating whether the lock was actually acquired
  *
@@ -198,25 +193,24 @@
 
 u8
 acpi_ex_acquire_global_lock (
-	u32                     rule)
+	u32                             field_flags)
 {
-	u8                      locked = FALSE;
-	acpi_status             status;
+	u8                              locked = FALSE;
+	acpi_status                     status;
 
 
-	FUNCTION_TRACE ("Ex_acquire_global_lock");
+	ACPI_FUNCTION_TRACE ("ex_acquire_global_lock");
 
 
-	/* Only attempt lock if the Rule says so */
+	/* Only attempt lock if the always_lock bit is set */
 
-	if (rule == (u32) GLOCK_ALWAYS_LOCK) {
-		/* We should attempt to get the lock */
+	if (field_flags & AML_FIELD_LOCK_RULE_MASK) {
+		/* We should attempt to get the lock, wait forever */
 
-		status = acpi_ev_acquire_global_lock ();
+		status = acpi_ev_acquire_global_lock (ACPI_WAIT_FOREVER);
 		if (ACPI_SUCCESS (status)) {
 			locked = TRUE;
 		}
-
 		else {
 			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not acquire Global Lock, %s\n",
 				acpi_format_exception (status)));
@@ -229,10 +223,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_release_global_lock
+ * FUNCTION:    acpi_ex_release_global_lock
  *
- * PARAMETERS:  Locked_by_me    - Return value from corresponding call to
- *                                Acquire_global_lock.
+ * PARAMETERS:  locked_by_me    - Return value from corresponding call to
+ *                                acquire_global_lock.
  *
  * RETURN:      Status
  *
@@ -240,12 +234,14 @@
  *
  ******************************************************************************/
 
-acpi_status
+void
 acpi_ex_release_global_lock (
-	u8                      locked_by_me)
+	u8                              locked_by_me)
 {
+	acpi_status                     status;
 
-	FUNCTION_TRACE ("Ex_release_global_lock");
+
+	ACPI_FUNCTION_TRACE ("ex_release_global_lock");
 
 
 	/* Only attempt unlock if the caller locked it */
@@ -253,17 +249,22 @@
 	if (locked_by_me) {
 		/* OK, now release the lock */
 
-		acpi_ev_release_global_lock ();
-	}
+		status = acpi_ev_release_global_lock ();
+		if (ACPI_FAILURE (status)) {
+			/* Report the error, but there isn't much else we can do */
 
+			ACPI_REPORT_ERROR (("Could not release ACPI Global Lock, %s\n",
+				acpi_format_exception (status)));
+		}
+	}
 
-	return_ACPI_STATUS (AE_OK);
+	return_VOID;
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_digits_needed
+ * FUNCTION:    acpi_ex_digits_needed
  *
  * PARAMETERS:  Value           - Value to be represented
  *              Base            - Base of representation
@@ -274,26 +275,30 @@
 
 u32
 acpi_ex_digits_needed (
-	acpi_integer            value,
-	u32                     base)
+	acpi_integer                    value,
+	u32                             base)
 {
-	u32                     num_digits = 0;
+	u32                             num_digits;
+	acpi_integer                    current_value;
+	acpi_integer                    quotient;
 
 
-	FUNCTION_TRACE ("Ex_digits_needed");
+	ACPI_FUNCTION_TRACE ("ex_digits_needed");
 
 
-	if (base < 1) {
-		REPORT_ERROR (("Ex_digits_needed: Internal error - Invalid base\n"));
+	/*
+	 * acpi_integer is unsigned, so we don't worry about a '-'
+	 */
+	if ((current_value = value) == 0) {
+		return_VALUE (1);
 	}
 
-	else {
-		/*
-		 * acpi_integer is unsigned, which is why we don't worry about a '-'
-		 */
-		for (num_digits = 1;
-			(acpi_ut_short_divide (&value, base, &value, NULL));
-			++num_digits) { ; }
+	num_digits = 0;
+
+	while (current_value) {
+		(void) acpi_ut_short_divide (&current_value, base, &quotient, NULL);
+		num_digits++;
+		current_value = quotient;
 	}
 
 	return_VALUE (num_digits);
@@ -302,115 +307,74 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    ntohl
- *
- * PARAMETERS:  Value           - Value to be converted
- *
- * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
- *
- ******************************************************************************/
-
-static u32
-_ntohl (
-	u32                     value)
-{
-	union {
-		u32                 value;
-		u8                  bytes[4];
-	} out;
-
-	union {
-		u32                 value;
-		u8                  bytes[4];
-	} in;
-
-
-	FUNCTION_ENTRY ();
-
-
-	in.value = value;
-
-	out.bytes[0] = in.bytes[3];
-	out.bytes[1] = in.bytes[2];
-	out.bytes[2] = in.bytes[1];
-	out.bytes[3] = in.bytes[0];
-
-	return (out.value);
-}
-
-
-/*******************************************************************************
- *
- * FUNCTION:    Acpi_ex_eisa_id_to_string
+ * FUNCTION:    acpi_ex_eisa_id_to_string
  *
- * PARAMETERS:  Numeric_id      - EISA ID to be converted
- *              Out_string      - Where to put the converted string (8 bytes)
+ * PARAMETERS:  numeric_id      - EISA ID to be converted
+ *              out_string      - Where to put the converted string (8 bytes)
  *
  * DESCRIPTION: Convert a numeric EISA ID to string representation
  *
  ******************************************************************************/
 
-acpi_status
+void
 acpi_ex_eisa_id_to_string (
-	u32                     numeric_id,
-	NATIVE_CHAR             *out_string)
+	u32                             numeric_id,
+	char                            *out_string)
 {
-	u32                     id;
+	u32                             eisa_id;
 
 
-	FUNCTION_ENTRY ();
+	ACPI_FUNCTION_ENTRY ();
 
 
-	/* swap to big-endian to get contiguous bits */
+	/* Swap ID to big-endian to get contiguous bits */
 
-	id = _ntohl (numeric_id);
+	eisa_id = acpi_ut_dword_byte_swap (numeric_id);
 
-	out_string[0] = (char) ('@' + ((id >> 26) & 0x1f));
-	out_string[1] = (char) ('@' + ((id >> 21) & 0x1f));
-	out_string[2] = (char) ('@' + ((id >> 16) & 0x1f));
-	out_string[3] = acpi_ut_hex_to_ascii_char (id, 12);
-	out_string[4] = acpi_ut_hex_to_ascii_char (id, 8);
-	out_string[5] = acpi_ut_hex_to_ascii_char (id, 4);
-	out_string[6] = acpi_ut_hex_to_ascii_char (id, 0);
+	out_string[0] = (char) ('@' + (((unsigned long) eisa_id >> 26) & 0x1f));
+	out_string[1] = (char) ('@' + ((eisa_id >> 21) & 0x1f));
+	out_string[2] = (char) ('@' + ((eisa_id >> 16) & 0x1f));
+	out_string[3] = acpi_ut_hex_to_ascii_char ((acpi_integer) eisa_id, 12);
+	out_string[4] = acpi_ut_hex_to_ascii_char ((acpi_integer) eisa_id, 8);
+	out_string[5] = acpi_ut_hex_to_ascii_char ((acpi_integer) eisa_id, 4);
+	out_string[6] = acpi_ut_hex_to_ascii_char ((acpi_integer) eisa_id, 0);
 	out_string[7] = 0;
-
-	return (AE_OK);
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_unsigned_integer_to_string
+ * FUNCTION:    acpi_ex_unsigned_integer_to_string
  *
  * PARAMETERS:  Value           - Value to be converted
- *              Out_string      - Where to put the converted string (8 bytes)
+ *              out_string      - Where to put the converted string (8 bytes)
  *
  * RETURN:      Convert a number to string representation
  *
  ******************************************************************************/
 
-acpi_status
+void
 acpi_ex_unsigned_integer_to_string (
-	acpi_integer            value,
-	NATIVE_CHAR             *out_string)
+	acpi_integer                    value,
+	char                            *out_string)
 {
-	u32                     count;
-	u32                     digits_needed;
-	u32                     remainder;
+	u32                             count;
+	u32                             digits_needed;
+	u32                             remainder;
+	acpi_integer                    quotient;
 
 
-	FUNCTION_ENTRY ();
+	ACPI_FUNCTION_ENTRY ();
 
 
 	digits_needed = acpi_ex_digits_needed (value, 10);
 	out_string[digits_needed] = 0;
 
 	for (count = digits_needed; count > 0; count--) {
-		acpi_ut_short_divide (&value, 10, &value, &remainder);
-		out_string[count-1] = (NATIVE_CHAR) ('0' + remainder);
+		(void) acpi_ut_short_divide (&value, 10, &quotient, &remainder);
+		out_string[count-1] = (char) ('0' + remainder);\
+		value = quotient;
 	}
-
-	return (AE_OK);
 }
 
-
+#endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)