Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / dbtest.c
blob6db44a5ac7860d1a6a3b7a2df75ca23ade71ccaa
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: dbtest - Various debug-related tests
6 ******************************************************************************/
8 #include <acpi/acpi.h>
9 #include "accommon.h"
10 #include "acdebug.h"
11 #include "acnamesp.h"
12 #include "acpredef.h"
13 #include "acinterp.h"
15 #define _COMPONENT ACPI_CA_DEBUGGER
16 ACPI_MODULE_NAME("dbtest")
18 /* Local prototypes */
19 static void acpi_db_test_all_objects(void);
21 static acpi_status
22 acpi_db_test_one_object(acpi_handle obj_handle,
23 u32 nesting_level, void *context, void **return_value);
25 static acpi_status
26 acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length);
28 static acpi_status
29 acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length);
31 static acpi_status
32 acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length);
34 static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node);
36 static acpi_status
37 acpi_db_test_field_unit_type(union acpi_operand_object *obj_desc);
39 static acpi_status
40 acpi_db_read_from_object(struct acpi_namespace_node *node,
41 acpi_object_type expected_type,
42 union acpi_object **value);
44 static acpi_status
45 acpi_db_write_to_object(struct acpi_namespace_node *node,
46 union acpi_object *value);
48 static void acpi_db_evaluate_all_predefined_names(char *count_arg);
50 static acpi_status
51 acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
52 u32 nesting_level,
53 void *context, void **return_value);
56 * Test subcommands
58 static struct acpi_db_argument_info acpi_db_test_types[] = {
59 {"OBJECTS"},
60 {"PREDEFINED"},
61 {NULL} /* Must be null terminated */
64 #define CMD_TEST_OBJECTS 0
65 #define CMD_TEST_PREDEFINED 1
67 #define BUFFER_FILL_VALUE 0xFF
70 * Support for the special debugger read/write control methods.
71 * These methods are installed into the current namespace and are
72 * used to read and write the various namespace objects. The point
73 * is to force the AML interpreter do all of the work.
75 #define ACPI_DB_READ_METHOD "\\_T98"
76 #define ACPI_DB_WRITE_METHOD "\\_T99"
78 static acpi_handle read_handle = NULL;
79 static acpi_handle write_handle = NULL;
81 /* ASL Definitions of the debugger read/write control methods. AML below. */
83 #if 0
84 definition_block("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
86 method(_T98, 1, not_serialized) { /* Read */
87 return (de_ref_of(arg0))
91 definition_block("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
93 method(_T99, 2, not_serialized) { /* Write */
94 store(arg1, arg0)
97 #endif
99 static unsigned char read_method_code[] = {
100 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
101 0x02, 0xC9, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
102 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
103 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
104 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
105 0x39, 0x38, 0x01, 0xA4, 0x83, 0x68 /* 00000028 "98...h" */
108 static unsigned char write_method_code[] = {
109 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
110 0x02, 0x15, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
111 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
112 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
113 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
114 0x39, 0x39, 0x02, 0x70, 0x69, 0x68 /* 00000028 "99.pih" */
117 /*******************************************************************************
119 * FUNCTION: acpi_db_execute_test
121 * PARAMETERS: type_arg - Subcommand
123 * RETURN: None
125 * DESCRIPTION: Execute various debug tests.
127 * Note: Code is prepared for future expansion of the TEST command.
129 ******************************************************************************/
131 void acpi_db_execute_test(char *type_arg)
133 u32 temp;
135 acpi_ut_strupr(type_arg);
136 temp = acpi_db_match_argument(type_arg, acpi_db_test_types);
137 if (temp == ACPI_TYPE_NOT_FOUND) {
138 acpi_os_printf("Invalid or unsupported argument\n");
139 return;
142 switch (temp) {
143 case CMD_TEST_OBJECTS:
145 acpi_db_test_all_objects();
146 break;
148 case CMD_TEST_PREDEFINED:
150 acpi_db_evaluate_all_predefined_names(NULL);
151 break;
153 default:
154 break;
158 /*******************************************************************************
160 * FUNCTION: acpi_db_test_all_objects
162 * PARAMETERS: None
164 * RETURN: None
166 * DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the
167 * namespace by reading/writing/comparing all data objects such
168 * as integers, strings, buffers, fields, buffer fields, etc.
170 ******************************************************************************/
172 static void acpi_db_test_all_objects(void)
174 acpi_status status;
176 /* Install the debugger read-object control method if necessary */
178 if (!read_handle) {
179 status = acpi_install_method(read_method_code);
180 if (ACPI_FAILURE(status)) {
181 acpi_os_printf
182 ("%s, Could not install debugger read method\n",
183 acpi_format_exception(status));
184 return;
187 status =
188 acpi_get_handle(NULL, ACPI_DB_READ_METHOD, &read_handle);
189 if (ACPI_FAILURE(status)) {
190 acpi_os_printf
191 ("Could not obtain handle for debug method %s\n",
192 ACPI_DB_READ_METHOD);
193 return;
197 /* Install the debugger write-object control method if necessary */
199 if (!write_handle) {
200 status = acpi_install_method(write_method_code);
201 if (ACPI_FAILURE(status)) {
202 acpi_os_printf
203 ("%s, Could not install debugger write method\n",
204 acpi_format_exception(status));
205 return;
208 status =
209 acpi_get_handle(NULL, ACPI_DB_WRITE_METHOD, &write_handle);
210 if (ACPI_FAILURE(status)) {
211 acpi_os_printf
212 ("Could not obtain handle for debug method %s\n",
213 ACPI_DB_WRITE_METHOD);
214 return;
218 /* Walk the entire namespace, testing each supported named data object */
220 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
221 ACPI_UINT32_MAX, acpi_db_test_one_object,
222 NULL, NULL, NULL);
225 /*******************************************************************************
227 * FUNCTION: acpi_db_test_one_object
229 * PARAMETERS: acpi_walk_callback
231 * RETURN: Status
233 * DESCRIPTION: Test one namespace object. Supported types are Integer,
234 * String, Buffer, Package, buffer_field, and field_unit.
235 * All other object types are simply ignored.
237 ******************************************************************************/
239 static acpi_status
240 acpi_db_test_one_object(acpi_handle obj_handle,
241 u32 nesting_level, void *context, void **return_value)
243 struct acpi_namespace_node *node;
244 union acpi_operand_object *obj_desc;
245 acpi_object_type local_type;
246 u32 bit_length = 0;
247 u32 byte_length = 0;
248 acpi_status status = AE_OK;
250 node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
251 obj_desc = node->object;
254 * For the supported types, get the actual bit length or
255 * byte length. Map the type to one of Integer/String/Buffer.
257 switch (node->type) {
258 case ACPI_TYPE_INTEGER:
260 /* Integer width is either 32 or 64 */
262 local_type = ACPI_TYPE_INTEGER;
263 bit_length = acpi_gbl_integer_bit_width;
264 break;
266 case ACPI_TYPE_STRING:
268 local_type = ACPI_TYPE_STRING;
269 byte_length = obj_desc->string.length;
270 break;
272 case ACPI_TYPE_BUFFER:
274 local_type = ACPI_TYPE_BUFFER;
275 byte_length = obj_desc->buffer.length;
276 bit_length = byte_length * 8;
277 break;
279 case ACPI_TYPE_PACKAGE:
281 local_type = ACPI_TYPE_PACKAGE;
282 break;
284 case ACPI_TYPE_FIELD_UNIT:
285 case ACPI_TYPE_LOCAL_REGION_FIELD:
286 case ACPI_TYPE_LOCAL_INDEX_FIELD:
287 case ACPI_TYPE_LOCAL_BANK_FIELD:
289 local_type = ACPI_TYPE_FIELD_UNIT;
290 break;
292 case ACPI_TYPE_BUFFER_FIELD:
294 * The returned object will be a Buffer if the field length
295 * is larger than the size of an Integer (32 or 64 bits
296 * depending on the DSDT version).
298 local_type = ACPI_TYPE_INTEGER;
299 if (obj_desc) {
300 bit_length = obj_desc->common_field.bit_length;
301 byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
302 if (bit_length > acpi_gbl_integer_bit_width) {
303 local_type = ACPI_TYPE_BUFFER;
306 break;
308 default:
310 /* Ignore all non-data types - Methods, Devices, Scopes, etc. */
312 return (AE_OK);
315 /* Emit the common prefix: Type:Name */
317 acpi_os_printf("%14s: %4.4s",
318 acpi_ut_get_type_name(node->type), node->name.ascii);
320 if (!obj_desc) {
321 acpi_os_printf(" No attached sub-object, ignoring\n");
322 return (AE_OK);
325 /* At this point, we have resolved the object to one of the major types */
327 switch (local_type) {
328 case ACPI_TYPE_INTEGER:
330 status = acpi_db_test_integer_type(node, bit_length);
331 break;
333 case ACPI_TYPE_STRING:
335 status = acpi_db_test_string_type(node, byte_length);
336 break;
338 case ACPI_TYPE_BUFFER:
340 status = acpi_db_test_buffer_type(node, bit_length);
341 break;
343 case ACPI_TYPE_PACKAGE:
345 status = acpi_db_test_package_type(node);
346 break;
348 case ACPI_TYPE_FIELD_UNIT:
350 status = acpi_db_test_field_unit_type(obj_desc);
351 break;
353 default:
355 acpi_os_printf(" Ignoring, type not implemented (%2.2X)",
356 local_type);
357 break;
360 /* Exit on error, but don't abort the namespace walk */
362 if (ACPI_FAILURE(status)) {
363 status = AE_OK;
366 acpi_os_printf("\n");
367 return (status);
370 /*******************************************************************************
372 * FUNCTION: acpi_db_test_integer_type
374 * PARAMETERS: node - Parent NS node for the object
375 * bit_length - Actual length of the object. Used for
376 * support of arbitrary length field_unit
377 * and buffer_field objects.
379 * RETURN: Status
381 * DESCRIPTION: Test read/write for an Integer-valued object. Performs a
382 * write/read/compare of an arbitrary new value, then performs
383 * a write/read/compare of the original value.
385 ******************************************************************************/
387 static acpi_status
388 acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length)
390 union acpi_object *temp1 = NULL;
391 union acpi_object *temp2 = NULL;
392 union acpi_object *temp3 = NULL;
393 union acpi_object write_value;
394 u64 value_to_write;
395 acpi_status status;
397 if (bit_length > 64) {
398 acpi_os_printf(" Invalid length for an Integer: %u",
399 bit_length);
400 return (AE_OK);
403 /* Read the original value */
405 status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp1);
406 if (ACPI_FAILURE(status)) {
407 return (status);
410 acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " %8.8X%8.8X",
411 bit_length, ACPI_ROUND_BITS_UP_TO_BYTES(bit_length),
412 ACPI_FORMAT_UINT64(temp1->integer.value));
414 value_to_write = ACPI_UINT64_MAX >> (64 - bit_length);
415 if (temp1->integer.value == value_to_write) {
416 value_to_write = 0;
418 /* Write a new value */
420 write_value.type = ACPI_TYPE_INTEGER;
421 write_value.integer.value = value_to_write;
422 status = acpi_db_write_to_object(node, &write_value);
423 if (ACPI_FAILURE(status)) {
424 goto exit;
427 /* Ensure that we can read back the new value */
429 status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp2);
430 if (ACPI_FAILURE(status)) {
431 goto exit;
434 if (temp2->integer.value != value_to_write) {
435 acpi_os_printf(" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X",
436 ACPI_FORMAT_UINT64(temp2->integer.value),
437 ACPI_FORMAT_UINT64(value_to_write));
440 /* Write back the original value */
442 write_value.integer.value = temp1->integer.value;
443 status = acpi_db_write_to_object(node, &write_value);
444 if (ACPI_FAILURE(status)) {
445 goto exit;
448 /* Ensure that we can read back the original value */
450 status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp3);
451 if (ACPI_FAILURE(status)) {
452 goto exit;
455 if (temp3->integer.value != temp1->integer.value) {
456 acpi_os_printf(" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X",
457 ACPI_FORMAT_UINT64(temp3->integer.value),
458 ACPI_FORMAT_UINT64(temp1->integer.value));
461 exit:
462 if (temp1) {
463 acpi_os_free(temp1);
465 if (temp2) {
466 acpi_os_free(temp2);
468 if (temp3) {
469 acpi_os_free(temp3);
471 return (AE_OK);
474 /*******************************************************************************
476 * FUNCTION: acpi_db_test_buffer_type
478 * PARAMETERS: node - Parent NS node for the object
479 * bit_length - Actual length of the object.
481 * RETURN: Status
483 * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a
484 * write/read/compare of an arbitrary new value, then performs
485 * a write/read/compare of the original value.
487 ******************************************************************************/
489 static acpi_status
490 acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length)
492 union acpi_object *temp1 = NULL;
493 union acpi_object *temp2 = NULL;
494 union acpi_object *temp3 = NULL;
495 u8 *buffer;
496 union acpi_object write_value;
497 acpi_status status;
498 u32 byte_length;
499 u32 i;
500 u8 extra_bits;
502 byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
503 if (byte_length == 0) {
504 acpi_os_printf(" Ignoring zero length buffer");
505 return (AE_OK);
508 /* Allocate a local buffer */
510 buffer = ACPI_ALLOCATE_ZEROED(byte_length);
511 if (!buffer) {
512 return (AE_NO_MEMORY);
515 /* Read the original value */
517 status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp1);
518 if (ACPI_FAILURE(status)) {
519 goto exit;
522 /* Emit a few bytes of the buffer */
524 acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT, bit_length,
525 temp1->buffer.length);
526 for (i = 0; ((i < 8) && (i < byte_length)); i++) {
527 acpi_os_printf(" %2.2X", temp1->buffer.pointer[i]);
529 acpi_os_printf("... ");
532 * Write a new value.
534 * Handle possible extra bits at the end of the buffer. Can
535 * happen for field_units larger than an integer, but the bit
536 * count is not an integral number of bytes. Zero out the
537 * unused bits.
539 memset(buffer, BUFFER_FILL_VALUE, byte_length);
540 extra_bits = bit_length % 8;
541 if (extra_bits) {
542 buffer[byte_length - 1] = ACPI_MASK_BITS_ABOVE(extra_bits);
545 write_value.type = ACPI_TYPE_BUFFER;
546 write_value.buffer.length = byte_length;
547 write_value.buffer.pointer = buffer;
549 status = acpi_db_write_to_object(node, &write_value);
550 if (ACPI_FAILURE(status)) {
551 goto exit;
554 /* Ensure that we can read back the new value */
556 status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp2);
557 if (ACPI_FAILURE(status)) {
558 goto exit;
561 if (memcmp(temp2->buffer.pointer, buffer, byte_length)) {
562 acpi_os_printf(" MISMATCH 2: New buffer value");
565 /* Write back the original value */
567 write_value.buffer.length = byte_length;
568 write_value.buffer.pointer = temp1->buffer.pointer;
570 status = acpi_db_write_to_object(node, &write_value);
571 if (ACPI_FAILURE(status)) {
572 goto exit;
575 /* Ensure that we can read back the original value */
577 status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp3);
578 if (ACPI_FAILURE(status)) {
579 goto exit;
582 if (memcmp(temp1->buffer.pointer, temp3->buffer.pointer, byte_length)) {
583 acpi_os_printf(" MISMATCH 3: While restoring original buffer");
586 exit:
587 ACPI_FREE(buffer);
588 if (temp1) {
589 acpi_os_free(temp1);
591 if (temp2) {
592 acpi_os_free(temp2);
594 if (temp3) {
595 acpi_os_free(temp3);
597 return (status);
600 /*******************************************************************************
602 * FUNCTION: acpi_db_test_string_type
604 * PARAMETERS: node - Parent NS node for the object
605 * byte_length - Actual length of the object.
607 * RETURN: Status
609 * DESCRIPTION: Test read/write for an String-valued object. Performs a
610 * write/read/compare of an arbitrary new value, then performs
611 * a write/read/compare of the original value.
613 ******************************************************************************/
615 static acpi_status
616 acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length)
618 union acpi_object *temp1 = NULL;
619 union acpi_object *temp2 = NULL;
620 union acpi_object *temp3 = NULL;
621 char *value_to_write = "Test String from AML Debugger";
622 union acpi_object write_value;
623 acpi_status status;
625 /* Read the original value */
627 status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp1);
628 if (ACPI_FAILURE(status)) {
629 return (status);
632 acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " \"%s\"",
633 (temp1->string.length * 8), temp1->string.length,
634 temp1->string.pointer);
636 /* Write a new value */
638 write_value.type = ACPI_TYPE_STRING;
639 write_value.string.length = strlen(value_to_write);
640 write_value.string.pointer = value_to_write;
642 status = acpi_db_write_to_object(node, &write_value);
643 if (ACPI_FAILURE(status)) {
644 goto exit;
647 /* Ensure that we can read back the new value */
649 status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp2);
650 if (ACPI_FAILURE(status)) {
651 goto exit;
654 if (strcmp(temp2->string.pointer, value_to_write)) {
655 acpi_os_printf(" MISMATCH 2: %s, expecting %s",
656 temp2->string.pointer, value_to_write);
659 /* Write back the original value */
661 write_value.string.length = strlen(temp1->string.pointer);
662 write_value.string.pointer = temp1->string.pointer;
664 status = acpi_db_write_to_object(node, &write_value);
665 if (ACPI_FAILURE(status)) {
666 goto exit;
669 /* Ensure that we can read back the original value */
671 status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp3);
672 if (ACPI_FAILURE(status)) {
673 goto exit;
676 if (strcmp(temp1->string.pointer, temp3->string.pointer)) {
677 acpi_os_printf(" MISMATCH 3: %s, expecting %s",
678 temp3->string.pointer, temp1->string.pointer);
681 exit:
682 if (temp1) {
683 acpi_os_free(temp1);
685 if (temp2) {
686 acpi_os_free(temp2);
688 if (temp3) {
689 acpi_os_free(temp3);
691 return (status);
694 /*******************************************************************************
696 * FUNCTION: acpi_db_test_package_type
698 * PARAMETERS: node - Parent NS node for the object
700 * RETURN: Status
702 * DESCRIPTION: Test read for a Package object.
704 ******************************************************************************/
706 static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node)
708 union acpi_object *temp1 = NULL;
709 acpi_status status;
711 /* Read the original value */
713 status = acpi_db_read_from_object(node, ACPI_TYPE_PACKAGE, &temp1);
714 if (ACPI_FAILURE(status)) {
715 return (status);
718 acpi_os_printf(" %.2X Elements", temp1->package.count);
719 acpi_os_free(temp1);
720 return (status);
723 /*******************************************************************************
725 * FUNCTION: acpi_db_test_field_unit_type
727 * PARAMETERS: obj_desc - A field unit object
729 * RETURN: Status
731 * DESCRIPTION: Test read/write on a named field unit.
733 ******************************************************************************/
735 static acpi_status
736 acpi_db_test_field_unit_type(union acpi_operand_object *obj_desc)
738 union acpi_operand_object *region_obj;
739 u32 bit_length = 0;
740 u32 byte_length = 0;
741 acpi_status status = AE_OK;
742 union acpi_operand_object *ret_buffer_desc;
744 /* Supported spaces are memory/io/pci_config */
746 region_obj = obj_desc->field.region_obj;
747 switch (region_obj->region.space_id) {
748 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
749 case ACPI_ADR_SPACE_SYSTEM_IO:
750 case ACPI_ADR_SPACE_PCI_CONFIG:
752 /* Need the interpreter to execute */
754 acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
755 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
757 /* Exercise read-then-write */
759 status =
760 acpi_ex_read_data_from_field(NULL, obj_desc,
761 &ret_buffer_desc);
762 if (status == AE_OK) {
763 acpi_ex_write_data_to_field(ret_buffer_desc, obj_desc,
764 NULL);
765 acpi_ut_remove_reference(ret_buffer_desc);
768 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
769 acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
771 bit_length = obj_desc->common_field.bit_length;
772 byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
774 acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " [%s]", bit_length,
775 byte_length,
776 acpi_ut_get_region_name(region_obj->region.
777 space_id));
778 return (status);
780 default:
782 acpi_os_printf
783 (" %s address space is not supported in this command [%4.4s]",
784 acpi_ut_get_region_name(region_obj->region.space_id),
785 region_obj->region.node->name.ascii);
786 return (AE_OK);
790 /*******************************************************************************
792 * FUNCTION: acpi_db_read_from_object
794 * PARAMETERS: node - Parent NS node for the object
795 * expected_type - Object type expected from the read
796 * value - Where the value read is returned
798 * RETURN: Status
800 * DESCRIPTION: Performs a read from the specified object by invoking the
801 * special debugger control method that reads the object. Thus,
802 * the AML interpreter is doing all of the work, increasing the
803 * validity of the test.
805 ******************************************************************************/
807 static acpi_status
808 acpi_db_read_from_object(struct acpi_namespace_node *node,
809 acpi_object_type expected_type,
810 union acpi_object **value)
812 union acpi_object *ret_value;
813 struct acpi_object_list param_objects;
814 union acpi_object params[2];
815 struct acpi_buffer return_obj;
816 acpi_status status;
818 params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
819 params[0].reference.actual_type = node->type;
820 params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
822 param_objects.count = 1;
823 param_objects.pointer = params;
825 return_obj.length = ACPI_ALLOCATE_BUFFER;
827 acpi_gbl_method_executing = TRUE;
828 status = acpi_evaluate_object(read_handle, NULL,
829 &param_objects, &return_obj);
831 acpi_gbl_method_executing = FALSE;
832 if (ACPI_FAILURE(status)) {
833 acpi_os_printf("Could not read from object, %s",
834 acpi_format_exception(status));
835 return (status);
838 ret_value = (union acpi_object *)return_obj.pointer;
840 switch (ret_value->type) {
841 case ACPI_TYPE_INTEGER:
842 case ACPI_TYPE_BUFFER:
843 case ACPI_TYPE_STRING:
844 case ACPI_TYPE_PACKAGE:
846 * Did we receive the type we wanted? Most important for the
847 * Integer/Buffer case (when a field is larger than an Integer,
848 * it should return a Buffer).
850 if (ret_value->type != expected_type) {
851 acpi_os_printf
852 (" Type mismatch: Expected %s, Received %s",
853 acpi_ut_get_type_name(expected_type),
854 acpi_ut_get_type_name(ret_value->type));
856 acpi_os_free(return_obj.pointer);
857 return (AE_TYPE);
860 *value = ret_value;
861 break;
863 default:
865 acpi_os_printf(" Unsupported return object type, %s",
866 acpi_ut_get_type_name(ret_value->type));
868 acpi_os_free(return_obj.pointer);
869 return (AE_TYPE);
872 return (status);
875 /*******************************************************************************
877 * FUNCTION: acpi_db_write_to_object
879 * PARAMETERS: node - Parent NS node for the object
880 * value - Value to be written
882 * RETURN: Status
884 * DESCRIPTION: Performs a write to the specified object by invoking the
885 * special debugger control method that writes the object. Thus,
886 * the AML interpreter is doing all of the work, increasing the
887 * validity of the test.
889 ******************************************************************************/
891 static acpi_status
892 acpi_db_write_to_object(struct acpi_namespace_node *node,
893 union acpi_object *value)
895 struct acpi_object_list param_objects;
896 union acpi_object params[2];
897 acpi_status status;
899 params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
900 params[0].reference.actual_type = node->type;
901 params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
903 /* Copy the incoming user parameter */
905 memcpy(&params[1], value, sizeof(union acpi_object));
907 param_objects.count = 2;
908 param_objects.pointer = params;
910 acpi_gbl_method_executing = TRUE;
911 status = acpi_evaluate_object(write_handle, NULL, &param_objects, NULL);
912 acpi_gbl_method_executing = FALSE;
914 if (ACPI_FAILURE(status)) {
915 acpi_os_printf("Could not write to object, %s",
916 acpi_format_exception(status));
919 return (status);
922 /*******************************************************************************
924 * FUNCTION: acpi_db_evaluate_all_predefined_names
926 * PARAMETERS: count_arg - Max number of methods to execute
928 * RETURN: None
930 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
931 * namespace, up to the max count, if specified.
933 ******************************************************************************/
935 static void acpi_db_evaluate_all_predefined_names(char *count_arg)
937 struct acpi_db_execute_walk info;
939 info.count = 0;
940 info.max_count = ACPI_UINT32_MAX;
942 if (count_arg) {
943 info.max_count = strtoul(count_arg, NULL, 0);
946 /* Search all nodes in namespace */
948 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
949 ACPI_UINT32_MAX,
950 acpi_db_evaluate_one_predefined_name, NULL,
951 (void *)&info, NULL);
953 acpi_os_printf("Evaluated %u predefined names in the namespace\n",
954 info.count);
957 /*******************************************************************************
959 * FUNCTION: acpi_db_evaluate_one_predefined_name
961 * PARAMETERS: Callback from walk_namespace
963 * RETURN: Status
965 * DESCRIPTION: Batch execution module. Currently only executes predefined
966 * ACPI names.
968 ******************************************************************************/
970 static acpi_status
971 acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
972 u32 nesting_level,
973 void *context, void **return_value)
975 struct acpi_namespace_node *node =
976 (struct acpi_namespace_node *)obj_handle;
977 struct acpi_db_execute_walk *info =
978 (struct acpi_db_execute_walk *)context;
979 char *pathname;
980 const union acpi_predefined_info *predefined;
981 struct acpi_device_info *obj_info;
982 struct acpi_object_list param_objects;
983 union acpi_object params[ACPI_METHOD_NUM_ARGS];
984 union acpi_object *this_param;
985 struct acpi_buffer return_obj;
986 acpi_status status;
987 u16 arg_type_list;
988 u8 arg_count;
989 u8 arg_type;
990 u32 i;
992 /* The name must be a predefined ACPI name */
994 predefined = acpi_ut_match_predefined_method(node->name.ascii);
995 if (!predefined) {
996 return (AE_OK);
999 if (node->type == ACPI_TYPE_LOCAL_SCOPE) {
1000 return (AE_OK);
1003 pathname = acpi_ns_get_normalized_pathname(node, TRUE);
1004 if (!pathname) {
1005 return (AE_OK);
1008 /* Get the object info for number of method parameters */
1010 status = acpi_get_object_info(obj_handle, &obj_info);
1011 if (ACPI_FAILURE(status)) {
1012 ACPI_FREE(pathname);
1013 return (status);
1016 param_objects.count = 0;
1017 param_objects.pointer = NULL;
1019 if (obj_info->type == ACPI_TYPE_METHOD) {
1021 /* Setup default parameters (with proper types) */
1023 arg_type_list = predefined->info.argument_list;
1024 arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
1027 * Setup the ACPI-required number of arguments, regardless of what
1028 * the actual method defines. If there is a difference, then the
1029 * method is wrong and a warning will be issued during execution.
1031 this_param = params;
1032 for (i = 0; i < arg_count; i++) {
1033 arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
1034 this_param->type = arg_type;
1036 switch (arg_type) {
1037 case ACPI_TYPE_INTEGER:
1039 this_param->integer.value = 1;
1040 break;
1042 case ACPI_TYPE_STRING:
1044 this_param->string.pointer =
1045 "This is the default argument string";
1046 this_param->string.length =
1047 strlen(this_param->string.pointer);
1048 break;
1050 case ACPI_TYPE_BUFFER:
1052 this_param->buffer.pointer = (u8 *)params; /* just a garbage buffer */
1053 this_param->buffer.length = 48;
1054 break;
1056 case ACPI_TYPE_PACKAGE:
1058 this_param->package.elements = NULL;
1059 this_param->package.count = 0;
1060 break;
1062 default:
1064 acpi_os_printf
1065 ("%s: Unsupported argument type: %u\n",
1066 pathname, arg_type);
1067 break;
1070 this_param++;
1073 param_objects.count = arg_count;
1074 param_objects.pointer = params;
1077 ACPI_FREE(obj_info);
1078 return_obj.pointer = NULL;
1079 return_obj.length = ACPI_ALLOCATE_BUFFER;
1081 /* Do the actual method execution */
1083 acpi_gbl_method_executing = TRUE;
1085 status = acpi_evaluate_object(node, NULL, &param_objects, &return_obj);
1087 acpi_os_printf("%-32s returned %s\n",
1088 pathname, acpi_format_exception(status));
1089 acpi_gbl_method_executing = FALSE;
1090 ACPI_FREE(pathname);
1092 /* Ignore status from method execution */
1094 status = AE_OK;
1096 /* Update count, check if we have executed enough methods */
1098 info->count++;
1099 if (info->count >= info->max_count) {
1100 status = AE_CTRL_TERMINATE;
1103 return (status);