nsxfname.c revision 193341
167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsxfname - Public interfaces to the ACPI subsystem
467754Smsmith *                         ACPI Namespace oriented interfaces
567754Smsmith *
667754Smsmith *****************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
12193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
1370243Smsmith * All rights reserved.
1467754Smsmith *
1567754Smsmith * 2. License
1667754Smsmith *
1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1867754Smsmith * rights.  You may have additional license terms from the party that provided
1967754Smsmith * you this software, covering your right to use that party's intellectual
2067754Smsmith * property rights.
2167754Smsmith *
2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2767754Smsmith * Code in any form, with the right to sublicense such rights; and
2867754Smsmith *
2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3067754Smsmith * license (with the right to sublicense), under only those claims of Intel
3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3467754Smsmith * license, and in no event shall the patent license extend to any additions
3567754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3667754Smsmith * is granted directly or by implication, estoppel or otherwise;
3767754Smsmith *
3867754Smsmith * The above copyright and patent license is granted only if the following
3967754Smsmith * conditions are met:
4067754Smsmith *
4167754Smsmith * 3. Conditions
4267754Smsmith *
4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4467754Smsmith * Redistribution of source code of any substantial portion of the Covered
4567754Smsmith * Code or modification with rights to further distribute source must include
4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4767754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5067754Smsmith * Code and the date of any change.  Licensee must include in that file the
5167754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5267754Smsmith * must include a prominent statement that the modification is derived,
5367754Smsmith * directly or indirectly, from Original Intel Code.
5467754Smsmith *
5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5667754Smsmith * Redistribution of source code of any substantial portion of the Covered
5767754Smsmith * Code or modification without rights to further distribute source must
5867754Smsmith * include the following Disclaimer and Export Compliance provision in the
5967754Smsmith * documentation and/or other materials provided with distribution.  In
6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6267754Smsmith * license from Licensee to its licensee is limited to the intellectual
6367754Smsmith * property embodied in the software Licensee provides to its licensee, and
6467754Smsmith * not to intellectual property embodied in modifications its licensee may
6567754Smsmith * make.
6667754Smsmith *
6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the
6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7067754Smsmith * provision in the documentation and/or other materials provided with the
7167754Smsmith * distribution.
7267754Smsmith *
7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7467754Smsmith * Intel Code.
7567754Smsmith *
7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7867754Smsmith * other dealings in products derived from or relating to the Covered Code
7967754Smsmith * without prior written authorization from Intel.
8067754Smsmith *
8167754Smsmith * 4. Disclaimer and Export Compliance
8267754Smsmith *
8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8467754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8967754Smsmith * PARTICULAR PURPOSE.
9067754Smsmith *
9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9867754Smsmith * LIMITED REMEDY.
9967754Smsmith *
10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10167754Smsmith * software or system incorporating such software without first obtaining any
10267754Smsmith * required license or other approval from the U. S. Department of Commerce or
10367754Smsmith * any other agency or department of the United States Government.  In the
10467754Smsmith * event Licensee exports any such software from the United States or
10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10667754Smsmith * ensure that the distribution and export/re-export of the software is in
10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11067754Smsmith * software, or service, directly or indirectly, to any country for which the
11167754Smsmith * United States government or any agency thereof requires an export license,
11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11367754Smsmith * such license, approval or letter.
11467754Smsmith *
11567754Smsmith *****************************************************************************/
11667754Smsmith
11767754Smsmith#define __NSXFNAME_C__
11867754Smsmith
119193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
120193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
121193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
122193341Sjkim#include <contrib/dev/acpica/include/acparser.h>
123193341Sjkim#include <contrib/dev/acpica/include/amlcode.h>
12467754Smsmith
12567754Smsmith
12677424Smsmith#define _COMPONENT          ACPI_NAMESPACE
12791116Smsmith        ACPI_MODULE_NAME    ("nsxfname")
12867754Smsmith
12967754Smsmith
130117521Snjl/******************************************************************************
13167754Smsmith *
13267754Smsmith * FUNCTION:    AcpiGetHandle
13367754Smsmith *
13467754Smsmith * PARAMETERS:  Parent          - Object to search under (search scope).
135151937Sjkim *              Pathname        - Pointer to an asciiz string containing the
136151937Sjkim *                                name
137151937Sjkim *              RetHandle       - Where the return handle is returned
13867754Smsmith *
13967754Smsmith * RETURN:      Status
14067754Smsmith *
14167754Smsmith * DESCRIPTION: This routine will search for a caller specified name in the
14267754Smsmith *              name space.  The caller can restrict the search region by
14367754Smsmith *              specifying a non NULL parent.  The parent value is itself a
14467754Smsmith *              namespace handle.
14567754Smsmith *
14667754Smsmith ******************************************************************************/
14767754Smsmith
14867754SmsmithACPI_STATUS
14967754SmsmithAcpiGetHandle (
15067754Smsmith    ACPI_HANDLE             Parent,
15167754Smsmith    ACPI_STRING             Pathname,
15267754Smsmith    ACPI_HANDLE             *RetHandle)
15367754Smsmith{
15467754Smsmith    ACPI_STATUS             Status;
15569450Smsmith    ACPI_NAMESPACE_NODE     *Node = NULL;
15667754Smsmith    ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
15767754Smsmith
15867754Smsmith
15991116Smsmith    ACPI_FUNCTION_ENTRY ();
16083174Smsmith
16183174Smsmith
16277424Smsmith    /* Parameter Validation */
16377424Smsmith
16467754Smsmith    if (!RetHandle || !Pathname)
16567754Smsmith    {
16667754Smsmith        return (AE_BAD_PARAMETER);
16767754Smsmith    }
16867754Smsmith
16969746Smsmith    /* Convert a parent handle to a prefix node */
17069746Smsmith
17167754Smsmith    if (Parent)
17267754Smsmith    {
17385756Smsmith        PrefixNode = AcpiNsMapHandleToNode (Parent);
17469450Smsmith        if (!PrefixNode)
17567754Smsmith        {
17667754Smsmith            return (AE_BAD_PARAMETER);
17767754Smsmith        }
178167802Sjkim    }
17967754Smsmith
180167802Sjkim    /*
181167802Sjkim     * Valid cases are:
182167802Sjkim     * 1) Fully qualified pathname
183167802Sjkim     * 2) Parent + Relative pathname
184167802Sjkim     *
185167802Sjkim     * Error for <null Parent + relative path>
186167802Sjkim     */
187167802Sjkim    if (AcpiNsValidRootPrefix (Pathname[0]))
188167802Sjkim    {
189167802Sjkim        /* Pathname is fully qualified (starts with '\') */
190167802Sjkim
191167802Sjkim        /* Special case for root-only, since we can't search for it */
192167802Sjkim
193167802Sjkim        if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
19491116Smsmith        {
195167802Sjkim            *RetHandle = AcpiNsConvertEntryToHandle (AcpiGbl_RootNode);
196167802Sjkim            return (AE_OK);
19791116Smsmith        }
19867754Smsmith    }
199167802Sjkim    else if (!PrefixNode)
200167802Sjkim    {
201167802Sjkim        /* Relative path with null prefix is disallowed */
20267754Smsmith
203167802Sjkim        return (AE_BAD_PARAMETER);
20467754Smsmith    }
20567754Smsmith
206167802Sjkim    /* Find the Node and convert to a handle */
20767754Smsmith
208167802Sjkim    Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
20969746Smsmith    if (ACPI_SUCCESS (Status))
21067754Smsmith    {
21167754Smsmith        *RetHandle = AcpiNsConvertEntryToHandle (Node);
21267754Smsmith    }
21367754Smsmith
21467754Smsmith    return (Status);
21567754Smsmith}
21667754Smsmith
217167802SjkimACPI_EXPORT_SYMBOL (AcpiGetHandle)
21867754Smsmith
219167802Sjkim
220117521Snjl/******************************************************************************
22167754Smsmith *
22283174Smsmith * FUNCTION:    AcpiGetName
22367754Smsmith *
22467754Smsmith * PARAMETERS:  Handle          - Handle to be converted to a pathname
22567754Smsmith *              NameType        - Full pathname or single segment
22691116Smsmith *              Buffer          - Buffer for returned path
22767754Smsmith *
22867754Smsmith * RETURN:      Pointer to a string containing the fully qualified Name.
22967754Smsmith *
23067754Smsmith * DESCRIPTION: This routine returns the fully qualified name associated with
23167754Smsmith *              the Handle parameter.  This and the AcpiPathnameToHandle are
23267754Smsmith *              complementary functions.
23367754Smsmith *
23467754Smsmith ******************************************************************************/
23567754Smsmith
23667754SmsmithACPI_STATUS
23767754SmsmithAcpiGetName (
23867754Smsmith    ACPI_HANDLE             Handle,
23967754Smsmith    UINT32                  NameType,
24091116Smsmith    ACPI_BUFFER             *Buffer)
24167754Smsmith{
24267754Smsmith    ACPI_STATUS             Status;
24367754Smsmith    ACPI_NAMESPACE_NODE     *Node;
24467754Smsmith
24567754Smsmith
24691116Smsmith    /* Parameter validation */
24767754Smsmith
24891116Smsmith    if (NameType > ACPI_NAME_TYPE_MAX)
24967754Smsmith    {
25067754Smsmith        return (AE_BAD_PARAMETER);
25167754Smsmith    }
25267754Smsmith
25391116Smsmith    Status = AcpiUtValidateBuffer (Buffer);
25491116Smsmith    if (ACPI_FAILURE (Status))
25567754Smsmith    {
25691116Smsmith        return (Status);
25767754Smsmith    }
25867754Smsmith
25967754Smsmith    if (NameType == ACPI_FULL_PATHNAME)
26067754Smsmith    {
26167754Smsmith        /* Get the full pathname (From the namespace root) */
26267754Smsmith
26391116Smsmith        Status = AcpiNsHandleToPathname (Handle, Buffer);
26467754Smsmith        return (Status);
26567754Smsmith    }
26667754Smsmith
26767754Smsmith    /*
26867754Smsmith     * Wants the single segment ACPI name.
26991116Smsmith     * Validate handle and convert to a namespace Node
27067754Smsmith     */
27191116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
27291116Smsmith    if (ACPI_FAILURE (Status))
27391116Smsmith    {
27491116Smsmith        return (Status);
27591116Smsmith    }
27691116Smsmith
27785756Smsmith    Node = AcpiNsMapHandleToNode (Handle);
27867754Smsmith    if (!Node)
27967754Smsmith    {
28067754Smsmith        Status = AE_BAD_PARAMETER;
28167754Smsmith        goto UnlockAndExit;
28267754Smsmith    }
28367754Smsmith
28491116Smsmith    /* Validate/Allocate/Clear caller buffer */
28567754Smsmith
286114237Snjl    Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
28791116Smsmith    if (ACPI_FAILURE (Status))
28867754Smsmith    {
28967754Smsmith        goto UnlockAndExit;
29067754Smsmith    }
29167754Smsmith
29267754Smsmith    /* Just copy the ACPI name from the Node and zero terminate it */
29367754Smsmith
294123315Snjl    ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
29567754Smsmith                ACPI_NAME_SIZE);
296114237Snjl    ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
29767754Smsmith    Status = AE_OK;
29867754Smsmith
29967754Smsmith
30067754SmsmithUnlockAndExit:
30167754Smsmith
30291116Smsmith    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
30367754Smsmith    return (Status);
30467754Smsmith}
30567754Smsmith
306167802SjkimACPI_EXPORT_SYMBOL (AcpiGetName)
30767754Smsmith
308167802Sjkim
309117521Snjl/******************************************************************************
31067754Smsmith *
31167754Smsmith * FUNCTION:    AcpiGetObjectInfo
31267754Smsmith *
31367754Smsmith * PARAMETERS:  Handle          - Object Handle
314151937Sjkim *              Buffer          - Where the info is returned
31567754Smsmith *
31667754Smsmith * RETURN:      Status
31767754Smsmith *
31867754Smsmith * DESCRIPTION: Returns information about an object as gleaned from the
31967754Smsmith *              namespace node and possibly by running several standard
32067754Smsmith *              control methods (Such as in the case of a device.)
32167754Smsmith *
32267754Smsmith ******************************************************************************/
32367754Smsmith
32467754SmsmithACPI_STATUS
32567754SmsmithAcpiGetObjectInfo (
32667754Smsmith    ACPI_HANDLE             Handle,
327117521Snjl    ACPI_BUFFER             *Buffer)
32867754Smsmith{
32967754Smsmith    ACPI_STATUS             Status;
33067754Smsmith    ACPI_NAMESPACE_NODE     *Node;
331151937Sjkim    ACPI_DEVICE_INFO        *Info;
332117521Snjl    ACPI_DEVICE_INFO        *ReturnInfo;
333117521Snjl    ACPI_COMPATIBLE_ID_LIST *CidList = NULL;
334117521Snjl    ACPI_SIZE               Size;
33567754Smsmith
33667754Smsmith
33767754Smsmith    /* Parameter validation */
33867754Smsmith
339117521Snjl    if (!Handle || !Buffer)
34067754Smsmith    {
34167754Smsmith        return (AE_BAD_PARAMETER);
34267754Smsmith    }
34367754Smsmith
344117521Snjl    Status = AcpiUtValidateBuffer (Buffer);
345117521Snjl    if (ACPI_FAILURE (Status))
346117521Snjl    {
347117521Snjl        return (Status);
348117521Snjl    }
349117521Snjl
350167802Sjkim    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_INFO));
351151937Sjkim    if (!Info)
352151937Sjkim    {
353151937Sjkim        return (AE_NO_MEMORY);
354151937Sjkim    }
355151937Sjkim
35691116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
35791116Smsmith    if (ACPI_FAILURE (Status))
35891116Smsmith    {
359151937Sjkim        goto Cleanup;
36091116Smsmith    }
36167754Smsmith
36285756Smsmith    Node = AcpiNsMapHandleToNode (Handle);
36367754Smsmith    if (!Node)
36467754Smsmith    {
36591116Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
366193267Sjkim        Status = AE_BAD_PARAMETER;
367151937Sjkim        goto Cleanup;
36867754Smsmith    }
36967754Smsmith
370117521Snjl    /* Init return structure */
37167754Smsmith
372117521Snjl    Size = sizeof (ACPI_DEVICE_INFO);
373117521Snjl
374151937Sjkim    Info->Type  = Node->Type;
375151937Sjkim    Info->Name  = Node->Name.Integer;
376151937Sjkim    Info->Valid = 0;
377117521Snjl
378193267Sjkim    if (Node->Type == ACPI_TYPE_METHOD)
379193267Sjkim    {
380193267Sjkim        Info->ParamCount = Node->Object->Method.ParamCount;
381193267Sjkim    }
382193267Sjkim
38391116Smsmith    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
38491116Smsmith    if (ACPI_FAILURE (Status))
38591116Smsmith    {
386151937Sjkim        goto Cleanup;
38791116Smsmith    }
38867754Smsmith
389117521Snjl    /* If not a device, we are all done */
390117521Snjl
391151937Sjkim    if (Info->Type == ACPI_TYPE_DEVICE)
39267754Smsmith    {
393117521Snjl        /*
394117521Snjl         * Get extra info for ACPI Devices objects only:
395129684Snjl         * Run the Device _HID, _UID, _CID, _STA, _ADR and _SxD methods.
396123315Snjl         *
397117521Snjl         * Note: none of these methods are required, so they may or may
398151937Sjkim         * not be present for this device.  The Info->Valid bitfield is used
399117521Snjl         * to indicate which methods were found and ran successfully.
400117521Snjl         */
40167754Smsmith
402117521Snjl        /* Execute the Device._HID method */
40367754Smsmith
404151937Sjkim        Status = AcpiUtExecute_HID (Node, &Info->HardwareId);
405117521Snjl        if (ACPI_SUCCESS (Status))
406117521Snjl        {
407151937Sjkim            Info->Valid |= ACPI_VALID_HID;
408117521Snjl        }
40967754Smsmith
410117521Snjl        /* Execute the Device._UID method */
41167754Smsmith
412151937Sjkim        Status = AcpiUtExecute_UID (Node, &Info->UniqueId);
413117521Snjl        if (ACPI_SUCCESS (Status))
414117521Snjl        {
415151937Sjkim            Info->Valid |= ACPI_VALID_UID;
416117521Snjl        }
417117521Snjl
418117521Snjl        /* Execute the Device._CID method */
419117521Snjl
420117521Snjl        Status = AcpiUtExecute_CID (Node, &CidList);
421117521Snjl        if (ACPI_SUCCESS (Status))
422117521Snjl        {
423167802Sjkim            Size += CidList->Size;
424151937Sjkim            Info->Valid |= ACPI_VALID_CID;
425117521Snjl        }
426117521Snjl
427117521Snjl        /* Execute the Device._STA method */
428117521Snjl
429151937Sjkim        Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
430117521Snjl        if (ACPI_SUCCESS (Status))
431117521Snjl        {
432151937Sjkim            Info->Valid |= ACPI_VALID_STA;
433117521Snjl        }
434117521Snjl
435117521Snjl        /* Execute the Device._ADR method */
436117521Snjl
437123315Snjl        Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
438151937Sjkim                        &Info->Address);
439117521Snjl        if (ACPI_SUCCESS (Status))
440117521Snjl        {
441151937Sjkim            Info->Valid |= ACPI_VALID_ADR;
442117521Snjl        }
443117521Snjl
444126372Snjl        /* Execute the Device._SxD methods */
445126372Snjl
446151937Sjkim        Status = AcpiUtExecute_Sxds (Node, Info->HighestDstates);
447126372Snjl        if (ACPI_SUCCESS (Status))
448126372Snjl        {
449151937Sjkim            Info->Valid |= ACPI_VALID_SXDS;
450126372Snjl        }
45167754Smsmith    }
45267754Smsmith
453117521Snjl    /* Validate/Allocate/Clear caller buffer */
45467754Smsmith
455117521Snjl    Status = AcpiUtInitializeBuffer (Buffer, Size);
456117521Snjl    if (ACPI_FAILURE (Status))
45767754Smsmith    {
458117521Snjl        goto Cleanup;
45967754Smsmith    }
46067754Smsmith
461117521Snjl    /* Populate the return buffer */
462117521Snjl
463117521Snjl    ReturnInfo = Buffer->Pointer;
464151937Sjkim    ACPI_MEMCPY (ReturnInfo, Info, sizeof (ACPI_DEVICE_INFO));
465117521Snjl
466117521Snjl    if (CidList)
46767754Smsmith    {
468117521Snjl        ACPI_MEMCPY (&ReturnInfo->CompatibilityId, CidList, CidList->Size);
46967754Smsmith    }
47067754Smsmith
47167754Smsmith
472117521SnjlCleanup:
473167802Sjkim    ACPI_FREE (Info);
474117521Snjl    if (CidList)
47567754Smsmith    {
476167802Sjkim        ACPI_FREE (CidList);
47767754Smsmith    }
478117521Snjl    return (Status);
47967754Smsmith}
48067754Smsmith
481167802SjkimACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
482167802Sjkim
483193267Sjkim
484193267Sjkim/******************************************************************************
485193267Sjkim *
486193267Sjkim * FUNCTION:    AcpiInstallMethod
487193267Sjkim *
488193267Sjkim * PARAMETERS:  Buffer         - An ACPI table containing one control method
489193267Sjkim *
490193267Sjkim * RETURN:      Status
491193267Sjkim *
492193267Sjkim * DESCRIPTION: Install a control method into the namespace. If the method
493193267Sjkim *              name already exists in the namespace, it is overwritten. The
494193267Sjkim *              input buffer must contain a valid DSDT or SSDT containing a
495193267Sjkim *              single control method.
496193267Sjkim *
497193267Sjkim ******************************************************************************/
498193267Sjkim
499193267SjkimACPI_STATUS
500193267SjkimAcpiInstallMethod (
501193267Sjkim    UINT8                   *Buffer)
502193267Sjkim{
503193267Sjkim    ACPI_TABLE_HEADER       *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
504193267Sjkim    UINT8                   *AmlBuffer;
505193267Sjkim    UINT8                   *AmlStart;
506193267Sjkim    char                    *Path;
507193267Sjkim    ACPI_NAMESPACE_NODE     *Node;
508193267Sjkim    ACPI_OPERAND_OBJECT     *MethodObj;
509193267Sjkim    ACPI_PARSE_STATE        ParserState;
510193267Sjkim    UINT32                  AmlLength;
511193267Sjkim    UINT16                  Opcode;
512193267Sjkim    UINT8                   MethodFlags;
513193267Sjkim    ACPI_STATUS             Status;
514193267Sjkim
515193267Sjkim
516193267Sjkim    /* Parameter validation */
517193267Sjkim
518193267Sjkim    if (!Buffer)
519193267Sjkim    {
520193267Sjkim        return (AE_BAD_PARAMETER);
521193267Sjkim    }
522193267Sjkim
523193267Sjkim    /* Table must be a DSDT or SSDT */
524193267Sjkim
525193267Sjkim    if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
526193267Sjkim        !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
527193267Sjkim    {
528193267Sjkim        return (AE_BAD_HEADER);
529193267Sjkim    }
530193267Sjkim
531193267Sjkim    /* First AML opcode in the table must be a control method */
532193267Sjkim
533193267Sjkim    ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
534193267Sjkim    Opcode = AcpiPsPeekOpcode (&ParserState);
535193267Sjkim    if (Opcode != AML_METHOD_OP)
536193267Sjkim    {
537193267Sjkim        return (AE_BAD_PARAMETER);
538193267Sjkim    }
539193267Sjkim
540193267Sjkim    /* Extract method information from the raw AML */
541193267Sjkim
542193267Sjkim    ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
543193267Sjkim    ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
544193267Sjkim    Path = AcpiPsGetNextNamestring (&ParserState);
545193267Sjkim    MethodFlags = *ParserState.Aml++;
546193267Sjkim    AmlStart = ParserState.Aml;
547193267Sjkim    AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
548193267Sjkim
549193267Sjkim    /*
550193267Sjkim     * Allocate resources up-front. We don't want to have to delete a new
551193267Sjkim     * node from the namespace if we cannot allocate memory.
552193267Sjkim     */
553193267Sjkim    AmlBuffer = ACPI_ALLOCATE (AmlLength);
554193267Sjkim    if (!AmlBuffer)
555193267Sjkim    {
556193267Sjkim        return (AE_NO_MEMORY);
557193267Sjkim    }
558193267Sjkim
559193267Sjkim    MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
560193267Sjkim    if (!MethodObj)
561193267Sjkim    {
562193267Sjkim        ACPI_FREE (AmlBuffer);
563193267Sjkim        return (AE_NO_MEMORY);
564193267Sjkim    }
565193267Sjkim
566193267Sjkim    /* Lock namespace for AcpiNsLookup, we may be creating a new node */
567193267Sjkim
568193267Sjkim    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
569193267Sjkim    if (ACPI_FAILURE (Status))
570193267Sjkim    {
571193267Sjkim        goto ErrorExit;
572193267Sjkim    }
573193267Sjkim
574193267Sjkim    /* The lookup either returns an existing node or creates a new one */
575193267Sjkim
576193267Sjkim    Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
577193267Sjkim                ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
578193267Sjkim
579193267Sjkim    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
580193267Sjkim
581193267Sjkim    if (ACPI_FAILURE (Status)) /* NsLookup */
582193267Sjkim    {
583193267Sjkim        if (Status != AE_ALREADY_EXISTS)
584193267Sjkim        {
585193267Sjkim            goto ErrorExit;
586193267Sjkim        }
587193267Sjkim
588193267Sjkim        /* Node existed previously, make sure it is a method node */
589193267Sjkim
590193267Sjkim        if (Node->Type != ACPI_TYPE_METHOD)
591193267Sjkim        {
592193267Sjkim            Status = AE_TYPE;
593193267Sjkim            goto ErrorExit;
594193267Sjkim        }
595193267Sjkim    }
596193267Sjkim
597193267Sjkim    /* Copy the method AML to the local buffer */
598193267Sjkim
599193267Sjkim    ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength);
600193267Sjkim
601193267Sjkim    /* Initialize the method object with the new method's information */
602193267Sjkim
603193267Sjkim    MethodObj->Method.AmlStart = AmlBuffer;
604193267Sjkim    MethodObj->Method.AmlLength = AmlLength;
605193267Sjkim
606193267Sjkim    MethodObj->Method.ParamCount = (UINT8)
607193267Sjkim        (MethodFlags & AML_METHOD_ARG_COUNT);
608193267Sjkim
609193267Sjkim    MethodObj->Method.MethodFlags = (UINT8)
610193267Sjkim        (MethodFlags & ~AML_METHOD_ARG_COUNT);
611193267Sjkim
612193267Sjkim    if (MethodFlags & AML_METHOD_SERIALIZED)
613193267Sjkim    {
614193267Sjkim        MethodObj->Method.SyncLevel = (UINT8)
615193267Sjkim            ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
616193267Sjkim    }
617193267Sjkim
618193267Sjkim    /*
619193267Sjkim     * Now that it is complete, we can attach the new method object to
620193267Sjkim     * the method Node (detaches/deletes any existing object)
621193267Sjkim     */
622193267Sjkim    Status = AcpiNsAttachObject (Node, MethodObj,
623193267Sjkim                ACPI_TYPE_METHOD);
624193267Sjkim
625193267Sjkim    /*
626193267Sjkim     * Flag indicates AML buffer is dynamic, must be deleted later.
627193267Sjkim     * Must be set only after attach above.
628193267Sjkim     */
629193267Sjkim    Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
630193267Sjkim
631193267Sjkim    /* Remove local reference to the method object */
632193267Sjkim
633193267Sjkim    AcpiUtRemoveReference (MethodObj);
634193267Sjkim    return (Status);
635193267Sjkim
636193267Sjkim
637193267SjkimErrorExit:
638193267Sjkim
639193267Sjkim    ACPI_FREE (AmlBuffer);
640193267Sjkim    ACPI_FREE (MethodObj);
641193267Sjkim    return (Status);
642193267Sjkim}
643193267Sjkim
644193267SjkimACPI_EXPORT_SYMBOL (AcpiInstallMethod)
645