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

📄 cmobject.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 * RETURN:      None. * * DESCRIPTION: Initialize a static object.  Sets flags to disallow dynamic *              deletion of the object. * ****************************************************************************/voidacpi_cm_init_static_object (	ACPI_OPERAND_OBJECT     *obj_desc){	if (!obj_desc) {		return;	}	/*	 * Clear the entire descriptor	 */	MEMSET ((void *) obj_desc, 0, sizeof (ACPI_OPERAND_OBJECT));	/*	 * Initialize the header fields	 * 1) This is an ACPI_OPERAND_OBJECT  descriptor	 * 2) The size is the full object (worst case)	 * 3) The flags field indicates static allocation	 * 4) Reference count starts at one (not really necessary since the	 *    object can't be deleted, but keeps everything sane)	 */	obj_desc->common.data_type      = ACPI_DESC_TYPE_INTERNAL;	obj_desc->common.flags          = AOPOBJ_STATIC_ALLOCATION;	obj_desc->common.reference_count = 1;	return;}/****************************************************************************** * * FUNCTION:    Acpi_cm_get_simple_object_size * * PARAMETERS:  *Internal_obj   - Pointer to the object we are examining *              *Ret_length     - Where the length is returned * * RETURN:      Status          - the status of the call * * DESCRIPTION: This function is called to determine the space required to *              contain a simple object for return to an API user. * *              The length includes the object structure plus any additional *              needed space. * ******************************************************************************/ACPI_STATUSacpi_cm_get_simple_object_size (	ACPI_OPERAND_OBJECT     *internal_obj,	u32                     *obj_length){	u32                     length;	ACPI_STATUS             status = AE_OK;	/* Handle a null object (Could be a uninitialized package element -- which is legal) */	if (!internal_obj) {		*obj_length = 0;		return (AE_OK);	}	/* Start with the length of the Acpi object */	length = sizeof (ACPI_OBJECT);	if (VALID_DESCRIPTOR_TYPE (internal_obj, ACPI_DESC_TYPE_NAMED)) {		/* Object is a named object (reference), just return the length */		*obj_length = (u32) ROUND_UP_TO_NATIVE_WORD (length);		return (status);	}	/*	 * The final length depends on the object type	 * Strings and Buffers are packed right up against the parent object and	 * must be accessed bytewise or there may be alignment problems.	 *	 * TBD:[Investigate] do strings and buffers require alignment also?	 */	switch (internal_obj->common.type)	{	case ACPI_TYPE_STRING:		length += internal_obj->string.length + 1;		break;	case ACPI_TYPE_BUFFER:		length += internal_obj->buffer.length;		break;	case ACPI_TYPE_NUMBER:	case ACPI_TYPE_PROCESSOR:	case ACPI_TYPE_POWER:		/*		 * No extra data for these types		 */		break;	case INTERNAL_TYPE_REFERENCE:		/*		 * The only type that should be here is opcode AML_NAMEPATH_OP -- since		 * this means an object reference		 */		if (internal_obj->reference.op_code != AML_NAMEPATH_OP) {			status = AE_TYPE;		}		break;	default:		status = AE_TYPE;		break;	}	/*	 * Account for the space required by the object rounded up to the next	 * multiple of the machine word size.  This keeps each object aligned	 * on a machine word boundary. (preventing alignment faults on some	 * machines.)	 */	*obj_length = (u32) ROUND_UP_TO_NATIVE_WORD (length);	return (status);}/****************************************************************************** * * FUNCTION:    Acpi_cm_get_package_object_size * * PARAMETERS:  *Internal_obj   - Pointer to the object we are examining *              *Ret_length     - Where the length is returned * * RETURN:      Status          - the status of the call * * DESCRIPTION: This function is called to determine the space required to contain *              a package object for return to an API user. * *              This is moderately complex since a package contains other objects *              including packages. * ******************************************************************************/ACPI_STATUSacpi_cm_get_package_object_size (	ACPI_OPERAND_OBJECT     *internal_obj,	u32                     *obj_length){	ACPI_OPERAND_OBJECT     *this_internal_obj;	ACPI_OPERAND_OBJECT     *parent_obj[MAX_PACKAGE_DEPTH];	ACPI_OPERAND_OBJECT     *this_parent;	u32                     this_index;	u32                     index[MAX_PACKAGE_DEPTH];	u32                     length = 0;	u32                     object_space;	u32                     current_depth = 0;	u32                     package_count = 1;	ACPI_STATUS             status;	/* Init the package stack TBD: replace with linked list */	MEMSET(parent_obj, 0, MAX_PACKAGE_DEPTH);	MEMSET(index, 0, MAX_PACKAGE_DEPTH);	parent_obj[0] = internal_obj;	while (1) {		this_parent     = parent_obj[current_depth];		this_index      = index[current_depth];		this_internal_obj = this_parent->package.elements[this_index];		/*		 * Check for 1) An uninitialized package element.  It is completely		 *              legal to declare a package and leave it uninitialized		 *           2) Any type other than a package.  Packages are handled		 *              below.		 */		if ((!this_internal_obj) ||			(!IS_THIS_OBJECT_TYPE (this_internal_obj, ACPI_TYPE_PACKAGE)))		{			/*			 * Simple object - just get the size (Null object/entry handled			 *  also)			 */			status =				acpi_cm_get_simple_object_size (this_internal_obj, &object_space);			if (ACPI_FAILURE (status)) {				return (status);			}			length += object_space;			index[current_depth]++;			while (index[current_depth] >=				parent_obj[current_depth]->package.count)			{				/*				 * We've handled all of the objects at				 * this level,  This means that we have				 * just completed a package.  That package				 * may have contained one or more packages				 * itself.				 */				if (current_depth == 0) {					/*					 * We have handled all of the objects					 * in the top level package just add the					 * length of the package objects and					 * get out. Round up to the next machine					 * word.					 */					length +=						ROUND_UP_TO_NATIVE_WORD (								sizeof (ACPI_OBJECT)) *								package_count;					*obj_length = length;					return (AE_OK);				}				/*				 * Go back up a level and move the index				 * past the just completed package object.				 */				current_depth--;				index[current_depth]++;			}		}		else {			/*			 * This object is a package			 * -- go one level deeper			 */			package_count++;			if (current_depth < MAX_PACKAGE_DEPTH-1) {				current_depth++;				parent_obj[current_depth] = this_internal_obj;				index[current_depth]    = 0;			}			else {				/*				 * Too many nested levels of packages for us				 * to handle				 */				return (AE_LIMIT);			}		}	}}/****************************************************************************** * * FUNCTION:    Acpi_cm_get_object_size * * PARAMETERS:  *Internal_obj   - Pointer to the object we are examining *              *Ret_length     - Where the length will be returned * * RETURN:      Status          - the status of the call * * DESCRIPTION: This function is called to determine the space required to *              contain an object for return to an API user. * ******************************************************************************/ACPI_STATUSacpi_cm_get_object_size(	ACPI_OPERAND_OBJECT     *internal_obj,	u32                     *obj_length){	ACPI_STATUS             status;	if ((VALID_DESCRIPTOR_TYPE (internal_obj, ACPI_DESC_TYPE_INTERNAL)) &&		(IS_THIS_OBJECT_TYPE (internal_obj, ACPI_TYPE_PACKAGE)))	{		status =			acpi_cm_get_package_object_size (internal_obj, obj_length);	}	else {		status =			acpi_cm_get_simple_object_size (internal_obj, obj_length);	}	return (status);}

⌨️ 快捷键说明

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