nsxfname.c revision 167802
167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsxfname - Public interfaces to the ACPI subsystem
467754Smsmith *                         ACPI Namespace oriented interfaces
5167802Sjkim *              $Revision: 1.112 $
667754Smsmith *
767754Smsmith *****************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
13167802Sjkim * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
1470243Smsmith * All rights reserved.
1567754Smsmith *
1667754Smsmith * 2. License
1767754Smsmith *
1867754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1967754Smsmith * rights.  You may have additional license terms from the party that provided
2067754Smsmith * you this software, covering your right to use that party's intellectual
2167754Smsmith * property rights.
2267754Smsmith *
2367754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2467754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2567754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2667754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2767754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2867754Smsmith * Code in any form, with the right to sublicense such rights; and
2967754Smsmith *
3067754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3167754Smsmith * license (with the right to sublicense), under only those claims of Intel
3267754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3367754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3467754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3567754Smsmith * license, and in no event shall the patent license extend to any additions
3667754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3767754Smsmith * is granted directly or by implication, estoppel or otherwise;
3867754Smsmith *
3967754Smsmith * The above copyright and patent license is granted only if the following
4067754Smsmith * conditions are met:
4167754Smsmith *
4267754Smsmith * 3. Conditions
4367754Smsmith *
4467754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4567754Smsmith * Redistribution of source code of any substantial portion of the Covered
4667754Smsmith * Code or modification with rights to further distribute source must include
4767754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4867754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4967754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
5067754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5167754Smsmith * Code and the date of any change.  Licensee must include in that file the
5267754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5367754Smsmith * must include a prominent statement that the modification is derived,
5467754Smsmith * directly or indirectly, from Original Intel Code.
5567754Smsmith *
5667754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5767754Smsmith * Redistribution of source code of any substantial portion of the Covered
5867754Smsmith * Code or modification without rights to further distribute source must
5967754Smsmith * include the following Disclaimer and Export Compliance provision in the
6067754Smsmith * documentation and/or other materials provided with distribution.  In
6167754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6267754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6367754Smsmith * license from Licensee to its licensee is limited to the intellectual
6467754Smsmith * property embodied in the software Licensee provides to its licensee, and
6567754Smsmith * not to intellectual property embodied in modifications its licensee may
6667754Smsmith * make.
6767754Smsmith *
6867754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6967754Smsmith * substantial portion of the Covered Code or modification must reproduce the
7067754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7167754Smsmith * provision in the documentation and/or other materials provided with the
7267754Smsmith * distribution.
7367754Smsmith *
7467754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7567754Smsmith * Intel Code.
7667754Smsmith *
7767754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7867754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7967754Smsmith * other dealings in products derived from or relating to the Covered Code
8067754Smsmith * without prior written authorization from Intel.
8167754Smsmith *
8267754Smsmith * 4. Disclaimer and Export Compliance
8367754Smsmith *
8467754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8567754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8667754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8767754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9067754Smsmith * PARTICULAR PURPOSE.
9167754Smsmith *
9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9967754Smsmith * LIMITED REMEDY.
10067754Smsmith *
10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10267754Smsmith * software or system incorporating such software without first obtaining any
10367754Smsmith * required license or other approval from the U. S. Department of Commerce or
10467754Smsmith * any other agency or department of the United States Government.  In the
10567754Smsmith * event Licensee exports any such software from the United States or
10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10767754Smsmith * ensure that the distribution and export/re-export of the software is in
10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11167754Smsmith * software, or service, directly or indirectly, to any country for which the
11267754Smsmith * United States government or any agency thereof requires an export license,
11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11467754Smsmith * such license, approval or letter.
11567754Smsmith *
11667754Smsmith *****************************************************************************/
11767754Smsmith
11867754Smsmith#define __NSXFNAME_C__
11967754Smsmith
120151600Sobrien#include <contrib/dev/acpica/acpi.h>
121151600Sobrien#include <contrib/dev/acpica/acnamesp.h>
12267754Smsmith
12367754Smsmith
12477424Smsmith#define _COMPONENT          ACPI_NAMESPACE
12591116Smsmith        ACPI_MODULE_NAME    ("nsxfname")
12667754Smsmith
12767754Smsmith
128117521Snjl/******************************************************************************
12967754Smsmith *
13067754Smsmith * FUNCTION:    AcpiGetHandle
13167754Smsmith *
13267754Smsmith * PARAMETERS:  Parent          - Object to search under (search scope).
133151937Sjkim *              Pathname        - Pointer to an asciiz string containing the
134151937Sjkim *                                name
135151937Sjkim *              RetHandle       - Where the return handle is returned
13667754Smsmith *
13767754Smsmith * RETURN:      Status
13867754Smsmith *
13967754Smsmith * DESCRIPTION: This routine will search for a caller specified name in the
14067754Smsmith *              name space.  The caller can restrict the search region by
14167754Smsmith *              specifying a non NULL parent.  The parent value is itself a
14267754Smsmith *              namespace handle.
14367754Smsmith *
14467754Smsmith ******************************************************************************/
14567754Smsmith
14667754SmsmithACPI_STATUS
14767754SmsmithAcpiGetHandle (
14867754Smsmith    ACPI_HANDLE             Parent,
14967754Smsmith    ACPI_STRING             Pathname,
15067754Smsmith    ACPI_HANDLE             *RetHandle)
15167754Smsmith{
15267754Smsmith    ACPI_STATUS             Status;
15369450Smsmith    ACPI_NAMESPACE_NODE     *Node = NULL;
15467754Smsmith    ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
15567754Smsmith
15667754Smsmith
15791116Smsmith    ACPI_FUNCTION_ENTRY ();
15883174Smsmith
15983174Smsmith
16077424Smsmith    /* Parameter Validation */
16177424Smsmith
16267754Smsmith    if (!RetHandle || !Pathname)
16367754Smsmith    {
16467754Smsmith        return (AE_BAD_PARAMETER);
16567754Smsmith    }
16667754Smsmith
16769746Smsmith    /* Convert a parent handle to a prefix node */
16869746Smsmith
16967754Smsmith    if (Parent)
17067754Smsmith    {
17185756Smsmith        PrefixNode = AcpiNsMapHandleToNode (Parent);
17269450Smsmith        if (!PrefixNode)
17367754Smsmith        {
17467754Smsmith            return (AE_BAD_PARAMETER);
17567754Smsmith        }
176167802Sjkim    }
17767754Smsmith
178167802Sjkim    /*
179167802Sjkim     * Valid cases are:
180167802Sjkim     * 1) Fully qualified pathname
181167802Sjkim     * 2) Parent + Relative pathname
182167802Sjkim     *
183167802Sjkim     * Error for <null Parent + relative path>
184167802Sjkim     */
185167802Sjkim    if (AcpiNsValidRootPrefix (Pathname[0]))
186167802Sjkim    {
187167802Sjkim        /* Pathname is fully qualified (starts with '\') */
188167802Sjkim
189167802Sjkim        /* Special case for root-only, since we can't search for it */
190167802Sjkim
191167802Sjkim        if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
19291116Smsmith        {
193167802Sjkim            *RetHandle = AcpiNsConvertEntryToHandle (AcpiGbl_RootNode);
194167802Sjkim            return (AE_OK);
19591116Smsmith        }
19667754Smsmith    }
197167802Sjkim    else if (!PrefixNode)
198167802Sjkim    {
199167802Sjkim        /* Relative path with null prefix is disallowed */
20067754Smsmith
201167802Sjkim        return (AE_BAD_PARAMETER);
20267754Smsmith    }
20367754Smsmith
204167802Sjkim    /* Find the Node and convert to a handle */
20567754Smsmith
206167802Sjkim    Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
20769746Smsmith    if (ACPI_SUCCESS (Status))
20867754Smsmith    {
20967754Smsmith        *RetHandle = AcpiNsConvertEntryToHandle (Node);
21067754Smsmith    }
21167754Smsmith
21267754Smsmith    return (Status);
21367754Smsmith}
21467754Smsmith
215167802SjkimACPI_EXPORT_SYMBOL (AcpiGetHandle)
21667754Smsmith
217167802Sjkim
218117521Snjl/******************************************************************************
21967754Smsmith *
22083174Smsmith * FUNCTION:    AcpiGetName
22167754Smsmith *
22267754Smsmith * PARAMETERS:  Handle          - Handle to be converted to a pathname
22367754Smsmith *              NameType        - Full pathname or single segment
22491116Smsmith *              Buffer          - Buffer for returned path
22567754Smsmith *
22667754Smsmith * RETURN:      Pointer to a string containing the fully qualified Name.
22767754Smsmith *
22867754Smsmith * DESCRIPTION: This routine returns the fully qualified name associated with
22967754Smsmith *              the Handle parameter.  This and the AcpiPathnameToHandle are
23067754Smsmith *              complementary functions.
23167754Smsmith *
23267754Smsmith ******************************************************************************/
23367754Smsmith
23467754SmsmithACPI_STATUS
23567754SmsmithAcpiGetName (
23667754Smsmith    ACPI_HANDLE             Handle,
23767754Smsmith    UINT32                  NameType,
23891116Smsmith    ACPI_BUFFER             *Buffer)
23967754Smsmith{
24067754Smsmith    ACPI_STATUS             Status;
24167754Smsmith    ACPI_NAMESPACE_NODE     *Node;
24267754Smsmith
24367754Smsmith
24491116Smsmith    /* Parameter validation */
24567754Smsmith
24691116Smsmith    if (NameType > ACPI_NAME_TYPE_MAX)
24767754Smsmith    {
24867754Smsmith        return (AE_BAD_PARAMETER);
24967754Smsmith    }
25067754Smsmith
25191116Smsmith    Status = AcpiUtValidateBuffer (Buffer);
25291116Smsmith    if (ACPI_FAILURE (Status))
25367754Smsmith    {
25491116Smsmith        return (Status);
25567754Smsmith    }
25667754Smsmith
25767754Smsmith    if (NameType == ACPI_FULL_PATHNAME)
25867754Smsmith    {
25967754Smsmith        /* Get the full pathname (From the namespace root) */
26067754Smsmith
26191116Smsmith        Status = AcpiNsHandleToPathname (Handle, Buffer);
26267754Smsmith        return (Status);
26367754Smsmith    }
26467754Smsmith
26567754Smsmith    /*
26667754Smsmith     * Wants the single segment ACPI name.
26791116Smsmith     * Validate handle and convert to a namespace Node
26867754Smsmith     */
26991116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
27091116Smsmith    if (ACPI_FAILURE (Status))
27191116Smsmith    {
27291116Smsmith        return (Status);
27391116Smsmith    }
27491116Smsmith
27585756Smsmith    Node = AcpiNsMapHandleToNode (Handle);
27667754Smsmith    if (!Node)
27767754Smsmith    {
27867754Smsmith        Status = AE_BAD_PARAMETER;
27967754Smsmith        goto UnlockAndExit;
28067754Smsmith    }
28167754Smsmith
28291116Smsmith    /* Validate/Allocate/Clear caller buffer */
28367754Smsmith
284114237Snjl    Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
28591116Smsmith    if (ACPI_FAILURE (Status))
28667754Smsmith    {
28767754Smsmith        goto UnlockAndExit;
28867754Smsmith    }
28967754Smsmith
29067754Smsmith    /* Just copy the ACPI name from the Node and zero terminate it */
29167754Smsmith
292123315Snjl    ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
29367754Smsmith                ACPI_NAME_SIZE);
294114237Snjl    ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
29567754Smsmith    Status = AE_OK;
29667754Smsmith
29767754Smsmith
29867754SmsmithUnlockAndExit:
29967754Smsmith
30091116Smsmith    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
30167754Smsmith    return (Status);
30267754Smsmith}
30367754Smsmith
304167802SjkimACPI_EXPORT_SYMBOL (AcpiGetName)
30567754Smsmith
306167802Sjkim
307117521Snjl/******************************************************************************
30867754Smsmith *
30967754Smsmith * FUNCTION:    AcpiGetObjectInfo
31067754Smsmith *
31167754Smsmith * PARAMETERS:  Handle          - Object Handle
312151937Sjkim *              Buffer          - Where the info is returned
31367754Smsmith *
31467754Smsmith * RETURN:      Status
31567754Smsmith *
31667754Smsmith * DESCRIPTION: Returns information about an object as gleaned from the
31767754Smsmith *              namespace node and possibly by running several standard
31867754Smsmith *              control methods (Such as in the case of a device.)
31967754Smsmith *
32067754Smsmith ******************************************************************************/
32167754Smsmith
32267754SmsmithACPI_STATUS
32367754SmsmithAcpiGetObjectInfo (
32467754Smsmith    ACPI_HANDLE             Handle,
325117521Snjl    ACPI_BUFFER             *Buffer)
32667754Smsmith{
32767754Smsmith    ACPI_STATUS             Status;
32867754Smsmith    ACPI_NAMESPACE_NODE     *Node;
329151937Sjkim    ACPI_DEVICE_INFO        *Info;
330117521Snjl    ACPI_DEVICE_INFO        *ReturnInfo;
331117521Snjl    ACPI_COMPATIBLE_ID_LIST *CidList = NULL;
332117521Snjl    ACPI_SIZE               Size;
33367754Smsmith
33467754Smsmith
33567754Smsmith    /* Parameter validation */
33667754Smsmith
337117521Snjl    if (!Handle || !Buffer)
33867754Smsmith    {
33967754Smsmith        return (AE_BAD_PARAMETER);
34067754Smsmith    }
34167754Smsmith
342117521Snjl    Status = AcpiUtValidateBuffer (Buffer);
343117521Snjl    if (ACPI_FAILURE (Status))
344117521Snjl    {
345117521Snjl        return (Status);
346117521Snjl    }
347117521Snjl
348167802Sjkim    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_INFO));
349151937Sjkim    if (!Info)
350151937Sjkim    {
351151937Sjkim        return (AE_NO_MEMORY);
352151937Sjkim    }
353151937Sjkim
35491116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
35591116Smsmith    if (ACPI_FAILURE (Status))
35691116Smsmith    {
357151937Sjkim        goto Cleanup;
35891116Smsmith    }
35967754Smsmith
36085756Smsmith    Node = AcpiNsMapHandleToNode (Handle);
36167754Smsmith    if (!Node)
36267754Smsmith    {
36391116Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
364151937Sjkim        goto Cleanup;
36567754Smsmith    }
36667754Smsmith
367117521Snjl    /* Init return structure */
36867754Smsmith
369117521Snjl    Size = sizeof (ACPI_DEVICE_INFO);
370117521Snjl
371151937Sjkim    Info->Type  = Node->Type;
372151937Sjkim    Info->Name  = Node->Name.Integer;
373151937Sjkim    Info->Valid = 0;
374117521Snjl
37591116Smsmith    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
37691116Smsmith    if (ACPI_FAILURE (Status))
37791116Smsmith    {
378151937Sjkim        goto Cleanup;
37991116Smsmith    }
38067754Smsmith
381117521Snjl    /* If not a device, we are all done */
382117521Snjl
383151937Sjkim    if (Info->Type == ACPI_TYPE_DEVICE)
38467754Smsmith    {
385117521Snjl        /*
386117521Snjl         * Get extra info for ACPI Devices objects only:
387129684Snjl         * Run the Device _HID, _UID, _CID, _STA, _ADR and _SxD methods.
388123315Snjl         *
389117521Snjl         * Note: none of these methods are required, so they may or may
390151937Sjkim         * not be present for this device.  The Info->Valid bitfield is used
391117521Snjl         * to indicate which methods were found and ran successfully.
392117521Snjl         */
39367754Smsmith
394117521Snjl        /* Execute the Device._HID method */
39567754Smsmith
396151937Sjkim        Status = AcpiUtExecute_HID (Node, &Info->HardwareId);
397117521Snjl        if (ACPI_SUCCESS (Status))
398117521Snjl        {
399151937Sjkim            Info->Valid |= ACPI_VALID_HID;
400117521Snjl        }
40167754Smsmith
402117521Snjl        /* Execute the Device._UID method */
40367754Smsmith
404151937Sjkim        Status = AcpiUtExecute_UID (Node, &Info->UniqueId);
405117521Snjl        if (ACPI_SUCCESS (Status))
406117521Snjl        {
407151937Sjkim            Info->Valid |= ACPI_VALID_UID;
408117521Snjl        }
409117521Snjl
410117521Snjl        /* Execute the Device._CID method */
411117521Snjl
412117521Snjl        Status = AcpiUtExecute_CID (Node, &CidList);
413117521Snjl        if (ACPI_SUCCESS (Status))
414117521Snjl        {
415167802Sjkim            Size += CidList->Size;
416151937Sjkim            Info->Valid |= ACPI_VALID_CID;
417117521Snjl        }
418117521Snjl
419117521Snjl        /* Execute the Device._STA method */
420117521Snjl
421151937Sjkim        Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
422117521Snjl        if (ACPI_SUCCESS (Status))
423117521Snjl        {
424151937Sjkim            Info->Valid |= ACPI_VALID_STA;
425117521Snjl        }
426117521Snjl
427117521Snjl        /* Execute the Device._ADR method */
428117521Snjl
429123315Snjl        Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
430151937Sjkim                        &Info->Address);
431117521Snjl        if (ACPI_SUCCESS (Status))
432117521Snjl        {
433151937Sjkim            Info->Valid |= ACPI_VALID_ADR;
434117521Snjl        }
435117521Snjl
436126372Snjl        /* Execute the Device._SxD methods */
437126372Snjl
438151937Sjkim        Status = AcpiUtExecute_Sxds (Node, Info->HighestDstates);
439126372Snjl        if (ACPI_SUCCESS (Status))
440126372Snjl        {
441151937Sjkim            Info->Valid |= ACPI_VALID_SXDS;
442126372Snjl        }
44367754Smsmith    }
44467754Smsmith
445117521Snjl    /* Validate/Allocate/Clear caller buffer */
44667754Smsmith
447117521Snjl    Status = AcpiUtInitializeBuffer (Buffer, Size);
448117521Snjl    if (ACPI_FAILURE (Status))
44967754Smsmith    {
450117521Snjl        goto Cleanup;
45167754Smsmith    }
45267754Smsmith
453117521Snjl    /* Populate the return buffer */
454117521Snjl
455117521Snjl    ReturnInfo = Buffer->Pointer;
456151937Sjkim    ACPI_MEMCPY (ReturnInfo, Info, sizeof (ACPI_DEVICE_INFO));
457117521Snjl
458117521Snjl    if (CidList)
45967754Smsmith    {
460117521Snjl        ACPI_MEMCPY (&ReturnInfo->CompatibilityId, CidList, CidList->Size);
46167754Smsmith    }
46267754Smsmith
46367754Smsmith
464117521SnjlCleanup:
465167802Sjkim    ACPI_FREE (Info);
466117521Snjl    if (CidList)
46767754Smsmith    {
468167802Sjkim        ACPI_FREE (CidList);
46967754Smsmith    }
470117521Snjl    return (Status);
47167754Smsmith}
47267754Smsmith
473167802SjkimACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
474167802Sjkim
475