8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / uts / intel / io / acpica / namespace / nsload.c
blob9c899e784619287f57dea90e245ff9f99195919e
1 /******************************************************************************
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acnamesp.h"
47 #include "acdispat.h"
48 #include "actables.h"
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsload")
54 /* Local prototypes */
56 #ifdef ACPI_FUTURE_IMPLEMENTATION
57 ACPI_STATUS
58 AcpiNsUnloadNamespace (
59 ACPI_HANDLE Handle);
61 static ACPI_STATUS
62 AcpiNsDeleteSubtree (
63 ACPI_HANDLE StartHandle);
64 #endif
67 #ifndef ACPI_NO_METHOD_EXECUTION
68 /*******************************************************************************
70 * FUNCTION: AcpiNsLoadTable
72 * PARAMETERS: TableIndex - Index for table to be loaded
73 * Node - Owning NS node
75 * RETURN: Status
77 * DESCRIPTION: Load one ACPI table into the namespace
79 ******************************************************************************/
81 ACPI_STATUS
82 AcpiNsLoadTable (
83 UINT32 TableIndex,
84 ACPI_NAMESPACE_NODE *Node)
86 ACPI_STATUS Status;
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;
112 goto Unlock;
115 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
116 "**** Loading table into namespace ****\n"));
118 Status = AcpiTbAllocateOwnerId (TableIndex);
119 if (ACPI_FAILURE (Status))
121 goto Unlock;
124 Status = AcpiNsParseTable (TableIndex, Node);
125 if (ACPI_SUCCESS (Status))
127 AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
129 else
132 * On error, delete any namespace objects created by this table.
133 * We cannot initialize these objects, so delete them. There are
134 * a couple of expecially bad cases:
135 * AE_ALREADY_EXISTS - namespace collision.
136 * AE_NOT_FOUND - the target of a Scope operator does not
137 * exist. This target of Scope must already exist in the
138 * namespace, as per the ACPI specification.
140 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
141 AcpiNsDeleteNamespaceByOwner (
142 AcpiGbl_RootTableList.Tables[TableIndex].OwnerId);
144 AcpiTbReleaseOwnerId (TableIndex);
145 return_ACPI_STATUS (Status);
148 Unlock:
149 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
151 if (ACPI_FAILURE (Status))
153 return_ACPI_STATUS (Status);
157 * Now we can parse the control methods. We always parse
158 * them here for a sanity check, and if configured for
159 * just-in-time parsing, we delete the control method
160 * parse trees.
162 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
163 "**** Begin Table Object Initialization\n"));
165 Status = AcpiDsInitializeObjects (TableIndex, Node);
167 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
168 "**** Completed Table Object Initialization\n"));
171 * Execute any module-level code that was detected during the table load
172 * phase. Although illegal since ACPI 2.0, there are many machines that
173 * contain this type of code. Each block of detected executable AML code
174 * outside of any control method is wrapped with a temporary control
175 * method object and placed on a global list. The methods on this list
176 * are executed below.
178 * This case executes the module-level code for each table immediately
179 * after the table has been loaded. This provides compatibility with
180 * other ACPI implementations. Optionally, the execution can be deferred
181 * until later, see AcpiInitializeObjects.
183 if (!AcpiGbl_GroupModuleLevelCode)
185 AcpiNsExecModuleCodeList ();
188 return_ACPI_STATUS (Status);
192 #ifdef ACPI_OBSOLETE_FUNCTIONS
193 /*******************************************************************************
195 * FUNCTION: AcpiLoadNamespace
197 * PARAMETERS: None
199 * RETURN: Status
201 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
202 * (DSDT points to either the BIOS or a buffer.)
204 ******************************************************************************/
206 ACPI_STATUS
207 AcpiNsLoadNamespace (
208 void)
210 ACPI_STATUS Status;
213 ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
216 /* There must be at least a DSDT installed */
218 if (AcpiGbl_DSDT == NULL)
220 ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
221 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
225 * Load the namespace. The DSDT is required,
226 * but the SSDT and PSDT tables are optional.
228 Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
229 if (ACPI_FAILURE (Status))
231 return_ACPI_STATUS (Status);
234 /* Ignore exceptions from these */
236 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
237 (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
239 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
240 "ACPI Namespace successfully loaded at root %p\n",
241 AcpiGbl_RootNode));
243 return_ACPI_STATUS (Status);
245 #endif
247 #ifdef ACPI_FUTURE_IMPLEMENTATION
248 /*******************************************************************************
250 * FUNCTION: AcpiNsDeleteSubtree
252 * PARAMETERS: StartHandle - Handle in namespace where search begins
254 * RETURNS Status
256 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
257 * all objects, entries, and scopes in the entire subtree.
259 * Namespace/Interpreter should be locked or the subsystem should
260 * be in shutdown before this routine is called.
262 ******************************************************************************/
264 static ACPI_STATUS
265 AcpiNsDeleteSubtree (
266 ACPI_HANDLE StartHandle)
268 ACPI_STATUS Status;
269 ACPI_HANDLE ChildHandle;
270 ACPI_HANDLE ParentHandle;
271 ACPI_HANDLE NextChildHandle;
272 ACPI_HANDLE Dummy;
273 UINT32 Level;
276 ACPI_FUNCTION_TRACE (NsDeleteSubtree);
279 ParentHandle = StartHandle;
280 ChildHandle = NULL;
281 Level = 1;
284 * Traverse the tree of objects until we bubble back up
285 * to where we started.
287 while (Level > 0)
289 /* Attempt to get the next object in this scope */
291 Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
292 ChildHandle, &NextChildHandle);
294 ChildHandle = NextChildHandle;
296 /* Did we get a new object? */
298 if (ACPI_SUCCESS (Status))
300 /* Check if this object has any children */
302 if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
303 NULL, &Dummy)))
306 * There is at least one child of this object,
307 * visit the object
309 Level++;
310 ParentHandle = ChildHandle;
311 ChildHandle = NULL;
314 else
317 * No more children in this object, go back up to
318 * the object's parent
320 Level--;
322 /* Delete all children now */
324 AcpiNsDeleteChildren (ChildHandle);
326 ChildHandle = ParentHandle;
327 Status = AcpiGetParent (ParentHandle, &ParentHandle);
328 if (ACPI_FAILURE (Status))
330 return_ACPI_STATUS (Status);
335 /* Now delete the starting object, and we are done */
337 AcpiNsRemoveNode (ChildHandle);
338 return_ACPI_STATUS (AE_OK);
342 /*******************************************************************************
344 * FUNCTION: AcpiNsUnloadNameSpace
346 * PARAMETERS: Handle - Root of namespace subtree to be deleted
348 * RETURN: Status
350 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
351 * event. Deletes an entire subtree starting from (and
352 * including) the given handle.
354 ******************************************************************************/
356 ACPI_STATUS
357 AcpiNsUnloadNamespace (
358 ACPI_HANDLE Handle)
360 ACPI_STATUS Status;
363 ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
366 /* Parameter validation */
368 if (!AcpiGbl_RootNode)
370 return_ACPI_STATUS (AE_NO_NAMESPACE);
373 if (!Handle)
375 return_ACPI_STATUS (AE_BAD_PARAMETER);
378 /* This function does the real work */
380 Status = AcpiNsDeleteSubtree (Handle);
381 return_ACPI_STATUS (Status);
383 #endif
384 #endif