xref: /linux/drivers/acpi/acpica/dbnames.c (revision c95baf12f5077419db01313ab61c2aac007d40cd)
195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
299575102SLv Zheng /*******************************************************************************
399575102SLv Zheng  *
499575102SLv Zheng  * Module Name: dbnames - Debugger commands for the acpi namespace
599575102SLv Zheng  *
699575102SLv Zheng  ******************************************************************************/
799575102SLv Zheng 
899575102SLv Zheng #include <acpi/acpi.h>
999575102SLv Zheng #include "accommon.h"
1099575102SLv Zheng #include "acnamesp.h"
1199575102SLv Zheng #include "acdebug.h"
1299575102SLv Zheng #include "acpredef.h"
135fd03328SErik Schmauss #include "acinterp.h"
1499575102SLv Zheng 
1599575102SLv Zheng #define _COMPONENT          ACPI_CA_DEBUGGER
1699575102SLv Zheng ACPI_MODULE_NAME("dbnames")
1799575102SLv Zheng 
1899575102SLv Zheng /* Local prototypes */
1999575102SLv Zheng static acpi_status
2099575102SLv Zheng acpi_db_walk_and_match_name(acpi_handle obj_handle,
2199575102SLv Zheng 			    u32 nesting_level,
2299575102SLv Zheng 			    void *context, void **return_value);
2399575102SLv Zheng 
2499575102SLv Zheng static acpi_status
2599575102SLv Zheng acpi_db_walk_for_predefined_names(acpi_handle obj_handle,
2699575102SLv Zheng 				  u32 nesting_level,
2799575102SLv Zheng 				  void *context, void **return_value);
2899575102SLv Zheng 
2999575102SLv Zheng static acpi_status
3099575102SLv Zheng acpi_db_walk_for_specific_objects(acpi_handle obj_handle,
3199575102SLv Zheng 				  u32 nesting_level,
3299575102SLv Zheng 				  void *context, void **return_value);
3399575102SLv Zheng 
3499575102SLv Zheng static acpi_status
3599575102SLv Zheng acpi_db_walk_for_object_counts(acpi_handle obj_handle,
3699575102SLv Zheng 			       u32 nesting_level,
3799575102SLv Zheng 			       void *context, void **return_value);
3899575102SLv Zheng 
3999575102SLv Zheng static acpi_status
4099575102SLv Zheng acpi_db_integrity_walk(acpi_handle obj_handle,
4199575102SLv Zheng 		       u32 nesting_level, void *context, void **return_value);
4299575102SLv Zheng 
4399575102SLv Zheng static acpi_status
4499575102SLv Zheng acpi_db_walk_for_references(acpi_handle obj_handle,
4599575102SLv Zheng 			    u32 nesting_level,
4699575102SLv Zheng 			    void *context, void **return_value);
4799575102SLv Zheng 
4899575102SLv Zheng static acpi_status
4999575102SLv Zheng acpi_db_bus_walk(acpi_handle obj_handle,
5099575102SLv Zheng 		 u32 nesting_level, void *context, void **return_value);
5199575102SLv Zheng 
5299575102SLv Zheng /*
5399575102SLv Zheng  * Arguments for the Objects command
5499575102SLv Zheng  * These object types map directly to the ACPI_TYPES
5599575102SLv Zheng  */
5699575102SLv Zheng static struct acpi_db_argument_info acpi_db_object_types[] = {
5799575102SLv Zheng 	{"ANY"},
5899575102SLv Zheng 	{"INTEGERS"},
5999575102SLv Zheng 	{"STRINGS"},
6099575102SLv Zheng 	{"BUFFERS"},
6199575102SLv Zheng 	{"PACKAGES"},
6299575102SLv Zheng 	{"FIELDS"},
6399575102SLv Zheng 	{"DEVICES"},
6499575102SLv Zheng 	{"EVENTS"},
6599575102SLv Zheng 	{"METHODS"},
6699575102SLv Zheng 	{"MUTEXES"},
6799575102SLv Zheng 	{"REGIONS"},
6899575102SLv Zheng 	{"POWERRESOURCES"},
6999575102SLv Zheng 	{"PROCESSORS"},
7099575102SLv Zheng 	{"THERMALZONES"},
7199575102SLv Zheng 	{"BUFFERFIELDS"},
7299575102SLv Zheng 	{"DDBHANDLES"},
7399575102SLv Zheng 	{"DEBUG"},
7499575102SLv Zheng 	{"REGIONFIELDS"},
7599575102SLv Zheng 	{"BANKFIELDS"},
7699575102SLv Zheng 	{"INDEXFIELDS"},
7799575102SLv Zheng 	{"REFERENCES"},
7899575102SLv Zheng 	{"ALIASES"},
7999575102SLv Zheng 	{"METHODALIASES"},
8099575102SLv Zheng 	{"NOTIFY"},
8199575102SLv Zheng 	{"ADDRESSHANDLER"},
8299575102SLv Zheng 	{"RESOURCE"},
8399575102SLv Zheng 	{"RESOURCEFIELD"},
8499575102SLv Zheng 	{"SCOPES"},
8599575102SLv Zheng 	{NULL}			/* Must be null terminated */
8699575102SLv Zheng };
8799575102SLv Zheng 
8899575102SLv Zheng /*******************************************************************************
8999575102SLv Zheng  *
9099575102SLv Zheng  * FUNCTION:    acpi_db_set_scope
9199575102SLv Zheng  *
9299575102SLv Zheng  * PARAMETERS:  name                - New scope path
9399575102SLv Zheng  *
9499575102SLv Zheng  * RETURN:      Status
9599575102SLv Zheng  *
9699575102SLv Zheng  * DESCRIPTION: Set the "current scope" as maintained by this utility.
9799575102SLv Zheng  *              The scope is used as a prefix to ACPI paths.
9899575102SLv Zheng  *
9999575102SLv Zheng  ******************************************************************************/
10099575102SLv Zheng 
10199575102SLv Zheng void acpi_db_set_scope(char *name)
10299575102SLv Zheng {
10399575102SLv Zheng 	acpi_status status;
10499575102SLv Zheng 	struct acpi_namespace_node *node;
10599575102SLv Zheng 
10699575102SLv Zheng 	if (!name || name[0] == 0) {
10799575102SLv Zheng 		acpi_os_printf("Current scope: %s\n", acpi_gbl_db_scope_buf);
10899575102SLv Zheng 		return;
10999575102SLv Zheng 	}
11099575102SLv Zheng 
11199575102SLv Zheng 	acpi_db_prep_namestring(name);
11299575102SLv Zheng 
11399575102SLv Zheng 	if (ACPI_IS_ROOT_PREFIX(name[0])) {
11499575102SLv Zheng 
11599575102SLv Zheng 		/* Validate new scope from the root */
11699575102SLv Zheng 
11799575102SLv Zheng 		status = acpi_ns_get_node(acpi_gbl_root_node, name,
11899575102SLv Zheng 					  ACPI_NS_NO_UPSEARCH, &node);
11999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
12099575102SLv Zheng 			goto error_exit;
12199575102SLv Zheng 		}
12299575102SLv Zheng 
12399575102SLv Zheng 		acpi_gbl_db_scope_buf[0] = 0;
12499575102SLv Zheng 	} else {
12599575102SLv Zheng 		/* Validate new scope relative to old scope */
12699575102SLv Zheng 
12799575102SLv Zheng 		status = acpi_ns_get_node(acpi_gbl_db_scope_node, name,
12899575102SLv Zheng 					  ACPI_NS_NO_UPSEARCH, &node);
12999575102SLv Zheng 		if (ACPI_FAILURE(status)) {
13099575102SLv Zheng 			goto error_exit;
13199575102SLv Zheng 		}
13299575102SLv Zheng 	}
13399575102SLv Zheng 
13499575102SLv Zheng 	/* Build the final pathname */
13599575102SLv Zheng 
13699575102SLv Zheng 	if (acpi_ut_safe_strcat
13799575102SLv Zheng 	    (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), name)) {
13899575102SLv Zheng 		status = AE_BUFFER_OVERFLOW;
13999575102SLv Zheng 		goto error_exit;
14099575102SLv Zheng 	}
14199575102SLv Zheng 
14299575102SLv Zheng 	if (acpi_ut_safe_strcat
14399575102SLv Zheng 	    (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), "\\")) {
14499575102SLv Zheng 		status = AE_BUFFER_OVERFLOW;
14599575102SLv Zheng 		goto error_exit;
14699575102SLv Zheng 	}
14799575102SLv Zheng 
14899575102SLv Zheng 	acpi_gbl_db_scope_node = node;
14999575102SLv Zheng 	acpi_os_printf("New scope: %s\n", acpi_gbl_db_scope_buf);
15099575102SLv Zheng 	return;
15199575102SLv Zheng 
15299575102SLv Zheng error_exit:
15399575102SLv Zheng 
15499575102SLv Zheng 	acpi_os_printf("Could not attach scope: %s, %s\n",
15599575102SLv Zheng 		       name, acpi_format_exception(status));
15699575102SLv Zheng }
15799575102SLv Zheng 
15899575102SLv Zheng /*******************************************************************************
15999575102SLv Zheng  *
16099575102SLv Zheng  * FUNCTION:    acpi_db_dump_namespace
16199575102SLv Zheng  *
16299575102SLv Zheng  * PARAMETERS:  start_arg       - Node to begin namespace dump
16399575102SLv Zheng  *              depth_arg       - Maximum tree depth to be dumped
16499575102SLv Zheng  *
16599575102SLv Zheng  * RETURN:      None
16699575102SLv Zheng  *
16799575102SLv Zheng  * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
16899575102SLv Zheng  *              with type and other information.
16999575102SLv Zheng  *
17099575102SLv Zheng  ******************************************************************************/
17199575102SLv Zheng 
17299575102SLv Zheng void acpi_db_dump_namespace(char *start_arg, char *depth_arg)
17399575102SLv Zheng {
17499575102SLv Zheng 	acpi_handle subtree_entry = acpi_gbl_root_node;
17599575102SLv Zheng 	u32 max_depth = ACPI_UINT32_MAX;
17699575102SLv Zheng 
17799575102SLv Zheng 	/* No argument given, just start at the root and dump entire namespace */
17899575102SLv Zheng 
17999575102SLv Zheng 	if (start_arg) {
18099575102SLv Zheng 		subtree_entry = acpi_db_convert_to_node(start_arg);
18199575102SLv Zheng 		if (!subtree_entry) {
18299575102SLv Zheng 			return;
18399575102SLv Zheng 		}
18499575102SLv Zheng 
18599575102SLv Zheng 		/* Now we can check for the depth argument */
18699575102SLv Zheng 
18799575102SLv Zheng 		if (depth_arg) {
18899575102SLv Zheng 			max_depth = strtoul(depth_arg, NULL, 0);
18999575102SLv Zheng 		}
19099575102SLv Zheng 	}
19199575102SLv Zheng 
19299575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
1934032cc3eSBob Moore 
1944032cc3eSBob Moore 	if (((struct acpi_namespace_node *)subtree_entry)->parent) {
19599575102SLv Zheng 		acpi_os_printf("ACPI Namespace (from %4.4s (%p) subtree):\n",
1964032cc3eSBob Moore 			       ((struct acpi_namespace_node *)subtree_entry)->
1974032cc3eSBob Moore 			       name.ascii, subtree_entry);
1984032cc3eSBob Moore 	} else {
1994032cc3eSBob Moore 		acpi_os_printf("ACPI Namespace (from %s):\n",
2004032cc3eSBob Moore 			       ACPI_NAMESPACE_ROOT);
2014032cc3eSBob Moore 	}
20299575102SLv Zheng 
20399575102SLv Zheng 	/* Display the subtree */
20499575102SLv Zheng 
20599575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
20699575102SLv Zheng 	acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, max_depth,
20799575102SLv Zheng 			     ACPI_OWNER_ID_MAX, subtree_entry);
20899575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
20999575102SLv Zheng }
21099575102SLv Zheng 
21199575102SLv Zheng /*******************************************************************************
21299575102SLv Zheng  *
21399575102SLv Zheng  * FUNCTION:    acpi_db_dump_namespace_paths
21499575102SLv Zheng  *
21599575102SLv Zheng  * PARAMETERS:  None
21699575102SLv Zheng  *
21799575102SLv Zheng  * RETURN:      None
21899575102SLv Zheng  *
21999575102SLv Zheng  * DESCRIPTION: Dump entire namespace with full object pathnames and object
22099575102SLv Zheng  *              type information. Alternative to "namespace" command.
22199575102SLv Zheng  *
22299575102SLv Zheng  ******************************************************************************/
22399575102SLv Zheng 
22499575102SLv Zheng void acpi_db_dump_namespace_paths(void)
22599575102SLv Zheng {
22699575102SLv Zheng 
22799575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
22899575102SLv Zheng 	acpi_os_printf("ACPI Namespace (from root):\n");
22999575102SLv Zheng 
23099575102SLv Zheng 	/* Display the entire namespace */
23199575102SLv Zheng 
23299575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
23399575102SLv Zheng 	acpi_ns_dump_object_paths(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY,
23499575102SLv Zheng 				  ACPI_UINT32_MAX, ACPI_OWNER_ID_MAX,
23599575102SLv Zheng 				  acpi_gbl_root_node);
23699575102SLv Zheng 
23799575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
23899575102SLv Zheng }
23999575102SLv Zheng 
24099575102SLv Zheng /*******************************************************************************
24199575102SLv Zheng  *
24299575102SLv Zheng  * FUNCTION:    acpi_db_dump_namespace_by_owner
24399575102SLv Zheng  *
24499575102SLv Zheng  * PARAMETERS:  owner_arg       - Owner ID whose nodes will be displayed
24599575102SLv Zheng  *              depth_arg       - Maximum tree depth to be dumped
24699575102SLv Zheng  *
24799575102SLv Zheng  * RETURN:      None
24899575102SLv Zheng  *
24999575102SLv Zheng  * DESCRIPTION: Dump elements of the namespace that are owned by the owner_id.
25099575102SLv Zheng  *
25199575102SLv Zheng  ******************************************************************************/
25299575102SLv Zheng 
25399575102SLv Zheng void acpi_db_dump_namespace_by_owner(char *owner_arg, char *depth_arg)
25499575102SLv Zheng {
25599575102SLv Zheng 	acpi_handle subtree_entry = acpi_gbl_root_node;
25699575102SLv Zheng 	u32 max_depth = ACPI_UINT32_MAX;
25799575102SLv Zheng 	acpi_owner_id owner_id;
25899575102SLv Zheng 
25999575102SLv Zheng 	owner_id = (acpi_owner_id)strtoul(owner_arg, NULL, 0);
26099575102SLv Zheng 
26199575102SLv Zheng 	/* Now we can check for the depth argument */
26299575102SLv Zheng 
26399575102SLv Zheng 	if (depth_arg) {
26499575102SLv Zheng 		max_depth = strtoul(depth_arg, NULL, 0);
26599575102SLv Zheng 	}
26699575102SLv Zheng 
26799575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
26899575102SLv Zheng 	acpi_os_printf("ACPI Namespace by owner %X:\n", owner_id);
26999575102SLv Zheng 
27099575102SLv Zheng 	/* Display the subtree */
27199575102SLv Zheng 
27299575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
27399575102SLv Zheng 	acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, max_depth,
27499575102SLv Zheng 			     owner_id, subtree_entry);
27599575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
27699575102SLv Zheng }
27799575102SLv Zheng 
27899575102SLv Zheng /*******************************************************************************
27999575102SLv Zheng  *
28099575102SLv Zheng  * FUNCTION:    acpi_db_walk_and_match_name
28199575102SLv Zheng  *
28299575102SLv Zheng  * PARAMETERS:  Callback from walk_namespace
28399575102SLv Zheng  *
28499575102SLv Zheng  * RETURN:      Status
28599575102SLv Zheng  *
28699575102SLv Zheng  * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
28799575102SLv Zheng  *              are supported -- '?' matches any character.
28899575102SLv Zheng  *
28999575102SLv Zheng  ******************************************************************************/
29099575102SLv Zheng 
29199575102SLv Zheng static acpi_status
29299575102SLv Zheng acpi_db_walk_and_match_name(acpi_handle obj_handle,
29399575102SLv Zheng 			    u32 nesting_level,
29499575102SLv Zheng 			    void *context, void **return_value)
29599575102SLv Zheng {
29699575102SLv Zheng 	acpi_status status;
29799575102SLv Zheng 	char *requested_name = (char *)context;
29899575102SLv Zheng 	u32 i;
29999575102SLv Zheng 	struct acpi_buffer buffer;
30099575102SLv Zheng 	struct acpi_walk_info info;
30199575102SLv Zheng 
30299575102SLv Zheng 	/* Check for a name match */
30399575102SLv Zheng 
30499575102SLv Zheng 	for (i = 0; i < 4; i++) {
30599575102SLv Zheng 
30699575102SLv Zheng 		/* Wildcard support */
30799575102SLv Zheng 
30899575102SLv Zheng 		if ((requested_name[i] != '?') &&
30999575102SLv Zheng 		    (requested_name[i] != ((struct acpi_namespace_node *)
31099575102SLv Zheng 					   obj_handle)->name.ascii[i])) {
31199575102SLv Zheng 
31299575102SLv Zheng 			/* No match, just exit */
31399575102SLv Zheng 
31499575102SLv Zheng 			return (AE_OK);
31599575102SLv Zheng 		}
31699575102SLv Zheng 	}
31799575102SLv Zheng 
31899575102SLv Zheng 	/* Get the full pathname to this object */
31999575102SLv Zheng 
32099575102SLv Zheng 	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
32199575102SLv Zheng 	status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
32299575102SLv Zheng 	if (ACPI_FAILURE(status)) {
32399575102SLv Zheng 		acpi_os_printf("Could Not get pathname for object %p\n",
32499575102SLv Zheng 			       obj_handle);
32599575102SLv Zheng 	} else {
3261387cdd8SBob Moore 		info.count = 0;
32799575102SLv Zheng 		info.owner_id = ACPI_OWNER_ID_MAX;
32899575102SLv Zheng 		info.debug_level = ACPI_UINT32_MAX;
32999575102SLv Zheng 		info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
33099575102SLv Zheng 
33199575102SLv Zheng 		acpi_os_printf("%32s", (char *)buffer.pointer);
33299575102SLv Zheng 		(void)acpi_ns_dump_one_object(obj_handle, nesting_level, &info,
33399575102SLv Zheng 					      NULL);
33499575102SLv Zheng 		ACPI_FREE(buffer.pointer);
33599575102SLv Zheng 	}
33699575102SLv Zheng 
33799575102SLv Zheng 	return (AE_OK);
33899575102SLv Zheng }
33999575102SLv Zheng 
34099575102SLv Zheng /*******************************************************************************
34199575102SLv Zheng  *
34299575102SLv Zheng  * FUNCTION:    acpi_db_find_name_in_namespace
34399575102SLv Zheng  *
34499575102SLv Zheng  * PARAMETERS:  name_arg        - The 4-character ACPI name to find.
34599575102SLv Zheng  *                                wildcards are supported.
34699575102SLv Zheng  *
34799575102SLv Zheng  * RETURN:      None
34899575102SLv Zheng  *
34999575102SLv Zheng  * DESCRIPTION: Search the namespace for a given name (with wildcards)
35099575102SLv Zheng  *
35199575102SLv Zheng  ******************************************************************************/
35299575102SLv Zheng 
35399575102SLv Zheng acpi_status acpi_db_find_name_in_namespace(char *name_arg)
35499575102SLv Zheng {
35599575102SLv Zheng 	char acpi_name[5] = "____";
35699575102SLv Zheng 	char *acpi_name_ptr = acpi_name;
35799575102SLv Zheng 
35832786755SBob Moore 	if (strlen(name_arg) > ACPI_NAMESEG_SIZE) {
35999575102SLv Zheng 		acpi_os_printf("Name must be no longer than 4 characters\n");
36099575102SLv Zheng 		return (AE_OK);
36199575102SLv Zheng 	}
36299575102SLv Zheng 
36399575102SLv Zheng 	/* Pad out name with underscores as necessary to create a 4-char name */
36499575102SLv Zheng 
36599575102SLv Zheng 	acpi_ut_strupr(name_arg);
36699575102SLv Zheng 	while (*name_arg) {
36799575102SLv Zheng 		*acpi_name_ptr = *name_arg;
36899575102SLv Zheng 		acpi_name_ptr++;
36999575102SLv Zheng 		name_arg++;
37099575102SLv Zheng 	}
37199575102SLv Zheng 
37299575102SLv Zheng 	/* Walk the namespace from the root */
37399575102SLv Zheng 
37499575102SLv Zheng 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
37599575102SLv Zheng 				  ACPI_UINT32_MAX, acpi_db_walk_and_match_name,
37699575102SLv Zheng 				  NULL, acpi_name, NULL);
37799575102SLv Zheng 
37899575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
37999575102SLv Zheng 	return (AE_OK);
38099575102SLv Zheng }
38199575102SLv Zheng 
38299575102SLv Zheng /*******************************************************************************
38399575102SLv Zheng  *
38499575102SLv Zheng  * FUNCTION:    acpi_db_walk_for_predefined_names
38599575102SLv Zheng  *
38699575102SLv Zheng  * PARAMETERS:  Callback from walk_namespace
38799575102SLv Zheng  *
38899575102SLv Zheng  * RETURN:      Status
38999575102SLv Zheng  *
39099575102SLv Zheng  * DESCRIPTION: Detect and display predefined ACPI names (names that start with
39199575102SLv Zheng  *              an underscore)
39299575102SLv Zheng  *
39399575102SLv Zheng  ******************************************************************************/
39499575102SLv Zheng 
39599575102SLv Zheng static acpi_status
39699575102SLv Zheng acpi_db_walk_for_predefined_names(acpi_handle obj_handle,
39799575102SLv Zheng 				  u32 nesting_level,
39899575102SLv Zheng 				  void *context, void **return_value)
39999575102SLv Zheng {
40099575102SLv Zheng 	struct acpi_namespace_node *node =
40199575102SLv Zheng 	    (struct acpi_namespace_node *)obj_handle;
40299575102SLv Zheng 	u32 *count = (u32 *)context;
40399575102SLv Zheng 	const union acpi_predefined_info *predefined;
40499575102SLv Zheng 	const union acpi_predefined_info *package = NULL;
40599575102SLv Zheng 	char *pathname;
40699575102SLv Zheng 	char string_buffer[48];
40799575102SLv Zheng 
40899575102SLv Zheng 	predefined = acpi_ut_match_predefined_method(node->name.ascii);
40999575102SLv Zheng 	if (!predefined) {
41099575102SLv Zheng 		return (AE_OK);
41199575102SLv Zheng 	}
41299575102SLv Zheng 
4130e166e4fSLv Zheng 	pathname = acpi_ns_get_normalized_pathname(node, TRUE);
41499575102SLv Zheng 	if (!pathname) {
41599575102SLv Zheng 		return (AE_OK);
41699575102SLv Zheng 	}
41799575102SLv Zheng 
41899575102SLv Zheng 	/* If method returns a package, the info is in the next table entry */
41999575102SLv Zheng 
42099575102SLv Zheng 	if (predefined->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
42199575102SLv Zheng 		package = predefined + 1;
42299575102SLv Zheng 	}
42399575102SLv Zheng 
42499575102SLv Zheng 	acpi_ut_get_expected_return_types(string_buffer,
42599575102SLv Zheng 					  predefined->info.expected_btypes);
42699575102SLv Zheng 
42799575102SLv Zheng 	acpi_os_printf("%-32s Arguments %X, Return Types: %s", pathname,
42899575102SLv Zheng 		       METHOD_GET_ARG_COUNT(predefined->info.argument_list),
42999575102SLv Zheng 		       string_buffer);
43099575102SLv Zheng 
43199575102SLv Zheng 	if (package) {
43299575102SLv Zheng 		acpi_os_printf(" (PkgType %2.2X, ObjType %2.2X, Count %2.2X)",
43399575102SLv Zheng 			       package->ret_info.type,
43499575102SLv Zheng 			       package->ret_info.object_type1,
43599575102SLv Zheng 			       package->ret_info.count1);
43699575102SLv Zheng 	}
43799575102SLv Zheng 
43899575102SLv Zheng 	acpi_os_printf("\n");
43999575102SLv Zheng 
44099575102SLv Zheng 	/* Check that the declared argument count matches the ACPI spec */
44199575102SLv Zheng 
44299575102SLv Zheng 	acpi_ns_check_acpi_compliance(pathname, node, predefined);
44399575102SLv Zheng 
44499575102SLv Zheng 	ACPI_FREE(pathname);
44599575102SLv Zheng 	(*count)++;
44699575102SLv Zheng 	return (AE_OK);
44799575102SLv Zheng }
44899575102SLv Zheng 
44999575102SLv Zheng /*******************************************************************************
45099575102SLv Zheng  *
45199575102SLv Zheng  * FUNCTION:    acpi_db_check_predefined_names
45299575102SLv Zheng  *
45399575102SLv Zheng  * PARAMETERS:  None
45499575102SLv Zheng  *
45599575102SLv Zheng  * RETURN:      None
45699575102SLv Zheng  *
45799575102SLv Zheng  * DESCRIPTION: Validate all predefined names in the namespace
45899575102SLv Zheng  *
45999575102SLv Zheng  ******************************************************************************/
46099575102SLv Zheng 
46199575102SLv Zheng void acpi_db_check_predefined_names(void)
46299575102SLv Zheng {
46399575102SLv Zheng 	u32 count = 0;
46499575102SLv Zheng 
46599575102SLv Zheng 	/* Search all nodes in namespace */
46699575102SLv Zheng 
46799575102SLv Zheng 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
46899575102SLv Zheng 				  ACPI_UINT32_MAX,
46999575102SLv Zheng 				  acpi_db_walk_for_predefined_names, NULL,
47099575102SLv Zheng 				  (void *)&count, NULL);
47199575102SLv Zheng 
47299575102SLv Zheng 	acpi_os_printf("Found %u predefined names in the namespace\n", count);
47399575102SLv Zheng }
47499575102SLv Zheng 
47599575102SLv Zheng /*******************************************************************************
47699575102SLv Zheng  *
47799575102SLv Zheng  * FUNCTION:    acpi_db_walk_for_object_counts
47899575102SLv Zheng  *
47999575102SLv Zheng  * PARAMETERS:  Callback from walk_namespace
48099575102SLv Zheng  *
48199575102SLv Zheng  * RETURN:      Status
48299575102SLv Zheng  *
48399575102SLv Zheng  * DESCRIPTION: Display short info about objects in the namespace
48499575102SLv Zheng  *
48599575102SLv Zheng  ******************************************************************************/
48699575102SLv Zheng 
48799575102SLv Zheng static acpi_status
48899575102SLv Zheng acpi_db_walk_for_object_counts(acpi_handle obj_handle,
48999575102SLv Zheng 			       u32 nesting_level,
49099575102SLv Zheng 			       void *context, void **return_value)
49199575102SLv Zheng {
49299575102SLv Zheng 	struct acpi_object_info *info = (struct acpi_object_info *)context;
49399575102SLv Zheng 	struct acpi_namespace_node *node =
49499575102SLv Zheng 	    (struct acpi_namespace_node *)obj_handle;
49599575102SLv Zheng 
49699575102SLv Zheng 	if (node->type > ACPI_TYPE_NS_NODE_MAX) {
49799575102SLv Zheng 		acpi_os_printf("[%4.4s]: Unknown object type %X\n",
49899575102SLv Zheng 			       node->name.ascii, node->type);
49999575102SLv Zheng 	} else {
50099575102SLv Zheng 		info->types[node->type]++;
50199575102SLv Zheng 	}
50299575102SLv Zheng 
50399575102SLv Zheng 	return (AE_OK);
50499575102SLv Zheng }
50599575102SLv Zheng 
50699575102SLv Zheng /*******************************************************************************
50799575102SLv Zheng  *
5085fd03328SErik Schmauss  * FUNCTION:    acpi_db_walk_for_fields
5095fd03328SErik Schmauss  *
5105fd03328SErik Schmauss  * PARAMETERS:  Callback from walk_namespace
5115fd03328SErik Schmauss  *
5125fd03328SErik Schmauss  * RETURN:      Status
5135fd03328SErik Schmauss  *
5145fd03328SErik Schmauss  * DESCRIPTION: Display short info about objects in the namespace
5155fd03328SErik Schmauss  *
5165fd03328SErik Schmauss  ******************************************************************************/
5175fd03328SErik Schmauss 
5185fd03328SErik Schmauss static acpi_status
5195fd03328SErik Schmauss acpi_db_walk_for_fields(acpi_handle obj_handle,
5205fd03328SErik Schmauss 			u32 nesting_level, void *context, void **return_value)
5215fd03328SErik Schmauss {
5225fd03328SErik Schmauss 	union acpi_object *ret_value;
5235fd03328SErik Schmauss 	struct acpi_region_walk_info *info =
5245fd03328SErik Schmauss 	    (struct acpi_region_walk_info *)context;
5255fd03328SErik Schmauss 	struct acpi_buffer buffer;
5265fd03328SErik Schmauss 	acpi_status status;
5275fd03328SErik Schmauss 	struct acpi_namespace_node *node = acpi_ns_validate_handle(obj_handle);
5285fd03328SErik Schmauss 
5295fd03328SErik Schmauss 	if (!node) {
5305fd03328SErik Schmauss 		return (AE_OK);
5315fd03328SErik Schmauss 	}
5325fd03328SErik Schmauss 	if (node->object->field.region_obj->region.space_id !=
5335fd03328SErik Schmauss 	    info->address_space_id) {
5345fd03328SErik Schmauss 		return (AE_OK);
5355fd03328SErik Schmauss 	}
5365fd03328SErik Schmauss 
5375fd03328SErik Schmauss 	info->count++;
5385fd03328SErik Schmauss 
5395fd03328SErik Schmauss 	/* Get and display the full pathname to this object */
5405fd03328SErik Schmauss 
5415fd03328SErik Schmauss 	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
5425fd03328SErik Schmauss 	status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
5435fd03328SErik Schmauss 	if (ACPI_FAILURE(status)) {
5445fd03328SErik Schmauss 		acpi_os_printf("Could Not get pathname for object %p\n",
5455fd03328SErik Schmauss 			       obj_handle);
5465fd03328SErik Schmauss 		return (AE_OK);
5475fd03328SErik Schmauss 	}
5485fd03328SErik Schmauss 
5495fd03328SErik Schmauss 	acpi_os_printf("%s ", (char *)buffer.pointer);
5505fd03328SErik Schmauss 	ACPI_FREE(buffer.pointer);
5515fd03328SErik Schmauss 
5525fd03328SErik Schmauss 	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
5535fd03328SErik Schmauss 	acpi_evaluate_object(obj_handle, NULL, NULL, &buffer);
5545fd03328SErik Schmauss 
555*20d93fceSErik Schmauss 	/*
556*20d93fceSErik Schmauss 	 * Since this is a field unit, surround the output in braces
557*20d93fceSErik Schmauss 	 */
558*20d93fceSErik Schmauss 	acpi_os_printf("{");
559*20d93fceSErik Schmauss 
5605fd03328SErik Schmauss 	ret_value = (union acpi_object *)buffer.pointer;
5615fd03328SErik Schmauss 	switch (ret_value->type) {
5625fd03328SErik Schmauss 	case ACPI_TYPE_INTEGER:
5635fd03328SErik Schmauss 
5645fd03328SErik Schmauss 		acpi_os_printf("%8.8X%8.8X",
5655fd03328SErik Schmauss 			       ACPI_FORMAT_UINT64(ret_value->integer.value));
5665fd03328SErik Schmauss 		break;
5675fd03328SErik Schmauss 
5685fd03328SErik Schmauss 	case ACPI_TYPE_BUFFER:
5695fd03328SErik Schmauss 
5705fd03328SErik Schmauss 		acpi_ut_dump_buffer(ret_value->buffer.pointer,
5715fd03328SErik Schmauss 				    ret_value->buffer.length,
5725fd03328SErik Schmauss 				    DB_DISPLAY_DATA_ONLY | DB_BYTE_DISPLAY, 0);
5735fd03328SErik Schmauss 		break;
5745fd03328SErik Schmauss 
5755fd03328SErik Schmauss 	default:
5765fd03328SErik Schmauss 
5775fd03328SErik Schmauss 		break;
5785fd03328SErik Schmauss 	}
579*20d93fceSErik Schmauss 	acpi_os_printf("}\n");
5805fd03328SErik Schmauss 
5815fd03328SErik Schmauss 	ACPI_FREE(buffer.pointer);
5825fd03328SErik Schmauss 
5835fd03328SErik Schmauss 	return (AE_OK);
5845fd03328SErik Schmauss }
5855fd03328SErik Schmauss 
5865fd03328SErik Schmauss /*******************************************************************************
5875fd03328SErik Schmauss  *
58899575102SLv Zheng  * FUNCTION:    acpi_db_walk_for_specific_objects
58999575102SLv Zheng  *
59099575102SLv Zheng  * PARAMETERS:  Callback from walk_namespace
59199575102SLv Zheng  *
59299575102SLv Zheng  * RETURN:      Status
59399575102SLv Zheng  *
59499575102SLv Zheng  * DESCRIPTION: Display short info about objects in the namespace
59599575102SLv Zheng  *
59699575102SLv Zheng  ******************************************************************************/
59799575102SLv Zheng 
59899575102SLv Zheng static acpi_status
59999575102SLv Zheng acpi_db_walk_for_specific_objects(acpi_handle obj_handle,
60099575102SLv Zheng 				  u32 nesting_level,
60199575102SLv Zheng 				  void *context, void **return_value)
60299575102SLv Zheng {
60399575102SLv Zheng 	struct acpi_walk_info *info = (struct acpi_walk_info *)context;
60499575102SLv Zheng 	struct acpi_buffer buffer;
60599575102SLv Zheng 	acpi_status status;
60699575102SLv Zheng 
60799575102SLv Zheng 	info->count++;
60899575102SLv Zheng 
60999575102SLv Zheng 	/* Get and display the full pathname to this object */
61099575102SLv Zheng 
61199575102SLv Zheng 	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
61299575102SLv Zheng 	status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
61399575102SLv Zheng 	if (ACPI_FAILURE(status)) {
61499575102SLv Zheng 		acpi_os_printf("Could Not get pathname for object %p\n",
61599575102SLv Zheng 			       obj_handle);
61699575102SLv Zheng 		return (AE_OK);
61799575102SLv Zheng 	}
61899575102SLv Zheng 
61999575102SLv Zheng 	acpi_os_printf("%32s", (char *)buffer.pointer);
62099575102SLv Zheng 	ACPI_FREE(buffer.pointer);
62199575102SLv Zheng 
62299575102SLv Zheng 	/* Dump short info about the object */
62399575102SLv Zheng 
62499575102SLv Zheng 	(void)acpi_ns_dump_one_object(obj_handle, nesting_level, info, NULL);
62599575102SLv Zheng 	return (AE_OK);
62699575102SLv Zheng }
62799575102SLv Zheng 
62899575102SLv Zheng /*******************************************************************************
62999575102SLv Zheng  *
63099575102SLv Zheng  * FUNCTION:    acpi_db_display_objects
63199575102SLv Zheng  *
63299575102SLv Zheng  * PARAMETERS:  obj_type_arg        - Type of object to display
63399575102SLv Zheng  *              display_count_arg   - Max depth to display
63499575102SLv Zheng  *
63599575102SLv Zheng  * RETURN:      None
63699575102SLv Zheng  *
63799575102SLv Zheng  * DESCRIPTION: Display objects in the namespace of the requested type
63899575102SLv Zheng  *
63999575102SLv Zheng  ******************************************************************************/
64099575102SLv Zheng 
64199575102SLv Zheng acpi_status acpi_db_display_objects(char *obj_type_arg, char *display_count_arg)
64299575102SLv Zheng {
64399575102SLv Zheng 	struct acpi_walk_info info;
64499575102SLv Zheng 	acpi_object_type type;
64599575102SLv Zheng 	struct acpi_object_info *object_info;
64699575102SLv Zheng 	u32 i;
64799575102SLv Zheng 	u32 total_objects = 0;
64899575102SLv Zheng 
64999575102SLv Zheng 	/* No argument means display summary/count of all object types */
65099575102SLv Zheng 
65199575102SLv Zheng 	if (!obj_type_arg) {
65299575102SLv Zheng 		object_info =
65399575102SLv Zheng 		    ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_object_info));
65499575102SLv Zheng 
65599575102SLv Zheng 		/* Walk the namespace from the root */
65699575102SLv Zheng 
65799575102SLv Zheng 		(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
65899575102SLv Zheng 					  ACPI_UINT32_MAX,
65999575102SLv Zheng 					  acpi_db_walk_for_object_counts, NULL,
66099575102SLv Zheng 					  (void *)object_info, NULL);
66199575102SLv Zheng 
66299575102SLv Zheng 		acpi_os_printf("\nSummary of namespace objects:\n\n");
66399575102SLv Zheng 
66499575102SLv Zheng 		for (i = 0; i < ACPI_TOTAL_TYPES; i++) {
66599575102SLv Zheng 			acpi_os_printf("%8u %s\n", object_info->types[i],
66699575102SLv Zheng 				       acpi_ut_get_type_name(i));
66799575102SLv Zheng 
66899575102SLv Zheng 			total_objects += object_info->types[i];
66999575102SLv Zheng 		}
67099575102SLv Zheng 
67199575102SLv Zheng 		acpi_os_printf("\n%8u Total namespace objects\n\n",
67299575102SLv Zheng 			       total_objects);
67399575102SLv Zheng 
67499575102SLv Zheng 		ACPI_FREE(object_info);
67599575102SLv Zheng 		return (AE_OK);
67699575102SLv Zheng 	}
67799575102SLv Zheng 
67899575102SLv Zheng 	/* Get the object type */
67999575102SLv Zheng 
68099575102SLv Zheng 	type = acpi_db_match_argument(obj_type_arg, acpi_db_object_types);
68199575102SLv Zheng 	if (type == ACPI_TYPE_NOT_FOUND) {
68299575102SLv Zheng 		acpi_os_printf("Invalid or unsupported argument\n");
68399575102SLv Zheng 		return (AE_OK);
68499575102SLv Zheng 	}
68599575102SLv Zheng 
68699575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
68799575102SLv Zheng 	acpi_os_printf
68899575102SLv Zheng 	    ("Objects of type [%s] defined in the current ACPI Namespace:\n",
68999575102SLv Zheng 	     acpi_ut_get_type_name(type));
69099575102SLv Zheng 
69199575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
69299575102SLv Zheng 
69399575102SLv Zheng 	info.count = 0;
69499575102SLv Zheng 	info.owner_id = ACPI_OWNER_ID_MAX;
69599575102SLv Zheng 	info.debug_level = ACPI_UINT32_MAX;
69699575102SLv Zheng 	info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
69799575102SLv Zheng 
69899575102SLv Zheng 	/* Walk the namespace from the root */
69999575102SLv Zheng 
70099575102SLv Zheng 	(void)acpi_walk_namespace(type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
70199575102SLv Zheng 				  acpi_db_walk_for_specific_objects, NULL,
70299575102SLv Zheng 				  (void *)&info, NULL);
70399575102SLv Zheng 
70499575102SLv Zheng 	acpi_os_printf
70599575102SLv Zheng 	    ("\nFound %u objects of type [%s] in the current ACPI Namespace\n",
70699575102SLv Zheng 	     info.count, acpi_ut_get_type_name(type));
70799575102SLv Zheng 
70899575102SLv Zheng 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
70999575102SLv Zheng 	return (AE_OK);
71099575102SLv Zheng }
71199575102SLv Zheng 
71299575102SLv Zheng /*******************************************************************************
71399575102SLv Zheng  *
7145fd03328SErik Schmauss  * FUNCTION:    acpi_db_display_fields
7155fd03328SErik Schmauss  *
7165fd03328SErik Schmauss  * PARAMETERS:  obj_type_arg        - Type of object to display
7175fd03328SErik Schmauss  *              display_count_arg   - Max depth to display
7185fd03328SErik Schmauss  *
7195fd03328SErik Schmauss  * RETURN:      None
7205fd03328SErik Schmauss  *
7215fd03328SErik Schmauss  * DESCRIPTION: Display objects in the namespace of the requested type
7225fd03328SErik Schmauss  *
7235fd03328SErik Schmauss  ******************************************************************************/
7245fd03328SErik Schmauss 
7255fd03328SErik Schmauss acpi_status acpi_db_display_fields(u32 address_space_id)
7265fd03328SErik Schmauss {
7275fd03328SErik Schmauss 	struct acpi_region_walk_info info;
7285fd03328SErik Schmauss 
7295fd03328SErik Schmauss 	info.count = 0;
7305fd03328SErik Schmauss 	info.owner_id = ACPI_OWNER_ID_MAX;
7315fd03328SErik Schmauss 	info.debug_level = ACPI_UINT32_MAX;
7325fd03328SErik Schmauss 	info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
7335fd03328SErik Schmauss 	info.address_space_id = address_space_id;
7345fd03328SErik Schmauss 
7355fd03328SErik Schmauss 	/* Walk the namespace from the root */
7365fd03328SErik Schmauss 
7375fd03328SErik Schmauss 	(void)acpi_walk_namespace(ACPI_TYPE_LOCAL_REGION_FIELD,
7385fd03328SErik Schmauss 				  ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
7395fd03328SErik Schmauss 				  acpi_db_walk_for_fields, NULL, (void *)&info,
7405fd03328SErik Schmauss 				  NULL);
7415fd03328SErik Schmauss 
7425fd03328SErik Schmauss 	return (AE_OK);
7435fd03328SErik Schmauss }
7445fd03328SErik Schmauss 
7455fd03328SErik Schmauss /*******************************************************************************
7465fd03328SErik Schmauss  *
74799575102SLv Zheng  * FUNCTION:    acpi_db_integrity_walk
74899575102SLv Zheng  *
74999575102SLv Zheng  * PARAMETERS:  Callback from walk_namespace
75099575102SLv Zheng  *
75199575102SLv Zheng  * RETURN:      Status
75299575102SLv Zheng  *
75399575102SLv Zheng  * DESCRIPTION: Examine one NS node for valid values.
75499575102SLv Zheng  *
75599575102SLv Zheng  ******************************************************************************/
75699575102SLv Zheng 
75799575102SLv Zheng static acpi_status
75899575102SLv Zheng acpi_db_integrity_walk(acpi_handle obj_handle,
75999575102SLv Zheng 		       u32 nesting_level, void *context, void **return_value)
76099575102SLv Zheng {
76199575102SLv Zheng 	struct acpi_integrity_info *info =
76299575102SLv Zheng 	    (struct acpi_integrity_info *)context;
76399575102SLv Zheng 	struct acpi_namespace_node *node =
76499575102SLv Zheng 	    (struct acpi_namespace_node *)obj_handle;
76599575102SLv Zheng 	union acpi_operand_object *object;
76699575102SLv Zheng 	u8 alias = TRUE;
76799575102SLv Zheng 
76899575102SLv Zheng 	info->nodes++;
76999575102SLv Zheng 
77099575102SLv Zheng 	/* Verify the NS node, and dereference aliases */
77199575102SLv Zheng 
77299575102SLv Zheng 	while (alias) {
77399575102SLv Zheng 		if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
77499575102SLv Zheng 			acpi_os_printf
77599575102SLv Zheng 			    ("Invalid Descriptor Type for Node %p [%s] - "
77699575102SLv Zheng 			     "is %2.2X should be %2.2X\n", node,
77799575102SLv Zheng 			     acpi_ut_get_descriptor_name(node),
77899575102SLv Zheng 			     ACPI_GET_DESCRIPTOR_TYPE(node),
77999575102SLv Zheng 			     ACPI_DESC_TYPE_NAMED);
78099575102SLv Zheng 			return (AE_OK);
78199575102SLv Zheng 		}
78299575102SLv Zheng 
78399575102SLv Zheng 		if ((node->type == ACPI_TYPE_LOCAL_ALIAS) ||
78499575102SLv Zheng 		    (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
78599575102SLv Zheng 			node = (struct acpi_namespace_node *)node->object;
78699575102SLv Zheng 		} else {
78799575102SLv Zheng 			alias = FALSE;
78899575102SLv Zheng 		}
78999575102SLv Zheng 	}
79099575102SLv Zheng 
79199575102SLv Zheng 	if (node->type > ACPI_TYPE_LOCAL_MAX) {
79299575102SLv Zheng 		acpi_os_printf("Invalid Object Type for Node %p, Type = %X\n",
79399575102SLv Zheng 			       node, node->type);
79499575102SLv Zheng 		return (AE_OK);
79599575102SLv Zheng 	}
79699575102SLv Zheng 
7976a0df32cSBob Moore 	if (!acpi_ut_valid_nameseg(node->name.ascii)) {
79899575102SLv Zheng 		acpi_os_printf("Invalid AcpiName for Node %p\n", node);
79999575102SLv Zheng 		return (AE_OK);
80099575102SLv Zheng 	}
80199575102SLv Zheng 
80299575102SLv Zheng 	object = acpi_ns_get_attached_object(node);
80399575102SLv Zheng 	if (object) {
80499575102SLv Zheng 		info->objects++;
80599575102SLv Zheng 		if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
80699575102SLv Zheng 			acpi_os_printf
80799575102SLv Zheng 			    ("Invalid Descriptor Type for Object %p [%s]\n",
80899575102SLv Zheng 			     object, acpi_ut_get_descriptor_name(object));
80999575102SLv Zheng 		}
81099575102SLv Zheng 	}
81199575102SLv Zheng 
81299575102SLv Zheng 	return (AE_OK);
81399575102SLv Zheng }
81499575102SLv Zheng 
81599575102SLv Zheng /*******************************************************************************
81699575102SLv Zheng  *
81799575102SLv Zheng  * FUNCTION:    acpi_db_check_integrity
81899575102SLv Zheng  *
81999575102SLv Zheng  * PARAMETERS:  None
82099575102SLv Zheng  *
82199575102SLv Zheng  * RETURN:      None
82299575102SLv Zheng  *
82399575102SLv Zheng  * DESCRIPTION: Check entire namespace for data structure integrity
82499575102SLv Zheng  *
82599575102SLv Zheng  ******************************************************************************/
82699575102SLv Zheng 
82799575102SLv Zheng void acpi_db_check_integrity(void)
82899575102SLv Zheng {
82999575102SLv Zheng 	struct acpi_integrity_info info = { 0, 0 };
83099575102SLv Zheng 
83199575102SLv Zheng 	/* Search all nodes in namespace */
83299575102SLv Zheng 
83399575102SLv Zheng 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
83499575102SLv Zheng 				  ACPI_UINT32_MAX, acpi_db_integrity_walk, NULL,
83599575102SLv Zheng 				  (void *)&info, NULL);
83699575102SLv Zheng 
83799575102SLv Zheng 	acpi_os_printf("Verified %u namespace nodes with %u Objects\n",
83899575102SLv Zheng 		       info.nodes, info.objects);
83999575102SLv Zheng }
84099575102SLv Zheng 
84199575102SLv Zheng /*******************************************************************************
84299575102SLv Zheng  *
84399575102SLv Zheng  * FUNCTION:    acpi_db_walk_for_references
84499575102SLv Zheng  *
84599575102SLv Zheng  * PARAMETERS:  Callback from walk_namespace
84699575102SLv Zheng  *
84799575102SLv Zheng  * RETURN:      Status
84899575102SLv Zheng  *
84999575102SLv Zheng  * DESCRIPTION: Check if this namespace object refers to the target object
85099575102SLv Zheng  *              that is passed in as the context value.
85199575102SLv Zheng  *
85299575102SLv Zheng  * Note: Currently doesn't check subobjects within the Node's object
85399575102SLv Zheng  *
85499575102SLv Zheng  ******************************************************************************/
85599575102SLv Zheng 
85699575102SLv Zheng static acpi_status
85799575102SLv Zheng acpi_db_walk_for_references(acpi_handle obj_handle,
85899575102SLv Zheng 			    u32 nesting_level,
85999575102SLv Zheng 			    void *context, void **return_value)
86099575102SLv Zheng {
86199575102SLv Zheng 	union acpi_operand_object *obj_desc =
86299575102SLv Zheng 	    (union acpi_operand_object *)context;
86399575102SLv Zheng 	struct acpi_namespace_node *node =
86499575102SLv Zheng 	    (struct acpi_namespace_node *)obj_handle;
86599575102SLv Zheng 
86699575102SLv Zheng 	/* Check for match against the namespace node itself */
86799575102SLv Zheng 
86899575102SLv Zheng 	if (node == (void *)obj_desc) {
86999575102SLv Zheng 		acpi_os_printf("Object is a Node [%4.4s]\n",
87099575102SLv Zheng 			       acpi_ut_get_node_name(node));
87199575102SLv Zheng 	}
87299575102SLv Zheng 
87399575102SLv Zheng 	/* Check for match against the object attached to the node */
87499575102SLv Zheng 
87599575102SLv Zheng 	if (acpi_ns_get_attached_object(node) == obj_desc) {
87699575102SLv Zheng 		acpi_os_printf("Reference at Node->Object %p [%4.4s]\n",
87799575102SLv Zheng 			       node, acpi_ut_get_node_name(node));
87899575102SLv Zheng 	}
87999575102SLv Zheng 
88099575102SLv Zheng 	return (AE_OK);
88199575102SLv Zheng }
88299575102SLv Zheng 
88399575102SLv Zheng /*******************************************************************************
88499575102SLv Zheng  *
88599575102SLv Zheng  * FUNCTION:    acpi_db_find_references
88699575102SLv Zheng  *
88799575102SLv Zheng  * PARAMETERS:  object_arg      - String with hex value of the object
88899575102SLv Zheng  *
88999575102SLv Zheng  * RETURN:      None
89099575102SLv Zheng  *
89199575102SLv Zheng  * DESCRIPTION: Search namespace for all references to the input object
89299575102SLv Zheng  *
89399575102SLv Zheng  ******************************************************************************/
89499575102SLv Zheng 
89599575102SLv Zheng void acpi_db_find_references(char *object_arg)
89699575102SLv Zheng {
89799575102SLv Zheng 	union acpi_operand_object *obj_desc;
89899575102SLv Zheng 	acpi_size address;
89999575102SLv Zheng 
90099575102SLv Zheng 	/* Convert string to object pointer */
90199575102SLv Zheng 
90299575102SLv Zheng 	address = strtoul(object_arg, NULL, 16);
90399575102SLv Zheng 	obj_desc = ACPI_TO_POINTER(address);
90499575102SLv Zheng 
90599575102SLv Zheng 	/* Search all nodes in namespace */
90699575102SLv Zheng 
90799575102SLv Zheng 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
90899575102SLv Zheng 				  ACPI_UINT32_MAX, acpi_db_walk_for_references,
90999575102SLv Zheng 				  NULL, (void *)obj_desc, NULL);
91099575102SLv Zheng }
91199575102SLv Zheng 
91299575102SLv Zheng /*******************************************************************************
91399575102SLv Zheng  *
91499575102SLv Zheng  * FUNCTION:    acpi_db_bus_walk
91599575102SLv Zheng  *
91699575102SLv Zheng  * PARAMETERS:  Callback from walk_namespace
91799575102SLv Zheng  *
91899575102SLv Zheng  * RETURN:      Status
91999575102SLv Zheng  *
92099575102SLv Zheng  * DESCRIPTION: Display info about device objects that have a corresponding
92199575102SLv Zheng  *              _PRT method.
92299575102SLv Zheng  *
92399575102SLv Zheng  ******************************************************************************/
92499575102SLv Zheng 
92599575102SLv Zheng static acpi_status
92699575102SLv Zheng acpi_db_bus_walk(acpi_handle obj_handle,
92799575102SLv Zheng 		 u32 nesting_level, void *context, void **return_value)
92899575102SLv Zheng {
92999575102SLv Zheng 	struct acpi_namespace_node *node =
93099575102SLv Zheng 	    (struct acpi_namespace_node *)obj_handle;
93199575102SLv Zheng 	acpi_status status;
93299575102SLv Zheng 	struct acpi_buffer buffer;
93399575102SLv Zheng 	struct acpi_namespace_node *temp_node;
93499575102SLv Zheng 	struct acpi_device_info *info;
93599575102SLv Zheng 	u32 i;
93699575102SLv Zheng 
93799575102SLv Zheng 	if ((node->type != ACPI_TYPE_DEVICE) &&
93899575102SLv Zheng 	    (node->type != ACPI_TYPE_PROCESSOR)) {
93999575102SLv Zheng 		return (AE_OK);
94099575102SLv Zheng 	}
94199575102SLv Zheng 
94299575102SLv Zheng 	/* Exit if there is no _PRT under this device */
94399575102SLv Zheng 
94499575102SLv Zheng 	status = acpi_get_handle(node, METHOD_NAME__PRT,
94599575102SLv Zheng 				 ACPI_CAST_PTR(acpi_handle, &temp_node));
94699575102SLv Zheng 	if (ACPI_FAILURE(status)) {
94799575102SLv Zheng 		return (AE_OK);
94899575102SLv Zheng 	}
94999575102SLv Zheng 
95099575102SLv Zheng 	/* Get the full path to this device object */
95199575102SLv Zheng 
95299575102SLv Zheng 	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
95399575102SLv Zheng 	status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
95499575102SLv Zheng 	if (ACPI_FAILURE(status)) {
95599575102SLv Zheng 		acpi_os_printf("Could Not get pathname for object %p\n",
95699575102SLv Zheng 			       obj_handle);
95799575102SLv Zheng 		return (AE_OK);
95899575102SLv Zheng 	}
95999575102SLv Zheng 
96099575102SLv Zheng 	status = acpi_get_object_info(obj_handle, &info);
96199575102SLv Zheng 	if (ACPI_FAILURE(status)) {
96299575102SLv Zheng 		return (AE_OK);
96399575102SLv Zheng 	}
96499575102SLv Zheng 
96599575102SLv Zheng 	/* Display the full path */
96699575102SLv Zheng 
96799575102SLv Zheng 	acpi_os_printf("%-32s Type %X", (char *)buffer.pointer, node->type);
96899575102SLv Zheng 	ACPI_FREE(buffer.pointer);
96999575102SLv Zheng 
97099575102SLv Zheng 	if (info->flags & ACPI_PCI_ROOT_BRIDGE) {
97199575102SLv Zheng 		acpi_os_printf(" - Is PCI Root Bridge");
97299575102SLv Zheng 	}
97399575102SLv Zheng 	acpi_os_printf("\n");
97499575102SLv Zheng 
97599575102SLv Zheng 	/* _PRT info */
97699575102SLv Zheng 
97799575102SLv Zheng 	acpi_os_printf("_PRT: %p\n", temp_node);
97899575102SLv Zheng 
97999575102SLv Zheng 	/* Dump _ADR, _HID, _UID, _CID */
98099575102SLv Zheng 
98199575102SLv Zheng 	if (info->valid & ACPI_VALID_ADR) {
98299575102SLv Zheng 		acpi_os_printf("_ADR: %8.8X%8.8X\n",
98399575102SLv Zheng 			       ACPI_FORMAT_UINT64(info->address));
98499575102SLv Zheng 	} else {
98599575102SLv Zheng 		acpi_os_printf("_ADR: <Not Present>\n");
98699575102SLv Zheng 	}
98799575102SLv Zheng 
98899575102SLv Zheng 	if (info->valid & ACPI_VALID_HID) {
98999575102SLv Zheng 		acpi_os_printf("_HID: %s\n", info->hardware_id.string);
99099575102SLv Zheng 	} else {
99199575102SLv Zheng 		acpi_os_printf("_HID: <Not Present>\n");
99299575102SLv Zheng 	}
99399575102SLv Zheng 
99499575102SLv Zheng 	if (info->valid & ACPI_VALID_UID) {
99599575102SLv Zheng 		acpi_os_printf("_UID: %s\n", info->unique_id.string);
99699575102SLv Zheng 	} else {
99799575102SLv Zheng 		acpi_os_printf("_UID: <Not Present>\n");
99899575102SLv Zheng 	}
99999575102SLv Zheng 
100099575102SLv Zheng 	if (info->valid & ACPI_VALID_CID) {
100199575102SLv Zheng 		for (i = 0; i < info->compatible_id_list.count; i++) {
100299575102SLv Zheng 			acpi_os_printf("_CID: %s\n",
100399575102SLv Zheng 				       info->compatible_id_list.ids[i].string);
100499575102SLv Zheng 		}
100599575102SLv Zheng 	} else {
100699575102SLv Zheng 		acpi_os_printf("_CID: <Not Present>\n");
100799575102SLv Zheng 	}
100899575102SLv Zheng 
100999575102SLv Zheng 	ACPI_FREE(info);
101099575102SLv Zheng 	return (AE_OK);
101199575102SLv Zheng }
101299575102SLv Zheng 
101399575102SLv Zheng /*******************************************************************************
101499575102SLv Zheng  *
101599575102SLv Zheng  * FUNCTION:    acpi_db_get_bus_info
101699575102SLv Zheng  *
101799575102SLv Zheng  * PARAMETERS:  None
101899575102SLv Zheng  *
101999575102SLv Zheng  * RETURN:      None
102099575102SLv Zheng  *
1021c163f90cSErik Schmauss  * DESCRIPTION: Display info about system buses.
102299575102SLv Zheng  *
102399575102SLv Zheng  ******************************************************************************/
102499575102SLv Zheng 
102599575102SLv Zheng void acpi_db_get_bus_info(void)
102699575102SLv Zheng {
102799575102SLv Zheng 	/* Search all nodes in namespace */
102899575102SLv Zheng 
102999575102SLv Zheng 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
103099575102SLv Zheng 				  ACPI_UINT32_MAX, acpi_db_bus_walk, NULL, NULL,
103199575102SLv Zheng 				  NULL);
103299575102SLv Zheng }
1033