dbnames.c 24 KB

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