nsxfname.c revision 126372
1254721Semaste/******************************************************************************
2254721Semaste *
3254721Semaste * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4254721Semaste *                         ACPI Namespace oriented interfaces
5254721Semaste *              $Revision: 100 $
6254721Semaste *
7254721Semaste *****************************************************************************/
8254721Semaste
9254721Semaste/******************************************************************************
10254721Semaste *
11254721Semaste * 1. Copyright Notice
12254721Semaste *
13254721Semaste * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14254721Semaste * All rights reserved.
15254721Semaste *
16254721Semaste * 2. License
17254721Semaste *
18254721Semaste * 2.1. This is your license from Intel Corp. under its intellectual property
19254721Semaste * rights.  You may have additional license terms from the party that provided
20254721Semaste * you this software, covering your right to use that party's intellectual
21254721Semaste * property rights.
22254721Semaste *
23254721Semaste * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24254721Semaste * copy of the source code appearing in this file ("Covered Code") an
25254721Semaste * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26254721Semaste * base code distributed originally by Intel ("Original Intel Code") to copy,
27254721Semaste * make derivatives, distribute, use and display any portion of the Covered
28254721Semaste * Code in any form, with the right to sublicense such rights; and
29254721Semaste *
30254721Semaste * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31254721Semaste * license (with the right to sublicense), under only those claims of Intel
32254721Semaste * patents that are infringed by the Original Intel Code, to make, use, sell,
33254721Semaste * offer to sell, and import the Covered Code and derivative works thereof
34254721Semaste * solely to the minimum extent necessary to exercise the above copyright
35254721Semaste * license, and in no event shall the patent license extend to any additions
36254721Semaste * to or modifications of the Original Intel Code.  No other license or right
37254721Semaste * is granted directly or by implication, estoppel or otherwise;
38254721Semaste *
39254721Semaste * The above copyright and patent license is granted only if the following
40254721Semaste * conditions are met:
41254721Semaste *
42254721Semaste * 3. Conditions
43254721Semaste *
44254721Semaste * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45254721Semaste * Redistribution of source code of any substantial portion of the Covered
46254721Semaste * Code or modification with rights to further distribute source must include
47254721Semaste * the above Copyright Notice, the above License, this list of Conditions,
48254721Semaste * and the following Disclaimer and Export Compliance provision.  In addition,
49254721Semaste * Licensee must cause all Covered Code to which Licensee contributes to
50254721Semaste * contain a file documenting the changes Licensee made to create that Covered
51254721Semaste * Code and the date of any change.  Licensee must include in that file the
52254721Semaste * documentation of any changes made by any predecessor Licensee.  Licensee
53254721Semaste * must include a prominent statement that the modification is derived,
54254721Semaste * directly or indirectly, from Original Intel Code.
55254721Semaste *
56254721Semaste * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57254721Semaste * Redistribution of source code of any substantial portion of the Covered
58254721Semaste * Code or modification without rights to further distribute source must
59254721Semaste * include the following Disclaimer and Export Compliance provision in the
60254721Semaste * documentation and/or other materials provided with distribution.  In
61254721Semaste * addition, Licensee may not authorize further sublicense of source of any
62254721Semaste * portion of the Covered Code, and must include terms to the effect that the
63254721Semaste * license from Licensee to its licensee is limited to the intellectual
64254721Semaste * property embodied in the software Licensee provides to its licensee, and
65254721Semaste * not to intellectual property embodied in modifications its licensee may
66254721Semaste * make.
67254721Semaste *
68254721Semaste * 3.3. Redistribution of Executable. Redistribution in executable form of any
69254721Semaste * substantial portion of the Covered Code or modification must reproduce the
70254721Semaste * above Copyright Notice, and the following Disclaimer and Export Compliance
71254721Semaste * provision in the documentation and/or other materials provided with the
72254721Semaste * distribution.
73254721Semaste *
74254721Semaste * 3.4. Intel retains all right, title, and interest in and to the Original
75254721Semaste * Intel Code.
76254721Semaste *
77254721Semaste * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78254721Semaste * Intel shall be used in advertising or otherwise to promote the sale, use or
79254721Semaste * other dealings in products derived from or relating to the Covered Code
80254721Semaste * without prior written authorization from Intel.
81254721Semaste *
82254721Semaste * 4. Disclaimer and Export Compliance
83254721Semaste *
84254721Semaste * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85254721Semaste * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86254721Semaste * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87254721Semaste * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88254721Semaste * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90254721Semaste * PARTICULAR PURPOSE.
91254721Semaste *
92254721Semaste * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93254721Semaste * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94254721Semaste * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95254721Semaste * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96254721Semaste * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97254721Semaste * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98254721Semaste * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99254721Semaste * LIMITED REMEDY.
100254721Semaste *
101254721Semaste * 4.3. Licensee shall not export, either directly or indirectly, any of this
102254721Semaste * software or system incorporating such software without first obtaining any
103254721Semaste * required license or other approval from the U. S. Department of Commerce or
104254721Semaste * any other agency or department of the United States Government.  In the
105254721Semaste * event Licensee exports any such software from the United States or
106254721Semaste * re-exports any such software from a foreign destination, Licensee shall
107254721Semaste * ensure that the distribution and export/re-export of the software is in
108254721Semaste * compliance with all laws, regulations, orders, or other restrictions of the
109254721Semaste * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110254721Semaste * any of its subsidiaries will export/re-export any technical data, process,
111254721Semaste * software, or service, directly or indirectly, to any country for which the
112254721Semaste * United States government or any agency thereof requires an export license,
113254721Semaste * other governmental approval, or letter of assurance, without first obtaining
114254721Semaste * such license, approval or letter.
115254721Semaste *
116254721Semaste *****************************************************************************/
117254721Semaste
118254721Semaste#define __NSXFNAME_C__
119254721Semaste
120254721Semaste#include "acpi.h"
121254721Semaste#include "acnamesp.h"
122254721Semaste
123254721Semaste
124254721Semaste#define _COMPONENT          ACPI_NAMESPACE
125254721Semaste        ACPI_MODULE_NAME    ("nsxfname")
126254721Semaste
127254721Semaste
128254721Semaste/******************************************************************************
129254721Semaste *
130254721Semaste * FUNCTION:    AcpiGetHandle
131254721Semaste *
132254721Semaste * PARAMETERS:  Parent          - Object to search under (search scope).
133254721Semaste *              PathName        - Pointer to an asciiz string containing the
134254721Semaste *                                  name
135254721Semaste *              RetHandle       - Where the return handle is placed
136254721Semaste *
137254721Semaste * RETURN:      Status
138254721Semaste *
139254721Semaste * DESCRIPTION: This routine will search for a caller specified name in the
140254721Semaste *              name space.  The caller can restrict the search region by
141254721Semaste *              specifying a non NULL parent.  The parent value is itself a
142254721Semaste *              namespace handle.
143254721Semaste *
144254721Semaste ******************************************************************************/
145254721Semaste
146254721SemasteACPI_STATUS
147254721SemasteAcpiGetHandle (
148254721Semaste    ACPI_HANDLE             Parent,
149254721Semaste    ACPI_STRING             Pathname,
150254721Semaste    ACPI_HANDLE             *RetHandle)
151254721Semaste{
152254721Semaste    ACPI_STATUS             Status;
153254721Semaste    ACPI_NAMESPACE_NODE     *Node = NULL;
154254721Semaste    ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
155254721Semaste
156254721Semaste
157254721Semaste    ACPI_FUNCTION_ENTRY ();
158254721Semaste
159254721Semaste
160254721Semaste    /* Parameter Validation */
161254721Semaste
162254721Semaste    if (!RetHandle || !Pathname)
163254721Semaste    {
164254721Semaste        return (AE_BAD_PARAMETER);
165254721Semaste    }
166254721Semaste
167254721Semaste    /* Convert a parent handle to a prefix node */
168254721Semaste
169254721Semaste    if (Parent)
170254721Semaste    {
171254721Semaste        Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
172254721Semaste        if (ACPI_FAILURE (Status))
173254721Semaste        {
174254721Semaste            return (Status);
175254721Semaste        }
176254721Semaste
177254721Semaste        PrefixNode = AcpiNsMapHandleToNode (Parent);
178254721Semaste        if (!PrefixNode)
179254721Semaste        {
180254721Semaste            (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
181254721Semaste            return (AE_BAD_PARAMETER);
182254721Semaste        }
183254721Semaste
184254721Semaste        Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
185254721Semaste        if (ACPI_FAILURE (Status))
186254721Semaste        {
187254721Semaste            return (Status);
188254721Semaste        }
189254721Semaste    }
190254721Semaste
191254721Semaste    /* Special case for root, since we can't search for it */
192254721Semaste
193254721Semaste    if (ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH) == 0)
194254721Semaste    {
195254721Semaste        *RetHandle = AcpiNsConvertEntryToHandle (AcpiGbl_RootNode);
196254721Semaste        return (AE_OK);
197254721Semaste    }
198254721Semaste
199254721Semaste    /*
200254721Semaste     *  Find the Node and convert to a handle
201254721Semaste     */
202254721Semaste    Status = AcpiNsGetNodeByPath (Pathname, PrefixNode, ACPI_NS_NO_UPSEARCH,
203254721Semaste                    &Node);
204254721Semaste
205254721Semaste    *RetHandle = NULL;
206254721Semaste    if (ACPI_SUCCESS (Status))
207254721Semaste    {
208254721Semaste        *RetHandle = AcpiNsConvertEntryToHandle (Node);
209254721Semaste    }
210254721Semaste
211254721Semaste    return (Status);
212254721Semaste}
213254721Semaste
214254721Semaste
215254721Semaste/******************************************************************************
216254721Semaste *
217254721Semaste * FUNCTION:    AcpiGetName
218254721Semaste *
219254721Semaste * PARAMETERS:  Handle          - Handle to be converted to a pathname
220254721Semaste *              NameType        - Full pathname or single segment
221254721Semaste *              Buffer          - Buffer for returned path
222254721Semaste *
223254721Semaste * RETURN:      Pointer to a string containing the fully qualified Name.
224254721Semaste *
225254721Semaste * DESCRIPTION: This routine returns the fully qualified name associated with
226254721Semaste *              the Handle parameter.  This and the AcpiPathnameToHandle are
227254721Semaste *              complementary functions.
228254721Semaste *
229254721Semaste ******************************************************************************/
230254721Semaste
231254721SemasteACPI_STATUS
232254721SemasteAcpiGetName (
233254721Semaste    ACPI_HANDLE             Handle,
234254721Semaste    UINT32                  NameType,
235254721Semaste    ACPI_BUFFER             *Buffer)
236254721Semaste{
237254721Semaste    ACPI_STATUS             Status;
238254721Semaste    ACPI_NAMESPACE_NODE     *Node;
239254721Semaste
240254721Semaste
241254721Semaste    /* Parameter validation */
242254721Semaste
243254721Semaste    if (NameType > ACPI_NAME_TYPE_MAX)
244254721Semaste    {
245254721Semaste        return (AE_BAD_PARAMETER);
246254721Semaste    }
247254721Semaste
248254721Semaste    Status = AcpiUtValidateBuffer (Buffer);
249254721Semaste    if (ACPI_FAILURE (Status))
250254721Semaste    {
251254721Semaste        return (Status);
252254721Semaste    }
253254721Semaste
254254721Semaste    if (NameType == ACPI_FULL_PATHNAME)
255254721Semaste    {
256254721Semaste        /* Get the full pathname (From the namespace root) */
257254721Semaste
258254721Semaste        Status = AcpiNsHandleToPathname (Handle, Buffer);
259254721Semaste        return (Status);
260254721Semaste    }
261254721Semaste
262254721Semaste    /*
263254721Semaste     * Wants the single segment ACPI name.
264254721Semaste     * Validate handle and convert to a namespace Node
265254721Semaste     */
266254721Semaste    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
267254721Semaste    if (ACPI_FAILURE (Status))
268254721Semaste    {
269254721Semaste        return (Status);
270254721Semaste    }
271254721Semaste
272254721Semaste    Node = AcpiNsMapHandleToNode (Handle);
273254721Semaste    if (!Node)
274254721Semaste    {
275254721Semaste        Status = AE_BAD_PARAMETER;
276254721Semaste        goto UnlockAndExit;
277254721Semaste    }
278254721Semaste
279254721Semaste    /* Validate/Allocate/Clear caller buffer */
280254721Semaste
281254721Semaste    Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
282254721Semaste    if (ACPI_FAILURE (Status))
283254721Semaste    {
284254721Semaste        goto UnlockAndExit;
285254721Semaste    }
286254721Semaste
287254721Semaste    /* Just copy the ACPI name from the Node and zero terminate it */
288254721Semaste
289254721Semaste    ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
290254721Semaste                ACPI_NAME_SIZE);
291254721Semaste    ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
292254721Semaste    Status = AE_OK;
293254721Semaste
294254721Semaste
295254721SemasteUnlockAndExit:
296254721Semaste
297254721Semaste    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
298254721Semaste    return (Status);
299254721Semaste}
300254721Semaste
301254721Semaste
302254721Semaste/******************************************************************************
303254721Semaste *
304254721Semaste * FUNCTION:    AcpiGetObjectInfo
305254721Semaste *
306254721Semaste * PARAMETERS:  Handle          - Object Handle
307254721Semaste *              Info            - Where the info is returned
308254721Semaste *
309254721Semaste * RETURN:      Status
310254721Semaste *
311254721Semaste * DESCRIPTION: Returns information about an object as gleaned from the
312254721Semaste *              namespace node and possibly by running several standard
313254721Semaste *              control methods (Such as in the case of a device.)
314254721Semaste *
315254721Semaste ******************************************************************************/
316254721Semaste
317254721SemasteACPI_STATUS
318254721SemasteAcpiGetObjectInfo (
319254721Semaste    ACPI_HANDLE             Handle,
320254721Semaste    ACPI_BUFFER             *Buffer)
321254721Semaste{
322254721Semaste    ACPI_STATUS             Status;
323254721Semaste    ACPI_NAMESPACE_NODE     *Node;
324254721Semaste    ACPI_DEVICE_INFO        Info;
325254721Semaste    ACPI_DEVICE_INFO        *ReturnInfo;
326254721Semaste    ACPI_COMPATIBLE_ID_LIST *CidList = NULL;
327254721Semaste    ACPI_SIZE               Size;
328254721Semaste
329254721Semaste
330254721Semaste    /* Parameter validation */
331254721Semaste
332254721Semaste    if (!Handle || !Buffer)
333254721Semaste    {
334254721Semaste        return (AE_BAD_PARAMETER);
335254721Semaste    }
336254721Semaste
337254721Semaste    Status = AcpiUtValidateBuffer (Buffer);
338254721Semaste    if (ACPI_FAILURE (Status))
339254721Semaste    {
340254721Semaste        return (Status);
341254721Semaste    }
342254721Semaste
343254721Semaste    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
344254721Semaste    if (ACPI_FAILURE (Status))
345254721Semaste    {
346254721Semaste        return (Status);
347254721Semaste    }
348254721Semaste
349254721Semaste    Node = AcpiNsMapHandleToNode (Handle);
350254721Semaste    if (!Node)
351254721Semaste    {
352254721Semaste        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
353254721Semaste        return (AE_BAD_PARAMETER);
354254721Semaste    }
355254721Semaste
356254721Semaste    /* Init return structure */
357254721Semaste
358254721Semaste    Size = sizeof (ACPI_DEVICE_INFO);
359254721Semaste    ACPI_MEMSET (&Info, 0, Size);
360254721Semaste
361254721Semaste    Info.Type  = Node->Type;
362254721Semaste    Info.Name  = Node->Name.Integer;
363254721Semaste    Info.Valid = 0;
364254721Semaste
365254721Semaste    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
366254721Semaste    if (ACPI_FAILURE (Status))
367254721Semaste    {
368254721Semaste        return (Status);
369254721Semaste    }
370254721Semaste
371254721Semaste    /* If not a device, we are all done */
372254721Semaste
373254721Semaste    if (Info.Type == ACPI_TYPE_DEVICE)
374254721Semaste    {
375254721Semaste        /*
376254721Semaste         * Get extra info for ACPI Devices objects only:
377254721Semaste         * Run the Device _HID, _UID, _CID, _STA, and _ADR methods.
378254721Semaste         *
379254721Semaste         * Note: none of these methods are required, so they may or may
380254721Semaste         * not be present for this device.  The Info.Valid bitfield is used
381254721Semaste         * to indicate which methods were found and ran successfully.
382254721Semaste         */
383254721Semaste
384254721Semaste        /* Execute the Device._HID method */
385254721Semaste
386254721Semaste        Status = AcpiUtExecute_HID (Node, &Info.HardwareId);
387254721Semaste        if (ACPI_SUCCESS (Status))
388254721Semaste        {
389254721Semaste            Info.Valid |= ACPI_VALID_HID;
390254721Semaste        }
391254721Semaste
392254721Semaste        /* Execute the Device._UID method */
393254721Semaste
394254721Semaste        Status = AcpiUtExecute_UID (Node, &Info.UniqueId);
395254721Semaste        if (ACPI_SUCCESS (Status))
396254721Semaste        {
397254721Semaste            Info.Valid |= ACPI_VALID_UID;
398254721Semaste        }
399254721Semaste
400254721Semaste        /* Execute the Device._CID method */
401254721Semaste
402254721Semaste        Status = AcpiUtExecute_CID (Node, &CidList);
403254721Semaste        if (ACPI_SUCCESS (Status))
404254721Semaste        {
405254721Semaste            Size += ((ACPI_SIZE) CidList->Count - 1) *
406254721Semaste                                 sizeof (ACPI_COMPATIBLE_ID);
407254721Semaste            Info.Valid |= ACPI_VALID_CID;
408254721Semaste        }
409254721Semaste
410254721Semaste        /* Execute the Device._STA method */
411254721Semaste
412254721Semaste        Status = AcpiUtExecute_STA (Node, &Info.CurrentStatus);
413254721Semaste        if (ACPI_SUCCESS (Status))
414254721Semaste        {
415254721Semaste            Info.Valid |= ACPI_VALID_STA;
416254721Semaste        }
417254721Semaste
418254721Semaste        /* Execute the Device._ADR method */
419254721Semaste
420254721Semaste        Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
421254721Semaste                        &Info.Address);
422254721Semaste        if (ACPI_SUCCESS (Status))
423254721Semaste        {
424254721Semaste            Info.Valid |= ACPI_VALID_ADR;
425254721Semaste        }
426254721Semaste
427254721Semaste        /* Execute the Device._SxD methods */
428254721Semaste
429254721Semaste        Status = AcpiUtExecute_Sxds (Node, Info.HighestDstates);
430254721Semaste        if (ACPI_SUCCESS (Status))
431254721Semaste        {
432254721Semaste            Info.Valid |= ACPI_VALID_STA;
433254721Semaste        }
434254721Semaste
435254721Semaste        Status = AE_OK;
436254721Semaste    }
437254721Semaste
438254721Semaste    /* Validate/Allocate/Clear caller buffer */
439254721Semaste
440254721Semaste    Status = AcpiUtInitializeBuffer (Buffer, Size);
441254721Semaste    if (ACPI_FAILURE (Status))
442254721Semaste    {
443254721Semaste        goto Cleanup;
444254721Semaste    }
445254721Semaste
446254721Semaste    /* Populate the return buffer */
447254721Semaste
448254721Semaste    ReturnInfo = Buffer->Pointer;
449254721Semaste    ACPI_MEMCPY (ReturnInfo, &Info, sizeof (ACPI_DEVICE_INFO));
450254721Semaste
451254721Semaste    if (CidList)
452254721Semaste    {
453254721Semaste        ACPI_MEMCPY (&ReturnInfo->CompatibilityId, CidList, CidList->Size);
454254721Semaste    }
455254721Semaste
456254721Semaste
457254721SemasteCleanup:
458254721Semaste    if (CidList)
459254721Semaste    {
460254721Semaste        ACPI_MEM_FREE (CidList);
461254721Semaste    }
462254721Semaste    return (Status);
463254721Semaste}
464254721Semaste
465254721Semaste