1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: nsinit - namespace initialization
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 "acinterp.h"
49433d6423SLionel Sambuc
50433d6423SLionel Sambuc #define _COMPONENT ACPI_NAMESPACE
51433d6423SLionel Sambuc ACPI_MODULE_NAME ("nsinit")
52433d6423SLionel Sambuc
53433d6423SLionel Sambuc /* Local prototypes */
54433d6423SLionel Sambuc
55433d6423SLionel Sambuc static ACPI_STATUS
56433d6423SLionel Sambuc AcpiNsInitOneObject (
57433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
58433d6423SLionel Sambuc UINT32 Level,
59433d6423SLionel Sambuc void *Context,
60433d6423SLionel Sambuc void **ReturnValue);
61433d6423SLionel Sambuc
62433d6423SLionel Sambuc static ACPI_STATUS
63433d6423SLionel Sambuc AcpiNsInitOneDevice (
64433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
65433d6423SLionel Sambuc UINT32 NestingLevel,
66433d6423SLionel Sambuc void *Context,
67433d6423SLionel Sambuc void **ReturnValue);
68433d6423SLionel Sambuc
69433d6423SLionel Sambuc static ACPI_STATUS
70433d6423SLionel Sambuc AcpiNsFindIniMethods (
71433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
72433d6423SLionel Sambuc UINT32 NestingLevel,
73433d6423SLionel Sambuc void *Context,
74433d6423SLionel Sambuc void **ReturnValue);
75433d6423SLionel Sambuc
76433d6423SLionel Sambuc
77433d6423SLionel Sambuc /*******************************************************************************
78433d6423SLionel Sambuc *
79433d6423SLionel Sambuc * FUNCTION: AcpiNsInitializeObjects
80433d6423SLionel Sambuc *
81433d6423SLionel Sambuc * PARAMETERS: None
82433d6423SLionel Sambuc *
83433d6423SLionel Sambuc * RETURN: Status
84433d6423SLionel Sambuc *
85433d6423SLionel Sambuc * DESCRIPTION: Walk the entire namespace and perform any necessary
86433d6423SLionel Sambuc * initialization on the objects found therein
87433d6423SLionel Sambuc *
88433d6423SLionel Sambuc ******************************************************************************/
89433d6423SLionel Sambuc
90433d6423SLionel Sambuc ACPI_STATUS
AcpiNsInitializeObjects(void)91433d6423SLionel Sambuc AcpiNsInitializeObjects (
92433d6423SLionel Sambuc void)
93433d6423SLionel Sambuc {
94433d6423SLionel Sambuc ACPI_STATUS Status;
95433d6423SLionel Sambuc ACPI_INIT_WALK_INFO Info;
96433d6423SLionel Sambuc
97433d6423SLionel Sambuc
98433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsInitializeObjects);
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc
101433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
102433d6423SLionel Sambuc "**** Starting initialization of namespace objects ****\n"));
103433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
104*29492bb7SDavid van Moolenbroek "Completing Region/Field/Buffer/Package initialization:\n"));
105433d6423SLionel Sambuc
106433d6423SLionel Sambuc /* Set all init info to zero */
107433d6423SLionel Sambuc
108433d6423SLionel Sambuc ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
109433d6423SLionel Sambuc
110433d6423SLionel Sambuc /* Walk entire namespace from the supplied root */
111433d6423SLionel Sambuc
112433d6423SLionel Sambuc Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
113433d6423SLionel Sambuc ACPI_UINT32_MAX, AcpiNsInitOneObject, NULL,
114433d6423SLionel Sambuc &Info, NULL);
115433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
116433d6423SLionel Sambuc {
117433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
118433d6423SLionel Sambuc }
119433d6423SLionel Sambuc
120433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
121*29492bb7SDavid van Moolenbroek " Initialized %u/%u Regions %u/%u Fields %u/%u "
122433d6423SLionel Sambuc "Buffers %u/%u Packages (%u nodes)\n",
123433d6423SLionel Sambuc Info.OpRegionInit, Info.OpRegionCount,
124433d6423SLionel Sambuc Info.FieldInit, Info.FieldCount,
125433d6423SLionel Sambuc Info.BufferInit, Info.BufferCount,
126433d6423SLionel Sambuc Info.PackageInit, Info.PackageCount, Info.ObjectCount));
127433d6423SLionel Sambuc
128433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
129*29492bb7SDavid van Moolenbroek "%u Control Methods found\n%u Op Regions found\n",
130*29492bb7SDavid van Moolenbroek Info.MethodCount, Info.OpRegionCount));
131433d6423SLionel Sambuc
132433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
133433d6423SLionel Sambuc }
134433d6423SLionel Sambuc
135433d6423SLionel Sambuc
136433d6423SLionel Sambuc /*******************************************************************************
137433d6423SLionel Sambuc *
138433d6423SLionel Sambuc * FUNCTION: AcpiNsInitializeDevices
139433d6423SLionel Sambuc *
140433d6423SLionel Sambuc * PARAMETERS: None
141433d6423SLionel Sambuc *
142433d6423SLionel Sambuc * RETURN: ACPI_STATUS
143433d6423SLionel Sambuc *
144433d6423SLionel Sambuc * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
145433d6423SLionel Sambuc * This means running _INI on all present devices.
146433d6423SLionel Sambuc *
147433d6423SLionel Sambuc * Note: We install PCI config space handler on region access,
148433d6423SLionel Sambuc * not here.
149433d6423SLionel Sambuc *
150433d6423SLionel Sambuc ******************************************************************************/
151433d6423SLionel Sambuc
152433d6423SLionel Sambuc ACPI_STATUS
AcpiNsInitializeDevices(void)153433d6423SLionel Sambuc AcpiNsInitializeDevices (
154433d6423SLionel Sambuc void)
155433d6423SLionel Sambuc {
156433d6423SLionel Sambuc ACPI_STATUS Status;
157433d6423SLionel Sambuc ACPI_DEVICE_WALK_INFO Info;
158433d6423SLionel Sambuc
159433d6423SLionel Sambuc
160433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsInitializeDevices);
161433d6423SLionel Sambuc
162433d6423SLionel Sambuc
163433d6423SLionel Sambuc /* Init counters */
164433d6423SLionel Sambuc
165433d6423SLionel Sambuc Info.DeviceCount = 0;
166433d6423SLionel Sambuc Info.Num_STA = 0;
167433d6423SLionel Sambuc Info.Num_INI = 0;
168433d6423SLionel Sambuc
169433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
170433d6423SLionel Sambuc "Initializing Device/Processor/Thermal objects "
171*29492bb7SDavid van Moolenbroek "and executing _INI/_STA methods:\n"));
172433d6423SLionel Sambuc
173433d6423SLionel Sambuc /* Tree analysis: find all subtrees that contain _INI methods */
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
176433d6423SLionel Sambuc ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL);
177433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
178433d6423SLionel Sambuc {
179433d6423SLionel Sambuc goto ErrorExit;
180433d6423SLionel Sambuc }
181433d6423SLionel Sambuc
182433d6423SLionel Sambuc /* Allocate the evaluation information block */
183433d6423SLionel Sambuc
184433d6423SLionel Sambuc Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
185433d6423SLionel Sambuc if (!Info.EvaluateInfo)
186433d6423SLionel Sambuc {
187433d6423SLionel Sambuc Status = AE_NO_MEMORY;
188433d6423SLionel Sambuc goto ErrorExit;
189433d6423SLionel Sambuc }
190433d6423SLionel Sambuc
191433d6423SLionel Sambuc /*
192433d6423SLionel Sambuc * Execute the "global" _INI method that may appear at the root. This
193433d6423SLionel Sambuc * support is provided for Windows compatibility (Vista+) and is not
194433d6423SLionel Sambuc * part of the ACPI specification.
195433d6423SLionel Sambuc */
196433d6423SLionel Sambuc Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode;
197*29492bb7SDavid van Moolenbroek Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI;
198433d6423SLionel Sambuc Info.EvaluateInfo->Parameters = NULL;
199433d6423SLionel Sambuc Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc Status = AcpiNsEvaluate (Info.EvaluateInfo);
202433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
203433d6423SLionel Sambuc {
204433d6423SLionel Sambuc Info.Num_INI++;
205433d6423SLionel Sambuc }
206433d6423SLionel Sambuc
207433d6423SLionel Sambuc /* Walk namespace to execute all _INIs on present devices */
208433d6423SLionel Sambuc
209433d6423SLionel Sambuc Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
210433d6423SLionel Sambuc ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL);
211433d6423SLionel Sambuc
212433d6423SLionel Sambuc /*
213433d6423SLionel Sambuc * Any _OSI requests should be completed by now. If the BIOS has
214433d6423SLionel Sambuc * requested any Windows OSI strings, we will always truncate
215433d6423SLionel Sambuc * I/O addresses to 16 bits -- for Windows compatibility.
216433d6423SLionel Sambuc */
217433d6423SLionel Sambuc if (AcpiGbl_OsiData >= ACPI_OSI_WIN_2000)
218433d6423SLionel Sambuc {
219433d6423SLionel Sambuc AcpiGbl_TruncateIoAddresses = TRUE;
220433d6423SLionel Sambuc }
221433d6423SLionel Sambuc
222433d6423SLionel Sambuc ACPI_FREE (Info.EvaluateInfo);
223433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
224433d6423SLionel Sambuc {
225433d6423SLionel Sambuc goto ErrorExit;
226433d6423SLionel Sambuc }
227433d6423SLionel Sambuc
228433d6423SLionel Sambuc ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
229*29492bb7SDavid van Moolenbroek " Executed %u _INI methods requiring %u _STA executions "
230433d6423SLionel Sambuc "(examined %u objects)\n",
231433d6423SLionel Sambuc Info.Num_INI, Info.Num_STA, Info.DeviceCount));
232433d6423SLionel Sambuc
233433d6423SLionel Sambuc return_ACPI_STATUS (Status);
234433d6423SLionel Sambuc
235433d6423SLionel Sambuc
236433d6423SLionel Sambuc ErrorExit:
237433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
238433d6423SLionel Sambuc return_ACPI_STATUS (Status);
239433d6423SLionel Sambuc }
240433d6423SLionel Sambuc
241433d6423SLionel Sambuc
242433d6423SLionel Sambuc /*******************************************************************************
243433d6423SLionel Sambuc *
244433d6423SLionel Sambuc * FUNCTION: AcpiNsInitOneObject
245433d6423SLionel Sambuc *
246433d6423SLionel Sambuc * PARAMETERS: ObjHandle - Node
247433d6423SLionel Sambuc * Level - Current nesting level
248433d6423SLionel Sambuc * Context - Points to a init info struct
249433d6423SLionel Sambuc * ReturnValue - Not used
250433d6423SLionel Sambuc *
251433d6423SLionel Sambuc * RETURN: Status
252433d6423SLionel Sambuc *
253433d6423SLionel Sambuc * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
254433d6423SLionel Sambuc * within the namespace.
255433d6423SLionel Sambuc *
256433d6423SLionel Sambuc * Currently, the only objects that require initialization are:
257433d6423SLionel Sambuc * 1) Methods
258433d6423SLionel Sambuc * 2) Op Regions
259433d6423SLionel Sambuc *
260433d6423SLionel Sambuc ******************************************************************************/
261433d6423SLionel Sambuc
262433d6423SLionel Sambuc static ACPI_STATUS
AcpiNsInitOneObject(ACPI_HANDLE ObjHandle,UINT32 Level,void * Context,void ** ReturnValue)263433d6423SLionel Sambuc AcpiNsInitOneObject (
264433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
265433d6423SLionel Sambuc UINT32 Level,
266433d6423SLionel Sambuc void *Context,
267433d6423SLionel Sambuc void **ReturnValue)
268433d6423SLionel Sambuc {
269433d6423SLionel Sambuc ACPI_OBJECT_TYPE Type;
270433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
271433d6423SLionel Sambuc ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;
272433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
273433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ObjDesc;
274433d6423SLionel Sambuc
275433d6423SLionel Sambuc
276433d6423SLionel Sambuc ACPI_FUNCTION_NAME (NsInitOneObject);
277433d6423SLionel Sambuc
278433d6423SLionel Sambuc
279433d6423SLionel Sambuc Info->ObjectCount++;
280433d6423SLionel Sambuc
281433d6423SLionel Sambuc /* And even then, we are only interested in a few object types */
282433d6423SLionel Sambuc
283433d6423SLionel Sambuc Type = AcpiNsGetType (ObjHandle);
284433d6423SLionel Sambuc ObjDesc = AcpiNsGetAttachedObject (Node);
285433d6423SLionel Sambuc if (!ObjDesc)
286433d6423SLionel Sambuc {
287433d6423SLionel Sambuc return (AE_OK);
288433d6423SLionel Sambuc }
289433d6423SLionel Sambuc
290433d6423SLionel Sambuc /* Increment counters for object types we are looking for */
291433d6423SLionel Sambuc
292433d6423SLionel Sambuc switch (Type)
293433d6423SLionel Sambuc {
294433d6423SLionel Sambuc case ACPI_TYPE_REGION:
295*29492bb7SDavid van Moolenbroek
296433d6423SLionel Sambuc Info->OpRegionCount++;
297433d6423SLionel Sambuc break;
298433d6423SLionel Sambuc
299433d6423SLionel Sambuc case ACPI_TYPE_BUFFER_FIELD:
300*29492bb7SDavid van Moolenbroek
301433d6423SLionel Sambuc Info->FieldCount++;
302433d6423SLionel Sambuc break;
303433d6423SLionel Sambuc
304433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_BANK_FIELD:
305*29492bb7SDavid van Moolenbroek
306433d6423SLionel Sambuc Info->FieldCount++;
307433d6423SLionel Sambuc break;
308433d6423SLionel Sambuc
309433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
310*29492bb7SDavid van Moolenbroek
311433d6423SLionel Sambuc Info->BufferCount++;
312433d6423SLionel Sambuc break;
313433d6423SLionel Sambuc
314433d6423SLionel Sambuc case ACPI_TYPE_PACKAGE:
315*29492bb7SDavid van Moolenbroek
316433d6423SLionel Sambuc Info->PackageCount++;
317433d6423SLionel Sambuc break;
318433d6423SLionel Sambuc
319433d6423SLionel Sambuc default:
320433d6423SLionel Sambuc
321433d6423SLionel Sambuc /* No init required, just exit now */
322*29492bb7SDavid van Moolenbroek
323433d6423SLionel Sambuc return (AE_OK);
324433d6423SLionel Sambuc }
325433d6423SLionel Sambuc
326433d6423SLionel Sambuc /* If the object is already initialized, nothing else to do */
327433d6423SLionel Sambuc
328433d6423SLionel Sambuc if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
329433d6423SLionel Sambuc {
330433d6423SLionel Sambuc return (AE_OK);
331433d6423SLionel Sambuc }
332433d6423SLionel Sambuc
333433d6423SLionel Sambuc /* Must lock the interpreter before executing AML code */
334433d6423SLionel Sambuc
335433d6423SLionel Sambuc AcpiExEnterInterpreter ();
336433d6423SLionel Sambuc
337433d6423SLionel Sambuc /*
338433d6423SLionel Sambuc * Each of these types can contain executable AML code within the
339433d6423SLionel Sambuc * declaration.
340433d6423SLionel Sambuc */
341433d6423SLionel Sambuc switch (Type)
342433d6423SLionel Sambuc {
343433d6423SLionel Sambuc case ACPI_TYPE_REGION:
344433d6423SLionel Sambuc
345433d6423SLionel Sambuc Info->OpRegionInit++;
346433d6423SLionel Sambuc Status = AcpiDsGetRegionArguments (ObjDesc);
347433d6423SLionel Sambuc break;
348433d6423SLionel Sambuc
349433d6423SLionel Sambuc case ACPI_TYPE_BUFFER_FIELD:
350433d6423SLionel Sambuc
351433d6423SLionel Sambuc Info->FieldInit++;
352433d6423SLionel Sambuc Status = AcpiDsGetBufferFieldArguments (ObjDesc);
353433d6423SLionel Sambuc break;
354433d6423SLionel Sambuc
355433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_BANK_FIELD:
356433d6423SLionel Sambuc
357433d6423SLionel Sambuc Info->FieldInit++;
358433d6423SLionel Sambuc Status = AcpiDsGetBankFieldArguments (ObjDesc);
359433d6423SLionel Sambuc break;
360433d6423SLionel Sambuc
361433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
362433d6423SLionel Sambuc
363433d6423SLionel Sambuc Info->BufferInit++;
364433d6423SLionel Sambuc Status = AcpiDsGetBufferArguments (ObjDesc);
365433d6423SLionel Sambuc break;
366433d6423SLionel Sambuc
367433d6423SLionel Sambuc case ACPI_TYPE_PACKAGE:
368433d6423SLionel Sambuc
369433d6423SLionel Sambuc Info->PackageInit++;
370433d6423SLionel Sambuc Status = AcpiDsGetPackageArguments (ObjDesc);
371433d6423SLionel Sambuc break;
372433d6423SLionel Sambuc
373433d6423SLionel Sambuc default:
374*29492bb7SDavid van Moolenbroek
375433d6423SLionel Sambuc /* No other types can get here */
376*29492bb7SDavid van Moolenbroek
377433d6423SLionel Sambuc break;
378433d6423SLionel Sambuc }
379433d6423SLionel Sambuc
380433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
381433d6423SLionel Sambuc {
382433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status,
383433d6423SLionel Sambuc "Could not execute arguments for [%4.4s] (%s)",
384433d6423SLionel Sambuc AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
385433d6423SLionel Sambuc }
386433d6423SLionel Sambuc
387433d6423SLionel Sambuc /*
388433d6423SLionel Sambuc * We ignore errors from above, and always return OK, since we don't want
389433d6423SLionel Sambuc * to abort the walk on any single error.
390433d6423SLionel Sambuc */
391433d6423SLionel Sambuc AcpiExExitInterpreter ();
392433d6423SLionel Sambuc return (AE_OK);
393433d6423SLionel Sambuc }
394433d6423SLionel Sambuc
395433d6423SLionel Sambuc
396433d6423SLionel Sambuc /*******************************************************************************
397433d6423SLionel Sambuc *
398433d6423SLionel Sambuc * FUNCTION: AcpiNsFindIniMethods
399433d6423SLionel Sambuc *
400433d6423SLionel Sambuc * PARAMETERS: ACPI_WALK_CALLBACK
401433d6423SLionel Sambuc *
402433d6423SLionel Sambuc * RETURN: ACPI_STATUS
403433d6423SLionel Sambuc *
404433d6423SLionel Sambuc * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
405433d6423SLionel Sambuc * device/processor/thermal objects, and marks the entire subtree
406433d6423SLionel Sambuc * with a SUBTREE_HAS_INI flag. This flag is used during the
407433d6423SLionel Sambuc * subsequent device initialization walk to avoid entire subtrees
408433d6423SLionel Sambuc * that do not contain an _INI.
409433d6423SLionel Sambuc *
410433d6423SLionel Sambuc ******************************************************************************/
411433d6423SLionel Sambuc
412433d6423SLionel Sambuc static ACPI_STATUS
AcpiNsFindIniMethods(ACPI_HANDLE ObjHandle,UINT32 NestingLevel,void * Context,void ** ReturnValue)413433d6423SLionel Sambuc AcpiNsFindIniMethods (
414433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
415433d6423SLionel Sambuc UINT32 NestingLevel,
416433d6423SLionel Sambuc void *Context,
417433d6423SLionel Sambuc void **ReturnValue)
418433d6423SLionel Sambuc {
419433d6423SLionel Sambuc ACPI_DEVICE_WALK_INFO *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
420433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
421433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode;
422433d6423SLionel Sambuc
423433d6423SLionel Sambuc
424433d6423SLionel Sambuc /* Keep count of device/processor/thermal objects */
425433d6423SLionel Sambuc
426433d6423SLionel Sambuc Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
427433d6423SLionel Sambuc if ((Node->Type == ACPI_TYPE_DEVICE) ||
428433d6423SLionel Sambuc (Node->Type == ACPI_TYPE_PROCESSOR) ||
429433d6423SLionel Sambuc (Node->Type == ACPI_TYPE_THERMAL))
430433d6423SLionel Sambuc {
431433d6423SLionel Sambuc Info->DeviceCount++;
432433d6423SLionel Sambuc return (AE_OK);
433433d6423SLionel Sambuc }
434433d6423SLionel Sambuc
435433d6423SLionel Sambuc /* We are only looking for methods named _INI */
436433d6423SLionel Sambuc
437433d6423SLionel Sambuc if (!ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__INI))
438433d6423SLionel Sambuc {
439433d6423SLionel Sambuc return (AE_OK);
440433d6423SLionel Sambuc }
441433d6423SLionel Sambuc
442433d6423SLionel Sambuc /*
443433d6423SLionel Sambuc * The only _INI methods that we care about are those that are
444433d6423SLionel Sambuc * present under Device, Processor, and Thermal objects.
445433d6423SLionel Sambuc */
446433d6423SLionel Sambuc ParentNode = Node->Parent;
447433d6423SLionel Sambuc switch (ParentNode->Type)
448433d6423SLionel Sambuc {
449433d6423SLionel Sambuc case ACPI_TYPE_DEVICE:
450433d6423SLionel Sambuc case ACPI_TYPE_PROCESSOR:
451433d6423SLionel Sambuc case ACPI_TYPE_THERMAL:
452433d6423SLionel Sambuc
453433d6423SLionel Sambuc /* Mark parent and bubble up the INI present flag to the root */
454433d6423SLionel Sambuc
455433d6423SLionel Sambuc while (ParentNode)
456433d6423SLionel Sambuc {
457433d6423SLionel Sambuc ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
458433d6423SLionel Sambuc ParentNode = ParentNode->Parent;
459433d6423SLionel Sambuc }
460433d6423SLionel Sambuc break;
461433d6423SLionel Sambuc
462433d6423SLionel Sambuc default:
463*29492bb7SDavid van Moolenbroek
464433d6423SLionel Sambuc break;
465433d6423SLionel Sambuc }
466433d6423SLionel Sambuc
467433d6423SLionel Sambuc return (AE_OK);
468433d6423SLionel Sambuc }
469433d6423SLionel Sambuc
470433d6423SLionel Sambuc
471433d6423SLionel Sambuc /*******************************************************************************
472433d6423SLionel Sambuc *
473433d6423SLionel Sambuc * FUNCTION: AcpiNsInitOneDevice
474433d6423SLionel Sambuc *
475433d6423SLionel Sambuc * PARAMETERS: ACPI_WALK_CALLBACK
476433d6423SLionel Sambuc *
477433d6423SLionel Sambuc * RETURN: ACPI_STATUS
478433d6423SLionel Sambuc *
479433d6423SLionel Sambuc * DESCRIPTION: This is called once per device soon after ACPI is enabled
480433d6423SLionel Sambuc * to initialize each device. It determines if the device is
481433d6423SLionel Sambuc * present, and if so, calls _INI.
482433d6423SLionel Sambuc *
483433d6423SLionel Sambuc ******************************************************************************/
484433d6423SLionel Sambuc
485433d6423SLionel Sambuc static ACPI_STATUS
AcpiNsInitOneDevice(ACPI_HANDLE ObjHandle,UINT32 NestingLevel,void * Context,void ** ReturnValue)486433d6423SLionel Sambuc AcpiNsInitOneDevice (
487433d6423SLionel Sambuc ACPI_HANDLE ObjHandle,
488433d6423SLionel Sambuc UINT32 NestingLevel,
489433d6423SLionel Sambuc void *Context,
490433d6423SLionel Sambuc void **ReturnValue)
491433d6423SLionel Sambuc {
492433d6423SLionel Sambuc ACPI_DEVICE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
493433d6423SLionel Sambuc ACPI_EVALUATE_INFO *Info = WalkInfo->EvaluateInfo;
494433d6423SLionel Sambuc UINT32 Flags;
495433d6423SLionel Sambuc ACPI_STATUS Status;
496433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *DeviceNode;
497433d6423SLionel Sambuc
498433d6423SLionel Sambuc
499433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsInitOneDevice);
500433d6423SLionel Sambuc
501433d6423SLionel Sambuc
502433d6423SLionel Sambuc /* We are interested in Devices, Processors and ThermalZones only */
503433d6423SLionel Sambuc
504433d6423SLionel Sambuc DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
505433d6423SLionel Sambuc if ((DeviceNode->Type != ACPI_TYPE_DEVICE) &&
506433d6423SLionel Sambuc (DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
507433d6423SLionel Sambuc (DeviceNode->Type != ACPI_TYPE_THERMAL))
508433d6423SLionel Sambuc {
509433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
510433d6423SLionel Sambuc }
511433d6423SLionel Sambuc
512433d6423SLionel Sambuc /*
513433d6423SLionel Sambuc * Because of an earlier namespace analysis, all subtrees that contain an
514433d6423SLionel Sambuc * _INI method are tagged.
515433d6423SLionel Sambuc *
516433d6423SLionel Sambuc * If this device subtree does not contain any _INI methods, we
517433d6423SLionel Sambuc * can exit now and stop traversing this entire subtree.
518433d6423SLionel Sambuc */
519433d6423SLionel Sambuc if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
520433d6423SLionel Sambuc {
521433d6423SLionel Sambuc return_ACPI_STATUS (AE_CTRL_DEPTH);
522433d6423SLionel Sambuc }
523433d6423SLionel Sambuc
524433d6423SLionel Sambuc /*
525433d6423SLionel Sambuc * Run _STA to determine if this device is present and functioning. We
526433d6423SLionel Sambuc * must know this information for two important reasons (from ACPI spec):
527433d6423SLionel Sambuc *
528433d6423SLionel Sambuc * 1) We can only run _INI if the device is present.
529433d6423SLionel Sambuc * 2) We must abort the device tree walk on this subtree if the device is
530433d6423SLionel Sambuc * not present and is not functional (we will not examine the children)
531433d6423SLionel Sambuc *
532433d6423SLionel Sambuc * The _STA method is not required to be present under the device, we
533433d6423SLionel Sambuc * assume the device is present if _STA does not exist.
534433d6423SLionel Sambuc */
535433d6423SLionel Sambuc ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
536433d6423SLionel Sambuc ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
537433d6423SLionel Sambuc
538433d6423SLionel Sambuc Status = AcpiUtExecute_STA (DeviceNode, &Flags);
539433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
540433d6423SLionel Sambuc {
541433d6423SLionel Sambuc /* Ignore error and move on to next device */
542433d6423SLionel Sambuc
543433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
544433d6423SLionel Sambuc }
545433d6423SLionel Sambuc
546433d6423SLionel Sambuc /*
547433d6423SLionel Sambuc * Flags == -1 means that _STA was not found. In this case, we assume that
548433d6423SLionel Sambuc * the device is both present and functional.
549433d6423SLionel Sambuc *
550433d6423SLionel Sambuc * From the ACPI spec, description of _STA:
551433d6423SLionel Sambuc *
552433d6423SLionel Sambuc * "If a device object (including the processor object) does not have an
553433d6423SLionel Sambuc * _STA object, then OSPM assumes that all of the above bits are set (in
554433d6423SLionel Sambuc * other words, the device is present, ..., and functioning)"
555433d6423SLionel Sambuc */
556433d6423SLionel Sambuc if (Flags != ACPI_UINT32_MAX)
557433d6423SLionel Sambuc {
558433d6423SLionel Sambuc WalkInfo->Num_STA++;
559433d6423SLionel Sambuc }
560433d6423SLionel Sambuc
561433d6423SLionel Sambuc /*
562433d6423SLionel Sambuc * Examine the PRESENT and FUNCTIONING status bits
563433d6423SLionel Sambuc *
564433d6423SLionel Sambuc * Note: ACPI spec does not seem to specify behavior for the present but
565433d6423SLionel Sambuc * not functioning case, so we assume functioning if present.
566433d6423SLionel Sambuc */
567433d6423SLionel Sambuc if (!(Flags & ACPI_STA_DEVICE_PRESENT))
568433d6423SLionel Sambuc {
569433d6423SLionel Sambuc /* Device is not present, we must examine the Functioning bit */
570433d6423SLionel Sambuc
571433d6423SLionel Sambuc if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
572433d6423SLionel Sambuc {
573433d6423SLionel Sambuc /*
574433d6423SLionel Sambuc * Device is not present but is "functioning". In this case,
575433d6423SLionel Sambuc * we will not run _INI, but we continue to examine the children
576433d6423SLionel Sambuc * of this device.
577433d6423SLionel Sambuc *
578433d6423SLionel Sambuc * From the ACPI spec, description of _STA: (Note - no mention
579433d6423SLionel Sambuc * of whether to run _INI or not on the device in question)
580433d6423SLionel Sambuc *
581433d6423SLionel Sambuc * "_STA may return bit 0 clear (not present) with bit 3 set
582433d6423SLionel Sambuc * (device is functional). This case is used to indicate a valid
583433d6423SLionel Sambuc * device for which no device driver should be loaded (for example,
584433d6423SLionel Sambuc * a bridge device.) Children of this device may be present and
585433d6423SLionel Sambuc * valid. OSPM should continue enumeration below a device whose
586433d6423SLionel Sambuc * _STA returns this bit combination"
587433d6423SLionel Sambuc */
588433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
589433d6423SLionel Sambuc }
590433d6423SLionel Sambuc else
591433d6423SLionel Sambuc {
592433d6423SLionel Sambuc /*
593433d6423SLionel Sambuc * Device is not present and is not functioning. We must abort the
594433d6423SLionel Sambuc * walk of this subtree immediately -- don't look at the children
595433d6423SLionel Sambuc * of such a device.
596433d6423SLionel Sambuc *
597433d6423SLionel Sambuc * From the ACPI spec, description of _INI:
598433d6423SLionel Sambuc *
599433d6423SLionel Sambuc * "If the _STA method indicates that the device is not present,
600433d6423SLionel Sambuc * OSPM will not run the _INI and will not examine the children
601433d6423SLionel Sambuc * of the device for _INI methods"
602433d6423SLionel Sambuc */
603433d6423SLionel Sambuc return_ACPI_STATUS (AE_CTRL_DEPTH);
604433d6423SLionel Sambuc }
605433d6423SLionel Sambuc }
606433d6423SLionel Sambuc
607433d6423SLionel Sambuc /*
608433d6423SLionel Sambuc * The device is present or is assumed present if no _STA exists.
609433d6423SLionel Sambuc * Run the _INI if it exists (not required to exist)
610433d6423SLionel Sambuc *
611433d6423SLionel Sambuc * Note: We know there is an _INI within this subtree, but it may not be
612433d6423SLionel Sambuc * under this particular device, it may be lower in the branch.
613433d6423SLionel Sambuc */
614433d6423SLionel Sambuc ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
615433d6423SLionel Sambuc ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
616433d6423SLionel Sambuc
617*29492bb7SDavid van Moolenbroek ACPI_MEMSET (Info, 0, sizeof (ACPI_EVALUATE_INFO));
618433d6423SLionel Sambuc Info->PrefixNode = DeviceNode;
619*29492bb7SDavid van Moolenbroek Info->RelativePathname = METHOD_NAME__INI;
620433d6423SLionel Sambuc Info->Parameters = NULL;
621433d6423SLionel Sambuc Info->Flags = ACPI_IGNORE_RETURN_VALUE;
622433d6423SLionel Sambuc
623433d6423SLionel Sambuc Status = AcpiNsEvaluate (Info);
624433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
625433d6423SLionel Sambuc {
626433d6423SLionel Sambuc WalkInfo->Num_INI++;
627433d6423SLionel Sambuc }
628433d6423SLionel Sambuc
629433d6423SLionel Sambuc #ifdef ACPI_DEBUG_OUTPUT
630433d6423SLionel Sambuc else if (Status != AE_NOT_FOUND)
631433d6423SLionel Sambuc {
632433d6423SLionel Sambuc /* Ignore error and move on to next device */
633433d6423SLionel Sambuc
634*29492bb7SDavid van Moolenbroek char *ScopeName = AcpiNsGetExternalPathname (Info->Node);
635433d6423SLionel Sambuc
636433d6423SLionel Sambuc ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
637433d6423SLionel Sambuc ScopeName));
638433d6423SLionel Sambuc ACPI_FREE (ScopeName);
639433d6423SLionel Sambuc }
640433d6423SLionel Sambuc #endif
641433d6423SLionel Sambuc
642433d6423SLionel Sambuc /* Ignore errors from above */
643433d6423SLionel Sambuc
644433d6423SLionel Sambuc Status = AE_OK;
645433d6423SLionel Sambuc
646433d6423SLionel Sambuc /*
647433d6423SLionel Sambuc * The _INI method has been run if present; call the Global Initialization
648433d6423SLionel Sambuc * Handler for this device.
649433d6423SLionel Sambuc */
650433d6423SLionel Sambuc if (AcpiGbl_InitHandler)
651433d6423SLionel Sambuc {
652433d6423SLionel Sambuc Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
653433d6423SLionel Sambuc }
654433d6423SLionel Sambuc
655433d6423SLionel Sambuc return_ACPI_STATUS (Status);
656433d6423SLionel Sambuc }
657