xref: /freebsd/sys/contrib/dev/acpica/components/namespace/nsxfname.c (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1 /******************************************************************************
2  *
3  * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4  *                         ACPI Namespace oriented interfaces
5  *
6  *****************************************************************************/
7 
8 /*
9  * Copyright (C) 2000 - 2015, Intel Corp.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions, and the following disclaimer,
17  *    without modification.
18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19  *    substantially similar to the "NO WARRANTY" disclaimer below
20  *    ("Disclaimer") and any redistribution must be conditioned upon
21  *    including a substantially similar Disclaimer requirement for further
22  *    binary redistribution.
23  * 3. Neither the names of the above-listed copyright holders nor the names
24  *    of any contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * Alternatively, this software may be distributed under the terms of the
28  * GNU General Public License ("GPL") version 2 as published by the Free
29  * Software Foundation.
30  *
31  * NO WARRANTY
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGES.
43  */
44 
45 #define EXPORT_ACPI_INTERFACES
46 
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acnamesp.h>
50 #include <contrib/dev/acpica/include/acparser.h>
51 #include <contrib/dev/acpica/include/amlcode.h>
52 
53 
54 #define _COMPONENT          ACPI_NAMESPACE
55         ACPI_MODULE_NAME    ("nsxfname")
56 
57 /* Local prototypes */
58 
59 static char *
60 AcpiNsCopyDeviceId (
61     ACPI_PNP_DEVICE_ID      *Dest,
62     ACPI_PNP_DEVICE_ID      *Source,
63     char                    *StringArea);
64 
65 
66 /******************************************************************************
67  *
68  * FUNCTION:    AcpiGetHandle
69  *
70  * PARAMETERS:  Parent          - Object to search under (search scope).
71  *              Pathname        - Pointer to an asciiz string containing the
72  *                                name
73  *              RetHandle       - Where the return handle is returned
74  *
75  * RETURN:      Status
76  *
77  * DESCRIPTION: This routine will search for a caller specified name in the
78  *              name space. The caller can restrict the search region by
79  *              specifying a non NULL parent. The parent value is itself a
80  *              namespace handle.
81  *
82  ******************************************************************************/
83 
84 ACPI_STATUS
85 AcpiGetHandle (
86     ACPI_HANDLE             Parent,
87     ACPI_STRING             Pathname,
88     ACPI_HANDLE             *RetHandle)
89 {
90     ACPI_STATUS             Status;
91     ACPI_NAMESPACE_NODE     *Node = NULL;
92     ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
93 
94 
95     ACPI_FUNCTION_ENTRY ();
96 
97 
98     /* Parameter Validation */
99 
100     if (!RetHandle || !Pathname)
101     {
102         return (AE_BAD_PARAMETER);
103     }
104 
105     /* Convert a parent handle to a prefix node */
106 
107     if (Parent)
108     {
109         PrefixNode = AcpiNsValidateHandle (Parent);
110         if (!PrefixNode)
111         {
112             return (AE_BAD_PARAMETER);
113         }
114     }
115 
116     /*
117      * Valid cases are:
118      * 1) Fully qualified pathname
119      * 2) Parent + Relative pathname
120      *
121      * Error for <null Parent + relative path>
122      */
123     if (ACPI_IS_ROOT_PREFIX (Pathname[0]))
124     {
125         /* Pathname is fully qualified (starts with '\') */
126 
127         /* Special case for root-only, since we can't search for it */
128 
129         if (!strcmp (Pathname, ACPI_NS_ROOT_PATH))
130         {
131             *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
132             return (AE_OK);
133         }
134     }
135     else if (!PrefixNode)
136     {
137         /* Relative path with null prefix is disallowed */
138 
139         return (AE_BAD_PARAMETER);
140     }
141 
142     /* Find the Node and convert to a handle */
143 
144     Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
145     if (ACPI_SUCCESS (Status))
146     {
147         *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
148     }
149 
150     return (Status);
151 }
152 
153 ACPI_EXPORT_SYMBOL (AcpiGetHandle)
154 
155 
156 /******************************************************************************
157  *
158  * FUNCTION:    AcpiGetName
159  *
160  * PARAMETERS:  Handle          - Handle to be converted to a pathname
161  *              NameType        - Full pathname or single segment
162  *              Buffer          - Buffer for returned path
163  *
164  * RETURN:      Pointer to a string containing the fully qualified Name.
165  *
166  * DESCRIPTION: This routine returns the fully qualified name associated with
167  *              the Handle parameter. This and the AcpiPathnameToHandle are
168  *              complementary functions.
169  *
170  ******************************************************************************/
171 
172 ACPI_STATUS
173 AcpiGetName (
174     ACPI_HANDLE             Handle,
175     UINT32                  NameType,
176     ACPI_BUFFER             *Buffer)
177 {
178     ACPI_STATUS             Status;
179     ACPI_NAMESPACE_NODE     *Node;
180     char                    *NodeName;
181 
182 
183     /* Parameter validation */
184 
185     if (NameType > ACPI_NAME_TYPE_MAX)
186     {
187         return (AE_BAD_PARAMETER);
188     }
189 
190     Status = AcpiUtValidateBuffer (Buffer);
191     if (ACPI_FAILURE (Status))
192     {
193         return (Status);
194     }
195 
196     if (NameType == ACPI_FULL_PATHNAME ||
197         NameType == ACPI_FULL_PATHNAME_NO_TRAILING)
198     {
199         /* Get the full pathname (From the namespace root) */
200 
201         Status = AcpiNsHandleToPathname (Handle, Buffer,
202                     NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE);
203         return (Status);
204     }
205 
206     /*
207      * Wants the single segment ACPI name.
208      * Validate handle and convert to a namespace Node
209      */
210     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
211     if (ACPI_FAILURE (Status))
212     {
213         return (Status);
214     }
215 
216     Node = AcpiNsValidateHandle (Handle);
217     if (!Node)
218     {
219         Status = AE_BAD_PARAMETER;
220         goto UnlockAndExit;
221     }
222 
223     /* Validate/Allocate/Clear caller buffer */
224 
225     Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
226     if (ACPI_FAILURE (Status))
227     {
228         goto UnlockAndExit;
229     }
230 
231     /* Just copy the ACPI name from the Node and zero terminate it */
232 
233     NodeName = AcpiUtGetNodeName (Node);
234     ACPI_MOVE_NAME (Buffer->Pointer, NodeName);
235     ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
236     Status = AE_OK;
237 
238 
239 UnlockAndExit:
240 
241     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
242     return (Status);
243 }
244 
245 ACPI_EXPORT_SYMBOL (AcpiGetName)
246 
247 
248 /******************************************************************************
249  *
250  * FUNCTION:    AcpiNsCopyDeviceId
251  *
252  * PARAMETERS:  Dest                - Pointer to the destination PNP_DEVICE_ID
253  *              Source              - Pointer to the source PNP_DEVICE_ID
254  *              StringArea          - Pointer to where to copy the dest string
255  *
256  * RETURN:      Pointer to the next string area
257  *
258  * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
259  *
260  ******************************************************************************/
261 
262 static char *
263 AcpiNsCopyDeviceId (
264     ACPI_PNP_DEVICE_ID      *Dest,
265     ACPI_PNP_DEVICE_ID      *Source,
266     char                    *StringArea)
267 {
268 
269     /* Create the destination PNP_DEVICE_ID */
270 
271     Dest->String = StringArea;
272     Dest->Length = Source->Length;
273 
274     /* Copy actual string and return a pointer to the next string area */
275 
276     memcpy (StringArea, Source->String, Source->Length);
277     return (StringArea + Source->Length);
278 }
279 
280 
281 /******************************************************************************
282  *
283  * FUNCTION:    AcpiGetObjectInfo
284  *
285  * PARAMETERS:  Handle              - Object Handle
286  *              ReturnBuffer        - Where the info is returned
287  *
288  * RETURN:      Status
289  *
290  * DESCRIPTION: Returns information about an object as gleaned from the
291  *              namespace node and possibly by running several standard
292  *              control methods (Such as in the case of a device.)
293  *
294  * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
295  * _CLS, _STA, _ADR, _SxW, and _SxD methods.
296  *
297  * Note: Allocates the return buffer, must be freed by the caller.
298  *
299  ******************************************************************************/
300 
301 ACPI_STATUS
302 AcpiGetObjectInfo (
303     ACPI_HANDLE             Handle,
304     ACPI_DEVICE_INFO        **ReturnBuffer)
305 {
306     ACPI_NAMESPACE_NODE     *Node;
307     ACPI_DEVICE_INFO        *Info;
308     ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;
309     ACPI_PNP_DEVICE_ID      *Hid = NULL;
310     ACPI_PNP_DEVICE_ID      *Uid = NULL;
311     ACPI_PNP_DEVICE_ID      *Sub = NULL;
312     ACPI_PNP_DEVICE_ID      *Cls = NULL;
313     char                    *NextIdString;
314     ACPI_OBJECT_TYPE        Type;
315     ACPI_NAME               Name;
316     UINT8                   ParamCount= 0;
317     UINT16                  Valid = 0;
318     UINT32                  InfoSize;
319     UINT32                  i;
320     ACPI_STATUS             Status;
321 
322 
323     /* Parameter validation */
324 
325     if (!Handle || !ReturnBuffer)
326     {
327         return (AE_BAD_PARAMETER);
328     }
329 
330     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
331     if (ACPI_FAILURE (Status))
332     {
333         return (Status);
334     }
335 
336     Node = AcpiNsValidateHandle (Handle);
337     if (!Node)
338     {
339         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
340         return (AE_BAD_PARAMETER);
341     }
342 
343     /* Get the namespace node data while the namespace is locked */
344 
345     InfoSize = sizeof (ACPI_DEVICE_INFO);
346     Type = Node->Type;
347     Name = Node->Name.Integer;
348 
349     if (Node->Type == ACPI_TYPE_METHOD)
350     {
351         ParamCount = Node->Object->Method.ParamCount;
352     }
353 
354     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
355     if (ACPI_FAILURE (Status))
356     {
357         return (Status);
358     }
359 
360     if ((Type == ACPI_TYPE_DEVICE) ||
361         (Type == ACPI_TYPE_PROCESSOR))
362     {
363         /*
364          * Get extra info for ACPI Device/Processor objects only:
365          * Run the Device _HID, _UID, _SUB, _CID, and _CLS methods.
366          *
367          * Note: none of these methods are required, so they may or may
368          * not be present for this device. The Info->Valid bitfield is used
369          * to indicate which methods were found and run successfully.
370          */
371 
372         /* Execute the Device._HID method */
373 
374         Status = AcpiUtExecute_HID (Node, &Hid);
375         if (ACPI_SUCCESS (Status))
376         {
377             InfoSize += Hid->Length;
378             Valid |= ACPI_VALID_HID;
379         }
380 
381         /* Execute the Device._UID method */
382 
383         Status = AcpiUtExecute_UID (Node, &Uid);
384         if (ACPI_SUCCESS (Status))
385         {
386             InfoSize += Uid->Length;
387             Valid |= ACPI_VALID_UID;
388         }
389 
390         /* Execute the Device._SUB method */
391 
392         Status = AcpiUtExecute_SUB (Node, &Sub);
393         if (ACPI_SUCCESS (Status))
394         {
395             InfoSize += Sub->Length;
396             Valid |= ACPI_VALID_SUB;
397         }
398 
399         /* Execute the Device._CID method */
400 
401         Status = AcpiUtExecute_CID (Node, &CidList);
402         if (ACPI_SUCCESS (Status))
403         {
404             /* Add size of CID strings and CID pointer array */
405 
406             InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));
407             Valid |= ACPI_VALID_CID;
408         }
409 
410         /* Execute the Device._CLS method */
411 
412         Status = AcpiUtExecute_CLS (Node, &Cls);
413         if (ACPI_SUCCESS (Status))
414         {
415             InfoSize += Cls->Length;
416             Valid |= ACPI_VALID_CLS;
417         }
418     }
419 
420     /*
421      * Now that we have the variable-length data, we can allocate the
422      * return buffer
423      */
424     Info = ACPI_ALLOCATE_ZEROED (InfoSize);
425     if (!Info)
426     {
427         Status = AE_NO_MEMORY;
428         goto Cleanup;
429     }
430 
431     /* Get the fixed-length data */
432 
433     if ((Type == ACPI_TYPE_DEVICE) ||
434         (Type == ACPI_TYPE_PROCESSOR))
435     {
436         /*
437          * Get extra info for ACPI Device/Processor objects only:
438          * Run the _STA, _ADR and, SxW, and _SxD methods.
439          *
440          * Notes: none of these methods are required, so they may or may
441          * not be present for this device. The Info->Valid bitfield is used
442          * to indicate which methods were found and run successfully.
443          *
444          * For _STA, if the method does not exist, then (as per the ACPI
445          * specification), the returned CurrentStatus flags will indicate
446          * that the device is present/functional/enabled. Otherwise, the
447          * CurrentStatus flags reflect the value returned from _STA.
448          */
449 
450         /* Execute the Device._STA method */
451 
452         Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
453         if (ACPI_SUCCESS (Status))
454         {
455             Valid |= ACPI_VALID_STA;
456         }
457 
458         /* Execute the Device._ADR method */
459 
460         Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
461                     &Info->Address);
462         if (ACPI_SUCCESS (Status))
463         {
464             Valid |= ACPI_VALID_ADR;
465         }
466 
467         /* Execute the Device._SxW methods */
468 
469         Status = AcpiUtExecutePowerMethods (Node,
470                     AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
471                     Info->LowestDstates);
472         if (ACPI_SUCCESS (Status))
473         {
474             Valid |= ACPI_VALID_SXWS;
475         }
476 
477         /* Execute the Device._SxD methods */
478 
479         Status = AcpiUtExecutePowerMethods (Node,
480                     AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
481                     Info->HighestDstates);
482         if (ACPI_SUCCESS (Status))
483         {
484             Valid |= ACPI_VALID_SXDS;
485         }
486     }
487 
488     /*
489      * Create a pointer to the string area of the return buffer.
490      * Point to the end of the base ACPI_DEVICE_INFO structure.
491      */
492     NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
493     if (CidList)
494     {
495         /* Point past the CID PNP_DEVICE_ID array */
496 
497         NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));
498     }
499 
500     /*
501      * Copy the HID, UID, SUB, and CIDs to the return buffer.
502      * The variable-length strings are copied to the reserved area
503      * at the end of the buffer.
504      *
505      * For HID and CID, check if the ID is a PCI Root Bridge.
506      */
507     if (Hid)
508     {
509         NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
510             Hid, NextIdString);
511 
512         if (AcpiUtIsPciRootBridge (Hid->String))
513         {
514             Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
515         }
516     }
517 
518     if (Uid)
519     {
520         NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
521             Uid, NextIdString);
522     }
523 
524     if (Sub)
525     {
526         NextIdString = AcpiNsCopyDeviceId (&Info->SubsystemId,
527             Sub, NextIdString);
528     }
529 
530     if (CidList)
531     {
532         Info->CompatibleIdList.Count = CidList->Count;
533         Info->CompatibleIdList.ListSize = CidList->ListSize;
534 
535         /* Copy each CID */
536 
537         for (i = 0; i < CidList->Count; i++)
538         {
539             NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
540                 &CidList->Ids[i], NextIdString);
541 
542             if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
543             {
544                 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
545             }
546         }
547     }
548 
549     if (Cls)
550     {
551         NextIdString = AcpiNsCopyDeviceId (&Info->ClassCode,
552             Cls, NextIdString);
553     }
554 
555     /* Copy the fixed-length data */
556 
557     Info->InfoSize = InfoSize;
558     Info->Type = Type;
559     Info->Name = Name;
560     Info->ParamCount = ParamCount;
561     Info->Valid = Valid;
562 
563     *ReturnBuffer = Info;
564     Status = AE_OK;
565 
566 
567 Cleanup:
568     if (Hid)
569     {
570         ACPI_FREE (Hid);
571     }
572     if (Uid)
573     {
574         ACPI_FREE (Uid);
575     }
576     if (Sub)
577     {
578         ACPI_FREE (Sub);
579     }
580     if (CidList)
581     {
582         ACPI_FREE (CidList);
583     }
584     if (Cls)
585     {
586         ACPI_FREE (Cls);
587     }
588     return (Status);
589 }
590 
591 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
592 
593 
594 /******************************************************************************
595  *
596  * FUNCTION:    AcpiInstallMethod
597  *
598  * PARAMETERS:  Buffer         - An ACPI table containing one control method
599  *
600  * RETURN:      Status
601  *
602  * DESCRIPTION: Install a control method into the namespace. If the method
603  *              name already exists in the namespace, it is overwritten. The
604  *              input buffer must contain a valid DSDT or SSDT containing a
605  *              single control method.
606  *
607  ******************************************************************************/
608 
609 ACPI_STATUS
610 AcpiInstallMethod (
611     UINT8                   *Buffer)
612 {
613     ACPI_TABLE_HEADER       *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
614     UINT8                   *AmlBuffer;
615     UINT8                   *AmlStart;
616     char                    *Path;
617     ACPI_NAMESPACE_NODE     *Node;
618     ACPI_OPERAND_OBJECT     *MethodObj;
619     ACPI_PARSE_STATE        ParserState;
620     UINT32                  AmlLength;
621     UINT16                  Opcode;
622     UINT8                   MethodFlags;
623     ACPI_STATUS             Status;
624 
625 
626     /* Parameter validation */
627 
628     if (!Buffer)
629     {
630         return (AE_BAD_PARAMETER);
631     }
632 
633     /* Table must be a DSDT or SSDT */
634 
635     if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
636         !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
637     {
638         return (AE_BAD_HEADER);
639     }
640 
641     /* First AML opcode in the table must be a control method */
642 
643     ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
644     Opcode = AcpiPsPeekOpcode (&ParserState);
645     if (Opcode != AML_METHOD_OP)
646     {
647         return (AE_BAD_PARAMETER);
648     }
649 
650     /* Extract method information from the raw AML */
651 
652     ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
653     ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
654     Path = AcpiPsGetNextNamestring (&ParserState);
655     MethodFlags = *ParserState.Aml++;
656     AmlStart = ParserState.Aml;
657     AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
658 
659     /*
660      * Allocate resources up-front. We don't want to have to delete a new
661      * node from the namespace if we cannot allocate memory.
662      */
663     AmlBuffer = ACPI_ALLOCATE (AmlLength);
664     if (!AmlBuffer)
665     {
666         return (AE_NO_MEMORY);
667     }
668 
669     MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
670     if (!MethodObj)
671     {
672         ACPI_FREE (AmlBuffer);
673         return (AE_NO_MEMORY);
674     }
675 
676     /* Lock namespace for AcpiNsLookup, we may be creating a new node */
677 
678     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
679     if (ACPI_FAILURE (Status))
680     {
681         goto ErrorExit;
682     }
683 
684     /* The lookup either returns an existing node or creates a new one */
685 
686     Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
687                 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
688 
689     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
690 
691     if (ACPI_FAILURE (Status)) /* NsLookup */
692     {
693         if (Status != AE_ALREADY_EXISTS)
694         {
695             goto ErrorExit;
696         }
697 
698         /* Node existed previously, make sure it is a method node */
699 
700         if (Node->Type != ACPI_TYPE_METHOD)
701         {
702             Status = AE_TYPE;
703             goto ErrorExit;
704         }
705     }
706 
707     /* Copy the method AML to the local buffer */
708 
709     memcpy (AmlBuffer, AmlStart, AmlLength);
710 
711     /* Initialize the method object with the new method's information */
712 
713     MethodObj->Method.AmlStart = AmlBuffer;
714     MethodObj->Method.AmlLength = AmlLength;
715 
716     MethodObj->Method.ParamCount = (UINT8)
717         (MethodFlags & AML_METHOD_ARG_COUNT);
718 
719     if (MethodFlags & AML_METHOD_SERIALIZED)
720     {
721         MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
722 
723         MethodObj->Method.SyncLevel = (UINT8)
724             ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
725     }
726 
727     /*
728      * Now that it is complete, we can attach the new method object to
729      * the method Node (detaches/deletes any existing object)
730      */
731     Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);
732 
733     /*
734      * Flag indicates AML buffer is dynamic, must be deleted later.
735      * Must be set only after attach above.
736      */
737     Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
738 
739     /* Remove local reference to the method object */
740 
741     AcpiUtRemoveReference (MethodObj);
742     return (Status);
743 
744 
745 ErrorExit:
746 
747     ACPI_FREE (AmlBuffer);
748     ACPI_FREE (MethodObj);
749     return (Status);
750 }
751 
752 ACPI_EXPORT_SYMBOL (AcpiInstallMethod)
753