xref: /linux/drivers/acpi/acpica/dbcmds.c (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
299575102SLv Zheng /*******************************************************************************
399575102SLv Zheng  *
499575102SLv Zheng  * Module Name: dbcmds - Miscellaneous debug commands and output routines
599575102SLv Zheng  *
699575102SLv Zheng  ******************************************************************************/
799575102SLv Zheng 
899575102SLv Zheng #include <acpi/acpi.h>
999575102SLv Zheng #include "accommon.h"
1099575102SLv Zheng #include "acevents.h"
1199575102SLv Zheng #include "acdebug.h"
1299575102SLv Zheng #include "acnamesp.h"
1399575102SLv Zheng #include "acresrc.h"
1499575102SLv Zheng #include "actables.h"
1599575102SLv Zheng 
1699575102SLv Zheng #define _COMPONENT          ACPI_CA_DEBUGGER
1799575102SLv Zheng ACPI_MODULE_NAME("dbcmds")
1899575102SLv Zheng 
1999575102SLv Zheng /* Local prototypes */
2099575102SLv Zheng static void
2199575102SLv Zheng acpi_dm_compare_aml_resources(u8 *aml1_buffer,
2299575102SLv Zheng 			      acpi_rsdesc_size aml1_buffer_length,
2399575102SLv Zheng 			      u8 *aml2_buffer,
2499575102SLv Zheng 			      acpi_rsdesc_size aml2_buffer_length);
2599575102SLv Zheng 
2699575102SLv Zheng static acpi_status
2799575102SLv Zheng acpi_dm_test_resource_conversion(struct acpi_namespace_node *node, char *name);
2899575102SLv Zheng 
2999575102SLv Zheng static acpi_status
3099575102SLv Zheng acpi_db_resource_callback(struct acpi_resource *resource, void *context);
3199575102SLv Zheng 
3299575102SLv Zheng static acpi_status
3399575102SLv Zheng acpi_db_device_resources(acpi_handle obj_handle,
3499575102SLv Zheng 			 u32 nesting_level, void *context, void **return_value);
3599575102SLv Zheng 
3699575102SLv Zheng static void acpi_db_do_one_sleep_state(u8 sleep_state);
3799575102SLv Zheng 
3899575102SLv Zheng static char *acpi_db_trace_method_name = NULL;
3999575102SLv Zheng 
4099575102SLv Zheng /*******************************************************************************
4199575102SLv Zheng  *
4299575102SLv Zheng  * FUNCTION:    acpi_db_convert_to_node
4399575102SLv Zheng  *
4499575102SLv Zheng  * PARAMETERS:  in_string           - String to convert
4599575102SLv Zheng  *
4699575102SLv Zheng  * RETURN:      Pointer to a NS node
4799575102SLv Zheng  *
4899575102SLv Zheng  * DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or
4999575102SLv Zheng  *              alphanumeric strings.
5099575102SLv Zheng  *
5199575102SLv Zheng  ******************************************************************************/
5299575102SLv Zheng 
acpi_db_convert_to_node(char * in_string)5399575102SLv Zheng struct acpi_namespace_node *acpi_db_convert_to_node(char *in_string)
5499575102SLv Zheng {
5599575102SLv Zheng 	struct acpi_namespace_node *node;
5699575102SLv Zheng 	acpi_size address;
5799575102SLv Zheng 
5899575102SLv Zheng 	if ((*in_string >= 0x30) && (*in_string <= 0x39)) {
5999575102SLv Zheng 
6099575102SLv Zheng 		/* Numeric argument, convert */
6199575102SLv Zheng 
6299575102SLv Zheng 		address = strtoul(in_string, NULL, 16);
6399575102SLv Zheng 		node = ACPI_TO_POINTER(address);
6499575102SLv Zheng 		if (!acpi_os_readable(node, sizeof(struct acpi_namespace_node))) {
6599575102SLv Zheng 			acpi_os_printf("Address %p is invalid", node);
6699575102SLv Zheng 			return (NULL);
6799575102SLv Zheng 		}
6899575102SLv Zheng 
6999575102SLv Zheng 		/* Make sure pointer is valid NS node */
7099575102SLv Zheng 
7199575102SLv Zheng 		if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
7299575102SLv Zheng 			acpi_os_printf
7399575102SLv Zheng 			    ("Address %p is not a valid namespace node [%s]\n",
7499575102SLv Zheng 			     node, acpi_ut_get_descriptor_name(node));
7599575102SLv Zheng 			return (NULL);
7699575102SLv Zheng 		}
7799575102SLv Zheng 	} else {
7899575102SLv Zheng 		/*
7999575102SLv Zheng 		 * Alpha argument: The parameter is a name string that must be
8099575102SLv Zheng 		 * resolved to a Namespace object.
8199575102SLv Zheng 		 */
8299575102SLv Zheng 		node = acpi_db_local_ns_lookup(in_string);
8399575102SLv Zheng 		if (!node) {
8499575102SLv Zheng 			acpi_os_printf
8599575102SLv Zheng 			    ("Could not find [%s] in namespace, defaulting to root node\n",
8699575102SLv Zheng 			     in_string);
8799575102SLv Zheng 			node = acpi_gbl_root_node;
8899575102SLv Zheng 		}
8999575102SLv Zheng 	}
9099575102SLv Zheng 
9199575102SLv Zheng 	return (node);
9299575102SLv Zheng }
9399575102SLv Zheng 
9499575102SLv Zheng /*******************************************************************************
9599575102SLv Zheng  *
9699575102SLv Zheng  * FUNCTION:    acpi_db_sleep
9799575102SLv Zheng  *
9899575102SLv Zheng  * PARAMETERS:  object_arg          - Desired sleep state (0-5). NULL means
9999575102SLv Zheng  *                                    invoke all possible sleep states.
10099575102SLv Zheng  *
10199575102SLv Zheng  * RETURN:      Status
10299575102SLv Zheng  *
10399575102SLv Zheng  * DESCRIPTION: Simulate sleep/wake sequences
10499575102SLv Zheng  *
10599575102SLv Zheng  ******************************************************************************/
10699575102SLv Zheng 
acpi_db_sleep(char * object_arg)10799575102SLv Zheng acpi_status acpi_db_sleep(char *object_arg)
10899575102SLv Zheng {
10999575102SLv Zheng 	u8 sleep_state;
11099575102SLv Zheng 	u32 i;
11199575102SLv Zheng 
11299575102SLv Zheng 	ACPI_FUNCTION_TRACE(acpi_db_sleep);
11399575102SLv Zheng 
11499575102SLv Zheng 	/* Null input (no arguments) means to invoke all sleep states */
11599575102SLv Zheng 
11699575102SLv Zheng 	if (!object_arg) {
11799575102SLv Zheng 		acpi_os_printf("Invoking all possible sleep states, 0-%d\n",
11899575102SLv Zheng 			       ACPI_S_STATES_MAX);
11999575102SLv Zheng 
12099575102SLv Zheng 		for (i = 0; i <= ACPI_S_STATES_MAX; i++) {
12199575102SLv Zheng 			acpi_db_do_one_sleep_state((u8)i);
12299575102SLv Zheng 		}
12399575102SLv Zheng 
12499575102SLv Zheng 		return_ACPI_STATUS(AE_OK);
12599575102SLv Zheng 	}
12699575102SLv Zheng 
12799575102SLv Zheng 	/* Convert argument to binary and invoke the sleep state */
12899575102SLv Zheng 
12999575102SLv Zheng 	sleep_state = (u8)strtoul(object_arg, NULL, 0);
13099575102SLv Zheng 	acpi_db_do_one_sleep_state(sleep_state);
13199575102SLv Zheng 	return_ACPI_STATUS(AE_OK);
13299575102SLv Zheng }
13399575102SLv Zheng 
13499575102SLv Zheng /*******************************************************************************
13599575102SLv Zheng  *
13699575102SLv Zheng  * FUNCTION:    acpi_db_do_one_sleep_state
13799575102SLv Zheng  *
13899575102SLv Zheng  * PARAMETERS:  sleep_state         - Desired sleep state (0-5)
13999575102SLv Zheng  *
14099575102SLv Zheng  * RETURN:      None
14199575102SLv Zheng  *
14299575102SLv Zheng  * DESCRIPTION: Simulate a sleep/wake sequence
14399575102SLv Zheng  *
14499575102SLv Zheng  ******************************************************************************/
14599575102SLv Zheng 
acpi_db_do_one_sleep_state(u8 sleep_state)14699575102SLv Zheng static void acpi_db_do_one_sleep_state(u8 sleep_state)
14799575102SLv Zheng {
14899575102SLv Zheng 	acpi_status status;
14999575102SLv Zheng 	u8 sleep_type_a;
15099575102SLv Zheng 	u8 sleep_type_b;
15199575102SLv Zheng 
15299575102SLv Zheng 	/* Validate parameter */
15399575102SLv Zheng 
15499575102SLv Zheng 	if (sleep_state > ACPI_S_STATES_MAX) {
15599575102SLv Zheng 		acpi_os_printf("Sleep state %d out of range (%d max)\n",
15699575102SLv Zheng 			       sleep_state, ACPI_S_STATES_MAX);
15799575102SLv Zheng 		return;
15899575102SLv Zheng 	}
15999575102SLv Zheng 
16099575102SLv Zheng 	acpi_os_printf("\n---- Invoking sleep state S%d (%s):\n",
16199575102SLv Zheng 		       sleep_state, acpi_gbl_sleep_state_names[sleep_state]);
16299575102SLv Zheng 
16399575102SLv Zheng 	/* Get the values for the sleep type registers (for display only) */
16499575102SLv Zheng 
16599575102SLv Zheng 	status =
16699575102SLv Zheng 	    acpi_get_sleep_type_data(sleep_state, &sleep_type_a, &sleep_type_b);
16799575102SLv Zheng 	if (ACPI_FAILURE(status)) {
16899575102SLv Zheng 		acpi_os_printf("Could not evaluate [%s] method, %s\n",
16999575102SLv Zheng 			       acpi_gbl_sleep_state_names[sleep_state],
17099575102SLv Zheng 			       acpi_format_exception(status));
17199575102SLv Zheng 		return;
17299575102SLv Zheng 	}
17399575102SLv Zheng 
17499575102SLv Zheng 	acpi_os_printf
17599575102SLv Zheng 	    ("Register values for sleep state S%d: Sleep-A: %.2X, Sleep-B: %.2X\n",
17699575102SLv Zheng 	     sleep_state, sleep_type_a, sleep_type_b);
17799575102SLv Zheng 
17899575102SLv Zheng 	/* Invoke the various sleep/wake interfaces */
17999575102SLv Zheng 
18099575102SLv Zheng 	acpi_os_printf("**** Sleep: Prepare to sleep (S%d) ****\n",
18199575102SLv Zheng 		       sleep_state);
18299575102SLv Zheng 	status = acpi_enter_sleep_state_prep(sleep_state);
18399575102SLv Zheng 	if (ACPI_FAILURE(status)) {
18499575102SLv Zheng 		goto error_exit;
18599575102SLv Zheng 	}
18699575102SLv Zheng 
18799575102SLv Zheng 	acpi_os_printf("**** Sleep: Going to sleep (S%d) ****\n", sleep_state);
18899575102SLv Zheng 	status = acpi_enter_sleep_state(sleep_state);
18999575102SLv Zheng 	if (ACPI_FAILURE(status)) {
19099575102SLv Zheng 		goto error_exit;
19199575102SLv Zheng 	}
19299575102SLv Zheng 
19399575102SLv Zheng 	acpi_os_printf("**** Wake: Prepare to return from sleep (S%d) ****\n",
19499575102SLv Zheng 		       sleep_state);
19599575102SLv Zheng 	status = acpi_leave_sleep_state_prep(sleep_state);
19699575102SLv Zheng 	if (ACPI_FAILURE(status)) {
19799575102SLv Zheng 		goto error_exit;
19899575102SLv Zheng 	}
19999575102SLv Zheng 
20099575102SLv Zheng 	acpi_os_printf("**** Wake: Return from sleep (S%d) ****\n",
20199575102SLv Zheng 		       sleep_state);
20299575102SLv Zheng 	status = acpi_leave_sleep_state(sleep_state);
20399575102SLv Zheng 	if (ACPI_FAILURE(status)) {
20499575102SLv Zheng 		goto error_exit;
20599575102SLv Zheng 	}
20699575102SLv Zheng 
20799575102SLv Zheng 	return;
20899575102SLv Zheng 
20999575102SLv Zheng error_exit:
21099575102SLv Zheng 	ACPI_EXCEPTION((AE_INFO, status, "During invocation of sleep state S%d",
21199575102SLv Zheng 			sleep_state));
21299575102SLv Zheng }
21399575102SLv Zheng 
21499575102SLv Zheng /*******************************************************************************
21599575102SLv Zheng  *
21699575102SLv Zheng  * FUNCTION:    acpi_db_display_locks
21799575102SLv Zheng  *
21899575102SLv Zheng  * PARAMETERS:  None
21999575102SLv Zheng  *
22099575102SLv Zheng  * RETURN:      None
22199575102SLv Zheng  *
22299575102SLv Zheng  * DESCRIPTION: Display information about internal mutexes.
22399575102SLv Zheng  *
22499575102SLv Zheng  ******************************************************************************/
22599575102SLv Zheng 
acpi_db_display_locks(void)22699575102SLv Zheng void acpi_db_display_locks(void)
22799575102SLv Zheng {
22899575102SLv Zheng 	u32 i;
22999575102SLv Zheng 
23099575102SLv Zheng 	for (i = 0; i < ACPI_MAX_MUTEX; i++) {
23199575102SLv Zheng 		acpi_os_printf("%26s : %s\n", acpi_ut_get_mutex_name(i),
23299575102SLv Zheng 			       acpi_gbl_mutex_info[i].thread_id ==
23399575102SLv Zheng 			       ACPI_MUTEX_NOT_ACQUIRED ? "Locked" : "Unlocked");
23499575102SLv Zheng 	}
23599575102SLv Zheng }
23699575102SLv Zheng 
23799575102SLv Zheng /*******************************************************************************
23899575102SLv Zheng  *
23999575102SLv Zheng  * FUNCTION:    acpi_db_display_table_info
24099575102SLv Zheng  *
24199575102SLv Zheng  * PARAMETERS:  table_arg           - Name of table to be displayed
24299575102SLv Zheng  *
24399575102SLv Zheng  * RETURN:      None
24499575102SLv Zheng  *
24599575102SLv Zheng  * DESCRIPTION: Display information about loaded tables. Current
24699575102SLv Zheng  *              implementation displays all loaded tables.
24799575102SLv Zheng  *
24899575102SLv Zheng  ******************************************************************************/
24999575102SLv Zheng 
acpi_db_display_table_info(char * table_arg)25099575102SLv Zheng void acpi_db_display_table_info(char *table_arg)
25199575102SLv Zheng {
25299575102SLv Zheng 	u32 i;
25399575102SLv Zheng 	struct acpi_table_desc *table_desc;
25499575102SLv Zheng 	acpi_status status;
25599575102SLv Zheng 
25699575102SLv Zheng 	/* Header */
25799575102SLv Zheng 
25899575102SLv Zheng 	acpi_os_printf("Idx ID  Status Type                    "
25999575102SLv Zheng 		       "TableHeader (Sig, Address, Length, Misc)\n");
26099575102SLv Zheng 
26199575102SLv Zheng 	/* Walk the entire root table list */
26299575102SLv Zheng 
26399575102SLv Zheng 	for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
26499575102SLv Zheng 		table_desc = &acpi_gbl_root_table_list.tables[i];
26599575102SLv Zheng 
26699575102SLv Zheng 		/* Index and Table ID */
26799575102SLv Zheng 
26899575102SLv Zheng 		acpi_os_printf("%3u %.2u ", i, table_desc->owner_id);
26999575102SLv Zheng 
27099575102SLv Zheng 		/* Decode the table flags */
27199575102SLv Zheng 
27299575102SLv Zheng 		if (!(table_desc->flags & ACPI_TABLE_IS_LOADED)) {
27399575102SLv Zheng 			acpi_os_printf("NotLoaded ");
27499575102SLv Zheng 		} else {
27599575102SLv Zheng 			acpi_os_printf(" Loaded ");
27699575102SLv Zheng 		}
27799575102SLv Zheng 
27899575102SLv Zheng 		switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
27999575102SLv Zheng 		case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
28099575102SLv Zheng 
28199575102SLv Zheng 			acpi_os_printf("External/virtual ");
28299575102SLv Zheng 			break;
28399575102SLv Zheng 
28499575102SLv Zheng 		case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
28599575102SLv Zheng 
28699575102SLv Zheng 			acpi_os_printf("Internal/physical ");
28799575102SLv Zheng 			break;
28899575102SLv Zheng 
28999575102SLv Zheng 		case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
29099575102SLv Zheng 
29199575102SLv Zheng 			acpi_os_printf("Internal/virtual ");
29299575102SLv Zheng 			break;
29399575102SLv Zheng 
29499575102SLv Zheng 		default:
29599575102SLv Zheng 
29699575102SLv Zheng 			acpi_os_printf("INVALID TYPE    ");
29799575102SLv Zheng 			break;
29899575102SLv Zheng 		}
29999575102SLv Zheng 
30099575102SLv Zheng 		/* Make sure that the table is mapped */
30199575102SLv Zheng 
30299575102SLv Zheng 		status = acpi_tb_validate_table(table_desc);
30399575102SLv Zheng 		if (ACPI_FAILURE(status)) {
30499575102SLv Zheng 			return;
30599575102SLv Zheng 		}
30699575102SLv Zheng 
30799575102SLv Zheng 		/* Dump the table header */
30899575102SLv Zheng 
30999575102SLv Zheng 		if (table_desc->pointer) {
31099575102SLv Zheng 			acpi_tb_print_table_header(table_desc->address,
31199575102SLv Zheng 						   table_desc->pointer);
31299575102SLv Zheng 		} else {
31399575102SLv Zheng 			/* If the pointer is null, the table has been unloaded */
31499575102SLv Zheng 
31505fb04b5SBob Moore 			ACPI_INFO(("%4.4s - Table has been unloaded",
31699575102SLv Zheng 				   table_desc->signature.ascii));
31799575102SLv Zheng 		}
31899575102SLv Zheng 	}
31999575102SLv Zheng }
32099575102SLv Zheng 
32199575102SLv Zheng /*******************************************************************************
32299575102SLv Zheng  *
32399575102SLv Zheng  * FUNCTION:    acpi_db_unload_acpi_table
32499575102SLv Zheng  *
32599575102SLv Zheng  * PARAMETERS:  object_name         - Namespace pathname for an object that
32699575102SLv Zheng  *                                    is owned by the table to be unloaded
32799575102SLv Zheng  *
32899575102SLv Zheng  * RETURN:      None
32999575102SLv Zheng  *
33099575102SLv Zheng  * DESCRIPTION: Unload an ACPI table, via any namespace node that is owned
33199575102SLv Zheng  *              by the table.
33299575102SLv Zheng  *
33399575102SLv Zheng  ******************************************************************************/
33499575102SLv Zheng 
acpi_db_unload_acpi_table(char * object_name)33599575102SLv Zheng void acpi_db_unload_acpi_table(char *object_name)
33699575102SLv Zheng {
33799575102SLv Zheng 	struct acpi_namespace_node *node;
33899575102SLv Zheng 	acpi_status status;
33999575102SLv Zheng 
34099575102SLv Zheng 	/* Translate name to an Named object */
34199575102SLv Zheng 
34299575102SLv Zheng 	node = acpi_db_convert_to_node(object_name);
34399575102SLv Zheng 	if (!node) {
34499575102SLv Zheng 		return;
34599575102SLv Zheng 	}
34699575102SLv Zheng 
34799575102SLv Zheng 	status = acpi_unload_parent_table(ACPI_CAST_PTR(acpi_handle, node));
34899575102SLv Zheng 	if (ACPI_SUCCESS(status)) {
34999575102SLv Zheng 		acpi_os_printf("Parent of [%s] (%p) unloaded and uninstalled\n",
35099575102SLv Zheng 			       object_name, node);
35199575102SLv Zheng 	} else {
35299575102SLv Zheng 		acpi_os_printf("%s, while unloading parent table of [%s]\n",
35399575102SLv Zheng 			       acpi_format_exception(status), object_name);
35499575102SLv Zheng 	}
35599575102SLv Zheng }
35699575102SLv Zheng 
35799575102SLv Zheng /*******************************************************************************
35899575102SLv Zheng  *
35999575102SLv Zheng  * FUNCTION:    acpi_db_send_notify
36099575102SLv Zheng  *
36199575102SLv Zheng  * PARAMETERS:  name                - Name of ACPI object where to send notify
36299575102SLv Zheng  *              value               - Value of the notify to send.
36399575102SLv Zheng  *
36499575102SLv Zheng  * RETURN:      None
36599575102SLv Zheng  *
36699575102SLv Zheng  * DESCRIPTION: Send an ACPI notification. The value specified is sent to the
36799575102SLv Zheng  *              named object as an ACPI notify.
36899575102SLv Zheng  *
36999575102SLv Zheng  ******************************************************************************/
37099575102SLv Zheng 
acpi_db_send_notify(char * name,u32 value)37199575102SLv Zheng void acpi_db_send_notify(char *name, u32 value)
37299575102SLv Zheng {
37399575102SLv Zheng 	struct acpi_namespace_node *node;
37499575102SLv Zheng 	acpi_status status;
37599575102SLv Zheng 
37699575102SLv Zheng 	/* Translate name to an Named object */
37799575102SLv Zheng 
37899575102SLv Zheng 	node = acpi_db_convert_to_node(name);
37999575102SLv Zheng 	if (!node) {
38099575102SLv Zheng 		return;
38199575102SLv Zheng 	}
38299575102SLv Zheng 
38399575102SLv Zheng 	/* Dispatch the notify if legal */
38499575102SLv Zheng 
38599575102SLv Zheng 	if (acpi_ev_is_notify_object(node)) {
38699575102SLv Zheng 		status = acpi_ev_queue_notify_request(node, value);
38799575102SLv Zheng 		if (ACPI_FAILURE(status)) {
38899575102SLv Zheng 			acpi_os_printf("Could not queue notify\n");
38999575102SLv Zheng 		}
39099575102SLv Zheng 	} else {
39199575102SLv Zheng 		acpi_os_printf("Named object [%4.4s] Type %s, "
39299575102SLv Zheng 			       "must be Device/Thermal/Processor type\n",
39399575102SLv Zheng 			       acpi_ut_get_node_name(node),
39499575102SLv Zheng 			       acpi_ut_get_type_name(node->type));
39599575102SLv Zheng 	}
39699575102SLv Zheng }
39799575102SLv Zheng 
39899575102SLv Zheng /*******************************************************************************
39999575102SLv Zheng  *
40099575102SLv Zheng  * FUNCTION:    acpi_db_display_interfaces
40199575102SLv Zheng  *
40299575102SLv Zheng  * PARAMETERS:  action_arg          - Null, "install", or "remove"
40399575102SLv Zheng  *              interface_name_arg  - Name for install/remove options
40499575102SLv Zheng  *
40599575102SLv Zheng  * RETURN:      None
40699575102SLv Zheng  *
40799575102SLv Zheng  * DESCRIPTION: Display or modify the global _OSI interface list
40899575102SLv Zheng  *
40999575102SLv Zheng  ******************************************************************************/
41099575102SLv Zheng 
acpi_db_display_interfaces(char * action_arg,char * interface_name_arg)41199575102SLv Zheng void acpi_db_display_interfaces(char *action_arg, char *interface_name_arg)
41299575102SLv Zheng {
41399575102SLv Zheng 	struct acpi_interface_info *next_interface;
41499575102SLv Zheng 	char *sub_string;
41599575102SLv Zheng 	acpi_status status;
41699575102SLv Zheng 
41799575102SLv Zheng 	/* If no arguments, just display current interface list */
41899575102SLv Zheng 
41999575102SLv Zheng 	if (!action_arg) {
42099575102SLv Zheng 		(void)acpi_os_acquire_mutex(acpi_gbl_osi_mutex,
42199575102SLv Zheng 					    ACPI_WAIT_FOREVER);
42299575102SLv Zheng 
42399575102SLv Zheng 		next_interface = acpi_gbl_supported_interfaces;
42499575102SLv Zheng 		while (next_interface) {
42599575102SLv Zheng 			if (!(next_interface->flags & ACPI_OSI_INVALID)) {
42699575102SLv Zheng 				acpi_os_printf("%s\n", next_interface->name);
42799575102SLv Zheng 			}
42899575102SLv Zheng 
42999575102SLv Zheng 			next_interface = next_interface->next;
43099575102SLv Zheng 		}
43199575102SLv Zheng 
43299575102SLv Zheng 		acpi_os_release_mutex(acpi_gbl_osi_mutex);
43399575102SLv Zheng 		return;
43499575102SLv Zheng 	}
43599575102SLv Zheng 
43699575102SLv Zheng 	/* If action_arg exists, so must interface_name_arg */
43799575102SLv Zheng 
43899575102SLv Zheng 	if (!interface_name_arg) {
43999575102SLv Zheng 		acpi_os_printf("Missing Interface Name argument\n");
44099575102SLv Zheng 		return;
44199575102SLv Zheng 	}
44299575102SLv Zheng 
44399575102SLv Zheng 	/* Uppercase the action for match below */
44499575102SLv Zheng 
44599575102SLv Zheng 	acpi_ut_strupr(action_arg);
44699575102SLv Zheng 
44799575102SLv Zheng 	/* install - install an interface */
44899575102SLv Zheng 
44999575102SLv Zheng 	sub_string = strstr("INSTALL", action_arg);
45099575102SLv Zheng 	if (sub_string) {
45199575102SLv Zheng 		status = acpi_install_interface(interface_name_arg);
45299575102SLv Zheng 		if (ACPI_FAILURE(status)) {
45399575102SLv Zheng 			acpi_os_printf("%s, while installing \"%s\"\n",
45499575102SLv Zheng 				       acpi_format_exception(status),
45599575102SLv Zheng 				       interface_name_arg);
45699575102SLv Zheng 		}
45799575102SLv Zheng 		return;
45899575102SLv Zheng 	}
45999575102SLv Zheng 
46099575102SLv Zheng 	/* remove - remove an interface */
46199575102SLv Zheng 
46299575102SLv Zheng 	sub_string = strstr("REMOVE", action_arg);
46399575102SLv Zheng 	if (sub_string) {
46499575102SLv Zheng 		status = acpi_remove_interface(interface_name_arg);
46599575102SLv Zheng 		if (ACPI_FAILURE(status)) {
46699575102SLv Zheng 			acpi_os_printf("%s, while removing \"%s\"\n",
46799575102SLv Zheng 				       acpi_format_exception(status),
46899575102SLv Zheng 				       interface_name_arg);
46999575102SLv Zheng 		}
47099575102SLv Zheng 		return;
47199575102SLv Zheng 	}
47299575102SLv Zheng 
47399575102SLv Zheng 	/* Invalid action_arg */
47499575102SLv Zheng 
47599575102SLv Zheng 	acpi_os_printf("Invalid action argument: %s\n", action_arg);
47699575102SLv Zheng 	return;
47799575102SLv Zheng }
47899575102SLv Zheng 
47999575102SLv Zheng /*******************************************************************************
48099575102SLv Zheng  *
48199575102SLv Zheng  * FUNCTION:    acpi_db_display_template
48299575102SLv Zheng  *
48399575102SLv Zheng  * PARAMETERS:  buffer_arg          - Buffer name or address
48499575102SLv Zheng  *
48599575102SLv Zheng  * RETURN:      None
48699575102SLv Zheng  *
48799575102SLv Zheng  * DESCRIPTION: Dump a buffer that contains a resource template
48899575102SLv Zheng  *
48999575102SLv Zheng  ******************************************************************************/
49099575102SLv Zheng 
acpi_db_display_template(char * buffer_arg)49199575102SLv Zheng void acpi_db_display_template(char *buffer_arg)
49299575102SLv Zheng {
49399575102SLv Zheng 	struct acpi_namespace_node *node;
49499575102SLv Zheng 	acpi_status status;
49599575102SLv Zheng 	struct acpi_buffer return_buffer;
49699575102SLv Zheng 
49799575102SLv Zheng 	/* Translate buffer_arg to an Named object */
49899575102SLv Zheng 
49999575102SLv Zheng 	node = acpi_db_convert_to_node(buffer_arg);
50099575102SLv Zheng 	if (!node || (node == acpi_gbl_root_node)) {
50199575102SLv Zheng 		acpi_os_printf("Invalid argument: %s\n", buffer_arg);
50299575102SLv Zheng 		return;
50399575102SLv Zheng 	}
50499575102SLv Zheng 
50599575102SLv Zheng 	/* We must have a buffer object */
50699575102SLv Zheng 
50799575102SLv Zheng 	if (node->type != ACPI_TYPE_BUFFER) {
50899575102SLv Zheng 		acpi_os_printf
50999575102SLv Zheng 		    ("Not a Buffer object, cannot be a template: %s\n",
51099575102SLv Zheng 		     buffer_arg);
51199575102SLv Zheng 		return;
51299575102SLv Zheng 	}
51399575102SLv Zheng 
51499575102SLv Zheng 	return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
51599575102SLv Zheng 	return_buffer.pointer = acpi_gbl_db_buffer;
51699575102SLv Zheng 
51799575102SLv Zheng 	/* Attempt to convert the raw buffer to a resource list */
51899575102SLv Zheng 
51999575102SLv Zheng 	status = acpi_rs_create_resource_list(node->object, &return_buffer);
52099575102SLv Zheng 
52199575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
52299575102SLv Zheng 	acpi_dbg_level |= ACPI_LV_RESOURCES;
52399575102SLv Zheng 
52499575102SLv Zheng 	if (ACPI_FAILURE(status)) {
52599575102SLv Zheng 		acpi_os_printf
52699575102SLv Zheng 		    ("Could not convert Buffer to a resource list: %s, %s\n",
52799575102SLv Zheng 		     buffer_arg, acpi_format_exception(status));
52899575102SLv Zheng 		goto dump_buffer;
52999575102SLv Zheng 	}
53099575102SLv Zheng 
53199575102SLv Zheng 	/* Now we can dump the resource list */
53299575102SLv Zheng 
53399575102SLv Zheng 	acpi_rs_dump_resource_list(ACPI_CAST_PTR(struct acpi_resource,
53499575102SLv Zheng 						 return_buffer.pointer));
53599575102SLv Zheng 
53699575102SLv Zheng dump_buffer:
53799575102SLv Zheng 	acpi_os_printf("\nRaw data buffer:\n");
53899575102SLv Zheng 	acpi_ut_debug_dump_buffer((u8 *)node->object->buffer.pointer,
53999575102SLv Zheng 				  node->object->buffer.length,
54099575102SLv Zheng 				  DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
54199575102SLv Zheng 
54299575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
54399575102SLv Zheng 	return;
54499575102SLv Zheng }
54599575102SLv Zheng 
54699575102SLv Zheng /*******************************************************************************
54799575102SLv Zheng  *
54899575102SLv Zheng  * FUNCTION:    acpi_dm_compare_aml_resources
54999575102SLv Zheng  *
55099575102SLv Zheng  * PARAMETERS:  aml1_buffer         - Contains first resource list
55199575102SLv Zheng  *              aml1_buffer_length  - Length of first resource list
55299575102SLv Zheng  *              aml2_buffer         - Contains second resource list
55399575102SLv Zheng  *              aml2_buffer_length  - Length of second resource list
55499575102SLv Zheng  *
55599575102SLv Zheng  * RETURN:      None
55699575102SLv Zheng  *
55799575102SLv Zheng  * DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in
55899575102SLv Zheng  *              order to isolate a miscompare to an individual resource)
55999575102SLv Zheng  *
56099575102SLv Zheng  ******************************************************************************/
56199575102SLv Zheng 
56299575102SLv Zheng static void
acpi_dm_compare_aml_resources(u8 * aml1_buffer,acpi_rsdesc_size aml1_buffer_length,u8 * aml2_buffer,acpi_rsdesc_size aml2_buffer_length)56399575102SLv Zheng acpi_dm_compare_aml_resources(u8 *aml1_buffer,
56499575102SLv Zheng 			      acpi_rsdesc_size aml1_buffer_length,
56599575102SLv Zheng 			      u8 *aml2_buffer,
56699575102SLv Zheng 			      acpi_rsdesc_size aml2_buffer_length)
56799575102SLv Zheng {
56899575102SLv Zheng 	u8 *aml1;
56999575102SLv Zheng 	u8 *aml2;
57099575102SLv Zheng 	u8 *aml1_end;
57199575102SLv Zheng 	u8 *aml2_end;
57299575102SLv Zheng 	acpi_rsdesc_size aml1_length;
57399575102SLv Zheng 	acpi_rsdesc_size aml2_length;
57499575102SLv Zheng 	acpi_rsdesc_size offset = 0;
57599575102SLv Zheng 	u8 resource_type;
57699575102SLv Zheng 	u32 count = 0;
57799575102SLv Zheng 	u32 i;
57899575102SLv Zheng 
57999575102SLv Zheng 	/* Compare overall buffer sizes (may be different due to size rounding) */
58099575102SLv Zheng 
58199575102SLv Zheng 	if (aml1_buffer_length != aml2_buffer_length) {
58299575102SLv Zheng 		acpi_os_printf("**** Buffer length mismatch in converted "
58399575102SLv Zheng 			       "AML: Original %X, New %X ****\n",
58499575102SLv Zheng 			       aml1_buffer_length, aml2_buffer_length);
58599575102SLv Zheng 	}
58699575102SLv Zheng 
58799575102SLv Zheng 	aml1 = aml1_buffer;
58899575102SLv Zheng 	aml2 = aml2_buffer;
58999575102SLv Zheng 	aml1_end = aml1_buffer + aml1_buffer_length;
59099575102SLv Zheng 	aml2_end = aml2_buffer + aml2_buffer_length;
59199575102SLv Zheng 
59299575102SLv Zheng 	/* Walk the descriptor lists, comparing each descriptor */
59399575102SLv Zheng 
59499575102SLv Zheng 	while ((aml1 < aml1_end) && (aml2 < aml2_end)) {
59599575102SLv Zheng 
59699575102SLv Zheng 		/* Get the lengths of each descriptor */
59799575102SLv Zheng 
59899575102SLv Zheng 		aml1_length = acpi_ut_get_descriptor_length(aml1);
59999575102SLv Zheng 		aml2_length = acpi_ut_get_descriptor_length(aml2);
60099575102SLv Zheng 		resource_type = acpi_ut_get_resource_type(aml1);
60199575102SLv Zheng 
60299575102SLv Zheng 		/* Check for descriptor length match */
60399575102SLv Zheng 
60499575102SLv Zheng 		if (aml1_length != aml2_length) {
60599575102SLv Zheng 			acpi_os_printf
60699575102SLv Zheng 			    ("**** Length mismatch in descriptor [%.2X] type %2.2X, "
60799575102SLv Zheng 			     "Offset %8.8X Len1 %X, Len2 %X ****\n", count,
60899575102SLv Zheng 			     resource_type, offset, aml1_length, aml2_length);
60999575102SLv Zheng 		}
61099575102SLv Zheng 
61199575102SLv Zheng 		/* Check for descriptor byte match */
61299575102SLv Zheng 
61399575102SLv Zheng 		else if (memcmp(aml1, aml2, aml1_length)) {
61499575102SLv Zheng 			acpi_os_printf
61599575102SLv Zheng 			    ("**** Data mismatch in descriptor [%.2X] type %2.2X, "
61699575102SLv Zheng 			     "Offset %8.8X ****\n", count, resource_type,
61799575102SLv Zheng 			     offset);
61899575102SLv Zheng 
61999575102SLv Zheng 			for (i = 0; i < aml1_length; i++) {
62099575102SLv Zheng 				if (aml1[i] != aml2[i]) {
62199575102SLv Zheng 					acpi_os_printf
62299575102SLv Zheng 					    ("Mismatch at byte offset %.2X: is %2.2X, "
62399575102SLv Zheng 					     "should be %2.2X\n", i, aml2[i],
62499575102SLv Zheng 					     aml1[i]);
62599575102SLv Zheng 				}
62699575102SLv Zheng 			}
62799575102SLv Zheng 		}
62899575102SLv Zheng 
62999575102SLv Zheng 		/* Exit on end_tag descriptor */
63099575102SLv Zheng 
63199575102SLv Zheng 		if (resource_type == ACPI_RESOURCE_NAME_END_TAG) {
63299575102SLv Zheng 			return;
63399575102SLv Zheng 		}
63499575102SLv Zheng 
63599575102SLv Zheng 		/* Point to next descriptor in each buffer */
63699575102SLv Zheng 
63799575102SLv Zheng 		count++;
63899575102SLv Zheng 		offset += aml1_length;
63999575102SLv Zheng 		aml1 += aml1_length;
64099575102SLv Zheng 		aml2 += aml2_length;
64199575102SLv Zheng 	}
64299575102SLv Zheng }
64399575102SLv Zheng 
64499575102SLv Zheng /*******************************************************************************
64599575102SLv Zheng  *
64699575102SLv Zheng  * FUNCTION:    acpi_dm_test_resource_conversion
64799575102SLv Zheng  *
64899575102SLv Zheng  * PARAMETERS:  node                - Parent device node
64999575102SLv Zheng  *              name                - resource method name (_CRS)
65099575102SLv Zheng  *
65199575102SLv Zheng  * RETURN:      Status
65299575102SLv Zheng  *
65399575102SLv Zheng  * DESCRIPTION: Compare the original AML with a conversion of the AML to
65499575102SLv Zheng  *              internal resource list, then back to AML.
65599575102SLv Zheng  *
65699575102SLv Zheng  ******************************************************************************/
65799575102SLv Zheng 
65899575102SLv Zheng static acpi_status
acpi_dm_test_resource_conversion(struct acpi_namespace_node * node,char * name)65999575102SLv Zheng acpi_dm_test_resource_conversion(struct acpi_namespace_node *node, char *name)
66099575102SLv Zheng {
66199575102SLv Zheng 	acpi_status status;
66299575102SLv Zheng 	struct acpi_buffer return_buffer;
66399575102SLv Zheng 	struct acpi_buffer resource_buffer;
66499575102SLv Zheng 	struct acpi_buffer new_aml;
66599575102SLv Zheng 	union acpi_object *original_aml;
66699575102SLv Zheng 
66799575102SLv Zheng 	acpi_os_printf("Resource Conversion Comparison:\n");
66899575102SLv Zheng 
66999575102SLv Zheng 	new_aml.length = ACPI_ALLOCATE_LOCAL_BUFFER;
67099575102SLv Zheng 	return_buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
67199575102SLv Zheng 	resource_buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
67299575102SLv Zheng 
67399575102SLv Zheng 	/* Get the original _CRS AML resource template */
67499575102SLv Zheng 
67599575102SLv Zheng 	status = acpi_evaluate_object(node, name, NULL, &return_buffer);
67699575102SLv Zheng 	if (ACPI_FAILURE(status)) {
67799575102SLv Zheng 		acpi_os_printf("Could not obtain %s: %s\n",
67899575102SLv Zheng 			       name, acpi_format_exception(status));
67999575102SLv Zheng 		return (status);
68099575102SLv Zheng 	}
68199575102SLv Zheng 
68299575102SLv Zheng 	/* Get the AML resource template, converted to internal resource structs */
68399575102SLv Zheng 
68499575102SLv Zheng 	status = acpi_get_current_resources(node, &resource_buffer);
68599575102SLv Zheng 	if (ACPI_FAILURE(status)) {
68699575102SLv Zheng 		acpi_os_printf("AcpiGetCurrentResources failed: %s\n",
68799575102SLv Zheng 			       acpi_format_exception(status));
68899575102SLv Zheng 		goto exit1;
68999575102SLv Zheng 	}
69099575102SLv Zheng 
69199575102SLv Zheng 	/* Convert internal resource list to external AML resource template */
69299575102SLv Zheng 
69399575102SLv Zheng 	status = acpi_rs_create_aml_resources(&resource_buffer, &new_aml);
69499575102SLv Zheng 	if (ACPI_FAILURE(status)) {
69599575102SLv Zheng 		acpi_os_printf("AcpiRsCreateAmlResources failed: %s\n",
69699575102SLv Zheng 			       acpi_format_exception(status));
69799575102SLv Zheng 		goto exit2;
69899575102SLv Zheng 	}
69999575102SLv Zheng 
70099575102SLv Zheng 	/* Compare original AML to the newly created AML resource list */
70199575102SLv Zheng 
70299575102SLv Zheng 	original_aml = return_buffer.pointer;
70399575102SLv Zheng 
70499575102SLv Zheng 	acpi_dm_compare_aml_resources(original_aml->buffer.pointer,
70599575102SLv Zheng 				      (acpi_rsdesc_size)original_aml->buffer.
70699575102SLv Zheng 				      length, new_aml.pointer,
70799575102SLv Zheng 				      (acpi_rsdesc_size)new_aml.length);
70899575102SLv Zheng 
70999575102SLv Zheng 	/* Cleanup and exit */
71099575102SLv Zheng 
71199575102SLv Zheng 	ACPI_FREE(new_aml.pointer);
71299575102SLv Zheng exit2:
71399575102SLv Zheng 	ACPI_FREE(resource_buffer.pointer);
71499575102SLv Zheng exit1:
71599575102SLv Zheng 	ACPI_FREE(return_buffer.pointer);
71699575102SLv Zheng 	return (status);
71799575102SLv Zheng }
71899575102SLv Zheng 
71999575102SLv Zheng /*******************************************************************************
72099575102SLv Zheng  *
72199575102SLv Zheng  * FUNCTION:    acpi_db_resource_callback
72299575102SLv Zheng  *
72399575102SLv Zheng  * PARAMETERS:  acpi_walk_resource_callback
72499575102SLv Zheng  *
72599575102SLv Zheng  * RETURN:      Status
72699575102SLv Zheng  *
72799575102SLv Zheng  * DESCRIPTION: Simple callback to exercise acpi_walk_resources and
72899575102SLv Zheng  *              acpi_walk_resource_buffer.
72999575102SLv Zheng  *
73099575102SLv Zheng  ******************************************************************************/
73199575102SLv Zheng 
73299575102SLv Zheng static acpi_status
acpi_db_resource_callback(struct acpi_resource * resource,void * context)73399575102SLv Zheng acpi_db_resource_callback(struct acpi_resource *resource, void *context)
73499575102SLv Zheng {
73599575102SLv Zheng 
73699575102SLv Zheng 	return (AE_OK);
73799575102SLv Zheng }
73899575102SLv Zheng 
73999575102SLv Zheng /*******************************************************************************
74099575102SLv Zheng  *
74199575102SLv Zheng  * FUNCTION:    acpi_db_device_resources
74299575102SLv Zheng  *
74399575102SLv Zheng  * PARAMETERS:  acpi_walk_callback
74499575102SLv Zheng  *
74599575102SLv Zheng  * RETURN:      Status
74699575102SLv Zheng  *
74799575102SLv Zheng  * DESCRIPTION: Display the _PRT/_CRS/_PRS resources for a device object.
74899575102SLv Zheng  *
74999575102SLv Zheng  ******************************************************************************/
75099575102SLv Zheng 
75199575102SLv Zheng static acpi_status
acpi_db_device_resources(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)75299575102SLv Zheng acpi_db_device_resources(acpi_handle obj_handle,
75399575102SLv Zheng 			 u32 nesting_level, void *context, void **return_value)
75499575102SLv Zheng {
75599575102SLv Zheng 	struct acpi_namespace_node *node;
75699575102SLv Zheng 	struct acpi_namespace_node *prt_node = NULL;
75799575102SLv Zheng 	struct acpi_namespace_node *crs_node = NULL;
75899575102SLv Zheng 	struct acpi_namespace_node *prs_node = NULL;
75999575102SLv Zheng 	struct acpi_namespace_node *aei_node = NULL;
76099575102SLv Zheng 	char *parent_path;
76199575102SLv Zheng 	struct acpi_buffer return_buffer;
76299575102SLv Zheng 	acpi_status status;
76399575102SLv Zheng 
76499575102SLv Zheng 	node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
7650e166e4fSLv Zheng 	parent_path = acpi_ns_get_normalized_pathname(node, TRUE);
76699575102SLv Zheng 	if (!parent_path) {
76799575102SLv Zheng 		return (AE_NO_MEMORY);
76899575102SLv Zheng 	}
76999575102SLv Zheng 
77099575102SLv Zheng 	/* Get handles to the resource methods for this device */
77199575102SLv Zheng 
77299575102SLv Zheng 	(void)acpi_get_handle(node, METHOD_NAME__PRT,
77399575102SLv Zheng 			      ACPI_CAST_PTR(acpi_handle, &prt_node));
77499575102SLv Zheng 	(void)acpi_get_handle(node, METHOD_NAME__CRS,
77599575102SLv Zheng 			      ACPI_CAST_PTR(acpi_handle, &crs_node));
77699575102SLv Zheng 	(void)acpi_get_handle(node, METHOD_NAME__PRS,
77799575102SLv Zheng 			      ACPI_CAST_PTR(acpi_handle, &prs_node));
77899575102SLv Zheng 	(void)acpi_get_handle(node, METHOD_NAME__AEI,
77999575102SLv Zheng 			      ACPI_CAST_PTR(acpi_handle, &aei_node));
78099575102SLv Zheng 
78199575102SLv Zheng 	if (!prt_node && !crs_node && !prs_node && !aei_node) {
78299575102SLv Zheng 		goto cleanup;	/* Nothing to do */
78399575102SLv Zheng 	}
78499575102SLv Zheng 
78599575102SLv Zheng 	acpi_os_printf("\nDevice: %s\n", parent_path);
78699575102SLv Zheng 
78799575102SLv Zheng 	/* Prepare for a return object of arbitrary size */
78899575102SLv Zheng 
78999575102SLv Zheng 	return_buffer.pointer = acpi_gbl_db_buffer;
79099575102SLv Zheng 	return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
79199575102SLv Zheng 
79299575102SLv Zheng 	/* _PRT */
79399575102SLv Zheng 
79499575102SLv Zheng 	if (prt_node) {
79599575102SLv Zheng 		acpi_os_printf("Evaluating _PRT\n");
79699575102SLv Zheng 
79799575102SLv Zheng 		status =
79899575102SLv Zheng 		    acpi_evaluate_object(prt_node, NULL, NULL, &return_buffer);
79999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
80099575102SLv Zheng 			acpi_os_printf("Could not evaluate _PRT: %s\n",
80199575102SLv Zheng 				       acpi_format_exception(status));
80299575102SLv Zheng 			goto get_crs;
80399575102SLv Zheng 		}
80499575102SLv Zheng 
80599575102SLv Zheng 		return_buffer.pointer = acpi_gbl_db_buffer;
80699575102SLv Zheng 		return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
80799575102SLv Zheng 
80899575102SLv Zheng 		status = acpi_get_irq_routing_table(node, &return_buffer);
80999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
81099575102SLv Zheng 			acpi_os_printf("GetIrqRoutingTable failed: %s\n",
81199575102SLv Zheng 				       acpi_format_exception(status));
81299575102SLv Zheng 			goto get_crs;
81399575102SLv Zheng 		}
81499575102SLv Zheng 
81599575102SLv Zheng 		acpi_rs_dump_irq_list(ACPI_CAST_PTR(u8, acpi_gbl_db_buffer));
81699575102SLv Zheng 	}
81799575102SLv Zheng 
81899575102SLv Zheng 	/* _CRS */
81999575102SLv Zheng 
82099575102SLv Zheng get_crs:
82199575102SLv Zheng 	if (crs_node) {
82299575102SLv Zheng 		acpi_os_printf("Evaluating _CRS\n");
82399575102SLv Zheng 
82499575102SLv Zheng 		return_buffer.pointer = acpi_gbl_db_buffer;
82599575102SLv Zheng 		return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
82699575102SLv Zheng 
82799575102SLv Zheng 		status =
82899575102SLv Zheng 		    acpi_evaluate_object(crs_node, NULL, NULL, &return_buffer);
82999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
83099575102SLv Zheng 			acpi_os_printf("Could not evaluate _CRS: %s\n",
83199575102SLv Zheng 				       acpi_format_exception(status));
83299575102SLv Zheng 			goto get_prs;
83399575102SLv Zheng 		}
83499575102SLv Zheng 
83599575102SLv Zheng 		/* This code exercises the acpi_walk_resources interface */
83699575102SLv Zheng 
83799575102SLv Zheng 		status = acpi_walk_resources(node, METHOD_NAME__CRS,
83899575102SLv Zheng 					     acpi_db_resource_callback, NULL);
83999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
84099575102SLv Zheng 			acpi_os_printf("AcpiWalkResources failed: %s\n",
84199575102SLv Zheng 				       acpi_format_exception(status));
84299575102SLv Zheng 			goto get_prs;
84399575102SLv Zheng 		}
84499575102SLv Zheng 
84599575102SLv Zheng 		/* Get the _CRS resource list (test ALLOCATE buffer) */
84699575102SLv Zheng 
84799575102SLv Zheng 		return_buffer.pointer = NULL;
84899575102SLv Zheng 		return_buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
84999575102SLv Zheng 
85099575102SLv Zheng 		status = acpi_get_current_resources(node, &return_buffer);
85199575102SLv Zheng 		if (ACPI_FAILURE(status)) {
85299575102SLv Zheng 			acpi_os_printf("AcpiGetCurrentResources failed: %s\n",
85399575102SLv Zheng 				       acpi_format_exception(status));
85499575102SLv Zheng 			goto get_prs;
85599575102SLv Zheng 		}
85699575102SLv Zheng 
85799575102SLv Zheng 		/* This code exercises the acpi_walk_resource_buffer interface */
85899575102SLv Zheng 
85999575102SLv Zheng 		status = acpi_walk_resource_buffer(&return_buffer,
86099575102SLv Zheng 						   acpi_db_resource_callback,
86199575102SLv Zheng 						   NULL);
86299575102SLv Zheng 		if (ACPI_FAILURE(status)) {
86399575102SLv Zheng 			acpi_os_printf("AcpiWalkResourceBuffer failed: %s\n",
86499575102SLv Zheng 				       acpi_format_exception(status));
86599575102SLv Zheng 			goto end_crs;
86699575102SLv Zheng 		}
86799575102SLv Zheng 
86899575102SLv Zheng 		/* Dump the _CRS resource list */
86999575102SLv Zheng 
87099575102SLv Zheng 		acpi_rs_dump_resource_list(ACPI_CAST_PTR(struct acpi_resource,
87199575102SLv Zheng 							 return_buffer.
87299575102SLv Zheng 							 pointer));
87399575102SLv Zheng 
87499575102SLv Zheng 		/*
87599575102SLv Zheng 		 * Perform comparison of original AML to newly created AML. This
87699575102SLv Zheng 		 * tests both the AML->Resource conversion and the Resource->AML
87799575102SLv Zheng 		 * conversion.
87899575102SLv Zheng 		 */
87999575102SLv Zheng 		(void)acpi_dm_test_resource_conversion(node, METHOD_NAME__CRS);
88099575102SLv Zheng 
88199575102SLv Zheng 		/* Execute _SRS with the resource list */
88299575102SLv Zheng 
88399575102SLv Zheng 		acpi_os_printf("Evaluating _SRS\n");
88499575102SLv Zheng 
88599575102SLv Zheng 		status = acpi_set_current_resources(node, &return_buffer);
88699575102SLv Zheng 		if (ACPI_FAILURE(status)) {
88799575102SLv Zheng 			acpi_os_printf("AcpiSetCurrentResources failed: %s\n",
88899575102SLv Zheng 				       acpi_format_exception(status));
88999575102SLv Zheng 			goto end_crs;
89099575102SLv Zheng 		}
89199575102SLv Zheng 
89299575102SLv Zheng end_crs:
89399575102SLv Zheng 		ACPI_FREE(return_buffer.pointer);
89499575102SLv Zheng 	}
89599575102SLv Zheng 
89699575102SLv Zheng 	/* _PRS */
89799575102SLv Zheng 
89899575102SLv Zheng get_prs:
89999575102SLv Zheng 	if (prs_node) {
90099575102SLv Zheng 		acpi_os_printf("Evaluating _PRS\n");
90199575102SLv Zheng 
90299575102SLv Zheng 		return_buffer.pointer = acpi_gbl_db_buffer;
90399575102SLv Zheng 		return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
90499575102SLv Zheng 
90599575102SLv Zheng 		status =
90699575102SLv Zheng 		    acpi_evaluate_object(prs_node, NULL, NULL, &return_buffer);
90799575102SLv Zheng 		if (ACPI_FAILURE(status)) {
90899575102SLv Zheng 			acpi_os_printf("Could not evaluate _PRS: %s\n",
90999575102SLv Zheng 				       acpi_format_exception(status));
91099575102SLv Zheng 			goto get_aei;
91199575102SLv Zheng 		}
91299575102SLv Zheng 
91399575102SLv Zheng 		return_buffer.pointer = acpi_gbl_db_buffer;
91499575102SLv Zheng 		return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
91599575102SLv Zheng 
91699575102SLv Zheng 		status = acpi_get_possible_resources(node, &return_buffer);
91799575102SLv Zheng 		if (ACPI_FAILURE(status)) {
91899575102SLv Zheng 			acpi_os_printf("AcpiGetPossibleResources failed: %s\n",
91999575102SLv Zheng 				       acpi_format_exception(status));
92099575102SLv Zheng 			goto get_aei;
92199575102SLv Zheng 		}
92299575102SLv Zheng 
92399575102SLv Zheng 		acpi_rs_dump_resource_list(ACPI_CAST_PTR
92499575102SLv Zheng 					   (struct acpi_resource,
92599575102SLv Zheng 					    acpi_gbl_db_buffer));
92699575102SLv Zheng 	}
92799575102SLv Zheng 
92899575102SLv Zheng 	/* _AEI */
92999575102SLv Zheng 
93099575102SLv Zheng get_aei:
93199575102SLv Zheng 	if (aei_node) {
93299575102SLv Zheng 		acpi_os_printf("Evaluating _AEI\n");
93399575102SLv Zheng 
93499575102SLv Zheng 		return_buffer.pointer = acpi_gbl_db_buffer;
93599575102SLv Zheng 		return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
93699575102SLv Zheng 
93799575102SLv Zheng 		status =
93899575102SLv Zheng 		    acpi_evaluate_object(aei_node, NULL, NULL, &return_buffer);
93999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
94099575102SLv Zheng 			acpi_os_printf("Could not evaluate _AEI: %s\n",
94199575102SLv Zheng 				       acpi_format_exception(status));
94299575102SLv Zheng 			goto cleanup;
94399575102SLv Zheng 		}
94499575102SLv Zheng 
94599575102SLv Zheng 		return_buffer.pointer = acpi_gbl_db_buffer;
94699575102SLv Zheng 		return_buffer.length = ACPI_DEBUG_BUFFER_SIZE;
94799575102SLv Zheng 
94899575102SLv Zheng 		status = acpi_get_event_resources(node, &return_buffer);
94999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
95099575102SLv Zheng 			acpi_os_printf("AcpiGetEventResources failed: %s\n",
95199575102SLv Zheng 				       acpi_format_exception(status));
95299575102SLv Zheng 			goto cleanup;
95399575102SLv Zheng 		}
95499575102SLv Zheng 
95599575102SLv Zheng 		acpi_rs_dump_resource_list(ACPI_CAST_PTR
95699575102SLv Zheng 					   (struct acpi_resource,
95799575102SLv Zheng 					    acpi_gbl_db_buffer));
95899575102SLv Zheng 	}
95999575102SLv Zheng 
96099575102SLv Zheng cleanup:
96199575102SLv Zheng 	ACPI_FREE(parent_path);
96299575102SLv Zheng 	return (AE_OK);
96399575102SLv Zheng }
96499575102SLv Zheng 
96599575102SLv Zheng /*******************************************************************************
96699575102SLv Zheng  *
96799575102SLv Zheng  * FUNCTION:    acpi_db_display_resources
96899575102SLv Zheng  *
96999575102SLv Zheng  * PARAMETERS:  object_arg          - String object name or object pointer.
97099575102SLv Zheng  *                                    NULL or "*" means "display resources for
97199575102SLv Zheng  *                                    all devices"
97299575102SLv Zheng  *
97399575102SLv Zheng  * RETURN:      None
97499575102SLv Zheng  *
97599575102SLv Zheng  * DESCRIPTION: Display the resource objects associated with a device.
97699575102SLv Zheng  *
97799575102SLv Zheng  ******************************************************************************/
97899575102SLv Zheng 
acpi_db_display_resources(char * object_arg)97999575102SLv Zheng void acpi_db_display_resources(char *object_arg)
98099575102SLv Zheng {
98199575102SLv Zheng 	struct acpi_namespace_node *node;
98299575102SLv Zheng 
98399575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
98499575102SLv Zheng 	acpi_dbg_level |= ACPI_LV_RESOURCES;
98599575102SLv Zheng 
98699575102SLv Zheng 	/* Asterisk means "display resources for all devices" */
98799575102SLv Zheng 
98899575102SLv Zheng 	if (!object_arg || (!strcmp(object_arg, "*"))) {
98999575102SLv Zheng 		(void)acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
99099575102SLv Zheng 					  ACPI_UINT32_MAX,
99199575102SLv Zheng 					  acpi_db_device_resources, NULL, NULL,
99299575102SLv Zheng 					  NULL);
99399575102SLv Zheng 	} else {
99499575102SLv Zheng 		/* Convert string to object pointer */
99599575102SLv Zheng 
99699575102SLv Zheng 		node = acpi_db_convert_to_node(object_arg);
99799575102SLv Zheng 		if (node) {
99899575102SLv Zheng 			if (node->type != ACPI_TYPE_DEVICE) {
99999575102SLv Zheng 				acpi_os_printf
100099575102SLv Zheng 				    ("%4.4s: Name is not a device object (%s)\n",
100199575102SLv Zheng 				     node->name.ascii,
100299575102SLv Zheng 				     acpi_ut_get_type_name(node->type));
100399575102SLv Zheng 			} else {
100499575102SLv Zheng 				(void)acpi_db_device_resources(node, 0, NULL,
100599575102SLv Zheng 							       NULL);
100699575102SLv Zheng 			}
100799575102SLv Zheng 		}
100899575102SLv Zheng 	}
100999575102SLv Zheng 
101099575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
101199575102SLv Zheng }
101299575102SLv Zheng 
1013*b0f2e7d7SJose Marinho /*******************************************************************************
1014*b0f2e7d7SJose Marinho  *
1015*b0f2e7d7SJose Marinho  * FUNCTION:    acpi_db_generate_ged
1016*b0f2e7d7SJose Marinho  *
1017*b0f2e7d7SJose Marinho  * PARAMETERS:  ged_arg             - Raw GED number, ascii string
1018*b0f2e7d7SJose Marinho  *
1019*b0f2e7d7SJose Marinho  * RETURN:      None
1020*b0f2e7d7SJose Marinho  *
1021*b0f2e7d7SJose Marinho  * DESCRIPTION: Simulate firing of a GED
1022*b0f2e7d7SJose Marinho  *
1023*b0f2e7d7SJose Marinho  ******************************************************************************/
1024*b0f2e7d7SJose Marinho 
acpi_db_generate_interrupt(char * gsiv_arg)1025*b0f2e7d7SJose Marinho void acpi_db_generate_interrupt(char *gsiv_arg)
1026*b0f2e7d7SJose Marinho {
1027*b0f2e7d7SJose Marinho 	u32 gsiv_number;
1028*b0f2e7d7SJose Marinho 	struct acpi_ged_handler_info *ged_info = acpi_gbl_ged_handler_list;
1029*b0f2e7d7SJose Marinho 
1030*b0f2e7d7SJose Marinho 	if (!ged_info) {
1031*b0f2e7d7SJose Marinho 		acpi_os_printf("No GED handling present\n");
1032*b0f2e7d7SJose Marinho 	}
1033*b0f2e7d7SJose Marinho 
1034*b0f2e7d7SJose Marinho 	gsiv_number = strtoul(gsiv_arg, NULL, 0);
1035*b0f2e7d7SJose Marinho 
1036*b0f2e7d7SJose Marinho 	while (ged_info) {
1037*b0f2e7d7SJose Marinho 
1038*b0f2e7d7SJose Marinho 		if (ged_info->int_id == gsiv_number) {
1039*b0f2e7d7SJose Marinho 			struct acpi_object_list arg_list;
1040*b0f2e7d7SJose Marinho 			union acpi_object arg0;
1041*b0f2e7d7SJose Marinho 			acpi_handle evt_handle = ged_info->evt_method;
1042*b0f2e7d7SJose Marinho 			acpi_status status;
1043*b0f2e7d7SJose Marinho 
1044*b0f2e7d7SJose Marinho 			acpi_os_printf("Evaluate GED _EVT (GSIV=%d)\n",
1045*b0f2e7d7SJose Marinho 				       gsiv_number);
1046*b0f2e7d7SJose Marinho 
1047*b0f2e7d7SJose Marinho 			if (!evt_handle) {
1048*b0f2e7d7SJose Marinho 				acpi_os_printf("Undefined _EVT method\n");
1049*b0f2e7d7SJose Marinho 				return;
1050*b0f2e7d7SJose Marinho 			}
1051*b0f2e7d7SJose Marinho 
1052*b0f2e7d7SJose Marinho 			arg0.integer.type = ACPI_TYPE_INTEGER;
1053*b0f2e7d7SJose Marinho 			arg0.integer.value = gsiv_number;
1054*b0f2e7d7SJose Marinho 
1055*b0f2e7d7SJose Marinho 			arg_list.count = 1;
1056*b0f2e7d7SJose Marinho 			arg_list.pointer = &arg0;
1057*b0f2e7d7SJose Marinho 
1058*b0f2e7d7SJose Marinho 			status =
1059*b0f2e7d7SJose Marinho 			    acpi_evaluate_object(evt_handle, NULL, &arg_list,
1060*b0f2e7d7SJose Marinho 						 NULL);
1061*b0f2e7d7SJose Marinho 			if (ACPI_FAILURE(status)) {
1062*b0f2e7d7SJose Marinho 				acpi_os_printf("Could not evaluate _EVT\n");
1063*b0f2e7d7SJose Marinho 				return;
1064*b0f2e7d7SJose Marinho 			}
1065*b0f2e7d7SJose Marinho 
1066*b0f2e7d7SJose Marinho 		}
1067*b0f2e7d7SJose Marinho 		ged_info = ged_info->next;
1068*b0f2e7d7SJose Marinho 	}
1069*b0f2e7d7SJose Marinho }
1070*b0f2e7d7SJose Marinho 
107199575102SLv Zheng #if (!ACPI_REDUCED_HARDWARE)
107299575102SLv Zheng /*******************************************************************************
107399575102SLv Zheng  *
107499575102SLv Zheng  * FUNCTION:    acpi_db_generate_gpe
107599575102SLv Zheng  *
107699575102SLv Zheng  * PARAMETERS:  gpe_arg             - Raw GPE number, ascii string
107799575102SLv Zheng  *              block_arg           - GPE block number, ascii string
107899575102SLv Zheng  *                                    0 or 1 for FADT GPE blocks
107999575102SLv Zheng  *
108099575102SLv Zheng  * RETURN:      None
108199575102SLv Zheng  *
108299575102SLv Zheng  * DESCRIPTION: Simulate firing of a GPE
108399575102SLv Zheng  *
108499575102SLv Zheng  ******************************************************************************/
108599575102SLv Zheng 
acpi_db_generate_gpe(char * gpe_arg,char * block_arg)108699575102SLv Zheng void acpi_db_generate_gpe(char *gpe_arg, char *block_arg)
108799575102SLv Zheng {
108899575102SLv Zheng 	u32 block_number = 0;
108999575102SLv Zheng 	u32 gpe_number;
109099575102SLv Zheng 	struct acpi_gpe_event_info *gpe_event_info;
109199575102SLv Zheng 
109299575102SLv Zheng 	gpe_number = strtoul(gpe_arg, NULL, 0);
109399575102SLv Zheng 
109499575102SLv Zheng 	/*
109599575102SLv Zheng 	 * If no block arg, or block arg == 0 or 1, use the FADT-defined
109699575102SLv Zheng 	 * GPE blocks.
109799575102SLv Zheng 	 */
109899575102SLv Zheng 	if (block_arg) {
109999575102SLv Zheng 		block_number = strtoul(block_arg, NULL, 0);
110099575102SLv Zheng 		if (block_number == 1) {
110199575102SLv Zheng 			block_number = 0;
110299575102SLv Zheng 		}
110399575102SLv Zheng 	}
110499575102SLv Zheng 
110599575102SLv Zheng 	gpe_event_info =
110699575102SLv Zheng 	    acpi_ev_get_gpe_event_info(ACPI_TO_POINTER(block_number),
110799575102SLv Zheng 				       gpe_number);
110899575102SLv Zheng 	if (!gpe_event_info) {
110999575102SLv Zheng 		acpi_os_printf("Invalid GPE\n");
111099575102SLv Zheng 		return;
111199575102SLv Zheng 	}
111299575102SLv Zheng 
111399575102SLv Zheng 	(void)acpi_ev_gpe_dispatch(NULL, gpe_event_info, gpe_number);
111499575102SLv Zheng }
111599575102SLv Zheng 
111699575102SLv Zheng /*******************************************************************************
111799575102SLv Zheng  *
111899575102SLv Zheng  * FUNCTION:    acpi_db_generate_sci
111999575102SLv Zheng  *
112099575102SLv Zheng  * PARAMETERS:  None
112199575102SLv Zheng  *
112299575102SLv Zheng  * RETURN:      None
112399575102SLv Zheng  *
112499575102SLv Zheng  * DESCRIPTION: Simulate an SCI -- just call the SCI dispatch.
112599575102SLv Zheng  *
112699575102SLv Zheng  ******************************************************************************/
112799575102SLv Zheng 
acpi_db_generate_sci(void)112899575102SLv Zheng void acpi_db_generate_sci(void)
112999575102SLv Zheng {
113099575102SLv Zheng 	acpi_ev_sci_dispatch();
113199575102SLv Zheng }
113299575102SLv Zheng 
113399575102SLv Zheng #endif				/* !ACPI_REDUCED_HARDWARE */
113499575102SLv Zheng 
113599575102SLv Zheng /*******************************************************************************
113699575102SLv Zheng  *
113799575102SLv Zheng  * FUNCTION:    acpi_db_trace
113899575102SLv Zheng  *
113999575102SLv Zheng  * PARAMETERS:  enable_arg          - ENABLE/AML to enable tracer
114099575102SLv Zheng  *                                    DISABLE to disable tracer
114199575102SLv Zheng  *              method_arg          - Method to trace
114299575102SLv Zheng  *              once_arg            - Whether trace once
114399575102SLv Zheng  *
114499575102SLv Zheng  * RETURN:      None
114599575102SLv Zheng  *
114699575102SLv Zheng  * DESCRIPTION: Control method tracing facility
114799575102SLv Zheng  *
114899575102SLv Zheng  ******************************************************************************/
114999575102SLv Zheng 
acpi_db_trace(char * enable_arg,char * method_arg,char * once_arg)115099575102SLv Zheng void acpi_db_trace(char *enable_arg, char *method_arg, char *once_arg)
115199575102SLv Zheng {
115299575102SLv Zheng 	u32 debug_level = 0;
115399575102SLv Zheng 	u32 debug_layer = 0;
115499575102SLv Zheng 	u32 flags = 0;
115599575102SLv Zheng 
115699575102SLv Zheng 	acpi_ut_strupr(enable_arg);
115799575102SLv Zheng 	acpi_ut_strupr(once_arg);
115899575102SLv Zheng 
115999575102SLv Zheng 	if (method_arg) {
116099575102SLv Zheng 		if (acpi_db_trace_method_name) {
116199575102SLv Zheng 			ACPI_FREE(acpi_db_trace_method_name);
116299575102SLv Zheng 			acpi_db_trace_method_name = NULL;
116399575102SLv Zheng 		}
116499575102SLv Zheng 
116599575102SLv Zheng 		acpi_db_trace_method_name =
116699575102SLv Zheng 		    ACPI_ALLOCATE(strlen(method_arg) + 1);
116799575102SLv Zheng 		if (!acpi_db_trace_method_name) {
116899575102SLv Zheng 			acpi_os_printf("Failed to allocate method name (%s)\n",
116999575102SLv Zheng 				       method_arg);
117099575102SLv Zheng 			return;
117199575102SLv Zheng 		}
117299575102SLv Zheng 
117399575102SLv Zheng 		strcpy(acpi_db_trace_method_name, method_arg);
117499575102SLv Zheng 	}
117599575102SLv Zheng 
117699575102SLv Zheng 	if (!strcmp(enable_arg, "ENABLE") ||
117799575102SLv Zheng 	    !strcmp(enable_arg, "METHOD") || !strcmp(enable_arg, "OPCODE")) {
117899575102SLv Zheng 		if (!strcmp(enable_arg, "ENABLE")) {
117999575102SLv Zheng 
118099575102SLv Zheng 			/* Inherit current console settings */
118199575102SLv Zheng 
118299575102SLv Zheng 			debug_level = acpi_gbl_db_console_debug_level;
118399575102SLv Zheng 			debug_layer = acpi_dbg_layer;
118499575102SLv Zheng 		} else {
118599575102SLv Zheng 			/* Restrict console output to trace points only */
118699575102SLv Zheng 
118799575102SLv Zheng 			debug_level = ACPI_LV_TRACE_POINT;
118899575102SLv Zheng 			debug_layer = ACPI_EXECUTER;
118999575102SLv Zheng 		}
119099575102SLv Zheng 
119199575102SLv Zheng 		flags = ACPI_TRACE_ENABLED;
119299575102SLv Zheng 
119399575102SLv Zheng 		if (!strcmp(enable_arg, "OPCODE")) {
119499575102SLv Zheng 			flags |= ACPI_TRACE_OPCODE;
119599575102SLv Zheng 		}
119699575102SLv Zheng 
119799575102SLv Zheng 		if (once_arg && !strcmp(once_arg, "ONCE")) {
119899575102SLv Zheng 			flags |= ACPI_TRACE_ONESHOT;
119999575102SLv Zheng 		}
120099575102SLv Zheng 	}
120199575102SLv Zheng 
120299575102SLv Zheng 	(void)acpi_debug_trace(acpi_db_trace_method_name,
120399575102SLv Zheng 			       debug_level, debug_layer, flags);
120499575102SLv Zheng }
1205