1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: dsinit - Object initialization namespace walk
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
17 #define _COMPONENT ACPI_DISPATCHER
18 ACPI_MODULE_NAME("dsinit")
20 /* Local prototypes */
22 acpi_ds_init_one_object(acpi_handle obj_handle
,
23 u32 level
, void *context
, void **return_value
);
25 /*******************************************************************************
27 * FUNCTION: acpi_ds_init_one_object
29 * PARAMETERS: obj_handle - Node for the object
30 * level - Current nesting level
31 * context - Points to a init info struct
32 * return_value - Not used
36 * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
37 * within the namespace.
39 * Currently, the only objects that require initialization are:
41 * 2) Operation Regions
43 ******************************************************************************/
46 acpi_ds_init_one_object(acpi_handle obj_handle
,
47 u32 level
, void *context
, void **return_value
)
49 struct acpi_init_walk_info
*info
=
50 (struct acpi_init_walk_info
*)context
;
51 struct acpi_namespace_node
*node
=
52 (struct acpi_namespace_node
*)obj_handle
;
54 union acpi_operand_object
*obj_desc
;
56 ACPI_FUNCTION_ENTRY();
59 * We are only interested in NS nodes owned by the table that
62 if (node
->owner_id
!= info
->owner_id
) {
68 /* And even then, we are only interested in a few object types */
70 switch (acpi_ns_get_type(obj_handle
)) {
71 case ACPI_TYPE_REGION
:
73 status
= acpi_ds_initialize_region(obj_handle
);
74 if (ACPI_FAILURE(status
)) {
75 ACPI_EXCEPTION((AE_INFO
, status
,
76 "During Region initialization %p [%4.4s]",
78 acpi_ut_get_node_name(obj_handle
)));
81 info
->op_region_count
++;
84 case ACPI_TYPE_METHOD
:
86 * Auto-serialization support. We will examine each method that is
87 * not_serialized to determine if it creates any Named objects. If
88 * it does, it will be marked serialized to prevent problems if
89 * the method is entered by two or more threads and an attempt is
90 * made to create the same named object twice -- which results in
91 * an AE_ALREADY_EXISTS exception and method abort.
94 obj_desc
= acpi_ns_get_attached_object(node
);
99 /* Ignore if already serialized */
101 if (obj_desc
->method
.info_flags
& ACPI_METHOD_SERIALIZED
) {
102 info
->serial_method_count
++;
106 if (acpi_gbl_auto_serialize_methods
) {
108 /* Parse/scan method and serialize it if necessary */
110 acpi_ds_auto_serialize_method(node
, obj_desc
);
111 if (obj_desc
->method
.
112 info_flags
& ACPI_METHOD_SERIALIZED
) {
114 /* Method was just converted to Serialized */
116 info
->serial_method_count
++;
117 info
->serialized_method_count
++;
122 info
->non_serial_method_count
++;
125 case ACPI_TYPE_DEVICE
:
127 info
->device_count
++;
136 * We ignore errors from above, and always return OK, since
137 * we don't want to abort the walk on a single error.
142 /*******************************************************************************
144 * FUNCTION: acpi_ds_initialize_objects
146 * PARAMETERS: table_desc - Descriptor for parent ACPI table
147 * start_node - Root of subtree to be initialized.
151 * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
152 * necessary initialization on the objects found therein
154 ******************************************************************************/
157 acpi_ds_initialize_objects(u32 table_index
,
158 struct acpi_namespace_node
*start_node
)
161 struct acpi_init_walk_info info
;
162 struct acpi_table_header
*table
;
163 acpi_owner_id owner_id
;
165 ACPI_FUNCTION_TRACE(ds_initialize_objects
);
167 status
= acpi_tb_get_owner_id(table_index
, &owner_id
);
168 if (ACPI_FAILURE(status
)) {
169 return_ACPI_STATUS(status
);
172 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
173 "**** Starting initialization of namespace objects ****\n"));
175 /* Set all init info to zero */
177 memset(&info
, 0, sizeof(struct acpi_init_walk_info
));
179 info
.owner_id
= owner_id
;
180 info
.table_index
= table_index
;
182 /* Walk entire namespace from the supplied root */
185 * We don't use acpi_walk_namespace since we do not want to acquire
186 * the namespace reader lock.
189 acpi_ns_walk_namespace(ACPI_TYPE_ANY
, start_node
, ACPI_UINT32_MAX
,
190 ACPI_NS_WALK_NO_UNLOCK
,
191 acpi_ds_init_one_object
, NULL
, &info
, NULL
);
192 if (ACPI_FAILURE(status
)) {
193 ACPI_EXCEPTION((AE_INFO
, status
, "During WalkNamespace"));
196 status
= acpi_get_table_by_index(table_index
, &table
);
197 if (ACPI_FAILURE(status
)) {
198 return_ACPI_STATUS(status
);
201 /* DSDT is always the first AML table */
203 if (ACPI_COMPARE_NAMESEG(table
->signature
, ACPI_SIG_DSDT
)) {
204 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
,
205 "\nACPI table initialization:\n"));
208 /* Summary of objects initialized */
210 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
,
211 "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
212 "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
213 table
->signature
, table
->oem_table_id
, owner_id
,
214 info
.object_count
, info
.device_count
,
215 info
.op_region_count
, info
.method_count
,
216 info
.serial_method_count
,
217 info
.non_serial_method_count
,
218 info
.serialized_method_count
));
220 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
, "%u Methods, %u Regions\n",
221 info
.method_count
, info
.op_region_count
));
223 return_ACPI_STATUS(AE_OK
);