1 /*******************************************************************************
   2  *
   3  * Module Name: utxferror - Various error/warning output functions
   4  *
   5  ******************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2011, 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 /*
  91  * Common message suffix
  92  */
  93 #define ACPI_MSG_SUFFIX \
  94     AcpiOsPrintf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, ModuleName, LineNumber)
  95 
  96 
  97 /*******************************************************************************
  98  *
  99  * FUNCTION:    AcpiError
 100  *
 101  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
 102  *              LineNumber          - Caller's line number (for error output)
 103  *              Format              - Printf format string + additional args
 104  *
 105  * RETURN:      None
 106  *
 107  * DESCRIPTION: Print "ACPI Error" message with module/line/version info
 108  *
 109  ******************************************************************************/
 110 
 111 void ACPI_INTERNAL_VAR_XFACE
 112 AcpiError (
 113     const char              *ModuleName,
 114     UINT32                  LineNumber,
 115     const char              *Format,
 116     ...)
 117 {
 118     va_list                 ArgList;
 119 
 120 
 121     ACPI_MSG_REDIRECT_BEGIN;
 122     AcpiOsPrintf (ACPI_MSG_ERROR);
 123 
 124     va_start (ArgList, Format);
 125     AcpiOsVprintf (Format, ArgList);
 126     ACPI_MSG_SUFFIX;
 127     va_end (ArgList);
 128 
 129     ACPI_MSG_REDIRECT_END;
 130 }
 131 
 132 ACPI_EXPORT_SYMBOL (AcpiError)
 133 
 134 
 135 /*******************************************************************************
 136  *
 137  * FUNCTION:    AcpiException
 138  *
 139  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
 140  *              LineNumber          - Caller's line number (for error output)
 141  *              Status              - Status to be formatted
 142  *              Format              - Printf format string + additional args
 143  *
 144  * RETURN:      None
 145  *
 146  * DESCRIPTION: Print "ACPI Exception" message with module/line/version info
 147  *              and decoded ACPI_STATUS.
 148  *
 149  ******************************************************************************/
 150 
 151 void ACPI_INTERNAL_VAR_XFACE
 152 AcpiException (
 153     const char              *ModuleName,
 154     UINT32                  LineNumber,
 155     ACPI_STATUS             Status,
 156     const char              *Format,
 157     ...)
 158 {
 159     va_list                 ArgList;
 160 
 161 
 162     ACPI_MSG_REDIRECT_BEGIN;
 163     AcpiOsPrintf (ACPI_MSG_EXCEPTION "%s, ", AcpiFormatException (Status));
 164 
 165     va_start (ArgList, Format);
 166     AcpiOsVprintf (Format, ArgList);
 167     ACPI_MSG_SUFFIX;
 168     va_end (ArgList);
 169 
 170     ACPI_MSG_REDIRECT_END;
 171 }
 172 
 173 ACPI_EXPORT_SYMBOL (AcpiException)
 174 
 175 
 176 /*******************************************************************************
 177  *
 178  * FUNCTION:    AcpiWarning
 179  *
 180  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
 181  *              LineNumber          - Caller's line number (for error output)
 182  *              Format              - Printf format string + additional args
 183  *
 184  * RETURN:      None
 185  *
 186  * DESCRIPTION: Print "ACPI Warning" message with module/line/version info
 187  *
 188  ******************************************************************************/
 189 
 190 void ACPI_INTERNAL_VAR_XFACE
 191 AcpiWarning (
 192     const char              *ModuleName,
 193     UINT32                  LineNumber,
 194     const char              *Format,
 195     ...)
 196 {
 197     va_list                 ArgList;
 198 
 199 
 200     ACPI_MSG_REDIRECT_BEGIN;
 201     AcpiOsPrintf (ACPI_MSG_WARNING);
 202 
 203     va_start (ArgList, Format);
 204     AcpiOsVprintf (Format, ArgList);
 205     ACPI_MSG_SUFFIX;
 206     va_end (ArgList);
 207 
 208     ACPI_MSG_REDIRECT_END;
 209 }
 210 
 211 ACPI_EXPORT_SYMBOL (AcpiWarning)
 212 
 213 
 214 /*******************************************************************************
 215  *
 216  * FUNCTION:    AcpiInfo
 217  *
 218  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
 219  *              LineNumber          - Caller's line number (for error output)
 220  *              Format              - Printf format string + additional args
 221  *
 222  * RETURN:      None
 223  *
 224  * DESCRIPTION: Print generic "ACPI:" information message. There is no
 225  *              module/line/version info in order to keep the message simple.
 226  *
 227  * TBD: ModuleName and LineNumber args are not needed, should be removed.
 228  *
 229  ******************************************************************************/
 230 
 231 void ACPI_INTERNAL_VAR_XFACE
 232 AcpiInfo (
 233     const char              *ModuleName,
 234     UINT32                  LineNumber,
 235     const char              *Format,
 236     ...)
 237 {
 238     va_list                 ArgList;
 239 
 240 
 241     ACPI_MSG_REDIRECT_BEGIN;
 242     AcpiOsPrintf (ACPI_MSG_INFO);
 243 
 244     va_start (ArgList, Format);
 245     AcpiOsVprintf (Format, ArgList);
 246     AcpiOsPrintf ("\n");
 247     va_end (ArgList);
 248 
 249     ACPI_MSG_REDIRECT_END;
 250 }
 251 
 252 ACPI_EXPORT_SYMBOL (AcpiInfo)
 253 
 254 
 255 /*
 256  * The remainder of this module contains internal error functions that may
 257  * be configured out.
 258  */
 259 #if !defined (ACPI_NO_ERROR_MESSAGES) && !defined (ACPI_BIN_APP)
 260 
 261 /*******************************************************************************
 262  *
 263  * FUNCTION:    AcpiUtPredefinedWarning
 264  *
 265  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
 266  *              LineNumber      - Caller's line number (for error output)
 267  *              Pathname        - Full pathname to the node
 268  *              NodeFlags       - From Namespace node for the method/object
 269  *              Format          - Printf format string + additional args
 270  *
 271  * RETURN:      None
 272  *
 273  * DESCRIPTION: Warnings for the predefined validation module. Messages are
 274  *              only emitted the first time a problem with a particular
 275  *              method/object is detected. This prevents a flood of error
 276  *              messages for methods that are repeatedly evaluated.
 277  *
 278  ******************************************************************************/
 279 
 280 void ACPI_INTERNAL_VAR_XFACE
 281 AcpiUtPredefinedWarning (
 282     const char              *ModuleName,
 283     UINT32                  LineNumber,
 284     char                    *Pathname,
 285     UINT8                   NodeFlags,
 286     const char              *Format,
 287     ...)
 288 {
 289     va_list                 ArgList;
 290 
 291 
 292     /*
 293      * Warning messages for this method/object will be disabled after the
 294      * first time a validation fails or an object is successfully repaired.
 295      */
 296     if (NodeFlags & ANOBJ_EVALUATED)
 297     {
 298         return;
 299     }
 300 
 301     AcpiOsPrintf (ACPI_MSG_WARNING "For %s: ", Pathname);
 302 
 303     va_start (ArgList, Format);
 304     AcpiOsVprintf (Format, ArgList);
 305     ACPI_MSG_SUFFIX;
 306     va_end (ArgList);
 307 }
 308 
 309 
 310 /*******************************************************************************
 311  *
 312  * FUNCTION:    AcpiUtPredefinedInfo
 313  *
 314  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
 315  *              LineNumber      - Caller's line number (for error output)
 316  *              Pathname        - Full pathname to the node
 317  *              NodeFlags       - From Namespace node for the method/object
 318  *              Format          - Printf format string + additional args
 319  *
 320  * RETURN:      None
 321  *
 322  * DESCRIPTION: Info messages for the predefined validation module. Messages
 323  *              are only emitted the first time a problem with a particular
 324  *              method/object is detected. This prevents a flood of
 325  *              messages for methods that are repeatedly evaluated.
 326  *
 327  ******************************************************************************/
 328 
 329 void ACPI_INTERNAL_VAR_XFACE
 330 AcpiUtPredefinedInfo (
 331     const char              *ModuleName,
 332     UINT32                  LineNumber,
 333     char                    *Pathname,
 334     UINT8                   NodeFlags,
 335     const char              *Format,
 336     ...)
 337 {
 338     va_list                 ArgList;
 339 
 340 
 341     /*
 342      * Warning messages for this method/object will be disabled after the
 343      * first time a validation fails or an object is successfully repaired.
 344      */
 345     if (NodeFlags & ANOBJ_EVALUATED)
 346     {
 347         return;
 348     }
 349 
 350     AcpiOsPrintf (ACPI_MSG_INFO "For %s: ", Pathname);
 351 
 352     va_start (ArgList, Format);
 353     AcpiOsVprintf (Format, ArgList);
 354     ACPI_MSG_SUFFIX;
 355     va_end (ArgList);
 356 }
 357 
 358 
 359 /*******************************************************************************
 360  *
 361  * FUNCTION:    AcpiUtNamespaceError
 362  *
 363  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
 364  *              LineNumber          - Caller's line number (for error output)
 365  *              InternalName        - Name or path of the namespace node
 366  *              LookupStatus        - Exception code from NS lookup
 367  *
 368  * RETURN:      None
 369  *
 370  * DESCRIPTION: Print error message with the full pathname for the NS node.
 371  *
 372  ******************************************************************************/
 373 
 374 void
 375 AcpiUtNamespaceError (
 376     const char              *ModuleName,
 377     UINT32                  LineNumber,
 378     const char              *InternalName,
 379     ACPI_STATUS             LookupStatus)
 380 {
 381     ACPI_STATUS             Status;
 382     UINT32                  BadName;
 383     char                    *Name = NULL;
 384 
 385 
 386     ACPI_MSG_REDIRECT_BEGIN;
 387     AcpiOsPrintf (ACPI_MSG_ERROR);
 388 
 389     if (LookupStatus == AE_BAD_CHARACTER)
 390     {
 391         /* There is a non-ascii character in the name */
 392 
 393         ACPI_MOVE_32_TO_32 (&BadName, ACPI_CAST_PTR (UINT32, InternalName));
 394         AcpiOsPrintf ("[0x%4.4X] (NON-ASCII)", BadName);
 395     }
 396     else
 397     {
 398         /* Convert path to external format */
 399 
 400         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
 401                     InternalName, NULL, &Name);
 402 
 403         /* Print target name */
 404 
 405         if (ACPI_SUCCESS (Status))
 406         {
 407             AcpiOsPrintf ("[%s]", Name);
 408         }
 409         else
 410         {
 411             AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
 412         }
 413 
 414         if (Name)
 415         {
 416             ACPI_FREE (Name);
 417         }
 418     }
 419 
 420     AcpiOsPrintf (" Namespace lookup failure, %s",
 421         AcpiFormatException (LookupStatus));
 422 
 423     ACPI_MSG_SUFFIX;
 424     ACPI_MSG_REDIRECT_END;
 425 }
 426 
 427 
 428 /*******************************************************************************
 429  *
 430  * FUNCTION:    AcpiUtMethodError
 431  *
 432  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
 433  *              LineNumber          - Caller's line number (for error output)
 434  *              Message             - Error message to use on failure
 435  *              PrefixNode          - Prefix relative to the path
 436  *              Path                - Path to the node (optional)
 437  *              MethodStatus        - Execution status
 438  *
 439  * RETURN:      None
 440  *
 441  * DESCRIPTION: Print error message with the full pathname for the method.
 442  *
 443  ******************************************************************************/
 444 
 445 void
 446 AcpiUtMethodError (
 447     const char              *ModuleName,
 448     UINT32                  LineNumber,
 449     const char              *Message,
 450     ACPI_NAMESPACE_NODE     *PrefixNode,
 451     const char              *Path,
 452     ACPI_STATUS             MethodStatus)
 453 {
 454     ACPI_STATUS             Status;
 455     ACPI_NAMESPACE_NODE     *Node = PrefixNode;
 456 
 457 
 458     ACPI_MSG_REDIRECT_BEGIN;
 459     AcpiOsPrintf (ACPI_MSG_ERROR);
 460 
 461     if (Path)
 462     {
 463         Status = AcpiNsGetNode (PrefixNode, Path, ACPI_NS_NO_UPSEARCH,
 464                     &Node);
 465         if (ACPI_FAILURE (Status))
 466         {
 467             AcpiOsPrintf ("[Could not get node by pathname]");
 468         }
 469     }
 470 
 471     AcpiNsPrintNodePathname (Node, Message);
 472     AcpiOsPrintf (", %s", AcpiFormatException (MethodStatus));
 473 
 474     ACPI_MSG_SUFFIX;
 475     ACPI_MSG_REDIRECT_END;
 476 }
 477 
 478 #endif /* ACPI_NO_ERROR_MESSAGES */