exdebug.c 9.4 KB

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