Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / components / namespace / nsxfname.c
blobf94c0e45de0385862ac880d7e073dc5bb1774152
1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
13 * All rights reserved.
15 * 2. License
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.
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
39 * conditions are met:
41 * 3. Conditions
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
65 * make.
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.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
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
89 * PARTICULAR PURPOSE.
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.
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 * Alternatively, you may choose to be licensed under the terms of the
118 * following license:
120 * Redistribution and use in source and binary forms, with or without
121 * modification, are permitted provided that the following conditions
122 * are met:
123 * 1. Redistributions of source code must retain the above copyright
124 * notice, this list of conditions, and the following disclaimer,
125 * without modification.
126 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127 * substantially similar to the "NO WARRANTY" disclaimer below
128 * ("Disclaimer") and any redistribution must be conditioned upon
129 * including a substantially similar Disclaimer requirement for further
130 * binary redistribution.
131 * 3. Neither the names of the above-listed copyright holders nor the names
132 * of any contributors may be used to endorse or promote products derived
133 * from this software without specific prior written permission.
135 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
147 * Alternatively, you may choose to be licensed under the terms of the
148 * GNU General Public License ("GPL") version 2 as published by the Free
149 * Software Foundation.
151 *****************************************************************************/
153 #define EXPORT_ACPI_INTERFACES
155 #include "acpi.h"
156 #include "accommon.h"
157 #include "acnamesp.h"
158 #include "acparser.h"
159 #include "amlcode.h"
162 #define _COMPONENT ACPI_NAMESPACE
163 ACPI_MODULE_NAME ("nsxfname")
165 /* Local prototypes */
167 static char *
168 AcpiNsCopyDeviceId (
169 ACPI_PNP_DEVICE_ID *Dest,
170 ACPI_PNP_DEVICE_ID *Source,
171 char *StringArea);
174 /******************************************************************************
176 * FUNCTION: AcpiGetHandle
178 * PARAMETERS: Parent - Object to search under (search scope).
179 * Pathname - Pointer to an asciiz string containing the
180 * name
181 * RetHandle - Where the return handle is returned
183 * RETURN: Status
185 * DESCRIPTION: This routine will search for a caller specified name in the
186 * name space. The caller can restrict the search region by
187 * specifying a non NULL parent. The parent value is itself a
188 * namespace handle.
190 ******************************************************************************/
192 ACPI_STATUS
193 AcpiGetHandle (
194 ACPI_HANDLE Parent,
195 ACPI_STRING Pathname,
196 ACPI_HANDLE *RetHandle)
198 ACPI_STATUS Status;
199 ACPI_NAMESPACE_NODE *Node = NULL;
200 ACPI_NAMESPACE_NODE *PrefixNode = NULL;
203 ACPI_FUNCTION_ENTRY ();
206 /* Parameter Validation */
208 if (!RetHandle || !Pathname)
210 return (AE_BAD_PARAMETER);
213 /* Convert a parent handle to a prefix node */
215 if (Parent)
217 PrefixNode = AcpiNsValidateHandle (Parent);
218 if (!PrefixNode)
220 return (AE_BAD_PARAMETER);
225 * Valid cases are:
226 * 1) Fully qualified pathname
227 * 2) Parent + Relative pathname
229 * Error for <null Parent + relative path>
231 if (ACPI_IS_ROOT_PREFIX (Pathname[0]))
233 /* Pathname is fully qualified (starts with '\') */
235 /* Special case for root-only, since we can't search for it */
237 if (!strcmp (Pathname, ACPI_NS_ROOT_PATH))
239 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
240 return (AE_OK);
243 else if (!PrefixNode)
245 /* Relative path with null prefix is disallowed */
247 return (AE_BAD_PARAMETER);
250 /* Find the Node and convert to a handle */
252 Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
253 if (ACPI_SUCCESS (Status))
255 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
258 return (Status);
261 ACPI_EXPORT_SYMBOL (AcpiGetHandle)
264 /******************************************************************************
266 * FUNCTION: AcpiGetName
268 * PARAMETERS: Handle - Handle to be converted to a pathname
269 * NameType - Full pathname or single segment
270 * Buffer - Buffer for returned path
272 * RETURN: Pointer to a string containing the fully qualified Name.
274 * DESCRIPTION: This routine returns the fully qualified name associated with
275 * the Handle parameter. This and the AcpiPathnameToHandle are
276 * complementary functions.
278 ******************************************************************************/
280 ACPI_STATUS
281 AcpiGetName (
282 ACPI_HANDLE Handle,
283 UINT32 NameType,
284 ACPI_BUFFER *Buffer)
286 ACPI_STATUS Status;
289 /* Parameter validation */
291 if (NameType > ACPI_NAME_TYPE_MAX)
293 return (AE_BAD_PARAMETER);
296 Status = AcpiUtValidateBuffer (Buffer);
297 if (ACPI_FAILURE (Status))
299 return (Status);
303 * Wants the single segment ACPI name.
304 * Validate handle and convert to a namespace Node
306 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
307 if (ACPI_FAILURE (Status))
309 return (Status);
312 if (NameType == ACPI_FULL_PATHNAME ||
313 NameType == ACPI_FULL_PATHNAME_NO_TRAILING)
315 /* Get the full pathname (From the namespace root) */
317 Status = AcpiNsHandleToPathname (Handle, Buffer,
318 NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE);
320 else
322 /* Get the single name */
324 Status = AcpiNsHandleToName (Handle, Buffer);
327 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
328 return (Status);
331 ACPI_EXPORT_SYMBOL (AcpiGetName)
334 /******************************************************************************
336 * FUNCTION: AcpiNsCopyDeviceId
338 * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID
339 * Source - Pointer to the source PNP_DEVICE_ID
340 * StringArea - Pointer to where to copy the dest string
342 * RETURN: Pointer to the next string area
344 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
346 ******************************************************************************/
348 static char *
349 AcpiNsCopyDeviceId (
350 ACPI_PNP_DEVICE_ID *Dest,
351 ACPI_PNP_DEVICE_ID *Source,
352 char *StringArea)
354 /* Create the destination PNP_DEVICE_ID */
356 Dest->String = StringArea;
357 Dest->Length = Source->Length;
359 /* Copy actual string and return a pointer to the next string area */
361 memcpy (StringArea, Source->String, Source->Length);
362 return (StringArea + Source->Length);
366 /******************************************************************************
368 * FUNCTION: AcpiGetObjectInfo
370 * PARAMETERS: Handle - Object Handle
371 * ReturnBuffer - Where the info is returned
373 * RETURN: Status
375 * DESCRIPTION: Returns information about an object as gleaned from the
376 * namespace node and possibly by running several standard
377 * control methods (Such as in the case of a device.)
379 * For Device and Processor objects, run the Device _HID, _UID, _CID,
380 * _CLS, _ADR, _SxW, and _SxD methods.
382 * Note: Allocates the return buffer, must be freed by the caller.
384 * Note: This interface is intended to be used during the initial device
385 * discovery namespace traversal. Therefore, no complex methods can be
386 * executed, especially those that access operation regions. Therefore, do
387 * not add any additional methods that could cause problems in this area.
388 * Because of this reason support for the following methods has been removed:
389 * 1) _SUB method was removed (11/2015)
390 * 2) _STA method was removed (02/2018)
392 ******************************************************************************/
394 ACPI_STATUS
395 AcpiGetObjectInfo (
396 ACPI_HANDLE Handle,
397 ACPI_DEVICE_INFO **ReturnBuffer)
399 ACPI_NAMESPACE_NODE *Node;
400 ACPI_DEVICE_INFO *Info;
401 ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;
402 ACPI_PNP_DEVICE_ID *Hid = NULL;
403 ACPI_PNP_DEVICE_ID *Uid = NULL;
404 ACPI_PNP_DEVICE_ID *Cls = NULL;
405 char *NextIdString;
406 ACPI_OBJECT_TYPE Type;
407 ACPI_NAME Name;
408 UINT8 ParamCount= 0;
409 UINT16 Valid = 0;
410 UINT32 InfoSize;
411 UINT32 i;
412 ACPI_STATUS Status;
415 /* Parameter validation */
417 if (!Handle || !ReturnBuffer)
419 return (AE_BAD_PARAMETER);
422 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
423 if (ACPI_FAILURE (Status))
425 return (Status);
428 Node = AcpiNsValidateHandle (Handle);
429 if (!Node)
431 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
432 return (AE_BAD_PARAMETER);
435 /* Get the namespace node data while the namespace is locked */
437 InfoSize = sizeof (ACPI_DEVICE_INFO);
438 Type = Node->Type;
439 Name = Node->Name.Integer;
441 if (Node->Type == ACPI_TYPE_METHOD)
443 ParamCount = Node->Object->Method.ParamCount;
446 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
447 if (ACPI_FAILURE (Status))
449 return (Status);
452 if ((Type == ACPI_TYPE_DEVICE) ||
453 (Type == ACPI_TYPE_PROCESSOR))
456 * Get extra info for ACPI Device/Processor objects only:
457 * Run the Device _HID, _UID, _CLS, and _CID methods.
459 * Note: none of these methods are required, so they may or may
460 * not be present for this device. The Info->Valid bitfield is used
461 * to indicate which methods were found and run successfully.
464 /* Execute the Device._HID method */
466 Status = AcpiUtExecute_HID (Node, &Hid);
467 if (ACPI_SUCCESS (Status))
469 InfoSize += Hid->Length;
470 Valid |= ACPI_VALID_HID;
473 /* Execute the Device._UID method */
475 Status = AcpiUtExecute_UID (Node, &Uid);
476 if (ACPI_SUCCESS (Status))
478 InfoSize += Uid->Length;
479 Valid |= ACPI_VALID_UID;
482 /* Execute the Device._CID method */
484 Status = AcpiUtExecute_CID (Node, &CidList);
485 if (ACPI_SUCCESS (Status))
487 /* Add size of CID strings and CID pointer array */
489 InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));
490 Valid |= ACPI_VALID_CID;
493 /* Execute the Device._CLS method */
495 Status = AcpiUtExecute_CLS (Node, &Cls);
496 if (ACPI_SUCCESS (Status))
498 InfoSize += Cls->Length;
499 Valid |= ACPI_VALID_CLS;
504 * Now that we have the variable-length data, we can allocate the
505 * return buffer
507 Info = ACPI_ALLOCATE_ZEROED (InfoSize);
508 if (!Info)
510 Status = AE_NO_MEMORY;
511 goto Cleanup;
514 /* Get the fixed-length data */
516 if ((Type == ACPI_TYPE_DEVICE) ||
517 (Type == ACPI_TYPE_PROCESSOR))
520 * Get extra info for ACPI Device/Processor objects only:
521 * Run the _ADR and, SxW, and _SxD methods.
523 * Notes: none of these methods are required, so they may or may
524 * not be present for this device. The Info->Valid bitfield is used
525 * to indicate which methods were found and run successfully.
528 /* Execute the Device._ADR method */
530 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
531 &Info->Address);
532 if (ACPI_SUCCESS (Status))
534 Valid |= ACPI_VALID_ADR;
537 /* Execute the Device._SxW methods */
539 Status = AcpiUtExecutePowerMethods (Node,
540 AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
541 Info->LowestDstates);
542 if (ACPI_SUCCESS (Status))
544 Valid |= ACPI_VALID_SXWS;
547 /* Execute the Device._SxD methods */
549 Status = AcpiUtExecutePowerMethods (Node,
550 AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
551 Info->HighestDstates);
552 if (ACPI_SUCCESS (Status))
554 Valid |= ACPI_VALID_SXDS;
559 * Create a pointer to the string area of the return buffer.
560 * Point to the end of the base ACPI_DEVICE_INFO structure.
562 NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
563 if (CidList)
565 /* Point past the CID PNP_DEVICE_ID array */
567 NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));
571 * Copy the HID, UID, and CIDs to the return buffer. The variable-length
572 * strings are copied to the reserved area at the end of the buffer.
574 * For HID and CID, check if the ID is a PCI Root Bridge.
576 if (Hid)
578 NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
579 Hid, NextIdString);
581 if (AcpiUtIsPciRootBridge (Hid->String))
583 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
587 if (Uid)
589 NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
590 Uid, NextIdString);
593 if (CidList)
595 Info->CompatibleIdList.Count = CidList->Count;
596 Info->CompatibleIdList.ListSize = CidList->ListSize;
598 /* Copy each CID */
600 for (i = 0; i < CidList->Count; i++)
602 NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
603 &CidList->Ids[i], NextIdString);
605 if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
607 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
612 if (Cls)
614 NextIdString = AcpiNsCopyDeviceId (&Info->ClassCode,
615 Cls, NextIdString);
618 /* Copy the fixed-length data */
620 Info->InfoSize = InfoSize;
621 Info->Type = Type;
622 Info->Name = Name;
623 Info->ParamCount = ParamCount;
624 Info->Valid = Valid;
626 *ReturnBuffer = Info;
627 Status = AE_OK;
630 Cleanup:
631 if (Hid)
633 ACPI_FREE (Hid);
635 if (Uid)
637 ACPI_FREE (Uid);
639 if (CidList)
641 ACPI_FREE (CidList);
643 if (Cls)
645 ACPI_FREE (Cls);
647 return (Status);
650 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
653 /******************************************************************************
655 * FUNCTION: AcpiInstallMethod
657 * PARAMETERS: Buffer - An ACPI table containing one control method
659 * RETURN: Status
661 * DESCRIPTION: Install a control method into the namespace. If the method
662 * name already exists in the namespace, it is overwritten. The
663 * input buffer must contain a valid DSDT or SSDT containing a
664 * single control method.
666 ******************************************************************************/
668 ACPI_STATUS
669 AcpiInstallMethod (
670 UINT8 *Buffer)
672 ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
673 UINT8 *AmlBuffer;
674 UINT8 *AmlStart;
675 char *Path;
676 ACPI_NAMESPACE_NODE *Node;
677 ACPI_OPERAND_OBJECT *MethodObj;
678 ACPI_PARSE_STATE ParserState;
679 UINT32 AmlLength;
680 UINT16 Opcode;
681 UINT8 MethodFlags;
682 ACPI_STATUS Status;
685 /* Parameter validation */
687 if (!Buffer)
689 return (AE_BAD_PARAMETER);
692 /* Table must be a DSDT or SSDT */
694 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
695 !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
697 return (AE_BAD_HEADER);
700 /* First AML opcode in the table must be a control method */
702 ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
703 Opcode = AcpiPsPeekOpcode (&ParserState);
704 if (Opcode != AML_METHOD_OP)
706 return (AE_BAD_PARAMETER);
709 /* Extract method information from the raw AML */
711 ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
712 ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
713 Path = AcpiPsGetNextNamestring (&ParserState);
715 MethodFlags = *ParserState.Aml++;
716 AmlStart = ParserState.Aml;
717 AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
720 * Allocate resources up-front. We don't want to have to delete a new
721 * node from the namespace if we cannot allocate memory.
723 AmlBuffer = ACPI_ALLOCATE (AmlLength);
724 if (!AmlBuffer)
726 return (AE_NO_MEMORY);
729 MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
730 if (!MethodObj)
732 ACPI_FREE (AmlBuffer);
733 return (AE_NO_MEMORY);
736 /* Lock namespace for AcpiNsLookup, we may be creating a new node */
738 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
739 if (ACPI_FAILURE (Status))
741 goto ErrorExit;
744 /* The lookup either returns an existing node or creates a new one */
746 Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
747 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
749 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
751 if (ACPI_FAILURE (Status)) /* NsLookup */
753 if (Status != AE_ALREADY_EXISTS)
755 goto ErrorExit;
758 /* Node existed previously, make sure it is a method node */
760 if (Node->Type != ACPI_TYPE_METHOD)
762 Status = AE_TYPE;
763 goto ErrorExit;
767 /* Copy the method AML to the local buffer */
769 memcpy (AmlBuffer, AmlStart, AmlLength);
771 /* Initialize the method object with the new method's information */
773 MethodObj->Method.AmlStart = AmlBuffer;
774 MethodObj->Method.AmlLength = AmlLength;
776 MethodObj->Method.ParamCount = (UINT8)
777 (MethodFlags & AML_METHOD_ARG_COUNT);
779 if (MethodFlags & AML_METHOD_SERIALIZED)
781 MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
783 MethodObj->Method.SyncLevel = (UINT8)
784 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
788 * Now that it is complete, we can attach the new method object to
789 * the method Node (detaches/deletes any existing object)
791 Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);
794 * Flag indicates AML buffer is dynamic, must be deleted later.
795 * Must be set only after attach above.
797 Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
799 /* Remove local reference to the method object */
801 AcpiUtRemoveReference (MethodObj);
802 return (Status);
805 ErrorExit:
807 ACPI_FREE (AmlBuffer);
808 ACPI_FREE (MethodObj);
809 return (Status);
812 ACPI_EXPORT_SYMBOL (AcpiInstallMethod)