Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennssearch.c
Go to the documentation of this file.
00001 /******************************************************************************* 00002 * 00003 * Module Name: nssearch - Namespace search 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 * 3.3. Redistribution of Executable. Redistribution in executable form of any 00067 * substantial portion of the Covered Code or modification must reproduce the 00068 * above Copyright Notice, and the following Disclaimer and Export Compliance 00069 * provision in the documentation and/or other materials provided with the 00070 * distribution. 00071 * 00072 * 3.4. Intel retains all right, title, and interest in and to the Original 00073 * Intel Code. 00074 * 00075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 00076 * Intel shall be used in advertising or otherwise to promote the sale, use or 00077 * other dealings in products derived from or relating to the Covered Code 00078 * without prior written authorization from Intel. 00079 * 00080 * 4. Disclaimer and Export Compliance 00081 * 00082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 00083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 00084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 00085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 00086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 00087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 00088 * PARTICULAR PURPOSE. 00089 * 00090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 00091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 00092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 00093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 00094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 00095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 00096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 00097 * LIMITED REMEDY. 00098 * 00099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 00100 * software or system incorporating such software without first obtaining any 00101 * required license or other approval from the U. S. Department of Commerce or 00102 * any other agency or department of the United States Government. In the 00103 * event Licensee exports any such software from the United States or 00104 * re-exports any such software from a foreign destination, Licensee shall 00105 * ensure that the distribution and export/re-export of the software is in 00106 * compliance with all laws, regulations, orders, or other restrictions of the 00107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 00108 * any of its subsidiaries will export/re-export any technical data, process, 00109 * software, or service, directly or indirectly, to any country for which the 00110 * United States government or any agency thereof requires an export license, 00111 * other governmental approval, or letter of assurance, without first obtaining 00112 * such license, approval or letter. 00113 * 00114 *****************************************************************************/ 00115 00116 #define __NSSEARCH_C__ 00117 00118 #include "acpi.h" 00119 #include "accommon.h" 00120 #include "acnamesp.h" 00121 00122 #ifdef ACPI_ASL_COMPILER 00123 #include "amlcode.h" 00124 #endif 00125 00126 #define _COMPONENT ACPI_NAMESPACE 00127 ACPI_MODULE_NAME ("nssearch") 00128 00129 /* Local prototypes */ 00130 00131 static ACPI_STATUS 00132 AcpiNsSearchParentTree ( 00133 UINT32 TargetName, 00134 ACPI_NAMESPACE_NODE *Node, 00135 ACPI_OBJECT_TYPE Type, 00136 ACPI_NAMESPACE_NODE **ReturnNode); 00137 00138 00139 /******************************************************************************* 00140 * 00141 * FUNCTION: AcpiNsSearchOneScope 00142 * 00143 * PARAMETERS: TargetName - Ascii ACPI name to search for 00144 * ParentNode - Starting node where search will begin 00145 * Type - Object type to match 00146 * ReturnNode - Where the matched Named obj is returned 00147 * 00148 * RETURN: Status 00149 * 00150 * DESCRIPTION: Search a single level of the namespace. Performs a 00151 * simple search of the specified level, and does not add 00152 * entries or search parents. 00153 * 00154 * 00155 * Named object lists are built (and subsequently dumped) in the 00156 * order in which the names are encountered during the namespace load; 00157 * 00158 * All namespace searching is linear in this implementation, but 00159 * could be easily modified to support any improved search 00160 * algorithm. However, the linear search was chosen for simplicity 00161 * and because the trees are small and the other interpreter 00162 * execution overhead is relatively high. 00163 * 00164 * Note: CPU execution analysis has shown that the AML interpreter spends 00165 * a very small percentage of its time searching the namespace. Therefore, 00166 * the linear search seems to be sufficient, as there would seem to be 00167 * little value in improving the search. 00168 * 00169 ******************************************************************************/ 00170 00171 ACPI_STATUS 00172 AcpiNsSearchOneScope ( 00173 UINT32 TargetName, 00174 ACPI_NAMESPACE_NODE *ParentNode, 00175 ACPI_OBJECT_TYPE Type, 00176 ACPI_NAMESPACE_NODE **ReturnNode) 00177 { 00178 ACPI_NAMESPACE_NODE *Node; 00179 00180 00181 ACPI_FUNCTION_TRACE (NsSearchOneScope); 00182 00183 00184 #ifdef ACPI_DEBUG_OUTPUT 00185 if (ACPI_LV_NAMES & AcpiDbgLevel) 00186 { 00187 char *ScopeName; 00188 00189 ScopeName = AcpiNsGetExternalPathname (ParentNode); 00190 if (ScopeName) 00191 { 00192 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00193 "Searching %s (%p) For [%4.4s] (%s)\n", 00194 ScopeName, ParentNode, ACPI_CAST_PTR (char, &TargetName), 00195 AcpiUtGetTypeName (Type))); 00196 00197 ACPI_FREE (ScopeName); 00198 } 00199 } 00200 #endif 00201 00202 /* 00203 * Search for name at this namespace level, which is to say that we 00204 * must search for the name among the children of this object 00205 */ 00206 Node = ParentNode->Child; 00207 while (Node) 00208 { 00209 /* Check for match against the name */ 00210 00211 if (Node->Name.Integer == TargetName) 00212 { 00213 /* Resolve a control method alias if any */ 00214 00215 if (AcpiNsGetType (Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) 00216 { 00217 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object); 00218 } 00219 00220 /* Found matching entry */ 00221 00222 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00223 "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n", 00224 ACPI_CAST_PTR (char, &TargetName), 00225 AcpiUtGetTypeName (Node->Type), 00226 Node, AcpiUtGetNodeName (ParentNode), ParentNode)); 00227 00228 *ReturnNode = Node; 00229 return_ACPI_STATUS (AE_OK); 00230 } 00231 00232 /* Didn't match name, move on to the next peer object */ 00233 00234 Node = Node->Peer; 00235 } 00236 00237 /* Searched entire namespace level, not found */ 00238 00239 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00240 "Name [%4.4s] (%s) not found in search in scope [%4.4s] " 00241 "%p first child %p\n", 00242 ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type), 00243 AcpiUtGetNodeName (ParentNode), ParentNode, ParentNode->Child)); 00244 00245 return_ACPI_STATUS (AE_NOT_FOUND); 00246 } 00247 00248 00249 /******************************************************************************* 00250 * 00251 * FUNCTION: AcpiNsSearchParentTree 00252 * 00253 * PARAMETERS: TargetName - Ascii ACPI name to search for 00254 * Node - Starting node where search will begin 00255 * Type - Object type to match 00256 * ReturnNode - Where the matched Node is returned 00257 * 00258 * RETURN: Status 00259 * 00260 * DESCRIPTION: Called when a name has not been found in the current namespace 00261 * level. Before adding it or giving up, ACPI scope rules require 00262 * searching enclosing scopes in cases identified by AcpiNsLocal(). 00263 * 00264 * "A name is located by finding the matching name in the current 00265 * name space, and then in the parent name space. If the parent 00266 * name space does not contain the name, the search continues 00267 * recursively until either the name is found or the name space 00268 * does not have a parent (the root of the name space). This 00269 * indicates that the name is not found" (From ACPI Specification, 00270 * section 5.3) 00271 * 00272 ******************************************************************************/ 00273 00274 static ACPI_STATUS 00275 AcpiNsSearchParentTree ( 00276 UINT32 TargetName, 00277 ACPI_NAMESPACE_NODE *Node, 00278 ACPI_OBJECT_TYPE Type, 00279 ACPI_NAMESPACE_NODE **ReturnNode) 00280 { 00281 ACPI_STATUS Status; 00282 ACPI_NAMESPACE_NODE *ParentNode; 00283 00284 00285 ACPI_FUNCTION_TRACE (NsSearchParentTree); 00286 00287 00288 ParentNode = Node->Parent; 00289 00290 /* 00291 * If there is no parent (i.e., we are at the root) or type is "local", 00292 * we won't be searching the parent tree. 00293 */ 00294 if (!ParentNode) 00295 { 00296 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] has no parent\n", 00297 ACPI_CAST_PTR (char, &TargetName))); 00298 return_ACPI_STATUS (AE_NOT_FOUND); 00299 } 00300 00301 if (AcpiNsLocal (Type)) 00302 { 00303 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00304 "[%4.4s] type [%s] must be local to this scope (no parent search)\n", 00305 ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type))); 00306 return_ACPI_STATUS (AE_NOT_FOUND); 00307 } 00308 00309 /* Search the parent tree */ 00310 00311 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00312 "Searching parent [%4.4s] for [%4.4s]\n", 00313 AcpiUtGetNodeName (ParentNode), ACPI_CAST_PTR (char, &TargetName))); 00314 00315 /* Search parents until target is found or we have backed up to the root */ 00316 00317 while (ParentNode) 00318 { 00319 /* 00320 * Search parent scope. Use TYPE_ANY because we don't care about the 00321 * object type at this point, we only care about the existence of 00322 * the actual name we are searching for. Typechecking comes later. 00323 */ 00324 Status = AcpiNsSearchOneScope ( 00325 TargetName, ParentNode, ACPI_TYPE_ANY, ReturnNode); 00326 if (ACPI_SUCCESS (Status)) 00327 { 00328 return_ACPI_STATUS (Status); 00329 } 00330 00331 /* Not found here, go up another level (until we reach the root) */ 00332 00333 ParentNode = ParentNode->Parent; 00334 } 00335 00336 /* Not found in parent tree */ 00337 00338 return_ACPI_STATUS (AE_NOT_FOUND); 00339 } 00340 00341 00342 /******************************************************************************* 00343 * 00344 * FUNCTION: AcpiNsSearchAndEnter 00345 * 00346 * PARAMETERS: TargetName - Ascii ACPI name to search for (4 chars) 00347 * WalkState - Current state of the walk 00348 * Node - Starting node where search will begin 00349 * InterpreterMode - Add names only in ACPI_MODE_LOAD_PASS_x. 00350 * Otherwise,search only. 00351 * Type - Object type to match 00352 * Flags - Flags describing the search restrictions 00353 * ReturnNode - Where the Node is returned 00354 * 00355 * RETURN: Status 00356 * 00357 * DESCRIPTION: Search for a name segment in a single namespace level, 00358 * optionally adding it if it is not found. If the passed 00359 * Type is not Any and the type previously stored in the 00360 * entry was Any (i.e. unknown), update the stored type. 00361 * 00362 * In ACPI_IMODE_EXECUTE, search only. 00363 * In other modes, search and add if not found. 00364 * 00365 ******************************************************************************/ 00366 00367 ACPI_STATUS 00368 AcpiNsSearchAndEnter ( 00369 UINT32 TargetName, 00370 ACPI_WALK_STATE *WalkState, 00371 ACPI_NAMESPACE_NODE *Node, 00372 ACPI_INTERPRETER_MODE InterpreterMode, 00373 ACPI_OBJECT_TYPE Type, 00374 UINT32 Flags, 00375 ACPI_NAMESPACE_NODE **ReturnNode) 00376 { 00377 ACPI_STATUS Status; 00378 ACPI_NAMESPACE_NODE *NewNode; 00379 00380 00381 ACPI_FUNCTION_TRACE (NsSearchAndEnter); 00382 00383 00384 /* Parameter validation */ 00385 00386 if (!Node || !TargetName || !ReturnNode) 00387 { 00388 ACPI_ERROR ((AE_INFO, 00389 "Null parameter: Node %p Name 0x%X ReturnNode %p", 00390 Node, TargetName, ReturnNode)); 00391 return_ACPI_STATUS (AE_BAD_PARAMETER); 00392 } 00393 00394 /* 00395 * Name must consist of valid ACPI characters. We will repair the name if 00396 * necessary because we don't want to abort because of this, but we want 00397 * all namespace names to be printable. A warning message is appropriate. 00398 * 00399 * This issue came up because there are in fact machines that exhibit 00400 * this problem, and we want to be able to enable ACPI support for them, 00401 * even though there are a few bad names. 00402 */ 00403 AcpiUtRepairName (ACPI_CAST_PTR (char, &TargetName)); 00404 00405 /* Try to find the name in the namespace level specified by the caller */ 00406 00407 *ReturnNode = ACPI_ENTRY_NOT_FOUND; 00408 Status = AcpiNsSearchOneScope (TargetName, Node, Type, ReturnNode); 00409 if (Status != AE_NOT_FOUND) 00410 { 00411 /* 00412 * If we found it AND the request specifies that a find is an error, 00413 * return the error 00414 */ 00415 if ((Status == AE_OK) && 00416 (Flags & ACPI_NS_ERROR_IF_FOUND)) 00417 { 00418 Status = AE_ALREADY_EXISTS; 00419 } 00420 00421 #ifdef ACPI_ASL_COMPILER 00422 if (*ReturnNode && (*ReturnNode)->Type == ACPI_TYPE_ANY) 00423 { 00424 (*ReturnNode)->Flags |= ANOBJ_IS_EXTERNAL; 00425 } 00426 #endif 00427 00428 /* Either found it or there was an error: finished either way */ 00429 00430 return_ACPI_STATUS (Status); 00431 } 00432 00433 /* 00434 * The name was not found. If we are NOT performing the first pass 00435 * (name entry) of loading the namespace, search the parent tree (all the 00436 * way to the root if necessary.) We don't want to perform the parent 00437 * search when the namespace is actually being loaded. We want to perform 00438 * the search when namespace references are being resolved (load pass 2) 00439 * and during the execution phase. 00440 */ 00441 if ((InterpreterMode != ACPI_IMODE_LOAD_PASS1) && 00442 (Flags & ACPI_NS_SEARCH_PARENT)) 00443 { 00444 /* 00445 * Not found at this level - search parent tree according to the 00446 * ACPI specification 00447 */ 00448 Status = AcpiNsSearchParentTree (TargetName, Node, Type, ReturnNode); 00449 if (ACPI_SUCCESS (Status)) 00450 { 00451 return_ACPI_STATUS (Status); 00452 } 00453 } 00454 00455 /* In execute mode, just search, never add names. Exit now */ 00456 00457 if (InterpreterMode == ACPI_IMODE_EXECUTE) 00458 { 00459 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00460 "%4.4s Not found in %p [Not adding]\n", 00461 ACPI_CAST_PTR (char, &TargetName), Node)); 00462 00463 return_ACPI_STATUS (AE_NOT_FOUND); 00464 } 00465 00466 /* Create the new named object */ 00467 00468 NewNode = AcpiNsCreateNode (TargetName); 00469 if (!NewNode) 00470 { 00471 return_ACPI_STATUS (AE_NO_MEMORY); 00472 } 00473 00474 #ifdef ACPI_ASL_COMPILER 00475 00476 /* Node is an object defined by an External() statement */ 00477 00478 if (Flags & ACPI_NS_EXTERNAL || 00479 (WalkState && WalkState->Opcode == AML_SCOPE_OP)) 00480 { 00481 NewNode->Flags |= ANOBJ_IS_EXTERNAL; 00482 } 00483 #endif 00484 00485 if (Flags & ACPI_NS_TEMPORARY) 00486 { 00487 NewNode->Flags |= ANOBJ_TEMPORARY; 00488 } 00489 00490 /* Install the new object into the parent's list of children */ 00491 00492 AcpiNsInstallNode (WalkState, Node, NewNode, Type); 00493 *ReturnNode = NewNode; 00494 return_ACPI_STATUS (AE_OK); 00495 } 00496 Generated on Sat May 26 2012 04:25:54 for ReactOS by
1.7.6.1
|