1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: dsinit - Object initialization namespace walk
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 "acdispat.h"
47433d6423SLionel Sambuc #include "acnamesp.h"
48433d6423SLionel Sambuc #include "actables.h"
49433d6423SLionel Sambuc
50433d6423SLionel Sambuc #define _COMPONENT ACPI_DISPATCHER
51433d6423SLionel Sambuc ACPI_MODULE_NAME ("dsinit")
52433d6423SLionel Sambuc
53*29492bb7SDavid van Moolenbroek
54433d6423SLionel Sambuc /* Local prototypes */
55433d6423SLionel Sambuc
56433d6423SLionel Sambuc static ACPI_STATUS
57433d6423SLionel Sambuc AcpiDsInitOneObject (
58433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
59433d6423SLionel Sambuc UINT32 Level,
60433d6423SLionel Sambuc void *Context,
61433d6423SLionel Sambuc void **ReturnValue);
62433d6423SLionel Sambuc
63433d6423SLionel Sambuc
64433d6423SLionel Sambuc /*******************************************************************************
65433d6423SLionel Sambuc *
66433d6423SLionel Sambuc * FUNCTION: AcpiDsInitOneObject
67433d6423SLionel Sambuc *
68433d6423SLionel Sambuc * PARAMETERS: ObjHandle - Node for the object
69433d6423SLionel Sambuc * Level - Current nesting level
70433d6423SLionel Sambuc * Context - Points to a init info struct
71433d6423SLionel Sambuc * ReturnValue - Not used
72433d6423SLionel Sambuc *
73433d6423SLionel Sambuc * RETURN: Status
74433d6423SLionel Sambuc *
75433d6423SLionel Sambuc * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
76433d6423SLionel Sambuc * within the namespace.
77433d6423SLionel Sambuc *
78433d6423SLionel Sambuc * Currently, the only objects that require initialization are:
79433d6423SLionel Sambuc * 1) Methods
80433d6423SLionel Sambuc * 2) Operation Regions
81433d6423SLionel Sambuc *
82433d6423SLionel Sambuc ******************************************************************************/
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc static ACPI_STATUS
AcpiDsInitOneObject(ACPI_HANDLE ObjHandle,UINT32 Level,void * Context,void ** ReturnValue)85433d6423SLionel Sambuc AcpiDsInitOneObject (
86433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
87433d6423SLionel Sambuc UINT32 Level,
88433d6423SLionel Sambuc void *Context,
89433d6423SLionel Sambuc void **ReturnValue)
90433d6423SLionel Sambuc {
91433d6423SLionel Sambuc ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;
92433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
93433d6423SLionel Sambuc ACPI_STATUS Status;
94*29492bb7SDavid van Moolenbroek ACPI_OPERAND_OBJECT *ObjDesc;
95433d6423SLionel Sambuc
96433d6423SLionel Sambuc
97433d6423SLionel Sambuc ACPI_FUNCTION_ENTRY ();
98433d6423SLionel Sambuc
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc /*
101433d6423SLionel Sambuc * We are only interested in NS nodes owned by the table that
102433d6423SLionel Sambuc * was just loaded
103433d6423SLionel Sambuc */
104433d6423SLionel Sambuc if (Node->OwnerId != Info->OwnerId)
105433d6423SLionel Sambuc {
106433d6423SLionel Sambuc return (AE_OK);
107433d6423SLionel Sambuc }
108433d6423SLionel Sambuc
109433d6423SLionel Sambuc Info->ObjectCount++;
110433d6423SLionel Sambuc
111433d6423SLionel Sambuc /* And even then, we are only interested in a few object types */
112433d6423SLionel Sambuc
113*29492bb7SDavid van Moolenbroek switch (AcpiNsGetType (ObjHandle))
114433d6423SLionel Sambuc {
115433d6423SLionel Sambuc case ACPI_TYPE_REGION:
116433d6423SLionel Sambuc
117433d6423SLionel Sambuc Status = AcpiDsInitializeRegion (ObjHandle);
118433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
119433d6423SLionel Sambuc {
120433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status,
121433d6423SLionel Sambuc "During Region initialization %p [%4.4s]",
122433d6423SLionel Sambuc ObjHandle, AcpiUtGetNodeName (ObjHandle)));
123433d6423SLionel Sambuc }
124433d6423SLionel Sambuc
125433d6423SLionel Sambuc Info->OpRegionCount++;
126433d6423SLionel Sambuc break;
127433d6423SLionel Sambuc
128433d6423SLionel Sambuc case ACPI_TYPE_METHOD:
129*29492bb7SDavid van Moolenbroek /*
130*29492bb7SDavid van Moolenbroek * Auto-serialization support. We will examine each method that is
131*29492bb7SDavid van Moolenbroek * NotSerialized to determine if it creates any Named objects. If
132*29492bb7SDavid van Moolenbroek * it does, it will be marked serialized to prevent problems if
133*29492bb7SDavid van Moolenbroek * the method is entered by two or more threads and an attempt is
134*29492bb7SDavid van Moolenbroek * made to create the same named object twice -- which results in
135*29492bb7SDavid van Moolenbroek * an AE_ALREADY_EXISTS exception and method abort.
136*29492bb7SDavid van Moolenbroek */
137433d6423SLionel Sambuc Info->MethodCount++;
138*29492bb7SDavid van Moolenbroek ObjDesc = AcpiNsGetAttachedObject (Node);
139*29492bb7SDavid van Moolenbroek if (!ObjDesc)
140*29492bb7SDavid van Moolenbroek {
141433d6423SLionel Sambuc break;
142*29492bb7SDavid van Moolenbroek }
143433d6423SLionel Sambuc
144*29492bb7SDavid van Moolenbroek /* Ignore if already serialized */
145*29492bb7SDavid van Moolenbroek
146*29492bb7SDavid van Moolenbroek if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
147*29492bb7SDavid van Moolenbroek {
148*29492bb7SDavid van Moolenbroek Info->SerialMethodCount++;
149*29492bb7SDavid van Moolenbroek break;
150*29492bb7SDavid van Moolenbroek }
151*29492bb7SDavid van Moolenbroek
152*29492bb7SDavid van Moolenbroek if (AcpiGbl_AutoSerializeMethods)
153*29492bb7SDavid van Moolenbroek {
154*29492bb7SDavid van Moolenbroek /* Parse/scan method and serialize it if necessary */
155*29492bb7SDavid van Moolenbroek
156*29492bb7SDavid van Moolenbroek AcpiDsAutoSerializeMethod (Node, ObjDesc);
157*29492bb7SDavid van Moolenbroek if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
158*29492bb7SDavid van Moolenbroek {
159*29492bb7SDavid van Moolenbroek /* Method was just converted to Serialized */
160*29492bb7SDavid van Moolenbroek
161*29492bb7SDavid van Moolenbroek Info->SerialMethodCount++;
162*29492bb7SDavid van Moolenbroek Info->SerializedMethodCount++;
163*29492bb7SDavid van Moolenbroek break;
164*29492bb7SDavid van Moolenbroek }
165*29492bb7SDavid van Moolenbroek }
166*29492bb7SDavid van Moolenbroek
167*29492bb7SDavid van Moolenbroek Info->NonSerialMethodCount++;
168*29492bb7SDavid van Moolenbroek break;
169433d6423SLionel Sambuc
170433d6423SLionel Sambuc case ACPI_TYPE_DEVICE:
171433d6423SLionel Sambuc
172433d6423SLionel Sambuc Info->DeviceCount++;
173433d6423SLionel Sambuc break;
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc default:
176*29492bb7SDavid van Moolenbroek
177433d6423SLionel Sambuc break;
178433d6423SLionel Sambuc }
179433d6423SLionel Sambuc
180433d6423SLionel Sambuc /*
181433d6423SLionel Sambuc * We ignore errors from above, and always return OK, since
182433d6423SLionel Sambuc * we don't want to abort the walk on a single error.
183433d6423SLionel Sambuc */
184433d6423SLionel Sambuc return (AE_OK);
185433d6423SLionel Sambuc }
186433d6423SLionel Sambuc
187433d6423SLionel Sambuc
188433d6423SLionel Sambuc /*******************************************************************************
189433d6423SLionel Sambuc *
190433d6423SLionel Sambuc * FUNCTION: AcpiDsInitializeObjects
191433d6423SLionel Sambuc *
192433d6423SLionel Sambuc * PARAMETERS: TableDesc - Descriptor for parent ACPI table
193433d6423SLionel Sambuc * StartNode - Root of subtree to be initialized.
194433d6423SLionel Sambuc *
195433d6423SLionel Sambuc * RETURN: Status
196433d6423SLionel Sambuc *
197433d6423SLionel Sambuc * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
198433d6423SLionel Sambuc * necessary initialization on the objects found therein
199433d6423SLionel Sambuc *
200433d6423SLionel Sambuc ******************************************************************************/
201433d6423SLionel Sambuc
202433d6423SLionel Sambuc ACPI_STATUS
AcpiDsInitializeObjects(UINT32 TableIndex,ACPI_NAMESPACE_NODE * StartNode)203433d6423SLionel Sambuc AcpiDsInitializeObjects (
204433d6423SLionel Sambuc UINT32 TableIndex,
205433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *StartNode)
206433d6423SLionel Sambuc {
207433d6423SLionel Sambuc ACPI_STATUS Status;
208433d6423SLionel Sambuc ACPI_INIT_WALK_INFO Info;
209433d6423SLionel Sambuc ACPI_TABLE_HEADER *Table;
210433d6423SLionel Sambuc ACPI_OWNER_ID OwnerId;
211433d6423SLionel Sambuc
212433d6423SLionel Sambuc
213433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (DsInitializeObjects);
214433d6423SLionel Sambuc
215433d6423SLionel Sambuc
216433d6423SLionel Sambuc Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
217433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
218433d6423SLionel Sambuc {
219433d6423SLionel Sambuc return_ACPI_STATUS (Status);
220433d6423SLionel Sambuc }
221433d6423SLionel Sambuc
222433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
223433d6423SLionel Sambuc "**** Starting initialization of namespace objects ****\n"));
224433d6423SLionel Sambuc
225433d6423SLionel Sambuc /* Set all init info to zero */
226433d6423SLionel Sambuc
227433d6423SLionel Sambuc ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
228433d6423SLionel Sambuc
229433d6423SLionel Sambuc Info.OwnerId = OwnerId;
230433d6423SLionel Sambuc Info.TableIndex = TableIndex;
231433d6423SLionel Sambuc
232433d6423SLionel Sambuc /* Walk entire namespace from the supplied root */
233433d6423SLionel Sambuc
234433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
235433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
236433d6423SLionel Sambuc {
237433d6423SLionel Sambuc return_ACPI_STATUS (Status);
238433d6423SLionel Sambuc }
239433d6423SLionel Sambuc
240433d6423SLionel Sambuc /*
241433d6423SLionel Sambuc * We don't use AcpiWalkNamespace since we do not want to acquire
242433d6423SLionel Sambuc * the namespace reader lock.
243433d6423SLionel Sambuc */
244433d6423SLionel Sambuc Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,
245433d6423SLionel Sambuc ACPI_NS_WALK_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);
246433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
247433d6423SLionel Sambuc {
248433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
249433d6423SLionel Sambuc }
250433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
251433d6423SLionel Sambuc
252433d6423SLionel Sambuc Status = AcpiGetTableByIndex (TableIndex, &Table);
253433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
254433d6423SLionel Sambuc {
255433d6423SLionel Sambuc return_ACPI_STATUS (Status);
256433d6423SLionel Sambuc }
257433d6423SLionel Sambuc
258433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
259*29492bb7SDavid van Moolenbroek "Table [%4.4s] (id %4.4X) - %4u Objects with %3u Devices, "
260*29492bb7SDavid van Moolenbroek "%3u Regions, %3u Methods (%u/%u/%u Serial/Non/Cvt)\n",
261*29492bb7SDavid van Moolenbroek Table->Signature, OwnerId, Info.ObjectCount, Info.DeviceCount,
262*29492bb7SDavid van Moolenbroek Info.OpRegionCount, Info.MethodCount, Info.SerialMethodCount,
263*29492bb7SDavid van Moolenbroek Info.NonSerialMethodCount, Info.SerializedMethodCount));
264433d6423SLionel Sambuc
265*29492bb7SDavid van Moolenbroek ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
266*29492bb7SDavid van Moolenbroek Info.MethodCount, Info.OpRegionCount));
267433d6423SLionel Sambuc
268433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
269433d6423SLionel Sambuc }
270