]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/components/utilities/utxferror.c
Import ACPICA 20130418.
[FreeBSD/FreeBSD.git] / source / components / utilities / utxferror.c
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 "acpi.h"
47 #include "accommon.h"
48 #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 Error (bug): "
91 #define ACPI_MSG_BIOS_WARNING   "ACPI BIOS Warning (bug): "
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
244     ACPI_MSG_REDIRECT_BEGIN;
245     AcpiOsPrintf (ACPI_MSG_INFO);
246
247     va_start (ArgList, Format);
248     AcpiOsVprintf (Format, ArgList);
249     AcpiOsPrintf ("\n");
250     va_end (ArgList);
251
252     ACPI_MSG_REDIRECT_END;
253 }
254
255 ACPI_EXPORT_SYMBOL (AcpiInfo)
256
257
258 /*******************************************************************************
259  *
260  * FUNCTION:    AcpiBiosError
261  *
262  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
263  *              LineNumber          - Caller's line number (for error output)
264  *              Format              - Printf format string + additional args
265  *
266  * RETURN:      None
267  *
268  * DESCRIPTION: Print "ACPI Firmware Error" message with module/line/version
269  *              info
270  *
271  ******************************************************************************/
272
273 void ACPI_INTERNAL_VAR_XFACE
274 AcpiBiosError (
275     const char              *ModuleName,
276     UINT32                  LineNumber,
277     const char              *Format,
278     ...)
279 {
280     va_list                 ArgList;
281
282
283     ACPI_MSG_REDIRECT_BEGIN;
284     AcpiOsPrintf (ACPI_MSG_BIOS_ERROR);
285
286     va_start (ArgList, Format);
287     AcpiOsVprintf (Format, ArgList);
288     ACPI_MSG_SUFFIX;
289     va_end (ArgList);
290
291     ACPI_MSG_REDIRECT_END;
292 }
293
294 ACPI_EXPORT_SYMBOL (AcpiBiosError)
295
296
297 /*******************************************************************************
298  *
299  * FUNCTION:    AcpiBiosWarning
300  *
301  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
302  *              LineNumber          - Caller's line number (for error output)
303  *              Format              - Printf format string + additional args
304  *
305  * RETURN:      None
306  *
307  * DESCRIPTION: Print "ACPI Firmware Warning" message with module/line/version
308  *              info
309  *
310  ******************************************************************************/
311
312 void ACPI_INTERNAL_VAR_XFACE
313 AcpiBiosWarning (
314     const char              *ModuleName,
315     UINT32                  LineNumber,
316     const char              *Format,
317     ...)
318 {
319     va_list                 ArgList;
320
321
322     ACPI_MSG_REDIRECT_BEGIN;
323     AcpiOsPrintf (ACPI_MSG_BIOS_WARNING);
324
325     va_start (ArgList, Format);
326     AcpiOsVprintf (Format, ArgList);
327     ACPI_MSG_SUFFIX;
328     va_end (ArgList);
329
330     ACPI_MSG_REDIRECT_END;
331 }
332
333 ACPI_EXPORT_SYMBOL (AcpiBiosWarning)
334
335
336 /*
337  * The remainder of this module contains internal error functions that may
338  * be configured out.
339  */
340 #if !defined (ACPI_NO_ERROR_MESSAGES) && !defined (ACPI_BIN_APP)
341
342 /*******************************************************************************
343  *
344  * FUNCTION:    AcpiUtPredefinedWarning
345  *
346  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
347  *              LineNumber      - Caller's line number (for error output)
348  *              Pathname        - Full pathname to the node
349  *              NodeFlags       - From Namespace node for the method/object
350  *              Format          - Printf format string + additional args
351  *
352  * RETURN:      None
353  *
354  * DESCRIPTION: Warnings for the predefined validation module. Messages are
355  *              only emitted the first time a problem with a particular
356  *              method/object is detected. This prevents a flood of error
357  *              messages for methods that are repeatedly evaluated.
358  *
359  ******************************************************************************/
360
361 void ACPI_INTERNAL_VAR_XFACE
362 AcpiUtPredefinedWarning (
363     const char              *ModuleName,
364     UINT32                  LineNumber,
365     char                    *Pathname,
366     UINT8                   NodeFlags,
367     const char              *Format,
368     ...)
369 {
370     va_list                 ArgList;
371
372
373     /*
374      * Warning messages for this method/object will be disabled after the
375      * first time a validation fails or an object is successfully repaired.
376      */
377     if (NodeFlags & ANOBJ_EVALUATED)
378     {
379         return;
380     }
381
382     AcpiOsPrintf (ACPI_MSG_WARNING "%s: ", Pathname);
383
384     va_start (ArgList, Format);
385     AcpiOsVprintf (Format, ArgList);
386     ACPI_MSG_SUFFIX;
387     va_end (ArgList);
388 }
389
390
391 /*******************************************************************************
392  *
393  * FUNCTION:    AcpiUtPredefinedInfo
394  *
395  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
396  *              LineNumber      - Caller's line number (for error output)
397  *              Pathname        - Full pathname to the node
398  *              NodeFlags       - From Namespace node for the method/object
399  *              Format          - Printf format string + additional args
400  *
401  * RETURN:      None
402  *
403  * DESCRIPTION: Info messages for the predefined validation module. Messages
404  *              are only emitted the first time a problem with a particular
405  *              method/object is detected. This prevents a flood of
406  *              messages for methods that are repeatedly evaluated.
407  *
408  ******************************************************************************/
409
410 void ACPI_INTERNAL_VAR_XFACE
411 AcpiUtPredefinedInfo (
412     const char              *ModuleName,
413     UINT32                  LineNumber,
414     char                    *Pathname,
415     UINT8                   NodeFlags,
416     const char              *Format,
417     ...)
418 {
419     va_list                 ArgList;
420
421
422     /*
423      * Warning messages for this method/object will be disabled after the
424      * first time a validation fails or an object is successfully repaired.
425      */
426     if (NodeFlags & ANOBJ_EVALUATED)
427     {
428         return;
429     }
430
431     AcpiOsPrintf (ACPI_MSG_INFO "%s: ", Pathname);
432
433     va_start (ArgList, Format);
434     AcpiOsVprintf (Format, ArgList);
435     ACPI_MSG_SUFFIX;
436     va_end (ArgList);
437 }
438
439
440 /*******************************************************************************
441  *
442  * FUNCTION:    AcpiUtPredefinedBiosError
443  *
444  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
445  *              LineNumber      - Caller's line number (for error output)
446  *              Pathname        - Full pathname to the node
447  *              NodeFlags       - From Namespace node for the method/object
448  *              Format          - Printf format string + additional args
449  *
450  * RETURN:      None
451  *
452  * DESCRIPTION: BIOS error message for predefined names. Messages
453  *              are only emitted the first time a problem with a particular
454  *              method/object is detected. This prevents a flood of
455  *              messages for methods that are repeatedly evaluated.
456  *
457  ******************************************************************************/
458
459 void ACPI_INTERNAL_VAR_XFACE
460 AcpiUtPredefinedBiosError (
461     const char              *ModuleName,
462     UINT32                  LineNumber,
463     char                    *Pathname,
464     UINT8                   NodeFlags,
465     const char              *Format,
466     ...)
467 {
468     va_list                 ArgList;
469
470
471     /*
472      * Warning messages for this method/object will be disabled after the
473      * first time a validation fails or an object is successfully repaired.
474      */
475     if (NodeFlags & ANOBJ_EVALUATED)
476     {
477         return;
478     }
479
480     AcpiOsPrintf (ACPI_MSG_BIOS_ERROR "%s: ", Pathname);
481
482     va_start (ArgList, Format);
483     AcpiOsVprintf (Format, ArgList);
484     ACPI_MSG_SUFFIX;
485     va_end (ArgList);
486 }
487
488
489 /*******************************************************************************
490  *
491  * FUNCTION:    AcpiUtNamespaceError
492  *
493  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
494  *              LineNumber          - Caller's line number (for error output)
495  *              InternalName        - Name or path of the namespace node
496  *              LookupStatus        - Exception code from NS lookup
497  *
498  * RETURN:      None
499  *
500  * DESCRIPTION: Print error message with the full pathname for the NS node.
501  *
502  ******************************************************************************/
503
504 void
505 AcpiUtNamespaceError (
506     const char              *ModuleName,
507     UINT32                  LineNumber,
508     const char              *InternalName,
509     ACPI_STATUS             LookupStatus)
510 {
511     ACPI_STATUS             Status;
512     UINT32                  BadName;
513     char                    *Name = NULL;
514
515
516     ACPI_MSG_REDIRECT_BEGIN;
517     AcpiOsPrintf (ACPI_MSG_ERROR);
518
519     if (LookupStatus == AE_BAD_CHARACTER)
520     {
521         /* There is a non-ascii character in the name */
522
523         ACPI_MOVE_32_TO_32 (&BadName, ACPI_CAST_PTR (UINT32, InternalName));
524         AcpiOsPrintf ("[0x%.8X] (NON-ASCII)", BadName);
525     }
526     else
527     {
528         /* Convert path to external format */
529
530         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
531                     InternalName, NULL, &Name);
532
533         /* Print target name */
534
535         if (ACPI_SUCCESS (Status))
536         {
537             AcpiOsPrintf ("[%s]", Name);
538         }
539         else
540         {
541             AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
542         }
543
544         if (Name)
545         {
546             ACPI_FREE (Name);
547         }
548     }
549
550     AcpiOsPrintf (" Namespace lookup failure, %s",
551         AcpiFormatException (LookupStatus));
552
553     ACPI_MSG_SUFFIX;
554     ACPI_MSG_REDIRECT_END;
555 }
556
557
558 /*******************************************************************************
559  *
560  * FUNCTION:    AcpiUtMethodError
561  *
562  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
563  *              LineNumber          - Caller's line number (for error output)
564  *              Message             - Error message to use on failure
565  *              PrefixNode          - Prefix relative to the path
566  *              Path                - Path to the node (optional)
567  *              MethodStatus        - Execution status
568  *
569  * RETURN:      None
570  *
571  * DESCRIPTION: Print error message with the full pathname for the method.
572  *
573  ******************************************************************************/
574
575 void
576 AcpiUtMethodError (
577     const char              *ModuleName,
578     UINT32                  LineNumber,
579     const char              *Message,
580     ACPI_NAMESPACE_NODE     *PrefixNode,
581     const char              *Path,
582     ACPI_STATUS             MethodStatus)
583 {
584     ACPI_STATUS             Status;
585     ACPI_NAMESPACE_NODE     *Node = PrefixNode;
586
587
588     ACPI_MSG_REDIRECT_BEGIN;
589     AcpiOsPrintf (ACPI_MSG_ERROR);
590
591     if (Path)
592     {
593         Status = AcpiNsGetNode (PrefixNode, Path, ACPI_NS_NO_UPSEARCH,
594                     &Node);
595         if (ACPI_FAILURE (Status))
596         {
597             AcpiOsPrintf ("[Could not get node by pathname]");
598         }
599     }
600
601     AcpiNsPrintNodePathname (Node, Message);
602     AcpiOsPrintf (", %s", AcpiFormatException (MethodStatus));
603
604     ACPI_MSG_SUFFIX;
605     ACPI_MSG_REDIRECT_END;
606 }
607
608 #endif /* ACPI_NO_ERROR_MESSAGES */