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

📄 nsutils.c

📁 h内核
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* Build the name */	info.internal_name = internal_name;	status = acpi_ns_build_internal_name (&info);	if (ACPI_FAILURE (status)) {		ACPI_MEM_FREE (internal_name);		return_ACPI_STATUS (status);	}	*converted_name = internal_name;	return_ACPI_STATUS (AE_OK);}/******************************************************************************* * * FUNCTION:    acpi_ns_externalize_name * * PARAMETERS:  *internal_name         - Internal representation of name *              **converted_name       - Where to return the resulting *                                       external representation of name * * RETURN:      Status * * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) *              to its external form (e.g. "\_PR_.CPU0") * ******************************************************************************/acpi_statusacpi_ns_externalize_name (	u32                             internal_name_length,	char                            *internal_name,	u32                             *converted_name_length,	char                            **converted_name){	acpi_native_uint                names_index = 0;	acpi_native_uint                num_segments = 0;	acpi_native_uint                required_length;	acpi_native_uint                prefix_length = 0;	acpi_native_uint                i = 0;	acpi_native_uint                j = 0;	ACPI_FUNCTION_TRACE ("ns_externalize_name");	if (!internal_name_length   ||		!internal_name          ||		!converted_name) {		return_ACPI_STATUS (AE_BAD_PARAMETER);	}	/*	 * Check for a prefix (one '\' | one or more '^').	 */	switch (internal_name[0]) {	case '\\':		prefix_length = 1;		break;	case '^':		for (i = 0; i < internal_name_length; i++) {			if (internal_name[i] == '^') {				prefix_length = i + 1;			}			else {				break;			}		}		if (i == internal_name_length) {			prefix_length = i;		}		break;	default:		break;	}	/*	 * Check for object names.  Note that there could be 0-255 of these	 * 4-byte elements.	 */	if (prefix_length < internal_name_length) {		switch (internal_name[prefix_length]) {		case AML_MULTI_NAME_PREFIX_OP:			/* <count> 4-byte names */			names_index = prefix_length + 2;			num_segments = (acpi_native_uint) (u8)					   internal_name[(acpi_native_uint) (prefix_length + 1)];			break;		case AML_DUAL_NAME_PREFIX:			/* Two 4-byte names */			names_index = prefix_length + 1;			num_segments = 2;			break;		case 0:			/* null_name */			names_index = 0;			num_segments = 0;			break;		default:			/* one 4-byte name */			names_index = prefix_length;			num_segments = 1;			break;		}	}	/*	 * Calculate the length of converted_name, which equals the length	 * of the prefix, length of all object names, length of any required	 * punctuation ('.') between object names, plus the NULL terminator.	 */	required_length = prefix_length + (4 * num_segments) +			   ((num_segments > 0) ? (num_segments - 1) : 0) + 1;	/*	 * Check to see if we're still in bounds.  If not, there's a problem	 * with internal_name (invalid format).	 */	if (required_length > internal_name_length) {		ACPI_REPORT_ERROR (("ns_externalize_name: Invalid internal name\n"));		return_ACPI_STATUS (AE_BAD_PATHNAME);	}	/*	 * Build converted_name	 */	*converted_name = ACPI_MEM_CALLOCATE (required_length);	if (!(*converted_name)) {		return_ACPI_STATUS (AE_NO_MEMORY);	}	j = 0;	for (i = 0; i < prefix_length; i++) {		(*converted_name)[j++] = internal_name[i];	}	if (num_segments > 0) {		for (i = 0; i < num_segments; i++) {			if (i > 0) {				(*converted_name)[j++] = '.';			}			(*converted_name)[j++] = internal_name[names_index++];			(*converted_name)[j++] = internal_name[names_index++];			(*converted_name)[j++] = internal_name[names_index++];			(*converted_name)[j++] = internal_name[names_index++];		}	}	if (converted_name_length) {		*converted_name_length = (u32) required_length;	}	return_ACPI_STATUS (AE_OK);}/******************************************************************************* * * FUNCTION:    acpi_ns_map_handle_to_node * * PARAMETERS:  Handle          - Handle to be converted to an Node * * RETURN:      A Name table entry pointer * * DESCRIPTION: Convert a namespace handle to a real Node * * Note: Real integer handles allow for more verification *       and keep all pointers within this subsystem. * ******************************************************************************/struct acpi_namespace_node *acpi_ns_map_handle_to_node (	acpi_handle                     handle){	ACPI_FUNCTION_ENTRY ();	/*	 * Simple implementation.	 */	if (!handle) {		return (NULL);	}	if (handle == ACPI_ROOT_OBJECT) {		return (acpi_gbl_root_node);	}	/* We can at least attempt to verify the handle */	if (ACPI_GET_DESCRIPTOR_TYPE (handle) != ACPI_DESC_TYPE_NAMED) {		return (NULL);	}	return ((struct acpi_namespace_node *) handle);}/******************************************************************************* * * FUNCTION:    acpi_ns_convert_entry_to_handle * * PARAMETERS:  Node          - Node to be converted to a Handle * * RETURN:      A user handle * * DESCRIPTION: Convert a real Node to a namespace handle * ******************************************************************************/acpi_handleacpi_ns_convert_entry_to_handle (	struct acpi_namespace_node          *node){	/*	 * Simple implementation for now;	 */	return ((acpi_handle) node);/* ---------------------------------------------------	if (!Node)	{		return (NULL);	}	if (Node == acpi_gbl_root_node)	{		return (ACPI_ROOT_OBJECT);	}	return ((acpi_handle) Node);------------------------------------------------------*/}/******************************************************************************* * * FUNCTION:    acpi_ns_terminate * * PARAMETERS:  none * * RETURN:      none * * DESCRIPTION: free memory allocated for table storage. * ******************************************************************************/voidacpi_ns_terminate (void){	union acpi_operand_object       *obj_desc;	ACPI_FUNCTION_TRACE ("ns_terminate");	/*	 * 1) Free the entire namespace -- all nodes and objects	 *	 * Delete all object descriptors attached to namepsace nodes	 */	acpi_ns_delete_namespace_subtree (acpi_gbl_root_node);	/* Detach any objects attached to the root */	obj_desc = acpi_ns_get_attached_object (acpi_gbl_root_node);	if (obj_desc) {		acpi_ns_detach_object (acpi_gbl_root_node);	}	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));	/*	 * 2) Now we can delete the ACPI tables	 */	acpi_tb_delete_all_tables ();	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));	return_VOID;}/******************************************************************************* * * FUNCTION:    acpi_ns_opens_scope * * PARAMETERS:  Type        - A valid namespace type * * RETURN:      NEWSCOPE if the passed type "opens a name scope" according *              to the ACPI specification, else 0 * ******************************************************************************/u32acpi_ns_opens_scope (	acpi_object_type                type){	ACPI_FUNCTION_TRACE_STR ("ns_opens_scope", acpi_ut_get_type_name (type));	if (!acpi_ut_valid_object_type (type)) {		/* type code out of range  */		ACPI_REPORT_WARNING (("ns_opens_scope: Invalid Object Type %X\n", type));		return_VALUE (ACPI_NS_NORMAL);	}	return_VALUE (((u32) acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE);}/******************************************************************************* * * FUNCTION:    acpi_ns_get_node_by_path * * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The *                            \ (backslash) and ^ (carat) prefixes, and the *                            . (period) to separate segments are supported. *              start_node  - Root of subtree to be searched, or NS_ALL for the *                            root of the name space.  If Name is fully *                            qualified (first s8 is '\'), the passed value *                            of Scope will not be accessed. *              Flags       - Used to indicate whether to perform upsearch or *                            not. *              return_node - Where the Node is returned * * DESCRIPTION: Look up a name relative to a given scope and return the *              corresponding Node.  NOTE: Scope can be null. * * MUTEX:       Locks namespace * ******************************************************************************/acpi_statusacpi_ns_get_node_by_path (	char                            *pathname,	struct acpi_namespace_node      *start_node,	u32                             flags,	struct acpi_namespace_node      **return_node){	union acpi_generic_state        scope_info;	acpi_status                     status;	char                            *internal_path = NULL;	ACPI_FUNCTION_TRACE_PTR ("ns_get_node_by_path", pathname);	if (pathname) {		/* Convert path to internal representation */		status = acpi_ns_internalize_name (pathname, &internal_path);		if (ACPI_FAILURE (status)) {			return_ACPI_STATUS (status);		}	}	/* Must lock namespace during lookup */	status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);	if (ACPI_FAILURE (status)) {		goto cleanup;	}	/* Setup lookup scope (search starting point) */	scope_info.scope.node = start_node;	/* Lookup the name in the namespace */	status = acpi_ns_lookup (&scope_info, internal_path,			 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,			 (flags | ACPI_NS_DONT_OPEN_SCOPE),			 NULL, return_node);	if (ACPI_FAILURE (status)) {		ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",				internal_path, acpi_format_exception (status)));	}	(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);cleanup:	/* Cleanup */	if (internal_path) {		ACPI_MEM_FREE (internal_path);	}	return_ACPI_STATUS (status);}/******************************************************************************* * * FUNCTION:    acpi_ns_find_parent_name * * PARAMETERS:  *child_node            - Named Obj whose name is to be found * * RETURN:      The ACPI name * * DESCRIPTION: Search for the given obj in its parent scope and return the *              name segment, or "????" if the parent name can't be found *              (which "should not happen"). * ******************************************************************************/#ifdef ACPI_FUTURE_USAGEacpi_nameacpi_ns_find_parent_name (	struct acpi_namespace_node      *child_node){	struct acpi_namespace_node      *parent_node;	ACPI_FUNCTION_TRACE ("ns_find_parent_name");	if (child_node) {		/* Valid entry.  Get the parent Node */		parent_node = acpi_ns_get_parent_node (child_node);		if (parent_node) {			ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,				"Parent of %p [%4.4s] is %p [%4.4s]\n",				child_node, acpi_ut_get_node_name (child_node),				parent_node, acpi_ut_get_node_name (parent_node)));			if (parent_node->name.integer) {				return_VALUE ((acpi_name) parent_node->name.integer);			}		}		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,			"Unable to find parent of %p (%4.4s)\n",			child_node, acpi_ut_get_node_name (child_node)));	}	return_VALUE (ACPI_UNKNOWN_NAME);}#endif/******************************************************************************* * * FUNCTION:    acpi_ns_get_parent_node * * PARAMETERS:  Node       - Current table entry * * RETURN:      Parent entry of the given entry * * DESCRIPTION: Obtain the parent entry for a given entry in the namespace. * ******************************************************************************/struct acpi_namespace_node *acpi_ns_get_parent_node (	struct acpi_namespace_node      *node){	ACPI_FUNCTION_ENTRY ();	if (!node) {		return (NULL);	}	/*	 * Walk to the end of this peer list. The last entry is marked with a flag	 * and the peer pointer is really a pointer back to the parent. This saves	 * putting a parent back pointer in each and every named object!	 */	while (!(node->flags & ANOBJ_END_OF_PEER_LIST)) {		node = node->peer;	}	return (node->peer);}/******************************************************************************* * * FUNCTION:    acpi_ns_get_next_valid_node * * PARAMETERS:  Node       - Current table entry * * RETURN:      Next valid Node in the linked node list. NULL if no more valid *              nodes. * * DESCRIPTION: Find the next valid node within a name table. *              Useful for implementing NULL-end-of-list loops. * ******************************************************************************/struct acpi_namespace_node *acpi_ns_get_next_valid_node (	struct acpi_namespace_node      *node){	/* If we are at the end of this peer list, return NULL */	if (node->flags & ANOBJ_END_OF_PEER_LIST) {		return NULL;	}	/* Otherwise just return the next peer */	return (node->peer);}

⌨️ 快捷键说明

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