Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennseval.c
Go to the documentation of this file.
00001 /******************************************************************************* 00002 * 00003 * Module Name: nseval - Object evaluation, includes control method execution 00004 * 00005 ******************************************************************************/ 00006 00007 /****************************************************************************** 00008 * 00009 * 1. Copyright Notice 00010 * 00011 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. 00012 * All rights reserved. 00013 * 00014 * 2. License 00015 * 00016 * 2.1. This is your license from Intel Corp. under its intellectual property 00017 * rights. You may have additional license terms from the party that provided 00018 * you this software, covering your right to use that party's intellectual 00019 * property rights. 00020 * 00021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 00022 * copy of the source code appearing in this file ("Covered Code") an 00023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 00024 * base code distributed originally by Intel ("Original Intel Code") to copy, 00025 * make derivatives, distribute, use and display any portion of the Covered 00026 * Code in any form, with the right to sublicense such rights; and 00027 * 00028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 00029 * license (with the right to sublicense), under only those claims of Intel 00030 * patents that are infringed by the Original Intel Code, to make, use, sell, 00031 * offer to sell, and import the Covered Code and derivative works thereof 00032 * solely to the minimum extent necessary to exercise the above copyright 00033 * license, and in no event shall the patent license extend to any additions 00034 * to or modifications of the Original Intel Code. No other license or right 00035 * is granted directly or by implication, estoppel or otherwise; 00036 * 00037 * The above copyright and patent license is granted only if the following 00038 * conditions are met: 00039 * 00040 * 3. Conditions 00041 * 00042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 00043 * Redistribution of source code of any substantial portion of the Covered 00044 * Code or modification with rights to further distribute source must include 00045 * the above Copyright Notice, the above License, this list of Conditions, 00046 * and the following Disclaimer and Export Compliance provision. In addition, 00047 * Licensee must cause all Covered Code to which Licensee contributes to 00048 * contain a file documenting the changes Licensee made to create that Covered 00049 * Code and the date of any change. Licensee must include in that file the 00050 * documentation of any changes made by any predecessor Licensee. Licensee 00051 * must include a prominent statement that the modification is derived, 00052 * directly or indirectly, from Original Intel Code. 00053 * 00054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 00055 * Redistribution of source code of any substantial portion of the Covered 00056 * Code or modification without rights to further distribute source must 00057 * include the following Disclaimer and Export Compliance provision in the 00058 * documentation and/or other materials provided with distribution. In 00059 * addition, Licensee may not authorize further sublicense of source of any 00060 * portion of the Covered Code, and must include terms to the effect that the 00061 * license from Licensee to its licensee is limited to the intellectual 00062 * property embodied in the software Licensee provides to its licensee, and 00063 * not to intellectual property embodied in modifications its licensee may 00064 * make. 00065 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 __NSEVAL_C__ 00118 00119 #include "acpi.h" 00120 #include "accommon.h" 00121 #include "acparser.h" 00122 #include "acinterp.h" 00123 #include "acnamesp.h" 00124 00125 00126 #define _COMPONENT ACPI_NAMESPACE 00127 ACPI_MODULE_NAME ("nseval") 00128 00129 /* Local prototypes */ 00130 00131 static void 00132 AcpiNsExecModuleCode ( 00133 ACPI_OPERAND_OBJECT *MethodObj, 00134 ACPI_EVALUATE_INFO *Info); 00135 00136 00137 /******************************************************************************* 00138 * 00139 * FUNCTION: AcpiNsEvaluate 00140 * 00141 * PARAMETERS: Info - Evaluation info block, contains: 00142 * PrefixNode - Prefix or Method/Object Node to execute 00143 * Pathname - Name of method to execute, If NULL, the 00144 * Node is the object to execute 00145 * Parameters - List of parameters to pass to the method, 00146 * terminated by NULL. Params itself may be 00147 * NULL if no parameters are being passed. 00148 * ReturnObject - Where to put method's return value (if 00149 * any). If NULL, no value is returned. 00150 * ParameterType - Type of Parameter list 00151 * ReturnObject - Where to put method's return value (if 00152 * any). If NULL, no value is returned. 00153 * Flags - ACPI_IGNORE_RETURN_VALUE to delete return 00154 * 00155 * RETURN: Status 00156 * 00157 * DESCRIPTION: Execute a control method or return the current value of an 00158 * ACPI namespace object. 00159 * 00160 * MUTEX: Locks interpreter 00161 * 00162 ******************************************************************************/ 00163 00164 ACPI_STATUS 00165 AcpiNsEvaluate ( 00166 ACPI_EVALUATE_INFO *Info) 00167 { 00168 ACPI_STATUS Status; 00169 ACPI_NAMESPACE_NODE *Node; 00170 00171 00172 ACPI_FUNCTION_TRACE (NsEvaluate); 00173 00174 00175 if (!Info) 00176 { 00177 return_ACPI_STATUS (AE_BAD_PARAMETER); 00178 } 00179 00180 /* Initialize the return value to an invalid object */ 00181 00182 Info->ReturnObject = NULL; 00183 Info->ParamCount = 0; 00184 00185 /* 00186 * Get the actual namespace node for the target object. Handles these cases: 00187 * 00188 * 1) Null node, Pathname (absolute path) 00189 * 2) Node, Pathname (path relative to Node) 00190 * 3) Node, Null Pathname 00191 */ 00192 Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname, 00193 ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode); 00194 if (ACPI_FAILURE (Status)) 00195 { 00196 return_ACPI_STATUS (Status); 00197 } 00198 00199 /* 00200 * For a method alias, we must grab the actual method node so that proper 00201 * scoping context will be established before execution. 00202 */ 00203 if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS) 00204 { 00205 Info->ResolvedNode = 00206 ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object); 00207 } 00208 00209 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname, 00210 Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode))); 00211 00212 Node = Info->ResolvedNode; 00213 00214 /* 00215 * Two major cases here: 00216 * 00217 * 1) The object is a control method -- execute it 00218 * 2) The object is not a method -- just return it's current value 00219 */ 00220 if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD) 00221 { 00222 /* 00223 * 1) Object is a control method - execute it 00224 */ 00225 00226 /* Verify that there is a method object associated with this node */ 00227 00228 Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode); 00229 if (!Info->ObjDesc) 00230 { 00231 ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object")); 00232 return_ACPI_STATUS (AE_NULL_OBJECT); 00233 } 00234 00235 /* Count the number of arguments being passed to the method */ 00236 00237 if (Info->Parameters) 00238 { 00239 while (Info->Parameters[Info->ParamCount]) 00240 { 00241 if (Info->ParamCount > ACPI_METHOD_MAX_ARG) 00242 { 00243 return_ACPI_STATUS (AE_LIMIT); 00244 } 00245 Info->ParamCount++; 00246 } 00247 } 00248 00249 ACPI_DUMP_PATHNAME (Info->ResolvedNode, "ACPI: Execute Method", 00250 ACPI_LV_INFO, _COMPONENT); 00251 00252 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 00253 "Method at AML address %p Length %X\n", 00254 Info->ObjDesc->Method.AmlStart + 1, 00255 Info->ObjDesc->Method.AmlLength - 1)); 00256 00257 /* 00258 * Any namespace deletion must acquire both the namespace and 00259 * interpreter locks to ensure that no thread is using the portion of 00260 * the namespace that is being deleted. 00261 * 00262 * Execute the method via the interpreter. The interpreter is locked 00263 * here before calling into the AML parser 00264 */ 00265 AcpiExEnterInterpreter (); 00266 Status = AcpiPsExecuteMethod (Info); 00267 AcpiExExitInterpreter (); 00268 } 00269 else 00270 { 00271 /* 00272 * 2) Object is not a method, return its current value 00273 * 00274 * Disallow certain object types. For these, "evaluation" is undefined. 00275 */ 00276 switch (Info->ResolvedNode->Type) 00277 { 00278 case ACPI_TYPE_DEVICE: 00279 case ACPI_TYPE_EVENT: 00280 case ACPI_TYPE_MUTEX: 00281 case ACPI_TYPE_REGION: 00282 case ACPI_TYPE_THERMAL: 00283 case ACPI_TYPE_LOCAL_SCOPE: 00284 00285 ACPI_ERROR ((AE_INFO, 00286 "[%4.4s] Evaluation of object type [%s] is not supported", 00287 Info->ResolvedNode->Name.Ascii, 00288 AcpiUtGetTypeName (Info->ResolvedNode->Type))); 00289 00290 return_ACPI_STATUS (AE_TYPE); 00291 00292 default: 00293 break; 00294 } 00295 00296 /* 00297 * Objects require additional resolution steps (e.g., the Node may be 00298 * a field that must be read, etc.) -- we can't just grab the object 00299 * out of the node. 00300 * 00301 * Use ResolveNodeToValue() to get the associated value. 00302 * 00303 * NOTE: we can get away with passing in NULL for a walk state because 00304 * ResolvedNode is guaranteed to not be a reference to either a method 00305 * local or a method argument (because this interface is never called 00306 * from a running method.) 00307 * 00308 * Even though we do not directly invoke the interpreter for object 00309 * resolution, we must lock it because we could access an opregion. 00310 * The opregion access code assumes that the interpreter is locked. 00311 */ 00312 AcpiExEnterInterpreter (); 00313 00314 /* Function has a strange interface */ 00315 00316 Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL); 00317 AcpiExExitInterpreter (); 00318 00319 /* 00320 * If AcpiExResolveNodeToValue() succeeded, the return value was placed 00321 * in ResolvedNode. 00322 */ 00323 if (ACPI_SUCCESS (Status)) 00324 { 00325 Status = AE_CTRL_RETURN_VALUE; 00326 Info->ReturnObject = 00327 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode); 00328 00329 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n", 00330 Info->ReturnObject, 00331 AcpiUtGetObjectTypeName (Info->ReturnObject))); 00332 } 00333 } 00334 00335 /* 00336 * Check input argument count against the ASL-defined count for a method. 00337 * Also check predefined names: argument count and return value against 00338 * the ACPI specification. Some incorrect return value types are repaired. 00339 */ 00340 (void) AcpiNsCheckPredefinedNames (Node, Info->ParamCount, 00341 Status, &Info->ReturnObject); 00342 00343 /* Check if there is a return value that must be dealt with */ 00344 00345 if (Status == AE_CTRL_RETURN_VALUE) 00346 { 00347 /* If caller does not want the return value, delete it */ 00348 00349 if (Info->Flags & ACPI_IGNORE_RETURN_VALUE) 00350 { 00351 AcpiUtRemoveReference (Info->ReturnObject); 00352 Info->ReturnObject = NULL; 00353 } 00354 00355 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ 00356 00357 Status = AE_OK; 00358 } 00359 00360 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00361 "*** Completed evaluation of object %s ***\n", Info->Pathname)); 00362 00363 /* 00364 * Namespace was unlocked by the handling AcpiNs* function, so we 00365 * just return 00366 */ 00367 return_ACPI_STATUS (Status); 00368 } 00369 00370 00371 /******************************************************************************* 00372 * 00373 * FUNCTION: AcpiNsExecModuleCodeList 00374 * 00375 * PARAMETERS: None 00376 * 00377 * RETURN: None. Exceptions during method execution are ignored, since 00378 * we cannot abort a table load. 00379 * 00380 * DESCRIPTION: Execute all elements of the global module-level code list. 00381 * Each element is executed as a single control method. 00382 * 00383 ******************************************************************************/ 00384 00385 void 00386 AcpiNsExecModuleCodeList ( 00387 void) 00388 { 00389 ACPI_OPERAND_OBJECT *Prev; 00390 ACPI_OPERAND_OBJECT *Next; 00391 ACPI_EVALUATE_INFO *Info; 00392 UINT32 MethodCount = 0; 00393 00394 00395 ACPI_FUNCTION_TRACE (NsExecModuleCodeList); 00396 00397 00398 /* Exit now if the list is empty */ 00399 00400 Next = AcpiGbl_ModuleCodeList; 00401 if (!Next) 00402 { 00403 return_VOID; 00404 } 00405 00406 /* Allocate the evaluation information block */ 00407 00408 Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO)); 00409 if (!Info) 00410 { 00411 return_VOID; 00412 } 00413 00414 /* Walk the list, executing each "method" */ 00415 00416 while (Next) 00417 { 00418 Prev = Next; 00419 Next = Next->Method.Mutex; 00420 00421 /* Clear the link field and execute the method */ 00422 00423 Prev->Method.Mutex = NULL; 00424 AcpiNsExecModuleCode (Prev, Info); 00425 MethodCount++; 00426 00427 /* Delete the (temporary) method object */ 00428 00429 AcpiUtRemoveReference (Prev); 00430 } 00431 00432 ACPI_INFO ((AE_INFO, 00433 "Executed %u blocks of module-level executable AML code", 00434 MethodCount)); 00435 00436 ACPI_FREE (Info); 00437 AcpiGbl_ModuleCodeList = NULL; 00438 return_VOID; 00439 } 00440 00441 00442 /******************************************************************************* 00443 * 00444 * FUNCTION: AcpiNsExecModuleCode 00445 * 00446 * PARAMETERS: MethodObj - Object container for the module-level code 00447 * Info - Info block for method evaluation 00448 * 00449 * RETURN: None. Exceptions during method execution are ignored, since 00450 * we cannot abort a table load. 00451 * 00452 * DESCRIPTION: Execute a control method containing a block of module-level 00453 * executable AML code. The control method is temporarily 00454 * installed to the root node, then evaluated. 00455 * 00456 ******************************************************************************/ 00457 00458 static void 00459 AcpiNsExecModuleCode ( 00460 ACPI_OPERAND_OBJECT *MethodObj, 00461 ACPI_EVALUATE_INFO *Info) 00462 { 00463 ACPI_OPERAND_OBJECT *ParentObj; 00464 ACPI_NAMESPACE_NODE *ParentNode; 00465 ACPI_OBJECT_TYPE Type; 00466 ACPI_STATUS Status; 00467 00468 00469 ACPI_FUNCTION_TRACE (NsExecModuleCode); 00470 00471 00472 /* 00473 * Get the parent node. We cheat by using the NextObject field 00474 * of the method object descriptor. 00475 */ 00476 ParentNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, 00477 MethodObj->Method.NextObject); 00478 Type = AcpiNsGetType (ParentNode); 00479 00480 /* 00481 * Get the region handler and save it in the method object. We may need 00482 * this if an operation region declaration causes a _REG method to be run. 00483 * 00484 * We can't do this in AcpiPsLinkModuleCode because 00485 * AcpiGbl_RootNode->Object is NULL at PASS1. 00486 */ 00487 if ((Type == ACPI_TYPE_DEVICE) && ParentNode->Object) 00488 { 00489 MethodObj->Method.Dispatch.Handler = 00490 ParentNode->Object->Device.Handler; 00491 } 00492 00493 /* Must clear NextObject (AcpiNsAttachObject needs the field) */ 00494 00495 MethodObj->Method.NextObject = NULL; 00496 00497 /* Initialize the evaluation information block */ 00498 00499 ACPI_MEMSET (Info, 0, sizeof (ACPI_EVALUATE_INFO)); 00500 Info->PrefixNode = ParentNode; 00501 00502 /* 00503 * Get the currently attached parent object. Add a reference, because the 00504 * ref count will be decreased when the method object is installed to 00505 * the parent node. 00506 */ 00507 ParentObj = AcpiNsGetAttachedObject (ParentNode); 00508 if (ParentObj) 00509 { 00510 AcpiUtAddReference (ParentObj); 00511 } 00512 00513 /* Install the method (module-level code) in the parent node */ 00514 00515 Status = AcpiNsAttachObject (ParentNode, MethodObj, 00516 ACPI_TYPE_METHOD); 00517 if (ACPI_FAILURE (Status)) 00518 { 00519 goto Exit; 00520 } 00521 00522 /* Execute the parent node as a control method */ 00523 00524 Status = AcpiNsEvaluate (Info); 00525 00526 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Executed module-level code at %p\n", 00527 MethodObj->Method.AmlStart)); 00528 00529 /* Delete a possible implicit return value (in slack mode) */ 00530 00531 if (Info->ReturnObject) 00532 { 00533 AcpiUtRemoveReference (Info->ReturnObject); 00534 } 00535 00536 /* Detach the temporary method object */ 00537 00538 AcpiNsDetachObject (ParentNode); 00539 00540 /* Restore the original parent object */ 00541 00542 if (ParentObj) 00543 { 00544 Status = AcpiNsAttachObject (ParentNode, ParentObj, Type); 00545 } 00546 else 00547 { 00548 ParentNode->Type = (UINT8) Type; 00549 } 00550 00551 Exit: 00552 if (ParentObj) 00553 { 00554 AcpiUtRemoveReference (ParentObj); 00555 } 00556 return_VOID; 00557 } 00558 Generated on Sat May 26 2012 04:25:53 for ReactOS by
1.7.6.1
|