1 /******************************************************************************
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsload")
54 /* Local prototypes */
56 #ifdef ACPI_FUTURE_IMPLEMENTATION
58 AcpiNsUnloadNamespace (
63 ACPI_HANDLE StartHandle);
67 #ifndef ACPI_NO_METHOD_EXECUTION
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);
93 * Parse the table and load the namespace with all named
94 * objects found within. Control methods are NOT parsed
95 * at this time. In fact, the control methods cannot be
96 * parsed until the entire namespace is loaded, because
97 * if a control method makes a forward reference (call)
98 * to another control method, we can't continue parsing
99 * because we don't know how many arguments to parse next!
101 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
102 if (ACPI_FAILURE (Status))
104 return_ACPI_STATUS (Status);
107 /* If table already loaded into namespace, just return */
109 if (AcpiTbIsTableLoaded (TableIndex))
111 Status = AE_ALREADY_EXISTS;
115 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
116 "**** Loading table into namespace ****\n"));
118 Status = AcpiTbAllocateOwnerId (TableIndex);
119 if (ACPI_FAILURE (Status))
124 Status = AcpiNsParseTable (TableIndex, Node);
125 if (ACPI_SUCCESS (Status))
127 AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
131 (void) AcpiTbReleaseOwnerId (TableIndex);
135 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
137 if (ACPI_FAILURE (Status))
139 return_ACPI_STATUS (Status);
143 * Now we can parse the control methods. We always parse
144 * them here for a sanity check, and if configured for
145 * just-in-time parsing, we delete the control method
148 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
149 "**** Begin Table Object Initialization\n"));
151 Status = AcpiDsInitializeObjects (TableIndex, Node);
153 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
154 "**** Completed Table Object Initialization\n"));
156 return_ACPI_STATUS (Status);
160 #ifdef ACPI_OBSOLETE_FUNCTIONS
161 /*******************************************************************************
163 * FUNCTION: AcpiLoadNamespace
169 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
170 * (DSDT points to either the BIOS or a buffer.)
172 ******************************************************************************/
175 AcpiNsLoadNamespace (
181 ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
184 /* There must be at least a DSDT installed */
186 if (AcpiGbl_DSDT == NULL)
188 ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
189 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
193 * Load the namespace. The DSDT is required,
194 * but the SSDT and PSDT tables are optional.
196 Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
197 if (ACPI_FAILURE (Status))
199 return_ACPI_STATUS (Status);
202 /* Ignore exceptions from these */
204 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
205 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
208 "ACPI Namespace successfully loaded at root %p\n",
211 return_ACPI_STATUS (Status);
215 #ifdef ACPI_FUTURE_IMPLEMENTATION
216 /*******************************************************************************
218 * FUNCTION: AcpiNsDeleteSubtree
220 * PARAMETERS: StartHandle - Handle in namespace where search begins
224 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
225 * all objects, entries, and scopes in the entire subtree.
227 * Namespace/Interpreter should be locked or the subsystem should
228 * be in shutdown before this routine is called.
230 ******************************************************************************/
233 AcpiNsDeleteSubtree (
234 ACPI_HANDLE StartHandle)
237 ACPI_HANDLE ChildHandle;
238 ACPI_HANDLE ParentHandle;
239 ACPI_HANDLE NextChildHandle;
244 ACPI_FUNCTION_TRACE (NsDeleteSubtree);
247 ParentHandle = StartHandle;
252 * Traverse the tree of objects until we bubble back up
253 * to where we started.
257 /* Attempt to get the next object in this scope */
259 Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
260 ChildHandle, &NextChildHandle);
262 ChildHandle = NextChildHandle;
264 /* Did we get a new object? */
266 if (ACPI_SUCCESS (Status))
268 /* Check if this object has any children */
270 if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
274 * There is at least one child of this object,
278 ParentHandle = ChildHandle;
285 * No more children in this object, go back up to
286 * the object's parent
290 /* Delete all children now */
292 AcpiNsDeleteChildren (ChildHandle);
294 ChildHandle = ParentHandle;
295 Status = AcpiGetParent (ParentHandle, &ParentHandle);
296 if (ACPI_FAILURE (Status))
298 return_ACPI_STATUS (Status);
303 /* Now delete the starting object, and we are done */
305 AcpiNsRemoveNode (ChildHandle);
306 return_ACPI_STATUS (AE_OK);
310 /*******************************************************************************
312 * FUNCTION: AcpiNsUnloadNameSpace
314 * PARAMETERS: Handle - Root of namespace subtree to be deleted
318 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
319 * event. Deletes an entire subtree starting from (and
320 * including) the given handle.
322 ******************************************************************************/
325 AcpiNsUnloadNamespace (
331 ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
334 /* Parameter validation */
336 if (!AcpiGbl_RootNode)
338 return_ACPI_STATUS (AE_NO_NAMESPACE);
343 return_ACPI_STATUS (AE_BAD_PARAMETER);
346 /* This function does the real work */
348 Status = AcpiNsDeleteSubtree (Handle);
350 return_ACPI_STATUS (Status);