dbnames.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  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. acpi_evaluate_object(obj_handle, NULL, NULL, &buffer);
  455. /*
  456. * Since this is a field unit, surround the output in braces
  457. */
  458. acpi_os_printf("{");
  459. ret_value = (union acpi_object *)buffer.pointer;
  460. switch (ret_value->type) {
  461. case ACPI_TYPE_INTEGER:
  462. acpi_os_printf("%8.8X%8.8X",
  463. ACPI_FORMAT_UINT64(ret_value->integer.value));
  464. break;
  465. case ACPI_TYPE_BUFFER:
  466. acpi_ut_dump_buffer(ret_value->buffer.pointer,
  467. ret_value->buffer.length,
  468. DB_DISPLAY_DATA_ONLY | DB_BYTE_DISPLAY, 0);
  469. break;
  470. default:
  471. break;
  472. }
  473. acpi_os_printf("}\n");
  474. ACPI_FREE(buffer.pointer);
  475. return (AE_OK);
  476. }
  477. /*******************************************************************************
  478. *
  479. * FUNCTION: acpi_db_walk_for_specific_objects
  480. *
  481. * PARAMETERS: Callback from walk_namespace
  482. *
  483. * RETURN: Status
  484. *
  485. * DESCRIPTION: Display short info about objects in the namespace
  486. *
  487. ******************************************************************************/
  488. static acpi_status
  489. acpi_db_walk_for_specific_objects(acpi_handle obj_handle,
  490. u32 nesting_level,
  491. void *context, void **return_value)
  492. {
  493. struct acpi_walk_info *info = (struct acpi_walk_info *)context;
  494. struct acpi_buffer buffer;
  495. acpi_status status;
  496. info->count++;
  497. /* Get and display the full pathname to this object */
  498. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  499. status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
  500. if (ACPI_FAILURE(status)) {
  501. acpi_os_printf("Could Not get pathname for object %p\n",
  502. obj_handle);
  503. return (AE_OK);
  504. }
  505. acpi_os_printf("%32s", (char *)buffer.pointer);
  506. ACPI_FREE(buffer.pointer);
  507. /* Dump short info about the object */
  508. (void)acpi_ns_dump_one_object(obj_handle, nesting_level, info, NULL);
  509. return (AE_OK);
  510. }
  511. /*******************************************************************************
  512. *
  513. * FUNCTION: acpi_db_display_objects
  514. *
  515. * PARAMETERS: obj_type_arg - Type of object to display
  516. * display_count_arg - Max depth to display
  517. *
  518. * RETURN: None
  519. *
  520. * DESCRIPTION: Display objects in the namespace of the requested type
  521. *
  522. ******************************************************************************/
  523. acpi_status acpi_db_display_objects(char *obj_type_arg, char *display_count_arg)
  524. {
  525. struct acpi_walk_info info;
  526. acpi_object_type type;
  527. struct acpi_object_info *object_info;
  528. u32 i;
  529. u32 total_objects = 0;
  530. /* No argument means display summary/count of all object types */
  531. if (!obj_type_arg) {
  532. object_info =
  533. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_object_info));
  534. if (!object_info)
  535. return (AE_NO_MEMORY);
  536. /* Walk the namespace from the root */
  537. (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  538. ACPI_UINT32_MAX,
  539. acpi_db_walk_for_object_counts, NULL,
  540. (void *)object_info, NULL);
  541. acpi_os_printf("\nSummary of namespace objects:\n\n");
  542. for (i = 0; i < ACPI_TOTAL_TYPES; i++) {
  543. acpi_os_printf("%8u %s\n", object_info->types[i],
  544. acpi_ut_get_type_name(i));
  545. total_objects += object_info->types[i];
  546. }
  547. acpi_os_printf("\n%8u Total namespace objects\n\n",
  548. total_objects);
  549. ACPI_FREE(object_info);
  550. return (AE_OK);
  551. }
  552. /* Get the object type */
  553. type = acpi_db_match_argument(obj_type_arg, acpi_db_object_types);
  554. if (type == ACPI_TYPE_NOT_FOUND) {
  555. acpi_os_printf("Invalid or unsupported argument\n");
  556. return (AE_OK);
  557. }
  558. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  559. acpi_os_printf
  560. ("Objects of type [%s] defined in the current ACPI Namespace:\n",
  561. acpi_ut_get_type_name(type));
  562. acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
  563. info.count = 0;
  564. info.owner_id = ACPI_OWNER_ID_MAX;
  565. info.debug_level = ACPI_UINT32_MAX;
  566. info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
  567. /* Walk the namespace from the root */
  568. (void)acpi_walk_namespace(type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
  569. acpi_db_walk_for_specific_objects, NULL,
  570. (void *)&info, NULL);
  571. acpi_os_printf
  572. ("\nFound %u objects of type [%s] in the current ACPI Namespace\n",
  573. info.count, acpi_ut_get_type_name(type));
  574. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  575. return (AE_OK);
  576. }
  577. /*******************************************************************************
  578. *
  579. * FUNCTION: acpi_db_display_fields
  580. *
  581. * PARAMETERS: obj_type_arg - Type of object to display
  582. * display_count_arg - Max depth to display
  583. *
  584. * RETURN: None
  585. *
  586. * DESCRIPTION: Display objects in the namespace of the requested type
  587. *
  588. ******************************************************************************/
  589. acpi_status acpi_db_display_fields(u32 address_space_id)
  590. {
  591. struct acpi_region_walk_info info;
  592. info.count = 0;
  593. info.owner_id = ACPI_OWNER_ID_MAX;
  594. info.debug_level = ACPI_UINT32_MAX;
  595. info.display_type = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
  596. info.address_space_id = address_space_id;
  597. /* Walk the namespace from the root */
  598. (void)acpi_walk_namespace(ACPI_TYPE_LOCAL_REGION_FIELD,
  599. ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
  600. acpi_db_walk_for_fields, NULL, (void *)&info,
  601. NULL);
  602. return (AE_OK);
  603. }
  604. /*******************************************************************************
  605. *
  606. * FUNCTION: acpi_db_integrity_walk
  607. *
  608. * PARAMETERS: Callback from walk_namespace
  609. *
  610. * RETURN: Status
  611. *
  612. * DESCRIPTION: Examine one NS node for valid values.
  613. *
  614. ******************************************************************************/
  615. static acpi_status
  616. acpi_db_integrity_walk(acpi_handle obj_handle,
  617. u32 nesting_level, void *context, void **return_value)
  618. {
  619. struct acpi_integrity_info *info =
  620. (struct acpi_integrity_info *)context;
  621. struct acpi_namespace_node *node =
  622. (struct acpi_namespace_node *)obj_handle;
  623. union acpi_operand_object *object;
  624. u8 alias = TRUE;
  625. info->nodes++;
  626. /* Verify the NS node, and dereference aliases */
  627. while (alias) {
  628. if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
  629. acpi_os_printf
  630. ("Invalid Descriptor Type for Node %p [%s] - "
  631. "is %2.2X should be %2.2X\n", node,
  632. acpi_ut_get_descriptor_name(node),
  633. ACPI_GET_DESCRIPTOR_TYPE(node),
  634. ACPI_DESC_TYPE_NAMED);
  635. return (AE_OK);
  636. }
  637. if ((node->type == ACPI_TYPE_LOCAL_ALIAS) ||
  638. (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  639. node = (struct acpi_namespace_node *)node->object;
  640. } else {
  641. alias = FALSE;
  642. }
  643. }
  644. if (node->type > ACPI_TYPE_LOCAL_MAX) {
  645. acpi_os_printf("Invalid Object Type for Node %p, Type = %X\n",
  646. node, node->type);
  647. return (AE_OK);
  648. }
  649. if (!acpi_ut_valid_nameseg(node->name.ascii)) {
  650. acpi_os_printf("Invalid AcpiName for Node %p\n", node);
  651. return (AE_OK);
  652. }
  653. object = acpi_ns_get_attached_object(node);
  654. if (object) {
  655. info->objects++;
  656. if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
  657. acpi_os_printf
  658. ("Invalid Descriptor Type for Object %p [%s]\n",
  659. object, acpi_ut_get_descriptor_name(object));
  660. }
  661. }
  662. return (AE_OK);
  663. }
  664. /*******************************************************************************
  665. *
  666. * FUNCTION: acpi_db_check_integrity
  667. *
  668. * PARAMETERS: None
  669. *
  670. * RETURN: None
  671. *
  672. * DESCRIPTION: Check entire namespace for data structure integrity
  673. *
  674. ******************************************************************************/
  675. void acpi_db_check_integrity(void)
  676. {
  677. struct acpi_integrity_info info = { 0, 0 };
  678. /* Search all nodes in namespace */
  679. (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  680. ACPI_UINT32_MAX, acpi_db_integrity_walk, NULL,
  681. (void *)&info, NULL);
  682. acpi_os_printf("Verified %u namespace nodes with %u Objects\n",
  683. info.nodes, info.objects);
  684. }
  685. /*******************************************************************************
  686. *
  687. * FUNCTION: acpi_db_walk_for_references
  688. *
  689. * PARAMETERS: Callback from walk_namespace
  690. *
  691. * RETURN: Status
  692. *
  693. * DESCRIPTION: Check if this namespace object refers to the target object
  694. * that is passed in as the context value.
  695. *
  696. * Note: Currently doesn't check subobjects within the Node's object
  697. *
  698. ******************************************************************************/
  699. static acpi_status
  700. acpi_db_walk_for_references(acpi_handle obj_handle,
  701. u32 nesting_level,
  702. void *context, void **return_value)
  703. {
  704. union acpi_operand_object *obj_desc =
  705. (union acpi_operand_object *)context;
  706. struct acpi_namespace_node *node =
  707. (struct acpi_namespace_node *)obj_handle;
  708. /* Check for match against the namespace node itself */
  709. if (node == (void *)obj_desc) {
  710. acpi_os_printf("Object is a Node [%4.4s]\n",
  711. acpi_ut_get_node_name(node));
  712. }
  713. /* Check for match against the object attached to the node */
  714. if (acpi_ns_get_attached_object(node) == obj_desc) {
  715. acpi_os_printf("Reference at Node->Object %p [%4.4s]\n",
  716. node, acpi_ut_get_node_name(node));
  717. }
  718. return (AE_OK);
  719. }
  720. /*******************************************************************************
  721. *
  722. * FUNCTION: acpi_db_find_references
  723. *
  724. * PARAMETERS: object_arg - String with hex value of the object
  725. *
  726. * RETURN: None
  727. *
  728. * DESCRIPTION: Search namespace for all references to the input object
  729. *
  730. ******************************************************************************/
  731. void acpi_db_find_references(char *object_arg)
  732. {
  733. union acpi_operand_object *obj_desc;
  734. acpi_size address;
  735. /* Convert string to object pointer */
  736. address = strtoul(object_arg, NULL, 16);
  737. obj_desc = ACPI_TO_POINTER(address);
  738. /* Search all nodes in namespace */
  739. (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  740. ACPI_UINT32_MAX, acpi_db_walk_for_references,
  741. NULL, (void *)obj_desc, NULL);
  742. }
  743. /*******************************************************************************
  744. *
  745. * FUNCTION: acpi_db_bus_walk
  746. *
  747. * PARAMETERS: Callback from walk_namespace
  748. *
  749. * RETURN: Status
  750. *
  751. * DESCRIPTION: Display info about device objects that have a corresponding
  752. * _PRT method.
  753. *
  754. ******************************************************************************/
  755. static acpi_status
  756. acpi_db_bus_walk(acpi_handle obj_handle,
  757. u32 nesting_level, void *context, void **return_value)
  758. {
  759. struct acpi_namespace_node *node =
  760. (struct acpi_namespace_node *)obj_handle;
  761. acpi_status status;
  762. struct acpi_buffer buffer;
  763. struct acpi_namespace_node *temp_node;
  764. struct acpi_device_info *info;
  765. u32 i;
  766. if ((node->type != ACPI_TYPE_DEVICE) &&
  767. (node->type != ACPI_TYPE_PROCESSOR)) {
  768. return (AE_OK);
  769. }
  770. /* Exit if there is no _PRT under this device */
  771. status = acpi_get_handle(node, METHOD_NAME__PRT,
  772. ACPI_CAST_PTR(acpi_handle, &temp_node));
  773. if (ACPI_FAILURE(status)) {
  774. return (AE_OK);
  775. }
  776. /* Get the full path to this device object */
  777. buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
  778. status = acpi_ns_handle_to_pathname(obj_handle, &buffer, TRUE);
  779. if (ACPI_FAILURE(status)) {
  780. acpi_os_printf("Could Not get pathname for object %p\n",
  781. obj_handle);
  782. return (AE_OK);
  783. }
  784. status = acpi_get_object_info(obj_handle, &info);
  785. if (ACPI_FAILURE(status)) {
  786. return (AE_OK);
  787. }
  788. /* Display the full path */
  789. acpi_os_printf("%-32s Type %X", (char *)buffer.pointer, node->type);
  790. ACPI_FREE(buffer.pointer);
  791. if (info->flags & ACPI_PCI_ROOT_BRIDGE) {
  792. acpi_os_printf(" - Is PCI Root Bridge");
  793. }
  794. acpi_os_printf("\n");
  795. /* _PRT info */
  796. acpi_os_printf("_PRT: %p\n", temp_node);
  797. /* Dump _ADR, _HID, _UID, _CID */
  798. if (info->valid & ACPI_VALID_ADR) {
  799. acpi_os_printf("_ADR: %8.8X%8.8X\n",
  800. ACPI_FORMAT_UINT64(info->address));
  801. } else {
  802. acpi_os_printf("_ADR: <Not Present>\n");
  803. }
  804. if (info->valid & ACPI_VALID_HID) {
  805. acpi_os_printf("_HID: %s\n", info->hardware_id.string);
  806. } else {
  807. acpi_os_printf("_HID: <Not Present>\n");
  808. }
  809. if (info->valid & ACPI_VALID_UID) {
  810. acpi_os_printf("_UID: %s\n", info->unique_id.string);
  811. } else {
  812. acpi_os_printf("_UID: <Not Present>\n");
  813. }
  814. if (info->valid & ACPI_VALID_CID) {
  815. for (i = 0; i < info->compatible_id_list.count; i++) {
  816. acpi_os_printf("_CID: %s\n",
  817. info->compatible_id_list.ids[i].string);
  818. }
  819. } else {
  820. acpi_os_printf("_CID: <Not Present>\n");
  821. }
  822. ACPI_FREE(info);
  823. return (AE_OK);
  824. }
  825. /*******************************************************************************
  826. *
  827. * FUNCTION: acpi_db_get_bus_info
  828. *
  829. * PARAMETERS: None
  830. *
  831. * RETURN: None
  832. *
  833. * DESCRIPTION: Display info about system buses.
  834. *
  835. ******************************************************************************/
  836. void acpi_db_get_bus_info(void)
  837. {
  838. /* Search all nodes in namespace */
  839. (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  840. ACPI_UINT32_MAX, acpi_db_bus_walk, NULL, NULL,
  841. NULL);
  842. }