📄 nsutils.c
字号:
/****************************************************************************** * * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing * parents and siblings and Scope manipulation * *****************************************************************************//* * Copyright (C) 2000 - 2005, R. Byron Moore * All rights reserved. * * 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. */#include <acpi/acpi.h>#include <acpi/acnamesp.h>#include <acpi/amlcode.h>#include <acpi/actables.h>#define _COMPONENT ACPI_NAMESPACEACPI_MODULE_NAME("nsutils")/* Local prototypes */static u8 acpi_ns_valid_path_separator(char sep);#ifdef ACPI_OBSOLETE_FUNCTIONSacpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search);#endif/******************************************************************************* * * FUNCTION: acpi_ns_report_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * component_id - Caller's component ID (for error output) * internal_name - Name or path of the namespace node * lookup_status - Exception code from NS lookup * * RETURN: None * * DESCRIPTION: Print warning message with full pathname * ******************************************************************************/voidacpi_ns_report_error(char *module_name, u32 line_number, u32 component_id, char *internal_name, acpi_status lookup_status){ acpi_status status; char *name = NULL; acpi_os_printf("%8s-%04d: *** Error: Looking up ", module_name, line_number); if (lookup_status == AE_BAD_CHARACTER) { /* There is a non-ascii character in the name */ acpi_os_printf("[0x%4.4X] (NON-ASCII)\n", *(ACPI_CAST_PTR(u32, internal_name))); } else { /* Convert path to external format */ status = acpi_ns_externalize_name(ACPI_UINT32_MAX, internal_name, NULL, &name); /* Print target name */ if (ACPI_SUCCESS(status)) { acpi_os_printf("[%s]", name); } else { acpi_os_printf("[COULD NOT EXTERNALIZE NAME]"); } if (name) { ACPI_MEM_FREE(name); } } acpi_os_printf(" in namespace, %s\n", acpi_format_exception(lookup_status));}/******************************************************************************* * * FUNCTION: acpi_ns_report_method_error * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * component_id - Caller's component ID (for error output) * Message - Error message to use on failure * prefix_node - Prefix relative to the path * Path - Path to the node * method_status - Execution status * * RETURN: None * * DESCRIPTION: Print warning message with full pathname * ******************************************************************************/voidacpi_ns_report_method_error(char *module_name, u32 line_number, u32 component_id, char *message, struct acpi_namespace_node *prefix_node, char *path, acpi_status method_status){ acpi_status status; struct acpi_namespace_node *node = prefix_node; if (path) { status = acpi_ns_get_node_by_path(path, prefix_node, ACPI_NS_NO_UPSEARCH, &node); if (ACPI_FAILURE(status)) { acpi_os_printf ("report_method_error: Could not get node\n"); return; } } acpi_os_printf("%8s-%04d: *** Error: ", module_name, line_number); acpi_ns_print_node_pathname(node, message); acpi_os_printf(", %s\n", acpi_format_exception(method_status));}/******************************************************************************* * * FUNCTION: acpi_ns_print_node_pathname * * PARAMETERS: Node - Object * Message - Prefix message * * DESCRIPTION: Print an object's full namespace pathname * Manages allocation/freeing of a pathname buffer * ******************************************************************************/voidacpi_ns_print_node_pathname(struct acpi_namespace_node *node, char *message){ struct acpi_buffer buffer; acpi_status status; if (!node) { acpi_os_printf("[NULL NAME]"); return; } /* Convert handle to full pathname and print it (with supplied message) */ buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; status = acpi_ns_handle_to_pathname(node, &buffer); if (ACPI_SUCCESS(status)) { if (message) { acpi_os_printf("%s ", message); } acpi_os_printf("[%s] (Node %p)", (char *)buffer.pointer, node); ACPI_MEM_FREE(buffer.pointer); }}/******************************************************************************* * * FUNCTION: acpi_ns_valid_root_prefix * * PARAMETERS: Prefix - Character to be checked * * RETURN: TRUE if a valid prefix * * DESCRIPTION: Check if a character is a valid ACPI Root prefix * ******************************************************************************/u8 acpi_ns_valid_root_prefix(char prefix){ return ((u8) (prefix == '\\'));}/******************************************************************************* * * FUNCTION: acpi_ns_valid_path_separator * * PARAMETERS: Sep - Character to be checked * * RETURN: TRUE if a valid path separator * * DESCRIPTION: Check if a character is a valid ACPI path separator * ******************************************************************************/static u8 acpi_ns_valid_path_separator(char sep){ return ((u8) (sep == '.'));}/******************************************************************************* * * FUNCTION: acpi_ns_get_type * * PARAMETERS: Node - Parent Node to be examined * * RETURN: Type field from Node whose handle is passed * * DESCRIPTION: Return the type of a Namespace node * ******************************************************************************/acpi_object_type acpi_ns_get_type(struct acpi_namespace_node * node){ ACPI_FUNCTION_TRACE("ns_get_type"); if (!node) { ACPI_REPORT_WARNING(("ns_get_type: Null Node input pointer\n")); return_VALUE(ACPI_TYPE_ANY); } return_VALUE((acpi_object_type) node->type);}/******************************************************************************* * * FUNCTION: acpi_ns_local * * PARAMETERS: Type - A namespace object type * * RETURN: LOCAL if names must be found locally in objects of the * passed type, 0 if enclosing scopes should be searched * * DESCRIPTION: Returns scope rule for the given object type. * ******************************************************************************/u32 acpi_ns_local(acpi_object_type type){ ACPI_FUNCTION_TRACE("ns_local"); if (!acpi_ut_valid_object_type(type)) { /* Type code out of range */ ACPI_REPORT_WARNING(("ns_local: Invalid Object Type\n")); return_VALUE(ACPI_NS_NORMAL); } return_VALUE((u32) acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL);}/******************************************************************************* * * FUNCTION: acpi_ns_get_internal_name_length * * PARAMETERS: Info - Info struct initialized with the * external name pointer. * * RETURN: None * * DESCRIPTION: Calculate the length of the internal (AML) namestring * corresponding to the external (ASL) namestring. * ******************************************************************************/void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info){ char *next_external_char; u32 i; ACPI_FUNCTION_ENTRY(); next_external_char = info->external_name; info->num_carats = 0; info->num_segments = 0; info->fully_qualified = FALSE; /* * For the internal name, the required length is 4 bytes per segment, plus * 1 each for root_prefix, multi_name_prefix_op, segment count, trailing null * (which is not really needed, but no there's harm in putting it there) * * strlen() + 1 covers the first name_seg, which has no path separator */ if (acpi_ns_valid_root_prefix(next_external_char[0])) { info->fully_qualified = TRUE; next_external_char++; } else { /* * Handle Carat prefixes */ while (*next_external_char == '^') { info->num_carats++; next_external_char++; } } /* * Determine the number of ACPI name "segments" by counting the number of * path separators within the string. Start with one segment since the * segment count is [(# separators) + 1], and zero separators is ok. */ if (*next_external_char) { info->num_segments = 1; for (i = 0; next_external_char[i]; i++) { if (acpi_ns_valid_path_separator(next_external_char[i])) { info->num_segments++; } } } info->length = (ACPI_NAME_SIZE * info->num_segments) + 4 + info->num_carats; info->next_external_char = next_external_char;}/******************************************************************************* * * FUNCTION: acpi_ns_build_internal_name * * PARAMETERS: Info - Info struct fully initialized * * RETURN: Status * * DESCRIPTION: Construct the internal (AML) namestring * corresponding to the external (ASL) namestring. * ******************************************************************************/acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info){ u32 num_segments = info->num_segments; char *internal_name = info->internal_name; char *external_name = info->next_external_char; char *result = NULL; acpi_native_uint i; ACPI_FUNCTION_TRACE("ns_build_internal_name"); /* Setup the correct prefixes, counts, and pointers */ if (info->fully_qualified) { internal_name[0] = '\\'; if (num_segments <= 1) { result = &internal_name[1]; } else if (num_segments == 2) { internal_name[1] = AML_DUAL_NAME_PREFIX; result = &internal_name[2]; } else { internal_name[1] = AML_MULTI_NAME_PREFIX_OP; internal_name[2] = (char)num_segments; result = &internal_name[3]; } } else { /* * Not fully qualified. * Handle Carats first, then append the name segments */ i = 0; if (info->num_carats) { for (i = 0; i < info->num_carats; i++) { internal_name[i] = '^'; } } if (num_segments <= 1) { result = &internal_name[i]; } else if (num_segments == 2) { internal_name[i] = AML_DUAL_NAME_PREFIX; result = &internal_name[(acpi_native_uint) (i + 1)]; } else { internal_name[i] = AML_MULTI_NAME_PREFIX_OP; internal_name[(acpi_native_uint) (i + 1)] = (char)num_segments; result = &internal_name[(acpi_native_uint) (i + 2)]; } } /* Build the name (minus path separators) */ for (; num_segments; num_segments--) { for (i = 0; i < ACPI_NAME_SIZE; i++) { if (acpi_ns_valid_path_separator(*external_name) || (*external_name == 0)) { /* Pad the segment with underscore(s) if segment is short */ result[i] = '_'; } else { /* Convert the character to uppercase and save it */ result[i] = (char)ACPI_TOUPPER((int)*external_name); external_name++; } } /* Now we must have a path separator, or the pathname is bad */ if (!acpi_ns_valid_path_separator(*external_name) && (*external_name != 0)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Move on the next segment */ external_name++; result += ACPI_NAME_SIZE; } /* Terminate the string */ *result = 0; if (info->fully_qualified) { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n", internal_name, internal_name)); } else { ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n", internal_name, internal_name)); } return_ACPI_STATUS(AE_OK);}/******************************************************************************* * * FUNCTION: acpi_ns_internalize_name * * PARAMETERS: *external_name - External representation of name * **Converted Name - Where to return the resulting * internal represention of the name * * RETURN: Status * * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0") * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) * *******************************************************************************/acpi_status acpi_ns_internalize_name(char *external_name, char **converted_name){ char *internal_name; struct acpi_namestring_info info; acpi_status status; ACPI_FUNCTION_TRACE("ns_internalize_name"); if ((!external_name) || (*external_name == 0) || (!converted_name)) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* Get the length of the new internal name */ info.external_name = external_name; acpi_ns_get_internal_name_length(&info); /* We need a segment to store the internal name */ internal_name = ACPI_MEM_CALLOCATE(info.length); if (!internal_name) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Build the name */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -