blob: aee5e45f6d35ecd39eb751e0008baeb9f252cfcc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: dsinit - Object initialization namespace walk
4 *
5 *****************************************************************************/
6
7/*
Bob Moorefbb7a2d2014-02-08 09:42:25 +08008 * Copyright (C) 2000 - 2014, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acdispat.h"
47#include "acnamesp.h"
48#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("dsinit")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Robert Moore44f6c012005-04-18 22:49:35 -040053/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040054static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040055acpi_ds_init_one_object(acpi_handle obj_handle,
56 u32 level, void *context, void **return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_ds_init_one_object
61 *
Robert Moore44f6c012005-04-18 22:49:35 -040062 * PARAMETERS: obj_handle - Node for the object
Bob Mooreba494be2012-07-12 09:40:10 +080063 * level - Current nesting level
64 * context - Points to a init info struct
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 * 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
Robert Moore44f6c012005-04-18 22:49:35 -040078static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040079acpi_ds_init_one_object(acpi_handle obj_handle,
80 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Len Brown4be44fc2005-08-05 00:44:28 -040082 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;
Len Brown4be44fc2005-08-05 00:44:28 -040086 acpi_status status;
Bob Moore22b5afc2014-03-24 14:49:00 +080087 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Bob Moore4a90c7e2006-01-13 16:22:00 -050089 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 /*
Robert Moore0c9938c2005-07-29 15:15:00 -070092 * We are only interested in NS nodes owned by the table that
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 * was just loaded
94 */
Bob Mooref3d2e782007-02-02 19:48:18 +030095 if (node->owner_id != info->owner_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return (AE_OK);
97 }
98
99 info->object_count++;
100
101 /* And even then, we are only interested in a few object types */
102
Bob Moore22b5afc2014-03-24 14:49:00 +0800103 switch (acpi_ns_get_type(obj_handle)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 case ACPI_TYPE_REGION:
105
Len Brown4be44fc2005-08-05 00:44:28 -0400106 status = acpi_ds_initialize_region(obj_handle);
107 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500108 ACPI_EXCEPTION((AE_INFO, status,
109 "During Region initialization %p [%4.4s]",
110 obj_handle,
111 acpi_ut_get_node_name(obj_handle)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113
114 info->op_region_count++;
115 break;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 case ACPI_TYPE_METHOD:
Bob Moore22b5afc2014-03-24 14:49:00 +0800118 /*
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 */
Robert Moore0c9938c2005-07-29 15:15:00 -0700126 info->method_count++;
Bob Moore22b5afc2014-03-24 14:49:00 +0800127 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++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 break;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 case ACPI_TYPE_DEVICE:
159
160 info->device_count++;
161 break;
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/*******************************************************************************
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 *
Bob Mooreb229cf92006-04-21 17:15:00 -0400184 * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 * necessary initialization on the objects found therein
186 *
187 ******************************************************************************/
188
189acpi_status
Bob Moore67a119f2008-06-10 13:42:13 +0800190acpi_ds_initialize_objects(u32 table_index,
Len Brown4be44fc2005-08-05 00:44:28 -0400191 struct acpi_namespace_node * start_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Len Brown4be44fc2005-08-05 00:44:28 -0400193 acpi_status status;
194 struct acpi_init_walk_info info;
Bob Mooref3d2e782007-02-02 19:48:18 +0300195 struct acpi_table_header *table;
196 acpi_owner_id owner_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Bob Mooreb229cf92006-04-21 17:15:00 -0400198 ACPI_FUNCTION_TRACE(ds_initialize_objects);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Bob Mooref3d2e782007-02-02 19:48:18 +0300200 status = acpi_tb_get_owner_id(table_index, &owner_id);
201 if (ACPI_FAILURE(status)) {
202 return_ACPI_STATUS(status);
203 }
204
Len Brown4be44fc2005-08-05 00:44:28 -0400205 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
206 "**** Starting initialization of namespace objects ****\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Alexey Starikovskiy96b7b7a2010-05-26 11:20:47 +0800208 /* Set all init info to zero */
209
210 ACPI_MEMSET(&info, 0, sizeof(struct acpi_init_walk_info));
211
Bob Mooref3d2e782007-02-02 19:48:18 +0300212 info.owner_id = owner_id;
Alexey Starikovskiy96b7b7a2010-05-26 11:20:47 +0800213 info.table_index = table_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 /* Walk entire namespace from the supplied root */
216
Bob Moore8a335a232009-03-09 16:31:04 +0800217 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,
Lin Ming22635762009-11-13 10:06:08 +0800229 NULL, &info, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400230 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400231 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
Bob Moore8a335a232009-03-09 16:31:04 +0800233 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Bob Mooref3d2e782007-02-02 19:48:18 +0300235 status = acpi_get_table_by_index(table_index, &table);
236 if (ACPI_FAILURE(status)) {
237 return_ACPI_STATUS(status);
238 }
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
Bob Moore22b5afc2014-03-24 14:49:00 +0800241 "Table [%4.4s] (id %4.4X) - %4u Objects with %3u Devices, "
242 "%3u Regions, %3u Methods (%u/%u/%u Serial/Non/Cvt)\n",
Bob Mooref3d2e782007-02-02 19:48:18 +0300243 table->signature, owner_id, info.object_count,
Bob Moore22b5afc2014-03-24 14:49:00 +0800244 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Bob Moore22b5afc2014-03-24 14:49:00 +0800249 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
250 info.method_count, info.op_region_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Len Brown4be44fc2005-08-05 00:44:28 -0400252 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}