blob: daf51b5b5875fd4978b8926d80931a19134c9806 [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 Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
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>
45#include <acpi/acdispat.h>
46#include <acpi/acnamesp.h>
47
48#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("dsinit")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040052static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040053acpi_ds_init_one_object(acpi_handle obj_handle,
54 u32 level, void *context, void **return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ds_init_one_object
59 *
Robert Moore44f6c012005-04-18 22:49:35 -040060 * PARAMETERS: obj_handle - Node for the object
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 * Level - Current nesting level
62 * Context - Points to a init info struct
63 * return_value - Not used
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
68 * within the namespace.
69 *
70 * Currently, the only objects that require initialization are:
71 * 1) Methods
72 * 2) Operation Regions
73 *
74 ******************************************************************************/
75
Robert Moore44f6c012005-04-18 22:49:35 -040076static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040077acpi_ds_init_one_object(acpi_handle obj_handle,
78 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Len Brown4be44fc2005-08-05 00:44:28 -040080 struct acpi_init_walk_info *info =
81 (struct acpi_init_walk_info *)context;
82 struct acpi_namespace_node *node =
83 (struct acpi_namespace_node *)obj_handle;
84 acpi_object_type type;
85 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Bob Moore4a90c7e2006-01-13 16:22:00 -050087 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 /*
Robert Moore0c9938c2005-07-29 15:15:00 -070090 * We are only interested in NS nodes owned by the table that
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 * was just loaded
92 */
Robert Moore0c9938c2005-07-29 15:15:00 -070093 if (node->owner_id != info->table_desc->owner_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return (AE_OK);
95 }
96
97 info->object_count++;
98
99 /* And even then, we are only interested in a few object types */
100
Len Brown4be44fc2005-08-05 00:44:28 -0400101 type = acpi_ns_get_type(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 switch (type) {
104 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:
118
Robert Moore44f6c012005-04-18 22:49:35 -0400119 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * Set the execution data width (32 or 64) based upon the
121 * revision number of the parent ACPI table.
122 * TBD: This is really for possible future support of integer width
123 * on a per-table basis. Currently, we just use a global for the width.
124 */
125 if (info->table_desc->pointer->revision == 1) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700126 node->flags |= ANOBJ_DATA_WIDTH_32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
Bob Moorec51a4de2005-11-17 13:07:00 -0500128
Robert Moore0c9938c2005-07-29 15:15:00 -0700129 info->method_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 break;
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 case ACPI_TYPE_DEVICE:
133
134 info->device_count++;
135 break;
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 default:
138 break;
139 }
140
141 /*
142 * We ignore errors from above, and always return OK, since
143 * we don't want to abort the walk on a single error.
144 */
145 return (AE_OK);
146}
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/*******************************************************************************
149 *
150 * FUNCTION: acpi_ds_initialize_objects
151 *
152 * PARAMETERS: table_desc - Descriptor for parent ACPI table
153 * start_node - Root of subtree to be initialized.
154 *
155 * RETURN: Status
156 *
Bob Mooreb229cf92006-04-21 17:15:00 -0400157 * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 * necessary initialization on the objects found therein
159 *
160 ******************************************************************************/
161
162acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400163acpi_ds_initialize_objects(struct acpi_table_desc * table_desc,
164 struct acpi_namespace_node * start_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Len Brown4be44fc2005-08-05 00:44:28 -0400166 acpi_status status;
167 struct acpi_init_walk_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Bob Mooreb229cf92006-04-21 17:15:00 -0400169 ACPI_FUNCTION_TRACE(ds_initialize_objects);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
172 "**** Starting initialization of namespace objects ****\n"));
173 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Parsing all Control Methods:"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Len Brown4be44fc2005-08-05 00:44:28 -0400175 info.method_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 info.op_region_count = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400177 info.object_count = 0;
178 info.device_count = 0;
179 info.table_desc = table_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /* Walk entire namespace from the supplied root */
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 status = acpi_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
184 acpi_ds_init_one_object, &info, NULL);
185 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400186 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
190 "\nTable [%4.4s](id %4.4X) - %hd Objects with %hd Devices %hd Methods %hd Regions\n",
191 table_desc->pointer->signature,
192 table_desc->owner_id, info.object_count,
193 info.device_count, info.method_count,
194 info.op_region_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Len Brown4be44fc2005-08-05 00:44:28 -0400196 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
197 "%hd Methods, %hd Regions\n", info.method_count,
198 info.op_region_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}