• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
3  *
4  * Module Name: dbnames - Debugger commands for the acpi namespace
5  *
6  ******************************************************************************/
7 
8 #include <acpi/acpi.h>
9 #include "accommon.h"
10 #include "acnamesp.h"
11 #include "acdebug.h"
12 #include "acpredef.h"
13 
14 #define _COMPONENT          ACPI_CA_DEBUGGER
15 ACPI_MODULE_NAME("dbnames")
16 
17 /* Local prototypes */
18 static acpi_status
19 acpi_db_walk_and_match_name(acpi_handle obj_handle,
20 			    u32 nesting_level,
21 			    void *context, void **return_value);
22 
23 static acpi_status
24 acpi_db_walk_for_predefined_names(acpi_handle obj_handle,
25 				  u32 nesting_level,
26 				  void *context, void **return_value);
27 
28 static acpi_status
29 acpi_db_walk_for_specific_objects(acpi_handle obj_handle,
30 				  u32 nesting_level,
31 				  void *context, void **return_value);
32 
33 static acpi_status
34 acpi_db_walk_for_object_counts(acpi_handle obj_handle,
35 			       u32 nesting_level,
36 			       void *context, void **return_value);
37 
38 static acpi_status
39 acpi_db_integrity_walk(acpi_handle obj_handle,
40 		       u32 nesting_level, void *context, void **return_value);
41 
42 static acpi_status
43 acpi_db_walk_for_references(acpi_handle obj_handle,
44 			    u32 nesting_level,
45 			    void *context, void **return_value);
46 
47 static acpi_status
48 acpi_db_bus_walk(acpi_handle obj_handle,
49 		 u32 nesting_level, void *context, void **return_value);
50 
51 /*
52  * Arguments for the Objects command
53  * These object types map directly to the ACPI_TYPES
54  */
55 static struct acpi_db_argument_info acpi_db_object_types[] = {
56 	{"ANY"},
57 	{"INTEGERS"},
58 	{"STRINGS"},
59 	{"BUFFERS"},
60 	{"PACKAGES"},
61 	{"FIELDS"},
62 	{"DEVICES"},
63 	{"EVENTS"},
64 	{"METHODS"},
65 	{"MUTEXES"},
66 	{"REGIONS"},
67 	{"POWERRESOURCES"},
68 	{"PROCESSORS"},
69 	{"THERMALZONES"},
70 	{"BUFFERFIELDS"},
71 	{"DDBHANDLES"},
72 	{"DEBUG"},
73 	{"REGIONFIELDS"},
74 	{"BANKFIELDS"},
75 	{"INDEXFIELDS"},
76 	{"REFERENCES"},
77 	{"ALIASES"},
78 	{"METHODALIASES"},
79 	{"NOTIFY"},
80 	{"ADDRESSHANDLER"},
81 	{"RESOURCE"},
82 	{"RESOURCEFIELD"},
83 	{"SCOPES"},
84 	{NULL}			/* Must be null terminated */
85 };
86 
87 /*******************************************************************************
88  *
89  * FUNCTION:    acpi_db_set_scope
90  *
91  * PARAMETERS:  name                - New scope path
92  *
93  * RETURN:      Status
94  *
95  * DESCRIPTION: Set the "current scope" as maintained by this utility.
96  *              The scope is used as a prefix to ACPI paths.
97  *
98  ******************************************************************************/
99 
acpi_db_set_scope(char * name)100 void acpi_db_set_scope(char *name)
101 {
102 	acpi_status status;
103 	struct acpi_namespace_node *node;
104 
105 	if (!name || name[0] == 0) {
106 		acpi_os_printf("Current scope: %s\n", acpi_gbl_db_scope_buf);
107 		return;
108 	}
109 
110 	acpi_db_prep_namestring(name);
111 
112 	if (ACPI_IS_ROOT_PREFIX(name[0])) {
113 
114 		/* Validate new scope from the root */
115 
116 		status = acpi_ns_get_node(acpi_gbl_root_node, name,
117 					  ACPI_NS_NO_UPSEARCH, &node);
118 		if (ACPI_FAILURE(status)) {
119 			goto error_exit;
120 		}
121 
122 		acpi_gbl_db_scope_buf[0] = 0;
123 	} else {
124 		/* Validate new scope relative to old scope */
125 
126 		status = acpi_ns_get_node(acpi_gbl_db_scope_node, name,
127 					  ACPI_NS_NO_UPSEARCH, &node);
128 		if (ACPI_FAILURE(status)) {
129 			goto error_exit;
130 		}
131 	}
132 
133 	/* Build the final pathname */
134 
135 	if (acpi_ut_safe_strcat
136 	    (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), name)) {
137 		status = AE_BUFFER_OVERFLOW;
138 		goto error_exit;
139 	}
140 
141 	if (acpi_ut_safe_strcat
142 	    (acpi_gbl_db_scope_buf, sizeof(acpi_gbl_db_scope_buf), "\\")) {
143 		status = AE_BUFFER_OVERFLOW;
144 		goto error_exit;
145 	}
146 
147 	acpi_gbl_db_scope_node = node;
148 	acpi_os_printf("New scope: %s\n", acpi_gbl_db_scope_buf);
149 	return;
150 
151 error_exit:
152 
153 	acpi_os_printf("Could not attach scope: %s, %s\n",
154 		       name, acpi_format_exception(status));
155 }
156 
157 /*******************************************************************************
158  *
159  * FUNCTION:    acpi_db_dump_namespace
160  *
161  * PARAMETERS:  start_arg       - Node to begin namespace dump
162  *              depth_arg       - Maximum tree depth to be dumped
163  *
164  * RETURN:      None
165  *
166  * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
167  *              with type and other information.
168  *
169  ******************************************************************************/
170 
acpi_db_dump_namespace(char * start_arg,char * depth_arg)171 void acpi_db_dump_namespace(char *start_arg, char *depth_arg)
172 {
173 	acpi_handle subtree_entry = acpi_gbl_root_node;
174 	u32 max_depth = ACPI_UINT32_MAX;
175 
176 	/* No argument given, just start at the root and dump entire namespace */
177 
178 	if (start_arg) {
179 		subtree_entry = acpi_db_convert_to_node(start_arg);
180 		if (!subtree_entry) {
181 			return;
182 		}
183 
184 		/* Now we can check for the depth argument */
185 
186 		if (depth_arg) {
187 			max_depth = strtoul(depth_arg, NULL, 0);
188 		}
189 	}
190 
191 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
192 
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);
197 	} else {
198 		acpi_os_printf("ACPI Namespace (from %s):\n",
199 			       ACPI_NAMESPACE_ROOT);
200 	}
201 
202 	/* Display the subtree */
203 
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);
208 }
209 
210 /*******************************************************************************
211  *
212  * FUNCTION:    acpi_db_dump_namespace_paths
213  *
214  * PARAMETERS:  None
215  *
216  * RETURN:      None
217  *
218  * DESCRIPTION: Dump entire namespace with full object pathnames and object
219  *              type information. Alternative to "namespace" command.
220  *
221  ******************************************************************************/
222 
acpi_db_dump_namespace_paths(void)223 void acpi_db_dump_namespace_paths(void)
224 {
225 
226 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
227 	acpi_os_printf("ACPI Namespace (from root):\n");
228 
229 	/* Display the entire namespace */
230 
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,
234 				  acpi_gbl_root_node);
235 
236 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
237 }
238 
239 /*******************************************************************************
240  *
241  * FUNCTION:    acpi_db_dump_namespace_by_owner
242  *
243  * PARAMETERS:  owner_arg       - Owner ID whose nodes will be displayed
244  *              depth_arg       - Maximum tree depth to be dumped
245  *
246  * RETURN:      None
247  *
248  * DESCRIPTION: Dump elements of the namespace that are owned by the owner_id.
249  *
250  ******************************************************************************/
251 
acpi_db_dump_namespace_by_owner(char * owner_arg,char * depth_arg)252 void acpi_db_dump_namespace_by_owner(char *owner_arg, char *depth_arg)
253 {
254 	acpi_handle subtree_entry = acpi_gbl_root_node;
255 	u32 max_depth = ACPI_UINT32_MAX;
256 	acpi_owner_id owner_id;
257 
258 	owner_id = (acpi_owner_id)strtoul(owner_arg, NULL, 0);
259 
260 	/* Now we can check for the depth argument */
261 
262 	if (depth_arg) {
263 		max_depth = strtoul(depth_arg, NULL, 0);
264 	}
265 
266 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
267 	acpi_os_printf("ACPI Namespace by owner %X:\n", owner_id);
268 
269 	/* Display the subtree */
270 
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);
275 }
276 
277 /*******************************************************************************
278  *
279  * FUNCTION:    acpi_db_walk_and_match_name
280  *
281  * PARAMETERS:  Callback from walk_namespace
282  *
283  * RETURN:      Status
284  *
285  * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
286  *              are supported -- '?' matches any character.
287  *
288  ******************************************************************************/
289 
290 static acpi_status
acpi_db_walk_and_match_name(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)291 acpi_db_walk_and_match_name(acpi_handle obj_handle,
292 			    u32 nesting_level,
293 			    void *context, void **return_value)
294 {
295 	acpi_status status;
296 	char *requested_name = (char *)context;
297 	u32 i;
298 	struct acpi_buffer buffer;
299 	struct acpi_walk_info info;
300 
301 	/* Check for a name match */
302 
303 	for (i = 0; i < 4; i++) {
304 
305 		/* Wildcard support */
306 
307 		if ((requested_name[i] != '?') &&
308 		    (requested_name[i] != ((struct acpi_namespace_node *)
309 					   obj_handle)->name.ascii[i])) {
310 
311 			/* No match, just exit */
312 
313 			return (AE_OK);
314 		}
315 	}
316 
317 	/* Get the full pathname to this object */
318 
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",
323 			       obj_handle);
324 	} else {
325 		info.count = 0;
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;
329 
330 		acpi_os_printf("%32s", (char *)buffer.pointer);
331 		(void)acpi_ns_dump_one_object(obj_handle, nesting_level, &info,
332 					      NULL);
333 		ACPI_FREE(buffer.pointer);
334 	}
335 
336 	return (AE_OK);
337 }
338 
339 /*******************************************************************************
340  *
341  * FUNCTION:    acpi_db_find_name_in_namespace
342  *
343  * PARAMETERS:  name_arg        - The 4-character ACPI name to find.
344  *                                wildcards are supported.
345  *
346  * RETURN:      None
347  *
348  * DESCRIPTION: Search the namespace for a given name (with wildcards)
349  *
350  ******************************************************************************/
351 
acpi_db_find_name_in_namespace(char * name_arg)352 acpi_status acpi_db_find_name_in_namespace(char *name_arg)
353 {
354 	char acpi_name[5] = "____";
355 	char *acpi_name_ptr = acpi_name;
356 
357 	if (strlen(name_arg) > ACPI_NAMESEG_SIZE) {
358 		acpi_os_printf("Name must be no longer than 4 characters\n");
359 		return (AE_OK);
360 	}
361 
362 	/* Pad out name with underscores as necessary to create a 4-char name */
363 
364 	acpi_ut_strupr(name_arg);
365 	while (*name_arg) {
366 		*acpi_name_ptr = *name_arg;
367 		acpi_name_ptr++;
368 		name_arg++;
369 	}
370 
371 	/* Walk the namespace from the root */
372 
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);
376 
377 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
378 	return (AE_OK);
379 }
380 
381 /*******************************************************************************
382  *
383  * FUNCTION:    acpi_db_walk_for_predefined_names
384  *
385  * PARAMETERS:  Callback from walk_namespace
386  *
387  * RETURN:      Status
388  *
389  * DESCRIPTION: Detect and display predefined ACPI names (names that start with
390  *              an underscore)
391  *
392  ******************************************************************************/
393 
394 static acpi_status
acpi_db_walk_for_predefined_names(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)395 acpi_db_walk_for_predefined_names(acpi_handle obj_handle,
396 				  u32 nesting_level,
397 				  void *context, void **return_value)
398 {
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;
404 	char *pathname;
405 	char string_buffer[48];
406 
407 	predefined = acpi_ut_match_predefined_method(node->name.ascii);
408 	if (!predefined) {
409 		return (AE_OK);
410 	}
411 
412 	pathname = acpi_ns_get_normalized_pathname(node, TRUE);
413 	if (!pathname) {
414 		return (AE_OK);
415 	}
416 
417 	/* If method returns a package, the info is in the next table entry */
418 
419 	if (predefined->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
420 		package = predefined + 1;
421 	}
422 
423 	acpi_ut_get_expected_return_types(string_buffer,
424 					  predefined->info.expected_btypes);
425 
426 	acpi_os_printf("%-32s Arguments %X, Return Types: %s", pathname,
427 		       METHOD_GET_ARG_COUNT(predefined->info.argument_list),
428 		       string_buffer);
429 
430 	if (package) {
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);
435 	}
436 
437 	acpi_os_printf("\n");
438 
439 	/* Check that the declared argument count matches the ACPI spec */
440 
441 	acpi_ns_check_acpi_compliance(pathname, node, predefined);
442 
443 	ACPI_FREE(pathname);
444 	(*count)++;
445 	return (AE_OK);
446 }
447 
448 /*******************************************************************************
449  *
450  * FUNCTION:    acpi_db_check_predefined_names
451  *
452  * PARAMETERS:  None
453  *
454  * RETURN:      None
455  *
456  * DESCRIPTION: Validate all predefined names in the namespace
457  *
458  ******************************************************************************/
459 
acpi_db_check_predefined_names(void)460 void acpi_db_check_predefined_names(void)
461 {
462 	u32 count = 0;
463 
464 	/* Search all nodes in namespace */
465 
466 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
467 				  ACPI_UINT32_MAX,
468 				  acpi_db_walk_for_predefined_names, NULL,
469 				  (void *)&count, NULL);
470 
471 	acpi_os_printf("Found %u predefined names in the namespace\n", count);
472 }
473 
474 /*******************************************************************************
475  *
476  * FUNCTION:    acpi_db_walk_for_object_counts
477  *
478  * PARAMETERS:  Callback from walk_namespace
479  *
480  * RETURN:      Status
481  *
482  * DESCRIPTION: Display short info about objects in the namespace
483  *
484  ******************************************************************************/
485 
486 static acpi_status
acpi_db_walk_for_object_counts(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)487 acpi_db_walk_for_object_counts(acpi_handle obj_handle,
488 			       u32 nesting_level,
489 			       void *context, void **return_value)
490 {
491 	struct acpi_object_info *info = (struct acpi_object_info *)context;
492 	struct acpi_namespace_node *node =
493 	    (struct acpi_namespace_node *)obj_handle;
494 
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);
498 	} else {
499 		info->types[node->type]++;
500 	}
501 
502 	return (AE_OK);
503 }
504 
505 /*******************************************************************************
506  *
507  * FUNCTION:    acpi_db_walk_for_specific_objects
508  *
509  * PARAMETERS:  Callback from walk_namespace
510  *
511  * RETURN:      Status
512  *
513  * DESCRIPTION: Display short info about objects in the namespace
514  *
515  ******************************************************************************/
516 
517 static acpi_status
acpi_db_walk_for_specific_objects(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)518 acpi_db_walk_for_specific_objects(acpi_handle obj_handle,
519 				  u32 nesting_level,
520 				  void *context, void **return_value)
521 {
522 	struct acpi_walk_info *info = (struct acpi_walk_info *)context;
523 	struct acpi_buffer buffer;
524 	acpi_status status;
525 
526 	info->count++;
527 
528 	/* Get and display the full pathname to this object */
529 
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",
534 			       obj_handle);
535 		return (AE_OK);
536 	}
537 
538 	acpi_os_printf("%32s", (char *)buffer.pointer);
539 	ACPI_FREE(buffer.pointer);
540 
541 	/* Dump short info about the object */
542 
543 	(void)acpi_ns_dump_one_object(obj_handle, nesting_level, info, NULL);
544 	return (AE_OK);
545 }
546 
547 /*******************************************************************************
548  *
549  * FUNCTION:    acpi_db_display_objects
550  *
551  * PARAMETERS:  obj_type_arg        - Type of object to display
552  *              display_count_arg   - Max depth to display
553  *
554  * RETURN:      None
555  *
556  * DESCRIPTION: Display objects in the namespace of the requested type
557  *
558  ******************************************************************************/
559 
acpi_db_display_objects(char * obj_type_arg,char * display_count_arg)560 acpi_status acpi_db_display_objects(char *obj_type_arg, char *display_count_arg)
561 {
562 	struct acpi_walk_info info;
563 	acpi_object_type type;
564 	struct acpi_object_info *object_info;
565 	u32 i;
566 	u32 total_objects = 0;
567 
568 	/* No argument means display summary/count of all object types */
569 
570 	if (!obj_type_arg) {
571 		object_info =
572 		    ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_object_info));
573 
574 		if (!object_info)
575 			return (AE_NO_MEMORY);
576 
577 		/* Walk the namespace from the root */
578 
579 		(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
580 					  ACPI_UINT32_MAX,
581 					  acpi_db_walk_for_object_counts, NULL,
582 					  (void *)object_info, NULL);
583 
584 		acpi_os_printf("\nSummary of namespace objects:\n\n");
585 
586 		for (i = 0; i < ACPI_TOTAL_TYPES; i++) {
587 			acpi_os_printf("%8u %s\n", object_info->types[i],
588 				       acpi_ut_get_type_name(i));
589 
590 			total_objects += object_info->types[i];
591 		}
592 
593 		acpi_os_printf("\n%8u Total namespace objects\n\n",
594 			       total_objects);
595 
596 		ACPI_FREE(object_info);
597 		return (AE_OK);
598 	}
599 
600 	/* Get the object type */
601 
602 	type = acpi_db_match_argument(obj_type_arg, acpi_db_object_types);
603 	if (type == ACPI_TYPE_NOT_FOUND) {
604 		acpi_os_printf("Invalid or unsupported argument\n");
605 		return (AE_OK);
606 	}
607 
608 	acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
609 	acpi_os_printf
610 	    ("Objects of type [%s] defined in the current ACPI Namespace:\n",
611 	     acpi_ut_get_type_name(type));
612 
613 	acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
614 
615 	info.count = 0;
616 	info.owner_id = ACPI_OWNER_ID_MAX;
617 	info.debug_level = ACPI_UINT32_MAX;
618 	info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
619 
620 	/* Walk the namespace from the root */
621 
622 	(void)acpi_walk_namespace(type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
623 				  acpi_db_walk_for_specific_objects, NULL,
624 				  (void *)&info, NULL);
625 
626 	acpi_os_printf
627 	    ("\nFound %u objects of type [%s] in the current ACPI Namespace\n",
628 	     info.count, acpi_ut_get_type_name(type));
629 
630 	acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
631 	return (AE_OK);
632 }
633 
634 /*******************************************************************************
635  *
636  * FUNCTION:    acpi_db_integrity_walk
637  *
638  * PARAMETERS:  Callback from walk_namespace
639  *
640  * RETURN:      Status
641  *
642  * DESCRIPTION: Examine one NS node for valid values.
643  *
644  ******************************************************************************/
645 
646 static acpi_status
acpi_db_integrity_walk(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)647 acpi_db_integrity_walk(acpi_handle obj_handle,
648 		       u32 nesting_level, void *context, void **return_value)
649 {
650 	struct acpi_integrity_info *info =
651 	    (struct acpi_integrity_info *)context;
652 	struct acpi_namespace_node *node =
653 	    (struct acpi_namespace_node *)obj_handle;
654 	union acpi_operand_object *object;
655 	u8 alias = TRUE;
656 
657 	info->nodes++;
658 
659 	/* Verify the NS node, and dereference aliases */
660 
661 	while (alias) {
662 		if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
663 			acpi_os_printf
664 			    ("Invalid Descriptor Type for Node %p [%s] - "
665 			     "is %2.2X should be %2.2X\n", node,
666 			     acpi_ut_get_descriptor_name(node),
667 			     ACPI_GET_DESCRIPTOR_TYPE(node),
668 			     ACPI_DESC_TYPE_NAMED);
669 			return (AE_OK);
670 		}
671 
672 		if ((node->type == ACPI_TYPE_LOCAL_ALIAS) ||
673 		    (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
674 			node = (struct acpi_namespace_node *)node->object;
675 		} else {
676 			alias = FALSE;
677 		}
678 	}
679 
680 	if (node->type > ACPI_TYPE_LOCAL_MAX) {
681 		acpi_os_printf("Invalid Object Type for Node %p, Type = %X\n",
682 			       node, node->type);
683 		return (AE_OK);
684 	}
685 
686 	if (!acpi_ut_valid_nameseg(node->name.ascii)) {
687 		acpi_os_printf("Invalid AcpiName for Node %p\n", node);
688 		return (AE_OK);
689 	}
690 
691 	object = acpi_ns_get_attached_object(node);
692 	if (object) {
693 		info->objects++;
694 		if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
695 			acpi_os_printf
696 			    ("Invalid Descriptor Type for Object %p [%s]\n",
697 			     object, acpi_ut_get_descriptor_name(object));
698 		}
699 	}
700 
701 	return (AE_OK);
702 }
703 
704 /*******************************************************************************
705  *
706  * FUNCTION:    acpi_db_check_integrity
707  *
708  * PARAMETERS:  None
709  *
710  * RETURN:      None
711  *
712  * DESCRIPTION: Check entire namespace for data structure integrity
713  *
714  ******************************************************************************/
715 
acpi_db_check_integrity(void)716 void acpi_db_check_integrity(void)
717 {
718 	struct acpi_integrity_info info = { 0, 0 };
719 
720 	/* Search all nodes in namespace */
721 
722 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
723 				  ACPI_UINT32_MAX, acpi_db_integrity_walk, NULL,
724 				  (void *)&info, NULL);
725 
726 	acpi_os_printf("Verified %u namespace nodes with %u Objects\n",
727 		       info.nodes, info.objects);
728 }
729 
730 /*******************************************************************************
731  *
732  * FUNCTION:    acpi_db_walk_for_references
733  *
734  * PARAMETERS:  Callback from walk_namespace
735  *
736  * RETURN:      Status
737  *
738  * DESCRIPTION: Check if this namespace object refers to the target object
739  *              that is passed in as the context value.
740  *
741  * Note: Currently doesn't check subobjects within the Node's object
742  *
743  ******************************************************************************/
744 
745 static acpi_status
acpi_db_walk_for_references(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)746 acpi_db_walk_for_references(acpi_handle obj_handle,
747 			    u32 nesting_level,
748 			    void *context, void **return_value)
749 {
750 	union acpi_operand_object *obj_desc =
751 	    (union acpi_operand_object *)context;
752 	struct acpi_namespace_node *node =
753 	    (struct acpi_namespace_node *)obj_handle;
754 
755 	/* Check for match against the namespace node itself */
756 
757 	if (node == (void *)obj_desc) {
758 		acpi_os_printf("Object is a Node [%4.4s]\n",
759 			       acpi_ut_get_node_name(node));
760 	}
761 
762 	/* Check for match against the object attached to the node */
763 
764 	if (acpi_ns_get_attached_object(node) == obj_desc) {
765 		acpi_os_printf("Reference at Node->Object %p [%4.4s]\n",
766 			       node, acpi_ut_get_node_name(node));
767 	}
768 
769 	return (AE_OK);
770 }
771 
772 /*******************************************************************************
773  *
774  * FUNCTION:    acpi_db_find_references
775  *
776  * PARAMETERS:  object_arg      - String with hex value of the object
777  *
778  * RETURN:      None
779  *
780  * DESCRIPTION: Search namespace for all references to the input object
781  *
782  ******************************************************************************/
783 
acpi_db_find_references(char * object_arg)784 void acpi_db_find_references(char *object_arg)
785 {
786 	union acpi_operand_object *obj_desc;
787 	acpi_size address;
788 
789 	/* Convert string to object pointer */
790 
791 	address = strtoul(object_arg, NULL, 16);
792 	obj_desc = ACPI_TO_POINTER(address);
793 
794 	/* Search all nodes in namespace */
795 
796 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
797 				  ACPI_UINT32_MAX, acpi_db_walk_for_references,
798 				  NULL, (void *)obj_desc, NULL);
799 }
800 
801 /*******************************************************************************
802  *
803  * FUNCTION:    acpi_db_bus_walk
804  *
805  * PARAMETERS:  Callback from walk_namespace
806  *
807  * RETURN:      Status
808  *
809  * DESCRIPTION: Display info about device objects that have a corresponding
810  *              _PRT method.
811  *
812  ******************************************************************************/
813 
814 static acpi_status
acpi_db_bus_walk(acpi_handle obj_handle,u32 nesting_level,void * context,void ** return_value)815 acpi_db_bus_walk(acpi_handle obj_handle,
816 		 u32 nesting_level, void *context, void **return_value)
817 {
818 	struct acpi_namespace_node *node =
819 	    (struct acpi_namespace_node *)obj_handle;
820 	acpi_status status;
821 	struct acpi_buffer buffer;
822 	struct acpi_namespace_node *temp_node;
823 	struct acpi_device_info *info;
824 	u32 i;
825 
826 	if ((node->type != ACPI_TYPE_DEVICE) &&
827 	    (node->type != ACPI_TYPE_PROCESSOR)) {
828 		return (AE_OK);
829 	}
830 
831 	/* Exit if there is no _PRT under this device */
832 
833 	status = acpi_get_handle(node, METHOD_NAME__PRT,
834 				 ACPI_CAST_PTR(acpi_handle, &temp_node));
835 	if (ACPI_FAILURE(status)) {
836 		return (AE_OK);
837 	}
838 
839 	/* Get the full path to this device object */
840 
841 	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
842 	status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
843 	if (ACPI_FAILURE(status)) {
844 		acpi_os_printf("Could Not get pathname for object %p\n",
845 			       obj_handle);
846 		return (AE_OK);
847 	}
848 
849 	status = acpi_get_object_info(obj_handle, &info);
850 	if (ACPI_FAILURE(status)) {
851 		return (AE_OK);
852 	}
853 
854 	/* Display the full path */
855 
856 	acpi_os_printf("%-32s Type %X", (char *)buffer.pointer, node->type);
857 	ACPI_FREE(buffer.pointer);
858 
859 	if (info->flags & ACPI_PCI_ROOT_BRIDGE) {
860 		acpi_os_printf(" - Is PCI Root Bridge");
861 	}
862 	acpi_os_printf("\n");
863 
864 	/* _PRT info */
865 
866 	acpi_os_printf("_PRT: %p\n", temp_node);
867 
868 	/* Dump _ADR, _HID, _UID, _CID */
869 
870 	if (info->valid & ACPI_VALID_ADR) {
871 		acpi_os_printf("_ADR: %8.8X%8.8X\n",
872 			       ACPI_FORMAT_UINT64(info->address));
873 	} else {
874 		acpi_os_printf("_ADR: <Not Present>\n");
875 	}
876 
877 	if (info->valid & ACPI_VALID_HID) {
878 		acpi_os_printf("_HID: %s\n", info->hardware_id.string);
879 	} else {
880 		acpi_os_printf("_HID: <Not Present>\n");
881 	}
882 
883 	if (info->valid & ACPI_VALID_UID) {
884 		acpi_os_printf("_UID: %s\n", info->unique_id.string);
885 	} else {
886 		acpi_os_printf("_UID: <Not Present>\n");
887 	}
888 
889 	if (info->valid & ACPI_VALID_CID) {
890 		for (i = 0; i < info->compatible_id_list.count; i++) {
891 			acpi_os_printf("_CID: %s\n",
892 				       info->compatible_id_list.ids[i].string);
893 		}
894 	} else {
895 		acpi_os_printf("_CID: <Not Present>\n");
896 	}
897 
898 	ACPI_FREE(info);
899 	return (AE_OK);
900 }
901 
902 /*******************************************************************************
903  *
904  * FUNCTION:    acpi_db_get_bus_info
905  *
906  * PARAMETERS:  None
907  *
908  * RETURN:      None
909  *
910  * DESCRIPTION: Display info about system buses.
911  *
912  ******************************************************************************/
913 
acpi_db_get_bus_info(void)914 void acpi_db_get_bus_info(void)
915 {
916 	/* Search all nodes in namespace */
917 
918 	(void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
919 				  ACPI_UINT32_MAX, acpi_db_bus_walk, NULL, NULL,
920 				  NULL);
921 }
922