exdebug.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: exdebug - Support for stores to the AML Debug Object
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acinterp.h"
  12. #define _COMPONENT ACPI_EXECUTER
  13. ACPI_MODULE_NAME("exdebug")
  14. #ifndef ACPI_NO_ERROR_MESSAGES
  15. /*******************************************************************************
  16. *
  17. * FUNCTION: acpi_ex_do_debug_object
  18. *
  19. * PARAMETERS: source_desc - Object to be output to "Debug Object"
  20. * level - Indentation level (used for packages)
  21. * index - Current package element, zero if not pkg
  22. *
  23. * RETURN: None
  24. *
  25. * DESCRIPTION: Handles stores to the AML Debug Object. For example:
  26. * Store(INT1, Debug)
  27. *
  28. * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
  29. *
  30. * This function is only enabled if acpi_gbl_enable_aml_debug_object is set, or
  31. * if ACPI_LV_DEBUG_OBJECT is set in the acpi_dbg_level. Thus, in the normal
  32. * operational case, stores to the debug object are ignored but can be easily
  33. * enabled if necessary.
  34. *
  35. ******************************************************************************/
  36. void
  37. acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
  38. u32 level, u32 index)
  39. {
  40. u32 i;
  41. u32 timer;
  42. union acpi_operand_object *object_desc;
  43. u32 value;
  44. ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
  45. /* Output must be enabled via the debug_object global or the dbg_level */
  46. if (!acpi_gbl_enable_aml_debug_object &&
  47. !(acpi_dbg_level & ACPI_LV_DEBUG_OBJECT)) {
  48. return_VOID;
  49. }
  50. /* Newline -- don't emit the line header */
  51. if (source_desc &&
  52. (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) &&
  53. (source_desc->common.type == ACPI_TYPE_STRING)) {
  54. if ((source_desc->string.length == 1) &&
  55. (*source_desc->string.pointer == '\n')) {
  56. acpi_os_printf("\n");
  57. return_VOID;
  58. }
  59. }
  60. /*
  61. * Print line header as long as we are not in the middle of an
  62. * object display
  63. */
  64. if (!((level > 0) && index == 0)) {
  65. if (acpi_gbl_display_debug_timer) {
  66. /*
  67. * We will emit the current timer value (in microseconds) with each
  68. * debug output. Only need the lower 26 bits. This allows for 67
  69. * million microseconds or 67 seconds before rollover.
  70. *
  71. * Convert 100 nanosecond units to microseconds
  72. */
  73. timer = ((u32)acpi_os_get_timer() / 10);
  74. timer &= 0x03FFFFFF;
  75. acpi_os_printf("ACPI Debug: T=0x%8.8X %*s", timer,
  76. level, " ");
  77. } else {
  78. acpi_os_printf("ACPI Debug: %*s", level, " ");
  79. }
  80. }
  81. /* Display the index for package output only */
  82. if (index > 0) {
  83. acpi_os_printf("(%.2u) ", index - 1);
  84. }
  85. if (!source_desc) {
  86. acpi_os_printf("[Null Object]\n");
  87. return_VOID;
  88. }
  89. if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
  90. /* No object type prefix needed for integers and strings */
  91. if ((source_desc->common.type != ACPI_TYPE_INTEGER) &&
  92. (source_desc->common.type != ACPI_TYPE_STRING)) {
  93. acpi_os_printf("%s ",
  94. acpi_ut_get_object_type_name
  95. (source_desc));
  96. }
  97. if (!acpi_ut_valid_internal_object(source_desc)) {
  98. acpi_os_printf("%p, Invalid Internal Object!\n",
  99. source_desc);
  100. return_VOID;
  101. }
  102. } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
  103. ACPI_DESC_TYPE_NAMED) {
  104. acpi_os_printf("%s (Node %p)\n",
  105. acpi_ut_get_type_name(((struct
  106. acpi_namespace_node *)
  107. source_desc)->type),
  108. source_desc);
  109. return_VOID;
  110. } else {
  111. return_VOID;
  112. }
  113. /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
  114. switch (source_desc->common.type) {
  115. case ACPI_TYPE_INTEGER:
  116. /* Output correct integer width */
  117. if (acpi_gbl_integer_byte_width == 4) {
  118. acpi_os_printf("0x%8.8X\n",
  119. (u32)source_desc->integer.value);
  120. } else {
  121. acpi_os_printf("0x%8.8X%8.8X\n",
  122. ACPI_FORMAT_UINT64(source_desc->integer.
  123. value));
  124. }
  125. break;
  126. case ACPI_TYPE_BUFFER:
  127. acpi_os_printf("[0x%.2X]\n", (u32)source_desc->buffer.length);
  128. acpi_ut_dump_buffer(source_desc->buffer.pointer,
  129. (source_desc->buffer.length < 256) ?
  130. source_desc->buffer.length : 256,
  131. DB_BYTE_DISPLAY, 0);
  132. break;
  133. case ACPI_TYPE_STRING:
  134. acpi_os_printf("\"%s\"\n", source_desc->string.pointer);
  135. break;
  136. case ACPI_TYPE_PACKAGE:
  137. acpi_os_printf("(Contains 0x%.2X Elements):\n",
  138. source_desc->package.count);
  139. /* Output the entire contents of the package */
  140. for (i = 0; i < source_desc->package.count; i++) {
  141. acpi_ex_do_debug_object(source_desc->package.
  142. elements[i], level + 4, i + 1);
  143. }
  144. break;
  145. case ACPI_TYPE_LOCAL_REFERENCE:
  146. acpi_os_printf("[%s] ",
  147. acpi_ut_get_reference_name(source_desc));
  148. /* Decode the reference */
  149. switch (source_desc->reference.class) {
  150. case ACPI_REFCLASS_INDEX:
  151. acpi_os_printf("0x%X\n", source_desc->reference.value);
  152. break;
  153. case ACPI_REFCLASS_TABLE:
  154. /* Case for ddb_handle */
  155. acpi_os_printf("Table Index 0x%X\n",
  156. source_desc->reference.value);
  157. return_VOID;
  158. default:
  159. break;
  160. }
  161. acpi_os_printf(" ");
  162. /* Check for valid node first, then valid object */
  163. if (source_desc->reference.node) {
  164. if (ACPI_GET_DESCRIPTOR_TYPE
  165. (source_desc->reference.node) !=
  166. ACPI_DESC_TYPE_NAMED) {
  167. acpi_os_printf
  168. (" %p - Not a valid namespace node\n",
  169. source_desc->reference.node);
  170. } else {
  171. acpi_os_printf("Node %p [%4.4s] ",
  172. source_desc->reference.node,
  173. (source_desc->reference.node)->
  174. name.ascii);
  175. switch ((source_desc->reference.node)->type) {
  176. /* These types have no attached object */
  177. case ACPI_TYPE_DEVICE:
  178. acpi_os_printf("Device\n");
  179. break;
  180. case ACPI_TYPE_THERMAL:
  181. acpi_os_printf("Thermal Zone\n");
  182. break;
  183. default:
  184. acpi_ex_do_debug_object((source_desc->
  185. reference.
  186. node)->object,
  187. level + 4, 0);
  188. break;
  189. }
  190. }
  191. } else if (source_desc->reference.object) {
  192. if (ACPI_GET_DESCRIPTOR_TYPE
  193. (source_desc->reference.object) ==
  194. ACPI_DESC_TYPE_NAMED) {
  195. /* Reference object is a namespace node */
  196. acpi_ex_do_debug_object(ACPI_CAST_PTR
  197. (union
  198. acpi_operand_object,
  199. source_desc->reference.
  200. object), level + 4, 0);
  201. } else {
  202. object_desc = source_desc->reference.object;
  203. value = source_desc->reference.value;
  204. switch (object_desc->common.type) {
  205. case ACPI_TYPE_BUFFER:
  206. acpi_os_printf("Buffer[%u] = 0x%2.2X\n",
  207. value,
  208. *source_desc->reference.
  209. index_pointer);
  210. break;
  211. case ACPI_TYPE_STRING:
  212. acpi_os_printf
  213. ("String[%u] = \"%c\" (0x%2.2X)\n",
  214. value,
  215. *source_desc->reference.
  216. index_pointer,
  217. *source_desc->reference.
  218. index_pointer);
  219. break;
  220. case ACPI_TYPE_PACKAGE:
  221. acpi_os_printf("Package[%u] = ", value);
  222. if (!(*source_desc->reference.where)) {
  223. acpi_os_printf
  224. ("[Uninitialized Package Element]\n");
  225. } else {
  226. acpi_ex_do_debug_object
  227. (*source_desc->reference.
  228. where, level + 4, 0);
  229. }
  230. break;
  231. default:
  232. acpi_os_printf
  233. ("Unknown Reference object type %X\n",
  234. object_desc->common.type);
  235. break;
  236. }
  237. }
  238. }
  239. break;
  240. default:
  241. acpi_os_printf("(Descriptor %p)\n", source_desc);
  242. break;
  243. }
  244. ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
  245. return_VOID;
  246. }
  247. #endif