dbnames.c 26 KB

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