dbnames.c 27 KB

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