aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/executer
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/executer')
-rw-r--r--drivers/acpi/executer/Makefile10
-rw-r--r--drivers/acpi/executer/exconfig.c535
-rw-r--r--drivers/acpi/executer/exconvrt.c691
-rw-r--r--drivers/acpi/executer/excreate.c521
-rw-r--r--drivers/acpi/executer/exdump.c1059
-rw-r--r--drivers/acpi/executer/exfield.c339
-rw-r--r--drivers/acpi/executer/exfldio.c957
-rw-r--r--drivers/acpi/executer/exmisc.c725
-rw-r--r--drivers/acpi/executer/exmutex.c473
-rw-r--r--drivers/acpi/executer/exnames.c435
-rw-r--r--drivers/acpi/executer/exoparg1.c1049
-rw-r--r--drivers/acpi/executer/exoparg2.c604
-rw-r--r--drivers/acpi/executer/exoparg3.c272
-rw-r--r--drivers/acpi/executer/exoparg6.c340
-rw-r--r--drivers/acpi/executer/exprep.c589
-rw-r--r--drivers/acpi/executer/exregion.c498
-rw-r--r--drivers/acpi/executer/exresnte.c277
-rw-r--r--drivers/acpi/executer/exresolv.c550
-rw-r--r--drivers/acpi/executer/exresop.c700
-rw-r--r--drivers/acpi/executer/exstore.c715
-rw-r--r--drivers/acpi/executer/exstoren.c303
-rw-r--r--drivers/acpi/executer/exstorob.c208
-rw-r--r--drivers/acpi/executer/exsystem.c302
-rw-r--r--drivers/acpi/executer/exutils.c420
24 files changed, 0 insertions, 12572 deletions
diff --git a/drivers/acpi/executer/Makefile b/drivers/acpi/executer/Makefile
deleted file mode 100644
index e09998aa012f..000000000000
--- a/drivers/acpi/executer/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
1#
2# Makefile for all Linux ACPI interpreter subdirectories
3#
4
5obj-y := exconfig.o exfield.o exnames.o exoparg6.o exresolv.o exstorob.o\
6 exconvrt.o exfldio.o exoparg1.o exprep.o exresop.o exsystem.o\
7 excreate.o exmisc.o exoparg2.o exregion.o exstore.o exutils.o \
8 exdump.o exmutex.o exoparg3.o exresnte.o exstoren.o
9
10EXTRA_CFLAGS += $(ACPI_CFLAGS)
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
deleted file mode 100644
index 74da6fa52ef1..000000000000
--- a/drivers/acpi/executer/exconfig.c
+++ /dev/null
@@ -1,535 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acinterp.h>
46#include <acpi/acnamesp.h>
47#include <acpi/actables.h>
48#include <acpi/acdispat.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exconfig")
52
53/* Local prototypes */
54static acpi_status
55acpi_ex_add_table(u32 table_index,
56 struct acpi_namespace_node *parent_node,
57 union acpi_operand_object **ddb_handle);
58
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ex_add_table
62 *
63 * PARAMETERS: Table - Pointer to raw table
64 * parent_node - Where to load the table (scope)
65 * ddb_handle - Where to return the table handle.
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Common function to Install and Load an ACPI table with a
70 * returned table handle.
71 *
72 ******************************************************************************/
73
74static acpi_status
75acpi_ex_add_table(u32 table_index,
76 struct acpi_namespace_node *parent_node,
77 union acpi_operand_object **ddb_handle)
78{
79 acpi_status status;
80 union acpi_operand_object *obj_desc;
81
82 ACPI_FUNCTION_TRACE(ex_add_table);
83
84 /* Create an object to be the table handle */
85
86 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
87 if (!obj_desc) {
88 return_ACPI_STATUS(AE_NO_MEMORY);
89 }
90
91 /* Init the table handle */
92
93 obj_desc->reference.class = ACPI_REFCLASS_TABLE;
94 *ddb_handle = obj_desc;
95
96 /* Install the new table into the local data structures */
97
98 obj_desc->reference.value = table_index;
99
100 /* Add the table to the namespace */
101
102 status = acpi_ns_load_table(table_index, parent_node);
103 if (ACPI_FAILURE(status)) {
104 acpi_ut_remove_reference(obj_desc);
105 *ddb_handle = NULL;
106 }
107
108 return_ACPI_STATUS(status);
109}
110
111/*******************************************************************************
112 *
113 * FUNCTION: acpi_ex_load_table_op
114 *
115 * PARAMETERS: walk_state - Current state with operands
116 * return_desc - Where to store the return object
117 *
118 * RETURN: Status
119 *
120 * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
121 *
122 ******************************************************************************/
123
124acpi_status
125acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
126 union acpi_operand_object **return_desc)
127{
128 acpi_status status;
129 union acpi_operand_object **operand = &walk_state->operands[0];
130 struct acpi_namespace_node *parent_node;
131 struct acpi_namespace_node *start_node;
132 struct acpi_namespace_node *parameter_node = NULL;
133 union acpi_operand_object *ddb_handle;
134 struct acpi_table_header *table;
135 u32 table_index;
136
137 ACPI_FUNCTION_TRACE(ex_load_table_op);
138
139 /* Validate lengths for the signature_string, OEMIDString, OEMtable_iD */
140
141 if ((operand[0]->string.length > ACPI_NAME_SIZE) ||
142 (operand[1]->string.length > ACPI_OEM_ID_SIZE) ||
143 (operand[2]->string.length > ACPI_OEM_TABLE_ID_SIZE)) {
144 return_ACPI_STATUS(AE_BAD_PARAMETER);
145 }
146
147 /* Find the ACPI table in the RSDT/XSDT */
148
149 status = acpi_tb_find_table(operand[0]->string.pointer,
150 operand[1]->string.pointer,
151 operand[2]->string.pointer, &table_index);
152 if (ACPI_FAILURE(status)) {
153 if (status != AE_NOT_FOUND) {
154 return_ACPI_STATUS(status);
155 }
156
157 /* Table not found, return an Integer=0 and AE_OK */
158
159 ddb_handle = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
160 if (!ddb_handle) {
161 return_ACPI_STATUS(AE_NO_MEMORY);
162 }
163
164 ddb_handle->integer.value = 0;
165 *return_desc = ddb_handle;
166
167 return_ACPI_STATUS(AE_OK);
168 }
169
170 /* Default nodes */
171
172 start_node = walk_state->scope_info->scope.node;
173 parent_node = acpi_gbl_root_node;
174
175 /* root_path (optional parameter) */
176
177 if (operand[3]->string.length > 0) {
178 /*
179 * Find the node referenced by the root_path_string. This is the
180 * location within the namespace where the table will be loaded.
181 */
182 status =
183 acpi_ns_get_node(start_node, operand[3]->string.pointer,
184 ACPI_NS_SEARCH_PARENT, &parent_node);
185 if (ACPI_FAILURE(status)) {
186 return_ACPI_STATUS(status);
187 }
188 }
189
190 /* parameter_path (optional parameter) */
191
192 if (operand[4]->string.length > 0) {
193 if ((operand[4]->string.pointer[0] != '\\') &&
194 (operand[4]->string.pointer[0] != '^')) {
195 /*
196 * Path is not absolute, so it will be relative to the node
197 * referenced by the root_path_string (or the NS root if omitted)
198 */
199 start_node = parent_node;
200 }
201
202 /* Find the node referenced by the parameter_path_string */
203
204 status =
205 acpi_ns_get_node(start_node, operand[4]->string.pointer,
206 ACPI_NS_SEARCH_PARENT, &parameter_node);
207 if (ACPI_FAILURE(status)) {
208 return_ACPI_STATUS(status);
209 }
210 }
211
212 /* Load the table into the namespace */
213
214 status = acpi_ex_add_table(table_index, parent_node, &ddb_handle);
215 if (ACPI_FAILURE(status)) {
216 return_ACPI_STATUS(status);
217 }
218
219 /* Parameter Data (optional) */
220
221 if (parameter_node) {
222
223 /* Store the parameter data into the optional parameter object */
224
225 status = acpi_ex_store(operand[5],
226 ACPI_CAST_PTR(union acpi_operand_object,
227 parameter_node),
228 walk_state);
229 if (ACPI_FAILURE(status)) {
230 (void)acpi_ex_unload_table(ddb_handle);
231 return_ACPI_STATUS(status);
232 }
233 }
234
235 status = acpi_get_table_by_index(table_index, &table);
236 if (ACPI_SUCCESS(status)) {
237 ACPI_INFO((AE_INFO,
238 "Dynamic OEM Table Load - [%.4s] OemId [%.6s] OemTableId [%.8s]",
239 table->signature, table->oem_id,
240 table->oem_table_id));
241 }
242
243 /* Invoke table handler if present */
244
245 if (acpi_gbl_table_handler) {
246 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
247 acpi_gbl_table_handler_context);
248 }
249
250 *return_desc = ddb_handle;
251 return_ACPI_STATUS(status);
252}
253
254/*******************************************************************************
255 *
256 * FUNCTION: acpi_ex_load_op
257 *
258 * PARAMETERS: obj_desc - Region or Buffer/Field where the table will be
259 * obtained
260 * Target - Where a handle to the table will be stored
261 * walk_state - Current state
262 *
263 * RETURN: Status
264 *
265 * DESCRIPTION: Load an ACPI table from a field or operation region
266 *
267 * NOTE: Region Fields (Field, bank_field, index_fields) are resolved to buffer
268 * objects before this code is reached.
269 *
270 * If source is an operation region, it must refer to system_memory, as
271 * per the ACPI specification.
272 *
273 ******************************************************************************/
274
275acpi_status
276acpi_ex_load_op(union acpi_operand_object *obj_desc,
277 union acpi_operand_object *target,
278 struct acpi_walk_state *walk_state)
279{
280 union acpi_operand_object *ddb_handle;
281 struct acpi_table_header *table;
282 struct acpi_table_desc table_desc;
283 u32 table_index;
284 acpi_status status;
285 u32 length;
286
287 ACPI_FUNCTION_TRACE(ex_load_op);
288
289 ACPI_MEMSET(&table_desc, 0, sizeof(struct acpi_table_desc));
290
291 /* Source Object can be either an op_region or a Buffer/Field */
292
293 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
294 case ACPI_TYPE_REGION:
295
296 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
297 "Load table from Region %p\n", obj_desc));
298
299 /* Region must be system_memory (from ACPI spec) */
300
301 if (obj_desc->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
302 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
303 }
304
305 /*
306 * If the Region Address and Length have not been previously evaluated,
307 * evaluate them now and save the results.
308 */
309 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
310 status = acpi_ds_get_region_arguments(obj_desc);
311 if (ACPI_FAILURE(status)) {
312 return_ACPI_STATUS(status);
313 }
314 }
315
316 /*
317 * Map the table header and get the actual table length. The region
318 * length is not guaranteed to be the same as the table length.
319 */
320 table = acpi_os_map_memory(obj_desc->region.address,
321 sizeof(struct acpi_table_header));
322 if (!table) {
323 return_ACPI_STATUS(AE_NO_MEMORY);
324 }
325
326 length = table->length;
327 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
328
329 /* Must have at least an ACPI table header */
330
331 if (length < sizeof(struct acpi_table_header)) {
332 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
333 }
334
335 /*
336 * The memory region is not guaranteed to remain stable and we must
337 * copy the table to a local buffer. For example, the memory region
338 * is corrupted after suspend on some machines. Dynamically loaded
339 * tables are usually small, so this overhead is minimal.
340 */
341
342 /* Allocate a buffer for the table */
343
344 table_desc.pointer = ACPI_ALLOCATE(length);
345 if (!table_desc.pointer) {
346 return_ACPI_STATUS(AE_NO_MEMORY);
347 }
348
349 /* Map the entire table and copy it */
350
351 table = acpi_os_map_memory(obj_desc->region.address, length);
352 if (!table) {
353 ACPI_FREE(table_desc.pointer);
354 return_ACPI_STATUS(AE_NO_MEMORY);
355 }
356
357 ACPI_MEMCPY(table_desc.pointer, table, length);
358 acpi_os_unmap_memory(table, length);
359
360 table_desc.address = obj_desc->region.address;
361 break;
362
363 case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */
364
365 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
366 "Load table from Buffer or Field %p\n",
367 obj_desc));
368
369 /* Must have at least an ACPI table header */
370
371 if (obj_desc->buffer.length < sizeof(struct acpi_table_header)) {
372 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
373 }
374
375 /* Get the actual table length from the table header */
376
377 table =
378 ACPI_CAST_PTR(struct acpi_table_header,
379 obj_desc->buffer.pointer);
380 length = table->length;
381
382 /* Table cannot extend beyond the buffer */
383
384 if (length > obj_desc->buffer.length) {
385 return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
386 }
387 if (length < sizeof(struct acpi_table_header)) {
388 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
389 }
390
391 /*
392 * Copy the table from the buffer because the buffer could be modified
393 * or even deleted in the future
394 */
395 table_desc.pointer = ACPI_ALLOCATE(length);
396 if (!table_desc.pointer) {
397 return_ACPI_STATUS(AE_NO_MEMORY);
398 }
399
400 ACPI_MEMCPY(table_desc.pointer, table, length);
401 table_desc.address = ACPI_TO_INTEGER(table_desc.pointer);
402 break;
403
404 default:
405 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
406 }
407
408 /* Validate table checksum (will not get validated in tb_add_table) */
409
410 status = acpi_tb_verify_checksum(table_desc.pointer, length);
411 if (ACPI_FAILURE(status)) {
412 ACPI_FREE(table_desc.pointer);
413 return_ACPI_STATUS(status);
414 }
415
416 /* Complete the table descriptor */
417
418 table_desc.length = length;
419 table_desc.flags = ACPI_TABLE_ORIGIN_ALLOCATED;
420
421 /* Install the new table into the local data structures */
422
423 status = acpi_tb_add_table(&table_desc, &table_index);
424 if (ACPI_FAILURE(status)) {
425 goto cleanup;
426 }
427
428 /*
429 * Add the table to the namespace.
430 *
431 * Note: Load the table objects relative to the root of the namespace.
432 * This appears to go against the ACPI specification, but we do it for
433 * compatibility with other ACPI implementations.
434 */
435 status =
436 acpi_ex_add_table(table_index, acpi_gbl_root_node, &ddb_handle);
437 if (ACPI_FAILURE(status)) {
438
439 /* On error, table_ptr was deallocated above */
440
441 return_ACPI_STATUS(status);
442 }
443
444 /* Store the ddb_handle into the Target operand */
445
446 status = acpi_ex_store(ddb_handle, target, walk_state);
447 if (ACPI_FAILURE(status)) {
448 (void)acpi_ex_unload_table(ddb_handle);
449
450 /* table_ptr was deallocated above */
451
452 acpi_ut_remove_reference(ddb_handle);
453 return_ACPI_STATUS(status);
454 }
455
456 /* Invoke table handler if present */
457
458 if (acpi_gbl_table_handler) {
459 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD,
460 table_desc.pointer,
461 acpi_gbl_table_handler_context);
462 }
463
464 cleanup:
465 if (ACPI_FAILURE(status)) {
466
467 /* Delete allocated table buffer */
468
469 acpi_tb_delete_table(&table_desc);
470 }
471 return_ACPI_STATUS(status);
472}
473
474/*******************************************************************************
475 *
476 * FUNCTION: acpi_ex_unload_table
477 *
478 * PARAMETERS: ddb_handle - Handle to a previously loaded table
479 *
480 * RETURN: Status
481 *
482 * DESCRIPTION: Unload an ACPI table
483 *
484 ******************************************************************************/
485
486acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
487{
488 acpi_status status = AE_OK;
489 union acpi_operand_object *table_desc = ddb_handle;
490 u32 table_index;
491 struct acpi_table_header *table;
492
493 ACPI_FUNCTION_TRACE(ex_unload_table);
494
495 /*
496 * Validate the handle
497 * Although the handle is partially validated in acpi_ex_reconfiguration(),
498 * when it calls acpi_ex_resolve_operands(), the handle is more completely
499 * validated here.
500 */
501 if ((!ddb_handle) ||
502 (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
503 (ACPI_GET_OBJECT_TYPE(ddb_handle) != ACPI_TYPE_LOCAL_REFERENCE)) {
504 return_ACPI_STATUS(AE_BAD_PARAMETER);
505 }
506
507 /* Get the table index from the ddb_handle */
508
509 table_index = table_desc->reference.value;
510
511 /* Invoke table handler if present */
512
513 if (acpi_gbl_table_handler) {
514 status = acpi_get_table_by_index(table_index, &table);
515 if (ACPI_SUCCESS(status)) {
516 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
517 table,
518 acpi_gbl_table_handler_context);
519 }
520 }
521
522 /*
523 * Delete the entire namespace under this table Node
524 * (Offset contains the table_id)
525 */
526 acpi_tb_delete_namespace_by_owner(table_index);
527 (void)acpi_tb_release_owner_id(table_index);
528
529 acpi_tb_set_table_loaded_flag(table_index, FALSE);
530
531 /* Table unloaded, remove a reference to the ddb_handle object */
532
533 acpi_ut_remove_reference(ddb_handle);
534 return_ACPI_STATUS(AE_OK);
535}
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
deleted file mode 100644
index 1d1f35adddde..000000000000
--- a/drivers/acpi/executer/exconvrt.c
+++ /dev/null
@@ -1,691 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: exconvrt - Object conversion routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acinterp.h>
46#include <acpi/amlcode.h>
47
48#define _COMPONENT ACPI_EXECUTER
49ACPI_MODULE_NAME("exconvrt")
50
51/* Local prototypes */
52static u32
53acpi_ex_convert_to_ascii(acpi_integer integer,
54 u16 base, u8 * string, u8 max_length);
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ex_convert_to_integer
59 *
60 * PARAMETERS: obj_desc - Object to be converted. Must be an
61 * Integer, Buffer, or String
62 * result_desc - Where the new Integer object is returned
63 * Flags - Used for string conversion
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Convert an ACPI Object to an integer.
68 *
69 ******************************************************************************/
70
71acpi_status
72acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
73 union acpi_operand_object **result_desc, u32 flags)
74{
75 union acpi_operand_object *return_desc;
76 u8 *pointer;
77 acpi_integer result;
78 u32 i;
79 u32 count;
80 acpi_status status;
81
82 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_integer, obj_desc);
83
84 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
85 case ACPI_TYPE_INTEGER:
86
87 /* No conversion necessary */
88
89 *result_desc = obj_desc;
90 return_ACPI_STATUS(AE_OK);
91
92 case ACPI_TYPE_BUFFER:
93 case ACPI_TYPE_STRING:
94
95 /* Note: Takes advantage of common buffer/string fields */
96
97 pointer = obj_desc->buffer.pointer;
98 count = obj_desc->buffer.length;
99 break;
100
101 default:
102 return_ACPI_STATUS(AE_TYPE);
103 }
104
105 /*
106 * Convert the buffer/string to an integer. Note that both buffers and
107 * strings are treated as raw data - we don't convert ascii to hex for
108 * strings.
109 *
110 * There are two terminating conditions for the loop:
111 * 1) The size of an integer has been reached, or
112 * 2) The end of the buffer or string has been reached
113 */
114 result = 0;
115
116 /* String conversion is different than Buffer conversion */
117
118 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
119 case ACPI_TYPE_STRING:
120
121 /*
122 * Convert string to an integer - for most cases, the string must be
123 * hexadecimal as per the ACPI specification. The only exception (as
124 * of ACPI 3.0) is that the to_integer() operator allows both decimal
125 * and hexadecimal strings (hex prefixed with "0x").
126 */
127 status = acpi_ut_strtoul64((char *)pointer, flags, &result);
128 if (ACPI_FAILURE(status)) {
129 return_ACPI_STATUS(status);
130 }
131 break;
132
133 case ACPI_TYPE_BUFFER:
134
135 /* Check for zero-length buffer */
136
137 if (!count) {
138 return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
139 }
140
141 /* Transfer no more than an integer's worth of data */
142
143 if (count > acpi_gbl_integer_byte_width) {
144 count = acpi_gbl_integer_byte_width;
145 }
146
147 /*
148 * Convert buffer to an integer - we simply grab enough raw data
149 * from the buffer to fill an integer
150 */
151 for (i = 0; i < count; i++) {
152 /*
153 * Get next byte and shift it into the Result.
154 * Little endian is used, meaning that the first byte of the buffer
155 * is the LSB of the integer
156 */
157 result |= (((acpi_integer) pointer[i]) << (i * 8));
158 }
159 break;
160
161 default:
162
163 /* No other types can get here */
164 break;
165 }
166
167 /* Create a new integer */
168
169 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
170 if (!return_desc) {
171 return_ACPI_STATUS(AE_NO_MEMORY);
172 }
173
174 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
175 ACPI_FORMAT_UINT64(result)));
176
177 /* Save the Result */
178
179 return_desc->integer.value = result;
180 acpi_ex_truncate_for32bit_table(return_desc);
181 *result_desc = return_desc;
182 return_ACPI_STATUS(AE_OK);
183}
184
185/*******************************************************************************
186 *
187 * FUNCTION: acpi_ex_convert_to_buffer
188 *
189 * PARAMETERS: obj_desc - Object to be converted. Must be an
190 * Integer, Buffer, or String
191 * result_desc - Where the new buffer object is returned
192 *
193 * RETURN: Status
194 *
195 * DESCRIPTION: Convert an ACPI Object to a Buffer
196 *
197 ******************************************************************************/
198
199acpi_status
200acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
201 union acpi_operand_object **result_desc)
202{
203 union acpi_operand_object *return_desc;
204 u8 *new_buf;
205
206 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_buffer, obj_desc);
207
208 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
209 case ACPI_TYPE_BUFFER:
210
211 /* No conversion necessary */
212
213 *result_desc = obj_desc;
214 return_ACPI_STATUS(AE_OK);
215
216 case ACPI_TYPE_INTEGER:
217
218 /*
219 * Create a new Buffer object.
220 * Need enough space for one integer
221 */
222 return_desc =
223 acpi_ut_create_buffer_object(acpi_gbl_integer_byte_width);
224 if (!return_desc) {
225 return_ACPI_STATUS(AE_NO_MEMORY);
226 }
227
228 /* Copy the integer to the buffer, LSB first */
229
230 new_buf = return_desc->buffer.pointer;
231 ACPI_MEMCPY(new_buf,
232 &obj_desc->integer.value,
233 acpi_gbl_integer_byte_width);
234 break;
235
236 case ACPI_TYPE_STRING:
237
238 /*
239 * Create a new Buffer object
240 * Size will be the string length
241 *
242 * NOTE: Add one to the string length to include the null terminator.
243 * The ACPI spec is unclear on this subject, but there is existing
244 * ASL/AML code that depends on the null being transferred to the new
245 * buffer.
246 */
247 return_desc = acpi_ut_create_buffer_object((acpi_size)
248 obj_desc->string.
249 length + 1);
250 if (!return_desc) {
251 return_ACPI_STATUS(AE_NO_MEMORY);
252 }
253
254 /* Copy the string to the buffer */
255
256 new_buf = return_desc->buffer.pointer;
257 ACPI_STRNCPY((char *)new_buf, (char *)obj_desc->string.pointer,
258 obj_desc->string.length);
259 break;
260
261 default:
262 return_ACPI_STATUS(AE_TYPE);
263 }
264
265 /* Mark buffer initialized */
266
267 return_desc->common.flags |= AOPOBJ_DATA_VALID;
268 *result_desc = return_desc;
269 return_ACPI_STATUS(AE_OK);
270}
271
272/*******************************************************************************
273 *
274 * FUNCTION: acpi_ex_convert_to_ascii
275 *
276 * PARAMETERS: Integer - Value to be converted
277 * Base - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
278 * String - Where the string is returned
279 * data_width - Size of data item to be converted, in bytes
280 *
281 * RETURN: Actual string length
282 *
283 * DESCRIPTION: Convert an ACPI Integer to a hex or decimal string
284 *
285 ******************************************************************************/
286
287static u32
288acpi_ex_convert_to_ascii(acpi_integer integer,
289 u16 base, u8 * string, u8 data_width)
290{
291 acpi_integer digit;
292 u32 i;
293 u32 j;
294 u32 k = 0;
295 u32 hex_length;
296 u32 decimal_length;
297 u32 remainder;
298 u8 supress_zeros;
299
300 ACPI_FUNCTION_ENTRY();
301
302 switch (base) {
303 case 10:
304
305 /* Setup max length for the decimal number */
306
307 switch (data_width) {
308 case 1:
309 decimal_length = ACPI_MAX8_DECIMAL_DIGITS;
310 break;
311
312 case 4:
313 decimal_length = ACPI_MAX32_DECIMAL_DIGITS;
314 break;
315
316 case 8:
317 default:
318 decimal_length = ACPI_MAX64_DECIMAL_DIGITS;
319 break;
320 }
321
322 supress_zeros = TRUE; /* No leading zeros */
323 remainder = 0;
324
325 for (i = decimal_length; i > 0; i--) {
326
327 /* Divide by nth factor of 10 */
328
329 digit = integer;
330 for (j = 0; j < i; j++) {
331 (void)acpi_ut_short_divide(digit, 10, &digit,
332 &remainder);
333 }
334
335 /* Handle leading zeros */
336
337 if (remainder != 0) {
338 supress_zeros = FALSE;
339 }
340
341 if (!supress_zeros) {
342 string[k] = (u8) (ACPI_ASCII_ZERO + remainder);
343 k++;
344 }
345 }
346 break;
347
348 case 16:
349
350 /* hex_length: 2 ascii hex chars per data byte */
351
352 hex_length = ACPI_MUL_2(data_width);
353 for (i = 0, j = (hex_length - 1); i < hex_length; i++, j--) {
354
355 /* Get one hex digit, most significant digits first */
356
357 string[k] =
358 (u8) acpi_ut_hex_to_ascii_char(integer,
359 ACPI_MUL_4(j));
360 k++;
361 }
362 break;
363
364 default:
365 return (0);
366 }
367
368 /*
369 * Since leading zeros are suppressed, we must check for the case where
370 * the integer equals 0
371 *
372 * Finally, null terminate the string and return the length
373 */
374 if (!k) {
375 string[0] = ACPI_ASCII_ZERO;
376 k = 1;
377 }
378
379 string[k] = 0;
380 return ((u32) k);
381}
382
383/*******************************************************************************
384 *
385 * FUNCTION: acpi_ex_convert_to_string
386 *
387 * PARAMETERS: obj_desc - Object to be converted. Must be an
388 * Integer, Buffer, or String
389 * result_desc - Where the string object is returned
390 * Type - String flags (base and conversion type)
391 *
392 * RETURN: Status
393 *
394 * DESCRIPTION: Convert an ACPI Object to a string
395 *
396 ******************************************************************************/
397
398acpi_status
399acpi_ex_convert_to_string(union acpi_operand_object * obj_desc,
400 union acpi_operand_object ** result_desc, u32 type)
401{
402 union acpi_operand_object *return_desc;
403 u8 *new_buf;
404 u32 i;
405 u32 string_length = 0;
406 u16 base = 16;
407 u8 separator = ',';
408
409 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_string, obj_desc);
410
411 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
412 case ACPI_TYPE_STRING:
413
414 /* No conversion necessary */
415
416 *result_desc = obj_desc;
417 return_ACPI_STATUS(AE_OK);
418
419 case ACPI_TYPE_INTEGER:
420
421 switch (type) {
422 case ACPI_EXPLICIT_CONVERT_DECIMAL:
423
424 /* Make room for maximum decimal number */
425
426 string_length = ACPI_MAX_DECIMAL_DIGITS;
427 base = 10;
428 break;
429
430 default:
431
432 /* Two hex string characters for each integer byte */
433
434 string_length = ACPI_MUL_2(acpi_gbl_integer_byte_width);
435 break;
436 }
437
438 /*
439 * Create a new String
440 * Need enough space for one ASCII integer (plus null terminator)
441 */
442 return_desc =
443 acpi_ut_create_string_object((acpi_size) string_length);
444 if (!return_desc) {
445 return_ACPI_STATUS(AE_NO_MEMORY);
446 }
447
448 new_buf = return_desc->buffer.pointer;
449
450 /* Convert integer to string */
451
452 string_length =
453 acpi_ex_convert_to_ascii(obj_desc->integer.value, base,
454 new_buf,
455 acpi_gbl_integer_byte_width);
456
457 /* Null terminate at the correct place */
458
459 return_desc->string.length = string_length;
460 new_buf[string_length] = 0;
461 break;
462
463 case ACPI_TYPE_BUFFER:
464
465 /* Setup string length, base, and separator */
466
467 switch (type) {
468 case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by to_decimal_string */
469 /*
470 * From ACPI: "If Data is a buffer, it is converted to a string of
471 * decimal values separated by commas."
472 */
473 base = 10;
474
475 /*
476 * Calculate the final string length. Individual string values
477 * are variable length (include separator for each)
478 */
479 for (i = 0; i < obj_desc->buffer.length; i++) {
480 if (obj_desc->buffer.pointer[i] >= 100) {
481 string_length += 4;
482 } else if (obj_desc->buffer.pointer[i] >= 10) {
483 string_length += 3;
484 } else {
485 string_length += 2;
486 }
487 }
488 break;
489
490 case ACPI_IMPLICIT_CONVERT_HEX:
491 /*
492 * From the ACPI spec:
493 *"The entire contents of the buffer are converted to a string of
494 * two-character hexadecimal numbers, each separated by a space."
495 */
496 separator = ' ';
497 string_length = (obj_desc->buffer.length * 3);
498 break;
499
500 case ACPI_EXPLICIT_CONVERT_HEX: /* Used by to_hex_string */
501 /*
502 * From ACPI: "If Data is a buffer, it is converted to a string of
503 * hexadecimal values separated by commas."
504 */
505 string_length = (obj_desc->buffer.length * 3);
506 break;
507
508 default:
509 return_ACPI_STATUS(AE_BAD_PARAMETER);
510 }
511
512 /*
513 * Create a new string object and string buffer
514 * (-1 because of extra separator included in string_length from above)
515 * Allow creation of zero-length strings from zero-length buffers.
516 */
517 if (string_length) {
518 string_length--;
519 }
520
521 return_desc = acpi_ut_create_string_object((acpi_size)
522 string_length);
523 if (!return_desc) {
524 return_ACPI_STATUS(AE_NO_MEMORY);
525 }
526
527 new_buf = return_desc->buffer.pointer;
528
529 /*
530 * Convert buffer bytes to hex or decimal values
531 * (separated by commas or spaces)
532 */
533 for (i = 0; i < obj_desc->buffer.length; i++) {
534 new_buf += acpi_ex_convert_to_ascii((acpi_integer)
535 obj_desc->buffer.
536 pointer[i], base,
537 new_buf, 1);
538 *new_buf++ = separator; /* each separated by a comma or space */
539 }
540
541 /*
542 * Null terminate the string
543 * (overwrites final comma/space from above)
544 */
545 if (obj_desc->buffer.length) {
546 new_buf--;
547 }
548 *new_buf = 0;
549 break;
550
551 default:
552 return_ACPI_STATUS(AE_TYPE);
553 }
554
555 *result_desc = return_desc;
556 return_ACPI_STATUS(AE_OK);
557}
558
559/*******************************************************************************
560 *
561 * FUNCTION: acpi_ex_convert_to_target_type
562 *
563 * PARAMETERS: destination_type - Current type of the destination
564 * source_desc - Source object to be converted.
565 * result_desc - Where the converted object is returned
566 * walk_state - Current method state
567 *
568 * RETURN: Status
569 *
570 * DESCRIPTION: Implements "implicit conversion" rules for storing an object.
571 *
572 ******************************************************************************/
573
574acpi_status
575acpi_ex_convert_to_target_type(acpi_object_type destination_type,
576 union acpi_operand_object *source_desc,
577 union acpi_operand_object **result_desc,
578 struct acpi_walk_state *walk_state)
579{
580 acpi_status status = AE_OK;
581
582 ACPI_FUNCTION_TRACE(ex_convert_to_target_type);
583
584 /* Default behavior */
585
586 *result_desc = source_desc;
587
588 /*
589 * If required by the target,
590 * perform implicit conversion on the source before we store it.
591 */
592 switch (GET_CURRENT_ARG_TYPE(walk_state->op_info->runtime_args)) {
593 case ARGI_SIMPLE_TARGET:
594 case ARGI_FIXED_TARGET:
595 case ARGI_INTEGER_REF: /* Handles Increment, Decrement cases */
596
597 switch (destination_type) {
598 case ACPI_TYPE_LOCAL_REGION_FIELD:
599 /*
600 * Named field can always handle conversions
601 */
602 break;
603
604 default:
605 /* No conversion allowed for these types */
606
607 if (destination_type !=
608 ACPI_GET_OBJECT_TYPE(source_desc)) {
609 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
610 "Explicit operator, will store (%s) over existing type (%s)\n",
611 acpi_ut_get_object_type_name
612 (source_desc),
613 acpi_ut_get_type_name
614 (destination_type)));
615 status = AE_TYPE;
616 }
617 }
618 break;
619
620 case ARGI_TARGETREF:
621
622 switch (destination_type) {
623 case ACPI_TYPE_INTEGER:
624 case ACPI_TYPE_BUFFER_FIELD:
625 case ACPI_TYPE_LOCAL_BANK_FIELD:
626 case ACPI_TYPE_LOCAL_INDEX_FIELD:
627 /*
628 * These types require an Integer operand. We can convert
629 * a Buffer or a String to an Integer if necessary.
630 */
631 status =
632 acpi_ex_convert_to_integer(source_desc, result_desc,
633 16);
634 break;
635
636 case ACPI_TYPE_STRING:
637 /*
638 * The operand must be a String. We can convert an
639 * Integer or Buffer if necessary
640 */
641 status =
642 acpi_ex_convert_to_string(source_desc, result_desc,
643 ACPI_IMPLICIT_CONVERT_HEX);
644 break;
645
646 case ACPI_TYPE_BUFFER:
647 /*
648 * The operand must be a Buffer. We can convert an
649 * Integer or String if necessary
650 */
651 status =
652 acpi_ex_convert_to_buffer(source_desc, result_desc);
653 break;
654
655 default:
656 ACPI_ERROR((AE_INFO,
657 "Bad destination type during conversion: %X",
658 destination_type));
659 status = AE_AML_INTERNAL;
660 break;
661 }
662 break;
663
664 case ARGI_REFERENCE:
665 /*
666 * create_xxxx_field cases - we are storing the field object into the name
667 */
668 break;
669
670 default:
671 ACPI_ERROR((AE_INFO,
672 "Unknown Target type ID 0x%X AmlOpcode %X DestType %s",
673 GET_CURRENT_ARG_TYPE(walk_state->op_info->
674 runtime_args),
675 walk_state->opcode,
676 acpi_ut_get_type_name(destination_type)));
677 status = AE_AML_INTERNAL;
678 }
679
680 /*
681 * Source-to-Target conversion semantics:
682 *
683 * If conversion to the target type cannot be performed, then simply
684 * overwrite the target with the new object and type.
685 */
686 if (status == AE_TYPE) {
687 status = AE_OK;
688 }
689
690 return_ACPI_STATUS(status);
691}
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
deleted file mode 100644
index ad09696d5069..000000000000
--- a/drivers/acpi/executer/excreate.c
+++ /dev/null
@@ -1,521 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: excreate - Named object creation
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acinterp.h>
46#include <acpi/amlcode.h>
47#include <acpi/acnamesp.h>
48
49#define _COMPONENT ACPI_EXECUTER
50ACPI_MODULE_NAME("excreate")
51#ifndef ACPI_NO_METHOD_EXECUTION
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_ex_create_alias
55 *
56 * PARAMETERS: walk_state - Current state, contains operands
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: Create a new named alias
61 *
62 ******************************************************************************/
63acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
64{
65 struct acpi_namespace_node *target_node;
66 struct acpi_namespace_node *alias_node;
67 acpi_status status = AE_OK;
68
69 ACPI_FUNCTION_TRACE(ex_create_alias);
70
71 /* Get the source/alias operands (both namespace nodes) */
72
73 alias_node = (struct acpi_namespace_node *)walk_state->operands[0];
74 target_node = (struct acpi_namespace_node *)walk_state->operands[1];
75
76 if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) ||
77 (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
78 /*
79 * Dereference an existing alias so that we don't create a chain
80 * of aliases. With this code, we guarantee that an alias is
81 * always exactly one level of indirection away from the
82 * actual aliased name.
83 */
84 target_node =
85 ACPI_CAST_PTR(struct acpi_namespace_node,
86 target_node->object);
87 }
88
89 /*
90 * For objects that can never change (i.e., the NS node will
91 * permanently point to the same object), we can simply attach
92 * the object to the new NS node. For other objects (such as
93 * Integers, buffers, etc.), we have to point the Alias node
94 * to the original Node.
95 */
96 switch (target_node->type) {
97
98 /* For these types, the sub-object can change dynamically via a Store */
99
100 case ACPI_TYPE_INTEGER:
101 case ACPI_TYPE_STRING:
102 case ACPI_TYPE_BUFFER:
103 case ACPI_TYPE_PACKAGE:
104 case ACPI_TYPE_BUFFER_FIELD:
105
106 /*
107 * These types open a new scope, so we need the NS node in order to access
108 * any children.
109 */
110 case ACPI_TYPE_DEVICE:
111 case ACPI_TYPE_POWER:
112 case ACPI_TYPE_PROCESSOR:
113 case ACPI_TYPE_THERMAL:
114 case ACPI_TYPE_LOCAL_SCOPE:
115
116 /*
117 * The new alias has the type ALIAS and points to the original
118 * NS node, not the object itself.
119 */
120 alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
121 alias_node->object =
122 ACPI_CAST_PTR(union acpi_operand_object, target_node);
123 break;
124
125 case ACPI_TYPE_METHOD:
126
127 /*
128 * Control method aliases need to be differentiated
129 */
130 alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
131 alias_node->object =
132 ACPI_CAST_PTR(union acpi_operand_object, target_node);
133 break;
134
135 default:
136
137 /* Attach the original source object to the new Alias Node */
138
139 /*
140 * The new alias assumes the type of the target, and it points
141 * to the same object. The reference count of the object has an
142 * additional reference to prevent deletion out from under either the
143 * target node or the alias Node
144 */
145 status = acpi_ns_attach_object(alias_node,
146 acpi_ns_get_attached_object
147 (target_node),
148 target_node->type);
149 break;
150 }
151
152 /* Since both operands are Nodes, we don't need to delete them */
153
154 return_ACPI_STATUS(status);
155}
156
157/*******************************************************************************
158 *
159 * FUNCTION: acpi_ex_create_event
160 *
161 * PARAMETERS: walk_state - Current state
162 *
163 * RETURN: Status
164 *
165 * DESCRIPTION: Create a new event object
166 *
167 ******************************************************************************/
168
169acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
170{
171 acpi_status status;
172 union acpi_operand_object *obj_desc;
173
174 ACPI_FUNCTION_TRACE(ex_create_event);
175
176 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_EVENT);
177 if (!obj_desc) {
178 status = AE_NO_MEMORY;
179 goto cleanup;
180 }
181
182 /*
183 * Create the actual OS semaphore, with zero initial units -- meaning
184 * that the event is created in an unsignalled state
185 */
186 status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
187 &obj_desc->event.os_semaphore);
188 if (ACPI_FAILURE(status)) {
189 goto cleanup;
190 }
191
192 /* Attach object to the Node */
193
194 status =
195 acpi_ns_attach_object((struct acpi_namespace_node *)walk_state->
196 operands[0], obj_desc, ACPI_TYPE_EVENT);
197
198 cleanup:
199 /*
200 * Remove local reference to the object (on error, will cause deletion
201 * of both object and semaphore if present.)
202 */
203 acpi_ut_remove_reference(obj_desc);
204 return_ACPI_STATUS(status);
205}
206
207/*******************************************************************************
208 *
209 * FUNCTION: acpi_ex_create_mutex
210 *
211 * PARAMETERS: walk_state - Current state
212 *
213 * RETURN: Status
214 *
215 * DESCRIPTION: Create a new mutex object
216 *
217 * Mutex (Name[0], sync_level[1])
218 *
219 ******************************************************************************/
220
221acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
222{
223 acpi_status status = AE_OK;
224 union acpi_operand_object *obj_desc;
225
226 ACPI_FUNCTION_TRACE_PTR(ex_create_mutex, ACPI_WALK_OPERANDS);
227
228 /* Create the new mutex object */
229
230 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
231 if (!obj_desc) {
232 status = AE_NO_MEMORY;
233 goto cleanup;
234 }
235
236 /* Create the actual OS Mutex */
237
238 status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex);
239 if (ACPI_FAILURE(status)) {
240 goto cleanup;
241 }
242
243 /* Init object and attach to NS node */
244
245 obj_desc->mutex.sync_level =
246 (u8) walk_state->operands[1]->integer.value;
247 obj_desc->mutex.node =
248 (struct acpi_namespace_node *)walk_state->operands[0];
249
250 status =
251 acpi_ns_attach_object(obj_desc->mutex.node, obj_desc,
252 ACPI_TYPE_MUTEX);
253
254 cleanup:
255 /*
256 * Remove local reference to the object (on error, will cause deletion
257 * of both object and semaphore if present.)
258 */
259 acpi_ut_remove_reference(obj_desc);
260 return_ACPI_STATUS(status);
261}
262
263/*******************************************************************************
264 *
265 * FUNCTION: acpi_ex_create_region
266 *
267 * PARAMETERS: aml_start - Pointer to the region declaration AML
268 * aml_length - Max length of the declaration AML
269 * region_space - space_iD for the region
270 * walk_state - Current state
271 *
272 * RETURN: Status
273 *
274 * DESCRIPTION: Create a new operation region object
275 *
276 ******************************************************************************/
277
278acpi_status
279acpi_ex_create_region(u8 * aml_start,
280 u32 aml_length,
281 u8 region_space, struct acpi_walk_state *walk_state)
282{
283 acpi_status status;
284 union acpi_operand_object *obj_desc;
285 struct acpi_namespace_node *node;
286 union acpi_operand_object *region_obj2;
287
288 ACPI_FUNCTION_TRACE(ex_create_region);
289
290 /* Get the Namespace Node */
291
292 node = walk_state->op->common.node;
293
294 /*
295 * If the region object is already attached to this node,
296 * just return
297 */
298 if (acpi_ns_get_attached_object(node)) {
299 return_ACPI_STATUS(AE_OK);
300 }
301
302 /*
303 * Space ID must be one of the predefined IDs, or in the user-defined
304 * range
305 */
306 if ((region_space >= ACPI_NUM_PREDEFINED_REGIONS) &&
307 (region_space < ACPI_USER_REGION_BEGIN)) {
308 ACPI_ERROR((AE_INFO, "Invalid AddressSpace type %X",
309 region_space));
310 return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
311 }
312
313 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
314 acpi_ut_get_region_name(region_space), region_space));
315
316 /* Create the region descriptor */
317
318 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
319 if (!obj_desc) {
320 status = AE_NO_MEMORY;
321 goto cleanup;
322 }
323
324 /*
325 * Remember location in AML stream of address & length
326 * operands since they need to be evaluated at run time.
327 */
328 region_obj2 = obj_desc->common.next_object;
329 region_obj2->extra.aml_start = aml_start;
330 region_obj2->extra.aml_length = aml_length;
331
332 /* Init the region from the operands */
333
334 obj_desc->region.space_id = region_space;
335 obj_desc->region.address = 0;
336 obj_desc->region.length = 0;
337 obj_desc->region.node = node;
338
339 /* Install the new region object in the parent Node */
340
341 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
342
343 cleanup:
344
345 /* Remove local reference to the object */
346
347 acpi_ut_remove_reference(obj_desc);
348 return_ACPI_STATUS(status);
349}
350
351/*******************************************************************************
352 *
353 * FUNCTION: acpi_ex_create_processor
354 *
355 * PARAMETERS: walk_state - Current state
356 *
357 * RETURN: Status
358 *
359 * DESCRIPTION: Create a new processor object and populate the fields
360 *
361 * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
362 *
363 ******************************************************************************/
364
365acpi_status acpi_ex_create_processor(struct acpi_walk_state *walk_state)
366{
367 union acpi_operand_object **operand = &walk_state->operands[0];
368 union acpi_operand_object *obj_desc;
369 acpi_status status;
370
371 ACPI_FUNCTION_TRACE_PTR(ex_create_processor, walk_state);
372
373 /* Create the processor object */
374
375 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PROCESSOR);
376 if (!obj_desc) {
377 return_ACPI_STATUS(AE_NO_MEMORY);
378 }
379
380 /* Initialize the processor object from the operands */
381
382 obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
383 obj_desc->processor.length = (u8) operand[3]->integer.value;
384 obj_desc->processor.address =
385 (acpi_io_address) operand[2]->integer.value;
386
387 /* Install the processor object in the parent Node */
388
389 status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
390 obj_desc, ACPI_TYPE_PROCESSOR);
391
392 /* Remove local reference to the object */
393
394 acpi_ut_remove_reference(obj_desc);
395 return_ACPI_STATUS(status);
396}
397
398/*******************************************************************************
399 *
400 * FUNCTION: acpi_ex_create_power_resource
401 *
402 * PARAMETERS: walk_state - Current state
403 *
404 * RETURN: Status
405 *
406 * DESCRIPTION: Create a new power_resource object and populate the fields
407 *
408 * power_resource (Name[0], system_level[1], resource_order[2])
409 *
410 ******************************************************************************/
411
412acpi_status acpi_ex_create_power_resource(struct acpi_walk_state *walk_state)
413{
414 union acpi_operand_object **operand = &walk_state->operands[0];
415 acpi_status status;
416 union acpi_operand_object *obj_desc;
417
418 ACPI_FUNCTION_TRACE_PTR(ex_create_power_resource, walk_state);
419
420 /* Create the power resource object */
421
422 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_POWER);
423 if (!obj_desc) {
424 return_ACPI_STATUS(AE_NO_MEMORY);
425 }
426
427 /* Initialize the power object from the operands */
428
429 obj_desc->power_resource.system_level = (u8) operand[1]->integer.value;
430 obj_desc->power_resource.resource_order =
431 (u16) operand[2]->integer.value;
432
433 /* Install the power resource object in the parent Node */
434
435 status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
436 obj_desc, ACPI_TYPE_POWER);
437
438 /* Remove local reference to the object */
439
440 acpi_ut_remove_reference(obj_desc);
441 return_ACPI_STATUS(status);
442}
443#endif
444
445/*******************************************************************************
446 *
447 * FUNCTION: acpi_ex_create_method
448 *
449 * PARAMETERS: aml_start - First byte of the method's AML
450 * aml_length - AML byte count for this method
451 * walk_state - Current state
452 *
453 * RETURN: Status
454 *
455 * DESCRIPTION: Create a new method object
456 *
457 ******************************************************************************/
458
459acpi_status
460acpi_ex_create_method(u8 * aml_start,
461 u32 aml_length, struct acpi_walk_state *walk_state)
462{
463 union acpi_operand_object **operand = &walk_state->operands[0];
464 union acpi_operand_object *obj_desc;
465 acpi_status status;
466 u8 method_flags;
467
468 ACPI_FUNCTION_TRACE_PTR(ex_create_method, walk_state);
469
470 /* Create a new method object */
471
472 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
473 if (!obj_desc) {
474 status = AE_NO_MEMORY;
475 goto exit;
476 }
477
478 /* Save the method's AML pointer and length */
479
480 obj_desc->method.aml_start = aml_start;
481 obj_desc->method.aml_length = aml_length;
482
483 /*
484 * Disassemble the method flags. Split off the Arg Count
485 * for efficiency
486 */
487 method_flags = (u8) operand[1]->integer.value;
488
489 obj_desc->method.method_flags =
490 (u8) (method_flags & ~AML_METHOD_ARG_COUNT);
491 obj_desc->method.param_count =
492 (u8) (method_flags & AML_METHOD_ARG_COUNT);
493
494 /*
495 * Get the sync_level. If method is serialized, a mutex will be
496 * created for this method when it is parsed.
497 */
498 if (method_flags & AML_METHOD_SERIALIZED) {
499 /*
500 * ACPI 1.0: sync_level = 0
501 * ACPI 2.0: sync_level = sync_level in method declaration
502 */
503 obj_desc->method.sync_level = (u8)
504 ((method_flags & AML_METHOD_SYNCH_LEVEL) >> 4);
505 }
506
507 /* Attach the new object to the method Node */
508
509 status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
510 obj_desc, ACPI_TYPE_METHOD);
511
512 /* Remove local reference to the object */
513
514 acpi_ut_remove_reference(obj_desc);
515
516 exit:
517 /* Remove a reference to the operand */
518
519 acpi_ut_remove_reference(operand[1]);
520 return_ACPI_STATUS(status);
521}
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
deleted file mode 100644
index d087a7d28aa5..000000000000
--- a/drivers/acpi/executer/exdump.c
+++ /dev/null
@@ -1,1059 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: exdump - Interpreter debug output routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acinterp.h>
46#include <acpi/amlcode.h>
47#include <acpi/acnamesp.h>
48
49#define _COMPONENT ACPI_EXECUTER
50ACPI_MODULE_NAME("exdump")
51
52/*
53 * The following routines are used for debug output only
54 */
55#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
56/* Local prototypes */
57static void acpi_ex_out_string(char *title, char *value);
58
59static void acpi_ex_out_pointer(char *title, void *value);
60
61static void
62acpi_ex_dump_object(union acpi_operand_object *obj_desc,
63 struct acpi_exdump_info *info);
64
65static void acpi_ex_dump_reference_obj(union acpi_operand_object *obj_desc);
66
67static void
68acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
69 u32 level, u32 index);
70
71/*******************************************************************************
72 *
73 * Object Descriptor info tables
74 *
75 * Note: The first table entry must be an INIT opcode and must contain
76 * the table length (number of table entries)
77 *
78 ******************************************************************************/
79
80static struct acpi_exdump_info acpi_ex_dump_integer[2] = {
81 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_integer), NULL},
82 {ACPI_EXD_UINT64, ACPI_EXD_OFFSET(integer.value), "Value"}
83};
84
85static struct acpi_exdump_info acpi_ex_dump_string[4] = {
86 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_string), NULL},
87 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(string.length), "Length"},
88 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(string.pointer), "Pointer"},
89 {ACPI_EXD_STRING, 0, NULL}
90};
91
92static struct acpi_exdump_info acpi_ex_dump_buffer[5] = {
93 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_buffer), NULL},
94 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(buffer.length), "Length"},
95 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.pointer), "Pointer"},
96 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.node), "Parent Node"},
97 {ACPI_EXD_BUFFER, 0, NULL}
98};
99
100static struct acpi_exdump_info acpi_ex_dump_package[5] = {
101 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_package), NULL},
102 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(package.flags), "Flags"},
103 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(package.count), "Elements"},
104 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(package.elements), "Element List"},
105 {ACPI_EXD_PACKAGE, 0, NULL}
106};
107
108static struct acpi_exdump_info acpi_ex_dump_device[4] = {
109 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_device), NULL},
110 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(device.handler), "Handler"},
111 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(device.system_notify),
112 "System Notify"},
113 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(device.device_notify),
114 "Device Notify"}
115};
116
117static struct acpi_exdump_info acpi_ex_dump_event[2] = {
118 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_event), NULL},
119 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(event.os_semaphore), "OsSemaphore"}
120};
121
122static struct acpi_exdump_info acpi_ex_dump_method[8] = {
123 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_method), NULL},
124 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.param_count), "ParamCount"},
125 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.sync_level), "Sync Level"},
126 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(method.mutex), "Mutex"},
127 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.owner_id), "Owner Id"},
128 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.thread_count), "Thread Count"},
129 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(method.aml_length), "Aml Length"},
130 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(method.aml_start), "Aml Start"}
131};
132
133static struct acpi_exdump_info acpi_ex_dump_mutex[5] = {
134 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL},
135 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"},
136 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"},
137 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth),
138 "Acquire Depth"},
139 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"}
140};
141
142static struct acpi_exdump_info acpi_ex_dump_region[7] = {
143 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_region), NULL},
144 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(region.space_id), "Space Id"},
145 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(region.flags), "Flags"},
146 {ACPI_EXD_ADDRESS, ACPI_EXD_OFFSET(region.address), "Address"},
147 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(region.length), "Length"},
148 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(region.handler), "Handler"},
149 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(region.next), "Next"}
150};
151
152static struct acpi_exdump_info acpi_ex_dump_power[5] = {
153 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_power), NULL},
154 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(power_resource.system_level),
155 "System Level"},
156 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(power_resource.resource_order),
157 "Resource Order"},
158 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(power_resource.system_notify),
159 "System Notify"},
160 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(power_resource.device_notify),
161 "Device Notify"}
162};
163
164static struct acpi_exdump_info acpi_ex_dump_processor[7] = {
165 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_processor), NULL},
166 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.proc_id), "Processor ID"},
167 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.length), "Length"},
168 {ACPI_EXD_ADDRESS, ACPI_EXD_OFFSET(processor.address), "Address"},
169 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.system_notify),
170 "System Notify"},
171 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.device_notify),
172 "Device Notify"},
173 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.handler), "Handler"}
174};
175
176static struct acpi_exdump_info acpi_ex_dump_thermal[4] = {
177 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_thermal), NULL},
178 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(thermal_zone.system_notify),
179 "System Notify"},
180 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(thermal_zone.device_notify),
181 "Device Notify"},
182 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(thermal_zone.handler), "Handler"}
183};
184
185static struct acpi_exdump_info acpi_ex_dump_buffer_field[3] = {
186 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_buffer_field), NULL},
187 {ACPI_EXD_FIELD, 0, NULL},
188 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer_field.buffer_obj),
189 "Buffer Object"}
190};
191
192static struct acpi_exdump_info acpi_ex_dump_region_field[3] = {
193 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_region_field), NULL},
194 {ACPI_EXD_FIELD, 0, NULL},
195 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(field.region_obj), "Region Object"}
196};
197
198static struct acpi_exdump_info acpi_ex_dump_bank_field[5] = {
199 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_bank_field), NULL},
200 {ACPI_EXD_FIELD, 0, NULL},
201 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(bank_field.value), "Value"},
202 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(bank_field.region_obj),
203 "Region Object"},
204 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(bank_field.bank_obj), "Bank Object"}
205};
206
207static struct acpi_exdump_info acpi_ex_dump_index_field[5] = {
208 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_bank_field), NULL},
209 {ACPI_EXD_FIELD, 0, NULL},
210 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(index_field.value), "Value"},
211 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(index_field.index_obj),
212 "Index Object"},
213 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(index_field.data_obj), "Data Object"}
214};
215
216static struct acpi_exdump_info acpi_ex_dump_reference[8] = {
217 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_reference), NULL},
218 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(reference.class), "Class"},
219 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(reference.target_type), "Target Type"},
220 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(reference.value), "Value"},
221 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(reference.object), "Object Desc"},
222 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(reference.node), "Node"},
223 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(reference.where), "Where"},
224 {ACPI_EXD_REFERENCE, 0, NULL}
225};
226
227static struct acpi_exdump_info acpi_ex_dump_address_handler[6] = {
228 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_address_handler),
229 NULL},
230 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(address_space.space_id), "Space Id"},
231 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.next), "Next"},
232 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.region_list),
233 "Region List"},
234 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.node), "Node"},
235 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.context), "Context"}
236};
237
238static struct acpi_exdump_info acpi_ex_dump_notify[3] = {
239 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_notify), NULL},
240 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(notify.node), "Node"},
241 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(notify.context), "Context"}
242};
243
244/* Miscellaneous tables */
245
246static struct acpi_exdump_info acpi_ex_dump_common[4] = {
247 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_common), NULL},
248 {ACPI_EXD_TYPE, 0, NULL},
249 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(common.reference_count),
250 "Reference Count"},
251 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common.flags), "Flags"}
252};
253
254static struct acpi_exdump_info acpi_ex_dump_field_common[7] = {
255 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_field_common), NULL},
256 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common_field.field_flags),
257 "Field Flags"},
258 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common_field.access_byte_width),
259 "Access Byte Width"},
260 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(common_field.bit_length),
261 "Bit Length"},
262 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common_field.start_field_bit_offset),
263 "Field Bit Offset"},
264 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(common_field.base_byte_offset),
265 "Base Byte Offset"},
266 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(common_field.node), "Parent Node"}
267};
268
269static struct acpi_exdump_info acpi_ex_dump_node[5] = {
270 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_node), NULL},
271 {ACPI_EXD_UINT8, ACPI_EXD_NSOFFSET(flags), "Flags"},
272 {ACPI_EXD_UINT8, ACPI_EXD_NSOFFSET(owner_id), "Owner Id"},
273 {ACPI_EXD_POINTER, ACPI_EXD_NSOFFSET(child), "Child List"},
274 {ACPI_EXD_POINTER, ACPI_EXD_NSOFFSET(peer), "Next Peer"}
275};
276
277/* Dispatch table, indexed by object type */
278
279static struct acpi_exdump_info *acpi_ex_dump_info[] = {
280 NULL,
281 acpi_ex_dump_integer,
282 acpi_ex_dump_string,
283 acpi_ex_dump_buffer,
284 acpi_ex_dump_package,
285 NULL,
286 acpi_ex_dump_device,
287 acpi_ex_dump_event,
288 acpi_ex_dump_method,
289 acpi_ex_dump_mutex,
290 acpi_ex_dump_region,
291 acpi_ex_dump_power,
292 acpi_ex_dump_processor,
293 acpi_ex_dump_thermal,
294 acpi_ex_dump_buffer_field,
295 NULL,
296 NULL,
297 acpi_ex_dump_region_field,
298 acpi_ex_dump_bank_field,
299 acpi_ex_dump_index_field,
300 acpi_ex_dump_reference,
301 NULL,
302 NULL,
303 acpi_ex_dump_notify,
304 acpi_ex_dump_address_handler,
305 NULL,
306 NULL,
307 NULL
308};
309
310/*******************************************************************************
311 *
312 * FUNCTION: acpi_ex_dump_object
313 *
314 * PARAMETERS: obj_desc - Descriptor to dump
315 * Info - Info table corresponding to this object
316 * type
317 *
318 * RETURN: None
319 *
320 * DESCRIPTION: Walk the info table for this object
321 *
322 ******************************************************************************/
323
324static void
325acpi_ex_dump_object(union acpi_operand_object *obj_desc,
326 struct acpi_exdump_info *info)
327{
328 u8 *target;
329 char *name;
330 u8 count;
331
332 if (!info) {
333 acpi_os_printf
334 ("ExDumpObject: Display not implemented for object type %s\n",
335 acpi_ut_get_object_type_name(obj_desc));
336 return;
337 }
338
339 /* First table entry must contain the table length (# of table entries) */
340
341 count = info->offset;
342
343 while (count) {
344 target = ACPI_ADD_PTR(u8, obj_desc, info->offset);
345 name = info->name;
346
347 switch (info->opcode) {
348 case ACPI_EXD_INIT:
349 break;
350
351 case ACPI_EXD_TYPE:
352 acpi_ex_out_string("Type",
353 acpi_ut_get_object_type_name
354 (obj_desc));
355 break;
356
357 case ACPI_EXD_UINT8:
358
359 acpi_os_printf("%20s : %2.2X\n", name, *target);
360 break;
361
362 case ACPI_EXD_UINT16:
363
364 acpi_os_printf("%20s : %4.4X\n", name,
365 ACPI_GET16(target));
366 break;
367
368 case ACPI_EXD_UINT32:
369
370 acpi_os_printf("%20s : %8.8X\n", name,
371 ACPI_GET32(target));
372 break;
373
374 case ACPI_EXD_UINT64:
375
376 acpi_os_printf("%20s : %8.8X%8.8X\n", "Value",
377 ACPI_FORMAT_UINT64(ACPI_GET64(target)));
378 break;
379
380 case ACPI_EXD_POINTER:
381 case ACPI_EXD_ADDRESS:
382
383 acpi_ex_out_pointer(name,
384 *ACPI_CAST_PTR(void *, target));
385 break;
386
387 case ACPI_EXD_STRING:
388
389 acpi_ut_print_string(obj_desc->string.pointer,
390 ACPI_UINT8_MAX);
391 acpi_os_printf("\n");
392 break;
393
394 case ACPI_EXD_BUFFER:
395
396 ACPI_DUMP_BUFFER(obj_desc->buffer.pointer,
397 obj_desc->buffer.length);
398 break;
399
400 case ACPI_EXD_PACKAGE:
401
402 /* Dump the package contents */
403
404 acpi_os_printf("\nPackage Contents:\n");
405 acpi_ex_dump_package_obj(obj_desc, 0, 0);
406 break;
407
408 case ACPI_EXD_FIELD:
409
410 acpi_ex_dump_object(obj_desc,
411 acpi_ex_dump_field_common);
412 break;
413
414 case ACPI_EXD_REFERENCE:
415
416 acpi_ex_out_string("Class Name",
417 (char *)
418 acpi_ut_get_reference_name
419 (obj_desc));
420 acpi_ex_dump_reference_obj(obj_desc);
421 break;
422
423 default:
424 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
425 info->opcode);
426 return;
427 }
428
429 info++;
430 count--;
431 }
432}
433
434/*******************************************************************************
435 *
436 * FUNCTION: acpi_ex_dump_operand
437 *
438 * PARAMETERS: *obj_desc - Pointer to entry to be dumped
439 * Depth - Current nesting depth
440 *
441 * RETURN: None
442 *
443 * DESCRIPTION: Dump an operand object
444 *
445 ******************************************************************************/
446
447void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
448{
449 u32 length;
450 u32 index;
451
452 ACPI_FUNCTION_NAME(ex_dump_operand)
453
454 if (!((ACPI_LV_EXEC & acpi_dbg_level)
455 && (_COMPONENT & acpi_dbg_layer))) {
456 return;
457 }
458
459 if (!obj_desc) {
460
461 /* This could be a null element of a package */
462
463 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Null Object Descriptor\n"));
464 return;
465 }
466
467 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_NAMED) {
468 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%p Namespace Node: ",
469 obj_desc));
470 ACPI_DUMP_ENTRY(obj_desc, ACPI_LV_EXEC);
471 return;
472 }
473
474 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) {
475 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
476 "%p is not a node or operand object: [%s]\n",
477 obj_desc,
478 acpi_ut_get_descriptor_name(obj_desc)));
479 ACPI_DUMP_BUFFER(obj_desc, sizeof(union acpi_operand_object));
480 return;
481 }
482
483 /* obj_desc is a valid object */
484
485 if (depth > 0) {
486 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%*s[%u] %p ",
487 depth, " ", depth, obj_desc));
488 } else {
489 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%p ", obj_desc));
490 }
491
492 /* Decode object type */
493
494 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
495 case ACPI_TYPE_LOCAL_REFERENCE:
496
497 acpi_os_printf("Reference: [%s] ",
498 acpi_ut_get_reference_name(obj_desc));
499
500 switch (obj_desc->reference.class) {
501 case ACPI_REFCLASS_DEBUG:
502
503 acpi_os_printf("\n");
504 break;
505
506 case ACPI_REFCLASS_INDEX:
507
508 acpi_os_printf("%p\n", obj_desc->reference.object);
509 break;
510
511 case ACPI_REFCLASS_TABLE:
512
513 acpi_os_printf("Table Index %X\n",
514 obj_desc->reference.value);
515 break;
516
517 case ACPI_REFCLASS_REFOF:
518
519 acpi_os_printf("%p [%s]\n", obj_desc->reference.object,
520 acpi_ut_get_type_name(((union
521 acpi_operand_object
522 *)
523 obj_desc->
524 reference.
525 object)->common.
526 type));
527 break;
528
529 case ACPI_REFCLASS_ARG:
530
531 acpi_os_printf("%X", obj_desc->reference.value);
532
533 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
534
535 /* Value is an Integer */
536
537 acpi_os_printf(" value is [%8.8X%8.8x]",
538 ACPI_FORMAT_UINT64(obj_desc->
539 integer.
540 value));
541 }
542
543 acpi_os_printf("\n");
544 break;
545
546 case ACPI_REFCLASS_LOCAL:
547
548 acpi_os_printf("%X", obj_desc->reference.value);
549
550 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
551
552 /* Value is an Integer */
553
554 acpi_os_printf(" value is [%8.8X%8.8x]",
555 ACPI_FORMAT_UINT64(obj_desc->
556 integer.
557 value));
558 }
559
560 acpi_os_printf("\n");
561 break;
562
563 case ACPI_REFCLASS_NAME:
564
565 acpi_os_printf("- [%4.4s]\n",
566 obj_desc->reference.node->name.ascii);
567 break;
568
569 default: /* Unknown reference class */
570
571 acpi_os_printf("%2.2X\n", obj_desc->reference.class);
572 break;
573 }
574 break;
575
576 case ACPI_TYPE_BUFFER:
577
578 acpi_os_printf("Buffer length %.2X @ %p\n",
579 obj_desc->buffer.length,
580 obj_desc->buffer.pointer);
581
582 /* Debug only -- dump the buffer contents */
583
584 if (obj_desc->buffer.pointer) {
585 length = obj_desc->buffer.length;
586 if (length > 128) {
587 length = 128;
588 }
589
590 acpi_os_printf
591 ("Buffer Contents: (displaying length 0x%.2X)\n",
592 length);
593 ACPI_DUMP_BUFFER(obj_desc->buffer.pointer, length);
594 }
595 break;
596
597 case ACPI_TYPE_INTEGER:
598
599 acpi_os_printf("Integer %8.8X%8.8X\n",
600 ACPI_FORMAT_UINT64(obj_desc->integer.value));
601 break;
602
603 case ACPI_TYPE_PACKAGE:
604
605 acpi_os_printf("Package [Len %X] ElementArray %p\n",
606 obj_desc->package.count,
607 obj_desc->package.elements);
608
609 /*
610 * If elements exist, package element pointer is valid,
611 * and debug_level exceeds 1, dump package's elements.
612 */
613 if (obj_desc->package.count &&
614 obj_desc->package.elements && acpi_dbg_level > 1) {
615 for (index = 0; index < obj_desc->package.count;
616 index++) {
617 acpi_ex_dump_operand(obj_desc->package.
618 elements[index],
619 depth + 1);
620 }
621 }
622 break;
623
624 case ACPI_TYPE_REGION:
625
626 acpi_os_printf("Region %s (%X)",
627 acpi_ut_get_region_name(obj_desc->region.
628 space_id),
629 obj_desc->region.space_id);
630
631 /*
632 * If the address and length have not been evaluated,
633 * don't print them.
634 */
635 if (!(obj_desc->region.flags & AOPOBJ_DATA_VALID)) {
636 acpi_os_printf("\n");
637 } else {
638 acpi_os_printf(" base %8.8X%8.8X Length %X\n",
639 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.
640 address),
641 obj_desc->region.length);
642 }
643 break;
644
645 case ACPI_TYPE_STRING:
646
647 acpi_os_printf("String length %X @ %p ",
648 obj_desc->string.length,
649 obj_desc->string.pointer);
650
651 acpi_ut_print_string(obj_desc->string.pointer, ACPI_UINT8_MAX);
652 acpi_os_printf("\n");
653 break;
654
655 case ACPI_TYPE_LOCAL_BANK_FIELD:
656
657 acpi_os_printf("BankField\n");
658 break;
659
660 case ACPI_TYPE_LOCAL_REGION_FIELD:
661
662 acpi_os_printf
663 ("RegionField: Bits=%X AccWidth=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n",
664 obj_desc->field.bit_length,
665 obj_desc->field.access_byte_width,
666 obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK,
667 obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK,
668 obj_desc->field.base_byte_offset,
669 obj_desc->field.start_field_bit_offset);
670
671 acpi_ex_dump_operand(obj_desc->field.region_obj, depth + 1);
672 break;
673
674 case ACPI_TYPE_LOCAL_INDEX_FIELD:
675
676 acpi_os_printf("IndexField\n");
677 break;
678
679 case ACPI_TYPE_BUFFER_FIELD:
680
681 acpi_os_printf("BufferField: %X bits at byte %X bit %X of\n",
682 obj_desc->buffer_field.bit_length,
683 obj_desc->buffer_field.base_byte_offset,
684 obj_desc->buffer_field.start_field_bit_offset);
685
686 if (!obj_desc->buffer_field.buffer_obj) {
687 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "*NULL*\n"));
688 } else
689 if (ACPI_GET_OBJECT_TYPE(obj_desc->buffer_field.buffer_obj)
690 != ACPI_TYPE_BUFFER) {
691 acpi_os_printf("*not a Buffer*\n");
692 } else {
693 acpi_ex_dump_operand(obj_desc->buffer_field.buffer_obj,
694 depth + 1);
695 }
696 break;
697
698 case ACPI_TYPE_EVENT:
699
700 acpi_os_printf("Event\n");
701 break;
702
703 case ACPI_TYPE_METHOD:
704
705 acpi_os_printf("Method(%X) @ %p:%X\n",
706 obj_desc->method.param_count,
707 obj_desc->method.aml_start,
708 obj_desc->method.aml_length);
709 break;
710
711 case ACPI_TYPE_MUTEX:
712
713 acpi_os_printf("Mutex\n");
714 break;
715
716 case ACPI_TYPE_DEVICE:
717
718 acpi_os_printf("Device\n");
719 break;
720
721 case ACPI_TYPE_POWER:
722
723 acpi_os_printf("Power\n");
724 break;
725
726 case ACPI_TYPE_PROCESSOR:
727
728 acpi_os_printf("Processor\n");
729 break;
730
731 case ACPI_TYPE_THERMAL:
732
733 acpi_os_printf("Thermal\n");
734 break;
735
736 default:
737 /* Unknown Type */
738
739 acpi_os_printf("Unknown Type %X\n",
740 ACPI_GET_OBJECT_TYPE(obj_desc));
741 break;
742 }
743
744 return;
745}
746
747/*******************************************************************************
748 *
749 * FUNCTION: acpi_ex_dump_operands
750 *
751 * PARAMETERS: Operands - A list of Operand objects
752 * opcode_name - AML opcode name
753 * num_operands - Operand count for this opcode
754 *
755 * DESCRIPTION: Dump the operands associated with the opcode
756 *
757 ******************************************************************************/
758
759void
760acpi_ex_dump_operands(union acpi_operand_object **operands,
761 const char *opcode_name, u32 num_operands)
762{
763 ACPI_FUNCTION_NAME(ex_dump_operands);
764
765 if (!opcode_name) {
766 opcode_name = "UNKNOWN";
767 }
768
769 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
770 "**** Start operand dump for opcode [%s], %d operands\n",
771 opcode_name, num_operands));
772
773 if (num_operands == 0) {
774 num_operands = 1;
775 }
776
777 /* Dump the individual operands */
778
779 while (num_operands) {
780 acpi_ex_dump_operand(*operands, 0);
781 operands++;
782 num_operands--;
783 }
784
785 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
786 "**** End operand dump for [%s]\n", opcode_name));
787 return;
788}
789
790/*******************************************************************************
791 *
792 * FUNCTION: acpi_ex_out* functions
793 *
794 * PARAMETERS: Title - Descriptive text
795 * Value - Value to be displayed
796 *
797 * DESCRIPTION: Object dump output formatting functions. These functions
798 * reduce the number of format strings required and keeps them
799 * all in one place for easy modification.
800 *
801 ******************************************************************************/
802
803static void acpi_ex_out_string(char *title, char *value)
804{
805 acpi_os_printf("%20s : %s\n", title, value);
806}
807
808static void acpi_ex_out_pointer(char *title, void *value)
809{
810 acpi_os_printf("%20s : %p\n", title, value);
811}
812
813/*******************************************************************************
814 *
815 * FUNCTION: acpi_ex_dump_namespace_node
816 *
817 * PARAMETERS: Node - Descriptor to dump
818 * Flags - Force display if TRUE
819 *
820 * DESCRIPTION: Dumps the members of the given.Node
821 *
822 ******************************************************************************/
823
824void acpi_ex_dump_namespace_node(struct acpi_namespace_node *node, u32 flags)
825{
826
827 ACPI_FUNCTION_ENTRY();
828
829 if (!flags) {
830 if (!((ACPI_LV_OBJECTS & acpi_dbg_level)
831 && (_COMPONENT & acpi_dbg_layer))) {
832 return;
833 }
834 }
835
836 acpi_os_printf("%20s : %4.4s\n", "Name", acpi_ut_get_node_name(node));
837 acpi_ex_out_string("Type", acpi_ut_get_type_name(node->type));
838 acpi_ex_out_pointer("Attached Object",
839 acpi_ns_get_attached_object(node));
840 acpi_ex_out_pointer("Parent", acpi_ns_get_parent_node(node));
841
842 acpi_ex_dump_object(ACPI_CAST_PTR(union acpi_operand_object, node),
843 acpi_ex_dump_node);
844}
845
846/*******************************************************************************
847 *
848 * FUNCTION: acpi_ex_dump_reference_obj
849 *
850 * PARAMETERS: Object - Descriptor to dump
851 *
852 * DESCRIPTION: Dumps a reference object
853 *
854 ******************************************************************************/
855
856static void acpi_ex_dump_reference_obj(union acpi_operand_object *obj_desc)
857{
858 struct acpi_buffer ret_buf;
859 acpi_status status;
860
861 ret_buf.length = ACPI_ALLOCATE_LOCAL_BUFFER;
862
863 if (obj_desc->reference.class == ACPI_REFCLASS_NAME) {
864 acpi_os_printf(" %p ", obj_desc->reference.node);
865
866 status =
867 acpi_ns_handle_to_pathname(obj_desc->reference.node,
868 &ret_buf);
869 if (ACPI_FAILURE(status)) {
870 acpi_os_printf(" Could not convert name to pathname\n");
871 } else {
872 acpi_os_printf("%s\n", (char *)ret_buf.pointer);
873 ACPI_FREE(ret_buf.pointer);
874 }
875 } else if (obj_desc->reference.object) {
876 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
877 ACPI_DESC_TYPE_OPERAND) {
878 acpi_os_printf(" Target: %p",
879 obj_desc->reference.object);
880 if (obj_desc->reference.class == ACPI_REFCLASS_TABLE) {
881 acpi_os_printf(" Table Index: %X\n",
882 obj_desc->reference.value);
883 } else {
884 acpi_os_printf(" Target: %p [%s]\n",
885 obj_desc->reference.object,
886 acpi_ut_get_type_name(((union
887 acpi_operand_object
888 *)
889 obj_desc->
890 reference.
891 object)->
892 common.
893 type));
894 }
895 } else {
896 acpi_os_printf(" Target: %p\n",
897 obj_desc->reference.object);
898 }
899 }
900}
901
902/*******************************************************************************
903 *
904 * FUNCTION: acpi_ex_dump_package_obj
905 *
906 * PARAMETERS: obj_desc - Descriptor to dump
907 * Level - Indentation Level
908 * Index - Package index for this object
909 *
910 * DESCRIPTION: Dumps the elements of the package
911 *
912 ******************************************************************************/
913
914static void
915acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
916 u32 level, u32 index)
917{
918 u32 i;
919
920 /* Indentation and index output */
921
922 if (level > 0) {
923 for (i = 0; i < level; i++) {
924 acpi_os_printf(" ");
925 }
926
927 acpi_os_printf("[%.2d] ", index);
928 }
929
930 acpi_os_printf("%p ", obj_desc);
931
932 /* Null package elements are allowed */
933
934 if (!obj_desc) {
935 acpi_os_printf("[Null Object]\n");
936 return;
937 }
938
939 /* Packages may only contain a few object types */
940
941 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
942 case ACPI_TYPE_INTEGER:
943
944 acpi_os_printf("[Integer] = %8.8X%8.8X\n",
945 ACPI_FORMAT_UINT64(obj_desc->integer.value));
946 break;
947
948 case ACPI_TYPE_STRING:
949
950 acpi_os_printf("[String] Value: ");
951 for (i = 0; i < obj_desc->string.length; i++) {
952 acpi_os_printf("%c", obj_desc->string.pointer[i]);
953 }
954 acpi_os_printf("\n");
955 break;
956
957 case ACPI_TYPE_BUFFER:
958
959 acpi_os_printf("[Buffer] Length %.2X = ",
960 obj_desc->buffer.length);
961 if (obj_desc->buffer.length) {
962 acpi_ut_dump_buffer(ACPI_CAST_PTR
963 (u8, obj_desc->buffer.pointer),
964 obj_desc->buffer.length,
965 DB_DWORD_DISPLAY, _COMPONENT);
966 } else {
967 acpi_os_printf("\n");
968 }
969 break;
970
971 case ACPI_TYPE_PACKAGE:
972
973 acpi_os_printf("[Package] Contains %d Elements:\n",
974 obj_desc->package.count);
975
976 for (i = 0; i < obj_desc->package.count; i++) {
977 acpi_ex_dump_package_obj(obj_desc->package.elements[i],
978 level + 1, i);
979 }
980 break;
981
982 case ACPI_TYPE_LOCAL_REFERENCE:
983
984 acpi_os_printf("[Object Reference] Type [%s] %2.2X",
985 acpi_ut_get_reference_name(obj_desc),
986 obj_desc->reference.class);
987 acpi_ex_dump_reference_obj(obj_desc);
988 break;
989
990 default:
991
992 acpi_os_printf("[Unknown Type] %X\n",
993 ACPI_GET_OBJECT_TYPE(obj_desc));
994 break;
995 }
996}
997
998/*******************************************************************************
999 *
1000 * FUNCTION: acpi_ex_dump_object_descriptor
1001 *
1002 * PARAMETERS: obj_desc - Descriptor to dump
1003 * Flags - Force display if TRUE
1004 *
1005 * DESCRIPTION: Dumps the members of the object descriptor given.
1006 *
1007 ******************************************************************************/
1008
1009void
1010acpi_ex_dump_object_descriptor(union acpi_operand_object *obj_desc, u32 flags)
1011{
1012 ACPI_FUNCTION_TRACE(ex_dump_object_descriptor);
1013
1014 if (!obj_desc) {
1015 return_VOID;
1016 }
1017
1018 if (!flags) {
1019 if (!((ACPI_LV_OBJECTS & acpi_dbg_level)
1020 && (_COMPONENT & acpi_dbg_layer))) {
1021 return_VOID;
1022 }
1023 }
1024
1025 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_NAMED) {
1026 acpi_ex_dump_namespace_node((struct acpi_namespace_node *)
1027 obj_desc, flags);
1028
1029 acpi_os_printf("\nAttached Object (%p):\n",
1030 ((struct acpi_namespace_node *)obj_desc)->
1031 object);
1032
1033 acpi_ex_dump_object_descriptor(((struct acpi_namespace_node *)
1034 obj_desc)->object, flags);
1035 return_VOID;
1036 }
1037
1038 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) {
1039 acpi_os_printf
1040 ("ExDumpObjectDescriptor: %p is not an ACPI operand object: [%s]\n",
1041 obj_desc, acpi_ut_get_descriptor_name(obj_desc));
1042 return_VOID;
1043 }
1044
1045 if (obj_desc->common.type > ACPI_TYPE_NS_NODE_MAX) {
1046 return_VOID;
1047 }
1048
1049 /* Common Fields */
1050
1051 acpi_ex_dump_object(obj_desc, acpi_ex_dump_common);
1052
1053 /* Object-specific fields */
1054
1055 acpi_ex_dump_object(obj_desc, acpi_ex_dump_info[obj_desc->common.type]);
1056 return_VOID;
1057}
1058
1059#endif
diff --git a/drivers/acpi/executer/exfield.c b/drivers/acpi/executer/exfield.c
deleted file mode 100644
index 3e440d84226a..000000000000
--- a/drivers/acpi/executer/exfield.c
+++ /dev/null
@@ -1,339 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: exfield - ACPI AML (p-code) execution - field manipulation
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acdispat.h>
46#include <acpi/acinterp.h>
47
48#define _COMPONENT ACPI_EXECUTER
49ACPI_MODULE_NAME("exfield")
50
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_ex_read_data_from_field
54 *
55 * PARAMETERS: walk_state - Current execution state
56 * obj_desc - The named field
57 * ret_buffer_desc - Where the return data object is stored
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Read from a named field. Returns either an Integer or a
62 * Buffer, depending on the size of the field.
63 *
64 ******************************************************************************/
65acpi_status
66acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
67 union acpi_operand_object *obj_desc,
68 union acpi_operand_object **ret_buffer_desc)
69{
70 acpi_status status;
71 union acpi_operand_object *buffer_desc;
72 acpi_size length;
73 void *buffer;
74
75 ACPI_FUNCTION_TRACE_PTR(ex_read_data_from_field, obj_desc);
76
77 /* Parameter validation */
78
79 if (!obj_desc) {
80 return_ACPI_STATUS(AE_AML_NO_OPERAND);
81 }
82 if (!ret_buffer_desc) {
83 return_ACPI_STATUS(AE_BAD_PARAMETER);
84 }
85
86 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
87 /*
88 * If the buffer_field arguments have not been previously evaluated,
89 * evaluate them now and save the results.
90 */
91 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
92 status = acpi_ds_get_buffer_field_arguments(obj_desc);
93 if (ACPI_FAILURE(status)) {
94 return_ACPI_STATUS(status);
95 }
96 }
97 } else
98 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD)
99 && (obj_desc->field.region_obj->region.space_id ==
100 ACPI_ADR_SPACE_SMBUS)) {
101 /*
102 * This is an SMBus read. We must create a buffer to hold the data
103 * and directly access the region handler.
104 */
105 buffer_desc =
106 acpi_ut_create_buffer_object(ACPI_SMBUS_BUFFER_SIZE);
107 if (!buffer_desc) {
108 return_ACPI_STATUS(AE_NO_MEMORY);
109 }
110
111 /* Lock entire transaction if requested */
112
113 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
114
115 /*
116 * Perform the read.
117 * Note: Smbus protocol value is passed in upper 16-bits of Function
118 */
119 status = acpi_ex_access_region(obj_desc, 0,
120 ACPI_CAST_PTR(acpi_integer,
121 buffer_desc->
122 buffer.pointer),
123 ACPI_READ | (obj_desc->field.
124 attribute << 16));
125 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
126 goto exit;
127 }
128
129 /*
130 * Allocate a buffer for the contents of the field.
131 *
132 * If the field is larger than the size of an acpi_integer, create
133 * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
134 * the use of arithmetic operators on the returned value if the
135 * field size is equal or smaller than an Integer.
136 *
137 * Note: Field.length is in bits.
138 */
139 length =
140 (acpi_size) ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->field.bit_length);
141 if (length > acpi_gbl_integer_byte_width) {
142
143 /* Field is too large for an Integer, create a Buffer instead */
144
145 buffer_desc = acpi_ut_create_buffer_object(length);
146 if (!buffer_desc) {
147 return_ACPI_STATUS(AE_NO_MEMORY);
148 }
149 buffer = buffer_desc->buffer.pointer;
150 } else {
151 /* Field will fit within an Integer (normal case) */
152
153 buffer_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
154 if (!buffer_desc) {
155 return_ACPI_STATUS(AE_NO_MEMORY);
156 }
157
158 length = acpi_gbl_integer_byte_width;
159 buffer_desc->integer.value = 0;
160 buffer = &buffer_desc->integer.value;
161 }
162
163 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
164 "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
165 obj_desc, ACPI_GET_OBJECT_TYPE(obj_desc), buffer,
166 (u32) length));
167 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
168 "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
169 obj_desc->common_field.bit_length,
170 obj_desc->common_field.start_field_bit_offset,
171 obj_desc->common_field.base_byte_offset));
172
173 /* Lock entire transaction if requested */
174
175 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
176
177 /* Read from the field */
178
179 status = acpi_ex_extract_from_field(obj_desc, buffer, (u32) length);
180 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
181
182 exit:
183 if (ACPI_FAILURE(status)) {
184 acpi_ut_remove_reference(buffer_desc);
185 } else {
186 *ret_buffer_desc = buffer_desc;
187 }
188
189 return_ACPI_STATUS(status);
190}
191
192/*******************************************************************************
193 *
194 * FUNCTION: acpi_ex_write_data_to_field
195 *
196 * PARAMETERS: source_desc - Contains data to write
197 * obj_desc - The named field
198 * result_desc - Where the return value is returned, if any
199 *
200 * RETURN: Status
201 *
202 * DESCRIPTION: Write to a named field
203 *
204 ******************************************************************************/
205
206acpi_status
207acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
208 union acpi_operand_object *obj_desc,
209 union acpi_operand_object **result_desc)
210{
211 acpi_status status;
212 u32 length;
213 void *buffer;
214 union acpi_operand_object *buffer_desc;
215
216 ACPI_FUNCTION_TRACE_PTR(ex_write_data_to_field, obj_desc);
217
218 /* Parameter validation */
219
220 if (!source_desc || !obj_desc) {
221 return_ACPI_STATUS(AE_AML_NO_OPERAND);
222 }
223
224 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
225 /*
226 * If the buffer_field arguments have not been previously evaluated,
227 * evaluate them now and save the results.
228 */
229 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
230 status = acpi_ds_get_buffer_field_arguments(obj_desc);
231 if (ACPI_FAILURE(status)) {
232 return_ACPI_STATUS(status);
233 }
234 }
235 } else
236 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD)
237 && (obj_desc->field.region_obj->region.space_id ==
238 ACPI_ADR_SPACE_SMBUS)) {
239 /*
240 * This is an SMBus write. We will bypass the entire field mechanism
241 * and handoff the buffer directly to the handler.
242 *
243 * Source must be a buffer of sufficient size (ACPI_SMBUS_BUFFER_SIZE).
244 */
245 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
246 ACPI_ERROR((AE_INFO,
247 "SMBus write requires Buffer, found type %s",
248 acpi_ut_get_object_type_name(source_desc)));
249
250 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
251 }
252
253 if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) {
254 ACPI_ERROR((AE_INFO,
255 "SMBus write requires Buffer of length %X, found length %X",
256 ACPI_SMBUS_BUFFER_SIZE,
257 source_desc->buffer.length));
258
259 return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
260 }
261
262 buffer_desc =
263 acpi_ut_create_buffer_object(ACPI_SMBUS_BUFFER_SIZE);
264 if (!buffer_desc) {
265 return_ACPI_STATUS(AE_NO_MEMORY);
266 }
267
268 buffer = buffer_desc->buffer.pointer;
269 ACPI_MEMCPY(buffer, source_desc->buffer.pointer,
270 ACPI_SMBUS_BUFFER_SIZE);
271
272 /* Lock entire transaction if requested */
273
274 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
275
276 /*
277 * Perform the write (returns status and perhaps data in the
278 * same buffer)
279 * Note: SMBus protocol type is passed in upper 16-bits of Function.
280 */
281 status = acpi_ex_access_region(obj_desc, 0,
282 (acpi_integer *) buffer,
283 ACPI_WRITE | (obj_desc->field.
284 attribute << 16));
285 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
286
287 *result_desc = buffer_desc;
288 return_ACPI_STATUS(status);
289 }
290
291 /* Get a pointer to the data to be written */
292
293 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
294 case ACPI_TYPE_INTEGER:
295 buffer = &source_desc->integer.value;
296 length = sizeof(source_desc->integer.value);
297 break;
298
299 case ACPI_TYPE_BUFFER:
300 buffer = source_desc->buffer.pointer;
301 length = source_desc->buffer.length;
302 break;
303
304 case ACPI_TYPE_STRING:
305 buffer = source_desc->string.pointer;
306 length = source_desc->string.length;
307 break;
308
309 default:
310 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
311 }
312
313 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
314 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
315 source_desc,
316 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE
317 (source_desc)),
318 ACPI_GET_OBJECT_TYPE(source_desc), buffer, length));
319
320 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
321 "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
322 obj_desc,
323 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE(obj_desc)),
324 ACPI_GET_OBJECT_TYPE(obj_desc),
325 obj_desc->common_field.bit_length,
326 obj_desc->common_field.start_field_bit_offset,
327 obj_desc->common_field.base_byte_offset));
328
329 /* Lock entire transaction if requested */
330
331 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
332
333 /* Write to the field */
334
335 status = acpi_ex_insert_into_field(obj_desc, buffer, length);
336 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
337
338 return_ACPI_STATUS(status);
339}
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
deleted file mode 100644
index 9ff9d1f4615d..000000000000
--- a/drivers/acpi/executer/exfldio.c
+++ /dev/null
@@ -1,957 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: exfldio - Aml Field I/O
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acinterp.h>
46#include <acpi/amlcode.h>
47#include <acpi/acevents.h>
48#include <acpi/acdispat.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exfldio")
52
53/* Local prototypes */
54static acpi_status
55acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
56 u32 field_datum_byte_offset,
57 acpi_integer * value, u32 read_write);
58
59static u8
60acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
61 acpi_integer value);
62
63static acpi_status
64acpi_ex_setup_region(union acpi_operand_object *obj_desc,
65 u32 field_datum_byte_offset);
66
67/*******************************************************************************
68 *
69 * FUNCTION: acpi_ex_setup_region
70 *
71 * PARAMETERS: obj_desc - Field to be read or written
72 * field_datum_byte_offset - Byte offset of this datum within the
73 * parent field
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: Common processing for acpi_ex_extract_from_field and
78 * acpi_ex_insert_into_field. Initialize the Region if necessary and
79 * validate the request.
80 *
81 ******************************************************************************/
82
83static acpi_status
84acpi_ex_setup_region(union acpi_operand_object *obj_desc,
85 u32 field_datum_byte_offset)
86{
87 acpi_status status = AE_OK;
88 union acpi_operand_object *rgn_desc;
89
90 ACPI_FUNCTION_TRACE_U32(ex_setup_region, field_datum_byte_offset);
91
92 rgn_desc = obj_desc->common_field.region_obj;
93
94 /* We must have a valid region */
95
96 if (ACPI_GET_OBJECT_TYPE(rgn_desc) != ACPI_TYPE_REGION) {
97 ACPI_ERROR((AE_INFO, "Needed Region, found type %X (%s)",
98 ACPI_GET_OBJECT_TYPE(rgn_desc),
99 acpi_ut_get_object_type_name(rgn_desc)));
100
101 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
102 }
103
104 /*
105 * If the Region Address and Length have not been previously evaluated,
106 * evaluate them now and save the results.
107 */
108 if (!(rgn_desc->common.flags & AOPOBJ_DATA_VALID)) {
109 status = acpi_ds_get_region_arguments(rgn_desc);
110 if (ACPI_FAILURE(status)) {
111 return_ACPI_STATUS(status);
112 }
113 }
114
115 /* Exit if Address/Length have been disallowed by the host OS */
116
117 if (rgn_desc->common.flags & AOPOBJ_INVALID) {
118 return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
119 }
120
121 /*
122 * Exit now for SMBus address space, it has a non-linear address space
123 * and the request cannot be directly validated
124 */
125 if (rgn_desc->region.space_id == ACPI_ADR_SPACE_SMBUS) {
126
127 /* SMBus has a non-linear address space */
128
129 return_ACPI_STATUS(AE_OK);
130 }
131#ifdef ACPI_UNDER_DEVELOPMENT
132 /*
133 * If the Field access is any_acc, we can now compute the optimal
134 * access (because we know know the length of the parent region)
135 */
136 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
137 if (ACPI_FAILURE(status)) {
138 return_ACPI_STATUS(status);
139 }
140 }
141#endif
142
143 /*
144 * Validate the request. The entire request from the byte offset for a
145 * length of one field datum (access width) must fit within the region.
146 * (Region length is specified in bytes)
147 */
148 if (rgn_desc->region.length <
149 (obj_desc->common_field.base_byte_offset +
150 field_datum_byte_offset +
151 obj_desc->common_field.access_byte_width)) {
152 if (acpi_gbl_enable_interpreter_slack) {
153 /*
154 * Slack mode only: We will go ahead and allow access to this
155 * field if it is within the region length rounded up to the next
156 * access width boundary. acpi_size cast for 64-bit compile.
157 */
158 if (ACPI_ROUND_UP(rgn_desc->region.length,
159 obj_desc->common_field.
160 access_byte_width) >=
161 ((acpi_size) obj_desc->common_field.
162 base_byte_offset +
163 obj_desc->common_field.access_byte_width +
164 field_datum_byte_offset)) {
165 return_ACPI_STATUS(AE_OK);
166 }
167 }
168
169 if (rgn_desc->region.length <
170 obj_desc->common_field.access_byte_width) {
171 /*
172 * This is the case where the access_type (acc_word, etc.) is wider
173 * than the region itself. For example, a region of length one
174 * byte, and a field with Dword access specified.
175 */
176 ACPI_ERROR((AE_INFO,
177 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)",
178 acpi_ut_get_node_name(obj_desc->
179 common_field.node),
180 obj_desc->common_field.access_byte_width,
181 acpi_ut_get_node_name(rgn_desc->region.
182 node),
183 rgn_desc->region.length));
184 }
185
186 /*
187 * Offset rounded up to next multiple of field width
188 * exceeds region length, indicate an error
189 */
190 ACPI_ERROR((AE_INFO,
191 "Field [%4.4s] Base+Offset+Width %X+%X+%X is beyond end of region [%4.4s] (length %X)",
192 acpi_ut_get_node_name(obj_desc->common_field.node),
193 obj_desc->common_field.base_byte_offset,
194 field_datum_byte_offset,
195 obj_desc->common_field.access_byte_width,
196 acpi_ut_get_node_name(rgn_desc->region.node),
197 rgn_desc->region.length));
198
199 return_ACPI_STATUS(AE_AML_REGION_LIMIT);
200 }
201
202 return_ACPI_STATUS(AE_OK);
203}
204
205/*******************************************************************************
206 *
207 * FUNCTION: acpi_ex_access_region
208 *
209 * PARAMETERS: obj_desc - Field to be read
210 * field_datum_byte_offset - Byte offset of this datum within the
211 * parent field
212 * Value - Where to store value (must at least
213 * the size of acpi_integer)
214 * Function - Read or Write flag plus other region-
215 * dependent flags
216 *
217 * RETURN: Status
218 *
219 * DESCRIPTION: Read or Write a single field datum to an Operation Region.
220 *
221 ******************************************************************************/
222
223acpi_status
224acpi_ex_access_region(union acpi_operand_object *obj_desc,
225 u32 field_datum_byte_offset,
226 acpi_integer * value, u32 function)
227{
228 acpi_status status;
229 union acpi_operand_object *rgn_desc;
230 acpi_physical_address address;
231
232 ACPI_FUNCTION_TRACE(ex_access_region);
233
234 /*
235 * Ensure that the region operands are fully evaluated and verify
236 * the validity of the request
237 */
238 status = acpi_ex_setup_region(obj_desc, field_datum_byte_offset);
239 if (ACPI_FAILURE(status)) {
240 return_ACPI_STATUS(status);
241 }
242
243 /*
244 * The physical address of this field datum is:
245 *
246 * 1) The base of the region, plus
247 * 2) The base offset of the field, plus
248 * 3) The current offset into the field
249 */
250 rgn_desc = obj_desc->common_field.region_obj;
251 address = rgn_desc->region.address +
252 obj_desc->common_field.base_byte_offset + field_datum_byte_offset;
253
254 if ((function & ACPI_IO_MASK) == ACPI_READ) {
255 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[READ]"));
256 } else {
257 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[WRITE]"));
258 }
259
260 ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD,
261 " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %p\n",
262 acpi_ut_get_region_name(rgn_desc->region.
263 space_id),
264 rgn_desc->region.space_id,
265 obj_desc->common_field.access_byte_width,
266 obj_desc->common_field.base_byte_offset,
267 field_datum_byte_offset, ACPI_CAST_PTR(void,
268 address)));
269
270 /* Invoke the appropriate address_space/op_region handler */
271
272 status = acpi_ev_address_space_dispatch(rgn_desc, function,
273 address,
274 ACPI_MUL_8(obj_desc->
275 common_field.
276 access_byte_width),
277 value);
278
279 if (ACPI_FAILURE(status)) {
280 if (status == AE_NOT_IMPLEMENTED) {
281 ACPI_ERROR((AE_INFO,
282 "Region %s(%X) not implemented",
283 acpi_ut_get_region_name(rgn_desc->region.
284 space_id),
285 rgn_desc->region.space_id));
286 } else if (status == AE_NOT_EXIST) {
287 ACPI_ERROR((AE_INFO,
288 "Region %s(%X) has no handler",
289 acpi_ut_get_region_name(rgn_desc->region.
290 space_id),
291 rgn_desc->region.space_id));
292 }
293 }
294
295 return_ACPI_STATUS(status);
296}
297
298/*******************************************************************************
299 *
300 * FUNCTION: acpi_ex_register_overflow
301 *
302 * PARAMETERS: obj_desc - Register(Field) to be written
303 * Value - Value to be stored
304 *
305 * RETURN: TRUE if value overflows the field, FALSE otherwise
306 *
307 * DESCRIPTION: Check if a value is out of range of the field being written.
308 * Used to check if the values written to Index and Bank registers
309 * are out of range. Normally, the value is simply truncated
310 * to fit the field, but this case is most likely a serious
311 * coding error in the ASL.
312 *
313 ******************************************************************************/
314
315static u8
316acpi_ex_register_overflow(union acpi_operand_object *obj_desc,
317 acpi_integer value)
318{
319
320 if (obj_desc->common_field.bit_length >= ACPI_INTEGER_BIT_SIZE) {
321 /*
322 * The field is large enough to hold the maximum integer, so we can
323 * never overflow it.
324 */
325 return (FALSE);
326 }
327
328 if (value >= ((acpi_integer) 1 << obj_desc->common_field.bit_length)) {
329 /*
330 * The Value is larger than the maximum value that can fit into
331 * the register.
332 */
333 return (TRUE);
334 }
335
336 /* The Value will fit into the field with no truncation */
337
338 return (FALSE);
339}
340
341/*******************************************************************************
342 *
343 * FUNCTION: acpi_ex_field_datum_io
344 *
345 * PARAMETERS: obj_desc - Field to be read
346 * field_datum_byte_offset - Byte offset of this datum within the
347 * parent field
348 * Value - Where to store value (must be 64 bits)
349 * read_write - Read or Write flag
350 *
351 * RETURN: Status
352 *
353 * DESCRIPTION: Read or Write a single datum of a field. The field_type is
354 * demultiplexed here to handle the different types of fields
355 * (buffer_field, region_field, index_field, bank_field)
356 *
357 ******************************************************************************/
358
359static acpi_status
360acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
361 u32 field_datum_byte_offset,
362 acpi_integer * value, u32 read_write)
363{
364 acpi_status status;
365 acpi_integer local_value;
366
367 ACPI_FUNCTION_TRACE_U32(ex_field_datum_io, field_datum_byte_offset);
368
369 if (read_write == ACPI_READ) {
370 if (!value) {
371 local_value = 0;
372
373 /* To support reads without saving return value */
374 value = &local_value;
375 }
376
377 /* Clear the entire return buffer first, [Very Important!] */
378
379 *value = 0;
380 }
381
382 /*
383 * The four types of fields are:
384 *
385 * buffer_field - Read/write from/to a Buffer
386 * region_field - Read/write from/to a Operation Region.
387 * bank_field - Write to a Bank Register, then read/write from/to an
388 * operation_region
389 * index_field - Write to an Index Register, then read/write from/to a
390 * Data Register
391 */
392 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
393 case ACPI_TYPE_BUFFER_FIELD:
394 /*
395 * If the buffer_field arguments have not been previously evaluated,
396 * evaluate them now and save the results.
397 */
398 if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
399 status = acpi_ds_get_buffer_field_arguments(obj_desc);
400 if (ACPI_FAILURE(status)) {
401 return_ACPI_STATUS(status);
402 }
403 }
404
405 if (read_write == ACPI_READ) {
406 /*
407 * Copy the data from the source buffer.
408 * Length is the field width in bytes.
409 */
410 ACPI_MEMCPY(value,
411 (obj_desc->buffer_field.buffer_obj)->buffer.
412 pointer +
413 obj_desc->buffer_field.base_byte_offset +
414 field_datum_byte_offset,
415 obj_desc->common_field.access_byte_width);
416 } else {
417 /*
418 * Copy the data to the target buffer.
419 * Length is the field width in bytes.
420 */
421 ACPI_MEMCPY((obj_desc->buffer_field.buffer_obj)->buffer.
422 pointer +
423 obj_desc->buffer_field.base_byte_offset +
424 field_datum_byte_offset, value,
425 obj_desc->common_field.access_byte_width);
426 }
427
428 status = AE_OK;
429 break;
430
431 case ACPI_TYPE_LOCAL_BANK_FIELD:
432
433 /*
434 * Ensure that the bank_value is not beyond the capacity of
435 * the register
436 */
437 if (acpi_ex_register_overflow(obj_desc->bank_field.bank_obj,
438 (acpi_integer) obj_desc->
439 bank_field.value)) {
440 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
441 }
442
443 /*
444 * For bank_fields, we must write the bank_value to the bank_register
445 * (itself a region_field) before we can access the data.
446 */
447 status =
448 acpi_ex_insert_into_field(obj_desc->bank_field.bank_obj,
449 &obj_desc->bank_field.value,
450 sizeof(obj_desc->bank_field.
451 value));
452 if (ACPI_FAILURE(status)) {
453 return_ACPI_STATUS(status);
454 }
455
456 /*
457 * Now that the Bank has been selected, fall through to the
458 * region_field case and write the datum to the Operation Region
459 */
460
461 /*lint -fallthrough */
462
463 case ACPI_TYPE_LOCAL_REGION_FIELD:
464 /*
465 * For simple region_fields, we just directly access the owning
466 * Operation Region.
467 */
468 status =
469 acpi_ex_access_region(obj_desc, field_datum_byte_offset,
470 value, read_write);
471 break;
472
473 case ACPI_TYPE_LOCAL_INDEX_FIELD:
474
475 /*
476 * Ensure that the index_value is not beyond the capacity of
477 * the register
478 */
479 if (acpi_ex_register_overflow(obj_desc->index_field.index_obj,
480 (acpi_integer) obj_desc->
481 index_field.value)) {
482 return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
483 }
484
485 /* Write the index value to the index_register (itself a region_field) */
486
487 field_datum_byte_offset += obj_desc->index_field.value;
488
489 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
490 "Write to Index Register: Value %8.8X\n",
491 field_datum_byte_offset));
492
493 status =
494 acpi_ex_insert_into_field(obj_desc->index_field.index_obj,
495 &field_datum_byte_offset,
496 sizeof(field_datum_byte_offset));
497 if (ACPI_FAILURE(status)) {
498 return_ACPI_STATUS(status);
499 }
500
501 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
502 "I/O to Data Register: ValuePtr %p\n",
503 value));
504
505 if (read_write == ACPI_READ) {
506
507 /* Read the datum from the data_register */
508
509 status =
510 acpi_ex_extract_from_field(obj_desc->index_field.
511 data_obj, value,
512 sizeof(acpi_integer));
513 } else {
514 /* Write the datum to the data_register */
515
516 status =
517 acpi_ex_insert_into_field(obj_desc->index_field.
518 data_obj, value,
519 sizeof(acpi_integer));
520 }
521 break;
522
523 default:
524
525 ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X",
526 ACPI_GET_OBJECT_TYPE(obj_desc)));
527 status = AE_AML_INTERNAL;
528 break;
529 }
530
531 if (ACPI_SUCCESS(status)) {
532 if (read_write == ACPI_READ) {
533 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
534 "Value Read %8.8X%8.8X, Width %d\n",
535 ACPI_FORMAT_UINT64(*value),
536 obj_desc->common_field.
537 access_byte_width));
538 } else {
539 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
540 "Value Written %8.8X%8.8X, Width %d\n",
541 ACPI_FORMAT_UINT64(*value),
542 obj_desc->common_field.
543 access_byte_width));
544 }
545 }
546
547 return_ACPI_STATUS(status);
548}
549
550/*******************************************************************************
551 *
552 * FUNCTION: acpi_ex_write_with_update_rule
553 *
554 * PARAMETERS: obj_desc - Field to be written
555 * Mask - bitmask within field datum
556 * field_value - Value to write
557 * field_datum_byte_offset - Offset of datum within field
558 *
559 * RETURN: Status
560 *
561 * DESCRIPTION: Apply the field update rule to a field write
562 *
563 ******************************************************************************/
564
565acpi_status
566acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc,
567 acpi_integer mask,
568 acpi_integer field_value,
569 u32 field_datum_byte_offset)
570{
571 acpi_status status = AE_OK;
572 acpi_integer merged_value;
573 acpi_integer current_value;
574
575 ACPI_FUNCTION_TRACE_U32(ex_write_with_update_rule, mask);
576
577 /* Start with the new bits */
578
579 merged_value = field_value;
580
581 /* If the mask is all ones, we don't need to worry about the update rule */
582
583 if (mask != ACPI_INTEGER_MAX) {
584
585 /* Decode the update rule */
586
587 switch (obj_desc->common_field.
588 field_flags & AML_FIELD_UPDATE_RULE_MASK) {
589 case AML_FIELD_UPDATE_PRESERVE:
590 /*
591 * Check if update rule needs to be applied (not if mask is all
592 * ones) The left shift drops the bits we want to ignore.
593 */
594 if ((~mask << (ACPI_MUL_8(sizeof(mask)) -
595 ACPI_MUL_8(obj_desc->common_field.
596 access_byte_width))) != 0) {
597 /*
598 * Read the current contents of the byte/word/dword containing
599 * the field, and merge with the new field value.
600 */
601 status =
602 acpi_ex_field_datum_io(obj_desc,
603 field_datum_byte_offset,
604 &current_value,
605 ACPI_READ);
606 if (ACPI_FAILURE(status)) {
607 return_ACPI_STATUS(status);
608 }
609
610 merged_value |= (current_value & ~mask);
611 }
612 break;
613
614 case AML_FIELD_UPDATE_WRITE_AS_ONES:
615
616 /* Set positions outside the field to all ones */
617
618 merged_value |= ~mask;
619 break;
620
621 case AML_FIELD_UPDATE_WRITE_AS_ZEROS:
622
623 /* Set positions outside the field to all zeros */
624
625 merged_value &= mask;
626 break;
627
628 default:
629
630 ACPI_ERROR((AE_INFO,
631 "Unknown UpdateRule value: %X",
632 (obj_desc->common_field.
633 field_flags &
634 AML_FIELD_UPDATE_RULE_MASK)));
635 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
636 }
637 }
638
639 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
640 "Mask %8.8X%8.8X, DatumOffset %X, Width %X, Value %8.8X%8.8X, MergedValue %8.8X%8.8X\n",
641 ACPI_FORMAT_UINT64(mask),
642 field_datum_byte_offset,
643 obj_desc->common_field.access_byte_width,
644 ACPI_FORMAT_UINT64(field_value),
645 ACPI_FORMAT_UINT64(merged_value)));
646
647 /* Write the merged value */
648
649 status = acpi_ex_field_datum_io(obj_desc, field_datum_byte_offset,
650 &merged_value, ACPI_WRITE);
651
652 return_ACPI_STATUS(status);
653}
654
655/*******************************************************************************
656 *
657 * FUNCTION: acpi_ex_extract_from_field
658 *
659 * PARAMETERS: obj_desc - Field to be read
660 * Buffer - Where to store the field data
661 * buffer_length - Length of Buffer
662 *
663 * RETURN: Status
664 *
665 * DESCRIPTION: Retrieve the current value of the given field
666 *
667 ******************************************************************************/
668
669acpi_status
670acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
671 void *buffer, u32 buffer_length)
672{
673 acpi_status status;
674 acpi_integer raw_datum;
675 acpi_integer merged_datum;
676 u32 field_offset = 0;
677 u32 buffer_offset = 0;
678 u32 buffer_tail_bits;
679 u32 datum_count;
680 u32 field_datum_count;
681 u32 i;
682
683 ACPI_FUNCTION_TRACE(ex_extract_from_field);
684
685 /* Validate target buffer and clear it */
686
687 if (buffer_length <
688 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) {
689 ACPI_ERROR((AE_INFO,
690 "Field size %X (bits) is too large for buffer (%X)",
691 obj_desc->common_field.bit_length, buffer_length));
692
693 return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
694 }
695 ACPI_MEMSET(buffer, 0, buffer_length);
696
697 /* Compute the number of datums (access width data items) */
698
699 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
700 obj_desc->common_field.access_bit_width);
701 field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
702 obj_desc->common_field.
703 start_field_bit_offset,
704 obj_desc->common_field.
705 access_bit_width);
706
707 /* Priming read from the field */
708
709 status =
710 acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum,
711 ACPI_READ);
712 if (ACPI_FAILURE(status)) {
713 return_ACPI_STATUS(status);
714 }
715 merged_datum =
716 raw_datum >> obj_desc->common_field.start_field_bit_offset;
717
718 /* Read the rest of the field */
719
720 for (i = 1; i < field_datum_count; i++) {
721
722 /* Get next input datum from the field */
723
724 field_offset += obj_desc->common_field.access_byte_width;
725 status = acpi_ex_field_datum_io(obj_desc, field_offset,
726 &raw_datum, ACPI_READ);
727 if (ACPI_FAILURE(status)) {
728 return_ACPI_STATUS(status);
729 }
730
731 /*
732 * Merge with previous datum if necessary.
733 *
734 * Note: Before the shift, check if the shift value will be larger than
735 * the integer size. If so, there is no need to perform the operation.
736 * This avoids the differences in behavior between different compilers
737 * concerning shift values larger than the target data width.
738 */
739 if ((obj_desc->common_field.access_bit_width -
740 obj_desc->common_field.start_field_bit_offset) <
741 ACPI_INTEGER_BIT_SIZE) {
742 merged_datum |=
743 raw_datum << (obj_desc->common_field.
744 access_bit_width -
745 obj_desc->common_field.
746 start_field_bit_offset);
747 }
748
749 if (i == datum_count) {
750 break;
751 }
752
753 /* Write merged datum to target buffer */
754
755 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
756 ACPI_MIN(obj_desc->common_field.access_byte_width,
757 buffer_length - buffer_offset));
758
759 buffer_offset += obj_desc->common_field.access_byte_width;
760 merged_datum =
761 raw_datum >> obj_desc->common_field.start_field_bit_offset;
762 }
763
764 /* Mask off any extra bits in the last datum */
765
766 buffer_tail_bits = obj_desc->common_field.bit_length %
767 obj_desc->common_field.access_bit_width;
768 if (buffer_tail_bits) {
769 merged_datum &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
770 }
771
772 /* Write the last datum to the buffer */
773
774 ACPI_MEMCPY(((char *)buffer) + buffer_offset, &merged_datum,
775 ACPI_MIN(obj_desc->common_field.access_byte_width,
776 buffer_length - buffer_offset));
777
778 return_ACPI_STATUS(AE_OK);
779}
780
781/*******************************************************************************
782 *
783 * FUNCTION: acpi_ex_insert_into_field
784 *
785 * PARAMETERS: obj_desc - Field to be written
786 * Buffer - Data to be written
787 * buffer_length - Length of Buffer
788 *
789 * RETURN: Status
790 *
791 * DESCRIPTION: Store the Buffer contents into the given field
792 *
793 ******************************************************************************/
794
795acpi_status
796acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
797 void *buffer, u32 buffer_length)
798{
799 acpi_status status;
800 acpi_integer mask;
801 acpi_integer width_mask;
802 acpi_integer merged_datum;
803 acpi_integer raw_datum = 0;
804 u32 field_offset = 0;
805 u32 buffer_offset = 0;
806 u32 buffer_tail_bits;
807 u32 datum_count;
808 u32 field_datum_count;
809 u32 i;
810 u32 required_length;
811 void *new_buffer;
812
813 ACPI_FUNCTION_TRACE(ex_insert_into_field);
814
815 /* Validate input buffer */
816
817 new_buffer = NULL;
818 required_length =
819 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length);
820 /*
821 * We must have a buffer that is at least as long as the field
822 * we are writing to. This is because individual fields are
823 * indivisible and partial writes are not supported -- as per
824 * the ACPI specification.
825 */
826 if (buffer_length < required_length) {
827
828 /* We need to create a new buffer */
829
830 new_buffer = ACPI_ALLOCATE_ZEROED(required_length);
831 if (!new_buffer) {
832 return_ACPI_STATUS(AE_NO_MEMORY);
833 }
834
835 /*
836 * Copy the original data to the new buffer, starting
837 * at Byte zero. All unused (upper) bytes of the
838 * buffer will be 0.
839 */
840 ACPI_MEMCPY((char *)new_buffer, (char *)buffer, buffer_length);
841 buffer = new_buffer;
842 buffer_length = required_length;
843 }
844
845 /*
846 * Create the bitmasks used for bit insertion.
847 * Note: This if/else is used to bypass compiler differences with the
848 * shift operator
849 */
850 if (obj_desc->common_field.access_bit_width == ACPI_INTEGER_BIT_SIZE) {
851 width_mask = ACPI_INTEGER_MAX;
852 } else {
853 width_mask =
854 ACPI_MASK_BITS_ABOVE(obj_desc->common_field.
855 access_bit_width);
856 }
857
858 mask = width_mask &
859 ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
860
861 /* Compute the number of datums (access width data items) */
862
863 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
864 obj_desc->common_field.access_bit_width);
865
866 field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
867 obj_desc->common_field.
868 start_field_bit_offset,
869 obj_desc->common_field.
870 access_bit_width);
871
872 /* Get initial Datum from the input buffer */
873
874 ACPI_MEMCPY(&raw_datum, buffer,
875 ACPI_MIN(obj_desc->common_field.access_byte_width,
876 buffer_length - buffer_offset));
877
878 merged_datum =
879 raw_datum << obj_desc->common_field.start_field_bit_offset;
880
881 /* Write the entire field */
882
883 for (i = 1; i < field_datum_count; i++) {
884
885 /* Write merged datum to the target field */
886
887 merged_datum &= mask;
888 status = acpi_ex_write_with_update_rule(obj_desc, mask,
889 merged_datum,
890 field_offset);
891 if (ACPI_FAILURE(status)) {
892 goto exit;
893 }
894
895 field_offset += obj_desc->common_field.access_byte_width;
896
897 /*
898 * Start new output datum by merging with previous input datum
899 * if necessary.
900 *
901 * Note: Before the shift, check if the shift value will be larger than
902 * the integer size. If so, there is no need to perform the operation.
903 * This avoids the differences in behavior between different compilers
904 * concerning shift values larger than the target data width.
905 */
906 if ((obj_desc->common_field.access_bit_width -
907 obj_desc->common_field.start_field_bit_offset) <
908 ACPI_INTEGER_BIT_SIZE) {
909 merged_datum =
910 raw_datum >> (obj_desc->common_field.
911 access_bit_width -
912 obj_desc->common_field.
913 start_field_bit_offset);
914 } else {
915 merged_datum = 0;
916 }
917
918 mask = width_mask;
919
920 if (i == datum_count) {
921 break;
922 }
923
924 /* Get the next input datum from the buffer */
925
926 buffer_offset += obj_desc->common_field.access_byte_width;
927 ACPI_MEMCPY(&raw_datum, ((char *)buffer) + buffer_offset,
928 ACPI_MIN(obj_desc->common_field.access_byte_width,
929 buffer_length - buffer_offset));
930 merged_datum |=
931 raw_datum << obj_desc->common_field.start_field_bit_offset;
932 }
933
934 /* Mask off any extra bits in the last datum */
935
936 buffer_tail_bits = (obj_desc->common_field.bit_length +
937 obj_desc->common_field.start_field_bit_offset) %
938 obj_desc->common_field.access_bit_width;
939 if (buffer_tail_bits) {
940 mask &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
941 }
942
943 /* Write the last datum to the field */
944
945 merged_datum &= mask;
946 status = acpi_ex_write_with_update_rule(obj_desc,
947 mask, merged_datum,
948 field_offset);
949
950 exit:
951 /* Free temporary buffer if we used one */
952
953 if (new_buffer) {
954 ACPI_FREE(new_buffer);
955 }
956 return_ACPI_STATUS(status);
957}
diff --git a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c
deleted file mode 100644
index efb191340059..000000000000
--- a/drivers/acpi/executer/exmisc.c
+++ /dev/null
@@ -1,725 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/amlcode.h>
48#include <acpi/amlresrc.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exmisc")
52
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_ex_get_object_reference
56 *
57 * PARAMETERS: obj_desc - Create a reference to this object
58 * return_desc - Where to store the reference
59 * walk_state - Current state
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: Obtain and return a "reference" to the target object
64 * Common code for the ref_of_op and the cond_ref_of_op.
65 *
66 ******************************************************************************/
67acpi_status
68acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
69 union acpi_operand_object **return_desc,
70 struct acpi_walk_state *walk_state)
71{
72 union acpi_operand_object *reference_obj;
73 union acpi_operand_object *referenced_obj;
74
75 ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc);
76
77 *return_desc = NULL;
78
79 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
80 case ACPI_DESC_TYPE_OPERAND:
81
82 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_LOCAL_REFERENCE) {
83 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
84 }
85
86 /*
87 * Must be a reference to a Local or Arg
88 */
89 switch (obj_desc->reference.class) {
90 case ACPI_REFCLASS_LOCAL:
91 case ACPI_REFCLASS_ARG:
92 case ACPI_REFCLASS_DEBUG:
93
94 /* The referenced object is the pseudo-node for the local/arg */
95
96 referenced_obj = obj_desc->reference.object;
97 break;
98
99 default:
100
101 ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X",
102 obj_desc->reference.class));
103 return_ACPI_STATUS(AE_AML_INTERNAL);
104 }
105 break;
106
107 case ACPI_DESC_TYPE_NAMED:
108
109 /*
110 * A named reference that has already been resolved to a Node
111 */
112 referenced_obj = obj_desc;
113 break;
114
115 default:
116
117 ACPI_ERROR((AE_INFO, "Invalid descriptor type %X",
118 ACPI_GET_DESCRIPTOR_TYPE(obj_desc)));
119 return_ACPI_STATUS(AE_TYPE);
120 }
121
122 /* Create a new reference object */
123
124 reference_obj =
125 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
126 if (!reference_obj) {
127 return_ACPI_STATUS(AE_NO_MEMORY);
128 }
129
130 reference_obj->reference.class = ACPI_REFCLASS_REFOF;
131 reference_obj->reference.object = referenced_obj;
132 *return_desc = reference_obj;
133
134 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
135 "Object %p Type [%s], returning Reference %p\n",
136 obj_desc, acpi_ut_get_object_type_name(obj_desc),
137 *return_desc));
138
139 return_ACPI_STATUS(AE_OK);
140}
141
142/*******************************************************************************
143 *
144 * FUNCTION: acpi_ex_concat_template
145 *
146 * PARAMETERS: Operand0 - First source object
147 * Operand1 - Second source object
148 * actual_return_desc - Where to place the return object
149 * walk_state - Current walk state
150 *
151 * RETURN: Status
152 *
153 * DESCRIPTION: Concatenate two resource templates
154 *
155 ******************************************************************************/
156
157acpi_status
158acpi_ex_concat_template(union acpi_operand_object *operand0,
159 union acpi_operand_object *operand1,
160 union acpi_operand_object **actual_return_desc,
161 struct acpi_walk_state *walk_state)
162{
163 acpi_status status;
164 union acpi_operand_object *return_desc;
165 u8 *new_buf;
166 u8 *end_tag;
167 acpi_size length0;
168 acpi_size length1;
169 acpi_size new_length;
170
171 ACPI_FUNCTION_TRACE(ex_concat_template);
172
173 /*
174 * Find the end_tag descriptor in each resource template.
175 * Note1: returned pointers point TO the end_tag, not past it.
176 * Note2: zero-length buffers are allowed; treated like one end_tag
177 */
178
179 /* Get the length of the first resource template */
180
181 status = acpi_ut_get_resource_end_tag(operand0, &end_tag);
182 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status);
184 }
185
186 length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer);
187
188 /* Get the length of the second resource template */
189
190 status = acpi_ut_get_resource_end_tag(operand1, &end_tag);
191 if (ACPI_FAILURE(status)) {
192 return_ACPI_STATUS(status);
193 }
194
195 length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer);
196
197 /* Combine both lengths, minimum size will be 2 for end_tag */
198
199 new_length = length0 + length1 + sizeof(struct aml_resource_end_tag);
200
201 /* Create a new buffer object for the result (with one end_tag) */
202
203 return_desc = acpi_ut_create_buffer_object(new_length);
204 if (!return_desc) {
205 return_ACPI_STATUS(AE_NO_MEMORY);
206 }
207
208 /*
209 * Copy the templates to the new buffer, 0 first, then 1 follows. One
210 * end_tag descriptor is copied from Operand1.
211 */
212 new_buf = return_desc->buffer.pointer;
213 ACPI_MEMCPY(new_buf, operand0->buffer.pointer, length0);
214 ACPI_MEMCPY(new_buf + length0, operand1->buffer.pointer, length1);
215
216 /* Insert end_tag and set the checksum to zero, means "ignore checksum" */
217
218 new_buf[new_length - 1] = 0;
219 new_buf[new_length - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
220
221 /* Return the completed resource template */
222
223 *actual_return_desc = return_desc;
224 return_ACPI_STATUS(AE_OK);
225}
226
227/*******************************************************************************
228 *
229 * FUNCTION: acpi_ex_do_concatenate
230 *
231 * PARAMETERS: Operand0 - First source object
232 * Operand1 - Second source object
233 * actual_return_desc - Where to place the return object
234 * walk_state - Current walk state
235 *
236 * RETURN: Status
237 *
238 * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
239 *
240 ******************************************************************************/
241
242acpi_status
243acpi_ex_do_concatenate(union acpi_operand_object *operand0,
244 union acpi_operand_object *operand1,
245 union acpi_operand_object **actual_return_desc,
246 struct acpi_walk_state *walk_state)
247{
248 union acpi_operand_object *local_operand1 = operand1;
249 union acpi_operand_object *return_desc;
250 char *new_buf;
251 acpi_status status;
252
253 ACPI_FUNCTION_TRACE(ex_do_concatenate);
254
255 /*
256 * Convert the second operand if necessary. The first operand
257 * determines the type of the second operand, (See the Data Types
258 * section of the ACPI specification.) Both object types are
259 * guaranteed to be either Integer/String/Buffer by the operand
260 * resolution mechanism.
261 */
262 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
263 case ACPI_TYPE_INTEGER:
264 status =
265 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
266 break;
267
268 case ACPI_TYPE_STRING:
269 status = acpi_ex_convert_to_string(operand1, &local_operand1,
270 ACPI_IMPLICIT_CONVERT_HEX);
271 break;
272
273 case ACPI_TYPE_BUFFER:
274 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
275 break;
276
277 default:
278 ACPI_ERROR((AE_INFO, "Invalid object type: %X",
279 ACPI_GET_OBJECT_TYPE(operand0)));
280 status = AE_AML_INTERNAL;
281 }
282
283 if (ACPI_FAILURE(status)) {
284 goto cleanup;
285 }
286
287 /*
288 * Both operands are now known to be the same object type
289 * (Both are Integer, String, or Buffer), and we can now perform the
290 * concatenation.
291 */
292
293 /*
294 * There are three cases to handle:
295 *
296 * 1) Two Integers concatenated to produce a new Buffer
297 * 2) Two Strings concatenated to produce a new String
298 * 3) Two Buffers concatenated to produce a new Buffer
299 */
300 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
301 case ACPI_TYPE_INTEGER:
302
303 /* Result of two Integers is a Buffer */
304 /* Need enough buffer space for two integers */
305
306 return_desc = acpi_ut_create_buffer_object((acpi_size)
307 ACPI_MUL_2
308 (acpi_gbl_integer_byte_width));
309 if (!return_desc) {
310 status = AE_NO_MEMORY;
311 goto cleanup;
312 }
313
314 new_buf = (char *)return_desc->buffer.pointer;
315
316 /* Copy the first integer, LSB first */
317
318 ACPI_MEMCPY(new_buf, &operand0->integer.value,
319 acpi_gbl_integer_byte_width);
320
321 /* Copy the second integer (LSB first) after the first */
322
323 ACPI_MEMCPY(new_buf + acpi_gbl_integer_byte_width,
324 &local_operand1->integer.value,
325 acpi_gbl_integer_byte_width);
326 break;
327
328 case ACPI_TYPE_STRING:
329
330 /* Result of two Strings is a String */
331
332 return_desc = acpi_ut_create_string_object(((acpi_size)
333 operand0->string.
334 length +
335 local_operand1->
336 string.length));
337 if (!return_desc) {
338 status = AE_NO_MEMORY;
339 goto cleanup;
340 }
341
342 new_buf = return_desc->string.pointer;
343
344 /* Concatenate the strings */
345
346 ACPI_STRCPY(new_buf, operand0->string.pointer);
347 ACPI_STRCPY(new_buf + operand0->string.length,
348 local_operand1->string.pointer);
349 break;
350
351 case ACPI_TYPE_BUFFER:
352
353 /* Result of two Buffers is a Buffer */
354
355 return_desc = acpi_ut_create_buffer_object(((acpi_size)
356 operand0->buffer.
357 length +
358 local_operand1->
359 buffer.length));
360 if (!return_desc) {
361 status = AE_NO_MEMORY;
362 goto cleanup;
363 }
364
365 new_buf = (char *)return_desc->buffer.pointer;
366
367 /* Concatenate the buffers */
368
369 ACPI_MEMCPY(new_buf, operand0->buffer.pointer,
370 operand0->buffer.length);
371 ACPI_MEMCPY(new_buf + operand0->buffer.length,
372 local_operand1->buffer.pointer,
373 local_operand1->buffer.length);
374 break;
375
376 default:
377
378 /* Invalid object type, should not happen here */
379
380 ACPI_ERROR((AE_INFO, "Invalid object type: %X",
381 ACPI_GET_OBJECT_TYPE(operand0)));
382 status = AE_AML_INTERNAL;
383 goto cleanup;
384 }
385
386 *actual_return_desc = return_desc;
387
388 cleanup:
389 if (local_operand1 != operand1) {
390 acpi_ut_remove_reference(local_operand1);
391 }
392 return_ACPI_STATUS(status);
393}
394
395/*******************************************************************************
396 *
397 * FUNCTION: acpi_ex_do_math_op
398 *
399 * PARAMETERS: Opcode - AML opcode
400 * Integer0 - Integer operand #0
401 * Integer1 - Integer operand #1
402 *
403 * RETURN: Integer result of the operation
404 *
405 * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
406 * math functions here is to prevent a lot of pointer dereferencing
407 * to obtain the operands.
408 *
409 ******************************************************************************/
410
411acpi_integer
412acpi_ex_do_math_op(u16 opcode, acpi_integer integer0, acpi_integer integer1)
413{
414
415 ACPI_FUNCTION_ENTRY();
416
417 switch (opcode) {
418 case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
419
420 return (integer0 + integer1);
421
422 case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
423
424 return (integer0 & integer1);
425
426 case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
427
428 return (~(integer0 & integer1));
429
430 case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
431
432 return (integer0 | integer1);
433
434 case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
435
436 return (~(integer0 | integer1));
437
438 case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
439
440 return (integer0 ^ integer1);
441
442 case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
443
444 return (integer0 * integer1);
445
446 case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */
447
448 /*
449 * We need to check if the shiftcount is larger than the integer bit
450 * width since the behavior of this is not well-defined in the C language.
451 */
452 if (integer1 >= acpi_gbl_integer_bit_width) {
453 return (0);
454 }
455 return (integer0 << integer1);
456
457 case AML_SHIFT_RIGHT_OP: /* shift_right (Operand, shift_count, Result) */
458
459 /*
460 * We need to check if the shiftcount is larger than the integer bit
461 * width since the behavior of this is not well-defined in the C language.
462 */
463 if (integer1 >= acpi_gbl_integer_bit_width) {
464 return (0);
465 }
466 return (integer0 >> integer1);
467
468 case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
469
470 return (integer0 - integer1);
471
472 default:
473
474 return (0);
475 }
476}
477
478/*******************************************************************************
479 *
480 * FUNCTION: acpi_ex_do_logical_numeric_op
481 *
482 * PARAMETERS: Opcode - AML opcode
483 * Integer0 - Integer operand #0
484 * Integer1 - Integer operand #1
485 * logical_result - TRUE/FALSE result of the operation
486 *
487 * RETURN: Status
488 *
489 * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
490 * operators (LAnd and LOr), both operands must be integers.
491 *
492 * Note: cleanest machine code seems to be produced by the code
493 * below, rather than using statements of the form:
494 * Result = (Integer0 && Integer1);
495 *
496 ******************************************************************************/
497
498acpi_status
499acpi_ex_do_logical_numeric_op(u16 opcode,
500 acpi_integer integer0,
501 acpi_integer integer1, u8 * logical_result)
502{
503 acpi_status status = AE_OK;
504 u8 local_result = FALSE;
505
506 ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op);
507
508 switch (opcode) {
509 case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
510
511 if (integer0 && integer1) {
512 local_result = TRUE;
513 }
514 break;
515
516 case AML_LOR_OP: /* LOr (Integer0, Integer1) */
517
518 if (integer0 || integer1) {
519 local_result = TRUE;
520 }
521 break;
522
523 default:
524 status = AE_AML_INTERNAL;
525 break;
526 }
527
528 /* Return the logical result and status */
529
530 *logical_result = local_result;
531 return_ACPI_STATUS(status);
532}
533
534/*******************************************************************************
535 *
536 * FUNCTION: acpi_ex_do_logical_op
537 *
538 * PARAMETERS: Opcode - AML opcode
539 * Operand0 - operand #0
540 * Operand1 - operand #1
541 * logical_result - TRUE/FALSE result of the operation
542 *
543 * RETURN: Status
544 *
545 * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
546 * functions here is to prevent a lot of pointer dereferencing
547 * to obtain the operands and to simplify the generation of the
548 * logical value. For the Numeric operators (LAnd and LOr), both
549 * operands must be integers. For the other logical operators,
550 * operands can be any combination of Integer/String/Buffer. The
551 * first operand determines the type to which the second operand
552 * will be converted.
553 *
554 * Note: cleanest machine code seems to be produced by the code
555 * below, rather than using statements of the form:
556 * Result = (Operand0 == Operand1);
557 *
558 ******************************************************************************/
559
560acpi_status
561acpi_ex_do_logical_op(u16 opcode,
562 union acpi_operand_object *operand0,
563 union acpi_operand_object *operand1, u8 * logical_result)
564{
565 union acpi_operand_object *local_operand1 = operand1;
566 acpi_integer integer0;
567 acpi_integer integer1;
568 u32 length0;
569 u32 length1;
570 acpi_status status = AE_OK;
571 u8 local_result = FALSE;
572 int compare;
573
574 ACPI_FUNCTION_TRACE(ex_do_logical_op);
575
576 /*
577 * Convert the second operand if necessary. The first operand
578 * determines the type of the second operand, (See the Data Types
579 * section of the ACPI 3.0+ specification.) Both object types are
580 * guaranteed to be either Integer/String/Buffer by the operand
581 * resolution mechanism.
582 */
583 switch (ACPI_GET_OBJECT_TYPE(operand0)) {
584 case ACPI_TYPE_INTEGER:
585 status =
586 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
587 break;
588
589 case ACPI_TYPE_STRING:
590 status = acpi_ex_convert_to_string(operand1, &local_operand1,
591 ACPI_IMPLICIT_CONVERT_HEX);
592 break;
593
594 case ACPI_TYPE_BUFFER:
595 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
596 break;
597
598 default:
599 status = AE_AML_INTERNAL;
600 break;
601 }
602
603 if (ACPI_FAILURE(status)) {
604 goto cleanup;
605 }
606
607 /*
608 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
609 */
610 if (ACPI_GET_OBJECT_TYPE(operand0) == ACPI_TYPE_INTEGER) {
611 /*
612 * 1) Both operands are of type integer
613 * Note: local_operand1 may have changed above
614 */
615 integer0 = operand0->integer.value;
616 integer1 = local_operand1->integer.value;
617
618 switch (opcode) {
619 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
620
621 if (integer0 == integer1) {
622 local_result = TRUE;
623 }
624 break;
625
626 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
627
628 if (integer0 > integer1) {
629 local_result = TRUE;
630 }
631 break;
632
633 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
634
635 if (integer0 < integer1) {
636 local_result = TRUE;
637 }
638 break;
639
640 default:
641 status = AE_AML_INTERNAL;
642 break;
643 }
644 } else {
645 /*
646 * 2) Both operands are Strings or both are Buffers
647 * Note: Code below takes advantage of common Buffer/String
648 * object fields. local_operand1 may have changed above. Use
649 * memcmp to handle nulls in buffers.
650 */
651 length0 = operand0->buffer.length;
652 length1 = local_operand1->buffer.length;
653
654 /* Lexicographic compare: compare the data bytes */
655
656 compare = ACPI_MEMCMP(operand0->buffer.pointer,
657 local_operand1->buffer.pointer,
658 (length0 > length1) ? length1 : length0);
659
660 switch (opcode) {
661 case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
662
663 /* Length and all bytes must be equal */
664
665 if ((length0 == length1) && (compare == 0)) {
666
667 /* Length and all bytes match ==> TRUE */
668
669 local_result = TRUE;
670 }
671 break;
672
673 case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
674
675 if (compare > 0) {
676 local_result = TRUE;
677 goto cleanup; /* TRUE */
678 }
679 if (compare < 0) {
680 goto cleanup; /* FALSE */
681 }
682
683 /* Bytes match (to shortest length), compare lengths */
684
685 if (length0 > length1) {
686 local_result = TRUE;
687 }
688 break;
689
690 case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
691
692 if (compare > 0) {
693 goto cleanup; /* FALSE */
694 }
695 if (compare < 0) {
696 local_result = TRUE;
697 goto cleanup; /* TRUE */
698 }
699
700 /* Bytes match (to shortest length), compare lengths */
701
702 if (length0 < length1) {
703 local_result = TRUE;
704 }
705 break;
706
707 default:
708 status = AE_AML_INTERNAL;
709 break;
710 }
711 }
712
713 cleanup:
714
715 /* New object was created if implicit conversion performed - delete */
716
717 if (local_operand1 != operand1) {
718 acpi_ut_remove_reference(local_operand1);
719 }
720
721 /* Return the logical result and status */
722
723 *logical_result = local_result;
724 return_ACPI_STATUS(status);
725}
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
deleted file mode 100644
index a8bf3d713e28..000000000000
--- a/drivers/acpi/executer/exmutex.c
+++ /dev/null
@@ -1,473 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exmutex - ASL Mutex Acquire/Release functions
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/acevents.h>
48
49#define _COMPONENT ACPI_EXECUTER
50ACPI_MODULE_NAME("exmutex")
51
52/* Local prototypes */
53static void
54acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
55 struct acpi_thread_state *thread);
56
57/*******************************************************************************
58 *
59 * FUNCTION: acpi_ex_unlink_mutex
60 *
61 * PARAMETERS: obj_desc - The mutex to be unlinked
62 *
63 * RETURN: None
64 *
65 * DESCRIPTION: Remove a mutex from the "AcquiredMutex" list
66 *
67 ******************************************************************************/
68
69void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc)
70{
71 struct acpi_thread_state *thread = obj_desc->mutex.owner_thread;
72
73 if (!thread) {
74 return;
75 }
76
77 /* Doubly linked list */
78
79 if (obj_desc->mutex.next) {
80 (obj_desc->mutex.next)->mutex.prev = obj_desc->mutex.prev;
81 }
82
83 if (obj_desc->mutex.prev) {
84 (obj_desc->mutex.prev)->mutex.next = obj_desc->mutex.next;
85 } else {
86 thread->acquired_mutex_list = obj_desc->mutex.next;
87 }
88}
89
90/*******************************************************************************
91 *
92 * FUNCTION: acpi_ex_link_mutex
93 *
94 * PARAMETERS: obj_desc - The mutex to be linked
95 * Thread - Current executing thread object
96 *
97 * RETURN: None
98 *
99 * DESCRIPTION: Add a mutex to the "AcquiredMutex" list for this walk
100 *
101 ******************************************************************************/
102
103static void
104acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
105 struct acpi_thread_state *thread)
106{
107 union acpi_operand_object *list_head;
108
109 list_head = thread->acquired_mutex_list;
110
111 /* This object will be the first object in the list */
112
113 obj_desc->mutex.prev = NULL;
114 obj_desc->mutex.next = list_head;
115
116 /* Update old first object to point back to this object */
117
118 if (list_head) {
119 list_head->mutex.prev = obj_desc;
120 }
121
122 /* Update list head */
123
124 thread->acquired_mutex_list = obj_desc;
125}
126
127/*******************************************************************************
128 *
129 * FUNCTION: acpi_ex_acquire_mutex_object
130 *
131 * PARAMETERS: time_desc - Timeout in milliseconds
132 * obj_desc - Mutex object
133 * Thread - Current thread state
134 *
135 * RETURN: Status
136 *
137 * DESCRIPTION: Acquire an AML mutex, low-level interface. Provides a common
138 * path that supports multiple acquires by the same thread.
139 *
140 * MUTEX: Interpreter must be locked
141 *
142 * NOTE: This interface is called from three places:
143 * 1) From acpi_ex_acquire_mutex, via an AML Acquire() operator
144 * 2) From acpi_ex_acquire_global_lock when an AML Field access requires the
145 * global lock
146 * 3) From the external interface, acpi_acquire_global_lock
147 *
148 ******************************************************************************/
149
150acpi_status
151acpi_ex_acquire_mutex_object(u16 timeout,
152 union acpi_operand_object *obj_desc,
153 acpi_thread_id thread_id)
154{
155 acpi_status status;
156
157 ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex_object, obj_desc);
158
159 if (!obj_desc) {
160 return_ACPI_STATUS(AE_BAD_PARAMETER);
161 }
162
163 /* Support for multiple acquires by the owning thread */
164
165 if (obj_desc->mutex.thread_id == thread_id) {
166 /*
167 * The mutex is already owned by this thread, just increment the
168 * acquisition depth
169 */
170 obj_desc->mutex.acquisition_depth++;
171 return_ACPI_STATUS(AE_OK);
172 }
173
174 /* Acquire the mutex, wait if necessary. Special case for Global Lock */
175
176 if (obj_desc == acpi_gbl_global_lock_mutex) {
177 status = acpi_ev_acquire_global_lock(timeout);
178 } else {
179 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
180 timeout);
181 }
182
183 if (ACPI_FAILURE(status)) {
184
185 /* Includes failure from a timeout on time_desc */
186
187 return_ACPI_STATUS(status);
188 }
189
190 /* Acquired the mutex: update mutex object */
191
192 obj_desc->mutex.thread_id = thread_id;
193 obj_desc->mutex.acquisition_depth = 1;
194 obj_desc->mutex.original_sync_level = 0;
195 obj_desc->mutex.owner_thread = NULL; /* Used only for AML Acquire() */
196
197 return_ACPI_STATUS(AE_OK);
198}
199
200/*******************************************************************************
201 *
202 * FUNCTION: acpi_ex_acquire_mutex
203 *
204 * PARAMETERS: time_desc - Timeout integer
205 * obj_desc - Mutex object
206 * walk_state - Current method execution state
207 *
208 * RETURN: Status
209 *
210 * DESCRIPTION: Acquire an AML mutex
211 *
212 ******************************************************************************/
213
214acpi_status
215acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
216 union acpi_operand_object *obj_desc,
217 struct acpi_walk_state *walk_state)
218{
219 acpi_status status;
220
221 ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex, obj_desc);
222
223 if (!obj_desc) {
224 return_ACPI_STATUS(AE_BAD_PARAMETER);
225 }
226
227 /* Must have a valid thread ID */
228
229 if (!walk_state->thread) {
230 ACPI_ERROR((AE_INFO,
231 "Cannot acquire Mutex [%4.4s], null thread info",
232 acpi_ut_get_node_name(obj_desc->mutex.node)));
233 return_ACPI_STATUS(AE_AML_INTERNAL);
234 }
235
236 /*
237 * Current sync level must be less than or equal to the sync level of the
238 * mutex. This mechanism provides some deadlock prevention
239 */
240 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
241 ACPI_ERROR((AE_INFO,
242 "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%d)",
243 acpi_ut_get_node_name(obj_desc->mutex.node),
244 walk_state->thread->current_sync_level));
245 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
246 }
247
248 status = acpi_ex_acquire_mutex_object((u16) time_desc->integer.value,
249 obj_desc,
250 walk_state->thread->thread_id);
251 if (ACPI_SUCCESS(status) && obj_desc->mutex.acquisition_depth == 1) {
252
253 /* Save Thread object, original/current sync levels */
254
255 obj_desc->mutex.owner_thread = walk_state->thread;
256 obj_desc->mutex.original_sync_level =
257 walk_state->thread->current_sync_level;
258 walk_state->thread->current_sync_level =
259 obj_desc->mutex.sync_level;
260
261 /* Link the mutex to the current thread for force-unlock at method exit */
262
263 acpi_ex_link_mutex(obj_desc, walk_state->thread);
264 }
265
266 return_ACPI_STATUS(status);
267}
268
269/*******************************************************************************
270 *
271 * FUNCTION: acpi_ex_release_mutex_object
272 *
273 * PARAMETERS: obj_desc - The object descriptor for this op
274 *
275 * RETURN: Status
276 *
277 * DESCRIPTION: Release a previously acquired Mutex, low level interface.
278 * Provides a common path that supports multiple releases (after
279 * previous multiple acquires) by the same thread.
280 *
281 * MUTEX: Interpreter must be locked
282 *
283 * NOTE: This interface is called from three places:
284 * 1) From acpi_ex_release_mutex, via an AML Acquire() operator
285 * 2) From acpi_ex_release_global_lock when an AML Field access requires the
286 * global lock
287 * 3) From the external interface, acpi_release_global_lock
288 *
289 ******************************************************************************/
290
291acpi_status acpi_ex_release_mutex_object(union acpi_operand_object *obj_desc)
292{
293 acpi_status status = AE_OK;
294
295 ACPI_FUNCTION_TRACE(ex_release_mutex_object);
296
297 if (obj_desc->mutex.acquisition_depth == 0) {
298 return (AE_NOT_ACQUIRED);
299 }
300
301 /* Match multiple Acquires with multiple Releases */
302
303 obj_desc->mutex.acquisition_depth--;
304 if (obj_desc->mutex.acquisition_depth != 0) {
305
306 /* Just decrement the depth and return */
307
308 return_ACPI_STATUS(AE_OK);
309 }
310
311 if (obj_desc->mutex.owner_thread) {
312
313 /* Unlink the mutex from the owner's list */
314
315 acpi_ex_unlink_mutex(obj_desc);
316 obj_desc->mutex.owner_thread = NULL;
317 }
318
319 /* Release the mutex, special case for Global Lock */
320
321 if (obj_desc == acpi_gbl_global_lock_mutex) {
322 status = acpi_ev_release_global_lock();
323 } else {
324 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
325 }
326
327 /* Clear mutex info */
328
329 obj_desc->mutex.thread_id = NULL;
330 return_ACPI_STATUS(status);
331}
332
333/*******************************************************************************
334 *
335 * FUNCTION: acpi_ex_release_mutex
336 *
337 * PARAMETERS: obj_desc - The object descriptor for this op
338 * walk_state - Current method execution state
339 *
340 * RETURN: Status
341 *
342 * DESCRIPTION: Release a previously acquired Mutex.
343 *
344 ******************************************************************************/
345
346acpi_status
347acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
348 struct acpi_walk_state *walk_state)
349{
350 acpi_status status = AE_OK;
351
352 ACPI_FUNCTION_TRACE(ex_release_mutex);
353
354 if (!obj_desc) {
355 return_ACPI_STATUS(AE_BAD_PARAMETER);
356 }
357
358 /* The mutex must have been previously acquired in order to release it */
359
360 if (!obj_desc->mutex.owner_thread) {
361 ACPI_ERROR((AE_INFO,
362 "Cannot release Mutex [%4.4s], not acquired",
363 acpi_ut_get_node_name(obj_desc->mutex.node)));
364 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED);
365 }
366
367 /*
368 * The Mutex is owned, but this thread must be the owner.
369 * Special case for Global Lock, any thread can release
370 */
371 if ((obj_desc->mutex.owner_thread->thread_id !=
372 walk_state->thread->thread_id)
373 && (obj_desc != acpi_gbl_global_lock_mutex)) {
374 ACPI_ERROR((AE_INFO,
375 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
376 (unsigned long)walk_state->thread->thread_id,
377 acpi_ut_get_node_name(obj_desc->mutex.node),
378 (unsigned long)obj_desc->mutex.owner_thread->
379 thread_id));
380 return_ACPI_STATUS(AE_AML_NOT_OWNER);
381 }
382
383 /* Must have a valid thread ID */
384
385 if (!walk_state->thread) {
386 ACPI_ERROR((AE_INFO,
387 "Cannot release Mutex [%4.4s], null thread info",
388 acpi_ut_get_node_name(obj_desc->mutex.node)));
389 return_ACPI_STATUS(AE_AML_INTERNAL);
390 }
391
392 /*
393 * The sync level of the mutex must be less than or equal to the current
394 * sync level
395 */
396 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
397 ACPI_ERROR((AE_INFO,
398 "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %d current %d",
399 acpi_ut_get_node_name(obj_desc->mutex.node),
400 obj_desc->mutex.sync_level,
401 walk_state->thread->current_sync_level));
402 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
403 }
404
405 status = acpi_ex_release_mutex_object(obj_desc);
406
407 if (obj_desc->mutex.acquisition_depth == 0) {
408
409 /* Restore the original sync_level */
410
411 walk_state->thread->current_sync_level =
412 obj_desc->mutex.original_sync_level;
413 }
414 return_ACPI_STATUS(status);
415}
416
417/*******************************************************************************
418 *
419 * FUNCTION: acpi_ex_release_all_mutexes
420 *
421 * PARAMETERS: Thread - Current executing thread object
422 *
423 * RETURN: Status
424 *
425 * DESCRIPTION: Release all mutexes held by this thread
426 *
427 * NOTE: This function is called as the thread is exiting the interpreter.
428 * Mutexes are not released when an individual control method is exited, but
429 * only when the parent thread actually exits the interpreter. This allows one
430 * method to acquire a mutex, and a different method to release it, as long as
431 * this is performed underneath a single parent control method.
432 *
433 ******************************************************************************/
434
435void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
436{
437 union acpi_operand_object *next = thread->acquired_mutex_list;
438 union acpi_operand_object *obj_desc;
439
440 ACPI_FUNCTION_ENTRY();
441
442 /* Traverse the list of owned mutexes, releasing each one */
443
444 while (next) {
445 obj_desc = next;
446 next = obj_desc->mutex.next;
447
448 obj_desc->mutex.prev = NULL;
449 obj_desc->mutex.next = NULL;
450 obj_desc->mutex.acquisition_depth = 0;
451
452 /* Release the mutex, special case for Global Lock */
453
454 if (obj_desc == acpi_gbl_global_lock_mutex) {
455
456 /* Ignore errors */
457
458 (void)acpi_ev_release_global_lock();
459 } else {
460 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
461 }
462
463 /* Mark mutex unowned */
464
465 obj_desc->mutex.owner_thread = NULL;
466 obj_desc->mutex.thread_id = NULL;
467
468 /* Update Thread sync_level (Last mutex is the important one) */
469
470 thread->current_sync_level =
471 obj_desc->mutex.original_sync_level;
472 }
473}
diff --git a/drivers/acpi/executer/exnames.c b/drivers/acpi/executer/exnames.c
deleted file mode 100644
index 817e67be3697..000000000000
--- a/drivers/acpi/executer/exnames.c
+++ /dev/null
@@ -1,435 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exnames - interpreter/scanner name load/execute
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/amlcode.h>
48
49#define _COMPONENT ACPI_EXECUTER
50ACPI_MODULE_NAME("exnames")
51
52/* Local prototypes */
53static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs);
54
55static acpi_status
56acpi_ex_name_segment(u8 ** in_aml_address, char *name_string);
57
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_ex_allocate_name_string
61 *
62 * PARAMETERS: prefix_count - Count of parent levels. Special cases:
63 * (-1)==root, 0==none
64 * num_name_segs - count of 4-character name segments
65 *
66 * RETURN: A pointer to the allocated string segment. This segment must
67 * be deleted by the caller.
68 *
69 * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name
70 * string is long enough, and set up prefix if any.
71 *
72 ******************************************************************************/
73
74static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs)
75{
76 char *temp_ptr;
77 char *name_string;
78 u32 size_needed;
79
80 ACPI_FUNCTION_TRACE(ex_allocate_name_string);
81
82 /*
83 * Allow room for all \ and ^ prefixes, all segments and a multi_name_prefix.
84 * Also, one byte for the null terminator.
85 * This may actually be somewhat longer than needed.
86 */
87 if (prefix_count == ACPI_UINT32_MAX) {
88
89 /* Special case for root */
90
91 size_needed = 1 + (ACPI_NAME_SIZE * num_name_segs) + 2 + 1;
92 } else {
93 size_needed =
94 prefix_count + (ACPI_NAME_SIZE * num_name_segs) + 2 + 1;
95 }
96
97 /*
98 * Allocate a buffer for the name.
99 * This buffer must be deleted by the caller!
100 */
101 name_string = ACPI_ALLOCATE(size_needed);
102 if (!name_string) {
103 ACPI_ERROR((AE_INFO,
104 "Could not allocate size %d", size_needed));
105 return_PTR(NULL);
106 }
107
108 temp_ptr = name_string;
109
110 /* Set up Root or Parent prefixes if needed */
111
112 if (prefix_count == ACPI_UINT32_MAX) {
113 *temp_ptr++ = AML_ROOT_PREFIX;
114 } else {
115 while (prefix_count--) {
116 *temp_ptr++ = AML_PARENT_PREFIX;
117 }
118 }
119
120 /* Set up Dual or Multi prefixes if needed */
121
122 if (num_name_segs > 2) {
123
124 /* Set up multi prefixes */
125
126 *temp_ptr++ = AML_MULTI_NAME_PREFIX_OP;
127 *temp_ptr++ = (char)num_name_segs;
128 } else if (2 == num_name_segs) {
129
130 /* Set up dual prefixes */
131
132 *temp_ptr++ = AML_DUAL_NAME_PREFIX;
133 }
134
135 /*
136 * Terminate string following prefixes. acpi_ex_name_segment() will
137 * append the segment(s)
138 */
139 *temp_ptr = 0;
140
141 return_PTR(name_string);
142}
143
144/*******************************************************************************
145 *
146 * FUNCTION: acpi_ex_name_segment
147 *
148 * PARAMETERS: in_aml_address - Pointer to the name in the AML code
149 * name_string - Where to return the name. The name is appended
150 * to any existing string to form a namepath
151 *
152 * RETURN: Status
153 *
154 * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream
155 *
156 ******************************************************************************/
157
158static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string)
159{
160 char *aml_address = (void *)*in_aml_address;
161 acpi_status status = AE_OK;
162 u32 index;
163 char char_buf[5];
164
165 ACPI_FUNCTION_TRACE(ex_name_segment);
166
167 /*
168 * If first character is a digit, then we know that we aren't looking at a
169 * valid name segment
170 */
171 char_buf[0] = *aml_address;
172
173 if ('0' <= char_buf[0] && char_buf[0] <= '9') {
174 ACPI_ERROR((AE_INFO, "Invalid leading digit: %c", char_buf[0]));
175 return_ACPI_STATUS(AE_CTRL_PENDING);
176 }
177
178 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Bytes from stream:\n"));
179
180 for (index = 0; (index < ACPI_NAME_SIZE)
181 && (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) {
182 char_buf[index] = *aml_address++;
183 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index]));
184 }
185
186 /* Valid name segment */
187
188 if (index == 4) {
189
190 /* Found 4 valid characters */
191
192 char_buf[4] = '\0';
193
194 if (name_string) {
195 ACPI_STRCAT(name_string, char_buf);
196 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
197 "Appended to - %s\n", name_string));
198 } else {
199 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
200 "No Name string - %s\n", char_buf));
201 }
202 } else if (index == 0) {
203 /*
204 * First character was not a valid name character,
205 * so we are looking at something other than a name.
206 */
207 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
208 "Leading character is not alpha: %02Xh (not a name)\n",
209 char_buf[0]));
210 status = AE_CTRL_PENDING;
211 } else {
212 /*
213 * Segment started with one or more valid characters, but fewer than
214 * the required 4
215 */
216 status = AE_AML_BAD_NAME;
217 ACPI_ERROR((AE_INFO,
218 "Bad character %02x in name, at %p",
219 *aml_address, aml_address));
220 }
221
222 *in_aml_address = ACPI_CAST_PTR(u8, aml_address);
223 return_ACPI_STATUS(status);
224}
225
226/*******************************************************************************
227 *
228 * FUNCTION: acpi_ex_get_name_string
229 *
230 * PARAMETERS: data_type - Object type to be associated with this
231 * name
232 * in_aml_address - Pointer to the namestring in the AML code
233 * out_name_string - Where the namestring is returned
234 * out_name_length - Length of the returned string
235 *
236 * RETURN: Status, namestring and length
237 *
238 * DESCRIPTION: Extract a full namepath from the AML byte stream,
239 * including any prefixes.
240 *
241 ******************************************************************************/
242
243acpi_status
244acpi_ex_get_name_string(acpi_object_type data_type,
245 u8 * in_aml_address,
246 char **out_name_string, u32 * out_name_length)
247{
248 acpi_status status = AE_OK;
249 u8 *aml_address = in_aml_address;
250 char *name_string = NULL;
251 u32 num_segments;
252 u32 prefix_count = 0;
253 u8 has_prefix = FALSE;
254
255 ACPI_FUNCTION_TRACE_PTR(ex_get_name_string, aml_address);
256
257 if (ACPI_TYPE_LOCAL_REGION_FIELD == data_type ||
258 ACPI_TYPE_LOCAL_BANK_FIELD == data_type ||
259 ACPI_TYPE_LOCAL_INDEX_FIELD == data_type) {
260
261 /* Disallow prefixes for types associated with field_unit names */
262
263 name_string = acpi_ex_allocate_name_string(0, 1);
264 if (!name_string) {
265 status = AE_NO_MEMORY;
266 } else {
267 status =
268 acpi_ex_name_segment(&aml_address, name_string);
269 }
270 } else {
271 /*
272 * data_type is not a field name.
273 * Examine first character of name for root or parent prefix operators
274 */
275 switch (*aml_address) {
276 case AML_ROOT_PREFIX:
277
278 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
279 "RootPrefix(\\) at %p\n",
280 aml_address));
281
282 /*
283 * Remember that we have a root_prefix --
284 * see comment in acpi_ex_allocate_name_string()
285 */
286 aml_address++;
287 prefix_count = ACPI_UINT32_MAX;
288 has_prefix = TRUE;
289 break;
290
291 case AML_PARENT_PREFIX:
292
293 /* Increment past possibly multiple parent prefixes */
294
295 do {
296 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
297 "ParentPrefix (^) at %p\n",
298 aml_address));
299
300 aml_address++;
301 prefix_count++;
302
303 } while (*aml_address == AML_PARENT_PREFIX);
304
305 has_prefix = TRUE;
306 break;
307
308 default:
309
310 /* Not a prefix character */
311
312 break;
313 }
314
315 /* Examine first character of name for name segment prefix operator */
316
317 switch (*aml_address) {
318 case AML_DUAL_NAME_PREFIX:
319
320 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
321 "DualNamePrefix at %p\n",
322 aml_address));
323
324 aml_address++;
325 name_string =
326 acpi_ex_allocate_name_string(prefix_count, 2);
327 if (!name_string) {
328 status = AE_NO_MEMORY;
329 break;
330 }
331
332 /* Indicate that we processed a prefix */
333
334 has_prefix = TRUE;
335
336 status =
337 acpi_ex_name_segment(&aml_address, name_string);
338 if (ACPI_SUCCESS(status)) {
339 status =
340 acpi_ex_name_segment(&aml_address,
341 name_string);
342 }
343 break;
344
345 case AML_MULTI_NAME_PREFIX_OP:
346
347 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
348 "MultiNamePrefix at %p\n",
349 aml_address));
350
351 /* Fetch count of segments remaining in name path */
352
353 aml_address++;
354 num_segments = *aml_address;
355
356 name_string =
357 acpi_ex_allocate_name_string(prefix_count,
358 num_segments);
359 if (!name_string) {
360 status = AE_NO_MEMORY;
361 break;
362 }
363
364 /* Indicate that we processed a prefix */
365
366 aml_address++;
367 has_prefix = TRUE;
368
369 while (num_segments &&
370 (status =
371 acpi_ex_name_segment(&aml_address,
372 name_string)) == AE_OK) {
373 num_segments--;
374 }
375
376 break;
377
378 case 0:
379
380 /* null_name valid as of 8-12-98 ASL/AML Grammar Update */
381
382 if (prefix_count == ACPI_UINT32_MAX) {
383 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
384 "NameSeg is \"\\\" followed by NULL\n"));
385 }
386
387 /* Consume the NULL byte */
388
389 aml_address++;
390 name_string =
391 acpi_ex_allocate_name_string(prefix_count, 0);
392 if (!name_string) {
393 status = AE_NO_MEMORY;
394 break;
395 }
396
397 break;
398
399 default:
400
401 /* Name segment string */
402
403 name_string =
404 acpi_ex_allocate_name_string(prefix_count, 1);
405 if (!name_string) {
406 status = AE_NO_MEMORY;
407 break;
408 }
409
410 status =
411 acpi_ex_name_segment(&aml_address, name_string);
412 break;
413 }
414 }
415
416 if (AE_CTRL_PENDING == status && has_prefix) {
417
418 /* Ran out of segments after processing a prefix */
419
420 ACPI_ERROR((AE_INFO, "Malformed Name at %p", name_string));
421 status = AE_AML_BAD_NAME;
422 }
423
424 if (ACPI_FAILURE(status)) {
425 if (name_string) {
426 ACPI_FREE(name_string);
427 }
428 return_ACPI_STATUS(status);
429 }
430
431 *out_name_string = name_string;
432 *out_name_length = (u32) (aml_address - in_aml_address);
433
434 return_ACPI_STATUS(status);
435}
diff --git a/drivers/acpi/executer/exoparg1.c b/drivers/acpi/executer/exoparg1.c
deleted file mode 100644
index f622f9eac8a1..000000000000
--- a/drivers/acpi/executer/exoparg1.c
+++ /dev/null
@@ -1,1049 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acparser.h>
47#include <acpi/acdispat.h>
48#include <acpi/acinterp.h>
49#include <acpi/amlcode.h>
50#include <acpi/acnamesp.h>
51
52#define _COMPONENT ACPI_EXECUTER
53ACPI_MODULE_NAME("exoparg1")
54
55/*!
56 * Naming convention for AML interpreter execution routines.
57 *
58 * The routines that begin execution of AML opcodes are named with a common
59 * convention based upon the number of arguments, the number of target operands,
60 * and whether or not a value is returned:
61 *
62 * AcpiExOpcode_xA_yT_zR
63 *
64 * Where:
65 *
66 * xA - ARGUMENTS: The number of arguments (input operands) that are
67 * required for this opcode type (0 through 6 args).
68 * yT - TARGETS: The number of targets (output operands) that are required
69 * for this opcode type (0, 1, or 2 targets).
70 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
71 * as the function return (0 or 1).
72 *
73 * The AcpiExOpcode* functions are called via the Dispatcher component with
74 * fully resolved operands.
75!*/
76/*******************************************************************************
77 *
78 * FUNCTION: acpi_ex_opcode_0A_0T_1R
79 *
80 * PARAMETERS: walk_state - Current state (contains AML opcode)
81 *
82 * RETURN: Status
83 *
84 * DESCRIPTION: Execute operator with no operands, one return value
85 *
86 ******************************************************************************/
87acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
88{
89 acpi_status status = AE_OK;
90 union acpi_operand_object *return_desc = NULL;
91
92 ACPI_FUNCTION_TRACE_STR(ex_opcode_0A_0T_1R,
93 acpi_ps_get_opcode_name(walk_state->opcode));
94
95 /* Examine the AML opcode */
96
97 switch (walk_state->opcode) {
98 case AML_TIMER_OP: /* Timer () */
99
100 /* Create a return object of type Integer */
101
102 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
103 if (!return_desc) {
104 status = AE_NO_MEMORY;
105 goto cleanup;
106 }
107 return_desc->integer.value = acpi_os_get_timer();
108 break;
109
110 default: /* Unknown opcode */
111
112 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
113 walk_state->opcode));
114 status = AE_AML_BAD_OPCODE;
115 break;
116 }
117
118 cleanup:
119
120 /* Delete return object on error */
121
122 if ((ACPI_FAILURE(status)) || walk_state->result_obj) {
123 acpi_ut_remove_reference(return_desc);
124 walk_state->result_obj = NULL;
125 } else {
126 /* Save the return value */
127
128 walk_state->result_obj = return_desc;
129 }
130
131 return_ACPI_STATUS(status);
132}
133
134/*******************************************************************************
135 *
136 * FUNCTION: acpi_ex_opcode_1A_0T_0R
137 *
138 * PARAMETERS: walk_state - Current state (contains AML opcode)
139 *
140 * RETURN: Status
141 *
142 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
143 * object stack
144 *
145 ******************************************************************************/
146
147acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
148{
149 union acpi_operand_object **operand = &walk_state->operands[0];
150 acpi_status status = AE_OK;
151
152 ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_0R,
153 acpi_ps_get_opcode_name(walk_state->opcode));
154
155 /* Examine the AML opcode */
156
157 switch (walk_state->opcode) {
158 case AML_RELEASE_OP: /* Release (mutex_object) */
159
160 status = acpi_ex_release_mutex(operand[0], walk_state);
161 break;
162
163 case AML_RESET_OP: /* Reset (event_object) */
164
165 status = acpi_ex_system_reset_event(operand[0]);
166 break;
167
168 case AML_SIGNAL_OP: /* Signal (event_object) */
169
170 status = acpi_ex_system_signal_event(operand[0]);
171 break;
172
173 case AML_SLEEP_OP: /* Sleep (msec_time) */
174
175 status = acpi_ex_system_do_suspend(operand[0]->integer.value);
176 break;
177
178 case AML_STALL_OP: /* Stall (usec_time) */
179
180 status =
181 acpi_ex_system_do_stall((u32) operand[0]->integer.value);
182 break;
183
184 case AML_UNLOAD_OP: /* Unload (Handle) */
185
186 status = acpi_ex_unload_table(operand[0]);
187 break;
188
189 default: /* Unknown opcode */
190
191 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
192 walk_state->opcode));
193 status = AE_AML_BAD_OPCODE;
194 break;
195 }
196
197 return_ACPI_STATUS(status);
198}
199
200/*******************************************************************************
201 *
202 * FUNCTION: acpi_ex_opcode_1A_1T_0R
203 *
204 * PARAMETERS: walk_state - Current state (contains AML opcode)
205 *
206 * RETURN: Status
207 *
208 * DESCRIPTION: Execute opcode with one argument, one target, and no
209 * return value.
210 *
211 ******************************************************************************/
212
213acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
214{
215 acpi_status status = AE_OK;
216 union acpi_operand_object **operand = &walk_state->operands[0];
217
218 ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_0R,
219 acpi_ps_get_opcode_name(walk_state->opcode));
220
221 /* Examine the AML opcode */
222
223 switch (walk_state->opcode) {
224 case AML_LOAD_OP:
225
226 status = acpi_ex_load_op(operand[0], operand[1], walk_state);
227 break;
228
229 default: /* Unknown opcode */
230
231 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
232 walk_state->opcode));
233 status = AE_AML_BAD_OPCODE;
234 goto cleanup;
235 }
236
237 cleanup:
238
239 return_ACPI_STATUS(status);
240}
241
242/*******************************************************************************
243 *
244 * FUNCTION: acpi_ex_opcode_1A_1T_1R
245 *
246 * PARAMETERS: walk_state - Current state (contains AML opcode)
247 *
248 * RETURN: Status
249 *
250 * DESCRIPTION: Execute opcode with one argument, one target, and a
251 * return value.
252 *
253 ******************************************************************************/
254
255acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
256{
257 acpi_status status = AE_OK;
258 union acpi_operand_object **operand = &walk_state->operands[0];
259 union acpi_operand_object *return_desc = NULL;
260 union acpi_operand_object *return_desc2 = NULL;
261 u32 temp32;
262 u32 i;
263 acpi_integer power_of_ten;
264 acpi_integer digit;
265
266 ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_1R,
267 acpi_ps_get_opcode_name(walk_state->opcode));
268
269 /* Examine the AML opcode */
270
271 switch (walk_state->opcode) {
272 case AML_BIT_NOT_OP:
273 case AML_FIND_SET_LEFT_BIT_OP:
274 case AML_FIND_SET_RIGHT_BIT_OP:
275 case AML_FROM_BCD_OP:
276 case AML_TO_BCD_OP:
277 case AML_COND_REF_OF_OP:
278
279 /* Create a return object of type Integer for these opcodes */
280
281 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
282 if (!return_desc) {
283 status = AE_NO_MEMORY;
284 goto cleanup;
285 }
286
287 switch (walk_state->opcode) {
288 case AML_BIT_NOT_OP: /* Not (Operand, Result) */
289
290 return_desc->integer.value = ~operand[0]->integer.value;
291 break;
292
293 case AML_FIND_SET_LEFT_BIT_OP: /* find_set_left_bit (Operand, Result) */
294
295 return_desc->integer.value = operand[0]->integer.value;
296
297 /*
298 * Acpi specification describes Integer type as a little
299 * endian unsigned value, so this boundary condition is valid.
300 */
301 for (temp32 = 0; return_desc->integer.value &&
302 temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
303 return_desc->integer.value >>= 1;
304 }
305
306 return_desc->integer.value = temp32;
307 break;
308
309 case AML_FIND_SET_RIGHT_BIT_OP: /* find_set_right_bit (Operand, Result) */
310
311 return_desc->integer.value = operand[0]->integer.value;
312
313 /*
314 * The Acpi specification describes Integer type as a little
315 * endian unsigned value, so this boundary condition is valid.
316 */
317 for (temp32 = 0; return_desc->integer.value &&
318 temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
319 return_desc->integer.value <<= 1;
320 }
321
322 /* Since the bit position is one-based, subtract from 33 (65) */
323
324 return_desc->integer.value =
325 temp32 ==
326 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - temp32;
327 break;
328
329 case AML_FROM_BCD_OP: /* from_bcd (BCDValue, Result) */
330
331 /*
332 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
333 * (if table is 32-bit, integer can hold 8 BCD characters)
334 * Convert each 4-bit BCD value
335 */
336 power_of_ten = 1;
337 return_desc->integer.value = 0;
338 digit = operand[0]->integer.value;
339
340 /* Convert each BCD digit (each is one nybble wide) */
341
342 for (i = 0;
343 (i < acpi_gbl_integer_nybble_width) && (digit > 0);
344 i++) {
345
346 /* Get the least significant 4-bit BCD digit */
347
348 temp32 = ((u32) digit) & 0xF;
349
350 /* Check the range of the digit */
351
352 if (temp32 > 9) {
353 ACPI_ERROR((AE_INFO,
354 "BCD digit too large (not decimal): 0x%X",
355 temp32));
356
357 status = AE_AML_NUMERIC_OVERFLOW;
358 goto cleanup;
359 }
360
361 /* Sum the digit into the result with the current power of 10 */
362
363 return_desc->integer.value +=
364 (((acpi_integer) temp32) * power_of_ten);
365
366 /* Shift to next BCD digit */
367
368 digit >>= 4;
369
370 /* Next power of 10 */
371
372 power_of_ten *= 10;
373 }
374 break;
375
376 case AML_TO_BCD_OP: /* to_bcd (Operand, Result) */
377
378 return_desc->integer.value = 0;
379 digit = operand[0]->integer.value;
380
381 /* Each BCD digit is one nybble wide */
382
383 for (i = 0;
384 (i < acpi_gbl_integer_nybble_width) && (digit > 0);
385 i++) {
386 (void)acpi_ut_short_divide(digit, 10, &digit,
387 &temp32);
388
389 /*
390 * Insert the BCD digit that resides in the
391 * remainder from above
392 */
393 return_desc->integer.value |=
394 (((acpi_integer) temp32) << ACPI_MUL_4(i));
395 }
396
397 /* Overflow if there is any data left in Digit */
398
399 if (digit > 0) {
400 ACPI_ERROR((AE_INFO,
401 "Integer too large to convert to BCD: %8.8X%8.8X",
402 ACPI_FORMAT_UINT64(operand[0]->
403 integer.value)));
404 status = AE_AML_NUMERIC_OVERFLOW;
405 goto cleanup;
406 }
407 break;
408
409 case AML_COND_REF_OF_OP: /* cond_ref_of (source_object, Result) */
410
411 /*
412 * This op is a little strange because the internal return value is
413 * different than the return value stored in the result descriptor
414 * (There are really two return values)
415 */
416 if ((struct acpi_namespace_node *)operand[0] ==
417 acpi_gbl_root_node) {
418 /*
419 * This means that the object does not exist in the namespace,
420 * return FALSE
421 */
422 return_desc->integer.value = 0;
423 goto cleanup;
424 }
425
426 /* Get the object reference, store it, and remove our reference */
427
428 status = acpi_ex_get_object_reference(operand[0],
429 &return_desc2,
430 walk_state);
431 if (ACPI_FAILURE(status)) {
432 goto cleanup;
433 }
434
435 status =
436 acpi_ex_store(return_desc2, operand[1], walk_state);
437 acpi_ut_remove_reference(return_desc2);
438
439 /* The object exists in the namespace, return TRUE */
440
441 return_desc->integer.value = ACPI_INTEGER_MAX;
442 goto cleanup;
443
444 default:
445 /* No other opcodes get here */
446 break;
447 }
448 break;
449
450 case AML_STORE_OP: /* Store (Source, Target) */
451
452 /*
453 * A store operand is typically a number, string, buffer or lvalue
454 * Be careful about deleting the source object,
455 * since the object itself may have been stored.
456 */
457 status = acpi_ex_store(operand[0], operand[1], walk_state);
458 if (ACPI_FAILURE(status)) {
459 return_ACPI_STATUS(status);
460 }
461
462 /* It is possible that the Store already produced a return object */
463
464 if (!walk_state->result_obj) {
465 /*
466 * Normally, we would remove a reference on the Operand[0]
467 * parameter; But since it is being used as the internal return
468 * object (meaning we would normally increment it), the two
469 * cancel out, and we simply don't do anything.
470 */
471 walk_state->result_obj = operand[0];
472 walk_state->operands[0] = NULL; /* Prevent deletion */
473 }
474 return_ACPI_STATUS(status);
475
476 /*
477 * ACPI 2.0 Opcodes
478 */
479 case AML_COPY_OP: /* Copy (Source, Target) */
480
481 status =
482 acpi_ut_copy_iobject_to_iobject(operand[0], &return_desc,
483 walk_state);
484 break;
485
486 case AML_TO_DECSTRING_OP: /* to_decimal_string (Data, Result) */
487
488 status = acpi_ex_convert_to_string(operand[0], &return_desc,
489 ACPI_EXPLICIT_CONVERT_DECIMAL);
490 if (return_desc == operand[0]) {
491
492 /* No conversion performed, add ref to handle return value */
493 acpi_ut_add_reference(return_desc);
494 }
495 break;
496
497 case AML_TO_HEXSTRING_OP: /* to_hex_string (Data, Result) */
498
499 status = acpi_ex_convert_to_string(operand[0], &return_desc,
500 ACPI_EXPLICIT_CONVERT_HEX);
501 if (return_desc == operand[0]) {
502
503 /* No conversion performed, add ref to handle return value */
504 acpi_ut_add_reference(return_desc);
505 }
506 break;
507
508 case AML_TO_BUFFER_OP: /* to_buffer (Data, Result) */
509
510 status = acpi_ex_convert_to_buffer(operand[0], &return_desc);
511 if (return_desc == operand[0]) {
512
513 /* No conversion performed, add ref to handle return value */
514 acpi_ut_add_reference(return_desc);
515 }
516 break;
517
518 case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */
519
520 status = acpi_ex_convert_to_integer(operand[0], &return_desc,
521 ACPI_ANY_BASE);
522 if (return_desc == operand[0]) {
523
524 /* No conversion performed, add ref to handle return value */
525 acpi_ut_add_reference(return_desc);
526 }
527 break;
528
529 case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */
530 case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */
531
532 /* These are two obsolete opcodes */
533
534 ACPI_ERROR((AE_INFO,
535 "%s is obsolete and not implemented",
536 acpi_ps_get_opcode_name(walk_state->opcode)));
537 status = AE_SUPPORT;
538 goto cleanup;
539
540 default: /* Unknown opcode */
541
542 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
543 walk_state->opcode));
544 status = AE_AML_BAD_OPCODE;
545 goto cleanup;
546 }
547
548 if (ACPI_SUCCESS(status)) {
549
550 /* Store the return value computed above into the target object */
551
552 status = acpi_ex_store(return_desc, operand[1], walk_state);
553 }
554
555 cleanup:
556
557 /* Delete return object on error */
558
559 if (ACPI_FAILURE(status)) {
560 acpi_ut_remove_reference(return_desc);
561 }
562
563 /* Save return object on success */
564
565 else if (!walk_state->result_obj) {
566 walk_state->result_obj = return_desc;
567 }
568
569 return_ACPI_STATUS(status);
570}
571
572/*******************************************************************************
573 *
574 * FUNCTION: acpi_ex_opcode_1A_0T_1R
575 *
576 * PARAMETERS: walk_state - Current state (contains AML opcode)
577 *
578 * RETURN: Status
579 *
580 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
581 *
582 ******************************************************************************/
583
584acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
585{
586 union acpi_operand_object **operand = &walk_state->operands[0];
587 union acpi_operand_object *temp_desc;
588 union acpi_operand_object *return_desc = NULL;
589 acpi_status status = AE_OK;
590 u32 type;
591 acpi_integer value;
592
593 ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_1R,
594 acpi_ps_get_opcode_name(walk_state->opcode));
595
596 /* Examine the AML opcode */
597
598 switch (walk_state->opcode) {
599 case AML_LNOT_OP: /* LNot (Operand) */
600
601 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
602 if (!return_desc) {
603 status = AE_NO_MEMORY;
604 goto cleanup;
605 }
606
607 /*
608 * Set result to ONES (TRUE) if Value == 0. Note:
609 * return_desc->Integer.Value is initially == 0 (FALSE) from above.
610 */
611 if (!operand[0]->integer.value) {
612 return_desc->integer.value = ACPI_INTEGER_MAX;
613 }
614 break;
615
616 case AML_DECREMENT_OP: /* Decrement (Operand) */
617 case AML_INCREMENT_OP: /* Increment (Operand) */
618
619 /*
620 * Create a new integer. Can't just get the base integer and
621 * increment it because it may be an Arg or Field.
622 */
623 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
624 if (!return_desc) {
625 status = AE_NO_MEMORY;
626 goto cleanup;
627 }
628
629 /*
630 * Since we are expecting a Reference operand, it can be either a
631 * NS Node or an internal object.
632 */
633 temp_desc = operand[0];
634 if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
635 ACPI_DESC_TYPE_OPERAND) {
636
637 /* Internal reference object - prevent deletion */
638
639 acpi_ut_add_reference(temp_desc);
640 }
641
642 /*
643 * Convert the Reference operand to an Integer (This removes a
644 * reference on the Operand[0] object)
645 *
646 * NOTE: We use LNOT_OP here in order to force resolution of the
647 * reference operand to an actual integer.
648 */
649 status =
650 acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
651 walk_state);
652 if (ACPI_FAILURE(status)) {
653 ACPI_EXCEPTION((AE_INFO, status,
654 "While resolving operands for [%s]",
655 acpi_ps_get_opcode_name(walk_state->
656 opcode)));
657
658 goto cleanup;
659 }
660
661 /*
662 * temp_desc is now guaranteed to be an Integer object --
663 * Perform the actual increment or decrement
664 */
665 if (walk_state->opcode == AML_INCREMENT_OP) {
666 return_desc->integer.value =
667 temp_desc->integer.value + 1;
668 } else {
669 return_desc->integer.value =
670 temp_desc->integer.value - 1;
671 }
672
673 /* Finished with this Integer object */
674
675 acpi_ut_remove_reference(temp_desc);
676
677 /*
678 * Store the result back (indirectly) through the original
679 * Reference object
680 */
681 status = acpi_ex_store(return_desc, operand[0], walk_state);
682 break;
683
684 case AML_TYPE_OP: /* object_type (source_object) */
685
686 /*
687 * Note: The operand is not resolved at this point because we want to
688 * get the associated object, not its value. For example, we don't
689 * want to resolve a field_unit to its value, we want the actual
690 * field_unit object.
691 */
692
693 /* Get the type of the base object */
694
695 status =
696 acpi_ex_resolve_multiple(walk_state, operand[0], &type,
697 NULL);
698 if (ACPI_FAILURE(status)) {
699 goto cleanup;
700 }
701
702 /* Allocate a descriptor to hold the type. */
703
704 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
705 if (!return_desc) {
706 status = AE_NO_MEMORY;
707 goto cleanup;
708 }
709
710 return_desc->integer.value = type;
711 break;
712
713 case AML_SIZE_OF_OP: /* size_of (source_object) */
714
715 /*
716 * Note: The operand is not resolved at this point because we want to
717 * get the associated object, not its value.
718 */
719
720 /* Get the base object */
721
722 status = acpi_ex_resolve_multiple(walk_state,
723 operand[0], &type,
724 &temp_desc);
725 if (ACPI_FAILURE(status)) {
726 goto cleanup;
727 }
728
729 /*
730 * The type of the base object must be integer, buffer, string, or
731 * package. All others are not supported.
732 *
733 * NOTE: Integer is not specifically supported by the ACPI spec,
734 * but is supported implicitly via implicit operand conversion.
735 * rather than bother with conversion, we just use the byte width
736 * global (4 or 8 bytes).
737 */
738 switch (type) {
739 case ACPI_TYPE_INTEGER:
740 value = acpi_gbl_integer_byte_width;
741 break;
742
743 case ACPI_TYPE_STRING:
744 value = temp_desc->string.length;
745 break;
746
747 case ACPI_TYPE_BUFFER:
748
749 /* Buffer arguments may not be evaluated at this point */
750
751 status = acpi_ds_get_buffer_arguments(temp_desc);
752 value = temp_desc->buffer.length;
753 break;
754
755 case ACPI_TYPE_PACKAGE:
756
757 /* Package arguments may not be evaluated at this point */
758
759 status = acpi_ds_get_package_arguments(temp_desc);
760 value = temp_desc->package.count;
761 break;
762
763 default:
764 ACPI_ERROR((AE_INFO,
765 "Operand must be Buffer/Integer/String/Package - found type %s",
766 acpi_ut_get_type_name(type)));
767 status = AE_AML_OPERAND_TYPE;
768 goto cleanup;
769 }
770
771 if (ACPI_FAILURE(status)) {
772 goto cleanup;
773 }
774
775 /*
776 * Now that we have the size of the object, create a result
777 * object to hold the value
778 */
779 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
780 if (!return_desc) {
781 status = AE_NO_MEMORY;
782 goto cleanup;
783 }
784
785 return_desc->integer.value = value;
786 break;
787
788 case AML_REF_OF_OP: /* ref_of (source_object) */
789
790 status =
791 acpi_ex_get_object_reference(operand[0], &return_desc,
792 walk_state);
793 if (ACPI_FAILURE(status)) {
794 goto cleanup;
795 }
796 break;
797
798 case AML_DEREF_OF_OP: /* deref_of (obj_reference | String) */
799
800 /* Check for a method local or argument, or standalone String */
801
802 if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
803 ACPI_DESC_TYPE_NAMED) {
804 temp_desc =
805 acpi_ns_get_attached_object((struct
806 acpi_namespace_node *)
807 operand[0]);
808 if (temp_desc
809 &&
810 ((ACPI_GET_OBJECT_TYPE(temp_desc) ==
811 ACPI_TYPE_STRING)
812 || (ACPI_GET_OBJECT_TYPE(temp_desc) ==
813 ACPI_TYPE_LOCAL_REFERENCE))) {
814 operand[0] = temp_desc;
815 acpi_ut_add_reference(temp_desc);
816 } else {
817 status = AE_AML_OPERAND_TYPE;
818 goto cleanup;
819 }
820 } else {
821 switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
822 case ACPI_TYPE_LOCAL_REFERENCE:
823 /*
824 * This is a deref_of (local_x | arg_x)
825 *
826 * Must resolve/dereference the local/arg reference first
827 */
828 switch (operand[0]->reference.class) {
829 case ACPI_REFCLASS_LOCAL:
830 case ACPI_REFCLASS_ARG:
831
832 /* Set Operand[0] to the value of the local/arg */
833
834 status =
835 acpi_ds_method_data_get_value
836 (operand[0]->reference.class,
837 operand[0]->reference.value,
838 walk_state, &temp_desc);
839 if (ACPI_FAILURE(status)) {
840 goto cleanup;
841 }
842
843 /*
844 * Delete our reference to the input object and
845 * point to the object just retrieved
846 */
847 acpi_ut_remove_reference(operand[0]);
848 operand[0] = temp_desc;
849 break;
850
851 case ACPI_REFCLASS_REFOF:
852
853 /* Get the object to which the reference refers */
854
855 temp_desc =
856 operand[0]->reference.object;
857 acpi_ut_remove_reference(operand[0]);
858 operand[0] = temp_desc;
859 break;
860
861 default:
862
863 /* Must be an Index op - handled below */
864 break;
865 }
866 break;
867
868 case ACPI_TYPE_STRING:
869 break;
870
871 default:
872 status = AE_AML_OPERAND_TYPE;
873 goto cleanup;
874 }
875 }
876
877 if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
878 ACPI_DESC_TYPE_NAMED) {
879 if (ACPI_GET_OBJECT_TYPE(operand[0]) ==
880 ACPI_TYPE_STRING) {
881 /*
882 * This is a deref_of (String). The string is a reference
883 * to a named ACPI object.
884 *
885 * 1) Find the owning Node
886 * 2) Dereference the node to an actual object. Could be a
887 * Field, so we need to resolve the node to a value.
888 */
889 status =
890 acpi_ns_get_node(walk_state->scope_info->
891 scope.node,
892 operand[0]->string.pointer,
893 ACPI_NS_SEARCH_PARENT,
894 ACPI_CAST_INDIRECT_PTR
895 (struct
896 acpi_namespace_node,
897 &return_desc));
898 if (ACPI_FAILURE(status)) {
899 goto cleanup;
900 }
901
902 status =
903 acpi_ex_resolve_node_to_value
904 (ACPI_CAST_INDIRECT_PTR
905 (struct acpi_namespace_node, &return_desc),
906 walk_state);
907 goto cleanup;
908 }
909 }
910
911 /* Operand[0] may have changed from the code above */
912
913 if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
914 ACPI_DESC_TYPE_NAMED) {
915 /*
916 * This is a deref_of (object_reference)
917 * Get the actual object from the Node (This is the dereference).
918 * This case may only happen when a local_x or arg_x is
919 * dereferenced above.
920 */
921 return_desc = acpi_ns_get_attached_object((struct
922 acpi_namespace_node
923 *)
924 operand[0]);
925 acpi_ut_add_reference(return_desc);
926 } else {
927 /*
928 * This must be a reference object produced by either the
929 * Index() or ref_of() operator
930 */
931 switch (operand[0]->reference.class) {
932 case ACPI_REFCLASS_INDEX:
933
934 /*
935 * The target type for the Index operator must be
936 * either a Buffer or a Package
937 */
938 switch (operand[0]->reference.target_type) {
939 case ACPI_TYPE_BUFFER_FIELD:
940
941 temp_desc =
942 operand[0]->reference.object;
943
944 /*
945 * Create a new object that contains one element of the
946 * buffer -- the element pointed to by the index.
947 *
948 * NOTE: index into a buffer is NOT a pointer to a
949 * sub-buffer of the main buffer, it is only a pointer to a
950 * single element (byte) of the buffer!
951 */
952 return_desc =
953 acpi_ut_create_internal_object
954 (ACPI_TYPE_INTEGER);
955 if (!return_desc) {
956 status = AE_NO_MEMORY;
957 goto cleanup;
958 }
959
960 /*
961 * Since we are returning the value of the buffer at the
962 * indexed location, we don't need to add an additional
963 * reference to the buffer itself.
964 */
965 return_desc->integer.value =
966 temp_desc->buffer.
967 pointer[operand[0]->reference.
968 value];
969 break;
970
971 case ACPI_TYPE_PACKAGE:
972
973 /*
974 * Return the referenced element of the package. We must
975 * add another reference to the referenced object, however.
976 */
977 return_desc =
978 *(operand[0]->reference.where);
979 if (return_desc) {
980 acpi_ut_add_reference
981 (return_desc);
982 }
983 break;
984
985 default:
986
987 ACPI_ERROR((AE_INFO,
988 "Unknown Index TargetType %X in reference object %p",
989 operand[0]->reference.
990 target_type, operand[0]));
991 status = AE_AML_OPERAND_TYPE;
992 goto cleanup;
993 }
994 break;
995
996 case ACPI_REFCLASS_REFOF:
997
998 return_desc = operand[0]->reference.object;
999
1000 if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) ==
1001 ACPI_DESC_TYPE_NAMED) {
1002 return_desc =
1003 acpi_ns_get_attached_object((struct
1004 acpi_namespace_node
1005 *)
1006 return_desc);
1007 }
1008
1009 /* Add another reference to the object! */
1010
1011 acpi_ut_add_reference(return_desc);
1012 break;
1013
1014 default:
1015 ACPI_ERROR((AE_INFO,
1016 "Unknown class in reference(%p) - %2.2X",
1017 operand[0],
1018 operand[0]->reference.class));
1019
1020 status = AE_TYPE;
1021 goto cleanup;
1022 }
1023 }
1024 break;
1025
1026 default:
1027
1028 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
1029 walk_state->opcode));
1030 status = AE_AML_BAD_OPCODE;
1031 goto cleanup;
1032 }
1033
1034 cleanup:
1035
1036 /* Delete return object on error */
1037
1038 if (ACPI_FAILURE(status)) {
1039 acpi_ut_remove_reference(return_desc);
1040 }
1041
1042 /* Save return object on success */
1043
1044 else {
1045 walk_state->result_obj = return_desc;
1046 }
1047
1048 return_ACPI_STATUS(status);
1049}
diff --git a/drivers/acpi/executer/exoparg2.c b/drivers/acpi/executer/exoparg2.c
deleted file mode 100644
index 368def5dffce..000000000000
--- a/drivers/acpi/executer/exoparg2.c
+++ /dev/null
@@ -1,604 +0,0 @@
1/******************************************************************************
2 *
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2008, 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 <acpi/acparser.h>
46#include <acpi/acinterp.h>
47#include <acpi/acevents.h>
48#include <acpi/amlcode.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exoparg2")
52
53/*!
54 * Naming convention for AML interpreter execution routines.
55 *
56 * The routines that begin execution of AML opcodes are named with a common
57 * convention based upon the number of arguments, the number of target operands,
58 * and whether or not a value is returned:
59 *
60 * AcpiExOpcode_xA_yT_zR
61 *
62 * Where:
63 *
64 * xA - ARGUMENTS: The number of arguments (input operands) that are
65 * required for this opcode type (1 through 6 args).
66 * yT - TARGETS: The number of targets (output operands) that are required
67 * for this opcode type (0, 1, or 2 targets).
68 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
69 * as the function return (0 or 1).
70 *
71 * The AcpiExOpcode* functions are called via the Dispatcher component with
72 * fully resolved operands.
73!*/
74/*******************************************************************************
75 *
76 * FUNCTION: acpi_ex_opcode_2A_0T_0R
77 *
78 * PARAMETERS: walk_state - Current walk state
79 *
80 * RETURN: Status
81 *
82 * DESCRIPTION: Execute opcode with two arguments, no target, and no return
83 * value.
84 *
85 * ALLOCATION: Deletes both operands
86 *
87 ******************************************************************************/
88acpi_status acpi_ex_opcode_2A_0T_0R(struct acpi_walk_state *walk_state)
89{
90 union acpi_operand_object **operand = &walk_state->operands[0];
91 struct acpi_namespace_node *node;
92 u32 value;
93 acpi_status status = AE_OK;
94
95 ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_0T_0R,
96 acpi_ps_get_opcode_name(walk_state->opcode));
97
98 /* Examine the opcode */
99
100 switch (walk_state->opcode) {
101 case AML_NOTIFY_OP: /* Notify (notify_object, notify_value) */
102
103 /* The first operand is a namespace node */
104
105 node = (struct acpi_namespace_node *)operand[0];
106
107 /* Second value is the notify value */
108
109 value = (u32) operand[1]->integer.value;
110
111 /* Are notifies allowed on this object? */
112
113 if (!acpi_ev_is_notify_object(node)) {
114 ACPI_ERROR((AE_INFO,
115 "Unexpected notify object type [%s]",
116 acpi_ut_get_type_name(node->type)));
117
118 status = AE_AML_OPERAND_TYPE;
119 break;
120 }
121#ifdef ACPI_GPE_NOTIFY_CHECK
122 /*
123 * GPE method wake/notify check. Here, we want to ensure that we
124 * don't receive any "DeviceWake" Notifies from a GPE _Lxx or _Exx
125 * GPE method during system runtime. If we do, the GPE is marked
126 * as "wake-only" and disabled.
127 *
128 * 1) Is the Notify() value == device_wake?
129 * 2) Is this a GPE deferred method? (An _Lxx or _Exx method)
130 * 3) Did the original GPE happen at system runtime?
131 * (versus during wake)
132 *
133 * If all three cases are true, this is a wake-only GPE that should
134 * be disabled at runtime.
135 */
136 if (value == 2) { /* device_wake */
137 status =
138 acpi_ev_check_for_wake_only_gpe(walk_state->
139 gpe_event_info);
140 if (ACPI_FAILURE(status)) {
141
142 /* AE_WAKE_ONLY_GPE only error, means ignore this notify */
143
144 return_ACPI_STATUS(AE_OK)
145 }
146 }
147#endif
148
149 /*
150 * Dispatch the notify to the appropriate handler
151 * NOTE: the request is queued for execution after this method
152 * completes. The notify handlers are NOT invoked synchronously
153 * from this thread -- because handlers may in turn run other
154 * control methods.
155 */
156 status = acpi_ev_queue_notify_request(node, value);
157 break;
158
159 default:
160
161 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
162 walk_state->opcode));
163 status = AE_AML_BAD_OPCODE;
164 }
165
166 return_ACPI_STATUS(status);
167}
168
169/*******************************************************************************
170 *
171 * FUNCTION: acpi_ex_opcode_2A_2T_1R
172 *
173 * PARAMETERS: walk_state - Current walk state
174 *
175 * RETURN: Status
176 *
177 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
178 * and one implicit return value.
179 *
180 ******************************************************************************/
181
182acpi_status acpi_ex_opcode_2A_2T_1R(struct acpi_walk_state *walk_state)
183{
184 union acpi_operand_object **operand = &walk_state->operands[0];
185 union acpi_operand_object *return_desc1 = NULL;
186 union acpi_operand_object *return_desc2 = NULL;
187 acpi_status status;
188
189 ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_2T_1R,
190 acpi_ps_get_opcode_name(walk_state->opcode));
191
192 /* Execute the opcode */
193
194 switch (walk_state->opcode) {
195 case AML_DIVIDE_OP:
196
197 /* Divide (Dividend, Divisor, remainder_result quotient_result) */
198
199 return_desc1 =
200 acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
201 if (!return_desc1) {
202 status = AE_NO_MEMORY;
203 goto cleanup;
204 }
205
206 return_desc2 =
207 acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
208 if (!return_desc2) {
209 status = AE_NO_MEMORY;
210 goto cleanup;
211 }
212
213 /* Quotient to return_desc1, remainder to return_desc2 */
214
215 status = acpi_ut_divide(operand[0]->integer.value,
216 operand[1]->integer.value,
217 &return_desc1->integer.value,
218 &return_desc2->integer.value);
219 if (ACPI_FAILURE(status)) {
220 goto cleanup;
221 }
222 break;
223
224 default:
225
226 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
227 walk_state->opcode));
228 status = AE_AML_BAD_OPCODE;
229 goto cleanup;
230 }
231
232 /* Store the results to the target reference operands */
233
234 status = acpi_ex_store(return_desc2, operand[2], walk_state);
235 if (ACPI_FAILURE(status)) {
236 goto cleanup;
237 }
238
239 status = acpi_ex_store(return_desc1, operand[3], walk_state);
240 if (ACPI_FAILURE(status)) {
241 goto cleanup;
242 }
243
244 cleanup:
245 /*
246 * Since the remainder is not returned indirectly, remove a reference to
247 * it. Only the quotient is returned indirectly.
248 */
249 acpi_ut_remove_reference(return_desc2);
250
251 if (ACPI_FAILURE(status)) {
252
253 /* Delete the return object */
254
255 acpi_ut_remove_reference(return_desc1);
256 }
257
258 /* Save return object (the remainder) on success */
259
260 else {
261 walk_state->result_obj = return_desc1;
262 }
263
264 return_ACPI_STATUS(status);
265}
266
267/*******************************************************************************
268 *
269 * FUNCTION: acpi_ex_opcode_2A_1T_1R
270 *
271 * PARAMETERS: walk_state - Current walk state
272 *
273 * RETURN: Status
274 *
275 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
276 * value.
277 *
278 ******************************************************************************/
279
280acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
281{
282 union acpi_operand_object **operand = &walk_state->operands[0];
283 union acpi_operand_object *return_desc = NULL;
284 acpi_integer index;
285 acpi_status status = AE_OK;
286 acpi_size length;
287
288 ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_1T_1R,
289 acpi_ps_get_opcode_name(walk_state->opcode));
290
291 /* Execute the opcode */
292
293 if (walk_state->op_info->flags & AML_MATH) {
294
295 /* All simple math opcodes (add, etc.) */
296
297 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
298 if (!return_desc) {
299 status = AE_NO_MEMORY;
300 goto cleanup;
301 }
302
303 return_desc->integer.value =
304 acpi_ex_do_math_op(walk_state->opcode,
305 operand[0]->integer.value,
306 operand[1]->integer.value);
307 goto store_result_to_target;
308 }
309
310 switch (walk_state->opcode) {
311 case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */
312
313 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
314 if (!return_desc) {
315 status = AE_NO_MEMORY;
316 goto cleanup;
317 }
318
319 /* return_desc will contain the remainder */
320
321 status = acpi_ut_divide(operand[0]->integer.value,
322 operand[1]->integer.value,
323 NULL, &return_desc->integer.value);
324 break;
325
326 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
327
328 status = acpi_ex_do_concatenate(operand[0], operand[1],
329 &return_desc, walk_state);
330 break;
331
332 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */
333
334 /*
335 * Input object is guaranteed to be a buffer at this point (it may have
336 * been converted.) Copy the raw buffer data to a new object of
337 * type String.
338 */
339
340 /*
341 * Get the length of the new string. It is the smallest of:
342 * 1) Length of the input buffer
343 * 2) Max length as specified in the to_string operator
344 * 3) Length of input buffer up to a zero byte (null terminator)
345 *
346 * NOTE: A length of zero is ok, and will create a zero-length, null
347 * terminated string.
348 */
349 length = 0;
350 while ((length < operand[0]->buffer.length) &&
351 (length < operand[1]->integer.value) &&
352 (operand[0]->buffer.pointer[length])) {
353 length++;
354 }
355
356 /* Allocate a new string object */
357
358 return_desc = acpi_ut_create_string_object(length);
359 if (!return_desc) {
360 status = AE_NO_MEMORY;
361 goto cleanup;
362 }
363
364 /*
365 * Copy the raw buffer data with no transform.
366 * (NULL terminated already)
367 */
368 ACPI_MEMCPY(return_desc->string.pointer,
369 operand[0]->buffer.pointer, length);
370 break;
371
372 case AML_CONCAT_RES_OP:
373
374 /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */
375
376 status = acpi_ex_concat_template(operand[0], operand[1],
377 &return_desc, walk_state);
378 break;
379
380 case AML_INDEX_OP: /* Index (Source Index Result) */
381
382 /* Create the internal return object */
383
384 return_desc =
385 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
386 if (!return_desc) {
387 status = AE_NO_MEMORY;
388 goto cleanup;
389 }
390
391 /* Initialize the Index reference object */
392
393 index = operand[1]->integer.value;
394 return_desc->reference.value = (u32) index;
395 return_desc->reference.class = ACPI_REFCLASS_INDEX;
396
397 /*
398 * At this point, the Source operand is a String, Buffer, or Package.
399 * Verify that the index is within range.
400 */
401 switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
402 case ACPI_TYPE_STRING:
403
404 if (index >= operand[0]->string.length) {
405 status = AE_AML_STRING_LIMIT;
406 }
407
408 return_desc->reference.target_type =
409 ACPI_TYPE_BUFFER_FIELD;
410 break;
411
412 case ACPI_TYPE_BUFFER:
413
414 if (index >= operand[0]->buffer.length) {
415 status = AE_AML_BUFFER_LIMIT;
416 }
417
418 return_desc->reference.target_type =
419 ACPI_TYPE_BUFFER_FIELD;
420 break;
421
422 case ACPI_TYPE_PACKAGE:
423
424 if (index >= operand[0]->package.count) {
425 status = AE_AML_PACKAGE_LIMIT;
426 }
427
428 return_desc->reference.target_type = ACPI_TYPE_PACKAGE;
429 return_desc->reference.where =
430 &operand[0]->package.elements[index];
431 break;
432
433 default:
434
435 status = AE_AML_INTERNAL;
436 goto cleanup;
437 }
438
439 /* Failure means that the Index was beyond the end of the object */
440
441 if (ACPI_FAILURE(status)) {
442 ACPI_EXCEPTION((AE_INFO, status,
443 "Index (%X%8.8X) is beyond end of object",
444 ACPI_FORMAT_UINT64(index)));
445 goto cleanup;
446 }
447
448 /*
449 * Save the target object and add a reference to it for the life
450 * of the index
451 */
452 return_desc->reference.object = operand[0];
453 acpi_ut_add_reference(operand[0]);
454
455 /* Store the reference to the Target */
456
457 status = acpi_ex_store(return_desc, operand[2], walk_state);
458
459 /* Return the reference */
460
461 walk_state->result_obj = return_desc;
462 goto cleanup;
463
464 default:
465
466 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
467 walk_state->opcode));
468 status = AE_AML_BAD_OPCODE;
469 break;
470 }
471
472 store_result_to_target:
473
474 if (ACPI_SUCCESS(status)) {
475 /*
476 * Store the result of the operation (which is now in return_desc) into
477 * the Target descriptor.
478 */
479 status = acpi_ex_store(return_desc, operand[2], walk_state);
480 if (ACPI_FAILURE(status)) {
481 goto cleanup;
482 }
483
484 if (!walk_state->result_obj) {
485 walk_state->result_obj = return_desc;
486 }
487 }
488
489 cleanup:
490
491 /* Delete return object on error */
492
493 if (ACPI_FAILURE(status)) {
494 acpi_ut_remove_reference(return_desc);
495 walk_state->result_obj = NULL;
496 }
497
498 return_ACPI_STATUS(status);
499}
500
501/*******************************************************************************
502 *
503 * FUNCTION: acpi_ex_opcode_2A_0T_1R
504 *
505 * PARAMETERS: walk_state - Current walk state
506 *
507 * RETURN: Status
508 *
509 * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
510 *
511 ******************************************************************************/
512
513acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state)
514{
515 union acpi_operand_object **operand = &walk_state->operands[0];
516 union acpi_operand_object *return_desc = NULL;
517 acpi_status status = AE_OK;
518 u8 logical_result = FALSE;
519
520 ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_0T_1R,
521 acpi_ps_get_opcode_name(walk_state->opcode));
522
523 /* Create the internal return object */
524
525 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
526 if (!return_desc) {
527 status = AE_NO_MEMORY;
528 goto cleanup;
529 }
530
531 /* Execute the Opcode */
532
533 if (walk_state->op_info->flags & AML_LOGICAL_NUMERIC) {
534
535 /* logical_op (Operand0, Operand1) */
536
537 status = acpi_ex_do_logical_numeric_op(walk_state->opcode,
538 operand[0]->integer.
539 value,
540 operand[1]->integer.
541 value, &logical_result);
542 goto store_logical_result;
543 } else if (walk_state->op_info->flags & AML_LOGICAL) {
544
545 /* logical_op (Operand0, Operand1) */
546
547 status = acpi_ex_do_logical_op(walk_state->opcode, operand[0],
548 operand[1], &logical_result);
549 goto store_logical_result;
550 }
551
552 switch (walk_state->opcode) {
553 case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */
554
555 status =
556 acpi_ex_acquire_mutex(operand[1], operand[0], walk_state);
557 if (status == AE_TIME) {
558 logical_result = TRUE; /* TRUE = Acquire timed out */
559 status = AE_OK;
560 }
561 break;
562
563 case AML_WAIT_OP: /* Wait (event_object, Timeout) */
564
565 status = acpi_ex_system_wait_event(operand[1], operand[0]);
566 if (status == AE_TIME) {
567 logical_result = TRUE; /* TRUE, Wait timed out */
568 status = AE_OK;
569 }
570 break;
571
572 default:
573
574 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
575 walk_state->opcode));
576 status = AE_AML_BAD_OPCODE;
577 goto cleanup;
578 }
579
580 store_logical_result:
581 /*
582 * Set return value to according to logical_result. logical TRUE (all ones)
583 * Default is FALSE (zero)
584 */
585 if (logical_result) {
586 return_desc->integer.value = ACPI_INTEGER_MAX;
587 }
588
589 cleanup:
590
591 /* Delete return object on error */
592
593 if (ACPI_FAILURE(status)) {
594 acpi_ut_remove_reference(return_desc);
595 }
596
597 /* Save return object on success */
598
599 else {
600 walk_state->result_obj = return_desc;
601 }
602
603 return_ACPI_STATUS(status);
604}
diff --git a/drivers/acpi/executer/exoparg3.c b/drivers/acpi/executer/exoparg3.c
deleted file mode 100644
index 9cb4197681af..000000000000
--- a/drivers/acpi/executer/exoparg3.c
+++ /dev/null
@@ -1,272 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/acparser.h>
48#include <acpi/amlcode.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exoparg3")
52
53/*!
54 * Naming convention for AML interpreter execution routines.
55 *
56 * The routines that begin execution of AML opcodes are named with a common
57 * convention based upon the number of arguments, the number of target operands,
58 * and whether or not a value is returned:
59 *
60 * AcpiExOpcode_xA_yT_zR
61 *
62 * Where:
63 *
64 * xA - ARGUMENTS: The number of arguments (input operands) that are
65 * required for this opcode type (1 through 6 args).
66 * yT - TARGETS: The number of targets (output operands) that are required
67 * for this opcode type (0, 1, or 2 targets).
68 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
69 * as the function return (0 or 1).
70 *
71 * The AcpiExOpcode* functions are called via the Dispatcher component with
72 * fully resolved operands.
73!*/
74/*******************************************************************************
75 *
76 * FUNCTION: acpi_ex_opcode_3A_0T_0R
77 *
78 * PARAMETERS: walk_state - Current walk state
79 *
80 * RETURN: Status
81 *
82 * DESCRIPTION: Execute Triadic operator (3 operands)
83 *
84 ******************************************************************************/
85acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
86{
87 union acpi_operand_object **operand = &walk_state->operands[0];
88 struct acpi_signal_fatal_info *fatal;
89 acpi_status status = AE_OK;
90
91 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
92 acpi_ps_get_opcode_name(walk_state->opcode));
93
94 switch (walk_state->opcode) {
95 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
96
97 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
98 "FatalOp: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
99 (u32) operand[0]->integer.value,
100 (u32) operand[1]->integer.value,
101 (u32) operand[2]->integer.value));
102
103 fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
104 if (fatal) {
105 fatal->type = (u32) operand[0]->integer.value;
106 fatal->code = (u32) operand[1]->integer.value;
107 fatal->argument = (u32) operand[2]->integer.value;
108 }
109
110 /* Always signal the OS! */
111
112 status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
113
114 /* Might return while OS is shutting down, just continue */
115
116 ACPI_FREE(fatal);
117 break;
118
119 default:
120
121 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
122 walk_state->opcode));
123 status = AE_AML_BAD_OPCODE;
124 goto cleanup;
125 }
126
127 cleanup:
128
129 return_ACPI_STATUS(status);
130}
131
132/*******************************************************************************
133 *
134 * FUNCTION: acpi_ex_opcode_3A_1T_1R
135 *
136 * PARAMETERS: walk_state - Current walk state
137 *
138 * RETURN: Status
139 *
140 * DESCRIPTION: Execute Triadic operator (3 operands)
141 *
142 ******************************************************************************/
143
144acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
145{
146 union acpi_operand_object **operand = &walk_state->operands[0];
147 union acpi_operand_object *return_desc = NULL;
148 char *buffer = NULL;
149 acpi_status status = AE_OK;
150 acpi_integer index;
151 acpi_size length;
152
153 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
154 acpi_ps_get_opcode_name(walk_state->opcode));
155
156 switch (walk_state->opcode) {
157 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
158
159 /*
160 * Create the return object. The Source operand is guaranteed to be
161 * either a String or a Buffer, so just use its type.
162 */
163 return_desc =
164 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE
165 (operand[0]));
166 if (!return_desc) {
167 status = AE_NO_MEMORY;
168 goto cleanup;
169 }
170
171 /* Get the Integer values from the objects */
172
173 index = operand[1]->integer.value;
174 length = (acpi_size) operand[2]->integer.value;
175
176 /*
177 * If the index is beyond the length of the String/Buffer, or if the
178 * requested length is zero, return a zero-length String/Buffer
179 */
180 if (index >= operand[0]->string.length) {
181 length = 0;
182 }
183
184 /* Truncate request if larger than the actual String/Buffer */
185
186 else if ((index + length) > operand[0]->string.length) {
187 length = (acpi_size) operand[0]->string.length -
188 (acpi_size) index;
189 }
190
191 /* Strings always have a sub-pointer, not so for buffers */
192
193 switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
194 case ACPI_TYPE_STRING:
195
196 /* Always allocate a new buffer for the String */
197
198 buffer = ACPI_ALLOCATE_ZEROED((acpi_size) length + 1);
199 if (!buffer) {
200 status = AE_NO_MEMORY;
201 goto cleanup;
202 }
203 break;
204
205 case ACPI_TYPE_BUFFER:
206
207 /* If the requested length is zero, don't allocate a buffer */
208
209 if (length > 0) {
210
211 /* Allocate a new buffer for the Buffer */
212
213 buffer = ACPI_ALLOCATE_ZEROED(length);
214 if (!buffer) {
215 status = AE_NO_MEMORY;
216 goto cleanup;
217 }
218 }
219 break;
220
221 default: /* Should not happen */
222
223 status = AE_AML_OPERAND_TYPE;
224 goto cleanup;
225 }
226
227 if (buffer) {
228
229 /* We have a buffer, copy the portion requested */
230
231 ACPI_MEMCPY(buffer, operand[0]->string.pointer + index,
232 length);
233 }
234
235 /* Set the length of the new String/Buffer */
236
237 return_desc->string.pointer = buffer;
238 return_desc->string.length = (u32) length;
239
240 /* Mark buffer initialized */
241
242 return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
243 break;
244
245 default:
246
247 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
248 walk_state->opcode));
249 status = AE_AML_BAD_OPCODE;
250 goto cleanup;
251 }
252
253 /* Store the result in the target */
254
255 status = acpi_ex_store(return_desc, operand[3], walk_state);
256
257 cleanup:
258
259 /* Delete return object on error */
260
261 if (ACPI_FAILURE(status) || walk_state->result_obj) {
262 acpi_ut_remove_reference(return_desc);
263 walk_state->result_obj = NULL;
264 }
265
266 /* Set the return object and exit */
267
268 else {
269 walk_state->result_obj = return_desc;
270 }
271 return_ACPI_STATUS(status);
272}
diff --git a/drivers/acpi/executer/exoparg6.c b/drivers/acpi/executer/exoparg6.c
deleted file mode 100644
index 67d48737af53..000000000000
--- a/drivers/acpi/executer/exoparg6.c
+++ /dev/null
@@ -1,340 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/acparser.h>
48#include <acpi/amlcode.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exoparg6")
52
53/*!
54 * Naming convention for AML interpreter execution routines.
55 *
56 * The routines that begin execution of AML opcodes are named with a common
57 * convention based upon the number of arguments, the number of target operands,
58 * and whether or not a value is returned:
59 *
60 * AcpiExOpcode_xA_yT_zR
61 *
62 * Where:
63 *
64 * xA - ARGUMENTS: The number of arguments (input operands) that are
65 * required for this opcode type (1 through 6 args).
66 * yT - TARGETS: The number of targets (output operands) that are required
67 * for this opcode type (0, 1, or 2 targets).
68 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
69 * as the function return (0 or 1).
70 *
71 * The AcpiExOpcode* functions are called via the Dispatcher component with
72 * fully resolved operands.
73!*/
74/* Local prototypes */
75static u8
76acpi_ex_do_match(u32 match_op,
77 union acpi_operand_object *package_obj,
78 union acpi_operand_object *match_obj);
79
80/*******************************************************************************
81 *
82 * FUNCTION: acpi_ex_do_match
83 *
84 * PARAMETERS: match_op - The AML match operand
85 * package_obj - Object from the target package
86 * match_obj - Object to be matched
87 *
88 * RETURN: TRUE if the match is successful, FALSE otherwise
89 *
90 * DESCRIPTION: Implements the low-level match for the ASL Match operator.
91 * Package elements will be implicitly converted to the type of
92 * the match object (Integer/Buffer/String).
93 *
94 ******************************************************************************/
95
96static u8
97acpi_ex_do_match(u32 match_op,
98 union acpi_operand_object *package_obj,
99 union acpi_operand_object *match_obj)
100{
101 u8 logical_result = TRUE;
102 acpi_status status;
103
104 /*
105 * Note: Since the package_obj/match_obj ordering is opposite to that of
106 * the standard logical operators, we have to reverse them when we call
107 * do_logical_op in order to make the implicit conversion rules work
108 * correctly. However, this means we have to flip the entire equation
109 * also. A bit ugly perhaps, but overall, better than fussing the
110 * parameters around at runtime, over and over again.
111 *
112 * Below, P[i] refers to the package element, M refers to the Match object.
113 */
114 switch (match_op) {
115 case MATCH_MTR:
116
117 /* Always true */
118
119 break;
120
121 case MATCH_MEQ:
122
123 /*
124 * True if equal: (P[i] == M)
125 * Change to: (M == P[i])
126 */
127 status =
128 acpi_ex_do_logical_op(AML_LEQUAL_OP, match_obj, package_obj,
129 &logical_result);
130 if (ACPI_FAILURE(status)) {
131 return (FALSE);
132 }
133 break;
134
135 case MATCH_MLE:
136
137 /*
138 * True if less than or equal: (P[i] <= M) (P[i] not_greater than M)
139 * Change to: (M >= P[i]) (M not_less than P[i])
140 */
141 status =
142 acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
143 &logical_result);
144 if (ACPI_FAILURE(status)) {
145 return (FALSE);
146 }
147 logical_result = (u8) ! logical_result;
148 break;
149
150 case MATCH_MLT:
151
152 /*
153 * True if less than: (P[i] < M)
154 * Change to: (M > P[i])
155 */
156 status =
157 acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
158 package_obj, &logical_result);
159 if (ACPI_FAILURE(status)) {
160 return (FALSE);
161 }
162 break;
163
164 case MATCH_MGE:
165
166 /*
167 * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
168 * Change to: (M <= P[i]) (M not_greater than P[i])
169 */
170 status =
171 acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
172 package_obj, &logical_result);
173 if (ACPI_FAILURE(status)) {
174 return (FALSE);
175 }
176 logical_result = (u8) ! logical_result;
177 break;
178
179 case MATCH_MGT:
180
181 /*
182 * True if greater than: (P[i] > M)
183 * Change to: (M < P[i])
184 */
185 status =
186 acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
187 &logical_result);
188 if (ACPI_FAILURE(status)) {
189 return (FALSE);
190 }
191 break;
192
193 default:
194
195 /* Undefined */
196
197 return (FALSE);
198 }
199
200 return logical_result;
201}
202
203/*******************************************************************************
204 *
205 * FUNCTION: acpi_ex_opcode_6A_0T_1R
206 *
207 * PARAMETERS: walk_state - Current walk state
208 *
209 * RETURN: Status
210 *
211 * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
212 *
213 ******************************************************************************/
214
215acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
216{
217 union acpi_operand_object **operand = &walk_state->operands[0];
218 union acpi_operand_object *return_desc = NULL;
219 acpi_status status = AE_OK;
220 acpi_integer index;
221 union acpi_operand_object *this_element;
222
223 ACPI_FUNCTION_TRACE_STR(ex_opcode_6A_0T_1R,
224 acpi_ps_get_opcode_name(walk_state->opcode));
225
226 switch (walk_state->opcode) {
227 case AML_MATCH_OP:
228 /*
229 * Match (search_pkg[0], match_op1[1], match_obj1[2],
230 * match_op2[3], match_obj2[4], start_index[5])
231 */
232
233 /* Validate both Match Term Operators (MTR, MEQ, etc.) */
234
235 if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
236 (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
237 ACPI_ERROR((AE_INFO, "Match operator out of range"));
238 status = AE_AML_OPERAND_VALUE;
239 goto cleanup;
240 }
241
242 /* Get the package start_index, validate against the package length */
243
244 index = operand[5]->integer.value;
245 if (index >= operand[0]->package.count) {
246 ACPI_ERROR((AE_INFO,
247 "Index (%X%8.8X) beyond package end (%X)",
248 ACPI_FORMAT_UINT64(index),
249 operand[0]->package.count));
250 status = AE_AML_PACKAGE_LIMIT;
251 goto cleanup;
252 }
253
254 /* Create an integer for the return value */
255
256 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
257 if (!return_desc) {
258 status = AE_NO_MEMORY;
259 goto cleanup;
260
261 }
262
263 /* Default return value if no match found */
264
265 return_desc->integer.value = ACPI_INTEGER_MAX;
266
267 /*
268 * Examine each element until a match is found. Both match conditions
269 * must be satisfied for a match to occur. Within the loop,
270 * "continue" signifies that the current element does not match
271 * and the next should be examined.
272 *
273 * Upon finding a match, the loop will terminate via "break" at
274 * the bottom. If it terminates "normally", match_value will be
275 * ACPI_INTEGER_MAX (Ones) (its initial value) indicating that no
276 * match was found.
277 */
278 for (; index < operand[0]->package.count; index++) {
279
280 /* Get the current package element */
281
282 this_element = operand[0]->package.elements[index];
283
284 /* Treat any uninitialized (NULL) elements as non-matching */
285
286 if (!this_element) {
287 continue;
288 }
289
290 /*
291 * Both match conditions must be satisfied. Execution of a continue
292 * (proceed to next iteration of enclosing for loop) signifies a
293 * non-match.
294 */
295 if (!acpi_ex_do_match((u32) operand[1]->integer.value,
296 this_element, operand[2])) {
297 continue;
298 }
299
300 if (!acpi_ex_do_match((u32) operand[3]->integer.value,
301 this_element, operand[4])) {
302 continue;
303 }
304
305 /* Match found: Index is the return value */
306
307 return_desc->integer.value = index;
308 break;
309 }
310 break;
311
312 case AML_LOAD_TABLE_OP:
313
314 status = acpi_ex_load_table_op(walk_state, &return_desc);
315 break;
316
317 default:
318
319 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
320 walk_state->opcode));
321 status = AE_AML_BAD_OPCODE;
322 goto cleanup;
323 }
324
325 cleanup:
326
327 /* Delete return object on error */
328
329 if (ACPI_FAILURE(status)) {
330 acpi_ut_remove_reference(return_desc);
331 }
332
333 /* Save return object on success */
334
335 else {
336 walk_state->result_obj = return_desc;
337 }
338
339 return_ACPI_STATUS(status);
340}
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
deleted file mode 100644
index a7dc87ecee37..000000000000
--- a/drivers/acpi/executer/exprep.c
+++ /dev/null
@@ -1,589 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/amlcode.h>
48#include <acpi/acnamesp.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exprep")
52
53/* Local prototypes */
54static u32
55acpi_ex_decode_field_access(union acpi_operand_object *obj_desc,
56 u8 field_flags, u32 * return_byte_alignment);
57
58#ifdef ACPI_UNDER_DEVELOPMENT
59
60static u32
61acpi_ex_generate_access(u32 field_bit_offset,
62 u32 field_bit_length, u32 region_length);
63
64/*******************************************************************************
65 *
66 * FUNCTION: acpi_ex_generate_access
67 *
68 * PARAMETERS: field_bit_offset - Start of field within parent region/buffer
69 * field_bit_length - Length of field in bits
70 * region_length - Length of parent in bytes
71 *
72 * RETURN: Field granularity (8, 16, 32 or 64) and
73 * byte_alignment (1, 2, 3, or 4)
74 *
75 * DESCRIPTION: Generate an optimal access width for fields defined with the
76 * any_acc keyword.
77 *
78 * NOTE: Need to have the region_length in order to check for boundary
79 * conditions (end-of-region). However, the region_length is a deferred
80 * operation. Therefore, to complete this implementation, the generation
81 * of this access width must be deferred until the region length has
82 * been evaluated.
83 *
84 ******************************************************************************/
85
86static u32
87acpi_ex_generate_access(u32 field_bit_offset,
88 u32 field_bit_length, u32 region_length)
89{
90 u32 field_byte_length;
91 u32 field_byte_offset;
92 u32 field_byte_end_offset;
93 u32 access_byte_width;
94 u32 field_start_offset;
95 u32 field_end_offset;
96 u32 minimum_access_width = 0xFFFFFFFF;
97 u32 minimum_accesses = 0xFFFFFFFF;
98 u32 accesses;
99
100 ACPI_FUNCTION_TRACE(ex_generate_access);
101
102 /* Round Field start offset and length to "minimal" byte boundaries */
103
104 field_byte_offset = ACPI_DIV_8(ACPI_ROUND_DOWN(field_bit_offset, 8));
105 field_byte_end_offset = ACPI_DIV_8(ACPI_ROUND_UP(field_bit_length +
106 field_bit_offset, 8));
107 field_byte_length = field_byte_end_offset - field_byte_offset;
108
109 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
110 "Bit length %d, Bit offset %d\n",
111 field_bit_length, field_bit_offset));
112
113 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
114 "Byte Length %d, Byte Offset %d, End Offset %d\n",
115 field_byte_length, field_byte_offset,
116 field_byte_end_offset));
117
118 /*
119 * Iterative search for the maximum access width that is both aligned
120 * and does not go beyond the end of the region
121 *
122 * Start at byte_acc and work upwards to qword_acc max. (1,2,4,8 bytes)
123 */
124 for (access_byte_width = 1; access_byte_width <= 8;
125 access_byte_width <<= 1) {
126 /*
127 * 1) Round end offset up to next access boundary and make sure that
128 * this does not go beyond the end of the parent region.
129 * 2) When the Access width is greater than the field_byte_length, we
130 * are done. (This does not optimize for the perfectly aligned
131 * case yet).
132 */
133 if (ACPI_ROUND_UP(field_byte_end_offset, access_byte_width) <=
134 region_length) {
135 field_start_offset =
136 ACPI_ROUND_DOWN(field_byte_offset,
137 access_byte_width) /
138 access_byte_width;
139
140 field_end_offset =
141 ACPI_ROUND_UP((field_byte_length +
142 field_byte_offset),
143 access_byte_width) /
144 access_byte_width;
145
146 accesses = field_end_offset - field_start_offset;
147
148 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
149 "AccessWidth %d end is within region\n",
150 access_byte_width));
151
152 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
153 "Field Start %d, Field End %d -- requires %d accesses\n",
154 field_start_offset, field_end_offset,
155 accesses));
156
157 /* Single access is optimal */
158
159 if (accesses <= 1) {
160 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
161 "Entire field can be accessed with one operation of size %d\n",
162 access_byte_width));
163 return_VALUE(access_byte_width);
164 }
165
166 /*
167 * Fits in the region, but requires more than one read/write.
168 * try the next wider access on next iteration
169 */
170 if (accesses < minimum_accesses) {
171 minimum_accesses = accesses;
172 minimum_access_width = access_byte_width;
173 }
174 } else {
175 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
176 "AccessWidth %d end is NOT within region\n",
177 access_byte_width));
178 if (access_byte_width == 1) {
179 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
180 "Field goes beyond end-of-region!\n"));
181
182 /* Field does not fit in the region at all */
183
184 return_VALUE(0);
185 }
186
187 /*
188 * This width goes beyond the end-of-region, back off to
189 * previous access
190 */
191 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
192 "Backing off to previous optimal access width of %d\n",
193 minimum_access_width));
194 return_VALUE(minimum_access_width);
195 }
196 }
197
198 /*
199 * Could not read/write field with one operation,
200 * just use max access width
201 */
202 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
203 "Cannot access field in one operation, using width 8\n"));
204 return_VALUE(8);
205}
206#endif /* ACPI_UNDER_DEVELOPMENT */
207
208/*******************************************************************************
209 *
210 * FUNCTION: acpi_ex_decode_field_access
211 *
212 * PARAMETERS: obj_desc - Field object
213 * field_flags - Encoded fieldflags (contains access bits)
214 * return_byte_alignment - Where the byte alignment is returned
215 *
216 * RETURN: Field granularity (8, 16, 32 or 64) and
217 * byte_alignment (1, 2, 3, or 4)
218 *
219 * DESCRIPTION: Decode the access_type bits of a field definition.
220 *
221 ******************************************************************************/
222
223static u32
224acpi_ex_decode_field_access(union acpi_operand_object *obj_desc,
225 u8 field_flags, u32 * return_byte_alignment)
226{
227 u32 access;
228 u32 byte_alignment;
229 u32 bit_length;
230
231 ACPI_FUNCTION_TRACE(ex_decode_field_access);
232
233 access = (field_flags & AML_FIELD_ACCESS_TYPE_MASK);
234
235 switch (access) {
236 case AML_FIELD_ACCESS_ANY:
237
238#ifdef ACPI_UNDER_DEVELOPMENT
239 byte_alignment =
240 acpi_ex_generate_access(obj_desc->common_field.
241 start_field_bit_offset,
242 obj_desc->common_field.bit_length,
243 0xFFFFFFFF
244 /* Temp until we pass region_length as parameter */
245 );
246 bit_length = byte_alignment * 8;
247#endif
248
249 byte_alignment = 1;
250 bit_length = 8;
251 break;
252
253 case AML_FIELD_ACCESS_BYTE:
254 case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */
255 byte_alignment = 1;
256 bit_length = 8;
257 break;
258
259 case AML_FIELD_ACCESS_WORD:
260 byte_alignment = 2;
261 bit_length = 16;
262 break;
263
264 case AML_FIELD_ACCESS_DWORD:
265 byte_alignment = 4;
266 bit_length = 32;
267 break;
268
269 case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */
270 byte_alignment = 8;
271 bit_length = 64;
272 break;
273
274 default:
275 /* Invalid field access type */
276
277 ACPI_ERROR((AE_INFO, "Unknown field access type %X", access));
278 return_UINT32(0);
279 }
280
281 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
282 /*
283 * buffer_field access can be on any byte boundary, so the
284 * byte_alignment is always 1 byte -- regardless of any byte_alignment
285 * implied by the field access type.
286 */
287 byte_alignment = 1;
288 }
289
290 *return_byte_alignment = byte_alignment;
291 return_UINT32(bit_length);
292}
293
294/*******************************************************************************
295 *
296 * FUNCTION: acpi_ex_prep_common_field_object
297 *
298 * PARAMETERS: obj_desc - The field object
299 * field_flags - Access, lock_rule, and update_rule.
300 * The format of a field_flag is described
301 * in the ACPI specification
302 * field_attribute - Special attributes (not used)
303 * field_bit_position - Field start position
304 * field_bit_length - Field length in number of bits
305 *
306 * RETURN: Status
307 *
308 * DESCRIPTION: Initialize the areas of the field object that are common
309 * to the various types of fields. Note: This is very "sensitive"
310 * code because we are solving the general case for field
311 * alignment.
312 *
313 ******************************************************************************/
314
315acpi_status
316acpi_ex_prep_common_field_object(union acpi_operand_object *obj_desc,
317 u8 field_flags,
318 u8 field_attribute,
319 u32 field_bit_position, u32 field_bit_length)
320{
321 u32 access_bit_width;
322 u32 byte_alignment;
323 u32 nearest_byte_address;
324
325 ACPI_FUNCTION_TRACE(ex_prep_common_field_object);
326
327 /*
328 * Note: the structure being initialized is the
329 * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common
330 * area are initialized by this procedure.
331 */
332 obj_desc->common_field.field_flags = field_flags;
333 obj_desc->common_field.attribute = field_attribute;
334 obj_desc->common_field.bit_length = field_bit_length;
335
336 /*
337 * Decode the access type so we can compute offsets. The access type gives
338 * two pieces of information - the width of each field access and the
339 * necessary byte_alignment (address granularity) of the access.
340 *
341 * For any_acc, the access_bit_width is the largest width that is both
342 * necessary and possible in an attempt to access the whole field in one
343 * I/O operation. However, for any_acc, the byte_alignment is always one
344 * byte.
345 *
346 * For all Buffer Fields, the byte_alignment is always one byte.
347 *
348 * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
349 * the same (equivalent) as the byte_alignment.
350 */
351 access_bit_width = acpi_ex_decode_field_access(obj_desc, field_flags,
352 &byte_alignment);
353 if (!access_bit_width) {
354 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
355 }
356
357 /* Setup width (access granularity) fields */
358
359 obj_desc->common_field.access_byte_width = (u8)
360 ACPI_DIV_8(access_bit_width); /* 1, 2, 4, 8 */
361
362 obj_desc->common_field.access_bit_width = (u8) access_bit_width;
363
364 /*
365 * base_byte_offset is the address of the start of the field within the
366 * region. It is the byte address of the first *datum* (field-width data
367 * unit) of the field. (i.e., the first datum that contains at least the
368 * first *bit* of the field.)
369 *
370 * Note: byte_alignment is always either equal to the access_bit_width or 8
371 * (Byte access), and it defines the addressing granularity of the parent
372 * region or buffer.
373 */
374 nearest_byte_address =
375 ACPI_ROUND_BITS_DOWN_TO_BYTES(field_bit_position);
376 obj_desc->common_field.base_byte_offset = (u32)
377 ACPI_ROUND_DOWN(nearest_byte_address, byte_alignment);
378
379 /*
380 * start_field_bit_offset is the offset of the first bit of the field within
381 * a field datum.
382 */
383 obj_desc->common_field.start_field_bit_offset = (u8)
384 (field_bit_position -
385 ACPI_MUL_8(obj_desc->common_field.base_byte_offset));
386
387 /*
388 * Does the entire field fit within a single field access element? (datum)
389 * (i.e., without crossing a datum boundary)
390 */
391 if ((obj_desc->common_field.start_field_bit_offset +
392 field_bit_length) <= (u16) access_bit_width) {
393 obj_desc->common.flags |= AOPOBJ_SINGLE_DATUM;
394 }
395
396 return_ACPI_STATUS(AE_OK);
397}
398
399/*******************************************************************************
400 *
401 * FUNCTION: acpi_ex_prep_field_value
402 *
403 * PARAMETERS: Info - Contains all field creation info
404 *
405 * RETURN: Status
406 *
407 * DESCRIPTION: Construct a union acpi_operand_object of type def_field and
408 * connect it to the parent Node.
409 *
410 ******************************************************************************/
411
412acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info)
413{
414 union acpi_operand_object *obj_desc;
415 union acpi_operand_object *second_desc = NULL;
416 u32 type;
417 acpi_status status;
418
419 ACPI_FUNCTION_TRACE(ex_prep_field_value);
420
421 /* Parameter validation */
422
423 if (info->field_type != ACPI_TYPE_LOCAL_INDEX_FIELD) {
424 if (!info->region_node) {
425 ACPI_ERROR((AE_INFO, "Null RegionNode"));
426 return_ACPI_STATUS(AE_AML_NO_OPERAND);
427 }
428
429 type = acpi_ns_get_type(info->region_node);
430 if (type != ACPI_TYPE_REGION) {
431 ACPI_ERROR((AE_INFO,
432 "Needed Region, found type %X (%s)",
433 type, acpi_ut_get_type_name(type)));
434
435 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
436 }
437 }
438
439 /* Allocate a new field object */
440
441 obj_desc = acpi_ut_create_internal_object(info->field_type);
442 if (!obj_desc) {
443 return_ACPI_STATUS(AE_NO_MEMORY);
444 }
445
446 /* Initialize areas of the object that are common to all fields */
447
448 obj_desc->common_field.node = info->field_node;
449 status = acpi_ex_prep_common_field_object(obj_desc, info->field_flags,
450 info->attribute,
451 info->field_bit_position,
452 info->field_bit_length);
453 if (ACPI_FAILURE(status)) {
454 acpi_ut_delete_object_desc(obj_desc);
455 return_ACPI_STATUS(status);
456 }
457
458 /* Initialize areas of the object that are specific to the field type */
459
460 switch (info->field_type) {
461 case ACPI_TYPE_LOCAL_REGION_FIELD:
462
463 obj_desc->field.region_obj =
464 acpi_ns_get_attached_object(info->region_node);
465
466 /* An additional reference for the container */
467
468 acpi_ut_add_reference(obj_desc->field.region_obj);
469
470 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
471 "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
472 obj_desc->field.start_field_bit_offset,
473 obj_desc->field.base_byte_offset,
474 obj_desc->field.access_byte_width,
475 obj_desc->field.region_obj));
476 break;
477
478 case ACPI_TYPE_LOCAL_BANK_FIELD:
479
480 obj_desc->bank_field.value = info->bank_value;
481 obj_desc->bank_field.region_obj =
482 acpi_ns_get_attached_object(info->region_node);
483 obj_desc->bank_field.bank_obj =
484 acpi_ns_get_attached_object(info->register_node);
485
486 /* An additional reference for the attached objects */
487
488 acpi_ut_add_reference(obj_desc->bank_field.region_obj);
489 acpi_ut_add_reference(obj_desc->bank_field.bank_obj);
490
491 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
492 "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
493 obj_desc->bank_field.start_field_bit_offset,
494 obj_desc->bank_field.base_byte_offset,
495 obj_desc->field.access_byte_width,
496 obj_desc->bank_field.region_obj,
497 obj_desc->bank_field.bank_obj));
498
499 /*
500 * Remember location in AML stream of the field unit
501 * opcode and operands -- since the bank_value
502 * operands must be evaluated.
503 */
504 second_desc = obj_desc->common.next_object;
505 second_desc->extra.aml_start =
506 ACPI_CAST_PTR(union acpi_parse_object,
507 info->data_register_node)->named.data;
508 second_desc->extra.aml_length =
509 ACPI_CAST_PTR(union acpi_parse_object,
510 info->data_register_node)->named.length;
511
512 break;
513
514 case ACPI_TYPE_LOCAL_INDEX_FIELD:
515
516 /* Get the Index and Data registers */
517
518 obj_desc->index_field.index_obj =
519 acpi_ns_get_attached_object(info->register_node);
520 obj_desc->index_field.data_obj =
521 acpi_ns_get_attached_object(info->data_register_node);
522
523 if (!obj_desc->index_field.data_obj
524 || !obj_desc->index_field.index_obj) {
525 ACPI_ERROR((AE_INFO,
526 "Null Index Object during field prep"));
527 acpi_ut_delete_object_desc(obj_desc);
528 return_ACPI_STATUS(AE_AML_INTERNAL);
529 }
530
531 /* An additional reference for the attached objects */
532
533 acpi_ut_add_reference(obj_desc->index_field.data_obj);
534 acpi_ut_add_reference(obj_desc->index_field.index_obj);
535
536 /*
537 * April 2006: Changed to match MS behavior
538 *
539 * The value written to the Index register is the byte offset of the
540 * target field in units of the granularity of the index_field
541 *
542 * Previously, the value was calculated as an index in terms of the
543 * width of the Data register, as below:
544 *
545 * obj_desc->index_field.Value = (u32)
546 * (Info->field_bit_position / ACPI_MUL_8 (
547 * obj_desc->Field.access_byte_width));
548 *
549 * February 2006: Tried value as a byte offset:
550 * obj_desc->index_field.Value = (u32)
551 * ACPI_DIV_8 (Info->field_bit_position);
552 */
553 obj_desc->index_field.value =
554 (u32) ACPI_ROUND_DOWN(ACPI_DIV_8(info->field_bit_position),
555 obj_desc->index_field.
556 access_byte_width);
557
558 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
559 "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n",
560 obj_desc->index_field.start_field_bit_offset,
561 obj_desc->index_field.base_byte_offset,
562 obj_desc->index_field.value,
563 obj_desc->field.access_byte_width,
564 obj_desc->index_field.index_obj,
565 obj_desc->index_field.data_obj));
566 break;
567
568 default:
569 /* No other types should get here */
570 break;
571 }
572
573 /*
574 * Store the constructed descriptor (obj_desc) into the parent Node,
575 * preserving the current type of that named_obj.
576 */
577 status = acpi_ns_attach_object(info->field_node, obj_desc,
578 acpi_ns_get_type(info->field_node));
579
580 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
581 "Set NamedObj %p [%4.4s], ObjDesc %p\n",
582 info->field_node,
583 acpi_ut_get_node_name(info->field_node), obj_desc));
584
585 /* Remove local reference to the object */
586
587 acpi_ut_remove_reference(obj_desc);
588 return_ACPI_STATUS(status);
589}
diff --git a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c
deleted file mode 100644
index 7a41c409ae4d..000000000000
--- a/drivers/acpi/executer/exregion.c
+++ /dev/null
@@ -1,498 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exregion - ACPI default op_region (address space) handlers
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47
48#define _COMPONENT ACPI_EXECUTER
49ACPI_MODULE_NAME("exregion")
50
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_ex_system_memory_space_handler
54 *
55 * PARAMETERS: Function - Read or Write operation
56 * Address - Where in the space to read or write
57 * bit_width - Field width in bits (8, 16, or 32)
58 * Value - Pointer to in or out value
59 * handler_context - Pointer to Handler's context
60 * region_context - Pointer to context specific to the
61 * accessed region
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Handler for the System Memory address space (Op Region)
66 *
67 ******************************************************************************/
68acpi_status
69acpi_ex_system_memory_space_handler(u32 function,
70 acpi_physical_address address,
71 u32 bit_width,
72 acpi_integer * value,
73 void *handler_context, void *region_context)
74{
75 acpi_status status = AE_OK;
76 void *logical_addr_ptr = NULL;
77 struct acpi_mem_space_context *mem_info = region_context;
78 u32 length;
79 acpi_size window_size;
80#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
81 u32 remainder;
82#endif
83
84 ACPI_FUNCTION_TRACE(ex_system_memory_space_handler);
85
86 /* Validate and translate the bit width */
87
88 switch (bit_width) {
89 case 8:
90 length = 1;
91 break;
92
93 case 16:
94 length = 2;
95 break;
96
97 case 32:
98 length = 4;
99 break;
100
101 case 64:
102 length = 8;
103 break;
104
105 default:
106 ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %d",
107 bit_width));
108 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
109 }
110
111#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
112 /*
113 * Hardware does not support non-aligned data transfers, we must verify
114 * the request.
115 */
116 (void)acpi_ut_short_divide((acpi_integer) address, length, NULL,
117 &remainder);
118 if (remainder != 0) {
119 return_ACPI_STATUS(AE_AML_ALIGNMENT);
120 }
121#endif
122
123 /*
124 * Does the request fit into the cached memory mapping?
125 * Is 1) Address below the current mapping? OR
126 * 2) Address beyond the current mapping?
127 */
128 if ((address < mem_info->mapped_physical_address) ||
129 (((acpi_integer) address + length) > ((acpi_integer)
130 mem_info->
131 mapped_physical_address +
132 mem_info->mapped_length))) {
133 /*
134 * The request cannot be resolved by the current memory mapping;
135 * Delete the existing mapping and create a new one.
136 */
137 if (mem_info->mapped_length) {
138
139 /* Valid mapping, delete it */
140
141 acpi_os_unmap_memory(mem_info->mapped_logical_address,
142 mem_info->mapped_length);
143 }
144
145 /*
146 * Don't attempt to map memory beyond the end of the region, and
147 * constrain the maximum mapping size to something reasonable.
148 */
149 window_size = (acpi_size)
150 ((mem_info->address + mem_info->length) - address);
151
152 if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) {
153 window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE;
154 }
155
156 /* Create a new mapping starting at the address given */
157
158 mem_info->mapped_logical_address =
159 acpi_os_map_memory((acpi_physical_address) address, window_size);
160 if (!mem_info->mapped_logical_address) {
161 ACPI_ERROR((AE_INFO,
162 "Could not map memory at %8.8X%8.8X, size %X",
163 ACPI_FORMAT_NATIVE_UINT(address),
164 (u32) window_size));
165 mem_info->mapped_length = 0;
166 return_ACPI_STATUS(AE_NO_MEMORY);
167 }
168
169 /* Save the physical address and mapping size */
170
171 mem_info->mapped_physical_address = address;
172 mem_info->mapped_length = window_size;
173 }
174
175 /*
176 * Generate a logical pointer corresponding to the address we want to
177 * access
178 */
179 logical_addr_ptr = mem_info->mapped_logical_address +
180 ((acpi_integer) address -
181 (acpi_integer) mem_info->mapped_physical_address);
182
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
184 "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
185 bit_width, function,
186 ACPI_FORMAT_NATIVE_UINT(address)));
187
188 /*
189 * Perform the memory read or write
190 *
191 * Note: For machines that do not support non-aligned transfers, the target
192 * address was checked for alignment above. We do not attempt to break the
193 * transfer up into smaller (byte-size) chunks because the AML specifically
194 * asked for a transfer width that the hardware may require.
195 */
196 switch (function) {
197 case ACPI_READ:
198
199 *value = 0;
200 switch (bit_width) {
201 case 8:
202 *value = (acpi_integer) ACPI_GET8(logical_addr_ptr);
203 break;
204
205 case 16:
206 *value = (acpi_integer) ACPI_GET16(logical_addr_ptr);
207 break;
208
209 case 32:
210 *value = (acpi_integer) ACPI_GET32(logical_addr_ptr);
211 break;
212
213 case 64:
214 *value = (acpi_integer) ACPI_GET64(logical_addr_ptr);
215 break;
216
217 default:
218 /* bit_width was already validated */
219 break;
220 }
221 break;
222
223 case ACPI_WRITE:
224
225 switch (bit_width) {
226 case 8:
227 ACPI_SET8(logical_addr_ptr) = (u8) * value;
228 break;
229
230 case 16:
231 ACPI_SET16(logical_addr_ptr) = (u16) * value;
232 break;
233
234 case 32:
235 ACPI_SET32(logical_addr_ptr) = (u32) * value;
236 break;
237
238 case 64:
239 ACPI_SET64(logical_addr_ptr) = (u64) * value;
240 break;
241
242 default:
243 /* bit_width was already validated */
244 break;
245 }
246 break;
247
248 default:
249 status = AE_BAD_PARAMETER;
250 break;
251 }
252
253 return_ACPI_STATUS(status);
254}
255
256/*******************************************************************************
257 *
258 * FUNCTION: acpi_ex_system_io_space_handler
259 *
260 * PARAMETERS: Function - Read or Write operation
261 * Address - Where in the space to read or write
262 * bit_width - Field width in bits (8, 16, or 32)
263 * Value - Pointer to in or out value
264 * handler_context - Pointer to Handler's context
265 * region_context - Pointer to context specific to the
266 * accessed region
267 *
268 * RETURN: Status
269 *
270 * DESCRIPTION: Handler for the System IO address space (Op Region)
271 *
272 ******************************************************************************/
273
274acpi_status
275acpi_ex_system_io_space_handler(u32 function,
276 acpi_physical_address address,
277 u32 bit_width,
278 acpi_integer * value,
279 void *handler_context, void *region_context)
280{
281 acpi_status status = AE_OK;
282 u32 value32;
283
284 ACPI_FUNCTION_TRACE(ex_system_io_space_handler);
285
286 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
287 "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
288 bit_width, function,
289 ACPI_FORMAT_NATIVE_UINT(address)));
290
291 /* Decode the function parameter */
292
293 switch (function) {
294 case ACPI_READ:
295
296 status = acpi_os_read_port((acpi_io_address) address,
297 &value32, bit_width);
298 *value = value32;
299 break;
300
301 case ACPI_WRITE:
302
303 status = acpi_os_write_port((acpi_io_address) address,
304 (u32) * value, bit_width);
305 break;
306
307 default:
308 status = AE_BAD_PARAMETER;
309 break;
310 }
311
312 return_ACPI_STATUS(status);
313}
314
315/*******************************************************************************
316 *
317 * FUNCTION: acpi_ex_pci_config_space_handler
318 *
319 * PARAMETERS: Function - Read or Write operation
320 * Address - Where in the space to read or write
321 * bit_width - Field width in bits (8, 16, or 32)
322 * Value - Pointer to in or out value
323 * handler_context - Pointer to Handler's context
324 * region_context - Pointer to context specific to the
325 * accessed region
326 *
327 * RETURN: Status
328 *
329 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
330 *
331 ******************************************************************************/
332
333acpi_status
334acpi_ex_pci_config_space_handler(u32 function,
335 acpi_physical_address address,
336 u32 bit_width,
337 acpi_integer * value,
338 void *handler_context, void *region_context)
339{
340 acpi_status status = AE_OK;
341 struct acpi_pci_id *pci_id;
342 u16 pci_register;
343 u32 value32;
344
345 ACPI_FUNCTION_TRACE(ex_pci_config_space_handler);
346
347 /*
348 * The arguments to acpi_os(Read|Write)pci_configuration are:
349 *
350 * pci_segment is the PCI bus segment range 0-31
351 * pci_bus is the PCI bus number range 0-255
352 * pci_device is the PCI device number range 0-31
353 * pci_function is the PCI device function number
354 * pci_register is the Config space register range 0-255 bytes
355 *
356 * Value - input value for write, output address for read
357 *
358 */
359 pci_id = (struct acpi_pci_id *)region_context;
360 pci_register = (u16) (u32) address;
361
362 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
363 "Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
364 function, bit_width, pci_id->segment, pci_id->bus,
365 pci_id->device, pci_id->function, pci_register));
366
367 switch (function) {
368 case ACPI_READ:
369
370 status = acpi_os_read_pci_configuration(pci_id, pci_register,
371 &value32, bit_width);
372 *value = value32;
373 break;
374
375 case ACPI_WRITE:
376
377 status = acpi_os_write_pci_configuration(pci_id, pci_register,
378 *value, bit_width);
379 break;
380
381 default:
382
383 status = AE_BAD_PARAMETER;
384 break;
385 }
386
387 return_ACPI_STATUS(status);
388}
389
390/*******************************************************************************
391 *
392 * FUNCTION: acpi_ex_cmos_space_handler
393 *
394 * PARAMETERS: Function - Read or Write operation
395 * Address - Where in the space to read or write
396 * bit_width - Field width in bits (8, 16, or 32)
397 * Value - Pointer to in or out value
398 * handler_context - Pointer to Handler's context
399 * region_context - Pointer to context specific to the
400 * accessed region
401 *
402 * RETURN: Status
403 *
404 * DESCRIPTION: Handler for the CMOS address space (Op Region)
405 *
406 ******************************************************************************/
407
408acpi_status
409acpi_ex_cmos_space_handler(u32 function,
410 acpi_physical_address address,
411 u32 bit_width,
412 acpi_integer * value,
413 void *handler_context, void *region_context)
414{
415 acpi_status status = AE_OK;
416
417 ACPI_FUNCTION_TRACE(ex_cmos_space_handler);
418
419 return_ACPI_STATUS(status);
420}
421
422/*******************************************************************************
423 *
424 * FUNCTION: acpi_ex_pci_bar_space_handler
425 *
426 * PARAMETERS: Function - Read or Write operation
427 * Address - Where in the space to read or write
428 * bit_width - Field width in bits (8, 16, or 32)
429 * Value - Pointer to in or out value
430 * handler_context - Pointer to Handler's context
431 * region_context - Pointer to context specific to the
432 * accessed region
433 *
434 * RETURN: Status
435 *
436 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
437 *
438 ******************************************************************************/
439
440acpi_status
441acpi_ex_pci_bar_space_handler(u32 function,
442 acpi_physical_address address,
443 u32 bit_width,
444 acpi_integer * value,
445 void *handler_context, void *region_context)
446{
447 acpi_status status = AE_OK;
448
449 ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler);
450
451 return_ACPI_STATUS(status);
452}
453
454/*******************************************************************************
455 *
456 * FUNCTION: acpi_ex_data_table_space_handler
457 *
458 * PARAMETERS: Function - Read or Write operation
459 * Address - Where in the space to read or write
460 * bit_width - Field width in bits (8, 16, or 32)
461 * Value - Pointer to in or out value
462 * handler_context - Pointer to Handler's context
463 * region_context - Pointer to context specific to the
464 * accessed region
465 *
466 * RETURN: Status
467 *
468 * DESCRIPTION: Handler for the Data Table address space (Op Region)
469 *
470 ******************************************************************************/
471
472acpi_status
473acpi_ex_data_table_space_handler(u32 function,
474 acpi_physical_address address,
475 u32 bit_width,
476 acpi_integer * value,
477 void *handler_context, void *region_context)
478{
479 ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
480
481 /* Perform the memory read or write */
482
483 switch (function) {
484 case ACPI_READ:
485
486 ACPI_MEMCPY(ACPI_CAST_PTR(char, value),
487 ACPI_PHYSADDR_TO_PTR(address),
488 ACPI_DIV_8(bit_width));
489 break;
490
491 case ACPI_WRITE:
492 default:
493
494 return_ACPI_STATUS(AE_SUPPORT);
495 }
496
497 return_ACPI_STATUS(AE_OK);
498}
diff --git a/drivers/acpi/executer/exresnte.c b/drivers/acpi/executer/exresnte.c
deleted file mode 100644
index 423ad3635f3d..000000000000
--- a/drivers/acpi/executer/exresnte.c
+++ /dev/null
@@ -1,277 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exresnte - AML Interpreter object resolution
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acdispat.h>
47#include <acpi/acinterp.h>
48#include <acpi/acnamesp.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exresnte")
52
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_ex_resolve_node_to_value
56 *
57 * PARAMETERS: object_ptr - Pointer to a location that contains
58 * a pointer to a NS node, and will receive a
59 * pointer to the resolved object.
60 * walk_state - Current state. Valid only if executing AML
61 * code. NULL if simply resolving an object
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Resolve a Namespace node to a valued object
66 *
67 * Note: for some of the data types, the pointer attached to the Node
68 * can be either a pointer to an actual internal object or a pointer into the
69 * AML stream itself. These types are currently:
70 *
71 * ACPI_TYPE_INTEGER
72 * ACPI_TYPE_STRING
73 * ACPI_TYPE_BUFFER
74 * ACPI_TYPE_MUTEX
75 * ACPI_TYPE_PACKAGE
76 *
77 ******************************************************************************/
78acpi_status
79acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
80 struct acpi_walk_state *walk_state)
81{
82 acpi_status status = AE_OK;
83 union acpi_operand_object *source_desc;
84 union acpi_operand_object *obj_desc = NULL;
85 struct acpi_namespace_node *node;
86 acpi_object_type entry_type;
87
88 ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
89
90 /*
91 * The stack pointer points to a struct acpi_namespace_node (Node). Get the
92 * object that is attached to the Node.
93 */
94 node = *object_ptr;
95 source_desc = acpi_ns_get_attached_object(node);
96 entry_type = acpi_ns_get_type((acpi_handle) node);
97
98 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
99 node, source_desc,
100 acpi_ut_get_type_name(entry_type)));
101
102 if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
103 (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
104
105 /* There is always exactly one level of indirection */
106
107 node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
108 source_desc = acpi_ns_get_attached_object(node);
109 entry_type = acpi_ns_get_type((acpi_handle) node);
110 *object_ptr = node;
111 }
112
113 /*
114 * Several object types require no further processing:
115 * 1) Device/Thermal objects don't have a "real" subobject, return the Node
116 * 2) Method locals and arguments have a pseudo-Node
117 * 3) 10/2007: Added method type to assist with Package construction.
118 */
119 if ((entry_type == ACPI_TYPE_DEVICE) ||
120 (entry_type == ACPI_TYPE_THERMAL) ||
121 (entry_type == ACPI_TYPE_METHOD) ||
122 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
123 return_ACPI_STATUS(AE_OK);
124 }
125
126 if (!source_desc) {
127 ACPI_ERROR((AE_INFO, "No object attached to node %p", node));
128 return_ACPI_STATUS(AE_AML_NO_OPERAND);
129 }
130
131 /*
132 * Action is based on the type of the Node, which indicates the type
133 * of the attached object or pointer
134 */
135 switch (entry_type) {
136 case ACPI_TYPE_PACKAGE:
137
138 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
139 ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
140 acpi_ut_get_object_type_name(source_desc)));
141 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
142 }
143
144 status = acpi_ds_get_package_arguments(source_desc);
145 if (ACPI_SUCCESS(status)) {
146
147 /* Return an additional reference to the object */
148
149 obj_desc = source_desc;
150 acpi_ut_add_reference(obj_desc);
151 }
152 break;
153
154 case ACPI_TYPE_BUFFER:
155
156 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
157 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
158 acpi_ut_get_object_type_name(source_desc)));
159 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
160 }
161
162 status = acpi_ds_get_buffer_arguments(source_desc);
163 if (ACPI_SUCCESS(status)) {
164
165 /* Return an additional reference to the object */
166
167 obj_desc = source_desc;
168 acpi_ut_add_reference(obj_desc);
169 }
170 break;
171
172 case ACPI_TYPE_STRING:
173
174 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
175 ACPI_ERROR((AE_INFO, "Object not a String, type %s",
176 acpi_ut_get_object_type_name(source_desc)));
177 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
178 }
179
180 /* Return an additional reference to the object */
181
182 obj_desc = source_desc;
183 acpi_ut_add_reference(obj_desc);
184 break;
185
186 case ACPI_TYPE_INTEGER:
187
188 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
189 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
190 acpi_ut_get_object_type_name(source_desc)));
191 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
192 }
193
194 /* Return an additional reference to the object */
195
196 obj_desc = source_desc;
197 acpi_ut_add_reference(obj_desc);
198 break;
199
200 case ACPI_TYPE_BUFFER_FIELD:
201 case ACPI_TYPE_LOCAL_REGION_FIELD:
202 case ACPI_TYPE_LOCAL_BANK_FIELD:
203 case ACPI_TYPE_LOCAL_INDEX_FIELD:
204
205 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
206 "FieldRead Node=%p SourceDesc=%p Type=%X\n",
207 node, source_desc, entry_type));
208
209 status =
210 acpi_ex_read_data_from_field(walk_state, source_desc,
211 &obj_desc);
212 break;
213
214 /* For these objects, just return the object attached to the Node */
215
216 case ACPI_TYPE_MUTEX:
217 case ACPI_TYPE_POWER:
218 case ACPI_TYPE_PROCESSOR:
219 case ACPI_TYPE_EVENT:
220 case ACPI_TYPE_REGION:
221
222 /* Return an additional reference to the object */
223
224 obj_desc = source_desc;
225 acpi_ut_add_reference(obj_desc);
226 break;
227
228 /* TYPE_ANY is untyped, and thus there is no object associated with it */
229
230 case ACPI_TYPE_ANY:
231
232 ACPI_ERROR((AE_INFO,
233 "Untyped entry %p, no attached object!", node));
234
235 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
236
237 case ACPI_TYPE_LOCAL_REFERENCE:
238
239 switch (source_desc->reference.class) {
240 case ACPI_REFCLASS_TABLE: /* This is a ddb_handle */
241 case ACPI_REFCLASS_REFOF:
242 case ACPI_REFCLASS_INDEX:
243
244 /* Return an additional reference to the object */
245
246 obj_desc = source_desc;
247 acpi_ut_add_reference(obj_desc);
248 break;
249
250 default:
251 /* No named references are allowed here */
252
253 ACPI_ERROR((AE_INFO,
254 "Unsupported Reference type %X",
255 source_desc->reference.class));
256
257 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
258 }
259 break;
260
261 default:
262
263 /* Default case is for unknown types */
264
265 ACPI_ERROR((AE_INFO,
266 "Node %p - Unknown object type %X",
267 node, entry_type));
268
269 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
270
271 } /* switch (entry_type) */
272
273 /* Return the object descriptor */
274
275 *object_ptr = (void *)obj_desc;
276 return_ACPI_STATUS(status);
277}
diff --git a/drivers/acpi/executer/exresolv.c b/drivers/acpi/executer/exresolv.c
deleted file mode 100644
index 60e8c47128e9..000000000000
--- a/drivers/acpi/executer/exresolv.c
+++ /dev/null
@@ -1,550 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exresolv - AML Interpreter object resolution
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/amlcode.h>
47#include <acpi/acdispat.h>
48#include <acpi/acinterp.h>
49#include <acpi/acnamesp.h>
50
51#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("exresolv")
53
54/* Local prototypes */
55static acpi_status
56acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
57 struct acpi_walk_state *walk_state);
58
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ex_resolve_to_value
62 *
63 * PARAMETERS: **stack_ptr - Points to entry on obj_stack, which can
64 * be either an (union acpi_operand_object *)
65 * or an acpi_handle.
66 * walk_state - Current method state
67 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Convert Reference objects to values
71 *
72 ******************************************************************************/
73
74acpi_status
75acpi_ex_resolve_to_value(union acpi_operand_object **stack_ptr,
76 struct acpi_walk_state *walk_state)
77{
78 acpi_status status;
79
80 ACPI_FUNCTION_TRACE_PTR(ex_resolve_to_value, stack_ptr);
81
82 if (!stack_ptr || !*stack_ptr) {
83 ACPI_ERROR((AE_INFO, "Internal - null pointer"));
84 return_ACPI_STATUS(AE_AML_NO_OPERAND);
85 }
86
87 /*
88 * The entity pointed to by the stack_ptr can be either
89 * 1) A valid union acpi_operand_object, or
90 * 2) A struct acpi_namespace_node (named_obj)
91 */
92 if (ACPI_GET_DESCRIPTOR_TYPE(*stack_ptr) == ACPI_DESC_TYPE_OPERAND) {
93 status = acpi_ex_resolve_object_to_value(stack_ptr, walk_state);
94 if (ACPI_FAILURE(status)) {
95 return_ACPI_STATUS(status);
96 }
97
98 if (!*stack_ptr) {
99 ACPI_ERROR((AE_INFO, "Internal - null pointer"));
100 return_ACPI_STATUS(AE_AML_NO_OPERAND);
101 }
102 }
103
104 /*
105 * Object on the stack may have changed if acpi_ex_resolve_object_to_value()
106 * was called (i.e., we can't use an _else_ here.)
107 */
108 if (ACPI_GET_DESCRIPTOR_TYPE(*stack_ptr) == ACPI_DESC_TYPE_NAMED) {
109 status =
110 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
111 (struct acpi_namespace_node,
112 stack_ptr), walk_state);
113 if (ACPI_FAILURE(status)) {
114 return_ACPI_STATUS(status);
115 }
116 }
117
118 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Resolved object %p\n", *stack_ptr));
119 return_ACPI_STATUS(AE_OK);
120}
121
122/*******************************************************************************
123 *
124 * FUNCTION: acpi_ex_resolve_object_to_value
125 *
126 * PARAMETERS: stack_ptr - Pointer to an internal object
127 * walk_state - Current method state
128 *
129 * RETURN: Status
130 *
131 * DESCRIPTION: Retrieve the value from an internal object. The Reference type
132 * uses the associated AML opcode to determine the value.
133 *
134 ******************************************************************************/
135
136static acpi_status
137acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
138 struct acpi_walk_state *walk_state)
139{
140 acpi_status status = AE_OK;
141 union acpi_operand_object *stack_desc;
142 union acpi_operand_object *obj_desc = NULL;
143 u8 ref_type;
144
145 ACPI_FUNCTION_TRACE(ex_resolve_object_to_value);
146
147 stack_desc = *stack_ptr;
148
149 /* This is a union acpi_operand_object */
150
151 switch (ACPI_GET_OBJECT_TYPE(stack_desc)) {
152 case ACPI_TYPE_LOCAL_REFERENCE:
153
154 ref_type = stack_desc->reference.class;
155
156 switch (ref_type) {
157 case ACPI_REFCLASS_LOCAL:
158 case ACPI_REFCLASS_ARG:
159
160 /*
161 * Get the local from the method's state info
162 * Note: this increments the local's object reference count
163 */
164 status = acpi_ds_method_data_get_value(ref_type,
165 stack_desc->
166 reference.value,
167 walk_state,
168 &obj_desc);
169 if (ACPI_FAILURE(status)) {
170 return_ACPI_STATUS(status);
171 }
172
173 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
174 "[Arg/Local %X] ValueObj is %p\n",
175 stack_desc->reference.value,
176 obj_desc));
177
178 /*
179 * Now we can delete the original Reference Object and
180 * replace it with the resolved value
181 */
182 acpi_ut_remove_reference(stack_desc);
183 *stack_ptr = obj_desc;
184 break;
185
186 case ACPI_REFCLASS_INDEX:
187
188 switch (stack_desc->reference.target_type) {
189 case ACPI_TYPE_BUFFER_FIELD:
190
191 /* Just return - do not dereference */
192 break;
193
194 case ACPI_TYPE_PACKAGE:
195
196 /* If method call or copy_object - do not dereference */
197
198 if ((walk_state->opcode ==
199 AML_INT_METHODCALL_OP)
200 || (walk_state->opcode == AML_COPY_OP)) {
201 break;
202 }
203
204 /* Otherwise, dereference the package_index to a package element */
205
206 obj_desc = *stack_desc->reference.where;
207 if (obj_desc) {
208 /*
209 * Valid object descriptor, copy pointer to return value
210 * (i.e., dereference the package index)
211 * Delete the ref object, increment the returned object
212 */
213 acpi_ut_remove_reference(stack_desc);
214 acpi_ut_add_reference(obj_desc);
215 *stack_ptr = obj_desc;
216 } else {
217 /*
218 * A NULL object descriptor means an uninitialized element of
219 * the package, can't dereference it
220 */
221 ACPI_ERROR((AE_INFO,
222 "Attempt to dereference an Index to NULL package element Idx=%p",
223 stack_desc));
224 status = AE_AML_UNINITIALIZED_ELEMENT;
225 }
226 break;
227
228 default:
229
230 /* Invalid reference object */
231
232 ACPI_ERROR((AE_INFO,
233 "Unknown TargetType %X in Index/Reference object %p",
234 stack_desc->reference.target_type,
235 stack_desc));
236 status = AE_AML_INTERNAL;
237 break;
238 }
239 break;
240
241 case ACPI_REFCLASS_REFOF:
242 case ACPI_REFCLASS_DEBUG:
243 case ACPI_REFCLASS_TABLE:
244
245 /* Just leave the object as-is, do not dereference */
246
247 break;
248
249 case ACPI_REFCLASS_NAME: /* Reference to a named object */
250
251 /* Dereference the name */
252
253 if ((stack_desc->reference.node->type ==
254 ACPI_TYPE_DEVICE)
255 || (stack_desc->reference.node->type ==
256 ACPI_TYPE_THERMAL)) {
257
258 /* These node types do not have 'real' subobjects */
259
260 *stack_ptr = (void *)stack_desc->reference.node;
261 } else {
262 /* Get the object pointed to by the namespace node */
263
264 *stack_ptr =
265 (stack_desc->reference.node)->object;
266 acpi_ut_add_reference(*stack_ptr);
267 }
268
269 acpi_ut_remove_reference(stack_desc);
270 break;
271
272 default:
273
274 ACPI_ERROR((AE_INFO,
275 "Unknown Reference type %X in %p", ref_type,
276 stack_desc));
277 status = AE_AML_INTERNAL;
278 break;
279 }
280 break;
281
282 case ACPI_TYPE_BUFFER:
283
284 status = acpi_ds_get_buffer_arguments(stack_desc);
285 break;
286
287 case ACPI_TYPE_PACKAGE:
288
289 status = acpi_ds_get_package_arguments(stack_desc);
290 break;
291
292 case ACPI_TYPE_BUFFER_FIELD:
293 case ACPI_TYPE_LOCAL_REGION_FIELD:
294 case ACPI_TYPE_LOCAL_BANK_FIELD:
295 case ACPI_TYPE_LOCAL_INDEX_FIELD:
296
297 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
298 "FieldRead SourceDesc=%p Type=%X\n",
299 stack_desc,
300 ACPI_GET_OBJECT_TYPE(stack_desc)));
301
302 status =
303 acpi_ex_read_data_from_field(walk_state, stack_desc,
304 &obj_desc);
305
306 /* Remove a reference to the original operand, then override */
307
308 acpi_ut_remove_reference(*stack_ptr);
309 *stack_ptr = (void *)obj_desc;
310 break;
311
312 default:
313 break;
314 }
315
316 return_ACPI_STATUS(status);
317}
318
319/*******************************************************************************
320 *
321 * FUNCTION: acpi_ex_resolve_multiple
322 *
323 * PARAMETERS: walk_state - Current state (contains AML opcode)
324 * Operand - Starting point for resolution
325 * return_type - Where the object type is returned
326 * return_desc - Where the resolved object is returned
327 *
328 * RETURN: Status
329 *
330 * DESCRIPTION: Return the base object and type. Traverse a reference list if
331 * necessary to get to the base object.
332 *
333 ******************************************************************************/
334
335acpi_status
336acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
337 union acpi_operand_object *operand,
338 acpi_object_type * return_type,
339 union acpi_operand_object **return_desc)
340{
341 union acpi_operand_object *obj_desc = (void *)operand;
342 struct acpi_namespace_node *node;
343 acpi_object_type type;
344 acpi_status status;
345
346 ACPI_FUNCTION_TRACE(acpi_ex_resolve_multiple);
347
348 /* Operand can be either a namespace node or an operand descriptor */
349
350 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
351 case ACPI_DESC_TYPE_OPERAND:
352 type = obj_desc->common.type;
353 break;
354
355 case ACPI_DESC_TYPE_NAMED:
356 type = ((struct acpi_namespace_node *)obj_desc)->type;
357 obj_desc =
358 acpi_ns_get_attached_object((struct acpi_namespace_node *)
359 obj_desc);
360
361 /* If we had an Alias node, use the attached object for type info */
362
363 if (type == ACPI_TYPE_LOCAL_ALIAS) {
364 type = ((struct acpi_namespace_node *)obj_desc)->type;
365 obj_desc =
366 acpi_ns_get_attached_object((struct
367 acpi_namespace_node *)
368 obj_desc);
369 }
370 break;
371
372 default:
373 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
374 }
375
376 /* If type is anything other than a reference, we are done */
377
378 if (type != ACPI_TYPE_LOCAL_REFERENCE) {
379 goto exit;
380 }
381
382 /*
383 * For reference objects created via the ref_of, Index, or Load/load_table
384 * operators, we need to get to the base object (as per the ACPI
385 * specification of the object_type and size_of operators). This means
386 * traversing the list of possibly many nested references.
387 */
388 while (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) {
389 switch (obj_desc->reference.class) {
390 case ACPI_REFCLASS_REFOF:
391 case ACPI_REFCLASS_NAME:
392
393 /* Dereference the reference pointer */
394
395 if (obj_desc->reference.class == ACPI_REFCLASS_REFOF) {
396 node = obj_desc->reference.object;
397 } else { /* AML_INT_NAMEPATH_OP */
398
399 node = obj_desc->reference.node;
400 }
401
402 /* All "References" point to a NS node */
403
404 if (ACPI_GET_DESCRIPTOR_TYPE(node) !=
405 ACPI_DESC_TYPE_NAMED) {
406 ACPI_ERROR((AE_INFO, "Not a NS node %p [%s]",
407 node,
408 acpi_ut_get_descriptor_name(node)));
409 return_ACPI_STATUS(AE_AML_INTERNAL);
410 }
411
412 /* Get the attached object */
413
414 obj_desc = acpi_ns_get_attached_object(node);
415 if (!obj_desc) {
416
417 /* No object, use the NS node type */
418
419 type = acpi_ns_get_type(node);
420 goto exit;
421 }
422
423 /* Check for circular references */
424
425 if (obj_desc == operand) {
426 return_ACPI_STATUS(AE_AML_CIRCULAR_REFERENCE);
427 }
428 break;
429
430 case ACPI_REFCLASS_INDEX:
431
432 /* Get the type of this reference (index into another object) */
433
434 type = obj_desc->reference.target_type;
435 if (type != ACPI_TYPE_PACKAGE) {
436 goto exit;
437 }
438
439 /*
440 * The main object is a package, we want to get the type
441 * of the individual package element that is referenced by
442 * the index.
443 *
444 * This could of course in turn be another reference object.
445 */
446 obj_desc = *(obj_desc->reference.where);
447 if (!obj_desc) {
448
449 /* NULL package elements are allowed */
450
451 type = 0; /* Uninitialized */
452 goto exit;
453 }
454 break;
455
456 case ACPI_REFCLASS_TABLE:
457
458 type = ACPI_TYPE_DDB_HANDLE;
459 goto exit;
460
461 case ACPI_REFCLASS_LOCAL:
462 case ACPI_REFCLASS_ARG:
463
464 if (return_desc) {
465 status =
466 acpi_ds_method_data_get_value(obj_desc->
467 reference.
468 class,
469 obj_desc->
470 reference.
471 value,
472 walk_state,
473 &obj_desc);
474 if (ACPI_FAILURE(status)) {
475 return_ACPI_STATUS(status);
476 }
477 acpi_ut_remove_reference(obj_desc);
478 } else {
479 status =
480 acpi_ds_method_data_get_node(obj_desc->
481 reference.
482 class,
483 obj_desc->
484 reference.
485 value,
486 walk_state,
487 &node);
488 if (ACPI_FAILURE(status)) {
489 return_ACPI_STATUS(status);
490 }
491
492 obj_desc = acpi_ns_get_attached_object(node);
493 if (!obj_desc) {
494 type = ACPI_TYPE_ANY;
495 goto exit;
496 }
497 }
498 break;
499
500 case ACPI_REFCLASS_DEBUG:
501
502 /* The Debug Object is of type "DebugObject" */
503
504 type = ACPI_TYPE_DEBUG_OBJECT;
505 goto exit;
506
507 default:
508
509 ACPI_ERROR((AE_INFO,
510 "Unknown Reference Class %2.2X",
511 obj_desc->reference.class));
512 return_ACPI_STATUS(AE_AML_INTERNAL);
513 }
514 }
515
516 /*
517 * Now we are guaranteed to have an object that has not been created
518 * via the ref_of or Index operators.
519 */
520 type = ACPI_GET_OBJECT_TYPE(obj_desc);
521
522 exit:
523 /* Convert internal types to external types */
524
525 switch (type) {
526 case ACPI_TYPE_LOCAL_REGION_FIELD:
527 case ACPI_TYPE_LOCAL_BANK_FIELD:
528 case ACPI_TYPE_LOCAL_INDEX_FIELD:
529
530 type = ACPI_TYPE_FIELD_UNIT;
531 break;
532
533 case ACPI_TYPE_LOCAL_SCOPE:
534
535 /* Per ACPI Specification, Scope is untyped */
536
537 type = ACPI_TYPE_ANY;
538 break;
539
540 default:
541 /* No change to Type required */
542 break;
543 }
544
545 *return_type = type;
546 if (return_desc) {
547 *return_desc = obj_desc;
548 }
549 return_ACPI_STATUS(AE_OK);
550}
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
deleted file mode 100644
index 0bb82593da72..000000000000
--- a/drivers/acpi/executer/exresop.c
+++ /dev/null
@@ -1,700 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exresop - AML Interpreter operand/object resolution
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/amlcode.h>
47#include <acpi/acparser.h>
48#include <acpi/acinterp.h>
49#include <acpi/acnamesp.h>
50
51#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("exresop")
53
54/* Local prototypes */
55static acpi_status
56acpi_ex_check_object_type(acpi_object_type type_needed,
57 acpi_object_type this_type, void *object);
58
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ex_check_object_type
62 *
63 * PARAMETERS: type_needed Object type needed
64 * this_type Actual object type
65 * Object Object pointer
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Check required type against actual type
70 *
71 ******************************************************************************/
72
73static acpi_status
74acpi_ex_check_object_type(acpi_object_type type_needed,
75 acpi_object_type this_type, void *object)
76{
77 ACPI_FUNCTION_ENTRY();
78
79 if (type_needed == ACPI_TYPE_ANY) {
80
81 /* All types OK, so we don't perform any typechecks */
82
83 return (AE_OK);
84 }
85
86 if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
87 /*
88 * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
89 * objects and thus allow them to be targets. (As per the ACPI
90 * specification, a store to a constant is a noop.)
91 */
92 if ((this_type == ACPI_TYPE_INTEGER) &&
93 (((union acpi_operand_object *)object)->common.
94 flags & AOPOBJ_AML_CONSTANT)) {
95 return (AE_OK);
96 }
97 }
98
99 if (type_needed != this_type) {
100 ACPI_ERROR((AE_INFO,
101 "Needed type [%s], found [%s] %p",
102 acpi_ut_get_type_name(type_needed),
103 acpi_ut_get_type_name(this_type), object));
104
105 return (AE_AML_OPERAND_TYPE);
106 }
107
108 return (AE_OK);
109}
110
111/*******************************************************************************
112 *
113 * FUNCTION: acpi_ex_resolve_operands
114 *
115 * PARAMETERS: Opcode - Opcode being interpreted
116 * stack_ptr - Pointer to the operand stack to be
117 * resolved
118 * walk_state - Current state
119 *
120 * RETURN: Status
121 *
122 * DESCRIPTION: Convert multiple input operands to the types required by the
123 * target operator.
124 *
125 * Each 5-bit group in arg_types represents one required
126 * operand and indicates the required Type. The corresponding operand
127 * will be converted to the required type if possible, otherwise we
128 * abort with an exception.
129 *
130 ******************************************************************************/
131
132acpi_status
133acpi_ex_resolve_operands(u16 opcode,
134 union acpi_operand_object ** stack_ptr,
135 struct acpi_walk_state * walk_state)
136{
137 union acpi_operand_object *obj_desc;
138 acpi_status status = AE_OK;
139 u8 object_type;
140 u32 arg_types;
141 const struct acpi_opcode_info *op_info;
142 u32 this_arg_type;
143 acpi_object_type type_needed;
144 u16 target_op = 0;
145
146 ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
147
148 op_info = acpi_ps_get_opcode_info(opcode);
149 if (op_info->class == AML_CLASS_UNKNOWN) {
150 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
151 }
152
153 arg_types = op_info->runtime_args;
154 if (arg_types == ARGI_INVALID_OPCODE) {
155 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", opcode));
156
157 return_ACPI_STATUS(AE_AML_INTERNAL);
158 }
159
160 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
161 "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
162 opcode, op_info->name, arg_types));
163
164 /*
165 * Normal exit is with (arg_types == 0) at end of argument list.
166 * Function will return an exception from within the loop upon
167 * finding an entry which is not (or cannot be converted
168 * to) the required type; if stack underflows; or upon
169 * finding a NULL stack entry (which should not happen).
170 */
171 while (GET_CURRENT_ARG_TYPE(arg_types)) {
172 if (!stack_ptr || !*stack_ptr) {
173 ACPI_ERROR((AE_INFO, "Null stack entry at %p",
174 stack_ptr));
175
176 return_ACPI_STATUS(AE_AML_INTERNAL);
177 }
178
179 /* Extract useful items */
180
181 obj_desc = *stack_ptr;
182
183 /* Decode the descriptor type */
184
185 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
186 case ACPI_DESC_TYPE_NAMED:
187
188 /* Namespace Node */
189
190 object_type =
191 ((struct acpi_namespace_node *)obj_desc)->type;
192
193 /*
194 * Resolve an alias object. The construction of these objects
195 * guarantees that there is only one level of alias indirection;
196 * thus, the attached object is always the aliased namespace node
197 */
198 if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
199 obj_desc =
200 acpi_ns_get_attached_object((struct
201 acpi_namespace_node
202 *)obj_desc);
203 *stack_ptr = obj_desc;
204 object_type =
205 ((struct acpi_namespace_node *)obj_desc)->
206 type;
207 }
208 break;
209
210 case ACPI_DESC_TYPE_OPERAND:
211
212 /* ACPI internal object */
213
214 object_type = ACPI_GET_OBJECT_TYPE(obj_desc);
215
216 /* Check for bad acpi_object_type */
217
218 if (!acpi_ut_valid_object_type(object_type)) {
219 ACPI_ERROR((AE_INFO,
220 "Bad operand object type [%X]",
221 object_type));
222
223 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
224 }
225
226 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
227
228 /* Validate the Reference */
229
230 switch (obj_desc->reference.class) {
231 case ACPI_REFCLASS_DEBUG:
232
233 target_op = AML_DEBUG_OP;
234
235 /*lint -fallthrough */
236
237 case ACPI_REFCLASS_ARG:
238 case ACPI_REFCLASS_LOCAL:
239 case ACPI_REFCLASS_INDEX:
240 case ACPI_REFCLASS_REFOF:
241 case ACPI_REFCLASS_TABLE: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
242 case ACPI_REFCLASS_NAME: /* Reference to a named object */
243
244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
245 "Operand is a Reference, Class [%s] %2.2X\n",
246 acpi_ut_get_reference_name
247 (obj_desc),
248 obj_desc->reference.
249 class));
250 break;
251
252 default:
253
254 ACPI_ERROR((AE_INFO,
255 "Unknown Reference Class %2.2X in %p",
256 obj_desc->reference.class,
257 obj_desc));
258
259 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
260 }
261 }
262 break;
263
264 default:
265
266 /* Invalid descriptor */
267
268 ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]",
269 obj_desc,
270 acpi_ut_get_descriptor_name(obj_desc)));
271
272 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
273 }
274
275 /* Get one argument type, point to the next */
276
277 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
278 INCREMENT_ARG_LIST(arg_types);
279
280 /*
281 * Handle cases where the object does not need to be
282 * resolved to a value
283 */
284 switch (this_arg_type) {
285 case ARGI_REF_OR_STRING: /* Can be a String or Reference */
286
287 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
288 ACPI_DESC_TYPE_OPERAND)
289 && (ACPI_GET_OBJECT_TYPE(obj_desc) ==
290 ACPI_TYPE_STRING)) {
291 /*
292 * String found - the string references a named object and
293 * must be resolved to a node
294 */
295 goto next_operand;
296 }
297
298 /*
299 * Else not a string - fall through to the normal Reference
300 * case below
301 */
302 /*lint -fallthrough */
303
304 case ARGI_REFERENCE: /* References: */
305 case ARGI_INTEGER_REF:
306 case ARGI_OBJECT_REF:
307 case ARGI_DEVICE_REF:
308 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
309 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
310 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
311
312 /*
313 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
314 * A Namespace Node is OK as-is
315 */
316 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
317 ACPI_DESC_TYPE_NAMED) {
318 goto next_operand;
319 }
320
321 status =
322 acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
323 object_type, obj_desc);
324 if (ACPI_FAILURE(status)) {
325 return_ACPI_STATUS(status);
326 }
327 goto next_operand;
328
329 case ARGI_DATAREFOBJ: /* Store operator only */
330
331 /*
332 * We don't want to resolve index_op reference objects during
333 * a store because this would be an implicit de_ref_of operation.
334 * Instead, we just want to store the reference object.
335 * -- All others must be resolved below.
336 */
337 if ((opcode == AML_STORE_OP) &&
338 (ACPI_GET_OBJECT_TYPE(*stack_ptr) ==
339 ACPI_TYPE_LOCAL_REFERENCE)
340 && ((*stack_ptr)->reference.class == ACPI_REFCLASS_INDEX)) {
341 goto next_operand;
342 }
343 break;
344
345 default:
346 /* All cases covered above */
347 break;
348 }
349
350 /*
351 * Resolve this object to a value
352 */
353 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
354 if (ACPI_FAILURE(status)) {
355 return_ACPI_STATUS(status);
356 }
357
358 /* Get the resolved object */
359
360 obj_desc = *stack_ptr;
361
362 /*
363 * Check the resulting object (value) type
364 */
365 switch (this_arg_type) {
366 /*
367 * For the simple cases, only one type of resolved object
368 * is allowed
369 */
370 case ARGI_MUTEX:
371
372 /* Need an operand of type ACPI_TYPE_MUTEX */
373
374 type_needed = ACPI_TYPE_MUTEX;
375 break;
376
377 case ARGI_EVENT:
378
379 /* Need an operand of type ACPI_TYPE_EVENT */
380
381 type_needed = ACPI_TYPE_EVENT;
382 break;
383
384 case ARGI_PACKAGE: /* Package */
385
386 /* Need an operand of type ACPI_TYPE_PACKAGE */
387
388 type_needed = ACPI_TYPE_PACKAGE;
389 break;
390
391 case ARGI_ANYTYPE:
392
393 /* Any operand type will do */
394
395 type_needed = ACPI_TYPE_ANY;
396 break;
397
398 case ARGI_DDBHANDLE:
399
400 /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
401
402 type_needed = ACPI_TYPE_LOCAL_REFERENCE;
403 break;
404
405 /*
406 * The more complex cases allow multiple resolved object types
407 */
408 case ARGI_INTEGER:
409
410 /*
411 * Need an operand of type ACPI_TYPE_INTEGER,
412 * But we can implicitly convert from a STRING or BUFFER
413 * Aka - "Implicit Source Operand Conversion"
414 */
415 status =
416 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
417 if (ACPI_FAILURE(status)) {
418 if (status == AE_TYPE) {
419 ACPI_ERROR((AE_INFO,
420 "Needed [Integer/String/Buffer], found [%s] %p",
421 acpi_ut_get_object_type_name
422 (obj_desc), obj_desc));
423
424 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
425 }
426
427 return_ACPI_STATUS(status);
428 }
429
430 if (obj_desc != *stack_ptr) {
431 acpi_ut_remove_reference(obj_desc);
432 }
433 goto next_operand;
434
435 case ARGI_BUFFER:
436
437 /*
438 * Need an operand of type ACPI_TYPE_BUFFER,
439 * But we can implicitly convert from a STRING or INTEGER
440 * Aka - "Implicit Source Operand Conversion"
441 */
442 status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
443 if (ACPI_FAILURE(status)) {
444 if (status == AE_TYPE) {
445 ACPI_ERROR((AE_INFO,
446 "Needed [Integer/String/Buffer], found [%s] %p",
447 acpi_ut_get_object_type_name
448 (obj_desc), obj_desc));
449
450 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
451 }
452
453 return_ACPI_STATUS(status);
454 }
455
456 if (obj_desc != *stack_ptr) {
457 acpi_ut_remove_reference(obj_desc);
458 }
459 goto next_operand;
460
461 case ARGI_STRING:
462
463 /*
464 * Need an operand of type ACPI_TYPE_STRING,
465 * But we can implicitly convert from a BUFFER or INTEGER
466 * Aka - "Implicit Source Operand Conversion"
467 */
468 status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
469 ACPI_IMPLICIT_CONVERT_HEX);
470 if (ACPI_FAILURE(status)) {
471 if (status == AE_TYPE) {
472 ACPI_ERROR((AE_INFO,
473 "Needed [Integer/String/Buffer], found [%s] %p",
474 acpi_ut_get_object_type_name
475 (obj_desc), obj_desc));
476
477 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
478 }
479
480 return_ACPI_STATUS(status);
481 }
482
483 if (obj_desc != *stack_ptr) {
484 acpi_ut_remove_reference(obj_desc);
485 }
486 goto next_operand;
487
488 case ARGI_COMPUTEDATA:
489
490 /* Need an operand of type INTEGER, STRING or BUFFER */
491
492 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
493 case ACPI_TYPE_INTEGER:
494 case ACPI_TYPE_STRING:
495 case ACPI_TYPE_BUFFER:
496
497 /* Valid operand */
498 break;
499
500 default:
501 ACPI_ERROR((AE_INFO,
502 "Needed [Integer/String/Buffer], found [%s] %p",
503 acpi_ut_get_object_type_name
504 (obj_desc), obj_desc));
505
506 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
507 }
508 goto next_operand;
509
510 case ARGI_BUFFER_OR_STRING:
511
512 /* Need an operand of type STRING or BUFFER */
513
514 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
515 case ACPI_TYPE_STRING:
516 case ACPI_TYPE_BUFFER:
517
518 /* Valid operand */
519 break;
520
521 case ACPI_TYPE_INTEGER:
522
523 /* Highest priority conversion is to type Buffer */
524
525 status =
526 acpi_ex_convert_to_buffer(obj_desc,
527 stack_ptr);
528 if (ACPI_FAILURE(status)) {
529 return_ACPI_STATUS(status);
530 }
531
532 if (obj_desc != *stack_ptr) {
533 acpi_ut_remove_reference(obj_desc);
534 }
535 break;
536
537 default:
538 ACPI_ERROR((AE_INFO,
539 "Needed [Integer/String/Buffer], found [%s] %p",
540 acpi_ut_get_object_type_name
541 (obj_desc), obj_desc));
542
543 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
544 }
545 goto next_operand;
546
547 case ARGI_DATAOBJECT:
548 /*
549 * ARGI_DATAOBJECT is only used by the size_of operator.
550 * Need a buffer, string, package, or ref_of reference.
551 *
552 * The only reference allowed here is a direct reference to
553 * a namespace node.
554 */
555 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
556 case ACPI_TYPE_PACKAGE:
557 case ACPI_TYPE_STRING:
558 case ACPI_TYPE_BUFFER:
559 case ACPI_TYPE_LOCAL_REFERENCE:
560
561 /* Valid operand */
562 break;
563
564 default:
565 ACPI_ERROR((AE_INFO,
566 "Needed [Buffer/String/Package/Reference], found [%s] %p",
567 acpi_ut_get_object_type_name
568 (obj_desc), obj_desc));
569
570 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
571 }
572 goto next_operand;
573
574 case ARGI_COMPLEXOBJ:
575
576 /* Need a buffer or package or (ACPI 2.0) String */
577
578 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
579 case ACPI_TYPE_PACKAGE:
580 case ACPI_TYPE_STRING:
581 case ACPI_TYPE_BUFFER:
582
583 /* Valid operand */
584 break;
585
586 default:
587 ACPI_ERROR((AE_INFO,
588 "Needed [Buffer/String/Package], found [%s] %p",
589 acpi_ut_get_object_type_name
590 (obj_desc), obj_desc));
591
592 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
593 }
594 goto next_operand;
595
596 case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
597
598 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
599
600 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
601 case ACPI_TYPE_BUFFER:
602 case ACPI_TYPE_REGION:
603
604 /* Valid operand */
605 break;
606
607 default:
608 ACPI_ERROR((AE_INFO,
609 "Needed [Region/Buffer], found [%s] %p",
610 acpi_ut_get_object_type_name
611 (obj_desc), obj_desc));
612
613 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
614 }
615 goto next_operand;
616
617 case ARGI_DATAREFOBJ:
618
619 /* Used by the Store() operator only */
620
621 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
622 case ACPI_TYPE_INTEGER:
623 case ACPI_TYPE_PACKAGE:
624 case ACPI_TYPE_STRING:
625 case ACPI_TYPE_BUFFER:
626 case ACPI_TYPE_BUFFER_FIELD:
627 case ACPI_TYPE_LOCAL_REFERENCE:
628 case ACPI_TYPE_LOCAL_REGION_FIELD:
629 case ACPI_TYPE_LOCAL_BANK_FIELD:
630 case ACPI_TYPE_LOCAL_INDEX_FIELD:
631 case ACPI_TYPE_DDB_HANDLE:
632
633 /* Valid operand */
634 break;
635
636 default:
637
638 if (acpi_gbl_enable_interpreter_slack) {
639 /*
640 * Enable original behavior of Store(), allowing any and all
641 * objects as the source operand. The ACPI spec does not
642 * allow this, however.
643 */
644 break;
645 }
646
647 if (target_op == AML_DEBUG_OP) {
648
649 /* Allow store of any object to the Debug object */
650
651 break;
652 }
653
654 ACPI_ERROR((AE_INFO,
655 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
656 acpi_ut_get_object_type_name
657 (obj_desc), obj_desc));
658
659 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
660 }
661 goto next_operand;
662
663 default:
664
665 /* Unknown type */
666
667 ACPI_ERROR((AE_INFO,
668 "Internal - Unknown ARGI (required operand) type %X",
669 this_arg_type));
670
671 return_ACPI_STATUS(AE_BAD_PARAMETER);
672 }
673
674 /*
675 * Make sure that the original object was resolved to the
676 * required object type (Simple cases only).
677 */
678 status = acpi_ex_check_object_type(type_needed,
679 ACPI_GET_OBJECT_TYPE
680 (*stack_ptr), *stack_ptr);
681 if (ACPI_FAILURE(status)) {
682 return_ACPI_STATUS(status);
683 }
684
685 next_operand:
686 /*
687 * If more operands needed, decrement stack_ptr to point
688 * to next operand on stack
689 */
690 if (GET_CURRENT_ARG_TYPE(arg_types)) {
691 stack_ptr--;
692 }
693 }
694
695 ACPI_DUMP_OPERANDS(walk_state->operands,
696 acpi_ps_get_opcode_name(opcode),
697 walk_state->num_operands);
698
699 return_ACPI_STATUS(status);
700}
diff --git a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c
deleted file mode 100644
index 1c118ba78adb..000000000000
--- a/drivers/acpi/executer/exstore.c
+++ /dev/null
@@ -1,715 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exstore - AML Interpreter object store support
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acdispat.h>
47#include <acpi/acinterp.h>
48#include <acpi/amlcode.h>
49#include <acpi/acnamesp.h>
50
51#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("exstore")
53
54/* Local prototypes */
55static void
56acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
57 u32 level, u32 index);
58
59static acpi_status
60acpi_ex_store_object_to_index(union acpi_operand_object *val_desc,
61 union acpi_operand_object *dest_desc,
62 struct acpi_walk_state *walk_state);
63
64/*******************************************************************************
65 *
66 * FUNCTION: acpi_ex_do_debug_object
67 *
68 * PARAMETERS: source_desc - Value to be stored
69 * Level - Indentation level (used for packages)
70 * Index - Current package element, zero if not pkg
71 *
72 * RETURN: None
73 *
74 * DESCRIPTION: Handles stores to the Debug Object.
75 *
76 ******************************************************************************/
77
78static void
79acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
80 u32 level, u32 index)
81{
82 u32 i;
83
84 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
85
86 /* Print line header as long as we are not in the middle of an object display */
87
88 if (!((level > 0) && index == 0)) {
89 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
90 level, " "));
91 }
92
93 /* Display index for package output only */
94
95 if (index > 0) {
96 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
97 "(%.2u) ", index - 1));
98 }
99
100 if (!source_desc) {
101 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[Null Object]\n"));
102 return_VOID;
103 }
104
105 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
106 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s ",
107 acpi_ut_get_object_type_name
108 (source_desc)));
109
110 if (!acpi_ut_valid_internal_object(source_desc)) {
111 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
112 "%p, Invalid Internal Object!\n",
113 source_desc));
114 return_VOID;
115 }
116 } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
117 ACPI_DESC_TYPE_NAMED) {
118 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
119 acpi_ut_get_type_name(((struct
120 acpi_namespace_node
121 *)source_desc)->
122 type),
123 source_desc));
124 return_VOID;
125 } else {
126 return_VOID;
127 }
128
129 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
130
131 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
132 case ACPI_TYPE_INTEGER:
133
134 /* Output correct integer width */
135
136 if (acpi_gbl_integer_byte_width == 4) {
137 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
138 (u32) source_desc->integer.
139 value));
140 } else {
141 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
142 "0x%8.8X%8.8X\n",
143 ACPI_FORMAT_UINT64(source_desc->
144 integer.
145 value)));
146 }
147 break;
148
149 case ACPI_TYPE_BUFFER:
150
151 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n",
152 (u32) source_desc->buffer.length));
153 ACPI_DUMP_BUFFER(source_desc->buffer.pointer,
154 (source_desc->buffer.length <
155 256) ? source_desc->buffer.length : 256);
156 break;
157
158 case ACPI_TYPE_STRING:
159
160 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
161 source_desc->string.length,
162 source_desc->string.pointer));
163 break;
164
165 case ACPI_TYPE_PACKAGE:
166
167 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
168 "[Contains 0x%.2X Elements]\n",
169 source_desc->package.count));
170
171 /* Output the entire contents of the package */
172
173 for (i = 0; i < source_desc->package.count; i++) {
174 acpi_ex_do_debug_object(source_desc->package.
175 elements[i], level + 4, i + 1);
176 }
177 break;
178
179 case ACPI_TYPE_LOCAL_REFERENCE:
180
181 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s] ",
182 acpi_ut_get_reference_name(source_desc)));
183
184 /* Decode the reference */
185
186 switch (source_desc->reference.class) {
187 case ACPI_REFCLASS_INDEX:
188
189 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%X\n",
190 source_desc->reference.value));
191 break;
192
193 case ACPI_REFCLASS_TABLE:
194
195 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
196 "Table Index 0x%X\n",
197 source_desc->reference.value));
198 break;
199
200 default:
201 break;
202 }
203
204 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, " "));
205
206 /* Check for valid node first, then valid object */
207
208 if (source_desc->reference.node) {
209 if (ACPI_GET_DESCRIPTOR_TYPE
210 (source_desc->reference.node) !=
211 ACPI_DESC_TYPE_NAMED) {
212 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
213 " %p - Not a valid namespace node\n",
214 source_desc->reference.
215 node));
216 } else {
217 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
218 "Node %p [%4.4s] ",
219 source_desc->reference.
220 node,
221 (source_desc->reference.
222 node)->name.ascii));
223
224 switch ((source_desc->reference.node)->type) {
225
226 /* These types have no attached object */
227
228 case ACPI_TYPE_DEVICE:
229 acpi_os_printf("Device\n");
230 break;
231
232 case ACPI_TYPE_THERMAL:
233 acpi_os_printf("Thermal Zone\n");
234 break;
235
236 default:
237 acpi_ex_do_debug_object((source_desc->
238 reference.
239 node)->object,
240 level + 4, 0);
241 break;
242 }
243 }
244 } else if (source_desc->reference.object) {
245 if (ACPI_GET_DESCRIPTOR_TYPE
246 (source_desc->reference.object) ==
247 ACPI_DESC_TYPE_NAMED) {
248 acpi_ex_do_debug_object(((struct
249 acpi_namespace_node *)
250 source_desc->reference.
251 object)->object,
252 level + 4, 0);
253 } else {
254 acpi_ex_do_debug_object(source_desc->reference.
255 object, level + 4, 0);
256 }
257 }
258 break;
259
260 default:
261
262 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p\n",
263 source_desc));
264 break;
265 }
266
267 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
268 return_VOID;
269}
270
271/*******************************************************************************
272 *
273 * FUNCTION: acpi_ex_store
274 *
275 * PARAMETERS: *source_desc - Value to be stored
276 * *dest_desc - Where to store it. Must be an NS node
277 * or a union acpi_operand_object of type
278 * Reference;
279 * walk_state - Current walk state
280 *
281 * RETURN: Status
282 *
283 * DESCRIPTION: Store the value described by source_desc into the location
284 * described by dest_desc. Called by various interpreter
285 * functions to store the result of an operation into
286 * the destination operand -- not just simply the actual "Store"
287 * ASL operator.
288 *
289 ******************************************************************************/
290
291acpi_status
292acpi_ex_store(union acpi_operand_object *source_desc,
293 union acpi_operand_object *dest_desc,
294 struct acpi_walk_state *walk_state)
295{
296 acpi_status status = AE_OK;
297 union acpi_operand_object *ref_desc = dest_desc;
298
299 ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc);
300
301 /* Validate parameters */
302
303 if (!source_desc || !dest_desc) {
304 ACPI_ERROR((AE_INFO, "Null parameter"));
305 return_ACPI_STATUS(AE_AML_NO_OPERAND);
306 }
307
308 /* dest_desc can be either a namespace node or an ACPI object */
309
310 if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) {
311 /*
312 * Dest is a namespace node,
313 * Storing an object into a Named node.
314 */
315 status = acpi_ex_store_object_to_node(source_desc,
316 (struct
317 acpi_namespace_node *)
318 dest_desc, walk_state,
319 ACPI_IMPLICIT_CONVERSION);
320
321 return_ACPI_STATUS(status);
322 }
323
324 /* Destination object must be a Reference or a Constant object */
325
326 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
327 case ACPI_TYPE_LOCAL_REFERENCE:
328 break;
329
330 case ACPI_TYPE_INTEGER:
331
332 /* Allow stores to Constants -- a Noop as per ACPI spec */
333
334 if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
335 return_ACPI_STATUS(AE_OK);
336 }
337
338 /*lint -fallthrough */
339
340 default:
341
342 /* Destination is not a Reference object */
343
344 ACPI_ERROR((AE_INFO,
345 "Target is not a Reference or Constant object - %s [%p]",
346 acpi_ut_get_object_type_name(dest_desc),
347 dest_desc));
348
349 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
350 }
351
352 /*
353 * Examine the Reference class. These cases are handled:
354 *
355 * 1) Store to Name (Change the object associated with a name)
356 * 2) Store to an indexed area of a Buffer or Package
357 * 3) Store to a Method Local or Arg
358 * 4) Store to the debug object
359 */
360 switch (ref_desc->reference.class) {
361 case ACPI_REFCLASS_REFOF:
362
363 /* Storing an object into a Name "container" */
364
365 status = acpi_ex_store_object_to_node(source_desc,
366 ref_desc->reference.
367 object, walk_state,
368 ACPI_IMPLICIT_CONVERSION);
369 break;
370
371 case ACPI_REFCLASS_INDEX:
372
373 /* Storing to an Index (pointer into a packager or buffer) */
374
375 status =
376 acpi_ex_store_object_to_index(source_desc, ref_desc,
377 walk_state);
378 break;
379
380 case ACPI_REFCLASS_LOCAL:
381 case ACPI_REFCLASS_ARG:
382
383 /* Store to a method local/arg */
384
385 status =
386 acpi_ds_store_object_to_local(ref_desc->reference.class,
387 ref_desc->reference.value,
388 source_desc, walk_state);
389 break;
390
391 case ACPI_REFCLASS_DEBUG:
392
393 /*
394 * Storing to the Debug object causes the value stored to be
395 * displayed and otherwise has no effect -- see ACPI Specification
396 */
397 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
398 "**** Write to Debug Object: Object %p %s ****:\n\n",
399 source_desc,
400 acpi_ut_get_object_type_name(source_desc)));
401
402 acpi_ex_do_debug_object(source_desc, 0, 0);
403 break;
404
405 default:
406
407 ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X",
408 ref_desc->reference.class));
409 ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_INFO);
410
411 status = AE_AML_INTERNAL;
412 break;
413 }
414
415 return_ACPI_STATUS(status);
416}
417
418/*******************************************************************************
419 *
420 * FUNCTION: acpi_ex_store_object_to_index
421 *
422 * PARAMETERS: *source_desc - Value to be stored
423 * *dest_desc - Named object to receive the value
424 * walk_state - Current walk state
425 *
426 * RETURN: Status
427 *
428 * DESCRIPTION: Store the object to indexed Buffer or Package element
429 *
430 ******************************************************************************/
431
432static acpi_status
433acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
434 union acpi_operand_object *index_desc,
435 struct acpi_walk_state *walk_state)
436{
437 acpi_status status = AE_OK;
438 union acpi_operand_object *obj_desc;
439 union acpi_operand_object *new_desc;
440 u8 value = 0;
441 u32 i;
442
443 ACPI_FUNCTION_TRACE(ex_store_object_to_index);
444
445 /*
446 * Destination must be a reference pointer, and
447 * must point to either a buffer or a package
448 */
449 switch (index_desc->reference.target_type) {
450 case ACPI_TYPE_PACKAGE:
451 /*
452 * Storing to a package element. Copy the object and replace
453 * any existing object with the new object. No implicit
454 * conversion is performed.
455 *
456 * The object at *(index_desc->Reference.Where) is the
457 * element within the package that is to be modified.
458 * The parent package object is at index_desc->Reference.Object
459 */
460 obj_desc = *(index_desc->reference.where);
461
462 if (ACPI_GET_OBJECT_TYPE(source_desc) ==
463 ACPI_TYPE_LOCAL_REFERENCE
464 && source_desc->reference.class == ACPI_REFCLASS_TABLE) {
465
466 /* This is a DDBHandle, just add a reference to it */
467
468 acpi_ut_add_reference(source_desc);
469 new_desc = source_desc;
470 } else {
471 /* Normal object, copy it */
472
473 status =
474 acpi_ut_copy_iobject_to_iobject(source_desc,
475 &new_desc,
476 walk_state);
477 if (ACPI_FAILURE(status)) {
478 return_ACPI_STATUS(status);
479 }
480 }
481
482 if (obj_desc) {
483
484 /* Decrement reference count by the ref count of the parent package */
485
486 for (i = 0; i < ((union acpi_operand_object *)
487 index_desc->reference.object)->common.
488 reference_count; i++) {
489 acpi_ut_remove_reference(obj_desc);
490 }
491 }
492
493 *(index_desc->reference.where) = new_desc;
494
495 /* Increment ref count by the ref count of the parent package-1 */
496
497 for (i = 1; i < ((union acpi_operand_object *)
498 index_desc->reference.object)->common.
499 reference_count; i++) {
500 acpi_ut_add_reference(new_desc);
501 }
502
503 break;
504
505 case ACPI_TYPE_BUFFER_FIELD:
506
507 /*
508 * Store into a Buffer or String (not actually a real buffer_field)
509 * at a location defined by an Index.
510 *
511 * The first 8-bit element of the source object is written to the
512 * 8-bit Buffer location defined by the Index destination object,
513 * according to the ACPI 2.0 specification.
514 */
515
516 /*
517 * Make sure the target is a Buffer or String. An error should
518 * not happen here, since the reference_object was constructed
519 * by the INDEX_OP code.
520 */
521 obj_desc = index_desc->reference.object;
522 if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) &&
523 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) {
524 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
525 }
526
527 /*
528 * The assignment of the individual elements will be slightly
529 * different for each source type.
530 */
531 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
532 case ACPI_TYPE_INTEGER:
533
534 /* Use the least-significant byte of the integer */
535
536 value = (u8) (source_desc->integer.value);
537 break;
538
539 case ACPI_TYPE_BUFFER:
540 case ACPI_TYPE_STRING:
541
542 /* Note: Takes advantage of common string/buffer fields */
543
544 value = source_desc->buffer.pointer[0];
545 break;
546
547 default:
548
549 /* All other types are invalid */
550
551 ACPI_ERROR((AE_INFO,
552 "Source must be Integer/Buffer/String type, not %s",
553 acpi_ut_get_object_type_name(source_desc)));
554 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
555 }
556
557 /* Store the source value into the target buffer byte */
558
559 obj_desc->buffer.pointer[index_desc->reference.value] = value;
560 break;
561
562 default:
563 ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField"));
564 status = AE_AML_OPERAND_TYPE;
565 break;
566 }
567
568 return_ACPI_STATUS(status);
569}
570
571/*******************************************************************************
572 *
573 * FUNCTION: acpi_ex_store_object_to_node
574 *
575 * PARAMETERS: source_desc - Value to be stored
576 * Node - Named object to receive the value
577 * walk_state - Current walk state
578 * implicit_conversion - Perform implicit conversion (yes/no)
579 *
580 * RETURN: Status
581 *
582 * DESCRIPTION: Store the object to the named object.
583 *
584 * The Assignment of an object to a named object is handled here
585 * The value passed in will replace the current value (if any)
586 * with the input value.
587 *
588 * When storing into an object the data is converted to the
589 * target object type then stored in the object. This means
590 * that the target object type (for an initialized target) will
591 * not be changed by a store operation.
592 *
593 * Assumes parameters are already validated.
594 *
595 ******************************************************************************/
596
597acpi_status
598acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
599 struct acpi_namespace_node *node,
600 struct acpi_walk_state *walk_state,
601 u8 implicit_conversion)
602{
603 acpi_status status = AE_OK;
604 union acpi_operand_object *target_desc;
605 union acpi_operand_object *new_desc;
606 acpi_object_type target_type;
607
608 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc);
609
610 /* Get current type of the node, and object attached to Node */
611
612 target_type = acpi_ns_get_type(node);
613 target_desc = acpi_ns_get_attached_object(node);
614
615 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
616 source_desc,
617 acpi_ut_get_object_type_name(source_desc), node,
618 acpi_ut_get_type_name(target_type)));
619
620 /*
621 * Resolve the source object to an actual value
622 * (If it is a reference object)
623 */
624 status = acpi_ex_resolve_object(&source_desc, target_type, walk_state);
625 if (ACPI_FAILURE(status)) {
626 return_ACPI_STATUS(status);
627 }
628
629 /* If no implicit conversion, drop into the default case below */
630
631 if ((!implicit_conversion) ||
632 ((walk_state->opcode == AML_COPY_OP) &&
633 (target_type != ACPI_TYPE_LOCAL_REGION_FIELD) &&
634 (target_type != ACPI_TYPE_LOCAL_BANK_FIELD) &&
635 (target_type != ACPI_TYPE_LOCAL_INDEX_FIELD))) {
636 /*
637 * Force execution of default (no implicit conversion). Note:
638 * copy_object does not perform an implicit conversion, as per the ACPI
639 * spec -- except in case of region/bank/index fields -- because these
640 * objects must retain their original type permanently.
641 */
642 target_type = ACPI_TYPE_ANY;
643 }
644
645 /* Do the actual store operation */
646
647 switch (target_type) {
648 case ACPI_TYPE_BUFFER_FIELD:
649 case ACPI_TYPE_LOCAL_REGION_FIELD:
650 case ACPI_TYPE_LOCAL_BANK_FIELD:
651 case ACPI_TYPE_LOCAL_INDEX_FIELD:
652
653 /* For fields, copy the source data to the target field. */
654
655 status = acpi_ex_write_data_to_field(source_desc, target_desc,
656 &walk_state->result_obj);
657 break;
658
659 case ACPI_TYPE_INTEGER:
660 case ACPI_TYPE_STRING:
661 case ACPI_TYPE_BUFFER:
662
663 /*
664 * These target types are all of type Integer/String/Buffer, and
665 * therefore support implicit conversion before the store.
666 *
667 * Copy and/or convert the source object to a new target object
668 */
669 status =
670 acpi_ex_store_object_to_object(source_desc, target_desc,
671 &new_desc, walk_state);
672 if (ACPI_FAILURE(status)) {
673 return_ACPI_STATUS(status);
674 }
675
676 if (new_desc != target_desc) {
677 /*
678 * Store the new new_desc as the new value of the Name, and set
679 * the Name's type to that of the value being stored in it.
680 * source_desc reference count is incremented by attach_object.
681 *
682 * Note: This may change the type of the node if an explicit store
683 * has been performed such that the node/object type has been
684 * changed.
685 */
686 status =
687 acpi_ns_attach_object(node, new_desc,
688 new_desc->common.type);
689
690 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
691 "Store %s into %s via Convert/Attach\n",
692 acpi_ut_get_object_type_name
693 (source_desc),
694 acpi_ut_get_object_type_name
695 (new_desc)));
696 }
697 break;
698
699 default:
700
701 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
702 "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
703 acpi_ut_get_object_type_name(source_desc),
704 source_desc, node));
705
706 /* No conversions for all other types. Just attach the source object */
707
708 status = acpi_ns_attach_object(node, source_desc,
709 ACPI_GET_OBJECT_TYPE
710 (source_desc));
711 break;
712 }
713
714 return_ACPI_STATUS(status);
715}
diff --git a/drivers/acpi/executer/exstoren.c b/drivers/acpi/executer/exstoren.c
deleted file mode 100644
index eef61a00803e..000000000000
--- a/drivers/acpi/executer/exstoren.c
+++ /dev/null
@@ -1,303 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exstoren - AML Interpreter object store support,
5 * Store to Node (namespace object)
6 *
7 *****************************************************************************/
8
9/*
10 * Copyright (C) 2000 - 2008, Intel Corp.
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions, and the following disclaimer,
18 * without modification.
19 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
20 * substantially similar to the "NO WARRANTY" disclaimer below
21 * ("Disclaimer") and any redistribution must be conditioned upon
22 * including a substantially similar Disclaimer requirement for further
23 * binary redistribution.
24 * 3. Neither the names of the above-listed copyright holders nor the names
25 * of any contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * Alternatively, this software may be distributed under the terms of the
29 * GNU General Public License ("GPL") version 2 as published by the Free
30 * Software Foundation.
31 *
32 * NO WARRANTY
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGES.
44 */
45
46#include <acpi/acpi.h>
47#include <acpi/acinterp.h>
48#include <acpi/amlcode.h>
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exstoren")
52
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_ex_resolve_object
56 *
57 * PARAMETERS: source_desc_ptr - Pointer to the source object
58 * target_type - Current type of the target
59 * walk_state - Current walk state
60 *
61 * RETURN: Status, resolved object in source_desc_ptr.
62 *
63 * DESCRIPTION: Resolve an object. If the object is a reference, dereference
64 * it and return the actual object in the source_desc_ptr.
65 *
66 ******************************************************************************/
67acpi_status
68acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
69 acpi_object_type target_type,
70 struct acpi_walk_state *walk_state)
71{
72 union acpi_operand_object *source_desc = *source_desc_ptr;
73 acpi_status status = AE_OK;
74
75 ACPI_FUNCTION_TRACE(ex_resolve_object);
76
77 /* Ensure we have a Target that can be stored to */
78
79 switch (target_type) {
80 case ACPI_TYPE_BUFFER_FIELD:
81 case ACPI_TYPE_LOCAL_REGION_FIELD:
82 case ACPI_TYPE_LOCAL_BANK_FIELD:
83 case ACPI_TYPE_LOCAL_INDEX_FIELD:
84 /*
85 * These cases all require only Integers or values that
86 * can be converted to Integers (Strings or Buffers)
87 */
88
89 case ACPI_TYPE_INTEGER:
90 case ACPI_TYPE_STRING:
91 case ACPI_TYPE_BUFFER:
92
93 /*
94 * Stores into a Field/Region or into a Integer/Buffer/String
95 * are all essentially the same. This case handles the
96 * "interchangeable" types Integer, String, and Buffer.
97 */
98 if (ACPI_GET_OBJECT_TYPE(source_desc) ==
99 ACPI_TYPE_LOCAL_REFERENCE) {
100
101 /* Resolve a reference object first */
102
103 status =
104 acpi_ex_resolve_to_value(source_desc_ptr,
105 walk_state);
106 if (ACPI_FAILURE(status)) {
107 break;
108 }
109 }
110
111 /* For copy_object, no further validation necessary */
112
113 if (walk_state->opcode == AML_COPY_OP) {
114 break;
115 }
116
117 /* Must have a Integer, Buffer, or String */
118
119 if ((ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) &&
120 (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) &&
121 (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) &&
122 !((ACPI_GET_OBJECT_TYPE(source_desc) ==
123 ACPI_TYPE_LOCAL_REFERENCE)
124 && (source_desc->reference.class ==
125 ACPI_REFCLASS_TABLE))) {
126
127 /* Conversion successful but still not a valid type */
128
129 ACPI_ERROR((AE_INFO,
130 "Cannot assign type %s to %s (must be type Int/Str/Buf)",
131 acpi_ut_get_object_type_name(source_desc),
132 acpi_ut_get_type_name(target_type)));
133 status = AE_AML_OPERAND_TYPE;
134 }
135 break;
136
137 case ACPI_TYPE_LOCAL_ALIAS:
138 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
139
140 /*
141 * All aliases should have been resolved earlier, during the
142 * operand resolution phase.
143 */
144 ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object"));
145 status = AE_AML_INTERNAL;
146 break;
147
148 case ACPI_TYPE_PACKAGE:
149 default:
150
151 /*
152 * All other types than Alias and the various Fields come here,
153 * including the untyped case - ACPI_TYPE_ANY.
154 */
155 break;
156 }
157
158 return_ACPI_STATUS(status);
159}
160
161/*******************************************************************************
162 *
163 * FUNCTION: acpi_ex_store_object_to_object
164 *
165 * PARAMETERS: source_desc - Object to store
166 * dest_desc - Object to receive a copy of the source
167 * new_desc - New object if dest_desc is obsoleted
168 * walk_state - Current walk state
169 *
170 * RETURN: Status
171 *
172 * DESCRIPTION: "Store" an object to another object. This may include
173 * converting the source type to the target type (implicit
174 * conversion), and a copy of the value of the source to
175 * the target.
176 *
177 * The Assignment of an object to another (not named) object
178 * is handled here.
179 * The Source passed in will replace the current value (if any)
180 * with the input value.
181 *
182 * When storing into an object the data is converted to the
183 * target object type then stored in the object. This means
184 * that the target object type (for an initialized target) will
185 * not be changed by a store operation.
186 *
187 * This module allows destination types of Number, String,
188 * Buffer, and Package.
189 *
190 * Assumes parameters are already validated. NOTE: source_desc
191 * resolution (from a reference object) must be performed by
192 * the caller if necessary.
193 *
194 ******************************************************************************/
195
196acpi_status
197acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
198 union acpi_operand_object *dest_desc,
199 union acpi_operand_object **new_desc,
200 struct acpi_walk_state *walk_state)
201{
202 union acpi_operand_object *actual_src_desc;
203 acpi_status status = AE_OK;
204
205 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc);
206
207 actual_src_desc = source_desc;
208 if (!dest_desc) {
209 /*
210 * There is no destination object (An uninitialized node or
211 * package element), so we can simply copy the source object
212 * creating a new destination object
213 */
214 status =
215 acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc,
216 walk_state);
217 return_ACPI_STATUS(status);
218 }
219
220 if (ACPI_GET_OBJECT_TYPE(source_desc) !=
221 ACPI_GET_OBJECT_TYPE(dest_desc)) {
222 /*
223 * The source type does not match the type of the destination.
224 * Perform the "implicit conversion" of the source to the current type
225 * of the target as per the ACPI specification.
226 *
227 * If no conversion performed, actual_src_desc = source_desc.
228 * Otherwise, actual_src_desc is a temporary object to hold the
229 * converted object.
230 */
231 status =
232 acpi_ex_convert_to_target_type(ACPI_GET_OBJECT_TYPE
233 (dest_desc), source_desc,
234 &actual_src_desc,
235 walk_state);
236 if (ACPI_FAILURE(status)) {
237 return_ACPI_STATUS(status);
238 }
239
240 if (source_desc == actual_src_desc) {
241 /*
242 * No conversion was performed. Return the source_desc as the
243 * new object.
244 */
245 *new_desc = source_desc;
246 return_ACPI_STATUS(AE_OK);
247 }
248 }
249
250 /*
251 * We now have two objects of identical types, and we can perform a
252 * copy of the *value* of the source object.
253 */
254 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
255 case ACPI_TYPE_INTEGER:
256
257 dest_desc->integer.value = actual_src_desc->integer.value;
258
259 /* Truncate value if we are executing from a 32-bit ACPI table */
260
261 acpi_ex_truncate_for32bit_table(dest_desc);
262 break;
263
264 case ACPI_TYPE_STRING:
265
266 status =
267 acpi_ex_store_string_to_string(actual_src_desc, dest_desc);
268 break;
269
270 case ACPI_TYPE_BUFFER:
271
272 status =
273 acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc);
274 break;
275
276 case ACPI_TYPE_PACKAGE:
277
278 status =
279 acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc,
280 walk_state);
281 break;
282
283 default:
284 /*
285 * All other types come here.
286 */
287 ACPI_WARNING((AE_INFO, "Store into type %s not implemented",
288 acpi_ut_get_object_type_name(dest_desc)));
289
290 status = AE_NOT_IMPLEMENTED;
291 break;
292 }
293
294 if (actual_src_desc != source_desc) {
295
296 /* Delete the intermediate (temporary) source object */
297
298 acpi_ut_remove_reference(actual_src_desc);
299 }
300
301 *new_desc = dest_desc;
302 return_ACPI_STATUS(status);
303}
diff --git a/drivers/acpi/executer/exstorob.c b/drivers/acpi/executer/exstorob.c
deleted file mode 100644
index 9a75ff09fb0c..000000000000
--- a/drivers/acpi/executer/exstorob.c
+++ /dev/null
@@ -1,208 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exstorob - AML Interpreter object store support, store to object
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47
48#define _COMPONENT ACPI_EXECUTER
49ACPI_MODULE_NAME("exstorob")
50
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_ex_store_buffer_to_buffer
54 *
55 * PARAMETERS: source_desc - Source object to copy
56 * target_desc - Destination object of the copy
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: Copy a buffer object to another buffer object.
61 *
62 ******************************************************************************/
63acpi_status
64acpi_ex_store_buffer_to_buffer(union acpi_operand_object *source_desc,
65 union acpi_operand_object *target_desc)
66{
67 u32 length;
68 u8 *buffer;
69
70 ACPI_FUNCTION_TRACE_PTR(ex_store_buffer_to_buffer, source_desc);
71
72 /* We know that source_desc is a buffer by now */
73
74 buffer = ACPI_CAST_PTR(u8, source_desc->buffer.pointer);
75 length = source_desc->buffer.length;
76
77 /*
78 * If target is a buffer of length zero or is a static buffer,
79 * allocate a new buffer of the proper length
80 */
81 if ((target_desc->buffer.length == 0) ||
82 (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) {
83 target_desc->buffer.pointer = ACPI_ALLOCATE(length);
84 if (!target_desc->buffer.pointer) {
85 return_ACPI_STATUS(AE_NO_MEMORY);
86 }
87
88 target_desc->buffer.length = length;
89 }
90
91 /* Copy source buffer to target buffer */
92
93 if (length <= target_desc->buffer.length) {
94
95 /* Clear existing buffer and copy in the new one */
96
97 ACPI_MEMSET(target_desc->buffer.pointer, 0,
98 target_desc->buffer.length);
99 ACPI_MEMCPY(target_desc->buffer.pointer, buffer, length);
100
101#ifdef ACPI_OBSOLETE_BEHAVIOR
102 /*
103 * NOTE: ACPI versions up to 3.0 specified that the buffer must be
104 * truncated if the string is smaller than the buffer. However, "other"
105 * implementations of ACPI never did this and thus became the defacto
106 * standard. ACPI 3.0_a changes this behavior such that the buffer
107 * is no longer truncated.
108 */
109
110 /*
111 * OBSOLETE BEHAVIOR:
112 * If the original source was a string, we must truncate the buffer,
113 * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
114 * copy must not truncate the original buffer.
115 */
116 if (original_src_type == ACPI_TYPE_STRING) {
117
118 /* Set the new length of the target */
119
120 target_desc->buffer.length = length;
121 }
122#endif
123 } else {
124 /* Truncate the source, copy only what will fit */
125
126 ACPI_MEMCPY(target_desc->buffer.pointer, buffer,
127 target_desc->buffer.length);
128
129 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
130 "Truncating source buffer from %X to %X\n",
131 length, target_desc->buffer.length));
132 }
133
134 /* Copy flags */
135
136 target_desc->buffer.flags = source_desc->buffer.flags;
137 target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
138 return_ACPI_STATUS(AE_OK);
139}
140
141/*******************************************************************************
142 *
143 * FUNCTION: acpi_ex_store_string_to_string
144 *
145 * PARAMETERS: source_desc - Source object to copy
146 * target_desc - Destination object of the copy
147 *
148 * RETURN: Status
149 *
150 * DESCRIPTION: Copy a String object to another String object
151 *
152 ******************************************************************************/
153
154acpi_status
155acpi_ex_store_string_to_string(union acpi_operand_object *source_desc,
156 union acpi_operand_object *target_desc)
157{
158 u32 length;
159 u8 *buffer;
160
161 ACPI_FUNCTION_TRACE_PTR(ex_store_string_to_string, source_desc);
162
163 /* We know that source_desc is a string by now */
164
165 buffer = ACPI_CAST_PTR(u8, source_desc->string.pointer);
166 length = source_desc->string.length;
167
168 /*
169 * Replace existing string value if it will fit and the string
170 * pointer is not a static pointer (part of an ACPI table)
171 */
172 if ((length < target_desc->string.length) &&
173 (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
174 /*
175 * String will fit in existing non-static buffer.
176 * Clear old string and copy in the new one
177 */
178 ACPI_MEMSET(target_desc->string.pointer, 0,
179 (acpi_size) target_desc->string.length + 1);
180 ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
181 } else {
182 /*
183 * Free the current buffer, then allocate a new buffer
184 * large enough to hold the value
185 */
186 if (target_desc->string.pointer &&
187 (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
188
189 /* Only free if not a pointer into the DSDT */
190
191 ACPI_FREE(target_desc->string.pointer);
192 }
193
194 target_desc->string.pointer = ACPI_ALLOCATE_ZEROED((acpi_size)
195 length + 1);
196 if (!target_desc->string.pointer) {
197 return_ACPI_STATUS(AE_NO_MEMORY);
198 }
199
200 target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
201 ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
202 }
203
204 /* Set the new target length */
205
206 target_desc->string.length = length;
207 return_ACPI_STATUS(AE_OK);
208}
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
deleted file mode 100644
index 68990f1df371..000000000000
--- a/drivers/acpi/executer/exsystem.c
+++ /dev/null
@@ -1,302 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exsystem - Interface to OS services
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47
48#define _COMPONENT ACPI_EXECUTER
49ACPI_MODULE_NAME("exsystem")
50
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_ex_system_wait_semaphore
54 *
55 * PARAMETERS: Semaphore - Semaphore to wait on
56 * Timeout - Max time to wait
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: Implements a semaphore wait with a check to see if the
61 * semaphore is available immediately. If it is not, the
62 * interpreter is released before waiting.
63 *
64 ******************************************************************************/
65acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
66{
67 acpi_status status;
68
69 ACPI_FUNCTION_TRACE(ex_system_wait_semaphore);
70
71 status = acpi_os_wait_semaphore(semaphore, 1, ACPI_DO_NOT_WAIT);
72 if (ACPI_SUCCESS(status)) {
73 return_ACPI_STATUS(status);
74 }
75
76 if (status == AE_TIME) {
77
78 /* We must wait, so unlock the interpreter */
79
80 acpi_ex_relinquish_interpreter();
81
82 status = acpi_os_wait_semaphore(semaphore, 1, timeout);
83
84 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
85 "*** Thread awake after blocking, %s\n",
86 acpi_format_exception(status)));
87
88 /* Reacquire the interpreter */
89
90 acpi_ex_reacquire_interpreter();
91 }
92
93 return_ACPI_STATUS(status);
94}
95
96/*******************************************************************************
97 *
98 * FUNCTION: acpi_ex_system_wait_mutex
99 *
100 * PARAMETERS: Mutex - Mutex to wait on
101 * Timeout - Max time to wait
102 *
103 * RETURN: Status
104 *
105 * DESCRIPTION: Implements a mutex wait with a check to see if the
106 * mutex is available immediately. If it is not, the
107 * interpreter is released before waiting.
108 *
109 ******************************************************************************/
110
111acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
112{
113 acpi_status status;
114
115 ACPI_FUNCTION_TRACE(ex_system_wait_mutex);
116
117 status = acpi_os_acquire_mutex(mutex, ACPI_DO_NOT_WAIT);
118 if (ACPI_SUCCESS(status)) {
119 return_ACPI_STATUS(status);
120 }
121
122 if (status == AE_TIME) {
123
124 /* We must wait, so unlock the interpreter */
125
126 acpi_ex_relinquish_interpreter();
127
128 status = acpi_os_acquire_mutex(mutex, timeout);
129
130 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
131 "*** Thread awake after blocking, %s\n",
132 acpi_format_exception(status)));
133
134 /* Reacquire the interpreter */
135
136 acpi_ex_reacquire_interpreter();
137 }
138
139 return_ACPI_STATUS(status);
140}
141
142/*******************************************************************************
143 *
144 * FUNCTION: acpi_ex_system_do_stall
145 *
146 * PARAMETERS: how_long - The amount of time to stall,
147 * in microseconds
148 *
149 * RETURN: Status
150 *
151 * DESCRIPTION: Suspend running thread for specified amount of time.
152 * Note: ACPI specification requires that Stall() does not
153 * relinquish the processor, and delays longer than 100 usec
154 * should use Sleep() instead. We allow stalls up to 255 usec
155 * for compatibility with other interpreters and existing BIOSs.
156 *
157 ******************************************************************************/
158
159acpi_status acpi_ex_system_do_stall(u32 how_long)
160{
161 acpi_status status = AE_OK;
162
163 ACPI_FUNCTION_ENTRY();
164
165 if (how_long > 255) { /* 255 microseconds */
166 /*
167 * Longer than 255 usec, this is an error
168 *
169 * (ACPI specifies 100 usec as max, but this gives some slack in
170 * order to support existing BIOSs)
171 */
172 ACPI_ERROR((AE_INFO, "Time parameter is too large (%d)",
173 how_long));
174 status = AE_AML_OPERAND_VALUE;
175 } else {
176 acpi_os_stall(how_long);
177 }
178
179 return (status);
180}
181
182/*******************************************************************************
183 *
184 * FUNCTION: acpi_ex_system_do_suspend
185 *
186 * PARAMETERS: how_long - The amount of time to suspend,
187 * in milliseconds
188 *
189 * RETURN: None
190 *
191 * DESCRIPTION: Suspend running thread for specified amount of time.
192 *
193 ******************************************************************************/
194
195acpi_status acpi_ex_system_do_suspend(acpi_integer how_long)
196{
197 ACPI_FUNCTION_ENTRY();
198
199 /* Since this thread will sleep, we must release the interpreter */
200
201 acpi_ex_relinquish_interpreter();
202
203 acpi_os_sleep(how_long);
204
205 /* And now we must get the interpreter again */
206
207 acpi_ex_reacquire_interpreter();
208 return (AE_OK);
209}
210
211/*******************************************************************************
212 *
213 * FUNCTION: acpi_ex_system_signal_event
214 *
215 * PARAMETERS: obj_desc - The object descriptor for this op
216 *
217 * RETURN: Status
218 *
219 * DESCRIPTION: Provides an access point to perform synchronization operations
220 * within the AML.
221 *
222 ******************************************************************************/
223
224acpi_status acpi_ex_system_signal_event(union acpi_operand_object * obj_desc)
225{
226 acpi_status status = AE_OK;
227
228 ACPI_FUNCTION_TRACE(ex_system_signal_event);
229
230 if (obj_desc) {
231 status =
232 acpi_os_signal_semaphore(obj_desc->event.os_semaphore, 1);
233 }
234
235 return_ACPI_STATUS(status);
236}
237
238/*******************************************************************************
239 *
240 * FUNCTION: acpi_ex_system_wait_event
241 *
242 * PARAMETERS: time_desc - The 'time to delay' object descriptor
243 * obj_desc - The object descriptor for this op
244 *
245 * RETURN: Status
246 *
247 * DESCRIPTION: Provides an access point to perform synchronization operations
248 * within the AML. This operation is a request to wait for an
249 * event.
250 *
251 ******************************************************************************/
252
253acpi_status
254acpi_ex_system_wait_event(union acpi_operand_object *time_desc,
255 union acpi_operand_object *obj_desc)
256{
257 acpi_status status = AE_OK;
258
259 ACPI_FUNCTION_TRACE(ex_system_wait_event);
260
261 if (obj_desc) {
262 status =
263 acpi_ex_system_wait_semaphore(obj_desc->event.os_semaphore,
264 (u16) time_desc->integer.
265 value);
266 }
267
268 return_ACPI_STATUS(status);
269}
270
271/*******************************************************************************
272 *
273 * FUNCTION: acpi_ex_system_reset_event
274 *
275 * PARAMETERS: obj_desc - The object descriptor for this op
276 *
277 * RETURN: Status
278 *
279 * DESCRIPTION: Reset an event to a known state.
280 *
281 ******************************************************************************/
282
283acpi_status acpi_ex_system_reset_event(union acpi_operand_object *obj_desc)
284{
285 acpi_status status = AE_OK;
286 acpi_semaphore temp_semaphore;
287
288 ACPI_FUNCTION_ENTRY();
289
290 /*
291 * We are going to simply delete the existing semaphore and
292 * create a new one!
293 */
294 status =
295 acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore);
296 if (ACPI_SUCCESS(status)) {
297 (void)acpi_os_delete_semaphore(obj_desc->event.os_semaphore);
298 obj_desc->event.os_semaphore = temp_semaphore;
299 }
300
301 return (status);
302}
diff --git a/drivers/acpi/executer/exutils.c b/drivers/acpi/executer/exutils.c
deleted file mode 100644
index 86c03880b523..000000000000
--- a/drivers/acpi/executer/exutils.c
+++ /dev/null
@@ -1,420 +0,0 @@
1
2/******************************************************************************
3 *
4 * Module Name: exutils - interpreter/scanner utilities
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45/*
46 * DEFINE_AML_GLOBALS is tested in amlcode.h
47 * to determine whether certain global names should be "defined" or only
48 * "declared" in the current compilation. This enhances maintainability
49 * by enabling a single header file to embody all knowledge of the names
50 * in question.
51 *
52 * Exactly one module of any executable should #define DEFINE_GLOBALS
53 * before #including the header files which use this convention. The
54 * names in question will be defined and initialized in that module,
55 * and declared as extern in all other modules which #include those
56 * header files.
57 */
58
59#define DEFINE_AML_GLOBALS
60
61#include <acpi/acpi.h>
62#include <acpi/acinterp.h>
63#include <acpi/amlcode.h>
64
65#define _COMPONENT ACPI_EXECUTER
66ACPI_MODULE_NAME("exutils")
67
68/* Local prototypes */
69static u32 acpi_ex_digits_needed(acpi_integer value, u32 base);
70
71#ifndef ACPI_NO_METHOD_EXECUTION
72/*******************************************************************************
73 *
74 * FUNCTION: acpi_ex_enter_interpreter
75 *
76 * PARAMETERS: None
77 *
78 * RETURN: None
79 *
80 * DESCRIPTION: Enter the interpreter execution region. Failure to enter
81 * the interpreter region is a fatal system error. Used in
82 * conjunction with exit_interpreter.
83 *
84 ******************************************************************************/
85
86void acpi_ex_enter_interpreter(void)
87{
88 acpi_status status;
89
90 ACPI_FUNCTION_TRACE(ex_enter_interpreter);
91
92 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
93 if (ACPI_FAILURE(status)) {
94 ACPI_ERROR((AE_INFO,
95 "Could not acquire AML Interpreter mutex"));
96 }
97
98 return_VOID;
99}
100
101/*******************************************************************************
102 *
103 * FUNCTION: acpi_ex_reacquire_interpreter
104 *
105 * PARAMETERS: None
106 *
107 * RETURN: None
108 *
109 * DESCRIPTION: Reacquire the interpreter execution region from within the
110 * interpreter code. Failure to enter the interpreter region is a
111 * fatal system error. Used in conjuction with
112 * relinquish_interpreter
113 *
114 ******************************************************************************/
115
116void acpi_ex_reacquire_interpreter(void)
117{
118 ACPI_FUNCTION_TRACE(ex_reacquire_interpreter);
119
120 /*
121 * If the global serialized flag is set, do not release the interpreter,
122 * since it was not actually released by acpi_ex_relinquish_interpreter.
123 * This forces the interpreter to be single threaded.
124 */
125 if (!acpi_gbl_all_methods_serialized) {
126 acpi_ex_enter_interpreter();
127 }
128
129 return_VOID;
130}
131
132/*******************************************************************************
133 *
134 * FUNCTION: acpi_ex_exit_interpreter
135 *
136 * PARAMETERS: None
137 *
138 * RETURN: None
139 *
140 * DESCRIPTION: Exit the interpreter execution region. This is the top level
141 * routine used to exit the interpreter when all processing has
142 * been completed.
143 *
144 ******************************************************************************/
145
146void acpi_ex_exit_interpreter(void)
147{
148 acpi_status status;
149
150 ACPI_FUNCTION_TRACE(ex_exit_interpreter);
151
152 status = acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
153 if (ACPI_FAILURE(status)) {
154 ACPI_ERROR((AE_INFO,
155 "Could not release AML Interpreter mutex"));
156 }
157
158 return_VOID;
159}
160
161/*******************************************************************************
162 *
163 * FUNCTION: acpi_ex_relinquish_interpreter
164 *
165 * PARAMETERS: None
166 *
167 * RETURN: None
168 *
169 * DESCRIPTION: Exit the interpreter execution region, from within the
170 * interpreter - before attempting an operation that will possibly
171 * block the running thread.
172 *
173 * Cases where the interpreter is unlocked internally
174 * 1) Method to be blocked on a Sleep() AML opcode
175 * 2) Method to be blocked on an Acquire() AML opcode
176 * 3) Method to be blocked on a Wait() AML opcode
177 * 4) Method to be blocked to acquire the global lock
178 * 5) Method to be blocked waiting to execute a serialized control method
179 * that is currently executing
180 * 6) About to invoke a user-installed opregion handler
181 *
182 ******************************************************************************/
183
184void acpi_ex_relinquish_interpreter(void)
185{
186 ACPI_FUNCTION_TRACE(ex_relinquish_interpreter);
187
188 /*
189 * If the global serialized flag is set, do not release the interpreter.
190 * This forces the interpreter to be single threaded.
191 */
192 if (!acpi_gbl_all_methods_serialized) {
193 acpi_ex_exit_interpreter();
194 }
195
196 return_VOID;
197}
198
199/*******************************************************************************
200 *
201 * FUNCTION: acpi_ex_truncate_for32bit_table
202 *
203 * PARAMETERS: obj_desc - Object to be truncated
204 *
205 * RETURN: none
206 *
207 * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
208 * 32-bit, as determined by the revision of the DSDT.
209 *
210 ******************************************************************************/
211
212void acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc)
213{
214
215 ACPI_FUNCTION_ENTRY();
216
217 /*
218 * Object must be a valid number and we must be executing
219 * a control method. NS node could be there for AML_INT_NAMEPATH_OP.
220 */
221 if ((!obj_desc) ||
222 (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) ||
223 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) {
224 return;
225 }
226
227 if (acpi_gbl_integer_byte_width == 4) {
228 /*
229 * We are running a method that exists in a 32-bit ACPI table.
230 * Truncate the value to 32 bits by zeroing out the upper 32-bit field
231 */
232 obj_desc->integer.value &= (acpi_integer) ACPI_UINT32_MAX;
233 }
234}
235
236/*******************************************************************************
237 *
238 * FUNCTION: acpi_ex_acquire_global_lock
239 *
240 * PARAMETERS: field_flags - Flags with Lock rule:
241 * always_lock or never_lock
242 *
243 * RETURN: None
244 *
245 * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
246 * flags specifiy that it is to be obtained before field access.
247 *
248 ******************************************************************************/
249
250void acpi_ex_acquire_global_lock(u32 field_flags)
251{
252 acpi_status status;
253
254 ACPI_FUNCTION_TRACE(ex_acquire_global_lock);
255
256 /* Only use the lock if the always_lock bit is set */
257
258 if (!(field_flags & AML_FIELD_LOCK_RULE_MASK)) {
259 return_VOID;
260 }
261
262 /* Attempt to get the global lock, wait forever */
263
264 status = acpi_ex_acquire_mutex_object(ACPI_WAIT_FOREVER,
265 acpi_gbl_global_lock_mutex,
266 acpi_os_get_thread_id());
267
268 if (ACPI_FAILURE(status)) {
269 ACPI_EXCEPTION((AE_INFO, status,
270 "Could not acquire Global Lock"));
271 }
272
273 return_VOID;
274}
275
276/*******************************************************************************
277 *
278 * FUNCTION: acpi_ex_release_global_lock
279 *
280 * PARAMETERS: field_flags - Flags with Lock rule:
281 * always_lock or never_lock
282 *
283 * RETURN: None
284 *
285 * DESCRIPTION: Release the ACPI hardware Global Lock
286 *
287 ******************************************************************************/
288
289void acpi_ex_release_global_lock(u32 field_flags)
290{
291 acpi_status status;
292
293 ACPI_FUNCTION_TRACE(ex_release_global_lock);
294
295 /* Only use the lock if the always_lock bit is set */
296
297 if (!(field_flags & AML_FIELD_LOCK_RULE_MASK)) {
298 return_VOID;
299 }
300
301 /* Release the global lock */
302
303 status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
304 if (ACPI_FAILURE(status)) {
305
306 /* Report the error, but there isn't much else we can do */
307
308 ACPI_EXCEPTION((AE_INFO, status,
309 "Could not release Global Lock"));
310 }
311
312 return_VOID;
313}
314
315/*******************************************************************************
316 *
317 * FUNCTION: acpi_ex_digits_needed
318 *
319 * PARAMETERS: Value - Value to be represented
320 * Base - Base of representation
321 *
322 * RETURN: The number of digits.
323 *
324 * DESCRIPTION: Calculate the number of digits needed to represent the Value
325 * in the given Base (Radix)
326 *
327 ******************************************************************************/
328
329static u32 acpi_ex_digits_needed(acpi_integer value, u32 base)
330{
331 u32 num_digits;
332 acpi_integer current_value;
333
334 ACPI_FUNCTION_TRACE(ex_digits_needed);
335
336 /* acpi_integer is unsigned, so we don't worry about a '-' prefix */
337
338 if (value == 0) {
339 return_UINT32(1);
340 }
341
342 current_value = value;
343 num_digits = 0;
344
345 /* Count the digits in the requested base */
346
347 while (current_value) {
348 (void)acpi_ut_short_divide(current_value, base, &current_value,
349 NULL);
350 num_digits++;
351 }
352
353 return_UINT32(num_digits);
354}
355
356/*******************************************************************************
357 *
358 * FUNCTION: acpi_ex_eisa_id_to_string
359 *
360 * PARAMETERS: numeric_id - EISA ID to be converted
361 * out_string - Where to put the converted string (8 bytes)
362 *
363 * RETURN: None
364 *
365 * DESCRIPTION: Convert a numeric EISA ID to string representation
366 *
367 ******************************************************************************/
368
369void acpi_ex_eisa_id_to_string(u32 numeric_id, char *out_string)
370{
371 u32 eisa_id;
372
373 ACPI_FUNCTION_ENTRY();
374
375 /* Swap ID to big-endian to get contiguous bits */
376
377 eisa_id = acpi_ut_dword_byte_swap(numeric_id);
378
379 out_string[0] = (char)('@' + (((unsigned long)eisa_id >> 26) & 0x1f));
380 out_string[1] = (char)('@' + ((eisa_id >> 21) & 0x1f));
381 out_string[2] = (char)('@' + ((eisa_id >> 16) & 0x1f));
382 out_string[3] = acpi_ut_hex_to_ascii_char((acpi_integer) eisa_id, 12);
383 out_string[4] = acpi_ut_hex_to_ascii_char((acpi_integer) eisa_id, 8);
384 out_string[5] = acpi_ut_hex_to_ascii_char((acpi_integer) eisa_id, 4);
385 out_string[6] = acpi_ut_hex_to_ascii_char((acpi_integer) eisa_id, 0);
386 out_string[7] = 0;
387}
388
389/*******************************************************************************
390 *
391 * FUNCTION: acpi_ex_unsigned_integer_to_string
392 *
393 * PARAMETERS: Value - Value to be converted
394 * out_string - Where to put the converted string (8 bytes)
395 *
396 * RETURN: None, string
397 *
398 * DESCRIPTION: Convert a number to string representation. Assumes string
399 * buffer is large enough to hold the string.
400 *
401 ******************************************************************************/
402
403void acpi_ex_unsigned_integer_to_string(acpi_integer value, char *out_string)
404{
405 u32 count;
406 u32 digits_needed;
407 u32 remainder;
408
409 ACPI_FUNCTION_ENTRY();
410
411 digits_needed = acpi_ex_digits_needed(value, 10);
412 out_string[digits_needed] = 0;
413
414 for (count = digits_needed; count > 0; count--) {
415 (void)acpi_ut_short_divide(value, 10, &value, &remainder);
416 out_string[count - 1] = (char)('0' + remainder);
417 }
418}
419
420#endif