Home | History | Annotate | Line # | Download | only in namespace
nsxfname.c revision 1.9
      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 - 2017, 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 "acpi.h"
     48 #include "accommon.h"
     49 #include "acnamesp.h"
     50 #include "acparser.h"
     51 #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_CONST_STRING       Pathname,
     88     ACPI_HANDLE             *RetHandle)
     89 {
     90     ACPI_STATUS             Status;
     91     ACPI_NAMESPACE_NODE     *Node = NULL;
     92     ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
     93     ACPI_STRING             UPathname = __UNCONST(Pathname);
     94 
     95 
     96     ACPI_FUNCTION_ENTRY ();
     97 
     98 
     99     /* Parameter Validation */
    100 
    101     if (!RetHandle || !Pathname)
    102     {
    103         return (AE_BAD_PARAMETER);
    104     }
    105 
    106     /* Convert a parent handle to a prefix node */
    107 
    108     if (Parent)
    109     {
    110         PrefixNode = AcpiNsValidateHandle (Parent);
    111         if (!PrefixNode)
    112         {
    113             return (AE_BAD_PARAMETER);
    114         }
    115     }
    116 
    117     /*
    118      * Valid cases are:
    119      * 1) Fully qualified pathname
    120      * 2) Parent + Relative pathname
    121      *
    122      * Error for <null Parent + relative path>
    123      */
    124     if (ACPI_IS_ROOT_PREFIX (Pathname[0]))
    125     {
    126         /* Pathname is fully qualified (starts with '\') */
    127 
    128         /* Special case for root-only, since we can't search for it */
    129 
    130         if (!strcmp (Pathname, ACPI_NS_ROOT_PATH))
    131         {
    132             *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
    133             return (AE_OK);
    134         }
    135     }
    136     else if (!PrefixNode)
    137     {
    138         /* Relative path with null prefix is disallowed */
    139 
    140         return (AE_BAD_PARAMETER);
    141     }
    142 
    143     /* Find the Node and convert to a handle */
    144 
    145     Status = AcpiNsGetNode (PrefixNode, UPathname, ACPI_NS_NO_UPSEARCH, &Node);
    146     if (ACPI_SUCCESS (Status))
    147     {
    148         *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
    149     }
    150 
    151     return (Status);
    152 }
    153 
    154 ACPI_EXPORT_SYMBOL (AcpiGetHandle)
    155 
    156 
    157 /******************************************************************************
    158  *
    159  * FUNCTION:    AcpiGetName
    160  *
    161  * PARAMETERS:  Handle          - Handle to be converted to a pathname
    162  *              NameType        - Full pathname or single segment
    163  *              Buffer          - Buffer for returned path
    164  *
    165  * RETURN:      Pointer to a string containing the fully qualified Name.
    166  *
    167  * DESCRIPTION: This routine returns the fully qualified name associated with
    168  *              the Handle parameter. This and the AcpiPathnameToHandle are
    169  *              complementary functions.
    170  *
    171  ******************************************************************************/
    172 
    173 ACPI_STATUS
    174 AcpiGetName (
    175     ACPI_HANDLE             Handle,
    176     UINT32                  NameType,
    177     ACPI_BUFFER             *Buffer)
    178 {
    179     ACPI_STATUS             Status;
    180 
    181 
    182     /* Parameter validation */
    183 
    184     if (NameType > ACPI_NAME_TYPE_MAX)
    185     {
    186         return (AE_BAD_PARAMETER);
    187     }
    188 
    189     Status = AcpiUtValidateBuffer (Buffer);
    190     if (ACPI_FAILURE (Status))
    191     {
    192         return (Status);
    193     }
    194 
    195     /*
    196      * Wants the single segment ACPI name.
    197      * Validate handle and convert to a namespace Node
    198      */
    199     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    200     if (ACPI_FAILURE (Status))
    201     {
    202         return (Status);
    203     }
    204 
    205     if (NameType == ACPI_FULL_PATHNAME ||
    206         NameType == ACPI_FULL_PATHNAME_NO_TRAILING)
    207     {
    208         /* Get the full pathname (From the namespace root) */
    209 
    210         Status = AcpiNsHandleToPathname (Handle, Buffer,
    211             NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE);
    212     }
    213     else
    214     {
    215         /* Get the single name */
    216 
    217         Status = AcpiNsHandleToName (Handle, Buffer);
    218     }
    219 
    220     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    221     return (Status);
    222 }
    223 
    224 ACPI_EXPORT_SYMBOL (AcpiGetName)
    225 
    226 
    227 /******************************************************************************
    228  *
    229  * FUNCTION:    AcpiNsCopyDeviceId
    230  *
    231  * PARAMETERS:  Dest                - Pointer to the destination PNP_DEVICE_ID
    232  *              Source              - Pointer to the source PNP_DEVICE_ID
    233  *              StringArea          - Pointer to where to copy the dest string
    234  *
    235  * RETURN:      Pointer to the next string area
    236  *
    237  * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
    238  *
    239  ******************************************************************************/
    240 
    241 static char *
    242 AcpiNsCopyDeviceId (
    243     ACPI_PNP_DEVICE_ID      *Dest,
    244     ACPI_PNP_DEVICE_ID      *Source,
    245     char                    *StringArea)
    246 {
    247     /* Create the destination PNP_DEVICE_ID */
    248 
    249     Dest->String = StringArea;
    250     Dest->Length = Source->Length;
    251 
    252     /* Copy actual string and return a pointer to the next string area */
    253 
    254     memcpy (StringArea, Source->String, Source->Length);
    255     return (StringArea + Source->Length);
    256 }
    257 
    258 
    259 /******************************************************************************
    260  *
    261  * FUNCTION:    AcpiGetObjectInfo
    262  *
    263  * PARAMETERS:  Handle              - Object Handle
    264  *              ReturnBuffer        - Where the info is returned
    265  *
    266  * RETURN:      Status
    267  *
    268  * DESCRIPTION: Returns information about an object as gleaned from the
    269  *              namespace node and possibly by running several standard
    270  *              control methods (Such as in the case of a device.)
    271  *
    272  * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
    273  * _CLS, _ADR, _SxW, and _SxD methods.
    274  *
    275  * Note: Allocates the return buffer, must be freed by the caller.
    276  *
    277  * Note: This interface is intended to be used during the initial device
    278  * discovery namespace traversal. Therefore, no complex methods can be
    279  * executed, especially those that access operation regions. Therefore, do
    280  * not add any additional methods that could cause problems in this area.
    281  * this was the fate of the _SUB method which was found to cause such
    282  * problems and was removed (11/2015).
    283  *
    284  ******************************************************************************/
    285 
    286 ACPI_STATUS
    287 AcpiGetObjectInfo (
    288     ACPI_HANDLE             Handle,
    289     ACPI_DEVICE_INFO        **ReturnBuffer)
    290 {
    291     ACPI_NAMESPACE_NODE     *Node;
    292     ACPI_DEVICE_INFO        *Info;
    293     ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;
    294     ACPI_PNP_DEVICE_ID      *Hid = NULL;
    295     ACPI_PNP_DEVICE_ID      *Uid = NULL;
    296     ACPI_PNP_DEVICE_ID      *Cls = NULL;
    297     char                    *NextIdString;
    298     ACPI_OBJECT_TYPE        Type;
    299     ACPI_NAME               Name;
    300     UINT8                   ParamCount= 0;
    301     UINT16                  Valid = 0;
    302     UINT32                  InfoSize;
    303     UINT32                  i;
    304     ACPI_STATUS             Status;
    305 
    306 
    307     /* Parameter validation */
    308 
    309     if (!Handle || !ReturnBuffer)
    310     {
    311         return (AE_BAD_PARAMETER);
    312     }
    313 
    314     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    315     if (ACPI_FAILURE (Status))
    316     {
    317         return (Status);
    318     }
    319 
    320     Node = AcpiNsValidateHandle (Handle);
    321     if (!Node)
    322     {
    323         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    324         return (AE_BAD_PARAMETER);
    325     }
    326 
    327     /* Get the namespace node data while the namespace is locked */
    328 
    329     InfoSize = sizeof (ACPI_DEVICE_INFO);
    330     Type = Node->Type;
    331     Name = Node->Name.Integer;
    332 
    333     if (Node->Type == ACPI_TYPE_METHOD)
    334     {
    335         ParamCount = Node->Object->Method.ParamCount;
    336     }
    337 
    338     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    339     if (ACPI_FAILURE (Status))
    340     {
    341         return (Status);
    342     }
    343 
    344     if ((Type == ACPI_TYPE_DEVICE) ||
    345         (Type == ACPI_TYPE_PROCESSOR))
    346     {
    347         /*
    348          * Get extra info for ACPI Device/Processor objects only:
    349          * Run the Device _HID, _UID, _CLS, and _CID methods.
    350          *
    351          * Note: none of these methods are required, so they may or may
    352          * not be present for this device. The Info->Valid bitfield is used
    353          * to indicate which methods were found and run successfully.
    354          */
    355 
    356         /* Execute the Device._HID method */
    357 
    358         Status = AcpiUtExecute_HID (Node, &Hid);
    359         if (ACPI_SUCCESS (Status))
    360         {
    361             InfoSize += Hid->Length;
    362             Valid |= ACPI_VALID_HID;
    363         }
    364 
    365         /* Execute the Device._UID method */
    366 
    367         Status = AcpiUtExecute_UID (Node, &Uid);
    368         if (ACPI_SUCCESS (Status))
    369         {
    370             InfoSize += Uid->Length;
    371             Valid |= ACPI_VALID_UID;
    372         }
    373 
    374         /* Execute the Device._CID method */
    375 
    376         Status = AcpiUtExecute_CID (Node, &CidList);
    377         if (ACPI_SUCCESS (Status))
    378         {
    379             /* Add size of CID strings and CID pointer array */
    380 
    381             InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));
    382             Valid |= ACPI_VALID_CID;
    383         }
    384 
    385         /* Execute the Device._CLS method */
    386 
    387         Status = AcpiUtExecute_CLS (Node, &Cls);
    388         if (ACPI_SUCCESS (Status))
    389         {
    390             InfoSize += Cls->Length;
    391             Valid |= ACPI_VALID_CLS;
    392         }
    393     }
    394 
    395     /*
    396      * Now that we have the variable-length data, we can allocate the
    397      * return buffer
    398      */
    399     Info = ACPI_ALLOCATE_ZEROED (InfoSize);
    400     if (!Info)
    401     {
    402         Status = AE_NO_MEMORY;
    403         goto Cleanup;
    404     }
    405 
    406     /* Get the fixed-length data */
    407 
    408     if ((Type == ACPI_TYPE_DEVICE) ||
    409         (Type == ACPI_TYPE_PROCESSOR))
    410     {
    411         /*
    412          * Get extra info for ACPI Device/Processor objects only:
    413          * Run the _STA, _ADR and, SxW, and _SxD methods.
    414          *
    415          * Notes: none of these methods are required, so they may or may
    416          * not be present for this device. The Info->Valid bitfield is used
    417          * to indicate which methods were found and run successfully.
    418          *
    419          * For _STA, if the method does not exist, then (as per the ACPI
    420          * specification), the returned CurrentStatus flags will indicate
    421          * that the device is present/functional/enabled. Otherwise, the
    422          * CurrentStatus flags reflect the value returned from _STA.
    423          */
    424 
    425         /* Execute the Device._STA method */
    426 
    427         Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
    428         if (ACPI_SUCCESS (Status))
    429         {
    430             Valid |= ACPI_VALID_STA;
    431         }
    432 
    433         /* Execute the Device._ADR method */
    434 
    435         Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
    436             &Info->Address);
    437         if (ACPI_SUCCESS (Status))
    438         {
    439             Valid |= ACPI_VALID_ADR;
    440         }
    441 
    442         /* Execute the Device._SxW methods */
    443 
    444         Status = AcpiUtExecutePowerMethods (Node,
    445             AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
    446             Info->LowestDstates);
    447         if (ACPI_SUCCESS (Status))
    448         {
    449             Valid |= ACPI_VALID_SXWS;
    450         }
    451 
    452         /* Execute the Device._SxD methods */
    453 
    454         Status = AcpiUtExecutePowerMethods (Node,
    455             AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
    456             Info->HighestDstates);
    457         if (ACPI_SUCCESS (Status))
    458         {
    459             Valid |= ACPI_VALID_SXDS;
    460         }
    461     }
    462 
    463     /*
    464      * Create a pointer to the string area of the return buffer.
    465      * Point to the end of the base ACPI_DEVICE_INFO structure.
    466      */
    467     NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
    468     if (CidList)
    469     {
    470         /* Point past the CID PNP_DEVICE_ID array */
    471 
    472         NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));
    473     }
    474 
    475     /*
    476      * Copy the HID, UID, and CIDs to the return buffer. The variable-length
    477      * strings are copied to the reserved area at the end of the buffer.
    478      *
    479      * For HID and CID, check if the ID is a PCI Root Bridge.
    480      */
    481     if (Hid)
    482     {
    483         NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
    484             Hid, NextIdString);
    485 
    486         if (AcpiUtIsPciRootBridge (Hid->String))
    487         {
    488             Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
    489         }
    490     }
    491 
    492     if (Uid)
    493     {
    494         NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
    495             Uid, NextIdString);
    496     }
    497 
    498     if (CidList)
    499     {
    500         Info->CompatibleIdList.Count = CidList->Count;
    501         Info->CompatibleIdList.ListSize = CidList->ListSize;
    502 
    503         /* Copy each CID */
    504 
    505         for (i = 0; i < CidList->Count; i++)
    506         {
    507             NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
    508                 &CidList->Ids[i], NextIdString);
    509 
    510             if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
    511             {
    512                 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
    513             }
    514         }
    515     }
    516 
    517     if (Cls)
    518     {
    519         NextIdString = AcpiNsCopyDeviceId (&Info->ClassCode,
    520             Cls, NextIdString);
    521     }
    522 
    523     /* Copy the fixed-length data */
    524 
    525     Info->InfoSize = InfoSize;
    526     Info->Type = Type;
    527     Info->Name = Name;
    528     Info->ParamCount = ParamCount;
    529     Info->Valid = Valid;
    530 
    531     *ReturnBuffer = Info;
    532     Status = AE_OK;
    533 
    534 
    535 Cleanup:
    536     if (Hid)
    537     {
    538         ACPI_FREE (Hid);
    539     }
    540     if (Uid)
    541     {
    542         ACPI_FREE (Uid);
    543     }
    544     if (CidList)
    545     {
    546         ACPI_FREE (CidList);
    547     }
    548     if (Cls)
    549     {
    550         ACPI_FREE (Cls);
    551     }
    552     return (Status);
    553 }
    554 
    555 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
    556 
    557 
    558 /******************************************************************************
    559  *
    560  * FUNCTION:    AcpiInstallMethod
    561  *
    562  * PARAMETERS:  Buffer         - An ACPI table containing one control method
    563  *
    564  * RETURN:      Status
    565  *
    566  * DESCRIPTION: Install a control method into the namespace. If the method
    567  *              name already exists in the namespace, it is overwritten. The
    568  *              input buffer must contain a valid DSDT or SSDT containing a
    569  *              single control method.
    570  *
    571  ******************************************************************************/
    572 
    573 ACPI_STATUS
    574 AcpiInstallMethod (
    575     UINT8                   *Buffer)
    576 {
    577     ACPI_TABLE_HEADER       *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
    578     UINT8                   *AmlBuffer;
    579     UINT8                   *AmlStart;
    580     char                    *Path;
    581     ACPI_NAMESPACE_NODE     *Node;
    582     ACPI_OPERAND_OBJECT     *MethodObj;
    583     ACPI_PARSE_STATE        ParserState;
    584     UINT32                  AmlLength;
    585     UINT16                  Opcode;
    586     UINT8                   MethodFlags;
    587     ACPI_STATUS             Status;
    588 
    589 
    590     /* Parameter validation */
    591 
    592     if (!Buffer)
    593     {
    594         return (AE_BAD_PARAMETER);
    595     }
    596 
    597     /* Table must be a DSDT or SSDT */
    598 
    599     if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
    600         !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
    601     {
    602         return (AE_BAD_HEADER);
    603     }
    604 
    605     /* First AML opcode in the table must be a control method */
    606 
    607     ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
    608     Opcode = AcpiPsPeekOpcode (&ParserState);
    609     if (Opcode != AML_METHOD_OP)
    610     {
    611         return (AE_BAD_PARAMETER);
    612     }
    613 
    614     /* Extract method information from the raw AML */
    615 
    616     ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
    617     ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
    618     Path = AcpiPsGetNextNamestring (&ParserState);
    619 
    620     MethodFlags = *ParserState.Aml++;
    621     AmlStart = ParserState.Aml;
    622     AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
    623 
    624     /*
    625      * Allocate resources up-front. We don't want to have to delete a new
    626      * node from the namespace if we cannot allocate memory.
    627      */
    628     AmlBuffer = ACPI_ALLOCATE (AmlLength);
    629     if (!AmlBuffer)
    630     {
    631         return (AE_NO_MEMORY);
    632     }
    633 
    634     MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
    635     if (!MethodObj)
    636     {
    637         ACPI_FREE (AmlBuffer);
    638         return (AE_NO_MEMORY);
    639     }
    640 
    641     /* Lock namespace for AcpiNsLookup, we may be creating a new node */
    642 
    643     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    644     if (ACPI_FAILURE (Status))
    645     {
    646         goto ErrorExit;
    647     }
    648 
    649     /* The lookup either returns an existing node or creates a new one */
    650 
    651     Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
    652         ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
    653 
    654     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    655 
    656     if (ACPI_FAILURE (Status)) /* NsLookup */
    657     {
    658         if (Status != AE_ALREADY_EXISTS)
    659         {
    660             goto ErrorExit;
    661         }
    662 
    663         /* Node existed previously, make sure it is a method node */
    664 
    665         if (Node->Type != ACPI_TYPE_METHOD)
    666         {
    667             Status = AE_TYPE;
    668             goto ErrorExit;
    669         }
    670     }
    671 
    672     /* Copy the method AML to the local buffer */
    673 
    674     memcpy (AmlBuffer, AmlStart, AmlLength);
    675 
    676     /* Initialize the method object with the new method's information */
    677 
    678     MethodObj->Method.AmlStart = AmlBuffer;
    679     MethodObj->Method.AmlLength = AmlLength;
    680 
    681     MethodObj->Method.ParamCount = (UINT8)
    682         (MethodFlags & AML_METHOD_ARG_COUNT);
    683 
    684     if (MethodFlags & AML_METHOD_SERIALIZED)
    685     {
    686         MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
    687 
    688         MethodObj->Method.SyncLevel = (UINT8)
    689             ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
    690     }
    691 
    692     /*
    693      * Now that it is complete, we can attach the new method object to
    694      * the method Node (detaches/deletes any existing object)
    695      */
    696     Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);
    697 
    698     /*
    699      * Flag indicates AML buffer is dynamic, must be deleted later.
    700      * Must be set only after attach above.
    701      */
    702     Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
    703 
    704     /* Remove local reference to the method object */
    705 
    706     AcpiUtRemoveReference (MethodObj);
    707     return (Status);
    708 
    709 
    710 ErrorExit:
    711 
    712     ACPI_FREE (AmlBuffer);
    713     ACPI_FREE (MethodObj);
    714     return (Status);
    715 }
    716 
    717 ACPI_EXPORT_SYMBOL (AcpiInstallMethod)
    718