1 /*******************************************************************************
3 * Module Name: nssearch - Namespace search
6 ******************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #define _COMPONENT ACPI_NAMESPACE
34 MODULE_NAME ("nssearch")
37 /*******************************************************************************
39 * FUNCTION: Acpi_ns_search_node
41 * PARAMETERS: *Target_name - Ascii ACPI name to search for
42 * *Node - Starting table where search will begin
43 * Type - Object type to match
44 * **Return_node - Where the matched Named obj is returned
48 * DESCRIPTION: Search a single namespace table. Performs a simple search,
49 * does not add entries or search parents.
52 * Named object lists are built (and subsequently dumped) in the
53 * order in which the names are encountered during the namespace load;
55 * All namespace searching is linear in this implementation, but
56 * could be easily modified to support any improved search
57 * algorithm. However, the linear search was chosen for simplicity
58 * and because the trees are small and the other interpreter
59 * execution overhead is relatively high.
61 ******************************************************************************/
66 ACPI_NAMESPACE_NODE
*node
,
67 OBJECT_TYPE_INTERNAL type
,
68 ACPI_NAMESPACE_NODE
**return_node
)
70 ACPI_NAMESPACE_NODE
*next_node
;
74 * Search for name in this table, which is to say that we must search
75 * for the name among the children of this object
78 next_node
= node
->child
;
80 /* Check for match against the name */
82 if (next_node
->name
== target_name
) {
84 * Found matching entry. Capture the type if appropriate, before
85 * returning the entry.
87 * The Def_field_defn and Bank_field_defn cases are actually looking up
88 * the Region in which the field will be defined
91 if ((INTERNAL_TYPE_DEF_FIELD_DEFN
== type
) ||
92 (INTERNAL_TYPE_BANK_FIELD_DEFN
== type
)) {
93 type
= ACPI_TYPE_REGION
;
97 * Scope, Def_any, and Index_field_defn are bogus "types" which do not
98 * actually have anything to do with the type of the name being
99 * looked up. For any other value of Type, if the type stored in
100 * the entry is Any (i.e. unknown), save the actual type.
103 if (type
!= INTERNAL_TYPE_SCOPE
&&
104 type
!= INTERNAL_TYPE_DEF_ANY
&&
105 type
!= INTERNAL_TYPE_INDEX_FIELD_DEFN
&&
106 next_node
->type
== ACPI_TYPE_ANY
) {
107 next_node
->type
= (u8
) type
;
110 *return_node
= next_node
;
116 * The last entry in the list points back to the parent,
117 * so a flag is used to indicate the end-of-list
119 if (next_node
->flags
& ANOBJ_END_OF_PEER_LIST
) {
120 /* Searched entire list, we are done */
125 /* Didn't match name, move on to the next peer object */
127 next_node
= next_node
->peer
;
131 /* Searched entire table, not found */
134 return (AE_NOT_FOUND
);
138 /*******************************************************************************
140 * FUNCTION: Acpi_ns_search_parent_tree
142 * PARAMETERS: *Target_name - Ascii ACPI name to search for
143 * *Node - Starting table where search will begin
144 * Type - Object type to match
145 * **Return_node - Where the matched Named Obj is returned
149 * DESCRIPTION: Called when a name has not been found in the current namespace
150 * table. Before adding it or giving up, ACPI scope rules require
151 * searching enclosing scopes in cases identified by Acpi_ns_local().
153 * "A name is located by finding the matching name in the current
154 * name space, and then in the parent name space. If the parent
155 * name space does not contain the name, the search continues
156 * recursively until either the name is found or the name space
157 * does not have a parent (the root of the name space). This
158 * indicates that the name is not found" (From ACPI Specification,
161 ******************************************************************************/
164 acpi_ns_search_parent_tree (
166 ACPI_NAMESPACE_NODE
*node
,
167 OBJECT_TYPE_INTERNAL type
,
168 ACPI_NAMESPACE_NODE
**return_node
)
171 ACPI_NAMESPACE_NODE
*parent_node
;
174 parent_node
= acpi_ns_get_parent_object (node
);
177 * If there is no parent (at the root) or type is "local", we won't be
178 * searching the parent tree.
180 if ((acpi_ns_local (type
)) ||
184 return (AE_NOT_FOUND
);
188 /* Search the parent tree */
191 * Search parents until found the target or we have backed up to
195 while (parent_node
) {
196 /* Search parent scope */
197 /* TBD: [Investigate] Why ACPI_TYPE_ANY? */
199 status
= acpi_ns_search_node (target_name
, parent_node
,
200 ACPI_TYPE_ANY
, return_node
);
202 if (ACPI_SUCCESS (status
)) {
207 * Not found here, go up another level
208 * (until we reach the root)
211 parent_node
= acpi_ns_get_parent_object (parent_node
);
215 /* Not found in parent tree */
217 return (AE_NOT_FOUND
);
221 /*******************************************************************************
223 * FUNCTION: Acpi_ns_search_and_enter
225 * PARAMETERS: Target_name - Ascii ACPI name to search for (4 chars)
226 * Walk_state - Current state of the walk
227 * *Node - Starting table where search will begin
228 * Interpreter_mode - Add names only in MODE_Load_pass_x.
229 * Otherwise,search only.
230 * Type - Object type to match
231 * Flags - Flags describing the search restrictions
232 * **Return_node - Where the Node is returned
236 * DESCRIPTION: Search for a name segment in a single name table,
237 * optionally adding it if it is not found. If the passed
238 * Type is not Any and the type previously stored in the
239 * entry was Any (i.e. unknown), update the stored type.
241 * In IMODE_EXECUTE, search only.
242 * In other modes, search and add if not found.
244 ******************************************************************************/
247 acpi_ns_search_and_enter (
249 ACPI_WALK_STATE
*walk_state
,
250 ACPI_NAMESPACE_NODE
*node
,
251 OPERATING_MODE interpreter_mode
,
252 OBJECT_TYPE_INTERNAL type
,
254 ACPI_NAMESPACE_NODE
**return_node
)
257 ACPI_NAMESPACE_NODE
*new_node
;
260 /* Parameter validation */
262 if (!node
|| !target_name
|| !return_node
) {
263 REPORT_ERROR (("Ns_search_and_enter: bad (null) parameter\n"));
264 return (AE_BAD_PARAMETER
);
268 /* Name must consist of printable characters */
270 if (!acpi_cm_valid_acpi_name (target_name
)) {
271 REPORT_ERROR (("Ns_search_and_enter: Bad character in ACPI Name\n"));
272 return (AE_BAD_CHARACTER
);
276 /* Try to find the name in the table specified by the caller */
278 *return_node
= ENTRY_NOT_FOUND
;
279 status
= acpi_ns_search_node (target_name
, node
,
281 if (status
!= AE_NOT_FOUND
) {
283 * If we found it AND the request specifies that a find is an error,
286 if ((status
== AE_OK
) &&
287 (flags
& NS_ERROR_IF_FOUND
)) {
292 * Either found it or there was an error
293 * -- finished either way
300 * Not found in the table. If we are NOT performing the
301 * first pass (name entry) of loading the namespace, search
302 * the parent tree (all the way to the root if necessary.)
303 * We don't want to perform the parent search when the
304 * namespace is actually being loaded. We want to perform
305 * the search when namespace references are being resolved
306 * (load pass 2) and during the execution phase.
309 if ((interpreter_mode
!= IMODE_LOAD_PASS1
) &&
310 (flags
& NS_SEARCH_PARENT
)) {
312 * Not found in table - search parent tree according
313 * to ACPI specification
316 status
= acpi_ns_search_parent_tree (target_name
, node
,
318 if (ACPI_SUCCESS (status
)) {
325 * In execute mode, just search, never add names. Exit now.
327 if (interpreter_mode
== IMODE_EXECUTE
) {
328 return (AE_NOT_FOUND
);
332 /* Create the new named object */
334 new_node
= acpi_ns_create_node (target_name
);
336 return (AE_NO_MEMORY
);
339 /* Install the new object into the parent's list of children */
341 acpi_ns_install_node (walk_state
, node
, new_node
, type
);
342 *return_node
= new_node
;