nsdump.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. /******************************************************************************
  2. *
  3. * Module Name: nsdump - table dumping routines for debug
  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 <acpi/acoutput.h>
  46. #define _COMPONENT ACPI_NAMESPACE
  47. ACPI_MODULE_NAME("nsdump")
  48. /* Local prototypes */
  49. #ifdef ACPI_OBSOLETE_FUNCTIONS
  50. void acpi_ns_dump_root_devices(void);
  51. static acpi_status
  52. acpi_ns_dump_one_device(acpi_handle obj_handle,
  53. u32 level, void *context, void **return_value);
  54. #endif
  55. #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
  56. static acpi_status
  57. acpi_ns_dump_one_object_path(acpi_handle obj_handle,
  58. u32 level, void *context, void **return_value);
  59. static acpi_status
  60. acpi_ns_get_max_depth(acpi_handle obj_handle,
  61. u32 level, void *context, void **return_value);
  62. /*******************************************************************************
  63. *
  64. * FUNCTION: acpi_ns_print_pathname
  65. *
  66. * PARAMETERS: num_segments - Number of ACPI name segments
  67. * pathname - The compressed (internal) path
  68. *
  69. * RETURN: None
  70. *
  71. * DESCRIPTION: Print an object's full namespace pathname
  72. *
  73. ******************************************************************************/
  74. void acpi_ns_print_pathname(u32 num_segments, char *pathname)
  75. {
  76. u32 i;
  77. ACPI_FUNCTION_NAME(ns_print_pathname);
  78. /* Check if debug output enabled */
  79. if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_NAMES, ACPI_NAMESPACE)) {
  80. return;
  81. }
  82. /* Print the entire name */
  83. ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "["));
  84. while (num_segments) {
  85. for (i = 0; i < 4; i++) {
  86. isprint((int)pathname[i]) ?
  87. acpi_os_printf("%c", pathname[i]) :
  88. acpi_os_printf("?");
  89. }
  90. pathname += ACPI_NAME_SIZE;
  91. num_segments--;
  92. if (num_segments) {
  93. acpi_os_printf(".");
  94. }
  95. }
  96. acpi_os_printf("]\n");
  97. }
  98. /*******************************************************************************
  99. *
  100. * FUNCTION: acpi_ns_dump_pathname
  101. *
  102. * PARAMETERS: handle - Object
  103. * msg - Prefix message
  104. * level - Desired debug level
  105. * component - Caller's component ID
  106. *
  107. * RETURN: None
  108. *
  109. * DESCRIPTION: Print an object's full namespace pathname
  110. * Manages allocation/freeing of a pathname buffer
  111. *
  112. ******************************************************************************/
  113. void
  114. acpi_ns_dump_pathname(acpi_handle handle, char *msg, u32 level, u32 component)
  115. {
  116. ACPI_FUNCTION_TRACE(ns_dump_pathname);
  117. /* Do this only if the requested debug level and component are enabled */
  118. if (!ACPI_IS_DEBUG_ENABLED(level, component)) {
  119. return_VOID;
  120. }
  121. /* Convert handle to a full pathname and print it (with supplied message) */
  122. acpi_ns_print_node_pathname(handle, msg);
  123. acpi_os_printf("\n");
  124. return_VOID;
  125. }
  126. /*******************************************************************************
  127. *
  128. * FUNCTION: acpi_ns_dump_one_object
  129. *
  130. * PARAMETERS: obj_handle - Node to be dumped
  131. * level - Nesting level of the handle
  132. * context - Passed into walk_namespace
  133. * return_value - Not used
  134. *
  135. * RETURN: Status
  136. *
  137. * DESCRIPTION: Dump a single Node
  138. * This procedure is a user_function called by acpi_ns_walk_namespace.
  139. *
  140. ******************************************************************************/
  141. acpi_status
  142. acpi_ns_dump_one_object(acpi_handle obj_handle,
  143. u32 level, void *context, void **return_value)
  144. {
  145. struct acpi_walk_info *info = (struct acpi_walk_info *)context;
  146. struct acpi_namespace_node *this_node;
  147. union acpi_operand_object *obj_desc = NULL;
  148. acpi_object_type obj_type;
  149. acpi_object_type type;
  150. u32 bytes_to_dump;
  151. u32 dbg_level;
  152. u32 i;
  153. ACPI_FUNCTION_NAME(ns_dump_one_object);
  154. /* Is output enabled? */
  155. if (!(acpi_dbg_level & info->debug_level)) {
  156. return (AE_OK);
  157. }
  158. if (!obj_handle) {
  159. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Null object handle\n"));
  160. return (AE_OK);
  161. }
  162. this_node = acpi_ns_validate_handle(obj_handle);
  163. if (!this_node) {
  164. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid object handle %p\n",
  165. obj_handle));
  166. return (AE_OK);
  167. }
  168. type = this_node->type;
  169. /* Check if the owner matches */
  170. if ((info->owner_id != ACPI_OWNER_ID_MAX) &&
  171. (info->owner_id != this_node->owner_id)) {
  172. return (AE_OK);
  173. }
  174. if (!(info->display_type & ACPI_DISPLAY_SHORT)) {
  175. /* Indent the object according to the level */
  176. acpi_os_printf("%2d%*s", (u32) level - 1, (int)level * 2, " ");
  177. /* Check the node type and name */
  178. if (type > ACPI_TYPE_LOCAL_MAX) {
  179. ACPI_WARNING((AE_INFO,
  180. "Invalid ACPI Object Type 0x%08X", type));
  181. }
  182. acpi_os_printf("%4.4s", acpi_ut_get_node_name(this_node));
  183. }
  184. /* Now we can print out the pertinent information */
  185. acpi_os_printf(" %-12s %p %2.2X ",
  186. acpi_ut_get_type_name(type), this_node,
  187. this_node->owner_id);
  188. dbg_level = acpi_dbg_level;
  189. acpi_dbg_level = 0;
  190. obj_desc = acpi_ns_get_attached_object(this_node);
  191. acpi_dbg_level = dbg_level;
  192. /* Temp nodes are those nodes created by a control method */
  193. if (this_node->flags & ANOBJ_TEMPORARY) {
  194. acpi_os_printf("(T) ");
  195. }
  196. switch (info->display_type & ACPI_DISPLAY_MASK) {
  197. case ACPI_DISPLAY_SUMMARY:
  198. if (!obj_desc) {
  199. /* No attached object. Some types should always have an object */
  200. switch (type) {
  201. case ACPI_TYPE_INTEGER:
  202. case ACPI_TYPE_PACKAGE:
  203. case ACPI_TYPE_BUFFER:
  204. case ACPI_TYPE_STRING:
  205. case ACPI_TYPE_METHOD:
  206. acpi_os_printf("<No attached object>");
  207. break;
  208. default:
  209. break;
  210. }
  211. acpi_os_printf("\n");
  212. return (AE_OK);
  213. }
  214. switch (type) {
  215. case ACPI_TYPE_PROCESSOR:
  216. acpi_os_printf("ID %02X Len %02X Addr %8.8X%8.8X\n",
  217. obj_desc->processor.proc_id,
  218. obj_desc->processor.length,
  219. ACPI_FORMAT_UINT64(obj_desc->processor.
  220. address));
  221. break;
  222. case ACPI_TYPE_DEVICE:
  223. acpi_os_printf("Notify Object: %p\n", obj_desc);
  224. break;
  225. case ACPI_TYPE_METHOD:
  226. acpi_os_printf("Args %X Len %.4X Aml %p\n",
  227. (u32) obj_desc->method.param_count,
  228. obj_desc->method.aml_length,
  229. obj_desc->method.aml_start);
  230. break;
  231. case ACPI_TYPE_INTEGER:
  232. acpi_os_printf("= %8.8X%8.8X\n",
  233. ACPI_FORMAT_UINT64(obj_desc->integer.
  234. value));
  235. break;
  236. case ACPI_TYPE_PACKAGE:
  237. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  238. acpi_os_printf("Elements %.2X\n",
  239. obj_desc->package.count);
  240. } else {
  241. acpi_os_printf("[Length not yet evaluated]\n");
  242. }
  243. break;
  244. case ACPI_TYPE_BUFFER:
  245. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  246. acpi_os_printf("Len %.2X",
  247. obj_desc->buffer.length);
  248. /* Dump some of the buffer */
  249. if (obj_desc->buffer.length > 0) {
  250. acpi_os_printf(" =");
  251. for (i = 0;
  252. (i < obj_desc->buffer.length
  253. && i < 12); i++) {
  254. acpi_os_printf(" %.2hX",
  255. obj_desc->buffer.
  256. pointer[i]);
  257. }
  258. }
  259. acpi_os_printf("\n");
  260. } else {
  261. acpi_os_printf("[Length not yet evaluated]\n");
  262. }
  263. break;
  264. case ACPI_TYPE_STRING:
  265. acpi_os_printf("Len %.2X ", obj_desc->string.length);
  266. acpi_ut_print_string(obj_desc->string.pointer, 32);
  267. acpi_os_printf("\n");
  268. break;
  269. case ACPI_TYPE_REGION:
  270. acpi_os_printf("[%s]",
  271. acpi_ut_get_region_name(obj_desc->region.
  272. space_id));
  273. if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
  274. acpi_os_printf(" Addr %8.8X%8.8X Len %.4X\n",
  275. ACPI_FORMAT_UINT64(obj_desc->
  276. region.
  277. address),
  278. obj_desc->region.length);
  279. } else {
  280. acpi_os_printf
  281. (" [Address/Length not yet evaluated]\n");
  282. }
  283. break;
  284. case ACPI_TYPE_LOCAL_REFERENCE:
  285. acpi_os_printf("[%s]\n",
  286. acpi_ut_get_reference_name(obj_desc));
  287. break;
  288. case ACPI_TYPE_BUFFER_FIELD:
  289. if (obj_desc->buffer_field.buffer_obj &&
  290. obj_desc->buffer_field.buffer_obj->buffer.node) {
  291. acpi_os_printf("Buf [%4.4s]",
  292. acpi_ut_get_node_name(obj_desc->
  293. buffer_field.
  294. buffer_obj->
  295. buffer.
  296. node));
  297. }
  298. break;
  299. case ACPI_TYPE_LOCAL_REGION_FIELD:
  300. acpi_os_printf("Rgn [%4.4s]",
  301. acpi_ut_get_node_name(obj_desc->
  302. common_field.
  303. region_obj->region.
  304. node));
  305. break;
  306. case ACPI_TYPE_LOCAL_BANK_FIELD:
  307. acpi_os_printf("Rgn [%4.4s] Bnk [%4.4s]",
  308. acpi_ut_get_node_name(obj_desc->
  309. common_field.
  310. region_obj->region.
  311. node),
  312. acpi_ut_get_node_name(obj_desc->
  313. bank_field.
  314. bank_obj->
  315. common_field.
  316. node));
  317. break;
  318. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  319. acpi_os_printf("Idx [%4.4s] Dat [%4.4s]",
  320. acpi_ut_get_node_name(obj_desc->
  321. index_field.
  322. index_obj->
  323. common_field.node),
  324. acpi_ut_get_node_name(obj_desc->
  325. index_field.
  326. data_obj->
  327. common_field.
  328. node));
  329. break;
  330. case ACPI_TYPE_LOCAL_ALIAS:
  331. case ACPI_TYPE_LOCAL_METHOD_ALIAS:
  332. acpi_os_printf("Target %4.4s (%p)\n",
  333. acpi_ut_get_node_name(obj_desc),
  334. obj_desc);
  335. break;
  336. default:
  337. acpi_os_printf("Object %p\n", obj_desc);
  338. break;
  339. }
  340. /* Common field handling */
  341. switch (type) {
  342. case ACPI_TYPE_BUFFER_FIELD:
  343. case ACPI_TYPE_LOCAL_REGION_FIELD:
  344. case ACPI_TYPE_LOCAL_BANK_FIELD:
  345. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  346. acpi_os_printf(" Off %.3X Len %.2X Acc %.2hd\n",
  347. (obj_desc->common_field.
  348. base_byte_offset * 8)
  349. +
  350. obj_desc->common_field.
  351. start_field_bit_offset,
  352. obj_desc->common_field.bit_length,
  353. obj_desc->common_field.
  354. access_byte_width);
  355. break;
  356. default:
  357. break;
  358. }
  359. break;
  360. case ACPI_DISPLAY_OBJECTS:
  361. acpi_os_printf("O:%p", obj_desc);
  362. if (!obj_desc) {
  363. /* No attached object, we are done */
  364. acpi_os_printf("\n");
  365. return (AE_OK);
  366. }
  367. acpi_os_printf("(R%u)", obj_desc->common.reference_count);
  368. switch (type) {
  369. case ACPI_TYPE_METHOD:
  370. /* Name is a Method and its AML offset/length are set */
  371. acpi_os_printf(" M:%p-%X\n", obj_desc->method.aml_start,
  372. obj_desc->method.aml_length);
  373. break;
  374. case ACPI_TYPE_INTEGER:
  375. acpi_os_printf(" I:%8.8X8.8%X\n",
  376. ACPI_FORMAT_UINT64(obj_desc->integer.
  377. value));
  378. break;
  379. case ACPI_TYPE_STRING:
  380. acpi_os_printf(" S:%p-%X\n", obj_desc->string.pointer,
  381. obj_desc->string.length);
  382. break;
  383. case ACPI_TYPE_BUFFER:
  384. acpi_os_printf(" B:%p-%X\n", obj_desc->buffer.pointer,
  385. obj_desc->buffer.length);
  386. break;
  387. default:
  388. acpi_os_printf("\n");
  389. break;
  390. }
  391. break;
  392. default:
  393. acpi_os_printf("\n");
  394. break;
  395. }
  396. /* If debug turned off, done */
  397. if (!(acpi_dbg_level & ACPI_LV_VALUES)) {
  398. return (AE_OK);
  399. }
  400. /* If there is an attached object, display it */
  401. dbg_level = acpi_dbg_level;
  402. acpi_dbg_level = 0;
  403. obj_desc = acpi_ns_get_attached_object(this_node);
  404. acpi_dbg_level = dbg_level;
  405. /* Dump attached objects */
  406. while (obj_desc) {
  407. obj_type = ACPI_TYPE_INVALID;
  408. acpi_os_printf("Attached Object %p: ", obj_desc);
  409. /* Decode the type of attached object and dump the contents */
  410. switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
  411. case ACPI_DESC_TYPE_NAMED:
  412. acpi_os_printf("(Ptr to Node)\n");
  413. bytes_to_dump = sizeof(struct acpi_namespace_node);
  414. ACPI_DUMP_BUFFER(obj_desc, bytes_to_dump);
  415. break;
  416. case ACPI_DESC_TYPE_OPERAND:
  417. obj_type = obj_desc->common.type;
  418. if (obj_type > ACPI_TYPE_LOCAL_MAX) {
  419. acpi_os_printf
  420. ("(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
  421. obj_type);
  422. bytes_to_dump = 32;
  423. } else {
  424. acpi_os_printf
  425. ("(Pointer to ACPI Object type %.2X [%s])\n",
  426. obj_type, acpi_ut_get_type_name(obj_type));
  427. bytes_to_dump =
  428. sizeof(union acpi_operand_object);
  429. }
  430. ACPI_DUMP_BUFFER(obj_desc, bytes_to_dump);
  431. break;
  432. default:
  433. break;
  434. }
  435. /* If value is NOT an internal object, we are done */
  436. if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) !=
  437. ACPI_DESC_TYPE_OPERAND) {
  438. goto cleanup;
  439. }
  440. /* Valid object, get the pointer to next level, if any */
  441. switch (obj_type) {
  442. case ACPI_TYPE_BUFFER:
  443. case ACPI_TYPE_STRING:
  444. /*
  445. * NOTE: takes advantage of common fields between string/buffer
  446. */
  447. bytes_to_dump = obj_desc->string.length;
  448. obj_desc = (void *)obj_desc->string.pointer;
  449. acpi_os_printf("(Buffer/String pointer %p length %X)\n",
  450. obj_desc, bytes_to_dump);
  451. ACPI_DUMP_BUFFER(obj_desc, bytes_to_dump);
  452. goto cleanup;
  453. case ACPI_TYPE_BUFFER_FIELD:
  454. obj_desc =
  455. (union acpi_operand_object *)obj_desc->buffer_field.
  456. buffer_obj;
  457. break;
  458. case ACPI_TYPE_PACKAGE:
  459. obj_desc = (void *)obj_desc->package.elements;
  460. break;
  461. case ACPI_TYPE_METHOD:
  462. obj_desc = (void *)obj_desc->method.aml_start;
  463. break;
  464. case ACPI_TYPE_LOCAL_REGION_FIELD:
  465. obj_desc = (void *)obj_desc->field.region_obj;
  466. break;
  467. case ACPI_TYPE_LOCAL_BANK_FIELD:
  468. obj_desc = (void *)obj_desc->bank_field.region_obj;
  469. break;
  470. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  471. obj_desc = (void *)obj_desc->index_field.index_obj;
  472. break;
  473. default:
  474. goto cleanup;
  475. }
  476. obj_type = ACPI_TYPE_INVALID; /* Terminate loop after next pass */
  477. }
  478. cleanup:
  479. acpi_os_printf("\n");
  480. return (AE_OK);
  481. }
  482. /*******************************************************************************
  483. *
  484. * FUNCTION: acpi_ns_dump_objects
  485. *
  486. * PARAMETERS: type - Object type to be dumped
  487. * display_type - 0 or ACPI_DISPLAY_SUMMARY
  488. * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
  489. * for an effectively unlimited depth.
  490. * owner_id - Dump only objects owned by this ID. Use
  491. * ACPI_UINT32_MAX to match all owners.
  492. * start_handle - Where in namespace to start/end search
  493. *
  494. * RETURN: None
  495. *
  496. * DESCRIPTION: Dump typed objects within the loaded namespace. Uses
  497. * acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
  498. *
  499. ******************************************************************************/
  500. void
  501. acpi_ns_dump_objects(acpi_object_type type,
  502. u8 display_type,
  503. u32 max_depth,
  504. acpi_owner_id owner_id, acpi_handle start_handle)
  505. {
  506. struct acpi_walk_info info;
  507. acpi_status status;
  508. ACPI_FUNCTION_ENTRY();
  509. /*
  510. * Just lock the entire namespace for the duration of the dump.
  511. * We don't want any changes to the namespace during this time,
  512. * especially the temporary nodes since we are going to display
  513. * them also.
  514. */
  515. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  516. if (ACPI_FAILURE(status)) {
  517. acpi_os_printf("Could not acquire namespace mutex\n");
  518. return;
  519. }
  520. info.debug_level = ACPI_LV_TABLES;
  521. info.owner_id = owner_id;
  522. info.display_type = display_type;
  523. (void)acpi_ns_walk_namespace(type, start_handle, max_depth,
  524. ACPI_NS_WALK_NO_UNLOCK |
  525. ACPI_NS_WALK_TEMP_NODES,
  526. acpi_ns_dump_one_object, NULL,
  527. (void *)&info, NULL);
  528. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  529. }
  530. /*******************************************************************************
  531. *
  532. * FUNCTION: acpi_ns_dump_one_object_path, acpi_ns_get_max_depth
  533. *
  534. * PARAMETERS: obj_handle - Node to be dumped
  535. * level - Nesting level of the handle
  536. * context - Passed into walk_namespace
  537. * return_value - Not used
  538. *
  539. * RETURN: Status
  540. *
  541. * DESCRIPTION: Dump the full pathname to a namespace object. acp_ns_get_max_depth
  542. * computes the maximum nesting depth in the namespace tree, in
  543. * order to simplify formatting in acpi_ns_dump_one_object_path.
  544. * These procedures are user_functions called by acpi_ns_walk_namespace.
  545. *
  546. ******************************************************************************/
  547. static acpi_status
  548. acpi_ns_dump_one_object_path(acpi_handle obj_handle,
  549. u32 level, void *context, void **return_value)
  550. {
  551. u32 max_level = *((u32 *)context);
  552. char *pathname;
  553. struct acpi_namespace_node *node;
  554. int path_indent;
  555. if (!obj_handle) {
  556. return (AE_OK);
  557. }
  558. node = acpi_ns_validate_handle(obj_handle);
  559. if (!node) {
  560. /* Ignore bad node during namespace walk */
  561. return (AE_OK);
  562. }
  563. pathname = acpi_ns_get_external_pathname(node);
  564. path_indent = 1;
  565. if (level <= max_level) {
  566. path_indent = max_level - level + 1;
  567. }
  568. acpi_os_printf("%2d%*s%-12s%*s",
  569. level, level, " ", acpi_ut_get_type_name(node->type),
  570. path_indent, " ");
  571. acpi_os_printf("%s\n", &pathname[1]);
  572. ACPI_FREE(pathname);
  573. return (AE_OK);
  574. }
  575. static acpi_status
  576. acpi_ns_get_max_depth(acpi_handle obj_handle,
  577. u32 level, void *context, void **return_value)
  578. {
  579. u32 *max_level = (u32 *)context;
  580. if (level > *max_level) {
  581. *max_level = level;
  582. }
  583. return (AE_OK);
  584. }
  585. /*******************************************************************************
  586. *
  587. * FUNCTION: acpi_ns_dump_object_paths
  588. *
  589. * PARAMETERS: type - Object type to be dumped
  590. * display_type - 0 or ACPI_DISPLAY_SUMMARY
  591. * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
  592. * for an effectively unlimited depth.
  593. * owner_id - Dump only objects owned by this ID. Use
  594. * ACPI_UINT32_MAX to match all owners.
  595. * start_handle - Where in namespace to start/end search
  596. *
  597. * RETURN: None
  598. *
  599. * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
  600. * acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object_path.
  601. *
  602. ******************************************************************************/
  603. void
  604. acpi_ns_dump_object_paths(acpi_object_type type,
  605. u8 display_type,
  606. u32 max_depth,
  607. acpi_owner_id owner_id, acpi_handle start_handle)
  608. {
  609. acpi_status status;
  610. u32 max_level = 0;
  611. ACPI_FUNCTION_ENTRY();
  612. /*
  613. * Just lock the entire namespace for the duration of the dump.
  614. * We don't want any changes to the namespace during this time,
  615. * especially the temporary nodes since we are going to display
  616. * them also.
  617. */
  618. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  619. if (ACPI_FAILURE(status)) {
  620. acpi_os_printf("Could not acquire namespace mutex\n");
  621. return;
  622. }
  623. /* Get the max depth of the namespace tree, for formatting later */
  624. (void)acpi_ns_walk_namespace(type, start_handle, max_depth,
  625. ACPI_NS_WALK_NO_UNLOCK |
  626. ACPI_NS_WALK_TEMP_NODES,
  627. acpi_ns_get_max_depth, NULL,
  628. (void *)&max_level, NULL);
  629. /* Now dump the entire namespace */
  630. (void)acpi_ns_walk_namespace(type, start_handle, max_depth,
  631. ACPI_NS_WALK_NO_UNLOCK |
  632. ACPI_NS_WALK_TEMP_NODES,
  633. acpi_ns_dump_one_object_path, NULL,
  634. (void *)&max_level, NULL);
  635. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  636. }
  637. /*******************************************************************************
  638. *
  639. * FUNCTION: acpi_ns_dump_entry
  640. *
  641. * PARAMETERS: handle - Node to be dumped
  642. * debug_level - Output level
  643. *
  644. * RETURN: None
  645. *
  646. * DESCRIPTION: Dump a single Node
  647. *
  648. ******************************************************************************/
  649. void acpi_ns_dump_entry(acpi_handle handle, u32 debug_level)
  650. {
  651. struct acpi_walk_info info;
  652. ACPI_FUNCTION_ENTRY();
  653. info.debug_level = debug_level;
  654. info.owner_id = ACPI_OWNER_ID_MAX;
  655. info.display_type = ACPI_DISPLAY_SUMMARY;
  656. (void)acpi_ns_dump_one_object(handle, 1, &info, NULL);
  657. }
  658. #ifdef ACPI_ASL_COMPILER
  659. /*******************************************************************************
  660. *
  661. * FUNCTION: acpi_ns_dump_tables
  662. *
  663. * PARAMETERS: search_base - Root of subtree to be dumped, or
  664. * NS_ALL to dump the entire namespace
  665. * max_depth - Maximum depth of dump. Use INT_MAX
  666. * for an effectively unlimited depth.
  667. *
  668. * RETURN: None
  669. *
  670. * DESCRIPTION: Dump the name space, or a portion of it.
  671. *
  672. ******************************************************************************/
  673. void acpi_ns_dump_tables(acpi_handle search_base, u32 max_depth)
  674. {
  675. acpi_handle search_handle = search_base;
  676. ACPI_FUNCTION_TRACE(ns_dump_tables);
  677. if (!acpi_gbl_root_node) {
  678. /*
  679. * If the name space has not been initialized,
  680. * there is nothing to dump.
  681. */
  682. ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
  683. "namespace not initialized!\n"));
  684. return_VOID;
  685. }
  686. if (ACPI_NS_ALL == search_base) {
  687. /* Entire namespace */
  688. search_handle = acpi_gbl_root_node;
  689. ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "\\\n"));
  690. }
  691. acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, max_depth,
  692. ACPI_OWNER_ID_MAX, search_handle);
  693. return_VOID;
  694. }
  695. #endif
  696. #endif