13446Smrj /*******************************************************************************
23446Smrj *
33446Smrj * Module Name: nsnames - Name manipulation and search
43446Smrj *
53446Smrj ******************************************************************************/
63446Smrj
73446Smrj /******************************************************************************
83446Smrj *
93446Smrj * 1. Copyright Notice
103446Smrj *
11*9980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj * All rights reserved.
133446Smrj *
143446Smrj * 2. License
153446Smrj *
163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj * rights. You may have additional license terms from the party that provided
183446Smrj * you this software, covering your right to use that party's intellectual
193446Smrj * property rights.
203446Smrj *
213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj * copy of the source code appearing in this file ("Covered Code") an
233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj * make derivatives, distribute, use and display any portion of the Covered
263446Smrj * Code in any form, with the right to sublicense such rights; and
273446Smrj *
283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj * license (with the right to sublicense), under only those claims of Intel
303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj * solely to the minimum extent necessary to exercise the above copyright
333446Smrj * license, and in no event shall the patent license extend to any additions
343446Smrj * to or modifications of the Original Intel Code. No other license or right
353446Smrj * is granted directly or by implication, estoppel or otherwise;
363446Smrj *
373446Smrj * The above copyright and patent license is granted only if the following
383446Smrj * conditions are met:
393446Smrj *
403446Smrj * 3. Conditions
413446Smrj *
423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj * Redistribution of source code of any substantial portion of the Covered
443446Smrj * Code or modification with rights to further distribute source must include
453446Smrj * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj * and the following Disclaimer and Export Compliance provision. In addition,
473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj * contain a file documenting the changes Licensee made to create that Covered
493446Smrj * Code and the date of any change. Licensee must include in that file the
503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee
513446Smrj * must include a prominent statement that the modification is derived,
523446Smrj * directly or indirectly, from Original Intel Code.
533446Smrj *
543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj * Redistribution of source code of any substantial portion of the Covered
563446Smrj * Code or modification without rights to further distribute source must
573446Smrj * include the following Disclaimer and Export Compliance provision in the
583446Smrj * documentation and/or other materials provided with distribution. In
593446Smrj * addition, Licensee may not authorize further sublicense of source of any
603446Smrj * portion of the Covered Code, and must include terms to the effect that the
613446Smrj * license from Licensee to its licensee is limited to the intellectual
623446Smrj * property embodied in the software Licensee provides to its licensee, and
633446Smrj * not to intellectual property embodied in modifications its licensee may
643446Smrj * make.
653446Smrj *
663446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj * substantial portion of the Covered Code or modification must reproduce the
683446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj * provision in the documentation and/or other materials provided with the
703446Smrj * distribution.
713446Smrj *
723446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj * Intel Code.
743446Smrj *
753446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj * other dealings in products derived from or relating to the Covered Code
783446Smrj * without prior written authorization from Intel.
793446Smrj *
803446Smrj * 4. Disclaimer and Export Compliance
813446Smrj *
823446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
853446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
863446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj * PARTICULAR PURPOSE.
893446Smrj *
903446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
963446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj * LIMITED REMEDY.
983446Smrj *
993446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj * software or system incorporating such software without first obtaining any
1013446Smrj * required license or other approval from the U. S. Department of Commerce or
1023446Smrj * any other agency or department of the United States Government. In the
1033446Smrj * event Licensee exports any such software from the United States or
1043446Smrj * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj * ensure that the distribution and export/re-export of the software is in
1063446Smrj * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj * software, or service, directly or indirectly, to any country for which the
1103446Smrj * United States government or any agency thereof requires an export license,
1113446Smrj * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj * such license, approval or letter.
1133446Smrj *
1143446Smrj *****************************************************************************/
1153446Smrj
1163446Smrj #define __NSNAMES_C__
1173446Smrj
1183446Smrj #include "acpi.h"
119*9980SDana.Myers@Sun.COM #include "accommon.h"
1203446Smrj #include "amlcode.h"
1213446Smrj #include "acnamesp.h"
1223446Smrj
1233446Smrj
1243446Smrj #define _COMPONENT ACPI_NAMESPACE
1253446Smrj ACPI_MODULE_NAME ("nsnames")
1263446Smrj
1273446Smrj
1283446Smrj /*******************************************************************************
1293446Smrj *
1303446Smrj * FUNCTION: AcpiNsBuildExternalPath
1313446Smrj *
1323446Smrj * PARAMETERS: Node - NS node whose pathname is needed
1333446Smrj * Size - Size of the pathname
1343446Smrj * *NameBuffer - Where to return the pathname
1353446Smrj *
1367851SDana.Myers@Sun.COM * RETURN: Status
1377851SDana.Myers@Sun.COM * Places the pathname into the NameBuffer, in external format
1383446Smrj * (name segments separated by path separators)
1393446Smrj *
1403446Smrj * DESCRIPTION: Generate a full pathaname
1413446Smrj *
1423446Smrj ******************************************************************************/
1433446Smrj
1447851SDana.Myers@Sun.COM ACPI_STATUS
AcpiNsBuildExternalPath(ACPI_NAMESPACE_NODE * Node,ACPI_SIZE Size,char * NameBuffer)1453446Smrj AcpiNsBuildExternalPath (
1463446Smrj ACPI_NAMESPACE_NODE *Node,
1473446Smrj ACPI_SIZE Size,
1483446Smrj char *NameBuffer)
1493446Smrj {
1503446Smrj ACPI_SIZE Index;
1513446Smrj ACPI_NAMESPACE_NODE *ParentNode;
1523446Smrj
1533446Smrj
1543446Smrj ACPI_FUNCTION_ENTRY ();
1553446Smrj
1563446Smrj
1573446Smrj /* Special case for root */
1583446Smrj
1593446Smrj Index = Size - 1;
1603446Smrj if (Index < ACPI_NAME_SIZE)
1613446Smrj {
1623446Smrj NameBuffer[0] = AML_ROOT_PREFIX;
1633446Smrj NameBuffer[1] = 0;
1647851SDana.Myers@Sun.COM return (AE_OK);
1653446Smrj }
1663446Smrj
1673446Smrj /* Store terminator byte, then build name backwards */
1683446Smrj
1693446Smrj ParentNode = Node;
1703446Smrj NameBuffer[Index] = 0;
1713446Smrj
1723446Smrj while ((Index > ACPI_NAME_SIZE) && (ParentNode != AcpiGbl_RootNode))
1733446Smrj {
1743446Smrj Index -= ACPI_NAME_SIZE;
1753446Smrj
1763446Smrj /* Put the name into the buffer */
1773446Smrj
1783446Smrj ACPI_MOVE_32_TO_32 ((NameBuffer + Index), &ParentNode->Name);
1793446Smrj ParentNode = AcpiNsGetParentNode (ParentNode);
1803446Smrj
1813446Smrj /* Prefix name with the path separator */
1823446Smrj
1833446Smrj Index--;
1843446Smrj NameBuffer[Index] = ACPI_PATH_SEPARATOR;
1853446Smrj }
1863446Smrj
1873446Smrj /* Overwrite final separator with the root prefix character */
1883446Smrj
1893446Smrj NameBuffer[Index] = AML_ROOT_PREFIX;
1903446Smrj
1913446Smrj if (Index != 0)
1923446Smrj {
1933446Smrj ACPI_ERROR ((AE_INFO,
1947851SDana.Myers@Sun.COM "Could not construct external pathname; index=%X, size=%X, Path=%s",
1953446Smrj (UINT32) Index, (UINT32) Size, &NameBuffer[Size]));
1967851SDana.Myers@Sun.COM
1977851SDana.Myers@Sun.COM return (AE_BAD_PARAMETER);
1983446Smrj }
1993446Smrj
2007851SDana.Myers@Sun.COM return (AE_OK);
2013446Smrj }
2023446Smrj
2033446Smrj
2043446Smrj /*******************************************************************************
2053446Smrj *
2063446Smrj * FUNCTION: AcpiNsGetExternalPathname
2073446Smrj *
2083446Smrj * PARAMETERS: Node - Namespace node whose pathname is needed
2093446Smrj *
2103446Smrj * RETURN: Pointer to storage containing the fully qualified name of
2113446Smrj * the node, In external format (name segments separated by path
2123446Smrj * separators.)
2133446Smrj *
214*9980SDana.Myers@Sun.COM * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
215*9980SDana.Myers@Sun.COM * for error and debug statements.
2163446Smrj *
2173446Smrj ******************************************************************************/
2183446Smrj
2193446Smrj char *
AcpiNsGetExternalPathname(ACPI_NAMESPACE_NODE * Node)2203446Smrj AcpiNsGetExternalPathname (
2213446Smrj ACPI_NAMESPACE_NODE *Node)
2223446Smrj {
2237851SDana.Myers@Sun.COM ACPI_STATUS Status;
2243446Smrj char *NameBuffer;
2253446Smrj ACPI_SIZE Size;
2263446Smrj
2273446Smrj
2283446Smrj ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
2293446Smrj
2303446Smrj
2313446Smrj /* Calculate required buffer size based on depth below root */
2323446Smrj
2333446Smrj Size = AcpiNsGetPathnameLength (Node);
2347851SDana.Myers@Sun.COM if (!Size)
2357851SDana.Myers@Sun.COM {
2367851SDana.Myers@Sun.COM return_PTR (NULL);
2377851SDana.Myers@Sun.COM }
2383446Smrj
2393446Smrj /* Allocate a buffer to be returned to caller */
2403446Smrj
2413446Smrj NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
2423446Smrj if (!NameBuffer)
2433446Smrj {
244*9980SDana.Myers@Sun.COM ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
2453446Smrj return_PTR (NULL);
2463446Smrj }
2473446Smrj
2483446Smrj /* Build the path in the allocated buffer */
2493446Smrj
2507851SDana.Myers@Sun.COM Status = AcpiNsBuildExternalPath (Node, Size, NameBuffer);
2517851SDana.Myers@Sun.COM if (ACPI_FAILURE (Status))
2527851SDana.Myers@Sun.COM {
2537851SDana.Myers@Sun.COM ACPI_FREE (NameBuffer);
2547851SDana.Myers@Sun.COM return_PTR (NULL);
2557851SDana.Myers@Sun.COM }
2567851SDana.Myers@Sun.COM
2573446Smrj return_PTR (NameBuffer);
2583446Smrj }
2593446Smrj
2603446Smrj
2613446Smrj /*******************************************************************************
2623446Smrj *
2633446Smrj * FUNCTION: AcpiNsGetPathnameLength
2643446Smrj *
2653446Smrj * PARAMETERS: Node - Namespace node
2663446Smrj *
2673446Smrj * RETURN: Length of path, including prefix
2683446Smrj *
2693446Smrj * DESCRIPTION: Get the length of the pathname string for this node
2703446Smrj *
2713446Smrj ******************************************************************************/
2723446Smrj
2733446Smrj ACPI_SIZE
AcpiNsGetPathnameLength(ACPI_NAMESPACE_NODE * Node)2743446Smrj AcpiNsGetPathnameLength (
2753446Smrj ACPI_NAMESPACE_NODE *Node)
2763446Smrj {
2773446Smrj ACPI_SIZE Size;
2783446Smrj ACPI_NAMESPACE_NODE *NextNode;
2793446Smrj
2803446Smrj
2813446Smrj ACPI_FUNCTION_ENTRY ();
2823446Smrj
2833446Smrj
2843446Smrj /*
2853446Smrj * Compute length of pathname as 5 * number of name segments.
2863446Smrj * Go back up the parent tree to the root
2873446Smrj */
2883446Smrj Size = 0;
2893446Smrj NextNode = Node;
2903446Smrj
2913446Smrj while (NextNode && (NextNode != AcpiGbl_RootNode))
2923446Smrj {
2937851SDana.Myers@Sun.COM if (ACPI_GET_DESCRIPTOR_TYPE (NextNode) != ACPI_DESC_TYPE_NAMED)
2947851SDana.Myers@Sun.COM {
2957851SDana.Myers@Sun.COM ACPI_ERROR ((AE_INFO,
2967851SDana.Myers@Sun.COM "Invalid Namespace Node (%p) while traversing namespace",
2977851SDana.Myers@Sun.COM NextNode));
2987851SDana.Myers@Sun.COM return 0;
2997851SDana.Myers@Sun.COM }
3003446Smrj Size += ACPI_PATH_SEGMENT_LENGTH;
3013446Smrj NextNode = AcpiNsGetParentNode (NextNode);
3023446Smrj }
3033446Smrj
3043446Smrj if (!Size)
3053446Smrj {
306*9980SDana.Myers@Sun.COM Size = 1; /* Root node case */
3073446Smrj }
3083446Smrj
3093446Smrj return (Size + 1); /* +1 for null string terminator */
3103446Smrj }
3113446Smrj
3123446Smrj
3133446Smrj /*******************************************************************************
3143446Smrj *
3153446Smrj * FUNCTION: AcpiNsHandleToPathname
3163446Smrj *
3173446Smrj * PARAMETERS: TargetHandle - Handle of named object whose name is
3183446Smrj * to be found
3193446Smrj * Buffer - Where the pathname is returned
3203446Smrj *
3213446Smrj * RETURN: Status, Buffer is filled with pathname if status is AE_OK
3223446Smrj *
3233446Smrj * DESCRIPTION: Build and return a full namespace pathname
3243446Smrj *
3253446Smrj ******************************************************************************/
3263446Smrj
3273446Smrj ACPI_STATUS
AcpiNsHandleToPathname(ACPI_HANDLE TargetHandle,ACPI_BUFFER * Buffer)3283446Smrj AcpiNsHandleToPathname (
3293446Smrj ACPI_HANDLE TargetHandle,
3303446Smrj ACPI_BUFFER *Buffer)
3313446Smrj {
3323446Smrj ACPI_STATUS Status;
3333446Smrj ACPI_NAMESPACE_NODE *Node;
3343446Smrj ACPI_SIZE RequiredSize;
3353446Smrj
3363446Smrj
3373446Smrj ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle);
3383446Smrj
3393446Smrj
3403446Smrj Node = AcpiNsMapHandleToNode (TargetHandle);
3413446Smrj if (!Node)
3423446Smrj {
3433446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
3443446Smrj }
3453446Smrj
3463446Smrj /* Determine size required for the caller buffer */
3473446Smrj
3483446Smrj RequiredSize = AcpiNsGetPathnameLength (Node);
3497851SDana.Myers@Sun.COM if (!RequiredSize)
3507851SDana.Myers@Sun.COM {
3517851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_BAD_PARAMETER);
3527851SDana.Myers@Sun.COM }
3533446Smrj
3543446Smrj /* Validate/Allocate/Clear caller buffer */
3553446Smrj
3563446Smrj Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
3573446Smrj if (ACPI_FAILURE (Status))
3583446Smrj {
3593446Smrj return_ACPI_STATUS (Status);
3603446Smrj }
3613446Smrj
3623446Smrj /* Build the path in the caller buffer */
3633446Smrj
3647851SDana.Myers@Sun.COM Status = AcpiNsBuildExternalPath (Node, RequiredSize, Buffer->Pointer);
3657851SDana.Myers@Sun.COM if (ACPI_FAILURE (Status))
3667851SDana.Myers@Sun.COM {
3677851SDana.Myers@Sun.COM return_ACPI_STATUS (Status);
3687851SDana.Myers@Sun.COM }
3693446Smrj
3703446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n",
3713446Smrj (char *) Buffer->Pointer, (UINT32) RequiredSize));
3723446Smrj return_ACPI_STATUS (AE_OK);
3733446Smrj }
3743446Smrj
3753446Smrj
376