xref: /titanic_50/usr/src/uts/intel/io/acpica/namespace/nsxfname.c (revision 269473047d747f7815af570197e4ef7322d3632c)
1 /******************************************************************************
2  *
3  * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4  *                         ACPI Namespace oriented interfaces
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
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
20  * property rights.
21  *
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
28  *
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;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
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.
54  *
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
65  * make.
66  *
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
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
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.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
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
89  * PARTICULAR PURPOSE.
90  *
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
98  * LIMITED REMEDY.
99  *
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.
114  *
115  *****************************************************************************/
116 
117 #define __NSXFNAME_C__
118 
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "acparser.h"
123 #include "amlcode.h"
124 
125 
126 #define _COMPONENT          ACPI_NAMESPACE
127         ACPI_MODULE_NAME    ("nsxfname")
128 
129 
130 /******************************************************************************
131  *
132  * FUNCTION:    AcpiGetHandle
133  *
134  * PARAMETERS:  Parent          - Object to search under (search scope).
135  *              Pathname        - Pointer to an asciiz string containing the
136  *                                name
137  *              RetHandle       - Where the return handle is returned
138  *
139  * RETURN:      Status
140  *
141  * DESCRIPTION: This routine will search for a caller specified name in the
142  *              name space.  The caller can restrict the search region by
143  *              specifying a non NULL parent.  The parent value is itself a
144  *              namespace handle.
145  *
146  ******************************************************************************/
147 
148 ACPI_STATUS
149 AcpiGetHandle (
150     ACPI_HANDLE             Parent,
151     ACPI_STRING             Pathname,
152     ACPI_HANDLE             *RetHandle)
153 {
154     ACPI_STATUS             Status;
155     ACPI_NAMESPACE_NODE     *Node = NULL;
156     ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
157 
158 
159     ACPI_FUNCTION_ENTRY ();
160 
161 
162     /* Parameter Validation */
163 
164     if (!RetHandle || !Pathname)
165     {
166         return (AE_BAD_PARAMETER);
167     }
168 
169     /* Convert a parent handle to a prefix node */
170 
171     if (Parent)
172     {
173         PrefixNode = AcpiNsMapHandleToNode (Parent);
174         if (!PrefixNode)
175         {
176             return (AE_BAD_PARAMETER);
177         }
178     }
179 
180     /*
181      * Valid cases are:
182      * 1) Fully qualified pathname
183      * 2) Parent + Relative pathname
184      *
185      * Error for <null Parent + relative path>
186      */
187     if (AcpiNsValidRootPrefix (Pathname[0]))
188     {
189         /* Pathname is fully qualified (starts with '\') */
190 
191         /* Special case for root-only, since we can't search for it */
192 
193         if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
194         {
195             *RetHandle = AcpiNsConvertEntryToHandle (AcpiGbl_RootNode);
196             return (AE_OK);
197         }
198     }
199     else if (!PrefixNode)
200     {
201         /* Relative path with null prefix is disallowed */
202 
203         return (AE_BAD_PARAMETER);
204     }
205 
206     /* Find the Node and convert to a handle */
207 
208     Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
209     if (ACPI_SUCCESS (Status))
210     {
211         *RetHandle = AcpiNsConvertEntryToHandle (Node);
212     }
213 
214     return (Status);
215 }
216 
217 ACPI_EXPORT_SYMBOL (AcpiGetHandle)
218 
219 
220 /******************************************************************************
221  *
222  * FUNCTION:    AcpiGetName
223  *
224  * PARAMETERS:  Handle          - Handle to be converted to a pathname
225  *              NameType        - Full pathname or single segment
226  *              Buffer          - Buffer for returned path
227  *
228  * RETURN:      Pointer to a string containing the fully qualified Name.
229  *
230  * DESCRIPTION: This routine returns the fully qualified name associated with
231  *              the Handle parameter.  This and the AcpiPathnameToHandle are
232  *              complementary functions.
233  *
234  ******************************************************************************/
235 
236 ACPI_STATUS
237 AcpiGetName (
238     ACPI_HANDLE             Handle,
239     UINT32                  NameType,
240     ACPI_BUFFER             *Buffer)
241 {
242     ACPI_STATUS             Status;
243     ACPI_NAMESPACE_NODE     *Node;
244 
245 
246     /* Parameter validation */
247 
248     if (NameType > ACPI_NAME_TYPE_MAX)
249     {
250         return (AE_BAD_PARAMETER);
251     }
252 
253     Status = AcpiUtValidateBuffer (Buffer);
254     if (ACPI_FAILURE (Status))
255     {
256         return (Status);
257     }
258 
259     if (NameType == ACPI_FULL_PATHNAME)
260     {
261         /* Get the full pathname (From the namespace root) */
262 
263         Status = AcpiNsHandleToPathname (Handle, Buffer);
264         return (Status);
265     }
266 
267     /*
268      * Wants the single segment ACPI name.
269      * Validate handle and convert to a namespace Node
270      */
271     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
272     if (ACPI_FAILURE (Status))
273     {
274         return (Status);
275     }
276 
277     Node = AcpiNsMapHandleToNode (Handle);
278     if (!Node)
279     {
280         Status = AE_BAD_PARAMETER;
281         goto UnlockAndExit;
282     }
283 
284     /* Validate/Allocate/Clear caller buffer */
285 
286     Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
287     if (ACPI_FAILURE (Status))
288     {
289         goto UnlockAndExit;
290     }
291 
292     /* Just copy the ACPI name from the Node and zero terminate it */
293 
294     ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
295                 ACPI_NAME_SIZE);
296     ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
297     Status = AE_OK;
298 
299 
300 UnlockAndExit:
301 
302     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
303     return (Status);
304 }
305 
306 ACPI_EXPORT_SYMBOL (AcpiGetName)
307 
308 
309 /******************************************************************************
310  *
311  * FUNCTION:    AcpiGetObjectInfo
312  *
313  * PARAMETERS:  Handle          - Object Handle
314  *              Buffer          - Where the info is returned
315  *
316  * RETURN:      Status
317  *
318  * DESCRIPTION: Returns information about an object as gleaned from the
319  *              namespace node and possibly by running several standard
320  *              control methods (Such as in the case of a device.)
321  *
322  ******************************************************************************/
323 
324 ACPI_STATUS
325 AcpiGetObjectInfo (
326     ACPI_HANDLE             Handle,
327     ACPI_BUFFER             *Buffer)
328 {
329     ACPI_STATUS             Status;
330     ACPI_NAMESPACE_NODE     *Node;
331     ACPI_DEVICE_INFO        *Info;
332     ACPI_DEVICE_INFO        *ReturnInfo;
333     ACPI_COMPATIBLE_ID_LIST *CidList = NULL;
334     ACPI_SIZE               Size;
335 
336 
337     /* Parameter validation */
338 
339     if (!Handle || !Buffer)
340     {
341         return (AE_BAD_PARAMETER);
342     }
343 
344     Status = AcpiUtValidateBuffer (Buffer);
345     if (ACPI_FAILURE (Status))
346     {
347         return (Status);
348     }
349 
350     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_INFO));
351     if (!Info)
352     {
353         return (AE_NO_MEMORY);
354     }
355 
356     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
357     if (ACPI_FAILURE (Status))
358     {
359         goto Cleanup;
360     }
361 
362     Node = AcpiNsMapHandleToNode (Handle);
363     if (!Node)
364     {
365         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
366         Status = AE_BAD_PARAMETER;
367         goto Cleanup;
368     }
369 
370     /* Init return structure */
371 
372     Size = sizeof (ACPI_DEVICE_INFO);
373 
374     Info->Type  = Node->Type;
375     Info->Name  = Node->Name.Integer;
376     Info->Valid = 0;
377 
378     if (Node->Type == ACPI_TYPE_METHOD)
379     {
380         Info->ParamCount = Node->Object->Method.ParamCount;
381     }
382 
383     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
384     if (ACPI_FAILURE (Status))
385     {
386         goto Cleanup;
387     }
388 
389     /* If not a device, we are all done */
390 
391     if (Info->Type == ACPI_TYPE_DEVICE || Info->Type == ACPI_TYPE_PROCESSOR)
392     {
393         /*
394          * Get extra info for ACPI Devices objects only:
395          * Run the Device _HID, _UID, _CID, _STA, _ADR and _SxD methods.
396          *
397          * Note: none of these methods are required, so they may or may
398          * not be present for this device.  The Info->Valid bitfield is used
399          * to indicate which methods were found and ran successfully.
400          */
401 
402         /* Execute the Device._HID method */
403 
404         Status = AcpiUtExecute_HID (Node, &Info->HardwareId);
405         if (ACPI_SUCCESS (Status))
406         {
407             Info->Valid |= ACPI_VALID_HID;
408         }
409 
410         /* Execute the Device._UID method */
411 
412         Status = AcpiUtExecute_UID (Node, &Info->UniqueId);
413         if (ACPI_SUCCESS (Status))
414         {
415             Info->Valid |= ACPI_VALID_UID;
416         }
417 
418         /* Execute the Device._CID method */
419 
420         Status = AcpiUtExecute_CID (Node, &CidList);
421         if (ACPI_SUCCESS (Status))
422         {
423             Size += CidList->Size;
424             Info->Valid |= ACPI_VALID_CID;
425         }
426 
427         /* Execute the Device._STA method */
428 
429         Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
430         if (ACPI_SUCCESS (Status))
431         {
432             Info->Valid |= ACPI_VALID_STA;
433         }
434 
435         /* Execute the Device._ADR method */
436 
437         Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
438                         &Info->Address);
439         if (ACPI_SUCCESS (Status))
440         {
441             Info->Valid |= ACPI_VALID_ADR;
442         }
443 
444         /* Execute the Device._SxD methods */
445 
446         Status = AcpiUtExecute_Sxds (Node, Info->HighestDstates);
447         if (ACPI_SUCCESS (Status))
448         {
449             Info->Valid |= ACPI_VALID_SXDS;
450         }
451     }
452 
453     /* Validate/Allocate/Clear caller buffer */
454 
455     Status = AcpiUtInitializeBuffer (Buffer, Size);
456     if (ACPI_FAILURE (Status))
457     {
458         goto Cleanup;
459     }
460 
461     /* Populate the return buffer */
462 
463     ReturnInfo = Buffer->Pointer;
464     ACPI_MEMCPY (ReturnInfo, Info, sizeof (ACPI_DEVICE_INFO));
465 
466     if (CidList)
467     {
468         ACPI_MEMCPY (&ReturnInfo->CompatibilityId, CidList, CidList->Size);
469     }
470 
471 
472 Cleanup:
473     ACPI_FREE (Info);
474     if (CidList)
475     {
476         ACPI_FREE (CidList);
477     }
478     return (Status);
479 }
480 
481 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
482 
483 
484 /******************************************************************************
485  *
486  * FUNCTION:    AcpiInstallMethod
487  *
488  * PARAMETERS:  Buffer         - An ACPI table containing one control method
489  *
490  * RETURN:      Status
491  *
492  * DESCRIPTION: Install a control method into the namespace. If the method
493  *              name already exists in the namespace, it is overwritten. The
494  *              input buffer must contain a valid DSDT or SSDT containing a
495  *              single control method.
496  *
497  ******************************************************************************/
498 
499 ACPI_STATUS
500 AcpiInstallMethod (
501     UINT8                   *Buffer)
502 {
503     ACPI_TABLE_HEADER       *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
504     UINT8                   *AmlBuffer;
505     UINT8                   *AmlStart;
506     char                    *Path;
507     ACPI_NAMESPACE_NODE     *Node;
508     ACPI_OPERAND_OBJECT     *MethodObj;
509     ACPI_PARSE_STATE        ParserState;
510     UINT32                  AmlLength;
511     UINT16                  Opcode;
512     UINT8                   MethodFlags;
513     ACPI_STATUS             Status;
514 
515 
516     /* Parameter validation */
517 
518     if (!Buffer)
519     {
520         return (AE_BAD_PARAMETER);
521     }
522 
523     /* Table must be a DSDT or SSDT */
524 
525     if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
526         !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
527     {
528         return (AE_BAD_HEADER);
529     }
530 
531     /* First AML opcode in the table must be a control method */
532 
533     ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
534     Opcode = AcpiPsPeekOpcode (&ParserState);
535     if (Opcode != AML_METHOD_OP)
536     {
537         return (AE_BAD_PARAMETER);
538     }
539 
540     /* Extract method information from the raw AML */
541 
542     ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
543     ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
544     Path = AcpiPsGetNextNamestring (&ParserState);
545     MethodFlags = *ParserState.Aml++;
546     AmlStart = ParserState.Aml;
547     AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
548 
549     /*
550      * Allocate resources up-front. We don't want to have to delete a new
551      * node from the namespace if we cannot allocate memory.
552      */
553     AmlBuffer = ACPI_ALLOCATE (AmlLength);
554     if (!AmlBuffer)
555     {
556         return (AE_NO_MEMORY);
557     }
558 
559     MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
560     if (!MethodObj)
561     {
562         ACPI_FREE (AmlBuffer);
563         return (AE_NO_MEMORY);
564     }
565 
566     /* Lock namespace for AcpiNsLookup, we may be creating a new node */
567 
568     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
569     if (ACPI_FAILURE (Status))
570     {
571         goto ErrorExit;
572     }
573 
574     /* The lookup either returns an existing node or creates a new one */
575 
576     Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
577                 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
578 
579     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
580 
581     if (ACPI_FAILURE (Status)) /* NsLookup */
582     {
583         if (Status != AE_ALREADY_EXISTS)
584         {
585             goto ErrorExit;
586         }
587 
588         /* Node existed previously, make sure it is a method node */
589 
590         if (Node->Type != ACPI_TYPE_METHOD)
591         {
592             Status = AE_TYPE;
593             goto ErrorExit;
594         }
595     }
596 
597     /* Copy the method AML to the local buffer */
598 
599     ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength);
600 
601     /* Initialize the method object with the new method's information */
602 
603     MethodObj->Method.AmlStart = AmlBuffer;
604     MethodObj->Method.AmlLength = AmlLength;
605 
606     MethodObj->Method.ParamCount = (UINT8)
607         (MethodFlags & AML_METHOD_ARG_COUNT);
608 
609     MethodObj->Method.MethodFlags = (UINT8)
610         (MethodFlags & ~AML_METHOD_ARG_COUNT);
611 
612     if (MethodFlags & AML_METHOD_SERIALIZED)
613     {
614         MethodObj->Method.SyncLevel = (UINT8)
615             ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
616     }
617 
618     /*
619      * Now that it is complete, we can attach the new method object to
620      * the method Node (detaches/deletes any existing object)
621      */
622     Status = AcpiNsAttachObject (Node, MethodObj,
623                 ACPI_TYPE_METHOD);
624 
625     /*
626      * Flag indicates AML buffer is dynamic, must be deleted later.
627      * Must be set only after attach above.
628      */
629     Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
630 
631     /* Remove local reference to the method object */
632 
633     AcpiUtRemoveReference (MethodObj);
634     return (Status);
635 
636 
637 ErrorExit:
638 
639     ACPI_FREE (AmlBuffer);
640     ACPI_FREE (MethodObj);
641     return (Status);
642 }
643 
644 ACPI_EXPORT_SYMBOL (AcpiInstallMethod)
645