nsxfname.c revision 83174
1219820Sjeff/******************************************************************************
2219820Sjeff *
3219820Sjeff * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4219820Sjeff *                         ACPI Namespace oriented interfaces
5219820Sjeff *              $Revision: 80 $
6219820Sjeff *
7219820Sjeff *****************************************************************************/
8219820Sjeff
9219820Sjeff/******************************************************************************
10219820Sjeff *
11219820Sjeff * 1. Copyright Notice
12219820Sjeff *
13219820Sjeff * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
14219820Sjeff * All rights reserved.
15219820Sjeff *
16219820Sjeff * 2. License
17219820Sjeff *
18219820Sjeff * 2.1. This is your license from Intel Corp. under its intellectual property
19219820Sjeff * rights.  You may have additional license terms from the party that provided
20219820Sjeff * you this software, covering your right to use that party's intellectual
21219820Sjeff * property rights.
22219820Sjeff *
23219820Sjeff * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24219820Sjeff * copy of the source code appearing in this file ("Covered Code") an
25219820Sjeff * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26219820Sjeff * base code distributed originally by Intel ("Original Intel Code") to copy,
27219820Sjeff * make derivatives, distribute, use and display any portion of the Covered
28219820Sjeff * Code in any form, with the right to sublicense such rights; and
29219820Sjeff *
30219820Sjeff * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31219820Sjeff * license (with the right to sublicense), under only those claims of Intel
32219820Sjeff * patents that are infringed by the Original Intel Code, to make, use, sell,
33219820Sjeff * offer to sell, and import the Covered Code and derivative works thereof
34219820Sjeff * solely to the minimum extent necessary to exercise the above copyright
35219820Sjeff * license, and in no event shall the patent license extend to any additions
36219820Sjeff * to or modifications of the Original Intel Code.  No other license or right
37219820Sjeff * is granted directly or by implication, estoppel or otherwise;
38219820Sjeff *
39219820Sjeff * The above copyright and patent license is granted only if the following
40219820Sjeff * conditions are met:
41219820Sjeff *
42219820Sjeff * 3. Conditions
43219820Sjeff *
44219820Sjeff * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45219820Sjeff * Redistribution of source code of any substantial portion of the Covered
46219820Sjeff * Code or modification with rights to further distribute source must include
47219820Sjeff * the above Copyright Notice, the above License, this list of Conditions,
48219820Sjeff * and the following Disclaimer and Export Compliance provision.  In addition,
49219820Sjeff * Licensee must cause all Covered Code to which Licensee contributes to
50219820Sjeff * contain a file documenting the changes Licensee made to create that Covered
51219820Sjeff * Code and the date of any change.  Licensee must include in that file the
52219820Sjeff * documentation of any changes made by any predecessor Licensee.  Licensee
53219820Sjeff * must include a prominent statement that the modification is derived,
54219820Sjeff * directly or indirectly, from Original Intel Code.
55219820Sjeff *
56219820Sjeff * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57219820Sjeff * Redistribution of source code of any substantial portion of the Covered
58219820Sjeff * Code or modification without rights to further distribute source must
59219820Sjeff * include the following Disclaimer and Export Compliance provision in the
60219820Sjeff * documentation and/or other materials provided with distribution.  In
61219820Sjeff * addition, Licensee may not authorize further sublicense of source of any
62219820Sjeff * portion of the Covered Code, and must include terms to the effect that the
63219820Sjeff * license from Licensee to its licensee is limited to the intellectual
64219820Sjeff * property embodied in the software Licensee provides to its licensee, and
65219820Sjeff * not to intellectual property embodied in modifications its licensee may
66219820Sjeff * make.
67219820Sjeff *
68219820Sjeff * 3.3. Redistribution of Executable. Redistribution in executable form of any
69219820Sjeff * substantial portion of the Covered Code or modification must reproduce the
70219820Sjeff * above Copyright Notice, and the following Disclaimer and Export Compliance
71219820Sjeff * provision in the documentation and/or other materials provided with the
72219820Sjeff * distribution.
73219820Sjeff *
74219820Sjeff * 3.4. Intel retains all right, title, and interest in and to the Original
75219820Sjeff * Intel Code.
76219820Sjeff *
77219820Sjeff * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78219820Sjeff * Intel shall be used in advertising or otherwise to promote the sale, use or
79219820Sjeff * other dealings in products derived from or relating to the Covered Code
80219820Sjeff * without prior written authorization from Intel.
81219820Sjeff *
82219820Sjeff * 4. Disclaimer and Export Compliance
83219820Sjeff *
84219820Sjeff * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85219820Sjeff * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86219820Sjeff * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87219820Sjeff * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88219820Sjeff * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89219820Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90219820Sjeff * PARTICULAR PURPOSE.
91219820Sjeff *
92219820Sjeff * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93219820Sjeff * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94219820Sjeff * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95219820Sjeff * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96219820Sjeff * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97219820Sjeff * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98219820Sjeff * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99219820Sjeff * LIMITED REMEDY.
100219820Sjeff *
101219820Sjeff * 4.3. Licensee shall not export, either directly or indirectly, any of this
102219820Sjeff * software or system incorporating such software without first obtaining any
103219820Sjeff * required license or other approval from the U. S. Department of Commerce or
104219820Sjeff * any other agency or department of the United States Government.  In the
105219820Sjeff * event Licensee exports any such software from the United States or
106219820Sjeff * re-exports any such software from a foreign destination, Licensee shall
107219820Sjeff * ensure that the distribution and export/re-export of the software is in
108219820Sjeff * compliance with all laws, regulations, orders, or other restrictions of the
109219820Sjeff * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110219820Sjeff * any of its subsidiaries will export/re-export any technical data, process,
111219820Sjeff * software, or service, directly or indirectly, to any country for which the
112219820Sjeff * United States government or any agency thereof requires an export license,
113219820Sjeff * other governmental approval, or letter of assurance, without first obtaining
114219820Sjeff * such license, approval or letter.
115219820Sjeff *
116219820Sjeff *****************************************************************************/
117219820Sjeff
118219820Sjeff#define __NSXFNAME_C__
119219820Sjeff
120219820Sjeff#include "acpi.h"
121219820Sjeff#include "acinterp.h"
122219820Sjeff#include "acnamesp.h"
123219820Sjeff#include "amlcode.h"
124219820Sjeff#include "acparser.h"
125219820Sjeff#include "acdispat.h"
126219820Sjeff#include "acevents.h"
127219820Sjeff
128219820Sjeff
129219820Sjeff#define _COMPONENT          ACPI_NAMESPACE
130219820Sjeff        MODULE_NAME         ("nsxfname")
131219820Sjeff
132219820Sjeff
133219820Sjeff/****************************************************************************
134219820Sjeff *
135219820Sjeff * FUNCTION:    AcpiGetHandle
136219820Sjeff *
137219820Sjeff * PARAMETERS:  Parent          - Object to search under (search scope).
138219820Sjeff *              PathName        - Pointer to an asciiz string containing the
139219820Sjeff *                                  name
140219820Sjeff *              RetHandle       - Where the return handle is placed
141219820Sjeff *
142219820Sjeff * RETURN:      Status
143219820Sjeff *
144219820Sjeff * DESCRIPTION: This routine will search for a caller specified name in the
145219820Sjeff *              name space.  The caller can restrict the search region by
146219820Sjeff *              specifying a non NULL parent.  The parent value is itself a
147219820Sjeff *              namespace handle.
148219820Sjeff *
149219820Sjeff ******************************************************************************/
150219820Sjeff
151219820SjeffACPI_STATUS
152219820SjeffAcpiGetHandle (
153219820Sjeff    ACPI_HANDLE             Parent,
154219820Sjeff    ACPI_STRING             Pathname,
155219820Sjeff    ACPI_HANDLE             *RetHandle)
156219820Sjeff{
157219820Sjeff    ACPI_STATUS             Status;
158219820Sjeff    ACPI_NAMESPACE_NODE     *Node = NULL;
159219820Sjeff    ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
160219820Sjeff
161219820Sjeff
162219820Sjeff    FUNCTION_ENTRY ();
163219820Sjeff
164219820Sjeff
165219820Sjeff    /* Ensure that ACPI has been initialized */
166219820Sjeff
167219820Sjeff    ACPI_IS_INITIALIZATION_COMPLETE (Status);
168219820Sjeff    if (ACPI_FAILURE (Status))
169219820Sjeff    {
170219820Sjeff        return (Status);
171219820Sjeff    }
172219820Sjeff
173219820Sjeff    /* Parameter Validation */
174219820Sjeff
175219820Sjeff    if (!RetHandle || !Pathname)
176219820Sjeff    {
177219820Sjeff        return (AE_BAD_PARAMETER);
178219820Sjeff    }
179219820Sjeff
180219820Sjeff    /* Convert a parent handle to a prefix node */
181219820Sjeff
182219820Sjeff    if (Parent)
183219820Sjeff    {
184219820Sjeff        AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
185219820Sjeff
186219820Sjeff        PrefixNode = AcpiNsConvertHandleToEntry (Parent);
187219820Sjeff        if (!PrefixNode)
188219820Sjeff        {
189219820Sjeff            AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
190219820Sjeff            return (AE_BAD_PARAMETER);
191219820Sjeff        }
192219820Sjeff
193219820Sjeff        AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
194219820Sjeff    }
195219820Sjeff
196219820Sjeff    /* Special case for root, since we can't search for it */
197219820Sjeff
198219820Sjeff    if (STRCMP (Pathname, NS_ROOT_PATH) == 0)
199219820Sjeff    {
200219820Sjeff        *RetHandle = AcpiNsConvertEntryToHandle (AcpiGbl_RootNode);
201219820Sjeff        return (AE_OK);
202219820Sjeff    }
203
204    /*
205     *  Find the Node and convert to a handle
206     */
207    Status = AcpiNsGetNode (Pathname, PrefixNode, &Node);
208
209    *RetHandle = NULL;
210    if (ACPI_SUCCESS (Status))
211    {
212        *RetHandle = AcpiNsConvertEntryToHandle (Node);
213    }
214
215    return (Status);
216}
217
218
219/****************************************************************************
220 *
221 * FUNCTION:    AcpiGetName
222 *
223 * PARAMETERS:  Handle          - Handle to be converted to a pathname
224 *              NameType        - Full pathname or single segment
225 *              RetPathPtr      - Buffer for returned path
226 *
227 * RETURN:      Pointer to a string containing the fully qualified Name.
228 *
229 * DESCRIPTION: This routine returns the fully qualified name associated with
230 *              the Handle parameter.  This and the AcpiPathnameToHandle are
231 *              complementary functions.
232 *
233 ******************************************************************************/
234
235ACPI_STATUS
236AcpiGetName (
237    ACPI_HANDLE             Handle,
238    UINT32                  NameType,
239    ACPI_BUFFER             *RetPathPtr)
240{
241    ACPI_STATUS             Status;
242    ACPI_NAMESPACE_NODE     *Node;
243
244
245    /* Ensure that ACPI has been initialized */
246
247    ACPI_IS_INITIALIZATION_COMPLETE (Status);
248    if (ACPI_FAILURE (Status))
249    {
250        return (Status);
251    }
252
253    /* Buffer pointer must be valid always */
254
255    if (!RetPathPtr || (NameType > ACPI_NAME_TYPE_MAX))
256    {
257        return (AE_BAD_PARAMETER);
258    }
259
260    /* Allow length to be zero and ignore the pointer */
261
262    if ((RetPathPtr->Length) &&
263       (!RetPathPtr->Pointer))
264    {
265        return (AE_BAD_PARAMETER);
266    }
267
268    if (NameType == ACPI_FULL_PATHNAME)
269    {
270        /* Get the full pathname (From the namespace root) */
271
272        Status = AcpiNsHandleToPathname (Handle, &RetPathPtr->Length,
273                                        RetPathPtr->Pointer);
274        return (Status);
275    }
276
277    /*
278     * Wants the single segment ACPI name.
279     * Validate handle and convert to an Node
280     */
281    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
282    Node = AcpiNsConvertHandleToEntry (Handle);
283    if (!Node)
284    {
285        Status = AE_BAD_PARAMETER;
286        goto UnlockAndExit;
287    }
288
289    /* Check if name will fit in buffer */
290
291    if (RetPathPtr->Length < PATH_SEGMENT_LENGTH)
292    {
293        RetPathPtr->Length = PATH_SEGMENT_LENGTH;
294        Status = AE_BUFFER_OVERFLOW;
295        goto UnlockAndExit;
296    }
297
298    /* Just copy the ACPI name from the Node and zero terminate it */
299
300    STRNCPY (RetPathPtr->Pointer, (NATIVE_CHAR *) &Node->Name,
301                ACPI_NAME_SIZE);
302    ((NATIVE_CHAR *) RetPathPtr->Pointer) [ACPI_NAME_SIZE] = 0;
303    Status = AE_OK;
304
305
306UnlockAndExit:
307
308    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
309    return (Status);
310}
311
312
313/****************************************************************************
314 *
315 * FUNCTION:    AcpiGetObjectInfo
316 *
317 * PARAMETERS:  Handle          - Object Handle
318 *              Info            - Where the info is returned
319 *
320 * RETURN:      Status
321 *
322 * DESCRIPTION: Returns information about an object as gleaned from the
323 *              namespace node and possibly by running several standard
324 *              control methods (Such as in the case of a device.)
325 *
326 ******************************************************************************/
327
328ACPI_STATUS
329AcpiGetObjectInfo (
330    ACPI_HANDLE             Handle,
331    ACPI_DEVICE_INFO        *Info)
332{
333    ACPI_DEVICE_ID          Hid;
334    ACPI_DEVICE_ID          Uid;
335    ACPI_STATUS             Status;
336    UINT32                  DeviceStatus = 0;
337    ACPI_INTEGER            Address = 0;
338    ACPI_NAMESPACE_NODE     *Node;
339
340
341    /* Ensure that ACPI has been initialized */
342
343    ACPI_IS_INITIALIZATION_COMPLETE (Status);
344    if (ACPI_FAILURE (Status))
345    {
346        return (Status);
347    }
348
349    /* Parameter validation */
350
351    if (!Handle || !Info)
352    {
353        return (AE_BAD_PARAMETER);
354    }
355
356    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
357
358    Node = AcpiNsConvertHandleToEntry (Handle);
359    if (!Node)
360    {
361        AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
362        return (AE_BAD_PARAMETER);
363    }
364
365    Info->Type      = Node->Type;
366    Info->Name      = Node->Name;
367
368    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
369
370    /*
371     * If not a device, we are all done.
372     */
373    if (Info->Type != ACPI_TYPE_DEVICE)
374    {
375        return (AE_OK);
376    }
377
378
379    /*
380     * Get extra info for ACPI devices only.  Run the
381     * _HID, _UID, _STA, and _ADR methods.  Note: none
382     * of these methods are required, so they may or may
383     * not be present.  The Info->Valid bits are used
384     * to indicate which methods ran successfully.
385     */
386    Info->Valid = 0;
387
388    /* Execute the _HID method and save the result */
389
390    Status = AcpiUtExecute_HID (Node, &Hid);
391    if (ACPI_SUCCESS (Status))
392    {
393        STRNCPY (Info->HardwareId, Hid.Buffer, sizeof(Info->HardwareId));
394
395        Info->Valid |= ACPI_VALID_HID;
396    }
397
398    /* Execute the _UID method and save the result */
399
400    Status = AcpiUtExecute_UID (Node, &Uid);
401    if (ACPI_SUCCESS (Status))
402    {
403        STRCPY (Info->UniqueId, Uid.Buffer);
404
405        Info->Valid |= ACPI_VALID_UID;
406    }
407
408    /*
409     * Execute the _STA method and save the result
410     * _STA is not always present
411     */
412    Status = AcpiUtExecute_STA (Node, &DeviceStatus);
413    if (ACPI_SUCCESS (Status))
414    {
415        Info->CurrentStatus = DeviceStatus;
416        Info->Valid |= ACPI_VALID_STA;
417    }
418
419    /*
420     * Execute the _ADR method and save result if successful
421     * _ADR is not always present
422     */
423    Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
424                                            Node, &Address);
425
426    if (ACPI_SUCCESS (Status))
427    {
428        Info->Address = Address;
429        Info->Valid |= ACPI_VALID_ADR;
430    }
431
432    return (AE_OK);
433}
434
435