nsxfname.c revision 129684
1169689Skan/******************************************************************************
2169689Skan *
3169689Skan * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4169689Skan *                         ACPI Namespace oriented interfaces
5169689Skan *              $Revision: 101 $
6169689Skan *
7169689Skan *****************************************************************************/
8169689Skan
9169689Skan/******************************************************************************
10169689Skan *
11169689Skan * 1. Copyright Notice
12169689Skan *
13169689Skan * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14169689Skan * All rights reserved.
15169689Skan *
16169689Skan * 2. License
17169689Skan *
18169689Skan * 2.1. This is your license from Intel Corp. under its intellectual property
19169689Skan * rights.  You may have additional license terms from the party that provided
20169689Skan * you this software, covering your right to use that party's intellectual
21169689Skan * property rights.
22169689Skan *
23169689Skan * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24169689Skan * copy of the source code appearing in this file ("Covered Code") an
25169689Skan * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26169689Skan * base code distributed originally by Intel ("Original Intel Code") to copy,
27169689Skan * make derivatives, distribute, use and display any portion of the Covered
28169689Skan * Code in any form, with the right to sublicense such rights; and
29169689Skan *
30169689Skan * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31169689Skan * license (with the right to sublicense), under only those claims of Intel
32169689Skan * patents that are infringed by the Original Intel Code, to make, use, sell,
33169689Skan * offer to sell, and import the Covered Code and derivative works thereof
34169689Skan * solely to the minimum extent necessary to exercise the above copyright
35169689Skan * license, and in no event shall the patent license extend to any additions
36169689Skan * to or modifications of the Original Intel Code.  No other license or right
37169689Skan * is granted directly or by implication, estoppel or otherwise;
38169689Skan *
39169689Skan * The above copyright and patent license is granted only if the following
40169689Skan * conditions are met:
41169689Skan *
42169689Skan * 3. Conditions
43169689Skan *
44169689Skan * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45169689Skan * Redistribution of source code of any substantial portion of the Covered
46169689Skan * Code or modification with rights to further distribute source must include
47169689Skan * the above Copyright Notice, the above License, this list of Conditions,
48169689Skan * and the following Disclaimer and Export Compliance provision.  In addition,
49169689Skan * Licensee must cause all Covered Code to which Licensee contributes to
50169689Skan * contain a file documenting the changes Licensee made to create that Covered
51169689Skan * Code and the date of any change.  Licensee must include in that file the
52169689Skan * documentation of any changes made by any predecessor Licensee.  Licensee
53169689Skan * must include a prominent statement that the modification is derived,
54169689Skan * directly or indirectly, from Original Intel Code.
55169689Skan *
56169689Skan * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57169689Skan * Redistribution of source code of any substantial portion of the Covered
58169689Skan * Code or modification without rights to further distribute source must
59169689Skan * include the following Disclaimer and Export Compliance provision in the
60169689Skan * documentation and/or other materials provided with distribution.  In
61169689Skan * addition, Licensee may not authorize further sublicense of source of any
62169689Skan * portion of the Covered Code, and must include terms to the effect that the
63169689Skan * license from Licensee to its licensee is limited to the intellectual
64169689Skan * property embodied in the software Licensee provides to its licensee, and
65169689Skan * not to intellectual property embodied in modifications its licensee may
66169689Skan * make.
67169689Skan *
68169689Skan * 3.3. Redistribution of Executable. Redistribution in executable form of any
69169689Skan * substantial portion of the Covered Code or modification must reproduce the
70169689Skan * above Copyright Notice, and the following Disclaimer and Export Compliance
71169689Skan * provision in the documentation and/or other materials provided with the
72169689Skan * distribution.
73169689Skan *
74169689Skan * 3.4. Intel retains all right, title, and interest in and to the Original
75169689Skan * Intel Code.
76169689Skan *
77169689Skan * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78169689Skan * Intel shall be used in advertising or otherwise to promote the sale, use or
79169689Skan * other dealings in products derived from or relating to the Covered Code
80169689Skan * without prior written authorization from Intel.
81169689Skan *
82169689Skan * 4. Disclaimer and Export Compliance
83169689Skan *
84169689Skan * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85169689Skan * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86169689Skan * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87169689Skan * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88169689Skan * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89169689Skan * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90169689Skan * PARTICULAR PURPOSE.
91169689Skan *
92169689Skan * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93169689Skan * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94169689Skan * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95169689Skan * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96169689Skan * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97169689Skan * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98169689Skan * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99169689Skan * LIMITED REMEDY.
100169689Skan *
101169689Skan * 4.3. Licensee shall not export, either directly or indirectly, any of this
102169689Skan * software or system incorporating such software without first obtaining any
103169689Skan * required license or other approval from the U. S. Department of Commerce or
104169689Skan * any other agency or department of the United States Government.  In the
105169689Skan * event Licensee exports any such software from the United States or
106169689Skan * re-exports any such software from a foreign destination, Licensee shall
107169689Skan * ensure that the distribution and export/re-export of the software is in
108169689Skan * compliance with all laws, regulations, orders, or other restrictions of the
109169689Skan * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110169689Skan * any of its subsidiaries will export/re-export any technical data, process,
111169689Skan * software, or service, directly or indirectly, to any country for which the
112169689Skan * United States government or any agency thereof requires an export license,
113169689Skan * other governmental approval, or letter of assurance, without first obtaining
114169689Skan * such license, approval or letter.
115169689Skan *
116169689Skan *****************************************************************************/
117169689Skan
118169689Skan#define __NSXFNAME_C__
119169689Skan
120169689Skan#include "acpi.h"
121169689Skan#include "acnamesp.h"
122169689Skan
123169689Skan
124169689Skan#define _COMPONENT          ACPI_NAMESPACE
125169689Skan        ACPI_MODULE_NAME    ("nsxfname")
126169689Skan
127169689Skan
128169689Skan/******************************************************************************
129169689Skan *
130169689Skan * FUNCTION:    AcpiGetHandle
131169689Skan *
132169689Skan * PARAMETERS:  Parent          - Object to search under (search scope).
133169689Skan *              PathName        - Pointer to an asciiz string containing the
134169689Skan *                                  name
135169689Skan *              RetHandle       - Where the return handle is placed
136169689Skan *
137169689Skan * RETURN:      Status
138169689Skan *
139169689Skan * DESCRIPTION: This routine will search for a caller specified name in the
140169689Skan *              name space.  The caller can restrict the search region by
141169689Skan *              specifying a non NULL parent.  The parent value is itself a
142169689Skan *              namespace handle.
143169689Skan *
144169689Skan ******************************************************************************/
145169689Skan
146169689SkanACPI_STATUS
147169689SkanAcpiGetHandle (
148169689Skan    ACPI_HANDLE             Parent,
149169689Skan    ACPI_STRING             Pathname,
150169689Skan    ACPI_HANDLE             *RetHandle)
151169689Skan{
152169689Skan    ACPI_STATUS             Status;
153169689Skan    ACPI_NAMESPACE_NODE     *Node = NULL;
154169689Skan    ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
155169689Skan
156169689Skan
157169689Skan    ACPI_FUNCTION_ENTRY ();
158169689Skan
159169689Skan
160169689Skan    /* Parameter Validation */
161169689Skan
162169689Skan    if (!RetHandle || !Pathname)
163169689Skan    {
164169689Skan        return (AE_BAD_PARAMETER);
165169689Skan    }
166169689Skan
167169689Skan    /* Convert a parent handle to a prefix node */
168169689Skan
169169689Skan    if (Parent)
170169689Skan    {
171169689Skan        Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
172169689Skan        if (ACPI_FAILURE (Status))
173169689Skan        {
174169689Skan            return (Status);
175169689Skan        }
176169689Skan
177169689Skan        PrefixNode = AcpiNsMapHandleToNode (Parent);
178169689Skan        if (!PrefixNode)
179169689Skan        {
180169689Skan            (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
181169689Skan            return (AE_BAD_PARAMETER);
182169689Skan        }
183169689Skan
184169689Skan        Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
185169689Skan        if (ACPI_FAILURE (Status))
186169689Skan        {
187169689Skan            return (Status);
188169689Skan        }
189169689Skan    }
190169689Skan
191260918Spfg    /* Special case for root, since we can't search for it */
192260918Spfg
193260918Spfg    if (ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH) == 0)
194260918Spfg    {
195169689Skan        *RetHandle = AcpiNsConvertEntryToHandle (AcpiGbl_RootNode);
196169689Skan        return (AE_OK);
197169689Skan    }
198169689Skan
199169689Skan    /*
200169689Skan     *  Find the Node and convert to a handle
201169689Skan     */
202169689Skan    Status = AcpiNsGetNodeByPath (Pathname, PrefixNode, ACPI_NS_NO_UPSEARCH,
203261188Spfg                    &Node);
204261188Spfg
205261188Spfg    *RetHandle = NULL;
206261188Spfg    if (ACPI_SUCCESS (Status))
207261188Spfg    {
208261188Spfg        *RetHandle = AcpiNsConvertEntryToHandle (Node);
209261188Spfg    }
210261188Spfg
211261188Spfg    return (Status);
212261188Spfg}
213261188Spfg
214261188Spfg
215261188Spfg/******************************************************************************
216261188Spfg *
217169689Skan * FUNCTION:    AcpiGetName
218169689Skan *
219169689Skan * PARAMETERS:  Handle          - Handle to be converted to a pathname
220169689Skan *              NameType        - Full pathname or single segment
221169689Skan *              Buffer          - Buffer for returned path
222169689Skan *
223169689Skan * RETURN:      Pointer to a string containing the fully qualified Name.
224169689Skan *
225169689Skan * DESCRIPTION: This routine returns the fully qualified name associated with
226169689Skan *              the Handle parameter.  This and the AcpiPathnameToHandle are
227169689Skan *              complementary functions.
228169689Skan *
229169689Skan ******************************************************************************/
230169689Skan
231169689SkanACPI_STATUS
232169689SkanAcpiGetName (
233169689Skan    ACPI_HANDLE             Handle,
234169689Skan    UINT32                  NameType,
235169689Skan    ACPI_BUFFER             *Buffer)
236169689Skan{
237169689Skan    ACPI_STATUS             Status;
238169689Skan    ACPI_NAMESPACE_NODE     *Node;
239169689Skan
240169689Skan
241260918Spfg    /* Parameter validation */
242260918Spfg
243260918Spfg    if (NameType > ACPI_NAME_TYPE_MAX)
244260918Spfg    {
245260918Spfg        return (AE_BAD_PARAMETER);
246260918Spfg    }
247169689Skan
248169689Skan    Status = AcpiUtValidateBuffer (Buffer);
249169689Skan    if (ACPI_FAILURE (Status))
250169689Skan    {
251169689Skan        return (Status);
252169689Skan    }
253169689Skan
254169689Skan    if (NameType == ACPI_FULL_PATHNAME)
255169689Skan    {
256169689Skan        /* Get the full pathname (From the namespace root) */
257169689Skan
258169689Skan        Status = AcpiNsHandleToPathname (Handle, Buffer);
259169689Skan        return (Status);
260169689Skan    }
261169689Skan
262169689Skan    /*
263169689Skan     * Wants the single segment ACPI name.
264169689Skan     * Validate handle and convert to a namespace Node
265169689Skan     */
266169689Skan    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
267261188Spfg    if (ACPI_FAILURE (Status))
268261188Spfg    {
269261188Spfg        return (Status);
270261188Spfg    }
271261188Spfg
272169689Skan    Node = AcpiNsMapHandleToNode (Handle);
273169689Skan    if (!Node)
274169689Skan    {
275169689Skan        Status = AE_BAD_PARAMETER;
276261188Spfg        goto UnlockAndExit;
277261188Spfg    }
278261188Spfg
279261188Spfg    /* Validate/Allocate/Clear caller buffer */
280169689Skan
281169689Skan    Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
282169689Skan    if (ACPI_FAILURE (Status))
283169689Skan    {
284169689Skan        goto UnlockAndExit;
285169689Skan    }
286169689Skan
287169689Skan    /* Just copy the ACPI name from the Node and zero terminate it */
288169689Skan
289169689Skan    ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
290169689Skan                ACPI_NAME_SIZE);
291169689Skan    ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
292169689Skan    Status = AE_OK;
293169689Skan
294169689Skan
295169689SkanUnlockAndExit:
296169689Skan
297169689Skan    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
298169689Skan    return (Status);
299169689Skan}
300169689Skan
301169689Skan
302169689Skan/******************************************************************************
303260918Spfg *
304169689Skan * FUNCTION:    AcpiGetObjectInfo
305260918Spfg *
306260918Spfg * PARAMETERS:  Handle          - Object Handle
307260918Spfg *              Info            - Where the info is returned
308169689Skan *
309169689Skan * RETURN:      Status
310169689Skan *
311169689Skan * DESCRIPTION: Returns information about an object as gleaned from the
312169689Skan *              namespace node and possibly by running several standard
313169689Skan *              control methods (Such as in the case of a device.)
314169689Skan *
315169689Skan ******************************************************************************/
316260918Spfg
317169689SkanACPI_STATUS
318260918SpfgAcpiGetObjectInfo (
319260918Spfg    ACPI_HANDLE             Handle,
320260918Spfg    ACPI_BUFFER             *Buffer)
321169689Skan{
322169689Skan    ACPI_STATUS             Status;
323169689Skan    ACPI_NAMESPACE_NODE     *Node;
324169689Skan    ACPI_DEVICE_INFO        Info;
325169689Skan    ACPI_DEVICE_INFO        *ReturnInfo;
326169689Skan    ACPI_COMPATIBLE_ID_LIST *CidList = NULL;
327169689Skan    ACPI_SIZE               Size;
328169689Skan
329260918Spfg
330169689Skan    /* Parameter validation */
331260918Spfg
332260918Spfg    if (!Handle || !Buffer)
333260918Spfg    {
334169689Skan        return (AE_BAD_PARAMETER);
335169689Skan    }
336169689Skan
337169689Skan    Status = AcpiUtValidateBuffer (Buffer);
338169689Skan    if (ACPI_FAILURE (Status))
339169689Skan    {
340169689Skan        return (Status);
341169689Skan    }
342169689Skan
343169689Skan    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
344169689Skan    if (ACPI_FAILURE (Status))
345169689Skan    {
346169689Skan        return (Status);
347169689Skan    }
348169689Skan
349169689Skan    Node = AcpiNsMapHandleToNode (Handle);
350169689Skan    if (!Node)
351169689Skan    {
352169689Skan        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
353169689Skan        return (AE_BAD_PARAMETER);
354169689Skan    }
355169689Skan
356169689Skan    /* Init return structure */
357169689Skan
358169689Skan    Size = sizeof (ACPI_DEVICE_INFO);
359169689Skan    ACPI_MEMSET (&Info, 0, Size);
360169689Skan
361169689Skan    Info.Type  = Node->Type;
362169689Skan    Info.Name  = Node->Name.Integer;
363169689Skan    Info.Valid = 0;
364169689Skan
365169689Skan    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
366169689Skan    if (ACPI_FAILURE (Status))
367169689Skan    {
368169689Skan        return (Status);
369169689Skan    }
370169689Skan
371169689Skan    /* If not a device, we are all done */
372169689Skan
373169689Skan    if (Info.Type == ACPI_TYPE_DEVICE)
374169689Skan    {
375169689Skan        /*
376169689Skan         * Get extra info for ACPI Devices objects only:
377169689Skan         * Run the Device _HID, _UID, _CID, _STA, _ADR and _SxD methods.
378169689Skan         *
379169689Skan         * Note: none of these methods are required, so they may or may
380169689Skan         * not be present for this device.  The Info.Valid bitfield is used
381169689Skan         * to indicate which methods were found and ran successfully.
382169689Skan         */
383169689Skan
384169689Skan        /* Execute the Device._HID method */
385169689Skan
386169689Skan        Status = AcpiUtExecute_HID (Node, &Info.HardwareId);
387169689Skan        if (ACPI_SUCCESS (Status))
388169689Skan        {
389169689Skan            Info.Valid |= ACPI_VALID_HID;
390169689Skan        }
391169689Skan
392169689Skan        /* Execute the Device._UID method */
393169689Skan
394169689Skan        Status = AcpiUtExecute_UID (Node, &Info.UniqueId);
395169689Skan        if (ACPI_SUCCESS (Status))
396169689Skan        {
397169689Skan            Info.Valid |= ACPI_VALID_UID;
398169689Skan        }
399169689Skan
400169689Skan        /* Execute the Device._CID method */
401169689Skan
402169689Skan        Status = AcpiUtExecute_CID (Node, &CidList);
403169689Skan        if (ACPI_SUCCESS (Status))
404169689Skan        {
405169689Skan            Size += ((ACPI_SIZE) CidList->Count - 1) *
406169689Skan                                 sizeof (ACPI_COMPATIBLE_ID);
407169689Skan            Info.Valid |= ACPI_VALID_CID;
408169689Skan        }
409169689Skan
410169689Skan        /* Execute the Device._STA method */
411169689Skan
412169689Skan        Status = AcpiUtExecute_STA (Node, &Info.CurrentStatus);
413169689Skan        if (ACPI_SUCCESS (Status))
414169689Skan        {
415169689Skan            Info.Valid |= ACPI_VALID_STA;
416169689Skan        }
417169689Skan
418169689Skan        /* Execute the Device._ADR method */
419169689Skan
420169689Skan        Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
421169689Skan                        &Info.Address);
422169689Skan        if (ACPI_SUCCESS (Status))
423169689Skan        {
424169689Skan            Info.Valid |= ACPI_VALID_ADR;
425169689Skan        }
426169689Skan
427169689Skan        /* Execute the Device._SxD methods */
428169689Skan
429169689Skan        Status = AcpiUtExecute_Sxds (Node, Info.HighestDstates);
430169689Skan        if (ACPI_SUCCESS (Status))
431169689Skan        {
432169689Skan            Info.Valid |= ACPI_VALID_SXDS;
433169689Skan        }
434169689Skan
435169689Skan        Status = AE_OK;
436169689Skan    }
437169689Skan
438169689Skan    /* Validate/Allocate/Clear caller buffer */
439169689Skan
440169689Skan    Status = AcpiUtInitializeBuffer (Buffer, Size);
441169689Skan    if (ACPI_FAILURE (Status))
442169689Skan    {
443169689Skan        goto Cleanup;
444169689Skan    }
445169689Skan
446169689Skan    /* Populate the return buffer */
447169689Skan
448169689Skan    ReturnInfo = Buffer->Pointer;
449169689Skan    ACPI_MEMCPY (ReturnInfo, &Info, sizeof (ACPI_DEVICE_INFO));
450169689Skan
451169689Skan    if (CidList)
452169689Skan    {
453169689Skan        ACPI_MEMCPY (&ReturnInfo->CompatibilityId, CidList, CidList->Size);
454169689Skan    }
455169689Skan
456169689Skan
457169689SkanCleanup:
458169689Skan    if (CidList)
459169689Skan    {
460169689Skan        ACPI_MEM_FREE (CidList);
461169689Skan    }
462169689Skan    return (Status);
463169689Skan}
464169689Skan
465169689Skan