Merge remote-tracking branch 'sound-asoc/for-next'
[deliverable/linux.git] / drivers / acpi / acpica / dsinit.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: dsinit - Object initialization namespace walk
4 *
5 *****************************************************************************/
6
7/*
c8100dc4 8 * Copyright (C) 2000 - 2016, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acdispat.h"
47#include "acnamesp.h"
48#include "actables.h"
1da177e4
LT
49
50#define _COMPONENT ACPI_DISPATCHER
4be44fcd 51ACPI_MODULE_NAME("dsinit")
1da177e4 52
44f6c012 53/* Local prototypes */
44f6c012 54static acpi_status
4be44fcd
LB
55acpi_ds_init_one_object(acpi_handle obj_handle,
56 u32 level, void *context, void **return_value);
1da177e4
LT
57
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_ds_init_one_object
61 *
44f6c012 62 * PARAMETERS: obj_handle - Node for the object
ba494bee
BM
63 * level - Current nesting level
64 * context - Points to a init info struct
1da177e4
LT
65 * return_value - Not used
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
70 * within the namespace.
71 *
72 * Currently, the only objects that require initialization are:
73 * 1) Methods
74 * 2) Operation Regions
75 *
76 ******************************************************************************/
77
44f6c012 78static acpi_status
4be44fcd
LB
79acpi_ds_init_one_object(acpi_handle obj_handle,
80 u32 level, void *context, void **return_value)
1da177e4 81{
4be44fcd
LB
82 struct acpi_init_walk_info *info =
83 (struct acpi_init_walk_info *)context;
84 struct acpi_namespace_node *node =
85 (struct acpi_namespace_node *)obj_handle;
4be44fcd 86 acpi_status status;
22b5afce 87 union acpi_operand_object *obj_desc;
1da177e4 88
4a90c7e8 89 ACPI_FUNCTION_ENTRY();
1da177e4
LT
90
91 /*
0c9938cc 92 * We are only interested in NS nodes owned by the table that
1da177e4
LT
93 * was just loaded
94 */
f3d2e786 95 if (node->owner_id != info->owner_id) {
1da177e4
LT
96 return (AE_OK);
97 }
98
99 info->object_count++;
100
101 /* And even then, we are only interested in a few object types */
102
22b5afce 103 switch (acpi_ns_get_type(obj_handle)) {
1da177e4
LT
104 case ACPI_TYPE_REGION:
105
4be44fcd
LB
106 status = acpi_ds_initialize_region(obj_handle);
107 if (ACPI_FAILURE(status)) {
b8e4d893
BM
108 ACPI_EXCEPTION((AE_INFO, status,
109 "During Region initialization %p [%4.4s]",
110 obj_handle,
111 acpi_ut_get_node_name(obj_handle)));
1da177e4
LT
112 }
113
114 info->op_region_count++;
115 break;
116
1da177e4 117 case ACPI_TYPE_METHOD:
22b5afce
BM
118 /*
119 * Auto-serialization support. We will examine each method that is
120 * not_serialized to determine if it creates any Named objects. If
121 * it does, it will be marked serialized to prevent problems if
122 * the method is entered by two or more threads and an attempt is
123 * made to create the same named object twice -- which results in
124 * an AE_ALREADY_EXISTS exception and method abort.
125 */
0c9938cc 126 info->method_count++;
22b5afce
BM
127 obj_desc = acpi_ns_get_attached_object(node);
128 if (!obj_desc) {
129 break;
130 }
131
132 /* Ignore if already serialized */
133
134 if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) {
135 info->serial_method_count++;
136 break;
137 }
138
139 if (acpi_gbl_auto_serialize_methods) {
140
141 /* Parse/scan method and serialize it if necessary */
142
143 acpi_ds_auto_serialize_method(node, obj_desc);
144 if (obj_desc->method.
145 info_flags & ACPI_METHOD_SERIALIZED) {
146
147 /* Method was just converted to Serialized */
148
149 info->serial_method_count++;
150 info->serialized_method_count++;
151 break;
152 }
153 }
154
155 info->non_serial_method_count++;
1da177e4
LT
156 break;
157
1da177e4
LT
158 case ACPI_TYPE_DEVICE:
159
160 info->device_count++;
161 break;
162
1da177e4 163 default:
1d1ea1b7 164
1da177e4
LT
165 break;
166 }
167
168 /*
169 * We ignore errors from above, and always return OK, since
170 * we don't want to abort the walk on a single error.
171 */
172 return (AE_OK);
173}
174
1da177e4
LT
175/*******************************************************************************
176 *
177 * FUNCTION: acpi_ds_initialize_objects
178 *
179 * PARAMETERS: table_desc - Descriptor for parent ACPI table
180 * start_node - Root of subtree to be initialized.
181 *
182 * RETURN: Status
183 *
b229cf92 184 * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
1da177e4
LT
185 * necessary initialization on the objects found therein
186 *
187 ******************************************************************************/
188
189acpi_status
67a119f9 190acpi_ds_initialize_objects(u32 table_index,
f5c1e1c5 191 struct acpi_namespace_node *start_node)
1da177e4 192{
4be44fcd
LB
193 acpi_status status;
194 struct acpi_init_walk_info info;
f3d2e786
BM
195 struct acpi_table_header *table;
196 acpi_owner_id owner_id;
1da177e4 197
b229cf92 198 ACPI_FUNCTION_TRACE(ds_initialize_objects);
1da177e4 199
f3d2e786
BM
200 status = acpi_tb_get_owner_id(table_index, &owner_id);
201 if (ACPI_FAILURE(status)) {
202 return_ACPI_STATUS(status);
203 }
204
4be44fcd
LB
205 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
206 "**** Starting initialization of namespace objects ****\n"));
1da177e4 207
96b7b7ad
AS
208 /* Set all init info to zero */
209
4fa4616e 210 memset(&info, 0, sizeof(struct acpi_init_walk_info));
96b7b7ad 211
f3d2e786 212 info.owner_id = owner_id;
96b7b7ad 213 info.table_index = table_index;
1da177e4
LT
214
215 /* Walk entire namespace from the supplied root */
216
8a335a23
BM
217 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
218 if (ACPI_FAILURE(status)) {
219 return_ACPI_STATUS(status);
220 }
221
222 /*
223 * We don't use acpi_walk_namespace since we do not want to acquire
224 * the namespace reader lock.
225 */
226 status =
227 acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
228 ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object,
2263576c 229 NULL, &info, NULL);
4be44fcd 230 if (ACPI_FAILURE(status)) {
b229cf92 231 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
1da177e4 232 }
8a335a23 233 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4 234
f3d2e786
BM
235 status = acpi_get_table_by_index(table_index, &table);
236 if (ACPI_FAILURE(status)) {
237 return_ACPI_STATUS(status);
238 }
239
92b21a95
BM
240 /* DSDT is always the first AML table */
241
242 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT)) {
243 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
244 "\nInitializing Namespace objects:\n"));
245 }
246
247 /* Summary of objects initialized */
248
4be44fcd 249 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
1fad8738 250 "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
3c0503dd
BM
251 "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
252 table->signature, table->oem_table_id, owner_id,
253 info.object_count, info.device_count,
254 info.op_region_count, info.method_count,
255 info.serial_method_count,
22b5afce
BM
256 info.non_serial_method_count,
257 info.serialized_method_count));
1da177e4 258
22b5afce
BM
259 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
260 info.method_count, info.op_region_count));
1da177e4 261
4be44fcd 262 return_ACPI_STATUS(AE_OK);
1da177e4 263}
This page took 0.719152 seconds and 5 git commands to generate.