xref: /freebsd/sys/contrib/dev/acpica/components/utilities/utxferror.c (revision f5f7c05209ca2c3748fd8b27c5e80ffad49120eb)
1 /*******************************************************************************
2  *
3  * Module Name: utxferror - Various error/warning output functions
4  *
5  ******************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 #define __UTXFERROR_C__
45 
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
49 
50 
51 #define _COMPONENT          ACPI_UTILITIES
52         ACPI_MODULE_NAME    ("utxferror")
53 
54 /*
55  * This module is used for the in-kernel ACPICA as well as the ACPICA
56  * tools/applications.
57  *
58  * For the iASL compiler case, the output is redirected to stderr so that
59  * any of the various ACPI errors and warnings do not appear in the output
60  * files, for either the compiler or disassembler portions of the tool.
61  */
62 #ifdef ACPI_ASL_COMPILER
63 #include <stdio.h>
64 
65 extern FILE                 *AcpiGbl_OutputFile;
66 
67 #define ACPI_MSG_REDIRECT_BEGIN \
68     FILE                    *OutputFile = AcpiGbl_OutputFile; \
69     AcpiOsRedirectOutput (stderr);
70 
71 #define ACPI_MSG_REDIRECT_END \
72     AcpiOsRedirectOutput (OutputFile);
73 
74 #else
75 /*
76  * non-iASL case - no redirection, nothing to do
77  */
78 #define ACPI_MSG_REDIRECT_BEGIN
79 #define ACPI_MSG_REDIRECT_END
80 #endif
81 
82 /*
83  * Common message prefixes
84  */
85 #define ACPI_MSG_ERROR          "ACPI Error: "
86 #define ACPI_MSG_EXCEPTION      "ACPI Exception: "
87 #define ACPI_MSG_WARNING        "ACPI Warning: "
88 #define ACPI_MSG_INFO           "ACPI: "
89 
90 #define ACPI_MSG_BIOS_ERROR     "ACPI BIOS Bug: Error: "
91 #define ACPI_MSG_BIOS_WARNING   "ACPI BIOS Bug: Warning: "
92 
93 /*
94  * Common message suffix
95  */
96 #define ACPI_MSG_SUFFIX \
97     AcpiOsPrintf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, ModuleName, LineNumber)
98 
99 
100 /*******************************************************************************
101  *
102  * FUNCTION:    AcpiError
103  *
104  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
105  *              LineNumber          - Caller's line number (for error output)
106  *              Format              - Printf format string + additional args
107  *
108  * RETURN:      None
109  *
110  * DESCRIPTION: Print "ACPI Error" message with module/line/version info
111  *
112  ******************************************************************************/
113 
114 void ACPI_INTERNAL_VAR_XFACE
115 AcpiError (
116     const char              *ModuleName,
117     UINT32                  LineNumber,
118     const char              *Format,
119     ...)
120 {
121     va_list                 ArgList;
122 
123 
124     ACPI_MSG_REDIRECT_BEGIN;
125     AcpiOsPrintf (ACPI_MSG_ERROR);
126 
127     va_start (ArgList, Format);
128     AcpiOsVprintf (Format, ArgList);
129     ACPI_MSG_SUFFIX;
130     va_end (ArgList);
131 
132     ACPI_MSG_REDIRECT_END;
133 }
134 
135 ACPI_EXPORT_SYMBOL (AcpiError)
136 
137 
138 /*******************************************************************************
139  *
140  * FUNCTION:    AcpiException
141  *
142  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
143  *              LineNumber          - Caller's line number (for error output)
144  *              Status              - Status to be formatted
145  *              Format              - Printf format string + additional args
146  *
147  * RETURN:      None
148  *
149  * DESCRIPTION: Print "ACPI Exception" message with module/line/version info
150  *              and decoded ACPI_STATUS.
151  *
152  ******************************************************************************/
153 
154 void ACPI_INTERNAL_VAR_XFACE
155 AcpiException (
156     const char              *ModuleName,
157     UINT32                  LineNumber,
158     ACPI_STATUS             Status,
159     const char              *Format,
160     ...)
161 {
162     va_list                 ArgList;
163 
164 
165     ACPI_MSG_REDIRECT_BEGIN;
166     AcpiOsPrintf (ACPI_MSG_EXCEPTION "%s, ", AcpiFormatException (Status));
167 
168     va_start (ArgList, Format);
169     AcpiOsVprintf (Format, ArgList);
170     ACPI_MSG_SUFFIX;
171     va_end (ArgList);
172 
173     ACPI_MSG_REDIRECT_END;
174 }
175 
176 ACPI_EXPORT_SYMBOL (AcpiException)
177 
178 
179 /*******************************************************************************
180  *
181  * FUNCTION:    AcpiWarning
182  *
183  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
184  *              LineNumber          - Caller's line number (for error output)
185  *              Format              - Printf format string + additional args
186  *
187  * RETURN:      None
188  *
189  * DESCRIPTION: Print "ACPI Warning" message with module/line/version info
190  *
191  ******************************************************************************/
192 
193 void ACPI_INTERNAL_VAR_XFACE
194 AcpiWarning (
195     const char              *ModuleName,
196     UINT32                  LineNumber,
197     const char              *Format,
198     ...)
199 {
200     va_list                 ArgList;
201 
202 
203     ACPI_MSG_REDIRECT_BEGIN;
204     AcpiOsPrintf (ACPI_MSG_WARNING);
205 
206     va_start (ArgList, Format);
207     AcpiOsVprintf (Format, ArgList);
208     ACPI_MSG_SUFFIX;
209     va_end (ArgList);
210 
211     ACPI_MSG_REDIRECT_END;
212 }
213 
214 ACPI_EXPORT_SYMBOL (AcpiWarning)
215 
216 
217 /*******************************************************************************
218  *
219  * FUNCTION:    AcpiInfo
220  *
221  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
222  *              LineNumber          - Caller's line number (for error output)
223  *              Format              - Printf format string + additional args
224  *
225  * RETURN:      None
226  *
227  * DESCRIPTION: Print generic "ACPI:" information message. There is no
228  *              module/line/version info in order to keep the message simple.
229  *
230  * TBD: ModuleName and LineNumber args are not needed, should be removed.
231  *
232  ******************************************************************************/
233 
234 void ACPI_INTERNAL_VAR_XFACE
235 AcpiInfo (
236     const char              *ModuleName,
237     UINT32                  LineNumber,
238     const char              *Format,
239     ...)
240 {
241     va_list                 ArgList;
242 
243 #ifdef _KERNEL
244     /* Temporarily hide too verbose printfs. */
245     if (!bootverbose)
246 	return;
247 #endif
248 
249     ACPI_MSG_REDIRECT_BEGIN;
250     AcpiOsPrintf (ACPI_MSG_INFO);
251 
252     va_start (ArgList, Format);
253     AcpiOsVprintf (Format, ArgList);
254     AcpiOsPrintf ("\n");
255     va_end (ArgList);
256 
257     ACPI_MSG_REDIRECT_END;
258 }
259 
260 ACPI_EXPORT_SYMBOL (AcpiInfo)
261 
262 
263 /*******************************************************************************
264  *
265  * FUNCTION:    AcpiBiosError
266  *
267  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
268  *              LineNumber          - Caller's line number (for error output)
269  *              Format              - Printf format string + additional args
270  *
271  * RETURN:      None
272  *
273  * DESCRIPTION: Print "ACPI Firmware Error" message with module/line/version
274  *              info
275  *
276  ******************************************************************************/
277 
278 void ACPI_INTERNAL_VAR_XFACE
279 AcpiBiosError (
280     const char              *ModuleName,
281     UINT32                  LineNumber,
282     const char              *Format,
283     ...)
284 {
285     va_list                 ArgList;
286 
287 
288     ACPI_MSG_REDIRECT_BEGIN;
289     AcpiOsPrintf (ACPI_MSG_BIOS_ERROR);
290 
291     va_start (ArgList, Format);
292     AcpiOsVprintf (Format, ArgList);
293     ACPI_MSG_SUFFIX;
294     va_end (ArgList);
295 
296     ACPI_MSG_REDIRECT_END;
297 }
298 
299 ACPI_EXPORT_SYMBOL (AcpiBiosError)
300 
301 
302 /*******************************************************************************
303  *
304  * FUNCTION:    AcpiBiosWarning
305  *
306  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
307  *              LineNumber          - Caller's line number (for error output)
308  *              Format              - Printf format string + additional args
309  *
310  * RETURN:      None
311  *
312  * DESCRIPTION: Print "ACPI Firmware Warning" message with module/line/version
313  *              info
314  *
315  ******************************************************************************/
316 
317 void ACPI_INTERNAL_VAR_XFACE
318 AcpiBiosWarning (
319     const char              *ModuleName,
320     UINT32                  LineNumber,
321     const char              *Format,
322     ...)
323 {
324     va_list                 ArgList;
325 
326 
327     ACPI_MSG_REDIRECT_BEGIN;
328     AcpiOsPrintf (ACPI_MSG_BIOS_WARNING);
329 
330     va_start (ArgList, Format);
331     AcpiOsVprintf (Format, ArgList);
332     ACPI_MSG_SUFFIX;
333     va_end (ArgList);
334 
335     ACPI_MSG_REDIRECT_END;
336 }
337 
338 ACPI_EXPORT_SYMBOL (AcpiBiosWarning)
339 
340 
341 /*
342  * The remainder of this module contains internal error functions that may
343  * be configured out.
344  */
345 #if !defined (ACPI_NO_ERROR_MESSAGES) && !defined (ACPI_BIN_APP)
346 
347 /*******************************************************************************
348  *
349  * FUNCTION:    AcpiUtPredefinedWarning
350  *
351  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
352  *              LineNumber      - Caller's line number (for error output)
353  *              Pathname        - Full pathname to the node
354  *              NodeFlags       - From Namespace node for the method/object
355  *              Format          - Printf format string + additional args
356  *
357  * RETURN:      None
358  *
359  * DESCRIPTION: Warnings for the predefined validation module. Messages are
360  *              only emitted the first time a problem with a particular
361  *              method/object is detected. This prevents a flood of error
362  *              messages for methods that are repeatedly evaluated.
363  *
364  ******************************************************************************/
365 
366 void ACPI_INTERNAL_VAR_XFACE
367 AcpiUtPredefinedWarning (
368     const char              *ModuleName,
369     UINT32                  LineNumber,
370     char                    *Pathname,
371     UINT8                   NodeFlags,
372     const char              *Format,
373     ...)
374 {
375     va_list                 ArgList;
376 
377 
378     /*
379      * Warning messages for this method/object will be disabled after the
380      * first time a validation fails or an object is successfully repaired.
381      */
382     if (NodeFlags & ANOBJ_EVALUATED)
383     {
384         return;
385     }
386 
387     AcpiOsPrintf (ACPI_MSG_WARNING "For %s: ", Pathname);
388 
389     va_start (ArgList, Format);
390     AcpiOsVprintf (Format, ArgList);
391     ACPI_MSG_SUFFIX;
392     va_end (ArgList);
393 }
394 
395 
396 /*******************************************************************************
397  *
398  * FUNCTION:    AcpiUtPredefinedInfo
399  *
400  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
401  *              LineNumber      - Caller's line number (for error output)
402  *              Pathname        - Full pathname to the node
403  *              NodeFlags       - From Namespace node for the method/object
404  *              Format          - Printf format string + additional args
405  *
406  * RETURN:      None
407  *
408  * DESCRIPTION: Info messages for the predefined validation module. Messages
409  *              are only emitted the first time a problem with a particular
410  *              method/object is detected. This prevents a flood of
411  *              messages for methods that are repeatedly evaluated.
412  *
413  ******************************************************************************/
414 
415 void ACPI_INTERNAL_VAR_XFACE
416 AcpiUtPredefinedInfo (
417     const char              *ModuleName,
418     UINT32                  LineNumber,
419     char                    *Pathname,
420     UINT8                   NodeFlags,
421     const char              *Format,
422     ...)
423 {
424     va_list                 ArgList;
425 
426 
427     /*
428      * Warning messages for this method/object will be disabled after the
429      * first time a validation fails or an object is successfully repaired.
430      */
431     if (NodeFlags & ANOBJ_EVALUATED)
432     {
433         return;
434     }
435 
436     AcpiOsPrintf (ACPI_MSG_INFO "For %s: ", Pathname);
437 
438     va_start (ArgList, Format);
439     AcpiOsVprintf (Format, ArgList);
440     ACPI_MSG_SUFFIX;
441     va_end (ArgList);
442 }
443 
444 
445 /*******************************************************************************
446  *
447  * FUNCTION:    AcpiUtNamespaceError
448  *
449  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
450  *              LineNumber          - Caller's line number (for error output)
451  *              InternalName        - Name or path of the namespace node
452  *              LookupStatus        - Exception code from NS lookup
453  *
454  * RETURN:      None
455  *
456  * DESCRIPTION: Print error message with the full pathname for the NS node.
457  *
458  ******************************************************************************/
459 
460 void
461 AcpiUtNamespaceError (
462     const char              *ModuleName,
463     UINT32                  LineNumber,
464     const char              *InternalName,
465     ACPI_STATUS             LookupStatus)
466 {
467     ACPI_STATUS             Status;
468     UINT32                  BadName;
469     char                    *Name = NULL;
470 
471 
472     ACPI_MSG_REDIRECT_BEGIN;
473     AcpiOsPrintf (ACPI_MSG_ERROR);
474 
475     if (LookupStatus == AE_BAD_CHARACTER)
476     {
477         /* There is a non-ascii character in the name */
478 
479         ACPI_MOVE_32_TO_32 (&BadName, ACPI_CAST_PTR (UINT32, InternalName));
480         AcpiOsPrintf ("[0x%.8X] (NON-ASCII)", BadName);
481     }
482     else
483     {
484         /* Convert path to external format */
485 
486         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
487                     InternalName, NULL, &Name);
488 
489         /* Print target name */
490 
491         if (ACPI_SUCCESS (Status))
492         {
493             AcpiOsPrintf ("[%s]", Name);
494         }
495         else
496         {
497             AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
498         }
499 
500         if (Name)
501         {
502             ACPI_FREE (Name);
503         }
504     }
505 
506     AcpiOsPrintf (" Namespace lookup failure, %s",
507         AcpiFormatException (LookupStatus));
508 
509     ACPI_MSG_SUFFIX;
510     ACPI_MSG_REDIRECT_END;
511 }
512 
513 
514 /*******************************************************************************
515  *
516  * FUNCTION:    AcpiUtMethodError
517  *
518  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
519  *              LineNumber          - Caller's line number (for error output)
520  *              Message             - Error message to use on failure
521  *              PrefixNode          - Prefix relative to the path
522  *              Path                - Path to the node (optional)
523  *              MethodStatus        - Execution status
524  *
525  * RETURN:      None
526  *
527  * DESCRIPTION: Print error message with the full pathname for the method.
528  *
529  ******************************************************************************/
530 
531 void
532 AcpiUtMethodError (
533     const char              *ModuleName,
534     UINT32                  LineNumber,
535     const char              *Message,
536     ACPI_NAMESPACE_NODE     *PrefixNode,
537     const char              *Path,
538     ACPI_STATUS             MethodStatus)
539 {
540     ACPI_STATUS             Status;
541     ACPI_NAMESPACE_NODE     *Node = PrefixNode;
542 
543 
544     ACPI_MSG_REDIRECT_BEGIN;
545     AcpiOsPrintf (ACPI_MSG_ERROR);
546 
547     if (Path)
548     {
549         Status = AcpiNsGetNode (PrefixNode, Path, ACPI_NS_NO_UPSEARCH,
550                     &Node);
551         if (ACPI_FAILURE (Status))
552         {
553             AcpiOsPrintf ("[Could not get node by pathname]");
554         }
555     }
556 
557     AcpiNsPrintNodePathname (Node, Message);
558     AcpiOsPrintf (", %s", AcpiFormatException (MethodStatus));
559 
560     ACPI_MSG_SUFFIX;
561     ACPI_MSG_REDIRECT_END;
562 }
563 
564 #endif /* ACPI_NO_ERROR_MESSAGES */
565