ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

nsxfname.c
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Module Name: nsxfname - Public interfaces to the ACPI subsystem
00004  *                         ACPI Namespace oriented interfaces
00005  *
00006  *****************************************************************************/
00007 
00008 /******************************************************************************
00009  *
00010  * 1. Copyright Notice
00011  *
00012  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00013  * All rights reserved.
00014  *
00015  * 2. License
00016  *
00017  * 2.1. This is your license from Intel Corp. under its intellectual property
00018  * rights.  You may have additional license terms from the party that provided
00019  * you this software, covering your right to use that party's intellectual
00020  * property rights.
00021  *
00022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00023  * copy of the source code appearing in this file ("Covered Code") an
00024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00025  * base code distributed originally by Intel ("Original Intel Code") to copy,
00026  * make derivatives, distribute, use and display any portion of the Covered
00027  * Code in any form, with the right to sublicense such rights; and
00028  *
00029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00030  * license (with the right to sublicense), under only those claims of Intel
00031  * patents that are infringed by the Original Intel Code, to make, use, sell,
00032  * offer to sell, and import the Covered Code and derivative works thereof
00033  * solely to the minimum extent necessary to exercise the above copyright
00034  * license, and in no event shall the patent license extend to any additions
00035  * to or modifications of the Original Intel Code.  No other license or right
00036  * is granted directly or by implication, estoppel or otherwise;
00037  *
00038  * The above copyright and patent license is granted only if the following
00039  * conditions are met:
00040  *
00041  * 3. Conditions
00042  *
00043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00044  * Redistribution of source code of any substantial portion of the Covered
00045  * Code or modification with rights to further distribute source must include
00046  * the above Copyright Notice, the above License, this list of Conditions,
00047  * and the following Disclaimer and Export Compliance provision.  In addition,
00048  * Licensee must cause all Covered Code to which Licensee contributes to
00049  * contain a file documenting the changes Licensee made to create that Covered
00050  * Code and the date of any change.  Licensee must include in that file the
00051  * documentation of any changes made by any predecessor Licensee.  Licensee
00052  * must include a prominent statement that the modification is derived,
00053  * directly or indirectly, from Original Intel Code.
00054  *
00055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00056  * Redistribution of source code of any substantial portion of the Covered
00057  * Code or modification without rights to further distribute source must
00058  * include the following Disclaimer and Export Compliance provision in the
00059  * documentation and/or other materials provided with distribution.  In
00060  * addition, Licensee may not authorize further sublicense of source of any
00061  * portion of the Covered Code, and must include terms to the effect that the
00062  * license from Licensee to its licensee is limited to the intellectual
00063  * property embodied in the software Licensee provides to its licensee, and
00064  * not to intellectual property embodied in modifications its licensee may
00065  * make.
00066  *
00067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00068  * substantial portion of the Covered Code or modification must reproduce the
00069  * above Copyright Notice, and the following Disclaimer and Export Compliance
00070  * provision in the documentation and/or other materials provided with the
00071  * distribution.
00072  *
00073  * 3.4. Intel retains all right, title, and interest in and to the Original
00074  * Intel Code.
00075  *
00076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00077  * Intel shall be used in advertising or otherwise to promote the sale, use or
00078  * other dealings in products derived from or relating to the Covered Code
00079  * without prior written authorization from Intel.
00080  *
00081  * 4. Disclaimer and Export Compliance
00082  *
00083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00084  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00086  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00087  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00089  * PARTICULAR PURPOSE.
00090  *
00091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00098  * LIMITED REMEDY.
00099  *
00100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00101  * software or system incorporating such software without first obtaining any
00102  * required license or other approval from the U. S. Department of Commerce or
00103  * any other agency or department of the United States Government.  In the
00104  * event Licensee exports any such software from the United States or
00105  * re-exports any such software from a foreign destination, Licensee shall
00106  * ensure that the distribution and export/re-export of the software is in
00107  * compliance with all laws, regulations, orders, or other restrictions of the
00108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00109  * any of its subsidiaries will export/re-export any technical data, process,
00110  * software, or service, directly or indirectly, to any country for which the
00111  * United States government or any agency thereof requires an export license,
00112  * other governmental approval, or letter of assurance, without first obtaining
00113  * such license, approval or letter.
00114  *
00115  *****************************************************************************/
00116 
00117 #define __NSXFNAME_C__
00118 
00119 #include "acpi.h"
00120 #include "accommon.h"
00121 #include "acnamesp.h"
00122 #include "acparser.h"
00123 #include "amlcode.h"
00124 
00125 
00126 #define _COMPONENT          ACPI_NAMESPACE
00127         ACPI_MODULE_NAME    ("nsxfname")
00128 
00129 /* Local prototypes */
00130 
00131 static char *
00132 AcpiNsCopyDeviceId (
00133     ACPI_DEVICE_ID          *Dest,
00134     ACPI_DEVICE_ID          *Source,
00135     char                    *StringArea);
00136 
00137 
00138 /******************************************************************************
00139  *
00140  * FUNCTION:    AcpiGetHandle
00141  *
00142  * PARAMETERS:  Parent          - Object to search under (search scope).
00143  *              Pathname        - Pointer to an asciiz string containing the
00144  *                                name
00145  *              RetHandle       - Where the return handle is returned
00146  *
00147  * RETURN:      Status
00148  *
00149  * DESCRIPTION: This routine will search for a caller specified name in the
00150  *              name space.  The caller can restrict the search region by
00151  *              specifying a non NULL parent.  The parent value is itself a
00152  *              namespace handle.
00153  *
00154  ******************************************************************************/
00155 
00156 ACPI_STATUS
00157 AcpiGetHandle (
00158     ACPI_HANDLE             Parent,
00159     ACPI_STRING             Pathname,
00160     ACPI_HANDLE             *RetHandle)
00161 {
00162     ACPI_STATUS             Status;
00163     ACPI_NAMESPACE_NODE     *Node = NULL;
00164     ACPI_NAMESPACE_NODE     *PrefixNode = NULL;
00165 
00166 
00167     ACPI_FUNCTION_ENTRY ();
00168 
00169 
00170     /* Parameter Validation */
00171 
00172     if (!RetHandle || !Pathname)
00173     {
00174         return (AE_BAD_PARAMETER);
00175     }
00176 
00177     /* Convert a parent handle to a prefix node */
00178 
00179     if (Parent)
00180     {
00181         PrefixNode = AcpiNsValidateHandle (Parent);
00182         if (!PrefixNode)
00183         {
00184             return (AE_BAD_PARAMETER);
00185         }
00186     }
00187 
00188     /*
00189      * Valid cases are:
00190      * 1) Fully qualified pathname
00191      * 2) Parent + Relative pathname
00192      *
00193      * Error for <null Parent + relative path>
00194      */
00195     if (AcpiNsValidRootPrefix (Pathname[0]))
00196     {
00197         /* Pathname is fully qualified (starts with '\') */
00198 
00199         /* Special case for root-only, since we can't search for it */
00200 
00201         if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
00202         {
00203             *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
00204             return (AE_OK);
00205         }
00206     }
00207     else if (!PrefixNode)
00208     {
00209         /* Relative path with null prefix is disallowed */
00210 
00211         return (AE_BAD_PARAMETER);
00212     }
00213 
00214     /* Find the Node and convert to a handle */
00215 
00216     Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
00217     if (ACPI_SUCCESS (Status))
00218     {
00219         *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
00220     }
00221 
00222     return (Status);
00223 }
00224 
00225 ACPI_EXPORT_SYMBOL (AcpiGetHandle)
00226 
00227 
00228 /******************************************************************************
00229  *
00230  * FUNCTION:    AcpiGetName
00231  *
00232  * PARAMETERS:  Handle          - Handle to be converted to a pathname
00233  *              NameType        - Full pathname or single segment
00234  *              Buffer          - Buffer for returned path
00235  *
00236  * RETURN:      Pointer to a string containing the fully qualified Name.
00237  *
00238  * DESCRIPTION: This routine returns the fully qualified name associated with
00239  *              the Handle parameter.  This and the AcpiPathnameToHandle are
00240  *              complementary functions.
00241  *
00242  ******************************************************************************/
00243 
00244 ACPI_STATUS
00245 AcpiGetName (
00246     ACPI_HANDLE             Handle,
00247     UINT32                  NameType,
00248     ACPI_BUFFER             *Buffer)
00249 {
00250     ACPI_STATUS             Status;
00251     ACPI_NAMESPACE_NODE     *Node;
00252 
00253 
00254     /* Parameter validation */
00255 
00256     if (NameType > ACPI_NAME_TYPE_MAX)
00257     {
00258         return (AE_BAD_PARAMETER);
00259     }
00260 
00261     Status = AcpiUtValidateBuffer (Buffer);
00262     if (ACPI_FAILURE (Status))
00263     {
00264         return (Status);
00265     }
00266 
00267     if (NameType == ACPI_FULL_PATHNAME)
00268     {
00269         /* Get the full pathname (From the namespace root) */
00270 
00271         Status = AcpiNsHandleToPathname (Handle, Buffer);
00272         return (Status);
00273     }
00274 
00275     /*
00276      * Wants the single segment ACPI name.
00277      * Validate handle and convert to a namespace Node
00278      */
00279     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
00280     if (ACPI_FAILURE (Status))
00281     {
00282         return (Status);
00283     }
00284 
00285     Node = AcpiNsValidateHandle (Handle);
00286     if (!Node)
00287     {
00288         Status = AE_BAD_PARAMETER;
00289         goto UnlockAndExit;
00290     }
00291 
00292     /* Validate/Allocate/Clear caller buffer */
00293 
00294     Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
00295     if (ACPI_FAILURE (Status))
00296     {
00297         goto UnlockAndExit;
00298     }
00299 
00300     /* Just copy the ACPI name from the Node and zero terminate it */
00301 
00302     ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
00303                 ACPI_NAME_SIZE);
00304     ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
00305     Status = AE_OK;
00306 
00307 
00308 UnlockAndExit:
00309 
00310     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
00311     return (Status);
00312 }
00313 
00314 ACPI_EXPORT_SYMBOL (AcpiGetName)
00315 
00316 
00317 /******************************************************************************
00318  *
00319  * FUNCTION:    AcpiNsCopyDeviceId
00320  *
00321  * PARAMETERS:  Dest                - Pointer to the destination DEVICE_ID
00322  *              Source              - Pointer to the source DEVICE_ID
00323  *              StringArea          - Pointer to where to copy the dest string
00324  *
00325  * RETURN:      Pointer to the next string area
00326  *
00327  * DESCRIPTION: Copy a single DEVICE_ID, including the string data.
00328  *
00329  ******************************************************************************/
00330 
00331 static char *
00332 AcpiNsCopyDeviceId (
00333     ACPI_DEVICE_ID          *Dest,
00334     ACPI_DEVICE_ID          *Source,
00335     char                    *StringArea)
00336 {
00337     /* Create the destination DEVICE_ID */
00338 
00339     Dest->String = StringArea;
00340     Dest->Length = Source->Length;
00341 
00342     /* Copy actual string and return a pointer to the next string area */
00343 
00344     ACPI_MEMCPY (StringArea, Source->String, Source->Length);
00345     return (StringArea + Source->Length);
00346 }
00347 
00348 
00349 /******************************************************************************
00350  *
00351  * FUNCTION:    AcpiGetObjectInfo
00352  *
00353  * PARAMETERS:  Handle              - Object Handle
00354  *              ReturnBuffer        - Where the info is returned
00355  *
00356  * RETURN:      Status
00357  *
00358  * DESCRIPTION: Returns information about an object as gleaned from the
00359  *              namespace node and possibly by running several standard
00360  *              control methods (Such as in the case of a device.)
00361  *
00362  * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
00363  * _ADR, _SxW, and _SxD methods.
00364  *
00365  * Note: Allocates the return buffer, must be freed by the caller.
00366  *
00367  ******************************************************************************/
00368 
00369 ACPI_STATUS
00370 AcpiGetObjectInfo (
00371     ACPI_HANDLE             Handle,
00372     ACPI_DEVICE_INFO        **ReturnBuffer)
00373 {
00374     ACPI_NAMESPACE_NODE     *Node;
00375     ACPI_DEVICE_INFO        *Info;
00376     ACPI_DEVICE_ID_LIST     *CidList = NULL;
00377     ACPI_DEVICE_ID          *Hid = NULL;
00378     ACPI_DEVICE_ID          *Uid = NULL;
00379     char                    *NextIdString;
00380     ACPI_OBJECT_TYPE        Type;
00381     ACPI_NAME               Name;
00382     UINT8                   ParamCount= 0;
00383     UINT8                   Valid = 0;
00384     UINT32                  InfoSize;
00385     UINT32                  i;
00386     ACPI_STATUS             Status;
00387 
00388 
00389     /* Parameter validation */
00390 
00391     if (!Handle || !ReturnBuffer)
00392     {
00393         return (AE_BAD_PARAMETER);
00394     }
00395 
00396     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
00397     if (ACPI_FAILURE (Status))
00398     {
00399         goto Cleanup;
00400     }
00401 
00402     Node = AcpiNsValidateHandle (Handle);
00403     if (!Node)
00404     {
00405         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
00406         return (AE_BAD_PARAMETER);
00407     }
00408 
00409     /* Get the namespace node data while the namespace is locked */
00410 
00411     InfoSize = sizeof (ACPI_DEVICE_INFO);
00412     Type = Node->Type;
00413     Name = Node->Name.Integer;
00414 
00415     if (Node->Type == ACPI_TYPE_METHOD)
00416     {
00417         ParamCount = Node->Object->Method.ParamCount;
00418     }
00419 
00420     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
00421     if (ACPI_FAILURE (Status))
00422     {
00423         return (Status);
00424     }
00425 
00426     if ((Type == ACPI_TYPE_DEVICE) ||
00427         (Type == ACPI_TYPE_PROCESSOR))
00428     {
00429         /*
00430          * Get extra info for ACPI Device/Processor objects only:
00431          * Run the Device _HID, _UID, and _CID methods.
00432          *
00433          * Note: none of these methods are required, so they may or may
00434          * not be present for this device. The Info->Valid bitfield is used
00435          * to indicate which methods were found and run successfully.
00436          */
00437 
00438         /* Execute the Device._HID method */
00439 
00440         Status = AcpiUtExecute_HID (Node, &Hid);
00441         if (ACPI_SUCCESS (Status))
00442         {
00443             InfoSize += Hid->Length;
00444             Valid |= ACPI_VALID_HID;
00445         }
00446 
00447         /* Execute the Device._UID method */
00448 
00449         Status = AcpiUtExecute_UID (Node, &Uid);
00450         if (ACPI_SUCCESS (Status))
00451         {
00452             InfoSize += Uid->Length;
00453             Valid |= ACPI_VALID_UID;
00454         }
00455 
00456         /* Execute the Device._CID method */
00457 
00458         Status = AcpiUtExecute_CID (Node, &CidList);
00459         if (ACPI_SUCCESS (Status))
00460         {
00461             /* Add size of CID strings and CID pointer array */
00462 
00463             InfoSize += (CidList->ListSize - sizeof (ACPI_DEVICE_ID_LIST));
00464             Valid |= ACPI_VALID_CID;
00465         }
00466     }
00467 
00468     /*
00469      * Now that we have the variable-length data, we can allocate the
00470      * return buffer
00471      */
00472     Info = ACPI_ALLOCATE_ZEROED (InfoSize);
00473     if (!Info)
00474     {
00475         Status = AE_NO_MEMORY;
00476         goto Cleanup;
00477     }
00478 
00479     /* Get the fixed-length data */
00480 
00481     if ((Type == ACPI_TYPE_DEVICE) ||
00482         (Type == ACPI_TYPE_PROCESSOR))
00483     {
00484         /*
00485          * Get extra info for ACPI Device/Processor objects only:
00486          * Run the _STA, _ADR and, SxW, and _SxD methods.
00487          *
00488          * Note: none of these methods are required, so they may or may
00489          * not be present for this device. The Info->Valid bitfield is used
00490          * to indicate which methods were found and run successfully.
00491          */
00492 
00493         /* Execute the Device._STA method */
00494 
00495         Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
00496         if (ACPI_SUCCESS (Status))
00497         {
00498             Valid |= ACPI_VALID_STA;
00499         }
00500 
00501         /* Execute the Device._ADR method */
00502 
00503         Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
00504                     &Info->Address);
00505         if (ACPI_SUCCESS (Status))
00506         {
00507             Valid |= ACPI_VALID_ADR;
00508         }
00509 
00510         /* Execute the Device._SxW methods */
00511 
00512         Status = AcpiUtExecutePowerMethods (Node,
00513                     AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
00514                     Info->LowestDstates);
00515         if (ACPI_SUCCESS (Status))
00516         {
00517             Valid |= ACPI_VALID_SXWS;
00518         }
00519 
00520         /* Execute the Device._SxD methods */
00521 
00522         Status = AcpiUtExecutePowerMethods (Node,
00523                     AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
00524                     Info->HighestDstates);
00525         if (ACPI_SUCCESS (Status))
00526         {
00527             Valid |= ACPI_VALID_SXDS;
00528         }
00529     }
00530 
00531     /*
00532      * Create a pointer to the string area of the return buffer.
00533      * Point to the end of the base ACPI_DEVICE_INFO structure.
00534      */
00535     NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
00536     if (CidList)
00537     {
00538         /* Point past the CID DEVICE_ID array */
00539 
00540         NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_DEVICE_ID));
00541     }
00542 
00543     /*
00544      * Copy the HID, UID, and CIDs to the return buffer. The variable-length
00545      * strings are copied to the reserved area at the end of the buffer.
00546      *
00547      * For HID and CID, check if the ID is a PCI Root Bridge.
00548      */
00549     if (Hid)
00550     {
00551         NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
00552             Hid, NextIdString);
00553 
00554         if (AcpiUtIsPciRootBridge (Hid->String))
00555         {
00556             Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
00557         }
00558     }
00559 
00560     if (Uid)
00561     {
00562         NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
00563             Uid, NextIdString);
00564     }
00565 
00566     if (CidList)
00567     {
00568         Info->CompatibleIdList.Count = CidList->Count;
00569         Info->CompatibleIdList.ListSize = CidList->ListSize;
00570 
00571         /* Copy each CID */
00572 
00573         for (i = 0; i < CidList->Count; i++)
00574         {
00575             NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
00576                 &CidList->Ids[i], NextIdString);
00577 
00578             if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
00579             {
00580                 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
00581             }
00582         }
00583     }
00584 
00585     /* Copy the fixed-length data */
00586 
00587     Info->InfoSize = InfoSize;
00588     Info->Type = Type;
00589     Info->Name = Name;
00590     Info->ParamCount = ParamCount;
00591     Info->Valid = Valid;
00592 
00593     *ReturnBuffer = Info;
00594     Status = AE_OK;
00595 
00596 
00597 Cleanup:
00598     if (Hid)
00599     {
00600         ACPI_FREE (Hid);
00601     }
00602     if (Uid)
00603     {
00604         ACPI_FREE (Uid);
00605     }
00606     if (CidList)
00607     {
00608         ACPI_FREE (CidList);
00609     }
00610     return (Status);
00611 }
00612 
00613 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
00614 
00615 
00616 /******************************************************************************
00617  *
00618  * FUNCTION:    AcpiInstallMethod
00619  *
00620  * PARAMETERS:  Buffer         - An ACPI table containing one control method
00621  *
00622  * RETURN:      Status
00623  *
00624  * DESCRIPTION: Install a control method into the namespace. If the method
00625  *              name already exists in the namespace, it is overwritten. The
00626  *              input buffer must contain a valid DSDT or SSDT containing a
00627  *              single control method.
00628  *
00629  ******************************************************************************/
00630 
00631 ACPI_STATUS
00632 AcpiInstallMethod (
00633     UINT8                   *Buffer)
00634 {
00635     ACPI_TABLE_HEADER       *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
00636     UINT8                   *AmlBuffer;
00637     UINT8                   *AmlStart;
00638     char                    *Path;
00639     ACPI_NAMESPACE_NODE     *Node;
00640     ACPI_OPERAND_OBJECT     *MethodObj;
00641     ACPI_PARSE_STATE        ParserState;
00642     UINT32                  AmlLength;
00643     UINT16                  Opcode;
00644     UINT8                   MethodFlags;
00645     ACPI_STATUS             Status;
00646 
00647 
00648     /* Parameter validation */
00649 
00650     if (!Buffer)
00651     {
00652         return (AE_BAD_PARAMETER);
00653     }
00654 
00655     /* Table must be a DSDT or SSDT */
00656 
00657     if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
00658         !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
00659     {
00660         return (AE_BAD_HEADER);
00661     }
00662 
00663     /* First AML opcode in the table must be a control method */
00664 
00665     ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
00666     Opcode = AcpiPsPeekOpcode (&ParserState);
00667     if (Opcode != AML_METHOD_OP)
00668     {
00669         return (AE_BAD_PARAMETER);
00670     }
00671 
00672     /* Extract method information from the raw AML */
00673 
00674     ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
00675     ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
00676     Path = AcpiPsGetNextNamestring (&ParserState);
00677     MethodFlags = *ParserState.Aml++;
00678     AmlStart = ParserState.Aml;
00679     AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
00680 
00681     /*
00682      * Allocate resources up-front. We don't want to have to delete a new
00683      * node from the namespace if we cannot allocate memory.
00684      */
00685     AmlBuffer = ACPI_ALLOCATE (AmlLength);
00686     if (!AmlBuffer)
00687     {
00688         return (AE_NO_MEMORY);
00689     }
00690 
00691     MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
00692     if (!MethodObj)
00693     {
00694         ACPI_FREE (AmlBuffer);
00695         return (AE_NO_MEMORY);
00696     }
00697 
00698     /* Lock namespace for AcpiNsLookup, we may be creating a new node */
00699 
00700     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
00701     if (ACPI_FAILURE (Status))
00702     {
00703         goto ErrorExit;
00704     }
00705 
00706     /* The lookup either returns an existing node or creates a new one */
00707 
00708     Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
00709                 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
00710 
00711     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
00712 
00713     if (ACPI_FAILURE (Status)) /* NsLookup */
00714     {
00715         if (Status != AE_ALREADY_EXISTS)
00716         {
00717             goto ErrorExit;
00718         }
00719 
00720         /* Node existed previously, make sure it is a method node */
00721 
00722         if (Node->Type != ACPI_TYPE_METHOD)
00723         {
00724             Status = AE_TYPE;
00725             goto ErrorExit;
00726         }
00727     }
00728 
00729     /* Copy the method AML to the local buffer */
00730 
00731     ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength);
00732 
00733     /* Initialize the method object with the new method's information */
00734 
00735     MethodObj->Method.AmlStart = AmlBuffer;
00736     MethodObj->Method.AmlLength = AmlLength;
00737 
00738     MethodObj->Method.ParamCount = (UINT8)
00739         (MethodFlags & AML_METHOD_ARG_COUNT);
00740 
00741     if (MethodFlags & AML_METHOD_SERIALIZED)
00742     {
00743         MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
00744 
00745         MethodObj->Method.SyncLevel = (UINT8)
00746             ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
00747     }
00748 
00749     /*
00750      * Now that it is complete, we can attach the new method object to
00751      * the method Node (detaches/deletes any existing object)
00752      */
00753     Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);
00754 
00755     /*
00756      * Flag indicates AML buffer is dynamic, must be deleted later.
00757      * Must be set only after attach above.
00758      */
00759     Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
00760 
00761     /* Remove local reference to the method object */
00762 
00763     AcpiUtRemoveReference (MethodObj);
00764     return (Status);
00765 
00766 
00767 ErrorExit:
00768 
00769     ACPI_FREE (AmlBuffer);
00770     ACPI_FREE (MethodObj);
00771     return (Status);
00772 }
00773 
00774 ACPI_EXPORT_SYMBOL (AcpiInstallMethod)

Generated on Sun May 27 2012 04:27:21 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.