nsnames.c revision 117521
11722Sjkh/******************************************************************************* 21722Sjkh * 31722Sjkh * Module Name: nsnames - Name manipulation and search 41722Sjkh * $Revision: 83 $ 51722Sjkh * 61722Sjkh ******************************************************************************/ 71722Sjkh 81722Sjkh/****************************************************************************** 91722Sjkh * 101722Sjkh * 1. Copyright Notice 111722Sjkh * 121722Sjkh * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp. 131722Sjkh * All rights reserved. 141722Sjkh * 151722Sjkh * 2. License 161722Sjkh * 171722Sjkh * 2.1. This is your license from Intel Corp. under its intellectual property 181722Sjkh * rights. You may have additional license terms from the party that provided 191722Sjkh * you this software, covering your right to use that party's intellectual 201722Sjkh * property rights. 211722Sjkh * 221722Sjkh * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 231722Sjkh * copy of the source code appearing in this file ("Covered Code") an 241722Sjkh * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2556995Sluigi * base code distributed originally by Intel ("Original Intel Code") to copy, 2656995Sluigi * make derivatives, distribute, use and display any portion of the Covered 271722Sjkh * Code in any form, with the right to sublicense such rights; and 281722Sjkh * 291722Sjkh * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 301722Sjkh * license (with the right to sublicense), under only those claims of Intel 311722Sjkh * patents that are infringed by the Original Intel Code, to make, use, sell, 321722Sjkh * offer to sell, and import the Covered Code and derivative works thereof 338857Srgrimes * solely to the minimum extent necessary to exercise the above copyright 341722Sjkh * license, and in no event shall the patent license extend to any additions 3529453Scharnier * to or modifications of the Original Intel Code. No other license or right 3629453Scharnier * is granted directly or by implication, estoppel or otherwise; 3729453Scharnier * 381722Sjkh * The above copyright and patent license is granted only if the following 3929453Scharnier * conditions are met: 401722Sjkh * 411722Sjkh * 3. Conditions 421722Sjkh * 431722Sjkh * 3.1. Redistribution of Source with Rights to Further Distribute Source. 441722Sjkh * Redistribution of source code of any substantial portion of the Covered 451722Sjkh * Code or modification with rights to further distribute source must include 461722Sjkh * the above Copyright Notice, the above License, this list of Conditions, 471722Sjkh * and the following Disclaimer and Export Compliance provision. In addition, 481722Sjkh * Licensee must cause all Covered Code to which Licensee contributes to 491722Sjkh * contain a file documenting the changes Licensee made to create that Covered 501722Sjkh * Code and the date of any change. Licensee must include in that file the 511722Sjkh * documentation of any changes made by any predecessor Licensee. Licensee 521722Sjkh * must include a prominent statement that the modification is derived, 531722Sjkh * directly or indirectly, from Original Intel Code. 541722Sjkh * 551722Sjkh * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 561722Sjkh * Redistribution of source code of any substantial portion of the Covered 571722Sjkh * Code or modification without rights to further distribute source must 581722Sjkh * include the following Disclaimer and Export Compliance provision in the 591722Sjkh * documentation and/or other materials provided with distribution. In 601722Sjkh * addition, Licensee may not authorize further sublicense of source of any 611722Sjkh * portion of the Covered Code, and must include terms to the effect that the 621722Sjkh * license from Licensee to its licensee is limited to the intellectual 631722Sjkh * property embodied in the software Licensee provides to its licensee, and 6456995Sluigi * not to intellectual property embodied in modifications its licensee may 6556995Sluigi * make. 6656995Sluigi * 6756995Sluigi * 3.3. Redistribution of Executable. Redistribution in executable form of any 6870112Sjoe * substantial portion of the Covered Code or modification must reproduce the 6956995Sluigi * above Copyright Notice, and the following Disclaimer and Export Compliance 7056995Sluigi * provision in the documentation and/or other materials provided with the 711722Sjkh * distribution. 7268569Sjoe * 7330120Sjoerg * 3.4. Intel retains all right, title, and interest in and to the Original 741722Sjkh * Intel Code. 751722Sjkh * 761722Sjkh * 3.5. Neither the name Intel nor any other trademark owned or controlled by 771722Sjkh * Intel shall be used in advertising or otherwise to promote the sale, use or 781722Sjkh * other dealings in products derived from or relating to the Covered Code 791722Sjkh * without prior written authorization from Intel. 801722Sjkh * 8168750Sjoe * 4. Disclaimer and Export Compliance 821722Sjkh * 831722Sjkh * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 841722Sjkh * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 851722Sjkh * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 861722Sjkh * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 871722Sjkh * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 881722Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8956995Sluigi * PARTICULAR PURPOSE. 9069413Sluigi * 911722Sjkh * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 921722Sjkh * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 931722Sjkh * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 941722Sjkh * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 951722Sjkh * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9668286Sjoe * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 971722Sjkh * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 986696Sphk * LIMITED REMEDY. 996696Sphk * 1001722Sjkh * 4.3. Licensee shall not export, either directly or indirectly, any of this 1011722Sjkh * software or system incorporating such software without first obtaining any 1021722Sjkh * required license or other approval from the U. S. Department of Commerce or 1031722Sjkh * any other agency or department of the United States Government. In the 1041722Sjkh * event Licensee exports any such software from the United States or 1051722Sjkh * re-exports any such software from a foreign destination, Licensee shall 1061722Sjkh * ensure that the distribution and export/re-export of the software is in 1071722Sjkh * compliance with all laws, regulations, orders, or other restrictions of the 1081722Sjkh * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1091722Sjkh * any of its subsidiaries will export/re-export any technical data, process, 1108857Srgrimes * software, or service, directly or indirectly, to any country for which the 1111722Sjkh * United States government or any agency thereof requires an export license, 1121722Sjkh * other governmental approval, or letter of assurance, without first obtaining 1131722Sjkh * such license, approval or letter. 1141722Sjkh * 1151722Sjkh *****************************************************************************/ 1161722Sjkh 1171722Sjkh#define __NSNAMES_C__ 1181722Sjkh 1191722Sjkh#include "acpi.h" 1201722Sjkh#include "amlcode.h" 1211722Sjkh#include "acnamesp.h" 1221722Sjkh 1238857Srgrimes 12469413Sluigi#define _COMPONENT ACPI_NAMESPACE 12569413Sluigi ACPI_MODULE_NAME ("nsnames") 12669413Sluigi 12769413Sluigi 12869413Sluigi/******************************************************************************* 12969413Sluigi * 13069413Sluigi * FUNCTION: AcpiNsBuildExternalPath 1311722Sjkh * 1321722Sjkh * PARAMETERS: Node - NS node whose pathname is needed 13368286Sjoe * Size - Size of the pathname 1341722Sjkh * *NameBuffer - Where to return the pathname 1351722Sjkh * 1361722Sjkh * RETURN: Places the pathname into the NameBuffer, in external format 13769413Sluigi * (name segments separated by path separators) 13856995Sluigi * 1391722Sjkh * DESCRIPTION: Generate a full pathaname 1401722Sjkh * 1416696Sphk ******************************************************************************/ 1421722Sjkh 1431722Sjkhvoid 1441722SjkhAcpiNsBuildExternalPath ( 1451722Sjkh ACPI_NAMESPACE_NODE *Node, 1461722Sjkh ACPI_SIZE Size, 1471722Sjkh char *NameBuffer) 1481722Sjkh{ 1491722Sjkh ACPI_SIZE Index; 1501722Sjkh ACPI_NAMESPACE_NODE *ParentNode; 1511722Sjkh 1521722Sjkh 1538857Srgrimes ACPI_FUNCTION_NAME ("NsBuildExternalPath"); 1541722Sjkh 1551722Sjkh 1561722Sjkh /* Special case for root */ 1571722Sjkh 1581722Sjkh Index = Size - 1; 1591722Sjkh if (Index < ACPI_NAME_SIZE) 1601722Sjkh { 1611722Sjkh NameBuffer[0] = AML_ROOT_PREFIX; 1621722Sjkh NameBuffer[1] = 0; 1631722Sjkh return; 1641722Sjkh } 1651722Sjkh 1661722Sjkh /* Store terminator byte, then build name backwards */ 1671722Sjkh 1681722Sjkh ParentNode = Node; 16969413Sluigi NameBuffer[Index] = 0; 17069413Sluigi 1711722Sjkh while ((Index > ACPI_NAME_SIZE) && (ParentNode != AcpiGbl_RootNode)) 1721722Sjkh { 1731722Sjkh Index -= ACPI_NAME_SIZE; 1741722Sjkh 1751722Sjkh /* Put the name into the buffer */ 1761722Sjkh 1776696Sphk ACPI_MOVE_32_TO_32 ((NameBuffer + Index), &ParentNode->Name); 1786696Sphk ParentNode = AcpiNsGetParentNode (ParentNode); 1796696Sphk 1801722Sjkh /* Prefix name with the path separator */ 1811722Sjkh 1821722Sjkh Index--; 1831722Sjkh NameBuffer[Index] = ACPI_PATH_SEPARATOR; 1841722Sjkh } 1851722Sjkh 1861722Sjkh /* Overwrite final separator with the root prefix character */ 1871722Sjkh 18829453Scharnier NameBuffer[Index] = AML_ROOT_PREFIX; 18969413Sluigi 19069413Sluigi if (Index != 0) 1911722Sjkh { 1921722Sjkh ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 1931722Sjkh "Could not construct pathname; index=%X, size=%X, Path=%s\n", 1941722Sjkh (UINT32) Index, (UINT32) Size, &NameBuffer[Size])); 1951722Sjkh } 1961722Sjkh 1971722Sjkh return; 1981722Sjkh} 1991722Sjkh 2001722Sjkh 2011722Sjkh#ifdef ACPI_DEBUG_OUTPUT 2021722Sjkh/******************************************************************************* 2031722Sjkh * 2048857Srgrimes * FUNCTION: AcpiNsGetExternalPathname 2051722Sjkh * 2061722Sjkh * PARAMETERS: Node - NS node whose pathname is needed 2071722Sjkh * 2081722Sjkh * RETURN: Pointer to storage containing the fully qualified name of 20968750Sjoe * the node, In external format (name segments separated by path 2101722Sjkh * separators.) 2111722Sjkh * 2121722Sjkh * DESCRIPTION: Used for debug printing in AcpiNsSearchTable(). 2131722Sjkh * 2141722Sjkh ******************************************************************************/ 2151722Sjkh 2161722Sjkhchar * 2171722SjkhAcpiNsGetExternalPathname ( 21829453Scharnier ACPI_NAMESPACE_NODE *Node) 21929453Scharnier{ 2201722Sjkh char *NameBuffer; 2211722Sjkh ACPI_SIZE Size; 2221722Sjkh 2231722Sjkh 2241722Sjkh ACPI_FUNCTION_TRACE_PTR ("NsGetExternalPathname", Node); 2251722Sjkh 2261722Sjkh 2271722Sjkh /* Calculate required buffer size based on depth below root */ 2281722Sjkh 2291722Sjkh Size = AcpiNsGetPathnameLength (Node); 2301722Sjkh 2311722Sjkh /* Allocate a buffer to be returned to caller */ 2321722Sjkh 2331722Sjkh NameBuffer = ACPI_MEM_CALLOCATE (Size); 23469413Sluigi if (!NameBuffer) 2351722Sjkh { 2361722Sjkh ACPI_REPORT_ERROR (("NsGetTablePathname: allocation failure\n")); 2371722Sjkh return_PTR (NULL); 2381722Sjkh } 2391722Sjkh 2401722Sjkh /* Build the path in the allocated buffer */ 24129453Scharnier 2421722Sjkh AcpiNsBuildExternalPath (Node, Size, NameBuffer); 2431722Sjkh return_PTR (NameBuffer); 2441722Sjkh} 2451722Sjkh#endif 2461722Sjkh 2471722Sjkh 2481722Sjkh/******************************************************************************* 2491722Sjkh * 2501722Sjkh * FUNCTION: AcpiNsGetPathnameLength 2511722Sjkh * 2521722Sjkh * PARAMETERS: Node - Namespace node 2531722Sjkh * 2541722Sjkh * RETURN: Length of path, including prefix 25568750Sjoe * 2561722Sjkh * DESCRIPTION: Get the length of the pathname string for this node 2571722Sjkh * 25829453Scharnier ******************************************************************************/ 2591722Sjkh 2601722SjkhACPI_SIZE 2611722SjkhAcpiNsGetPathnameLength ( 2621722Sjkh ACPI_NAMESPACE_NODE *Node) 2631722Sjkh{ 26429453Scharnier ACPI_SIZE Size; 2651722Sjkh ACPI_NAMESPACE_NODE *NextNode; 2661722Sjkh 2671722Sjkh 2681722Sjkh ACPI_FUNCTION_ENTRY (); 2691722Sjkh 2701722Sjkh 2711722Sjkh /* 2721722Sjkh * Compute length of pathname as 5 * number of name segments. 27329453Scharnier * Go back up the parent tree to the root 2741722Sjkh */ 2751722Sjkh Size = 0; 2761722Sjkh NextNode = Node; 2771722Sjkh 2781722Sjkh while (NextNode && (NextNode != AcpiGbl_RootNode)) 2791722Sjkh { 2801722Sjkh Size += ACPI_PATH_SEGMENT_LENGTH; 2811722Sjkh NextNode = AcpiNsGetParentNode (NextNode); 2821722Sjkh } 2831722Sjkh 2841722Sjkh return (Size + 1); 2851722Sjkh} 2861722Sjkh 2871722Sjkh 2881722Sjkh/******************************************************************************* 2891722Sjkh * 2901722Sjkh * FUNCTION: AcpiNsHandleToPathname 2911722Sjkh * 2921722Sjkh * PARAMETERS: TargetHandle - Handle of named object whose name is 2931722Sjkh * to be found 2941722Sjkh * Buffer - Where the pathname is returned 2951722Sjkh * 2961722Sjkh * RETURN: Status, Buffer is filled with pathname if status is AE_OK 2971722Sjkh * 2981722Sjkh * DESCRIPTION: Build and return a full namespace pathname 2991722Sjkh * 3001722Sjkh ******************************************************************************/ 3011722Sjkh 3021722SjkhACPI_STATUS 3031722SjkhAcpiNsHandleToPathname ( 3041722Sjkh ACPI_HANDLE TargetHandle, 3051722Sjkh ACPI_BUFFER *Buffer) 3061722Sjkh{ 30729453Scharnier ACPI_STATUS Status; 3081722Sjkh ACPI_NAMESPACE_NODE *Node; 3091722Sjkh ACPI_SIZE RequiredSize; 3101722Sjkh 3111722Sjkh 3121722Sjkh ACPI_FUNCTION_TRACE_PTR ("NsHandleToPathname", TargetHandle); 3131722Sjkh 3141722Sjkh 3151722Sjkh Node = AcpiNsMapHandleToNode (TargetHandle); 3161722Sjkh if (!Node) 3171722Sjkh { 3181722Sjkh return_ACPI_STATUS (AE_BAD_PARAMETER); 3191722Sjkh } 3201722Sjkh 3211722Sjkh /* Determine size required for the caller buffer */ 3221722Sjkh 3231722Sjkh RequiredSize = AcpiNsGetPathnameLength (Node); 3241722Sjkh 3251722Sjkh /* Validate/Allocate/Clear caller buffer */ 3261722Sjkh 3271722Sjkh Status = AcpiUtInitializeBuffer (Buffer, RequiredSize); 3281722Sjkh if (ACPI_FAILURE (Status)) 3291722Sjkh { 3301722Sjkh return_ACPI_STATUS (Status); 3311722Sjkh } 3321722Sjkh 3331722Sjkh /* Build the path in the caller buffer */ 33419822Sjoerg 33519822Sjoerg AcpiNsBuildExternalPath (Node, RequiredSize, Buffer->Pointer); 33619822Sjoerg 33719822Sjoerg ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X] \n", (char *) Buffer->Pointer, (UINT32) RequiredSize)); 3388857Srgrimes return_ACPI_STATUS (AE_OK); 3391722Sjkh} 3401722Sjkh 3411722Sjkh 3421722Sjkh