![]() |
|
|||
File indexing completed on 2025-05-11 08:24:03
0001 /******************************************************************************* 0002 * 0003 * Module Name: nssearch - Namespace search 0004 * 0005 ******************************************************************************/ 0006 0007 /****************************************************************************** 0008 * 0009 * 1. Copyright Notice 0010 * 0011 * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp. 0012 * All rights reserved. 0013 * 0014 * 2. License 0015 * 0016 * 2.1. This is your license from Intel Corp. under its intellectual property 0017 * rights. You may have additional license terms from the party that provided 0018 * you this software, covering your right to use that party's intellectual 0019 * property rights. 0020 * 0021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 0022 * copy of the source code appearing in this file ("Covered Code") an 0023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 0024 * base code distributed originally by Intel ("Original Intel Code") to copy, 0025 * make derivatives, distribute, use and display any portion of the Covered 0026 * Code in any form, with the right to sublicense such rights; and 0027 * 0028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 0029 * license (with the right to sublicense), under only those claims of Intel 0030 * patents that are infringed by the Original Intel Code, to make, use, sell, 0031 * offer to sell, and import the Covered Code and derivative works thereof 0032 * solely to the minimum extent necessary to exercise the above copyright 0033 * license, and in no event shall the patent license extend to any additions 0034 * to or modifications of the Original Intel Code. No other license or right 0035 * is granted directly or by implication, estoppel or otherwise; 0036 * 0037 * The above copyright and patent license is granted only if the following 0038 * conditions are met: 0039 * 0040 * 3. Conditions 0041 * 0042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 0043 * Redistribution of source code of any substantial portion of the Covered 0044 * Code or modification with rights to further distribute source must include 0045 * the above Copyright Notice, the above License, this list of Conditions, 0046 * and the following Disclaimer and Export Compliance provision. In addition, 0047 * Licensee must cause all Covered Code to which Licensee contributes to 0048 * contain a file documenting the changes Licensee made to create that Covered 0049 * Code and the date of any change. Licensee must include in that file the 0050 * documentation of any changes made by any predecessor Licensee. Licensee 0051 * must include a prominent statement that the modification is derived, 0052 * directly or indirectly, from Original Intel Code. 0053 * 0054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 0055 * Redistribution of source code of any substantial portion of the Covered 0056 * Code or modification without rights to further distribute source must 0057 * include the following Disclaimer and Export Compliance provision in the 0058 * documentation and/or other materials provided with distribution. In 0059 * addition, Licensee may not authorize further sublicense of source of any 0060 * portion of the Covered Code, and must include terms to the effect that the 0061 * license from Licensee to its licensee is limited to the intellectual 0062 * property embodied in the software Licensee provides to its licensee, and 0063 * not to intellectual property embodied in modifications its licensee may 0064 * make. 0065 * 0066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 0067 * substantial portion of the Covered Code or modification must reproduce the 0068 * above Copyright Notice, and the following Disclaimer and Export Compliance 0069 * provision in the documentation and/or other materials provided with the 0070 * distribution. 0071 * 0072 * 3.4. Intel retains all right, title, and interest in and to the Original 0073 * Intel Code. 0074 * 0075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 0076 * Intel shall be used in advertising or otherwise to promote the sale, use or 0077 * other dealings in products derived from or relating to the Covered Code 0078 * without prior written authorization from Intel. 0079 * 0080 * 4. Disclaimer and Export Compliance 0081 * 0082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 0083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 0084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 0085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 0086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 0087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 0088 * PARTICULAR PURPOSE. 0089 * 0090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 0091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 0092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 0093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 0094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 0095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 0096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 0097 * LIMITED REMEDY. 0098 * 0099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 0100 * software or system incorporating such software without first obtaining any 0101 * required license or other approval from the U. S. Department of Commerce or 0102 * any other agency or department of the United States Government. In the 0103 * event Licensee exports any such software from the United States or 0104 * re-exports any such software from a foreign destination, Licensee shall 0105 * ensure that the distribution and export/re-export of the software is in 0106 * compliance with all laws, regulations, orders, or other restrictions of the 0107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 0108 * any of its subsidiaries will export/re-export any technical data, process, 0109 * software, or service, directly or indirectly, to any country for which the 0110 * United States government or any agency thereof requires an export license, 0111 * other governmental approval, or letter of assurance, without first obtaining 0112 * such license, approval or letter. 0113 * 0114 ***************************************************************************** 0115 * 0116 * Alternatively, you may choose to be licensed under the terms of the 0117 * following license: 0118 * 0119 * Redistribution and use in source and binary forms, with or without 0120 * modification, are permitted provided that the following conditions 0121 * are met: 0122 * 1. Redistributions of source code must retain the above copyright 0123 * notice, this list of conditions, and the following disclaimer, 0124 * without modification. 0125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 0126 * substantially similar to the "NO WARRANTY" disclaimer below 0127 * ("Disclaimer") and any redistribution must be conditioned upon 0128 * including a substantially similar Disclaimer requirement for further 0129 * binary redistribution. 0130 * 3. Neither the names of the above-listed copyright holders nor the names 0131 * of any contributors may be used to endorse or promote products derived 0132 * from this software without specific prior written permission. 0133 * 0134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0145 * 0146 * Alternatively, you may choose to be licensed under the terms of the 0147 * GNU General Public License ("GPL") version 2 as published by the Free 0148 * Software Foundation. 0149 * 0150 *****************************************************************************/ 0151 0152 #include "acpi.h" 0153 #include "accommon.h" 0154 #include "acnamesp.h" 0155 0156 #ifdef ACPI_ASL_COMPILER 0157 #include "amlcode.h" 0158 #endif 0159 0160 #define _COMPONENT ACPI_NAMESPACE 0161 ACPI_MODULE_NAME ("nssearch") 0162 0163 /* Local prototypes */ 0164 0165 static ACPI_STATUS 0166 AcpiNsSearchParentTree ( 0167 UINT32 TargetName, 0168 ACPI_NAMESPACE_NODE *Node, 0169 ACPI_OBJECT_TYPE Type, 0170 ACPI_NAMESPACE_NODE **ReturnNode); 0171 0172 0173 /******************************************************************************* 0174 * 0175 * FUNCTION: AcpiNsSearchOneScope 0176 * 0177 * PARAMETERS: TargetName - Ascii ACPI name to search for 0178 * ParentNode - Starting node where search will begin 0179 * Type - Object type to match 0180 * ReturnNode - Where the matched Named obj is returned 0181 * 0182 * RETURN: Status 0183 * 0184 * DESCRIPTION: Search a single level of the namespace. Performs a 0185 * simple search of the specified level, and does not add 0186 * entries or search parents. 0187 * 0188 * 0189 * Named object lists are built (and subsequently dumped) in the 0190 * order in which the names are encountered during the namespace load; 0191 * 0192 * All namespace searching is linear in this implementation, but 0193 * could be easily modified to support any improved search 0194 * algorithm. However, the linear search was chosen for simplicity 0195 * and because the trees are small and the other interpreter 0196 * execution overhead is relatively high. 0197 * 0198 * Note: CPU execution analysis has shown that the AML interpreter spends 0199 * a very small percentage of its time searching the namespace. Therefore, 0200 * the linear search seems to be sufficient, as there would seem to be 0201 * little value in improving the search. 0202 * 0203 ******************************************************************************/ 0204 0205 ACPI_STATUS 0206 AcpiNsSearchOneScope ( 0207 UINT32 TargetName, 0208 ACPI_NAMESPACE_NODE *ParentNode, 0209 ACPI_OBJECT_TYPE Type, 0210 ACPI_NAMESPACE_NODE **ReturnNode) 0211 { 0212 ACPI_NAMESPACE_NODE *Node; 0213 0214 0215 ACPI_FUNCTION_TRACE (NsSearchOneScope); 0216 0217 0218 #ifdef ACPI_DEBUG_OUTPUT 0219 if (ACPI_LV_NAMES & AcpiDbgLevel) 0220 { 0221 char *ScopeName; 0222 0223 ScopeName = AcpiNsGetNormalizedPathname (ParentNode, TRUE); 0224 if (ScopeName) 0225 { 0226 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 0227 "Searching %s (%p) For [%4.4s] (%s)\n", 0228 ScopeName, ParentNode, ACPI_CAST_PTR (char, &TargetName), 0229 AcpiUtGetTypeName (Type))); 0230 0231 ACPI_FREE (ScopeName); 0232 } 0233 } 0234 #endif 0235 0236 /* 0237 * Search for name at this namespace level, which is to say that we 0238 * must search for the name among the children of this object 0239 */ 0240 Node = ParentNode->Child; 0241 while (Node) 0242 { 0243 /* Check for match against the name */ 0244 0245 if (Node->Name.Integer == TargetName) 0246 { 0247 /* Resolve a control method alias if any */ 0248 0249 if (AcpiNsGetType (Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) 0250 { 0251 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object); 0252 } 0253 0254 /* Found matching entry */ 0255 0256 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 0257 "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n", 0258 ACPI_CAST_PTR (char, &TargetName), 0259 AcpiUtGetTypeName (Node->Type), 0260 Node, AcpiUtGetNodeName (ParentNode), ParentNode)); 0261 0262 *ReturnNode = Node; 0263 return_ACPI_STATUS (AE_OK); 0264 } 0265 0266 /* Didn't match name, move on to the next peer object */ 0267 0268 Node = Node->Peer; 0269 } 0270 0271 /* Searched entire namespace level, not found */ 0272 0273 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 0274 "Name [%4.4s] (%s) not found in search in scope [%4.4s] " 0275 "%p first child %p\n", 0276 ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type), 0277 AcpiUtGetNodeName (ParentNode), ParentNode, ParentNode->Child)); 0278 0279 return_ACPI_STATUS (AE_NOT_FOUND); 0280 } 0281 0282 0283 /******************************************************************************* 0284 * 0285 * FUNCTION: AcpiNsSearchParentTree 0286 * 0287 * PARAMETERS: TargetName - Ascii ACPI name to search for 0288 * Node - Starting node where search will begin 0289 * Type - Object type to match 0290 * ReturnNode - Where the matched Node is returned 0291 * 0292 * RETURN: Status 0293 * 0294 * DESCRIPTION: Called when a name has not been found in the current namespace 0295 * level. Before adding it or giving up, ACPI scope rules require 0296 * searching enclosing scopes in cases identified by AcpiNsLocal(). 0297 * 0298 * "A name is located by finding the matching name in the current 0299 * name space, and then in the parent name space. If the parent 0300 * name space does not contain the name, the search continues 0301 * recursively until either the name is found or the name space 0302 * does not have a parent (the root of the name space). This 0303 * indicates that the name is not found" (From ACPI Specification, 0304 * section 5.3) 0305 * 0306 ******************************************************************************/ 0307 0308 static ACPI_STATUS 0309 AcpiNsSearchParentTree ( 0310 UINT32 TargetName, 0311 ACPI_NAMESPACE_NODE *Node, 0312 ACPI_OBJECT_TYPE Type, 0313 ACPI_NAMESPACE_NODE **ReturnNode) 0314 { 0315 ACPI_STATUS Status; 0316 ACPI_NAMESPACE_NODE *ParentNode; 0317 0318 0319 ACPI_FUNCTION_TRACE (NsSearchParentTree); 0320 0321 0322 ParentNode = Node->Parent; 0323 0324 /* 0325 * If there is no parent (i.e., we are at the root) or type is "local", 0326 * we won't be searching the parent tree. 0327 */ 0328 if (!ParentNode) 0329 { 0330 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] has no parent\n", 0331 ACPI_CAST_PTR (char, &TargetName))); 0332 return_ACPI_STATUS (AE_NOT_FOUND); 0333 } 0334 0335 if (AcpiNsLocal (Type)) 0336 { 0337 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 0338 "[%4.4s] type [%s] must be local to this scope (no parent search)\n", 0339 ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type))); 0340 return_ACPI_STATUS (AE_NOT_FOUND); 0341 } 0342 0343 /* Search the parent tree */ 0344 0345 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 0346 "Searching parent [%4.4s] for [%4.4s]\n", 0347 AcpiUtGetNodeName (ParentNode), ACPI_CAST_PTR (char, &TargetName))); 0348 0349 /* Search parents until target is found or we have backed up to the root */ 0350 0351 while (ParentNode) 0352 { 0353 /* 0354 * Search parent scope. Use TYPE_ANY because we don't care about the 0355 * object type at this point, we only care about the existence of 0356 * the actual name we are searching for. Typechecking comes later. 0357 */ 0358 Status = AcpiNsSearchOneScope ( 0359 TargetName, ParentNode, ACPI_TYPE_ANY, ReturnNode); 0360 if (ACPI_SUCCESS (Status)) 0361 { 0362 return_ACPI_STATUS (Status); 0363 } 0364 0365 /* Not found here, go up another level (until we reach the root) */ 0366 0367 ParentNode = ParentNode->Parent; 0368 } 0369 0370 /* Not found in parent tree */ 0371 0372 return_ACPI_STATUS (AE_NOT_FOUND); 0373 } 0374 0375 0376 /******************************************************************************* 0377 * 0378 * FUNCTION: AcpiNsSearchAndEnter 0379 * 0380 * PARAMETERS: TargetName - Ascii ACPI name to search for (4 chars) 0381 * WalkState - Current state of the walk 0382 * Node - Starting node where search will begin 0383 * InterpreterMode - Add names only in ACPI_MODE_LOAD_PASS_x. 0384 * Otherwise,search only. 0385 * Type - Object type to match 0386 * Flags - Flags describing the search restrictions 0387 * ReturnNode - Where the Node is returned 0388 * 0389 * RETURN: Status 0390 * 0391 * DESCRIPTION: Search for a name segment in a single namespace level, 0392 * optionally adding it if it is not found. If the passed 0393 * Type is not Any and the type previously stored in the 0394 * entry was Any (i.e. unknown), update the stored type. 0395 * 0396 * In ACPI_IMODE_EXECUTE, search only. 0397 * In other modes, search and add if not found. 0398 * 0399 ******************************************************************************/ 0400 0401 ACPI_STATUS 0402 AcpiNsSearchAndEnter ( 0403 UINT32 TargetName, 0404 ACPI_WALK_STATE *WalkState, 0405 ACPI_NAMESPACE_NODE *Node, 0406 ACPI_INTERPRETER_MODE InterpreterMode, 0407 ACPI_OBJECT_TYPE Type, 0408 UINT32 Flags, 0409 ACPI_NAMESPACE_NODE **ReturnNode) 0410 { 0411 ACPI_STATUS Status; 0412 ACPI_NAMESPACE_NODE *NewNode; 0413 0414 0415 ACPI_FUNCTION_TRACE (NsSearchAndEnter); 0416 0417 0418 /* Parameter validation */ 0419 0420 if (!Node || !TargetName || !ReturnNode) 0421 { 0422 ACPI_ERROR ((AE_INFO, 0423 "Null parameter: Node %p Name 0x%X ReturnNode %p", 0424 Node, TargetName, ReturnNode)); 0425 return_ACPI_STATUS (AE_BAD_PARAMETER); 0426 } 0427 0428 /* 0429 * Name must consist of valid ACPI characters. We will repair the name if 0430 * necessary because we don't want to abort because of this, but we want 0431 * all namespace names to be printable. A warning message is appropriate. 0432 * 0433 * This issue came up because there are in fact machines that exhibit 0434 * this problem, and we want to be able to enable ACPI support for them, 0435 * even though there are a few bad names. 0436 */ 0437 AcpiUtRepairName (ACPI_CAST_PTR (char, &TargetName)); 0438 0439 /* Try to find the name in the namespace level specified by the caller */ 0440 0441 *ReturnNode = ACPI_ENTRY_NOT_FOUND; 0442 Status = AcpiNsSearchOneScope (TargetName, Node, Type, ReturnNode); 0443 if (Status != AE_NOT_FOUND) 0444 { 0445 /* 0446 * If we found it AND the request specifies that a find is an error, 0447 * return the error 0448 */ 0449 if (Status == AE_OK) 0450 { 0451 /* The node was found in the namespace */ 0452 0453 /* 0454 * If the namespace override feature is enabled for this node, 0455 * delete any existing attached sub-object and make the node 0456 * look like a new node that is owned by the override table. 0457 */ 0458 if (Flags & ACPI_NS_OVERRIDE_IF_FOUND) 0459 { 0460 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 0461 "Namespace override: %4.4s pass %u type %X Owner %X\n", 0462 ACPI_CAST_PTR(char, &TargetName), InterpreterMode, 0463 (*ReturnNode)->Type, WalkState->OwnerId)); 0464 0465 AcpiNsDeleteChildren (*ReturnNode); 0466 if (AcpiGbl_RuntimeNamespaceOverride) 0467 { 0468 AcpiUtRemoveReference ((*ReturnNode)->Object); 0469 (*ReturnNode)->Object = NULL; 0470 (*ReturnNode)->OwnerId = WalkState->OwnerId; 0471 } 0472 else 0473 { 0474 AcpiNsRemoveNode (*ReturnNode); 0475 *ReturnNode = ACPI_ENTRY_NOT_FOUND; 0476 } 0477 } 0478 0479 /* Return an error if we don't expect to find the object */ 0480 0481 else if (Flags & ACPI_NS_ERROR_IF_FOUND) 0482 { 0483 Status = AE_ALREADY_EXISTS; 0484 } 0485 } 0486 0487 #ifdef ACPI_ASL_COMPILER 0488 if (*ReturnNode && (*ReturnNode)->Type == ACPI_TYPE_ANY) 0489 { 0490 (*ReturnNode)->Flags |= ANOBJ_IS_EXTERNAL; 0491 } 0492 #endif 0493 0494 /* Either found it or there was an error: finished either way */ 0495 0496 return_ACPI_STATUS (Status); 0497 } 0498 0499 /* 0500 * The name was not found. If we are NOT performing the first pass 0501 * (name entry) of loading the namespace, search the parent tree (all the 0502 * way to the root if necessary.) We don't want to perform the parent 0503 * search when the namespace is actually being loaded. We want to perform 0504 * the search when namespace references are being resolved (load pass 2) 0505 * and during the execution phase. 0506 */ 0507 if ((InterpreterMode != ACPI_IMODE_LOAD_PASS1) && 0508 (Flags & ACPI_NS_SEARCH_PARENT)) 0509 { 0510 /* 0511 * Not found at this level - search parent tree according to the 0512 * ACPI specification 0513 */ 0514 Status = AcpiNsSearchParentTree (TargetName, Node, Type, ReturnNode); 0515 if (ACPI_SUCCESS (Status)) 0516 { 0517 return_ACPI_STATUS (Status); 0518 } 0519 } 0520 0521 /* In execute mode, just search, never add names. Exit now */ 0522 0523 if (InterpreterMode == ACPI_IMODE_EXECUTE) 0524 { 0525 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 0526 "%4.4s Not found in %p [Not adding]\n", 0527 ACPI_CAST_PTR (char, &TargetName), Node)); 0528 0529 return_ACPI_STATUS (AE_NOT_FOUND); 0530 } 0531 0532 /* Create the new named object */ 0533 0534 NewNode = AcpiNsCreateNode (TargetName); 0535 if (!NewNode) 0536 { 0537 return_ACPI_STATUS (AE_NO_MEMORY); 0538 } 0539 0540 #ifdef ACPI_ASL_COMPILER 0541 0542 /* Node is an object defined by an External() statement */ 0543 0544 if (Flags & ACPI_NS_EXTERNAL || 0545 (WalkState && WalkState->Opcode == AML_SCOPE_OP)) 0546 { 0547 NewNode->Flags |= ANOBJ_IS_EXTERNAL; 0548 } 0549 #endif 0550 0551 if (Flags & ACPI_NS_TEMPORARY) 0552 { 0553 NewNode->Flags |= ANOBJ_TEMPORARY; 0554 } 0555 0556 /* Install the new object into the parent's list of children */ 0557 0558 AcpiNsInstallNode (WalkState, Node, NewNode, Type); 0559 *ReturnNode = NewNode; 0560 return_ACPI_STATUS (AE_OK); 0561 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |