195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
299575102SLv Zheng /*******************************************************************************
399575102SLv Zheng *
499575102SLv Zheng * Module Name: dbtest - Various debug-related tests
599575102SLv Zheng *
699575102SLv Zheng ******************************************************************************/
799575102SLv Zheng
899575102SLv Zheng #include <acpi/acpi.h>
999575102SLv Zheng #include "accommon.h"
1099575102SLv Zheng #include "acdebug.h"
1199575102SLv Zheng #include "acnamesp.h"
1299575102SLv Zheng #include "acpredef.h"
13*90791fbbSBob Moore #include "acinterp.h"
1499575102SLv Zheng
1599575102SLv Zheng #define _COMPONENT ACPI_CA_DEBUGGER
1699575102SLv Zheng ACPI_MODULE_NAME("dbtest")
1799575102SLv Zheng
1899575102SLv Zheng /* Local prototypes */
1999575102SLv Zheng static void acpi_db_test_all_objects(void);
2099575102SLv Zheng
2199575102SLv Zheng static acpi_status
2299575102SLv Zheng acpi_db_test_one_object(acpi_handle obj_handle,
2399575102SLv Zheng u32 nesting_level, void *context, void **return_value);
2499575102SLv Zheng
2599575102SLv Zheng static acpi_status
2699575102SLv Zheng acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length);
2799575102SLv Zheng
2899575102SLv Zheng static acpi_status
2999575102SLv Zheng acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length);
3099575102SLv Zheng
3199575102SLv Zheng static acpi_status
3299575102SLv Zheng acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length);
3399575102SLv Zheng
34db2e11a7SBob Moore static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node);
35db2e11a7SBob Moore
3699575102SLv Zheng static acpi_status
37*90791fbbSBob Moore acpi_db_test_field_unit_type(union acpi_operand_object *obj_desc);
38*90791fbbSBob Moore
39*90791fbbSBob Moore static acpi_status
4099575102SLv Zheng acpi_db_read_from_object(struct acpi_namespace_node *node,
4199575102SLv Zheng acpi_object_type expected_type,
4299575102SLv Zheng union acpi_object **value);
4399575102SLv Zheng
4499575102SLv Zheng static acpi_status
4599575102SLv Zheng acpi_db_write_to_object(struct acpi_namespace_node *node,
4699575102SLv Zheng union acpi_object *value);
4799575102SLv Zheng
4899575102SLv Zheng static void acpi_db_evaluate_all_predefined_names(char *count_arg);
4999575102SLv Zheng
5099575102SLv Zheng static acpi_status
5199575102SLv Zheng acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
5299575102SLv Zheng u32 nesting_level,
5399575102SLv Zheng void *context, void **return_value);
5499575102SLv Zheng
5599575102SLv Zheng /*
5699575102SLv Zheng * Test subcommands
5799575102SLv Zheng */
5899575102SLv Zheng static struct acpi_db_argument_info acpi_db_test_types[] = {
5999575102SLv Zheng {"OBJECTS"},
6099575102SLv Zheng {"PREDEFINED"},
6199575102SLv Zheng {NULL} /* Must be null terminated */
6299575102SLv Zheng };
6399575102SLv Zheng
6499575102SLv Zheng #define CMD_TEST_OBJECTS 0
6599575102SLv Zheng #define CMD_TEST_PREDEFINED 1
6699575102SLv Zheng
6799575102SLv Zheng #define BUFFER_FILL_VALUE 0xFF
6899575102SLv Zheng
6999575102SLv Zheng /*
7099575102SLv Zheng * Support for the special debugger read/write control methods.
7199575102SLv Zheng * These methods are installed into the current namespace and are
7299575102SLv Zheng * used to read and write the various namespace objects. The point
7399575102SLv Zheng * is to force the AML interpreter do all of the work.
7499575102SLv Zheng */
7599575102SLv Zheng #define ACPI_DB_READ_METHOD "\\_T98"
7699575102SLv Zheng #define ACPI_DB_WRITE_METHOD "\\_T99"
7799575102SLv Zheng
7899575102SLv Zheng static acpi_handle read_handle = NULL;
7999575102SLv Zheng static acpi_handle write_handle = NULL;
8099575102SLv Zheng
81*90791fbbSBob Moore /* ASL Definitions of the debugger read/write control methods. AML below. */
8299575102SLv Zheng
8399575102SLv Zheng #if 0
8499575102SLv Zheng definition_block("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
8599575102SLv Zheng {
8699575102SLv Zheng method(_T98, 1, not_serialized) { /* Read */
8799575102SLv Zheng return (de_ref_of(arg0))
8899575102SLv Zheng }
8999575102SLv Zheng }
9099575102SLv Zheng
9199575102SLv Zheng definition_block("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
9299575102SLv Zheng {
9399575102SLv Zheng method(_T99, 2, not_serialized) { /* Write */
9499575102SLv Zheng store(arg1, arg0)
9599575102SLv Zheng }
9699575102SLv Zheng }
9799575102SLv Zheng #endif
9899575102SLv Zheng
9999575102SLv Zheng static unsigned char read_method_code[] = {
10099575102SLv Zheng 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
10199575102SLv Zheng 0x02, 0xC9, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
10299575102SLv Zheng 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
10399575102SLv Zheng 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
10499575102SLv Zheng 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
10599575102SLv Zheng 0x39, 0x38, 0x01, 0xA4, 0x83, 0x68 /* 00000028 "98...h" */
10699575102SLv Zheng };
10799575102SLv Zheng
10899575102SLv Zheng static unsigned char write_method_code[] = {
10999575102SLv Zheng 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
11099575102SLv Zheng 0x02, 0x15, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
11199575102SLv Zheng 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
11299575102SLv Zheng 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
11399575102SLv Zheng 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
11499575102SLv Zheng 0x39, 0x39, 0x02, 0x70, 0x69, 0x68 /* 00000028 "99.pih" */
11599575102SLv Zheng };
11699575102SLv Zheng
11799575102SLv Zheng /*******************************************************************************
11899575102SLv Zheng *
11999575102SLv Zheng * FUNCTION: acpi_db_execute_test
12099575102SLv Zheng *
12199575102SLv Zheng * PARAMETERS: type_arg - Subcommand
12299575102SLv Zheng *
12399575102SLv Zheng * RETURN: None
12499575102SLv Zheng *
12599575102SLv Zheng * DESCRIPTION: Execute various debug tests.
12699575102SLv Zheng *
12799575102SLv Zheng * Note: Code is prepared for future expansion of the TEST command.
12899575102SLv Zheng *
12999575102SLv Zheng ******************************************************************************/
13099575102SLv Zheng
acpi_db_execute_test(char * type_arg)13199575102SLv Zheng void acpi_db_execute_test(char *type_arg)
13299575102SLv Zheng {
13399575102SLv Zheng u32 temp;
13499575102SLv Zheng
13599575102SLv Zheng acpi_ut_strupr(type_arg);
13699575102SLv Zheng temp = acpi_db_match_argument(type_arg, acpi_db_test_types);
13799575102SLv Zheng if (temp == ACPI_TYPE_NOT_FOUND) {
13899575102SLv Zheng acpi_os_printf("Invalid or unsupported argument\n");
13999575102SLv Zheng return;
14099575102SLv Zheng }
14199575102SLv Zheng
14299575102SLv Zheng switch (temp) {
14399575102SLv Zheng case CMD_TEST_OBJECTS:
14499575102SLv Zheng
14599575102SLv Zheng acpi_db_test_all_objects();
14699575102SLv Zheng break;
14799575102SLv Zheng
14899575102SLv Zheng case CMD_TEST_PREDEFINED:
14999575102SLv Zheng
15099575102SLv Zheng acpi_db_evaluate_all_predefined_names(NULL);
15199575102SLv Zheng break;
15299575102SLv Zheng
15399575102SLv Zheng default:
15499575102SLv Zheng break;
15599575102SLv Zheng }
15699575102SLv Zheng }
15799575102SLv Zheng
15899575102SLv Zheng /*******************************************************************************
15999575102SLv Zheng *
16099575102SLv Zheng * FUNCTION: acpi_db_test_all_objects
16199575102SLv Zheng *
16299575102SLv Zheng * PARAMETERS: None
16399575102SLv Zheng *
16499575102SLv Zheng * RETURN: None
16599575102SLv Zheng *
16699575102SLv Zheng * DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the
16799575102SLv Zheng * namespace by reading/writing/comparing all data objects such
16899575102SLv Zheng * as integers, strings, buffers, fields, buffer fields, etc.
16999575102SLv Zheng *
17099575102SLv Zheng ******************************************************************************/
17199575102SLv Zheng
acpi_db_test_all_objects(void)17299575102SLv Zheng static void acpi_db_test_all_objects(void)
17399575102SLv Zheng {
17499575102SLv Zheng acpi_status status;
17599575102SLv Zheng
17699575102SLv Zheng /* Install the debugger read-object control method if necessary */
17799575102SLv Zheng
17899575102SLv Zheng if (!read_handle) {
17999575102SLv Zheng status = acpi_install_method(read_method_code);
18099575102SLv Zheng if (ACPI_FAILURE(status)) {
18199575102SLv Zheng acpi_os_printf
18299575102SLv Zheng ("%s, Could not install debugger read method\n",
18399575102SLv Zheng acpi_format_exception(status));
18499575102SLv Zheng return;
18599575102SLv Zheng }
18699575102SLv Zheng
18799575102SLv Zheng status =
18899575102SLv Zheng acpi_get_handle(NULL, ACPI_DB_READ_METHOD, &read_handle);
18999575102SLv Zheng if (ACPI_FAILURE(status)) {
19099575102SLv Zheng acpi_os_printf
19199575102SLv Zheng ("Could not obtain handle for debug method %s\n",
19299575102SLv Zheng ACPI_DB_READ_METHOD);
19399575102SLv Zheng return;
19499575102SLv Zheng }
19599575102SLv Zheng }
19699575102SLv Zheng
19799575102SLv Zheng /* Install the debugger write-object control method if necessary */
19899575102SLv Zheng
19999575102SLv Zheng if (!write_handle) {
20099575102SLv Zheng status = acpi_install_method(write_method_code);
20199575102SLv Zheng if (ACPI_FAILURE(status)) {
20299575102SLv Zheng acpi_os_printf
20399575102SLv Zheng ("%s, Could not install debugger write method\n",
20499575102SLv Zheng acpi_format_exception(status));
20599575102SLv Zheng return;
20699575102SLv Zheng }
20799575102SLv Zheng
20899575102SLv Zheng status =
20999575102SLv Zheng acpi_get_handle(NULL, ACPI_DB_WRITE_METHOD, &write_handle);
21099575102SLv Zheng if (ACPI_FAILURE(status)) {
21199575102SLv Zheng acpi_os_printf
21299575102SLv Zheng ("Could not obtain handle for debug method %s\n",
21399575102SLv Zheng ACPI_DB_WRITE_METHOD);
21499575102SLv Zheng return;
21599575102SLv Zheng }
21699575102SLv Zheng }
21799575102SLv Zheng
21899575102SLv Zheng /* Walk the entire namespace, testing each supported named data object */
21999575102SLv Zheng
22099575102SLv Zheng (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
22199575102SLv Zheng ACPI_UINT32_MAX, acpi_db_test_one_object,
22299575102SLv Zheng NULL, NULL, NULL);
22399575102SLv Zheng }
22499575102SLv Zheng
22599575102SLv Zheng /*******************************************************************************
22699575102SLv Zheng *
22799575102SLv Zheng * FUNCTION: acpi_db_test_one_object
22899575102SLv Zheng *
22999575102SLv Zheng * PARAMETERS: acpi_walk_callback
23099575102SLv Zheng *
23199575102SLv Zheng * RETURN: Status
23299575102SLv Zheng *
23399575102SLv Zheng * DESCRIPTION: Test one namespace object. Supported types are Integer,
234*90791fbbSBob Moore * String, Buffer, Package, buffer_field, and field_unit.
235*90791fbbSBob Moore * All other object types are simply ignored.
23699575102SLv Zheng *
23799575102SLv Zheng ******************************************************************************/
23899575102SLv Zheng
23999575102SLv Zheng static acpi_status
acpi_db_test_one_object(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)24099575102SLv Zheng acpi_db_test_one_object(acpi_handle obj_handle,
24199575102SLv Zheng u32 nesting_level, void *context, void **return_value)
24299575102SLv Zheng {
24399575102SLv Zheng struct acpi_namespace_node *node;
24499575102SLv Zheng union acpi_operand_object *obj_desc;
24599575102SLv Zheng acpi_object_type local_type;
24699575102SLv Zheng u32 bit_length = 0;
24799575102SLv Zheng u32 byte_length = 0;
24899575102SLv Zheng acpi_status status = AE_OK;
24999575102SLv Zheng
25099575102SLv Zheng node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
25199575102SLv Zheng obj_desc = node->object;
25299575102SLv Zheng
25399575102SLv Zheng /*
25499575102SLv Zheng * For the supported types, get the actual bit length or
25599575102SLv Zheng * byte length. Map the type to one of Integer/String/Buffer.
25699575102SLv Zheng */
25799575102SLv Zheng switch (node->type) {
25899575102SLv Zheng case ACPI_TYPE_INTEGER:
25999575102SLv Zheng
26099575102SLv Zheng /* Integer width is either 32 or 64 */
26199575102SLv Zheng
26299575102SLv Zheng local_type = ACPI_TYPE_INTEGER;
26399575102SLv Zheng bit_length = acpi_gbl_integer_bit_width;
26499575102SLv Zheng break;
26599575102SLv Zheng
26699575102SLv Zheng case ACPI_TYPE_STRING:
26799575102SLv Zheng
26899575102SLv Zheng local_type = ACPI_TYPE_STRING;
26999575102SLv Zheng byte_length = obj_desc->string.length;
27099575102SLv Zheng break;
27199575102SLv Zheng
27299575102SLv Zheng case ACPI_TYPE_BUFFER:
27399575102SLv Zheng
27499575102SLv Zheng local_type = ACPI_TYPE_BUFFER;
27599575102SLv Zheng byte_length = obj_desc->buffer.length;
27699575102SLv Zheng bit_length = byte_length * 8;
27799575102SLv Zheng break;
27899575102SLv Zheng
279db2e11a7SBob Moore case ACPI_TYPE_PACKAGE:
280db2e11a7SBob Moore
281db2e11a7SBob Moore local_type = ACPI_TYPE_PACKAGE;
282db2e11a7SBob Moore break;
283db2e11a7SBob Moore
28499575102SLv Zheng case ACPI_TYPE_FIELD_UNIT:
28599575102SLv Zheng case ACPI_TYPE_LOCAL_REGION_FIELD:
28699575102SLv Zheng case ACPI_TYPE_LOCAL_INDEX_FIELD:
28799575102SLv Zheng case ACPI_TYPE_LOCAL_BANK_FIELD:
28899575102SLv Zheng
289*90791fbbSBob Moore local_type = ACPI_TYPE_FIELD_UNIT;
290*90791fbbSBob Moore break;
291*90791fbbSBob Moore
292*90791fbbSBob Moore case ACPI_TYPE_BUFFER_FIELD:
29399575102SLv Zheng /*
294*90791fbbSBob Moore * The returned object will be a Buffer if the field length
29599575102SLv Zheng * is larger than the size of an Integer (32 or 64 bits
29699575102SLv Zheng * depending on the DSDT version).
29799575102SLv Zheng */
298*90791fbbSBob Moore local_type = ACPI_TYPE_INTEGER;
299*90791fbbSBob Moore if (obj_desc) {
30099575102SLv Zheng bit_length = obj_desc->common_field.bit_length;
30199575102SLv Zheng byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
30299575102SLv Zheng if (bit_length > acpi_gbl_integer_bit_width) {
30399575102SLv Zheng local_type = ACPI_TYPE_BUFFER;
30499575102SLv Zheng }
30599575102SLv Zheng }
30699575102SLv Zheng break;
30799575102SLv Zheng
30899575102SLv Zheng default:
30999575102SLv Zheng
310*90791fbbSBob Moore /* Ignore all non-data types - Methods, Devices, Scopes, etc. */
31199575102SLv Zheng
31299575102SLv Zheng return (AE_OK);
31399575102SLv Zheng }
31499575102SLv Zheng
31599575102SLv Zheng /* Emit the common prefix: Type:Name */
31699575102SLv Zheng
31799575102SLv Zheng acpi_os_printf("%14s: %4.4s",
31899575102SLv Zheng acpi_ut_get_type_name(node->type), node->name.ascii);
319db2e11a7SBob Moore
32099575102SLv Zheng if (!obj_desc) {
321*90791fbbSBob Moore acpi_os_printf(" No attached sub-object, ignoring\n");
32299575102SLv Zheng return (AE_OK);
32399575102SLv Zheng }
32499575102SLv Zheng
32599575102SLv Zheng /* At this point, we have resolved the object to one of the major types */
32699575102SLv Zheng
32799575102SLv Zheng switch (local_type) {
32899575102SLv Zheng case ACPI_TYPE_INTEGER:
32999575102SLv Zheng
33099575102SLv Zheng status = acpi_db_test_integer_type(node, bit_length);
33199575102SLv Zheng break;
33299575102SLv Zheng
33399575102SLv Zheng case ACPI_TYPE_STRING:
33499575102SLv Zheng
33599575102SLv Zheng status = acpi_db_test_string_type(node, byte_length);
33699575102SLv Zheng break;
33799575102SLv Zheng
33899575102SLv Zheng case ACPI_TYPE_BUFFER:
33999575102SLv Zheng
34099575102SLv Zheng status = acpi_db_test_buffer_type(node, bit_length);
34199575102SLv Zheng break;
34299575102SLv Zheng
343db2e11a7SBob Moore case ACPI_TYPE_PACKAGE:
344db2e11a7SBob Moore
345db2e11a7SBob Moore status = acpi_db_test_package_type(node);
346db2e11a7SBob Moore break;
347db2e11a7SBob Moore
348*90791fbbSBob Moore case ACPI_TYPE_FIELD_UNIT:
349*90791fbbSBob Moore
350*90791fbbSBob Moore status = acpi_db_test_field_unit_type(obj_desc);
351*90791fbbSBob Moore break;
352*90791fbbSBob Moore
35399575102SLv Zheng default:
35499575102SLv Zheng
35599575102SLv Zheng acpi_os_printf(" Ignoring, type not implemented (%2.2X)",
35699575102SLv Zheng local_type);
35799575102SLv Zheng break;
35899575102SLv Zheng }
35999575102SLv Zheng
360db2e11a7SBob Moore /* Exit on error, but don't abort the namespace walk */
361db2e11a7SBob Moore
362db2e11a7SBob Moore if (ACPI_FAILURE(status)) {
363db2e11a7SBob Moore status = AE_OK;
364db2e11a7SBob Moore }
365db2e11a7SBob Moore
36699575102SLv Zheng acpi_os_printf("\n");
36799575102SLv Zheng return (status);
36899575102SLv Zheng }
36999575102SLv Zheng
37099575102SLv Zheng /*******************************************************************************
37199575102SLv Zheng *
37299575102SLv Zheng * FUNCTION: acpi_db_test_integer_type
37399575102SLv Zheng *
37499575102SLv Zheng * PARAMETERS: node - Parent NS node for the object
37599575102SLv Zheng * bit_length - Actual length of the object. Used for
37699575102SLv Zheng * support of arbitrary length field_unit
37799575102SLv Zheng * and buffer_field objects.
37899575102SLv Zheng *
37999575102SLv Zheng * RETURN: Status
38099575102SLv Zheng *
38199575102SLv Zheng * DESCRIPTION: Test read/write for an Integer-valued object. Performs a
38299575102SLv Zheng * write/read/compare of an arbitrary new value, then performs
38399575102SLv Zheng * a write/read/compare of the original value.
38499575102SLv Zheng *
38599575102SLv Zheng ******************************************************************************/
38699575102SLv Zheng
38799575102SLv Zheng static acpi_status
acpi_db_test_integer_type(struct acpi_namespace_node * node,u32 bit_length)38899575102SLv Zheng acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length)
38999575102SLv Zheng {
39099575102SLv Zheng union acpi_object *temp1 = NULL;
39199575102SLv Zheng union acpi_object *temp2 = NULL;
39299575102SLv Zheng union acpi_object *temp3 = NULL;
39399575102SLv Zheng union acpi_object write_value;
39499575102SLv Zheng u64 value_to_write;
39599575102SLv Zheng acpi_status status;
39699575102SLv Zheng
39799575102SLv Zheng if (bit_length > 64) {
39899575102SLv Zheng acpi_os_printf(" Invalid length for an Integer: %u",
39999575102SLv Zheng bit_length);
40099575102SLv Zheng return (AE_OK);
40199575102SLv Zheng }
40299575102SLv Zheng
40399575102SLv Zheng /* Read the original value */
40499575102SLv Zheng
40599575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp1);
40699575102SLv Zheng if (ACPI_FAILURE(status)) {
40799575102SLv Zheng return (status);
40899575102SLv Zheng }
40999575102SLv Zheng
410*90791fbbSBob Moore acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " %8.8X%8.8X",
41199575102SLv Zheng bit_length, ACPI_ROUND_BITS_UP_TO_BYTES(bit_length),
41299575102SLv Zheng ACPI_FORMAT_UINT64(temp1->integer.value));
41399575102SLv Zheng
41499575102SLv Zheng value_to_write = ACPI_UINT64_MAX >> (64 - bit_length);
41599575102SLv Zheng if (temp1->integer.value == value_to_write) {
41699575102SLv Zheng value_to_write = 0;
41799575102SLv Zheng }
41899575102SLv Zheng /* Write a new value */
41999575102SLv Zheng
42099575102SLv Zheng write_value.type = ACPI_TYPE_INTEGER;
42199575102SLv Zheng write_value.integer.value = value_to_write;
42299575102SLv Zheng status = acpi_db_write_to_object(node, &write_value);
42399575102SLv Zheng if (ACPI_FAILURE(status)) {
42499575102SLv Zheng goto exit;
42599575102SLv Zheng }
42699575102SLv Zheng
42799575102SLv Zheng /* Ensure that we can read back the new value */
42899575102SLv Zheng
42999575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp2);
43099575102SLv Zheng if (ACPI_FAILURE(status)) {
43199575102SLv Zheng goto exit;
43299575102SLv Zheng }
43399575102SLv Zheng
43499575102SLv Zheng if (temp2->integer.value != value_to_write) {
43599575102SLv Zheng acpi_os_printf(" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X",
43699575102SLv Zheng ACPI_FORMAT_UINT64(temp2->integer.value),
43799575102SLv Zheng ACPI_FORMAT_UINT64(value_to_write));
43899575102SLv Zheng }
43999575102SLv Zheng
44099575102SLv Zheng /* Write back the original value */
44199575102SLv Zheng
44299575102SLv Zheng write_value.integer.value = temp1->integer.value;
44399575102SLv Zheng status = acpi_db_write_to_object(node, &write_value);
44499575102SLv Zheng if (ACPI_FAILURE(status)) {
44599575102SLv Zheng goto exit;
44699575102SLv Zheng }
44799575102SLv Zheng
44899575102SLv Zheng /* Ensure that we can read back the original value */
44999575102SLv Zheng
45099575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp3);
45199575102SLv Zheng if (ACPI_FAILURE(status)) {
45299575102SLv Zheng goto exit;
45399575102SLv Zheng }
45499575102SLv Zheng
45599575102SLv Zheng if (temp3->integer.value != temp1->integer.value) {
45699575102SLv Zheng acpi_os_printf(" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X",
45799575102SLv Zheng ACPI_FORMAT_UINT64(temp3->integer.value),
45899575102SLv Zheng ACPI_FORMAT_UINT64(temp1->integer.value));
45999575102SLv Zheng }
46099575102SLv Zheng
46199575102SLv Zheng exit:
46299575102SLv Zheng if (temp1) {
46399575102SLv Zheng acpi_os_free(temp1);
46499575102SLv Zheng }
46599575102SLv Zheng if (temp2) {
46699575102SLv Zheng acpi_os_free(temp2);
46799575102SLv Zheng }
46899575102SLv Zheng if (temp3) {
46999575102SLv Zheng acpi_os_free(temp3);
47099575102SLv Zheng }
47199575102SLv Zheng return (AE_OK);
47299575102SLv Zheng }
47399575102SLv Zheng
47499575102SLv Zheng /*******************************************************************************
47599575102SLv Zheng *
47699575102SLv Zheng * FUNCTION: acpi_db_test_buffer_type
47799575102SLv Zheng *
47899575102SLv Zheng * PARAMETERS: node - Parent NS node for the object
47999575102SLv Zheng * bit_length - Actual length of the object.
48099575102SLv Zheng *
48199575102SLv Zheng * RETURN: Status
48299575102SLv Zheng *
48399575102SLv Zheng * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a
48499575102SLv Zheng * write/read/compare of an arbitrary new value, then performs
48599575102SLv Zheng * a write/read/compare of the original value.
48699575102SLv Zheng *
48799575102SLv Zheng ******************************************************************************/
48899575102SLv Zheng
48999575102SLv Zheng static acpi_status
acpi_db_test_buffer_type(struct acpi_namespace_node * node,u32 bit_length)49099575102SLv Zheng acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length)
49199575102SLv Zheng {
49299575102SLv Zheng union acpi_object *temp1 = NULL;
49399575102SLv Zheng union acpi_object *temp2 = NULL;
49499575102SLv Zheng union acpi_object *temp3 = NULL;
49599575102SLv Zheng u8 *buffer;
49699575102SLv Zheng union acpi_object write_value;
49799575102SLv Zheng acpi_status status;
49899575102SLv Zheng u32 byte_length;
49999575102SLv Zheng u32 i;
50099575102SLv Zheng u8 extra_bits;
50199575102SLv Zheng
50299575102SLv Zheng byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
50399575102SLv Zheng if (byte_length == 0) {
50499575102SLv Zheng acpi_os_printf(" Ignoring zero length buffer");
50599575102SLv Zheng return (AE_OK);
50699575102SLv Zheng }
50799575102SLv Zheng
50899575102SLv Zheng /* Allocate a local buffer */
50999575102SLv Zheng
51099575102SLv Zheng buffer = ACPI_ALLOCATE_ZEROED(byte_length);
51199575102SLv Zheng if (!buffer) {
51299575102SLv Zheng return (AE_NO_MEMORY);
51399575102SLv Zheng }
51499575102SLv Zheng
51599575102SLv Zheng /* Read the original value */
51699575102SLv Zheng
51799575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp1);
51899575102SLv Zheng if (ACPI_FAILURE(status)) {
51999575102SLv Zheng goto exit;
52099575102SLv Zheng }
52199575102SLv Zheng
52299575102SLv Zheng /* Emit a few bytes of the buffer */
52399575102SLv Zheng
524*90791fbbSBob Moore acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT, bit_length,
525*90791fbbSBob Moore temp1->buffer.length);
526*90791fbbSBob Moore for (i = 0; ((i < 8) && (i < byte_length)); i++) {
52799575102SLv Zheng acpi_os_printf(" %2.2X", temp1->buffer.pointer[i]);
52899575102SLv Zheng }
52999575102SLv Zheng acpi_os_printf("... ");
53099575102SLv Zheng
53199575102SLv Zheng /*
53299575102SLv Zheng * Write a new value.
53399575102SLv Zheng *
53499575102SLv Zheng * Handle possible extra bits at the end of the buffer. Can
53599575102SLv Zheng * happen for field_units larger than an integer, but the bit
53699575102SLv Zheng * count is not an integral number of bytes. Zero out the
53799575102SLv Zheng * unused bits.
53899575102SLv Zheng */
53999575102SLv Zheng memset(buffer, BUFFER_FILL_VALUE, byte_length);
54099575102SLv Zheng extra_bits = bit_length % 8;
54199575102SLv Zheng if (extra_bits) {
54299575102SLv Zheng buffer[byte_length - 1] = ACPI_MASK_BITS_ABOVE(extra_bits);
54399575102SLv Zheng }
54499575102SLv Zheng
54599575102SLv Zheng write_value.type = ACPI_TYPE_BUFFER;
54699575102SLv Zheng write_value.buffer.length = byte_length;
54799575102SLv Zheng write_value.buffer.pointer = buffer;
54899575102SLv Zheng
54999575102SLv Zheng status = acpi_db_write_to_object(node, &write_value);
55099575102SLv Zheng if (ACPI_FAILURE(status)) {
55199575102SLv Zheng goto exit;
55299575102SLv Zheng }
55399575102SLv Zheng
55499575102SLv Zheng /* Ensure that we can read back the new value */
55599575102SLv Zheng
55699575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp2);
55799575102SLv Zheng if (ACPI_FAILURE(status)) {
55899575102SLv Zheng goto exit;
55999575102SLv Zheng }
56099575102SLv Zheng
56199575102SLv Zheng if (memcmp(temp2->buffer.pointer, buffer, byte_length)) {
56299575102SLv Zheng acpi_os_printf(" MISMATCH 2: New buffer value");
56399575102SLv Zheng }
56499575102SLv Zheng
56599575102SLv Zheng /* Write back the original value */
56699575102SLv Zheng
56799575102SLv Zheng write_value.buffer.length = byte_length;
56899575102SLv Zheng write_value.buffer.pointer = temp1->buffer.pointer;
56999575102SLv Zheng
57099575102SLv Zheng status = acpi_db_write_to_object(node, &write_value);
57199575102SLv Zheng if (ACPI_FAILURE(status)) {
57299575102SLv Zheng goto exit;
57399575102SLv Zheng }
57499575102SLv Zheng
57599575102SLv Zheng /* Ensure that we can read back the original value */
57699575102SLv Zheng
57799575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp3);
57899575102SLv Zheng if (ACPI_FAILURE(status)) {
57999575102SLv Zheng goto exit;
58099575102SLv Zheng }
58199575102SLv Zheng
58299575102SLv Zheng if (memcmp(temp1->buffer.pointer, temp3->buffer.pointer, byte_length)) {
58399575102SLv Zheng acpi_os_printf(" MISMATCH 3: While restoring original buffer");
58499575102SLv Zheng }
58599575102SLv Zheng
58699575102SLv Zheng exit:
58799575102SLv Zheng ACPI_FREE(buffer);
58899575102SLv Zheng if (temp1) {
58999575102SLv Zheng acpi_os_free(temp1);
59099575102SLv Zheng }
59199575102SLv Zheng if (temp2) {
59299575102SLv Zheng acpi_os_free(temp2);
59399575102SLv Zheng }
59499575102SLv Zheng if (temp3) {
59599575102SLv Zheng acpi_os_free(temp3);
59699575102SLv Zheng }
59799575102SLv Zheng return (status);
59899575102SLv Zheng }
59999575102SLv Zheng
60099575102SLv Zheng /*******************************************************************************
60199575102SLv Zheng *
60299575102SLv Zheng * FUNCTION: acpi_db_test_string_type
60399575102SLv Zheng *
60499575102SLv Zheng * PARAMETERS: node - Parent NS node for the object
60599575102SLv Zheng * byte_length - Actual length of the object.
60699575102SLv Zheng *
60799575102SLv Zheng * RETURN: Status
60899575102SLv Zheng *
60999575102SLv Zheng * DESCRIPTION: Test read/write for an String-valued object. Performs a
61099575102SLv Zheng * write/read/compare of an arbitrary new value, then performs
61199575102SLv Zheng * a write/read/compare of the original value.
61299575102SLv Zheng *
61399575102SLv Zheng ******************************************************************************/
61499575102SLv Zheng
61599575102SLv Zheng static acpi_status
acpi_db_test_string_type(struct acpi_namespace_node * node,u32 byte_length)61699575102SLv Zheng acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length)
61799575102SLv Zheng {
61899575102SLv Zheng union acpi_object *temp1 = NULL;
61999575102SLv Zheng union acpi_object *temp2 = NULL;
62099575102SLv Zheng union acpi_object *temp3 = NULL;
62199575102SLv Zheng char *value_to_write = "Test String from AML Debugger";
62299575102SLv Zheng union acpi_object write_value;
62399575102SLv Zheng acpi_status status;
62499575102SLv Zheng
62599575102SLv Zheng /* Read the original value */
62699575102SLv Zheng
62799575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp1);
62899575102SLv Zheng if (ACPI_FAILURE(status)) {
62999575102SLv Zheng return (status);
63099575102SLv Zheng }
63199575102SLv Zheng
632*90791fbbSBob Moore acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " \"%s\"",
633*90791fbbSBob Moore (temp1->string.length * 8), temp1->string.length,
634*90791fbbSBob Moore temp1->string.pointer);
63599575102SLv Zheng
63699575102SLv Zheng /* Write a new value */
63799575102SLv Zheng
63899575102SLv Zheng write_value.type = ACPI_TYPE_STRING;
63999575102SLv Zheng write_value.string.length = strlen(value_to_write);
64099575102SLv Zheng write_value.string.pointer = value_to_write;
64199575102SLv Zheng
64299575102SLv Zheng status = acpi_db_write_to_object(node, &write_value);
64399575102SLv Zheng if (ACPI_FAILURE(status)) {
64499575102SLv Zheng goto exit;
64599575102SLv Zheng }
64699575102SLv Zheng
64799575102SLv Zheng /* Ensure that we can read back the new value */
64899575102SLv Zheng
64999575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp2);
65099575102SLv Zheng if (ACPI_FAILURE(status)) {
65199575102SLv Zheng goto exit;
65299575102SLv Zheng }
65399575102SLv Zheng
65499575102SLv Zheng if (strcmp(temp2->string.pointer, value_to_write)) {
65599575102SLv Zheng acpi_os_printf(" MISMATCH 2: %s, expecting %s",
65699575102SLv Zheng temp2->string.pointer, value_to_write);
65799575102SLv Zheng }
65899575102SLv Zheng
65999575102SLv Zheng /* Write back the original value */
66099575102SLv Zheng
66199575102SLv Zheng write_value.string.length = strlen(temp1->string.pointer);
66299575102SLv Zheng write_value.string.pointer = temp1->string.pointer;
66399575102SLv Zheng
66499575102SLv Zheng status = acpi_db_write_to_object(node, &write_value);
66599575102SLv Zheng if (ACPI_FAILURE(status)) {
66699575102SLv Zheng goto exit;
66799575102SLv Zheng }
66899575102SLv Zheng
66999575102SLv Zheng /* Ensure that we can read back the original value */
67099575102SLv Zheng
67199575102SLv Zheng status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp3);
67299575102SLv Zheng if (ACPI_FAILURE(status)) {
67399575102SLv Zheng goto exit;
67499575102SLv Zheng }
67599575102SLv Zheng
67699575102SLv Zheng if (strcmp(temp1->string.pointer, temp3->string.pointer)) {
67799575102SLv Zheng acpi_os_printf(" MISMATCH 3: %s, expecting %s",
67899575102SLv Zheng temp3->string.pointer, temp1->string.pointer);
67999575102SLv Zheng }
68099575102SLv Zheng
68199575102SLv Zheng exit:
68299575102SLv Zheng if (temp1) {
68399575102SLv Zheng acpi_os_free(temp1);
68499575102SLv Zheng }
68599575102SLv Zheng if (temp2) {
68699575102SLv Zheng acpi_os_free(temp2);
68799575102SLv Zheng }
68899575102SLv Zheng if (temp3) {
68999575102SLv Zheng acpi_os_free(temp3);
69099575102SLv Zheng }
69199575102SLv Zheng return (status);
69299575102SLv Zheng }
69399575102SLv Zheng
69499575102SLv Zheng /*******************************************************************************
69599575102SLv Zheng *
696db2e11a7SBob Moore * FUNCTION: acpi_db_test_package_type
697db2e11a7SBob Moore *
698db2e11a7SBob Moore * PARAMETERS: node - Parent NS node for the object
699db2e11a7SBob Moore *
700db2e11a7SBob Moore * RETURN: Status
701db2e11a7SBob Moore *
702db2e11a7SBob Moore * DESCRIPTION: Test read for a Package object.
703db2e11a7SBob Moore *
704db2e11a7SBob Moore ******************************************************************************/
705db2e11a7SBob Moore
acpi_db_test_package_type(struct acpi_namespace_node * node)706db2e11a7SBob Moore static acpi_status acpi_db_test_package_type(struct acpi_namespace_node *node)
707db2e11a7SBob Moore {
708db2e11a7SBob Moore union acpi_object *temp1 = NULL;
709db2e11a7SBob Moore acpi_status status;
710db2e11a7SBob Moore
711db2e11a7SBob Moore /* Read the original value */
712db2e11a7SBob Moore
713db2e11a7SBob Moore status = acpi_db_read_from_object(node, ACPI_TYPE_PACKAGE, &temp1);
714db2e11a7SBob Moore if (ACPI_FAILURE(status)) {
715db2e11a7SBob Moore return (status);
716db2e11a7SBob Moore }
717db2e11a7SBob Moore
718*90791fbbSBob Moore acpi_os_printf(" %.2X Elements", temp1->package.count);
719db2e11a7SBob Moore acpi_os_free(temp1);
720db2e11a7SBob Moore return (status);
721db2e11a7SBob Moore }
722db2e11a7SBob Moore
723db2e11a7SBob Moore /*******************************************************************************
724db2e11a7SBob Moore *
725*90791fbbSBob Moore * FUNCTION: acpi_db_test_field_unit_type
726*90791fbbSBob Moore *
727*90791fbbSBob Moore * PARAMETERS: obj_desc - A field unit object
728*90791fbbSBob Moore *
729*90791fbbSBob Moore * RETURN: Status
730*90791fbbSBob Moore *
731*90791fbbSBob Moore * DESCRIPTION: Test read/write on a named field unit.
732*90791fbbSBob Moore *
733*90791fbbSBob Moore ******************************************************************************/
734*90791fbbSBob Moore
735*90791fbbSBob Moore static acpi_status
acpi_db_test_field_unit_type(union acpi_operand_object * obj_desc)736*90791fbbSBob Moore acpi_db_test_field_unit_type(union acpi_operand_object *obj_desc)
737*90791fbbSBob Moore {
738*90791fbbSBob Moore union acpi_operand_object *region_obj;
739*90791fbbSBob Moore u32 bit_length = 0;
740*90791fbbSBob Moore u32 byte_length = 0;
741*90791fbbSBob Moore acpi_status status = AE_OK;
742*90791fbbSBob Moore union acpi_operand_object *ret_buffer_desc;
743*90791fbbSBob Moore
744*90791fbbSBob Moore /* Supported spaces are memory/io/pci_config */
745*90791fbbSBob Moore
746*90791fbbSBob Moore region_obj = obj_desc->field.region_obj;
747*90791fbbSBob Moore switch (region_obj->region.space_id) {
748*90791fbbSBob Moore case ACPI_ADR_SPACE_SYSTEM_MEMORY:
749*90791fbbSBob Moore case ACPI_ADR_SPACE_SYSTEM_IO:
750*90791fbbSBob Moore case ACPI_ADR_SPACE_PCI_CONFIG:
751*90791fbbSBob Moore
752*90791fbbSBob Moore /* Need the interpreter to execute */
753*90791fbbSBob Moore
754*90791fbbSBob Moore acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
755*90791fbbSBob Moore acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
756*90791fbbSBob Moore
757*90791fbbSBob Moore /* Exercise read-then-write */
758*90791fbbSBob Moore
759*90791fbbSBob Moore status =
760*90791fbbSBob Moore acpi_ex_read_data_from_field(NULL, obj_desc,
761*90791fbbSBob Moore &ret_buffer_desc);
762*90791fbbSBob Moore if (status == AE_OK) {
763*90791fbbSBob Moore acpi_ex_write_data_to_field(ret_buffer_desc, obj_desc,
764*90791fbbSBob Moore NULL);
765*90791fbbSBob Moore acpi_ut_remove_reference(ret_buffer_desc);
766*90791fbbSBob Moore }
767*90791fbbSBob Moore
768*90791fbbSBob Moore acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
769*90791fbbSBob Moore acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
770*90791fbbSBob Moore
771*90791fbbSBob Moore bit_length = obj_desc->common_field.bit_length;
772*90791fbbSBob Moore byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
773*90791fbbSBob Moore
774*90791fbbSBob Moore acpi_os_printf(ACPI_DEBUG_LENGTH_FORMAT " [%s]", bit_length,
775*90791fbbSBob Moore byte_length,
776*90791fbbSBob Moore acpi_ut_get_region_name(region_obj->region.
777*90791fbbSBob Moore space_id));
778*90791fbbSBob Moore return (status);
779*90791fbbSBob Moore
780*90791fbbSBob Moore default:
781*90791fbbSBob Moore
782*90791fbbSBob Moore acpi_os_printf
783*90791fbbSBob Moore (" %s address space is not supported in this command [%4.4s]",
784*90791fbbSBob Moore acpi_ut_get_region_name(region_obj->region.space_id),
785*90791fbbSBob Moore region_obj->region.node->name.ascii);
786*90791fbbSBob Moore return (AE_OK);
787*90791fbbSBob Moore }
788*90791fbbSBob Moore }
789*90791fbbSBob Moore
790*90791fbbSBob Moore /*******************************************************************************
791*90791fbbSBob Moore *
79299575102SLv Zheng * FUNCTION: acpi_db_read_from_object
79399575102SLv Zheng *
79499575102SLv Zheng * PARAMETERS: node - Parent NS node for the object
79599575102SLv Zheng * expected_type - Object type expected from the read
79699575102SLv Zheng * value - Where the value read is returned
79799575102SLv Zheng *
79899575102SLv Zheng * RETURN: Status
79999575102SLv Zheng *
80099575102SLv Zheng * DESCRIPTION: Performs a read from the specified object by invoking the
80199575102SLv Zheng * special debugger control method that reads the object. Thus,
80299575102SLv Zheng * the AML interpreter is doing all of the work, increasing the
80399575102SLv Zheng * validity of the test.
80499575102SLv Zheng *
80599575102SLv Zheng ******************************************************************************/
80699575102SLv Zheng
80799575102SLv Zheng static acpi_status
acpi_db_read_from_object(struct acpi_namespace_node * node,acpi_object_type expected_type,union acpi_object ** value)80899575102SLv Zheng acpi_db_read_from_object(struct acpi_namespace_node *node,
80999575102SLv Zheng acpi_object_type expected_type,
81099575102SLv Zheng union acpi_object **value)
81199575102SLv Zheng {
81299575102SLv Zheng union acpi_object *ret_value;
81399575102SLv Zheng struct acpi_object_list param_objects;
81499575102SLv Zheng union acpi_object params[2];
81599575102SLv Zheng struct acpi_buffer return_obj;
81699575102SLv Zheng acpi_status status;
81799575102SLv Zheng
81899575102SLv Zheng params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
81999575102SLv Zheng params[0].reference.actual_type = node->type;
82099575102SLv Zheng params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
82199575102SLv Zheng
82299575102SLv Zheng param_objects.count = 1;
82399575102SLv Zheng param_objects.pointer = params;
82499575102SLv Zheng
82599575102SLv Zheng return_obj.length = ACPI_ALLOCATE_BUFFER;
82699575102SLv Zheng
82799575102SLv Zheng acpi_gbl_method_executing = TRUE;
82899575102SLv Zheng status = acpi_evaluate_object(read_handle, NULL,
82999575102SLv Zheng ¶m_objects, &return_obj);
83099575102SLv Zheng
831db2e11a7SBob Moore acpi_gbl_method_executing = FALSE;
83299575102SLv Zheng if (ACPI_FAILURE(status)) {
83399575102SLv Zheng acpi_os_printf("Could not read from object, %s",
83499575102SLv Zheng acpi_format_exception(status));
83599575102SLv Zheng return (status);
83699575102SLv Zheng }
83799575102SLv Zheng
83899575102SLv Zheng ret_value = (union acpi_object *)return_obj.pointer;
83999575102SLv Zheng
84099575102SLv Zheng switch (ret_value->type) {
84199575102SLv Zheng case ACPI_TYPE_INTEGER:
84299575102SLv Zheng case ACPI_TYPE_BUFFER:
84399575102SLv Zheng case ACPI_TYPE_STRING:
844db2e11a7SBob Moore case ACPI_TYPE_PACKAGE:
84599575102SLv Zheng /*
84699575102SLv Zheng * Did we receive the type we wanted? Most important for the
84799575102SLv Zheng * Integer/Buffer case (when a field is larger than an Integer,
84899575102SLv Zheng * it should return a Buffer).
84999575102SLv Zheng */
85099575102SLv Zheng if (ret_value->type != expected_type) {
85199575102SLv Zheng acpi_os_printf
85299575102SLv Zheng (" Type mismatch: Expected %s, Received %s",
85399575102SLv Zheng acpi_ut_get_type_name(expected_type),
85499575102SLv Zheng acpi_ut_get_type_name(ret_value->type));
85599575102SLv Zheng
856db2e11a7SBob Moore acpi_os_free(return_obj.pointer);
85799575102SLv Zheng return (AE_TYPE);
85899575102SLv Zheng }
85999575102SLv Zheng
86099575102SLv Zheng *value = ret_value;
86199575102SLv Zheng break;
86299575102SLv Zheng
86399575102SLv Zheng default:
86499575102SLv Zheng
86599575102SLv Zheng acpi_os_printf(" Unsupported return object type, %s",
86699575102SLv Zheng acpi_ut_get_type_name(ret_value->type));
86799575102SLv Zheng
86899575102SLv Zheng acpi_os_free(return_obj.pointer);
86999575102SLv Zheng return (AE_TYPE);
87099575102SLv Zheng }
87199575102SLv Zheng
87299575102SLv Zheng return (status);
87399575102SLv Zheng }
87499575102SLv Zheng
87599575102SLv Zheng /*******************************************************************************
87699575102SLv Zheng *
87799575102SLv Zheng * FUNCTION: acpi_db_write_to_object
87899575102SLv Zheng *
87999575102SLv Zheng * PARAMETERS: node - Parent NS node for the object
88099575102SLv Zheng * value - Value to be written
88199575102SLv Zheng *
88299575102SLv Zheng * RETURN: Status
88399575102SLv Zheng *
88499575102SLv Zheng * DESCRIPTION: Performs a write to the specified object by invoking the
88599575102SLv Zheng * special debugger control method that writes the object. Thus,
88699575102SLv Zheng * the AML interpreter is doing all of the work, increasing the
88799575102SLv Zheng * validity of the test.
88899575102SLv Zheng *
88999575102SLv Zheng ******************************************************************************/
89099575102SLv Zheng
89199575102SLv Zheng static acpi_status
acpi_db_write_to_object(struct acpi_namespace_node * node,union acpi_object * value)89299575102SLv Zheng acpi_db_write_to_object(struct acpi_namespace_node *node,
89399575102SLv Zheng union acpi_object *value)
89499575102SLv Zheng {
89599575102SLv Zheng struct acpi_object_list param_objects;
89699575102SLv Zheng union acpi_object params[2];
89799575102SLv Zheng acpi_status status;
89899575102SLv Zheng
89999575102SLv Zheng params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
90099575102SLv Zheng params[0].reference.actual_type = node->type;
90199575102SLv Zheng params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
90299575102SLv Zheng
90399575102SLv Zheng /* Copy the incoming user parameter */
90499575102SLv Zheng
90599575102SLv Zheng memcpy(¶ms[1], value, sizeof(union acpi_object));
90699575102SLv Zheng
90799575102SLv Zheng param_objects.count = 2;
90899575102SLv Zheng param_objects.pointer = params;
90999575102SLv Zheng
91099575102SLv Zheng acpi_gbl_method_executing = TRUE;
91199575102SLv Zheng status = acpi_evaluate_object(write_handle, NULL, ¶m_objects, NULL);
91299575102SLv Zheng acpi_gbl_method_executing = FALSE;
91399575102SLv Zheng
91499575102SLv Zheng if (ACPI_FAILURE(status)) {
91599575102SLv Zheng acpi_os_printf("Could not write to object, %s",
91699575102SLv Zheng acpi_format_exception(status));
91799575102SLv Zheng }
91899575102SLv Zheng
91999575102SLv Zheng return (status);
92099575102SLv Zheng }
92199575102SLv Zheng
92299575102SLv Zheng /*******************************************************************************
92399575102SLv Zheng *
92499575102SLv Zheng * FUNCTION: acpi_db_evaluate_all_predefined_names
92599575102SLv Zheng *
92699575102SLv Zheng * PARAMETERS: count_arg - Max number of methods to execute
92799575102SLv Zheng *
92899575102SLv Zheng * RETURN: None
92999575102SLv Zheng *
93099575102SLv Zheng * DESCRIPTION: Namespace batch execution. Execute predefined names in the
93199575102SLv Zheng * namespace, up to the max count, if specified.
93299575102SLv Zheng *
93399575102SLv Zheng ******************************************************************************/
93499575102SLv Zheng
acpi_db_evaluate_all_predefined_names(char * count_arg)93599575102SLv Zheng static void acpi_db_evaluate_all_predefined_names(char *count_arg)
93699575102SLv Zheng {
93799575102SLv Zheng struct acpi_db_execute_walk info;
93899575102SLv Zheng
93999575102SLv Zheng info.count = 0;
94099575102SLv Zheng info.max_count = ACPI_UINT32_MAX;
94199575102SLv Zheng
94299575102SLv Zheng if (count_arg) {
94399575102SLv Zheng info.max_count = strtoul(count_arg, NULL, 0);
94499575102SLv Zheng }
94599575102SLv Zheng
94699575102SLv Zheng /* Search all nodes in namespace */
94799575102SLv Zheng
94899575102SLv Zheng (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
94999575102SLv Zheng ACPI_UINT32_MAX,
95099575102SLv Zheng acpi_db_evaluate_one_predefined_name, NULL,
95199575102SLv Zheng (void *)&info, NULL);
95299575102SLv Zheng
95399575102SLv Zheng acpi_os_printf("Evaluated %u predefined names in the namespace\n",
95499575102SLv Zheng info.count);
95599575102SLv Zheng }
95699575102SLv Zheng
95799575102SLv Zheng /*******************************************************************************
95899575102SLv Zheng *
95999575102SLv Zheng * FUNCTION: acpi_db_evaluate_one_predefined_name
96099575102SLv Zheng *
96199575102SLv Zheng * PARAMETERS: Callback from walk_namespace
96299575102SLv Zheng *
96399575102SLv Zheng * RETURN: Status
96499575102SLv Zheng *
96599575102SLv Zheng * DESCRIPTION: Batch execution module. Currently only executes predefined
96699575102SLv Zheng * ACPI names.
96799575102SLv Zheng *
96899575102SLv Zheng ******************************************************************************/
96999575102SLv Zheng
97099575102SLv Zheng static acpi_status
acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)97199575102SLv Zheng acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
97299575102SLv Zheng u32 nesting_level,
97399575102SLv Zheng void *context, void **return_value)
97499575102SLv Zheng {
97599575102SLv Zheng struct acpi_namespace_node *node =
97699575102SLv Zheng (struct acpi_namespace_node *)obj_handle;
97799575102SLv Zheng struct acpi_db_execute_walk *info =
97899575102SLv Zheng (struct acpi_db_execute_walk *)context;
97999575102SLv Zheng char *pathname;
98099575102SLv Zheng const union acpi_predefined_info *predefined;
98199575102SLv Zheng struct acpi_device_info *obj_info;
98299575102SLv Zheng struct acpi_object_list param_objects;
98399575102SLv Zheng union acpi_object params[ACPI_METHOD_NUM_ARGS];
98499575102SLv Zheng union acpi_object *this_param;
98599575102SLv Zheng struct acpi_buffer return_obj;
98699575102SLv Zheng acpi_status status;
98799575102SLv Zheng u16 arg_type_list;
98899575102SLv Zheng u8 arg_count;
98999575102SLv Zheng u8 arg_type;
99099575102SLv Zheng u32 i;
99199575102SLv Zheng
99299575102SLv Zheng /* The name must be a predefined ACPI name */
99399575102SLv Zheng
99499575102SLv Zheng predefined = acpi_ut_match_predefined_method(node->name.ascii);
99599575102SLv Zheng if (!predefined) {
99699575102SLv Zheng return (AE_OK);
99799575102SLv Zheng }
99899575102SLv Zheng
99999575102SLv Zheng if (node->type == ACPI_TYPE_LOCAL_SCOPE) {
100099575102SLv Zheng return (AE_OK);
100199575102SLv Zheng }
100299575102SLv Zheng
10030e166e4fSLv Zheng pathname = acpi_ns_get_normalized_pathname(node, TRUE);
100499575102SLv Zheng if (!pathname) {
100599575102SLv Zheng return (AE_OK);
100699575102SLv Zheng }
100799575102SLv Zheng
100899575102SLv Zheng /* Get the object info for number of method parameters */
100999575102SLv Zheng
101099575102SLv Zheng status = acpi_get_object_info(obj_handle, &obj_info);
101199575102SLv Zheng if (ACPI_FAILURE(status)) {
101299575102SLv Zheng ACPI_FREE(pathname);
101399575102SLv Zheng return (status);
101499575102SLv Zheng }
101599575102SLv Zheng
101699575102SLv Zheng param_objects.count = 0;
101799575102SLv Zheng param_objects.pointer = NULL;
101899575102SLv Zheng
101999575102SLv Zheng if (obj_info->type == ACPI_TYPE_METHOD) {
102099575102SLv Zheng
102199575102SLv Zheng /* Setup default parameters (with proper types) */
102299575102SLv Zheng
102399575102SLv Zheng arg_type_list = predefined->info.argument_list;
102499575102SLv Zheng arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
102599575102SLv Zheng
102699575102SLv Zheng /*
102799575102SLv Zheng * Setup the ACPI-required number of arguments, regardless of what
102899575102SLv Zheng * the actual method defines. If there is a difference, then the
102999575102SLv Zheng * method is wrong and a warning will be issued during execution.
103099575102SLv Zheng */
103199575102SLv Zheng this_param = params;
103299575102SLv Zheng for (i = 0; i < arg_count; i++) {
103399575102SLv Zheng arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
103499575102SLv Zheng this_param->type = arg_type;
103599575102SLv Zheng
103699575102SLv Zheng switch (arg_type) {
103799575102SLv Zheng case ACPI_TYPE_INTEGER:
103899575102SLv Zheng
103999575102SLv Zheng this_param->integer.value = 1;
104099575102SLv Zheng break;
104199575102SLv Zheng
104299575102SLv Zheng case ACPI_TYPE_STRING:
104399575102SLv Zheng
104499575102SLv Zheng this_param->string.pointer =
104599575102SLv Zheng "This is the default argument string";
104699575102SLv Zheng this_param->string.length =
104799575102SLv Zheng strlen(this_param->string.pointer);
104899575102SLv Zheng break;
104999575102SLv Zheng
105099575102SLv Zheng case ACPI_TYPE_BUFFER:
105199575102SLv Zheng
105299575102SLv Zheng this_param->buffer.pointer = (u8 *)params; /* just a garbage buffer */
105399575102SLv Zheng this_param->buffer.length = 48;
105499575102SLv Zheng break;
105599575102SLv Zheng
105699575102SLv Zheng case ACPI_TYPE_PACKAGE:
105799575102SLv Zheng
105899575102SLv Zheng this_param->package.elements = NULL;
105999575102SLv Zheng this_param->package.count = 0;
106099575102SLv Zheng break;
106199575102SLv Zheng
106299575102SLv Zheng default:
106399575102SLv Zheng
106499575102SLv Zheng acpi_os_printf
106599575102SLv Zheng ("%s: Unsupported argument type: %u\n",
106699575102SLv Zheng pathname, arg_type);
106799575102SLv Zheng break;
106899575102SLv Zheng }
106999575102SLv Zheng
107099575102SLv Zheng this_param++;
107199575102SLv Zheng }
107299575102SLv Zheng
107399575102SLv Zheng param_objects.count = arg_count;
107499575102SLv Zheng param_objects.pointer = params;
107599575102SLv Zheng }
107699575102SLv Zheng
107799575102SLv Zheng ACPI_FREE(obj_info);
107899575102SLv Zheng return_obj.pointer = NULL;
107999575102SLv Zheng return_obj.length = ACPI_ALLOCATE_BUFFER;
108099575102SLv Zheng
108199575102SLv Zheng /* Do the actual method execution */
108299575102SLv Zheng
108399575102SLv Zheng acpi_gbl_method_executing = TRUE;
108499575102SLv Zheng
108599575102SLv Zheng status = acpi_evaluate_object(node, NULL, ¶m_objects, &return_obj);
108699575102SLv Zheng
108799575102SLv Zheng acpi_os_printf("%-32s returned %s\n",
108899575102SLv Zheng pathname, acpi_format_exception(status));
108999575102SLv Zheng acpi_gbl_method_executing = FALSE;
109099575102SLv Zheng ACPI_FREE(pathname);
109199575102SLv Zheng
109299575102SLv Zheng /* Ignore status from method execution */
109399575102SLv Zheng
109499575102SLv Zheng status = AE_OK;
109599575102SLv Zheng
109699575102SLv Zheng /* Update count, check if we have executed enough methods */
109799575102SLv Zheng
109899575102SLv Zheng info->count++;
109999575102SLv Zheng if (info->count >= info->max_count) {
110099575102SLv Zheng status = AE_CTRL_TERMINATE;
110199575102SLv Zheng }
110299575102SLv Zheng
110399575102SLv Zheng return (status);
110499575102SLv Zheng }
1105