1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: dbnames - Debugger commands for the acpi namespace
6 ******************************************************************************/
14 #define _COMPONENT ACPI_CA_DEBUGGER
15 ACPI_MODULE_NAME("dbnames")
17 /* Local prototypes */
19 acpi_db_walk_and_match_name(acpi_handle obj_handle,
21 void *context, void **return_value);
24 acpi_db_walk_for_predefined_names(acpi_handle obj_handle,
26 void *context, void **return_value);
29 acpi_db_walk_for_specific_objects(acpi_handle obj_handle,
31 void *context, void **return_value);
34 acpi_db_walk_for_object_counts(acpi_handle obj_handle,
36 void *context, void **return_value);
39 acpi_db_integrity_walk(acpi_handle obj_handle,
40 u32 nesting_level, void *context, void **return_value);
43 acpi_db_walk_for_references(acpi_handle obj_handle,
45 void *context, void **return_value);
48 acpi_db_bus_walk(acpi_handle obj_handle,
49 u32 nesting_level, void *context, void **return_value);
52 * Arguments for the Objects command
53 * These object types map directly to the ACPI_TYPES
55 static struct acpi_db_argument_info acpi_db_object_types[] = {
84 {NULL} /* Must be null terminated */
87 /*******************************************************************************
89 * FUNCTION: acpi_db_set_scope
91 * PARAMETERS: name - New scope path
95 * DESCRIPTION: Set the "current scope" as maintained by this utility.
96 * The scope is used as a prefix to ACPI paths.
98 ******************************************************************************/
100 void acpi_db_set_scope(char *name)
103 struct acpi_namespace_node *node;
105 if (!name || name[0] == 0) {
106 acpi_os_printf("Current scope: %s\n", acpi_gbl_db_scope_buf);
110 acpi_db_prep_namestring(name);
112 if (ACPI_IS_ROOT_PREFIX(name[0])) {
114 /* Validate new scope from the root */
116 status = acpi_ns_get_node(acpi_gbl_root_node, name,
117 ACPI_NS_NO_UPSEARCH, &node);
118 if (ACPI_FAILURE(status)) {
122 acpi_gbl_db_scope_buf[0] = 0;
124 /* Validate new scope relative to old scope */
126 status = acpi_ns_get_node(acpi_gbl_db_scope_node, name,
127 ACPI_NS_NO_UPSEARCH, &node);
128 if (ACPI_FAILURE(status)) {
133 /* Build the final pathname */
135 if (acpi_ut_safe_strcat
136 (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), name)) {
137 status = AE_BUFFER_OVERFLOW;
141 if (acpi_ut_safe_strcat
142 (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), "\\")) {
143 status = AE_BUFFER_OVERFLOW;
147 acpi_gbl_db_scope_node = node;
148 acpi_os_printf("New scope: %s\n", acpi_gbl_db_scope_buf);
153 acpi_os_printf("Could not attach scope: %s, %s\n",
154 name, acpi_format_exception(status));
157 /*******************************************************************************
159 * FUNCTION: acpi_db_dump_namespace
161 * PARAMETERS: start_arg - Node to begin namespace dump
162 * depth_arg - Maximum tree depth to be dumped
166 * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
167 * with type and other information.
169 ******************************************************************************/
171 void acpi_db_dump_namespace(char *start_arg, char *depth_arg)
173 acpi_handle subtree_entry = acpi_gbl_root_node;
174 u32 max_depth = ACPI_UINT32_MAX;
176 /* No argument given, just start at the root and dump entire namespace */
179 subtree_entry = acpi_db_convert_to_node(start_arg);
180 if (!subtree_entry) {
184 /* Now we can check for the depth argument */
187 max_depth = strtoul(depth_arg, NULL, 0);
191 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
193 if (((struct acpi_namespace_node *)subtree_entry)->parent) {
194 acpi_os_printf("ACPI Namespace (from %4.4s (%p) subtree):\n",
195 ((struct acpi_namespace_node *)subtree_entry)->
196 name.ascii, subtree_entry);
198 acpi_os_printf("ACPI Namespace (from %s):\n",
199 ACPI_NAMESPACE_ROOT);
202 /* Display the subtree */
204 acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
205 acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, max_depth,
206 ACPI_OWNER_ID_MAX, subtree_entry);
207 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
210 /*******************************************************************************
212 * FUNCTION: acpi_db_dump_namespace_paths
218 * DESCRIPTION: Dump entire namespace with full object pathnames and object
219 * type information. Alternative to "namespace" command.
221 ******************************************************************************/
223 void acpi_db_dump_namespace_paths(void)
226 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
227 acpi_os_printf("ACPI Namespace (from root):\n");
229 /* Display the entire namespace */
231 acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
232 acpi_ns_dump_object_paths(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY,
233 ACPI_UINT32_MAX, ACPI_OWNER_ID_MAX,
236 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
239 /*******************************************************************************
241 * FUNCTION: acpi_db_dump_namespace_by_owner
243 * PARAMETERS: owner_arg - Owner ID whose nodes will be displayed
244 * depth_arg - Maximum tree depth to be dumped
248 * DESCRIPTION: Dump elements of the namespace that are owned by the owner_id.
250 ******************************************************************************/
252 void acpi_db_dump_namespace_by_owner(char *owner_arg, char *depth_arg)
254 acpi_handle subtree_entry = acpi_gbl_root_node;
255 u32 max_depth = ACPI_UINT32_MAX;
256 acpi_owner_id owner_id;
258 owner_id = (acpi_owner_id)strtoul(owner_arg, NULL, 0);
260 /* Now we can check for the depth argument */
263 max_depth = strtoul(depth_arg, NULL, 0);
266 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
267 acpi_os_printf("ACPI Namespace by owner %X:\n", owner_id);
269 /* Display the subtree */
271 acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
272 acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, max_depth,
273 owner_id, subtree_entry);
274 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
277 /*******************************************************************************
279 * FUNCTION: acpi_db_walk_and_match_name
281 * PARAMETERS: Callback from walk_namespace
285 * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
286 * are supported -- '?' matches any character.
288 ******************************************************************************/
291 acpi_db_walk_and_match_name(acpi_handle obj_handle,
293 void *context, void **return_value)
296 char *requested_name = (char *)context;
298 struct acpi_buffer buffer;
299 struct acpi_walk_info info;
301 /* Check for a name match */
303 for (i = 0; i < 4; i++) {
305 /* Wildcard support */
307 if ((requested_name[i] != '?') &&
308 (requested_name[i] != ((struct acpi_namespace_node *)
309 obj_handle)->name.ascii[i])) {
311 /* No match, just exit */
317 /* Get the full pathname to this object */
319 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
320 status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
321 if (ACPI_FAILURE(status)) {
322 acpi_os_printf("Could Not get pathname for object %p\n",
326 info.owner_id = ACPI_OWNER_ID_MAX;
327 info.debug_level = ACPI_UINT32_MAX;
328 info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
330 acpi_os_printf("%32s", (char *)buffer.pointer);
331 (void)acpi_ns_dump_one_object(obj_handle, nesting_level, &info,
333 ACPI_FREE(buffer.pointer);
339 /*******************************************************************************
341 * FUNCTION: acpi_db_find_name_in_namespace
343 * PARAMETERS: name_arg - The 4-character ACPI name to find.
344 * wildcards are supported.
348 * DESCRIPTION: Search the namespace for a given name (with wildcards)
350 ******************************************************************************/
352 acpi_status acpi_db_find_name_in_namespace(char *name_arg)
354 char acpi_name[5] = "____";
355 char *acpi_name_ptr = acpi_name;
357 if (strlen(name_arg) > ACPI_NAME_SIZE) {
358 acpi_os_printf("Name must be no longer than 4 characters\n");
362 /* Pad out name with underscores as necessary to create a 4-char name */
364 acpi_ut_strupr(name_arg);
366 *acpi_name_ptr = *name_arg;
371 /* Walk the namespace from the root */
373 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
374 ACPI_UINT32_MAX, acpi_db_walk_and_match_name,
375 NULL, acpi_name, NULL);
377 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
381 /*******************************************************************************
383 * FUNCTION: acpi_db_walk_for_predefined_names
385 * PARAMETERS: Callback from walk_namespace
389 * DESCRIPTION: Detect and display predefined ACPI names (names that start with
392 ******************************************************************************/
395 acpi_db_walk_for_predefined_names(acpi_handle obj_handle,
397 void *context, void **return_value)
399 struct acpi_namespace_node *node =
400 (struct acpi_namespace_node *)obj_handle;
401 u32 *count = (u32 *)context;
402 const union acpi_predefined_info *predefined;
403 const union acpi_predefined_info *package = NULL;
405 char string_buffer[48];
407 predefined = acpi_ut_match_predefined_method(node->name.ascii);
412 pathname = acpi_ns_get_normalized_pathname(node, TRUE);
417 /* If method returns a package, the info is in the next table entry */
419 if (predefined->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
420 package = predefined + 1;
423 acpi_ut_get_expected_return_types(string_buffer,
424 predefined->info.expected_btypes);
426 acpi_os_printf("%-32s Arguments %X, Return Types: %s", pathname,
427 METHOD_GET_ARG_COUNT(predefined->info.argument_list),
431 acpi_os_printf(" (PkgType %2.2X, ObjType %2.2X, Count %2.2X)",
432 package->ret_info.type,
433 package->ret_info.object_type1,
434 package->ret_info.count1);
437 acpi_os_printf("\n");
439 /* Check that the declared argument count matches the ACPI spec */
441 acpi_ns_check_acpi_compliance(pathname, node, predefined);
448 /*******************************************************************************
450 * FUNCTION: acpi_db_check_predefined_names
456 * DESCRIPTION: Validate all predefined names in the namespace
458 ******************************************************************************/
460 void acpi_db_check_predefined_names(void)
464 /* Search all nodes in namespace */
466 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
468 acpi_db_walk_for_predefined_names, NULL,
469 (void *)&count, NULL);
471 acpi_os_printf("Found %u predefined names in the namespace\n", count);
474 /*******************************************************************************
476 * FUNCTION: acpi_db_walk_for_object_counts
478 * PARAMETERS: Callback from walk_namespace
482 * DESCRIPTION: Display short info about objects in the namespace
484 ******************************************************************************/
487 acpi_db_walk_for_object_counts(acpi_handle obj_handle,
489 void *context, void **return_value)
491 struct acpi_object_info *info = (struct acpi_object_info *)context;
492 struct acpi_namespace_node *node =
493 (struct acpi_namespace_node *)obj_handle;
495 if (node->type > ACPI_TYPE_NS_NODE_MAX) {
496 acpi_os_printf("[%4.4s]: Unknown object type %X\n",
497 node->name.ascii, node->type);
499 info->types[node->type]++;
505 /*******************************************************************************
507 * FUNCTION: acpi_db_walk_for_specific_objects
509 * PARAMETERS: Callback from walk_namespace
513 * DESCRIPTION: Display short info about objects in the namespace
515 ******************************************************************************/
518 acpi_db_walk_for_specific_objects(acpi_handle obj_handle,
520 void *context, void **return_value)
522 struct acpi_walk_info *info = (struct acpi_walk_info *)context;
523 struct acpi_buffer buffer;
528 /* Get and display the full pathname to this object */
530 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
531 status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
532 if (ACPI_FAILURE(status)) {
533 acpi_os_printf("Could Not get pathname for object %p\n",
538 acpi_os_printf("%32s", (char *)buffer.pointer);
539 ACPI_FREE(buffer.pointer);
541 /* Dump short info about the object */
543 (void)acpi_ns_dump_one_object(obj_handle, nesting_level, info, NULL);
547 /*******************************************************************************
549 * FUNCTION: acpi_db_display_objects
551 * PARAMETERS: obj_type_arg - Type of object to display
552 * display_count_arg - Max depth to display
556 * DESCRIPTION: Display objects in the namespace of the requested type
558 ******************************************************************************/
560 acpi_status acpi_db_display_objects(char *obj_type_arg, char *display_count_arg)
562 struct acpi_walk_info info;
563 acpi_object_type type;
564 struct acpi_object_info *object_info;
566 u32 total_objects = 0;
568 /* No argument means display summary/count of all object types */
572 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_object_info));
574 /* Walk the namespace from the root */
576 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
578 acpi_db_walk_for_object_counts, NULL,
579 (void *)object_info, NULL);
581 acpi_os_printf("\nSummary of namespace objects:\n\n");
583 for (i = 0; i < ACPI_TOTAL_TYPES; i++) {
584 acpi_os_printf("%8u %s\n", object_info->types[i],
585 acpi_ut_get_type_name(i));
587 total_objects += object_info->types[i];
590 acpi_os_printf("\n%8u Total namespace objects\n\n",
593 ACPI_FREE(object_info);
597 /* Get the object type */
599 type = acpi_db_match_argument(obj_type_arg, acpi_db_object_types);
600 if (type == ACPI_TYPE_NOT_FOUND) {
601 acpi_os_printf("Invalid or unsupported argument\n");
605 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
607 ("Objects of type [%s] defined in the current ACPI Namespace:\n",
608 acpi_ut_get_type_name(type));
610 acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
613 info.owner_id = ACPI_OWNER_ID_MAX;
614 info.debug_level = ACPI_UINT32_MAX;
615 info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
617 /* Walk the namespace from the root */
619 (void)acpi_walk_namespace(type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
620 acpi_db_walk_for_specific_objects, NULL,
621 (void *)&info, NULL);
624 ("\nFound %u objects of type [%s] in the current ACPI Namespace\n",
625 info.count, acpi_ut_get_type_name(type));
627 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
631 /*******************************************************************************
633 * FUNCTION: acpi_db_integrity_walk
635 * PARAMETERS: Callback from walk_namespace
639 * DESCRIPTION: Examine one NS node for valid values.
641 ******************************************************************************/
644 acpi_db_integrity_walk(acpi_handle obj_handle,
645 u32 nesting_level, void *context, void **return_value)
647 struct acpi_integrity_info *info =
648 (struct acpi_integrity_info *)context;
649 struct acpi_namespace_node *node =
650 (struct acpi_namespace_node *)obj_handle;
651 union acpi_operand_object *object;
656 /* Verify the NS node, and dereference aliases */
659 if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
661 ("Invalid Descriptor Type for Node %p [%s] - "
662 "is %2.2X should be %2.2X\n", node,
663 acpi_ut_get_descriptor_name(node),
664 ACPI_GET_DESCRIPTOR_TYPE(node),
665 ACPI_DESC_TYPE_NAMED);
669 if ((node->type == ACPI_TYPE_LOCAL_ALIAS) ||
670 (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
671 node = (struct acpi_namespace_node *)node->object;
677 if (node->type > ACPI_TYPE_LOCAL_MAX) {
678 acpi_os_printf("Invalid Object Type for Node %p, Type = %X\n",
683 if (!acpi_ut_valid_nameseg(node->name.ascii)) {
684 acpi_os_printf("Invalid AcpiName for Node %p\n", node);
688 object = acpi_ns_get_attached_object(node);
691 if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
693 ("Invalid Descriptor Type for Object %p [%s]\n",
694 object, acpi_ut_get_descriptor_name(object));
701 /*******************************************************************************
703 * FUNCTION: acpi_db_check_integrity
709 * DESCRIPTION: Check entire namespace for data structure integrity
711 ******************************************************************************/
713 void acpi_db_check_integrity(void)
715 struct acpi_integrity_info info = { 0, 0 };
717 /* Search all nodes in namespace */
719 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
720 ACPI_UINT32_MAX, acpi_db_integrity_walk, NULL,
721 (void *)&info, NULL);
723 acpi_os_printf("Verified %u namespace nodes with %u Objects\n",
724 info.nodes, info.objects);
727 /*******************************************************************************
729 * FUNCTION: acpi_db_walk_for_references
731 * PARAMETERS: Callback from walk_namespace
735 * DESCRIPTION: Check if this namespace object refers to the target object
736 * that is passed in as the context value.
738 * Note: Currently doesn't check subobjects within the Node's object
740 ******************************************************************************/
743 acpi_db_walk_for_references(acpi_handle obj_handle,
745 void *context, void **return_value)
747 union acpi_operand_object *obj_desc =
748 (union acpi_operand_object *)context;
749 struct acpi_namespace_node *node =
750 (struct acpi_namespace_node *)obj_handle;
752 /* Check for match against the namespace node itself */
754 if (node == (void *)obj_desc) {
755 acpi_os_printf("Object is a Node [%4.4s]\n",
756 acpi_ut_get_node_name(node));
759 /* Check for match against the object attached to the node */
761 if (acpi_ns_get_attached_object(node) == obj_desc) {
762 acpi_os_printf("Reference at Node->Object %p [%4.4s]\n",
763 node, acpi_ut_get_node_name(node));
769 /*******************************************************************************
771 * FUNCTION: acpi_db_find_references
773 * PARAMETERS: object_arg - String with hex value of the object
777 * DESCRIPTION: Search namespace for all references to the input object
779 ******************************************************************************/
781 void acpi_db_find_references(char *object_arg)
783 union acpi_operand_object *obj_desc;
786 /* Convert string to object pointer */
788 address = strtoul(object_arg, NULL, 16);
789 obj_desc = ACPI_TO_POINTER(address);
791 /* Search all nodes in namespace */
793 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
794 ACPI_UINT32_MAX, acpi_db_walk_for_references,
795 NULL, (void *)obj_desc, NULL);
798 /*******************************************************************************
800 * FUNCTION: acpi_db_bus_walk
802 * PARAMETERS: Callback from walk_namespace
806 * DESCRIPTION: Display info about device objects that have a corresponding
809 ******************************************************************************/
812 acpi_db_bus_walk(acpi_handle obj_handle,
813 u32 nesting_level, void *context, void **return_value)
815 struct acpi_namespace_node *node =
816 (struct acpi_namespace_node *)obj_handle;
818 struct acpi_buffer buffer;
819 struct acpi_namespace_node *temp_node;
820 struct acpi_device_info *info;
823 if ((node->type != ACPI_TYPE_DEVICE) &&
824 (node->type != ACPI_TYPE_PROCESSOR)) {
828 /* Exit if there is no _PRT under this device */
830 status = acpi_get_handle(node, METHOD_NAME__PRT,
831 ACPI_CAST_PTR(acpi_handle, &temp_node));
832 if (ACPI_FAILURE(status)) {
836 /* Get the full path to this device object */
838 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
839 status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
840 if (ACPI_FAILURE(status)) {
841 acpi_os_printf("Could Not get pathname for object %p\n",
846 status = acpi_get_object_info(obj_handle, &info);
847 if (ACPI_FAILURE(status)) {
851 /* Display the full path */
853 acpi_os_printf("%-32s Type %X", (char *)buffer.pointer, node->type);
854 ACPI_FREE(buffer.pointer);
856 if (info->flags & ACPI_PCI_ROOT_BRIDGE) {
857 acpi_os_printf(" - Is PCI Root Bridge");
859 acpi_os_printf("\n");
863 acpi_os_printf("_PRT: %p\n", temp_node);
865 /* Dump _ADR, _HID, _UID, _CID */
867 if (info->valid & ACPI_VALID_ADR) {
868 acpi_os_printf("_ADR: %8.8X%8.8X\n",
869 ACPI_FORMAT_UINT64(info->address));
871 acpi_os_printf("_ADR: <Not Present>\n");
874 if (info->valid & ACPI_VALID_HID) {
875 acpi_os_printf("_HID: %s\n", info->hardware_id.string);
877 acpi_os_printf("_HID: <Not Present>\n");
880 if (info->valid & ACPI_VALID_UID) {
881 acpi_os_printf("_UID: %s\n", info->unique_id.string);
883 acpi_os_printf("_UID: <Not Present>\n");
886 if (info->valid & ACPI_VALID_CID) {
887 for (i = 0; i < info->compatible_id_list.count; i++) {
888 acpi_os_printf("_CID: %s\n",
889 info->compatible_id_list.ids[i].string);
892 acpi_os_printf("_CID: <Not Present>\n");
899 /*******************************************************************************
901 * FUNCTION: acpi_db_get_bus_info
907 * DESCRIPTION: Display info about system buses.
909 ******************************************************************************/
911 void acpi_db_get_bus_info(void)
913 /* Search all nodes in namespace */
915 (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
916 ACPI_UINT32_MAX, acpi_db_bus_walk, NULL, NULL,