⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exconvrt.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * * Module Name: exconvrt - Object conversion routines *              $Revision: 24 $ * *****************************************************************************//* *  Copyright (C) 2000, 2001 R. Byron Moore * *  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 */#include "acpi.h"#include "acparser.h"#include "acnamesp.h"#include "acinterp.h"#include "acevents.h"#include "amlcode.h"#include "acdispat.h"#define _COMPONENT          ACPI_EXECUTER	 MODULE_NAME         ("exconvrt")/******************************************************************************* * * FUNCTION:    Acpi_ex_convert_to_integer * * PARAMETERS:  *Obj_desc       - Object to be converted.  Must be an *                                Integer, Buffer, or String *              Walk_state      - Current method state * * RETURN:      Status * * DESCRIPTION: Convert an ACPI Object to an integer. * ******************************************************************************/acpi_statusacpi_ex_convert_to_integer (	acpi_operand_object     *obj_desc,	acpi_operand_object     **result_desc,	acpi_walk_state         *walk_state){	u32                     i;	acpi_operand_object     *ret_desc;	u32                     count;	char                    *pointer;	acpi_integer            result;	u32                     integer_size = sizeof (acpi_integer);	FUNCTION_ENTRY ();	switch (obj_desc->common.type) {	case ACPI_TYPE_INTEGER:		*result_desc = obj_desc;		return (AE_OK);	case ACPI_TYPE_STRING:		pointer = obj_desc->string.pointer;		count   = obj_desc->string.length;		break;	case ACPI_TYPE_BUFFER:		pointer = (char *) obj_desc->buffer.pointer;		count   = obj_desc->buffer.length;		break;	default:		return (AE_TYPE);	}	/*	 * Create a new integer	 */	ret_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);	if (!ret_desc) {		return (AE_NO_MEMORY);	}	/* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */	if (walk_state->method_node->flags & ANOBJ_DATA_WIDTH_32) {		/*		 * 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		 */		integer_size = sizeof (u32);	}	/*	 * Convert the buffer/string to an integer.  Note that both buffers and	 * strings are treated as raw data - we don't convert ascii to hex for	 * strings.	 *	 * There are two terminating conditions for the loop:	 * 1) The size of an integer has been reached, or	 * 2) The end of the buffer or string has been reached	 */	result = 0;	/* Transfer no more than an integer's worth of data */	if (count > integer_size) {		count = integer_size;	}	/*	 * String conversion is different than Buffer conversion	 */	switch (obj_desc->common.type) {	case ACPI_TYPE_STRING:		/* TBD: Need to use 64-bit STRTOUL */		/*		 * Convert string to an integer		 * String must be hexadecimal as per the ACPI specification		 */		result = STRTOUL (pointer, NULL, 16);		break;	case ACPI_TYPE_BUFFER:		/*		 * Buffer conversion - we simply grab enough raw data from the		 * buffer to fill an integer		 */		for (i = 0; i < count; i++) {			/*			 * Get next byte and shift it into the Result.			 * Little endian is used, meaning that the first byte of the buffer			 * is the LSB of the integer			 */			result |= (((acpi_integer) pointer[i]) << (i * 8));		}		break;	}	/* Save the Result, delete original descriptor, store new descriptor */	ret_desc->integer.value = result;	if (*result_desc == obj_desc) {		if (walk_state->opcode != AML_STORE_OP) {			acpi_ut_remove_reference (obj_desc);		}	}	*result_desc = ret_desc;	return (AE_OK);}/******************************************************************************* * * FUNCTION:    Acpi_ex_convert_to_buffer * * PARAMETERS:  *Obj_desc       - Object to be converted.  Must be an *                                Integer, Buffer, or String *              Walk_state      - Current method state * * RETURN:      Status * * DESCRIPTION: Convert an ACPI Object to an Buffer * ******************************************************************************/acpi_statusacpi_ex_convert_to_buffer (	acpi_operand_object     *obj_desc,	acpi_operand_object     **result_desc,	acpi_walk_state         *walk_state){	acpi_operand_object     *ret_desc;	u32                     i;	u32                     integer_size = sizeof (acpi_integer);	u8                      *new_buf;	FUNCTION_ENTRY ();	switch (obj_desc->common.type) {	case ACPI_TYPE_INTEGER:		/*		 * Create a new Buffer		 */		ret_desc = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER);		if (!ret_desc) {			return (AE_NO_MEMORY);		}		/* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */		if (walk_state->method_node->flags & ANOBJ_DATA_WIDTH_32) {			/*			 * 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			 */			integer_size = sizeof (u32);		}		/* Need enough space for one integers */		ret_desc->buffer.length = integer_size;		new_buf = ACPI_MEM_CALLOCATE (integer_size);		if (!new_buf) {			REPORT_ERROR				(("Ex_convert_to_buffer: Buffer allocation failure\n"));			acpi_ut_remove_reference (ret_desc);			return (AE_NO_MEMORY);		}		/* Copy the integer to the buffer */		for (i = 0; i < integer_size; i++) {			new_buf[i] = (u8) (obj_desc->integer.value >> (i * 8));		}		ret_desc->buffer.pointer = new_buf;		/* Return the new buffer descriptor */		if (*result_desc == obj_desc) {			if (walk_state->opcode != AML_STORE_OP) {				acpi_ut_remove_reference (obj_desc);			}		}		*result_desc = ret_desc;		break;	case ACPI_TYPE_STRING:		*result_desc = obj_desc;		break;	case ACPI_TYPE_BUFFER:		*result_desc = obj_desc;		break;	default:		return (AE_TYPE);		break;   }	return (AE_OK);}/******************************************************************************* * * FUNCTION:    Acpi_ex_convert_ascii * * PARAMETERS:  Integer * * RETURN:      Actual string length * * DESCRIPTION: Convert an ACPI Integer to a hex string * ******************************************************************************/u32acpi_ex_convert_to_ascii (	acpi_integer            integer,	u32                     base,	u8                      *string){	u32                     i;	u32                     j;	u32                     k = 0;	u8                      hex_digit;	acpi_integer            digit;	u32                     remainder;	u32                     length = sizeof (acpi_integer);	u8                      leading_zero = TRUE;	FUNCTION_ENTRY ();	switch (base) {	case 10:		remainder = 0;		for (i = ACPI_MAX_DECIMAL_DIGITS; i > 0 ; i--) {			/* Divide by nth factor of 10 */			digit = integer;			for (j = 1; j < i; j++) {				acpi_ut_short_divide (&digit, 10, &digit, &remainder);			}			/* Create the decimal digit */			if (digit != 0) {				leading_zero = FALSE;			}			if (!leading_zero) {				string[k] = (u8) (ASCII_ZERO + remainder);				k++;			}		}		break;	case 16:		/* Copy the integer to the buffer */		for (i = 0, j = ((length * 2) -1); i < (length * 2); i++, j--) {			hex_digit = acpi_ut_hex_to_ascii_char (integer, (j * 4));			if (hex_digit != ASCII_ZERO) {				leading_zero = FALSE;			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -