1 /******************************************************************************
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2019, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nsload")
55 /* Local prototypes */
57 #ifdef ACPI_FUTURE_IMPLEMENTATION
59 AcpiNsUnloadNamespace (
64 ACPI_HANDLE StartHandle
);
68 /*******************************************************************************
70 * FUNCTION: AcpiNsLoadTable
72 * PARAMETERS: TableIndex - Index for table to be loaded
73 * Node - Owning NS node
77 * DESCRIPTION: Load one ACPI table into the namespace
79 ******************************************************************************/
84 ACPI_NAMESPACE_NODE
*Node
)
89 ACPI_FUNCTION_TRACE (NsLoadTable
);
92 /* If table already loaded into namespace, just return */
94 if (AcpiTbIsTableLoaded (TableIndex
))
96 Status
= AE_ALREADY_EXISTS
;
100 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
101 "**** Loading table into namespace ****\n"));
103 Status
= AcpiTbAllocateOwnerId (TableIndex
);
104 if (ACPI_FAILURE (Status
))
110 * Parse the table and load the namespace with all named
111 * objects found within. Control methods are NOT parsed
112 * at this time. In fact, the control methods cannot be
113 * parsed until the entire namespace is loaded, because
114 * if a control method makes a forward reference (call)
115 * to another control method, we can't continue parsing
116 * because we don't know how many arguments to parse next!
118 Status
= AcpiNsParseTable (TableIndex
, Node
);
119 if (ACPI_SUCCESS (Status
))
121 AcpiTbSetTableLoadedFlag (TableIndex
, TRUE
);
126 * On error, delete any namespace objects created by this table.
127 * We cannot initialize these objects, so delete them. There are
128 * a couple of expecially bad cases:
129 * AE_ALREADY_EXISTS - namespace collision.
130 * AE_NOT_FOUND - the target of a Scope operator does not
131 * exist. This target of Scope must already exist in the
132 * namespace, as per the ACPI specification.
134 AcpiNsDeleteNamespaceByOwner (
135 AcpiGbl_RootTableList
.Tables
[TableIndex
].OwnerId
);
137 AcpiTbReleaseOwnerId (TableIndex
);
138 return_ACPI_STATUS (Status
);
142 if (ACPI_FAILURE (Status
))
144 return_ACPI_STATUS (Status
);
148 * Now we can parse the control methods. We always parse
149 * them here for a sanity check, and if configured for
150 * just-in-time parsing, we delete the control method
153 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
154 "**** Begin Table Object Initialization\n"));
156 AcpiExEnterInterpreter ();
157 Status
= AcpiDsInitializeObjects (TableIndex
, Node
);
158 AcpiExExitInterpreter ();
160 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
161 "**** Completed Table Object Initialization\n"));
164 * This case handles the legacy option that groups all module-level
165 * code blocks together and defers execution until all of the tables
166 * are loaded. Execute all of these blocks at this time.
167 * Execute any module-level code that was detected during the table
170 * Note: this option is deprecated and will be eliminated in the
171 * future. Use of this option can cause problems with AML code that
172 * depends upon in-order immediate execution of module-level code.
174 AcpiNsExecModuleCodeList ();
175 return_ACPI_STATUS (Status
);
179 #ifdef ACPI_OBSOLETE_FUNCTIONS
180 /*******************************************************************************
182 * FUNCTION: AcpiLoadNamespace
188 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
189 * (DSDT points to either the BIOS or a buffer.)
191 ******************************************************************************/
194 AcpiNsLoadNamespace (
200 ACPI_FUNCTION_TRACE (AcpiLoadNameSpace
);
203 /* There must be at least a DSDT installed */
205 if (AcpiGbl_DSDT
== NULL
)
207 ACPI_ERROR ((AE_INFO
, "DSDT is not in memory"));
208 return_ACPI_STATUS (AE_NO_ACPI_TABLES
);
212 * Load the namespace. The DSDT is required,
213 * but the SSDT and PSDT tables are optional.
215 Status
= AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT
);
216 if (ACPI_FAILURE (Status
))
218 return_ACPI_STATUS (Status
);
221 /* Ignore exceptions from these */
223 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT
);
224 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT
);
226 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
227 "ACPI Namespace successfully loaded at root %p\n",
230 return_ACPI_STATUS (Status
);
234 #ifdef ACPI_FUTURE_IMPLEMENTATION
235 /*******************************************************************************
237 * FUNCTION: AcpiNsDeleteSubtree
239 * PARAMETERS: StartHandle - Handle in namespace where search begins
243 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
244 * all objects, entries, and scopes in the entire subtree.
246 * Namespace/Interpreter should be locked or the subsystem should
247 * be in shutdown before this routine is called.
249 ******************************************************************************/
252 AcpiNsDeleteSubtree (
253 ACPI_HANDLE StartHandle
)
256 ACPI_HANDLE ChildHandle
;
257 ACPI_HANDLE ParentHandle
;
258 ACPI_HANDLE NextChildHandle
;
263 ACPI_FUNCTION_TRACE (NsDeleteSubtree
);
266 ParentHandle
= StartHandle
;
271 * Traverse the tree of objects until we bubble back up
272 * to where we started.
276 /* Attempt to get the next object in this scope */
278 Status
= AcpiGetNextObject (ACPI_TYPE_ANY
, ParentHandle
,
279 ChildHandle
, &NextChildHandle
);
281 ChildHandle
= NextChildHandle
;
283 /* Did we get a new object? */
285 if (ACPI_SUCCESS (Status
))
287 /* Check if this object has any children */
289 if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY
, ChildHandle
,
293 * There is at least one child of this object,
297 ParentHandle
= ChildHandle
;
304 * No more children in this object, go back up to
305 * the object's parent
309 /* Delete all children now */
311 AcpiNsDeleteChildren (ChildHandle
);
313 ChildHandle
= ParentHandle
;
314 Status
= AcpiGetParent (ParentHandle
, &ParentHandle
);
315 if (ACPI_FAILURE (Status
))
317 return_ACPI_STATUS (Status
);
322 /* Now delete the starting object, and we are done */
324 AcpiNsRemoveNode (ChildHandle
);
325 return_ACPI_STATUS (AE_OK
);
329 /*******************************************************************************
331 * FUNCTION: AcpiNsUnloadNameSpace
333 * PARAMETERS: Handle - Root of namespace subtree to be deleted
337 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
338 * event. Deletes an entire subtree starting from (and
339 * including) the given handle.
341 ******************************************************************************/
344 AcpiNsUnloadNamespace (
350 ACPI_FUNCTION_TRACE (NsUnloadNameSpace
);
353 /* Parameter validation */
355 if (!AcpiGbl_RootNode
)
357 return_ACPI_STATUS (AE_NO_NAMESPACE
);
362 return_ACPI_STATUS (AE_BAD_PARAMETER
);
365 /* This function does the real work */
367 Status
= AcpiNsDeleteSubtree (Handle
);
368 return_ACPI_STATUS (Status
);