blob: cc4a38c5755824f758a51e466c033c2b3440dd8a [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 Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * 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
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;
86 acpi_object_type type;
87 acpi_status status;
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
Len Brown4be44fc2005-08-05 00:44:28 -0400103 type = acpi_ns_get_type(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 switch (type) {
106 case ACPI_TYPE_REGION:
107
Len Brown4be44fc2005-08-05 00:44:28 -0400108 status = acpi_ds_initialize_region(obj_handle);
109 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500110 ACPI_EXCEPTION((AE_INFO, status,
111 "During Region initialization %p [%4.4s]",
112 obj_handle,
113 acpi_ut_get_node_name(obj_handle)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115
116 info->op_region_count++;
117 break;
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 case ACPI_TYPE_METHOD:
120
Robert Moore0c9938c2005-07-29 15:15:00 -0700121 info->method_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 break;
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 case ACPI_TYPE_DEVICE:
125
126 info->device_count++;
127 break;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 default:
130 break;
131 }
132
133 /*
134 * We ignore errors from above, and always return OK, since
135 * we don't want to abort the walk on a single error.
136 */
137 return (AE_OK);
138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/*******************************************************************************
141 *
142 * FUNCTION: acpi_ds_initialize_objects
143 *
144 * PARAMETERS: table_desc - Descriptor for parent ACPI table
145 * start_node - Root of subtree to be initialized.
146 *
147 * RETURN: Status
148 *
Bob Mooreb229cf92006-04-21 17:15:00 -0400149 * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 * necessary initialization on the objects found therein
151 *
152 ******************************************************************************/
153
154acpi_status
Bob Moore67a119f2008-06-10 13:42:13 +0800155acpi_ds_initialize_objects(u32 table_index,
Len Brown4be44fc2005-08-05 00:44:28 -0400156 struct acpi_namespace_node * start_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Len Brown4be44fc2005-08-05 00:44:28 -0400158 acpi_status status;
159 struct acpi_init_walk_info info;
Bob Mooref3d2e782007-02-02 19:48:18 +0300160 struct acpi_table_header *table;
161 acpi_owner_id owner_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Bob Mooreb229cf92006-04-21 17:15:00 -0400163 ACPI_FUNCTION_TRACE(ds_initialize_objects);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Bob Mooref3d2e782007-02-02 19:48:18 +0300165 status = acpi_tb_get_owner_id(table_index, &owner_id);
166 if (ACPI_FAILURE(status)) {
167 return_ACPI_STATUS(status);
168 }
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
171 "**** Starting initialization of namespace objects ****\n"));
172 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Parsing all Control Methods:"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Alexey Starikovskiy96b7b7a2010-05-26 11:20:47 +0800174 /* Set all init info to zero */
175
176 ACPI_MEMSET(&info, 0, sizeof(struct acpi_init_walk_info));
177
Bob Mooref3d2e782007-02-02 19:48:18 +0300178 info.owner_id = owner_id;
Alexey Starikovskiy96b7b7a2010-05-26 11:20:47 +0800179 info.table_index = table_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /* Walk entire namespace from the supplied root */
182
Bob Moore8a335a232009-03-09 16:31:04 +0800183 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
184 if (ACPI_FAILURE(status)) {
185 return_ACPI_STATUS(status);
186 }
187
188 /*
189 * We don't use acpi_walk_namespace since we do not want to acquire
190 * the namespace reader lock.
191 */
192 status =
193 acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
194 ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object,
Lin Ming22635762009-11-13 10:06:08 +0800195 NULL, &info, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400196 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400197 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
Bob Moore8a335a232009-03-09 16:31:04 +0800199 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Bob Mooref3d2e782007-02-02 19:48:18 +0300201 status = acpi_get_table_by_index(table_index, &table);
202 if (ACPI_FAILURE(status)) {
203 return_ACPI_STATUS(status);
204 }
205
Len Brown4be44fc2005-08-05 00:44:28 -0400206 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
Alexey Starikovskiy96b7b7a2010-05-26 11:20:47 +0800207 "\nTable [%4.4s](id %4.4X) - %u Objects with %u Devices %u Methods %u Regions\n",
Bob Mooref3d2e782007-02-02 19:48:18 +0300208 table->signature, owner_id, info.object_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400209 info.device_count, info.method_count,
210 info.op_region_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Len Brown4be44fc2005-08-05 00:44:28 -0400212 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
Alexey Starikovskiy96b7b7a2010-05-26 11:20:47 +0800213 "%u Methods, %u Regions\n", info.method_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400214 info.op_region_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}