1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acnamesp.h"
13#include "acdispat.h"
14#include "acinterp.h"
15#include "acevents.h"
16
17#define _COMPONENT ACPI_NAMESPACE
18ACPI_MODULE_NAME("nsinit")
19
20
21static acpi_status
22acpi_ns_init_one_object(acpi_handle obj_handle,
23 u32 level, void *context, void **return_value);
24
25static acpi_status
26acpi_ns_init_one_device(acpi_handle obj_handle,
27 u32 nesting_level, void *context, void **return_value);
28
29static acpi_status
30acpi_ns_find_ini_methods(acpi_handle obj_handle,
31 u32 nesting_level, void *context, void **return_value);
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46acpi_status acpi_ns_initialize_objects(void)
47{
48 acpi_status status;
49 struct acpi_init_walk_info info;
50
51 ACPI_FUNCTION_TRACE(ns_initialize_objects);
52
53 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
54 "[Init] Completing Initialization of ACPI Objects\n"));
55 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
56 "**** Starting initialization of namespace objects ****\n"));
57 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
58 "Completing Region/Field/Buffer/Package initialization:\n"));
59
60
61
62 memset(&info, 0, sizeof(struct acpi_init_walk_info));
63
64
65
66 status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
67 ACPI_UINT32_MAX, acpi_ns_init_one_object,
68 NULL, &info, NULL);
69 if (ACPI_FAILURE(status)) {
70 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
71 }
72
73 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
74 " Initialized %u/%u Regions %u/%u Fields %u/%u "
75 "Buffers %u/%u Packages (%u nodes)\n",
76 info.op_region_init, info.op_region_count,
77 info.field_init, info.field_count,
78 info.buffer_init, info.buffer_count,
79 info.package_init, info.package_count,
80 info.object_count));
81
82 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
83 "%u Control Methods found\n%u Op Regions found\n",
84 info.method_count, info.op_region_count));
85
86 return_ACPI_STATUS(AE_OK);
87}
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105acpi_status acpi_ns_initialize_devices(u32 flags)
106{
107 acpi_status status = AE_OK;
108 struct acpi_device_walk_info info;
109 acpi_handle handle;
110
111 ACPI_FUNCTION_TRACE(ns_initialize_devices);
112
113 if (!(flags & ACPI_NO_DEVICE_INIT)) {
114 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
115 "[Init] Initializing ACPI Devices\n"));
116
117
118
119 info.device_count = 0;
120 info.num_STA = 0;
121 info.num_INI = 0;
122
123 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
124 "Initializing Device/Processor/Thermal objects "
125 "and executing _INI/_STA methods:\n"));
126
127
128
129 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
130 ACPI_UINT32_MAX, FALSE,
131 acpi_ns_find_ini_methods, NULL,
132 &info, NULL);
133 if (ACPI_FAILURE(status)) {
134 goto error_exit;
135 }
136
137
138
139 info.evaluate_info =
140 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
141 if (!info.evaluate_info) {
142 status = AE_NO_MEMORY;
143 goto error_exit;
144 }
145
146
147
148
149
150
151 info.evaluate_info->prefix_node = acpi_gbl_root_node;
152 info.evaluate_info->relative_pathname = METHOD_NAME__INI;
153 info.evaluate_info->parameters = NULL;
154 info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE;
155
156 status = acpi_ns_evaluate(info.evaluate_info);
157 if (ACPI_SUCCESS(status)) {
158 info.num_INI++;
159 }
160
161
162
163
164
165
166 status = acpi_get_handle(NULL, "\\_SB", &handle);
167 if (ACPI_SUCCESS(status)) {
168 memset(info.evaluate_info, 0,
169 sizeof(struct acpi_evaluate_info));
170 info.evaluate_info->prefix_node = handle;
171 info.evaluate_info->relative_pathname =
172 METHOD_NAME__INI;
173 info.evaluate_info->parameters = NULL;
174 info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE;
175
176 status = acpi_ns_evaluate(info.evaluate_info);
177 if (ACPI_SUCCESS(status)) {
178 info.num_INI++;
179 }
180 }
181 }
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
197 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
198 "[Init] Executing _REG OpRegion methods\n"));
199
200 status = acpi_ev_initialize_op_regions();
201 if (ACPI_FAILURE(status)) {
202 goto error_exit;
203 }
204 }
205
206 if (!(flags & ACPI_NO_DEVICE_INIT)) {
207
208
209
210 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
211 ACPI_UINT32_MAX, FALSE,
212 acpi_ns_init_one_device, NULL,
213 &info, NULL);
214
215
216
217
218
219
220 if (acpi_gbl_osi_data >= ACPI_OSI_WIN_2000) {
221 acpi_gbl_truncate_io_addresses = TRUE;
222 }
223
224 ACPI_FREE(info.evaluate_info);
225 if (ACPI_FAILURE(status)) {
226 goto error_exit;
227 }
228
229 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
230 " Executed %u _INI methods requiring %u _STA executions "
231 "(examined %u objects)\n",
232 info.num_INI, info.num_STA,
233 info.device_count));
234 }
235
236 return_ACPI_STATUS(status);
237
238error_exit:
239 ACPI_EXCEPTION((AE_INFO, status, "During device initialization"));
240 return_ACPI_STATUS(status);
241}
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259acpi_status
260acpi_ns_init_one_package(acpi_handle obj_handle,
261 u32 level, void *context, void **return_value)
262{
263 acpi_status status;
264 union acpi_operand_object *obj_desc;
265 struct acpi_namespace_node *node =
266 (struct acpi_namespace_node *)obj_handle;
267
268 obj_desc = acpi_ns_get_attached_object(node);
269 if (!obj_desc) {
270 return (AE_OK);
271 }
272
273
274
275 if (obj_desc->package.flags & AOPOBJ_DATA_VALID) {
276 return (AE_OK);
277 }
278
279 status = acpi_ds_get_package_arguments(obj_desc);
280 if (ACPI_FAILURE(status)) {
281 return (AE_OK);
282 }
283
284 status =
285 acpi_ut_walk_package_tree(obj_desc, NULL,
286 acpi_ds_init_package_element, NULL);
287 if (ACPI_FAILURE(status)) {
288 return (AE_OK);
289 }
290
291 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
292 return (AE_OK);
293}
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315static acpi_status
316acpi_ns_init_one_object(acpi_handle obj_handle,
317 u32 level, void *context, void **return_value)
318{
319 acpi_object_type type;
320 acpi_status status = AE_OK;
321 struct acpi_init_walk_info *info =
322 (struct acpi_init_walk_info *)context;
323 struct acpi_namespace_node *node =
324 (struct acpi_namespace_node *)obj_handle;
325 union acpi_operand_object *obj_desc;
326
327 ACPI_FUNCTION_NAME(ns_init_one_object);
328
329 info->object_count++;
330
331
332
333 type = acpi_ns_get_type(obj_handle);
334 obj_desc = acpi_ns_get_attached_object(node);
335 if (!obj_desc) {
336 return (AE_OK);
337 }
338
339
340
341 switch (type) {
342 case ACPI_TYPE_REGION:
343
344 info->op_region_count++;
345 break;
346
347 case ACPI_TYPE_BUFFER_FIELD:
348
349 info->field_count++;
350 break;
351
352 case ACPI_TYPE_LOCAL_BANK_FIELD:
353
354 info->field_count++;
355 break;
356
357 case ACPI_TYPE_BUFFER:
358
359 info->buffer_count++;
360 break;
361
362 case ACPI_TYPE_PACKAGE:
363
364 info->package_count++;
365 break;
366
367 default:
368
369
370
371 return (AE_OK);
372 }
373
374
375
376 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
377 return (AE_OK);
378 }
379
380
381
382 acpi_ex_enter_interpreter();
383
384
385
386
387
388 switch (type) {
389 case ACPI_TYPE_REGION:
390
391 info->op_region_init++;
392 status = acpi_ds_get_region_arguments(obj_desc);
393 break;
394
395 case ACPI_TYPE_BUFFER_FIELD:
396
397 info->field_init++;
398 status = acpi_ds_get_buffer_field_arguments(obj_desc);
399 break;
400
401 case ACPI_TYPE_LOCAL_BANK_FIELD:
402
403 info->field_init++;
404 status = acpi_ds_get_bank_field_arguments(obj_desc);
405 break;
406
407 case ACPI_TYPE_BUFFER:
408
409 info->buffer_init++;
410 status = acpi_ds_get_buffer_arguments(obj_desc);
411 break;
412
413 case ACPI_TYPE_PACKAGE:
414
415
416
417 info->package_init++;
418 status =
419 acpi_ns_init_one_package(obj_handle, level, NULL, NULL);
420 break;
421
422 default:
423
424
425
426 break;
427 }
428
429 if (ACPI_FAILURE(status)) {
430 ACPI_EXCEPTION((AE_INFO, status,
431 "Could not execute arguments for [%4.4s] (%s)",
432 acpi_ut_get_node_name(node),
433 acpi_ut_get_type_name(type)));
434 }
435
436
437
438
439
440 acpi_ex_exit_interpreter();
441 return (AE_OK);
442}
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460static acpi_status
461acpi_ns_find_ini_methods(acpi_handle obj_handle,
462 u32 nesting_level, void *context, void **return_value)
463{
464 struct acpi_device_walk_info *info =
465 ACPI_CAST_PTR(struct acpi_device_walk_info, context);
466 struct acpi_namespace_node *node;
467 struct acpi_namespace_node *parent_node;
468
469
470
471 node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
472 if ((node->type == ACPI_TYPE_DEVICE) ||
473 (node->type == ACPI_TYPE_PROCESSOR) ||
474 (node->type == ACPI_TYPE_THERMAL)) {
475 info->device_count++;
476 return (AE_OK);
477 }
478
479
480
481 if (!ACPI_COMPARE_NAMESEG(node->name.ascii, METHOD_NAME__INI)) {
482 return (AE_OK);
483 }
484
485
486
487
488
489 parent_node = node->parent;
490 switch (parent_node->type) {
491 case ACPI_TYPE_DEVICE:
492 case ACPI_TYPE_PROCESSOR:
493 case ACPI_TYPE_THERMAL:
494
495
496
497 while (parent_node) {
498 parent_node->flags |= ANOBJ_SUBTREE_HAS_INI;
499 parent_node = parent_node->parent;
500 }
501 break;
502
503 default:
504
505 break;
506 }
507
508 return (AE_OK);
509}
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525static acpi_status
526acpi_ns_init_one_device(acpi_handle obj_handle,
527 u32 nesting_level, void *context, void **return_value)
528{
529 struct acpi_device_walk_info *walk_info =
530 ACPI_CAST_PTR(struct acpi_device_walk_info, context);
531 struct acpi_evaluate_info *info = walk_info->evaluate_info;
532 u32 flags;
533 acpi_status status;
534 struct acpi_namespace_node *device_node;
535
536 ACPI_FUNCTION_TRACE(ns_init_one_device);
537
538
539
540 device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
541 if ((device_node->type != ACPI_TYPE_DEVICE) &&
542 (device_node->type != ACPI_TYPE_PROCESSOR) &&
543 (device_node->type != ACPI_TYPE_THERMAL)) {
544 return_ACPI_STATUS(AE_OK);
545 }
546
547
548
549
550
551
552
553
554 if (!(device_node->flags & ANOBJ_SUBTREE_HAS_INI)) {
555 return_ACPI_STATUS(AE_CTRL_DEPTH);
556 }
557
558
559
560
561
562
563
564
565
566
567
568
569 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
570 (ACPI_TYPE_METHOD, device_node, METHOD_NAME__STA));
571
572 status = acpi_ut_execute_STA(device_node, &flags);
573 if (ACPI_FAILURE(status)) {
574
575
576
577 return_ACPI_STATUS(AE_OK);
578 }
579
580
581
582
583
584
585
586
587
588
589
590 if (flags != ACPI_UINT32_MAX) {
591 walk_info->num_STA++;
592 }
593
594
595
596
597
598
599
600 if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
601
602
603
604 if (flags & ACPI_STA_DEVICE_FUNCTIONING) {
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620 return_ACPI_STATUS(AE_OK);
621 } else {
622
623
624
625
626
627
628
629
630
631
632
633 return_ACPI_STATUS(AE_CTRL_DEPTH);
634 }
635 }
636
637
638
639
640
641
642
643
644 if (!ACPI_COMPARE_NAMESEG(device_node->name.ascii, "_SB_") ||
645 device_node->parent != acpi_gbl_root_node) {
646 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
647 (ACPI_TYPE_METHOD, device_node,
648 METHOD_NAME__INI));
649
650 memset(info, 0, sizeof(struct acpi_evaluate_info));
651 info->prefix_node = device_node;
652 info->relative_pathname = METHOD_NAME__INI;
653 info->parameters = NULL;
654 info->flags = ACPI_IGNORE_RETURN_VALUE;
655
656 status = acpi_ns_evaluate(info);
657 if (ACPI_SUCCESS(status)) {
658 walk_info->num_INI++;
659 }
660#ifdef ACPI_DEBUG_OUTPUT
661 else if (status != AE_NOT_FOUND) {
662
663
664
665 char *scope_name =
666 acpi_ns_get_normalized_pathname(device_node, TRUE);
667
668 ACPI_EXCEPTION((AE_INFO, status,
669 "during %s._INI execution",
670 scope_name));
671 ACPI_FREE(scope_name);
672 }
673#endif
674 }
675
676
677
678 status = AE_OK;
679
680
681
682
683
684 if (acpi_gbl_init_handler) {
685 status =
686 acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI);
687 }
688
689 return_ACPI_STATUS(status);
690}
691