Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/dev/acpica/components/namespace/nsinit.c
48524 views
1
/******************************************************************************
2
*
3
* Module Name: nsinit - namespace initialization
4
*
5
*****************************************************************************/
6
7
/******************************************************************************
8
*
9
* 1. Copyright Notice
10
*
11
* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12
* All rights reserved.
13
*
14
* 2. License
15
*
16
* 2.1. This is your license from Intel Corp. under its intellectual property
17
* rights. You may have additional license terms from the party that provided
18
* you this software, covering your right to use that party's intellectual
19
* property rights.
20
*
21
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
* copy of the source code appearing in this file ("Covered Code") an
23
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
* base code distributed originally by Intel ("Original Intel Code") to copy,
25
* make derivatives, distribute, use and display any portion of the Covered
26
* Code in any form, with the right to sublicense such rights; and
27
*
28
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
* license (with the right to sublicense), under only those claims of Intel
30
* patents that are infringed by the Original Intel Code, to make, use, sell,
31
* offer to sell, and import the Covered Code and derivative works thereof
32
* solely to the minimum extent necessary to exercise the above copyright
33
* license, and in no event shall the patent license extend to any additions
34
* to or modifications of the Original Intel Code. No other license or right
35
* is granted directly or by implication, estoppel or otherwise;
36
*
37
* The above copyright and patent license is granted only if the following
38
* conditions are met:
39
*
40
* 3. Conditions
41
*
42
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
* Redistribution of source code of any substantial portion of the Covered
44
* Code or modification with rights to further distribute source must include
45
* the above Copyright Notice, the above License, this list of Conditions,
46
* and the following Disclaimer and Export Compliance provision. In addition,
47
* Licensee must cause all Covered Code to which Licensee contributes to
48
* contain a file documenting the changes Licensee made to create that Covered
49
* Code and the date of any change. Licensee must include in that file the
50
* documentation of any changes made by any predecessor Licensee. Licensee
51
* must include a prominent statement that the modification is derived,
52
* directly or indirectly, from Original Intel Code.
53
*
54
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
* Redistribution of source code of any substantial portion of the Covered
56
* Code or modification without rights to further distribute source must
57
* include the following Disclaimer and Export Compliance provision in the
58
* documentation and/or other materials provided with distribution. In
59
* addition, Licensee may not authorize further sublicense of source of any
60
* portion of the Covered Code, and must include terms to the effect that the
61
* license from Licensee to its licensee is limited to the intellectual
62
* property embodied in the software Licensee provides to its licensee, and
63
* not to intellectual property embodied in modifications its licensee may
64
* make.
65
*
66
* 3.3. Redistribution of Executable. Redistribution in executable form of any
67
* substantial portion of the Covered Code or modification must reproduce the
68
* above Copyright Notice, and the following Disclaimer and Export Compliance
69
* provision in the documentation and/or other materials provided with the
70
* distribution.
71
*
72
* 3.4. Intel retains all right, title, and interest in and to the Original
73
* Intel Code.
74
*
75
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
* Intel shall be used in advertising or otherwise to promote the sale, use or
77
* other dealings in products derived from or relating to the Covered Code
78
* without prior written authorization from Intel.
79
*
80
* 4. Disclaimer and Export Compliance
81
*
82
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
* PARTICULAR PURPOSE.
89
*
90
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
* LIMITED REMEDY.
98
*
99
* 4.3. Licensee shall not export, either directly or indirectly, any of this
100
* software or system incorporating such software without first obtaining any
101
* required license or other approval from the U. S. Department of Commerce or
102
* any other agency or department of the United States Government. In the
103
* event Licensee exports any such software from the United States or
104
* re-exports any such software from a foreign destination, Licensee shall
105
* ensure that the distribution and export/re-export of the software is in
106
* compliance with all laws, regulations, orders, or other restrictions of the
107
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
* any of its subsidiaries will export/re-export any technical data, process,
109
* software, or service, directly or indirectly, to any country for which the
110
* United States government or any agency thereof requires an export license,
111
* other governmental approval, or letter of assurance, without first obtaining
112
* such license, approval or letter.
113
*
114
*****************************************************************************
115
*
116
* Alternatively, you may choose to be licensed under the terms of the
117
* following license:
118
*
119
* Redistribution and use in source and binary forms, with or without
120
* modification, are permitted provided that the following conditions
121
* are met:
122
* 1. Redistributions of source code must retain the above copyright
123
* notice, this list of conditions, and the following disclaimer,
124
* without modification.
125
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
126
* substantially similar to the "NO WARRANTY" disclaimer below
127
* ("Disclaimer") and any redistribution must be conditioned upon
128
* including a substantially similar Disclaimer requirement for further
129
* binary redistribution.
130
* 3. Neither the names of the above-listed copyright holders nor the names
131
* of any contributors may be used to endorse or promote products derived
132
* from this software without specific prior written permission.
133
*
134
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145
*
146
* Alternatively, you may choose to be licensed under the terms of the
147
* GNU General Public License ("GPL") version 2 as published by the Free
148
* Software Foundation.
149
*
150
*****************************************************************************/
151
152
#include <contrib/dev/acpica/include/acpi.h>
153
#include <contrib/dev/acpica/include/accommon.h>
154
#include <contrib/dev/acpica/include/acnamesp.h>
155
#include <contrib/dev/acpica/include/acdispat.h>
156
#include <contrib/dev/acpica/include/acinterp.h>
157
#include <contrib/dev/acpica/include/acevents.h>
158
159
#define _COMPONENT ACPI_NAMESPACE
160
ACPI_MODULE_NAME ("nsinit")
161
162
/* Local prototypes */
163
164
static ACPI_STATUS
165
AcpiNsInitOneObject (
166
ACPI_HANDLE ObjHandle,
167
UINT32 Level,
168
void *Context,
169
void **ReturnValue);
170
171
static ACPI_STATUS
172
AcpiNsInitOneDevice (
173
ACPI_HANDLE ObjHandle,
174
UINT32 NestingLevel,
175
void *Context,
176
void **ReturnValue);
177
178
static ACPI_STATUS
179
AcpiNsFindIniMethods (
180
ACPI_HANDLE ObjHandle,
181
UINT32 NestingLevel,
182
void *Context,
183
void **ReturnValue);
184
185
186
/*******************************************************************************
187
*
188
* FUNCTION: AcpiNsInitializeObjects
189
*
190
* PARAMETERS: None
191
*
192
* RETURN: Status
193
*
194
* DESCRIPTION: Walk the entire namespace and perform any necessary
195
* initialization on the objects found therein
196
*
197
******************************************************************************/
198
199
ACPI_STATUS
200
AcpiNsInitializeObjects (
201
void)
202
{
203
ACPI_STATUS Status;
204
ACPI_INIT_WALK_INFO Info;
205
206
207
ACPI_FUNCTION_TRACE (NsInitializeObjects);
208
209
210
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
211
"[Init] Completing Initialization of ACPI Objects\n"));
212
ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
213
"**** Starting initialization of namespace objects ****\n"));
214
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
215
"Final data object initialization: "));
216
217
/* Clear the info block */
218
219
memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
220
221
/* Walk entire namespace from the supplied root */
222
223
/*
224
* TBD: will become ACPI_TYPE_PACKAGE as this type object
225
* is now the only one that supports deferred initialization
226
* (forward references).
227
*/
228
Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
229
ACPI_UINT32_MAX, AcpiNsInitOneObject, NULL, &Info, NULL);
230
if (ACPI_FAILURE (Status))
231
{
232
ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
233
}
234
235
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
236
"Namespace contains %u (0x%X) objects\n",
237
Info.ObjectCount,
238
Info.ObjectCount));
239
240
ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
241
"%u Control Methods found\n%u Op Regions found\n",
242
Info.MethodCount, Info.OpRegionCount));
243
244
return_ACPI_STATUS (AE_OK);
245
}
246
247
248
/*******************************************************************************
249
*
250
* FUNCTION: AcpiNsInitializeDevices
251
*
252
* PARAMETERS: None
253
*
254
* RETURN: ACPI_STATUS
255
*
256
* DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
257
* This means running _INI on all present devices.
258
*
259
* Note: We install PCI config space handler on region access,
260
* not here.
261
*
262
******************************************************************************/
263
264
ACPI_STATUS
265
AcpiNsInitializeDevices (
266
UINT32 Flags)
267
{
268
ACPI_STATUS Status = AE_OK;
269
ACPI_DEVICE_WALK_INFO Info;
270
ACPI_HANDLE Handle;
271
272
273
ACPI_FUNCTION_TRACE (NsInitializeDevices);
274
275
276
if (!(Flags & ACPI_NO_DEVICE_INIT))
277
{
278
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
279
"[Init] Initializing ACPI Devices\n"));
280
281
/* Init counters */
282
283
Info.DeviceCount = 0;
284
Info.Num_STA = 0;
285
Info.Num_INI = 0;
286
287
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
288
"Initializing Device/Processor/Thermal objects "
289
"and executing _INI/_STA methods:\n"));
290
291
/* Tree analysis: find all subtrees that contain _INI methods */
292
293
Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
294
ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL);
295
if (ACPI_FAILURE (Status))
296
{
297
goto ErrorExit;
298
}
299
300
/* Allocate the evaluation information block */
301
302
Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
303
if (!Info.EvaluateInfo)
304
{
305
Status = AE_NO_MEMORY;
306
goto ErrorExit;
307
}
308
309
/*
310
* Execute the "global" _INI method that may appear at the root.
311
* This support is provided for Windows compatibility (Vista+) and
312
* is not part of the ACPI specification.
313
*/
314
Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode;
315
Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI;
316
Info.EvaluateInfo->Parameters = NULL;
317
Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
318
319
Status = AcpiNsEvaluate (Info.EvaluateInfo);
320
if (ACPI_SUCCESS (Status))
321
{
322
Info.Num_INI++;
323
}
324
325
/*
326
* Execute \_SB._INI.
327
* There appears to be a strict order requirement for \_SB._INI,
328
* which should be evaluated before any _REG evaluations.
329
*/
330
Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
331
if (ACPI_SUCCESS (Status))
332
{
333
memset (Info.EvaluateInfo, 0, sizeof (ACPI_EVALUATE_INFO));
334
Info.EvaluateInfo->PrefixNode = Handle;
335
Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI;
336
Info.EvaluateInfo->Parameters = NULL;
337
Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
338
339
Status = AcpiNsEvaluate (Info.EvaluateInfo);
340
if (ACPI_SUCCESS (Status))
341
{
342
Info.Num_INI++;
343
}
344
}
345
}
346
347
/*
348
* Run all _REG methods
349
*
350
* Note: Any objects accessed by the _REG methods will be automatically
351
* initialized, even if they contain executable AML (see the call to
352
* AcpiNsInitializeObjects below).
353
*
354
* Note: According to the ACPI specification, we actually needn't execute
355
* _REG for SystemMemory/SystemIo operation regions, but for PCI_Config
356
* operation regions, it is required to evaluate _REG for those on a PCI
357
* root bus that doesn't contain _BBN object. So this code is kept here
358
* in order not to break things.
359
*/
360
if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
361
{
362
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
363
"[Init] Executing _REG OpRegion methods\n"));
364
365
Status = AcpiEvInitializeOpRegions ();
366
if (ACPI_FAILURE (Status))
367
{
368
goto ErrorExit;
369
}
370
}
371
372
if (!(Flags & ACPI_NO_DEVICE_INIT))
373
{
374
/* Walk namespace to execute all _INIs on present devices */
375
376
Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
377
ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL);
378
379
/*
380
* Any _OSI requests should be completed by now. If the BIOS has
381
* requested any Windows OSI strings, we will always truncate
382
* I/O addresses to 16 bits -- for Windows compatibility.
383
*/
384
if (AcpiGbl_OsiData >= ACPI_OSI_WIN_2000)
385
{
386
AcpiGbl_TruncateIoAddresses = TRUE;
387
}
388
389
ACPI_FREE (Info.EvaluateInfo);
390
if (ACPI_FAILURE (Status))
391
{
392
goto ErrorExit;
393
}
394
395
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
396
" Executed %u _INI methods requiring %u _STA executions "
397
"(examined %u objects)\n",
398
Info.Num_INI, Info.Num_STA, Info.DeviceCount));
399
}
400
401
return_ACPI_STATUS (Status);
402
403
404
ErrorExit:
405
ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
406
return_ACPI_STATUS (Status);
407
}
408
409
410
/*******************************************************************************
411
*
412
* FUNCTION: AcpiNsInitOnePackage
413
*
414
* PARAMETERS: ObjHandle - Node
415
* Level - Current nesting level
416
* Context - Not used
417
* ReturnValue - Not used
418
*
419
* RETURN: Status
420
*
421
* DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every package
422
* within the namespace. Used during dynamic load of an SSDT.
423
*
424
******************************************************************************/
425
426
ACPI_STATUS
427
AcpiNsInitOnePackage (
428
ACPI_HANDLE ObjHandle,
429
UINT32 Level,
430
void *Context,
431
void **ReturnValue)
432
{
433
ACPI_STATUS Status;
434
ACPI_OPERAND_OBJECT *ObjDesc;
435
ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
436
437
438
ObjDesc = AcpiNsGetAttachedObject (Node);
439
if (!ObjDesc)
440
{
441
return (AE_OK);
442
}
443
444
/* Exit if package is already initialized */
445
446
if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID)
447
{
448
return (AE_OK);
449
}
450
451
Status = AcpiDsGetPackageArguments (ObjDesc);
452
if (ACPI_FAILURE (Status))
453
{
454
return (AE_OK);
455
}
456
457
Status = AcpiUtWalkPackageTree (ObjDesc, NULL, AcpiDsInitPackageElement,
458
NULL);
459
if (ACPI_FAILURE (Status))
460
{
461
return (AE_OK);
462
}
463
464
ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
465
return (AE_OK);
466
}
467
468
469
/*******************************************************************************
470
*
471
* FUNCTION: AcpiNsInitOneObject
472
*
473
* PARAMETERS: ObjHandle - Node
474
* Level - Current nesting level
475
* Context - Points to a init info struct
476
* ReturnValue - Not used
477
*
478
* RETURN: Status
479
*
480
* DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
481
* within the namespace.
482
*
483
* Currently, the only objects that require initialization are:
484
* 1) Methods
485
* 2) Op Regions
486
*
487
******************************************************************************/
488
489
static ACPI_STATUS
490
AcpiNsInitOneObject (
491
ACPI_HANDLE ObjHandle,
492
UINT32 Level,
493
void *Context,
494
void **ReturnValue)
495
{
496
ACPI_OBJECT_TYPE Type;
497
ACPI_STATUS Status = AE_OK;
498
ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;
499
ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
500
ACPI_OPERAND_OBJECT *ObjDesc;
501
502
503
ACPI_FUNCTION_NAME (NsInitOneObject);
504
505
506
Info->ObjectCount++;
507
508
/* And even then, we are only interested in a few object types */
509
510
Type = AcpiNsGetType (ObjHandle);
511
ObjDesc = AcpiNsGetAttachedObject (Node);
512
if (!ObjDesc)
513
{
514
return (AE_OK);
515
}
516
517
/* Increment counters for object types we are looking for */
518
519
switch (Type)
520
{
521
case ACPI_TYPE_REGION:
522
523
Info->OpRegionCount++;
524
break;
525
526
case ACPI_TYPE_BUFFER_FIELD:
527
528
Info->FieldCount++;
529
break;
530
531
case ACPI_TYPE_LOCAL_BANK_FIELD:
532
533
Info->FieldCount++;
534
break;
535
536
case ACPI_TYPE_BUFFER:
537
538
Info->BufferCount++;
539
break;
540
541
case ACPI_TYPE_PACKAGE:
542
543
Info->PackageCount++;
544
break;
545
546
default:
547
548
/* No init required, just exit now */
549
550
return (AE_OK);
551
}
552
553
/* If the object is already initialized, nothing else to do */
554
555
if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
556
{
557
return (AE_OK);
558
}
559
560
/* Must lock the interpreter before executing AML code */
561
562
AcpiExEnterInterpreter ();
563
564
/*
565
* Only initialization of Package objects can be deferred, in order
566
* to support forward references.
567
*/
568
switch (Type)
569
{
570
case ACPI_TYPE_LOCAL_BANK_FIELD:
571
572
/* TBD: BankFields do not require deferred init, remove this code */
573
574
Info->FieldInit++;
575
Status = AcpiDsGetBankFieldArguments (ObjDesc);
576
break;
577
578
case ACPI_TYPE_PACKAGE:
579
580
/* Complete the initialization/resolution of the package object */
581
582
Info->PackageInit++;
583
Status = AcpiNsInitOnePackage (ObjHandle, Level, NULL, NULL);
584
break;
585
586
default:
587
588
/* No other types should get here */
589
590
Status = AE_TYPE;
591
ACPI_EXCEPTION ((AE_INFO, Status,
592
"Opcode is not deferred [%4.4s] (%s)",
593
AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
594
break;
595
}
596
597
if (ACPI_FAILURE (Status))
598
{
599
ACPI_EXCEPTION ((AE_INFO, Status,
600
"Could not execute arguments for [%4.4s] (%s)",
601
AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
602
}
603
604
/*
605
* We ignore errors from above, and always return OK, since we don't want
606
* to abort the walk on any single error.
607
*/
608
AcpiExExitInterpreter ();
609
return (AE_OK);
610
}
611
612
613
/*******************************************************************************
614
*
615
* FUNCTION: AcpiNsFindIniMethods
616
*
617
* PARAMETERS: ACPI_WALK_CALLBACK
618
*
619
* RETURN: ACPI_STATUS
620
*
621
* DESCRIPTION: Called during namespace walk. Finds objects named _INI under
622
* device/processor/thermal objects, and marks the entire subtree
623
* with a SUBTREE_HAS_INI flag. This flag is used during the
624
* subsequent device initialization walk to avoid entire subtrees
625
* that do not contain an _INI.
626
*
627
******************************************************************************/
628
629
static ACPI_STATUS
630
AcpiNsFindIniMethods (
631
ACPI_HANDLE ObjHandle,
632
UINT32 NestingLevel,
633
void *Context,
634
void **ReturnValue)
635
{
636
ACPI_DEVICE_WALK_INFO *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
637
ACPI_NAMESPACE_NODE *Node;
638
ACPI_NAMESPACE_NODE *ParentNode;
639
640
641
/* Keep count of device/processor/thermal objects */
642
643
Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
644
if ((Node->Type == ACPI_TYPE_DEVICE) ||
645
(Node->Type == ACPI_TYPE_PROCESSOR) ||
646
(Node->Type == ACPI_TYPE_THERMAL))
647
{
648
Info->DeviceCount++;
649
return (AE_OK);
650
}
651
652
/* We are only looking for methods named _INI */
653
654
if (!ACPI_COMPARE_NAMESEG (Node->Name.Ascii, METHOD_NAME__INI))
655
{
656
return (AE_OK);
657
}
658
659
/*
660
* The only _INI methods that we care about are those that are
661
* present under Device, Processor, and Thermal objects.
662
*/
663
ParentNode = Node->Parent;
664
switch (ParentNode->Type)
665
{
666
case ACPI_TYPE_DEVICE:
667
case ACPI_TYPE_PROCESSOR:
668
case ACPI_TYPE_THERMAL:
669
670
/* Mark parent and bubble up the INI present flag to the root */
671
672
while (ParentNode)
673
{
674
ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
675
ParentNode = ParentNode->Parent;
676
}
677
break;
678
679
default:
680
681
break;
682
}
683
684
return (AE_OK);
685
}
686
687
688
/*******************************************************************************
689
*
690
* FUNCTION: AcpiNsInitOneDevice
691
*
692
* PARAMETERS: ACPI_WALK_CALLBACK
693
*
694
* RETURN: ACPI_STATUS
695
*
696
* DESCRIPTION: This is called once per device soon after ACPI is enabled
697
* to initialize each device. It determines if the device is
698
* present, and if so, calls _INI.
699
*
700
******************************************************************************/
701
702
static ACPI_STATUS
703
AcpiNsInitOneDevice (
704
ACPI_HANDLE ObjHandle,
705
UINT32 NestingLevel,
706
void *Context,
707
void **ReturnValue)
708
{
709
ACPI_DEVICE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
710
ACPI_EVALUATE_INFO *Info = WalkInfo->EvaluateInfo;
711
UINT32 Flags;
712
ACPI_STATUS Status;
713
ACPI_NAMESPACE_NODE *DeviceNode;
714
715
716
ACPI_FUNCTION_TRACE (NsInitOneDevice);
717
718
719
/* We are interested in Devices, Processors and ThermalZones only */
720
721
DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
722
if ((DeviceNode->Type != ACPI_TYPE_DEVICE) &&
723
(DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
724
(DeviceNode->Type != ACPI_TYPE_THERMAL))
725
{
726
return_ACPI_STATUS (AE_OK);
727
}
728
729
/*
730
* Because of an earlier namespace analysis, all subtrees that contain an
731
* _INI method are tagged.
732
*
733
* If this device subtree does not contain any _INI methods, we
734
* can exit now and stop traversing this entire subtree.
735
*/
736
if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
737
{
738
return_ACPI_STATUS (AE_CTRL_DEPTH);
739
}
740
741
/*
742
* Run _STA to determine if this device is present and functioning. We
743
* must know this information for two important reasons (from ACPI spec):
744
*
745
* 1) We can only run _INI if the device is present.
746
* 2) We must abort the device tree walk on this subtree if the device is
747
* not present and is not functional (we will not examine the children)
748
*
749
* The _STA method is not required to be present under the device, we
750
* assume the device is present if _STA does not exist.
751
*/
752
ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
753
ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
754
755
Status = AcpiUtExecute_STA (DeviceNode, &Flags);
756
if (ACPI_FAILURE (Status))
757
{
758
/* Ignore error and move on to next device */
759
760
return_ACPI_STATUS (AE_OK);
761
}
762
763
/*
764
* Flags == -1 means that _STA was not found. In this case, we assume that
765
* the device is both present and functional.
766
*
767
* From the ACPI spec, description of _STA:
768
*
769
* "If a device object (including the processor object) does not have an
770
* _STA object, then OSPM assumes that all of the above bits are set (in
771
* other words, the device is present, ..., and functioning)"
772
*/
773
if (Flags != ACPI_UINT32_MAX)
774
{
775
WalkInfo->Num_STA++;
776
}
777
778
/*
779
* Examine the PRESENT and FUNCTIONING status bits
780
*
781
* Note: ACPI spec does not seem to specify behavior for the present but
782
* not functioning case, so we assume functioning if present.
783
*/
784
if (!(Flags & ACPI_STA_DEVICE_PRESENT))
785
{
786
/* Device is not present, we must examine the Functioning bit */
787
788
if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
789
{
790
/*
791
* Device is not present but is "functioning". In this case,
792
* we will not run _INI, but we continue to examine the children
793
* of this device.
794
*
795
* From the ACPI spec, description of _STA: (Note - no mention
796
* of whether to run _INI or not on the device in question)
797
*
798
* "_STA may return bit 0 clear (not present) with bit 3 set
799
* (device is functional). This case is used to indicate a valid
800
* device for which no device driver should be loaded (for example,
801
* a bridge device.) Children of this device may be present and
802
* valid. OSPM should continue enumeration below a device whose
803
* _STA returns this bit combination"
804
*/
805
return_ACPI_STATUS (AE_OK);
806
}
807
else
808
{
809
/*
810
* Device is not present and is not functioning. We must abort the
811
* walk of this subtree immediately -- don't look at the children
812
* of such a device.
813
*
814
* From the ACPI spec, description of _INI:
815
*
816
* "If the _STA method indicates that the device is not present,
817
* OSPM will not run the _INI and will not examine the children
818
* of the device for _INI methods"
819
*/
820
return_ACPI_STATUS (AE_CTRL_DEPTH);
821
}
822
}
823
824
/*
825
* The device is present or is assumed present if no _STA exists.
826
* Run the _INI if it exists (not required to exist)
827
*
828
* Note: We know there is an _INI within this subtree, but it may not be
829
* under this particular device, it may be lower in the branch.
830
*/
831
if (!ACPI_COMPARE_NAMESEG (DeviceNode->Name.Ascii, "_SB_") ||
832
DeviceNode->Parent != AcpiGbl_RootNode)
833
{
834
ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
835
ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
836
837
memset (Info, 0, sizeof (ACPI_EVALUATE_INFO));
838
Info->PrefixNode = DeviceNode;
839
Info->RelativePathname = METHOD_NAME__INI;
840
Info->Parameters = NULL;
841
Info->Flags = ACPI_IGNORE_RETURN_VALUE;
842
843
Status = AcpiNsEvaluate (Info);
844
if (ACPI_SUCCESS (Status))
845
{
846
WalkInfo->Num_INI++;
847
}
848
849
#ifdef ACPI_DEBUG_OUTPUT
850
else if (Status != AE_NOT_FOUND)
851
{
852
/* Ignore error and move on to next device */
853
854
char *ScopeName = AcpiNsGetNormalizedPathname (DeviceNode, TRUE);
855
856
ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
857
ScopeName));
858
ACPI_FREE (ScopeName);
859
}
860
#endif
861
}
862
863
/* Ignore errors from above */
864
865
Status = AE_OK;
866
867
/*
868
* The _INI method has been run if present; call the Global Initialization
869
* Handler for this device.
870
*/
871
if (AcpiGbl_InitHandler)
872
{
873
Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
874
}
875
876
return_ACPI_STATUS (Status);
877
}
878
879