xref: /openbmc/linux/drivers/acpi/acpica/dsinit.c (revision e0bf6c5c)
1 /******************************************************************************
2  *
3  * Module Name: dsinit - Object initialization namespace walk
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
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 
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acdispat.h"
47 #include "acnamesp.h"
48 #include "actables.h"
49 
50 #define _COMPONENT          ACPI_DISPATCHER
51 ACPI_MODULE_NAME("dsinit")
52 
53 /* Local prototypes */
54 static acpi_status
55 acpi_ds_init_one_object(acpi_handle obj_handle,
56 			u32 level, void *context, void **return_value);
57 
58 /*******************************************************************************
59  *
60  * FUNCTION:    acpi_ds_init_one_object
61  *
62  * PARAMETERS:  obj_handle      - Node for the object
63  *              level           - Current nesting level
64  *              context         - Points to a init info struct
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 
78 static acpi_status
79 acpi_ds_init_one_object(acpi_handle obj_handle,
80 			u32 level, void *context, void **return_value)
81 {
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;
86 	acpi_status status;
87 	union acpi_operand_object *obj_desc;
88 
89 	ACPI_FUNCTION_ENTRY();
90 
91 	/*
92 	 * We are only interested in NS nodes owned by the table that
93 	 * was just loaded
94 	 */
95 	if (node->owner_id != info->owner_id) {
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 
103 	switch (acpi_ns_get_type(obj_handle)) {
104 	case ACPI_TYPE_REGION:
105 
106 		status = acpi_ds_initialize_region(obj_handle);
107 		if (ACPI_FAILURE(status)) {
108 			ACPI_EXCEPTION((AE_INFO, status,
109 					"During Region initialization %p [%4.4s]",
110 					obj_handle,
111 					acpi_ut_get_node_name(obj_handle)));
112 		}
113 
114 		info->op_region_count++;
115 		break;
116 
117 	case ACPI_TYPE_METHOD:
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 		 */
126 		info->method_count++;
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++;
156 		break;
157 
158 	case ACPI_TYPE_DEVICE:
159 
160 		info->device_count++;
161 		break;
162 
163 	default:
164 
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 
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  *
184  * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
185  *              necessary initialization on the objects found therein
186  *
187  ******************************************************************************/
188 
189 acpi_status
190 acpi_ds_initialize_objects(u32 table_index,
191 			   struct acpi_namespace_node * start_node)
192 {
193 	acpi_status status;
194 	struct acpi_init_walk_info info;
195 	struct acpi_table_header *table;
196 	acpi_owner_id owner_id;
197 
198 	ACPI_FUNCTION_TRACE(ds_initialize_objects);
199 
200 	status = acpi_tb_get_owner_id(table_index, &owner_id);
201 	if (ACPI_FAILURE(status)) {
202 		return_ACPI_STATUS(status);
203 	}
204 
205 	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
206 			  "**** Starting initialization of namespace objects ****\n"));
207 
208 	/* Set all init info to zero */
209 
210 	ACPI_MEMSET(&info, 0, sizeof(struct acpi_init_walk_info));
211 
212 	info.owner_id = owner_id;
213 	info.table_index = table_index;
214 
215 	/* Walk entire namespace from the supplied root */
216 
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,
229 				   NULL, &info, NULL);
230 	if (ACPI_FAILURE(status)) {
231 		ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
232 	}
233 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
234 
235 	status = acpi_get_table_by_index(table_index, &table);
236 	if (ACPI_FAILURE(status)) {
237 		return_ACPI_STATUS(status);
238 	}
239 
240 	ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
241 			      "Table [%4.4s] (id %4.4X) - %4u Objects with %3u Devices, "
242 			      "%3u Regions, %3u Methods (%u/%u/%u Serial/Non/Cvt)\n",
243 			      table->signature, owner_id, info.object_count,
244 			      info.device_count, info.op_region_count,
245 			      info.method_count, info.serial_method_count,
246 			      info.non_serial_method_count,
247 			      info.serialized_method_count));
248 
249 	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
250 			  info.method_count, info.op_region_count));
251 
252 	return_ACPI_STATUS(AE_OK);
253 }
254