xref: /titanic_41/usr/src/uts/intel/io/acpica/namespace/nsload.c (revision de5d74c22760a6d2cefd94d0e7f0fd87214fb71f)
1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: nsload - namespace loading/expanding/contracting procedures
4ae115bc7Smrj  *
5ae115bc7Smrj  *****************************************************************************/
6ae115bc7Smrj 
726f3cdf0SGordon Ross /*
8*de5d74c2SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj  * All rights reserved.
10ae115bc7Smrj  *
1126f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross  * are met:
1426f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross  *    without modification.
1726f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross  *    binary redistribution.
2226f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25ae115bc7Smrj  *
2626f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross  * Software Foundation.
29ae115bc7Smrj  *
3026f3cdf0SGordon Ross  * NO WARRANTY
3126f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross  */
43ae115bc7Smrj 
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj #include "acnamesp.h"
47ae115bc7Smrj #include "acdispat.h"
48db2bae30SDana Myers #include "actables.h"
49ae115bc7Smrj 
50ae115bc7Smrj 
51ae115bc7Smrj #define _COMPONENT          ACPI_NAMESPACE
52ae115bc7Smrj         ACPI_MODULE_NAME    ("nsload")
53ae115bc7Smrj 
54ae115bc7Smrj /* Local prototypes */
55ae115bc7Smrj 
56ae115bc7Smrj #ifdef ACPI_FUTURE_IMPLEMENTATION
57ae115bc7Smrj ACPI_STATUS
58ae115bc7Smrj AcpiNsUnloadNamespace (
59ae115bc7Smrj     ACPI_HANDLE             Handle);
60ae115bc7Smrj 
61ae115bc7Smrj static ACPI_STATUS
62ae115bc7Smrj AcpiNsDeleteSubtree (
63ae115bc7Smrj     ACPI_HANDLE             StartHandle);
64ae115bc7Smrj #endif
65ae115bc7Smrj 
66ae115bc7Smrj 
67ae115bc7Smrj #ifndef ACPI_NO_METHOD_EXECUTION
68ae115bc7Smrj /*******************************************************************************
69ae115bc7Smrj  *
70ae115bc7Smrj  * FUNCTION:    AcpiNsLoadTable
71ae115bc7Smrj  *
72db2bae30SDana Myers  * PARAMETERS:  TableIndex      - Index for table to be loaded
73ae115bc7Smrj  *              Node            - Owning NS node
74ae115bc7Smrj  *
75ae115bc7Smrj  * RETURN:      Status
76ae115bc7Smrj  *
77ae115bc7Smrj  * DESCRIPTION: Load one ACPI table into the namespace
78ae115bc7Smrj  *
79ae115bc7Smrj  ******************************************************************************/
80ae115bc7Smrj 
81ae115bc7Smrj ACPI_STATUS
AcpiNsLoadTable(UINT32 TableIndex,ACPI_NAMESPACE_NODE * Node)82ae115bc7Smrj AcpiNsLoadTable (
83db2bae30SDana Myers     UINT32                  TableIndex,
84ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node)
85ae115bc7Smrj {
86ae115bc7Smrj     ACPI_STATUS             Status;
87ae115bc7Smrj 
88ae115bc7Smrj 
89ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsLoadTable);
90ae115bc7Smrj 
91ae115bc7Smrj 
92ae115bc7Smrj     /*
93ae115bc7Smrj      * Parse the table and load the namespace with all named
94ae115bc7Smrj      * objects found within. Control methods are NOT parsed
95ae115bc7Smrj      * at this time. In fact, the control methods cannot be
96ae115bc7Smrj      * parsed until the entire namespace is loaded, because
97ae115bc7Smrj      * if a control method makes a forward reference (call)
98ae115bc7Smrj      * to another control method, we can't continue parsing
99ae115bc7Smrj      * because we don't know how many arguments to parse next!
100ae115bc7Smrj      */
101ae115bc7Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
102ae115bc7Smrj     if (ACPI_FAILURE (Status))
103ae115bc7Smrj     {
104ae115bc7Smrj         return_ACPI_STATUS (Status);
105ae115bc7Smrj     }
106ae115bc7Smrj 
107db2bae30SDana Myers     /* If table already loaded into namespace, just return */
108db2bae30SDana Myers 
109db2bae30SDana Myers     if (AcpiTbIsTableLoaded (TableIndex))
110db2bae30SDana Myers     {
111db2bae30SDana Myers         Status = AE_ALREADY_EXISTS;
112db2bae30SDana Myers         goto Unlock;
113db2bae30SDana Myers     }
114db2bae30SDana Myers 
115db2bae30SDana Myers     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
116db2bae30SDana Myers         "**** Loading table into namespace ****\n"));
117db2bae30SDana Myers 
118db2bae30SDana Myers     Status = AcpiTbAllocateOwnerId (TableIndex);
119db2bae30SDana Myers     if (ACPI_FAILURE (Status))
120db2bae30SDana Myers     {
121db2bae30SDana Myers         goto Unlock;
122db2bae30SDana Myers     }
123db2bae30SDana Myers 
124db2bae30SDana Myers     Status = AcpiNsParseTable (TableIndex, Node);
125db2bae30SDana Myers     if (ACPI_SUCCESS (Status))
126db2bae30SDana Myers     {
127db2bae30SDana Myers         AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
128db2bae30SDana Myers     }
129db2bae30SDana Myers     else
130db2bae30SDana Myers     {
131*de5d74c2SJerry Jelinek         /*
132*de5d74c2SJerry Jelinek          * On error, delete any namespace objects created by this table.
133*de5d74c2SJerry Jelinek          * We cannot initialize these objects, so delete them. There are
134*de5d74c2SJerry Jelinek          * a couple of expecially bad cases:
135*de5d74c2SJerry Jelinek          * AE_ALREADY_EXISTS - namespace collision.
136*de5d74c2SJerry Jelinek          * AE_NOT_FOUND - the target of a Scope operator does not
137*de5d74c2SJerry Jelinek          * exist. This target of Scope must already exist in the
138*de5d74c2SJerry Jelinek          * namespace, as per the ACPI specification.
139*de5d74c2SJerry Jelinek          */
140*de5d74c2SJerry Jelinek         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
141*de5d74c2SJerry Jelinek         AcpiNsDeleteNamespaceByOwner (
142*de5d74c2SJerry Jelinek             AcpiGbl_RootTableList.Tables[TableIndex].OwnerId);
143*de5d74c2SJerry Jelinek 
144*de5d74c2SJerry Jelinek         AcpiTbReleaseOwnerId (TableIndex);
145*de5d74c2SJerry Jelinek         return_ACPI_STATUS (Status);
146db2bae30SDana Myers     }
147db2bae30SDana Myers 
148db2bae30SDana Myers Unlock:
149ae115bc7Smrj     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
150ae115bc7Smrj 
151ae115bc7Smrj     if (ACPI_FAILURE (Status))
152ae115bc7Smrj     {
153ae115bc7Smrj         return_ACPI_STATUS (Status);
154ae115bc7Smrj     }
155ae115bc7Smrj 
156ae115bc7Smrj     /*
157ae115bc7Smrj      * Now we can parse the control methods. We always parse
158ae115bc7Smrj      * them here for a sanity check, and if configured for
159ae115bc7Smrj      * just-in-time parsing, we delete the control method
160ae115bc7Smrj      * parse trees.
161ae115bc7Smrj      */
162ae115bc7Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
163*de5d74c2SJerry Jelinek         "**** Begin Table Object Initialization\n"));
164ae115bc7Smrj 
165db2bae30SDana Myers     Status = AcpiDsInitializeObjects (TableIndex, Node);
166ae115bc7Smrj 
167ae115bc7Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
168*de5d74c2SJerry Jelinek         "**** Completed Table Object Initialization\n"));
169*de5d74c2SJerry Jelinek 
170*de5d74c2SJerry Jelinek     /*
171*de5d74c2SJerry Jelinek      * Execute any module-level code that was detected during the table load
172*de5d74c2SJerry Jelinek      * phase. Although illegal since ACPI 2.0, there are many machines that
173*de5d74c2SJerry Jelinek      * contain this type of code. Each block of detected executable AML code
174*de5d74c2SJerry Jelinek      * outside of any control method is wrapped with a temporary control
175*de5d74c2SJerry Jelinek      * method object and placed on a global list. The methods on this list
176*de5d74c2SJerry Jelinek      * are executed below.
177*de5d74c2SJerry Jelinek      *
178*de5d74c2SJerry Jelinek      * This case executes the module-level code for each table immediately
179*de5d74c2SJerry Jelinek      * after the table has been loaded. This provides compatibility with
180*de5d74c2SJerry Jelinek      * other ACPI implementations. Optionally, the execution can be deferred
181*de5d74c2SJerry Jelinek      * until later, see AcpiInitializeObjects.
182*de5d74c2SJerry Jelinek      */
183*de5d74c2SJerry Jelinek     if (!AcpiGbl_GroupModuleLevelCode)
184*de5d74c2SJerry Jelinek     {
185*de5d74c2SJerry Jelinek         AcpiNsExecModuleCodeList ();
186*de5d74c2SJerry Jelinek     }
187ae115bc7Smrj 
188ae115bc7Smrj     return_ACPI_STATUS (Status);
189ae115bc7Smrj }
190ae115bc7Smrj 
191ae115bc7Smrj 
192db2bae30SDana Myers #ifdef ACPI_OBSOLETE_FUNCTIONS
193ae115bc7Smrj /*******************************************************************************
194ae115bc7Smrj  *
195ae115bc7Smrj  * FUNCTION:    AcpiLoadNamespace
196ae115bc7Smrj  *
197ae115bc7Smrj  * PARAMETERS:  None
198ae115bc7Smrj  *
199ae115bc7Smrj  * RETURN:      Status
200ae115bc7Smrj  *
201ae115bc7Smrj  * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
202ae115bc7Smrj  *              (DSDT points to either the BIOS or a buffer.)
203ae115bc7Smrj  *
204ae115bc7Smrj  ******************************************************************************/
205ae115bc7Smrj 
206ae115bc7Smrj ACPI_STATUS
AcpiNsLoadNamespace(void)207ae115bc7Smrj AcpiNsLoadNamespace (
208ae115bc7Smrj     void)
209ae115bc7Smrj {
210ae115bc7Smrj     ACPI_STATUS             Status;
211ae115bc7Smrj 
212ae115bc7Smrj 
213ae115bc7Smrj     ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
214ae115bc7Smrj 
215ae115bc7Smrj 
216ae115bc7Smrj     /* There must be at least a DSDT installed */
217ae115bc7Smrj 
218ae115bc7Smrj     if (AcpiGbl_DSDT == NULL)
219ae115bc7Smrj     {
220ae115bc7Smrj         ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
221ae115bc7Smrj         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
222ae115bc7Smrj     }
223ae115bc7Smrj 
224ae115bc7Smrj     /*
225ae115bc7Smrj      * Load the namespace. The DSDT is required,
226ae115bc7Smrj      * but the SSDT and PSDT tables are optional.
227ae115bc7Smrj      */
228ae115bc7Smrj     Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
229ae115bc7Smrj     if (ACPI_FAILURE (Status))
230ae115bc7Smrj     {
231ae115bc7Smrj         return_ACPI_STATUS (Status);
232ae115bc7Smrj     }
233ae115bc7Smrj 
234ae115bc7Smrj     /* Ignore exceptions from these */
235ae115bc7Smrj 
236ae115bc7Smrj     (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
237ae115bc7Smrj     (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
238ae115bc7Smrj 
239ae115bc7Smrj     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
240ae115bc7Smrj         "ACPI Namespace successfully loaded at root %p\n",
241ae115bc7Smrj         AcpiGbl_RootNode));
242ae115bc7Smrj 
243ae115bc7Smrj     return_ACPI_STATUS (Status);
244ae115bc7Smrj }
245db2bae30SDana Myers #endif
246ae115bc7Smrj 
247ae115bc7Smrj #ifdef ACPI_FUTURE_IMPLEMENTATION
248ae115bc7Smrj /*******************************************************************************
249ae115bc7Smrj  *
250ae115bc7Smrj  * FUNCTION:    AcpiNsDeleteSubtree
251ae115bc7Smrj  *
252ae115bc7Smrj  * PARAMETERS:  StartHandle         - Handle in namespace where search begins
253ae115bc7Smrj  *
254ae115bc7Smrj  * RETURNS      Status
255ae115bc7Smrj  *
256ae115bc7Smrj  * DESCRIPTION: Walks the namespace starting at the given handle and deletes
257ae115bc7Smrj  *              all objects, entries, and scopes in the entire subtree.
258ae115bc7Smrj  *
259ae115bc7Smrj  *              Namespace/Interpreter should be locked or the subsystem should
260ae115bc7Smrj  *              be in shutdown before this routine is called.
261ae115bc7Smrj  *
262ae115bc7Smrj  ******************************************************************************/
263ae115bc7Smrj 
264ae115bc7Smrj static ACPI_STATUS
AcpiNsDeleteSubtree(ACPI_HANDLE StartHandle)265ae115bc7Smrj AcpiNsDeleteSubtree (
266ae115bc7Smrj     ACPI_HANDLE             StartHandle)
267ae115bc7Smrj {
268ae115bc7Smrj     ACPI_STATUS             Status;
269ae115bc7Smrj     ACPI_HANDLE             ChildHandle;
270ae115bc7Smrj     ACPI_HANDLE             ParentHandle;
271ae115bc7Smrj     ACPI_HANDLE             NextChildHandle;
272ae115bc7Smrj     ACPI_HANDLE             Dummy;
273ae115bc7Smrj     UINT32                  Level;
274ae115bc7Smrj 
275ae115bc7Smrj 
276ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsDeleteSubtree);
277ae115bc7Smrj 
278ae115bc7Smrj 
279ae115bc7Smrj     ParentHandle = StartHandle;
280ae115bc7Smrj     ChildHandle = NULL;
281ae115bc7Smrj     Level = 1;
282ae115bc7Smrj 
283ae115bc7Smrj     /*
284ae115bc7Smrj      * Traverse the tree of objects until we bubble back up
285ae115bc7Smrj      * to where we started.
286ae115bc7Smrj      */
287ae115bc7Smrj     while (Level > 0)
288ae115bc7Smrj     {
289ae115bc7Smrj         /* Attempt to get the next object in this scope */
290ae115bc7Smrj 
291ae115bc7Smrj         Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
292ae115bc7Smrj             ChildHandle, &NextChildHandle);
293ae115bc7Smrj 
294ae115bc7Smrj         ChildHandle = NextChildHandle;
295ae115bc7Smrj 
296ae115bc7Smrj         /* Did we get a new object? */
297ae115bc7Smrj 
298ae115bc7Smrj         if (ACPI_SUCCESS (Status))
299ae115bc7Smrj         {
300ae115bc7Smrj             /* Check if this object has any children */
301ae115bc7Smrj 
302ae115bc7Smrj             if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
303ae115bc7Smrj                 NULL, &Dummy)))
304ae115bc7Smrj             {
305ae115bc7Smrj                 /*
306ae115bc7Smrj                  * There is at least one child of this object,
307ae115bc7Smrj                  * visit the object
308ae115bc7Smrj                  */
309ae115bc7Smrj                 Level++;
310ae115bc7Smrj                 ParentHandle = ChildHandle;
311ae115bc7Smrj                 ChildHandle  = NULL;
312ae115bc7Smrj             }
313ae115bc7Smrj         }
314ae115bc7Smrj         else
315ae115bc7Smrj         {
316ae115bc7Smrj             /*
317ae115bc7Smrj              * No more children in this object, go back up to
318ae115bc7Smrj              * the object's parent
319ae115bc7Smrj              */
320ae115bc7Smrj             Level--;
321ae115bc7Smrj 
322ae115bc7Smrj             /* Delete all children now */
323ae115bc7Smrj 
324ae115bc7Smrj             AcpiNsDeleteChildren (ChildHandle);
325ae115bc7Smrj 
326ae115bc7Smrj             ChildHandle = ParentHandle;
327ae115bc7Smrj             Status = AcpiGetParent (ParentHandle, &ParentHandle);
328ae115bc7Smrj             if (ACPI_FAILURE (Status))
329ae115bc7Smrj             {
330ae115bc7Smrj                 return_ACPI_STATUS (Status);
331ae115bc7Smrj             }
332ae115bc7Smrj         }
333ae115bc7Smrj     }
334ae115bc7Smrj 
335ae115bc7Smrj     /* Now delete the starting object, and we are done */
336ae115bc7Smrj 
33757190917SDana Myers     AcpiNsRemoveNode (ChildHandle);
338ae115bc7Smrj     return_ACPI_STATUS (AE_OK);
339ae115bc7Smrj }
340ae115bc7Smrj 
341ae115bc7Smrj 
342ae115bc7Smrj /*******************************************************************************
343ae115bc7Smrj  *
344ae115bc7Smrj  *  FUNCTION:       AcpiNsUnloadNameSpace
345ae115bc7Smrj  *
346ae115bc7Smrj  *  PARAMETERS:     Handle          - Root of namespace subtree to be deleted
347ae115bc7Smrj  *
348ae115bc7Smrj  *  RETURN:         Status
349ae115bc7Smrj  *
350ae115bc7Smrj  *  DESCRIPTION:    Shrinks the namespace, typically in response to an undocking
351ae115bc7Smrj  *                  event. Deletes an entire subtree starting from (and
352ae115bc7Smrj  *                  including) the given handle.
353ae115bc7Smrj  *
354ae115bc7Smrj  ******************************************************************************/
355ae115bc7Smrj 
356ae115bc7Smrj ACPI_STATUS
AcpiNsUnloadNamespace(ACPI_HANDLE Handle)357ae115bc7Smrj AcpiNsUnloadNamespace (
358ae115bc7Smrj     ACPI_HANDLE             Handle)
359ae115bc7Smrj {
360ae115bc7Smrj     ACPI_STATUS             Status;
361ae115bc7Smrj 
362ae115bc7Smrj 
363ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
364ae115bc7Smrj 
365ae115bc7Smrj 
366ae115bc7Smrj     /* Parameter validation */
367ae115bc7Smrj 
368ae115bc7Smrj     if (!AcpiGbl_RootNode)
369ae115bc7Smrj     {
370ae115bc7Smrj         return_ACPI_STATUS (AE_NO_NAMESPACE);
371ae115bc7Smrj     }
372ae115bc7Smrj 
373ae115bc7Smrj     if (!Handle)
374ae115bc7Smrj     {
375ae115bc7Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
376ae115bc7Smrj     }
377ae115bc7Smrj 
378ae115bc7Smrj     /* This function does the real work */
379ae115bc7Smrj 
380ae115bc7Smrj     Status = AcpiNsDeleteSubtree (Handle);
381ae115bc7Smrj     return_ACPI_STATUS (Status);
382ae115bc7Smrj }
383ae115bc7Smrj #endif
384ae115bc7Smrj #endif
385