1 /******************************************************************************
2  *
3  * Module Name: dsinit - Object initialization namespace walk
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2014, Intel Corp.
9  * All rights reserved.
10  *
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.
25  *
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.
29  *
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.
42  */
43 
44 #define __DSINIT_C__
45 
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acdispat.h"
49 #include "acnamesp.h"
50 #include "actables.h"
51 
52 #define _COMPONENT          ACPI_DISPATCHER
53         ACPI_MODULE_NAME    ("dsinit")
54 
55 
56 /* Local prototypes */
57 
58 static ACPI_STATUS
59 AcpiDsInitOneObject (
60     ACPI_HANDLE             ObjHandle,
61     UINT32                  Level,
62     void                    *Context,
63     void                    **ReturnValue);
64 
65 
66 /*******************************************************************************
67  *
68  * FUNCTION:    AcpiDsInitOneObject
69  *
70  * PARAMETERS:  ObjHandle       - Node for the object
71  *              Level           - Current nesting level
72  *              Context         - Points to a init info struct
73  *              ReturnValue     - Not used
74  *
75  * RETURN:      Status
76  *
77  * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
78  *              within the namespace.
79  *
80  *              Currently, the only objects that require initialization are:
81  *              1) Methods
82  *              2) Operation Regions
83  *
84  ******************************************************************************/
85 
86 static ACPI_STATUS
87 AcpiDsInitOneObject (
88     ACPI_HANDLE             ObjHandle,
89     UINT32                  Level,
90     void                    *Context,
91     void                    **ReturnValue)
92 {
93     ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
94     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
95     ACPI_STATUS             Status;
96     ACPI_OPERAND_OBJECT     *ObjDesc;
97 
98 
99     ACPI_FUNCTION_ENTRY ();
100 
101 
102     /*
103      * We are only interested in NS nodes owned by the table that
104      * was just loaded
105      */
106     if (Node->OwnerId != Info->OwnerId)
107     {
108         return (AE_OK);
109     }
110 
111     Info->ObjectCount++;
112 
113     /* And even then, we are only interested in a few object types */
114 
115     switch (AcpiNsGetType (ObjHandle))
116     {
117     case ACPI_TYPE_REGION:
118 
119         Status = AcpiDsInitializeRegion (ObjHandle);
120         if (ACPI_FAILURE (Status))
121         {
122             ACPI_EXCEPTION ((AE_INFO, Status,
123                 "During Region initialization %p [%4.4s]",
124                 ObjHandle, AcpiUtGetNodeName (ObjHandle)));
125         }
126 
127         Info->OpRegionCount++;
128         break;
129 
130     case ACPI_TYPE_METHOD:
131         /*
132          * Auto-serialization support. We will examine each method that is
133          * NotSerialized to determine if it creates any Named objects. If
134          * it does, it will be marked serialized to prevent problems if
135          * the method is entered by two or more threads and an attempt is
136          * made to create the same named object twice -- which results in
137          * an AE_ALREADY_EXISTS exception and method abort.
138          */
139         Info->MethodCount++;
140         ObjDesc = AcpiNsGetAttachedObject (Node);
141         if (!ObjDesc)
142         {
143             break;
144         }
145 
146         /* Ignore if already serialized */
147 
148         if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
149         {
150             Info->SerialMethodCount++;
151             break;
152         }
153 
154         if (AcpiGbl_AutoSerializeMethods)
155         {
156             /* Parse/scan method and serialize it if necessary */
157 
158             AcpiDsAutoSerializeMethod (Node, ObjDesc);
159             if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
160             {
161                 /* Method was just converted to Serialized */
162 
163                 Info->SerialMethodCount++;
164                 Info->SerializedMethodCount++;
165                 break;
166             }
167         }
168 
169         Info->NonSerialMethodCount++;
170         break;
171 
172     case ACPI_TYPE_DEVICE:
173 
174         Info->DeviceCount++;
175         break;
176 
177     default:
178 
179         break;
180     }
181 
182     /*
183      * We ignore errors from above, and always return OK, since
184      * we don't want to abort the walk on a single error.
185      */
186     return (AE_OK);
187 }
188 
189 
190 /*******************************************************************************
191  *
192  * FUNCTION:    AcpiDsInitializeObjects
193  *
194  * PARAMETERS:  TableDesc       - Descriptor for parent ACPI table
195  *              StartNode       - Root of subtree to be initialized.
196  *
197  * RETURN:      Status
198  *
199  * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
200  *              necessary initialization on the objects found therein
201  *
202  ******************************************************************************/
203 
204 ACPI_STATUS
205 AcpiDsInitializeObjects (
206     UINT32                  TableIndex,
207     ACPI_NAMESPACE_NODE     *StartNode)
208 {
209     ACPI_STATUS             Status;
210     ACPI_INIT_WALK_INFO     Info;
211     ACPI_TABLE_HEADER       *Table;
212     ACPI_OWNER_ID           OwnerId;
213 
214 
215     ACPI_FUNCTION_TRACE (DsInitializeObjects);
216 
217 
218     Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
219     if (ACPI_FAILURE (Status))
220     {
221         return_ACPI_STATUS (Status);
222     }
223 
224     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
225         "**** Starting initialization of namespace objects ****\n"));
226 
227     /* Set all init info to zero */
228 
229     ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
230 
231     Info.OwnerId = OwnerId;
232     Info.TableIndex = TableIndex;
233 
234     /* Walk entire namespace from the supplied root */
235 
236     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
237     if (ACPI_FAILURE (Status))
238     {
239         return_ACPI_STATUS (Status);
240     }
241 
242     /*
243      * We don't use AcpiWalkNamespace since we do not want to acquire
244      * the namespace reader lock.
245      */
246     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,
247                 ACPI_NS_WALK_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);
248     if (ACPI_FAILURE (Status))
249     {
250         ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
251     }
252     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
253 
254     Status = AcpiGetTableByIndex (TableIndex, &Table);
255     if (ACPI_FAILURE (Status))
256     {
257         return_ACPI_STATUS (Status);
258     }
259 
260     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
261         "Table [%4.4s] (id %4.4X) - %4u Objects with %3u Devices, "
262         "%3u Regions, %3u Methods (%u/%u/%u Serial/Non/Cvt)\n",
263         Table->Signature, OwnerId, Info.ObjectCount, Info.DeviceCount,
264         Info.OpRegionCount, Info.MethodCount, Info.SerialMethodCount,
265         Info.NonSerialMethodCount, Info.SerializedMethodCount));
266 
267     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
268         Info.MethodCount, Info.OpRegionCount));
269 
270     return_ACPI_STATUS (AE_OK);
271 }
272