sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / acpi / acpica / dbtest.c
blob74aa38156cdc089ed1f84bd5d93d19425cafdbad
1 /*******************************************************************************
3 * Module Name: dbtest - Various debug-related tests
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acdebug.h"
47 #include "acnamesp.h"
48 #include "acpredef.h"
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME("dbtest")
53 /* Local prototypes */
54 static void acpi_db_test_all_objects(void);
56 static acpi_status
57 acpi_db_test_one_object(acpi_handle obj_handle,
58 u32 nesting_level, void *context, void **return_value);
60 static acpi_status
61 acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length);
63 static acpi_status
64 acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length);
66 static acpi_status
67 acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length);
69 static acpi_status
70 acpi_db_read_from_object(struct acpi_namespace_node *node,
71 acpi_object_type expected_type,
72 union acpi_object **value);
74 static acpi_status
75 acpi_db_write_to_object(struct acpi_namespace_node *node,
76 union acpi_object *value);
78 static void acpi_db_evaluate_all_predefined_names(char *count_arg);
80 static acpi_status
81 acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
82 u32 nesting_level,
83 void *context, void **return_value);
86 * Test subcommands
88 static struct acpi_db_argument_info acpi_db_test_types[] = {
89 {"OBJECTS"},
90 {"PREDEFINED"},
91 {NULL} /* Must be null terminated */
94 #define CMD_TEST_OBJECTS 0
95 #define CMD_TEST_PREDEFINED 1
97 #define BUFFER_FILL_VALUE 0xFF
100 * Support for the special debugger read/write control methods.
101 * These methods are installed into the current namespace and are
102 * used to read and write the various namespace objects. The point
103 * is to force the AML interpreter do all of the work.
105 #define ACPI_DB_READ_METHOD "\\_T98"
106 #define ACPI_DB_WRITE_METHOD "\\_T99"
108 static acpi_handle read_handle = NULL;
109 static acpi_handle write_handle = NULL;
111 /* ASL Definitions of the debugger read/write control methods */
113 #if 0
114 definition_block("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
116 method(_T98, 1, not_serialized) { /* Read */
117 return (de_ref_of(arg0))
121 definition_block("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
123 method(_T99, 2, not_serialized) { /* Write */
124 store(arg1, arg0)
127 #endif
129 static unsigned char read_method_code[] = {
130 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
131 0x02, 0xC9, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
132 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
133 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
134 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
135 0x39, 0x38, 0x01, 0xA4, 0x83, 0x68 /* 00000028 "98...h" */
138 static unsigned char write_method_code[] = {
139 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
140 0x02, 0x15, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
141 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
142 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
143 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
144 0x39, 0x39, 0x02, 0x70, 0x69, 0x68 /* 00000028 "99.pih" */
147 /*******************************************************************************
149 * FUNCTION: acpi_db_execute_test
151 * PARAMETERS: type_arg - Subcommand
153 * RETURN: None
155 * DESCRIPTION: Execute various debug tests.
157 * Note: Code is prepared for future expansion of the TEST command.
159 ******************************************************************************/
161 void acpi_db_execute_test(char *type_arg)
163 u32 temp;
165 acpi_ut_strupr(type_arg);
166 temp = acpi_db_match_argument(type_arg, acpi_db_test_types);
167 if (temp == ACPI_TYPE_NOT_FOUND) {
168 acpi_os_printf("Invalid or unsupported argument\n");
169 return;
172 switch (temp) {
173 case CMD_TEST_OBJECTS:
175 acpi_db_test_all_objects();
176 break;
178 case CMD_TEST_PREDEFINED:
180 acpi_db_evaluate_all_predefined_names(NULL);
181 break;
183 default:
184 break;
188 /*******************************************************************************
190 * FUNCTION: acpi_db_test_all_objects
192 * PARAMETERS: None
194 * RETURN: None
196 * DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the
197 * namespace by reading/writing/comparing all data objects such
198 * as integers, strings, buffers, fields, buffer fields, etc.
200 ******************************************************************************/
202 static void acpi_db_test_all_objects(void)
204 acpi_status status;
206 /* Install the debugger read-object control method if necessary */
208 if (!read_handle) {
209 status = acpi_install_method(read_method_code);
210 if (ACPI_FAILURE(status)) {
211 acpi_os_printf
212 ("%s, Could not install debugger read method\n",
213 acpi_format_exception(status));
214 return;
217 status =
218 acpi_get_handle(NULL, ACPI_DB_READ_METHOD, &read_handle);
219 if (ACPI_FAILURE(status)) {
220 acpi_os_printf
221 ("Could not obtain handle for debug method %s\n",
222 ACPI_DB_READ_METHOD);
223 return;
227 /* Install the debugger write-object control method if necessary */
229 if (!write_handle) {
230 status = acpi_install_method(write_method_code);
231 if (ACPI_FAILURE(status)) {
232 acpi_os_printf
233 ("%s, Could not install debugger write method\n",
234 acpi_format_exception(status));
235 return;
238 status =
239 acpi_get_handle(NULL, ACPI_DB_WRITE_METHOD, &write_handle);
240 if (ACPI_FAILURE(status)) {
241 acpi_os_printf
242 ("Could not obtain handle for debug method %s\n",
243 ACPI_DB_WRITE_METHOD);
244 return;
248 /* Walk the entire namespace, testing each supported named data object */
250 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
251 ACPI_UINT32_MAX, acpi_db_test_one_object,
252 NULL, NULL, NULL);
255 /*******************************************************************************
257 * FUNCTION: acpi_db_test_one_object
259 * PARAMETERS: acpi_walk_callback
261 * RETURN: Status
263 * DESCRIPTION: Test one namespace object. Supported types are Integer,
264 * String, Buffer, buffer_field, and field_unit. All other object
265 * types are simply ignored.
267 * Note: Support for Packages is not implemented.
269 ******************************************************************************/
271 static acpi_status
272 acpi_db_test_one_object(acpi_handle obj_handle,
273 u32 nesting_level, void *context, void **return_value)
275 struct acpi_namespace_node *node;
276 union acpi_operand_object *obj_desc;
277 union acpi_operand_object *region_obj;
278 acpi_object_type local_type;
279 u32 bit_length = 0;
280 u32 byte_length = 0;
281 acpi_status status = AE_OK;
283 node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
284 obj_desc = node->object;
287 * For the supported types, get the actual bit length or
288 * byte length. Map the type to one of Integer/String/Buffer.
290 switch (node->type) {
291 case ACPI_TYPE_INTEGER:
293 /* Integer width is either 32 or 64 */
295 local_type = ACPI_TYPE_INTEGER;
296 bit_length = acpi_gbl_integer_bit_width;
297 break;
299 case ACPI_TYPE_STRING:
301 local_type = ACPI_TYPE_STRING;
302 byte_length = obj_desc->string.length;
303 break;
305 case ACPI_TYPE_BUFFER:
307 local_type = ACPI_TYPE_BUFFER;
308 byte_length = obj_desc->buffer.length;
309 bit_length = byte_length * 8;
310 break;
312 case ACPI_TYPE_FIELD_UNIT:
313 case ACPI_TYPE_BUFFER_FIELD:
314 case ACPI_TYPE_LOCAL_REGION_FIELD:
315 case ACPI_TYPE_LOCAL_INDEX_FIELD:
316 case ACPI_TYPE_LOCAL_BANK_FIELD:
318 local_type = ACPI_TYPE_INTEGER;
319 if (obj_desc) {
321 * Returned object will be a Buffer if the field length
322 * is larger than the size of an Integer (32 or 64 bits
323 * depending on the DSDT version).
325 bit_length = obj_desc->common_field.bit_length;
326 byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
327 if (bit_length > acpi_gbl_integer_bit_width) {
328 local_type = ACPI_TYPE_BUFFER;
331 break;
333 default:
335 /* Ignore all other types */
337 return (AE_OK);
340 /* Emit the common prefix: Type:Name */
342 acpi_os_printf("%14s: %4.4s",
343 acpi_ut_get_type_name(node->type), node->name.ascii);
344 if (!obj_desc) {
345 acpi_os_printf(" Ignoring, no attached object\n");
346 return (AE_OK);
350 * Check for unsupported region types. Note: acpi_exec simulates
351 * access to system_memory, system_IO, PCI_Config, and EC.
353 switch (node->type) {
354 case ACPI_TYPE_LOCAL_REGION_FIELD:
356 region_obj = obj_desc->field.region_obj;
357 switch (region_obj->region.space_id) {
358 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
359 case ACPI_ADR_SPACE_SYSTEM_IO:
360 case ACPI_ADR_SPACE_PCI_CONFIG:
361 case ACPI_ADR_SPACE_EC:
363 break;
365 default:
367 acpi_os_printf
368 (" %s space is not supported [%4.4s]\n",
369 acpi_ut_get_region_name(region_obj->region.
370 space_id),
371 region_obj->region.node->name.ascii);
372 return (AE_OK);
374 break;
376 default:
377 break;
380 /* At this point, we have resolved the object to one of the major types */
382 switch (local_type) {
383 case ACPI_TYPE_INTEGER:
385 status = acpi_db_test_integer_type(node, bit_length);
386 break;
388 case ACPI_TYPE_STRING:
390 status = acpi_db_test_string_type(node, byte_length);
391 break;
393 case ACPI_TYPE_BUFFER:
395 status = acpi_db_test_buffer_type(node, bit_length);
396 break;
398 default:
400 acpi_os_printf(" Ignoring, type not implemented (%2.2X)",
401 local_type);
402 break;
405 switch (node->type) {
406 case ACPI_TYPE_LOCAL_REGION_FIELD:
408 region_obj = obj_desc->field.region_obj;
409 acpi_os_printf(" (%s)",
410 acpi_ut_get_region_name(region_obj->region.
411 space_id));
412 break;
414 default:
415 break;
418 acpi_os_printf("\n");
419 return (status);
422 /*******************************************************************************
424 * FUNCTION: acpi_db_test_integer_type
426 * PARAMETERS: node - Parent NS node for the object
427 * bit_length - Actual length of the object. Used for
428 * support of arbitrary length field_unit
429 * and buffer_field objects.
431 * RETURN: Status
433 * DESCRIPTION: Test read/write for an Integer-valued object. Performs a
434 * write/read/compare of an arbitrary new value, then performs
435 * a write/read/compare of the original value.
437 ******************************************************************************/
439 static acpi_status
440 acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length)
442 union acpi_object *temp1 = NULL;
443 union acpi_object *temp2 = NULL;
444 union acpi_object *temp3 = NULL;
445 union acpi_object write_value;
446 u64 value_to_write;
447 acpi_status status;
449 if (bit_length > 64) {
450 acpi_os_printf(" Invalid length for an Integer: %u",
451 bit_length);
452 return (AE_OK);
455 /* Read the original value */
457 status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp1);
458 if (ACPI_FAILURE(status)) {
459 return (status);
462 acpi_os_printf(" (%4.4X/%3.3X) %8.8X%8.8X",
463 bit_length, ACPI_ROUND_BITS_UP_TO_BYTES(bit_length),
464 ACPI_FORMAT_UINT64(temp1->integer.value));
466 value_to_write = ACPI_UINT64_MAX >> (64 - bit_length);
467 if (temp1->integer.value == value_to_write) {
468 value_to_write = 0;
471 /* Write a new value */
473 write_value.type = ACPI_TYPE_INTEGER;
474 write_value.integer.value = value_to_write;
475 status = acpi_db_write_to_object(node, &write_value);
476 if (ACPI_FAILURE(status)) {
477 goto exit;
480 /* Ensure that we can read back the new value */
482 status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp2);
483 if (ACPI_FAILURE(status)) {
484 goto exit;
487 if (temp2->integer.value != value_to_write) {
488 acpi_os_printf(" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X",
489 ACPI_FORMAT_UINT64(temp2->integer.value),
490 ACPI_FORMAT_UINT64(value_to_write));
493 /* Write back the original value */
495 write_value.integer.value = temp1->integer.value;
496 status = acpi_db_write_to_object(node, &write_value);
497 if (ACPI_FAILURE(status)) {
498 goto exit;
501 /* Ensure that we can read back the original value */
503 status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp3);
504 if (ACPI_FAILURE(status)) {
505 goto exit;
508 if (temp3->integer.value != temp1->integer.value) {
509 acpi_os_printf(" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X",
510 ACPI_FORMAT_UINT64(temp3->integer.value),
511 ACPI_FORMAT_UINT64(temp1->integer.value));
514 exit:
515 if (temp1) {
516 acpi_os_free(temp1);
518 if (temp2) {
519 acpi_os_free(temp2);
521 if (temp3) {
522 acpi_os_free(temp3);
524 return (AE_OK);
527 /*******************************************************************************
529 * FUNCTION: acpi_db_test_buffer_type
531 * PARAMETERS: node - Parent NS node for the object
532 * bit_length - Actual length of the object.
534 * RETURN: Status
536 * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a
537 * write/read/compare of an arbitrary new value, then performs
538 * a write/read/compare of the original value.
540 ******************************************************************************/
542 static acpi_status
543 acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length)
545 union acpi_object *temp1 = NULL;
546 union acpi_object *temp2 = NULL;
547 union acpi_object *temp3 = NULL;
548 u8 *buffer;
549 union acpi_object write_value;
550 acpi_status status;
551 u32 byte_length;
552 u32 i;
553 u8 extra_bits;
555 byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
556 if (byte_length == 0) {
557 acpi_os_printf(" Ignoring zero length buffer");
558 return (AE_OK);
561 /* Allocate a local buffer */
563 buffer = ACPI_ALLOCATE_ZEROED(byte_length);
564 if (!buffer) {
565 return (AE_NO_MEMORY);
568 /* Read the original value */
570 status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp1);
571 if (ACPI_FAILURE(status)) {
572 goto exit;
575 /* Emit a few bytes of the buffer */
577 acpi_os_printf(" (%4.4X/%3.3X)", bit_length, temp1->buffer.length);
578 for (i = 0; ((i < 4) && (i < byte_length)); i++) {
579 acpi_os_printf(" %2.2X", temp1->buffer.pointer[i]);
581 acpi_os_printf("... ");
584 * Write a new value.
586 * Handle possible extra bits at the end of the buffer. Can
587 * happen for field_units larger than an integer, but the bit
588 * count is not an integral number of bytes. Zero out the
589 * unused bits.
591 memset(buffer, BUFFER_FILL_VALUE, byte_length);
592 extra_bits = bit_length % 8;
593 if (extra_bits) {
594 buffer[byte_length - 1] = ACPI_MASK_BITS_ABOVE(extra_bits);
597 write_value.type = ACPI_TYPE_BUFFER;
598 write_value.buffer.length = byte_length;
599 write_value.buffer.pointer = buffer;
601 status = acpi_db_write_to_object(node, &write_value);
602 if (ACPI_FAILURE(status)) {
603 goto exit;
606 /* Ensure that we can read back the new value */
608 status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp2);
609 if (ACPI_FAILURE(status)) {
610 goto exit;
613 if (memcmp(temp2->buffer.pointer, buffer, byte_length)) {
614 acpi_os_printf(" MISMATCH 2: New buffer value");
617 /* Write back the original value */
619 write_value.buffer.length = byte_length;
620 write_value.buffer.pointer = temp1->buffer.pointer;
622 status = acpi_db_write_to_object(node, &write_value);
623 if (ACPI_FAILURE(status)) {
624 goto exit;
627 /* Ensure that we can read back the original value */
629 status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp3);
630 if (ACPI_FAILURE(status)) {
631 goto exit;
634 if (memcmp(temp1->buffer.pointer, temp3->buffer.pointer, byte_length)) {
635 acpi_os_printf(" MISMATCH 3: While restoring original buffer");
638 exit:
639 ACPI_FREE(buffer);
640 if (temp1) {
641 acpi_os_free(temp1);
643 if (temp2) {
644 acpi_os_free(temp2);
646 if (temp3) {
647 acpi_os_free(temp3);
649 return (status);
652 /*******************************************************************************
654 * FUNCTION: acpi_db_test_string_type
656 * PARAMETERS: node - Parent NS node for the object
657 * byte_length - Actual length of the object.
659 * RETURN: Status
661 * DESCRIPTION: Test read/write for an String-valued object. Performs a
662 * write/read/compare of an arbitrary new value, then performs
663 * a write/read/compare of the original value.
665 ******************************************************************************/
667 static acpi_status
668 acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length)
670 union acpi_object *temp1 = NULL;
671 union acpi_object *temp2 = NULL;
672 union acpi_object *temp3 = NULL;
673 char *value_to_write = "Test String from AML Debugger";
674 union acpi_object write_value;
675 acpi_status status;
677 /* Read the original value */
679 status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp1);
680 if (ACPI_FAILURE(status)) {
681 return (status);
684 acpi_os_printf(" (%4.4X/%3.3X) \"%s\"", (temp1->string.length * 8),
685 temp1->string.length, temp1->string.pointer);
687 /* Write a new value */
689 write_value.type = ACPI_TYPE_STRING;
690 write_value.string.length = strlen(value_to_write);
691 write_value.string.pointer = value_to_write;
693 status = acpi_db_write_to_object(node, &write_value);
694 if (ACPI_FAILURE(status)) {
695 goto exit;
698 /* Ensure that we can read back the new value */
700 status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp2);
701 if (ACPI_FAILURE(status)) {
702 goto exit;
705 if (strcmp(temp2->string.pointer, value_to_write)) {
706 acpi_os_printf(" MISMATCH 2: %s, expecting %s",
707 temp2->string.pointer, value_to_write);
710 /* Write back the original value */
712 write_value.string.length = strlen(temp1->string.pointer);
713 write_value.string.pointer = temp1->string.pointer;
715 status = acpi_db_write_to_object(node, &write_value);
716 if (ACPI_FAILURE(status)) {
717 goto exit;
720 /* Ensure that we can read back the original value */
722 status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp3);
723 if (ACPI_FAILURE(status)) {
724 goto exit;
727 if (strcmp(temp1->string.pointer, temp3->string.pointer)) {
728 acpi_os_printf(" MISMATCH 3: %s, expecting %s",
729 temp3->string.pointer, temp1->string.pointer);
732 exit:
733 if (temp1) {
734 acpi_os_free(temp1);
736 if (temp2) {
737 acpi_os_free(temp2);
739 if (temp3) {
740 acpi_os_free(temp3);
742 return (status);
745 /*******************************************************************************
747 * FUNCTION: acpi_db_read_from_object
749 * PARAMETERS: node - Parent NS node for the object
750 * expected_type - Object type expected from the read
751 * value - Where the value read is returned
753 * RETURN: Status
755 * DESCRIPTION: Performs a read from the specified object by invoking the
756 * special debugger control method that reads the object. Thus,
757 * the AML interpreter is doing all of the work, increasing the
758 * validity of the test.
760 ******************************************************************************/
762 static acpi_status
763 acpi_db_read_from_object(struct acpi_namespace_node *node,
764 acpi_object_type expected_type,
765 union acpi_object **value)
767 union acpi_object *ret_value;
768 struct acpi_object_list param_objects;
769 union acpi_object params[2];
770 struct acpi_buffer return_obj;
771 acpi_status status;
773 params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
774 params[0].reference.actual_type = node->type;
775 params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
777 param_objects.count = 1;
778 param_objects.pointer = params;
780 return_obj.length = ACPI_ALLOCATE_BUFFER;
782 acpi_gbl_method_executing = TRUE;
783 status = acpi_evaluate_object(read_handle, NULL,
784 &param_objects, &return_obj);
785 acpi_gbl_method_executing = FALSE;
787 if (ACPI_FAILURE(status)) {
788 acpi_os_printf("Could not read from object, %s",
789 acpi_format_exception(status));
790 return (status);
793 ret_value = (union acpi_object *)return_obj.pointer;
795 switch (ret_value->type) {
796 case ACPI_TYPE_INTEGER:
797 case ACPI_TYPE_BUFFER:
798 case ACPI_TYPE_STRING:
800 * Did we receive the type we wanted? Most important for the
801 * Integer/Buffer case (when a field is larger than an Integer,
802 * it should return a Buffer).
804 if (ret_value->type != expected_type) {
805 acpi_os_printf
806 (" Type mismatch: Expected %s, Received %s",
807 acpi_ut_get_type_name(expected_type),
808 acpi_ut_get_type_name(ret_value->type));
810 return (AE_TYPE);
813 *value = ret_value;
814 break;
816 default:
818 acpi_os_printf(" Unsupported return object type, %s",
819 acpi_ut_get_type_name(ret_value->type));
821 acpi_os_free(return_obj.pointer);
822 return (AE_TYPE);
825 return (status);
828 /*******************************************************************************
830 * FUNCTION: acpi_db_write_to_object
832 * PARAMETERS: node - Parent NS node for the object
833 * value - Value to be written
835 * RETURN: Status
837 * DESCRIPTION: Performs a write to the specified object by invoking the
838 * special debugger control method that writes the object. Thus,
839 * the AML interpreter is doing all of the work, increasing the
840 * validity of the test.
842 ******************************************************************************/
844 static acpi_status
845 acpi_db_write_to_object(struct acpi_namespace_node *node,
846 union acpi_object *value)
848 struct acpi_object_list param_objects;
849 union acpi_object params[2];
850 acpi_status status;
852 params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
853 params[0].reference.actual_type = node->type;
854 params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
856 /* Copy the incoming user parameter */
858 memcpy(&params[1], value, sizeof(union acpi_object));
860 param_objects.count = 2;
861 param_objects.pointer = params;
863 acpi_gbl_method_executing = TRUE;
864 status = acpi_evaluate_object(write_handle, NULL, &param_objects, NULL);
865 acpi_gbl_method_executing = FALSE;
867 if (ACPI_FAILURE(status)) {
868 acpi_os_printf("Could not write to object, %s",
869 acpi_format_exception(status));
872 return (status);
875 /*******************************************************************************
877 * FUNCTION: acpi_db_evaluate_all_predefined_names
879 * PARAMETERS: count_arg - Max number of methods to execute
881 * RETURN: None
883 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
884 * namespace, up to the max count, if specified.
886 ******************************************************************************/
888 static void acpi_db_evaluate_all_predefined_names(char *count_arg)
890 struct acpi_db_execute_walk info;
892 info.count = 0;
893 info.max_count = ACPI_UINT32_MAX;
895 if (count_arg) {
896 info.max_count = strtoul(count_arg, NULL, 0);
899 /* Search all nodes in namespace */
901 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
902 ACPI_UINT32_MAX,
903 acpi_db_evaluate_one_predefined_name, NULL,
904 (void *)&info, NULL);
906 acpi_os_printf("Evaluated %u predefined names in the namespace\n",
907 info.count);
910 /*******************************************************************************
912 * FUNCTION: acpi_db_evaluate_one_predefined_name
914 * PARAMETERS: Callback from walk_namespace
916 * RETURN: Status
918 * DESCRIPTION: Batch execution module. Currently only executes predefined
919 * ACPI names.
921 ******************************************************************************/
923 static acpi_status
924 acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
925 u32 nesting_level,
926 void *context, void **return_value)
928 struct acpi_namespace_node *node =
929 (struct acpi_namespace_node *)obj_handle;
930 struct acpi_db_execute_walk *info =
931 (struct acpi_db_execute_walk *)context;
932 char *pathname;
933 const union acpi_predefined_info *predefined;
934 struct acpi_device_info *obj_info;
935 struct acpi_object_list param_objects;
936 union acpi_object params[ACPI_METHOD_NUM_ARGS];
937 union acpi_object *this_param;
938 struct acpi_buffer return_obj;
939 acpi_status status;
940 u16 arg_type_list;
941 u8 arg_count;
942 u8 arg_type;
943 u32 i;
945 /* The name must be a predefined ACPI name */
947 predefined = acpi_ut_match_predefined_method(node->name.ascii);
948 if (!predefined) {
949 return (AE_OK);
952 if (node->type == ACPI_TYPE_LOCAL_SCOPE) {
953 return (AE_OK);
956 pathname = acpi_ns_get_normalized_pathname(node, TRUE);
957 if (!pathname) {
958 return (AE_OK);
961 /* Get the object info for number of method parameters */
963 status = acpi_get_object_info(obj_handle, &obj_info);
964 if (ACPI_FAILURE(status)) {
965 ACPI_FREE(pathname);
966 return (status);
969 param_objects.count = 0;
970 param_objects.pointer = NULL;
972 if (obj_info->type == ACPI_TYPE_METHOD) {
974 /* Setup default parameters (with proper types) */
976 arg_type_list = predefined->info.argument_list;
977 arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
980 * Setup the ACPI-required number of arguments, regardless of what
981 * the actual method defines. If there is a difference, then the
982 * method is wrong and a warning will be issued during execution.
984 this_param = params;
985 for (i = 0; i < arg_count; i++) {
986 arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
987 this_param->type = arg_type;
989 switch (arg_type) {
990 case ACPI_TYPE_INTEGER:
992 this_param->integer.value = 1;
993 break;
995 case ACPI_TYPE_STRING:
997 this_param->string.pointer =
998 "This is the default argument string";
999 this_param->string.length =
1000 strlen(this_param->string.pointer);
1001 break;
1003 case ACPI_TYPE_BUFFER:
1005 this_param->buffer.pointer = (u8 *)params; /* just a garbage buffer */
1006 this_param->buffer.length = 48;
1007 break;
1009 case ACPI_TYPE_PACKAGE:
1011 this_param->package.elements = NULL;
1012 this_param->package.count = 0;
1013 break;
1015 default:
1017 acpi_os_printf
1018 ("%s: Unsupported argument type: %u\n",
1019 pathname, arg_type);
1020 break;
1023 this_param++;
1026 param_objects.count = arg_count;
1027 param_objects.pointer = params;
1030 ACPI_FREE(obj_info);
1031 return_obj.pointer = NULL;
1032 return_obj.length = ACPI_ALLOCATE_BUFFER;
1034 /* Do the actual method execution */
1036 acpi_gbl_method_executing = TRUE;
1038 status = acpi_evaluate_object(node, NULL, &param_objects, &return_obj);
1040 acpi_os_printf("%-32s returned %s\n",
1041 pathname, acpi_format_exception(status));
1042 acpi_gbl_method_executing = FALSE;
1043 ACPI_FREE(pathname);
1045 /* Ignore status from method execution */
1047 status = AE_OK;
1049 /* Update count, check if we have executed enough methods */
1051 info->count++;
1052 if (info->count >= info->max_count) {
1053 status = AE_CTRL_TERMINATE;
1056 return (status);