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
29 #define _COMPONENT ACPI_NAMESPACE
30 MODULE_NAME ("nssearch")
33 /*******************************************************************************
35 * FUNCTION: Acpi_ns_search_node
37 * PARAMETERS: *Target_name - Ascii ACPI name to search for
38 * *Node - Starting table where search will begin
39 * Type - Object type to match
40 * **Return_node - Where the matched Named obj is returned
44 * DESCRIPTION: Search a single namespace table. Performs a simple search,
45 * does not add entries or search parents.
48 * Named object lists are built (and subsequently dumped) in the
49 * order in which the names are encountered during the namespace load;
51 * All namespace searching is linear in this implementation, but
52 * could be easily modified to support any improved search
53 * algorithm. However, the linear search was chosen for simplicity
54 * and because the trees are small and the other interpreter
55 * execution overhead is relatively high.
57 ******************************************************************************/
62 ACPI_NAMESPACE_NODE
*node
,
63 OBJECT_TYPE_INTERNAL type
,
64 ACPI_NAMESPACE_NODE
**return_node
)
66 ACPI_NAMESPACE_NODE
*next_node
;
70 * Search for name in this table, which is to say that we must search
71 * for the name among the children of this object
74 next_node
= node
->child
;
76 /* Check for match against the name */
78 if (next_node
->name
== target_name
) {
80 * Found matching entry. Capture the type if appropriate, before
81 * returning the entry.
83 * The Def_field_defn and Bank_field_defn cases are actually looking up
84 * the Region in which the field will be defined
87 if ((INTERNAL_TYPE_DEF_FIELD_DEFN
== type
) ||
88 (INTERNAL_TYPE_BANK_FIELD_DEFN
== type
)) {
89 type
= ACPI_TYPE_REGION
;
93 * Scope, Def_any, and Index_field_defn are bogus "types" which do not
94 * actually have anything to do with the type of the name being
95 * looked up. For any other value of Type, if the type stored in
96 * the entry is Any (i.e. unknown), save the actual type.
99 if (type
!= INTERNAL_TYPE_SCOPE
&&
100 type
!= INTERNAL_TYPE_DEF_ANY
&&
101 type
!= INTERNAL_TYPE_INDEX_FIELD_DEFN
&&
102 next_node
->type
== ACPI_TYPE_ANY
) {
103 next_node
->type
= (u8
) type
;
106 *return_node
= next_node
;
112 * The last entry in the list points back to the parent,
113 * so a flag is used to indicate the end-of-list
115 if (next_node
->flags
& ANOBJ_END_OF_PEER_LIST
) {
116 /* Searched entire list, we are done */
121 /* Didn't match name, move on to the next peer object */
123 next_node
= next_node
->peer
;
127 /* Searched entire table, not found */
130 return (AE_NOT_FOUND
);
134 /*******************************************************************************
136 * FUNCTION: Acpi_ns_search_parent_tree
138 * PARAMETERS: *Target_name - Ascii ACPI name to search for
139 * *Node - Starting table where search will begin
140 * Type - Object type to match
141 * **Return_node - Where the matched Named Obj is returned
145 * DESCRIPTION: Called when a name has not been found in the current namespace
146 * table. Before adding it or giving up, ACPI scope rules require
147 * searching enclosing scopes in cases identified by Acpi_ns_local().
149 * "A name is located by finding the matching name in the current
150 * name space, and then in the parent name space. If the parent
151 * name space does not contain the name, the search continues
152 * recursively until either the name is found or the name space
153 * does not have a parent (the root of the name space). This
154 * indicates that the name is not found" (From ACPI Specification,
157 ******************************************************************************/
160 acpi_ns_search_parent_tree (
162 ACPI_NAMESPACE_NODE
*node
,
163 OBJECT_TYPE_INTERNAL type
,
164 ACPI_NAMESPACE_NODE
**return_node
)
167 ACPI_NAMESPACE_NODE
*parent_node
;
170 parent_node
= acpi_ns_get_parent_object (node
);
173 * If there is no parent (at the root) or type is "local", we won't be
174 * searching the parent tree.
176 if ((acpi_ns_local (type
)) ||
180 return (AE_NOT_FOUND
);
184 /* Search the parent tree */
187 * Search parents until found the target or we have backed up to
191 while (parent_node
) {
192 /* Search parent scope */
193 /* TBD: [Investigate] Why ACPI_TYPE_ANY? */
195 status
= acpi_ns_search_node (target_name
, parent_node
,
196 ACPI_TYPE_ANY
, return_node
);
198 if (ACPI_SUCCESS (status
)) {
203 * Not found here, go up another level
204 * (until we reach the root)
207 parent_node
= acpi_ns_get_parent_object (parent_node
);
211 /* Not found in parent tree */
213 return (AE_NOT_FOUND
);
217 /*******************************************************************************
219 * FUNCTION: Acpi_ns_search_and_enter
221 * PARAMETERS: Target_name - Ascii ACPI name to search for (4 chars)
222 * Walk_state - Current state of the walk
223 * *Node - Starting table where search will begin
224 * Interpreter_mode - Add names only in MODE_Load_pass_x.
225 * Otherwise,search only.
226 * Type - Object type to match
227 * Flags - Flags describing the search restrictions
228 * **Return_node - Where the Node is returned
232 * DESCRIPTION: Search for a name segment in a single name table,
233 * optionally adding it if it is not found. If the passed
234 * Type is not Any and the type previously stored in the
235 * entry was Any (i.e. unknown), update the stored type.
237 * In IMODE_EXECUTE, search only.
238 * In other modes, search and add if not found.
240 ******************************************************************************/
243 acpi_ns_search_and_enter (
245 ACPI_WALK_STATE
*walk_state
,
246 ACPI_NAMESPACE_NODE
*node
,
247 OPERATING_MODE interpreter_mode
,
248 OBJECT_TYPE_INTERNAL type
,
250 ACPI_NAMESPACE_NODE
**return_node
)
253 ACPI_NAMESPACE_NODE
*new_node
;
256 /* Parameter validation */
258 if (!node
|| !target_name
|| !return_node
) {
259 REPORT_ERROR (("Ns_search_and_enter: bad (null) parameter\n"));
260 return (AE_BAD_PARAMETER
);
264 /* Name must consist of printable characters */
266 if (!acpi_cm_valid_acpi_name (target_name
)) {
267 REPORT_ERROR (("Ns_search_and_enter: Bad character in ACPI Name\n"));
268 return (AE_BAD_CHARACTER
);
272 /* Try to find the name in the table specified by the caller */
274 *return_node
= ENTRY_NOT_FOUND
;
275 status
= acpi_ns_search_node (target_name
, node
,
277 if (status
!= AE_NOT_FOUND
) {
279 * If we found it AND the request specifies that a find is an error,
282 if ((status
== AE_OK
) &&
283 (flags
& NS_ERROR_IF_FOUND
)) {
288 * Either found it or there was an error
289 * -- finished either way
296 * Not found in the table. If we are NOT performing the
297 * first pass (name entry) of loading the namespace, search
298 * the parent tree (all the way to the root if necessary.)
299 * We don't want to perform the parent search when the
300 * namespace is actually being loaded. We want to perform
301 * the search when namespace references are being resolved
302 * (load pass 2) and during the execution phase.
305 if ((interpreter_mode
!= IMODE_LOAD_PASS1
) &&
306 (flags
& NS_SEARCH_PARENT
)) {
308 * Not found in table - search parent tree according
309 * to ACPI specification
312 status
= acpi_ns_search_parent_tree (target_name
, node
,
314 if (ACPI_SUCCESS (status
)) {
321 * In execute mode, just search, never add names. Exit now.
323 if (interpreter_mode
== IMODE_EXECUTE
) {
324 return (AE_NOT_FOUND
);
328 /* Create the new named object */
330 new_node
= acpi_ns_create_node (target_name
);
332 return (AE_NO_MEMORY
);
335 /* Install the new object into the parent's list of children */
337 acpi_ns_install_node (walk_state
, node
, new_node
, type
);
338 *return_node
= new_node
;