utxferror.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*******************************************************************************
  2. *
  3. * Module Name: utxferror - Various error/warning output functions
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, 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 <linux/export.h>
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acnamesp.h"
  46. #define _COMPONENT ACPI_UTILITIES
  47. ACPI_MODULE_NAME("utxferror")
  48. /*
  49. * This module is used for the in-kernel ACPICA as well as the ACPICA
  50. * tools/applications.
  51. *
  52. * For the i_aSL compiler case, the output is redirected to stderr so that
  53. * any of the various ACPI errors and warnings do not appear in the output
  54. * files, for either the compiler or disassembler portions of the tool.
  55. */
  56. #ifdef ACPI_ASL_COMPILER
  57. #include <stdio.h>
  58. extern FILE *acpi_gbl_output_file;
  59. #define ACPI_MSG_REDIRECT_BEGIN \
  60. FILE *output_file = acpi_gbl_output_file; \
  61. acpi_os_redirect_output (stderr);
  62. #define ACPI_MSG_REDIRECT_END \
  63. acpi_os_redirect_output (output_file);
  64. #else
  65. /*
  66. * non-i_aSL case - no redirection, nothing to do
  67. */
  68. #define ACPI_MSG_REDIRECT_BEGIN
  69. #define ACPI_MSG_REDIRECT_END
  70. #endif
  71. /*
  72. * Common message prefixes
  73. */
  74. #define ACPI_MSG_ERROR "ACPI Error: "
  75. #define ACPI_MSG_EXCEPTION "ACPI Exception: "
  76. #define ACPI_MSG_WARNING "ACPI Warning: "
  77. #define ACPI_MSG_INFO "ACPI: "
  78. /*
  79. * Common message suffix
  80. */
  81. #define ACPI_MSG_SUFFIX \
  82. acpi_os_printf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number)
  83. /*******************************************************************************
  84. *
  85. * FUNCTION: acpi_error
  86. *
  87. * PARAMETERS: module_name - Caller's module name (for error output)
  88. * line_number - Caller's line number (for error output)
  89. * Format - Printf format string + additional args
  90. *
  91. * RETURN: None
  92. *
  93. * DESCRIPTION: Print "ACPI Error" message with module/line/version info
  94. *
  95. ******************************************************************************/
  96. void ACPI_INTERNAL_VAR_XFACE
  97. acpi_error(const char *module_name, u32 line_number, const char *format, ...)
  98. {
  99. va_list arg_list;
  100. ACPI_MSG_REDIRECT_BEGIN;
  101. acpi_os_printf(ACPI_MSG_ERROR);
  102. va_start(arg_list, format);
  103. acpi_os_vprintf(format, arg_list);
  104. ACPI_MSG_SUFFIX;
  105. va_end(arg_list);
  106. ACPI_MSG_REDIRECT_END;
  107. }
  108. ACPI_EXPORT_SYMBOL(acpi_error)
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: acpi_exception
  112. *
  113. * PARAMETERS: module_name - Caller's module name (for error output)
  114. * line_number - Caller's line number (for error output)
  115. * Status - Status to be formatted
  116. * Format - Printf format string + additional args
  117. *
  118. * RETURN: None
  119. *
  120. * DESCRIPTION: Print "ACPI Exception" message with module/line/version info
  121. * and decoded acpi_status.
  122. *
  123. ******************************************************************************/
  124. void ACPI_INTERNAL_VAR_XFACE
  125. acpi_exception(const char *module_name,
  126. u32 line_number, acpi_status status, const char *format, ...)
  127. {
  128. va_list arg_list;
  129. ACPI_MSG_REDIRECT_BEGIN;
  130. acpi_os_printf(ACPI_MSG_EXCEPTION "%s, ",
  131. acpi_format_exception(status));
  132. va_start(arg_list, format);
  133. acpi_os_vprintf(format, arg_list);
  134. ACPI_MSG_SUFFIX;
  135. va_end(arg_list);
  136. ACPI_MSG_REDIRECT_END;
  137. }
  138. ACPI_EXPORT_SYMBOL(acpi_exception)
  139. /*******************************************************************************
  140. *
  141. * FUNCTION: acpi_warning
  142. *
  143. * PARAMETERS: module_name - Caller's module name (for error output)
  144. * line_number - Caller's line number (for error output)
  145. * Format - Printf format string + additional args
  146. *
  147. * RETURN: None
  148. *
  149. * DESCRIPTION: Print "ACPI Warning" message with module/line/version info
  150. *
  151. ******************************************************************************/
  152. void ACPI_INTERNAL_VAR_XFACE
  153. acpi_warning(const char *module_name, u32 line_number, const char *format, ...)
  154. {
  155. va_list arg_list;
  156. ACPI_MSG_REDIRECT_BEGIN;
  157. acpi_os_printf(ACPI_MSG_WARNING);
  158. va_start(arg_list, format);
  159. acpi_os_vprintf(format, arg_list);
  160. ACPI_MSG_SUFFIX;
  161. va_end(arg_list);
  162. ACPI_MSG_REDIRECT_END;
  163. }
  164. ACPI_EXPORT_SYMBOL(acpi_warning)
  165. /*******************************************************************************
  166. *
  167. * FUNCTION: acpi_info
  168. *
  169. * PARAMETERS: module_name - Caller's module name (for error output)
  170. * line_number - Caller's line number (for error output)
  171. * Format - Printf format string + additional args
  172. *
  173. * RETURN: None
  174. *
  175. * DESCRIPTION: Print generic "ACPI:" information message. There is no
  176. * module/line/version info in order to keep the message simple.
  177. *
  178. * TBD: module_name and line_number args are not needed, should be removed.
  179. *
  180. ******************************************************************************/
  181. void ACPI_INTERNAL_VAR_XFACE
  182. acpi_info(const char *module_name, u32 line_number, const char *format, ...)
  183. {
  184. va_list arg_list;
  185. ACPI_MSG_REDIRECT_BEGIN;
  186. acpi_os_printf(ACPI_MSG_INFO);
  187. va_start(arg_list, format);
  188. acpi_os_vprintf(format, arg_list);
  189. acpi_os_printf("\n");
  190. va_end(arg_list);
  191. ACPI_MSG_REDIRECT_END;
  192. }
  193. ACPI_EXPORT_SYMBOL(acpi_info)
  194. /*
  195. * The remainder of this module contains internal error functions that may
  196. * be configured out.
  197. */
  198. #if !defined (ACPI_NO_ERROR_MESSAGES) && !defined (ACPI_BIN_APP)
  199. /*******************************************************************************
  200. *
  201. * FUNCTION: acpi_ut_predefined_warning
  202. *
  203. * PARAMETERS: module_name - Caller's module name (for error output)
  204. * line_number - Caller's line number (for error output)
  205. * Pathname - Full pathname to the node
  206. * node_flags - From Namespace node for the method/object
  207. * Format - Printf format string + additional args
  208. *
  209. * RETURN: None
  210. *
  211. * DESCRIPTION: Warnings for the predefined validation module. Messages are
  212. * only emitted the first time a problem with a particular
  213. * method/object is detected. This prevents a flood of error
  214. * messages for methods that are repeatedly evaluated.
  215. *
  216. ******************************************************************************/
  217. void ACPI_INTERNAL_VAR_XFACE
  218. acpi_ut_predefined_warning(const char *module_name,
  219. u32 line_number,
  220. char *pathname,
  221. u8 node_flags, const char *format, ...)
  222. {
  223. va_list arg_list;
  224. /*
  225. * Warning messages for this method/object will be disabled after the
  226. * first time a validation fails or an object is successfully repaired.
  227. */
  228. if (node_flags & ANOBJ_EVALUATED) {
  229. return;
  230. }
  231. acpi_os_printf(ACPI_MSG_WARNING "For %s: ", pathname);
  232. va_start(arg_list, format);
  233. acpi_os_vprintf(format, arg_list);
  234. ACPI_MSG_SUFFIX;
  235. va_end(arg_list);
  236. }
  237. /*******************************************************************************
  238. *
  239. * FUNCTION: acpi_ut_predefined_info
  240. *
  241. * PARAMETERS: module_name - Caller's module name (for error output)
  242. * line_number - Caller's line number (for error output)
  243. * Pathname - Full pathname to the node
  244. * node_flags - From Namespace node for the method/object
  245. * Format - Printf format string + additional args
  246. *
  247. * RETURN: None
  248. *
  249. * DESCRIPTION: Info messages for the predefined validation module. Messages
  250. * are only emitted the first time a problem with a particular
  251. * method/object is detected. This prevents a flood of
  252. * messages for methods that are repeatedly evaluated.
  253. *
  254. ******************************************************************************/
  255. void ACPI_INTERNAL_VAR_XFACE
  256. acpi_ut_predefined_info(const char *module_name,
  257. u32 line_number,
  258. char *pathname, u8 node_flags, const char *format, ...)
  259. {
  260. va_list arg_list;
  261. /*
  262. * Warning messages for this method/object will be disabled after the
  263. * first time a validation fails or an object is successfully repaired.
  264. */
  265. if (node_flags & ANOBJ_EVALUATED) {
  266. return;
  267. }
  268. acpi_os_printf(ACPI_MSG_INFO "For %s: ", pathname);
  269. va_start(arg_list, format);
  270. acpi_os_vprintf(format, arg_list);
  271. ACPI_MSG_SUFFIX;
  272. va_end(arg_list);
  273. }
  274. /*******************************************************************************
  275. *
  276. * FUNCTION: acpi_ut_namespace_error
  277. *
  278. * PARAMETERS: module_name - Caller's module name (for error output)
  279. * line_number - Caller's line number (for error output)
  280. * internal_name - Name or path of the namespace node
  281. * lookup_status - Exception code from NS lookup
  282. *
  283. * RETURN: None
  284. *
  285. * DESCRIPTION: Print error message with the full pathname for the NS node.
  286. *
  287. ******************************************************************************/
  288. void
  289. acpi_ut_namespace_error(const char *module_name,
  290. u32 line_number,
  291. const char *internal_name, acpi_status lookup_status)
  292. {
  293. acpi_status status;
  294. u32 bad_name;
  295. char *name = NULL;
  296. ACPI_MSG_REDIRECT_BEGIN;
  297. acpi_os_printf(ACPI_MSG_ERROR);
  298. if (lookup_status == AE_BAD_CHARACTER) {
  299. /* There is a non-ascii character in the name */
  300. ACPI_MOVE_32_TO_32(&bad_name,
  301. ACPI_CAST_PTR(u32, internal_name));
  302. acpi_os_printf("[0x%4.4X] (NON-ASCII)", bad_name);
  303. } else {
  304. /* Convert path to external format */
  305. status = acpi_ns_externalize_name(ACPI_UINT32_MAX,
  306. internal_name, NULL, &name);
  307. /* Print target name */
  308. if (ACPI_SUCCESS(status)) {
  309. acpi_os_printf("[%s]", name);
  310. } else {
  311. acpi_os_printf("[COULD NOT EXTERNALIZE NAME]");
  312. }
  313. if (name) {
  314. ACPI_FREE(name);
  315. }
  316. }
  317. acpi_os_printf(" Namespace lookup failure, %s",
  318. acpi_format_exception(lookup_status));
  319. ACPI_MSG_SUFFIX;
  320. ACPI_MSG_REDIRECT_END;
  321. }
  322. /*******************************************************************************
  323. *
  324. * FUNCTION: acpi_ut_method_error
  325. *
  326. * PARAMETERS: module_name - Caller's module name (for error output)
  327. * line_number - Caller's line number (for error output)
  328. * Message - Error message to use on failure
  329. * prefix_node - Prefix relative to the path
  330. * Path - Path to the node (optional)
  331. * method_status - Execution status
  332. *
  333. * RETURN: None
  334. *
  335. * DESCRIPTION: Print error message with the full pathname for the method.
  336. *
  337. ******************************************************************************/
  338. void
  339. acpi_ut_method_error(const char *module_name,
  340. u32 line_number,
  341. const char *message,
  342. struct acpi_namespace_node *prefix_node,
  343. const char *path, acpi_status method_status)
  344. {
  345. acpi_status status;
  346. struct acpi_namespace_node *node = prefix_node;
  347. ACPI_MSG_REDIRECT_BEGIN;
  348. acpi_os_printf(ACPI_MSG_ERROR);
  349. if (path) {
  350. status =
  351. acpi_ns_get_node(prefix_node, path, ACPI_NS_NO_UPSEARCH,
  352. &node);
  353. if (ACPI_FAILURE(status)) {
  354. acpi_os_printf("[Could not get node by pathname]");
  355. }
  356. }
  357. acpi_ns_print_node_pathname(node, message);
  358. acpi_os_printf(", %s", acpi_format_exception(method_status));
  359. ACPI_MSG_SUFFIX;
  360. ACPI_MSG_REDIRECT_END;
  361. }
  362. #endif /* ACPI_NO_ERROR_MESSAGES */