Blame view

drivers/acpi/acpica/exresnte.c 8.38 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
  
  /******************************************************************************
   *
   * Module Name: exresnte - AML Interpreter object resolution
   *
   *****************************************************************************/
  
  /*
75a44ce00   Len Brown   ACPICA: update In...
9
   * Copyright (C) 2000 - 2008, Intel Corp.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions, and the following disclaimer,
   *    without modification.
   * 2. Redistributions in binary form must reproduce at minimum a disclaimer
   *    substantially similar to the "NO WARRANTY" disclaimer below
   *    ("Disclaimer") and any redistribution must be conditioned upon
   *    including a substantially similar Disclaimer requirement for further
   *    binary redistribution.
   * 3. Neither the names of the above-listed copyright holders nor the names
   *    of any contributors may be used to endorse or promote products derived
   *    from this software without specific prior written permission.
   *
   * Alternatively, this software may be distributed under the terms of the
   * GNU General Public License ("GPL") version 2 as published by the Free
   * Software Foundation.
   *
   * NO WARRANTY
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   * POSSIBILITY OF SUCH DAMAGES.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  #include <acpi/acpi.h>
e2f7a7772   Len Brown   ACPICA: hide priv...
45
46
47
48
  #include "accommon.h"
  #include "acdispat.h"
  #include "acinterp.h"
  #include "acnamesp.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  #define _COMPONENT          ACPI_EXECUTER
4be44fcd3   Len Brown   [ACPI] Lindent al...
51
  ACPI_MODULE_NAME("exresnte")
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ex_resolve_node_to_value
   *
   * PARAMETERS:  object_ptr      - Pointer to a location that contains
   *                                a pointer to a NS node, and will receive a
   *                                pointer to the resolved object.
   *              walk_state      - Current state.  Valid only if executing AML
   *                                code.  NULL if simply resolving an object
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Resolve a Namespace node to a valued object
   *
   * Note: for some of the data types, the pointer attached to the Node
   * can be either a pointer to an actual internal object or a pointer into the
   * AML stream itself.  These types are currently:
   *
   *      ACPI_TYPE_INTEGER
   *      ACPI_TYPE_STRING
   *      ACPI_TYPE_BUFFER
   *      ACPI_TYPE_MUTEX
   *      ACPI_TYPE_PACKAGE
   *
   ******************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
  acpi_status
4be44fcd3   Len Brown   [ACPI] Lindent al...
79
80
  acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
  			      struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
82
83
84
85
86
  	acpi_status status = AE_OK;
  	union acpi_operand_object *source_desc;
  	union acpi_operand_object *obj_desc = NULL;
  	struct acpi_namespace_node *node;
  	acpi_object_type entry_type;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
88
  	ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
90
91
92
93
  
  	/*
  	 * The stack pointer points to a struct acpi_namespace_node (Node).  Get the
  	 * object that is attached to the Node.
  	 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
94
95
96
  	node = *object_ptr;
  	source_desc = acpi_ns_get_attached_object(node);
  	entry_type = acpi_ns_get_type((acpi_handle) node);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
97

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
98
99
  	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]
  ",
4be44fcd3   Len Brown   [ACPI] Lindent al...
100
101
  			  node, source_desc,
  			  acpi_ut_get_type_name(entry_type)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
103
  
  	if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
4be44fcd3   Len Brown   [ACPI] Lindent al...
104
  	    (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
105

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106
  		/* There is always exactly one level of indirection */
4be44fcd3   Len Brown   [ACPI] Lindent al...
107
108
109
  		node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
  		source_desc = acpi_ns_get_attached_object(node);
  		entry_type = acpi_ns_get_type((acpi_handle) node);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
112
113
114
  		*object_ptr = node;
  	}
  
  	/*
  	 * Several object types require no further processing:
4c90ece24   Bob Moore   ACPI: ACPICA 2006...
115
  	 * 1) Device/Thermal objects don't have a "real" subobject, return the Node
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116
  	 * 2) Method locals and arguments have a pseudo-Node
b160987df   Bob Moore   ACPICA: Fixes a p...
117
  	 * 3) 10/2007: Added method type to assist with Package construction.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
  	 */
4c90ece24   Bob Moore   ACPI: ACPICA 2006...
119
120
  	if ((entry_type == ACPI_TYPE_DEVICE) ||
  	    (entry_type == ACPI_TYPE_THERMAL) ||
b160987df   Bob Moore   ACPICA: Fixes a p...
121
  	    (entry_type == ACPI_TYPE_METHOD) ||
4be44fcd3   Len Brown   [ACPI] Lindent al...
122
123
  	    (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
  		return_ACPI_STATUS(AE_OK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
126
  	}
  
  	if (!source_desc) {
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
127
  		ACPI_ERROR((AE_INFO, "No object attached to node %p", node));
4be44fcd3   Len Brown   [ACPI] Lindent al...
128
  		return_ACPI_STATUS(AE_AML_NO_OPERAND);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
131
132
133
134
135
136
  	}
  
  	/*
  	 * Action is based on the type of the Node, which indicates the type
  	 * of the attached object or pointer
  	 */
  	switch (entry_type) {
  	case ACPI_TYPE_PACKAGE:
3371c19c2   Bob Moore   ACPICA: Remove AC...
137
  		if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
138
139
  			ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
  				    acpi_ut_get_object_type_name(source_desc)));
4be44fcd3   Len Brown   [ACPI] Lindent al...
140
  			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
  		}
4be44fcd3   Len Brown   [ACPI] Lindent al...
142
143
  		status = acpi_ds_get_package_arguments(source_desc);
  		if (ACPI_SUCCESS(status)) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
144

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145
146
147
  			/* Return an additional reference to the object */
  
  			obj_desc = source_desc;
4be44fcd3   Len Brown   [ACPI] Lindent al...
148
  			acpi_ut_add_reference(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
150
  		}
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151
  	case ACPI_TYPE_BUFFER:
3371c19c2   Bob Moore   ACPICA: Remove AC...
152
  		if (source_desc->common.type != ACPI_TYPE_BUFFER) {
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
153
154
  			ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
  				    acpi_ut_get_object_type_name(source_desc)));
4be44fcd3   Len Brown   [ACPI] Lindent al...
155
  			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
  		}
4be44fcd3   Len Brown   [ACPI] Lindent al...
157
158
  		status = acpi_ds_get_buffer_arguments(source_desc);
  		if (ACPI_SUCCESS(status)) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
159

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
  			/* Return an additional reference to the object */
  
  			obj_desc = source_desc;
4be44fcd3   Len Brown   [ACPI] Lindent al...
163
  			acpi_ut_add_reference(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
164
165
  		}
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
166
  	case ACPI_TYPE_STRING:
3371c19c2   Bob Moore   ACPICA: Remove AC...
167
  		if (source_desc->common.type != ACPI_TYPE_STRING) {
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
168
169
  			ACPI_ERROR((AE_INFO, "Object not a String, type %s",
  				    acpi_ut_get_object_type_name(source_desc)));
4be44fcd3   Len Brown   [ACPI] Lindent al...
170
  			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
172
173
174
175
  		}
  
  		/* Return an additional reference to the object */
  
  		obj_desc = source_desc;
4be44fcd3   Len Brown   [ACPI] Lindent al...
176
  		acpi_ut_add_reference(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
  	case ACPI_TYPE_INTEGER:
3371c19c2   Bob Moore   ACPICA: Remove AC...
179
  		if (source_desc->common.type != ACPI_TYPE_INTEGER) {
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
180
181
  			ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
  				    acpi_ut_get_object_type_name(source_desc)));
4be44fcd3   Len Brown   [ACPI] Lindent al...
182
  			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
184
185
186
187
  		}
  
  		/* Return an additional reference to the object */
  
  		obj_desc = source_desc;
4be44fcd3   Len Brown   [ACPI] Lindent al...
188
  		acpi_ut_add_reference(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
191
192
193
  	case ACPI_TYPE_BUFFER_FIELD:
  	case ACPI_TYPE_LOCAL_REGION_FIELD:
  	case ACPI_TYPE_LOCAL_BANK_FIELD:
  	case ACPI_TYPE_LOCAL_INDEX_FIELD:
4be44fcd3   Len Brown   [ACPI] Lindent al...
194
  		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
195
196
  				  "FieldRead Node=%p SourceDesc=%p Type=%X
  ",
4be44fcd3   Len Brown   [ACPI] Lindent al...
197
  				  node, source_desc, entry_type));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198

4be44fcd3   Len Brown   [ACPI] Lindent al...
199
200
201
  		status =
  		    acpi_ex_read_data_from_field(walk_state, source_desc,
  						 &obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202
  		break;
4be44fcd3   Len Brown   [ACPI] Lindent al...
203
  		/* For these objects, just return the object attached to the Node */
44f6c0124   Robert Moore   ACPICA 20050408 f...
204

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
  	case ACPI_TYPE_MUTEX:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
206
207
  	case ACPI_TYPE_POWER:
  	case ACPI_TYPE_PROCESSOR:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
210
211
212
213
  	case ACPI_TYPE_EVENT:
  	case ACPI_TYPE_REGION:
  
  		/* Return an additional reference to the object */
  
  		obj_desc = source_desc;
4be44fcd3   Len Brown   [ACPI] Lindent al...
214
  		acpi_ut_add_reference(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
  		break;
4be44fcd3   Len Brown   [ACPI] Lindent al...
216
  		/* TYPE_ANY is untyped, and thus there is no object associated with it */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
218
  
  	case ACPI_TYPE_ANY:
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
219
220
  		ACPI_ERROR((AE_INFO,
  			    "Untyped entry %p, no attached object!", node));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221

4be44fcd3   Len Brown   [ACPI] Lindent al...
222
  		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);	/* Cannot be AE_TYPE */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
  
  	case ACPI_TYPE_LOCAL_REFERENCE:
1044f1f65   Bob Moore   ACPICA: Cleanup f...
225
226
227
228
  		switch (source_desc->reference.class) {
  		case ACPI_REFCLASS_TABLE:	/* This is a ddb_handle */
  		case ACPI_REFCLASS_REFOF:
  		case ACPI_REFCLASS_INDEX:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
232
  			/* Return an additional reference to the object */
  
  			obj_desc = source_desc;
4be44fcd3   Len Brown   [ACPI] Lindent al...
233
  			acpi_ut_add_reference(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
236
237
  			break;
  
  		default:
  			/* No named references are allowed here */
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
238
  			ACPI_ERROR((AE_INFO,
1044f1f65   Bob Moore   ACPICA: Cleanup f...
239
240
  				    "Unsupported Reference type %X",
  				    source_desc->reference.class));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241

4be44fcd3   Len Brown   [ACPI] Lindent al...
242
  			return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
243
244
  		}
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
245
  	default:
44f6c0124   Robert Moore   ACPICA 20050408 f...
246
  		/* Default case is for unknown types */
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
247
248
249
  		ACPI_ERROR((AE_INFO,
  			    "Node %p - Unknown object type %X",
  			    node, entry_type));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
250

4be44fcd3   Len Brown   [ACPI] Lindent al...
251
  		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252

4be44fcd3   Len Brown   [ACPI] Lindent al...
253
  	}			/* switch (entry_type) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
254

44f6c0124   Robert Moore   ACPICA 20050408 f...
255
  	/* Return the object descriptor */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256

4be44fcd3   Len Brown   [ACPI] Lindent al...
257
258
  	*object_ptr = (void *)obj_desc;
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
259
  }