1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: nsload - namespace loading/expanding/contracting procedures
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc *****************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acnamesp.h"
47433d6423SLionel Sambuc #include "acdispat.h"
48433d6423SLionel Sambuc #include "actables.h"
49433d6423SLionel Sambuc
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc #define _COMPONENT ACPI_NAMESPACE
52433d6423SLionel Sambuc ACPI_MODULE_NAME ("nsload")
53433d6423SLionel Sambuc
54433d6423SLionel Sambuc /* Local prototypes */
55433d6423SLionel Sambuc
56433d6423SLionel Sambuc #ifdef ACPI_FUTURE_IMPLEMENTATION
57433d6423SLionel Sambuc ACPI_STATUS
58433d6423SLionel Sambuc AcpiNsUnloadNamespace (
59433d6423SLionel Sambuc ACPI_HANDLE Handle);
60433d6423SLionel Sambuc
61433d6423SLionel Sambuc static ACPI_STATUS
62433d6423SLionel Sambuc AcpiNsDeleteSubtree (
63433d6423SLionel Sambuc ACPI_HANDLE StartHandle);
64433d6423SLionel Sambuc #endif
65433d6423SLionel Sambuc
66433d6423SLionel Sambuc
67433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
68433d6423SLionel Sambuc /*******************************************************************************
69433d6423SLionel Sambuc *
70433d6423SLionel Sambuc * FUNCTION: AcpiNsLoadTable
71433d6423SLionel Sambuc *
72433d6423SLionel Sambuc * PARAMETERS: TableIndex - Index for table to be loaded
73433d6423SLionel Sambuc * Node - Owning NS node
74433d6423SLionel Sambuc *
75433d6423SLionel Sambuc * RETURN: Status
76433d6423SLionel Sambuc *
77433d6423SLionel Sambuc * DESCRIPTION: Load one ACPI table into the namespace
78433d6423SLionel Sambuc *
79433d6423SLionel Sambuc ******************************************************************************/
80433d6423SLionel Sambuc
81433d6423SLionel Sambuc ACPI_STATUS
AcpiNsLoadTable(UINT32 TableIndex,ACPI_NAMESPACE_NODE * Node)82433d6423SLionel Sambuc AcpiNsLoadTable (
83433d6423SLionel Sambuc UINT32 TableIndex,
84433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node)
85433d6423SLionel Sambuc {
86433d6423SLionel Sambuc ACPI_STATUS Status;
87433d6423SLionel Sambuc
88433d6423SLionel Sambuc
89433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsLoadTable);
90433d6423SLionel Sambuc
91433d6423SLionel Sambuc
92433d6423SLionel Sambuc /*
93433d6423SLionel Sambuc * Parse the table and load the namespace with all named
94433d6423SLionel Sambuc * objects found within. Control methods are NOT parsed
95433d6423SLionel Sambuc * at this time. In fact, the control methods cannot be
96433d6423SLionel Sambuc * parsed until the entire namespace is loaded, because
97433d6423SLionel Sambuc * if a control method makes a forward reference (call)
98433d6423SLionel Sambuc * to another control method, we can't continue parsing
99433d6423SLionel Sambuc * because we don't know how many arguments to parse next!
100433d6423SLionel Sambuc */
101433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
102433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
103433d6423SLionel Sambuc {
104433d6423SLionel Sambuc return_ACPI_STATUS (Status);
105433d6423SLionel Sambuc }
106433d6423SLionel Sambuc
107433d6423SLionel Sambuc /* If table already loaded into namespace, just return */
108433d6423SLionel Sambuc
109433d6423SLionel Sambuc if (AcpiTbIsTableLoaded (TableIndex))
110433d6423SLionel Sambuc {
111433d6423SLionel Sambuc Status = AE_ALREADY_EXISTS;
112433d6423SLionel Sambuc goto Unlock;
113433d6423SLionel Sambuc }
114433d6423SLionel Sambuc
115433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
116433d6423SLionel Sambuc "**** Loading table into namespace ****\n"));
117433d6423SLionel Sambuc
118433d6423SLionel Sambuc Status = AcpiTbAllocateOwnerId (TableIndex);
119433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
120433d6423SLionel Sambuc {
121433d6423SLionel Sambuc goto Unlock;
122433d6423SLionel Sambuc }
123433d6423SLionel Sambuc
124433d6423SLionel Sambuc Status = AcpiNsParseTable (TableIndex, Node);
125433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
126433d6423SLionel Sambuc {
127433d6423SLionel Sambuc AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
128433d6423SLionel Sambuc }
129433d6423SLionel Sambuc else
130433d6423SLionel Sambuc {
131433d6423SLionel Sambuc (void) AcpiTbReleaseOwnerId (TableIndex);
132433d6423SLionel Sambuc }
133433d6423SLionel Sambuc
134433d6423SLionel Sambuc Unlock:
135433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
136433d6423SLionel Sambuc
137433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
138433d6423SLionel Sambuc {
139433d6423SLionel Sambuc return_ACPI_STATUS (Status);
140433d6423SLionel Sambuc }
141433d6423SLionel Sambuc
142433d6423SLionel Sambuc /*
143433d6423SLionel Sambuc * Now we can parse the control methods. We always parse
144433d6423SLionel Sambuc * them here for a sanity check, and if configured for
145433d6423SLionel Sambuc * just-in-time parsing, we delete the control method
146433d6423SLionel Sambuc * parse trees.
147433d6423SLionel Sambuc */
148433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
149*29492bb7SDavid van Moolenbroek "**** Begin Table Object Initialization\n"));
150433d6423SLionel Sambuc
151433d6423SLionel Sambuc Status = AcpiDsInitializeObjects (TableIndex, Node);
152433d6423SLionel Sambuc
153433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
154*29492bb7SDavid van Moolenbroek "**** Completed Table Object Initialization\n"));
155433d6423SLionel Sambuc
156433d6423SLionel Sambuc return_ACPI_STATUS (Status);
157433d6423SLionel Sambuc }
158433d6423SLionel Sambuc
159433d6423SLionel Sambuc
160433d6423SLionel Sambuc #ifdef ACPI_OBSOLETE_FUNCTIONS
161433d6423SLionel Sambuc /*******************************************************************************
162433d6423SLionel Sambuc *
163433d6423SLionel Sambuc * FUNCTION: AcpiLoadNamespace
164433d6423SLionel Sambuc *
165433d6423SLionel Sambuc * PARAMETERS: None
166433d6423SLionel Sambuc *
167433d6423SLionel Sambuc * RETURN: Status
168433d6423SLionel Sambuc *
169433d6423SLionel Sambuc * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
170433d6423SLionel Sambuc * (DSDT points to either the BIOS or a buffer.)
171433d6423SLionel Sambuc *
172433d6423SLionel Sambuc ******************************************************************************/
173433d6423SLionel Sambuc
174433d6423SLionel Sambuc ACPI_STATUS
AcpiNsLoadNamespace(void)175433d6423SLionel Sambuc AcpiNsLoadNamespace (
176433d6423SLionel Sambuc void)
177433d6423SLionel Sambuc {
178433d6423SLionel Sambuc ACPI_STATUS Status;
179433d6423SLionel Sambuc
180433d6423SLionel Sambuc
181433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
182433d6423SLionel Sambuc
183433d6423SLionel Sambuc
184433d6423SLionel Sambuc /* There must be at least a DSDT installed */
185433d6423SLionel Sambuc
186433d6423SLionel Sambuc if (AcpiGbl_DSDT == NULL)
187433d6423SLionel Sambuc {
188433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
189433d6423SLionel Sambuc return_ACPI_STATUS (AE_NO_ACPI_TABLES);
190433d6423SLionel Sambuc }
191433d6423SLionel Sambuc
192433d6423SLionel Sambuc /*
193433d6423SLionel Sambuc * Load the namespace. The DSDT is required,
194433d6423SLionel Sambuc * but the SSDT and PSDT tables are optional.
195433d6423SLionel Sambuc */
196433d6423SLionel Sambuc Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
197433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
198433d6423SLionel Sambuc {
199433d6423SLionel Sambuc return_ACPI_STATUS (Status);
200433d6423SLionel Sambuc }
201433d6423SLionel Sambuc
202433d6423SLionel Sambuc /* Ignore exceptions from these */
203433d6423SLionel Sambuc
204433d6423SLionel Sambuc (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
205433d6423SLionel Sambuc (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
206433d6423SLionel Sambuc
207433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
208433d6423SLionel Sambuc "ACPI Namespace successfully loaded at root %p\n",
209433d6423SLionel Sambuc AcpiGbl_RootNode));
210433d6423SLionel Sambuc
211433d6423SLionel Sambuc return_ACPI_STATUS (Status);
212433d6423SLionel Sambuc }
213433d6423SLionel Sambuc #endif
214433d6423SLionel Sambuc
215433d6423SLionel Sambuc #ifdef ACPI_FUTURE_IMPLEMENTATION
216433d6423SLionel Sambuc /*******************************************************************************
217433d6423SLionel Sambuc *
218433d6423SLionel Sambuc * FUNCTION: AcpiNsDeleteSubtree
219433d6423SLionel Sambuc *
220433d6423SLionel Sambuc * PARAMETERS: StartHandle - Handle in namespace where search begins
221433d6423SLionel Sambuc *
222433d6423SLionel Sambuc * RETURNS Status
223433d6423SLionel Sambuc *
224433d6423SLionel Sambuc * DESCRIPTION: Walks the namespace starting at the given handle and deletes
225433d6423SLionel Sambuc * all objects, entries, and scopes in the entire subtree.
226433d6423SLionel Sambuc *
227433d6423SLionel Sambuc * Namespace/Interpreter should be locked or the subsystem should
228433d6423SLionel Sambuc * be in shutdown before this routine is called.
229433d6423SLionel Sambuc *
230433d6423SLionel Sambuc ******************************************************************************/
231433d6423SLionel Sambuc
232433d6423SLionel Sambuc static ACPI_STATUS
AcpiNsDeleteSubtree(ACPI_HANDLE StartHandle)233433d6423SLionel Sambuc AcpiNsDeleteSubtree (
234433d6423SLionel Sambuc ACPI_HANDLE StartHandle)
235433d6423SLionel Sambuc {
236433d6423SLionel Sambuc ACPI_STATUS Status;
237433d6423SLionel Sambuc ACPI_HANDLE ChildHandle;
238433d6423SLionel Sambuc ACPI_HANDLE ParentHandle;
239433d6423SLionel Sambuc ACPI_HANDLE NextChildHandle;
240433d6423SLionel Sambuc ACPI_HANDLE Dummy;
241433d6423SLionel Sambuc UINT32 Level;
242433d6423SLionel Sambuc
243433d6423SLionel Sambuc
244433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsDeleteSubtree);
245433d6423SLionel Sambuc
246433d6423SLionel Sambuc
247433d6423SLionel Sambuc ParentHandle = StartHandle;
248433d6423SLionel Sambuc ChildHandle = NULL;
249433d6423SLionel Sambuc Level = 1;
250433d6423SLionel Sambuc
251433d6423SLionel Sambuc /*
252433d6423SLionel Sambuc * Traverse the tree of objects until we bubble back up
253433d6423SLionel Sambuc * to where we started.
254433d6423SLionel Sambuc */
255433d6423SLionel Sambuc while (Level > 0)
256433d6423SLionel Sambuc {
257433d6423SLionel Sambuc /* Attempt to get the next object in this scope */
258433d6423SLionel Sambuc
259433d6423SLionel Sambuc Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
260433d6423SLionel Sambuc ChildHandle, &NextChildHandle);
261433d6423SLionel Sambuc
262433d6423SLionel Sambuc ChildHandle = NextChildHandle;
263433d6423SLionel Sambuc
264433d6423SLionel Sambuc /* Did we get a new object? */
265433d6423SLionel Sambuc
266433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
267433d6423SLionel Sambuc {
268433d6423SLionel Sambuc /* Check if this object has any children */
269433d6423SLionel Sambuc
270433d6423SLionel Sambuc if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
271433d6423SLionel Sambuc NULL, &Dummy)))
272433d6423SLionel Sambuc {
273433d6423SLionel Sambuc /*
274433d6423SLionel Sambuc * There is at least one child of this object,
275433d6423SLionel Sambuc * visit the object
276433d6423SLionel Sambuc */
277433d6423SLionel Sambuc Level++;
278433d6423SLionel Sambuc ParentHandle = ChildHandle;
279433d6423SLionel Sambuc ChildHandle = NULL;
280433d6423SLionel Sambuc }
281433d6423SLionel Sambuc }
282433d6423SLionel Sambuc else
283433d6423SLionel Sambuc {
284433d6423SLionel Sambuc /*
285433d6423SLionel Sambuc * No more children in this object, go back up to
286433d6423SLionel Sambuc * the object's parent
287433d6423SLionel Sambuc */
288433d6423SLionel Sambuc Level--;
289433d6423SLionel Sambuc
290433d6423SLionel Sambuc /* Delete all children now */
291433d6423SLionel Sambuc
292433d6423SLionel Sambuc AcpiNsDeleteChildren (ChildHandle);
293433d6423SLionel Sambuc
294433d6423SLionel Sambuc ChildHandle = ParentHandle;
295433d6423SLionel Sambuc Status = AcpiGetParent (ParentHandle, &ParentHandle);
296433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
297433d6423SLionel Sambuc {
298433d6423SLionel Sambuc return_ACPI_STATUS (Status);
299433d6423SLionel Sambuc }
300433d6423SLionel Sambuc }
301433d6423SLionel Sambuc }
302433d6423SLionel Sambuc
303433d6423SLionel Sambuc /* Now delete the starting object, and we are done */
304433d6423SLionel Sambuc
305433d6423SLionel Sambuc AcpiNsRemoveNode (ChildHandle);
306433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
307433d6423SLionel Sambuc }
308433d6423SLionel Sambuc
309433d6423SLionel Sambuc
310433d6423SLionel Sambuc /*******************************************************************************
311433d6423SLionel Sambuc *
312433d6423SLionel Sambuc * FUNCTION: AcpiNsUnloadNameSpace
313433d6423SLionel Sambuc *
314433d6423SLionel Sambuc * PARAMETERS: Handle - Root of namespace subtree to be deleted
315433d6423SLionel Sambuc *
316433d6423SLionel Sambuc * RETURN: Status
317433d6423SLionel Sambuc *
318433d6423SLionel Sambuc * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
319433d6423SLionel Sambuc * event. Deletes an entire subtree starting from (and
320433d6423SLionel Sambuc * including) the given handle.
321433d6423SLionel Sambuc *
322433d6423SLionel Sambuc ******************************************************************************/
323433d6423SLionel Sambuc
324433d6423SLionel Sambuc ACPI_STATUS
AcpiNsUnloadNamespace(ACPI_HANDLE Handle)325433d6423SLionel Sambuc AcpiNsUnloadNamespace (
326433d6423SLionel Sambuc ACPI_HANDLE Handle)
327433d6423SLionel Sambuc {
328433d6423SLionel Sambuc ACPI_STATUS Status;
329433d6423SLionel Sambuc
330433d6423SLionel Sambuc
331433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
332433d6423SLionel Sambuc
333433d6423SLionel Sambuc
334433d6423SLionel Sambuc /* Parameter validation */
335433d6423SLionel Sambuc
336433d6423SLionel Sambuc if (!AcpiGbl_RootNode)
337433d6423SLionel Sambuc {
338433d6423SLionel Sambuc return_ACPI_STATUS (AE_NO_NAMESPACE);
339433d6423SLionel Sambuc }
340433d6423SLionel Sambuc
341433d6423SLionel Sambuc if (!Handle)
342433d6423SLionel Sambuc {
343433d6423SLionel Sambuc return_ACPI_STATUS (AE_BAD_PARAMETER);
344433d6423SLionel Sambuc }
345433d6423SLionel Sambuc
346433d6423SLionel Sambuc /* This function does the real work */
347433d6423SLionel Sambuc
348433d6423SLionel Sambuc Status = AcpiNsDeleteSubtree (Handle);
349433d6423SLionel Sambuc
350433d6423SLionel Sambuc return_ACPI_STATUS (Status);
351433d6423SLionel Sambuc }
352433d6423SLionel Sambuc #endif
353433d6423SLionel Sambuc #endif
354