Path: blob/main/sys/contrib/dev/acpica/components/namespace/nsxfname.c
48524 views
/******************************************************************************1*2* Module Name: nsxfname - Public interfaces to the ACPI subsystem3* ACPI Namespace oriented interfaces4*5*****************************************************************************/67/******************************************************************************8*9* 1. Copyright Notice10*11* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.12* All rights reserved.13*14* 2. License15*16* 2.1. This is your license from Intel Corp. under its intellectual property17* rights. You may have additional license terms from the party that provided18* you this software, covering your right to use that party's intellectual19* property rights.20*21* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a22* copy of the source code appearing in this file ("Covered Code") an23* irrevocable, perpetual, worldwide license under Intel's copyrights in the24* base code distributed originally by Intel ("Original Intel Code") to copy,25* make derivatives, distribute, use and display any portion of the Covered26* Code in any form, with the right to sublicense such rights; and27*28* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent29* license (with the right to sublicense), under only those claims of Intel30* patents that are infringed by the Original Intel Code, to make, use, sell,31* offer to sell, and import the Covered Code and derivative works thereof32* solely to the minimum extent necessary to exercise the above copyright33* license, and in no event shall the patent license extend to any additions34* to or modifications of the Original Intel Code. No other license or right35* is granted directly or by implication, estoppel or otherwise;36*37* The above copyright and patent license is granted only if the following38* conditions are met:39*40* 3. Conditions41*42* 3.1. Redistribution of Source with Rights to Further Distribute Source.43* Redistribution of source code of any substantial portion of the Covered44* Code or modification with rights to further distribute source must include45* the above Copyright Notice, the above License, this list of Conditions,46* and the following Disclaimer and Export Compliance provision. In addition,47* Licensee must cause all Covered Code to which Licensee contributes to48* contain a file documenting the changes Licensee made to create that Covered49* Code and the date of any change. Licensee must include in that file the50* documentation of any changes made by any predecessor Licensee. Licensee51* must include a prominent statement that the modification is derived,52* directly or indirectly, from Original Intel Code.53*54* 3.2. Redistribution of Source with no Rights to Further Distribute Source.55* Redistribution of source code of any substantial portion of the Covered56* Code or modification without rights to further distribute source must57* include the following Disclaimer and Export Compliance provision in the58* documentation and/or other materials provided with distribution. In59* addition, Licensee may not authorize further sublicense of source of any60* portion of the Covered Code, and must include terms to the effect that the61* license from Licensee to its licensee is limited to the intellectual62* property embodied in the software Licensee provides to its licensee, and63* not to intellectual property embodied in modifications its licensee may64* make.65*66* 3.3. Redistribution of Executable. Redistribution in executable form of any67* substantial portion of the Covered Code or modification must reproduce the68* above Copyright Notice, and the following Disclaimer and Export Compliance69* provision in the documentation and/or other materials provided with the70* distribution.71*72* 3.4. Intel retains all right, title, and interest in and to the Original73* Intel Code.74*75* 3.5. Neither the name Intel nor any other trademark owned or controlled by76* Intel shall be used in advertising or otherwise to promote the sale, use or77* other dealings in products derived from or relating to the Covered Code78* without prior written authorization from Intel.79*80* 4. Disclaimer and Export Compliance81*82* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED83* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE84* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,85* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY86* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY87* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A88* PARTICULAR PURPOSE.89*90* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES91* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR92* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,93* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY94* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL95* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS96* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY97* LIMITED REMEDY.98*99* 4.3. Licensee shall not export, either directly or indirectly, any of this100* software or system incorporating such software without first obtaining any101* required license or other approval from the U. S. Department of Commerce or102* any other agency or department of the United States Government. In the103* event Licensee exports any such software from the United States or104* re-exports any such software from a foreign destination, Licensee shall105* ensure that the distribution and export/re-export of the software is in106* compliance with all laws, regulations, orders, or other restrictions of the107* U.S. Export Administration Regulations. Licensee agrees that neither it nor108* any of its subsidiaries will export/re-export any technical data, process,109* software, or service, directly or indirectly, to any country for which the110* United States government or any agency thereof requires an export license,111* other governmental approval, or letter of assurance, without first obtaining112* such license, approval or letter.113*114*****************************************************************************115*116* Alternatively, you may choose to be licensed under the terms of the117* following license:118*119* Redistribution and use in source and binary forms, with or without120* modification, are permitted provided that the following conditions121* are met:122* 1. Redistributions of source code must retain the above copyright123* notice, this list of conditions, and the following disclaimer,124* without modification.125* 2. Redistributions in binary form must reproduce at minimum a disclaimer126* substantially similar to the "NO WARRANTY" disclaimer below127* ("Disclaimer") and any redistribution must be conditioned upon128* including a substantially similar Disclaimer requirement for further129* binary redistribution.130* 3. Neither the names of the above-listed copyright holders nor the names131* of any contributors may be used to endorse or promote products derived132* from this software without specific prior written permission.133*134* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS135* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT136* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR137* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT138* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,139* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT140* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,141* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY142* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT143* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE144* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.145*146* Alternatively, you may choose to be licensed under the terms of the147* GNU General Public License ("GPL") version 2 as published by the Free148* Software Foundation.149*150*****************************************************************************/151152#define EXPORT_ACPI_INTERFACES153154#include <contrib/dev/acpica/include/acpi.h>155#include <contrib/dev/acpica/include/accommon.h>156#include <contrib/dev/acpica/include/acnamesp.h>157#include <contrib/dev/acpica/include/acparser.h>158#include <contrib/dev/acpica/include/amlcode.h>159160161#define _COMPONENT ACPI_NAMESPACE162ACPI_MODULE_NAME ("nsxfname")163164/* Local prototypes */165166static char *167AcpiNsCopyDeviceId (168ACPI_PNP_DEVICE_ID *Dest,169ACPI_PNP_DEVICE_ID *Source,170char *StringArea);171172173/******************************************************************************174*175* FUNCTION: AcpiGetHandle176*177* PARAMETERS: Parent - Object to search under (search scope).178* Pathname - Pointer to an asciiz string containing the179* name180* RetHandle - Where the return handle is returned181*182* RETURN: Status183*184* DESCRIPTION: This routine will search for a caller specified name in the185* name space. The caller can restrict the search region by186* specifying a non NULL parent. The parent value is itself a187* namespace handle.188*189******************************************************************************/190191ACPI_STATUS192AcpiGetHandle (193ACPI_HANDLE Parent,194const char *Pathname,195ACPI_HANDLE *RetHandle)196{197ACPI_STATUS Status;198ACPI_NAMESPACE_NODE *Node = NULL;199ACPI_NAMESPACE_NODE *PrefixNode = NULL;200201202ACPI_FUNCTION_ENTRY ();203204205/* Parameter Validation */206207if (!RetHandle || !Pathname)208{209return (AE_BAD_PARAMETER);210}211212/* Convert a parent handle to a prefix node */213214if (Parent)215{216PrefixNode = AcpiNsValidateHandle (Parent);217if (!PrefixNode)218{219return (AE_BAD_PARAMETER);220}221}222223/*224* Valid cases are:225* 1) Fully qualified pathname226* 2) Parent + Relative pathname227*228* Error for <null Parent + relative path>229*/230if (ACPI_IS_ROOT_PREFIX (Pathname[0]))231{232/* Pathname is fully qualified (starts with '\') */233234/* Special case for root-only, since we can't search for it */235236if (!strcmp (Pathname, ACPI_NS_ROOT_PATH))237{238*RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);239return (AE_OK);240}241}242else if (!PrefixNode)243{244/* Relative path with null prefix is disallowed */245246return (AE_BAD_PARAMETER);247}248249/* Find the Node and convert to a handle */250251Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);252if (ACPI_SUCCESS (Status))253{254*RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);255}256257return (Status);258}259260ACPI_EXPORT_SYMBOL (AcpiGetHandle)261262263/******************************************************************************264*265* FUNCTION: AcpiGetName266*267* PARAMETERS: Handle - Handle to be converted to a pathname268* NameType - Full pathname or single segment269* Buffer - Buffer for returned path270*271* RETURN: Pointer to a string containing the fully qualified Name.272*273* DESCRIPTION: This routine returns the fully qualified name associated with274* the Handle parameter. This and the AcpiPathnameToHandle are275* complementary functions.276*277******************************************************************************/278279ACPI_STATUS280AcpiGetName (281ACPI_HANDLE Handle,282UINT32 NameType,283ACPI_BUFFER *Buffer)284{285ACPI_STATUS Status;286287288/* Parameter validation */289290if (NameType > ACPI_NAME_TYPE_MAX)291{292return (AE_BAD_PARAMETER);293}294295Status = AcpiUtValidateBuffer (Buffer);296if (ACPI_FAILURE (Status))297{298return (Status);299}300301/*302* Wants the single segment ACPI name.303* Validate handle and convert to a namespace Node304*/305Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);306if (ACPI_FAILURE (Status))307{308return (Status);309}310311if (NameType == ACPI_FULL_PATHNAME ||312NameType == ACPI_FULL_PATHNAME_NO_TRAILING)313{314/* Get the full pathname (From the namespace root) */315316Status = AcpiNsHandleToPathname (Handle, Buffer,317NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE);318}319else320{321/* Get the single name */322323Status = AcpiNsHandleToName (Handle, Buffer);324}325326(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);327return (Status);328}329330ACPI_EXPORT_SYMBOL (AcpiGetName)331332333/******************************************************************************334*335* FUNCTION: AcpiNsCopyDeviceId336*337* PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID338* Source - Pointer to the source PNP_DEVICE_ID339* StringArea - Pointer to where to copy the dest string340*341* RETURN: Pointer to the next string area342*343* DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.344*345******************************************************************************/346347static char *348AcpiNsCopyDeviceId (349ACPI_PNP_DEVICE_ID *Dest,350ACPI_PNP_DEVICE_ID *Source,351char *StringArea)352{353/* Create the destination PNP_DEVICE_ID */354355Dest->String = StringArea;356Dest->Length = Source->Length;357358/* Copy actual string and return a pointer to the next string area */359360memcpy (StringArea, Source->String, Source->Length);361return (StringArea + Source->Length);362}363364365/******************************************************************************366*367* FUNCTION: AcpiGetObjectInfo368*369* PARAMETERS: Handle - Object Handle370* ReturnBuffer - Where the info is returned371*372* RETURN: Status373*374* DESCRIPTION: Returns information about an object as gleaned from the375* namespace node and possibly by running several standard376* control methods (Such as in the case of a device.)377*378* For Device and Processor objects, run the Device _HID, _UID, _CID,379* _CLS, _ADR, _SxW, and _SxD methods.380*381* Note: Allocates the return buffer, must be freed by the caller.382*383* Note: This interface is intended to be used during the initial device384* discovery namespace traversal. Therefore, no complex methods can be385* executed, especially those that access operation regions. Therefore, do386* not add any additional methods that could cause problems in this area.387* Because of this reason support for the following methods has been removed:388* 1) _SUB method was removed (11/2015)389* 2) _STA method was removed (02/2018)390*391******************************************************************************/392393ACPI_STATUS394AcpiGetObjectInfo (395ACPI_HANDLE Handle,396ACPI_DEVICE_INFO **ReturnBuffer)397{398ACPI_NAMESPACE_NODE *Node;399ACPI_DEVICE_INFO *Info;400ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;401ACPI_PNP_DEVICE_ID *Hid = NULL;402ACPI_PNP_DEVICE_ID *Uid = NULL;403ACPI_PNP_DEVICE_ID *Cls = NULL;404char *NextIdString;405ACPI_OBJECT_TYPE Type;406ACPI_NAME Name;407UINT8 ParamCount= 0;408UINT16 Valid = 0;409UINT32 InfoSize;410UINT32 i;411ACPI_STATUS Status;412413414/* Parameter validation */415416if (!Handle || !ReturnBuffer)417{418return (AE_BAD_PARAMETER);419}420421Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);422if (ACPI_FAILURE (Status))423{424return (Status);425}426427Node = AcpiNsValidateHandle (Handle);428if (!Node)429{430(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);431return (AE_BAD_PARAMETER);432}433434/* Get the namespace node data while the namespace is locked */435436InfoSize = sizeof (ACPI_DEVICE_INFO);437Type = Node->Type;438Name = Node->Name.Integer;439440if (Node->Type == ACPI_TYPE_METHOD)441{442ParamCount = Node->Object->Method.ParamCount;443}444445Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);446if (ACPI_FAILURE (Status))447{448return (Status);449}450451if ((Type == ACPI_TYPE_DEVICE) ||452(Type == ACPI_TYPE_PROCESSOR))453{454/*455* Get extra info for ACPI Device/Processor objects only:456* Run the Device _HID, _UID, _CLS, and _CID methods.457*458* Note: none of these methods are required, so they may or may459* not be present for this device. The Info->Valid bitfield is used460* to indicate which methods were found and run successfully.461*/462463/* Execute the Device._HID method */464465Status = AcpiUtExecute_HID (Node, &Hid);466if (ACPI_SUCCESS (Status))467{468InfoSize += Hid->Length;469Valid |= ACPI_VALID_HID;470}471472/* Execute the Device._UID method */473474Status = AcpiUtExecute_UID (Node, &Uid);475if (ACPI_SUCCESS (Status))476{477InfoSize += Uid->Length;478Valid |= ACPI_VALID_UID;479}480481/* Execute the Device._CID method */482483Status = AcpiUtExecute_CID (Node, &CidList);484if (ACPI_SUCCESS (Status))485{486/* Add size of CID strings and CID pointer array */487488InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));489Valid |= ACPI_VALID_CID;490}491492/* Execute the Device._CLS method */493494Status = AcpiUtExecute_CLS (Node, &Cls);495if (ACPI_SUCCESS (Status))496{497InfoSize += Cls->Length;498Valid |= ACPI_VALID_CLS;499}500}501502/*503* Now that we have the variable-length data, we can allocate the504* return buffer505*/506Info = ACPI_ALLOCATE_ZEROED (InfoSize);507if (!Info)508{509Status = AE_NO_MEMORY;510goto Cleanup;511}512513/* Get the fixed-length data */514515if ((Type == ACPI_TYPE_DEVICE) ||516(Type == ACPI_TYPE_PROCESSOR))517{518/*519* Get extra info for ACPI Device/Processor objects only:520* Run the _ADR and, SxW, and _SxD methods.521*522* Notes: none of these methods are required, so they may or may523* not be present for this device. The Info->Valid bitfield is used524* to indicate which methods were found and run successfully.525*/526527/* Execute the Device._ADR method */528529Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,530&Info->Address);531if (ACPI_SUCCESS (Status))532{533Valid |= ACPI_VALID_ADR;534}535536/* Execute the Device._SxW methods */537538Status = AcpiUtExecutePowerMethods (Node,539AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,540Info->LowestDstates);541if (ACPI_SUCCESS (Status))542{543Valid |= ACPI_VALID_SXWS;544}545546/* Execute the Device._SxD methods */547548Status = AcpiUtExecutePowerMethods (Node,549AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,550Info->HighestDstates);551if (ACPI_SUCCESS (Status))552{553Valid |= ACPI_VALID_SXDS;554}555}556557/*558* Create a pointer to the string area of the return buffer.559* Point to the end of the base ACPI_DEVICE_INFO structure.560*/561NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);562if (CidList)563{564/* Point past the CID PNP_DEVICE_ID array */565566NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));567}568569/*570* Copy the HID, UID, and CIDs to the return buffer. The variable-length571* strings are copied to the reserved area at the end of the buffer.572*573* For HID and CID, check if the ID is a PCI Root Bridge.574*/575if (Hid)576{577NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,578Hid, NextIdString);579580if (AcpiUtIsPciRootBridge (Hid->String))581{582Info->Flags |= ACPI_PCI_ROOT_BRIDGE;583}584}585586if (Uid)587{588NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,589Uid, NextIdString);590}591592if (CidList)593{594Info->CompatibleIdList.Count = CidList->Count;595Info->CompatibleIdList.ListSize = CidList->ListSize;596597/* Copy each CID */598599for (i = 0; i < CidList->Count; i++)600{601NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],602&CidList->Ids[i], NextIdString);603604if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))605{606Info->Flags |= ACPI_PCI_ROOT_BRIDGE;607}608}609}610611if (Cls)612{613(void) AcpiNsCopyDeviceId (&Info->ClassCode,614Cls, NextIdString);615}616617/* Copy the fixed-length data */618619Info->InfoSize = InfoSize;620Info->Type = Type;621Info->Name = Name;622Info->ParamCount = ParamCount;623Info->Valid = Valid;624625*ReturnBuffer = Info;626Status = AE_OK;627628629Cleanup:630if (Hid)631{632ACPI_FREE (Hid);633}634if (Uid)635{636ACPI_FREE (Uid);637}638if (CidList)639{640ACPI_FREE (CidList);641}642if (Cls)643{644ACPI_FREE (Cls);645}646return (Status);647}648649ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)650651652/******************************************************************************653*654* FUNCTION: AcpiInstallMethod655*656* PARAMETERS: Buffer - An ACPI table containing one control method657*658* RETURN: Status659*660* DESCRIPTION: Install a control method into the namespace. If the method661* name already exists in the namespace, it is overwritten. The662* input buffer must contain a valid DSDT or SSDT containing a663* single control method.664*665******************************************************************************/666667ACPI_STATUS668AcpiInstallMethod (669UINT8 *Buffer)670{671ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);672UINT8 *AmlBuffer;673UINT8 *AmlStart;674char *Path;675ACPI_NAMESPACE_NODE *Node;676ACPI_OPERAND_OBJECT *MethodObj;677ACPI_PARSE_STATE ParserState;678UINT32 AmlLength;679UINT16 Opcode;680UINT8 MethodFlags;681ACPI_STATUS Status;682683684/* Parameter validation */685686if (!Buffer)687{688return (AE_BAD_PARAMETER);689}690691/* Table must be a DSDT or SSDT */692693if (!ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_DSDT) &&694!ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_SSDT))695{696return (AE_BAD_HEADER);697}698699/* First AML opcode in the table must be a control method */700701ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);702Opcode = AcpiPsPeekOpcode (&ParserState);703if (Opcode != AML_METHOD_OP)704{705return (AE_BAD_PARAMETER);706}707708/* Extract method information from the raw AML */709710ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);711ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);712Path = AcpiPsGetNextNamestring (&ParserState);713714MethodFlags = *ParserState.Aml++;715AmlStart = ParserState.Aml;716AmlLength = (UINT32) ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);717718/*719* Allocate resources up-front. We don't want to have to delete a new720* node from the namespace if we cannot allocate memory.721*/722AmlBuffer = ACPI_ALLOCATE (AmlLength);723if (!AmlBuffer)724{725return (AE_NO_MEMORY);726}727728MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);729if (!MethodObj)730{731ACPI_FREE (AmlBuffer);732return (AE_NO_MEMORY);733}734735/* Lock namespace for AcpiNsLookup, we may be creating a new node */736737Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);738if (ACPI_FAILURE (Status))739{740goto ErrorExit;741}742743/* The lookup either returns an existing node or creates a new one */744745Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,746ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);747748(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);749750if (ACPI_FAILURE (Status)) /* NsLookup */751{752if (Status != AE_ALREADY_EXISTS)753{754goto ErrorExit;755}756757/* Node existed previously, make sure it is a method node */758759if (Node->Type != ACPI_TYPE_METHOD)760{761Status = AE_TYPE;762goto ErrorExit;763}764}765766/* Copy the method AML to the local buffer */767768memcpy (AmlBuffer, AmlStart, AmlLength);769770/* Initialize the method object with the new method's information */771772MethodObj->Method.AmlStart = AmlBuffer;773MethodObj->Method.AmlLength = AmlLength;774775MethodObj->Method.ParamCount = (UINT8)776(MethodFlags & AML_METHOD_ARG_COUNT);777778if (MethodFlags & AML_METHOD_SERIALIZED)779{780MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;781782MethodObj->Method.SyncLevel = (UINT8)783((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);784}785786/*787* Now that it is complete, we can attach the new method object to788* the method Node (detaches/deletes any existing object)789*/790Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);791792/*793* Flag indicates AML buffer is dynamic, must be deleted later.794* Must be set only after attach above.795*/796Node->Flags |= ANOBJ_ALLOCATED_BUFFER;797798/* Remove local reference to the method object */799800AcpiUtRemoveReference (MethodObj);801return (Status);802803804ErrorExit:805806ACPI_FREE (AmlBuffer);807ACPI_FREE (MethodObj);808return (Status);809}810811ACPI_EXPORT_SYMBOL (AcpiInstallMethod)812813814