1
1

exdebug.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /******************************************************************************
  2. *
  3. * Module Name: exdebug - Support for stores to the AML Debug Object
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2019, 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.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: AcpiExDoDebugObject
  51. *
  52. * PARAMETERS: SourceDesc - 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 AcpiGbl_EnableAmlDebugObject is set, or
  64. * if ACPI_LV_DEBUG_OBJECT is set in the AcpiDbgLevel. 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. AcpiExDoDebugObject (
  71. ACPI_OPERAND_OBJECT *SourceDesc,
  72. UINT32 Level,
  73. UINT32 Index)
  74. {
  75. UINT32 i;
  76. UINT32 Timer;
  77. ACPI_OPERAND_OBJECT *ObjectDesc;
  78. UINT32 Value;
  79. ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
  80. /* Output must be enabled via the DebugObject global or the DbgLevel */
  81. if (!AcpiGbl_EnableAmlDebugObject &&
  82. !(AcpiDbgLevel & ACPI_LV_DEBUG_OBJECT))
  83. {
  84. return_VOID;
  85. }
  86. /* Newline -- don't emit the line header */
  87. if (SourceDesc &&
  88. (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND) &&
  89. (SourceDesc->Common.Type == ACPI_TYPE_STRING))
  90. {
  91. if ((SourceDesc->String.Length == 1) &&
  92. (*SourceDesc->String.Pointer == '\n'))
  93. {
  94. AcpiOsPrintf ("\n");
  95. return_VOID;
  96. }
  97. }
  98. /*
  99. * Print line header as long as we are not in the middle of an
  100. * object display
  101. */
  102. if (!((Level > 0) && Index == 0))
  103. {
  104. if (AcpiGbl_DisplayDebugTimer)
  105. {
  106. /*
  107. * We will emit the current timer value (in microseconds) with each
  108. * debug output. Only need the lower 26 bits. This allows for 67
  109. * million microseconds or 67 seconds before rollover.
  110. *
  111. * Convert 100 nanosecond units to microseconds
  112. */
  113. Timer = ((UINT32) AcpiOsGetTimer () / 10);
  114. Timer &= 0x03FFFFFF;
  115. AcpiOsPrintf ("ACPI Debug: T=0x%8.8X %*s", Timer, Level, " ");
  116. }
  117. else
  118. {
  119. AcpiOsPrintf ("ACPI Debug: %*s", Level, " ");
  120. }
  121. }
  122. /* Display the index for package output only */
  123. if (Index > 0)
  124. {
  125. AcpiOsPrintf ("(%.2u) ", Index - 1);
  126. }
  127. if (!SourceDesc)
  128. {
  129. AcpiOsPrintf ("[Null Object]\n");
  130. return_VOID;
  131. }
  132. if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
  133. {
  134. /* No object type prefix needed for integers and strings */
  135. if ((SourceDesc->Common.Type != ACPI_TYPE_INTEGER) &&
  136. (SourceDesc->Common.Type != ACPI_TYPE_STRING))
  137. {
  138. AcpiOsPrintf ("%s ", AcpiUtGetObjectTypeName (SourceDesc));
  139. }
  140. if (!AcpiUtValidInternalObject (SourceDesc))
  141. {
  142. AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc);
  143. return_VOID;
  144. }
  145. }
  146. else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
  147. {
  148. AcpiOsPrintf ("%s (Node %p)\n",
  149. AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
  150. SourceDesc);
  151. return_VOID;
  152. }
  153. else
  154. {
  155. return_VOID;
  156. }
  157. /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */
  158. switch (SourceDesc->Common.Type)
  159. {
  160. case ACPI_TYPE_INTEGER:
  161. /* Output correct integer width */
  162. if (AcpiGbl_IntegerByteWidth == 4)
  163. {
  164. AcpiOsPrintf ("0x%8.8X\n",
  165. (UINT32) SourceDesc->Integer.Value);
  166. }
  167. else
  168. {
  169. AcpiOsPrintf ("0x%8.8X%8.8X\n",
  170. ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value));
  171. }
  172. break;
  173. case ACPI_TYPE_BUFFER:
  174. AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length);
  175. AcpiUtDumpBuffer (SourceDesc->Buffer.Pointer,
  176. (SourceDesc->Buffer.Length < 256) ?
  177. SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY, 0);
  178. break;
  179. case ACPI_TYPE_STRING:
  180. AcpiOsPrintf ("\"%s\"\n", SourceDesc->String.Pointer);
  181. break;
  182. case ACPI_TYPE_PACKAGE:
  183. AcpiOsPrintf ("(Contains 0x%.2X Elements):\n",
  184. SourceDesc->Package.Count);
  185. /* Output the entire contents of the package */
  186. for (i = 0; i < SourceDesc->Package.Count; i++)
  187. {
  188. AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
  189. Level + 4, i + 1);
  190. }
  191. break;
  192. case ACPI_TYPE_LOCAL_REFERENCE:
  193. AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc));
  194. /* Decode the reference */
  195. switch (SourceDesc->Reference.Class)
  196. {
  197. case ACPI_REFCLASS_INDEX:
  198. AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value);
  199. break;
  200. case ACPI_REFCLASS_TABLE:
  201. /* Case for DdbHandle */
  202. AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value);
  203. return_VOID;
  204. default:
  205. break;
  206. }
  207. AcpiOsPrintf (" ");
  208. /* Check for valid node first, then valid object */
  209. if (SourceDesc->Reference.Node)
  210. {
  211. if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) !=
  212. ACPI_DESC_TYPE_NAMED)
  213. {
  214. AcpiOsPrintf (" %p - Not a valid namespace node\n",
  215. SourceDesc->Reference.Node);
  216. }
  217. else
  218. {
  219. AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node,
  220. (SourceDesc->Reference.Node)->Name.Ascii);
  221. switch ((SourceDesc->Reference.Node)->Type)
  222. {
  223. /* These types have no attached object */
  224. case ACPI_TYPE_DEVICE:
  225. AcpiOsPrintf ("Device\n");
  226. break;
  227. case ACPI_TYPE_THERMAL:
  228. AcpiOsPrintf ("Thermal Zone\n");
  229. break;
  230. default:
  231. AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
  232. Level + 4, 0);
  233. break;
  234. }
  235. }
  236. }
  237. else if (SourceDesc->Reference.Object)
  238. {
  239. if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
  240. ACPI_DESC_TYPE_NAMED)
  241. {
  242. /* Reference object is a namespace node */
  243. AcpiExDoDebugObject (ACPI_CAST_PTR (ACPI_OPERAND_OBJECT,
  244. SourceDesc->Reference.Object),
  245. Level + 4, 0);
  246. }
  247. else
  248. {
  249. ObjectDesc = SourceDesc->Reference.Object;
  250. Value = SourceDesc->Reference.Value;
  251. switch (ObjectDesc->Common.Type)
  252. {
  253. case ACPI_TYPE_BUFFER:
  254. AcpiOsPrintf ("Buffer[%u] = 0x%2.2X\n",
  255. Value, *SourceDesc->Reference.IndexPointer);
  256. break;
  257. case ACPI_TYPE_STRING:
  258. AcpiOsPrintf ("String[%u] = \"%c\" (0x%2.2X)\n",
  259. Value, *SourceDesc->Reference.IndexPointer,
  260. *SourceDesc->Reference.IndexPointer);
  261. break;
  262. case ACPI_TYPE_PACKAGE:
  263. AcpiOsPrintf ("Package[%u] = ", Value);
  264. if (!(*SourceDesc->Reference.Where))
  265. {
  266. AcpiOsPrintf ("[Uninitialized Package Element]\n");
  267. }
  268. else
  269. {
  270. AcpiExDoDebugObject (*SourceDesc->Reference.Where,
  271. Level+4, 0);
  272. }
  273. break;
  274. default:
  275. AcpiOsPrintf ("Unknown Reference object type %X\n",
  276. ObjectDesc->Common.Type);
  277. break;
  278. }
  279. }
  280. }
  281. break;
  282. default:
  283. AcpiOsPrintf ("(Descriptor %p)\n", SourceDesc);
  284. break;
  285. }
  286. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
  287. return_VOID;
  288. }
  289. #endif