nsdump.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /******************************************************************************
  2. *
  3. * Module Name: nsdump - table dumping routines for debug
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acnamesp.h>
  44. #include <acpi/acparser.h>
  45. #define _COMPONENT ACPI_NAMESPACE
  46. ACPI_MODULE_NAME ("nsdump")
  47. #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_ns_print_pathname
  51. *
  52. * PARAMETERS: num_segment - Number of ACPI name segments
  53. * Pathname - The compressed (internal) path
  54. *
  55. * DESCRIPTION: Print an object's full namespace pathname
  56. *
  57. ******************************************************************************/
  58. void
  59. acpi_ns_print_pathname (
  60. u32 num_segments,
  61. char *pathname)
  62. {
  63. ACPI_FUNCTION_NAME ("ns_print_pathname");
  64. if (!(acpi_dbg_level & ACPI_LV_NAMES) || !(acpi_dbg_layer & ACPI_NAMESPACE)) {
  65. return;
  66. }
  67. /* Print the entire name */
  68. ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "["));
  69. while (num_segments) {
  70. acpi_os_printf ("%4.4s", pathname);
  71. pathname += ACPI_NAME_SIZE;
  72. num_segments--;
  73. if (num_segments) {
  74. acpi_os_printf (".");
  75. }
  76. }
  77. acpi_os_printf ("]\n");
  78. }
  79. /*******************************************************************************
  80. *
  81. * FUNCTION: acpi_ns_dump_pathname
  82. *
  83. * PARAMETERS: Handle - Object
  84. * Msg - Prefix message
  85. * Level - Desired debug level
  86. * Component - Caller's component ID
  87. *
  88. * DESCRIPTION: Print an object's full namespace pathname
  89. * Manages allocation/freeing of a pathname buffer
  90. *
  91. ******************************************************************************/
  92. void
  93. acpi_ns_dump_pathname (
  94. acpi_handle handle,
  95. char *msg,
  96. u32 level,
  97. u32 component)
  98. {
  99. ACPI_FUNCTION_TRACE ("ns_dump_pathname");
  100. /* Do this only if the requested debug level and component are enabled */
  101. if (!(acpi_dbg_level & level) || !(acpi_dbg_layer & component)) {
  102. return_VOID;
  103. }
  104. /* Convert handle to a full pathname and print it (with supplied message) */
  105. acpi_ns_print_node_pathname (handle, msg);
  106. acpi_os_printf ("\n");
  107. return_VOID;
  108. }
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: acpi_ns_dump_one_object
  112. *
  113. * PARAMETERS: Handle - Node to be dumped
  114. * Level - Nesting level of the handle
  115. * Context - Passed into walk_namespace
  116. *
  117. * DESCRIPTION: Dump a single Node
  118. * This procedure is a user_function called by acpi_ns_walk_namespace.
  119. *
  120. ******************************************************************************/
  121. acpi_status
  122. acpi_ns_dump_one_object (
  123. acpi_handle obj_handle,
  124. u32 level,
  125. void *context,
  126. void **return_value)
  127. {
  128. struct acpi_walk_info *info = (struct acpi_walk_info *) context;
  129. struct acpi_namespace_node *this_node;
  130. union acpi_operand_object *obj_desc = NULL;
  131. acpi_object_type obj_type;
  132. acpi_object_type type;
  133. u32 bytes_to_dump;
  134. u32 dbg_level;
  135. u32 i;
  136. ACPI_FUNCTION_NAME ("ns_dump_one_object");
  137. /* Is output enabled? */
  138. if (!(acpi_dbg_level & info->debug_level)) {
  139. return (AE_OK);
  140. }
  141. if (!obj_handle) {
  142. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
  143. return (AE_OK);
  144. }
  145. this_node = acpi_ns_map_handle_to_node (obj_handle);
  146. type = this_node->type;
  147. /* Check if the owner matches */
  148. if ((info->owner_id != ACPI_UINT32_MAX) &&
  149. (info->owner_id != this_node->owner_id)) {
  150. return (AE_OK);
  151. }
  152. /* Indent the object according to the level */
  153. acpi_os_printf ("%2d%*s", (u32) level - 1, (int) level * 2, " ");
  154. /* Check the node type and name */
  155. if (type > ACPI_TYPE_LOCAL_MAX) {
  156. ACPI_REPORT_WARNING (("Invalid ACPI Type %08X\n", type));
  157. }
  158. if (!acpi_ut_valid_acpi_name (this_node->name.integer)) {
  159. ACPI_REPORT_WARNING (("Invalid ACPI Name %08X\n",
  160. this_node->name.integer));
  161. }
  162. /*
  163. * Now we can print out the pertinent information
  164. */
  165. acpi_os_printf ("%4.4s %-12s %p ",
  166. acpi_ut_get_node_name (this_node), acpi_ut_get_type_name (type), this_node);
  167. dbg_level = acpi_dbg_level;
  168. acpi_dbg_level = 0;
  169. obj_desc = acpi_ns_get_attached_object (this_node);
  170. acpi_dbg_level = dbg_level;
  171. switch (info->display_type) {
  172. case ACPI_DISPLAY_SUMMARY:
  173. if (!obj_desc) {
  174. /* No attached object, we are done */
  175. acpi_os_printf ("\n");
  176. return (AE_OK);
  177. }
  178. switch (type) {
  179. case ACPI_TYPE_PROCESSOR:
  180. acpi_os_printf ("ID %X Len %.4X Addr %p\n",
  181. obj_desc->processor.proc_id, obj_desc->processor.length,
  182. (char *) obj_desc->processor.address);
  183. break;
  184. case ACPI_TYPE_DEVICE:
  185. acpi_os_printf ("Notify Object: %p\n", obj_desc);
  186. break;
  187. case ACPI_TYPE_METHOD:
  188. acpi_os_printf ("Args %X Len %.4X Aml %p\n",
  189. (u32) obj_desc->method.param_count,
  190. obj_desc->method.aml_length, obj_desc->method.aml_start);
  191. break;
  192. case ACPI_TYPE_INTEGER:
  193. acpi_os_printf ("= %8.8X%8.8X\n",
  194. ACPI_FORMAT_UINT64 (obj_desc->integer.value));
  195. break;
  196. case ACPI_TYPE_PACKAGE:
  197. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  198. acpi_os_printf ("Elements %.2X\n",
  199. obj_desc->package.count);
  200. }
  201. else {
  202. acpi_os_printf ("[Length not yet evaluated]\n");
  203. }
  204. break;
  205. case ACPI_TYPE_BUFFER:
  206. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  207. acpi_os_printf ("Len %.2X",
  208. obj_desc->buffer.length);
  209. /* Dump some of the buffer */
  210. if (obj_desc->buffer.length > 0) {
  211. acpi_os_printf (" =");
  212. for (i = 0; (i < obj_desc->buffer.length && i < 12); i++) {
  213. acpi_os_printf (" %.2hX", obj_desc->buffer.pointer[i]);
  214. }
  215. }
  216. acpi_os_printf ("\n");
  217. }
  218. else {
  219. acpi_os_printf ("[Length not yet evaluated]\n");
  220. }
  221. break;
  222. case ACPI_TYPE_STRING:
  223. acpi_os_printf ("Len %.2X ", obj_desc->string.length);
  224. acpi_ut_print_string (obj_desc->string.pointer, 32);
  225. acpi_os_printf ("\n");
  226. break;
  227. case ACPI_TYPE_REGION:
  228. acpi_os_printf ("[%s]",
  229. acpi_ut_get_region_name (obj_desc->region.space_id));
  230. if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
  231. acpi_os_printf (" Addr %8.8X%8.8X Len %.4X\n",
  232. ACPI_FORMAT_UINT64 (obj_desc->region.address),
  233. obj_desc->region.length);
  234. }
  235. else {
  236. acpi_os_printf (" [Address/Length not yet evaluated]\n");
  237. }
  238. break;
  239. case ACPI_TYPE_LOCAL_REFERENCE:
  240. acpi_os_printf ("[%s]\n",
  241. acpi_ps_get_opcode_name (obj_desc->reference.opcode));
  242. break;
  243. case ACPI_TYPE_BUFFER_FIELD:
  244. if (obj_desc->buffer_field.buffer_obj &&
  245. obj_desc->buffer_field.buffer_obj->buffer.node) {
  246. acpi_os_printf ("Buf [%4.4s]",
  247. acpi_ut_get_node_name (obj_desc->buffer_field.buffer_obj->buffer.node));
  248. }
  249. break;
  250. case ACPI_TYPE_LOCAL_REGION_FIELD:
  251. acpi_os_printf ("Rgn [%4.4s]",
  252. acpi_ut_get_node_name (obj_desc->common_field.region_obj->region.node));
  253. break;
  254. case ACPI_TYPE_LOCAL_BANK_FIELD:
  255. acpi_os_printf ("Rgn [%4.4s] Bnk [%4.4s]",
  256. acpi_ut_get_node_name (obj_desc->common_field.region_obj->region.node),
  257. acpi_ut_get_node_name (obj_desc->bank_field.bank_obj->common_field.node));
  258. break;
  259. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  260. acpi_os_printf ("Idx [%4.4s] Dat [%4.4s]",
  261. acpi_ut_get_node_name (obj_desc->index_field.index_obj->common_field.node),
  262. acpi_ut_get_node_name (obj_desc->index_field.data_obj->common_field.node));
  263. break;
  264. case ACPI_TYPE_LOCAL_ALIAS:
  265. case ACPI_TYPE_LOCAL_METHOD_ALIAS:
  266. acpi_os_printf ("Target %4.4s (%p)\n",
  267. acpi_ut_get_node_name (obj_desc), obj_desc);
  268. break;
  269. default:
  270. acpi_os_printf ("Object %p\n", obj_desc);
  271. break;
  272. }
  273. /* Common field handling */
  274. switch (type) {
  275. case ACPI_TYPE_BUFFER_FIELD:
  276. case ACPI_TYPE_LOCAL_REGION_FIELD:
  277. case ACPI_TYPE_LOCAL_BANK_FIELD:
  278. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  279. acpi_os_printf (" Off %.3X Len %.2X Acc %.2hd\n",
  280. (obj_desc->common_field.base_byte_offset * 8)
  281. + obj_desc->common_field.start_field_bit_offset,
  282. obj_desc->common_field.bit_length,
  283. obj_desc->common_field.access_byte_width);
  284. break;
  285. default:
  286. break;
  287. }
  288. break;
  289. case ACPI_DISPLAY_OBJECTS:
  290. acpi_os_printf ("O:%p", obj_desc);
  291. if (!obj_desc) {
  292. /* No attached object, we are done */
  293. acpi_os_printf ("\n");
  294. return (AE_OK);
  295. }
  296. acpi_os_printf ("(R%d)",
  297. obj_desc->common.reference_count);
  298. switch (type) {
  299. case ACPI_TYPE_METHOD:
  300. /* Name is a Method and its AML offset/length are set */
  301. acpi_os_printf (" M:%p-%X\n", obj_desc->method.aml_start,
  302. obj_desc->method.aml_length);
  303. break;
  304. case ACPI_TYPE_INTEGER:
  305. acpi_os_printf (" I:%8.8X8.8%X\n",
  306. ACPI_FORMAT_UINT64 (obj_desc->integer.value));
  307. break;
  308. case ACPI_TYPE_STRING:
  309. acpi_os_printf (" S:%p-%X\n", obj_desc->string.pointer,
  310. obj_desc->string.length);
  311. break;
  312. case ACPI_TYPE_BUFFER:
  313. acpi_os_printf (" B:%p-%X\n", obj_desc->buffer.pointer,
  314. obj_desc->buffer.length);
  315. break;
  316. default:
  317. acpi_os_printf ("\n");
  318. break;
  319. }
  320. break;
  321. default:
  322. acpi_os_printf ("\n");
  323. break;
  324. }
  325. /* If debug turned off, done */
  326. if (!(acpi_dbg_level & ACPI_LV_VALUES)) {
  327. return (AE_OK);
  328. }
  329. /* If there is an attached object, display it */
  330. dbg_level = acpi_dbg_level;
  331. acpi_dbg_level = 0;
  332. obj_desc = acpi_ns_get_attached_object (this_node);
  333. acpi_dbg_level = dbg_level;
  334. /* Dump attached objects */
  335. while (obj_desc) {
  336. obj_type = ACPI_TYPE_INVALID;
  337. acpi_os_printf (" Attached Object %p: ", obj_desc);
  338. /* Decode the type of attached object and dump the contents */
  339. switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
  340. case ACPI_DESC_TYPE_NAMED:
  341. acpi_os_printf ("(Ptr to Node)\n");
  342. bytes_to_dump = sizeof (struct acpi_namespace_node);
  343. break;
  344. case ACPI_DESC_TYPE_OPERAND:
  345. obj_type = ACPI_GET_OBJECT_TYPE (obj_desc);
  346. if (obj_type > ACPI_TYPE_LOCAL_MAX) {
  347. acpi_os_printf ("(Ptr to ACPI Object type %X [UNKNOWN])\n",
  348. obj_type);
  349. bytes_to_dump = 32;
  350. }
  351. else {
  352. acpi_os_printf ("(Ptr to ACPI Object type %s, %X)\n",
  353. acpi_ut_get_type_name (obj_type), obj_type);
  354. bytes_to_dump = sizeof (union acpi_operand_object);
  355. }
  356. break;
  357. default:
  358. acpi_os_printf (
  359. "(String or Buffer ptr - not an object descriptor) [%s]\n",
  360. acpi_ut_get_descriptor_name (obj_desc));
  361. bytes_to_dump = 16;
  362. break;
  363. }
  364. ACPI_DUMP_BUFFER (obj_desc, bytes_to_dump);
  365. /* If value is NOT an internal object, we are done */
  366. if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) != ACPI_DESC_TYPE_OPERAND) {
  367. goto cleanup;
  368. }
  369. /*
  370. * Valid object, get the pointer to next level, if any
  371. */
  372. switch (obj_type) {
  373. case ACPI_TYPE_STRING:
  374. obj_desc = (void *) obj_desc->string.pointer;
  375. break;
  376. case ACPI_TYPE_BUFFER:
  377. obj_desc = (void *) obj_desc->buffer.pointer;
  378. break;
  379. case ACPI_TYPE_BUFFER_FIELD:
  380. obj_desc = (union acpi_operand_object *) obj_desc->buffer_field.buffer_obj;
  381. break;
  382. case ACPI_TYPE_PACKAGE:
  383. obj_desc = (void *) obj_desc->package.elements;
  384. break;
  385. case ACPI_TYPE_METHOD:
  386. obj_desc = (void *) obj_desc->method.aml_start;
  387. break;
  388. case ACPI_TYPE_LOCAL_REGION_FIELD:
  389. obj_desc = (void *) obj_desc->field.region_obj;
  390. break;
  391. case ACPI_TYPE_LOCAL_BANK_FIELD:
  392. obj_desc = (void *) obj_desc->bank_field.region_obj;
  393. break;
  394. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  395. obj_desc = (void *) obj_desc->index_field.index_obj;
  396. break;
  397. default:
  398. goto cleanup;
  399. }
  400. obj_type = ACPI_TYPE_INVALID; /* Terminate loop after next pass */
  401. }
  402. cleanup:
  403. acpi_os_printf ("\n");
  404. return (AE_OK);
  405. }
  406. #ifdef ACPI_FUTURE_USAGE
  407. /*******************************************************************************
  408. *
  409. * FUNCTION: acpi_ns_dump_objects
  410. *
  411. * PARAMETERS: Type - Object type to be dumped
  412. * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
  413. * for an effectively unlimited depth.
  414. * owner_id - Dump only objects owned by this ID. Use
  415. * ACPI_UINT32_MAX to match all owners.
  416. * start_handle - Where in namespace to start/end search
  417. *
  418. * DESCRIPTION: Dump typed objects within the loaded namespace.
  419. * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
  420. *
  421. ******************************************************************************/
  422. void
  423. acpi_ns_dump_objects (
  424. acpi_object_type type,
  425. u8 display_type,
  426. u32 max_depth,
  427. u32 owner_id,
  428. acpi_handle start_handle)
  429. {
  430. struct acpi_walk_info info;
  431. ACPI_FUNCTION_ENTRY ();
  432. info.debug_level = ACPI_LV_TABLES;
  433. info.owner_id = owner_id;
  434. info.display_type = display_type;
  435. (void) acpi_ns_walk_namespace (type, start_handle, max_depth,
  436. ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_object,
  437. (void *) &info, NULL);
  438. }
  439. /*******************************************************************************
  440. *
  441. * FUNCTION: acpi_ns_dump_tables
  442. *
  443. * PARAMETERS: search_base - Root of subtree to be dumped, or
  444. * NS_ALL to dump the entire namespace
  445. * max_depth - Maximum depth of dump. Use INT_MAX
  446. * for an effectively unlimited depth.
  447. *
  448. * DESCRIPTION: Dump the name space, or a portion of it.
  449. *
  450. ******************************************************************************/
  451. void
  452. acpi_ns_dump_tables (
  453. acpi_handle search_base,
  454. u32 max_depth)
  455. {
  456. acpi_handle search_handle = search_base;
  457. ACPI_FUNCTION_TRACE ("ns_dump_tables");
  458. if (!acpi_gbl_root_node) {
  459. /*
  460. * If the name space has not been initialized,
  461. * there is nothing to dump.
  462. */
  463. ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "namespace not initialized!\n"));
  464. return_VOID;
  465. }
  466. if (ACPI_NS_ALL == search_base) {
  467. /* entire namespace */
  468. search_handle = acpi_gbl_root_node;
  469. ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
  470. }
  471. acpi_ns_dump_objects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, max_depth,
  472. ACPI_UINT32_MAX, search_handle);
  473. return_VOID;
  474. }
  475. #endif /* ACPI_FUTURE_USAGE */
  476. /*******************************************************************************
  477. *
  478. * FUNCTION: acpi_ns_dump_entry
  479. *
  480. * PARAMETERS: Handle - Node to be dumped
  481. * debug_level - Output level
  482. *
  483. * DESCRIPTION: Dump a single Node
  484. *
  485. ******************************************************************************/
  486. void
  487. acpi_ns_dump_entry (
  488. acpi_handle handle,
  489. u32 debug_level)
  490. {
  491. struct acpi_walk_info info;
  492. ACPI_FUNCTION_ENTRY ();
  493. info.debug_level = debug_level;
  494. info.owner_id = ACPI_UINT32_MAX;
  495. info.display_type = ACPI_DISPLAY_SUMMARY;
  496. (void) acpi_ns_dump_one_object (handle, 1, &info, NULL);
  497. }
  498. #endif