1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #define __NSXFNAME_C__
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "acparser.h"
126 #define _COMPONENT ACPI_NAMESPACE
127 ACPI_MODULE_NAME ("nsxfname")
129 /* Local prototypes */
133 ACPI_DEVICE_ID
*Dest
,
134 ACPI_DEVICE_ID
*Source
,
138 /******************************************************************************
140 * FUNCTION: AcpiGetHandle
142 * PARAMETERS: Parent - Object to search under (search scope).
143 * Pathname - Pointer to an asciiz string containing the
145 * RetHandle - Where the return handle is returned
149 * DESCRIPTION: This routine will search for a caller specified name in the
150 * name space. The caller can restrict the search region by
151 * specifying a non NULL parent. The parent value is itself a
154 ******************************************************************************/
159 ACPI_CONST_STRING Pathname
,
160 ACPI_HANDLE
*RetHandle
)
163 ACPI_NAMESPACE_NODE
*Node
= NULL
;
164 ACPI_NAMESPACE_NODE
*PrefixNode
= NULL
;
165 ACPI_STRING UPathname
= __UNCONST(Pathname
);
168 ACPI_FUNCTION_ENTRY ();
171 /* Parameter Validation */
173 if (!RetHandle
|| !Pathname
)
175 return (AE_BAD_PARAMETER
);
178 /* Convert a parent handle to a prefix node */
182 PrefixNode
= AcpiNsMapHandleToNode (Parent
);
185 return (AE_BAD_PARAMETER
);
191 * 1) Fully qualified pathname
192 * 2) Parent + Relative pathname
194 * Error for <null Parent + relative path>
196 if (AcpiNsValidRootPrefix (UPathname
[0]))
198 /* Pathname is fully qualified (starts with '\') */
200 /* Special case for root-only, since we can't search for it */
202 if (!ACPI_STRCMP (UPathname
, ACPI_NS_ROOT_PATH
))
204 *RetHandle
= AcpiNsConvertEntryToHandle (AcpiGbl_RootNode
);
208 else if (!PrefixNode
)
210 /* Relative path with null prefix is disallowed */
212 return (AE_BAD_PARAMETER
);
215 /* Find the Node and convert to a handle */
217 Status
= AcpiNsGetNode (PrefixNode
, UPathname
, ACPI_NS_NO_UPSEARCH
, &Node
);
218 if (ACPI_SUCCESS (Status
))
220 *RetHandle
= AcpiNsConvertEntryToHandle (Node
);
226 ACPI_EXPORT_SYMBOL (AcpiGetHandle
)
229 /******************************************************************************
231 * FUNCTION: AcpiGetName
233 * PARAMETERS: Handle - Handle to be converted to a pathname
234 * NameType - Full pathname or single segment
235 * Buffer - Buffer for returned path
237 * RETURN: Pointer to a string containing the fully qualified Name.
239 * DESCRIPTION: This routine returns the fully qualified name associated with
240 * the Handle parameter. This and the AcpiPathnameToHandle are
241 * complementary functions.
243 ******************************************************************************/
252 ACPI_NAMESPACE_NODE
*Node
;
255 /* Parameter validation */
257 if (NameType
> ACPI_NAME_TYPE_MAX
)
259 return (AE_BAD_PARAMETER
);
262 Status
= AcpiUtValidateBuffer (Buffer
);
263 if (ACPI_FAILURE (Status
))
268 if (NameType
== ACPI_FULL_PATHNAME
)
270 /* Get the full pathname (From the namespace root) */
272 Status
= AcpiNsHandleToPathname (Handle
, Buffer
);
277 * Wants the single segment ACPI name.
278 * Validate handle and convert to a namespace Node
280 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
281 if (ACPI_FAILURE (Status
))
286 Node
= AcpiNsMapHandleToNode (Handle
);
289 Status
= AE_BAD_PARAMETER
;
293 /* Validate/Allocate/Clear caller buffer */
295 Status
= AcpiUtInitializeBuffer (Buffer
, ACPI_PATH_SEGMENT_LENGTH
);
296 if (ACPI_FAILURE (Status
))
301 /* Just copy the ACPI name from the Node and zero terminate it */
303 ACPI_STRNCPY (Buffer
->Pointer
, AcpiUtGetNodeName (Node
),
305 ((char *) Buffer
->Pointer
) [ACPI_NAME_SIZE
] = 0;
311 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
315 ACPI_EXPORT_SYMBOL (AcpiGetName
)
318 /******************************************************************************
320 * FUNCTION: AcpiNsCopyDeviceId
322 * PARAMETERS: Dest - Pointer to the destination DEVICE_ID
323 * Source - Pointer to the source DEVICE_ID
324 * StringArea - Pointer to where to copy the dest string
326 * RETURN: Pointer to the next string area
328 * DESCRIPTION: Copy a single DEVICE_ID, including the string data.
330 ******************************************************************************/
334 ACPI_DEVICE_ID
*Dest
,
335 ACPI_DEVICE_ID
*Source
,
338 /* Create the destination DEVICE_ID */
340 Dest
->String
= StringArea
;
341 Dest
->Length
= Source
->Length
;
343 /* Copy actual string and return a pointer to the next string area */
345 ACPI_MEMCPY (StringArea
, Source
->String
, Source
->Length
);
346 return (StringArea
+ Source
->Length
);
350 /******************************************************************************
352 * FUNCTION: AcpiGetObjectInfo
354 * PARAMETERS: Handle - Object Handle
355 * ReturnBuffer - Where the info is returned
359 * DESCRIPTION: Returns information about an object as gleaned from the
360 * namespace node and possibly by running several standard
361 * control methods (Such as in the case of a device.)
363 * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
364 * _ADR, _SxW, and _SxD methods.
366 * Note: Allocates the return buffer, must be freed by the caller.
368 ******************************************************************************/
373 ACPI_DEVICE_INFO
**ReturnBuffer
)
375 ACPI_NAMESPACE_NODE
*Node
;
376 ACPI_DEVICE_INFO
*Info
;
377 ACPI_DEVICE_ID_LIST
*CidList
= NULL
;
378 ACPI_DEVICE_ID
*Hid
= NULL
;
379 ACPI_DEVICE_ID
*Uid
= NULL
;
381 ACPI_OBJECT_TYPE Type
;
390 /* Parameter validation */
392 if (!Handle
|| !ReturnBuffer
)
394 return (AE_BAD_PARAMETER
);
397 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
398 if (ACPI_FAILURE (Status
))
403 Node
= AcpiNsMapHandleToNode (Handle
);
406 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
407 return (AE_BAD_PARAMETER
);
410 /* Get the namespace node data while the namespace is locked */
412 InfoSize
= sizeof (ACPI_DEVICE_INFO
);
414 Name
= Node
->Name
.Integer
;
416 if (Node
->Type
== ACPI_TYPE_METHOD
)
418 ParamCount
= Node
->Object
->Method
.ParamCount
;
421 Status
= AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
422 if (ACPI_FAILURE (Status
))
427 if ((Type
== ACPI_TYPE_DEVICE
) ||
428 (Type
== ACPI_TYPE_PROCESSOR
))
431 * Get extra info for ACPI Device/Processor objects only:
432 * Run the Device _HID, _UID, and _CID methods.
434 * Note: none of these methods are required, so they may or may
435 * not be present for this device. The Info->Valid bitfield is used
436 * to indicate which methods were found and run successfully.
439 /* Execute the Device._HID method */
441 Status
= AcpiUtExecute_HID (Node
, &Hid
);
442 if (ACPI_SUCCESS (Status
))
444 InfoSize
+= Hid
->Length
;
445 Valid
|= ACPI_VALID_HID
;
448 /* Execute the Device._UID method */
450 Status
= AcpiUtExecute_UID (Node
, &Uid
);
451 if (ACPI_SUCCESS (Status
))
453 InfoSize
+= Uid
->Length
;
454 Valid
|= ACPI_VALID_UID
;
457 /* Execute the Device._CID method */
459 Status
= AcpiUtExecute_CID (Node
, &CidList
);
460 if (ACPI_SUCCESS (Status
))
462 /* Add size of CID strings and CID pointer array */
464 InfoSize
+= (CidList
->ListSize
- sizeof (ACPI_DEVICE_ID_LIST
));
465 Valid
|= ACPI_VALID_CID
;
470 * Now that we have the variable-length data, we can allocate the
473 Info
= ACPI_ALLOCATE_ZEROED (InfoSize
);
476 Status
= AE_NO_MEMORY
;
480 /* Get the fixed-length data */
482 if ((Type
== ACPI_TYPE_DEVICE
) ||
483 (Type
== ACPI_TYPE_PROCESSOR
))
486 * Get extra info for ACPI Device/Processor objects only:
487 * Run the _STA, _ADR and, SxW, and _SxD methods.
489 * Note: none of these methods are required, so they may or may
490 * not be present for this device. The Info->Valid bitfield is used
491 * to indicate which methods were found and run successfully.
494 /* Execute the Device._STA method */
496 Status
= AcpiUtExecute_STA (Node
, &Info
->CurrentStatus
);
497 if (ACPI_SUCCESS (Status
))
499 Valid
|= ACPI_VALID_STA
;
502 /* Execute the Device._ADR method */
504 Status
= AcpiUtEvaluateNumericObject (METHOD_NAME__ADR
, Node
,
506 if (ACPI_SUCCESS (Status
))
508 Valid
|= ACPI_VALID_ADR
;
511 /* Execute the Device._SxW methods */
513 Status
= AcpiUtExecutePowerMethods (Node
,
514 AcpiGbl_LowestDstateNames
, ACPI_NUM_SxW_METHODS
,
515 Info
->LowestDstates
);
516 if (ACPI_SUCCESS (Status
))
518 Valid
|= ACPI_VALID_SXWS
;
521 /* Execute the Device._SxD methods */
523 Status
= AcpiUtExecutePowerMethods (Node
,
524 AcpiGbl_HighestDstateNames
, ACPI_NUM_SxD_METHODS
,
525 Info
->HighestDstates
);
526 if (ACPI_SUCCESS (Status
))
528 Valid
|= ACPI_VALID_SXDS
;
533 * Create a pointer to the string area of the return buffer.
534 * Point to the end of the base ACPI_DEVICE_INFO structure.
536 NextIdString
= ACPI_CAST_PTR (char, Info
->CompatibleIdList
.Ids
);
539 /* Point past the CID DEVICE_ID array */
541 NextIdString
+= ((ACPI_SIZE
) CidList
->Count
* sizeof (ACPI_DEVICE_ID
));
545 * Copy the HID, UID, and CIDs to the return buffer. The variable-length
546 * strings are copied to the reserved area at the end of the buffer.
548 * For HID and CID, check if the ID is a PCI Root Bridge.
552 NextIdString
= AcpiNsCopyDeviceId (&Info
->HardwareId
,
555 if (AcpiUtIsPciRootBridge (Hid
->String
))
557 Info
->Flags
|= ACPI_PCI_ROOT_BRIDGE
;
563 NextIdString
= AcpiNsCopyDeviceId (&Info
->UniqueId
,
569 Info
->CompatibleIdList
.Count
= CidList
->Count
;
570 Info
->CompatibleIdList
.ListSize
= CidList
->ListSize
;
574 for (i
= 0; i
< CidList
->Count
; i
++)
576 NextIdString
= AcpiNsCopyDeviceId (&Info
->CompatibleIdList
.Ids
[i
],
577 &CidList
->Ids
[i
], NextIdString
);
579 if (AcpiUtIsPciRootBridge (CidList
->Ids
[i
].String
))
581 Info
->Flags
|= ACPI_PCI_ROOT_BRIDGE
;
586 /* Copy the fixed-length data */
588 Info
->InfoSize
= InfoSize
;
591 Info
->ParamCount
= ParamCount
;
594 *ReturnBuffer
= Info
;
614 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo
)
617 /******************************************************************************
619 * FUNCTION: AcpiInstallMethod
621 * PARAMETERS: Buffer - An ACPI table containing one control method
625 * DESCRIPTION: Install a control method into the namespace. If the method
626 * name already exists in the namespace, it is overwritten. The
627 * input buffer must contain a valid DSDT or SSDT containing a
628 * single control method.
630 ******************************************************************************/
636 ACPI_TABLE_HEADER
*Table
= ACPI_CAST_PTR (ACPI_TABLE_HEADER
, Buffer
);
640 ACPI_NAMESPACE_NODE
*Node
;
641 ACPI_OPERAND_OBJECT
*MethodObj
;
642 ACPI_PARSE_STATE ParserState
;
649 /* Parameter validation */
653 return (AE_BAD_PARAMETER
);
656 /* Table must be a DSDT or SSDT */
658 if (!ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_DSDT
) &&
659 !ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_SSDT
))
661 return (AE_BAD_HEADER
);
664 /* First AML opcode in the table must be a control method */
666 ParserState
.Aml
= Buffer
+ sizeof (ACPI_TABLE_HEADER
);
667 Opcode
= AcpiPsPeekOpcode (&ParserState
);
668 if (Opcode
!= AML_METHOD_OP
)
670 return (AE_BAD_PARAMETER
);
673 /* Extract method information from the raw AML */
675 ParserState
.Aml
+= AcpiPsGetOpcodeSize (Opcode
);
676 ParserState
.PkgEnd
= AcpiPsGetNextPackageEnd (&ParserState
);
677 Path
= AcpiPsGetNextNamestring (&ParserState
);
678 MethodFlags
= *ParserState
.Aml
++;
679 AmlStart
= ParserState
.Aml
;
680 AmlLength
= ACPI_PTR_DIFF (ParserState
.PkgEnd
, AmlStart
);
683 * Allocate resources up-front. We don't want to have to delete a new
684 * node from the namespace if we cannot allocate memory.
686 AmlBuffer
= ACPI_ALLOCATE (AmlLength
);
689 return (AE_NO_MEMORY
);
692 MethodObj
= AcpiUtCreateInternalObject (ACPI_TYPE_METHOD
);
695 ACPI_FREE (AmlBuffer
);
696 return (AE_NO_MEMORY
);
699 /* Lock namespace for AcpiNsLookup, we may be creating a new node */
701 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
702 if (ACPI_FAILURE (Status
))
707 /* The lookup either returns an existing node or creates a new one */
709 Status
= AcpiNsLookup (NULL
, Path
, ACPI_TYPE_METHOD
, ACPI_IMODE_LOAD_PASS1
,
710 ACPI_NS_DONT_OPEN_SCOPE
| ACPI_NS_ERROR_IF_FOUND
, NULL
, &Node
);
712 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
714 if (ACPI_FAILURE (Status
)) /* NsLookup */
716 if (Status
!= AE_ALREADY_EXISTS
)
721 /* Node existed previously, make sure it is a method node */
723 if (Node
->Type
!= ACPI_TYPE_METHOD
)
730 /* Copy the method AML to the local buffer */
732 ACPI_MEMCPY (AmlBuffer
, AmlStart
, AmlLength
);
734 /* Initialize the method object with the new method's information */
736 MethodObj
->Method
.AmlStart
= AmlBuffer
;
737 MethodObj
->Method
.AmlLength
= AmlLength
;
739 MethodObj
->Method
.ParamCount
= (UINT8
)
740 (MethodFlags
& AML_METHOD_ARG_COUNT
);
742 MethodObj
->Method
.MethodFlags
= (UINT8
)
743 (MethodFlags
& ~AML_METHOD_ARG_COUNT
);
745 if (MethodFlags
& AML_METHOD_SERIALIZED
)
747 MethodObj
->Method
.SyncLevel
= (UINT8
)
748 ((MethodFlags
& AML_METHOD_SYNC_LEVEL
) >> 4);
752 * Now that it is complete, we can attach the new method object to
753 * the method Node (detaches/deletes any existing object)
755 Status
= AcpiNsAttachObject (Node
, MethodObj
,
759 * Flag indicates AML buffer is dynamic, must be deleted later.
760 * Must be set only after attach above.
762 Node
->Flags
|= ANOBJ_ALLOCATED_BUFFER
;
764 /* Remove local reference to the method object */
766 AcpiUtRemoveReference (MethodObj
);
772 ACPI_FREE (AmlBuffer
);
773 ACPI_FREE (MethodObj
);
777 ACPI_EXPORT_SYMBOL (AcpiInstallMethod
)