1 /******************************************************************************
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
49 #include <contrib/dev/acpica/include/acdispat.h>
50 #include <contrib/dev/acpica/include/actables.h>
53 #define _COMPONENT ACPI_NAMESPACE
54 ACPI_MODULE_NAME ("nsload")
56 /* Local prototypes */
58 #ifdef ACPI_FUTURE_IMPLEMENTATION
60 AcpiNsUnloadNamespace (
65 ACPI_HANDLE StartHandle);
69 #ifndef ACPI_NO_METHOD_EXECUTION
70 /*******************************************************************************
72 * FUNCTION: AcpiNsLoadTable
74 * PARAMETERS: TableIndex - Index for table to be loaded
75 * Node - Owning NS node
79 * DESCRIPTION: Load one ACPI table into the namespace
81 ******************************************************************************/
86 ACPI_NAMESPACE_NODE *Node)
91 ACPI_FUNCTION_TRACE (NsLoadTable);
95 * Parse the table and load the namespace with all named
96 * objects found within. Control methods are NOT parsed
97 * at this time. In fact, the control methods cannot be
98 * parsed until the entire namespace is loaded, because
99 * if a control method makes a forward reference (call)
100 * to another control method, we can't continue parsing
101 * because we don't know how many arguments to parse next!
103 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
104 if (ACPI_FAILURE (Status))
106 return_ACPI_STATUS (Status);
109 /* If table already loaded into namespace, just return */
111 if (AcpiTbIsTableLoaded (TableIndex))
113 Status = AE_ALREADY_EXISTS;
117 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
118 "**** Loading table into namespace ****\n"));
120 Status = AcpiTbAllocateOwnerId (TableIndex);
121 if (ACPI_FAILURE (Status))
126 Status = AcpiNsParseTable (TableIndex, Node);
127 if (ACPI_SUCCESS (Status))
129 AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
133 (void) AcpiTbReleaseOwnerId (TableIndex);
137 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
139 if (ACPI_FAILURE (Status))
141 return_ACPI_STATUS (Status);
145 * Now we can parse the control methods. We always parse
146 * them here for a sanity check, and if configured for
147 * just-in-time parsing, we delete the control method
150 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
151 "**** Begin Table Method Parsing and Object Initialization\n"));
153 Status = AcpiDsInitializeObjects (TableIndex, Node);
155 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
156 "**** Completed Table Method Parsing and Object Initialization\n"));
158 return_ACPI_STATUS (Status);
162 #ifdef ACPI_OBSOLETE_FUNCTIONS
163 /*******************************************************************************
165 * FUNCTION: AcpiLoadNamespace
171 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
172 * (DSDT points to either the BIOS or a buffer.)
174 ******************************************************************************/
177 AcpiNsLoadNamespace (
183 ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
186 /* There must be at least a DSDT installed */
188 if (AcpiGbl_DSDT == NULL)
190 ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
191 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
195 * Load the namespace. The DSDT is required,
196 * but the SSDT and PSDT tables are optional.
198 Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
199 if (ACPI_FAILURE (Status))
201 return_ACPI_STATUS (Status);
204 /* Ignore exceptions from these */
206 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
207 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
209 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
210 "ACPI Namespace successfully loaded at root %p\n",
213 return_ACPI_STATUS (Status);
217 #ifdef ACPI_FUTURE_IMPLEMENTATION
218 /*******************************************************************************
220 * FUNCTION: AcpiNsDeleteSubtree
222 * PARAMETERS: StartHandle - Handle in namespace where search begins
226 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
227 * all objects, entries, and scopes in the entire subtree.
229 * Namespace/Interpreter should be locked or the subsystem should
230 * be in shutdown before this routine is called.
232 ******************************************************************************/
235 AcpiNsDeleteSubtree (
236 ACPI_HANDLE StartHandle)
239 ACPI_HANDLE ChildHandle;
240 ACPI_HANDLE ParentHandle;
241 ACPI_HANDLE NextChildHandle;
246 ACPI_FUNCTION_TRACE (NsDeleteSubtree);
249 ParentHandle = StartHandle;
254 * Traverse the tree of objects until we bubble back up
255 * to where we started.
259 /* Attempt to get the next object in this scope */
261 Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
262 ChildHandle, &NextChildHandle);
264 ChildHandle = NextChildHandle;
266 /* Did we get a new object? */
268 if (ACPI_SUCCESS (Status))
270 /* Check if this object has any children */
272 if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
276 * There is at least one child of this object,
280 ParentHandle = ChildHandle;
287 * No more children in this object, go back up to
288 * the object's parent
292 /* Delete all children now */
294 AcpiNsDeleteChildren (ChildHandle);
296 ChildHandle = ParentHandle;
297 Status = AcpiGetParent (ParentHandle, &ParentHandle);
298 if (ACPI_FAILURE (Status))
300 return_ACPI_STATUS (Status);
305 /* Now delete the starting object, and we are done */
307 AcpiNsRemoveNode (ChildHandle);
308 return_ACPI_STATUS (AE_OK);
312 /*******************************************************************************
314 * FUNCTION: AcpiNsUnloadNameSpace
316 * PARAMETERS: Handle - Root of namespace subtree to be deleted
320 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
321 * event. Deletes an entire subtree starting from (and
322 * including) the given handle.
324 ******************************************************************************/
327 AcpiNsUnloadNamespace (
333 ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
336 /* Parameter validation */
338 if (!AcpiGbl_RootNode)
340 return_ACPI_STATUS (AE_NO_NAMESPACE);
345 return_ACPI_STATUS (AE_BAD_PARAMETER);
348 /* This function does the real work */
350 Status = AcpiNsDeleteSubtree (Handle);
352 return_ACPI_STATUS (Status);