// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/*******************************************************************************
*
* Module Name: dbtest - Various debug-related tests
*
******************************************************************************/
#include <acpi/acpi.h>
#include "accommon.h"
#include "acdebug.h"
#include "acnamesp.h"
#include "acpredef.h"
#define _COMPONENT ACPI_CA_DEBUGGER
ACPI_MODULE_NAME("dbtest")
/* Local prototypes */
static void acpi_db_test_all_objects(void);
static acpi_status
acpi_db_test_one_object(acpi_handle obj_handle,
u32 nesting_level, void *context, void **return_value);
static acpi_status
acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length);
static acpi_status
acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length);
static acpi_status
acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length);
static acpi_status
acpi_db_read_from_object(struct acpi_namespace_node *node,
acpi_object_type expected_type,
union acpi_object **value);
static acpi_status
acpi_db_write_to_object(struct acpi_namespace_node *node,
union acpi_object *value);
static void acpi_db_evaluate_all_predefined_names(char *count_arg);
static acpi_status
acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
u32 nesting_level,
void *context, void **return_value);
/*
* Test subcommands
*/
static struct acpi_db_argument_info acpi_db_test_types[] = {
{"OBJECTS"},
{"PREDEFINED"},
{NULL} /* Must be null terminated */
};
#define CMD_TEST_OBJECTS 0
#define CMD_TEST_PREDEFINED 1
#define BUFFER_FILL_VALUE 0xFF
/*
* Support for the special debugger read/write control methods.
* These methods are installed into the current namespace and are
* used to read and write the various namespace objects. The point
* is to force the AML interpreter do all of the work.
*/
#define ACPI_DB_READ_METHOD "\\_T98"
#define ACPI_DB_WRITE_METHOD "\\_T99"
static acpi_handle read_handle = NULL;
static acpi_handle write_handle = NULL;
/* ASL Definitions of the debugger read/write control methods */
#if 0
definition_block("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
{
method(_T98, 1, not_serialized) { /* Read */
return (de_ref_of(arg0))
}
}
definition_block("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
{
method(_T99, 2, not_serialized) { /* Write */
store(arg1, arg0)
}
}
#endif
static unsigned char read_method_code[] = {
0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
0x02, 0xC9, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
0x39, 0x38, 0x01, 0xA4, 0x83, 0x68 /* 00000028 "98...h" */
};
static unsigned char write_method_code[] = {
0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
0x02, 0x15, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
0x39, 0x39, 0x02, 0x70, 0x69, 0x68 /* 00000028 "99.pih" */
};
/*******************************************************************************
*
* FUNCTION: acpi_db_execute_test
*
* PARAMETERS: type_arg - Subcommand
*
* RETURN: None
*
* DESCRIPTION: Execute various debug tests.
*
* Note: Code is prepared for future expansion of the TEST command.
*
******************************************************************************/
void acpi_db_execute_test(char *type_arg)
{
u32 temp;
acpi_ut_strupr(type_arg);
temp = acpi_db_match_argument(type_arg, acpi_db_test_types);
if (temp == ACPI_TYPE_NOT_FOUND) {
acpi_os_printf("Invalid or unsupported argument\n");
return;
}
switch (temp) {
case CMD_TEST_OBJECTS:
acpi_db_test_all_objects();
break;
case CMD_TEST_PREDEFINED:
acpi_db_evaluate_all_predefined_names(NULL);
break;
default:
break;
}
}
/*******************************************************************************
*
* FUNCTION: acpi_db_test_all_objects
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the
* namespace by reading/writing/comparing all data objects such
* as integers, strings, buffers, fields, buffer fields, etc.
*
******************************************************************************/
static void acpi_db_test_all_objects(void)
{
acpi_status<